Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="node">Parent Node</param>
        /// <param name="Model">Sharp Model</param>
        public Node(SharpDevice device, ModelNode node, SharpModel Model)
        {
            Name = node.Name;
            World = node.World;
            PreComputed = this.World;
            Children = new List<Node>();

            //Create Child Nodes
            foreach (var m in node.Children)
            {
                var c = new Node(device, m, Model);
                c.Parent = this;
                Children.Add(c);
            }

            //Create Node Geometries
            foreach (var g in node.Geometries)
            {
                var g3d = new Geometry(device, g, node.Skinning != null);
                g3d.Node = this;
                Model.Geometries.Add(g3d);
            }

            //Get Skinning Data
            if (node.Skinning != null)
            {
                Skinning = new SkinData()
                {
                    BindMatrix = node.Skinning.BindMatrix,
                    InverseBindMatrix = new List<Matrix>(node.Skinning.InverseBinding),
                    JointNames = new List<string>(node.Skinning.JointNames),
                };
            }
        }
Ejemplo n.º 2
0
        private static ModelNode LoadNodes(XElement element, SemanticAssociations association)
        {
            ModelNode node = new ModelNode();

            node.Name = element.GetAttribute("id");

            //type
            string type = element.GetAttribute("type").ToLower();
            if (string.IsNullOrEmpty(type) || type == "node")
                node.Type = NodeType.Node;
            else
                node.Type = NodeType.Joint;

            //world matrix
            node.World = ComputeMatrix(element);

            //Iterate each node
            foreach (XElement c in element.GetChildren("node"))
            {
                //Load Children
                node.Children.Add(LoadNodes(c, association));
            }

            //Iterate Geometries
            foreach (XElement g in element.GetNodes("instance_geometry"))
            {
                node.Geometries.AddRange(LoadGeometries(g.GetReference(), association));
            }

            //Get Animation Controller
            foreach (XElement c in element.GetNodes("instance_controller"))
            {
                SkinInformation skin;
                node.Geometries.AddRange(LoadController(c, association, out skin));
                node.Skinning = skin;
            }

            return node;
        }