Exemple #1
0
        public static void CenterPivot(ref AMT_MODEL model)
        {
            List <Vector3> vertices = new List <Vector3>();

            for (int i = 0; i < model.Vertices.Count; i++)
            {
                vertices.Add(model.Vertices[i].Position);
            }

            BoundingBox bb            = BoundingBox.CreateFromPoints(vertices);
            Vector3     positionAjust = -(bb.Max + bb.Min) / 2;

            Matrix translation = Matrix.CreateTranslation(positionAjust);

            //redimensiona os vertices
            for (int i = 0; i < model.Vertices.Count; i++)
            {
                model.Vertices[i].Position = Vector3.Transform(model.Vertices[i].Position, translation);
            }

            //reposiciona tb todos os bones e os keyframes
            if (model.Joints != null)
            {
                for (int i = 0; i < model.Joints.Count; i++)
                {
                    AMT_JOINT v = model.Joints[i];

                    //como ele mexeu na posicao entao mexe so no raiz
                    if (v.Name == "Root")
                    {
                        v.BindMatrix *= translation;
                    }

                    if (model.Joints[i].ParentID != -1)
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix *
                                           model.Joints[model.Joints[i].ParentID].MatrixAbsolute;
                    }
                    else
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix;
                    }

                    v.InverseBindMatrix = Matrix.Invert(translation) * v.InverseBindMatrix;

                    //mexe so no raiz
                    if (v.Name == "Root")
                    {
                        for (int j = 0; j < v.KFData.Count; j++)
                        {
                            AMT_KF p = v.KFData[j];
                            p.BindMatrix *= translation;
                            v.KFData[j]   = p;
                        }
                    }

                    model.Joints[i] = v;
                }
            }
        }
Exemple #2
0
        void AddAnimations(ref AMT_MODEL?amtModel)
        {
            List <AMT_ANIMATION> animations = new List <AMT_ANIMATION>();

            for (int i = 0; i < animationsData.Rows.Count; i++)
            {
                var animation = new AMT_ANIMATION()
                {
                    StartFrame = (uint)animationsData.Rows[i]["Start"],
                    EndFrame   = (uint)animationsData.Rows[i]["End"],
                    Name       = animationsData.Rows[i]["Name"].ToString()
                };
                animations.Add(animation);
            }

            AMT_MODEL im = amtModel.Value;

            im.Animations         = animations;
            im.Head.NumAnimations = (uint)animations.Count;
            amtModel = im;
        }
        public AMT_MODEL ConvertCollada(Stream stream)
        {
            var amtModel = new AMT_MODEL();

            var doc         = XDocument.Load(stream);
            var colladaNode = doc.Root;

            Namespace = doc.Root.Name.Namespace.NamespaceName;
            //ReadGeometries(new XElement(XName.Get("library_geometries", Namespace)), ref amtModel);

            //_effects = ReadEffects(colladaNode.Element(XName.Get("library_effects", COLLADAConverter.Namespace)));
            //_materials = ReadMaterials(colladaNode.Element(XName.Get("library_materials", COLLADAConverter.Namespace)));

            ////Lê os layers
            //var geometryNodes = colladaNode.Element(XName.Get("library_geometries", COLLADAConverter.Namespace));
            //if (geometryNodes != null)
            //    pmobDoc.Layers = ReadLayers(geometryNodes.Elements());

            //ReadLibraryNodes(colladaNode.Element(XName.Get("library_nodes", COLLADAConverter.Namespace)));

            //var scenesElement = colladaNode.Element(XName.Get("library_visual_scenes", COLLADAConverter.Namespace));
            //if (scenesElement != null)
            //{
            //    var nodes = ReadNodes(scenesElement.Element(XName.Get("visual_scene", COLLADAConverter.Namespace)));

            //    var rootNode = new Node("root", "root", nodes);
            //    pmobDoc.Primitive = CreatePrimitive(rootNode);
            //}

            ////Gira o objeto dependendo do up
            //var assetNode = colladaNode.Element(XName.Get("asset", COLLADAConverter.Namespace));
            //if (assetNode != null)
            //{
            //    var upAxis = assetNode.Elements(XName.Get("up_axis", COLLADAConverter.Namespace));
            //}


            return(amtModel);
        }
Exemple #4
0
        public static void SetYUp(ref AMT_MODEL model, Vector3 upVector)
        {
            if (upVector == Vector3.UnitY)
            {
                return;
            }

            //aplica a rotacao
            Matrix rotation;

            if (upVector == Vector3.UnitX)
            {
                rotation = Matrix.CreateRotationZ(-MathHelper.PiOver2);
            }
            else
            {
                rotation = Matrix.CreateRotationX(-MathHelper.PiOver2);
            }

            List <Vector3> vertices = new List <Vector3>();

            for (int i = 0; i < model.Vertices.Count; i++)
            {
                AMT_VERTEX v = model.Vertices[i];
                Vector3.Transform(ref v.Position, ref rotation, out v.Position);
                Vector3.TransformNormal(ref v.Normal, ref rotation, out v.Normal);
            }

            if (model.Joints != null)
            {
                for (int i = 0; i < model.Joints.Count; i++)
                {
                    AMT_JOINT v = model.Joints[i];

                    //como ele mexeu na posicao entao mexe so no raiz
                    if (v.Name == "Root")
                    {
                        v.BindMatrix *= rotation;
                    }

                    if (model.Joints[i].ParentID != -1)
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix *
                                           model.Joints[model.Joints[i].ParentID].MatrixAbsolute;
                    }
                    else
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix;
                    }

                    v.InverseBindMatrix = Matrix.Invert(rotation) * v.InverseBindMatrix;

                    //mexe so no raiz
                    if (v.Name == "Root")
                    {
                        for (int j = 0; j < v.KFData.Count; j++)
                        {
                            AMT_KF p = v.KFData[j];
                            p.BindMatrix *= rotation;
                            v.KFData[j]   = p;
                        }
                    }

                    model.Joints[i] = v;
                }
            }
        }
Exemple #5
0
        //deixa todos os modelos com tamanho 1 para serem redimensionados no editor
        public static void UniformScale(ref AMT_MODEL model)
        {
            List <Vector3> vertices = new List <Vector3>();

            for (int i = 0; i < model.Vertices.Count; i++)
            {
                vertices.Add(model.Vertices[i].Position);
            }

            BoundingSphere sphere = BoundingSphere.CreateFromPoints(vertices);

            //redimensiona os vertices
            float scalefactor = 1.0f / sphere.Radius;

            //redimensiona tb todos os bones e os keyframes
            Matrix scale = Matrix.CreateScale(scalefactor);

            for (int i = 0; i < model.Vertices.Count; i++)
            {
                model.Vertices[i].Position = Vector3.Transform(model.Vertices[i].Position, scale);
                model.Vertices[i].Normal   = Vector3.TransformNormal(model.Vertices[i].Normal, scale);
            }

            if (model.Joints != null)
            {
                for (int i = 0; i < model.Joints.Count; i++)
                {
                    AMT_JOINT v = model.Joints[i];

                    //como ele mexeu na posicao entao mexe so no raiz
                    if (v.Name == "Root")
                    {
                        v.BindMatrix *= scale;
                    }

                    if (model.Joints[i].ParentID != -1)
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix *
                                           model.Joints[model.Joints[i].ParentID].MatrixAbsolute;
                    }
                    else
                    {
                        v.MatrixAbsolute = model.Joints[i].BindMatrix;
                    }

                    v.InverseBindMatrix = Matrix.Invert(scale) * v.InverseBindMatrix;

                    if (v.Name == "Root")
                    {
                        for (int j = 0; j < v.KFData.Count; j++)
                        {
                            AMT_KF p = v.KFData[j];
                            p.BindMatrix *= scale;
                            v.KFData[j]   = p;
                        }
                    }

                    model.Joints[i] = v;
                }
            }
        }