Esempio n. 1
0
        public IGeometricElement Clone(MeshObject mesh)
        {
            SpriteElement sm = (SpriteElement)MemberwiseClone();

            sm.mesh = mesh;
            sm.Reset();
            return(sm);
        }
Esempio n. 2
0
        public IGeometricObject Clone()
        {
            MeshObject m = (MeshObject)MemberwiseClone();

            m.gao       = new GameObject(m.name);
            m.gao.tag   = "Visual";
            m.subblocks = new IGeometricElement[num_subblocks];
            for (uint i = 0; i < m.num_subblocks; i++)
            {
                if (subblocks[i] != null)
                {
                    m.subblocks[i] = subblocks[i].Clone(m);
                    if (m.subblocks[i] is DeformSet)
                    {
                        m.bones = (DeformSet)m.subblocks[i];
                    }
                }
            }
            m.InitGameObjects();
            return(m);
        }
Esempio n. 3
0
 public SpriteElement(Pointer offset, MeshObject mesh)
 {
     this.mesh   = mesh;
     this.offset = offset;
 }
Esempio n. 4
0
        public static SpriteElement Read(EndianBinaryReader reader, Pointer offset, MeshObject m)
        {
            MapLoader     l = MapLoader.Loader;
            SpriteElement s = new SpriteElement(offset, m);

            s.name = "Sprite @ pos " + offset;

            s.off_sprites = Pointer.Read(reader);
            s.num_sprites = reader.ReadUInt16();
            reader.ReadInt16(); // -1
            reader.ReadUInt32();
            reader.ReadUInt32();

            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();
                    s.sprites[i].off_info    = Pointer.Read(reader);
                    s.sprites[i].size        = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    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 (l.mode == MapLoader.Mode.Rayman2PC)
                    {
                        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_uv1 = Pointer.Read(reader);
                        Pointer off_info_uv2 = Pointer.Read(reader);
                        s.sprites[i].off_material_pointer = Pointer.Read(reader);
                        Pointer.Goto(ref reader, off_current);

                        if (off_info_uv1 != null)
                        {
                            off_current           = Pointer.Goto(ref reader, off_info_uv1);
                            s.sprites[i].info_uv1 = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            Pointer.Goto(ref reader, off_current);
                        }
                        if (off_info_uv2 != null)
                        {
                            off_current           = Pointer.Goto(ref reader, off_info_uv2);
                            s.sprites[i].info_uv2 = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            Pointer.Goto(ref reader, off_current);
                        }
                        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 (l.mode == MapLoader.Mode.Rayman2PC && s.sprites[i].off_material != null)
                            {
                                Pointer.Goto(ref reader, s.sprites[i].off_material);
                                s.sprites[i].off_material = Pointer.Read(reader);
                            }
                            if (s.sprites[i].off_material != null)
                            {
                                Pointer.Goto(ref reader, s.sprites[i].off_material);
                                s.sprites[i].r3mat = VisualMaterial.FromOffset(s.sprites[i].off_material, createIfNull: true);
                            }
                            else
                            {
                                s.sprites[i].r3mat = null;
                            }
                            Pointer.Goto(ref reader, off_current);
                        }
                    }
                }
            }

            return(s);
        }
Esempio n. 5
0
        public static MeshObject Read(EndianBinaryReader reader, PhysicalObject po, Pointer offset)
        {
            MapLoader  l = MapLoader.Loader;
            MeshObject m = new MeshObject(po, offset);
            Pointer    off_modelstart = Pointer.Read(reader);

            m.off_modelstart = off_modelstart;
            Pointer.Goto(ref reader, off_modelstart);
            m.off_vertices     = Pointer.Read(reader);
            m.off_normals      = Pointer.Read(reader);
            m.off_blendWeights = Pointer.Read(reader);
            if (l.mode == MapLoader.Mode.Rayman3PC || l.mode == MapLoader.Mode.RaymanArenaPC ||
                l.mode == MapLoader.Mode.Rayman3GC || l.mode == MapLoader.Mode.Rayman2PC)
            {
                reader.ReadInt32();
            }
            m.off_subblock_types = Pointer.Read(reader);
            m.off_subblocks      = Pointer.Read(reader);
            reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            if (l.mode == MapLoader.Mode.Rayman2PC)
            {
                reader.ReadInt32();
                reader.ReadInt32();
            }
            m.num_vertices  = reader.ReadUInt16();
            m.num_subblocks = reader.ReadUInt16();
            reader.ReadInt32();
            reader.ReadSingle();
            reader.ReadSingle();
            reader.ReadSingle();
            reader.ReadSingle();
            reader.ReadInt32();
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                reader.ReadInt32();
                reader.ReadInt16();
            }
            m.name = "Mesh";
            if (l.mode == MapLoader.Mode.Rayman3GC)
            {
                m.name = new string(reader.ReadChars(0x32)).TrimEnd('\0');
            }
            // Vertices
            Pointer off_current = Pointer.Goto(ref reader, m.off_vertices);

            //print("Loading vertices at " + String.Format("0x{0:X}", fs.Position) + " | Amount: " + num_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.Goto(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);
            }
            if (m.off_blendWeights != null)
            {
                Pointer.Goto(ref reader, m.off_blendWeights);

                /*reader.ReadUInt32(); // 0
                 * R3Pointer off_blendWeightsStart = R3Pointer.Read(reader);
                 * R3Pointer.Goto(ref reader, off_blendWeightsStart);*/
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                m.blendWeights = new float[m.num_vertices];
                for (int i = 0; i < m.num_vertices; i++)
                {
                    m.blendWeights[i] = reader.ReadSingle();
                }
            }
            // Read subblock types & initialize arrays
            Pointer.Goto(ref reader, m.off_subblock_types);
            m.subblock_types = new ushort[m.num_subblocks];
            m.subblocks      = new IGeometricElement[m.num_subblocks];
            for (uint i = 0; i < m.num_subblocks; i++)
            {
                m.subblock_types[i] = reader.ReadUInt16();
            }
            m.gao     = new GameObject(m.name);
            m.gao.tag = "Visual";
            // Process blocks
            for (uint i = 0; i < m.num_subblocks; i++)
            {
                Pointer.Goto(ref reader, m.off_subblocks + (i * 4));
                Pointer block_offset = Pointer.Read(reader);
                Pointer.Goto(ref reader, block_offset);
                switch (m.subblock_types[i])
                {
                case 1:     // Material
                    m.subblocks[i] = MeshElement.Read(reader, block_offset, m);
                    break;

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

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

                default:
                    m.subblocks[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.subblock_types[i] + " at offset " + block_offset);
                    break;
                }
            }
            m.InitGameObjects();
            return(m);
        }
Esempio n. 6
0
        public static MeshElement Read(EndianBinaryReader reader, Pointer offset, MeshObject m)
        {
            MapLoader   l  = MapLoader.Loader;
            MeshElement sm = new MeshElement(offset, m);

            sm.name            = "Submesh @ pos " + offset;
            sm.backfaceCulling = !l.forceDisplayBackfaces;
            sm.off_material    = Pointer.Read(reader);
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                sm.r3mat = VisualMaterial.FromOffset(sm.off_material);
            }
            else
            {
                Pointer off_current = Pointer.Goto(ref reader, sm.off_material);
                sm.off_material = Pointer.Read(reader);
                if (sm.off_material != null)
                {
                    Pointer.Goto(ref reader, sm.off_material);
                    sm.r3mat = VisualMaterial.FromOffset(sm.off_material, createIfNull: true);
                }
                else
                {
                    sm.r3mat = null;
                }
                Pointer.Goto(ref reader, off_current);
            }
            if (sm.r3mat != null)
            {
                sm.backfaceCulling = ((sm.r3mat.flags & VisualMaterial.flags_backfaceCulling) != 0) && !l.forceDisplayBackfaces;
            }
            sm.num_disconnected_triangles_spe = reader.ReadUInt16();
            sm.num_uvs = reader.ReadUInt16();
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                sm.num_uvMaps = reader.ReadUInt16();
                reader.ReadUInt16();
            }
            sm.off_disconnected_triangles_spe = Pointer.Read(reader); // 1 entry = 3 shorts. Max: num_vertices
            if (l.mode == MapLoader.Mode.Rayman3GC)
            {
                reader.ReadUInt32();
            }
            sm.off_mapping_uvs_spe = Pointer.Read(reader); // 1 entry = 3 shorts. Max: num_weights
            sm.off_weights_spe     = Pointer.Read(reader); // 1 entry = 3 floats
            sm.off_uvs             = Pointer.Read(reader); // 1 entry = 2 floats
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                reader.ReadUInt32();
                reader.ReadUInt32();
            }
            sm.off_vertex_indices = Pointer.Read(reader);
            sm.num_vertex_indices = reader.ReadUInt16();
            reader.ReadInt16();
            reader.ReadUInt32();
            if (l.mode != MapLoader.Mode.Rayman2PC)
            {
                reader.ReadUInt16();
                sm.num_mapping_entries        = reader.ReadUInt16();  // num_shorts
                sm.off_mapping_vertices       = Pointer.Read(reader); // shorts_offset1 (1st array of size num_shorts, max_num_vertices)
                sm.off_mapping_uvs            = Pointer.Read(reader); // shorts_offset2 (2nd array of size num_shorts, max: num_weights)
                sm.num_connected_vertices     = reader.ReadUInt16();  // num_shorts2
                sm.num_disconnected_triangles = reader.ReadUInt16();
                sm.off_connected_vertices     = Pointer.Read(reader); // shorts2_offset (array of size num_shorts2)
                sm.off_disconnected_triangles = Pointer.Read(reader);
                if (l.mode == MapLoader.Mode.Rayman3GC)
                {
                    sm.name = new string(reader.ReadChars(0x34)).TrimEnd('\0');
                }
            }
            else
            {
                // Defaults for Rayman 2
                sm.num_uvMaps                 = 1;
                sm.num_mapping_entries        = 0;
                sm.off_mapping_vertices       = null;
                sm.off_mapping_uvs            = null;
                sm.num_connected_vertices     = 0;
                sm.num_disconnected_triangles = 0;
                sm.off_connected_vertices     = null;
                sm.off_disconnected_triangles = null;
            }

            // Read mapping tables
            sm.mapping_uvs = new int[sm.num_uvMaps][];
            if (sm.num_mapping_entries > 0)
            {
                Pointer.Goto(ref reader, sm.off_mapping_vertices);
                //print("Mapping offset: " + String.Format("0x{0:X}", fs.Position));
                sm.mapping_vertices = new int[sm.num_mapping_entries];
                for (int j = 0; j < sm.num_mapping_entries; j++)
                {
                    sm.mapping_vertices[j] = reader.ReadInt16();
                }
                Pointer.Goto(ref reader, sm.off_mapping_uvs);
                for (int j = 0; j < sm.num_uvMaps; j++)
                {
                    sm.mapping_uvs[j] = new int[sm.num_mapping_entries];
                }
                for (int j = 0; j < sm.num_mapping_entries; j++)
                {
                    for (int um = 0; um < sm.num_uvMaps; um++)
                    {
                        sm.mapping_uvs[um][j] = reader.ReadInt16();
                    }
                }
            }
            if (sm.num_disconnected_triangles_spe > 0)
            {
                Pointer.Goto(ref reader, sm.off_mapping_uvs_spe);
                sm.mapping_uvs_spe = new int[sm.num_uvMaps][];
                for (int j = 0; j < sm.num_uvMaps; j++)
                {
                    sm.mapping_uvs_spe[j] = new int[sm.num_disconnected_triangles_spe * 3];
                }
                // Why is uv maps here the outer loop instead of inner like the other thing?
                for (int um = 0; um < sm.num_uvMaps; um++)
                {
                    for (int j = 0; j < sm.num_disconnected_triangles_spe * 3; j++)
                    {
                        sm.mapping_uvs_spe[um][j] = reader.ReadInt16();
                    }
                }
            }

            // Read UVs
            Pointer.Goto(ref reader, sm.off_uvs);
            sm.uvs = new Vector2[sm.num_uvs];
            for (int j = 0; j < sm.num_uvs; j++)
            {
                sm.uvs[j] = new Vector2(reader.ReadSingle(), reader.ReadSingle());
            }
            // Read triangle data
            Pointer.Goto(ref reader, sm.off_connected_vertices);
            //print("Creating triangles from connected vertices at " + String.Format("0x{0:X}", fs.Position));
            sm.connected_vertices = new int[sm.num_connected_vertices];
            for (int j = 0; j < sm.num_connected_vertices; j++)
            {
                sm.connected_vertices[j] = reader.ReadInt16();
            }
            Pointer.Goto(ref reader, sm.off_disconnected_triangles);
            sm.disconnected_triangles = new int[sm.num_disconnected_triangles * 3];
            //print("Loading disconnected triangles at " + String.Format("0x{0:X}", fs.Position));
            for (int j = 0; j < sm.num_disconnected_triangles; j++)
            {
                sm.disconnected_triangles[(j * 3) + 0] = reader.ReadInt16();
                sm.disconnected_triangles[(j * 3) + 1] = reader.ReadInt16();
                sm.disconnected_triangles[(j * 3) + 2] = reader.ReadInt16();
            }
            if (sm.num_disconnected_triangles_spe > 0)
            {
                Pointer.Goto(ref reader, sm.off_disconnected_triangles_spe);
                sm.disconnected_triangles_spe = new int[sm.num_disconnected_triangles_spe * 3];
                //print("Loading disconnected triangles at " + String.Format("0x{0:X}", fs.Position));
                for (int j = 0; j < sm.num_disconnected_triangles_spe; j++)
                {
                    sm.disconnected_triangles_spe[(j * 3) + 0] = reader.ReadInt16();
                    sm.disconnected_triangles_spe[(j * 3) + 1] = reader.ReadInt16();
                    sm.disconnected_triangles_spe[(j * 3) + 2] = reader.ReadInt16();
                }
            }
            return(sm);
        }