void LoadTetrahedraCube(DemoEntityManager* const scene, int materialID) { dFloat mass = 5.0f; NewtonWorld* const world = scene->GetNewton(); char name[2048]; dGetWorkingFileName ("box.tet", name); NewtonMesh* const tetraCube = NewtonMeshLoadTetrahedraMesh(scene->GetNewton(), name); dMatrix aligmentUV(dGetIdentityMatrix()); int material = LoadTexture("smilli.tga"); NewtonMeshApplyBoxMapping(tetraCube, material, material, material, &aligmentUV[0][0]); NewtonMeshCalculateVertexNormals(tetraCube, 60.0f * dDegreeToRad); // make a deformable collision mesh NewtonCollision* const deformableCollision = NewtonCreateDeformableSolid(world, tetraCube, materialID); //create a rigid body with a deformable mesh m_body = CreateRigidBody(scene, mass, deformableCollision); // create the soft body mesh //m_mesh = new TetrahedraSoftMesh(tetraCube, m_body); DemoMesh* const mesh = new TetrahedraSoftMesh(scene, tetraCube, m_body); SetMesh(mesh, dGetIdentityMatrix()); // do not forget to destroy this objects, else you get bad memory leaks. mesh->Release (); NewtonDestroyCollision(deformableCollision); NewtonMeshDestroy(tetraCube); }
void BuildRegularTetrahedra (DemoEntityManager* const scene, int materialID) { dFloat mass = 5.0f; NewtonWorld* const world = scene->GetNewton(); dVector tetra[] = { dVector(-1.0f, 0.0f, -0.71f, 0.0f), dVector(1.0f, 0.0f, -0.71f, 0.0f), dVector(0.0f, -1.0f, 0.71f, 0.0f), dVector(0.0f, 1.0f, 0.71f, 0.0f) }; NewtonMesh* const tetrahedra = NewtonMeshCreate(scene->GetNewton()); NewtonMeshBeginBuild(tetrahedra); AddTetra (tetrahedra, 0, 1, 2, 3, tetra, 0); NewtonMeshEndBuild(tetrahedra); dMatrix aligmentUV(dGetIdentityMatrix()); int material = LoadTexture("smilli.tga"); NewtonMeshApplyBoxMapping (tetrahedra, material, material, material, &aligmentUV[0][0]); NewtonMeshCalculateVertexNormals (tetrahedra, 60.0f * dDegreeToRad); // make a deformable collision mesh NewtonCollision* const deformableCollision = NewtonCreateDeformableSolid(world, tetrahedra, materialID); //create a rigid body with a deformable mesh m_body = CreateRigidBody (scene, mass, deformableCollision); // create the soft body mesh DemoMesh* const mesh = new TetrahedraSoftMesh(scene, tetrahedra, m_body); SetMesh(mesh, dGetIdentityMatrix()); // do not forget to destroy this objects, else you get bad memory leaks. mesh->Release (); NewtonMeshDestroy (tetrahedra); NewtonDestroyCollision(deformableCollision); }
void dMeshNodeInfo::SmoothNormals (dFloat angleInRadiants) { NewtonMeshCalculateVertexNormals(m_mesh, angleInRadiants); }
DemoMesh::DemoMesh(const char* const name, const NewtonCollision* const collision, const char* const texture0, const char* const texture1, const char* const texture2, dFloat opacity, const dMatrix& uvMatrix) :DemoMeshInterface() ,dList<DemoSubMesh>() ,m_uv(NULL) ,m_vertex(NULL) ,m_normal(NULL) ,m_optimizedOpaqueDiplayList(0) ,m_optimizedTransparentDiplayList(0) { // create a helper mesh from the collision collision NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision); // apply the vertex normals NewtonMeshCalculateVertexNormals(mesh, 30.0f * dDegreeToRad); dMatrix aligmentUV(uvMatrix); // NewtonCollisionGetMatrix(collision, &aligmentUV[0][0]); aligmentUV = aligmentUV.Inverse(); // apply uv projections NewtonCollisionInfoRecord info; NewtonCollisionGetInfo (collision, &info); switch (info.m_collisionType) { case SERIALIZE_ID_SPHERE: { NewtonMeshApplySphericalMapping(mesh, LoadTexture (texture0), &aligmentUV[0][0]); break; } case SERIALIZE_ID_CONE: case SERIALIZE_ID_CAPSULE: case SERIALIZE_ID_CYLINDER: case SERIALIZE_ID_CHAMFERCYLINDER: { //NewtonMeshApplySphericalMapping(mesh, LoadTexture(texture0)); NewtonMeshApplyCylindricalMapping(mesh, LoadTexture(texture0), LoadTexture(texture1), &aligmentUV[0][0]); break; } default: { int tex0 = LoadTexture(texture0); int tex1 = LoadTexture(texture1); int tex2 = LoadTexture(texture2); NewtonMeshApplyBoxMapping(mesh, tex0, tex1, tex2, &aligmentUV[0][0]); break; } } // extract vertex data from the newton mesh int vertexCount = NewtonMeshGetPointCount (mesh); AllocVertexData(vertexCount); NewtonMeshGetVertexChannel(mesh, 3 * sizeof (dFloat), (dFloat*)m_vertex); NewtonMeshGetNormalChannel(mesh, 3 * sizeof (dFloat), (dFloat*)m_normal); NewtonMeshGetUV0Channel(mesh, 2 * sizeof (dFloat), (dFloat*)m_uv); // extract the materials index array for mesh void* const geometryHandle = NewtonMeshBeginHandle (mesh); for (int handle = NewtonMeshFirstMaterial (mesh, geometryHandle); handle != -1; handle = NewtonMeshNextMaterial (mesh, geometryHandle, handle)) { int material = NewtonMeshMaterialGetMaterial (mesh, geometryHandle, handle); int indexCount = NewtonMeshMaterialGetIndexCount (mesh, geometryHandle, handle); DemoSubMesh* const segment = AddSubMesh(); segment->m_textureHandle = (GLuint)material; segment->SetOpacity(opacity); segment->AllocIndexData (indexCount); NewtonMeshMaterialGetIndexStream (mesh, geometryHandle, handle, (int*)segment->m_indexes); } NewtonMeshEndHandle (mesh, geometryHandle); // destroy helper mesh NewtonMeshDestroy(mesh); // optimize this mesh for hardware buffers if possible OptimizeForRender (); }