NewtonCreateCompoundCollisionFromMesh not working correct?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonCreateCompoundCollisionFromMesh not working correct?

Postby Overhertz » Tue Nov 20, 2012 5:10 pm

OK, i've checked a couple of the newton samples and i'm trying to implement NewtonCreateCompoundCollisionFromMesh, however it is not going well.

Image

my code:

Code: Select all
    pnMesh := D3DXMeshToNewtonMesh(ge_NewtonWorld, Result.F_Mesh);

    approxMesh := NewtonMeshApproximateConvexDecomposition(pnMesh, 0.01, 0.2, 32, 100, nil);

    Result.NewtonCol :=  NewtonCreateCompoundCollisionFromMesh(ge_NewtonWorld, approxMesh, 0.001, 0, 0);
    Result.NewtonBody := NewtonCreateDynamicBody(ge_NewtonWorld, Result.NewtonCol, @Result.Position);

    NewtonMeshDestroy(pnMesh);
    NewtonMeshDestroy(approxMesh);

    //set body userdata as entity object.
    NewtonBodySetUserData(Result.NewtonBody, Result);

    NewtonBodySetMassProperties(Result.NewtonBody, mass, Result.NewtonCol);

    NewtonDestroyCollision(Result.NewtonCol);
    NewtonBodySetForceAndTorqueCallBack(Result.NewtonBody, @newtForceAndTorqueCallback);


any help please? :)
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 » Tue Nov 20, 2012 8:36 pm

can you do this:
NewtonMeshSaveOFF(pnMesh, "somefielName.fff");

and five me the ouput file to see what 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 » Tue Nov 20, 2012 9:21 pm

sure,

download from here

but I will go to bed now, good night, I will check back first thing tomorrow :)
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 9:20 am

Ok I load it, and I think you are exposing a problem with et decompsition tha is relatiev to scale.
you scale is really huge.

bascailly when I scale the model by 0.05 I get a perfect decomposition,
but if I do not then I get error, I will see what that is, and try to make it independed of the scale
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 10:14 am

Umm I do no knwo what are yo having worng, I get perfect decompsoition.
I did fine one bug by it should no affect the output.

whith this lien fo code:
Code: Select all
   GetWorkingFileName ("mesh.off", fileName);
   NewtonMesh* const mesh = NewtonMeshLoadOFF(world, fileName);

   NewtonMesh* const newtonMesh = NewtonMeshSimplify(mesh, 500, NULL);

   // create a convex approximation form the original mesh, 32 convex max and no more than 100 vertex convex hulls
   NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (newtonMesh, 0.01f, 0.2f, 32, 100, NULL);

   // create a compound collision by creation a convex hull of each segment of the source mesh
   NewtonCollision* const compound = NewtonCreateCompoundCollisionFromMesh (world, convexApproximation, 0.001f, 0, 0);

this is what I get, teh blue line are the outline of teh decomposition.
project.png
project.png (549.97 KiB) Viewed 4444 times


update to latest SDK, and try again, you should ge the same thing,
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 10:14 am

I have just tried to down-scale the model and still have same problem

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 » Wed Nov 21, 2012 10:21 am

If we are running teh same code, hwo it is that we get diffrent result?
I just try the newton_d.dll an dnetwon.dll the also produce teh same result.
are you compiling the dlls newton DLL?
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 10:26 am

No I used the dll from SVN, maybe it has been updated? I will re-download it and replace it to see if that helps.

EDIT: with latest "Revision 2853" still the same.
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 10:32 am

I just test all dll, vs2008 and vs2010 32 and 64 bit and teh all yiled teh same result.

I just check in all of then plus the sand demo decomposing just yor mesh,
plase try synk again, and run teh sandbox demo see if it generate the same mesh that should produces.
and use the DLL that I checked in in your project.
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 10:36 am

OK, i've just tried the sandbox demo app but it crashes on load, what OS are you running? Here i'm running XP Pro SP3

Meanwhile i will delete everything and re-sync then test again.

EDIT: ok i deleted all newton files and re-sync'd, upon running the sdk Demo sandbox:

Image

Re-Edit: Just tested the demo sandbox on Win 7 and it works, but not on XP
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 11:02 am

Oh so you gusy are using window XP,
maybe this is why I do not see the error that othe people are seeing.

I thonk I have an old laptop with windowXP professinal; I see if I can try that there
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 11:12 am

Oh, that laptop I intalled linux 32, but I have the win32 profetional dvd, I will intall it and see what is wrong.
I am guessing this is related to the openAL because it was warking before that.
This will take maybe a day to set everything up, because I have to set up every thing on that machine
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:22 am

OK, else i have tested my app with the model scaled on windows 7 and it still does the sub objects incorrect.... I have no idea what to try next :/
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 11:25 am

I do not know why this happens, can you post your executable so that I can run run the DLL 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:28 am

OK so what i have tried now is to save as an OFF file and then re-load it, which works

Code: Select all
    pnMesh := D3DXMeshToNewtonMesh(ge_NewtonWorld, Result.F_Mesh);

    NewtonMeshSaveOFF(pnMesh, 'mesh.fff');
    pnMesh := NewtonMeshLoadOFF(ge_NewtonWorld, 'mesh.fff');

    pnMesh := NewtonMeshSimplify(pnMesh, 500, nil);

    approxMesh := NewtonMeshApproximateConvexDecomposition(pnMesh, 0.01, 0.2, 64, 200, nil);

    Result.NewtonCol :=  NewtonCreateCompoundCollisionFromMesh(ge_NewtonWorld, approxMesh, 0.001, 0, 0);
    Result.NewtonBody := NewtonCreateDynamicBody(ge_NewtonWorld, Result.NewtonCol, @Result.Position);

    NewtonMeshDestroy(pnMesh);
    NewtonMeshDestroy(approxMesh);

    //set body userdata as entity object.
    NewtonBodySetUserData(Result.NewtonBody, Result);

    NewtonBodySetMassProperties(Result.NewtonBody, mass, Result.NewtonCol);

    NewtonDestroyCollision(Result.NewtonCol);
    NewtonBodySetForceAndTorqueCallBack(Result.NewtonBody, @newtForceAndTorqueCallback);


so now i will assume there is a problem with 1 of 2 things, my mesh converter is submitting the data to the newton mesh incorrectly and newton does not report a problem, when saved or loaded then newton corrects the model issue.

Edit: I have uploaded sample app: download here

just move into the open W A S D + Mouse, then open console "`" write "spawn ramp1.x 100 1 compound" press enter then write "debug on"

the D3DXMesh Converter:

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;
Last edited by Overhertz on Wed Nov 21, 2012 11:56 am, edited 2 times in total.
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron