-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support KHR_materials_anisotropy (#228)
- Loading branch information
1 parent
de37778
commit 95ed362
Showing
19 changed files
with
591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
lib/src/ext/KHR_materials_anisotropy/khr_materials_anisotropy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> KHR_MATERIALS_ANISOTROPY_MEMBERS = <String>[ | ||
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<String, Object> extensions, Object extras) | ||
: super(extensions, extras); | ||
|
||
static KhrMaterialsAnisotropy fromMap( | ||
Map<String, Object> 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<TextureInfo>( | ||
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, <Type, ExtensionDescriptor>{ | ||
Material: ExtensionDescriptor(KhrMaterialsAnisotropy.fromMap) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"asset": { | ||
"version": "2.0" | ||
}, | ||
"extensionsUsed": [ | ||
"KHR_materials_anisotropy" | ||
], | ||
"materials": [ | ||
{ | ||
"extensions": { | ||
"KHR_materials_anisotropy": { | ||
"customProperty": true | ||
} | ||
} | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
test/ext/KHR_materials_anisotropy/data/material/custom_property.gltf.report.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [ | ||
{ | ||
}, { | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
test/ext/KHR_materials_anisotropy/data/material/different_texcoords.gltf.report.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
test/ext/KHR_materials_anisotropy/data/material/no_tangent_space.gltf.report.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
Oops, something went wrong.