static void AddStaticMesh(DemoEntityManager* const scene) { char fileName[2048]; NewtonWorld* const world = scene->GetNewton(); GetWorkingFileName ("ramp.off", fileName); NewtonMesh* const ntMesh = NewtonMeshLoadOFF(world, fileName); dMatrix matrix (dGetIdentityMatrix()); DemoMesh* mesh = new DemoMesh(ntMesh); DemoEntity* const entity = new DemoEntity(matrix, NULL); entity->SetMesh(mesh, dGetIdentityMatrix()); mesh->Release(); scene->Append(entity); CreateLevelMeshBody (world, entity, true); NewtonMeshDestroy (ntMesh); }
static void CreateConvexAproximation (const char* const name, DemoEntityManager* const scene, const dVector& origin, int instaceCount, const char* const texture) { char fileName[2048]; dGetWorkingFileName (name, fileName); NewtonWorld* const world = scene->GetNewton(); dScene compoundTestMesh (world); compoundTestMesh.Deserialize(fileName); // freeze the scale and pivot on the model compoundTestMesh.FreezeScale(); // compoundTestMesh.FreezeGeometryPivot (); dMeshNodeInfo* meshInfo = NULL; dMatrix scale (dGetIdentityMatrix()); for (dScene::dTreeNode* node = compoundTestMesh.GetFirstNode (); node; node = compoundTestMesh.GetNextNode (node)) { dNodeInfo* info = compoundTestMesh.GetInfoFromNode(node); if (info->GetTypeId() == dMeshNodeInfo::GetRttiType()) { for (void* link = compoundTestMesh.GetFirstParentLink(node); link; link = compoundTestMesh.GetNextParentLink (node, link)) { dScene::dTreeNode* const node = compoundTestMesh.GetNodeFromLink(link); dNodeInfo* const info = compoundTestMesh.GetInfoFromNode(node); if (info->GetTypeId() == dSceneNodeInfo::GetRttiType()) { scale = ((dSceneNodeInfo*)info)->GetGeometryTransform(); break; } } meshInfo = (dMeshNodeInfo*) info; break; } } NewtonMeshApplyTransform(meshInfo->GetMesh(), &scale[0][0]); dAssert (meshInfo); dAssert (meshInfo->GetMesh()); #if 1 NewtonMesh* const mesh = meshInfo->GetMesh(); #else dGetWorkingFileName ("mesh.off", fileName); NewtonMesh* const mesh = NewtonMeshLoadOFF(world, fileName); // dMatrix scale (GetIdentityMatrix()); // //dFloat scaleMag = 0.05f; // dFloat scaleMag = 1.0f; // scale[0][0] = scaleMag; // scale[1][1] = scaleMag; // scale[2][2] = scaleMag; // NewtonMesApplyTransform (mesh, &scale[0][0]); #endif //NewtonMesh* const newtonMesh = NewtonMeshSimplify(mesh, 500, ReportProgress); // create a convex approximation form the original mesh, 32 convex max and no more than 100 vertex convex hulls // NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (mesh, 0.01f, 0.2f, 32, 100, ReportProgress, scene); NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (mesh, 0.01f, 0.2f, 256, 100, ReportProgress, scene); // NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (mesh, 0.00001f, 0.0f, 256, 100, ReportProgress, scene); // create a compound collision by creation a convex hull of each segment of the source mesh NewtonCollision* const compound = NewtonCreateCompoundCollisionFromMesh (world, convexApproximation, 0.001f, 0, 0); // test collision mode // NewtonCollisionSetCollisonMode(compound, 0); // make a visual Mesh int tex = LoadTexture(texture); dMatrix aligmentUV(dGetIdentityMatrix()); NewtonMeshApplyBoxMapping(mesh, tex, tex, tex, &aligmentUV[0][0]); DemoMesh* const visualMesh = new DemoMesh (mesh); dMatrix matrix (dGetIdentityMatrix()); matrix.m_posit = origin; for (int ix = 0; ix < instaceCount; ix ++) { for (int iz = 0; iz < instaceCount; iz ++) { dFloat y = origin.m_y; dFloat x = origin.m_x + (ix - instaceCount/2) * 10.0f; dFloat z = origin.m_z + (iz - instaceCount/2) * 10.0f; matrix.m_posit = FindFloor (world, dVector (x, y + 10.0f, z, 0.0f), 20.0f); ; matrix.m_posit.m_y += 2.0f; CreateSimpleSolid (scene, visualMesh, 10.0f, matrix, compound, 0); } } visualMesh->Release(); NewtonDestroyCollision(compound); NewtonMeshDestroy (convexApproximation); }