Example #1
0
    private void _GenerateSPSMesh()
    {
        if (this.spsPrims.Count == 0)
        {
            return;
        }
        Single    num      = (Single)this.scale / 4096f;
        Matrix4x4 matrix4x = Matrix4x4.TRS(this.pos, Quaternion.Euler(this.rot.x, this.rot.y, this.rot.z), new Vector3(-num, -num, num));

        base.transform.position = this.pos;
        Single d = 0.00390625f;

        this._vertices.Clear();
        this._colors.Clear();
        this._uv.Clear();
        this._indices.Clear();
        for (Int32 i = 0; i < this.spsPrims.Count; i++)
        {
            WorldSPS.WorldSPSPrim worldSPSPrim = this.spsPrims[i];
            Vector3 b     = new Vector3(0f, 0f, (Single)(this.spsPrims.Count - i) / 100f);
            Int32   count = this._vertices.Count;
            this._vertices.Add(worldSPSPrim.v0 + b);
            this._vertices.Add(worldSPSPrim.v1 + b);
            this._vertices.Add(worldSPSPrim.v2 + b);
            this._vertices.Add(worldSPSPrim.v3 + b);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._colors.Add(worldSPSPrim.color);
            this._uv.Add(worldSPSPrim.uv0 * d);
            this._uv.Add(worldSPSPrim.uv1 * d);
            this._uv.Add(worldSPSPrim.uv2 * d);
            this._uv.Add(worldSPSPrim.uv3 * d);
            this._indices.Add(count);
            this._indices.Add(count + 1);
            this._indices.Add(count + 2);
            this._indices.Add(count + 1);
            this._indices.Add(count + 3);
            this._indices.Add(count + 2);
        }
        Mesh mesh = this.meshFilter.mesh;

        mesh.Clear();
        mesh.vertices        = this._vertices.ToArray();
        mesh.colors          = this._colors.ToArray();
        mesh.uv              = this._uv.ToArray();
        mesh.triangles       = this._indices.ToArray();
        this.meshFilter.mesh = mesh;
        WorldSPS.WorldSPSPrim worldSPSPrim2 = this.spsPrims[0];
        PSXTexture            texture       = PSXTextureMgr.GetTexture(worldSPSPrim2.FlagTP, worldSPSPrim2.FlagTY, worldSPSPrim2.FlagTX, worldSPSPrim2.FlagClutY, worldSPSPrim2.FlagClutX);

        if (texture.texture.filterMode != FilterMode.Bilinear)
        {
            texture.SetFilter(FilterMode.Bilinear);
        }
        Int32 num2 = (Int32)((this.arate >= 4) ? 4 : this.arate);

        this.materials[num2].mainTexture = texture.texture;
        this.meshRenderer.material       = this.materials[num2];
    }
Example #2
0
    private void _GenerateSPSPrims(BinaryReader reader, Int32 spsOffset)
    {
        this.spsPrims.Clear();
        WorldSPS.WorldSPSPrim item = default(WorldSPS.WorldSPSPrim);
        Int32 num  = this.works.shtsc;
        Int32 num2 = this.works.w << num;
        Int32 num3 = this.works.h << num;

        num++;
        reader.BaseStream.Seek((Int64)spsOffset, SeekOrigin.Begin);
        for (Int32 i = 0; i < this.works.primCount; i++)
        {
            item.code  = this.works.code;
            item.tpage = this.works.tpage;
            item.clut  = this.works.clut;
            Int32 num4 = (Int32)reader.ReadSByte();
            Int32 num5 = (Int32)reader.ReadSByte();
            num4 <<= 2;
            Int32 num6 = num4 - num3;
            Int32 num7 = num4 + num3;
            num5 <<= 2;
            Int32 num8 = num5 - num2;
            num5  += num2;
            num6  &= 65535;
            num7  &= 65535;
            num8 <<= 16;
            num5 <<= 16;
            Int32toSByteConverter int32toSByteConverter = num6 | num8;
            item.v0 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f);
            int32toSByteConverter = (num7 | num8);
            item.v1 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f);
            int32toSByteConverter = (num6 | num5);
            item.v2 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f);
            int32toSByteConverter = (num7 | num5);
            item.v3 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f);
            num6    = (Int32)reader.ReadByte();
            Int64 position = reader.BaseStream.Position;
            num8   = (num6 & 15);
            num8 <<= 1;
            num8  += this.works.pt;
            reader.BaseStream.Seek((Int64)num8, SeekOrigin.Begin);
            num7 = (Int32)reader.ReadUInt16();
            Int32 num9 = (Int32)((UInt32)num3 >> num);
            num8     = (num7 & 255);
            num7     = (Int32)((UInt32)num7 >> 8);
            num5     = num8 + num9;
            num9     = (Int32)((UInt32)num2 >> num);
            num4     = num7 + num9;
            num7   <<= 8;
            num4   <<= 8;
            num9     = (num8 | num7);
            item.uv0 = new Vector2((Single)(num9 & 255), (Single)(num9 >> 8 & 255));
            num9     = (num5 | num7);
            item.uv1 = new Vector2((Single)(num9 & 255), (Single)(num9 >> 8 & 255));
            num9     = (num8 | num4);
            item.uv2 = new Vector2((Single)(num9 & 255), (Single)(num9 >> 8 & 255));
            num9     = (num5 | num4);
            item.uv3 = new Vector2((Single)(num9 & 255), (Single)(num9 >> 8 & 255));
            num4     = (Int32)((UInt32)num6 >> 4);
            num4   <<= 2;
            num4    += this.works.rgb;
            reader.BaseStream.Seek((Int64)num4, SeekOrigin.Begin);
            num6   = (Int32)reader.ReadUInt16();
            num8   = (Int32)reader.ReadSByte();
            num8 <<= 16;
            num6  |= num8;
            if (this.works.fade >= 0)
            {
                UInt32 fade = (UInt32)this.works.fade;
                num8 = (num6 & 255);
                UInt32 num10 = (UInt32)num8;
                num7  = (Int32)((UInt32)num6 >> 8);
                num7 &= 255;
                UInt32 num11 = (UInt32)num7;
                num8  = (Int32)((UInt32)num6 >> 16);
                num8 &= 255;
                UInt32 num12 = (UInt32)num8;
                num10      = num10 * fade >> 12;
                num11      = num11 * fade >> 12;
                num12      = num12 * fade >> 12;
                num10      = (UInt32)Mathf.Clamp(num10, -32768f, 32767f);
                num11      = (UInt32)Mathf.Clamp(num11, -32768f, 32767f);
                num12      = (UInt32)Mathf.Clamp(num12, -32768f, 32767f);
                item.color = new Color(num10 / 127f, num11 / 127f, num12 / 127f, 1f);
            }
            else
            {
                num8 = (num6 & 255);
                UInt32 num10 = (UInt32)num8;
                num7  = (Int32)((UInt32)num6 >> 8);
                num7 &= 255;
                UInt32 num11 = (UInt32)num7;
                num8  = (Int32)((UInt32)num6 >> 16);
                num8 &= 255;
                UInt32 num12 = (UInt32)num8;
                item.color = new Color(num10 / 127f, num11 / 127f, num12 / 127f, 1f);
            }
            item.otz = 0;
            this.spsPrims.Add(item);
            reader.BaseStream.Seek(position, SeekOrigin.Begin);
        }
    }