Ejemplo n.º 1
0
        public static ModelData Load(Stream stream)
        {
            ModelData   modelData   = new ModelData();
            ColladaRoot colladaRoot = new ColladaRoot(XElement.Load(stream));

            if (colladaRoot.Scene.VisualScene.Nodes.Count > 1)
            {
                ModelBoneData modelBoneData = new ModelBoneData();
                modelData.Bones.Add(modelBoneData);
                modelBoneData.ParentBoneIndex = -1;
                modelBoneData.Name            = string.Empty;
                modelBoneData.Transform       = Matrix.Identity;
                using (List <ColladaNode> .Enumerator enumerator = colladaRoot.Scene.VisualScene.Nodes.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ColladaNode current = enumerator.Current;
                        LoadNode(modelData, modelBoneData, current, colladaRoot.Asset.Meter);
                    }
                    goto IL_F7;
                }
            }
            foreach (ColladaNode current2 in colladaRoot.Scene.VisualScene.Nodes)
            {
                LoadNode(modelData, null, current2, colladaRoot.Asset.Meter);
            }
IL_F7:
            foreach (ModelBuffersData current3 in modelData.Buffers)
            {
                IndexVertices(current3.VertexDeclaration.VertexStride, current3.Vertices, out current3.Vertices, out current3.Indices);
            }
            return(modelData);
        }
Ejemplo n.º 2
0
        static ModelBoneData LoadNode(ModelData data, ModelBoneData parentBoneData, ColladaNode node, float meter)
        {
            ModelBoneData modelBoneData = new ModelBoneData();

            data.Bones.Add(modelBoneData);
            modelBoneData.ParentBoneIndex = ((parentBoneData != null) ? data.Bones.IndexOf(parentBoneData) : (-1));
            modelBoneData.Name            = node.Name;
            modelBoneData.Transform       = node.Transform * Matrix.CreateScale(meter);
            foreach (ColladaNode current in node.Nodes)
            {
                LoadNode(data, modelBoneData, current, 1f);
            }
            foreach (ColladaGeometry current2 in node.Geometries)
            {
                LoadGeometry(data, modelBoneData, current2);
            }
            return(modelBoneData);
        }
            public void Read(XmlNode root)
            {
                root = root.ChildNodes[0];
                id   = (string)root.Attributes["id"].Value;
                name = (string)root.Attributes["name"].Value;

                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.Name.Equals("node"))
                    {
                        ColladaNode n = new ColladaNode();
                        n.Read(node, null);
                        nodes.Add(n);
                        foreach (var v in n.materialIds)
                        {
                            if (!MaterialIds.ContainsKey(v.Key))
                            {
                                MaterialIds.Add(v.Key, v.Value);
                            }
                        }
                    }
                }
            }
            public void Read(XmlNode root, ColladaNode parent)
            {
                this.parent = parent;
                id          = (string)root.Attributes["id"].Value;
                name        = (string)root.Attributes["name"].Value;
                if (root.Attributes["type"] != null)
                {
                    type = (string)root.Attributes["type"].Value;
                }

                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.Name.Equals("node"))
                    {
                        ColladaNode n = new ColladaNode();
                        n.Read(node, this);
                        children.Add(n);
                    }
                    else if (node.Name.Equals("matrix"))
                    {
                        string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' ');
                        mat     = new Matrix4();
                        mat.M11 = float.Parse(data[0]); mat.M12 = float.Parse(data[1]); mat.M13 = float.Parse(data[2]); mat.M14 = float.Parse(data[3]);
                        mat.M21 = float.Parse(data[4]); mat.M22 = float.Parse(data[5]); mat.M23 = float.Parse(data[6]); mat.M24 = float.Parse(data[7]);
                        mat.M31 = float.Parse(data[8]); mat.M32 = float.Parse(data[9]); mat.M33 = float.Parse(data[10]); mat.M34 = float.Parse(data[11]);
                        mat.M41 = float.Parse(data[12]); mat.M42 = float.Parse(data[13]); mat.M43 = float.Parse(data[14]); mat.M44 = float.Parse(data[15]);

                        pos   = new Vector3(mat.M14, mat.M24, mat.M34);
                        scale = mat.ExtractScale();

                        mat.ClearScale();
                        mat.ClearTranslation();
                        mat.Invert();
                        var quat = mat.ExtractRotation();
                        rot = Switch_Toolbox.Library.AssimpHelper.ToEular(quat);
                        if (float.IsNaN(rot.X))
                        {
                            rot.X = 0;
                        }
                        if (float.IsNaN(rot.Y))
                        {
                            rot.Y = 0;
                        }
                        if (float.IsNaN(rot.Z))
                        {
                            rot.Z = 0;
                        }

                        mat.M11 = float.Parse(data[0]); mat.M12 = float.Parse(data[1]); mat.M13 = float.Parse(data[2]); mat.M14 = float.Parse(data[3]);
                        mat.M21 = float.Parse(data[4]); mat.M22 = float.Parse(data[5]); mat.M23 = float.Parse(data[6]); mat.M24 = float.Parse(data[7]);
                        mat.M31 = float.Parse(data[8]); mat.M32 = float.Parse(data[9]); mat.M33 = float.Parse(data[10]); mat.M34 = float.Parse(data[11]);
                        mat.M41 = float.Parse(data[12]); mat.M42 = float.Parse(data[13]); mat.M43 = float.Parse(data[14]); mat.M44 = float.Parse(data[15]);
                    }
                    else if (node.Name.Equals("extra"))
                    {
                    }
                    else if (node.Name.Equals("instance_controller") || node.Name.Equals("instance_geometry"))
                    {
                        if (node.Name.Equals("instance_geometry"))
                        {
                            geom_id = node.Attributes["url"].Value.Replace("#", "");
                        }
                        foreach (XmlNode node1 in node.ChildNodes)
                        {
                            if (node1.Name.Equals("bind_material"))
                            {
                                foreach (XmlNode node2 in node1.ChildNodes)
                                {
                                    if (node2.Name.Equals("technique_common"))
                                    {
                                        if (node2.ChildNodes[0].Attributes["symbol"] != null && !materialIds.ContainsKey(node2.ChildNodes[0].Attributes["symbol"].Value))
                                        {
                                            materialIds.Add(node2.ChildNodes[0].Attributes["symbol"].Value, node2.ChildNodes[0].Attributes["target"].Value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (node.Name.Equals("translate"))
                    {
                        string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' ');
                        pos = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2]));
                    }
                    else if (node.Name.Equals("scale"))
                    {
                        string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' ');
                        scale = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2]));
                    }
                    else if (node.Name.Equals("rotate"))
                    {
                        string[] data = node.InnerText.Trim().Replace("\n", " ").Split(' ');
                        rot = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2]));
                    }
                }
            }
Ejemplo n.º 5
0
 public ColladaJoint(ref XmlTextReader reader, ColladaNode parent, ColladaScene scene)
     : base(ref reader, parent, scene)
 {
     //scene.nodes.Add(this);
 }
Ejemplo n.º 6
0
                public void resolveTarget()
                {
                    string[] tmpAry = targetString.Split('/');
                    targetObject = getNodeById(tmpAry[0]);

                    switch (tmpAry[1])
                    {
                        case "location":
                            targetValue = Target.location;
                            break;
                        case "rotationX.ANGLE":
                            targetValue = Target.rotationX;
                            break;
                        case "rotationY.ANGLE":
                            targetValue = Target.rotationY;
                            break;
                        case "rotationZ.ANGLE":
                            targetValue = Target.rotationZ;
                            break;
                        case "transform":
                            targetValue = Target.transform;
                            break;
                        default:
                            break;
                    }
                }
Ejemplo n.º 7
0
            private void genericAttributes(ref XmlTextReader reader)
            {
                if (reader.Name == "source" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaSource(ref reader, this, scene);
                }

                if (reader.Name == "vertices" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaVerts(ref reader, this, scene);
                }

                if (reader.Name == "library_animations" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaLibraryAnimation(ref reader, this, scene);
                }

                if (reader.Name == "animation" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaAnimation(ref reader, this, scene);
                }

                if (reader.Name == "controller" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaControler(ref reader, this, scene);
                }

                if (reader.Name == "polylist" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaPolys(ref reader, this, scene);
                }
                /*
                if (reader.Name == "visual_scene")
                {
                    ColladaObject newObj = new ColladaVScene(ref reader, this, scene);
                    scene.colladaObjects.Add(newObj);
                }
                */
                if (reader.Name == "vertex_weights" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaVertWeights(ref reader, this, scene);
                }

                if (reader.Name == "node" && reader.NodeType != XmlNodeType.EndElement)
                {
                    ColladaObject newObj = new ColladaNode(ref reader, this, scene);
                }

                if (reader.Name == "input")
                    inputs.Add(new ColladaInput(ref reader, this, scene));
            }
Ejemplo n.º 8
0
        public static ModelBoneData LoadNode(ModelData data, ModelBoneData parentBoneData, ColladaNode node, Matrix transform)
        {
            ModelBoneData modelBoneData = new ModelBoneData();

            data.Bones.Add(modelBoneData);
            modelBoneData.ParentBoneIndex = ((parentBoneData != null) ? data.Bones.IndexOf(parentBoneData) : (-1));
            modelBoneData.Name            = node.Name;
            modelBoneData.Transform       = node.Transform * transform;
            foreach (ColladaNode node2 in node.Nodes)
            {
                LoadNode(data, modelBoneData, node2, Matrix.Identity);
            }
            foreach (ColladaGeometry geometry in node.Geometries)
            {
                LoadGeometry(data, modelBoneData, geometry);
            }
            return(modelBoneData);
        }