void BuildTetraHedraCube(DemoEntityManager* const scene, int materialID) { dFloat mass = 5.0f; NewtonWorld* const world = scene->GetNewton(); NewtonMesh* const tetraCube = NewtonMeshCreate(scene->GetNewton()); NewtonMeshBeginBuild(tetraCube); BuildTetraSolidBlock(tetraCube, 2, 2, 15, 0.5f, 0.5f, 0.5f); NewtonMeshEndBuild(tetraCube); 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 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); }
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; }
NewtonMesh* CreateCollisionTreeDoubleFaces (NewtonWorld* world, NewtonCollision* optimizedDoubelFacesTree) { NewtonMesh* mesh = NewtonMeshCreate(world); dMatrix matrix (dGetIdentityMatrix()); NewtonMeshBeginBuild(mesh); NewtonCollisionForEachPolygonDo (optimizedDoubelFacesTree, &matrix[0][0], ExtrudeFaces, mesh); NewtonMeshEndBuild(mesh); return mesh; }
void dMeshNodeInfo::BeginBuild () { NewtonMeshBeginBuild(m_mesh); }