Example #1
0
 public void Open(string filename, bool read_only)
 {
     Errors.Text = "";
     meshMain.TriangleIndices.Clear();
     meshMain.Positions.Clear();
     meshMain.Normals.Clear();
     wireframe.Points.Clear();
     if (filename != null)
     {
         try
         {
             var imp = new RenderWare4.OgreXmlReader(filename + "model.mesh.xml");
             foreach (var v in imp.vertices)
             {
                 meshMain.Positions.Add(new Point3D(v.x, v.y, v.z));
                 meshMain.Normals.Add(new Vector3D(
                                          RenderWare4.Vertex.UnpackNormal(v.normal, 0),
                                          RenderWare4.Vertex.UnpackNormal(v.normal, 1),
                                          RenderWare4.Vertex.UnpackNormal(v.normal, 2)));
             }
             foreach (var t in imp.triangles)
             {
                 meshMain.TriangleIndices.Add((int)t.i);
                 meshMain.TriangleIndices.Add((int)t.j);
                 meshMain.TriangleIndices.Add((int)t.k);
             }
             wireframe.MakeWireframe(Model);
         }
         catch (Exception e)
         {
             Errors.Text = e.ToString();
         }
     }
 }
Example #2
0
 public void Open(string filename, bool read_only)
 {
     Errors.Text = "";
     meshMain.TriangleIndices.Clear();
     meshMain.Positions.Clear();
     meshMain.Normals.Clear();
     wireframe.Points.Clear();
     if (filename != null) {
         try
         {
             var imp = new RenderWare4.OgreXmlReader(filename + "model.mesh.xml");
             foreach (var v in imp.vertices)
             {
                 meshMain.Positions.Add(new Point3D(v.x, v.y, v.z));
                 meshMain.Normals.Add(new Vector3D(
                     RenderWare4.Vertex.UnpackNormal(v.normal, 0),
                     RenderWare4.Vertex.UnpackNormal(v.normal, 1),
                     RenderWare4.Vertex.UnpackNormal(v.normal, 2)));
             }
             foreach (var t in imp.triangles)
             {
                 meshMain.TriangleIndices.Add((int)t.i);
                 meshMain.TriangleIndices.Add((int)t.j);
                 meshMain.TriangleIndices.Add((int)t.k);
             }
             wireframe.MakeWireframe(Model);
         }
         catch (Exception e)
         {
             Errors.Text = e.ToString();
         }
     }
 }
Example #3
0
        public ModelPack(string inputFileName, Stream output)
        {
            var src_model = new OgreXmlReader(inputFileName);

            var model = new RW4Model();
            model.New();

            pack(src_model, model);

            model.Write(output);
        }
Example #4
0
        void pack(OgreXmlReader src_model, RW4Model model)
        {
            model.FileType = RW4Model.FileTypes.Model;

            RW4Skeleton skel = new RW4Skeleton();

            skel.unk1 = 0x8d6da0;
            skel.mat3 = new Matrices4x3()
            {
                items = new Mat4x3[] { new Mat4x3()
                                       {
                                           m = new float[] {
                                               1.0f, 0.0f, 0.0f, 0.0f,
                                               0.0f, 1.0f, 0.0f, 0.0f,
                                               0.0f, 0.0f, 1.0f, 0.0f
                                           }
                                       } }
            };
            skel.mat4 = new Matrices4x4()
            {
                items = new Mat4x4[] { new Mat4x4()
                                       {
                                           m = new float[] {
/*                1.0f, 0.0f, 0.0f, 0.0f,
 *              0.0f, 1.0f, 0.0f, 0.0f,
 *              0.0f, 0.0f, 1.0f, 0.0f,*/
                                               0.0f, 1.0f, 0.0f, 0.0f,
                                               -1.0f, 0.0f, 0.0f, 0.0f,
                                               0.0f, 0.0f, 1.0f, 0.0f,
                                               0.0f, 0.0f, 0.0f, 0.0f
                                           }
                                       } }
            };
            skel.jointInfo = new RW4HierarchyInfo()
            {
                id    = "skeleton1".FNV(),
                items = new RW4HierarchyInfo.Item[] {
                    new RW4HierarchyInfo.Item {
                        index = 0, name_fnv = "joint1".FNV(), flags = 1, parent = null
                    }
                },
            };

            var anim = new Anim()
            {
                skeleton_id   = skel.jointInfo.id,
                flags         = 3,
                length        = 1.25f,
                channel_names = (from j in skel.jointInfo.items select j.name_fnv).ToArray(),
            };

            anim.channel_frame_pose = new JointPose[, ] {
                {
                    new JointPose {
                        qx   = 0, qy = 0, qz = 0, qs = 1,
                        tx   = 0, ty = 0, tz = 0,
                        sx   = 1, sy = 1, sz = 1,
                        time = 1.25f
                    }
                }
            };

            var mesh = new RW4Mesh()
            {
                vertices  = new RW4VertexArray(),
                triangles = new RW4TriangleArray(),
            };

            mesh.vertices.unk2   = 0; //< ?
            mesh.vertices.format = new VertexFormat()
            {
                blob = RW4Garbage.vertex_format
            };
            mesh.vertices.vertices = new Buffer <Vertex>(0);
            mesh.vertices.vertices.Assign(src_model.vertices);
            mesh.triangles.unk1      = 0; //< ?
            mesh.triangles.triangles = new Buffer <Triangle>(0);
            mesh.triangles.triangles.Assign(src_model.triangles);

            var texture = new Texture()
            {
                width       = 64,
                height      = 64,
                mipmapInfo  = 0x708,
                textureType = Texture.DXT5,
                unk1        = 0,
                texData     = new TextureBlob()
                {
                    blob = new byte[5488]
                }
            };
            var texture_format = new RW4TexMetadata()
            {
                unk_data_1 = RW4Garbage.texture_format_1,
                unk_data_2 = RW4Garbage.texture_format_2,
                texture    = texture
            };
            var meshMaterial = new RWMeshMaterialAssignment()
            {
                mesh = mesh,
                mat  = new RW4TexMetadata[] { texture_format }
            };

            model.AddObject(anim, Anim.type_code);
            model.AddObject(mesh.vertices.format, VertexFormat.type_code);
            model.AddObject(skel.mat4, Matrices4x4.type_code);
            model.AddObject(skel.mat3, Matrices4x3.type_code);
            skel.mat3.section.fixup_offsets.Add(16);   // !?
            model.AddObject(skel, RW4Skeleton.type_code);
            model.AddObject(mesh.triangles.triangles, Buffer <Triangle> .type_code);
            model.AddObject(mesh.triangles, RW4TriangleArray.type_code);
            model.AddObject(mesh, RW4Mesh.type_code);
            model.AddObject(texture_format, RW4TexMetadata.type_code);
            model.AddObject(meshMaterial, RWMeshMaterialAssignment.type_code);
            model.AddObject(skel.jointInfo, RW4HierarchyInfo.type_code);

            model.AddObject(mesh.vertices.vertices, Buffer <Vertex> .type_code);
            model.AddObject(mesh.vertices, RW4VertexArray.type_code);

            model.AddObject(texture.texData, TextureBlob.type_code);
            model.AddObject(texture, Texture.type_code);
        }
Example #5
0
        public ModelPack(string inputFileName, Stream output)
        {
            var src_model = new OgreXmlReader(inputFileName);

            var model = new RW4Model();
            model.New();

            pack(src_model, model);

            model.Write(output);
        }
Example #6
0
        void pack(OgreXmlReader src_model, RW4Model model)
        {
            model.FileType = RW4Model.FileTypes.Model;

            RW4Skeleton skel = new RW4Skeleton();
            skel.unk1 = 0x8d6da0;
            skel.mat3 = new Matrices4x3()
            {
                items = new Mat4x3[] { new Mat4x3() { m = new float[] {
                1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f
            } } }
            };
            skel.mat4 = new Matrices4x4()
            {
                items = new Mat4x4[] { new Mat4x4() { m = new float[] {
            /*                1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,*/
                0.0f, 1.0f, 0.0f, 0.0f,
               -1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,
                0.0f, 0.0f, 0.0f, 0.0f
            } } }
            };
            skel.jointInfo = new RW4HierarchyInfo()
            {
                id = "skeleton1".FNV(),
                items = new RW4HierarchyInfo.Item[] {
                            new RW4HierarchyInfo.Item { index=0, name_fnv = "joint1".FNV(), flags=1, parent=null }
                        },
            };

            var anim = new Anim()
            {
                skeleton_id = skel.jointInfo.id,
                flags = 3,
                length = 1.25f,
                channel_names = (from j in skel.jointInfo.items select j.name_fnv).ToArray(),
            };
            anim.channel_frame_pose = new JointPose[,] {
                {
                    new JointPose{ qx=0, qy=0, qz=0, qs=1,
                                   tx=0, ty=0, tz=0,
                                   sx=1, sy=1, sz=1,
                                   time=1.25f }
                }
            };

            var mesh = new RW4Mesh()
            {
                vertices = new RW4VertexArray(),
                triangles = new RW4TriangleArray(),
            };
            mesh.vertices.unk2 = 0;  //< ?
            mesh.vertices.format = new VertexFormat() { blob = RW4Garbage.vertex_format };
            mesh.vertices.vertices = new Buffer<Vertex>(0);
            mesh.vertices.vertices.Assign(src_model.vertices);
            mesh.triangles.unk1 = 0;  //< ?
            mesh.triangles.triangles = new Buffer<Triangle>(0);
            mesh.triangles.triangles.Assign(src_model.triangles);

            var texture = new Texture()
            {
                width = 64,
                height = 64,
                mipmapInfo = 0x708,
                textureType = Texture.DXT5,
                unk1 = 0,
                texData = new TextureBlob() { blob = new byte[5488] }
            };
            var texture_format = new RW4TexMetadata()
            {
                unk_data_1 = RW4Garbage.texture_format_1,
                unk_data_2 = RW4Garbage.texture_format_2,
                texture = texture
            };
            var meshMaterial = new RWMeshMaterialAssignment()
            {
                mesh = mesh,
                mat = new RW4TexMetadata[] { texture_format }
            };

            model.AddObject(anim, Anim.type_code);
            model.AddObject(mesh.vertices.format, VertexFormat.type_code);
            model.AddObject(skel.mat4, Matrices4x4.type_code);
            model.AddObject(skel.mat3, Matrices4x3.type_code);
            skel.mat3.section.fixup_offsets.Add(16);   // !?
            model.AddObject(skel, RW4Skeleton.type_code);
            model.AddObject(mesh.triangles.triangles, Buffer<Triangle>.type_code);
            model.AddObject(mesh.triangles, RW4TriangleArray.type_code);
            model.AddObject(mesh, RW4Mesh.type_code);
            model.AddObject(texture_format, RW4TexMetadata.type_code);
            model.AddObject(meshMaterial, RWMeshMaterialAssignment.type_code);
            model.AddObject(skel.jointInfo, RW4HierarchyInfo.type_code);

            model.AddObject(mesh.vertices.vertices, Buffer<Vertex>.type_code);
            model.AddObject(mesh.vertices, RW4VertexArray.type_code);

            model.AddObject(texture.texData, TextureBlob.type_code);
            model.AddObject(texture, Texture.type_code);
        }