// Token: 0x060000E2 RID: 226 RVA: 0x0000B288 File Offset: 0x00009488
 public static void Write(string filepath, ACCMaterialEx mate)
 {
     using (BinaryWriter binaryWriter = new BinaryWriter(File.OpenWrite(filepath)))
     {
         ACCMaterialEx.Write(binaryWriter, mate);
     }
 }
        public static void Write(BinaryWriter writer, ACCMaterialEx mate)
        {
            writer.Write(FileConst.HEAD_MATE);
            writer.Write(1000); // version

            writer.Write(mate.name1);
            writer.Write(mate.name2);

            var shaderName1 = mate.type.name;

            writer.Write(shaderName1);
            var shaderName2 = ShaderType.GetShader2(shaderName1);

            writer.Write(shaderName2);

            // tex
            for (int i = 0; i < mate.type.texProps.Length; i++)
            {
                var texProp = mate.type.texProps[i];
                if (texProp.key == PropKey._RenderTex)
                {
                    writer.Write("null");
                }
                else
                {
                    writer.Write("tex2d");
                    var tex = mate.texDic[texProp.key];
                    writer.Write(tex.editname);
                    writer.Write(tex.txtpath);

                    outUtil.Write(writer, tex.texOffset.Value);
                    outUtil.Write(writer, tex.texScale.Value);
                }
            }
            // col
            for (int i = 0; i < mate.editColors.Length; i++)
            {
                var colProp = mate.type.colProps[i];
                var eColor  = mate.editColors[i];

                // PropType.col
                writer.Write(colProp.type.ToString());
                writer.Write(colProp.keyName);
                outUtil.Write(writer, eColor.val.Value);
            }
            // f
            for (int i = 0; i < mate.editVals.Length; i++)
            {
                var prop = mate.type.fProps[i];
                var eVal = mate.editVals[i];

                // PropType.f
                writer.Write(prop.type.ToString());
                writer.Write(prop.keyName);
                writer.Write(eVal.val);
            }
        }
        // Token: 0x060000E3 RID: 227 RVA: 0x0000B2C4 File Offset: 0x000094C4
        public static void Write(BinaryWriter writer, ACCMaterialEx mate)
        {
            writer.Write(FileConst.HEAD_MATE);
            writer.Write(1000);
            writer.Write(mate.name1);
            writer.Write(mate.name2);
            string name = mate.type.name;

            writer.Write(name);
            string mateName = ShaderType.GetMateName(name);

            writer.Write(mateName);
            foreach (ShaderPropTex shaderPropTex in mate.type.texProps)
            {
                if (shaderPropTex.key == PropKey._RenderTex)
                {
                    writer.Write("null");
                }
                else
                {
                    writer.Write("tex2d");
                    ACCTextureEx acctextureEx = mate.texDic[shaderPropTex.key];
                    writer.Write(acctextureEx.editname);
                    writer.Write(acctextureEx.txtpath);
                    ACCMaterialEx.OUT_UTIL.Write(writer, acctextureEx.texOffset);
                    ACCMaterialEx.OUT_UTIL.Write(writer, acctextureEx.texScale);
                }
            }
            for (int j = 0; j < mate.editColors.Length; j++)
            {
                ShaderPropColor shaderPropColor = mate.type.colProps[j];
                EditColor       editColor       = mate.editColors[j];
                writer.Write(shaderPropColor.type.ToString());
                writer.Write(shaderPropColor.keyName);
                ACCMaterialEx.OUT_UTIL.Write(writer, editColor.val);
            }
            for (int k = 0; k < mate.editVals.Length; k++)
            {
                ShaderPropFloat shaderPropFloat = mate.type.fProps[k];
                EditValue       editValue       = mate.editVals[k];
                writer.Write(shaderPropFloat.type.ToString());
                writer.Write(shaderPropFloat.keyName);
                writer.Write(editValue.val);
            }
        }
        // Token: 0x060000E0 RID: 224 RVA: 0x0000AF74 File Offset: 0x00009174
        public static ACCMaterialEx Load(string file)
        {
            bool flag;

            using (BinaryReader binaryReader = new BinaryReader(FileUtilEx.Instance.GetStream(file, out flag), Encoding.UTF8))
            {
                string text = binaryReader.ReadString();
                if (flag || binaryReader.BaseStream.Position > 0L)
                {
                    if (text == FileConst.HEAD_MATE)
                    {
                        return(ACCMaterialEx.Load(binaryReader));
                    }
                    StringBuilder stringBuilder = LogUtil.Log(new object[]
                    {
                        "指定されたファイルのヘッダが不正です。",
                        text,
                        file
                    });
                    throw new ACCException(stringBuilder.ToString());
                }
            }
            ACCMaterialEx result;

            using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(FileUtilEx.Instance.LoadInternal(file), false), Encoding.UTF8))
            {
                string text2 = binaryReader2.ReadString();
                if (!(text2 == FileConst.HEAD_MATE))
                {
                    StringBuilder stringBuilder2 = LogUtil.Log(new object[]
                    {
                        "指定されたファイルのヘッダが不正です。",
                        text2,
                        file
                    });
                    throw new ACCException(stringBuilder2.ToString());
                }
                result = ACCMaterialEx.Load(binaryReader2);
            }
            return(result);
        }
Ejemplo n.º 5
0
        public void Init(ACCMaterial edited)
        {
            editedMat = edited;

            // ファイルからマテリアル情報をロード
            if (onlyModel)
            {
                // modelファイルからマテリアルのロード
            }
            else if (!string.IsNullOrEmpty(filename))
            {
                LogUtil.Debug("load material file", filename);
                srcMat        = ACCMaterialEx.Load(filename);
                shaderChanged = (editedMat.type != srcMat.type);
            }

            // pmat チェック
            //  透過型のみを対象とし、
            //     1. マテリアル名に対応するpmatが存在しない場合
            //     2. renderQueueが変更されている場合
            if (edited.type.isTrans)
            {
                // renderqueueがデフォルト値であれば変更不要
                if (Math.Abs(edited.renderQueue.val - 2000) < 0.01f)
                {
                    needPmat = false;
                }
                else
                {
                    needPmat = true;

                    var matName = (srcMat != null)? srcMat.name2 : edited.name;
                    var srcRq   = MaterialUtil.GetRenderQueue(matName);
                    // 既存のマテリアル名に対応するpmatが存在しない => 変更必要
                    if (srcRq < 0)
                    {
                        needPmatChange = true;
                    }
                    LogUtil.DebugF("render queue: src={0}, edited={1}", srcRq, edited.renderQueue);

                    needPmatChange |= !NumberUtil.Equals(edited.renderQueue.val, srcRq, 0.01f);
                    pmatExport      = needPmatChange;
                }
            }

            if (!shaderChanged)
            {
                // TODO modelロードでsrcMatを作成した場合は条件削除可能
                if (srcMat != null)
                {
                    hasParamChanged = editedMat.HasChanged(srcMat);
                }
            }

            editname = editedMat.material.name;
            var maid = MaidHolder.Instance.CurrentMaid;

            // テクスチャの変更フラグチェック
            foreach (var texProp in editedMat.type.texProps)
            {
                //foreach (string propName in editedMat.type1.texPropNames) {
                LogUtil.Debug("propName:", texProp.key);

                var tex          = editedMat.material.GetTexture(texProp.propId);
                var filter       = ACCTexturesView.GetFilter(maid, slotName, editedMat.material, texProp.propId);
                var colorChanged = (filter != null) && !filter.HasNotChanged();
                var fileChanged  = false;
                if (tex != null && srcMat != null)
                {
                    ACCTextureEx baseTex;
                    if (srcMat.texDic.TryGetValue(texProp.key, out baseTex))
                    {
                        fileChanged = (baseTex.editname != tex.name);
                    }
                }

                var trgtTex = new TargetTexture(colorChanged, fileChanged, tex)
                {
                    filter = filter
                };
                texDic[texProp.key] = trgtTex;
                hasTexColorChanged |= colorChanged;
                hasTexFileChanged  |= fileChanged;
            }
            LogUtil.Debug("target material initialized");
        }
        private static ACCMaterialEx Load(BinaryReader reader)
        {
            int    version     = reader.ReadInt32();
            string name1       = reader.ReadString();
            string name2       = reader.ReadString();
            string shaderName1 = reader.ReadString();
            var    shaderType  = ShaderType.Resolve(shaderName1);

            var created = new ACCMaterialEx(shaderType);

            created.name1 = name1;
            created.name2 = name2;

            //created.shader = created.type;
            //created.type1 = ShaderMapper.resolve(shaderName1);
            //created.shader = created.type1.shader;

            string shaderName2 = reader.ReadString();

            while (true)
            {
                string type = reader.ReadString();
                if (type == "end")
                {
                    break;
                }

                string propName = reader.ReadString();
                switch (type)
                {
                case "tex":
                    string sub = reader.ReadString();
                    switch (sub)
                    {
                    case "tex2d":

                        var tex = new ACCTextureEx(propName);
                        tex.editname  = reader.ReadString();
                        tex.txtpath   = reader.ReadString();
                        tex.texOffset = new Vector2(reader.ReadSingle(),
                                                    reader.ReadSingle());
                        tex.texScale = new Vector2(reader.ReadSingle(),
                                                   reader.ReadSingle());
                        created.texDic[tex.propKey] = tex;
                        break;

                    case "null":
                        break;

                    case "texRT":
                        reader.ReadString();
                        reader.ReadString();
                        break;
                    }
                    break;

                case "col":
                case "vec":
                    var c = new Color(reader.ReadSingle(), reader.ReadSingle(),
                                      reader.ReadSingle(), reader.ReadSingle());
                    created.SetColor(propName, c);
                    break;

                case "f":
                    float f = reader.ReadSingle();
                    created.SetFloat(propName, f);
                    break;
                }
            }
            return(created);
        }
        // Token: 0x060000E1 RID: 225 RVA: 0x0000B0A4 File Offset: 0x000092A4
        private static ACCMaterialEx Load(BinaryReader reader)
        {
            reader.ReadInt32();
            string        text          = reader.ReadString();
            string        text2         = reader.ReadString();
            string        name          = reader.ReadString();
            ShaderType    type          = ShaderType.Resolve(name);
            ACCMaterialEx accmaterialEx = new ACCMaterialEx(type)
            {
                name1 = text,
                name2 = text2
            };

            reader.ReadString();
            for (;;)
            {
                string text3 = reader.ReadString();
                if (text3 == "end")
                {
                    break;
                }
                string propName = reader.ReadString();
                string a;
                if ((a = text3) != null)
                {
                    if (!(a == "tex"))
                    {
                        if (!(a == "col") && !(a == "vec"))
                        {
                            if (a == "f")
                            {
                                float f = reader.ReadSingle();
                                accmaterialEx.SetFloat(propName, f);
                            }
                        }
                        else
                        {
                            Color c = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                            accmaterialEx.SetColor(propName, c);
                        }
                    }
                    else
                    {
                        string text4 = reader.ReadString();
                        string a2;
                        if ((a2 = text4) != null)
                        {
                            if (!(a2 == "tex2d"))
                            {
                                if (!(a2 == "null"))
                                {
                                    if (a2 == "texRT")
                                    {
                                        reader.ReadString();
                                        reader.ReadString();
                                    }
                                }
                            }
                            else
                            {
                                ACCTextureEx acctextureEx = new ACCTextureEx(propName);
                                acctextureEx.editname    = reader.ReadString();
                                acctextureEx.txtpath     = reader.ReadString();
                                acctextureEx.texOffset.x = reader.ReadSingle();
                                acctextureEx.texOffset.y = reader.ReadSingle();
                                acctextureEx.texScale.x  = reader.ReadSingle();
                                acctextureEx.texScale.y  = reader.ReadSingle();
                                accmaterialEx.texDic[acctextureEx.propKey] = acctextureEx;
                            }
                        }
                    }
                }
            }
            return(accmaterialEx);
        }
        public static void Write(BinaryWriter writer, ACCMaterialEx mate) {
            writer.Write(FileConst.HEAD_MATE);
            writer.Write(1000); // version

            writer.Write(mate.name1);
            writer.Write(mate.name2);

            var shaderName1 = mate.type.name;
            writer.Write(shaderName1);
            var shaderName2 = ShaderType.GetShader2(shaderName1);
            writer.Write(shaderName2);

            // tex
            for (int i=0; i<mate.type.texProps.Length; i++) {
                var texProp = mate.type.texProps[i];
                if (texProp.key == PropKey._RenderTex) {
                    writer.Write("null");
                } else {
                    writer.Write("tex2d");
                    var tex = mate.texDic[texProp.key];
                    writer.Write( tex.editname );
                    writer.Write( tex.txtpath );
    
                    outUtil.Write(writer,  tex.texOffset.Value);
                    outUtil.Write(writer,  tex.texScale.Value);
                }
            }
            // col
            for (int i=0; i<mate.editColors.Length; i++) {
                var colProp = mate.type.colProps[i];
                var eColor = mate.editColors[i];

                // PropType.col
                writer.Write(colProp.type.ToString());
                writer.Write(colProp.keyName);
                outUtil.Write(writer, eColor.val.Value);
            }
            // f
            for (int i=0; i<mate.editVals.Length; i++) {
                var prop = mate.type.fProps[i];
                var eVal = mate.editVals[i];

                // PropType.f
                writer.Write(prop.type.ToString());
                writer.Write(prop.keyName);
                writer.Write(eVal.val);
            }
        }
 public static void Write(string filepath, ACCMaterialEx mate) {
     using ( var writer = new BinaryWriter(File.OpenWrite(filepath)) ) {
         Write(writer, mate);
     }
 }
        private static ACCMaterialEx Load(BinaryReader reader) {
            int version = reader.ReadInt32();
            string name1 = reader.ReadString();
            string name2 = reader.ReadString();
            string shaderName1 = reader.ReadString();
            var shaderType = ShaderType.Resolve(shaderName1);
            
            var created = new ACCMaterialEx(shaderType);
            created.name1 = name1;
            created.name2 = name2;

            //created.shader = created.type;
            //created.type1 = ShaderMapper.resolve(shaderName1);
            //created.shader = created.type1.shader;
            
            string shaderName2 = reader.ReadString();

            while(true) {
                string type = reader.ReadString();
                if (type == "end") break;

                string propName = reader.ReadString();
                switch (type) {
                    case "tex":
                        string sub = reader.ReadString();
                        switch (sub) {
                        case "tex2d":
                            
                            var tex = new ACCTextureEx(propName);
                            tex.editname = reader.ReadString();
                            tex.txtpath  = reader.ReadString();
                            tex.texOffset = new Vector2(reader.ReadSingle(),
                                                        reader.ReadSingle());
                            tex.texScale  = new Vector2(reader.ReadSingle(),
                                                        reader.ReadSingle());                                
                            created.texDic[tex.propKey] = tex;
                            break;
                        case "null":
                            break;
                        case "texRT":
                            reader.ReadString();
                            reader.ReadString();
                            break;
                    }
                    break;
                case "col":
                case "vec":
                    var c = new Color(reader.ReadSingle(), reader.ReadSingle(),
                                      reader.ReadSingle(), reader.ReadSingle());
                    created.SetColor(propName, c);
                    break;
                case "f":
                    float f = reader.ReadSingle();
                    created.SetFloat(propName, f);
                    break;
                }
            }
            return created;           
        }
Ejemplo n.º 11
0
        // Token: 0x06000139 RID: 313 RVA: 0x0000C670 File Offset: 0x0000A870
        public void Init(ACCMaterial edited)
        {
            this.editedMat = edited;
            if (!this.onlyModel && !string.IsNullOrEmpty(this.filename))
            {
                LogUtil.Debug(new object[]
                {
                    "load material file",
                    this.filename
                });
                this.srcMat        = ACCMaterialEx.Load(this.filename);
                this.shaderChanged = (this.editedMat.type != this.srcMat.type);
            }
            if (edited.type.isTrans)
            {
                if (Math.Abs(edited.renderQueue.val - 2000f) < 0.01f)
                {
                    this.needPmat = false;
                }
                else
                {
                    this.needPmat = true;
                    string matName     = (this.srcMat != null) ? this.srcMat.name2 : edited.name;
                    float  renderQueue = MaterialUtil.GetRenderQueue(matName);
                    if (renderQueue < 0f)
                    {
                        this.needPmatChange = true;
                    }
                    LogUtil.DebugF("render queue: src={0}, edited={1}", new object[]
                    {
                        renderQueue,
                        edited.renderQueue
                    });
                    this.needPmatChange |= !NumberUtil.Equals(edited.renderQueue.val, renderQueue, 0.01f);
                    this.pmatExport      = this.needPmatChange;
                }
            }
            if (!this.shaderChanged && this.srcMat != null)
            {
                this.hasParamChanged = this.editedMat.HasChanged(this.srcMat);
            }
            this.editname = this.editedMat.material.name;
            Maid currentMaid = MaidHolder.Instance.CurrentMaid;

            foreach (ShaderPropTex shaderPropTex in this.editedMat.type.texProps)
            {
                LogUtil.Debug(new object[]
                {
                    "propName:",
                    shaderPropTex.key
                });
                Texture texture = this.editedMat.material.GetTexture(shaderPropTex.propId);
                TextureModifier.FilterParam filter = ACCTexturesView.GetFilter(currentMaid, this.slotName, this.editedMat.material, shaderPropTex.propId);
                bool         flag  = filter != null && !filter.HasNotChanged();
                bool         flag2 = false;
                ACCTextureEx acctextureEx;
                if (texture != null && this.srcMat != null && this.srcMat.texDic.TryGetValue(shaderPropTex.key, out acctextureEx))
                {
                    flag2 = (acctextureEx.editname != texture.name);
                }
                TargetTexture value = new TargetTexture(flag, flag2, texture)
                {
                    filter = filter
                };
                this.texDic[shaderPropTex.key] = value;
                this.hasTexColorChanged        = (this.hasTexColorChanged || flag);
                this.hasTexFileChanged         = (this.hasTexFileChanged || flag2);
            }
            LogUtil.Debug(new object[]
            {
                "target material initialized"
            });
        }
        public void Init(ACCMaterial edited) {
            this.editedMat = edited;

            // ファイルからマテリアル情報をロード
            if (onlyModel) {
                // modelファイルからマテリアルのロード
                
            } else if (!string.IsNullOrEmpty(filename)) {
                LogUtil.Debug("load material file", filename);
                srcMat = ACCMaterialEx.Load(filename);
                shaderChanged = (editedMat.type != srcMat.type);
            }

            // pmat チェック
            //  透過型のみを対象とし、
            //     1. マテリアル名に対応するpmatが存在しない場合
            //     2. renderQueueが変更されている場合
            if (edited.type.isTrans) {
                // renderqueueがデフォルト値であれば変更不要
                if (Math.Abs(edited.renderQueue.val - 2000) < 0.01f) {
                    this.needPmat = false;
                } else {
                    this.needPmat = true;

                    string matName = (srcMat != null)? srcMat.name2 : edited.name;
                    float srcRq = MaterialType.GetRenderQueue(matName);
                    // 既存のマテリアル名に対応するpmatが存在しない => 変更必要
                    if (srcRq < 0) this.needPmatChange = true;
                    LogUtil.DebugF("render queue: src={0}, edited={1}", srcRq, edited.renderQueue);
    
                    this.needPmatChange |= !NumberUtil.Equals(edited.renderQueue.val, srcRq, 0.01f);
                    this.pmatExport = needPmatChange;
                }
            }

            if (!shaderChanged) {
                // TODO modelロードでsrcMatを作成した場合は条件削除可能
                if (srcMat != null) hasParamChanged = editedMat.hasChanged(srcMat);
            }

            this.editname = editedMat.material.name;
            var maid = MaidHolder.Instance.currentMaid;

            // テクスチャの変更フラグチェック
            foreach (var texProp in editedMat.type.texProps) {
            //foreach (string propName in editedMat.type1.texPropNames) {
                LogUtil.Debug("propName:", texProp.key);
                
                Texture tex = editedMat.material.GetTexture(texProp.propId);
                var filter = ACCTexturesView.GetFilter(maid, slotName, editedMat.material, texProp.propId);
                var colorChanged = (filter != null) && !filter.hasNotChanged();
                var fileChanged = false;
                if (tex != null && srcMat != null) {
                    ACCTextureEx baseTex;
                    if (srcMat.texDic.TryGetValue(texProp.key, out baseTex)) {
                        fileChanged = (baseTex.editname != tex.name);
                    }
                }
                var trgtTex = new TargetTexture(colorChanged, fileChanged, tex);
                trgtTex.filter = filter;
                texDic[texProp.key] = trgtTex;
                hasTexColorChanged  |= colorChanged;
                hasTexFileChanged   |= fileChanged;
            }
            LogUtil.Debug("target material initialized");
        }