private void ExportTexture() { var tex = this.texture; var path = PathHelper.GetTexturePath(tex); byte[] bs = ExportImage.Export(tex); if (!SerializeObject.assetsData.ContainsKey(path)) { var assetData = AssetData.Create(path); assetData.buffer = bs; SerializeObject.assetsData.Add(path, assetData); } }
protected override void Serialize(UnityEngine.Object sourceAsset) { this.texture = sourceAsset as UnityEngine.Texture2D; //先把原始图片导出来 this.ExportTexture(); var path = PathHelper.GetTexturePath(this.texture); var mipmap = this.texture.mipmapCount > 1; // { this._root.Images.Add(new Image() { Uri = ExportSetting.instance.GetExportPath(path) }); } // { var filterMode = this.texture.filterMode; var wrapMode = this.texture.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() { anisotropy = this.texture.anisoLevel, format = GetTextureFormat(), levels = mipmap ? 0 : 1 } } }; } }
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, } } }; } }