public override IUniformMap Clone() { var copy = new SpecGlossMap(new Material(_material)); base.Copy(copy); return(copy); }
protected virtual MaterialCacheData CreateMaterial(GLTF.Schema.Material def, int materialIndex) { MaterialCacheData materialWrapper = null; if (materialIndex < 0 || _assetCache.MaterialCache[materialIndex] == null) { IUniformMap mapper; const string specGlossExtName = KHR_materials_pbrSpecularGlossinessExtensionFactory.EXTENSION_NAME; if (_root.ExtensionsUsed != null && _root.ExtensionsUsed.Contains(specGlossExtName) && def.Extensions != null && def.Extensions.ContainsKey(specGlossExtName)) { mapper = new SpecGlossMap(MaximumLod); } else { mapper = new MetalRoughMap(MaximumLod); } mapper.AlphaMode = def.AlphaMode; mapper.DoubleSided = def.DoubleSided; var mrMapper = mapper as IMetalRoughUniformMap; if (def.PbrMetallicRoughness != null && mrMapper != null) { var pbr = def.PbrMetallicRoughness; mrMapper.BaseColorFactor = pbr.BaseColorFactor.ToUnityColorRaw(); if (pbr.BaseColorTexture != null) { var textureDef = pbr.BaseColorTexture.Index.Value; mrMapper.BaseColorTexture = CreateTexture(textureDef); mrMapper.BaseColorTexCoord = pbr.BaseColorTexture.TexCoord; //ApplyTextureTransform(pbr.BaseColorTexture, material, "_MainTex"); } mrMapper.MetallicFactor = pbr.MetallicFactor; if (pbr.MetallicRoughnessTexture != null) { var texture = pbr.MetallicRoughnessTexture.Index.Value; mrMapper.MetallicRoughnessTexture = CreateTexture(texture); mrMapper.MetallicRoughnessTexCoord = pbr.MetallicRoughnessTexture.TexCoord; //ApplyTextureTransform(pbr.MetallicRoughnessTexture, material, "_MetallicRoughnessMap"); } mrMapper.RoughnessFactor = pbr.RoughnessFactor; } var sgMapper = mapper as ISpecGlossUniformMap; if (sgMapper != null) { var specGloss = def.Extensions[specGlossExtName] as KHR_materials_pbrSpecularGlossinessExtension; sgMapper.DiffuseFactor = specGloss.DiffuseFactor.ToUnityColorRaw(); if (specGloss.DiffuseTexture != null) { var texture = specGloss.DiffuseTexture.Index.Value; sgMapper.DiffuseTexture = CreateTexture(texture); sgMapper.DiffuseTexCoord = specGloss.DiffuseTexture.TexCoord; //ApplyTextureTransform(specGloss.DiffuseTexture, material, "_MainTex"); } sgMapper.SpecularFactor = specGloss.SpecularFactor.ToUnityVector3Raw(); sgMapper.GlossinessFactor = specGloss.GlossinessFactor; if (specGloss.SpecularGlossinessTexture != null) { var texture = specGloss.SpecularGlossinessTexture.Index.Value; sgMapper.SpecularGlossinessTexture = CreateTexture(texture); //ApplyTextureTransform(specGloss.SpecularGlossinessTexture, material, "_SpecGlossMap"); } } if (def.NormalTexture != null) { var texture = def.NormalTexture.Index.Value; mapper.NormalTexture = CreateTexture(texture); mapper.NormalTexCoord = def.NormalTexture.TexCoord; mapper.NormalTexScale = def.NormalTexture.Scale; //ApplyTextureTransform(def.NormalTexture, material, "_BumpMap"); } if (def.OcclusionTexture != null) { mapper.OcclusionTexStrength = def.OcclusionTexture.Strength; var texture = def.OcclusionTexture.Index; mapper.OcclusionTexture = CreateTexture(texture.Value); //ApplyTextureTransform(def.OcclusionTexture, material, "_OcclusionMap"); } if (def.EmissiveTexture != null) { var texture = def.EmissiveTexture.Index.Value; mapper.EmissiveTexture = CreateTexture(texture); mapper.EmissiveTexCoord = def.EmissiveTexture.TexCoord; //ApplyTextureTransform(def.EmissiveTexture, material, "_EmissionMap"); } mapper.EmissiveFactor = def.EmissiveFactor.ToUnityColorRaw(); var vertColorMapper = mapper.Clone(); vertColorMapper.VertexColorsEnabled = true; materialWrapper = new MaterialCacheData { UnityMaterial = mapper.Material, UnityMaterialWithVertexColor = vertColorMapper.Material, GLTFMaterial = def }; if (materialIndex > 0) { _assetCache.MaterialCache[materialIndex] = materialWrapper; } } return(materialIndex > 0 ? _assetCache.MaterialCache[materialIndex] : materialWrapper); }