private static AnimationMesh CreateMesh(SerializableMesh meshContent) { AnimationMesh mesh = new AnimationMesh(meshContent.name); AnimationVertex[] vertices = new AnimationVertex[meshContent.vertices.Length]; for (int i = 0; i < vertices.Length; i++) { SerializableVertex vertexContent = meshContent.vertices[i]; vertices[i] = new AnimationVertex { position = vertexContent.position, normal = vertexContent.normal, texture = vertexContent.texture, blendweights = vertexContent.blendweights, blendindices = vertexContent.blendindices }; } mesh.SetIndices(meshContent.indices); mesh.SetVertices(vertices); mesh.SetTextureName(meshContent.textureName); return(mesh); }
private void ProcessGeometry(GeometryContent xnaGeometry) { // find and process the geometry's bone weights for (int i = 0; i < xnaGeometry.Vertices.Channels.Count; i++) { string channelName = xnaGeometry.Vertices.Channels[i].Name; string baseName = VertexChannelNames.DecodeBaseName(channelName); if (baseName == "Weights") { ProcessWeightsChannel(xnaGeometry, i, outputModel.skeleton); } } // retrieve the four vertex channels we require for CPU skinning. we ignore any // other channels the model might have. string normalName = VertexChannelNames.EncodeName(Microsoft.Xna.Framework.Graphics.VertexElementUsage.Normal, 0); string texCoordName = VertexChannelNames.EncodeName(Microsoft.Xna.Framework.Graphics.VertexElementUsage.TextureCoordinate, 0); string blendWeightName = VertexChannelNames.EncodeName(Microsoft.Xna.Framework.Graphics.VertexElementUsage.BlendWeight, 0); string blendIndexName = VertexChannelNames.EncodeName(Microsoft.Xna.Framework.Graphics.VertexElementUsage.BlendIndices, 0); VertexChannel <Vector3> normals = xnaGeometry.Vertices.Channels[normalName] as VertexChannel <Vector3>; VertexChannel <Vector2> texCoords = xnaGeometry.Vertices.Channels[texCoordName] as VertexChannel <Vector2>; VertexChannel <Vector4> blendWeights = xnaGeometry.Vertices.Channels[blendWeightName] as VertexChannel <Vector4>; VertexChannel <Vector4> blendIndices = xnaGeometry.Vertices.Channels[blendIndexName] as VertexChannel <Vector4>; // create our array of vertices int triangleCount = xnaGeometry.Indices.Count / 3; SerializableVertex[] vertices = new SerializableVertex[xnaGeometry.Vertices.VertexCount]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new SerializableVertex { position = xnaGeometry.Vertices.Positions[i], normal = normals[i], texture = texCoords[i], blendweights = blendWeights[i], blendindices = blendIndices[i] }; } int[] indices = new int[xnaGeometry.Indices.Count]; for (int i = 0; i < xnaGeometry.Indices.Count; i++) { indices[i] = xnaGeometry.Indices[i]; } SerializableMesh mesh = new SerializableMesh(); mesh.name = string.Format("mesh_{0}_{1}", outputModel.meshList.Count, xnaGeometry.Name); mesh.textureName = GetTextureName(xnaGeometry); mesh.vertices = vertices; mesh.indices = indices; outputModel.meshList.Add(mesh); }
/// <summary> /// Serializes the vertices /// </summary> /// <param name="stream"></param> /// <param name="graph"></param> protected virtual void SerializeVertices(LimitedStream stream, DynamicGraphRouterDataSource <TEdgeData> graph) { RuntimeTypeModel typeModel = RuntimeTypeModel.Create(); typeModel.Add(typeof(SerializableVertex), true); int blockSize = 1000; var vertices = new SerializableVertex[blockSize]; uint vertex = 1; float latitude, longitude; while (vertex <= graph.VertexCount) { // adjust array size if needed. if (vertices.Length > graph.VertexCount - vertex) { // shrink array. vertices = new SerializableVertex[graph.VertexCount - vertex + 1]; } // build block. for (uint idx = 0; idx < vertices.Length; idx++) { uint current = vertex + idx; if (vertex <= graph.VertexCount && graph.GetVertex(current, out latitude, out longitude)) { // vertex in the graph. if (vertices[idx] == null) { // make sure there is a vertex. vertices[idx] = new SerializableVertex(); } vertices[idx].Latitude = latitude; vertices[idx].Longitude = longitude; } else { // vertex not in the graph. throw new Exception("Cannot serialize non-existing vertices!"); } } // serialize. typeModel.SerializeWithSize(stream, vertices); // move to the next vertex. vertex = (uint)(vertex + blockSize); } }