示例#1
0
        private NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, NJS_OBJECT parent, Dictionary <int, string> labels)
        {
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "object_" + address.ToString("X8");
            }
            ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address);

            RotateZYX = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX;
            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);
                Attach  = Attach.Load(file, tmpaddr, imageBase, format, labels);
            }
            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);
            }
            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);
            }

            //Assimp.AssimpContext context = new AssimpContext();
            //Scene scene = context.ImportFile("F:\\untitled.obj", PostProcessSteps.Triangulate);
            //AssimpLoad(scene, scene.RootNode);
        }
示例#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();
            }
        }
示例#3
0
 private void ProcessShapeMotionVertexData(NJS_MOTION motion, int 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);
     }
 }
示例#4
0
        public NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary <int, string> labels)
        {
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "object_" + address.ToString("X8");
            }
            ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address);

            RotateZYX = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX;
            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);
                Attach  = Attach.Load(file, tmpaddr, imageBase, format, labels);
            }
            Position = new Vertex(file, address + 8);
            Rotation = new Rotation(file, address + 0x14);
            Scale    = new Vertex(file, address + 0x20);
            Children = new List <NJS_OBJECT>();
            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, labels);
            }
            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, labels);
            }
        }
示例#5
0
        public NJS_OBJECT ToChunkModel()
        {
            List <NJS_OBJECT> newchildren = new List <NJS_OBJECT>(Children.Count);

            foreach (NJS_OBJECT item in Children)
            {
                newchildren.Add(item.ToBasicModel());
            }
            NJS_OBJECT result = new NJS_OBJECT();

            if (Attach != null)
            {
                result.Attach = Attach.ToChunkModel();
            }
            result.Position = Position;
            result.Rotation = Rotation;
            result.Scale    = Scale;
            result.Children = newchildren;
            return(result);
        }
示例#6
0
        public byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, out uint address)
        {
            FixSiblings();
            List <byte> result      = new List <byte>();
            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);
                    result.AddRange(Children[0].GetBytes(imageBase, DX, labels, out childaddr));
                    childaddr += imageBase;
                }
            }
            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, 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, out attachaddr);
                    attachaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            result.Align(4);
            address = (uint)result.Count;
            ObjectFlags flags = GetFlags();

            result.AddRange(ByteConverter.GetBytes((int)flags));
            result.AddRange(ByteConverter.GetBytes(attachaddr));
            result.AddRange(Position.GetBytes());
            result.AddRange(Rotation.GetBytes());
            result.AddRange(Scale.GetBytes());
            result.AddRange(ByteConverter.GetBytes(childaddr));
            result.AddRange(ByteConverter.GetBytes(siblingaddr));
            labels.Add(Name, address + imageBase);
            return(result.ToArray());
        }