Exemple #1
0
        public IGeometricObjectElement Clone(GeometricObject mesh)
        {
            GeometricObjectElementSprites sm = (GeometricObjectElementSprites)MemberwiseClone();

            sm.geo = mesh;
            sm.Reset();
            return(sm);
        }
        public static GeometricObject Read(Reader reader, Pointer offset)
        {
            MapLoader l = MapLoader.Loader;
            //l.print("Geometric Object: " + offset);
            GeometricObject m = new GeometricObject(offset);

            if (Settings.s.game == Settings.Game.LargoWinch)
            {
                uint flags = reader.ReadUInt32();
                m.num_vertices      = reader.ReadUInt16();
                m.num_elements      = reader.ReadUInt16();
                m.off_element_types = Pointer.Read(reader);
                m.off_elements      = Pointer.Read(reader);
                m.off_vertices      = Pointer.Read(reader);
                m.off_normals       = Pointer.Read(reader);
                reader.ReadSingle();
                reader.ReadSingle();
                reader.ReadSingle();
                reader.ReadSingle();
                m.lookAtMode = reader.ReadUInt32();
            }
            else if (Settings.s.game == Settings.Game.R2Revolution)
            {
                m.off_element_types = Pointer.Read(reader);
                m.off_elements      = Pointer.Read(reader);
                uint flags = reader.ReadUInt32();
                reader.ReadSingle();
                reader.ReadSingle();
                reader.ReadSingle();
                reader.ReadSingle();
                m.off_mapping  = Pointer.Read(reader);
                m.num_vertices = reader.ReadUInt16();
                m.num_elements = reader.ReadUInt16();
                m.off_vertices = Pointer.Read(reader);
                m.off_normals  = Pointer.Read(reader);
                m.lookAtMode   = flags & 3;
            }
            else
            {
                if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                {
                    m.num_vertices = (ushort)reader.ReadUInt32();
                }
                m.off_vertices = Pointer.Read(reader);
                m.off_normals  = Pointer.Read(reader);
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    m.off_materials = Pointer.Read(reader);
                }
                else
                {
                    m.off_blendWeights = Pointer.Read(reader);
                }
                if (Settings.s.mode != Settings.Mode.RaymanArenaGC &&
                    Settings.s.mode != Settings.Mode.RaymanArenaGCDemo &&
                    Settings.s.game != Settings.Game.RM &&
                    Settings.s.mode != Settings.Mode.DonaldDuckPKGC &&
                    !(Settings.s.platform == Settings.Platform.PS2 && Settings.s.engineVersion == Settings.EngineVersion.R3))
                {
                    reader.ReadInt32();
                }
                if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                {
                    m.num_elements = (ushort)reader.ReadUInt32();
                }
                m.off_element_types = Pointer.Read(reader);
                m.off_elements      = Pointer.Read(reader);
                reader.ReadInt32();
                reader.ReadInt32();
                if (Settings.s.engineVersion == Settings.EngineVersion.R2)
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                }
                if (Settings.s.game == Settings.Game.Dinosaur)
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadInt32();
                }
                if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                {
                    m.lookAtMode = reader.ReadUInt32();
                    //if (m.lookAtMode != 0) l.print(m.lookAtMode);
                    m.num_vertices = reader.ReadUInt16();
                    m.num_elements = reader.ReadUInt16();
                    reader.ReadInt32();
                    reader.ReadSingle();                     // bounding volume radius
                    reader.ReadSingle();                     // x
                    reader.ReadSingle();                     // z
                    reader.ReadSingle();                     // y
                    reader.ReadInt32();
                    if (Settings.s.engineVersion == Settings.EngineVersion.R3)
                    {
                        reader.ReadInt32();
                        if (!(Settings.s.platform == Settings.Platform.PS2 && (Settings.s.game == Settings.Game.RM || Settings.s.game == Settings.Game.RA)))
                        {
                            reader.ReadInt16();
                            if (Settings.s.platform == Settings.Platform.PS2)
                            {
                                reader.ReadInt16();
                                reader.ReadUInt32();
                            }
                        }
                    }
                }
                else
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                    reader.ReadSingle();
                    reader.ReadSingle();
                    reader.ReadSingle();
                    reader.ReadSingle();
                }
            }
            m.name = "Mesh @ " + offset;
            if (Settings.s.hasNames)
            {
                m.name = reader.ReadString(0x32);
            }
            if (Settings.s.platform == Settings.Platform.PS2 && Settings.s.engineVersion >= Settings.EngineVersion.R3)
            {
                reader.Align(0x4);
                reader.ReadUInt32();
                reader.ReadUInt32();
                m.optimizedObject = new Pointer <PS2OptimizedSDCStructure>(reader, resolve: false);
                reader.ReadUInt32();
                reader.ReadUInt32();
                if (Settings.s.game == Settings.Game.R3)
                {
                    m.ps2IsSinus = reader.ReadUInt32();
                }
            }
            // Vertices
            Pointer.DoAt(ref reader, m.off_vertices, () => {
                m.vertices = new Vector3[m.num_vertices];
                for (int i = 0; i < m.num_vertices; i++)
                {
                    float x       = reader.ReadSingle();
                    float z       = reader.ReadSingle();
                    float y       = reader.ReadSingle();
                    m.vertices[i] = new Vector3(x, y, z);
                }
            });
            // Normals
            Pointer.DoAt(ref reader, m.off_normals, () => {
                m.normals = new Vector3[m.num_vertices];
                for (int i = 0; i < m.num_vertices; i++)
                {
                    float x      = reader.ReadSingle();
                    float z      = reader.ReadSingle();
                    float y      = reader.ReadSingle();
                    m.normals[i] = new Vector3(x, y, z);
                }
            });
            Pointer.DoAt(ref reader, m.off_blendWeights, () => {
                m.blendWeights = new float[4][];

                /*reader.ReadUInt32(); // 0
                 * R3Pointer off_blendWeightsStart = R3Pointer.Read(reader);
                 * R3Pointer.Goto(ref reader, off_blendWeightsStart);*/
                for (int i = 0; i < 4; i++)
                {
                    Pointer off_blendWeights = Pointer.Read(reader);
                    Pointer.DoAt(ref reader, off_blendWeights, () => {
                        m.blendWeights[i] = new float[m.num_vertices];
                        for (int j = 0; j < m.num_vertices; j++)
                        {
                            m.blendWeights[i][j] = reader.ReadSingle();
                        }
                    });
                }
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
            });
            Pointer.DoAt(ref reader, m.off_mapping, () => {
                // Revolution only
                reader.ReadUInt32();
                Pointer.Read(reader);
                Pointer off_mappingBlocks = Pointer.Read(reader);
                Pointer.Read(reader);
                Pointer.Read(reader);
                ushort num_mappingBlocks = reader.ReadUInt16();
                reader.ReadUInt16();
                Pointer.DoAt(ref reader, off_mappingBlocks, () => {
                    m.mapping = new int[num_mappingBlocks][];
                    for (int i = 0; i < num_mappingBlocks; i++)
                    {
                        Pointer off_mapping = Pointer.Read(reader);
                        Pointer.DoAt(ref reader, off_mapping, () => {
                            m.mapping[i] = new int[m.num_vertices];
                            for (int j = 0; j < m.num_vertices; j++)
                            {
                                m.mapping[i][j] = reader.ReadUInt16();
                                if (m.mapping[i][j] >= m.num_vertices)
                                {
                                    l.print(m.offset);
                                }
                            }
                        });
                    }
                });
            });
            // Read element types & initialize arrays
            Pointer.Goto(ref reader, m.off_element_types);
            m.element_types = new ushort[m.num_elements];
            m.elements      = new IGeometricObjectElement[m.num_elements];
            for (uint i = 0; i < m.num_elements; i++)
            {
                m.element_types[i] = reader.ReadUInt16();
            }
            // Process elements
            for (uint i = 0; i < m.num_elements; i++)
            {
                Pointer.Goto(ref reader, m.off_elements + (i * 4));
                Pointer block_offset = Pointer.Read(reader);
                Pointer.Goto(ref reader, block_offset);
                switch (m.element_types[i])
                {
                case 1:     // Material
                    m.elements[i] = GeometricObjectElementTriangles.Read(reader, block_offset, m);
                    break;

                case 3:     // Sprite
                    m.elements[i] = GeometricObjectElementSprites.Read(reader, block_offset, m);
                    break;

                case 13:
                case 15:
                    m.bones       = DeformSet.Read(reader, block_offset, m);
                    m.elements[i] = m.bones;
                    break;

                default:
                    m.elements[i] = null;

                    /*1 = indexedtriangles
                     * 2 = facemap
                     * 3 = sprite
                     * 4 = TMesh
                     * 5 = points
                     * 6 = lines
                     * 7 = spheres
                     * 8 = alignedboxes
                     * 9 = cones
                     * 13 = deformationsetinfo*/
                    l.print("Unknown geometric element type " + m.element_types[i] + " at offset " + block_offset);
                    break;
                }
            }
            ReadMeshFromATO(reader, m);
            if (Settings.s.platform == Settings.Platform.PS2 && Settings.s.engineVersion == Settings.EngineVersion.R3)
            {
                m.optimizedObject?.Resolve(reader, onPreRead: opt => opt.isSinus = m.ps2IsSinus);
                m.ReadMeshFromSDC();
            }
            m.InitGameObject();
            return(m);
        }
Exemple #3
0
        public static GeometricObjectElementSprites Read(Reader reader, Pointer offset, GeometricObject m)
        {
            MapLoader l = MapLoader.Loader;
            GeometricObjectElementSprites s = new GeometricObjectElementSprites(offset, m);

            s.name = "Sprite @ pos " + offset;
            //l.print(s.name);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                if (Settings.s.platform == Settings.Platform.DC)
                {
                    s.off_sprites = offset;
                    s.num_sprites = 1;
                }
                else
                {
                    s.off_sprites = Pointer.Read(reader);
                    s.num_sprites = reader.ReadUInt16();
                    reader.ReadInt16(); // -1
                    if (Settings.s.game != Settings.Game.R2Revolution)
                    {
                        reader.ReadUInt32();
                        if (Settings.s.game != Settings.Game.LargoWinch)
                        {
                            reader.ReadUInt32();
                        }
                    }
                }
            }
            else
            {
                s.num_sprites = (ushort)reader.ReadUInt32();
                s.off_sprites = Pointer.Read(reader);
                reader.ReadUInt32();
            }
            if (Settings.s.game == Settings.Game.R2Revolution)
            {
                Pointer.DoAt(ref reader, s.off_sprites, () => {
                    s.sprites = new IndexedSprite[s.num_sprites];
                    for (uint i = 0; i < s.num_sprites; i++)
                    {
                        s.sprites[i]            = new IndexedSprite();
                        uint type               = reader.ReadUInt32();
                        s.sprites[i].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        if (type == 0x20)
                        {
                            // Light cookie sprite
                            uint index                              = reader.ReadUInt32();
                            R2PS2Loader ps2l                        = MapLoader.Loader as R2PS2Loader;
                            s.sprites[i].visualMaterial             = ps2l.lightCookieMaterial.Clone();
                            s.sprites[i].visualMaterial.diffuseCoef = ps2l.lightCookieColors[index];
                        }
                        else
                        {
                            s.sprites[i].off_material = Pointer.Read(reader);
                            if (s.sprites[i].off_material != null)
                            {
                                s.sprites[i].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[0].off_material, reader);
                            }
                        }
                    }
                });
            }
            else if (Settings.s.platform == Settings.Platform.DC)
            {
                s.sprites    = new IndexedSprite[1];
                s.sprites[0] = new IndexedSprite();
                s.sprites[0].off_material = Pointer.Read(reader);
                if (s.sprites[0].off_material != null)
                {
                    s.sprites[0].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[0].off_material, reader);
                }
                s.sprites[0].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                reader.ReadUInt16();
                s.sprites[0].centerPoint = reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
            }
            else
            {
                if (s.off_sprites != null)
                {
                    Pointer.Goto(ref reader, s.off_sprites);
                    s.sprites = new IndexedSprite[s.num_sprites];
                    for (uint i = 0; i < s.num_sprites; i++)
                    {
                        s.sprites[i] = new IndexedSprite();
                        if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                        {
                            reader.ReadUInt32();
                        }
                        s.sprites[i].off_info = Pointer.Read(reader);
                        s.sprites[i].size     = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                        if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                        {
                            if (Settings.s.game != Settings.Game.LargoWinch)
                            {
                                s.sprites[i].constraint = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                                s.sprites[i].uv1        = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                                s.sprites[i].uv2        = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            }
                            s.sprites[i].centerPoint = reader.ReadUInt16();
                            reader.ReadUInt16();
                            if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                            {
                                reader.ReadUInt32();
                            }
                        }

                        if (s.sprites[i].off_info != null)
                        {
                            Pointer off_current = Pointer.Goto(ref reader, s.sprites[i].off_info);
                            reader.ReadUInt32();
                            Pointer.Read(reader);
                            Pointer.Read(reader);
                            Pointer off_info_scale   = Pointer.Read(reader);
                            Pointer off_info_unknown = Pointer.Read(reader);
                            s.sprites[i].off_material_pointer = Pointer.Read(reader);
                            Pointer.Goto(ref reader, off_current);

                            Pointer.DoAt(ref reader, off_info_scale, () => {
                                s.sprites[i].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            });
                            Pointer.DoAt(ref reader, off_info_unknown, () => {
                                s.sprites[i].info_unknown = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            });
                            if (s.sprites[i].off_material_pointer != null)
                            {
                                off_current = Pointer.Goto(ref reader, s.sprites[i].off_material_pointer);
                                s.sprites[i].off_material = Pointer.Read(reader);
                                if (s.sprites[i].off_material != null)
                                {
                                    if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                                    {
                                        s.sprites[i].gameMaterial   = GameMaterial.FromOffsetOrRead(s.sprites[i].off_material, reader);
                                        s.sprites[i].visualMaterial = s.sprites[i].gameMaterial.visualMaterial;
                                    }
                                    else
                                    {
                                        s.sprites[i].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[i].off_material, reader);
                                    }
                                }
                                Pointer.Goto(ref reader, off_current);
                            }
                        }
                    }
                }
            }

            return(s);
        }