From 95ed362391e48b3fae56de7a4503b4016f1a64a8 Mon Sep 17 00:00:00 2001 From: Alexey Knyazev <3479527+lexaknyazev@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:02:02 +0400 Subject: [PATCH] Support KHR_materials_anisotropy (#228) --- ISSUES.md | 1 + README.md | 1 + lib/src/errors.dart | 7 ++ .../khr_materials_anisotropy.dart | 87 +++++++++++++++++++ lib/src/ext/extensions.dart | 3 + test/ext/KHR_materials_anisotropy/assets.json | 13 +++ .../data/material/custom_property.gltf | 17 ++++ .../material/custom_property.gltf.report.json | 44 ++++++++++ .../data/material/different_texcoords.gltf | 28 ++++++ .../different_texcoords.gltf.report.json | 44 ++++++++++ .../data/material/no_tangent_space.gltf | 49 +++++++++++ .../no_tangent_space.gltf.report.json | 44 ++++++++++ .../data/material/out_of_range.gltf | 24 +++++ .../material/out_of_range.gltf.report.json | 56 ++++++++++++ .../data/material/unexpected_extension.gltf | 18 ++++ .../unexpected_extension.gltf.report.json | 44 ++++++++++ .../data/material/valid.gltf | 31 +++++++ .../data/material/valid.gltf.report.json | 44 ++++++++++ .../khr_materials_anisotropy_test.dart | 36 ++++++++ 19 files changed, 591 insertions(+) create mode 100644 lib/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart create mode 100644 test/ext/KHR_materials_anisotropy/assets.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/data/material/valid.gltf create mode 100644 test/ext/KHR_materials_anisotropy/data/material/valid.gltf.report.json create mode 100644 test/ext/KHR_materials_anisotropy/khr_materials_anisotropy_test.dart diff --git a/ISSUES.md b/ISSUES.md index 0b8c2a3..fe43bdd 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_ANISOTROPY_ANISOTROPY_TEXTURE_TEXCOORD|Normal and anisotropy textures should use the same texture coords.|Warning| |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| diff --git a/README.md b/README.md index 7380501..85b2b77 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ NuGet package [Third-party contribution]: https://www.nuget.org/packages/GltfVal - Extensions validation - EXT_texture_webp - KHR_lights_punctual + - KHR_materials_anisotropy - KHR_materials_clearcoat - KHR_materials_dispersion - KHR_materials_emissive_strength diff --git a/lib/src/errors.dart b/lib/src/errors.dart index 08304df..7152dd0 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 khrMaterialsAnisotropyAnisotropyTextureTexCoord = + SemanticError._( + 'KHR_MATERIALS_ANISOTROPY_ANISOTROPY_TEXTURE_TEXCOORD', + (args) => 'Normal and anisotropy textures ' + 'should use the same texture coords.', + Severity.Warning); + static final SemanticError khrMaterialsClearcoatClearcoatNormalTextureTexCoord = SemanticError._( 'KHR_MATERIALS_CLEARCOAT_CLEARCOAT_NORMAL_TEXTURE_TEXCOORD', diff --git a/lib/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart b/lib/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart new file mode 100644 index 0000000..2efde5a --- /dev/null +++ b/lib/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart @@ -0,0 +1,87 @@ +// Copyright 2024 The Khronos Group Inc. +// +// SPDX-License-Identifier: Apache-2.0 + +library gltf.extensions.khr_materials_anisotropy; + +import 'package:gltf/src/base/gltf_property.dart'; +import 'package:gltf/src/ext/extensions.dart'; + +const String KHR_MATERIALS_ANISOTROPY = 'KHR_materials_anisotropy'; + +const String ANISOTROPY_STRENGTH = 'anisotropyStrength'; +const String ANISOTROPY_ROTATION = 'anisotropyRotation'; +const String ANISOTROPY_TEXTURE = 'anisotropyTexture'; + +const List KHR_MATERIALS_ANISOTROPY_MEMBERS = [ + ANISOTROPY_STRENGTH, + ANISOTROPY_ROTATION, + ANISOTROPY_TEXTURE +]; + +class KhrMaterialsAnisotropy extends GltfProperty { + final double anisotropyStrength; + final double anisotropyRotation; + final TextureInfo anisotropyTexture; + + KhrMaterialsAnisotropy._(this.anisotropyStrength, this.anisotropyRotation, + this.anisotropyTexture, Map extensions, Object extras) + : super(extensions, extras); + + static KhrMaterialsAnisotropy fromMap( + Map map, Context context) { + if (context.validate) { + checkMembers(map, KHR_MATERIALS_ANISOTROPY_MEMBERS, context); + } + + final anisotropyStrength = + getFloat(map, ANISOTROPY_STRENGTH, context, min: 0, max: 1, def: 0); + final anisotropyRotation = + getFloat(map, ANISOTROPY_ROTATION, context, def: 0); + final anisotropyTexture = getObjectFromInnerMap( + map, ANISOTROPY_TEXTURE, context, TextureInfo.fromMap); + + final extensions = getExtensions(map, KhrMaterialsAnisotropy, context); + + final anisotropy = KhrMaterialsAnisotropy._( + anisotropyStrength, + anisotropyRotation, + anisotropyTexture, + extensions, + getExtras(map, context)); + + context.registerObjectsOwner( + anisotropy, [anisotropyTexture, ...extensions.values]); + + return anisotropy; + } + + @override + void link(Gltf gltf, Context context) { + if (anisotropyTexture != null) { + context.path.add(ANISOTROPY_TEXTURE); + anisotropyTexture.link(gltf, context); + + Object o = this; + while (o != null) { + o = context.owners[o]; + if (o is Material) { + o.needsTangent = true; + final normalTexture = o.normalTexture; + if (normalTexture != null && + normalTexture.texCoord != anisotropyTexture.texCoord) { + context.addIssue( + SemanticError.khrMaterialsAnisotropyAnisotropyTextureTexCoord); + } + break; + } + } + context.path.removeLast(); + } + } +} + +const Extension khrMaterialsAnisotropyExtension = Extension( + KHR_MATERIALS_ANISOTROPY, { + Material: ExtensionDescriptor(KhrMaterialsAnisotropy.fromMap) +}); diff --git a/lib/src/ext/extensions.dart b/lib/src/ext/extensions.dart index 72807ab..d858183 100644 --- a/lib/src/ext/extensions.dart +++ b/lib/src/ext/extensions.dart @@ -19,6 +19,7 @@ library gltf.extensions; import 'package:gltf/src/base/gltf_property.dart'; import 'package:gltf/src/ext/EXT_texture_webp/ext_texture_webp.dart'; import 'package:gltf/src/ext/KHR_lights_punctual/khr_lights_punctual.dart'; +import 'package:gltf/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart'; import 'package:gltf/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart'; import 'package:gltf/src/ext/KHR_materials_dispersion/khr_materials_dispersion.dart'; import 'package:gltf/src/ext/KHR_materials_emissive_strength/khr_materials_emissive_strength.dart'; @@ -38,6 +39,7 @@ import 'package:meta/meta.dart'; export 'package:gltf/src/ext/EXT_texture_webp/ext_texture_webp.dart'; export 'package:gltf/src/ext/KHR_lights_punctual/khr_lights_punctual.dart'; +export 'package:gltf/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart'; export 'package:gltf/src/ext/KHR_materials_clearcoat/khr_materials_clearcoat.dart'; export 'package:gltf/src/ext/KHR_materials_dispersion/khr_materials_dispersion.dart'; export 'package:gltf/src/ext/KHR_materials_emissive_strength/khr_materials_emissive_strength.dart'; @@ -101,6 +103,7 @@ class ResourceValidatableExtensionEntry { const List kDefaultExtensions = [ extTextureWebPExtension, khrLightsPunctualExtension, + khrMaterialsAnisotropyExtension, khrMaterialsClearcoatExtension, khrMaterialsDispersionExtension, khrMaterialsEmissiveStrengthExtension, diff --git a/test/ext/KHR_materials_anisotropy/assets.json b/test/ext/KHR_materials_anisotropy/assets.json new file mode 100644 index 0000000..386fa72 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/assets.json @@ -0,0 +1,13 @@ +{ + "material": { + "name": "material.KHR_materials_anisotropy", + "tests": { + "custom_property.gltf": "Custom property", + "different_texcoords.gltf": "Normal and anisotropy textures with different texcoords", + "no_tangent_space.gltf": "No tangent space", + "out_of_range.gltf": "Out of range values", + "unexpected_extension.gltf": "Unexpected extension object location", + "valid.gltf": "Valid" + } + } +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf b/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf new file mode 100644 index 0000000..3adb84a --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf @@ -0,0 +1,17 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "materials": [ + { + "extensions": { + "KHR_materials_anisotropy": { + "customProperty": true + } + } + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf.report.json new file mode 100644 index 0000000..075b58f --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 0, + "numWarnings": 1, + "numInfos": 1, + "numHints": 0, + "messages": [ + { + "code": "UNEXPECTED_PROPERTY", + "message": "Unexpected property.", + "severity": 1, + "pointer": "/materials/0/extensions/KHR_materials_anisotropy/customProperty" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "animationCount": 0, + "materialCount": 1, + "hasMorphTargets": false, + "hasSkins": false, + "hasTextures": false, + "hasDefaultScene": false, + "drawCallCount": 0, + "totalVertexCount": 0, + "totalTriangleCount": 0, + "maxUVs": 0, + "maxInfluences": 0, + "maxAttributes": 0 + } +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf b/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf new file mode 100644 index 0000000..76d8024 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf @@ -0,0 +1,28 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "materials": [ + { + "normalTexture": { + "index": 0 + }, + "extensions": { + "KHR_materials_anisotropy": { + "anisotropyTexture": { + "index": 1, + "texCoord": 1 + } + } + } + } + ], + "textures": [ + { + }, { + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf.report.json new file mode 100644 index 0000000..f049eb4 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/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_ANISOTROPY_ANISOTROPY_TEXTURE_TEXCOORD", + "message": "Normal and anisotropy textures should use the same texture coords.", + "severity": 1, + "pointer": "/materials/0/extensions/KHR_materials_anisotropy/anisotropyTexture" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "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 diff --git a/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf b/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf new file mode 100644 index 0000000..243faa3 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf @@ -0,0 +1,49 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "material": 0 + } + ] + } + ], + "materials": [ + { + "extensions": { + "KHR_materials_anisotropy": { + "anisotropyTexture": { + "index": 0 + } + } + } + } + ], + "textures": [ + { } + ], + "accessors": [ + { + "componentType": 5126, + "count": 3, + "type": "VEC3", + "min": [0, 0, 0], + "max": [1, 1, 1] + }, + { + "componentType": 5126, + "count": 3, + "type": "VEC2" + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf.report.json new file mode 100644 index 0000000..5eab9b9 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 1, + "numWarnings": 0, + "numInfos": 1, + "numHints": 0, + "messages": [ + { + "code": "MESH_PRIMITIVE_NO_TANGENT_SPACE", + "message": "Material requires a tangent space but the mesh primitive does not provide it and the material does not contain a normal map to generate it.", + "severity": 0, + "pointer": "/meshes/0/primitives/0/material" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/meshes/0" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "animationCount": 0, + "materialCount": 1, + "hasMorphTargets": false, + "hasSkins": false, + "hasTextures": true, + "hasDefaultScene": false, + "drawCallCount": 1, + "totalVertexCount": 3, + "totalTriangleCount": 1, + "maxUVs": 1, + "maxInfluences": 0, + "maxAttributes": 2 + } +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf b/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf new file mode 100644 index 0000000..57e39fe --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf @@ -0,0 +1,24 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "materials": [ + { + "extensions": { + "KHR_materials_anisotropy": { + "anisotropyStrength": -0.5 + } + } + }, + { + "extensions": { + "KHR_materials_anisotropy": { + "anisotropyStrength": 1.5 + } + } + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf.report.json new file mode 100644 index 0000000..76df1fb --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf.report.json @@ -0,0 +1,56 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/data/material/out_of_range.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 2, + "numWarnings": 0, + "numInfos": 2, + "numHints": 0, + "messages": [ + { + "code": "VALUE_NOT_IN_RANGE", + "message": "Value -0.5 is out of range.", + "severity": 0, + "pointer": "/materials/0/extensions/KHR_materials_anisotropy/anisotropyStrength" + }, + { + "code": "VALUE_NOT_IN_RANGE", + "message": "Value 1.5 is out of range.", + "severity": 0, + "pointer": "/materials/1/extensions/KHR_materials_anisotropy/anisotropyStrength" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/1" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "animationCount": 0, + "materialCount": 2, + "hasMorphTargets": false, + "hasSkins": false, + "hasTextures": false, + "hasDefaultScene": false, + "drawCallCount": 0, + "totalVertexCount": 0, + "totalTriangleCount": 0, + "maxUVs": 0, + "maxInfluences": 0, + "maxAttributes": 0 + } +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf b/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf new file mode 100644 index 0000000..2718b84 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf @@ -0,0 +1,18 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "materials": [ + { + "pbrMetallicRoughness": { + "extensions": { + "KHR_materials_anisotropy": { + } + } + } + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf.report.json new file mode 100644 index 0000000..5a0e281 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/data/material/unexpected_extension.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 1, + "numWarnings": 0, + "numInfos": 1, + "numHints": 0, + "messages": [ + { + "code": "UNEXPECTED_EXTENSION_OBJECT", + "message": "Unexpected location for this extension.", + "severity": 0, + "pointer": "/materials/0/pbrMetallicRoughness/extensions/KHR_materials_anisotropy" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "animationCount": 0, + "materialCount": 1, + "hasMorphTargets": false, + "hasSkins": false, + "hasTextures": false, + "hasDefaultScene": false, + "drawCallCount": 0, + "totalVertexCount": 0, + "totalTriangleCount": 0, + "maxUVs": 0, + "maxInfluences": 0, + "maxAttributes": 0 + } +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/valid.gltf b/test/ext/KHR_materials_anisotropy/data/material/valid.gltf new file mode 100644 index 0000000..f0f1522 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/valid.gltf @@ -0,0 +1,31 @@ +{ + "asset": { + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "materials": [ + { + "extensions": { + "KHR_materials_anisotropy": { + } + } + }, + { + "extensions": { + "KHR_materials_anisotropy": { + "anisotropyStrength": 0.5, + "anisotropyRotation": 1.5, + "anisotropyTexture": { + "index": 0 + } + } + } + } + ], + "textures": [ + { + } + ] +} \ No newline at end of file diff --git a/test/ext/KHR_materials_anisotropy/data/material/valid.gltf.report.json b/test/ext/KHR_materials_anisotropy/data/material/valid.gltf.report.json new file mode 100644 index 0000000..7f19483 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/data/material/valid.gltf.report.json @@ -0,0 +1,44 @@ +{ + "uri": "test/ext/KHR_materials_anisotropy/data/material/valid.gltf", + "mimeType": "model/gltf+json", + "validatorVersion": "2.0.0-dev.3.10", + "issues": { + "numErrors": 0, + "numWarnings": 0, + "numInfos": 2, + "numHints": 0, + "messages": [ + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/0" + }, + { + "code": "UNUSED_OBJECT", + "message": "This object may be unused.", + "severity": 2, + "pointer": "/materials/1" + } + ], + "truncated": false + }, + "info": { + "version": "2.0", + "extensionsUsed": [ + "KHR_materials_anisotropy" + ], + "animationCount": 0, + "materialCount": 2, + "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 diff --git a/test/ext/KHR_materials_anisotropy/khr_materials_anisotropy_test.dart b/test/ext/KHR_materials_anisotropy/khr_materials_anisotropy_test.dart new file mode 100644 index 0000000..a586cc5 --- /dev/null +++ b/test/ext/KHR_materials_anisotropy/khr_materials_anisotropy_test.dart @@ -0,0 +1,36 @@ +// Copyright 2024 The Khronos Group Inc. +// +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:async'; + +import 'package:gltf/gltf.dart'; +import 'package:test/test.dart'; + +import '../../utils.dart'; + +Future main() async { + await compareReports('test/ext/KHR_materials_anisotropy'); + + group('Evaluate valid objects', () { + test('material.KHR_materials_anisotropy', () async { + final gltf = (await read( + 'ext/KHR_materials_anisotropy/data/material/valid.gltf', + ignoreUnused: true)) + .gltf; + + final anisotropy0 = gltf.materials[0] + .extensions['KHR_materials_anisotropy'] as KhrMaterialsAnisotropy; + expect(anisotropy0.anisotropyStrength, 0); + expect(anisotropy0.anisotropyRotation, 0); + expect(anisotropy0.anisotropyTexture, isNull); + expect(anisotropy0.extensions, isEmpty); + + final anisotropy1 = gltf.materials[1] + .extensions['KHR_materials_anisotropy'] as KhrMaterialsAnisotropy; + expect(anisotropy1.anisotropyStrength, 0.5); + expect(anisotropy1.anisotropyRotation, 1.5); + expect(anisotropy1.anisotropyTexture.texture, gltf.textures[0]); + }); + }); +}