예제 #1
0
        public void DistributeWeights(EVP1 envelopes, DRW1 partialWeights)
        {
            foreach (Shape shape in Shapes)
            {
                foreach (Packet pack in shape.Packets)
                {
                    foreach (Primitive prim in pack.Primitives)
                    {
                        foreach (Vertex vert in prim.Vertices)
                        {
                            uint drw1Index = vert.GetAttributeIndex(GXVertexAttribute.PositionMatrixIdx);

                            if (partialWeights.WeightTypeCheck[(int)drw1Index])
                            {
                                vert.SetWeight(envelopes.Weights[partialWeights.Indices[(int)drw1Index]]);
                            }
                            else
                            {
                                Rigging.Weight newWeight = new Rigging.Weight();
                                newWeight.AddWeight(1.0f, partialWeights.Indices[(int)drw1Index]);

                                vert.SetWeight(newWeight);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public static SHP1 Create(Scene scene, Dictionary <string, int> boneNames, VertexData vertData, out EVP1 evp1, out DRW1 drw1)
        {
            evp1 = new EVP1();
            drw1 = new DRW1();

            SHP1 shp1 = new SHP1(scene, vertData, boneNames, evp1, drw1);

            return(shp1);
        }
예제 #3
0
        private void SetMatrixIndices(Vertex vert, EVP1 envelopes, DRW1 partialWeight, List <int> matrixIndices)
        {
            vert.SetAttributeIndex(GXVertexAttribute.PositionMatrixIdx, (uint)matrixIndices.Count);
            matrixIndices.Add(partialWeight.WeightTypeCheck.Count);

            if (vert.VertexWeight.WeightCount > 1)
            {
                partialWeight.WeightTypeCheck.Add(true);
                partialWeight.Indices.Add(envelopes.Weights.Count);
                envelopes.Weights.Add(vert.VertexWeight);
            }
            else
            {
                partialWeight.WeightTypeCheck.Add(false);
                partialWeight.Indices.Add(vert.VertexWeight.BoneIndices[0]);
            }
        }
예제 #4
0
        public Model(EndianBinaryReader reader)
        {
            int j3d2Magic  = reader.ReadInt32();
            int modelMagic = reader.ReadInt32();

            if (j3d2Magic != 0x4A334432)
            {
                throw new Exception("Model was not a BMD or BDL! (J3D2 magic not found)");
            }
            if ((modelMagic != 0x62646C34) && (modelMagic != 0x626D6433))
            {
                throw new Exception("Model was not a BMD or BDL! (Model type was not bmd3 or bdl4)");
            }

            int modelSize    = reader.ReadInt32();
            int sectionCount = reader.ReadInt32();

            // Skip the dummy section, SVR3
            reader.Skip(16);

            Scenegraph        = new INF1(reader, 32);
            VertexData        = new VTX1(reader, (int)reader.BaseStream.Position);
            SkinningEnvelopes = new EVP1(reader, (int)reader.BaseStream.Position);
            PartialWeightData = new DRW1(reader, (int)reader.BaseStream.Position);
            Joints            = new JNT1(reader, (int)reader.BaseStream.Position);
            Shapes            = SHP1.Create(reader, (int)reader.BaseStream.Position);
            Materials         = new MAT3(reader, (int)reader.BaseStream.Position);
            SkipMDL3(reader);
            Textures = new TEX1(reader, (int)reader.BaseStream.Position);

            foreach (Geometry.Shape shape in Shapes.Shapes)
            {
                packetCount += shape.Packets.Count;
            }

            vertexCount = VertexData.Attributes.Positions.Count;
        }
예제 #5
0
        private void ProcessShapeVertices(Mesh mesh, Shape shape, VertexData vertData, Dictionary <string, int> boneNames, EVP1 envelopes, DRW1 partialWeight)
        {
            Primitive             prim          = new Primitive();
            List <int>            matrixIndices = new List <int>();
            List <Rigging.Weight> totalWeights  = new List <Rigging.Weight>();
            int totalMatrixCount = 0;

            for (int i = 0; i < mesh.FaceCount; i++)
            {
                List <Vertex> faceVertices = new List <Vertex>();
                Face          meshFace     = mesh.Faces[i];

                for (int j = 0; j < meshFace.IndexCount; j++)
                {
                    Vertex vert      = new Vertex();
                    int    vertIndex = meshFace.Indices[j];
                    SetVertexIndices(mesh, vert, vertData, shape.Descriptor, vertIndex);

                    foreach (Assimp.Bone bone in mesh.Bones)
                    {
                        foreach (Assimp.VertexWeight weight in bone.VertexWeights)
                        {
                            if (weight.VertexID == vertIndex)
                            {
                                vert.VertexWeight.AddWeight(weight.Weight, boneNames[bone.Name]);
                            }
                        }
                    }

                    faceVertices.Add(vert);
                }

                List <Rigging.Weight> currentWeights = new List <Rigging.Weight>();

                int currentMatrixCount = 0;
                for (int j = 0; j < meshFace.IndexCount; j++)
                {
                    currentWeights.Add(faceVertices[j].VertexWeight);
                }

                List <Rigging.Weight> newWeights = currentWeights.Except(totalWeights, new WeightEqualityComparer()).ToList();
                for (int j = 0; j < newWeights.Count; j++)
                {
                    currentMatrixCount += newWeights[j].WeightCount;
                }

                if (totalMatrixCount + currentMatrixCount > 10)
                {
                    //shape.Primitives.Add(prim);
                    //shape.MatrixDataIndices.Add(matrixIndices.ToArray());

                    prim          = new Primitive();
                    matrixIndices = new List <int>();
                    totalWeights.Clear();
                    totalMatrixCount = 0;

                    prim.Vertices.AddRange(faceVertices);
                }
                else
                {
                    totalMatrixCount += currentMatrixCount;

                    for (int j = 0; j < currentWeights.Count; j++)
                    {
                        if (!totalWeights.Contains(currentWeights[j]))
                        {
                            totalWeights.Add(currentWeights[j]);
                        }
                    }

                    prim.Vertices.AddRange(faceVertices);
                }

                // The following needs to be fixed so that the correct indices are given to the vertex and EVP1/DRW1
                for (int j = 0; j < meshFace.IndexCount; j++)
                {
                    faceVertices[j].SetAttributeIndex(GXVertexAttribute.PositionMatrixIdx, (uint)matrixIndices.Count);
                    matrixIndices.Add(partialWeight.WeightTypeCheck.Count);

                    if (faceVertices[j].VertexWeight.WeightCount > 1)
                    {
                        partialWeight.WeightTypeCheck.Add(true);
                        partialWeight.Indices.Add(envelopes.Weights.Count);
                        envelopes.Weights.Add(faceVertices[j].VertexWeight);
                    }
                    else
                    {
                        partialWeight.WeightTypeCheck.Add(false);
                        partialWeight.Indices.Add(faceVertices[j].VertexWeight.BoneIndices[0]);
                    }
                }
                //SetMatrixIndices(faceVertices[j], envelopes, partialWeight, matrixIndices);
            }
        }
예제 #6
0
        private SHP1(Assimp.Scene scene, VertexData vertData, Dictionary <string, int> boneNames, EVP1 envelopes, DRW1 partialWeight)
        {
            Shapes     = new List <Shape>();
            RemapTable = new List <int>();

            foreach (Mesh mesh in scene.Meshes)
            {
                Shape meshShape = new Shape(mesh);
                ProcessShapeVertices(mesh, meshShape, vertData, boneNames, envelopes, partialWeight);
                Shapes.Add(meshShape);
            }
        }