Esempio n. 1
0
        public NJS_MESHSET(Poly[] polys, bool hasPolyNormal, bool hasUV, bool hasVColor)
        {
            PolyName = "poly_" + Extensions.GenerateIdentifier();
            PolyType = polys[0].PolyType;
            int striptotal = 0;

            for (int i = 0; i < polys.Length; i++)
            {
                striptotal += polys[i].Indexes.Length;
            }
            Poly = new ReadOnlyCollection <Poly>(polys);
            if (hasVColor)
            {
                VColorName = "vcolor_" + Extensions.GenerateIdentifier();
                VColor     = new Color[striptotal];
            }
            if (hasUV)
            {
                UVName = "uv_" + Extensions.GenerateIdentifier();
                UV     = new UV[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    UV[i] = new UV();
                }
            }
        }
Esempio n. 2
0
 public NJS_OBJECT()
 {
     Name     = "object_" + Extensions.GenerateIdentifier();
     Position = new Vertex();
     Rotation = new Rotation();
     Scale    = new Vertex(1, 1, 1);
     Children = new List <NJS_OBJECT>();
 }
Esempio n. 3
0
 public LandTable()
 {
     Name     = "landtable_" + Extensions.GenerateIdentifier();
     COL      = new List <COL>();
     COLName  = "collist_" + Extensions.GenerateIdentifier();
     Anim     = new List <GeoAnimData>();
     AnimName = "animlist_" + Extensions.GenerateIdentifier();
     Metadata = new Dictionary <uint, byte[]>();
 }
Esempio n. 4
0
        public BasicAttach(Vertex[] vertex, Vertex[] normal, IEnumerable <NJS_MESHSET> mesh, IEnumerable <NJS_MATERIAL> material)
            : this()
        {
            Vertex   = vertex;
            Normal   = normal;
            Mesh     = new List <NJS_MESHSET>(mesh);
            Material = new List <NJS_MATERIAL>(material);

            Name = "attach_" + Extensions.GenerateIdentifier();
        }
Esempio n. 5
0
 public BasicAttach()
 {
     Name         = "attach_" + Extensions.GenerateIdentifier();
     Bounds       = new BoundingSphere();
     Material     = new List <NJS_MATERIAL>();
     MaterialName = "matlist_" + Extensions.GenerateIdentifier();
     Mesh         = new List <NJS_MESHSET>();
     MeshName     = "meshlist_" + Extensions.GenerateIdentifier();
     Vertex       = new Vertex[0];
     VertexName   = "vertex_" + Extensions.GenerateIdentifier();
     Normal       = new Vertex[0];
     NormalName   = "normal_" + Extensions.GenerateIdentifier();
 }
Esempio n. 6
0
 public ChunkAttach(bool hasVertex, bool hasPoly)
     : this()
 {
     if (hasVertex)
     {
         Vertex     = new List <VertexChunk>();
         VertexName = "vertex_" + Extensions.GenerateIdentifier();
     }
     if (hasPoly)
     {
         Poly     = new List <PolyChunk>();
         PolyName = "poly_" + Extensions.GenerateIdentifier();
     }
 }
Esempio n. 7
0
        public NJS_MESHSET(Basic_PolyType polyType, int polyCount, bool hasPolyNormal, bool hasUV, bool hasVColor)
        {
            if (polyType == Basic_PolyType.NPoly | polyType == Basic_PolyType.Strips)
            {
                throw new ArgumentException("Cannot create a Poly of that type!\nTry another overload to create Strip-type Polys.", "polyType");
            }
            PolyName = "poly_" + Extensions.GenerateIdentifier();
            PolyType = polyType;
            Poly[] polys      = new Poly[polyCount];
            int    striptotal = 0;

            for (int i = 0; i < polys.Length; i++)
            {
                polys[i]    = SAModel.Poly.CreatePoly(PolyType);
                striptotal += polys[i].Indexes.Length;
            }
            Poly = new ReadOnlyCollection <Poly>(polys);
            if (hasPolyNormal)
            {
                PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
                PolyNormal     = new Vertex[polys.Length];
                for (int i = 0; i < polys.Length; i++)
                {
                    PolyNormal[i] = new Vertex();
                }
            }
            if (hasVColor)
            {
                VColorName = "vcolor_" + Extensions.GenerateIdentifier();
                VColor     = new Color[striptotal];
            }
            if (hasUV)
            {
                UVName = "uv_" + Extensions.GenerateIdentifier();
                UV     = new UV[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    UV[i] = new UV();
                }
            }
        }
Esempio n. 8
0
        public LandTable(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels)
        {
            Format = format;
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "landtable_" + address.ToString("X8");
            }
            short colcnt = ByteConverter.ToInt16(file, address);

            switch (format)
            {
            case LandTableFormat.SA1:
            case LandTableFormat.SADX:
                short anicnt = ByteConverter.ToInt16(file, address + 2);
                Flags    = ByteConverter.ToInt32(file, address + 4);
                Unknown1 = ByteConverter.ToSingle(file, address + 8);
                COL      = new List <COL>();
                int tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        COLName = labels[tmpaddr];
                    }
                    else
                    {
                        COLName = "collist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < colcnt; i++)
                    {
                        COL.Add(new COL(file, tmpaddr, imageBase, format, labels));
                        tmpaddr += SAModel.COL.Size(format);
                    }
                }
                else
                {
                    COLName = "collist_" + Extensions.GenerateIdentifier();
                }
                Anim    = new List <GeoAnimData>();
                tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        AnimName = labels[tmpaddr];
                    }
                    else
                    {
                        AnimName = "animlist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < anicnt; i++)
                    {
                        Anim.Add(new GeoAnimData(file, tmpaddr, imageBase, format, labels));
                        tmpaddr += GeoAnimData.Size;
                    }
                }
                else
                {
                    AnimName = "animlist_" + Extensions.GenerateIdentifier();
                }
                tmpaddr = ByteConverter.ToInt32(file, address + 0x14);
                if (tmpaddr != 0)
                {
                    tmpaddr         = (int)unchecked ((uint)tmpaddr - imageBase);
                    TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII);
                }
                TextureList = ByteConverter.ToUInt32(file, address + 0x18);
                Unknown2    = ByteConverter.ToInt32(file, address + 0x1C);
                Unknown3    = ByteConverter.ToInt32(file, address + 0x20);
                break;

            case LandTableFormat.SA2:
                short cnkcnt = ByteConverter.ToInt16(file, address + 2);
                Unknown1 = ByteConverter.ToSingle(file, address + 0xC);
                COL      = new List <COL>();
                tmpaddr  = ByteConverter.ToInt32(file, address + 0x10);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        COLName = labels[tmpaddr];
                    }
                    else
                    {
                        COLName = "collist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < colcnt; i++)
                    {
                        COL.Add(new COL(file, tmpaddr, imageBase, format, labels, cnkcnt < 0 ? null : (bool?)(i >= cnkcnt)));
                        tmpaddr += SAModel.COL.Size(format);
                    }
                }
                else
                {
                    COLName = "collist_" + Extensions.GenerateIdentifier();
                }
                Anim     = new List <GeoAnimData>();
                AnimName = "animlist_" + Extensions.GenerateIdentifier();
                tmpaddr  = ByteConverter.ToInt32(file, address + 0x18);
                if (tmpaddr != 0)
                {
                    tmpaddr         = (int)unchecked ((uint)tmpaddr - imageBase);
                    TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII);
                }
                TextureList = ByteConverter.ToUInt32(file, address + 0x1C);
                break;
            }
            Metadata = new Dictionary <uint, byte[]>();
        }
Esempio n. 9
0
        public BasicAttach(List <NJS_MATERIAL> materials, List <Mesh> meshes)
        {
            Name         = "attach_" + Extensions.GenerateIdentifier();
            Bounds       = new BoundingSphere();
            Material     = new List <NJS_MATERIAL>();
            MaterialName = "matlist_" + Extensions.GenerateIdentifier();
            Mesh         = new List <NJS_MESHSET>();
            MeshName     = "meshlist_" + Extensions.GenerateIdentifier();
            Vertex       = new Vertex[0];
            VertexName   = "vertex_" + Extensions.GenerateIdentifier();
            Normal       = new Vertex[0];
            NormalName   = "normal_" + Extensions.GenerateIdentifier();

            List <Vertex> vertices = new List <Vertex>();

            foreach (Mesh m in meshes)
            {
                foreach (Vector3D ve in m.Vertices)
                {
                    vertices.Add(new Vertex(ve.X, ve.Y, ve.Z));
                }
            }
            Vertex = vertices.ToArray();

            List <Vertex> normals = new List <Vertex>();

            foreach (Mesh m in meshes)
            {
                foreach (Vector3D ve in m.Normals)
                {
                    normals.Add(new Vertex(ve.X, ve.Y, ve.Z));
                }
            }
            Normal = normals.ToArray();

            Material = materials;

            int polyIndex = 0;
            List <NJS_MESHSET> meshsets = new List <NJS_MESHSET>();

            for (int i = 0; i < meshes.Count; i++)
            {
                NJS_MESHSET meshset;                //= new NJS_MESHSET(polyType, meshes[i].Faces.Count, false, meshes[i].HasTextureCoords(0), meshes[i].HasVertexColors(0));

                List <Poly> polys = new List <Poly>();

                //i noticed the primitiveType of the Assimp Mesh is always triangles so...
                foreach (Face f in meshes[i].Faces)
                {
                    Triangle triangle = new Triangle();
                    triangle.Indexes[0] = (ushort)(f.Indices[0] + polyIndex);
                    triangle.Indexes[1] = (ushort)(f.Indices[1] + polyIndex);
                    triangle.Indexes[2] = (ushort)(f.Indices[2] + polyIndex);
                    polys.Add(triangle);
                }
                meshset            = new NJS_MESHSET(polys.ToArray(), false, meshes[i].HasTextureCoords(0), false);      //hasVColor = meshes[i].HasVertexColors(0);
                meshset.PolyName   = "poly_" + Extensions.GenerateIdentifier();
                meshset.MaterialID = (ushort)meshes[i].MaterialIndex;

                if (meshes[i].HasTextureCoords(0))
                {
                    meshset.UVName = "uv_" + Extensions.GenerateIdentifier();
                    for (int x = 0; x < meshes[i].TextureCoordinateChannels[0].Count; x++)
                    {
                        meshset.UV[x] = new UV()
                        {
                            U = meshes[i].TextureCoordinateChannels[0][x].X, V = meshes[i].TextureCoordinateChannels[0][x].Y
                        };
                    }
                }

                if (meshes[i].HasVertexColors(0))
                {
                    throw new NotImplementedException();
                }
                polyIndex += meshes[i].VertexCount;
                meshsets.Add(meshset);                //4B4834
            }
            Mesh   = meshsets;
            Bounds = new BoundingSphere()
            {
                Radius = 1.0f
            };
        }
Esempio n. 10
0
 public ChunkAttach()
 {
     Name   = "attach_" + Extensions.GenerateIdentifier();
     Bounds = new BoundingSphere();
 }
Esempio n. 11
0
        public NJS_MESHSET(byte[] file, int address, uint imageBase, Dictionary <int, string> labels)
        {
            MaterialID  = ByteConverter.ToUInt16(file, address);
            PolyType    = (Basic_PolyType)(MaterialID >> 0xE);
            MaterialID &= 0x3FFF;
            Poly[] polys   = new Poly[ByteConverter.ToInt16(file, address + 2)];
            int    tmpaddr = (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase);

            if (labels.ContainsKey(tmpaddr))
            {
                PolyName = labels[tmpaddr];
            }
            else
            {
                PolyName = "poly_" + tmpaddr.ToString("X8");
            }
            int striptotal = 0;

            for (int i = 0; i < polys.Length; i++)
            {
                polys[i]    = SAModel.Poly.CreatePoly(PolyType, file, tmpaddr);
                striptotal += polys[i].Indexes.Length;
                tmpaddr    += polys[i].Size;
            }
            Poly    = new ReadOnlyCollection <Poly>(polys);
            PAttr   = ByteConverter.ToInt32(file, address + 8);
            tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    PolyNormalName = labels[tmpaddr];
                }
                else
                {
                    PolyNormalName = "polynormal_" + tmpaddr.ToString("X8");
                }
                PolyNormal = new Vertex[polys.Length];
                for (int i = 0; i < polys.Length; i++)
                {
                    PolyNormal[i] = new Vertex(file, tmpaddr);
                    tmpaddr      += Vertex.Size;
                }
            }
            else
            {
                PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier();
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    VColorName = labels[tmpaddr];
                }
                else
                {
                    VColorName = "vcolor_" + tmpaddr.ToString("X8");
                }
                VColor = new Color[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    VColor[i] = SAModel.VColor.FromBytes(file, tmpaddr);
                    tmpaddr  += SAModel.VColor.Size(ColorType.ARGB8888_32);
                }
            }
            else
            {
                VColorName = "vcolor_" + Extensions.GenerateIdentifier();
            }
            tmpaddr = ByteConverter.ToInt32(file, address + 0x14);
            if (tmpaddr != 0)
            {
                tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                if (labels.ContainsKey(tmpaddr))
                {
                    UVName = labels[tmpaddr];
                }
                else
                {
                    UVName = "uv_" + tmpaddr.ToString("X8");
                }
                UV = new UV[striptotal];
                for (int i = 0; i < striptotal; i++)
                {
                    UV[i]    = new UV(file, tmpaddr);
                    tmpaddr += SAModel.UV.Size;
                }
            }
            else
            {
                UVName = "uv_" + Extensions.GenerateIdentifier();
            }
        }
Esempio n. 12
0
        public BasicAttach(List <Material> materials, List <Mesh> meshes, string[] textures = null)
        {
            Name         = "attach_" + Extensions.GenerateIdentifier();
            Bounds       = new BoundingSphere();
            Material     = new List <NJS_MATERIAL>();
            MaterialName = "matlist_" + Extensions.GenerateIdentifier();
            Mesh         = new List <NJS_MESHSET>();
            MeshName     = "meshlist_" + Extensions.GenerateIdentifier();
            Vertex       = new Vertex[0];
            VertexName   = "vertex_" + Extensions.GenerateIdentifier();
            Normal       = new Vertex[0];
            NormalName   = "normal_" + Extensions.GenerateIdentifier();


            List <Vertex>         vertices       = new List <Vertex>();
            List <Vertex>         normals        = new List <Vertex>();
            Dictionary <int, int> lookupMaterial = new Dictionary <int, int>();

            foreach (Mesh m in meshes)
            {
                foreach (Vector3D ve in m.Vertices)
                {
                    vertices.Add(new Vertex(ve.X, ve.Y, ve.Z));
                }
                foreach (Vector3D ve in m.Normals)
                {
                    normals.Add(new Vertex(ve.X, ve.Y, ve.Z));
                }
                lookupMaterial.Add(m.MaterialIndex, Material.Count);
                Material.Add(new NJS_MATERIAL(materials[m.MaterialIndex]));

                if (materials[m.MaterialIndex].HasTextureDiffuse)
                {
                    if (textures != null)
                    {
                        Material[Material.Count - 1].UseTexture = true;
                        for (int i = 0; i < textures.Length; i++)
                        {
                            if (textures[i] == Path.GetFileNameWithoutExtension(materials[m.MaterialIndex].TextureDiffuse.FilePath))
                            {
                                Material[Material.Count - 1].TextureID = i;
                            }
                        }
                    }
                }
            }
            Vertex = vertices.ToArray();
            Normal = normals.ToArray();

            int polyIndex = 0;
            List <NJS_MESHSET> meshsets = new List <NJS_MESHSET>();

            for (int i = 0; i < meshes.Count; i++)
            {
                NJS_MESHSET meshset;                //= new NJS_MESHSET(polyType, meshes[i].Faces.Count, false, meshes[i].HasTextureCoords(0), meshes[i].HasVertexColors(0));

                List <Poly> polys = new List <Poly>();

                //i noticed the primitiveType of the Assimp Mesh is always triangles so...
                foreach (Face f in meshes[i].Faces)
                {
                    Triangle triangle = new Triangle();
                    triangle.Indexes[0] = (ushort)(f.Indices[0] + polyIndex);
                    triangle.Indexes[1] = (ushort)(f.Indices[1] + polyIndex);
                    triangle.Indexes[2] = (ushort)(f.Indices[2] + polyIndex);
                    polys.Add(triangle);
                }
                meshset            = new NJS_MESHSET(polys.ToArray(), false, meshes[i].HasTextureCoords(0), meshes[i].HasVertexColors(0));
                meshset.PolyName   = "poly_" + Extensions.GenerateIdentifier();
                meshset.MaterialID = (ushort)lookupMaterial[meshes[i].MaterialIndex];

                if (meshes[i].HasTextureCoords(0))
                {
                    meshset.UVName = "uv_" + Extensions.GenerateIdentifier();
                    for (int x = 0; x < meshes[i].TextureCoordinateChannels[0].Count; x++)
                    {
                        meshset.UV[x] = new UV()
                        {
                            U = meshes[i].TextureCoordinateChannels[0][x].X, V = meshes[i].TextureCoordinateChannels[0][x].Y
                        };
                    }
                }

                if (meshes[i].HasVertexColors(0))
                {
                    meshset.VColorName = "vcolor_" + Extensions.GenerateIdentifier();
                    for (int x = 0; x < meshes[i].VertexColorChannels[0].Count; x++)
                    {
                        meshset.VColor[x] = Color.FromArgb((int)(meshes[i].VertexColorChannels[0][x].A * 255.0f), (int)(meshes[i].VertexColorChannels[0][x].R * 255.0f), (int)(meshes[i].VertexColorChannels[0][x].G * 255.0f), (int)(meshes[i].VertexColorChannels[0][x].B * 255.0f));
                    }
                }
                polyIndex += meshes[i].VertexCount;
                meshsets.Add(meshset);                //4B4834
            }
            Mesh   = meshsets;
            Bounds = new BoundingSphere()
            {
                Radius = 1.0f
            };
        }
Esempio n. 13
0
 public Animation()
 {
     Name = "animation_" + Extensions.GenerateIdentifier();
 }