Beispiel #1
0
        private void InitSkinInfo(AiMesh mesh, AssimpSceneContainer container)
        {
            var          boneIDs     = new uvec4[mesh.Vertexes.Length];
            var          boneWeights = new vec4[mesh.Vertexes.Length];
            AllBoneInfos allBones    = container.GetAllBoneInfos();
            Dictionary <string, uint> nameIndexDict = allBones.nameIndexDict;

            for (int i = 0; i < mesh.BoneCount; i++)
            {
                AiBone bone      = mesh.Bones[i]; // bones that influence this mesh.
                uint   boneIndex = nameIndexDict[bone.Name];

                for (int j = 0; j < bone.VertexWeightCount; j++)
                {
                    AiVertexWeight vertexWeight = bone.VertexWeights[j];
                    uint           vertexID     = vertexWeight.VertexID;
                    for (int t = 0; t < 4; t++)
                    {
                        if (boneWeights[vertexID][t] == 0.0f) // fill in x y z w.
                        {
                            boneIDs[vertexID][t]     = boneIndex;
                            boneWeights[vertexID][t] = vertexWeight.Weight;
                            break;
                        }
                    }
                }
            }
            this.boneIDs     = boneIDs;
            this.boneWeights = boneWeights;
        }
        private AllBoneInfos InitBonesInfo(AiScene aiScene)
        {
            List <BoneInfo> boneInfos     = new List <BoneInfo>();
            var             nameIndexDict = new Dictionary <string, uint>();

            for (int i = 0; i < aiScene.MeshCount; i++)
            {
                AiMesh mesh = aiScene.Meshes[i];
                for (int j = 0; j < mesh.BoneCount; j++)
                {
                    AiBone bone     = mesh.Bones[j];
                    string boneName = bone.Name;
                    if (!nameIndexDict.ContainsKey(boneName))
                    {
                        var boneInfo = new BoneInfo(bone);
                        boneInfos.Add(boneInfo);
                        nameIndexDict.Add(boneName, (uint)(boneInfos.Count - 1));
                    }
                }
            }

            return(new AllBoneInfos(boneInfos.ToArray(), nameIndexDict));
        }
        public static AiScene Parse(this EZMFile ezmFile)
        {
            if (ezmFile == null)
            {
                throw new ArgumentNullException();
            }

            var aiScene = new AiScene();

            aiScene.Fullname = ezmFile.Fullname;
            // root node.
            {
                EZMSkeleton skeleton = ezmFile.MeshSystem.Skeletons[0];
                EZMBone[]   bones    = skeleton.Bones;
                aiScene.RootNode = Parse(bones[0]);
                Match(aiScene.RootNode, bones[0]);
            }
            // meshes.
            {
                EZMMesh[] ezmMeshes = ezmFile.MeshSystem.Meshes;
                var       lstAiMesh = new List <AiMesh>();
                for (int i = 0; i < ezmMeshes.Length; i++)
                {
                    AiMesh[] aiMeshes = Parse(ezmMeshes[i]);
                    lstAiMesh.AddRange(aiMeshes);
                }
                aiScene.Meshes = lstAiMesh.ToArray();
            }
            // materials.
            {
                EZMMaterial[] ezmMaterials = ezmFile.MeshSystem.Materials;
                var           aiMaterials  = new AiMaterial[ezmMaterials.Length];
                for (int i = 0; i < aiMaterials.Length; i++)
                {
                    aiMaterials[i] = Parse(ezmMaterials[i]);
                }
                aiScene.Materials = aiMaterials;
            }
            // animations.
            {
                EZMAnimation[] ezmAnimations = ezmFile.MeshSystem.Animations;
                var            aiAnimations  = new AiAnimation[ezmAnimations.Length];
                for (int i = 0; i < ezmAnimations.Length; i++)
                {
                    aiAnimations[i] = Parse(ezmAnimations[i]);
                }
                aiScene.Animations = aiAnimations;
            }
            {
                // init material indexes in mesh.
                foreach (AiMesh aiMesh in aiScene.Meshes)
                {
                    string name = aiMesh.materialName;
                    for (int i = 0; i < aiScene.Materials.Length; i++)
                    {
                        if (aiScene.Materials[i].Name == name)
                        {
                            aiMesh.MaterialIndex = i;
                            break;
                        }
                    }
                }
            }
            {
                // bones.
                EZMSkeleton skeleton = ezmFile.MeshSystem.Skeletons[0];
                EZMBone[]   bones    = skeleton.Bones;
                var         aiBones  = new AiBone[bones.Length];
                for (int i = 0; i < bones.Length; i++)
                {
                    var aiBone = new AiBone();
                    var bone   = bones[i];
                    //bone.
                    aiBones[i] = aiBone;
                }
                aiScene.RootNode = Parse(bones[0]);
                Match(aiScene.RootNode, bones[0]);
            }
            return(aiScene);
        }
 public BoneInfo(AiBone bone)
 {
     this.bone = bone;
     this.finalTransformation = mat4.identity();
 }