コード例 #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Settings.OpenFileDialogFileName))
            {
                openFileDialog.InitialDirectory = Settings.OpenFileDialogFileName;
            }

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    file = new BrgFile(File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read), this);
                    //file.ExportToMax();
                    //debug();

                    loadUI();
                    this.Text       = "ABE - " + Path.GetFileName(openFileDialog.FileName);
                    isExportedToMax = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to open file!" + Environment.NewLine + Environment.NewLine + ex.Message, "ABE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     file = new BrgFile(this);
     loadUI();
     this.Text       = "ABE - Untitled";
     isExportedToMax = true;
 }
コード例 #3
0
ファイル: BrgMax.cs プロジェクト: heinezen/Age-of-Mythology
        public void Import()
        {
            BrgFile brg = this.File as BrgFile;

            Maxscript.Output.Clear();
            Maxscript.Command("importStartTime = timeStamp()");
            Maxscript.Command("frameRate = 30 --{0}", Math.Round(1 / this.File.Animation.TimeStep));
            Maxscript.Interval(0, this.File.Animation.Duration);

            if (this.File.Meshes.Count > 0)
            {
                string mainObject = "mainObj";
                for (int i = 0; i <= this.File.Meshes[0].MeshAnimations.Count; i++)
                {
                    Maxscript.CommentTitle("ANIMATE FRAME " + i);
                    if (i > 0)
                    {
                        ImportBrgMesh(mainObject, ((BrgMesh)brg.Meshes[0].MeshAnimations[i - 1]), brg.Animation.MeshKeys[i]);
                    }
                    else
                    {
                        ImportBrgMesh(mainObject, brg.Meshes[0], brg.Animation.MeshKeys[0]);
                    }
                }

                Maxscript.Command("update {0}", mainObject);
                if (this.modelAtCenter)
                {
                    Maxscript.Command("moveAmount = [0,0,0] - $Dummy_hotspot.position");
                    Maxscript.Command("max select all");
                    Maxscript.Command("move $ moveAmount");
                }
                Maxscript.Command("max select none");
                Maxscript.Command("max zoomext sel all");
                Maxscript.Command("max zoomext sel all");

                if (this.File.Materials.Count > 0)
                {
                    Maxscript.CommentTitle("LOAD MATERIALS");
                    Maxscript.Command("matGroup = multimaterial numsubs:{0}", this.File.Materials.Count);
                    for (int i = 0; i < this.File.Materials.Count; i++)
                    {
                        Maxscript.Command("matGroup[{0}] = {1}", i + 1, ImportBrgMaterial(brg.Materials[i]));
                        Maxscript.Command("matGroup.materialIDList[{0}] = {1}", i + 1, this.File.Materials[i].Id);
                    }
                    Maxscript.Command("{0}.material = matGroup", mainObject);
                }
            }

            Maxscript.Command("importEndTime = timeStamp()");
            Maxscript.Format("Import took % seconds\n", "((importEndTime - importStartTime) / 1000.0)");
        }
コード例 #4
0
ファイル: BrgMesh.cs プロジェクト: Ryder25/Age-of-Mythology
        public BrgMesh(BrgFile file)
            : base()
        {
            this.ParentFile = file;
            this.Header = new BrgMeshHeader();
            this.Header.Version = 22;
            this.Header.ExtendedHeaderSize = 40;

            this.VertexMaterials = new List<Int16>();

            this.ExtendedHeader = new BrgMeshExtendedHeader();
            this.ExtendedHeader.MaterialLibraryTimestamp = 191738312;
            this.ExtendedHeader.ExportedScaleFactor = 1f;

            this.UserDataEntries = new BrgUserDataEntry[0];
            this.particleData = new float[0];

            this.Attachpoints = new List<BrgAttachpoint>();
            this.NonUniformKeys = new float[0];
        }
コード例 #5
0
ファイル: BrgMesh.cs プロジェクト: Ryder25/Age-of-Mythology
        public BrgMesh(BrgBinaryReader reader, BrgFile file)
            : base()
        {
            this.ParentFile = file;
            this.Header = new BrgMeshHeader(reader);

            this.VertexMaterials = new List<Int16>();
            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                this.Vertices = new List<Vector3D>(this.Header.NumVertices);
                for (int i = 0; i < this.Header.NumVertices; i++)
                {
                    this.Vertices.Add(reader.ReadVector3D(true, this.Header.Version == 22));
                }
                this.Normals = new List<Vector3D>(this.Header.NumVertices);
                for (int i = 0; i < this.Header.NumVertices; i++)
                {
                    if (this.Header.Version >= 13 && this.Header.Version <= 17)
                    {
                        reader.ReadInt16(); // No idea what this is
                    }
                    else // v == 18, 19 or 22
                    {
                        this.Normals.Add(reader.ReadVector3D(true, this.Header.Version == 22));
                    }
                }

                if ((!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.ANIMTEXCOORDS) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM)) &&
                    this.Header.Flags.HasFlag(BrgMeshFlag.TEXCOORDSA))
                {
                    this.TextureCoordinates = new List<Vector3D>(this.Header.NumVertices);
                    for (int i = 0; i < this.Header.NumVertices; i++)
                    {
                        this.TextureCoordinates.Add(new Vector3D(reader.ReadVector2D(this.Header.Version == 22), 0f));
                    }
                }

                if (!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) ||
                    this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLESYSTEM))
                {
                    this.Faces = new List<Face>(this.Header.NumFaces);
                    for (int i = 0; i < this.Header.NumFaces; ++i)
                    {
                        this.Faces.Add(new Face());
                    }

                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        for (int i = 0; i < this.Header.NumFaces; i++)
                        {
                            this.Faces[i].MaterialIndex = reader.ReadInt16();
                        }
                    }

                    for (int i = 0; i < this.Header.NumFaces; i++)
                    {
                        this.Faces[i].Indices.Add(reader.ReadInt16());
                        this.Faces[i].Indices.Add(reader.ReadInt16());
                        this.Faces[i].Indices.Add(reader.ReadInt16());
                    }

                    if (this.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        this.VertexMaterials = new List<Int16>(this.Header.NumVertices);
                        for (int i = 0; i < this.Header.NumVertices; i++)
                        {
                            this.VertexMaterials.Add(reader.ReadInt16());
                        }
                    }
                }
            }

            this.UserDataEntries = new BrgUserDataEntry[this.Header.UserDataEntryCount];
            if (!this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                for (int i = 0; i < this.Header.UserDataEntryCount; i++)
                {
                    this.UserDataEntries[i] = reader.ReadUserDataEntry(false);
                }
            }

            this.ExtendedHeader = new BrgMeshExtendedHeader(reader, this.Header.ExtendedHeaderSize);

            this.particleData = new float[0];
            if (this.Header.Flags.HasFlag(BrgMeshFlag.PARTICLEPOINTS))
            {
                this.particleData = new float[4 * this.Header.NumVertices];
                for (int i = 0; i < this.particleData.Length; i++)
                {
                    this.particleData[i] = reader.ReadSingle();
                }
                for (int i = 0; i < this.Header.UserDataEntryCount; i++)
                {
                    this.UserDataEntries[i] = reader.ReadUserDataEntry(true);
                }
            }

            if (this.Header.Version == 13)
            {
                reader.ReadBytes(this.ExtendedHeader.NameLength);
            }

            if (this.Header.Version >= 13 && this.Header.Version <= 18)
            {
                this.Header.Flags |= BrgMeshFlag.ATTACHPOINTS;
            }
            if (this.Header.Flags.HasFlag(BrgMeshFlag.ATTACHPOINTS))
            {
                Int16 numMatrix = this.ExtendedHeader.NumDummies;
                Int16 numIndex = this.ExtendedHeader.NumNameIndexes;
                if (this.Header.Version == 19 || this.Header.Version == 22)
                {
                    numMatrix = reader.ReadInt16();
                    numIndex = reader.ReadInt16();
                    reader.ReadInt16();
                }

                BrgAttachpoint[] attpts = new BrgAttachpoint[numMatrix];
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i] = new BrgAttachpoint();
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i].XVector = reader.ReadVector3D(true, this.Header.Version == 22);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i].YVector = reader.ReadVector3D(true, this.Header.Version == 22);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i].ZVector = reader.ReadVector3D(true, this.Header.Version == 22);
                }
                if (this.Header.Version == 19 || this.Header.Version == 22)
                {
                    for (int i = 0; i < numMatrix; i++)
                    {
                        attpts[i].Position = reader.ReadVector3D(true, this.Header.Version == 22);
                    }
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i].BoundingBoxMin = reader.ReadVector3D(true, this.Header.Version == 22);
                }
                for (int i = 0; i < numMatrix; i++)
                {
                    attpts[i].BoundingBoxMax = reader.ReadVector3D(true, this.Header.Version == 22);
                }

                List<int> nameId = new List<int>();
                for (int i = 0; i < numIndex; i++)
                {
                    int duplicate = reader.ReadInt32(); // have yet to find a model with duplicates
                    reader.ReadInt32(); // Skip the id (at least I think its an ID)
                    for (int j = 0; j < duplicate; j++)
                    {
                        nameId.Add(i);
                    }
                }

                this.Attachpoints = new List<BrgAttachpoint>();
                for (int i = 0; i < nameId.Count; i++)
                {
                    this.Attachpoints.Add(new BrgAttachpoint(attpts[reader.ReadByte()]));
                    this.Attachpoints[i].NameId = nameId[i];
                    //attpts[reader.ReadByte()].NameId = nameId[i];
                }
                //attachpoints = new List<BrgAttachpoint>(attpts);
            }
            else
            {
                this.Attachpoints = new List<BrgAttachpoint>();
            }

            if (((this.Header.Flags.HasFlag(BrgMeshFlag.COLORALPHACHANNEL) ||
                this.Header.Flags.HasFlag(BrgMeshFlag.COLORCHANNEL)) &&
                !this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH)) ||
                this.Header.Flags.HasFlag(BrgMeshFlag.ANIMVERTCOLORALPHA))
            {
                this.Colors = new List<Color4D>(this.Header.NumVertices);
                for (int i = 0; i < this.Header.NumVertices; i++)
                {
                    this.Colors.Add(reader.ReadTexel());
                }
            }

            // Only seen on first mesh
            this.NonUniformKeys = new float[0];
            if (this.Header.AnimationType.HasFlag(BrgMeshAnimType.NonUniform))
            {
                this.NonUniformKeys = new float[this.ExtendedHeader.NumNonUniformKeys];
                for (int i = 0; i < this.ExtendedHeader.NumNonUniformKeys; i++)
                {
                    this.NonUniformKeys[i] = reader.ReadSingle();
                }
            }

            if (this.Header.Version >= 14 && this.Header.Version <= 19)
            {
                // Face Normals??
                Vector3D[] legacy = new Vector3D[this.Header.NumFaces];
                for (int i = 0; i < this.Header.NumFaces; i++)
                {
                    legacy[i] = reader.ReadVector3D();
                }
            }

            if (!this.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) && this.Header.Version != 22)
            {
                reader.ReadBytes(ExtendedHeader.ShadowNameLength0 + ExtendedHeader.ShadowNameLength1);
            }
        }
コード例 #6
0
ファイル: BrgUi.cs プロジェクト: heinezen/Age-of-Mythology
        public void Import(string fileName)
        {
            // Only need to Update the HEADER, and Animation.Duration, ASETHEADER is auto handled
            this.File = new BrgFile();
            BrgFile           model  = this.File; // just ref here so I don't have to rename model to this.File
            Grendgine_Collada cModel = Grendgine_Collada.Grendgine_Load_File(fileName);

            //Materials
            BrgMaterial mat = new BrgMaterial(model);

            model.Materials.Add(mat);
            mat.AmbientColor     = new Color3D();
            mat.DiffuseColor     = new Color3D();
            mat.SpecularColor    = new Color3D(0.5f);
            mat.SpecularExponent = 5;
            mat.Id      = 100;
            mat.Opacity = 1f;
            mat.Flags  |= BrgMatFlag.HasTexture | BrgMatFlag.SpecularExponent;

            model.Header.NumMaterials = model.Materials.Count();

            //Meshes
            foreach (Grendgine_Collada_Geometry geo in cModel.Library_Geometries.Geometry)
            {
                BrgMesh mesh = new BrgMesh(model);
                model.Meshes.Add(mesh);

                mesh.Header.Flags                     |= BrgMeshFlag.MATERIAL;
                mesh.Header.Flags                     |= model.Meshes.Count == 1 ? 0 : BrgMeshFlag.SECONDARYMESH;
                mesh.Header.AnimationType             |= BrgMeshAnimType.KeyFrame;
                mesh.Header.Format                    |= 0;
                mesh.ExtendedHeader.NumMaterials       = (byte)model.Header.NumMaterials;
                mesh.ExtendedHeader.AnimationLength    = 30;
                mesh.ExtendedHeader.NumUniqueMaterials = 0;

                string polyVertSourceID;
                string polyNormalsSourceID;
                string materialID;
                int[]  vertCountPerPoly;
                int[]  vertLinkPerPoly;
                int[]  vertNormalBindings;

                //Locate the vertices and convert them
                string vertexPosSourceID = geo.Mesh.Vertices.Input.First <Grendgine_Collada_Input_Unshared>(x => x.Semantic == Grendgine_Collada_Input_Semantic.POSITION).source;
                Grendgine_Collada_Float_Array vertsArray = FindSourceByID(geo.Mesh, vertexPosSourceID).Float_Array;

                mesh.Vertices           = FloatToVectorArray(vertsArray);
                mesh.Header.NumVertices = (short)mesh.Vertices.Count;

                //Check for polygons otherwise skip mesh
                if (geo.Mesh.Polylist != null || geo.Mesh.Polylist.Length > 0)
                {
                    mesh.Header.NumFaces = (short)geo.Mesh.Polylist[0].Count;
                    polyVertSourceID     = geo.Mesh.Polylist[0].Input.First <Grendgine_Collada_Input_Unshared>(x => x.Semantic == Grendgine_Collada_Input_Semantic.VERTEX).source;
                    polyNormalsSourceID  = geo.Mesh.Polylist[0].Input.First <Grendgine_Collada_Input_Unshared>(x => x.Semantic == Grendgine_Collada_Input_Semantic.NORMAL).source;
                    vertCountPerPoly     = geo.Mesh.Polylist[0].VCount.Value();
                    materialID           = geo.Mesh.Polylist[0].Material;
                    vertLinkPerPoly      = geo.Mesh.Polylist[0].P.Value();

                    mesh.Faces = new List <Face>(mesh.Header.NumFaces);

                    vertNormalBindings = new int[mesh.Header.NumVertices];

                    int  polyindex = 0;
                    Face ff;
                    foreach (int count in vertCountPerPoly)
                    {
                        if (count == 3) //If triangle
                        {
                            ff         = new Face();
                            ff.Indices = new List <short>(3);
                            ff.Indices.Add((short)vertLinkPerPoly[polyindex]);
                            ff.Indices.Add((short)vertLinkPerPoly[polyindex + 4]);
                            ff.Indices.Add((short)vertLinkPerPoly[polyindex + 2]);
                            //List correct normal bindings
                            vertNormalBindings[ff.Indices[0]] = vertLinkPerPoly[polyindex + 1];
                            vertNormalBindings[ff.Indices[1]] = vertLinkPerPoly[polyindex + 5];
                            vertNormalBindings[ff.Indices[2]] = vertLinkPerPoly[polyindex + 3];
                            //Bind materials
                            if (mesh.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                            {
                                ff.MaterialIndex = (short)mat.Id;
                            }
                            mesh.Faces.Add(ff);
                        }
                        polyindex += count * 2; //Including face normal bindings
                    }
                }
                else
                {
                    break;
                }

                //Locate the vertex normals
                Grendgine_Collada_Float_Array normalsArray = FindSourceByID(geo.Mesh, polyNormalsSourceID).Float_Array;
                if (normalsArray.Count != vertsArray.Count)
                {
                    System.Windows.Forms.MessageBox.Show("The mesh hash only face normals instead of vertex normals. Be sure to export only smooth shaded models.", "Model Import Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
                List <Vector3D> unsortedNormals = FloatToVectorArray(normalsArray);
                mesh.Normals = new List <Vector3D>(mesh.Header.NumVertices);
                for (int i = 0; i < mesh.Header.NumVertices; i++)
                {
                    mesh.Normals.Add(unsortedNormals[vertNormalBindings[i]]);
                }

                mesh.VertexMaterials = new List <short>(mesh.Header.NumVertices);
                for (int i = 0; i < mesh.Header.NumVertices; i++)
                {
                    mesh.VertexMaterials.Add((short)mat.Id);
                }
            }

            model.Header.NumMeshes = model.Meshes.Count();
        }
コード例 #7
0
ファイル: BrgMax.cs プロジェクト: heinezen/Age-of-Mythology
        public void Export()
        {
            BrgFile brg = this.File;

            Maxscript.Command("exportStartTime = timeStamp()");
            //Maxscript.Command("print heapSize");
            BrgMeshFlag              flags             = brg.Meshes[0].Header.Flags;
            BrgMeshFormat            format            = brg.Meshes[0].Header.Format;
            BrgMeshAnimType          animationType     = brg.Meshes[0].Header.AnimationType;
            BrgMeshInterpolationType interpolationType = brg.Meshes[0].Header.InterpolationType;

            Maxscript.Command("ExportBrgData()");
            int totalNumVerts = Maxscript.QueryInteger("brgtotalNumVerts");
            int totalNumFaces = Maxscript.QueryInteger("brgtotalNumFaces");
            int meshCount     = Maxscript.QueryInteger("brgMeshes.count");

            if (meshCount == 0)
            {
                throw new Exception("No Editable_Mesh objects detected!");
            }
            if (Maxscript.QueryBoolean("keys.Count == 0"))
            {
                throw new Exception("Could not acquire animation keys!");
            }

            brg.Header.NumMeshes = Maxscript.QueryInteger("keys.Count");
            brg.Animation        = new Animation();
            for (int i = 1; i <= brg.Header.NumMeshes; ++i)
            {
                brg.Animation.MeshKeys.Add(Maxscript.QueryFloat("keys[{0}]", i));
            }
            if (brg.Header.NumMeshes == 1)
            {
                brg.Animation.Duration = 0;
            }
            else
            {
                brg.Animation.Duration = Maxscript.QueryFloat("(animationRange.end.ticks - animationRange.start.ticks) / 4800.0");
            }
            brg.Animation.TimeStep = brg.Animation.Duration / (float)brg.Header.NumMeshes;

            string mainObject = "mainObject";

            brg.Materials = new List <BrgMaterial>();
            brg.Meshes    = new List <BrgMesh>(brg.Header.NumMeshes);
            for (int m = 0; m < meshCount; ++m)
            {
                Maxscript.Command("{0} = brgMeshes[{1}]", mainObject, m + 1);

                // Materials
                Dictionary <int, int> matIdMapping = new Dictionary <int, int>();
                if (Maxscript.QueryBoolean("classof {0}.material == Multimaterial", mainObject))
                {
                    brg.Header.NumMaterials = Maxscript.QueryInteger("{0}.material.materialList.count", mainObject);
                    for (int i = 0; i < brg.Header.NumMaterials; i++)
                    {
                        BrgMaterial mat = new BrgMaterial(brg);
                        mat.Id = brg.Materials.Count + 1;
                        Maxscript.Command("mat = {0}.material.materialList[{1}]", mainObject, i + 1);
                        this.ExportBrgMaterial(mainObject, mat);

                        int matListIndex = brg.Materials.IndexOf(mat);
                        int actualMatId  = Maxscript.QueryInteger("{0}.material.materialIdList[{1}]", mainObject, i + 1);
                        if (matListIndex >= 0)
                        {
                            if (!matIdMapping.ContainsKey(actualMatId))
                            {
                                matIdMapping.Add(actualMatId, brg.Materials[matListIndex].Id);
                            }
                        }
                        else
                        {
                            brg.Materials.Add(mat);
                            if (matIdMapping.ContainsKey(actualMatId))
                            {
                                matIdMapping[actualMatId] = mat.Id;
                            }
                            else
                            {
                                matIdMapping.Add(actualMatId, mat.Id);
                            }
                        }
                    }
                }
                else if (Maxscript.QueryBoolean("classof {0}.material == Standardmaterial", mainObject))
                {
                    BrgMaterial mat = new BrgMaterial(brg);
                    mat.Id = brg.Materials.Count + 1;
                    Maxscript.Command("mat = {0}.material", mainObject);
                    this.ExportBrgMaterial(mainObject, mat);

                    int matListIndex = brg.Materials.IndexOf(mat);
                    if (matListIndex >= 0)
                    {
                        matIdMapping.Add(1, brg.Materials[matListIndex].Id);
                    }
                    else
                    {
                        brg.Materials.Add(mat);
                        matIdMapping.Add(1, mat.Id);
                    }
                }
                else
                {
                    if (flags.HasFlag(BrgMeshFlag.MATERIAL))
                    {
                        throw new Exception("Not all meshes have a material applied! " + Maxscript.QueryString("{0}.name", mainObject));
                    }
                }

                // Mesh Animations
                for (int i = 0; i < brg.Header.NumMeshes; i++)
                {
                    if (i > 0)
                    {
                        if (m == 0)
                        {
                            BrgMesh mesh = new BrgMesh(brg);
                            mesh.Vertices           = new List <Vector3>(totalNumVerts);
                            mesh.Normals            = new List <Vector3>(totalNumVerts);
                            mesh.TextureCoordinates = new List <Vector3>(totalNumVerts);
                            mesh.Faces = new List <Face>(totalNumFaces);
                            brg.Meshes[0].MeshAnimations.Add(mesh);
                        }
                        brg.UpdateMeshSettings(i, flags, format, animationType, interpolationType);
                        this.ExportBrgMesh(mainObject, (BrgMesh)brg.Meshes[0].MeshAnimations[i - 1], brg.Animation.MeshKeys[i], matIdMapping);
                    }
                    else
                    {
                        if (m == 0)
                        {
                            BrgMesh mesh = new BrgMesh(brg);
                            mesh.Vertices           = new List <Vector3>(totalNumVerts);
                            mesh.Normals            = new List <Vector3>(totalNumVerts);
                            mesh.TextureCoordinates = new List <Vector3>(totalNumVerts);
                            mesh.Faces = new List <Face>(totalNumFaces);
                            brg.Meshes.Add(mesh);
                        }
                        brg.UpdateMeshSettings(i, flags, format, animationType, interpolationType);
                        this.ExportBrgMesh(mainObject, brg.Meshes[i], brg.Animation.MeshKeys[i], matIdMapping);
                    }
                }
            }

            // Export Attachpoints, and Update some Mesh data
            HashSet <int> usedFaceMaterials = new HashSet <int>();
            string        attachDummy       = Maxscript.NewArray("attachDummy");

            Maxscript.Command("{0} = for helpObj in ($helpers/Dummy_*) where classof helpObj == Dummy collect helpObj", attachDummy);//"$helpers/Dummy_* as array");
            for (int i = 0; i < brg.Header.NumMeshes; i++)
            {
                BrgMesh mesh;
                if (i > 0)
                {
                    mesh = (BrgMesh)brg.Meshes[0].MeshAnimations[i - 1];
                }
                else
                {
                    mesh = brg.Meshes[i];
                }

                this.ExportAttachpoints(attachDummy, mesh, brg.Animation.MeshKeys[i]);
                HashSet <int> diffFaceMats = new HashSet <int>();
                if (!mesh.Header.Flags.HasFlag(BrgMeshFlag.SECONDARYMESH) &&
                    mesh.Header.Flags.HasFlag(BrgMeshFlag.MATERIAL))
                {
                    for (int j = 0; j < mesh.Faces.Count; ++j)
                    {
                        diffFaceMats.Add(mesh.Faces[j].MaterialIndex);
                    }

                    if (diffFaceMats.Count > 0)
                    {
                        mesh.ExtendedHeader.NumMaterials       = (byte)(diffFaceMats.Count - 1);
                        mesh.ExtendedHeader.NumUniqueMaterials = diffFaceMats.Count;
                    }
                }
                usedFaceMaterials.UnionWith(diffFaceMats);
                mesh.ExtendedHeader.AnimationLength = this.File.Animation.Duration;
            }
            List <BrgMaterial> usedMats = new List <BrgMaterial>(brg.Materials.Count);

            for (int i = 0; i < brg.Materials.Count; ++i)
            {
                if (usedFaceMaterials.Contains(brg.Materials[i].Id))
                {
                    usedMats.Add(brg.Materials[i]);
                }
            }
            brg.Materials           = usedMats;
            brg.Header.NumMaterials = brg.Materials.Count;

            //Maxscript.Command("print heapSize");
            Maxscript.Command("exportEndTime = timeStamp()");
            Maxscript.Format("Export took % seconds\n", "((exportEndTime - exportStartTime) / 1000.0)");
        }
コード例 #8
0
        public MainWindow()
        {
            InitializeComponent();

            string[] args = Environment.GetCommandLineArgs();
            BrgFile  file;

            if (args.Length > 1 && false)
            {
                file = new BrgFile(File.Open(args[1], FileMode.Open, FileAccess.Read, FileShare.Read));
                file.WriteJson(File.Open(args[1] + ".json", FileMode.Create, FileAccess.Write, FileShare.Read));
                if (args.Length > 2 && args[2] == "-s")
                {
                    Application.Current.Shutdown();
                }
            }
            else
            {
                //archer e slinger_attacka.brg
                file = new BrgFile(File.Open(@"C:\Games\Steam\steamapps\common\Age of Mythology\models\version2.0\infantry g hoplite head standard.brg", FileMode.Open, FileAccess.Read, FileShare.Write));
                file.WriteJson(File.Open("infantry g hoplite head standard.brg.json.brg", FileMode.Create, FileAccess.Write, FileShare.Read));
                var grnFile = new AoMEngineLibrary.Graphics.Grn.GrnFile();
                grnFile.Read(File.Open(@"C:\Games\Steam\steamapps\common\Age of Mythology\models\version2.0\ajax.grn", FileMode.Open, FileAccess.Read, FileShare.Write));
            }

            //BrgFile t = new BrgFile();
            //t.ReadJson(File.Open("hi.brg", FileMode.Open, FileAccess.Read, FileShare.Read));
            //t.WriteJson(File.Open("hi2.brg", FileMode.Create, FileAccess.Write, FileShare.Read));

            List <Point3D> positions       = new List <Point3D>(file.Meshes[0].Vertices.Count);
            List <int>     triangleIndices = new List <int>(file.Meshes[0].Faces.Count * 3);

            for (int i = 0; i < file.Meshes[0].Vertices.Count; ++i)
            {
                positions.Add(new Point3D(
                                  file.Meshes[0].Vertices[i].X,
                                  file.Meshes[0].Vertices[i].Y,
                                  file.Meshes[0].Vertices[i].Z));
            }

            for (int i = 0; i < file.Meshes[0].Faces.Count; ++i)
            {
                triangleIndices.Add(file.Meshes[0].Faces[i].Indices[0]);
                triangleIndices.Add(file.Meshes[0].Faces[i].Indices[1]);
                triangleIndices.Add(file.Meshes[0].Faces[i].Indices[2]);
            }

            Mesh3D       mesh    = new Mesh3D(positions, triangleIndices);
            MeshVisual3D meshVis = new MeshVisual3D();

            meshVis.Mesh = mesh;

            ModelVisual3D   modVis  = new ModelVisual3D();
            GeometryModel3D geomod  = new GeometryModel3D();
            MeshGeometry3D  meshgeo = new MeshGeometry3D();

            //modVis.Transform = new MatrixTransform3D(new Matrix3D(-1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1));
            //modVis.Transform = new MatrixTransform3D(new Matrix3D(-0, -0, -1, 0, -1, -0, -0, 0, 0, 1, 0, 0, 0, 0, 0, 1));
            modVis.Transform        = new MatrixTransform3D(new Matrix3D(0, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1));
            meshgeo.Positions       = new Point3DCollection(positions);
            meshgeo.TriangleIndices = new Int32Collection(triangleIndices);
            geomod.Geometry         = meshgeo;
            modVis.Content          = geomod;
            MaterialGroup matGroup = new MaterialGroup();

            matGroup.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 0xFF, 0x00, 0xFF))));
            geomod.Material = matGroup;

            //viewport3d.Children.Add(meshVis);
            viewport3d.Children.Add(modVis);

            file = new BrgFile(File.Open(@"C:\Games\Steam\steamapps\common\Age of Mythology\models\version2.0\animal aurochs_attacka.brg", FileMode.Open, FileAccess.Read));
            glTFLoader.Schema.Gltf gltf;
            using (var stream = File.Open("dataBuffer.bin", FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                GltfFormatter frmt = new GltfFormatter();
                gltf = frmt.FromBrg(file, stream);
            }
            glTFLoader.Interface.SaveModel(gltf, "brgGltf.gltf");
        }
コード例 #9
0
        public Gltf FromBrg(BrgFile brg, Stream bufferStream)
        {
            // TODO clear class fields

            gltf.Asset         = new Asset();
            gltf.Asset.Version = "2.0";

            Scene scene = new Scene();

            scene.Nodes = new int[] { 0 };

            gltf.Scenes = new[] { scene };
            gltf.Scene  = 0;

            Node node = new Node();

            node.Mesh = 0;
            node.Name = "node";

            gltf.Nodes = new[] { node };

            //FromBrgMesh(brg.Meshes[0]);

            // Create materials / textures

            // Create primitives from first brg mesh
            // TODO: check if there is at least 1 mesh, and 1 face
            var primitives = (from face in brg.Meshes[0].Faces
                              group face by face.MaterialIndex into faceGroup
                              select new BrgMeshPrimitive(faceGroup.ToList())).ToList();

            // Load mesh data
            glTFLoader.Schema.Mesh mesh = new glTFLoader.Schema.Mesh();
            mesh.Primitives = new MeshPrimitive[primitives.Count];
            for (int i = 0; i < mesh.Primitives.Length; ++i)
            {
                mesh.Primitives[i] = new MeshPrimitive();
            }
            for (int j = 0; j < primitives.Count; ++j)
            {
                primitives[j].Serialize(mesh.Primitives[j], brg.Meshes[0], this, bufferStream);
            }
            for (int i = 0; i < brg.Meshes[0].MeshAnimations.Count; ++i)
            {
                for (int j = 0; j < primitives.Count; ++j)
                {
                    primitives[j].Serialize(mesh.Primitives[j], (BrgMesh)brg.Meshes[0].MeshAnimations[i], this, bufferStream);
                }
            }
            gltf.Meshes = new[] { mesh };

            // Create Animation
            if (brg.Meshes[0].MeshAnimations.Count > 0)
            {
                for (int i = 0; i < mesh.Primitives.Length; ++i)
                {
                    mesh.Primitives[i].Targets = primitives[i].Targets.ToArray();
                }

                mesh.Weights = new float[brg.Meshes[0].MeshAnimations.Count];

                gltf.Animations = new[] { CreateAnimation(brg.Animation, mesh.Weights.Length, bufferStream) };
            }

            // Create buffer stream
            gltf.BufferViews = bufferViews.ToArray();
            gltf.Accessors   = accessors.ToArray();
            var buffer = new glTFLoader.Schema.Buffer();

            gltf.Buffers      = new[] { buffer };
            buffer.ByteLength = (int)bufferStream.Length;
            buffer.Uri        = "dataBuffer.bin";

            return(gltf);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: Ryder25/Age-of-Mythology
        private static void Convert(string f)
        {
            string magic;
            using (FileStream fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BrgBinaryReader reader = new BrgBinaryReader(EndianBitConverter.Little, fs);
                magic = reader.ReadString(4);
            }

            if (f.EndsWith("anim.txt"))
            {
                AnimFile.ConvertToXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Anim converted.");
            }
            else if (f.EndsWith(".prt"))
            {
                PrtFile file = new PrtFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Prt converted.");
            }
            else if (magic == "MTRL")
            {
                MtrlFile file = new MtrlFile();
                file.Read(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Mtrl converted.");
            }
            else if (magic == "BANG")
            {
                string brgMtrlOutputPath = Path.Combine(Path.GetDirectoryName(f), "materials");
                if (!Directory.Exists(brgMtrlOutputPath))
                {
                    Directory.CreateDirectory(brgMtrlOutputPath);
                }

                BrgFile file = new BrgFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                for (int i = 0; i < file.Materials.Count; ++i)
                {
                    MtrlFile mtrl = new MtrlFile(file.Materials[i]);
                    mtrl.Write(File.Open(Path.Combine(brgMtrlOutputPath, Path.GetFileNameWithoutExtension(f) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read));
                }
                Console.WriteLine("Success! Mtrl files created.");
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(f);

                if (xmlDoc.DocumentElement.Name == "AnimFile")
                {
                    AnimFile.ConvertToAnim(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".txt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Anim converted.");
                }
                else if (xmlDoc.DocumentElement.Name == "ParticleFile")
                {
                    PrtFile file = PrtFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".prt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Prt converted.");
                }
                else
                {
                    MtrlFile file = MtrlFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".mtrl", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Mtrl converted.");
                }
            }
        }
コード例 #11
0
        private static void Convert(string f)
        {
            string magic;

            using (FileStream fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BrgBinaryReader reader = new BrgBinaryReader(EndianBitConverter.Little, fs);
                magic = reader.ReadString(4);
            }

            if (f.EndsWith("anim.txt"))
            {
                AnimFile.ConvertToXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Anim converted.");
            }
            else if (f.EndsWith(".prt"))
            {
                PrtFile file = new PrtFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Prt converted.");
            }
            else if (magic == "MTRL")
            {
                MtrlFile file = new MtrlFile();
                file.Read(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read));
                Console.WriteLine("Success! Mtrl converted.");
            }
            else if (magic == "BANG")
            {
                string brgMtrlOutputPath = Path.Combine(Path.GetDirectoryName(f), "materials");
                if (!Directory.Exists(brgMtrlOutputPath))
                {
                    Directory.CreateDirectory(brgMtrlOutputPath);
                }

                BrgFile file = new BrgFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                for (int i = 0; i < file.Materials.Count; ++i)
                {
                    MtrlFile mtrl = new MtrlFile(file.Materials[i]);
                    mtrl.Write(File.Open(Path.Combine(brgMtrlOutputPath, Path.GetFileNameWithoutExtension(f) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read));
                }
                Console.WriteLine("Success! Mtrl files created.");
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(f);

                if (xmlDoc.DocumentElement.Name == "AnimFile")
                {
                    AnimFile.ConvertToAnim(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".txt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Anim converted.");
                }
                else if (xmlDoc.DocumentElement.Name == "ParticleFile")
                {
                    PrtFile file = PrtFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".prt", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Prt converted.");
                }
                else
                {
                    MtrlFile file = MtrlFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read));
                    file.Write(File.Open(f + ".mtrl", FileMode.Create, FileAccess.Write, FileShare.Read));
                    Console.WriteLine("Success! Mtrl converted.");
                }
            }
        }