public static void ProcessNode(NodeContent node, ShapeN_SkinDContent_Writing outputModel, ref int curIndex, ref int parentIndex) { curIndex++; outputModel.TransDatas.NameGrp.Add(node.Name); outputModel.TransDatas.ParentIndex.Add(parentIndex); outputModel.TransDatas.RelativeMatrixGrp.Add(node.Transform); parentIndex = curIndex; // Is this node in fact a mesh? MeshContent mesh = node as MeshContent; if (mesh != null) { // Reorder vertex and index data so triangles will render in // an order that makes efficient use of the GPU vertex cache. MeshHelper.OptimizeForCache(mesh); // Process all the geometry in the mesh. foreach (GeometryContent geometry in mesh.Geometry) { ProcessGeometry(geometry, curIndex, "Shape:" + node.Name, outputModel); } } // Recurse over any child nodes. if (node.Children != null && node.Children.Count != 0) foreach (NodeContent child in node.Children) { ProcessNode(child, outputModel, ref curIndex, ref parentIndex); } else { parentIndex = outputModel.TransDatas.ParentIndex[curIndex]; } }
static void ProcessGeometry(GeometryContent geometry, int parentIndex, string shapeNm, ShapeN_SkinDContent_Writing output) { // 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); } // retrieve the four vertex channels we require for CPU skinning. we ignore any // other channels the model might have. string normalNm = VertexChannelNames.EncodeName(VertexElementUsage.Normal, 0); string texCoordNm = VertexChannelNames.EncodeName(VertexElementUsage.TextureCoordinate, 0); string blendWeightNm = VertexChannelNames.EncodeName(VertexElementUsage.BlendWeight, 0); string blendIndexNm = VertexChannelNames.EncodeName(VertexElementUsage.BlendIndices, 0); string positionNm = VertexChannelNames.EncodeName(VertexElementUsage.Position, 0); //var tmp = geometry.Vertices.Channels[positionNm] as VertexChannel<Vector3>; VertexChannel<Vector3> normals; VertexChannel<Vector2> texCoords; VertexChannel<Vector4> blendWeights; VertexChannel<Vector4> blendIndices; //if(geometry.Vertices.Channels.Contains(normalNm)) normals = geometry.Vertices.Channels[normalNm] as VertexChannel<Vector3>; if (geometry.Vertices.Channels.Contains(texCoordNm)) texCoords = geometry.Vertices.Channels[texCoordNm] as VertexChannel<Vector2>; if (geometry.Vertices.Channels.Contains(blendWeightNm)) blendWeights = geometry.Vertices.Channels[blendWeightNm] as VertexChannel<Vector4>; if (geometry.Vertices.Channels.Contains(blendIndexNm)) blendIndices = geometry.Vertices.Channels[blendIndexNm] as VertexChannel<Vector4>; // create our array of vertices int triangleCount = geometry.Indices.Count / 3; VertexData[] verticesData = new VertexData[geometry.Vertices.VertexCount]; Vector3[] vertice = new Vector3[verticesData.Length]; for (int i = 0; i < verticesData.Length; i++) { verticesData[i] = new VertexData { Position = geometry.Vertices.Positions[i], Normal = normals[i], //TextureCoordinate = texCoords[i], //BlendWeights = blendWeights[i], //BlendIndices = blendIndices[i] }; vertice[i] = verticesData[i].Position; } BoundingSphere[] bSpheres = new BoundingSphere[1] { BoundingSphere.CreateFromPoints(vertice) }; // Add the new piece of geometry to our output model. output.SetShapeNode( shapeNm, parentIndex, triangleCount, geometry.Indices, verticesData, bSpheres); }