[CLOSED] Blender animation of force field with clothes import to JME

Dear community,

in the game I have a flag moving by the wind.
So I did it in Blender, which is quite easy (cloth simulation for flag + force field of wind type).
However, I could not find any way how to export it to JME.

Is there any way? How would you as professionals implement such feature?

What comes to mind first would be baking the cloth as bone animation which can then be easily imported.
(Though I donā€™t consider myself a professional, try asking one of the Core devs if baking the animation isnā€™t enough).

Yes, there actually is one! One of the community, @Ali_RS, even made a video tutorial for exactly that. You basically have to apply your animation in blender to a key frame animation to your model. After that you easily can export it to jMonkeyEngine.

Here is the video:

Good luck!

2 Likes

Ali_RS tutorial is for Rigid Body - flag animation is mesh modifying and as I know it isnā€™t possible to export this to JME. You should search something about dispalce textures to modify vertex placement or use normalmaps to simulate cloth like in DeusEx.

1 Like

Of course it is, he already did it. He even uploaded a video, see yourself

2 Likes

Hi Domenic, thanks a lot for this video!

Current case is, on previous video ā€œBake Physics to Keyframe Animationā€ it is rigid body simulation, which could be baked to keyframes, but this option does not exist for cloth simulation.

Ali RS shows on his video clearly, that he got cloth simulation working, so I tried different options in Blender to make it work. No way :frowning: So I asked Ali RS, hope he will answer.

When I export it via xbuf into JME3, I see animation control created in j3o, but it cannot be played.
When I export via wavefront obj, 100 objects are created (1 for each frame), and I am not sure how to join them back to one j3o to get animationā€¦

Hi @Denis_Tislenko
Very sorry for late reply! I am busy doing my military service and we have no access to internet there. I can visit forum only on weekends :disappointed_relieved:

For physic rigid body simulation you can do like in video ā€œBake Physics to Keyframe Animationā€ to bake the physics simulation to blender keyframe animation (which is called SpatialAnimation in JME). Note you should export it to xbuf format for using in jme because as far as I know only xbuf is able to export SpatialAnimation from blender.

When I export via wavefront obj, 100 objects are created (1 for each frame), and I am not sure how to join them back to one j3o to get animationā€¦

** (First make sure you know about Spatial, Geometry and Mesh in JME.)

Regarding cloth simulation like flag waving, what I am doing is, after creating a flag simulation in blender (using blender cloth simulation) and exporting it as obj files (for example if your simulation is 100 frame it will export 100 obj files ). Then you need to load those obj files in jme, now for playing animation you need to switch the Mesh with time. For example for having a 30 fps animation speed you need to change the meshes after 1/30 second.
So for example for flag animation with 100 frame (100 obj files) you load all files and keep them in an array or list then start from the first geometry and after 1/30 s switch the geometryā€™s mesh with the second mesh and after another 1/30 s set the third mesh and so on.
Now you can set the array or list as UserData on spatial and save it as j3o (see wiki for how to save Spatial as j3o). After saving it as j3o you can delete all .obj files. The reason I am saying to save all in a j3o file instead of 100 separate files is that loading from hard disk is faster in first case.

Edit:
Note that this approach may not be a good approach for cloth simulation because of huge data size on disk and memory. Recently I have found about toxiclibs physic library for real time cloth simulation using Verlet integration but have not tried it yet. You might be interested to take a look at it :

1 Like

Thanks a lot! Everything worked as expected. If someone in future has same problem and needs code, I can share it

2 Likes