Exemplo n.º 1
0
        private static void F3D_TEXTURE(ref TempMaterial temp, byte[] cmd)
        {
            ushort tsX = (ushort)bytesToInt(cmd, 4, 2);
            ushort tsY = (ushort)bytesToInt(cmd, 6, 2);

            if ((temp.geometryMode & 0x40000) == 0x40000)
            {
                temp.w = (ushort)(tsX >> 6);
                temp.h = (ushort)(tsY >> 6);
            }
            else
            {
                if (tsX != 0xFFFF)
                {
                    temp.texScaleX = (float)tsX / 65536.0f;
                }
                else
                {
                    temp.texScaleX = 1.0f;
                }
                if (tsY != 0xFFFF)
                {
                    temp.texScaleY = (float)tsY / 65536.0f;
                }
                else
                {
                    temp.texScaleY = 1.0f;
                }
            }
        }
Exemplo n.º 2
0
 private static bool G_SETCOMBINE(ref TempMaterial temp, byte[] cmd)
 {
     if (bytesToInt(cmd, 0, 4) == 0xFCFFFFFF)
     {
         temp.segOff = 0;
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 private static void F3D_MOVEMEM(ref TempMaterial temp, ref Level lvl, byte[] cmd)
 {
     if (cmd[1] == 0x86)
     {
         ROM    rom     = ROM.Instance;
         byte[] colData = rom.getDataFromSegmentAddress(bytesToInt(cmd, 4, 4), 4);
         temp.color = (bytesToInt(colData, 0, 3) | 0xFF000000);
         //rom.printArray(colData, 4);
     }
 }
Exemplo n.º 4
0
        private static void switchTextureStatus(ref Model3D mdl, ref TempMaterial temp, bool status)
        {
            ROM rom = ROM.Instance;

            if (mdl.builder.processingTexture != status)
            {
                if (status == false)
                {
                    if (!mdl.builder.hasTexture(temp.segOff))
                    {
                        //System.Console.WriteLine("Adding new texture!");
                        if (temp.segOff != 0)
                        {
                            //System.Console.WriteLine("temp.segOff = " + temp.segOff.ToString("X8"));
                            mdl.builder.AddTexture(
                                TextureFormats.decodeTexture(
                                    temp.format,
                                    rom.getDataFromSegmentAddress_safe(
                                        temp.segOff,
                                        (uint)(temp.w * temp.h * 2)
                                        ),
                                    temp.w,
                                    temp.h
                                    ),
                                mdl.builder.newTexInfo(temp.wrapS, temp.wrapT),
                                temp.segOff
                                );
                        }
                        else
                        {
                            mdl.builder.AddTexture(
                                TextureFormats.createColorTexture(System.Drawing.Color.FromArgb((int)temp.color)),
                                mdl.builder.newTexInfo(temp.wrapS, temp.wrapT),
                                temp.segOff
                                );
                        }
                    }
                }
                mdl.builder.processingTexture = status;
            }
        }
Exemplo n.º 5
0
        private static void G_SETTILE(ref TempMaterial temp, byte[] cmd)
        {
            if (bytesToInt(cmd, 4, 4) == 0x07000000)
            {
                return;
            }

            if (cmd[4] == 0x00)             // Make sure the tile is TX_RENDERTILE (0x0) and not TX_LOADTILE (0x7)
            {
                /*
                 * The format for a texture should actually be used from SetTile (0xF5) command,
                 * and not the SetTextureImage (0xFD) command. If you used the format from 0xFD,
                 * then you will have issues with 4-bit textures. This is because the N64 4-bit
                 * textures use 16-bit formats to load data.
                 */
                temp.format = cmd[1];
            }

            temp.wrapT = getWrap((cmd[5] >> 2) & 0x2);
            temp.wrapS = getWrap(cmd[6] & 0x2);
        }
Exemplo n.º 6
0
        /*
         * public Vector3[] getVertices(int i) {
         * return TempMeshes[i].final.vertices.ToArray();
         * }
         *
         * public Vector2[] getTexCoords(int i)
         * {
         * return TempMeshes[i].final.texCoords.ToArray();
         * }
         *
         * public Vector4[] getColors(int i)
         * {
         *      return TempMeshes[i].final.colors.ToArray();
         * }
         *
         * public Vector3[] getNormals(int i)
         * {
         *      return TempMeshes[i].final.normals.ToArray();
         * }
         *
         * public uint[] getIndices(int i)
         * {
         * return TempMeshes[i].final.indices.ToArray();
         * }
         */
        public bool hasTexture(uint segmentAddress, TempMaterial register)
        {
            TempMesh mesh_iter;
            uint     mesh_iter_pos;

            if (null == (object)register)
            {
                for (mesh_iter = TempMeshes.first,
                     mesh_iter_pos = TempMeshes.count; 0 != mesh_iter_pos;
                     mesh_iter = mesh_iter.next, --mesh_iter_pos)
                {
                    if (mesh_iter.value.segmentAddress == segmentAddress && mesh_iter.value.wr_material == null)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (mesh_iter = TempMeshes.first,
                     mesh_iter_pos = TempMeshes.count; 0 != mesh_iter_pos;
                     mesh_iter = mesh_iter.next, --mesh_iter_pos)
                {
                    if (mesh_iter.value.segmentAddress == segmentAddress && mesh_iter.value.wr_material == register.weakref)
                    {
                        break;
                    }
                }
            }

            if (mesh_iter_pos != 0)
            {
                currentMaterial = mesh_iter;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
 private static void G_SETTIMG(ref TempMaterial temp, byte[] cmd)
 {
     temp.segOff = bytesToInt(cmd, 4, 4);
 }
Exemplo n.º 8
0
 private static void G_SETTILESIZE(byte[] cmd, ref TempMaterial temp)
 {
     temp.w = (ushort)((((cmd[5] << 8) | (cmd[6] & 0xF0)) >> 6) + 1);
     temp.h = (ushort)((((cmd[6] & 0x0F) << 8 | cmd[7]) >> 2) + 1);
 }
Exemplo n.º 9
0
        private static void F3D_TRI1(F3D_Vertex[] vertices, ref Model3D mdl, ref Level lvl, ref TempMaterial temp, byte[] cmd)
        {
            mdl.builder.numTriangles++;
            F3D_Vertex a       = vertices[cmd[5] / 0x0A];
            Vector3    a_pos   = new Vector3(a.x, a.y, a.z);
            Vector2    a_uv    = new Vector2(a.u * temp.texScaleX, a.v * temp.texScaleY);
            Vector4    a_color = new Vector4(a.nx_r / 255.0f, a.ny_g / 255.0f, a.nz_b / 255.0f, 1.0f);
            F3D_Vertex b       = vertices[cmd[6] / 0x0A];
            Vector3    b_pos   = new Vector3(b.x, b.y, b.z);
            Vector2    b_uv    = new Vector2(b.u * temp.texScaleX, b.v * temp.texScaleY);
            Vector4    b_color = new Vector4(b.nx_r / 255.0f, b.ny_g / 255.0f, b.nz_b / 255.0f, 1.0f);
            F3D_Vertex c       = vertices[cmd[7] / 0x0A];
            Vector3    c_pos   = new Vector3(c.x, c.y, c.z);
            Vector2    c_uv    = new Vector2(c.u * temp.texScaleX, c.v * temp.texScaleY);
            Vector4    c_color = new Vector4(c.nx_r / 255.0f, c.ny_g / 255.0f, c.nz_b / 255.0f, 1.0f);

            //System.Console.WriteLine("Adding new Triangle: " + a_pos + "," + b_pos + "," + c_pos);

            if ((temp.geometryMode & 0x20000) != 0)
            {
                mdl.builder.AddTempVertex(a_pos, a_uv, getColor(temp.color));
                mdl.builder.AddTempVertex(b_pos, b_uv, getColor(temp.color));
                mdl.builder.AddTempVertex(c_pos, c_uv, getColor(temp.color));
            }
            else
            {
                mdl.builder.AddTempVertex(a_pos, a_uv, a_color);
                mdl.builder.AddTempVertex(b_pos, b_uv, b_color);
                mdl.builder.AddTempVertex(c_pos, c_uv, c_color);
            }
        }
Exemplo n.º 10
0
        public void AddTexture(TextureFormats.Raw bmp, TextureInfo info, uint segmentAddress, TempMaterial material)
        {
            TempMeshData data;

            data.info           = info;
            data.segmentAddress = segmentAddress;
            if (null != (object)material)
            {
                data.wr_material = material.weakref;
            }
            else
            {
                data.wr_material = null;
            }
            TempMesh.Add(ref TempMeshes, ref data, new TempMeshReferences {
                bmp = bmp,
            });
            currentMaterial = TempMeshes.last;
        }