Skip to content

Commit de37778

Browse files
authored
Validate clearcoat normal texture texcoords (#225)
1 parent bc2159d commit de37778

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

ISSUES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
|INVALID_EXTENSION_NAME_FORMAT|Extension name has invalid format.|Warning|
4343
|INVALID_GL_VALUE|Invalid value `%1` for GL type '`%2`'.|Error|
4444
|KHR_LIGHTS_PUNCTUAL_LIGHT_SPOT_ANGLES|outerConeAngle (`%2`) is less than or equal to innerConeAngle (`%1`).|Error|
45+
|KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD|Normal and clearcoat normal textures should use the same texture coords.|Warning|
4546
|KHR_MATERIALS_DISPERSION_NO_VOLUME|The dispersion extension needs to be combined with the volume extension.|Warning|
4647
|KHR_MATERIALS_EMISSIVE_STRENGTH_ZERO_FACTOR|Emissive strength has no effect when the emissive factor is zero or undefined.|Warning|
4748
|KHR_MATERIALS_IRIDESCENCE_THICKNESS_RANGE_INVALID|Thickness maximum must be greater than or equal to the thickness minimum.|Error|

lib/src/errors.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ class SemanticError extends IssueType {
489489
(args) => 'outerConeAngle (${args[1]}) is less than or equal to '
490490
'innerConeAngle (${args[0]}).');
491491

492+
static final SemanticError
493+
khrMaterialsClearcoatClearcoatNormalTextureTexCoord = SemanticError._(
494+
'KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD',
495+
(args) => 'Normal and clearcoat normal textures '
496+
'should use the same texture coords.',
497+
Severity.Warning);
498+
492499
static final SemanticError khrMaterialsDispersionNoVolume = SemanticError._(
493500
'KHR_MATERIALS_DISPERSION_NO_VOLUME',
494501
(args) => 'The dispersion extension needs to be combined with '

lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ class KhrMaterialsClearcoat extends GltfProperty {
9797
if (clearcoatNormalTexture != null) {
9898
context.path.add(CLEARCOAT_NORMAL_TEXTURE);
9999
clearcoatNormalTexture.link(gltf, context);
100+
101+
Object o = this;
102+
while (o != null) {
103+
o = context.owners[o];
104+
if (o is Material) {
105+
final normalTexture = o.normalTexture;
106+
if (normalTexture != null &&
107+
normalTexture.texCoord != clearcoatNormalTexture.texCoord) {
108+
context.addIssue(SemanticError
109+
.khrMaterialsClearcoatClearcoatNormalTextureTexCoord);
110+
}
111+
break;
112+
}
113+
}
100114
context.path.removeLast();
101115
}
102116
}

test/ext/KHR_materials_clearcoat/assets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "material.KHR_materials_clearcoat",
44
"tests": {
55
"custom_property.gltf": "Custom property",
6+
"different_texcoords.gltf": "Normal and clearcoat normal textures with different texcoords",
67
"no_tangent_space.gltf": "No tangent space",
78
"unexpected_extension.gltf": "Unexpected extension object location",
89
"valid.gltf": "Valid",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"asset": {
3+
"version": "2.0"
4+
},
5+
"extensionsUsed": [
6+
"KHR_materials_clearcoat"
7+
],
8+
"materials": [
9+
{
10+
"normalTexture": {
11+
"index": 0
12+
},
13+
"extensions": {
14+
"KHR_materials_clearcoat": {
15+
"clearcoatNormalTexture": {
16+
"index": 1,
17+
"texCoord": 1
18+
}
19+
}
20+
}
21+
}
22+
],
23+
"textures": [
24+
{
25+
}, {
26+
}
27+
]
28+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"uri": "test/ext/KHR_materials_clearcoat/data/material/different_texcoords.gltf",
3+
"mimeType": "model/gltf+json",
4+
"validatorVersion": "2.0.0-dev.3.10",
5+
"issues": {
6+
"numErrors": 0,
7+
"numWarnings": 1,
8+
"numInfos": 1,
9+
"numHints": 0,
10+
"messages": [
11+
{
12+
"code": "KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD",
13+
"message": "Normal and clearcoat normal textures should use the same texture coords.",
14+
"severity": 1,
15+
"pointer": "/materials/0/extensions/KHR_materials_clearcoat/clearcoatNormalTexture"
16+
},
17+
{
18+
"code": "UNUSED_OBJECT",
19+
"message": "This object may be unused.",
20+
"severity": 2,
21+
"pointer": "/materials/0"
22+
}
23+
],
24+
"truncated": false
25+
},
26+
"info": {
27+
"version": "2.0",
28+
"extensionsUsed": [
29+
"KHR_materials_clearcoat"
30+
],
31+
"animationCount": 0,
32+
"materialCount": 1,
33+
"hasMorphTargets": false,
34+
"hasSkins": false,
35+
"hasTextures": true,
36+
"hasDefaultScene": false,
37+
"drawCallCount": 0,
38+
"totalVertexCount": 0,
39+
"totalTriangleCount": 0,
40+
"maxUVs": 0,
41+
"maxInfluences": 0,
42+
"maxAttributes": 0
43+
}
44+
}

0 commit comments

Comments
 (0)