public VertexBuffer GetVertexBuffer(IMeshPart meshPart) { var e = getEntry(meshPart); if (e.VertexBuffer == null) { var geomData = meshPart.GetGeometryData(); var positions = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Position); var normals = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Normal); var texcoords = geomData.GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord); // This might not work when no texcoords var vertices = new TangentVertex[positions.Length]; for (int j = 0; j < vertices.Length; j++) { vertices[j].pos = positions[j]; vertices[j].normal = normals[j]; if (texcoords != null) { vertices[j].uv = texcoords[j]; } //TODO: tangent } var vb = new VertexBuffer(game.GraphicsDevice, typeof(TangentVertex), vertices.Length, BufferUsage.None); vb.SetData(vertices); e.VertexBuffer = vb; } return(e.VertexBuffer); }
private void addPartToPart(IMeshPart source, IMeshPart dest, Matrix sourceTransform) { var sPositions = source.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position); var sNormals = source.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Normal); var sTexcoords = source.GetGeometryData().GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord); var dPositions = dest.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position); if (dPositions == null) { dPositions = new Vector3[0]; } var dNormals = dest.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Normal); if (dNormals == null) { dNormals = new Vector3[0]; } var dTexcoords = dest.GetGeometryData().GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord); if (dTexcoords == null) { dTexcoords = new Vector2[0]; } var nPositions = new Vector3[sPositions.Length + dPositions.Length]; var nNormals = new Vector3[sNormals.Length + dNormals.Length]; var nTexcoords = new Vector2[sTexcoords.Length + dTexcoords.Length]; dPositions.CopyTo(nPositions, 0); dNormals.CopyTo(nNormals, 0); dTexcoords.CopyTo(nTexcoords, 0); Vector3.Transform(sPositions, 0, ref sourceTransform, nPositions, dPositions.Length, sPositions.Length); Vector3.TransformNormal(sNormals, 0, ref sourceTransform, nNormals, dNormals.Length, sNormals.Length); sTexcoords.CopyTo(nTexcoords, dTexcoords.Length); dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Position, nPositions); dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Normal, nNormals); dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Texcoord, nTexcoords); }
public IndexBuffer GetIndexBuffer(IMeshPart meshPart) { var e = getEntry(meshPart); if (e.IndexBuffer == null) { var geomData = meshPart.GetGeometryData(); var positions = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Position); var indices = new int[positions.Length]; for (int j = 0; j < indices.Length; j++) { indices[j] = j; } var ib = new IndexBuffer(game.GraphicsDevice, typeof(int), indices.Length, BufferUsage.None); ib.SetData(indices); e.IndexBuffer = ib; } return(e.IndexBuffer); }
public static BoundingSphere CalculateBoundingSphere(IMeshPart mesh) { var positions = mesh.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position); return(Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(positions).dx()); }
public MeshPartRenderData CreateMeshPartData(IMeshPart part) { return(CreateMeshPartData(part.GetGeometryData().ToRawMeshData())); }