Skip to content

Commit

Permalink
Validate clearcoat normal texture texcoords (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexaknyazev authored Jun 25, 2024
1 parent bc2159d commit de37778
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
7 changes: 7 additions & 0 deletions lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
14 changes: 14 additions & 0 deletions lib/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions test/ext/KHR_materials_clearcoat/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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": [
{
}, {
}
]
}
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit de37778

Please sign in to comment.