Exemplo n.º 1
0
        private void InitSkinInfo(Assimp.Mesh mesh, AssimpSceneContainer container)
        {
            var          boneIDs     = new uvec4[mesh.VertexCount];
            var          boneWeights = new vec4[mesh.VertexCount];
            AllBoneInfos allBones    = container.GetAllBoneInfos();
            Dictionary <string, uint> nameIndexDict = allBones.nameIndexDict;

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

                for (int j = 0; j < bone.VertexWeightCount; j++)
                {
                    Assimp.VertexWeight 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;
        }
Exemplo n.º 2
0
        private void OpenFile(string filename)
        {
            var importer = new Assimp.AssimpImporter();

            Assimp.Scene aiScene = null;
            try
            {
                aiScene = importer.ImportFile(filename, Assimp.PostProcessSteps.GenerateSmoothNormals | Assimp.PostProcessSteps.Triangulate | Assimp.PostProcessSteps.FlipUVs);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); return; }

            var container = new AssimpSceneContainer(aiScene, filename);

            CreateAnimationNodes(aiScene, container);
            CreateSkeletonNode(aiScene, container);
            CreateJointNode(aiScene, container);

            {
                this.cmbAnimationIndex.Items.Clear();
                int count = container.aiScene.AnimationCount;
                for (int i = 0; i < count; i++)
                {
                    this.cmbAnimationIndex.Items.Add(string.Format("Animation {0}", i));
                }
            }
        }
Exemplo n.º 3
0
        private void CreateSkeletonNode(Assimp.Scene aiScene, AssimpSceneContainer container)
        {
            var rootElement = this.scene.RootNode;
            var model       = new SkeletonModel(aiScene, container.GetAllBoneInfos());
            var node        = SkeletonNode.Create(model);

            this.skeletonNode = node;
            rootElement.Children.Add(node);
        }
Exemplo n.º 4
0
        private void CreateJointNode(Assimp.Scene aiScene, AssimpSceneContainer container)
        {
            var rootElement = this.scene.RootNode;
            var model       = new JointModel(aiScene, container.GetAllBoneInfos());
            var node        = JointNode.Create(model);

            node.DiffuseColor = Color.Red;
            this.jointNode    = node;
            rootElement.Children.Add(node);
        }
Exemplo n.º 5
0
        private void CreateAnimationNodes(Assimp.Scene aiScene, AssimpSceneContainer container)
        {
            var  rootElement = this.scene.RootNode;
            bool first = true; vec3 max = new vec3(); vec3 min = new vec3();
            var  models = new AnimationModel[aiScene.MeshCount];

            if (aiScene.HasMeshes)
            {
                int index = 0;
                foreach (Assimp.Mesh mesh in aiScene.Meshes)
                {
                    models[index++] = new AnimationModel(mesh, container);
                }
            }
            if (aiScene.RootNode != null)
            {
                mat4 parentTransform = mat4.identity();
                BuildNode(aiScene.RootNode, parentTransform, models, rootElement, ref max, ref min, ref first);
            }

            vec3  center = max / 2.0f + min / 2.0f;
            vec3  size   = max - min;
            float v      = size.x;

            if (v < size.y)
            {
                v = size.y;
            }
            if (v < size.z)
            {
                v = size.z;
            }
            this.scene.Camera.Position = center + size;
            this.scene.Camera.Target   = center;
            //rootElement.WorldPosition = center;
            this.manipulater.StepLength = v / 30.0f;
        }
Exemplo n.º 6
0
 public AnimationModel(Assimp.Mesh mesh, AssimpSceneContainer container)
 {
     this.mesh      = mesh;
     this.container = container;
     InitSkinInfo(mesh, container);
 }