Creating a cloth from a mesh

NickM

18-03-2007 11:43:40

Hi,
I'm currently looking into using cloth metal in my project and was wondering whether you had done any work on creating a cloth from an Ogre mesh yet?
No problem if you haven't, I just thought I'd ask.

Keep up the good work.

Grom

18-03-2007 11:45:44

I think that's pretty much soft bodies, which is currently getting overhauled

NickM

20-03-2007 23:29:20

Ok, thanks.

NickM

25-03-2007 11:07:38

Has any progress been made on this yet?
I'm not being pushy, I'm just itching to see whether it'll be any good for my game. :)

betajaen

25-03-2007 11:19:31

The 0.6 SVN has soft bodies, but the rendering of it in Ogre is broken. I was hoping someone might fix my mistake, but nothing yet ;)

NickM

26-03-2007 22:48:36

What do I need to change in order to get the soft shape working again in the 0.6 SVN? (with the broken rendering, of course)

betajaen

26-03-2007 23:09:56

Nothing in theory. But I noticed in the source of NxOgre, line 549 in NxOgre_Scene.cpp is commented out. Uncomment it, and recompile.

You'll need to build a "tetrahedral mesh" or tet file from your mesh. This is done by getting the original and saving it as a "obj" file. Then use the PhysXViewer application that comes with the PhysXSDK to make the file.

This should be copied into the same directory as your executable. It should also have the same name as your mesh - "jelly_SB.mesh" and "jelly_SB.tet". The _SB means nothing, it's just a mental note to me that the mesh is a soft body.

And create it as:

mScene->createSoftBody("Jelly", "jelly_SB", new cubeShape(1), 10, Vector3(0,5,0));

The first parameter is the name, second is the name of your mesh and tetrahedral file without extensions. The cubeShape is used as the minimum shape (so if it was a block of jelly then it would be a cube, a frog a capsule, and a human a group of convexes), the others are density and pose.

I've uploaded the jelly files for you now, so you can try it out without messing around in the PhysXViewer.

http://get.nxogre.org/jelly_SB.zip


Good Luck!

NickM

26-03-2007 23:18:42

Thanks, I don't get much spare time but I'll take a look when I can, no promises. :wink:

NickM

27-03-2007 07:14:20

I guess it needs to use params<> now as I'm getting this...

..\source\nxOgre_shape_soft.cpp(45) : error C2039: 'SHAPE_SOFT' : is not a member of 'nxOgre::shape'

NickM

03-04-2007 07:03:45

A combination of very little time, the fact that I'm new to programming and (I think) that the NxOgre Shape system has been changed since SoftShapes worked, has meant I've not been able to even get NxOgre to compile. I just thought I'd let you know. :(

NickM

07-04-2007 11:59:58

I've spent some time trying to code generating a cloth from an ogre mesh in NxOgre0.4 RC3
I've got it semi working but for some reason the cloth doesn't hold together, the faces that make up the cloth are splitting apart, I've attached a couple of links to short videos, the 1st one is a mesh that I've made in 3d max and the 2nd one is the cube.1m.mesh, both meshes are dropping into the scene from above the car and splitting as they land on top of the car.
Anyone got any idea why this might be happening am I missing something simple?

http://www.youtube.com/watch?v=oIw5tjeIk6E

http://www.youtube.com/watch?v=BaGcehj-AKk

I've also implimented 'attachToCore' which attaches the cloth to an actor turning it into cloth metal but after a few collisions the faces start to split apart with that too.

I'll take a break and come back to it as I'm sure I'm missing something simple.

NickM

07-04-2007 13:27:03

Update, I think it's a problem with my index buffer, going to look into it later tonight.

NickM

07-04-2007 23:27:32

hmmm :cry:

It is'nt an index buffer problem, If I create a simple plane in 3dmax and use that as a mesh for the cloth it works perfectly ok (see the video link below) but if I create a simple 6 sided box and try to use that as cloth it falls apart with each side seemingly becoming a seperate cloth. I'm not sure whats going on. :(

I must be missing something, maybe what I'm trying to do isn't even possible, I really don't know.

http://www.youtube.com/watch?v=AK5w_w48W9A

betajaen

07-04-2007 23:34:45

Have you tried it directly with PhysX, with one of the OpenGL cloth demos? If it doesn't work, I'd try soft bodies.

Also, Nice videos - even if they don't work as expected ;)

NickM

08-04-2007 16:49:59

I think the reason I'm having problems is due to the Ogre 3dmax exporters not using shared vertices. The simple box in max has 8 verts, as you'd expect, but once exported it has 24. This means that once the triangles (faces) have been made, each side of the box has no real connection to any other side (each side uses it's own verts) hence the reason the box falls apart when it's made into a cloth. In theory it becomes 6 seperate cloths.

I tried writing my own XML for a simple box using shared verts but I couldn't get it through the Ogre XML converter.

At this moment in time I don't know how to get around this problem, any ideas?

betajaen

08-04-2007 16:54:29

Weird. Have you tried using Blender and the Ogre Exporter in that?

NickM

08-04-2007 20:18:50

Weird. Have you tried using Blender and the Ogre Exporter in that?

I haven't tried it, no. I just tried to download the plugin for it but sourceforge seems to be down?

NickM

08-04-2007 21:10:43

I've got the plugin but it appears to not use shared vertices either, you still have to run the exported XML through the converter.

betajaen

08-04-2007 21:53:10

That is strange. I'm sure it uses shared vertices else the meshes I created and use for meshShapes would not work.

Have you tried creating the mesh by hand in code? There are a few Ogre wiki articles with code explaining how to do this. As long as the mesh is created and loaded before you create the body, it should work.

NickM

08-04-2007 22:28:59

I think the problem is in the process of cooking the mesh into a cloth, the cooking process uses the indexes to create the links between vertices, because the vertices in the meshes I've been using aren't shared there is no link between each side of the box.
This is all just my theory from the experimenting I've done so far, of course I may be wrong lol

As we speak I am coding a box mesh by hand.

NickM

09-04-2007 00:13:03

A manually coded box with 8 vertices and 36 indexes seems to work ok....

NickM

09-04-2007 12:22:22

That is strange. I'm sure it uses shared vertices else the meshes I created and use for meshShapes would not work.


Have you got a particular mesh in mind that you think uses shared verts?
I've tried your cube.1m.mesh, it just falls apart as cloth.

I've posted on the main forum about exporting a mesh using shared verts, I'll await an answer.
I suppose we'll have to do a bit of coding to convert non shared meshes into shared vertex ones inside NxOgre, I'm not sure that I'm clever enough for that, I'll have to have a think about what it takes to do it.

NickM

14-04-2007 12:24:07

I've still been fiddling about with this, the problem is as follows...

A simple 6 sided cube with 12 faces as an Ogre mesh uses 24 vertices, each side of the cube uses it's own set of 4 vertices, it does this to allow each side to have it's own normals for smoothing but it means that a cloth made from this mesh has no connection between the sides of the box hence the reason it just falls apart.
In contrast the same cube exported as a .obj which is the format used in the PhysX examples uses only 8 vertices, so that works perfectly ok as a cloth.

Here's the XML for the Ogre cube....

- <mesh>
- <sharedgeometry vertexcount="24">
- <vertexbuffer positions="true" normals="true" colours_diffuse="false" colours_specular="false" texture_coords="0">
- <vertex>
<position x="-0.5" y="0.5" z="0.5" />
<normal x="-1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="-0.5" />
<normal x="-1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="0.5" />
<normal x="-1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="0.5" z="-0.5" />
<normal x="-1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="-0.5" />
<normal x="0" y="-1" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="0.5" />
<normal x="0" y="-1" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="0.5" />
<normal x="0" y="-1" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="-0.5" />
<normal x="0" y="-1" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="0.5" z="-0.5" />
<normal x="0" y="0" z="-1" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="-0.5" />
<normal x="0" y="0" z="-1" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="-0.5" />
<normal x="0" y="0" z="-1" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="-0.5" />
<normal x="0" y="-0" z="-1" />
</vertex>
- <vertex>
<position x="-0.5" y="0.5" z="-0.5" />
<normal x="0" y="1" z="-0" />
</vertex>
- <vertex>
<position x="-0.5" y="0.5" z="0.5" />
<normal x="0" y="1" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="0.5" />
<normal x="0" y="1" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="-0.5" />
<normal x="0" y="1" z="0" />
</vertex>
- <vertex>
<position x="-0.5" y="0.5" z="0.5" />
<normal x="0" y="0" z="1" />
</vertex>
- <vertex>
<position x="-0.5" y="-0.5" z="0.5" />
<normal x="0" y="0" z="1" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="0.5" />
<normal x="0" y="0" z="1" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="0.5" />
<normal x="0" y="0" z="1" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="-0.5" />
<normal x="1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="0.5" />
<normal x="1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="-0.5" z="0.5" />
<normal x="1" y="0" z="-0" />
</vertex>
- <vertex>
<position x="0.5" y="0.5" z="-0.5" />
<normal x="1" y="-0" z="-0" />
</vertex>
</vertexbuffer>
</sharedgeometry>
- <submeshes>
- <submesh material="Default" usesharedvertices="true" use32bitindexes="false" operationtype="triangle_list">
- <faces count="12">
<face v1="0" v2="1" v3="2" />
<face v1="0" v2="3" v3="1" />
<face v1="4" v2="5" v3="6" />
<face v1="4" v2="7" v3="5" />
<face v1="8" v2="9" v3="10" />
<face v1="8" v2="11" v3="9" />
<face v1="12" v2="13" v3="14" />
<face v1="15" v2="12" v3="14" />
<face v1="16" v2="17" v3="18" />
<face v1="19" v2="16" v3="18" />
<face v1="20" v2="21" v3="22" />
<face v1="23" v2="21" v3="20" />
</faces>
</submesh>
</submeshes>
</mesh>

and here's the .obj...

# Blender3D v243 OBJ File: untitled.blend
# www.blender3d.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
s 1
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8


If you want to be able to use Ogre meshes as cloth then some work will need to be done to remove duplicate verts and update the indices accordingly, it's quite a complicated problem as that will then mess up the smoothing, have you got any ideas about how you would like to handle this betajaen?

Lexx

14-04-2007 12:55:17

maybe i'm thinking wrong, but:
do you tried to use Maya exporter with "shared geometry" enabled options?

NickM

14-04-2007 13:23:08

maybe i'm thinking wrong, but:
do you tried to use Maya exporter with "shared geometry" enabled options?


I haven't got Maya, I suspect it will be the same as all the exporters I've tried, maybe you would be kind enough to make a simple cube and export it from Maya for me?

Lexx

14-04-2007 14:01:39

got one:
http://coderfx.nm.ru/cube.rar
617 bytes
it's used [MeshSerializer_v1.40], so mesh only for Ogre1.4 Eihort version

NickM

15-04-2007 10:07:25


it's used [MeshSerializer_v1.40], so mesh only for Ogre1.4 Eihort version

Thanks for doing that, I'm actually still using Dagon at the moment but I guess I should upgrade.

NickM

05-05-2007 14:56:19

I've still been beavering away at this when I get time, I've made some progress but still have a few problems to resolve.
What I'm doing is basically copying the vertex positions from a mesh into 2 lists, I then check vertex 1 from list 1 against every vertex in list 2 and any duplicates are removed from list 1, I go through the same process for every vert in list 1 and end up with a list of verts without any duplicates.
I then go through the index list and adjust the indices accordingly so that they point to the correct vertex.
This process can take a little time when trying to use a mesh with alot of verts. :cry:
After the above process I end up with a fully shared vertex mesh which will happily convert to a PhysX cloth, the downside is that proper smoothing is lost.
Here's a short video of a very simple cloth tyre model falling on top of my simple car model, as you'll see, the texture coordinates aren't quite right for some reason.

http://www.youtube.com/watch?v=9YxnWM6b5kE

betajaen

05-05-2007 18:24:49

I want to thank you for taking your time with this. The cloth and soft body system has always confused me a little and if your willing I'm more than happy to submit your changes and new code into NxOgre 0.9

NickM

05-05-2007 19:24:57

I want to thank you for taking your time with this. The cloth and soft body system has always confused me a little and if your willing I'm more than happy to submit your changes and new code into NxOgre 0.9

No problem, I'm learning new things as I go, so I'm actually enjoying it, I'd also like to be able to use this in my game so I hope I can get it working properly :D
Once I get it all working (fingers crossed) I'll happily send you the code. Keep up the good work betajaen.

NickM

17-05-2007 23:15:17

Just to keep you updated, I've made some more progress on this tonight, I still have a couple of bugs to sort out and alot of code tidying up to do but I have managed to create texture mapped cloth objects from an Ogre mesh :D

http://www.youtube.com/watch?v=MkRPk_y9Zjc

betajaen

17-05-2007 23:16:52

I can't wait.