private int[] ComputeBoneSet(GeometryContent geometry, ContentProcessorContext context, string asset, Dictionary <string, int> boneIndices) { SortedDictionary <int, bool> indicesInUse = new SortedDictionary <int, bool>(); foreach (VertexChannel vc in geometry.Vertices.Channels) { string str = VertexChannelNames.DecodeBaseName(vc.Name); if (str == "Weights") { VertexChannel <BoneWeightCollection> channel = vc as VertexChannel <BoneWeightCollection>; if (vc == null) { continue; } for (int n = 0; n < channel.Count; n++) { VertexWeightsInUse(context, asset, channel[n], boneIndices, indicesInUse); } } } int[] values = new int[indicesInUse.Count]; int i = 0; foreach (int index in indicesInUse.Keys) { values[i++] = index; } return(values); }
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); }
void ProcessGeometry(GeometryContent geometry) { // find and process the geometry's bone weights for (int i = 0; i < geometry.Vertices.Channels.Count; i++) { string channelName = geometry.Vertices.Channels[i].Name; string baseName = VertexChannelNames.DecodeBaseName(channelName); if (baseName == "Weights") { ProcessWeightsChannel(geometry, i); } } // retrieve the four vertex channels we require for CPU skinning. we ignore any // other channels the model might have. string normalName = VertexChannelNames.EncodeName(VertexElementUsage.Normal, 0); string texCoordName = VertexChannelNames.EncodeName(VertexElementUsage.TextureCoordinate, 0); string blendWeightName = VertexChannelNames.EncodeName(VertexElementUsage.BlendWeight, 0); string blendIndexName = VertexChannelNames.EncodeName(VertexElementUsage.BlendIndices, 0); VertexChannel <Vector3> normals = geometry.Vertices.Channels[normalName] as VertexChannel <Vector3>; VertexChannel <Vector2> texCoords = geometry.Vertices.Channels[texCoordName] as VertexChannel <Vector2>; VertexChannel <Vector4> blendWeights = geometry.Vertices.Channels[blendWeightName] as VertexChannel <Vector4>; VertexChannel <Vector4> blendIndices = geometry.Vertices.Channels[blendIndexName] as VertexChannel <Vector4>; // create our array of vertices int triangleCount = geometry.Indices.Count / 3; CpuVertex[] vertices = new CpuVertex[geometry.Vertices.VertexCount]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new CpuVertex { Position = geometry.Vertices.Positions[i], Normal = normals[i], TextureCoordinate = texCoords[i], BlendWeights = blendWeights[i], BlendIndices = blendIndices[i] }; } // Convert the input material. MaterialContent material = ProcessMaterial(geometry.Material); // Add the new piece of geometry to our output model. outputModel.AddModelPart(triangleCount, geometry.Indices, vertices, material as BasicMaterialContent); }
private void ProcessVertexChannel(GeometryContent geometry, int vertexChannelIndex, ContentProcessorContext context, string asset, Dictionary <string, int> boneIndices, Dictionary <int, int> boneRemap) { string str = VertexChannelNames.DecodeBaseName(geometry.Vertices.Channels[vertexChannelIndex].Name); if (str != null) { if (str == "Color") { ProcessColorChannel(geometry, vertexChannelIndex); } if (str == "Weights") { ProcessWeightsChannel(context, asset, geometry, vertexChannelIndex, boneIndices, boneRemap); } } }
private void ProcessVertexChannel(GeometryContent geometry, int channelIndex) { // Get the base name of a vertex channel (e.g. "Colors" for "Colors1"). string baseName = VertexChannelNames.DecodeBaseName(geometry.Vertices.Channels[channelIndex].Name); if (baseName != null) { if (baseName == "Color") { ProcessColorChannel(geometry, channelIndex); } else if (baseName == "Weights") { ProcessWeightsChannel(geometry, channelIndex); } } }