public DNode(DNode copy)
 {
     this.Name = copy.Name;
     this.Parent_NodeIndex = copy.Parent_NodeIndex;
     this.FirstChild_NodeIndex = copy.FirstChild_NodeIndex;
     this.NextSibling_NodeIndex = copy.NextSibling_NodeIndex;
     this.Rotation = copy.Rotation;
     this.Position = copy.Position;
     this.Scale = copy.Scale;
     this.Right = copy.Right;
     this.Up = copy.Up;
     this.Forward = copy.Forward;
     this.AbsolutePosition = copy.AbsolutePosition;
 }
Exemple #2
0
        private Collada141.node[] ParseNode(DNode dNode)
        {
            Matrix4 matrix = Matrix4.CreateTranslation(dNode.Position);

            List<Collada141.node> nodes = new List<Collada141.node>();

            if (dNode.NextSibling_NodeIndex != -1) nodes.AddRange(ParseNode(this.Nodes[dNode.NextSibling_NodeIndex]));

            var location = dNode.Position;
            var rotation = Matrix4.Rotate(dNode.Rotation);

            var current_node = new Collada141.node()
            {
                type = Collada141.NodeType.JOINT,
                name = "bone",
                sid = "bone",
                Items = new object[]{
                    new Collada141.TargetableFloat3() { sid = "location", Values = dNode.Position.ToArray() },
                    new Collada141.matrix(){ sid = "rotation", Values = Matrix4ToFloatArray(rotation) },
                    new Collada141.TargetableFloat3() { sid = "scale", Values =new double[] { 1f, 1f, 1f} },
                },
                ItemsElementName = new Collada141.ItemsChoiceType2[]{
                    Collada141.ItemsChoiceType2.translate,
                    Collada141.ItemsChoiceType2.matrix,
                    Collada141.ItemsChoiceType2.scale
                }
            };

            if (dNode.FirstChild_NodeIndex != -1) current_node.node1 = ParseNode(this.Nodes[dNode.FirstChild_NodeIndex]);

            nodes.Add(current_node);

            return nodes.ToArray();
        }
Exemple #3
0
        private void RenderNodes(DNode parent, DNode node)
        {
            /* Intent: render the current node (root) at its position,
             * then push all the nodes translations onto the stack and render the next child node
             * */
            var transformed = new DNode(parent);
            transformed.Position += node.Position;
            transformed.Rotation *= node.Rotation;
            var rotations = Matrix4.Rotate(transformed.Rotation);
            GL.Color4(Color4.Yellow);
            GL.Vertex3(transformed.Position);
            Vector3 pointer = new Vector3();

            pointer = Vector3.TransformVector(node.Up, rotations);
            pointer.Normalize();
            pointer *= 2 * unit_length;
            GL.Vertex3(transformed.Position + pointer);

            GL.Color4(Color4.Red);
            GL.Vertex3(transformed.Position);
            GL.Vertex3(transformed.Position + node.Up * unit_length);
            GL.Color4(Color4.Blue);
            GL.Vertex3(transformed.Position);
            GL.Vertex3(transformed.Position + node.Right * unit_length);
            GL.Color4(Color4.Green);
            GL.Vertex3(transformed.Position);
            GL.Vertex3(transformed.Position + node.Forward * unit_length);

            GL.Color4(Color4.DarkMagenta);
            GL.Vertex3(transformed.Position);
            GL.Vertex3(transformed.AbsolutePosition);

            if (node.FirstChild_NodeIndex != -1)
            {
                var next_node = new DNode(model.Nodes[node.FirstChild_NodeIndex]);
                var p_copy = new DNode(transformed);
                RenderNodes(p_copy, next_node);
            }
            if (node.NextSibling_NodeIndex != -1)
            {
                var sibling_node = new DNode(model.Nodes[node.NextSibling_NodeIndex]);
                RenderNodes(parent, sibling_node);
            }
        }
Exemple #4
0
 private Collada141.node GenerateColladaNode(DNode dNode)
 {
     var mat = Matrix4.Translation(dNode.Position);
     mat *= Matrix4.Rotate(dNode.Rotation);
     //Root node
     Collada141.node node = new Collada141.node()
     {
         name = "Armature",
         id = "Armature",
         type = Collada141.NodeType.NODE,
         Items = new object[] {
             new Collada141.TargetableFloat3() { sid = "location", Values = new double[]{ dNode.Position.X,  dNode.Position.Y,  dNode.Position.Z } },
             new Collada141.rotate(){ sid = "rotationX", Values =new double[]{ 1f, 0f, 0f } },
             new Collada141.rotate(){ sid = "rotationY", Values =new double[]{ 0f, 1f, 0f } },
             new Collada141.rotate(){ sid = "rotationZ", Values =new double[]{ 0f, 0f, 1f } },
             new Collada141.TargetableFloat3() { sid = "scale", Values =new double[] { 1f, 1f, 1f} },
         },
         ItemsElementName = new Collada141.ItemsChoiceType2[]{
             Collada141.ItemsChoiceType2.translate,
             Collada141.ItemsChoiceType2.rotate,
             Collada141.ItemsChoiceType2.rotate,
             Collada141.ItemsChoiceType2.rotate,
             Collada141.ItemsChoiceType2.scale
         },
         node1 = ParseNode(dNode)
     };
     return node;
 }