예제 #1
0
        private BulletShape CreatePhysicalMesh(string objName, ulong newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
        {
            IMesh    meshData = null;
            IntPtr   meshPtr;
            MeshDesc meshDesc;

            if (Meshes.TryGetValue(newMeshKey, out meshDesc))
            {
                // If the mesh has already been built just use it.
                meshPtr = meshDesc.ptr;
            }
            else
            {
                // Pass false for physicalness as this creates some sort of bounding box which we don't need
                meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, false);

                int[] indices = meshData.getIndexListAsInt();
                List <OMV.Vector3> vertices = meshData.getVertexList();

                float[] verticesAsFloats = new float[vertices.Count * 3];
                int     vi = 0;
                foreach (OMV.Vector3 vv in vertices)
                {
                    verticesAsFloats[vi++] = vv.X;
                    verticesAsFloats[vi++] = vv.Y;
                    verticesAsFloats[vi++] = vv.Z;
                }

                // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
                //                  LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count);

                meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr,
                                                        indices.GetLength(0), indices, vertices.Count, verticesAsFloats);
            }
            BulletShape newShape = new BulletShape(meshPtr, ShapeData.PhysicsShapeType.SHAPE_MESH);

            newShape.shapeKey = newMeshKey;

            return(newShape);
        }