Example #1
0
        protected override void ReadDataJson(JsonReader reader, string propName)
        {
            base.ReadDataJson(reader, propName);

            switch (propName)
            {
            case nameof(Id):
                Id = reader.ReadAsInt32().Value;
                break;

            case nameof(Flags):
                Flags = (BrgMatFlag)reader.ReadAsInt32();
                break;

            case nameof(unknown01b):
                unknown01b = reader.ReadAsInt32().Value;
                break;

            case nameof(DiffuseMap):
                DiffuseMap = reader.ReadAsString();
                break;

            case nameof(BumpMap):
                BumpMap = reader.ReadAsString();
                break;

            case nameof(sfx):
                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        continue;
                    }
                    if (reader.TokenType == JsonToken.EndArray)
                    {
                        break;
                    }

                    BrgMatSFX sfx = new BrgMatSFX();

                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.EndObject)
                        {
                            break;
                        }

                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            switch (reader.ReadAsString())
                            {
                            case nameof(BrgMatSFX.Id):
                                sfx.Id = (byte)reader.ReadAsInt32();
                                break;

                            case nameof(BrgMatSFX.Name):
                                sfx.Name = reader.ReadAsString();
                                break;

                            default:
                                break;
                                throw new Exception("Unexpected property name!");
                            }
                        }
                        else if (reader.TokenType != JsonToken.StartObject)
                        {
                            throw new Exception("Unexpected token type! " + reader.TokenType);
                        }
                    }

                    this.sfx.Add(sfx);
                }
                break;

            default:
                break;
                throw new Exception("Unexpected property name!");
            }
        }
Example #2
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);
        }
Example #3
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);
        }