Exemple #1
0
        public static TextureInfo Read(Reader reader, Pointer offset)
        {
            TextureInfo tex = new TextureInfo(offset);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                if (Settings.s.game == Settings.Game.LargoWinch)
                {
                    tex.field0    = reader.ReadUInt32();                  // 888 or 8888
                    tex.fieldC    = reader.ReadUInt32();
                    tex.field10   = reader.ReadUInt32();
                    tex.flags     = reader.ReadUInt32();
                    tex.height_   = reader.ReadUInt16();
                    tex.width_    = reader.ReadUInt16();
                    tex.height    = reader.ReadUInt16();
                    tex.width     = reader.ReadUInt16();
                    tex.field30   = reader.ReadUInt32();
                    tex.field48   = reader.ReadByte();
                    tex.flagsByte = reader.ReadByte();                     // contains stuff like tiling mode
                    tex.name      = reader.ReadString(0x80);
                }
                else if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    reader.ReadUInt32();
                    tex.flags     = reader.ReadUInt16();
                    tex.flagsByte = reader.ReadByte();
                    reader.ReadByte();
                    tex.height_ = reader.ReadUInt16();
                    tex.width_  = reader.ReadUInt16();
                    tex.height  = reader.ReadUInt16();
                    tex.width   = reader.ReadUInt16();
                    reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                }
                else if (Settings.s.platform == Settings.Platform.DC)
                {
                    reader.ReadUInt32();
                    tex.flags = reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    tex.flagsByte = reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    reader.ReadByte();
                    // tex.name is set when setting Texture
                }
                else
                {
                    //MapLoader.Loader.print("tex @ " + offset);
                    tex.field0 = reader.ReadUInt32(); // 888 or 8888
                    if (Settings.s.game == Settings.Game.Dinosaur)
                    {
                        reader.ReadUInt32();
                    }
                    tex.field4                  = reader.ReadUInt16();  // 20
                    tex.field6                  = reader.ReadUInt16();
                    tex.off_tempBuffer          = Pointer.Read(reader); // always null because it's stored here dynamically
                    tex.fieldC                  = reader.ReadUInt32();
                    tex.field10                 = reader.ReadUInt32();
                    tex.flags                   = reader.ReadUInt32();
                    tex.height_                 = reader.ReadUInt16();
                    tex.width_                  = reader.ReadUInt16();
                    tex.height                  = reader.ReadUInt16();
                    tex.width                   = reader.ReadUInt16();
                    tex.currentScrollX          = reader.ReadUInt32();
                    tex.currentScrollY          = reader.ReadUInt32();
                    tex.textureScrollingEnabled = reader.ReadUInt32();
                    tex.alphaMask               = reader.ReadUInt32();
                    tex.field30                 = reader.ReadUInt32();
                    if (Settings.s.engineVersion == Settings.EngineVersion.R3)
                    {
                        tex.numMipmaps = reader.ReadUInt32();
                    }
                    tex.field38   = reader.ReadUInt32();
                    tex.field3C   = reader.ReadUInt32();
                    tex.field40   = reader.ReadUInt32();
                    tex.field44   = reader.ReadUInt32();
                    tex.field48   = reader.ReadByte();
                    tex.flagsByte = reader.ReadByte(); // contains stuff like tiling mode
                    tex.name      = reader.ReadNullDelimitedString();
                    //MapLoader.Loader.print(tex.name + " - " + tex.width + " - " + tex.height + " - " + tex.width_ + " - " + tex.height_ + " - " + tex.IsMirrorX + " - " + tex.IsMirrorY);
                }
            }
            else
            {
                reader.ReadUInt32();
                reader.ReadUInt32();
                tex.flags   = reader.ReadUInt32();
                tex.height_ = (ushort)reader.ReadUInt32();
                tex.width_  = (ushort)reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                {
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                }
                tex.height = (ushort)reader.ReadUInt32();
                tex.width  = (ushort)reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                {
                    tex.name = reader.ReadString(0x50);
                }
                else
                {
                    tex.name = reader.ReadString(0x100);
                }
                if (Settings.s.game == Settings.Game.TTSE)
                {
                    tex.field48 = (byte)reader.ReadUInt32();
                }
                else
                {
                    tex.field48 = reader.ReadByte();
                }
                tex.flagsByte = reader.ReadByte(); // contains stuff like tiling mode
            }
            return(tex);
        }
Exemple #2
0
        private void CreateUnityMesh()
        {
            for (uint i = 0; i < num_sprites; i++)
            {
                bool       mirrorX = false;
                bool       mirrorY = false;
                GameObject spr_gao = new GameObject(name + " - Sprite " + i);
                spr_gao.transform.SetParent(gao.transform);
                spr_gao.transform.localPosition = geo.vertices[sprites[i].centerPoint];
                BillboardBehaviour billboard = spr_gao.AddComponent <BillboardBehaviour>();
                billboard.mode = BillboardBehaviour.LookAtMode.ViewRotation;
                MeshFilter   mf = spr_gao.AddComponent <MeshFilter>();
                MeshRenderer mr = spr_gao.AddComponent <MeshRenderer>();
                BoxCollider  bc = spr_gao.AddComponent <BoxCollider>();
                bc.size       = new Vector3(0, sprites[i].info_scale.y * 2, sprites[i].info_scale.x * 2);
                spr_gao.layer = LayerMask.NameToLayer("Visual");
                if (sprites[i].visualMaterial != null)
                {
                    if (Settings.s.game != Settings.Game.R2Revolution &&
                        sprites[i].visualMaterial.textures != null &&
                        sprites[i].visualMaterial.textures.Count > 0)
                    {
                        TextureInfo mainTex = sprites[i].visualMaterial.textures[0].texture;

                        if (mainTex != null && mainTex.IsMirrorX)
                        {
                            mirrorX = true;
                        }
                        if (mainTex != null && mainTex.IsMirrorY)
                        {
                            mirrorY = true;
                        }
                    }
                    //Material unityMat = sprites[i].visualMaterial.MaterialBillboard;
                    Material unityMat       = sprites[i].visualMaterial.GetMaterial(VisualMaterial.Hint.Billboard);
                    bool     receiveShadows = (sprites[i].visualMaterial.properties & VisualMaterial.property_receiveShadows) != 0;
                    //if (num_uvMaps > 1) unityMat.SetFloat("_UVSec", 50f);
                    //if (r3mat.Material.GetColor("_EmissionColor") != Color.black) print("Mesh with emission: " + name);
                    mr.sharedMaterial = unityMat;

                    /*mr.material.SetFloat("_ScaleX", sprites[i].info_scale.x);
                    *  mr.material.SetFloat("_ScaleY", sprites[i].info_scale.y);*/
                    if (!receiveShadows)
                    {
                        mr.receiveShadows = false;
                    }
                    if (sprites[i].visualMaterial.animTextures.Count > 0)
                    {
                        MultiTextureMaterial mtmat = mr.gameObject.AddComponent <MultiTextureMaterial>();
                        mtmat.visMat = sprites[i].visualMaterial;
                        mtmat.mat    = mr.material;
                    }
                }
                else
                {
                    Material  transMat = new Material(MapLoader.Loader.baseTransparentMaterial);
                    Texture2D tex      = new Texture2D(1, 1);
                    tex.SetPixel(0, 0, new Color(0, 0, 0, 0));
                    transMat.SetTexture("_Tex0", tex);
                    mr.sharedMaterial = transMat;
                }
                if (sprites[i].meshUnity == null)
                {
                    sprites[i].meshUnity = new Mesh();
                    Vector3[] vertices = new Vector3[4];
                    vertices[0] = new Vector3(0, -sprites[i].info_scale.y, -sprites[i].info_scale.x);
                    vertices[1] = new Vector3(0, -sprites[i].info_scale.y, sprites[i].info_scale.x);
                    vertices[2] = new Vector3(0, sprites[i].info_scale.y, -sprites[i].info_scale.x);
                    vertices[3] = new Vector3(0, sprites[i].info_scale.y, sprites[i].info_scale.x);
                    Vector3[] normals = new Vector3[4];
                    normals[0] = Vector3.forward;
                    normals[1] = Vector3.forward;
                    normals[2] = Vector3.forward;
                    normals[3] = Vector3.forward;
                    Vector3[] uvs = new Vector3[4];
                    uvs[0] = new Vector3(0, 0 - (mirrorY ? 1 : 0), 1);
                    uvs[1] = new Vector3(1 + (mirrorX ? 1 : 0), 0 - (mirrorY ? 1 : 0), 1);
                    uvs[2] = new Vector3(0, 1, 1);
                    uvs[3] = new Vector3(1 + (mirrorX ? 1 : 0), 1, 1);
                    int[] triangles = new int[] { 0, 2, 1, 1, 2, 3 };

                    sprites[i].meshUnity.vertices  = vertices;
                    sprites[i].meshUnity.normals   = normals;
                    sprites[i].meshUnity.triangles = triangles;
                    sprites[i].meshUnity.SetUVs(0, uvs.ToList());
                }


                mf.sharedMesh = sprites[i].meshUnity;
            }
        }