Ejemplo n.º 1
0
        public static void SetTextureArray(this JContainer jsonNode, string key, Texture2DArrayData value)
        {
            var assetData = SerializeObject.SerializeAsset(value);
            var uri       = ExportSetting.instance.GetExportPath(assetData.uri);

            jsonNode.Add(new JProperty(key, uri));
        }
Ejemplo n.º 2
0
        public override void CollectUniformValues()
        {
            base.CollectUniformValues();
            var source = this.source;
            var values = this.data.values;

            var frontTex = source.GetTexture("_FrontTex") as Texture2D;
            var backTex  = source.GetTexture("_BackTex") as Texture2D;
            var leftTex  = source.GetTexture("_LeftTex") as Texture2D;
            var rightTex = source.GetTexture("_RightTex") as Texture2D;
            var upTex    = source.GetTexture("_UpTex") as Texture2D;
            var downTex  = source.GetTexture("_DownTex") as Texture2D;

            /**
             * XxYyZz
             */
            var textureArr = new Texture2DArrayData();

            textureArr.textures     = new Texture2D[6];
            textureArr.textures[0]  = leftTex;
            textureArr.textures[1]  = rightTex;
            textureArr.textures[2]  = upTex;
            textureArr.textures[3]  = downTex;
            textureArr.textures[4]  = frontTex;
            textureArr.textures[5]  = backTex;
            textureArr.materialName = source.name;

            Debug.Log("materialName:" + textureArr.materialName);

            this.data.values.SetTextureArray("tCube", textureArr);
        }
Ejemplo n.º 3
0
        public static string GetTextureDescPath(Texture2DArrayData tex)
        {
            //Texture2DArray 以第一个图片为目录,  以材质名称为名称
            var path = GetTexturePath(tex.textures[0]);

            // //相对路径
            path = path.Substring(0, path.LastIndexOf("/") + 1) + tex.materialName + ".image.json";
            path = PathHelper.CheckFileName(path);
            return(path);
        }
        protected override void Serialize(UnityEngine.Object sourceAsset)
        {
            this.textureArray = sourceAsset as Texture2DArrayData;
            var firstTexture = this.textureArray.textures[0];

            //先把原始图片导出来
            this.ExportTexture();

            var mipmap = firstTexture.mipmapCount > 1;
            //
            {
                var image = new Image();
                image.Uris = new List <string>();
                foreach (var tex in this.textureArray.textures)
                {
                    image.Uris.Add(ExportSetting.instance.GetExportPath(PathHelper.GetTexturePath(tex)));
                }
                this._root.Images.Add(image);
            }
            //
            {
                var filterMode = firstTexture.filterMode;
                var wrapMode   = firstTexture.wrapMode;

                var sampler = new Sampler();
                this._root.Samplers.Add(sampler);
                if (wrapMode == TextureWrapMode.Repeat)
                {
                    sampler.WrapS = GLTF.Schema.WrapMode.Repeat;
                    sampler.WrapT = GLTF.Schema.WrapMode.Repeat;
                }
                else
                {
                    sampler.WrapS = GLTF.Schema.WrapMode.ClampToEdge;
                    sampler.WrapT = GLTF.Schema.WrapMode.ClampToEdge;
                }
                sampler.MagFilter = filterMode == FilterMode.Point ? MagFilterMode.Nearest : MagFilterMode.Linear;
                if (!mipmap)
                {
                    sampler.MagFilter = filterMode == FilterMode.Point ? MagFilterMode.Nearest : MagFilterMode.Linear;
                }
                else if (filterMode == FilterMode.Point)
                {
                    sampler.MinFilter = MinFilterMode.NearestMipmapNearest;
                }
                else if (filterMode == FilterMode.Bilinear)
                {
                    sampler.MinFilter = MinFilterMode.LinearMipmapNearest;
                }
                else if (filterMode == FilterMode.Trilinear)
                {
                    sampler.MinFilter = MinFilterMode.LinearMipmapLinear;
                }
            }
            //
            {
                var gltfTexture = new GLTF.Schema.Texture();
                this._root.Textures.Add(gltfTexture);

                gltfTexture.Sampler    = new SamplerId();
                gltfTexture.Source     = new ImageId();
                gltfTexture.Extensions = new Dictionary <string, IExtension>()
                {
                    {
                        TextureExtension.EXTENSION_NAME,
                        new TextureExtension()
                        {
                            width      = firstTexture.width,
                            height     = firstTexture.height,
                            format     = GetTextureFormat(),
                            levels     = mipmap ? 0 : 1,
                            encoding   = 2,
                            faces      = 6,
                            mapping    = 1,
                            anisotropy = firstTexture.anisoLevel,
                        }
                    }
                };
            }
        }