Example #1
0
        protected void AddMinMaxGradient(MyJson_Tree compItem, string key, ParticleSystem.MinMaxGradient gradient)
        {
            MyJson_Tree gradientItem = new MyJson_Tree(false);

            gradientItem.SetEnum("mode", gradient.mode);

            switch (gradient.mode)
            {
            case ParticleSystemGradientMode.Color:
                gradientItem.SetColor("color", gradient.color);
                break;

            case ParticleSystemGradientMode.TwoColors:
                gradientItem.SetColor("colorMin", gradient.colorMin);
                gradientItem.SetColor("colorMax", gradient.colorMax);
                break;

            case ParticleSystemGradientMode.Gradient:
                this.AddGradient(gradientItem, "gradient", gradient.gradient);
                break;

            case ParticleSystemGradientMode.TwoGradients:
                this.AddGradient(gradientItem, "gradientMin", gradient.gradientMin);
                this.AddGradient(gradientItem, "gradientMax", gradient.gradientMax);
                break;
            }

            compItem[key] = gradientItem;
        }
Example #2
0
        protected void AddMinMaxCurve(MyJson_Tree compItem, string key, ParticleSystem.MinMaxCurve curve, float scale = 1.0f)
        {
            MyJson_Tree curveItem = new MyJson_Tree(false);

            curveItem.SetEnum("mode", curve.mode);
            switch (curve.mode)
            {
            case ParticleSystemCurveMode.Constant:
                curveItem.SetNumber("constant", curve.constant);
                break;

            case ParticleSystemCurveMode.TwoConstants:
                curveItem.SetNumber("constantMin", curve.constantMin);
                curveItem.SetNumber("constantMax", curve.constantMax);
                break;

            case ParticleSystemCurveMode.Curve:
                this.AddCurve(curveItem, "curve", FillCurve(curve.curve, curve.curveMultiplier * scale));
                break;

            case ParticleSystemCurveMode.TwoCurves:
                this.AddCurve(curveItem, "curveMin", FillCurve(curve.curveMin, curve.curveMultiplier * scale));
                this.AddCurve(curveItem, "curveMax", FillCurve(curve.curveMax, curve.curveMultiplier * scale));
                break;
            }

            compItem[key] = curveItem;
        }
        public static void SetAnimation(this MyJson_Object jsonNode, GameObject obj, UnityEngine.AnimationClip[] animationClips)
        {
            var exportAnimations = new MyJson_Array();

            jsonNode["_animations"] = exportAnimations;

            foreach (var animationClip in animationClips)
            {
                var gltfHash = animationClip.GetInstanceID();
                var url      = UnityEditor.AssetDatabase.GetAssetPath(animationClip);
                url = url.Substring(0, url.LastIndexOf(".")) + "_" + animationClip.name + ".ani.bin";
                url = PathHelper.CheckFileName(url);
                //
                var assetIndex = ResourceManager.instance.AddAssetUrl(url);
                if (!ResourceManager.instance.HaveCache(gltfHash))
                {
                    var glTFWriter = new AnimationXWriter(obj.transform, animationClip);
                    ResourceManager.instance.AddFileBuffer(url, glTFWriter.WriteGLTF());
                    //
                    ResourceManager.instance.SaveCache(gltfHash, url);
                }
                var aniItem = new MyJson_Tree();
                aniItem.SetInt("asset", assetIndex);
                exportAnimations.Add(aniItem);
            }
        }
Example #4
0
        protected void SetBlend(MyJson_Array enalbesJson, MyJson_Tree functionsJson, BlendMode blend)
        {
            if (blend == BlendMode.None)
            {
                return;
            }
            enalbesJson.AddInt((int)EnableState.BLEND);

            var blendFuncSeparate = new int[4];

            switch (blend)
            {
            case BlendMode.Add:
                blendFuncSeparate[0] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[1] = (int)BlendFactor.ONE;
                blendFuncSeparate[2] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[3] = (int)BlendFactor.ONE;
                break;

            case BlendMode.Blend:
                blendFuncSeparate[0] = (int)BlendFactor.SRC_ALPHA;
                blendFuncSeparate[1] = (int)BlendFactor.ONE_MINUS_SRC_ALPHA;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE_MINUS_SRC_ALPHA;
                break;

            case BlendMode.Add_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ONE;
                blendFuncSeparate[1] = (int)BlendFactor.ONE;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE;
                break;

            case BlendMode.Blend_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ONE;
                blendFuncSeparate[1] = (int)BlendFactor.ONE_MINUS_CONSTANT_ALPHA;
                blendFuncSeparate[2] = (int)BlendFactor.ONE;
                blendFuncSeparate[3] = (int)BlendFactor.ONE_MINUS_CONSTANT_ALPHA;
                break;

            case BlendMode.Multiply:
                blendFuncSeparate[0] = (int)BlendFactor.ZERO;
                blendFuncSeparate[1] = (int)BlendFactor.SRC_COLOR;
                blendFuncSeparate[2] = (int)BlendFactor.ZERO;
                blendFuncSeparate[3] = (int)BlendFactor.SRC_COLOR;
                break;

            case BlendMode.Multiply_PreMultiply:
                blendFuncSeparate[0] = (int)BlendFactor.ZERO;
                blendFuncSeparate[1] = (int)BlendFactor.SRC_COLOR;
                blendFuncSeparate[2] = (int)BlendFactor.ZERO;
                blendFuncSeparate[3] = (int)BlendFactor.SRC_ALPHA;
                break;
            }

            int[] blendEquationSeparate = { (int)BlendEquation.FUNC_ADD, (int)BlendEquation.FUNC_ADD };
            this.SetBlendEquationSeparate(functionsJson, blendEquationSeparate);
            this.SetBlendFuncSeparate(functionsJson, blendFuncSeparate);
        }
        protected override void Update()
        {
            //自定义的value全部导出,不和默认值做过滤
            var target             = this.source;
            var materialProperties = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { target });

            foreach (var materialProperty in materialProperties)
            {
                if (materialProperty.flags == MaterialProperty.PropFlags.HideInInspector)
                {
                    continue;
                }

                var    uniform = new MyJson_Tree();
                string type    = materialProperty.type.ToString();
                if (type == "Float" || type == "Range")
                {
                    this.values.SetNumber(materialProperty.name, this.GetFloat(materialProperty.name, 0.0f));
                }
                else if (type == "Vector")
                {
                    this.values.SetVector4(materialProperty.name, this.GetVector4(materialProperty.name, Vector4.zero));
                }
                else if (type == "Color")
                {
                    this.values.SetColor(materialProperty.name, this.GetColor(materialProperty.name, Color.white));
                }
                else if (type == "Texture")
                {
                    var tex = this.GetTexture(materialProperty.name, null);
                    if (tex != null)
                    {
                        string texdim = materialProperty.textureDimension.ToString();
                        if (texdim == "Tex2D")
                        {
                            this.SetTexture(materialProperty.name, tex);

                            string propertyName = materialProperty.name + "_ST";
                            if (target.HasProperty(propertyName))
                            {
                                this.values.SetVector4(propertyName, this.GetVector4(propertyName, Vector4.zero));
                            }
                        }
                        else
                        {
                            throw new Exception("not suport texdim:" + texdim);
                        }
                    }
                }
                else
                {
                    throw new Exception("not support type: " + materialProperty.type);
                }
            }

            MyLog.Log("自定义Shader:" + this.technique);
        }
Example #6
0
        protected void SetFrontFace(MyJson_Tree functionsJson, int[] frontFaceValue)
        {
            var frontFace = new MyJson_Array();

            foreach (var v in frontFaceValue)
            {
                frontFace.AddInt(v);
            }
            functionsJson.Add("frontFace", frontFace);
        }
Example #7
0
        protected void SetCullFace(MyJson_Tree functionsJson, int[] cullFaceValue)
        {
            var cullFace = new MyJson_Array();

            foreach (var v in cullFaceValue)
            {
                cullFace.AddInt(v);
            }
            functionsJson.Add("cullFace", cullFace);
        }
Example #8
0
        protected void SetDepthFunc(MyJson_Tree functionsJson, int[] depthFuncValue)
        {
            var depthFunc = new MyJson_Array();

            foreach (var v in depthFuncValue)
            {
                depthFunc.AddInt(v);
            }
            functionsJson.Add("depthFunc", depthFunc);
        }
Example #9
0
        protected void SetDepthMask(MyJson_Tree functionsJson, int[] depthMaskValue)
        {
            var depthMask = new MyJson_Array();

            foreach (var v in depthMaskValue)
            {
                depthMask.AddBool(v != 0);
            }
            functionsJson.Add("depthMask", depthMask);
        }
Example #10
0
        protected void SetBlendFuncSeparate(MyJson_Tree functionsJson, int[] blendFuncSeparateValue)
        {
            var blendFuncSeparate = new MyJson_Array();

            foreach (var v in blendFuncSeparateValue)
            {
                blendFuncSeparate.AddInt((int)v);
            }
            functionsJson.Add("blendFuncSeparate", blendFuncSeparate);
        }
        /**
         * 保存纹理图片相关信息
         */
        public string SaveTextureFormat(Texture2D tex, string texPath, string matPath, bool closemipmap = false, string ext = "png", bool normal = false)
        {
            string name = PathHelper.CheckFileName(tex.name + ".image.json");

            MyJson_Tree textureItem = new MyJson_Tree();
            var         fileName    = texPath.Substring(0, texPath.LastIndexOf(".") + 1) + ext;

            textureItem.SetString("name", PathHelper.CheckFileName(texPath));
            textureItem.SetEnum("filterMode", tex.filterMode, true);
            textureItem.SetEnum("wrap", tex.wrapMode, true);
            textureItem.SetBool("mipmap", !closemipmap && tex.mipmapCount > 1);

            if (tex.anisoLevel > 1)
            {
                textureItem.SetNumber("anisotropy", tex.anisoLevel);
            }

            if (tex.format == TextureFormat.Alpha8)
            {
                textureItem.SetString("format", "Gray");
            }
            else if (ext == "jpg" ||
                     tex.format == TextureFormat.RGB24 ||
                     tex.format == TextureFormat.PVRTC_RGB2 ||
                     tex.format == TextureFormat.PVRTC_RGB4 ||
                     tex.format == TextureFormat.RGB565 ||
                     tex.format == TextureFormat.ETC_RGB4 ||
                     tex.format == TextureFormat.ATC_RGB4 ||
                     tex.format == TextureFormat.ETC2_RGB ||
                     tex.format == TextureFormat.ASTC_RGB_4x4 ||
                     tex.format == TextureFormat.ASTC_RGB_5x5 ||
                     tex.format == TextureFormat.ASTC_RGB_6x6 ||
                     tex.format == TextureFormat.ASTC_RGB_8x8 ||
                     tex.format == TextureFormat.ASTC_RGB_10x10 ||
                     tex.format == TextureFormat.ASTC_RGB_12x12
                     )
            {
                textureItem.SetString("format", "RGB");
            }

            textureItem.SetInt("version", 2);

            //得到.imgdesc.json数据,并保存到bufs中
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            textureItem.CovertToStringWithFormat(sb, 4);
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
            //相对路径
            var imgdescPath = texPath.Substring(0, texPath.LastIndexOf("/") + 1) + name;

            this.AddFileBuffer(imgdescPath, bs);

            return(imgdescPath);
        }
Example #12
0
        protected void SetCullFace(MyJson_Array enalbesJson, MyJson_Tree functionsJson, bool cull)
        {
            if (cull)
            {
                int[] frontFace = { (int)FrontFace.CCW };
                this.SetFrontFace(functionsJson, frontFace);
                int[] cullFace = { (int)CullFace.BACK };
                this.SetCullFace(functionsJson, cullFace);

                enalbesJson.AddInt((int)EnableState.CULL_FACE);
            }
        }
Example #13
0
        protected void AddCurve(MyJson_Tree curveItem, string key, Keyframe[] keys)
        {
            MyJson_Array frmes = new MyJson_Array();

            foreach (Keyframe k in keys)
            {
                MyJson_Array keyItem = new MyJson_Array();
                keyItem.AddNumber(k.time);
                keyItem.AddNumber(k.value);
                frmes.Add(keyItem);
            }
            curveItem[key] = frmes;
        }
        public static void SetMesh(this MyJson_Object jsonNode, GameObject obj, Mesh mesh)
        {
            if (mesh == null)
            {
                return;
            }

            int    meshHash   = mesh.GetInstanceID();
            string url        = ResourceManager.instance.SaveMesh(obj.transform, mesh);
            var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

            //mesh
            var meshItem = new MyJson_Tree(false);

            meshItem.SetInt("asset", assetIndex);
            jsonNode["_mesh"] = meshItem;
        }
Example #15
0
        protected void SetDepth(MyJson_Array enalbesJson, MyJson_Tree functionsJson, bool zTest, bool zWrite)
        {
            if (zTest && zWrite)
            {
                return;
            }

            if (zTest)
            {
                int[] depthFunc = { (int)DepthFunc.LEQUAL };
                this.SetDepthFunc(functionsJson, depthFunc);
                enalbesJson.AddInt((int)EnableState.DEPTH_TEST);
            }

            int[] depthMask = { zWrite ? 1 : 0 };
            this.SetDepthMask(functionsJson, depthMask);
        }
        public override byte[] WriteGLTF()
        {
            var target   = this._target;
            var gltfJson = new MyJson_Tree();
            //
            var assetJson = new MyJson_Tree();

            assetJson.SetInt("version", 2);
            gltfJson.Add("asset", assetJson);

            var materialsJson = new MyJson_Array();

            gltfJson.Add("materials", materialsJson);

            var extensionsRequired = new MyJson_Array();

            extensionsRequired.AddString("KHR_techniques_webgl");
            extensionsRequired.AddString("paper");
            gltfJson.Add("extensionsRequired", extensionsRequired);

            var extensionsUsed = new MyJson_Array();

            extensionsUsed.AddString("KHR_techniques_webgl");
            extensionsUsed.AddString("paper");
            gltfJson.Add("extensionsUsed", extensionsUsed);
            //
            gltfJson.SetInt("version", 4);

            //Unifrom or Defines
            var materialType = this.GetMaterialType();
            var writer       = MaterialWriterFactory.Create(materialType, target);

            var materialItemJson = writer.Write();

            materialsJson.Add(materialItemJson);
            writer.Clean();

            //
            gltfJson.isWithFormat = true;
            var jsonStr = gltfJson.ToString();

            return(System.Text.Encoding.UTF8.GetBytes(jsonStr));
        }
Example #17
0
        private static MyJson_Array AddLightmaps(string exportPath)
        {
            var lightmapsJson = new MyJson_Array();

            foreach (var lightmapData in LightmapSettings.lightmaps)
            {
                Texture2D lmTexture = lightmapData.lightmapColor;
                int       lmID      = lmTexture.GetInstanceID();
                if (!ResourceManager.instance.HaveCache(lmID))
                {
                    //格式转换
                    string suffix       = "png";
                    string relativePath = UnityEditor.AssetDatabase.GetAssetPath(lmTexture);
                    MyLog.Log("导出lightmap:" + relativePath);
                    string exrPath    = Path.Combine(Application.dataPath, relativePath.Replace("Assets/", ""));
                    string ralPngPath = PathHelper.CheckFileName(relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix);
                    string pngPath    = PathHelper.CheckFileName(Path.Combine(exportPath, ralPngPath));
                    // string ralPngPath = relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix;
                    // string pngPath = Path.Combine(exportPath, ralPngPath);

                    exrPath = exrPath.Replace("\\", "/");
                    pngPath = pngPath.Replace("\\", "/");
                    var bs = ExportImageTools.instance.EncodeToPNG(lmTexture);
                    ResourceManager.instance.AddFileBuffer(ralPngPath, bs);
                    // ExportImageTools.instance.AddExr(exrPath, pngPath);
                    //添加到 compList 和 assetsList
                    ResourceManager.instance.SaveTextureFormat(lmTexture, ralPngPath, ralPngPath + ".image", false);
                    string name        = lmTexture.name + ".image.json";
                    var    imgdescPath = PathHelper.CheckFileName(ralPngPath.Substring(0, ralPngPath.LastIndexOf("/") + 1) + name);

                    var assetIndex = ResourceManager.instance.AddAssetUrl(imgdescPath);

                    var assetItem = new MyJson_Tree();
                    assetItem.SetInt("asset", assetIndex);
                    lightmapsJson.Add(assetItem);
                }
            }
            // ExportImageTools.instance.ExrToPng();

            return(lightmapsJson);
        }
        public static void SetMaterials(this MyJson_Object jsonNode, GameObject obj, Material[] materials, bool isParticleMat = false, bool isAnimationMat = false)
        {
            var materialsItem = new MyJson_Array();

            jsonNode["_materials"] = materialsItem;
            //写材质
            foreach (var material in materials)
            {
                if (!material)
                {
                    Debug.LogWarning(obj.gameObject.name + " 材质缺失,请检查资源");
                    continue;
                }

                int    hash       = material.GetInstanceID();
                string url        = ResourceManager.instance.SaveMaterial(material, isParticleMat, isAnimationMat);
                var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

                var matItem = new MyJson_Tree();
                matItem.SetInt("asset", assetIndex);
                materialsItem.Add(matItem);
            }
        }
Example #19
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            FB.PosePlus.AniPlayer comp = component as FB.PosePlus.AniPlayer;

            var animationsItem = new MyJson_Array();

            compJson["_animations"] = animationsItem;

            var animator = obj.GetComponent <Animator>();

            if (comp.clips.Count > 0 && animator != null)
            {
                int    gltfHash   = animator.runtimeAnimatorController.GetInstanceID();
                string url        = ResourceManager.instance.SaveAniPlayer(comp, animator);
                var    assetIndex = ResourceManager.instance.AddAssetUrl(url);

                var aniItem = new MyJson_Tree();
                aniItem.SetInt("asset", assetIndex);
                animationsItem.Add(aniItem);
            }

            return(true);
        }
Example #20
0
        protected void AddGradient(MyJson_Tree gradientItem, string key, Gradient gradient)
        {
            //alpha和color过渡值最大为4,如果不够手动填充,如果超过,中间的截掉
            GradientAlphaKey[] alphaKeys = this.FillGradientAlpha(gradient);
            GradientColorKey[] colorKeys = this.FillGradientColor(gradient);

            MyJson_Tree gradients = new MyJson_Tree(false);

            gradients.SetEnum("mode", gradient.mode);
            var alphaKeysItem = new MyJson_Array();
            var colorKeysItem = new MyJson_Array();

            gradients["alphaKeys"] = alphaKeysItem;
            gradients["colorKeys"] = colorKeysItem;

            //alphaKey
            foreach (GradientAlphaKey _ak in alphaKeys)
            {
                MyJson_Tree akItem = new MyJson_Tree(false);
                int         akHash = akItem.GetHashCode();
                akItem.SetNumber("alpha", _ak.alpha);
                akItem.SetNumber("time", _ak.time);
                alphaKeysItem.Add(akItem);
            }

            //colorKey
            foreach (GradientColorKey _ck in colorKeys)
            {
                MyJson_Tree ckItem = new MyJson_Tree(false);
                int         ckHash = ckItem.GetHashCode();
                ckItem.SetColor("color", _ck.color);
                ckItem.SetNumber("time", _ck.time);
                colorKeysItem.Add(ckItem);
            }

            gradientItem[key] = gradients;
        }
Example #21
0
        public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson)
        {
            ParticleSystem comp = component as ParticleSystem;

            if (!comp.emission.enabled || obj.GetComponent <ParticleSystemRenderer>() == null)
            {
                MyLog.LogWarning("无效的粒子组件:" + obj.name);
                return(false);
            }

            //main
            {
                var main     = comp.main;
                var mainItem = new MyJson_Tree(false);
                compJson["main"] = mainItem;
                mainItem.SetNumber("duration", main.duration);
                mainItem.SetBool("loop", main.loop);
                this.AddMinMaxCurve(mainItem, "startDelay", main.startDelay);
                this.AddMinMaxCurve(mainItem, "startLifetime", main.startLifetime);
                this.AddMinMaxCurve(mainItem, "startSpeed", main.startSpeed);

                mainItem.SetBool("startSize3D", main.startSize3D);
                if (main.startSize3D)
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSizeX);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSizeY);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSizeZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startSizeX", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeY", main.startSize);
                    this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSize);
                }

                mainItem.SetBool("_startRotation3D", main.startRotation3D);
                if (main.startRotation3D)
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotationX);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotationY);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotationZ);
                }
                else
                {
                    this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotation);
                    this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotation);
                }

                this.AddMinMaxGradient(mainItem, "startColor", main.startColor);
                this.AddMinMaxCurve(mainItem, "gravityModifier", main.gravityModifier);
                mainItem.SetEnum("_simulationSpace", main.simulationSpace);
                mainItem.SetEnum("scaleMode", main.scalingMode);
                mainItem.SetBool("playOnAwake", main.playOnAwake);
                if (ExportToolsSetting.instance.estimateMaxParticles)
                {
                    var value = this.EstimateMaxParticles(comp);
                    mainItem.SetInt("_maxParticles", value);
                    MyLog.Log(comp.gameObject.name + " 粒子估算:" + value);
                }
                else
                {
                    mainItem.SetInt("_maxParticles", main.maxParticles);
                }
            }

            //emission
            {
                var emissionItem = new MyJson_Tree(false);
                compJson["emission"] = emissionItem;
                this.AddMinMaxCurve(emissionItem, "rateOverTime", comp.emission.rateOverTime);
                emissionItem["bursts"] = new MyJson_Array();
                var bursts = new ParticleSystem.Burst[comp.emission.burstCount];
                comp.emission.GetBursts(bursts);
                foreach (var burst in bursts)
                {
                    MyJson_Array burstItem = new MyJson_Array();
                    burstItem.AddNumber(burst.time);
                    burstItem.AddInt(burst.minCount);
                    burstItem.AddInt(burst.maxCount);
                    burstItem.AddInt(burst.cycleCount);
                    burstItem.AddNumber(burst.repeatInterval);
                    (emissionItem["bursts"] as MyJson_Array).Add(burstItem);
                }
            }
            //shape
            if (comp.shape.enabled)
            {
                var shapItem = new MyJson_Tree(false);
                compJson["shape"] = shapItem;
                shapItem.SetEnum("shapeType", comp.shape.shapeType);
                shapItem.SetNumber("angle", comp.shape.angle);
                shapItem.SetNumber("length", comp.shape.length);
                shapItem.SetEnum("arcMode", comp.shape.arcMode);
                shapItem.SetNumber("arc", comp.shape.arc);
                shapItem.SetNumber("arcSpread", comp.shape.arcSpread);
                shapItem.SetEnum("radiusMode", comp.shape.radiusMode);
                shapItem.SetNumber("radius", comp.shape.radius);
                shapItem.SetNumber("radiusSpread", comp.shape.radiusSpread);
                shapItem.SetVector3("box", comp.shape.box);
                shapItem.SetBool("randomDirection", comp.shape.randomDirectionAmount > 0);
                shapItem.SetBool("spherizeDirection", comp.shape.sphericalDirectionAmount > 0);
                this.AddMinMaxCurve(shapItem, "arcSpeed", comp.shape.arcSpeed);
            }
            //velocityOverLifetiem
            if (comp.velocityOverLifetime.enabled)
            {
                var velocityOverItem = new MyJson_Tree(false);
                compJson["velocityOverLifetime"] = velocityOverItem;
                velocityOverItem.SetEnum("_mode", comp.velocityOverLifetime.x.mode);
                velocityOverItem.SetEnum("_space", comp.velocityOverLifetime.space);
                this.AddMinMaxCurve(velocityOverItem, "_x", comp.velocityOverLifetime.x);
                this.AddMinMaxCurve(velocityOverItem, "_y", comp.velocityOverLifetime.y);
                this.AddMinMaxCurve(velocityOverItem, "_z", comp.velocityOverLifetime.z);
            }
            //colorOverLifetime
            if (comp.colorOverLifetime.enabled)
            {
                var colorOverItem = new MyJson_Tree(false);
                compJson["colorOverLifetime"] = colorOverItem;
                this.AddMinMaxGradient(colorOverItem, "_color", comp.colorOverLifetime.color);
            }
            //sizeOverLifetime
            if (comp.sizeOverLifetime.enabled)
            {
                var sizeOverItem = new MyJson_Tree(false);
                compJson["sizeOverLifetime"] = sizeOverItem;
                sizeOverItem.SetBool("_separateAxes", comp.sizeOverLifetime.separateAxes);
                this.AddMinMaxCurve(sizeOverItem, "_size", comp.sizeOverLifetime.size);
                this.AddMinMaxCurve(sizeOverItem, "_x", comp.sizeOverLifetime.x);
                this.AddMinMaxCurve(sizeOverItem, "_y", comp.sizeOverLifetime.y);
                this.AddMinMaxCurve(sizeOverItem, "_z", comp.sizeOverLifetime.z);
            }
            //rotationOverLifetime
            if (comp.rotationOverLifetime.enabled)
            {
                var rotationOverItem = new MyJson_Tree(false);
                compJson["rotationOverLifetime"] = rotationOverItem;
                rotationOverItem.SetBool("_separateAxes", comp.rotationOverLifetime.separateAxes);
                this.AddMinMaxCurve(rotationOverItem, "_x", comp.rotationOverLifetime.x);
                this.AddMinMaxCurve(rotationOverItem, "_y", comp.rotationOverLifetime.y);
                this.AddMinMaxCurve(rotationOverItem, "_z", comp.rotationOverLifetime.z);
            }
            //textureSheetAnimationModule
            if (comp.textureSheetAnimation.enabled)
            {
                var textureSheetAnimation = new MyJson_Tree(false);
                compJson["textureSheetAnimation"] = textureSheetAnimation;
                textureSheetAnimation.SetInt("_numTilesX", comp.textureSheetAnimation.numTilesX);
                textureSheetAnimation.SetInt("_numTilesY", comp.textureSheetAnimation.numTilesY);
                textureSheetAnimation.SetEnum("_animation", comp.textureSheetAnimation.animation);
                textureSheetAnimation.SetBool("_useRandomRow", comp.textureSheetAnimation.useRandomRow);
                textureSheetAnimation.SetInt("_cycleCount", comp.textureSheetAnimation.cycleCount);
                textureSheetAnimation.SetInt("_rowIndex", comp.textureSheetAnimation.rowIndex);
                this.AddMinMaxCurve(textureSheetAnimation, "_frameOverTime", comp.textureSheetAnimation.frameOverTime, comp.textureSheetAnimation.numTilesX * comp.textureSheetAnimation.numTilesY);
                this.AddMinMaxCurve(textureSheetAnimation, "_startFrame", comp.textureSheetAnimation.startFrame);
            }

            return(true);
        }
Example #22
0
        public MyJson_Tree Write()
        {
            this.Update();
            var customConfig = ExportConfig.instance.IsCustomShader(this.shaderName);
            //
            var materialItemJson = new MyJson_Tree();
            var extensions       = new MyJson_Tree();

            materialItemJson.Add("extensions", extensions);

            var KHR_techniques_webglJson = new MyJson_Tree();

            extensions.Add("KHR_techniques_webgl", KHR_techniques_webglJson);

            var paperJson = new MyJson_Tree();

            extensions.Add("paper", paperJson);

            var valuesJson = new MyJson_Tree();

            KHR_techniques_webglJson.Add("values", valuesJson);

            //
            var source     = this.source;
            var shaderName = source.shader.name.ToLower();

            MyLog.Log("Shader:" + shaderName);
            foreach (var value in this.values)
            {
                valuesJson.Add(value.Key, value.Value);
            }
            if (customConfig != null && !string.IsNullOrEmpty(customConfig.technique))
            {
                KHR_techniques_webglJson.SetString("technique", customConfig.technique);
            }
            else
            {
                KHR_techniques_webglJson.SetString("technique", this.technique);
            }
            //paper
            paperJson.SetInt("renderQueue", this.source.renderQueue);


            if (this.defines.Count > 0)
            {
                var definesJson = new MyJson_Array();
                foreach (var define in this.defines)
                {
                    definesJson.AddString(define);
                }
                paperJson.Add("defines", definesJson);
            }

            //
            //standard
            var isDoubleSide  = this.isDoubleSide;
            var isTransparent = this.isTransparent;

            var blend      = this.blendMode;
            var statesJson = new MyJson_Tree();
            var enable     = new MyJson_Array();

            if (isDoubleSide || blend != BlendMode.None || isTransparent || (customConfig != null && customConfig.enable != null))
            {
                //states
                paperJson.Add("states", statesJson);
                var functionsJson = new MyJson_Tree();
                statesJson.Add("enable", enable);
                statesJson.Add("functions", functionsJson);
                if (customConfig != null && customConfig.enable != null)
                {
                    foreach (var value in customConfig.enable)
                    {
                        enable.AddInt(value);
                    }
                    if (customConfig.blendEquationSeparate != null)
                    {
                        this.SetBlendEquationSeparate(functionsJson, customConfig.blendEquationSeparate);
                    }
                    if (customConfig.blendFuncSeparate != null)
                    {
                        this.SetBlendFuncSeparate(functionsJson, customConfig.blendFuncSeparate);
                    }
                    if (customConfig.frontFace != null)
                    {
                        this.SetFrontFace(functionsJson, customConfig.frontFace);
                    }
                    if (customConfig.cullFace != null)
                    {
                        this.SetCullFace(functionsJson, customConfig.cullFace);
                    }
                    if (customConfig.depthFunc != null)
                    {
                        this.SetDepthFunc(functionsJson, customConfig.depthFunc);
                    }
                    if (customConfig.depthMask != null)
                    {
                        this.SetDepthMask(functionsJson, customConfig.depthMask);
                    }
                }
                else
                {
                    this.SetBlend(enable, functionsJson, blend);
                    this.SetCullFace(enable, functionsJson, !isDoubleSide);
                    this.SetDepth(enable, functionsJson, true, !isTransparent);
                }
            }
            return(materialItemJson);
        }