Esempio n. 1
0
 private void ProcessShapeMotionVertexData(NJS_MOTION motion, float frame, ref int animindex)
 {
     if (Morph)
     {
         animindex++;
     }
     if (Attach != null)
     {
         Attach.ProcessShapeMotionVertexData(motion, frame, animindex);
     }
     foreach (NJS_OBJECT item in Children)
     {
         item.ProcessShapeMotionVertexData(motion, frame, ref animindex);
     }
 }
Esempio n. 2
0
        public void ProcessVertexData()
        {
#if modellog
            Extensions.Log("Processing Object " + Name + Environment.NewLine);
#endif
            if (Attach != null)
            {
                Attach.ProcessVertexData();
            }
            foreach (NJS_OBJECT item in Children)
            {
                item.ProcessVertexData();
            }
            if (Parent == null && Sibling != null)
            {
                Sibling.ProcessVertexData();
            }
        }
Esempio n. 3
0
        public byte[] NJGetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, List <uint> njOffsets, out uint address)
        {
            List <byte> result = new List <byte>();
            ObjectFlags flags  = GetFlags();

            FixSiblings();
            int attachAddressAddress  = result.Count + 0x4;
            int childAddressAddress   = result.Count + 0x2C;
            int siblingAddressAddress = result.Count + 0x30;

            address = 0;
            result.AddRange(ByteConverter.GetBytes((int)flags));
            result.AddRange(ByteConverter.GetBytes(0));             //Attach placeholder
            result.AddRange(Position.GetBytes());
            result.AddRange(Rotation.GetBytes());
            result.AddRange(Scale.GetBytes());
            result.AddRange(ByteConverter.GetBytes(0));             //Child placeholder
            result.AddRange(ByteConverter.GetBytes(0));             //Sibling placeholder
            result.Align(4);

            int currentEnd = result.Count;

            if (Attach != null)
            {
                if (labels.ContainsKey(Attach.Name))
                {
                    int attachAddress = (int)labels[Attach.Name];
                    result.SetByteListInt(attachAddressAddress, attachAddress);
                }
                else
                {
                    result.AddRange(Attach.GetBytes((uint)(imageBase + result.Count), DX, labels, njOffsets, out uint attachAddress));
                    result.SetByteListInt(attachAddressAddress, (int)(imageBase + currentEnd + attachAddress));
                    njOffsets.Add((uint)(imageBase + attachAddressAddress));
                    result.Align(4);
                    currentEnd = result.Count;
                }
            }
            if (Children.Count > 0)
            {
                if (labels.ContainsKey(Children[0].Name))
                {
                    int childAddress = (int)labels[Children[0].Name];
                    result.SetByteListInt(childAddressAddress, childAddress);
                }
                else
                {
                    result.AddRange(Children[0].NJGetBytes((uint)(imageBase + result.Count), DX, labels, njOffsets, out uint childAddress));
                    result.SetByteListInt(childAddressAddress, (int)(imageBase + currentEnd + childAddress));
                    njOffsets.Add((uint)(imageBase + childAddressAddress));
                    result.Align(4);
                    currentEnd = result.Count;
                }
            }
            if (Sibling != null)
            {
                if (labels.ContainsKey(Sibling.Name))
                {
                    int siblingAddress = (int)labels[Sibling.Name];
                    result.SetByteListInt(siblingAddressAddress, siblingAddress);
                }
                else
                {
                    result.AddRange(Sibling.NJGetBytes((uint)(imageBase + result.Count), DX, labels, njOffsets, out uint siblingAddress));
                    result.SetByteListInt(siblingAddressAddress, (int)(imageBase + currentEnd + siblingAddress));
                    njOffsets.Add((uint)(imageBase + siblingAddressAddress));
                    result.Align(4);
                }
            }

            labels.Add(Name, address + imageBase);

            return(result.ToArray());
        }
Esempio n. 4
0
        public byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, List <uint> njOffsets, out uint address, bool isFirst = false)
        {
            List <byte> result = new List <byte>();

            if (isFirst)
            {
                result.AddRange(new byte[0x34]);                 //Add size of NGS_OBJECT if first since we're inserting later
            }
            FixSiblings();
            uint childaddr   = 0;
            uint siblingaddr = 0;
            uint attachaddr  = 0;

            byte[] tmpbyte;
            if (Children.Count > 0)
            {
                if (labels.ContainsKey(Children[0].Name))
                {
                    childaddr = labels[Children[0].Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte    = Children[0].GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out childaddr);
                    childaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            if (Sibling != null)
            {
                if (labels.ContainsKey(Sibling.Name))
                {
                    siblingaddr = labels[Sibling.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte      = Sibling.GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out siblingaddr);
                    siblingaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            if (Attach != null)
            {
                if (labels.ContainsKey(Attach.Name))
                {
                    attachaddr = labels[Attach.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte     = Attach.GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out attachaddr);
                    attachaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }

            result.Align(4);
            address = isFirst ? 0 : (uint)result.Count;
            ObjectFlags flags    = GetFlags();
            List <byte> objBytes = new List <byte>();

            objBytes.AddRange(ByteConverter.GetBytes((int)flags));
            objBytes.AddRange(ByteConverter.GetBytes(attachaddr));
            objBytes.AddRange(Position.GetBytes());
            objBytes.AddRange(Rotation.GetBytes());
            objBytes.AddRange(Scale.GetBytes());
            objBytes.AddRange(ByteConverter.GetBytes(childaddr));
            objBytes.AddRange(ByteConverter.GetBytes(siblingaddr));

            if (isFirst)             //Formal ninja requires the initial object first since there's not a pointer to it
            {
                //POF0
                if (attachaddr != 0)
                {
                    njOffsets.Add(0x4);
                }
                if (childaddr != 0)
                {
                    njOffsets.Add(0x2C);
                }
                if (siblingaddr != 0)
                {
                    njOffsets.Add(0x30);
                }

                result.RemoveRange(0, 0x34);
                result.InsertRange(0, objBytes);
            }
            else
            {
                //POF0
                if (attachaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }
                if (childaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }
                if (siblingaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }

                result.AddRange(objBytes);
            }
            labels.Add(Name, address + imageBase);
            return(result.ToArray());
        }
Esempio n. 5
0
        private NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, NJS_OBJECT parent, Dictionary <int, string> labels, Dictionary <int, Attach> attaches)
        {
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "object_" + address.ToString("X8");
            }
            if (address > file.Length - 52)
            {
                Position = new Vertex();
                Rotation = new Rotation();
                Scale    = new Vertex(1, 1, 1);
                children = new List <NJS_OBJECT>();
                Children = new ReadOnlyCollection <NJS_OBJECT>(children);
                return;
            }
            ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address);

            RotateZYX      = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX;
            SkipDraw       = (flags & ObjectFlags.NoDisplay) == ObjectFlags.NoDisplay;
            SkipChildren   = (flags & ObjectFlags.NoChildren) == ObjectFlags.NoChildren;
            IgnorePosition = (flags & ObjectFlags.NoPosition) == ObjectFlags.NoPosition;
            IgnoreRotation = (flags & ObjectFlags.NoRotate) == ObjectFlags.NoRotate;
            IgnoreScale    = (flags & ObjectFlags.NoScale) == ObjectFlags.NoScale;
            Animate        = (flags & ObjectFlags.NoAnimate) == 0;
            Morph          = (flags & ObjectFlags.NoMorph) == 0;
            int tmpaddr = ByteConverter.ToInt32(file, address + 4);

            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (attaches != null && attaches.ContainsKey(tmpaddr))
                {
                    Attach = attaches[tmpaddr];
                }
                else
                {
                    Attach = Attach.Load(file, tmpaddr, imageBase, format, labels);
                    if (attaches != null)
                    {
                        attaches.Add(tmpaddr, Attach);
                    }
                }
            }
            Position = new Vertex(file, address + 8);
            Rotation = new Rotation(file, address + 0x14);
            Scale    = new Vertex(file, address + 0x20);
            Parent   = parent;
            children = new List <NJS_OBJECT>();
            Children = new ReadOnlyCollection <NJS_OBJECT>(children);
            NJS_OBJECT child = null;

            tmpaddr = ByteConverter.ToInt32(file, address + 0x2C);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                child   = new NJS_OBJECT(file, tmpaddr, imageBase, format, this, labels, attaches);
            }
            while (child != null)
            {
                children.Add(child);
                child = child.Sibling;
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 0x30);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                Sibling = new NJS_OBJECT(file, tmpaddr, imageBase, format, parent, labels, attaches);
            }

            //Assimp.AssimpContext context = new AssimpContext();
            //Scene scene = context.ImportFile("F:\\untitled.obj", PostProcessSteps.Triangulate);
            //AssimpLoad(scene, scene.RootNode);
        }