dNewtonMesh::BeginPolygon

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

dNewtonMesh::BeginPolygon

Postby Slick » Sun Sep 02, 2018 9:13 am

I updated to the latest Newton. I use Ogre and to convert meshes one of the functions that I was using is:

Code: Select all
void dNewtonMesh::BeginPolygon()
{
   dAssert (0);
//   NewtonMeshBeginFace(m_mesh);
}


It now has been commented out and an assert put there.

How can I achieve this functionality?
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Sun Sep 02, 2018 12:43 pm

Should I use functions in the dgMeshEffect classes?

I wish the wiki was more updated. How do other people load models into Newton.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Julio Jerez » Sun Sep 02, 2018 12:49 pm

oh I see, the was a while ago, the newton mesh use to have a fat vertex but I changed to use channels
when I do that I usually comment out all the places where teh funtionality is used, but I forget to re enable that.
since making a mesh is some what more involve now I try to add re example but most likely will fail
here is hwo a mesh is buidl now from the demos.
The convert a mesh similar to an ogre mesh to a newton mesh.
you can see that the funtion is comment out there and replaced with new interface.

Code: Select all
NewtonMesh* DemoMesh::CreateNewtonMesh(NewtonWorld* const world, const dMatrix& meshMatrix)
{
   NewtonMesh* const mesh = NewtonMeshCreate(world);

   NewtonMeshBeginBuild (mesh);
   dMatrix rotation ((meshMatrix.Inverse4x4()).Transpose4X4());

   for (dListNode* node = GetFirst(); node; node = node->GetNext()) {
      DemoSubMesh& segment = node->GetInfo();
      for (int i = 0; i < segment.m_indexCount; i += 3) {
         NewtonMeshBeginFace(mesh);
         for (int j = 0; j < 3; j ++) {
            int index = segment.m_indexes[i + j];
            dVector p (meshMatrix.TransformVector(dVector (m_vertex[index * 3 + 0], m_vertex[index * 3 + 1], m_vertex[index * 3 + 2], 0.0f)));
            dVector n (rotation.RotateVector(dVector (m_normal[index * 3 + 0], m_normal[index * 3 + 1], m_normal[index * 3 + 2], 0.0f)));
            dAssert ((n.DotProduct3(n)) > 0.0f);
            n = n.Scale (1.0f / dSqrt (n.DotProduct3(n)));
            
            NewtonMeshAddPoint(mesh, p.m_x, p.m_y, p.m_z);
            NewtonMeshAddNormal(mesh, n.m_x, n.m_y, n.m_z);
            NewtonMeshAddMaterial(mesh, segment.m_textureHandle);
            NewtonMeshAddUV0(mesh, m_uv[index * 2 + 0], m_uv[index * 2 + 1]);
         }
         NewtonMeshEndFace(mesh);
//         NewtonMeshAddFace(mesh, 3, &point[0][0], sizeof (point) / 3, segment.m_textureHandle);
      }
   }

   NewtonMeshEndBuild(mesh);
   return mesh;
}




this simple interface seem simple but in fact is too infelaxible
Code: Select all
void dNewtonMesh::BeginPolygon()
{
   NewtonMeshBeginFace(m_mesh);
}

void dNewtonMesh::AddFace (int vertexCount, const dFloat* const vertex, int strideInBytes, int materialIndex)
{
//   NewtonMeshAddFace (m_mesh, vertexCount, vertex, strideInBytes, materialIndex);
   int stride = strideInBytes / sizeof (dFloat);
   for (int i = 0; i < vertexCount; i ++) {
      NewtonMeshAddPoint(m_mesh, vertex[i * stride + 0], vertex[i * stride + 1], vertex[i * stride + 2]);
      NewtonMeshAddMaterial(m_mesh, materialIndex);
   }
}
void dNewtonMesh::EndPolygon()
{
   NewtonMeshEndFace(m_mesh);
}


do you want me to add the more atimic support?
Code: Select all
   NewtonMeshAddPoint(mesh, p.m_x, p.m_y, p.m_z);
   NewtonMeshAddNormal(mesh, n.m_x, n.m_y, n.m_z);
   NewtonMeshAddMaterial(mesh, segment.m_textureHandle);
   NewtonMeshAddUV0(mesh, m_uv[index * 2 + 0], m_uv[index * 2 + 1]);


can you show me the funtion you are using teh dNetwonMesh so that I have a better idea hwo to make teh update?
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Sun Sep 02, 2018 1:04 pm

I'll take a look at your suggestions and get back to you. I am/was using OgreNewton but am trying to get closer to using Newton directly. However, I need to load meshes and the coordinate system is different so there will be a need for me to create a few functions to get a thin wrapper working.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Sun Sep 02, 2018 1:49 pm

Why are there normals and UV's? Is this so rendering for some demos is easier since it is in the newton mesh and people can get it there?

I am planning (I think) just to provide the mesh info to newton and the rendering to be handled by a mesh in the renderer (like Ogre) that has normals/UV's.

Maybe some more atomic functions like you mentioned would be good. I do think that adds flexibility for people. That way people can just provide geometry if they don't want UV/Material etc. I am not skilled enough to be sure but I do wonder how people using different 3d models can easily convert them into Newton meshes.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Julio Jerez » Sun Sep 02, 2018 2:15 pm

the newton mesh for many years only had two type of information. vertices which was the position of a point, and the points which was normal, uve, material, weight etc.
this was ok for a while, but as more functionality was added it was evident, the format is inadequate to support a wide range of features.

it will be ok for engines like Ogre that fetuses some of the information, but say for example you want to add some functionality to an existing mesh of some other engine, and the uv, normal are already computed, you just want say a new set of uv.
this will must likely alter existing information on the mesh.
but having each channel be independent, then it is possible to add extra info without changing the original data.
the newton mesh is a utility for mesh manipulation.

if you want I can add an example of how to use the
dMesh to make a new render mesh to the sandbox.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Sun Sep 02, 2018 3:17 pm

Ok great another sample is good. I am also going to try using the code you posted. The atomic functions are good too for people not looking for uv's etc
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Mon Sep 03, 2018 4:36 am

Ok I am looking at it more. To me it seems that it it would be good to add this or something similar:
Code: Select all
AddPoint(p.m_x, p.m_y, p.m_z);
AddNormal(n.m_x, n.m_y, n.m_z);
AddMaterial(segment.m_textureHandle);
AddUV0(m_uv[index * 2 + 0], m_uv[index * 2 + 1]);


Since AddFace no longer exists these seem to be the replacements.

Also, if I understand it correctly Newton has 2 syles of interfaces the calls like:
Code: Select all
NewtonMeshAddPoint(mesh, p.m_x, p.m_y, p.m_z);
and then more C++ like:
AddPoint(p.m_x, p.m_y, p.m_z);


Am I right that there is two styles? I am more used to the member function approach in C++.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Julio Jerez » Tue Sep 04, 2018 1:43 am

Yes you are right.

ok I now added some of those functionality to the dNetwonMesh, you can check out function:
Code: Select all
static void CreateSimpledBox_dNetwonMesh(DemoEntityManager* const scene, const dVector& origin, const dVector& scale, dFloat mass)


in demo: ../applications\demosSandbox\sdkDemos\demos\UsingNewtonMeshTool.cpp

I still need to add the rest of teh funtionality: UV, binormal, vertex color etc.
I will do it later, but you can see how eassy and flexible is to use the mesh with channels.
once you have a newton Mesh then you can do many operations with it.

I am glad I did this because this is what force some of teh cool demos to be commented out:
soft bodies and cell destruction, now I can re example them again afte all funtionality is added.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Tue Sep 04, 2018 2:15 am

Ok great I will start resyncing to see what has been added back so far. My other post about collisiontree is probably related I assume.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Wed Sep 05, 2018 2:30 am

I saw you made various commits. Is the functionality back in place so I can try and get it to work?
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Julio Jerez » Wed Sep 05, 2018 8:12 am

yes look at demo …/applications\demosSandbox\sdkDemos\demos\UsingNewtonMeshTool.cpp

there a function that build a dNewtonMesh using the atomic vertex attributes, the mesh is a cube with quads and triangles.

remember the newton Mesh is not a general polygon soup mesh is only support manifold meshes.
meaning every edge on the mesh can onle be shared by tow faces.

It will try to accommodate ill formed meshes, but if is cant it will simply drop the malformed meshes.

The large majory of meshes but no all, meet that condition.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Wed Sep 05, 2018 11:53 am

Ok thanks I will take a look.
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Slick » Wed Oct 17, 2018 1:38 pm

Does Newton use the normal channel from a mesh? I was wondering whether I really need to supply normal info?
Slick
 
Posts: 266
Joined: Sat Feb 07, 2004 7:24 pm
Location: Los Angeles

Re: dNewtonMesh::BeginPolygon

Postby Julio Jerez » Wed Oct 17, 2018 1:51 pm

the normal channel is used yes, if you loading a mesh with normal, you can populate it,
however there is a function to calculate normal they is fearly good. it does a much better job that smoothing groups found on many 3d packages.
you can just omit filling normal angle call calculate normal with some angle tolerance.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests