Moderators: Sascha Willems, walaber
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);
}
NewtonMeshGetFirstFace(NewtonMesh, VertexIndexs, VertexCount, Additional Stuff) : Handle;
NewtonMeshGetFirstNext(NewtonMesh, VertexIndexs, VertexCount, Additional Stuff) : Handle;
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);
…
Stucuk wrote:Is each NewtonMesh Material a face with NewtonMeshMaterialGetIndexStream giving you the index's to which stuff belongs to it?
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?
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);
Julio Jerez wrote:can you add the set of functions you would like to have for editing and I will fill then up.
int NewtonMeshMaterialGetFaceCount(const NewtonMesh *mesh, void* Handle, int materialId);
int NewtonMeshMaterialGetFaceIndexStream(const NewtonMesh *mesh, void* Handle, int materialId, int faceid, int* index);
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);
int GetIndex();
int GetFaceCount();
void EnumerateFaces (int* FacesList, int* MaterailList, int* IndexList)
facecount = GetFaceCount (Mesh);
indexCount = GetIndex (Mesh);
facecountPrt = alloc (facecount);
matrailPrt = alloc (facecount);
indexcountPtr = alloc (indexCount);
EnumerateFaces (facecountPrt, matrailPrt, indexcountPtr);
start = 0;
faceStartPrt = alloc (facecount);
for (i = 0; i < facecountPrt; i ++)
{
faceStartPrt[i] = start;
start += facecountPrt[i];
}
indexcount = facecountPrt[n];
Material = matrailPrt[n]
faceIndex = &indexcountPtr[faceStartPrt[n]];
Julio Jerez wrote:is that OK?
Julio Jerez wrote:I think that with the the Pawaaa of the bolleans, it can make a cool game editor.
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);
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.
Users browsing this forum: No registered users and 0 guests