FreeCAD game

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

FreeCAD game

Post by JMG »

Hi!

I have done a script for a small 'game' using FreeCAD, see it in action here: https://www.youtube.com/watch?v=dORV7CjtmtA

I know this is something non-productive, but I had fun to working at it and it shows something that no other CAD engine has shown jet: to serve as game engine .

Though this assumption is relative, because there are not complex rotations or collisions, so basically is playing with the keyboard input and the placement of the objects. But who knows, maybe in a future it becomes able to handle collisions and other effects :)

The code is here: https://github.com/JMG1/FreeTruck
Have fun!

Javier.
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: FreeCAD game

Post by DeepSOIC »

Such functionality can be useful for architecture application, I guess. Cool!
m.no
Posts: 10
Joined: Wed Oct 29, 2014 6:51 pm

Re: FreeCAD game

Post by m.no »

It's easy to do sth similar in V-REP (or other robot simulators), but with working dynamics and collisions :). Maybe a little off-topic, but i'd love to see sth like V-REP or Gazebo built upon FreeCAD. It could be used not only for robot simulations but also for simulation of some production lines where there's need for more advanced control (PySimEd for that?) than in simple MBD simulations (NX have similar module). Just food for thought.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: FreeCAD game

Post by triplus »

Looking good.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FreeCAD game

Post by bernd »

Wow thats awesome, and yes thats really usefull for building modells !!!
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FreeCAD game

Post by bernd »

It really makes fun. And yes this is no game at all. In architecture this is highly appreciated feature. Has anyone an idea how to implement the impact of the truck. The truck should stay on the street. We would need to check if the truck intersects with any other part. I if the truck intersects the truck should go in the opposite direction as long as it intersects. But to test if the truck intersects with all the parts of the model in every second is quite heavy. Only the ones near the truck needs to be checked. Do I write some crap or is this doable. I have never tried something in this regard.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: FreeCAD game

Post by DeepSOIC »

As for collision testing, I think this can be done by somehow constructing a solid (or, actually, just a face) that contains all the points that truck's origin can be in. I guess, testing a point for being inside a solid is quite quick, should be doable in real time. The generation of the solid, of course, can take as long as needed.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: FreeCAD game

Post by microelly2 »

bernd wrote: But to test if the truck intersects with all the parts of the model in every second is quite heavy.
Spying the Blender collision dedection there is a simple algorithm to check the collisons of the bounding boxes.
For more complex structures in most cases its good enough to create a helper composite of some more boxes which approximate the figure.
I have done such scripts with javascript in vrml some years ago and I hope i can recover them.
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: FreeCAD game

Post by JMG »

Thanks for your support :)

I have uploaded a new version that does a very simple collision detection (with the .isInside function). It stops the truck if any of the vertexes is inside of the map.

I've also tried to link the bullet library included in Panda3D with FreeCAD, but without success, and currently, I'm struggling with a complete collision detection that would allow the truck to climb a ramp and something similar to free-fall (surprisingly, testing all the vertexes of the truck takes very little time).

I´ll post here any news about this. ;)
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: FreeCAD game

Post by microelly2 »

A simple and fast boundbox collision detection. In most cases this is realistic enough.

https://www.youtube.com/watch?v=UgImdIQ ... e=youtu.be

Code: Select all

def col(actor,obstacles):
	
	av=actor.Shape.BoundBox
	for obl in obstacles:
		ov=obl.Shape.BoundBox
		if ov.XMin < av.XMax  and  ov.XMax > av.XMin and ov.YMin <= av.YMax and  ov.YMax >= av.YMin and  ov.ZMin <= av.ZMax and  ov.ZMax >= av.ZMin:
			print obl.Label
			obl.ViewObject.DiffuseColor=(1.0,0.0,0.0)
		else:
			obl.ViewObject.DiffuseColor=(1.0,1.0,0.0)  

def checkCollision():

	App=FreeCAD
	cy=App.ActiveDocument.Cylinder
	c=App.ActiveDocument.Cone
	gd=App.ActiveDocument.GeodesicDome
	b=App.ActiveDocument.Box
	col(b,[cy,c,gd,App.ActiveDocument.Torus])
Post Reply