Example #1
0
        public void ImportFolder(string inFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(inFolder);

            FileInfo[] files;

            files = dir.GetFiles();
            foreach (FileInfo info in files)
            {
                string ext = Path.GetExtension(info.FullName).ToUpper();
                if (ext == ".PNG" || ext == ".TGA" || ext == ".BMP" || ext == ".JPG" || ext == ".JPEG" || ext == ".GIF" || ext == ".TIF" || ext == ".TIFF")
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog())
                    {
                        dlg.ImageSource = info.FullName;
                        dlg.ShowDialog(null, this);
                    }
                }
                else if (ext == ".TEX0")
                {
                    TEX0Node node = NodeFactory.FromFile(null, info.FullName) as TEX0Node;
                    GetOrCreateFolder <TEX0Node>().AddChild(node);
                }
                else if (ext == ".MDL0")
                {
                    MDL0Node node = NodeFactory.FromFile(null, info.FullName) as MDL0Node;
                    GetOrCreateFolder <MDL0Node>().AddChild(node);
                }
                else if (ext == ".CHR0")
                {
                    CHR0Node node = NodeFactory.FromFile(null, info.FullName) as CHR0Node;
                    GetOrCreateFolder <CHR0Node>().AddChild(node);
                }
                else if (ext == ".CLR0")
                {
                    CLR0Node node = NodeFactory.FromFile(null, info.FullName) as CLR0Node;
                    GetOrCreateFolder <CLR0Node>().AddChild(node);
                }
                else if (ext == ".SRT0")
                {
                    SRT0Node node = NodeFactory.FromFile(null, info.FullName) as SRT0Node;
                    GetOrCreateFolder <SRT0Node>().AddChild(node);
                }
                else if (ext == ".SHP0")
                {
                    SHP0Node node = NodeFactory.FromFile(null, info.FullName) as SHP0Node;
                    GetOrCreateFolder <SHP0Node>().AddChild(node);
                }
                else if (ext == ".PAT0")
                {
                    PAT0Node node = NodeFactory.FromFile(null, info.FullName) as PAT0Node;
                    GetOrCreateFolder <PAT0Node>().AddChild(node);
                }
                else if (ext == ".VIS0")
                {
                    VIS0Node node = NodeFactory.FromFile(null, info.FullName) as VIS0Node;
                    GetOrCreateFolder <VIS0Node>().AddChild(node);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds an animation opened by the user to the end of this one
        /// </summary>
        public void Append()
        {
            SHP0Node       external = null;
            OpenFileDialog o        = new OpenFileDialog();

            o.Filter = "SHP0 Animation (*.shp0)|*.shp0";
            o.Title  = "Please select an animation to append.";
            if (o.ShowDialog() == DialogResult.OK)
            {
                if ((external = (SHP0Node)NodeFactory.FromFile(null, o.FileName)) != null)
                {
                    Append(external);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(SHP0Node external)
        {
            KeyframeEntry kfe;

            int origIntCount = FrameCount;

            FrameCount += external.FrameCount;

            foreach (SHP0EntryNode w in external.Children)
            {
                foreach (SHP0VertexSetNode extEntry in w.Children)
                {
                    SHP0VertexSetNode intEntry = null;
                    if ((intEntry = (SHP0VertexSetNode)FindChild(w.Name + "/" + extEntry.Name, false)) == null)
                    {
                        SHP0EntryNode wi = null;
                        if ((wi = (SHP0EntryNode)FindChild(w.Name, false)) == null)
                        {
                            AddChild(wi = new SHP0EntryNode()
                            {
                                Name = FindName(null), _flags = w._flags
                            });
                        }

                        SHP0VertexSetNode newIntEntry = new SHP0VertexSetNode(extEntry.Name);
                        newIntEntry.SetSize(extEntry.FrameCount + origIntCount, Loop);
                        for (int x = 0; x < extEntry.FrameCount; x++)
                        {
                            if ((kfe = extEntry.GetKeyframe(x)) != null)
                            {
                                newIntEntry.Keyframes.SetFrameValue(x + origIntCount, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                        wi.AddChild(newIntEntry);
                    }
                    else
                    {
                        for (int x = 0; x < extEntry.FrameCount; x++)
                        {
                            if ((kfe = extEntry.GetKeyframe(x)) != null)
                            {
                                intEntry.Keyframes.SetFrameValue(x + origIntCount, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                    }
                }
            }
        }
        //This only modifies vertices after ApplyCHR0 has weighted them.
        //It cannot be used without calling ApplyCHR0 first.
        public void ApplySHP(SHP0Node node, int index)
        {
            _currentSHP = node;
            _currentSHPIndex = index;

            if (node == null || index == 0)
                return;

            SHP0EntryNode n;

            if (_objList != null)
                foreach (MDL0ObjectNode poly in _objList)
                    if ((n = node.FindChild(poly.VertexNode, true) as SHP0EntryNode) != null)
                    {
                        //Max amount of morphs allowed is 32
                        float[] weights = new float[n.Children.Count];
                        MDL0VertexNode[] nodes = new MDL0VertexNode[n.Children.Count];

                        foreach (SHP0VertexSetNode v in n.Children)
                        {
                            MDL0VertexNode vNode = null;
                            foreach (MDL0VertexNode vn in _vertList)
                                if (vn.Name == v.Name)
                                { vNode = vn; break; }

                            weights[v.Index] = vNode != null ? v.Keyframes.GetFrameValue(index - 1, SHP0VertexSetNode._linear) : 0;
                            nodes[v.Index] = vNode;
                        }

                        float totalWeight = 0;
                        foreach (float f in weights)
                            totalWeight += f;

                        float baseWeight = 1.0f - totalWeight;

                        //Calculate barycenter per vertex and set as weighted pos
                        for (int i = 0; i < poly._manager._vertices.Count; i++)
                        {
                            int x = 0;
                            Vertex3 v3 = poly._manager._vertices[i];
                            v3._weightedPosition *= baseWeight;

                            foreach (MDL0VertexNode vNode in nodes)
                                if (vNode != null)
                                    v3._weightedPosition += (v3.GetMatrix() * vNode.Vertices[v3._facepoints[0]._vertexIndex]) * weights[x++];

                            v3._weightedPosition /= (totalWeight + baseWeight);

                            v3.weights = weights;
                            v3.nodes = nodes;
                            v3.baseWeight = baseWeight;
                            v3.bCenter = v3._weightedPosition;
                        }
                    }
        }
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(SHP0Node external)
        {
            KeyframeEntry kfe;

            int origIntCount = FrameCount;
            FrameCount += external.FrameCount;

            foreach (SHP0EntryNode w in external.Children)
                foreach (SHP0VertexSetNode _extEntry in w.Children)
                {
                    SHP0VertexSetNode _intEntry = null;
                    if ((_intEntry = (SHP0VertexSetNode)FindChild(w.Name + "/" + _extEntry.Name, false)) == null)
                    {
                        SHP0EntryNode wi = null;
                        if ((wi = (SHP0EntryNode)FindChild(w.Name, false)) == null)
                            AddChild(wi = new SHP0EntryNode() { Name = FindName(null), _flags = w._flags });

                        SHP0VertexSetNode newIntEntry = new SHP0VertexSetNode(_extEntry.Name);
                        newIntEntry._numFrames = _extEntry.FrameCount + origIntCount;
                        for (int x = 0; x < _extEntry.FrameCount; x++)
                                if ((kfe = _extEntry.GetKeyframe(x)) != null)
                                    newIntEntry.Keyframes.SetFrameValue(x + origIntCount, kfe._value)._tangent = kfe._tangent;
                        wi.AddChild(newIntEntry);
                    }
                    else
                        for (int x = 0; x < _extEntry.FrameCount; x++)
                            if ((kfe = _extEntry.GetKeyframe(x)) != null)
                                _intEntry.Keyframes.SetFrameValue(x + origIntCount, kfe._value)._tangent = kfe._tangent;
                }
        }