protected bool TrySetTexture( TextureInfo textureInfo, UnityEngine.Material material, int propertyId, IGltfReadable gltf ) { if (textureInfo != null && textureInfo.index >= 0) { int textureIndex = textureInfo.index; var srcTexture = gltf.GetSourceTexture(textureIndex); if (srcTexture != null) { var texture = gltf.GetTexture(textureIndex); if (texture != null) { if (textureInfo.texCoord != 0) { logger?.Error(LogCode.UVMulti); } material.SetTexture(propertyId, texture); var isKtx = srcTexture.isKtx; TrySetTextureTransform(textureInfo, material, propertyId, isKtx); return(true); } logger?.Error(LogCode.TextureLoadFailed, textureIndex.ToString()); } else { logger?.Error(LogCode.TextureNotFound, textureIndex.ToString()); } } return(false); }
/// <summary> /// Attempts assigning a glTF texture to a Unity material. /// </summary> /// <param name="textureInfo">glTF source texture</param> /// <param name="material">target material</param> /// <param name="gltf">Context glTF</param> /// <param name="texturePropertyId">Target texture property</param> /// <param name="scaleTransformPropertyId">Scale/transform (_ST) property</param> /// <param name="rotationPropertyId">Rotation property</param> /// <param name="uvChannelPropertyId">UV channel selection property</param> /// <returns>True if texture assignment was successful, false otherwise.</returns> protected bool TrySetTexture( TextureInfo textureInfo, UnityEngine.Material material, IGltfReadable gltf, int texturePropertyId, int scaleTransformPropertyId = -1, int rotationPropertyId = -1, int uvChannelPropertyId = -1 ) { if (textureInfo != null && textureInfo.index >= 0) { int textureIndex = textureInfo.index; var srcTexture = gltf.GetSourceTexture(textureIndex); if (srcTexture != null) { var texture = gltf.GetTexture(textureIndex); if (texture != null) { material.SetTexture(texturePropertyId, texture); var isKtx = srcTexture.isKtx; TrySetTextureTransform( textureInfo, material, texturePropertyId, scaleTransformPropertyId, rotationPropertyId, uvChannelPropertyId, isKtx ); return(true); } #if UNITY_IMAGECONVERSION logger?.Error(LogCode.TextureLoadFailed, textureIndex.ToString()); #endif } else { logger?.Error(LogCode.TextureNotFound, textureIndex.ToString()); } } return(false); }