Skip to content

Commit bb86eac

Browse files
committed
update code of supporting i3dm for legacy texture
adds fallback logic to the baseColorTexture processing due to gltf 1.0 extension KHR_techniques_webgl
1 parent 57c072a commit bb86eac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

native~/Runtime/src/UnityPrepareRendererResources.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,10 @@ void setGltfMaterialParameterValues(
11431143
materialProperties.getMetallicRoughnessFactorID(),
11441144
{(float)pbr.metallicFactor, (float)pbr.roughnessFactor, 0, 0});
11451145

1146+
// Process baseColorTexture with fallback for legacy materials
11461147
const std::optional<TextureInfo>& baseColorTexture = pbr.baseColorTexture;
1148+
bool textureSet = false;
1149+
11471150
if (baseColorTexture) {
11481151
auto texCoordIndexIt =
11491152
primitiveInfo.uvIndexMap.find(baseColorTexture->texCoord);
@@ -1158,10 +1161,36 @@ void setGltfMaterialParameterValues(
11581161
unityMaterial.SetFloat(
11591162
materialProperties.getBaseColorTextureCoordinateIndexID(),
11601163
static_cast<float>(texCoordIndexIt->second));
1164+
textureSet = true;
11611165
}
11621166
}
11631167
}
11641168

1169+
// Fallback: If no standard PBR baseColorTexture, try to use first available
1170+
// texture Only apply fallback if this primitive actually has UV coordinates
1171+
if (!textureSet && !model.textures.empty() &&
1172+
!primitiveInfo.uvIndexMap.empty()) {
1173+
1174+
// Find first available UV channel
1175+
int32_t fallbackUvIndex = primitiveInfo.uvIndexMap.begin()->second;
1176+
1177+
// Try to load first texture
1178+
UnityEngine::Texture fallbackTexture =
1179+
TextureLoader::loadTexture(model, 0, true);
1180+
if (fallbackTexture != nullptr) {
1181+
fallbackTexture.hideFlags(
1182+
DotNet::UnityEngine::HideFlags::HideAndDontSave);
1183+
unityMaterial.SetTexture(
1184+
materialProperties.getBaseColorTextureID(),
1185+
fallbackTexture);
1186+
unityMaterial.SetFloat(
1187+
materialProperties.getBaseColorTextureCoordinateIndexID(),
1188+
static_cast<float>(fallbackUvIndex));
1189+
textureSet = true;
1190+
1191+
}
1192+
}
1193+
11651194
const std::optional<TextureInfo>& metallicRoughness =
11661195
pbr.metallicRoughnessTexture;
11671196
if (metallicRoughness) {

0 commit comments

Comments
 (0)