Skip to content

fix(assets): support rotation and texCoord in glTF KHR_texture_transform - #1072

Open
VanityNie wants to merge 1 commit into
cocos:mainfrom
VanityNie:fix/gltf-khr-texture-transform
Open

VanityNie wants to merge 1 commit into
cocos:mainfrom
VanityNie:fix/gltf-khr-texture-transform

Conversation

@VanityNie

Copy link
Copy Markdown

导入带有 KHR_texture_transform 扩展的 glTF / GLB 模型(论坛反馈 178201)时,GltfConverter 仅读取了 scale 与 offset 写入标准材质 tilingOffset(Vec4),忽略了 rotation(弧度旋转)与扩展内的 texCoord 通道覆写字段,导致带贴图旋转的模型 UV 方向错乱。

修改内容
Mesh 导入阶段(_applyPrimitiveTextureTransform):当 primitive 关联材质的 baseColorTexture 含有非零 KHR_texture_transform.rotation 时,在 _applySettings(法线/切线重算)前按 glTF 2.0 规范矩阵 T * R * S 将 scale、rotation、offset 原地烘焙进对应 TEXCOORD 顶点属性(兼容归一化整型 UV 转浮点);无 rotation 的模型保持原路径不变。
Material 导入阶段:
优先读取 KHR_texture_transform.texCoord 决定 ALBEDO_UV = 'v_uv1';
仅在 !baseColorTransform.rotation 时写入 props['tilingOffset'],避免已烘焙到顶点 UV 的缩放/偏移在 Shader 中被二次叠加。
单元测试:新增 src/core/assets/test/gltf-khr-texture-transform.test.ts,覆盖带 rotation 顶点 UV 烘焙、扩展 texCoord 覆写及无 rotation 模型 tilingOffset 回归校验。
image

@VanityNie
VanityNie force-pushed the fix/gltf-khr-texture-transform branch from 0680143 to fcb7d75 Compare December 3, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant