NewtonCreateCompoundCollisionFromMesh not working correct?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Wed Nov 21, 2012 11:53 am

to clarify, are you saying that if you save teh mesh and you reload it the bug goes away?

if this is the case then soem where teh mesh topolgy is change, which shoud not be the case.
I will debug thsi to see wh athe bug is, pls afet I fix what is wrong? I will spend soem time dong soem adjustmen to teh decompsoition, because when I load it Max I see that in soem cases so of teh decompustion are using face that are already use.
this is not a bug bu lead to underied descompositions.

for now I will debug thsi and see wha is wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Wed Nov 21, 2012 11:57 am

Yes if i save and reload it works fine

I have tested the mesh conversion process and it works correct, So I tried the following:

Code: Select all
    NewtonMeshSaveOFF(pnMesh, 'mesh.fff');
    pnMesh := NewtonMeshLoadOFF(ge_NewtonWorld, 'mesh.fff');
    NewtonMeshSaveOFF(pnMesh, 'mesh_clean.fff');


I have compared the output and both are identical, so i'm guessing there is a problem with the way newton handles the mesh in NewtonMeshApproximateConvexDecomposition after it has been created via NewtonMeshAddFace etc

Also 1 other thing to point out, if I don't save the OFF file and go straight onto NewtonMeshApproximateConvexDecomposition, there is a second pause in the application, if i save as OFF then reload there is no pause, it is super fast....
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Wed Nov 21, 2012 12:16 pm

The first thing I need fo find out is why Save and Load OFF file is changing the mesh topology?
This should not happens.

can you clarify this?
Overhertz wrote:Also 1 other thing to point out, if I don't save the OFF file and go straight onto NewtonMeshApproximateConvexDecomposition, there is a second pause in the application, if i save as OFF then reload there is no pause, it is super fast....


does this mean that it take longer of you do no save to an OFF?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Wed Nov 21, 2012 12:31 pm

How do I see the wire frame output of teh collision mesh?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Wed Nov 21, 2012 12:38 pm

Julio Jerez wrote:does this mean that it take longer of you do no save to an OFF?


Yes. But not only takes longer but it has the bug.

Julio Jerez wrote:How do I see the wire frame output of teh collision mesh?


in the console write "debug on"

so open app, open console "`" write "debug on" -> enter, then "spawn ramp1.x 100 1 compound" -> enter

spawn is as follows: spawn model.x mass scale collisiontype, so you can scale the model down via spawn ramp1.x 100 0.05 compound
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Thu Nov 22, 2012 6:54 pm

any news? :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Fri Nov 23, 2012 11:20 am

I found a problem, that explain why when you you save and lod teh OFF it work, but when you use teh fiel for teh .x mesh is fail

when you lod the OFF teh engien creat teh adjacen for all the faces, the grapgf look like this
    cluster node: 1
    links: 2 12 20 3
    cluster node: 2
    links: 10 11 12 1
    cluster node: 3
    links: 1 21 4
    cluster node: 4
    links: 3 22 5
    cluster node: 5
    links: 4 23 6
    cluster node: 6
    links: 5 24 7
    cluster node: 7
    links: 6 25 8

each face is conveted for series of faces,

how ever teh .x mesh all face are disjoint the is th graphs

    cluster node: 1
    links: 2
    cluster node: 2
    links: 1
    cluster node: 3
    links:
    cluster node: 4
    links:
    cluster node: 5
    links:
    cluster node: 6
    links:
    cluster node: 7
    links:
    cluster node: 8
    links:
    cluster node: 9
    links:
    cluster node: 10
    links:
    cluster node: 11
    links: 22
    cluster node: 12
    links: 33
    cluster node: 13
    links:
    cluster node: 14
    links:
    cluster node: 15
    links:
    cluster node: 16
    links:


how the question is to find out why teh original mesh is no creationgh the prpper adjacency
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Fri Nov 23, 2012 11:26 am

could the problem be when I submit the faces to NewtonMeshAddFace, from my conversion function?
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Fri Nov 23, 2012 11:50 am

Yes I veryfied that soem how this mesh does no have adjacengy,. for some reason all tringle are disjointed
if I load in Max here is how it looks. I selced few face segement, if the faces were conecetd then teh entire mesh will be read.
project.png
project.png (35.28 KiB) Viewed 4044 times


can I see the funtion you use to mak eteh MeshEffect form the .x file?
did you forget to call void NewtonMeshEndFace(const NewtonMesh* const mesh) afte you pass all the faces?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Fri Nov 23, 2012 12:58 pm

Ok I found the bug.
you were passing each triangel as poinst that ccontaing only thre components: x, y, z
In newton 300 point has 4 components: x, y, x, w

because of that the value of w was uninizialed, and the code could not make the adjacenry list because is consided then different points.
I made a modification that is the stride in 3, then the points only have x, y, z and w is set to zero.
the w value in the newton mesh is used to defined layers.

that fixed the bug, however I still see that the decomposition is not as good as I was expectiong.
Later I will see why is that bacuse I god a perfect decompsution before.
update and see fi this works for you now.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Fri Nov 23, 2012 1:09 pm

Julio Jerez wrote:can I see the funtion you use to mak eteh MeshEffect form the .x file?
did you forget to call void NewtonMeshEndFace(const NewtonMesh* const mesh) afte you pass all the faces?


Code: Select all
//
// Converts ID3DXMesh to PNewtonMesh.
// dev. Colin Stewart
//
function D3DXMeshToNewtonMesh(const nWorld: PNewtonWorld; pMesh: ID3DXMesh): PNewtonMesh;
type
  PIndex2 = ^TIndex2;
  TIndex2 = array[0..0] of Word;
  PIndex4 = ^TIndex4;
  TIndex4 = array[0..0] of DWord;
var
  newtFace: array[0..2] of TD3DXVector3;
  positions: array of TD3DXVector3;
  faces: array of array[0..2] of DWord;

  pVertices: Pointer;
  vertStride: Word;
  meshOptions: DWord;

  Indices2: PIndex2;
  Indices4: PIndex4;
  i: Integer;
begin
  meshOptions := pMesh.GetOptions;

  SetLength(positions, pMesh.GetNumVertices);
  SetLength(faces, pMesh.GetNumFaces);

  vertStride := pMesh.GetNumBytesPerVertex;

  pMesh.LockVertexBuffer(D3DLOCK_READONLY, pVertices);
  for i := 0 to High(Positions) do
    Positions[i] := PD3DXVector3(Pointer(Cardinal(pVertices) + i * vertStride))^;
  pMesh.UnlockVertexBuffer;

  if MeshOptions and D3DXMESH_32BIT = D3DXMESH_32BIT then begin
    pMesh.LockIndexBuffer(D3DLOCK_READONLY, Pointer(Indices4));
    for i := 0 to High(Faces) do begin
      faces[i][0] := Indices4^[i * 3];
      faces[i][1] := Indices4^[i * 3 + 1];
      faces[i][2] := Indices4^[i * 3 + 2];
    end;
  end else begin
    pMesh.LockIndexBuffer(D3DLOCK_READONLY, Pointer(Indices2));
    for i := 0 to High(Faces) do begin
      faces[i][0] := Indices2^[i * 3];
      faces[i][1] := Indices2^[i * 3 + 1];
      faces[i][2] := Indices2^[i * 3 + 2];
    end;
  end;
  pMesh.UnlockIndexBuffer;

  Result :=  NewtonMeshCreate(nWorld);
  NewtonMeshBeginFace(Result); // start adding faces

  for i := 0 to High(Faces) do begin
    newtFace[0] := Positions[Faces[i][0]];
    newtFace[1] := Positions[Faces[i][1]];
    newtFace[2] := Positions[Faces[i][2]];

    NewtonMeshAddFace(Result, 3, PFloat(@newtFace[0]), SizeOf(single)*3, 0);
  end;

  NewtonMeshEndFace(Result);

  SetLength(positions, 0);
  SetLength(faces, 0);
end;


I just updated newton.dll but it still seems not to be correct, infact looks exactly the same.

EDIT: if i make the stride as 4 parts as you said, it seems to do quite a bit better, i just set the .w = 1, i see the issue with the scale is still a problem, so i tried to downscale and it works better, but still not very good for some reason.

Image
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Julio Jerez » Fri Nov 23, 2012 2:56 pm

Oh I did not build the libraries. It is good of you pass the proper vertex size

Sink Again I check in comipiled libraries now, and you can pass vetex of x, y, z

in the future I will change the Newton Mesh to have vertex Channels, righ now it has a flat vertex array, but that limite teh mesh flexibility

regard the scale, yes tyou are right there si a problem that I nee to work on, but I will do that later afte I finish teh player and the vehicle.
I will revamp the complete Newton Mesh, and finish soem funtions that are still pending.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateCompoundCollisionFromMesh not working correc

Postby Overhertz » Fri Nov 23, 2012 3:16 pm

Thanks, I'm looking forward to the vehicle system, how long approx? :) :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests