A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Enclave » Tue May 14, 2013 2:41 pm
I am want to use functions NewtonMeshApproximateConvexDecomposition and NewtonCreateCompoundCollisionFromMesh for building the collision out from my mesh, as shown in the demo ConvexApproximation.cpp.
I am using the DirectX meshes, ID3DXmesh, i am load it from X file format.
But the Newton functions uses own mesh format, Newtonmesh.
So question is, a how to convert my Directx mesh to Newton mesh ?
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Julio Jerez » Tue May 14, 2013 5:27 pm
the easiest example is this:
..\applications\demosSandbox\sdkDemos\demos\UsingNewtonMeshTool.cpp
if you can iterate obe the D3D mesh you can either build and index list vertex list or you cna pass teh faces one at a time.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Enclave » Thu May 16, 2013 10:21 am
Thanks, Julio. I found a useful function here:
- 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 converted it to c++. Now I can create a collision of any mesh.)
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Enclave » Tue Mar 16, 2021 12:01 pm
Hi Julio!
Many years later I decided to continue my project, but there are so many changes in the last version of Newton (3.14) that the chances of success are almost zero.
Is there a way to make routine
D3DXMeshToNewtonMesh work? I need it, but I don't understand how to replace the missing
NewtonMeshAddFace function.
I've read this (
http://newtondynamics.com/forum/viewtopic.php?f=9&t=9290), but it didn't help.
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Julio Jerez » Tue Mar 16, 2021 12:41 pm
Since you are starting again why don't you use newton 4.
The newton mesh is easier to use.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Enclave » Tue Mar 16, 2021 1:18 pm
Is Newton 4.0 Better?
I downloaded it from github, but there are no project files, how can I compile it?
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Julio Jerez » Tue Mar 16, 2021 1:45 pm
it has some refinements and mistake fixed from previous experiences.
you download CMake and install it, the you open the CMake GUI and make a solution for visual studio.
It is not difficult.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Enclave » Wed Mar 17, 2021 9:23 am
Ok, I compiled all projects, Visual Studio 2015, no errors. And this is what we have.
- demos.jpg (179.35 KiB) Viewed 7888 times
What is it?
Earlier versions of Sandbox / Newton worked fine for me on the same system.
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Dave Gravel » Wed Mar 17, 2021 9:30 am
This look like a gl shader error.
Maybe you have a very old video card or old driver ?
If you don't find the problem maybe it can become a good idea to add gl debug callback to see what happen.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Enclave » Wed Mar 17, 2021 9:46 am
Dave Gravel wrote:This look like a gl shader error.
Maybe you have a very old video card or old driver ?
If you don't find the problem maybe it can become a good idea to add gl debug callback to see what happen.
Intel HD Graphics.
Games run normally, including 3D, not the newest of course. For example, Dungeon Siege with anisotropic filtering 16x.
add gl debug callback
Can you tell me how to do this?
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Dave Gravel » Wed Mar 17, 2021 10:00 am
If you have a old intel video card you surely need to set lower opengl version in the sdk project.
Try to see if your video card is compatible with opengl 3.2
Newton 4 sdk request opengl 3.2 at minimum.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Dave Gravel » Wed Mar 17, 2021 10:07 am
In file ndDemoEntityManager.cpp find ndDemoEntityManager::ndDemoEntityManager () around line 107
Under:
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
Add
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_NO_ERROR, GLFW_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
If it don't work you surely need a newer video card
One more thing try to compile the release version first.
Because the debug running very slow and the application can look like freeze with your video card and debug mode.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Enclave » Wed Mar 17, 2021 4:49 pm
Thanks, I checked the version. It's opengl 2.1 (core i5 520M).
But on netwon 3.14, the demo programs worked (but not all). I don't think there are significant differences in graphics, nevertheless newton 4 is primarily a physics engine.
I tried the code you suggested, but it doesn't work.
For Sandbox, I'll install visual studio on desktop and check there.
Now, first of all, I need to understand how to create a Newtonmesh from ID3DXmesh. I am using DirectX and its api to load the meshes, although this may be outdated at the moment.
-
Enclave
-
- Posts: 81
- Joined: Wed May 01, 2013 6:00 am
by Dave Gravel » Wed Mar 17, 2021 5:32 pm
In your screenshot opengl is working because I can see the skybox. The problem is because newton 4 using newer gl shader features for the render pass. GL 3.2 is request at minimum for run this shaders. Exemple for get some new gl features like instancing objects and bones animation shader.
When you have try my commands do you get exactly the same result or the screen becoming black ?
Maybe you can set a other version in the shader and maybe it can request little changes in the render parts to get it working.
If you add a gl debug callback it can let's you know what is the error if it coming from gl commands.
Currently your error look to come from the shader and in this case you need the shader debug infos to know what you need to change.
The shader look to partially work because you can see gray objects in middle of the screen.
You need the shader debug infos to know what variable is not working in the shader. Maybe you can take a look in the debug window console to see if you get a message about shader error.
About DXMesh
(1)If the mesh is dynamic you need to extract all vertices from your mesh and you fill a convexhull object with this data.
(2)With static mesh you need to extact the faces from the vertex with the indices as index. And you fill a dPolygonSoupBuilder object with this data. If i'm not wrong you need to split the indice by 3 to fill the data with 3 faces at time in a loop.
Edited:
I have badly explain about dynamic and static option.
The option (1) is for convex shape static or dynamic and the option (2) is for no convex mesh.
In general the option 2 is for static mesh.
The body part is done the same way that you use for the default newton geometry like box or sphere...
Last edited by
Dave Gravel on Thu Mar 18, 2021 3:36 am, edited 1 time in total.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Julio Jerez » Wed Mar 17, 2021 6:43 pm
Enclave wrote:Thanks, I checked the version. It's opengl 2.1 (core i5 520M).
isn't there a drive update that take it to gl 3.2
gl 3.2 is was relased more than 10 years ago. an intel icore 5 gpu is suppose to be dx11 so it should support gl 3.2
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 46 guests