NewtonMesh

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonMesh

Postby Stucuk » Sun Nov 15, 2009 1:16 pm

I assume its not possible to get the faces back from a NewtonMesh? Id like to try the NewtonMeshClip but if i can't get a list of faces back then i can't recreate the object. (Vertex list is useless to me. Need to be able to know which vertex's go with which faces)
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Sun Nov 15, 2009 2:16 pm

yes you can get the face back as vertex liste index list.
there are many exmples in the SDK, I think this is one of the simplest

Code: Select all
void OGLMesh::BuildFromMesh (const NewtonMesh* mesh)
{
   int vertexCount;

   // extract vertex data  from the newton mesh      
   vertexCount = NewtonMeshGetVertexCount (mesh);
   AllocVertexData(vertexCount);
   NewtonMeshGetVertexStreams (mesh,
      3 * sizeof (dFloat), (dFloat*) m_vertex,
      3 * sizeof (dFloat), (dFloat*) m_normal,
      2 * sizeof (dFloat), (dFloat*) m_uv);

   // extract the materials index array for mesh
   void* geometryHandle;
   geometryHandle = NewtonMeshBeginHandle (mesh);
   for (int handle = NewtonMeshFirstMaterial (mesh, geometryHandle); handle != -1; handle = NewtonMeshNextMaterial (mesh, geometryHandle, handle)) {

      int material;
      int indexCount;
      dSubMesh* segment;

      material = NewtonMeshMaterialGetMaterial (mesh, geometryHandle, handle);
      indexCount = NewtonMeshMaterialGetIndexCount (mesh, geometryHandle, handle);

      segment = AddSubMesh();
      segment->m_textureHandle = (GLuint)material;

      segment->AllocIndexData (indexCount);
//      NewtonMeshMaterialGetIndexStreamShort (mesh, geometryHandle, handle, (short int*)segment->m_indexes);
      NewtonMeshMaterialGetIndexStream (mesh, geometryHandle, handle, (int*)segment->m_indexes);
   }
   NewtonMeshEndHandle (mesh, geometryHandle);
}


is that sufficient?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Sun Nov 15, 2009 4:54 pm

Is each NewtonMesh Material a face with NewtonMeshMaterialGetIndexStream giving you the index's to which stuff belongs to it?

Basicaly i just need a way to get a list of what vertex's go with what faces.

EDIT: Assuming the NewtonMesh Material is just a group of all vertex's that share the same texture then something like the following would be great:

Code: Select all
NewtonMeshGetFirstFace(NewtonMesh, VertexIndexs, VertexCount, Additional Stuff) : Handle;
NewtonMeshGetFirstNext(NewtonMesh, VertexIndexs, VertexCount, Additional Stuff) : Handle;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Sun Nov 15, 2009 8:02 pm

Those functions gives you all the information you need about the faces of a mean

Code: Select all
geometryHandle = NewtonMeshBeginHandle (mesh);
for (int handle = NewtonMeshFirstMaterial (mesh, geometryHandle); handle != -1; handle = NewtonMeshNextMaterial (mesh, geometryHandle, handle)) {

material = NewtonMeshMaterialGetMaterial (mesh, geometryHandle, handle);
indexCount = NewtonMeshMaterialGetIndexCount (mesh, geometryHandle, handle);
NewtonMeshMaterialGetIndexStream (mesh, geometryHandle, handle, (int*)segment->m_indexes);

Materaial in the material ID,
indexCount is the number of indices of the faces of the material

the index count is a multiple of three, because each face has tree indices

The indices point to a global vertex array for the entire Newton Mesh

The last function get copy the indices into a pointer the you need to reallocated.
The loop is an iteration that goes over each Material in the mesh

You get the vertex arrays wit this functions

vertexCount = NewtonMeshGetVertexCount (mesh);
NewtonMeshGetVertexStreams (mesh,
3 * sizeof (dFloat), (dFloat*) m_vertex,
3 * sizeof (dFloat), (dFloat*) m_normal,
2 * sizeof (dFloat), (dFloat*) m_uv);



Stucuk wrote:Is each NewtonMesh Material a face with NewtonMeshMaterialGetIndexStream giving you the index's to which stuff belongs to it?

Yes this is a functing like
NewtonMeshGetFirstFace(NewtonMesh, VertexIndexs, VertexCount, Additional Stuff) : Handle;

with the exception that you get all the faces assigned to the Handle
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Mon Nov 16, 2009 12:07 am

If its breaking up all faces into Triangles even when they don't "need" to be, then it unfortunately isn't a viable option for what id need it for.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Mon Nov 16, 2009 10:24 am

It is made of faces, but it is providing then a a triangulated mesh.
I though this is what is need it for rendering

what are you using it for?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Mon Nov 16, 2009 11:05 am

Julio Jerez wrote:It is made of faces, but it is providing then a a triangulated mesh.
I though this is what is need it for rendering

what are you using it for?


Id like to use it for a Map Editor. For a Map Editor Triangulation makes the faces too complex(Instead of the user dealing with just 1 face, they then have to apply anything they would have done with 1 face, now to two faces or more).
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Tue Nov 17, 2009 8:22 am

The mesh dial with polygon intenally already,
but they are no expoiose I see yo uneed a more flexible inteface for editing.
I agree let us do this

this is the list of all the functions in the Mesh interface,

Code: Select all
   NEWTON_API NewtonMesh* NewtonMeshCreate();
   NEWTON_API NewtonMesh* NewtonMeshCreateFromCollision(const NewtonCollision* collision);
   NEWTON_API NewtonMesh* NewtonMeshCreatePlane (const dFloat* locationMatrix, dFloat witdth, dFloat breadth, int material, const dFloat* textureMatrix);
   
   NEWTON_API void NewtonMeshDestroy(const NewtonMesh*mesh);

   NEWTON_API void NewtonMeshCalculateOOBB(const NewtonMesh* mesh, dFloat* matrix, dFloat* x, dFloat* y, dFloat* z);

   NEWTON_API void NewtonMeshCalculateVertexNormals(const NewtonMesh* mesh, dFloat angleInRadians);
   NEWTON_API void NewtonMeshApplySphericalMapping(const NewtonMesh* mesh, int material);
   NEWTON_API void NewtonMeshApplyBoxMapping(const NewtonMesh* mesh, int front, int side, int top);
   NEWTON_API void NewtonMeshApplyCylindricalMapping(const NewtonMesh* mesh, int cylinderMaterial, int capMaterial);
   
   NEWTON_API int NewtonMeshIsOpenMesh (const NewtonMesh* mesh);
   NEWTON_API void NewtonMeshPolygonize (const NewtonMesh* mesh);
   NEWTON_API void NewtonMeshTriangulate (const NewtonMesh* mesh);
   NEWTON_API NewtonMesh* NewtonMeshUnion (const NewtonMesh* mesh, const NewtonMesh* clipper, const dFloat* clipperMatrix);
   NEWTON_API NewtonMesh* NewtonMeshDifference (const NewtonMesh* mesh, const NewtonMesh* clipper, const dFloat* clipperMatrix);
   NEWTON_API NewtonMesh* NewtonMeshIntersection (const NewtonMesh* mesh, const NewtonMesh* clipper, const dFloat* clipperMatrix);
   NEWTON_API void NewtonMeshClip (const NewtonMesh* mesh, const NewtonMesh* clipper, const dFloat* clipperMatrix, NewtonMesh** topMesh, NewtonMesh** bottomMesh);

   NEWTON_API void NewtonMeshBeginFace(const NewtonMesh *mesh);
   NEWTON_API void NewtonMeshAddFace(const NewtonMesh *mesh, int vertexCount, const dFloat* vertex, int strideInBytes, int materialIndex);
   NEWTON_API void NewtonMeshEndFace(const NewtonMesh *mesh);

   NEWTON_API int NewtonMeshGetVertexCount (const NewtonMesh *mesh);
   NEWTON_API void NewtonMeshGetVertexStreams (const NewtonMesh *mesh,
                                    int vertexStrideInByte, dFloat* vertex,
                                    int normalStrideInByte, dFloat* normal,
                                    int uvStrideInByte, dFloat* uv);
   NEWTON_API void NewtonMeshGetIndirectVertexStreams(const NewtonMesh *mesh,
                                          int vertexStrideInByte, dFloat* vertex, int* vertexIndices, int* vertexCount,
                                          int normalStrideInByte, dFloat* normal, int* normalIndices, int* normalCount,
                                          int uvStrideInByte, dFloat* uv, int* uvIndices, int* uvCount);
   NEWTON_API void* NewtonMeshBeginHandle (const NewtonMesh *mesh);
   NEWTON_API void NewtonMeshEndHandle (const NewtonMesh *mesh, void* Handle);
   NEWTON_API int NewtonMeshFirstMaterial (const NewtonMesh *mesh, void* Handle);
   NEWTON_API int NewtonMeshNextMaterial (const NewtonMesh *mesh, void* Handle, int materialId);
   NEWTON_API int NewtonMeshMaterialGetMaterial (const NewtonMesh *mesh, void* Handle, int materialId);
   NEWTON_API int NewtonMeshMaterialGetIndexCount (const NewtonMesh *mesh, void* Handle, int materialId);
   NEWTON_API void NewtonMeshMaterialGetIndexStream (const NewtonMesh *mesh, void* Handle, int materialId, int* index);
   NEWTON_API void NewtonMeshMaterialGetIndexStreamShort (const NewtonMesh *mesh, void* Handle, int materialId, short int* index);

   NEWTON_API NewtonMesh* NewtonMeshCreateFirstSingleSegment (const NewtonMesh *mesh);
   NEWTON_API NewtonMesh* NewtonMeshCreateNextSingleSegment (const NewtonMesh *mesh, const NewtonMesh *segment);



can you add the set of functions you would like to have for editing and I will fill then up.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Tue Nov 17, 2009 9:12 am

Julio Jerez wrote:can you add the set of functions you would like to have for editing and I will fill then up.


Something like the following would be good(But whatever is simpler for you to implement would be best):

Code: Select all
int NewtonMeshMaterialGetFaceCount(const NewtonMesh *mesh, void* Handle, int materialId);
int NewtonMeshMaterialGetFaceIndexStream(const NewtonMesh *mesh, void* Handle, int materialId, int faceid, int* index); 


NewtonMeshMaterialGetFaceCount would return amount of faces the material has. NewtonMeshMaterialGetFaceIndexStream would be the same as NewtonMeshMaterialGetIndexStream except it returns only the index's to faceid's face. NewtonMeshMaterialGetFaceIndexStream's return value would be the amount of index's that the index pointer is holding.

Usage:
Code: Select all
geometryHandle = NewtonMeshBeginHandle (mesh);
   for (int handle = NewtonMeshFirstMaterial (mesh, geometryHandle); handle != -1; handle = NewtonMeshNextMaterial (mesh, geometryHandle, handle)) {

      int material;
      int faceCount;
      int indexcount;

      material = NewtonMeshMaterialGetMaterial (mesh, geometryHandle, handle);
      faceCount = NewtonMeshMaterialGetFaceCount (mesh, geometryHandle, handle);

      for (int faceid = 0; faceid != faceCount; faceid++)
      {
       indexcount = NewtonMeshMaterialGetFaceIndexStream (mesh, geometryHandle, handle, faceid,(int*) indexs);
      }
   }
   NewtonMeshEndHandle (mesh, geometryHandle);


Note: Since i don't normally do C++ there is proberly errors in the above code.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Tue Nov 17, 2009 9:33 am

how about a funtion simuilar to teh one I use fo rteh user collision.

something like enumerate faces.

Code: Select all
int GetIndex();
int GetFaceCount();
void EnumerateFaces (int* FacesList, int* MaterailList, int* IndexList)


you use it like this

Code: Select all
facecount = GetFaceCount (Mesh);
indexCount = GetIndex (Mesh);

facecountPrt = alloc (facecount);
matrailPrt = alloc (facecount);
indexcountPtr = alloc (indexCount);

EnumerateFaces (facecountPrt, matrailPrt, indexcountPtr);


then say you want to get teh location of each face you can do this

Code: Select all
start = 0;
faceStartPrt = alloc (facecount);
for (i = 0; i < facecountPrt; i ++)
{
    faceStartPrt[i] = start;
    start += facecountPrt[i];
}



then face N is given by
Code: Select all
indexcount = facecountPrt[n];
Material = matrailPrt[n]
faceIndex = &indexcountPtr[faceStartPrt[n]]; 



teh funtion fo rteh vertex is teh same, and the indexce point the teh vartea array
you can edit the vetices by changing UV, of normal, even vertex position

then after you edit the array you just destroy the mesh and make a new one with the new edited set of indices, materail and points.

The easiest thing is a Matereal editor were you point a click a face and you chage teh materails, and or editr the UV in teh vertex array.
If the UV are chared you can add an unwrap function where you display the polygon by the UV values, say two faces shared the same UV and you wnat to edit just one face.
can detach that face by addin a new set of point wi teh same vertex position and normal to teh vertex array but wi teh teh new UV.
then you change the indices of that face in the index array.
now you have a new the same face with the same position and normals but with new UVs.

then you just replace the old mesh with a new rebuild one. Similarlly you can do weld UV or and other stuff.
there is a function to convert to triangles and to polygon at will.

I think that with the the Pawaaa of the bolleans, it can make a cool game editor.

is that OK?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Tue Nov 17, 2009 12:14 pm

Julio Jerez wrote:is that OK?

That should be fine.

Julio Jerez wrote:I think that with the the Pawaaa of the bolleans, it can make a cool game editor.

Booleans can create good results you can't get without them.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Tue Nov 17, 2009 12:27 pm

Alright them I will add those functions tonight.
It will be coll to se eteh mesh use in some editor capacity.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Julio Jerez » Wed Nov 18, 2009 10:47 am

Ok I added the interfave now

Code: Select all
   NEWTON_API int NewtonMeshGetTotalFaceCount (const NewtonMesh *mesh);
   NEWTON_API int NewtonMeshGetTotalIndexCount (const NewtonMesh *mesh);
   NEWTON_API void NewtonMeshGetFaces (const NewtonMesh *mesh, int* const faceIndexCount, int* const faceMaterial, int* const faceIndices);


you use like this
Code: Select all
   int faceCount;
   int indexCount;
   faceCount = NewtonMeshGetTotalFaceCount (mesh);
   indexCount = NewtonMeshGetTotalIndexCount (mesh);

   int* faceIndexCount = new int[faceCount];
   int* faceMaterial = new int[faceCount];
   int* faceIndexArray = new int[indexCount];

   NewtonMeshGetFaces (mesh, faceIndexCount, faceMaterial, faceIndexArray);

   int* faceStart = new int[faceCount];
   int start = 0;
   for (int i = 0; i < faceCount; i ++)
   {
      faceStart[i] = start;
      start += faceIndexCount[i];
   }

   // now you are ready to use all the faces
   // faceIndexCount[0] number of indices of face 0
   // faceMaterial[0] matrail of face 0
   // faceIndexArray[faceStart[0]] start index of face 0

   // faceIndexCount[1] number of indices of face 1
   // faceMaterial[1] matrail of face 1
   // faceIndexArray[faceStart[1]] start index of face 1

   // ...


   // do not forget to delete teh arrays.


I still need to complete few thong in the destruction but I can I can send you a test version send me PM,
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Wed Nov 18, 2009 12:39 pm

:) . I forgot to ask this before, but can the MaterialID for the NewtonMeshAddFace be used as if its a unique id? Basicaly wondering if its possible when i get the data back after the Boolean operation if i can then work out which faces existed before the boolean and apply there texture information to the faces that are returned. Since im making a map editor the textures UV are stored as Scale, Rotation, Position as well as the basic 0-1 UV coords. Editor only calculates the final UV values when its rendering.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Wed Nov 18, 2009 1:18 pm

you can use material ID as unique identifore, but I do not think it is nessesary.
The bolleans calcualet UV correctly, so if you apply a bollean and you calculate uv proceduarly, then the caculate UV value after the bollean should be identical to the intepolated value from the bollean.

hpwvene if you start usn teh Newton Mesh as buidling blocan you will see that you cna just just apply teh UV to teh mesh and use as it, no longe you nee to apply textures proceduratly.
You only apply to UV to teh face when you crate the solid and from there all operations will preserve the UV intepolated UV accorditly to the operation.

basically you tread Netwon Mesh as true solid with objects with materail, all editing operations preserve material and normal properties.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
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 1 guest