예제 #1
0
        public NJS_MESHSET Clone()
        {
            NJS_MESHSET result = (NJS_MESHSET)MemberwiseClone();
            List <Poly> polys  = new List <Poly>(Poly.Count);

            foreach (Poly item in Poly)
            {
                polys.Add(item.Clone());
            }
            result.Poly = new ReadOnlyCollection <Poly>(polys);
            if (PolyNormal != null)
            {
                result.PolyNormal = new Vertex[PolyNormal.Length];
                for (int i = 0; i < PolyNormal.Length; i++)
                {
                    result.PolyNormal[i] = PolyNormal[i].Clone();
                }
            }
            if (VColor != null)
            {
                result.VColor = (Color[])VColor.Clone();
            }
            if (UV != null)
            {
                result.UV = new UV[UV.Length];
                for (int i = 0; i < UV.Length; i++)
                {
                    result.UV[i] = UV[i].Clone();
                }
            }
            return(result);
        }
예제 #2
0
        public BasicAttach(byte[] file, int address, uint imageBase, bool DX, Dictionary <int, string> labels)
            : this()
        {
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "attach_" + address.ToString("X8");
            }
            Vertex = new Vertex[ByteConverter.ToInt32(file, address + 8)];
            Normal = new Vertex[Vertex.Length];
            int tmpaddr = (int)(ByteConverter.ToUInt32(file, address) - imageBase);

            if (labels.ContainsKey(tmpaddr))
            {
                VertexName = labels[tmpaddr];
            }
            else
            {
                VertexName = "vertex_" + tmpaddr.ToString("X8");
            }
            for (int i = 0; i < Vertex.Length; i++)
            {
                Vertex[i] = new Vertex(file, tmpaddr);
                tmpaddr  += SAModel.Vertex.Size;
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 4);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    NormalName = labels[tmpaddr];
                }
                else
                {
                    NormalName = "normal_" + tmpaddr.ToString("X8");
                }
                for (int i = 0; i < Vertex.Length; i++)
                {
                    Normal[i] = new Vertex(file, tmpaddr);
                    tmpaddr  += SAModel.Vertex.Size;
                }
            }
            else
            {
                for (int i = 0; i < Vertex.Length; i++)
                {
                    Normal[i] = new Vertex(0, 1, 0);
                }
            }
            int maxmat  = -1;
            int meshcnt = ByteConverter.ToInt16(file, address + 0x14);

            tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    MeshName = labels[tmpaddr];
                }
                else
                {
                    MeshName = "meshlist_" + tmpaddr.ToString("X8");
                }
                for (int i = 0; i < meshcnt; i++)
                {
                    Mesh.Add(new NJS_MESHSET(file, tmpaddr, imageBase, labels));
                    maxmat   = Math.Max(maxmat, Mesh[i].MaterialID);
                    tmpaddr += NJS_MESHSET.Size(DX);
                }
            }
            // fixes case where model declares material array as shorter than it really is
            int matcnt = Math.Max(ByteConverter.ToInt16(file, address + 0x16), maxmat + 1);

            tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    MaterialName = labels[tmpaddr];
                }
                else
                {
                    MaterialName = "matlist_" + tmpaddr.ToString("X8");
                }
                for (int i = 0; i < matcnt; i++)
                {
                    Material.Add(new NJS_MATERIAL(file, tmpaddr, labels));
                    tmpaddr += NJS_MATERIAL.Size;
                }
            }
            Bounds = new BoundingSphere(file, address + 0x18);
        }