Пример #1
0
        private string ImportBrgMaterial(BrgMaterial mat)
        {
            Maxscript.Command("mat = StandardMaterial()");
            this.ImportMaterialNameFromFlags(mat);
            Maxscript.Command("mat.adLock = false");
            Maxscript.Command("mat.useSelfIllumColor = true");
            Maxscript.Command("mat.diffuse = color {0} {1} {2}", mat.DiffuseColor.R * 255f, mat.DiffuseColor.G * 255f, mat.DiffuseColor.B * 255f);
            Maxscript.Command("mat.ambient = color {0} {1} {2}", mat.AmbientColor.R * 255f, mat.AmbientColor.G * 255f, mat.AmbientColor.B * 255f);
            Maxscript.Command("mat.specular = color {0} {1} {2}", mat.SpecularColor.R * 255f, mat.SpecularColor.G * 255f, mat.SpecularColor.B * 255f);
            Maxscript.Command("mat.selfIllumColor = color {0} {1} {2}", mat.EmissiveColor.R * 255f, mat.EmissiveColor.G * 255f, mat.EmissiveColor.B * 255f);
            Maxscript.Command("mat.opacity = {0}", mat.Opacity * 100f);
            Maxscript.Command("mat.specularLevel = {0}", mat.SpecularExponent);

            if (mat.Flags.HasFlag(BrgMatFlag.SubtractiveBlend))
            {
                Maxscript.Command("mat.opacityType = 1");
            }
            else if (mat.Flags.HasFlag(BrgMatFlag.AdditiveBlend))
            {
                Maxscript.Command("mat.opacityType = 2");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.TwoSided))
            {
                Maxscript.Command("mat.twoSided = true");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.FaceMap))
            {
                Maxscript.Command("mat.faceMap = true");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.REFLECTIONTEXTURE))
            {
                Maxscript.Command("rTex = BitmapTexture()");
                Maxscript.Command("rTex.name = \"{0}\"", Path.GetFileNameWithoutExtension(mat.sfx[0].Name));
                Maxscript.Command("rTex.filename = \"{0}\"", Path.GetFileNameWithoutExtension(mat.sfx[0].Name) + ".tga");
                Maxscript.Command("mat.reflectionMap = rTex");
            }
            if (mat.Flags.HasFlag(BrgMatFlag.BumpMap))
            {
                Maxscript.Command("aTex = BitmapTexture()");
                Maxscript.Command("aTex.name = \"{0}\"", mat.BumpMap);
                Maxscript.Command("aTex.filename = \"{0}\"", mat.BumpMap + ".tga");
                Maxscript.Command("mat.bumpMap = aTex");
            }
            if (mat.Flags.HasFlag(BrgMatFlag.WrapUTx1) && mat.Flags.HasFlag(BrgMatFlag.WrapVTx1))
            {
                Maxscript.Command("tex = BitmapTexture()");
                Maxscript.Command("tex.name = \"{0}\"", mat.DiffuseMap);
                Maxscript.Command("tex.filename = \"{0}\"", mat.DiffuseMap + ".tga");
                Maxscript.Command("mat.diffusemap = tex");
                if (mat.Flags.HasFlag(BrgMatFlag.PixelXForm1))
                {
                    Maxscript.Command("mat.filtermap = tex");
                }
            }

            return("mat");
        }
Пример #2
0
        private void materialFlagsCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (this.brgObjectsTreeListView.SelectedObject == null ||
                !(this.brgObjectsTreeListView.SelectedObject is BrgMaterial))
            {
                return;
            }

            BrgMaterial mat = (BrgMaterial)this.brgObjectsTreeListView.SelectedObject;

            mat.Flags = this.materialFlagsCheckedListBox.GetEnum <BrgMatFlag>();
            if (e.NewValue == CheckState.Checked)
            {
                mat.Flags |= (BrgMatFlag)this.materialFlagsCheckedListBox.Items[e.Index];
            }
            else
            {
                mat.Flags &= ~(BrgMatFlag)this.materialFlagsCheckedListBox.Items[e.Index];
            }
        }
        void materialListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (materialListBox.SelectedIndex >= 0)
            {
                BrgMaterial mat = file.Material[materialListBox.SelectedIndex];
                // Update Info
                diffuseMaxTextBox.BackColor   = mat.DiffuseColor;
                diffuseMaxTextBox.ForeColor   = ContrastColor(diffuseMaxTextBox.BackColor);
                ambientMaxTextBox.BackColor   = mat.AmbientColor;
                ambientMaxTextBox.ForeColor   = ContrastColor(ambientMaxTextBox.BackColor);
                specularMaxTextBox.BackColor  = mat.SpecularColor;
                specularMaxTextBox.ForeColor  = ContrastColor(specularMaxTextBox.BackColor);
                selfIllumMaxTextBox.BackColor = mat.SelfIllumColor;
                selfIllumMaxTextBox.ForeColor = ContrastColor(selfIllumMaxTextBox.BackColor);
                specularLevelMaxTextBox.Text  = mat.specularLevel.ToString();
                opacityMaxTextBox.Text        = mat.alphaOpacity.ToString();
                textureMaxTextBox.Text        = mat.name;
                if (mat.sfx.Count > 0)
                {
                    reflectionMaxTextBox.Text = mat.sfx[0].Name;
                }
                else
                {
                    reflectionMaxTextBox.Text = string.Empty;
                }
                unknownMaxTextBox.Text = mat.name2;

                // Update Flags box
                for (int i = 0; i < materialFlagsCheckedListBox.Items.Count; i++)
                {
                    if (mat.flags.HasFlag((BrgMatFlag)materialFlagsCheckedListBox.Items[i]))
                    {
                        materialFlagsCheckedListBox.SetItemChecked(i, true);
                    }
                    else
                    {
                        materialFlagsCheckedListBox.SetItemChecked(i, false);
                    }
                }
            }
        }
Пример #4
0
        private void ImportMaterialNameFromFlags(BrgMaterial mat)
        {
            //Maxscript.Command("mat.name = \"{0}\"", mat.DiffuseMap);
            string name = Path.GetFileNameWithoutExtension(mat.DiffuseMap);

            if (mat.Flags.HasFlag(BrgMatFlag.PlayerXFormColor1))
            {
                name += " colorxform1";
            }

            if (mat.Flags.HasFlag(BrgMatFlag.PixelXForm1))
            {
                name += " pixelxform1";
            }

            if (mat.Flags.HasFlag(BrgMatFlag.TwoSided))
            {
                name += " 2-sided";
            }

            Maxscript.Command("mat.name = \"{0}\"", name);
        }
Пример #5
0
        private void ExportMaterialFlagsFromName(BrgMaterial mat)
        {
            string           flags = Maxscript.QueryString("mat.name").ToLower();
            StringComparison cmp   = StringComparison.InvariantCultureIgnoreCase;

            if (flags.Contains("colorxform1", cmp))
            {
                mat.Flags |= BrgMatFlag.PlayerXFormColor1;
            }

            if (flags.Contains("2-sided", cmp) ||
                flags.Contains("2 sided", cmp) ||
                flags.Contains("2sided", cmp))
            {
                mat.Flags |= BrgMatFlag.TwoSided;
            }

            if (flags.Contains("pixelxform1", cmp))
            {
                mat.Flags |= BrgMatFlag.PixelXForm1;
            }
        }
Пример #6
0
        public MtrlFile(BrgMaterial mat)
            : this()
        {
            this.Diffuse = mat.DiffuseColor;
            this.Ambient = mat.AmbientColor;
            this.Specular = mat.SpecularColor;
            this.Emissive = mat.EmissiveColor;
            this.SpecularLevel = mat.SpecularExponent;
            this.Alpha = mat.Opacity;

            if (!mat.Flags.HasFlag(BrgMatFlag.WrapUTx1))
            {
                this.ClampU = 1;
            }

            if (!mat.Flags.HasFlag(BrgMatFlag.WrapVTx1))
            {
                this.ClampV = 1;
            }

            if (mat.Flags.HasFlag(BrgMatFlag.AdditiveBlend))
            {
                this.AlphaMode = 6;
            }

            if (mat.Flags.HasFlag(BrgMatFlag.PixelXForm1))
            {
                this.ColorTransform = 4;
            }

            if (mat.Flags.HasFlag(BrgMatFlag.REFLECTIONTEXTURE))
            {
                this.TextureFactor = 1275068416;
                this.MultiTextureMode = 12;
                this.TexGenMode1 = 1;
            }

            this.Texture = mat.DiffuseMap;
        }
Пример #7
0
        public void LoadMaterialUI()
        {
            BrgMaterial mat = (BrgMaterial)this.Plugin.brgObjectsTreeListView.SelectedObject;

            // Update Info
            this.Plugin.diffuseMaxTextBox.BackColor = System.Drawing.Color.FromArgb(Convert.ToByte(mat.DiffuseColor.R * Byte.MaxValue),
                                                                                    Convert.ToByte(mat.DiffuseColor.G * Byte.MaxValue),
                                                                                    Convert.ToByte(mat.DiffuseColor.B * Byte.MaxValue));
            this.Plugin.diffuseMaxTextBox.ForeColor = this.Plugin.ContrastColor(this.Plugin.diffuseMaxTextBox.BackColor);
            this.Plugin.ambientMaxTextBox.BackColor = System.Drawing.Color.FromArgb(Convert.ToByte(mat.AmbientColor.R * Byte.MaxValue),
                                                                                    Convert.ToByte(mat.AmbientColor.G * Byte.MaxValue),
                                                                                    Convert.ToByte(mat.AmbientColor.B * Byte.MaxValue));
            this.Plugin.ambientMaxTextBox.ForeColor  = this.Plugin.ContrastColor(this.Plugin.ambientMaxTextBox.BackColor);
            this.Plugin.specularMaxTextBox.BackColor = System.Drawing.Color.FromArgb(Convert.ToByte(mat.SpecularColor.R * Byte.MaxValue),
                                                                                     Convert.ToByte(mat.SpecularColor.G * Byte.MaxValue),
                                                                                     Convert.ToByte(mat.SpecularColor.B * Byte.MaxValue));
            this.Plugin.specularMaxTextBox.ForeColor  = this.Plugin.ContrastColor(this.Plugin.specularMaxTextBox.BackColor);
            this.Plugin.selfIllumMaxTextBox.BackColor = System.Drawing.Color.FromArgb(Convert.ToByte(mat.EmissiveColor.R * Byte.MaxValue),
                                                                                      Convert.ToByte(mat.EmissiveColor.G * Byte.MaxValue),
                                                                                      Convert.ToByte(mat.EmissiveColor.B * Byte.MaxValue));
            this.Plugin.selfIllumMaxTextBox.ForeColor = this.Plugin.ContrastColor(this.Plugin.selfIllumMaxTextBox.BackColor);
            this.Plugin.specularLevelMaxTextBox.Text  = mat.SpecularExponent.ToString();
            this.Plugin.opacityMaxTextBox.Text        = mat.Opacity.ToString();
            this.Plugin.textureMaxTextBox.Text        = mat.DiffuseMap;
            if (mat.sfx.Count > 0)
            {
                this.Plugin.reflectionMaxTextBox.Text = mat.sfx[0].Name;
            }
            else
            {
                this.Plugin.reflectionMaxTextBox.Text = string.Empty;
            }
            this.Plugin.bumpMapMaxTextBox.Text = mat.BumpMap;

            // Update Flags box
            this.Plugin.materialFlagsCheckedListBox.SetEnum <BrgMatFlag>(mat.Flags);
        }
Пример #8
0
        private void ExportBrgMaterial(string mainObject, BrgMaterial mat)
        {
            //mat.id = Maxscript.QueryInteger("{0}.material.materialIDList[{1}]", mainObject, materialIndex + 1);
            //Maxscript.Command("mat = {0}.material[{1}]", mainObject, mat.id);

            mat.DiffuseColor = new Color3D(Maxscript.QueryFloat("mat.diffuse.r") / 255f,
                Maxscript.QueryFloat("mat.diffuse.g") / 255f,
                Maxscript.QueryFloat("mat.diffuse.b") / 255f);
            mat.AmbientColor = new Color3D(Maxscript.QueryFloat("mat.ambient.r") / 255f,
                Maxscript.QueryFloat("mat.ambient.g") / 255f,
                Maxscript.QueryFloat("mat.ambient.b") / 255f);
            mat.SpecularColor = new Color3D(Maxscript.QueryFloat("mat.specular.r") / 255f,
                Maxscript.QueryFloat("mat.specular.g") / 255f,
                Maxscript.QueryFloat("mat.specular.b") / 255f);
            mat.EmissiveColor = new Color3D(Maxscript.QueryFloat("mat.selfIllumColor.r") / 255f,
                Maxscript.QueryFloat("mat.selfIllumColor.g") / 255f,
                Maxscript.QueryFloat("mat.selfIllumColor.b") / 255f);

            mat.SpecularExponent = Maxscript.QueryFloat("mat.specularLevel");
            if (mat.SpecularExponent > 0)
            {
                mat.Flags |= BrgMatFlag.SpecularExponent;
            }

            mat.Opacity = Maxscript.QueryFloat("mat.opacity") / 100f;
            if (mat.Opacity < 1f)
            {
                mat.Flags |= BrgMatFlag.Alpha;
            }

            int opacityType = Maxscript.QueryInteger("mat.opacityType");
            if (opacityType == 1)
            {
                mat.Flags |= BrgMatFlag.SubtractiveBlend;
            }
            else if (opacityType == 2)
            {
                mat.Flags |= BrgMatFlag.AdditiveBlend;
            }

            if (Maxscript.QueryBoolean("mat.twoSided"))
            {
                mat.Flags |= BrgMatFlag.TwoSided;
            }

            if (Maxscript.QueryBoolean("mat.faceMap"))
            {
                mat.Flags |= BrgMatFlag.FaceMap;
            }

            if (Maxscript.QueryBoolean("(classof mat.reflectionMap) == BitmapTexture"))
            {
                mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.REFLECTIONTEXTURE;
                BrgMatSFX sfxMap = new BrgMatSFX();
                sfxMap.Id = 30;
                sfxMap.Name = Maxscript.QueryString("getFilenameFile(mat.reflectionMap.filename)") + ".cub";
                mat.sfx.Add(sfxMap);
            }
            if (Maxscript.QueryBoolean("(classof mat.bumpMap) == BitmapTexture"))
            {
                mat.BumpMap = Maxscript.QueryString("getFilenameFile(mat.bumpMap.filename)");
                if (mat.BumpMap.Length > 0)
                {
                    mat.Flags |= BrgMatFlag.WrapUTx3 | BrgMatFlag.WrapVTx3 | BrgMatFlag.BumpMap;
                }
            }
            if (Maxscript.QueryBoolean("(classof mat.diffusemap) == BitmapTexture"))
            {
                mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.filename)");
                int parenthIndex = mat.DiffuseMap.IndexOf('(');
                if (parenthIndex > 0)
                {
                    mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
                }

                if (mat.DiffuseMap.Length > 0)
                {
                    mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1;
                    if (Maxscript.QueryBoolean("mat.diffusemap.filename == mat.filtermap.filename"))
                    {
                        mat.Flags |= BrgMatFlag.PixelXForm1;
                    }
                }
            }
            else if (Maxscript.QueryBoolean("(classof mat.diffusemap) == CompositeTextureMap") && Maxscript.QueryBoolean("(classof mat.diffusemap.mapList[1]) == BitmapTexture"))
            {
                mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.PixelXForm1;
                mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.mapList[1].filename)");
                int parenthIndex = mat.DiffuseMap.IndexOf('(');
                if (parenthIndex > 0)
                {
                    mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
                }
            }

            this.ExportMaterialFlagsFromName(mat);
        }
Пример #9
0
        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();
        }
Пример #10
0
        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();
        }
Пример #11
0
        public void LoadMaterialUI()
        {
            this.Plugin.brgObjectListView.Columns.Clear();
            OLVColumn idCol = new OLVColumn("ID", "Id");

            idCol.Width      = 35;
            idCol.IsEditable = false;
            this.Plugin.brgObjectListView.Columns.Add(idCol);

            OLVColumn flagsCol = new OLVColumn("Flags", "Flags");

            flagsCol.Width = 200;
            this.Plugin.brgObjectListView.Columns.Add(flagsCol);

            OLVColumn diffColorCol = new OLVColumn("Diffuse Color", "DiffuseColor");

            this.Plugin.brgObjectListView.Columns.Add(diffColorCol);
            OLVColumn ambColorCol = new OLVColumn("Ambient Color", "AmbientColor");

            this.Plugin.brgObjectListView.Columns.Add(ambColorCol);
            OLVColumn specColorCol = new OLVColumn("Specular Color", "SpecularColor");

            this.Plugin.brgObjectListView.Columns.Add(specColorCol);
            OLVColumn emisColorCol = new OLVColumn("Emissive Color", "EmissiveColor");

            this.Plugin.brgObjectListView.Columns.Add(emisColorCol);

            OLVColumn specLevelCol = new OLVColumn("Specular Level", "SpecularExponent");

            this.Plugin.brgObjectListView.Columns.Add(specLevelCol);

            OLVColumn opacityCol = new OLVColumn("Opacity", "Opacity");

            this.Plugin.brgObjectListView.Columns.Add(opacityCol);

            OLVColumn diffMapCol = new OLVColumn("Diffuse Map", "DiffuseMap");

            this.Plugin.brgObjectListView.Columns.Add(diffMapCol);

            OLVColumn bumpMapCol = new OLVColumn("Bump Map", "BumpMap");

            this.Plugin.brgObjectListView.Columns.Add(bumpMapCol);

            OLVColumn reflMapCol = new OLVColumn("Reflection Map", string.Empty);

            reflMapCol.AspectGetter = delegate(object rowObject)
            {
                BrgMaterial mat = (BrgMaterial)rowObject;
                if (mat.sfx.Count > 0)
                {
                    return(mat.sfx[0].Name);
                }
                else
                {
                    return(string.Empty);
                }
            };
            reflMapCol.AspectPutter = delegate(object rowObject, object newValue)
            {
                BrgMaterial mat    = (BrgMaterial)rowObject;
                BrgMatSFX   sfxMap = new BrgMatSFX();
                sfxMap.Id   = 30;
                sfxMap.Name = (string)newValue;

                if (mat.sfx.Count > 0)
                {
                    mat.sfx[0] = sfxMap;
                }
                else
                {
                    mat.sfx.Add(sfxMap);
                }
            };
            this.Plugin.brgObjectListView.Columns.Add(reflMapCol);
        }
Пример #12
0
        private void ExportBrgMaterial(string mainObject, BrgMaterial mat)
        {
            //mat.id = Maxscript.QueryInteger("{0}.material.materialIDList[{1}]", mainObject, materialIndex + 1);
            //Maxscript.Command("mat = {0}.material[{1}]", mainObject, mat.id);

            mat.DiffuseColor = new Color3D(Maxscript.QueryFloat("mat.diffuse.r") / 255f,
                                           Maxscript.QueryFloat("mat.diffuse.g") / 255f,
                                           Maxscript.QueryFloat("mat.diffuse.b") / 255f);
            mat.AmbientColor = new Color3D(Maxscript.QueryFloat("mat.ambient.r") / 255f,
                                           Maxscript.QueryFloat("mat.ambient.g") / 255f,
                                           Maxscript.QueryFloat("mat.ambient.b") / 255f);
            mat.SpecularColor = new Color3D(Maxscript.QueryFloat("mat.specular.r") / 255f,
                                            Maxscript.QueryFloat("mat.specular.g") / 255f,
                                            Maxscript.QueryFloat("mat.specular.b") / 255f);
            mat.EmissiveColor = new Color3D(Maxscript.QueryFloat("mat.selfIllumColor.r") / 255f,
                                            Maxscript.QueryFloat("mat.selfIllumColor.g") / 255f,
                                            Maxscript.QueryFloat("mat.selfIllumColor.b") / 255f);

            mat.SpecularExponent = Maxscript.QueryFloat("mat.specularLevel");
            if (mat.SpecularExponent > 0)
            {
                mat.Flags |= BrgMatFlag.SpecularExponent;
            }

            mat.Opacity = Maxscript.QueryFloat("mat.opacity") / 100f;
            if (mat.Opacity < 1f)
            {
                mat.Flags |= BrgMatFlag.Alpha;
            }

            int opacityType = Maxscript.QueryInteger("mat.opacityType");

            if (opacityType == 1)
            {
                mat.Flags |= BrgMatFlag.SubtractiveBlend;
            }
            else if (opacityType == 2)
            {
                mat.Flags |= BrgMatFlag.AdditiveBlend;
            }

            if (Maxscript.QueryBoolean("mat.twoSided"))
            {
                mat.Flags |= BrgMatFlag.TwoSided;
            }

            if (Maxscript.QueryBoolean("mat.faceMap"))
            {
                mat.Flags |= BrgMatFlag.FaceMap;
            }

            if (Maxscript.QueryBoolean("(classof mat.reflectionMap) == BitmapTexture"))
            {
                mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.REFLECTIONTEXTURE;
                BrgMatSFX sfxMap = new BrgMatSFX();
                sfxMap.Id   = 30;
                sfxMap.Name = Maxscript.QueryString("getFilenameFile(mat.reflectionMap.filename)") + ".cub";
                mat.sfx.Add(sfxMap);
            }
            if (Maxscript.QueryBoolean("(classof mat.bumpMap) == BitmapTexture"))
            {
                mat.BumpMap = Maxscript.QueryString("getFilenameFile(mat.bumpMap.filename)");
                if (mat.BumpMap.Length > 0)
                {
                    mat.Flags |= BrgMatFlag.WrapUTx3 | BrgMatFlag.WrapVTx3 | BrgMatFlag.BumpMap;
                }
            }
            if (Maxscript.QueryBoolean("(classof mat.diffusemap) == BitmapTexture"))
            {
                mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.filename)");
                int parenthIndex = mat.DiffuseMap.IndexOf('(');
                if (parenthIndex > 0)
                {
                    mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
                }

                if (mat.DiffuseMap.Length > 0)
                {
                    mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1;
                    if (Maxscript.QueryBoolean("mat.diffusemap.filename == mat.filtermap.filename"))
                    {
                        mat.Flags |= BrgMatFlag.PixelXForm1;
                    }
                }
            }
            else if (Maxscript.QueryBoolean("(classof mat.diffusemap) == CompositeTextureMap") && Maxscript.QueryBoolean("(classof mat.diffusemap.mapList[1]) == BitmapTexture"))
            {
                mat.Flags     |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.PixelXForm1;
                mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.mapList[1].filename)");
                int parenthIndex = mat.DiffuseMap.IndexOf('(');
                if (parenthIndex > 0)
                {
                    mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
                }
            }

            this.ExportMaterialFlagsFromName(mat);
        }
Пример #13
0
        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)");
        }
Пример #14
0
        private void ExportMaterialFlagsFromName(BrgMaterial mat)
        {
            string flags = Maxscript.QueryString("mat.name").ToLower();
            StringComparison cmp = StringComparison.InvariantCultureIgnoreCase;

            if (flags.Contains("colorxform1", cmp))
            {
                mat.Flags |= BrgMatFlag.PlayerXFormColor1;
            }

            if (flags.Contains("2-sided", cmp) ||
                flags.Contains("2 sided", cmp) ||
                flags.Contains("2sided", cmp))
            {
                mat.Flags |= BrgMatFlag.TwoSided;
            }

            if (flags.Contains("pixelxform1", cmp))
            {
                mat.Flags |= BrgMatFlag.PixelXForm1;
            }
        }
Пример #15
0
        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<Vector3D>(totalNumVerts);
                            mesh.Normals = new List<Vector3D>(totalNumVerts);
                            mesh.TextureCoordinates = new List<Vector3D>(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<Vector3D>(totalNumVerts);
                            mesh.Normals = new List<Vector3D>(totalNumVerts);
                            mesh.TextureCoordinates = new List<Vector3D>(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)");
        }
Пример #16
0
        private string ImportBrgMaterial(BrgMaterial mat)
        {
            Maxscript.Command("mat = StandardMaterial()");
            this.ImportMaterialNameFromFlags(mat);
            Maxscript.Command("mat.adLock = false");
            Maxscript.Command("mat.useSelfIllumColor = true");
            Maxscript.Command("mat.diffuse = color {0} {1} {2}", mat.DiffuseColor.R * 255f, mat.DiffuseColor.G * 255f, mat.DiffuseColor.B * 255f);
            Maxscript.Command("mat.ambient = color {0} {1} {2}", mat.AmbientColor.R * 255f, mat.AmbientColor.G * 255f, mat.AmbientColor.B * 255f);
            Maxscript.Command("mat.specular = color {0} {1} {2}", mat.SpecularColor.R * 255f, mat.SpecularColor.G * 255f, mat.SpecularColor.B * 255f);
            Maxscript.Command("mat.selfIllumColor = color {0} {1} {2}", mat.EmissiveColor.R * 255f, mat.EmissiveColor.G * 255f, mat.EmissiveColor.B * 255f);
            Maxscript.Command("mat.opacity = {0}", mat.Opacity * 100f);
            Maxscript.Command("mat.specularLevel = {0}", mat.SpecularExponent);

            if (mat.Flags.HasFlag(BrgMatFlag.SubtractiveBlend))
            {
                Maxscript.Command("mat.opacityType = 1");
            }
            else if (mat.Flags.HasFlag(BrgMatFlag.AdditiveBlend))
            {
                Maxscript.Command("mat.opacityType = 2");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.TwoSided))
            {
                Maxscript.Command("mat.twoSided = true");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.FaceMap))
            {
                Maxscript.Command("mat.faceMap = true");
            }

            if (mat.Flags.HasFlag(BrgMatFlag.REFLECTIONTEXTURE))
            {
                Maxscript.Command("rTex = BitmapTexture()");
                Maxscript.Command("rTex.name = \"{0}\"", Path.GetFileNameWithoutExtension(mat.sfx[0].Name));
                Maxscript.Command("rTex.filename = \"{0}\"", Path.GetFileNameWithoutExtension(mat.sfx[0].Name) + ".tga");
                Maxscript.Command("mat.reflectionMap = rTex");
            }
            if (mat.Flags.HasFlag(BrgMatFlag.BumpMap))
            {
                Maxscript.Command("aTex = BitmapTexture()");
                Maxscript.Command("aTex.name = \"{0}\"", mat.BumpMap);
                Maxscript.Command("aTex.filename = \"{0}\"", mat.BumpMap + ".tga");
                Maxscript.Command("mat.bumpMap = aTex");
            }
            if (mat.Flags.HasFlag(BrgMatFlag.WrapUTx1) && mat.Flags.HasFlag(BrgMatFlag.WrapVTx1))
            {
                Maxscript.Command("tex = BitmapTexture()");
                Maxscript.Command("tex.name = \"{0}\"", mat.DiffuseMap);
                Maxscript.Command("tex.filename = \"{0}\"", mat.DiffuseMap + ".tga");
                Maxscript.Command("mat.diffusemap = tex");
                if (mat.Flags.HasFlag(BrgMatFlag.PixelXForm1))
                {
                    Maxscript.Command("mat.filtermap = tex");
                }
            }

            return "mat";
        }
Пример #17
0
        private void ImportMaterialNameFromFlags(BrgMaterial mat)
        {
            //Maxscript.Command("mat.name = \"{0}\"", mat.DiffuseMap);
            string name = Path.GetFileNameWithoutExtension(mat.DiffuseMap);

            if (mat.Flags.HasFlag(BrgMatFlag.PlayerXFormColor1))
            {
                name += " colorxform1";
            }

            if (mat.Flags.HasFlag(BrgMatFlag.PixelXForm1))
            {
                name += " pixelxform1";
            }

            if (mat.Flags.HasFlag(BrgMatFlag.TwoSided))
            {
                name += " 2-sided";
            }

            Maxscript.Command("mat.name = \"{0}\"", name);
        }