Esempio n. 1
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            System.Drawing.Point targetPoint = treeView1.PointToClient(new System.Drawing.Point(e.X, e.Y));

            TreeNode targetNode = treeView1.GetNodeAt(targetPoint);

            TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(Bone));

            if (!draggedNode.Equals(targetNode) && targetNode != null && !IsAChildOfB(targetNode, draggedNode))
            {
                int oldParent = (int)vbn.bones[vbn.boneIndex(draggedNode.Text)].parentIndex;
                //VBN.bones[oldParent].children.Remove(VBN.boneIndex(draggedNode.Text));
                int  newParent = vbn.boneIndex(targetNode.Text);
                Bone temp      = vbn.bones[vbn.boneIndex(draggedNode.Text)];
                temp.parentIndex = (int)newParent;
                vbn.bones[vbn.boneIndex(draggedNode.Text)] = temp;
                //VBN.bones[newParent].children.Add(VBN.boneIndex(draggedNode.Text));

                draggedNode.Remove();
                targetNode.Nodes.Add(draggedNode);

                targetNode.Expand();
                Edited = true;
            }
            if (targetNode == null)
            {
                draggedNode.Remove();
                treeView1.Nodes.Add(draggedNode);
                Edited = true;
            }
            vbn.reset();
        }
Esempio n. 2
0
        // I'm completely totally serious

        public static Nud Create(VBN vbn)
        {
            Dictionary <string, string> files = new Dictionary <string, string>();
            ZipArchive zip = ZipFile.OpenRead("lib\\Skapon.zip");

            Random random       = new Random();
            int    randomNumber = random.Next(0, 0xFFFFFF);

            NUT nut = new NUT();

            foreach (ZipArchiveEntry e in zip.Entries)
            {
                byte[] b;
                using (BinaryReader br = new BinaryReader(e.Open()))
                {
                    b = br.ReadBytes((int)e.Length);
                }
                var    stream = new StreamReader(new MemoryStream(b));
                string s      = stream.ReadToEnd();
                files.Add(e.Name, s);

                if (e.Name.EndsWith(".dds"))
                {
                    NutTexture tex = new Dds(new FileData(b)).ToNutTexture();
                    nut.Nodes.Add(tex);
                    tex.HashId = 0x40000000 + randomNumber;
                    nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                }
            }

            Nud nud = new Nud();

            Nud.Mesh head = new Nud.Mesh();
            nud.Nodes.Add(head);
            head.Text = "Skapon";

            head.Nodes.Add(setToBone(scale(readPoly(files["head.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("HeadN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["body.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("BustN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), -1, -1, 1), vbn.bones[vbn.boneIndex("LHandN")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RFootJ")], vbn));
            head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), -1, -1, -1), vbn.bones[vbn.boneIndex("LFootJ")], vbn));

            foreach (Nud.Polygon p in head.Nodes)
            {
                p.materials[0].textures[0].hash = 0x40000000 + randomNumber;
            }

            nud.UpdateRenderMeshes();

            return(nud);
        }
Esempio n. 3
0
        public void CreateAnim(string fname, VBN vbn)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname))
            {
                file.WriteLine("animVersion 1.1;");
                file.WriteLine("mayaVersion 2014 x64;\ntimeUnit ntscf;\nlinearUnit cm;\nangularUnit deg;\nstartTime 1;\nendTime " + (anim.frameCount + 1) + ";");

                int i = 0;

                // writing node attributes
                foreach (Bone b in vbn.getBoneTreeOrder())
                {
                    i = vbn.boneIndex(b.Text);

                    if (i < anim.nodes.Count)
                    {
                        // write the bone attributes
                        // count the attributes
                        List <DAT_Animation.DATAnimTrack> tracks = anim.nodes[i];

                        int tracknum = 0;
                        if (tracks.Count == 0)
                        {
                            file.WriteLine("anim " + b.Text + " 0 0 0;");
                        }

                        foreach (DAT_Animation.DATAnimTrack track in tracks)
                        {
                            switch (track.type)
                            {
                            case DAT_Animation.AnimType.XPOS:
                                file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;

                            case DAT_Animation.AnimType.YPOS:
                                file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;

                            case DAT_Animation.AnimType.ZPOS:
                                file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;

                            case DAT_Animation.AnimType.XROT:
                                file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, true);
                                break;

                            case DAT_Animation.AnimType.YROT:
                                file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, true);
                                break;

                            case DAT_Animation.AnimType.ZROT:
                                file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, true);
                                break;

                            case DAT_Animation.AnimType.XSCA:
                                file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;

                            case DAT_Animation.AnimType.YSCA:
                                file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;

                            case DAT_Animation.AnimType.ZSCA:
                                file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (tracknum++) + ";");
                                WriteAnimKey(file, i, track, false);
                                break;
                            }
                        }
                    }
                    else
                    {
                        file.WriteLine("anim " + b.Text + " 0 0 0;");
                    }
                }
            }
        }
Esempio n. 4
0
        public Animation ToAnimation(VBN vbn)
        {
            Animation animation = new Animation(anim.Name);

            animation.frameCount = anim.frameCount;

            int i = 0;

            foreach (Bone b in vbn.bones)
            {
                i = vbn.boneIndex(b.Text);

                if (i < anim.nodes.Count)
                {
                    List <DAT_Animation.DATAnimTrack> tracks = anim.nodes[i];

                    Animation.KeyNode node = new Animation.KeyNode(b.Text);
                    node.rotType = Animation.RotationType.Euler;

                    foreach (DAT_Animation.DATAnimTrack track in tracks)
                    {
                        switch (track.type)
                        {
                        case DAT_Animation.AnimType.XPOS:
                            node.xpos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YPOS:
                            node.ypos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZPOS:
                            node.zpos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.XROT:
                            node.xrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YROT:
                            node.yrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZROT:
                            node.zrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.XSCA:
                            node.xsca = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YSCA:
                            node.ysca = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZSCA:
                            node.zsca = CreateKeyGroup(i, track, false);
                            break;
                        }
                    }

                    if (node.xsca.HasAnimation() || node.ysca.HasAnimation() || node.zsca.HasAnimation() ||
                        node.xpos.HasAnimation() || node.ypos.HasAnimation() || node.zpos.HasAnimation() ||
                        node.xrot.HasAnimation() || node.yrot.HasAnimation() || node.zrot.HasAnimation())
                    {
                        animation.bones.Add(node);
                    }
                }
            }

            return(animation);
        }
Esempio n. 5
0
        public static void CreateANIM(string fname, Animation a, VBN vbn)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname))
            {
                AnimHeader header = new AnimHeader();
                file.WriteLine("animVersion " + header.animVersion + ";");
                file.WriteLine("mayaVersion " + header.mayaVersion + ";");
                file.WriteLine("timeUnit " + header.timeUnit + ";");
                file.WriteLine("linearUnit " + header.linearUnit + ";");
                file.WriteLine("angularUnit " + header.angularUnit + ";");
                file.WriteLine("startTime " + 1 + ";");
                file.WriteLine("endTime " + a.frameCount + ";");

                a.SetFrame(a.frameCount - 1);             //from last frame
                for (int li = 0; li < a.frameCount; ++li) //go through each frame with nextFrame
                {
                    a.NextFrame(vbn);
                }
                a.NextFrame(vbn);  //go on first frame

                int i = 0;

                // writing node attributes
                foreach (Bone b in vbn.getBoneTreeOrder())
                {
                    i = vbn.boneIndex(b.Text);

                    if (a.HasBone(b.Text))
                    {
                        // write the bone attributes
                        // count the attributes
                        Animation.KeyNode n = a.GetBone(b.Text);
                        int ac = 0;

                        if (n.xpos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xpos, n, a.Size(), "translateX");
                            file.WriteLine("}");
                        }
                        if (n.ypos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.ypos, n, a.Size(), "translateY");
                            file.WriteLine("}");
                        }
                        if (n.zpos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zpos, n, a.Size(), "translateZ");
                            file.WriteLine("}");
                        }
                        if (n.xrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xrot, n, a.Size(), "rotateX");
                            file.WriteLine("}");
                        }
                        if (n.yrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.yrot, n, a.Size(), "rotateY");
                            file.WriteLine("}");
                        }
                        if (n.zrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zrot, n, a.Size(), "rotateZ");
                            file.WriteLine("}");
                        }
                        if (n.xsca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xsca, n, a.Size(), "scaleX");
                            file.WriteLine("}");
                        }
                        if (n.ysca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.ysca, n, a.Size(), "scaleY");
                            file.WriteLine("}");
                        }
                        if (n.zsca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zsca, n, a.Size(), "scaleZ");
                            file.WriteLine("}");
                        }

                        if (ac == 0)
                        {
                            file.WriteLine("anim " + b.Text + " 0 0 0;");
                        }
                    }
                    else
                    {
                        file.WriteLine("anim " + b.Text + " 0 0 0;");
                    }
                }
            }
        }