本文整理汇总了C#中Body.CreateMeshShape方法的典型用法代码示例。如果您正苦于以下问题:C# Body.CreateMeshShape方法的具体用法?C# Body.CreateMeshShape怎么用?C# Body.CreateMeshShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body.CreateMeshShape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateGeometry
//.........这里部分代码省略.........
if (nStep < steps - 1)
{
for (int nSegment = 0; nSegment < shapeSegments; nSegment++)
{
indices[currentIndex++] = startStepVertexIndex + nSegment;
indices[currentIndex++] = startStepVertexIndex + nSegment + 1;
indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1;
indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1;
indices[currentIndex++] = startStepVertexIndex + nSegment + shapeSegments + 1;
indices[currentIndex++] = startStepVertexIndex + nSegment;
}
}
lastPosition = pos;
lastRot = rot;
}
if (currentVertex != vertexCount)
Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentVertex != vertexCount.");
if (currentIndex != indexCount)
Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentIndex != indexCount.");
}
if (vertices.Length != 0 && indices.Length != 0)
{
//create mesh
string meshName = MeshManager.Instance.GetUniqueName(
string.Format("__RenderableCurve_{0}_{1}", Name, uniqueMeshIdentifier));
uniqueMeshIdentifier++;
//string meshName = MeshManager.Instance.GetUniqueName( string.Format( "__RenderableCurve_{0}", Name ) );
mesh = MeshManager.Instance.CreateManual(meshName);
SubMesh subMesh = mesh.CreateSubMesh();
subMesh.UseSharedVertices = false;
//init vertexData
VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration;
declaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position);
declaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal);
declaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0);
declaration.AddElement(0, 32, VertexElementType.Float4, VertexElementSemantic.Tangent, 0);
fixed (Vertex* pVertices = vertices)
{
subMesh.VertexData = VertexData.CreateFromArray(declaration, (IntPtr)pVertices,
vertices.Length * Marshal.SizeOf(typeof(Vertex)));
}
subMesh.IndexData = IndexData.CreateFromArray(indices, 0, indices.Length, false);
//set material
subMesh.MaterialName = materialName;
//set mesh gabarites
Bounds bounds = Bounds.Cleared;
foreach (Vertex vertex in vertices)
bounds.Add(vertex.position);
mesh.SetBoundsAndRadius(bounds, bounds.GetRadius());
}
}
//create MeshObject, SceneNode
if (mesh != null)
{
meshObject = SceneManager.Instance.CreateMeshObject(mesh.Name);
if (meshObject != null)
{
meshObject.SetMaterialNameForAllSubObjects(materialName);
meshObject.CastShadows = true;
sceneNode = new SceneNode();
sceneNode.Attach(meshObject);
//apply offset
sceneNode.Position = Position;
MapObject.AssociateSceneNodeWithMapObject(sceneNode, this);
}
}
//create collision body
if (mesh != null && collision)
{
Vec3[] positions = new Vec3[vertices.Length];
for (int n = 0; n < vertices.Length; n++)
positions[n] = vertices[n].position;
string meshPhysicsMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry(positions, indices, null,
MeshShape.MeshTypes.TriangleMesh, 0, 0);
collisionBody = PhysicsWorld.Instance.CreateBody();
collisionBody.Static = true;
collisionBody._InternalUserData = this;
collisionBody.Position = Position;
MeshShape shape = collisionBody.CreateMeshShape();
shape.MeshName = meshPhysicsMeshName;
shape.MaterialName = CollisionMaterialName;
shape.ContactGroup = (int)ContactGroup.Collision;
//shape.VehicleDrivableSurface = collisionVehicleDrivableSurface;
collisionBody.PushedToWorld = true;
}
needUpdate = false;
}