Convex Decomposition

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Convex Decomposition

Postby carli2 » Sun Nov 11, 2012 4:40 pm

Julio Jerez wrote:the plece I see teh grack indicate that the imput data is no correct, because it is rare that collision tree crashe with correct data.


Why does newton crash with certain input data? Couldn't you build some checks into newton to not dereference invalid pointers? That would make newton much more stable. I will give you a triangle list of a crashing example as soon as possible.
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Convex Decomposition

Postby Julio Jerez » Sun Nov 11, 2012 6:03 pm

bad data will make any porogram crash. It is a fallacy that any application can be safe to bad data.

But not newton does no do any checking of any kind other that the assert you get from running in debug.
in Linux teh asert is defined to nothing, if you change yo the linux assert it may trigger and assertiong.

the part that say that is crashing is when building a collsion tree, that part o fteh mewton mesh is teh same collsion tree that is use for the game collsion shapes. without a tes tI can no determine what could be.

the NetwonMesh has a save function
void NewtonMeshSaveOFF(const NewtonMesh* const mesh, const char* const filename);

if you save the mesh and post I can see why is cashing.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Decomposition

Postby carli2 » Mon Nov 12, 2012 3:43 am

Julio Jerez wrote:bad data will make any porogram crash.

That may be true for the windows operating system where still lots of remote vulnerabilities are hidden in the code... just send wrong data to RPC server and you can lead the server to a crash which you might exploit to take over the machine.


Julio Jerez wrote:It is a fallacy that any application can be safe to bad data.

For a C application, there should be of course pointer consistency, but data that's read from a file into a data structure should not lead any code to crash. It was so in 1995, but nowadays, too much "users" are using computers who just input any data. You cannot teach them to always enter correct data.

Julio Jerez wrote:But not newton does no do any checking of any kind other that the assert you get from running in debug.
in Linux teh asert is defined to nothing, if you change yo the linux assert it may trigger and assertiong.


Maybe you should make your functions return a null on consistant but unreasonable input data instead of asserting and crashing.

Julio Jerez wrote:the part that say that is crashing is when building a collsion tree, that part o fteh mewton mesh is teh same collsion tree that is use for the game collsion shapes. without a tes tI can no determine what could be.

the NetwonMesh has a save function
void NewtonMeshSaveOFF(const NewtonMesh* const mesh, const char* const filename);

if you save the mesh and post I can see why is cashing.


Okay, I tried a convex shape now and here's the result:
OFF: http://gwscript.goldenwipf.de/decomp.obj
Input 3ds file: http://gwscript.goldenwipf.de/stein.3ds
How the model should look like: Image

What the decompositor generated; read as follows: CreateCompoundBody([PrimitiveShape, PrimitiveShape, ....]) where PrimitiveShape is CreateStdBody("hull mass x y z x y z x y z")
Code: Select all
CreateCompoundBody([CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -50.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -40.8248 -20.4124 -20.4124 -50.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 15.8114 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 -35.3553 35.3553 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 15.8114 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 35.3553 0.0000 0.0000 0.0000 -47.4342 0.0000 15.8114 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 -35.3553 35.3553 0.0000 0.0000 0.0000 0.0000 -40.8248 20.4124 -20.4124 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -40.8248 -20.4124 -20.4124 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 -35.3553 35.3553 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 35.3553 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 35.3553 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 -35.3553 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 0.0000 35.3553 0.0000 -35.3553 -20.4124 -20.4124 -40.8248 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 -35.3553 0.0000 0.0000 0.0000 0.0000 0.0000 -20.4124 -20.4124 40.8248 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -35.3553 0.0000 0.0000 20.4124 40.8248 -20.4124 -15.8114 0.0000 -47.4342 "),
CreateStdBody("hull 100 -40.8248 -20.4124 20.4124 -20.4124 20.4124 -40.8248 -40.8248 20.4124 -20.4124 -20.4124 -40.8248 -20.4124 -47.4342 0.0000 -15.8114 148.0000 232.0000 35.3553 0.0000 0.0000 0.0000 Nan Nan Nan 35.3553 0.0000 35.3553 0.0000 35.3553 35.3553 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 35.3553 -35.3553 0.0000 20.4124 40.8248 -20.4124 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 -47.4342 0.0000 -15.8114 148.0000 232.0000 35.3553 0.0000 0.0000 0.0000 40.8248 -20.4124 -20.4124 35.3553 0.0000 35.3553 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 "),
CreateStdBody("hull 100 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -47.4342 0.0000 -15.8114 0.0000 0.0000 0.0000 Nan Nan Nan 35.3553 0.0000 35.3553 0.0000 0.0000 0.0000 ")])
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Convex Decomposition

Postby Julio Jerez » Mon Nov 12, 2012 9:03 am

Ok I just load the 3ds and teh OFF fiel in max an dteh look identical to me.

if the OFF file was what was generated by teh decomposition teh way I see, it did a perfect job.
I do not undestand what the problem is. I am confused

is the problem that you are havin deficulties recovering the data.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Decomposition

Postby carli2 » Mon Nov 12, 2012 3:55 pm

Julio Jerez wrote:Ok I just load the 3ds and teh OFF fiel in max an dteh look identical to me.

if the OFF file was what was generated by teh decomposition teh way I see, it did a perfect job.
I do not undestand what the problem is. I am confused

is the problem that you are havin deficulties recovering the data.


No. You understood that wrong.
Decompose this mesh now.

I thought you wanted to run decompose on that model on your own, so I kept it in the basis format.
When you look two posts above, you can see the result of the decomposition.
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Convex Decomposition

Postby Julio Jerez » Mon Nov 12, 2012 4:03 pm

carli2 wrote:
Julio Jerez wrote:I thought you wanted to run decompose on that model on your own


yes that's what I wna to do, to make it clear that first file http://gwscript.goldenwipf.de/decomp.obj is the one that when calling Convedecompistion produce teh wrong result?
I will try that in teh sand box demo and se what happens then.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Decomposition

Postby carli2 » Mon Nov 12, 2012 5:32 pm

Julio Jerez wrote:
carli2 wrote:
Julio Jerez wrote:I thought you wanted to run decompose on that model on your own


yes that's what I wna to do, to make it clear that first file http://gwscript.goldenwipf.de/decomp.obj is the one that when calling Convedecompistion produce teh wrong result?


Well, this model produces the wrong result. But I can also give you a model that leads newton to crash.
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Convex Decomposition

Postby Julio Jerez » Tue Nov 13, 2012 11:03 am

Ok I paste this

Code: Select all
//   NewtonMesh* const mesh = meshInfo->GetMesh();

   GetWorkingFileName ("decomp.off", fileName);
   NewtonMesh* const mesh = NewtonMeshLoadOFF(world, fileName);
   dMatrix scale (GetIdentityMatrix());
   scale[0][0] = 0.05f;
   scale[1][1] = 0.05f;
   scale[2][2] = 0.05f;
   NewtonMesApplyTransform (mesh, &scale[0][0]);


in function: void CreateConvexAproximation (const char* const name, DemoEntityManager* const scene, const dVector& origin, int instaceCount, const char* const texture)

in the sandbox demos, and I get the mesh converted to a single sonve spheroid just as I expected it would
at first I was confused becaus eteh mesh is super huge about 50 x 50 x 50
and itteh camera was inside of it, so I thought was failing, but afte I load in Max I saw it was teh size that was too big, so I scale it so that is become visible.

I still do not know what the problem is, and I beleive you are having problem geting the data back for the decomposition.
thsio sopdul be vey trivial to get ot going. can you show me the code you wrote to do the decomposition?

sink to svn so that you get the, code and I fix I added to the OFF loader so that in compute the normals, oteh wise the mesh looks invisible in teh demo becaus eteh normals were set to zero in the loader
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Decomposition

Postby carli2 » Wed Nov 14, 2012 2:37 am

Here's the code:

Code: Select all
procedure TDecompositor.Decompose;
type TdVec3 = array[0..2] of double;
     PdVec3 = ^TdVec3;
var hmesh: PNewtonMesh;
    segment, nextsegment: PNewtonMesh;
    v: TdVec3;
    i, p: integer;
begin
  NewtonMeshEndFace(newtonmesh);
  hmesh:=NewtonMeshApproximateConvexDecomposition(newtonmesh, 0.01, 0.2, 32, 100, nil);
  NewtonMeshBeginFace(newtonmesh);

  // hmesh in hulls übernehmen
  SetLength(hulls, 0);
  segment:=NewtonMeshCreateFirstSingleSegment(hmesh);
  while segment<>nil do begin
    nextsegment:=NewtonMeshCreateNextSingleSegment(hmesh, segment);
    // Hülle aus segment extrahieren
    SetLength(hulls, length(hulls)+1);
    for i:=NewtonMeshGetVertexCount(segment)-1 downto 0 do begin
      v:=PdVec3(NewtonMeshGetVertexArray(segment)+i*NewtonMeshGetVertexStrideInByte(segment))^;
      p:=getpoint(SetVector(v[0], v[1], v[2]));
      SetLength(hulls[high(hulls)], length(hulls[high(hulls)])+1);
      hulls[high(hulls)][high(hulls[high(hulls)])]:=p;
    end;
    NewtonMeshDestroy(segment);
    segment:=nextsegment;
  end;
end; 


Edit: AAaaaah, after reading through it, I noticed I did some type error in pointer arithmetics.

Now I get a reasonable data structure, but the decomposition results are not what I expected.
Image
Download the model: http://gwscript.goldenwipf.de/hinsel.md2
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Convex Decomposition

Postby Julio Jerez » Wed Nov 14, 2012 9:43 am

you give stuff peace meal by peace meal. Is that the same spheroid or a different model.

The decomposition should be acceptable in all cases. what model is that that you posted, I do not have a way to load MD2 file formats.

Like I said before, the simpler way is to load the model int a NewtonMesh by creation a mesh and then saving in as an OFF file, that I can load it.
The newton Mesh does not alter the mesh topology unless you ask to, neither does the OFF format, that makes it a good way for transfer data to debug.
can you save that model as a NewtopnMesh in OFF format?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Decomposition

Postby carli2 » Wed Nov 14, 2012 11:22 am

Julio Jerez wrote:you give stuff peace meal by peace meal. Is that the same spheroid or a different model.

different model

Julio Jerez wrote:The decomposition should be acceptable in all cases. what model is that that you posted, I do not have a way to load MD2 file formats.

The model posted is the one you see in the picture

Julio Jerez wrote:Like I said before, the simpler way is to load the model int a NewtonMesh by creation a mesh and then saving in as an OFF file, that I can load it.
The newton Mesh does not alter the mesh topology unless you ask to, neither does the OFF format, that makes it a good way for transfer data to debug.
can you save that model as a NewtopnMesh in OFF format?

Yep. I will do it ASAP
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron