Skip to content

Commit

Permalink
TinyGltfImporter: implement support for non-float attribute types.
Browse files Browse the repository at this point in the history
This also makes the plugin support KHR_mesh_quantization, yay! There's
an ugly interaction with Y-flip in texture coordiantes, hope this won't
bite back too often.
  • Loading branch information
mosra committed Mar 28, 2020
1 parent 1878e1b commit 80028f6
Show file tree
Hide file tree
Showing 16 changed files with 1,512 additions and 479 deletions.
4 changes: 2 additions & 2 deletions doc/changelog-plugins.dox
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace Magnum {
- Support for the `KHR_lights_punctual` extension in
@ref Trade::TinyGltfImporter "TinyGltfImporter", replacing the obsolete
unuspported `KHR_lights_cmn` (see [mosra/magnum-plugins#77](https://github.com/mosra/magnum-plugins/pull/77))
- Support for the `KHR_texture_transform` extension in
@ref Trade::TinyGltfImporter "TinyGltfImporter"
- Support for the `KHR_texture_transform` and `KHR_mesh_quantization`
extensions in @ref Trade::TinyGltfImporter "TinyGltfImporter"
- @ref Trade::DdsImporter "DdsImporter" and
@ref Trade::BasisImporter "BasisImporter", now support loading image mip
levels; @ref Trade::AssimpImporter "AssimpImporter",
Expand Down
5 changes: 3 additions & 2 deletions src/MagnumPlugins/TinyGltfImporter/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ corrade_add_test(TinyGltfImporterTest
material-specularglossiness.gltf
material-texcoord-flip.bin
material-texcoord-flip.gltf
material-texcoord-flip-unnormalized.gltf
mesh.gltf
mesh.bin
mesh.glb
Expand All @@ -103,8 +104,8 @@ corrade_add_test(TinyGltfImporterTest
mesh-invalid.bin
mesh-invalid.gltf
mesh-multiple-primitives.gltf
mesh-primitives.gltf
mesh-primitives.bin
mesh-primitives-types.gltf
mesh-primitives-types.bin
mesh-colors.gltf
mesh-colors.bin
přívodní-šňůra.gltf
Expand Down
454 changes: 322 additions & 132 deletions src/MagnumPlugins/TinyGltfImporter/Test/TinyGltfImporterTest.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"asset": {
"version": "2.0"
},
"meshes": [
{
"name": "normalized signed integer",
"primitives": [
{
"attributes": {
"TEXCOORD_0": 0
}
}
]
},
{
"name": "signed integer",
"primitives": [
{
"attributes": {
"TEXCOORD_0": 1
}
}
]
}
],
"accessors": [
{
"bufferView": 0,
"componentType": 5120,
"normalized": true,
"count": 3,
"type": "VEC2"
},
{
"bufferView": 1,
"componentType": 5122,
"count": 3,
"type": "VEC2"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 44,
"byteLength": 8
},
{
"buffer": 0,
"byteOffset": 52,
"byteLength": 12
}
],
"buffers": [
{
"note": "reusing the same as material-texcoord-flip.gltf",
"byteLength": 64,
"uri": "material-texcoord-flip.bin"
}
],
"materials": [
{
"name": "transform from normalized signed integer",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0,
"extensions": {
"KHR_texture_transform": {
"offset": [0.5, 0.5],
"scale": [-0.5, 0.5]
}
}
}
}
},
{
"name": "transform from signed integer",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0,
"extensions": {
"KHR_texture_transform": {
"offset": [0.0, 0.25],
"scale": [0.005, 0.0025]
}
}
}
}
}
],
"textures": [
{}
]
}
Binary file modified src/MagnumPlugins/TinyGltfImporter/Test/material-texcoord-flip.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
type = '<6f'
input = [
type = '<'
input = []

# Floats
type += '6f'
input += [
1.0, 0.5,
0.5, 0.0,
0.0, 1.0
]

# Normalized unsigned bytes. On Y it's flipped.
type += '6Bxx'
input += [
254, 127,
127, 254,
0, 0
]

# Normalized unsigned shorts. On Y it's flipped.
type += '6H'
input += [
65534, 32767,
32767, 65534,
0, 0
]

# Normalized signed bytes. On X it's flipped.
type += '6bxx'
input += [
-127, 0,
0, -127,
127, 127,
]

# Unnormalized signed shorts. On Y it's off-center.
type += '6h'
input += [
200, 100,
100, -100,
0, 300
]

# kate: hl python
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@
]
},
{
"name": "signed integer",
"name": "normalized unsigned byte",
"primitives": [
{
"attributes": {
"TEXCOORD_0": 1
}
}
]
},
{
"name": "normalized unsigned short",
"primitives": [
{
"attributes": {
"TEXCOORD_0": 2
}
}
]
}
],
"accessors": [
Expand All @@ -30,6 +40,20 @@
"componentType": 5126,
"count": 3,
"type": "VEC2"
},
{
"bufferView": 1,
"componentType": 5121,
"normalized": true,
"count": 3,
"type": "VEC2"
},
{
"bufferView": 2,
"componentType": 5123,
"normalized": true,
"count": 3,
"type": "VEC2"
}
],
"bufferViews": [
Expand All @@ -41,12 +65,17 @@
{
"buffer": 0,
"byteOffset": 24,
"byteLength": 8
},
{
"buffer": 0,
"byteOffset": 32,
"byteLength": 12
}
],
"buffers": [
{
"byteLength": 36,
"byteLength": 64,
"uri": "material-texcoord-flip.bin"
}
],
Expand Down Expand Up @@ -87,6 +116,34 @@
}
}
}
},
{
"name": "transform from normalized unsigned byte",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0,
"extensions": {
"KHR_texture_transform": {
"offset": [0.0, 1.0],
"scale": [1.003921568627451, -1.003921568627451]
}
}
}
}
},
{
"name": "transform from normalized unsigned short",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0,
"extensions": {
"KHR_texture_transform": {
"offset": [0.0, 1.0],
"scale": [1.000015259254738, -1.000015259254738]
}
}
}
}
}
],
"textures": [
Expand Down
Loading

0 comments on commit 80028f6

Please sign in to comment.