public MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, int[] adjacency, SkinInfo skinInfo) { var device = meshData.Mesh.Device; GMeshContainer meshContainer = new GMeshContainer(); meshContainer.Name = name; SlimDX.Direct3D9.Mesh mesh = meshData.Mesh; if (!mesh.VertexFormat.HasFlag(VertexFormat.Normal)) { meshContainer.MeshData = new MeshData(mesh.Clone(device, mesh.CreationOptions, mesh.VertexFormat | VertexFormat.Normal)); meshContainer.MeshData.Mesh.ComputeNormals(); } else { meshContainer.MeshData = new MeshData(mesh); } meshContainer.SetMaterials(materials); meshContainer.SetAdjacency(adjacency); meshContainer.SkinInfo = skinInfo; meshContainer.BoneOffsetsMatrix = new Matrix[skinInfo.BoneCount]; for (int i = 0; i < skinInfo.BoneCount; i++) { meshContainer.BoneOffsetsMatrix[i] = skinInfo.GetBoneOffsetMatrix(i); } GenerateSkinnedMesh(device, meshContainer); return(meshContainer); }
public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, int[] adjacency, SkinInfo skinInfo) { CustomMeshContainer meshContainer = new CustomMeshContainer(); meshContainer.Name = name; meshContainer.MeshData = meshData; meshContainer.SetAdjacency(adjacency); //meshContainer.SetEffects(effectInstances); meshContainer.SkinInfo = skinInfo; meshContainer.OriginalMesh = meshData.Mesh.Clone(meshData.Mesh.Device, meshData.Mesh.CreationOptions, meshData.Mesh.VertexFormat); if (skinInfo != null) { meshContainer.BoneOffsets = new Matrix[skinInfo.BoneCount]; for (int i = 0; i < skinInfo.BoneCount; i++) { meshContainer.BoneOffsets[i] = skinInfo.GetBoneOffsetMatrix(i); } meshContainer.PaletteEntries = Math.Min(MaxMatrices, meshContainer.SkinInfo.BoneCount); int influences; BoneCombination[] boneCombinations; meshContainer.MeshData.Mesh.Dispose(); meshContainer.MeshData = new MeshData(meshContainer.SkinInfo.ConvertToIndexedBlendedMesh(meshContainer.OriginalMesh, meshContainer.PaletteEntries, adjacency, out influences, out boneCombinations)); meshContainer.Influences = influences; meshContainer.BoneCombinations = boneCombinations; VertexElement[] elements = meshContainer.MeshData.Mesh.GetDeclaration(); for (int i = 0; i < elements.Length; i++) { if (elements[i].Stream == 0xff) { break; } if (elements[i].Usage == DeclarationUsage.BlendIndices && elements[i].UsageIndex == 0) { elements[i].Type = DeclarationType.Color; } } meshContainer.MeshData.Mesh.UpdateSemantics(elements); } return(meshContainer); }
public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, int[] adjacency, SkinInfo skinInfo) { CustomMeshContainer meshContainer = new CustomMeshContainer(); meshContainer.Name = name; meshContainer.MeshData = meshData; meshContainer.SetAdjacency(adjacency); meshContainer.SetEffects(effectInstances); meshContainer.SkinInfo = skinInfo; meshContainer.OriginalMesh = meshData.Mesh.Clone(meshData.Mesh.Device, meshData.Mesh.CreationOptions, meshData.Mesh.VertexFormat); if (skinInfo != null) { meshContainer.BoneOffsets = new Matrix[skinInfo.BoneCount]; for (int i = 0; i < skinInfo.BoneCount; i++) meshContainer.BoneOffsets[i] = skinInfo.GetBoneOffsetMatrix(i); meshContainer.PaletteEntries = Math.Min(MaxMatrices, meshContainer.SkinInfo.BoneCount); int influences; BoneCombination[] boneCombinations; meshContainer.MeshData.Mesh.Dispose(); meshContainer.MeshData = new MeshData(meshContainer.SkinInfo.ConvertToIndexedBlendedMesh(meshContainer.OriginalMesh, meshContainer.PaletteEntries, adjacency, out influences, out boneCombinations)); meshContainer.Influences = influences; meshContainer.BoneCombinations = boneCombinations; VertexElement[] elements = meshContainer.MeshData.Mesh.GetDeclaration(); for (int i = 0; i < elements.Length; i++) { if (elements[i].Stream == 0xff) break; if (elements[i].Usage == DeclarationUsage.BlendIndices && elements[i].UsageIndex == 0) elements[i].Type = DeclarationType.Color; } meshContainer.MeshData.Mesh.UpdateSemantics(elements); } return meshContainer; }