From 5fb803314843a58155207b212483e62f89735b43 Mon Sep 17 00:00:00 2001 From: Alexey Knyazev <3479527+lexaknyazev@users.noreply.github.com> Date: Mon, 17 Jun 2024 00:00:00 +0000 Subject: [PATCH] Validate clearcoat normal texture texcoords --- ISSUES.md | 1 + lib/src/errors.dart | 7 +++ .../khr_materials_clearcoat.dart | 14 ++++++ test/ext/KHR_materials_clearcoat/assets.json | 1 + .../data/material/different_texcoords.gltf | 28 ++++++++++++ .../different_texcoords.gltf.report.json | 44 +++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf create mode 100644 test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf.report.json diff --git a/ISSUES.md b/ISSUES.md index 4c384016..0b8c2a34 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -42,6 +42,7 @@ |INVALID_EXTENSION_NAME_FORMAT|Extension name has invalid format.|Warning| |INVALID_GL_VALUE|Invalid value `%1` for GL type '`%2`'.|Error| |KHR_LIGHTS_PUNCTUAL_LIGHT_SPOT_ANGLES|outerConeAngle (`%2`) is less than or equal to innerConeAngle (`%1`).|Error| +|KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD|Normal and clearcoat normal textures should use the same texture coords.|Warning| |KHR_MATERIALS_DISPERSION_NO_VOLUME|The dispersion extension needs to be combined with the volume extension.|Warning| |KHR_MATERIALS_EMISSIVE_STRENGTH_ZERO_FACTOR|Emissive strength has no effect when the emissive factor is zero or undefined.|Warning| |KHR_MATERIALS_IRIDESCENCE_THICKNESS_RANGE_INVALID|Thickness maximum must be greater than or equal to the thickness minimum.|Error| diff --git a/lib/src/errors.dart b/lib/src/errors.dart index 3580d503..08304df3 100644 --- a/lib/src/errors.dart +++ b/lib/src/errors.dart @@ -489,6 +489,13 @@ class SemanticError extends IssueType { (args) => 'outerConeAngle (${args[1]}) is less than or equal to ' 'innerConeAngle (${args[0]}).'); + static final SemanticError + khrMaterialsClearcoatClearcoatNormalTextureTexCoord = SemanticError._( + 'KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD', + (args) => 'Normal and clearcoat normal textures ' + 'should use the same texture coords.', + Severity.Warning); + static final SemanticError khrMaterialsDispersionNoVolume = SemanticError._( 'KHR_MATERIALS_DISPERSION_NO_VOLUME', (args) => 'The dispersion extension needs to be combined with ' diff --git a/lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart b/lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart index 43bf078a..f78efea6 100644 --- a/lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart +++ b/lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart @@ -97,6 +97,20 @@ class KhrMaterialsClearcoat extends GltfProperty { if (clearcoatNormalTexture != null) { context.path.add(CLEARCOAT_NORMAL_TEXTURE); clearcoatNormalTexture.link(gltf, context); + + Object o = this; + while (o != null) { + o = context.owners[o]; + if (o is Material) { + final normalTexture = o.normalTexture; + if (normalTexture != null && + normalTexture.texCoord != clearcoatNormalTexture.texCoord) { + context.addIssue(SemanticError + .khrMaterialsClearcoatClearcoatNormalTextureTexCoord); + } + break; + } + } context.path.removeLast(); } } diff --git a/test/ext/KHR_materials_clearcoat/assets.json b/test/ext/KHR_materials_clearcoat/assets.json index 2f417933..9ff88eeb 100644 --- a/test/ext/KHR_materials_clearcoat/assets.json +++ b/test/ext/KHR_materials_clearcoat/assets.json @@ -3,6 +3,7 @@ "name": "material.KHR_materials_clearcoat", "tests": { "custom_property.gltf": "Custom property", + "different_texcoords.gltf": "Normal and clearcoat normal textures with different texcoords", "no_tangent_space.gltf": "No tangent space", "unexpected_extension.gltf": "Unexpected extension object location", "valid.gltf": "Valid", diff --git a/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf b/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf new file mode 100644 index 00000000..ea8e76a1 --- /dev/null +++ b/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf @@ -0,0 +1,28 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_clearcoat" + ], + "materials": [ + { + "normalTexture": { + "index": 0 + }, + "extensions": { + "KHR_materials_clearcoat": { + "clearcoatNormalTexture": { + "index": 1, + "texCoord": 1 + } + } + } + } + ], + "textures": [ + { + }, { + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf.report.json b/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf.report.json new file mode 100644 index 00000000..1b6c088e --- /dev/null +++ b/test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 0, + "numWarnings": 1, + "numInfos": 1, + "numHints": 0, + "messages": [ + { + "code": "KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD", + "message": "Normal and clearcoat normal textures should use the same texture coords.", + "severity": 1, + "pointer": "/materials/0/extensions/KHR_materials_clearcoat/clearcoatNormalTexture" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_clearcoat" + ], + "animationCount": 0, + "materialCount": 1, + "hasMorphTargets": false, + "hasSkins": false, + "hasTextures": true, + "hasDefaultScene": false, + "drawCallCount": 0, + "totalVertexCount": 0, + "totalTriangleCount": 0, + "maxUVs": 0, + "maxInfluences": 0, + "maxAttributes": 0 + } +} \ No newline at end of file