Exemplo n.º 1
0
        private void EndModel()
        {
            if (skeletons.Count > 0)
            {
                Skeleton skeleton = skeletons[skeletons.Count - 1];
                if (skeleton.GetNumBones() > 0)
                {
                    for (int i = 0; i < skeleton.GetNumBones(); i++)
                        skeleton.GetBone(i).SetToBindingPose();
                    skeleton.GetBone(0).CalculateBindingRotation();
                    skeleton.GetBone(0).CalculateBindingTranslation();
                    for (int i = 0; i < skeleton.GetNumBones(); i++)
                    {
                        skeleton.GetBone(i).StoreBindingPose();
                        skeleton.GetBone(i).ClearPose();
                    }
                    skeleton.GetBone(0).UpdateTransform();
                }
                if (hasAnimations)
                {
                    for (int j = 0; j < animations.Count; j++)
                    {
                        skeletons[0].AddAnimation(animations[j]);
                    }
                    nodes[0].AddController(new AnimationController(skeletons[0]));
                }
            }
            for (int i = 0; i < meshes.Count; i++)
            {
                List<Vertex> cVerts = vertices[i];
                List<int> cFaces = faces[i];

                List<Vector3f> cPos = positions[i];
                List<Vector3f> cNorm = normals[i];
                List<Vector2f> tc0 = texcoords0[i];
                List<Vector2f> tc1 = texcoords1[i];
                List<BoneAssign> ba = null;

                Mesh mesh = meshes[i];
                if (boneAssigns.Count > 0)
                {
                    ba = boneAssigns[i];
                }
                int stride = 3;

                if (tc1.Count > 0)
                    stride++;
                for (int j = 0; j < cFaces.Count; j += stride)
                {
                    Vertex v = new Vertex(cPos[cFaces[j]]);
                    if (cNorm.Count > 0)
                    {
                        mesh.GetAttributes().SetAttribute(VertexAttributes.NORMALS);
                        v.SetNormal(cNorm[cFaces[j + 1]]);
                    }
                    if (tc0.Count > 0)
                    {
                        mesh.GetAttributes().SetAttribute(VertexAttributes.TEXCOORDS0);
                        v.SetTexCoord1(tc0[cFaces[j + 2]]);
                    }
                    if (tc1.Count > 0)
                    {
                        mesh.GetAttributes().SetAttribute(VertexAttributes.TEXCOORDS1);
                        v.SetTexCoord1(tc1[cFaces[j + 3]]);
                    }
                    cVerts.Add(v);
                }
                List<int> indexData = new List<int>();
                if (skeletons.Count > 0)
                {
                    mesh.SetSkeleton(skeletons[0]);
                    if (boneAssigns.Count > 0)
                    {
                        for (int j = 0; j < ba.Count; j++)
                        {
                            Vertex v = cVerts[ba[j].GetVertexIndex()];
                            v.AddBoneIndex(ba[j].GetBoneIndex());
                            v.AddBoneWeight(ba[j].GetBoneWeight());
                        }
                    }
                }
                mesh.SetVertices(cVerts);
                if (geoms.Count > 0)
                {
                    Geometry parent = geoms[i];
                    Material material = null;
                    if (geomMats.ContainsKey(parent))
                        material = geomMats[parent];
                    else
                        material = new Material();
                    parent.Mesh = mesh;
                    parent.Material = material;
                }
            }
        }
Exemplo n.º 2
0
        private void LoopThrough(List<int> faces, ref List<Vertex> outVerts)
        {
            for (int i = 0; i < faces.Count; i++)
            {
                Vertex v = new Vertex(positions[faces[i]],
                                      texCoords.Count > 0 ? texCoords[faces[i]] : null,
                                      normals.Count > 0 ? normals[faces[i]] : null);

                if (boneAssigns.ContainsKey(faces[i]))
                {
                    BoneAssign[] vertBoneAssigns = boneAssigns[faces[i]];
                    for (int j = 0; j < vertBoneAssigns.Length; j++)
                    {
                        if (vertBoneAssigns[j] != null)
                        {
                            v.AddBoneIndex(vertBoneAssigns[j].GetBoneIndex());
                            v.AddBoneWeight(vertBoneAssigns[j].GetBoneWeight());
                        }
                    }
                }
                outVerts.Add(v);
            }
        }