Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GltfImporter: Support morph target attributes #141

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 144 additions & 87 deletions src/MagnumPlugins/GltfImporter/GltfImporter.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/MagnumPlugins/GltfImporter/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,18 @@ corrade_add_test(GltfImporterTest
mesh-invalid-buffer-notfound.gltf
mesh-invalid-empty-primitives.gltf
mesh-invalid-missing-primitives-property.gltf
mesh-invalid-morph-target.gltf
mesh-invalid-primitive-attributes-property.gltf
mesh-invalid-primitive-targets-property.gltf
mesh-invalid-primitive.gltf
mesh-invalid-primitives-property.gltf
mesh-invalid-texcoord-flip-attribute-accessor-invalid-component-type.gltf
mesh-invalid-texcoord-flip-attribute-accessor-invalid-normalized.gltf
mesh-invalid-texcoord-flip-attribute-accessor-missing-component-type.gltf
mesh-invalid-texcoord-flip-attribute-oob.gltf
mesh-invalid-texcoord-flip-attribute.gltf
mesh-morph-target-attributes.gltf
mosra marked this conversation as resolved.
Show resolved Hide resolved
mesh-morph-target-attributes.bin
mesh-multiple-primitives.gltf
mesh-no-indices-no-vertices-no-buffer-uri.gltf
mesh-no-indices-no-vertices-no-buffer-uri.glb
Expand Down
170 changes: 144 additions & 26 deletions src/MagnumPlugins/GltfImporter/Test/GltfImporterTest.cpp

Large diffs are not rendered by default.

Binary file modified src/MagnumPlugins/GltfImporter/Test/mesh-custom-attributes.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ input += [
-7, -8, -9
]

# _OBJECT_ID, _DOUBLE_SHOT, _NEGATIVE_PADDING
# OBJECT_ID3, _DOUBLE_SHOT, _NEGATIVE_PADDING
type += 'Iddixxxx'
input += [5678125, 31.2, 28.8, -3548415]

Expand All @@ -37,4 +37,10 @@ input += [
1.3, 1.4, 1.5, 1.6
]

# _FANCY_PROPERTY3
type += '4f'
input += [
0.1, 0.2, 0.3, 0.4
]

# kate: hl python
26 changes: 19 additions & 7 deletions src/MagnumPlugins/GltfImporter/Test/mesh-custom-attributes.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"_UV_ROTATION": 1,
"_TBN_PRECISER": 2,
"OBJECT_ID3": 3
}
},
"targets": [
{
"_FANCY_PROPERTY3": 4
}
]
}
]
},
Expand All @@ -22,9 +27,9 @@
"primitives": [
{
"attributes": {
"_NEGATIVE_PADDING": 4,
"NOT_AN_IDENTITY": 5,
"_DOUBLE_SHOT": 6
"_NEGATIVE_PADDING": 5,
"NOT_AN_IDENTITY": 6,
"_DOUBLE_SHOT": 7
}
}
]
Expand Down Expand Up @@ -62,6 +67,13 @@
"count": 1,
"type": "SCALAR"
},
{
"bufferView": 0,
"byteOffset": 200,
"componentType": 5126,
"count": 1,
"type": "VEC4"
},
{
"bufferView": 0,
"byteOffset": 64,
Expand All @@ -87,13 +99,13 @@
"bufferViews": [
{
"buffer": 0,
"byteLength": 200,
"byteStride": 200
"byteLength": 216,
"byteStride": 216
}
],
"buffers": [
{
"byteLength": 200,
"byteLength": 216,
"uri": "mesh-custom-attributes.bin"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
"COLOR_0": 1,
"COLOR_1": 1,
"COLOR_0": 3
}
},
"targets": [
{
"COLOR_0": 3,
"COLOR_0": 1
}
]
}
]
}
Expand Down
19 changes: 19 additions & 0 deletions src/MagnumPlugins/GltfImporter/Test/mesh-invalid-morph-target.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"asset": {
"version": "2.0"
},
"meshes": [
{
"primitives": [
{}
]
},
{
"primitives": [
{
"targets": [-1]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"asset": {
"version": "2.0"
},
"meshes": [
{
"primitives": [
{}
]
},
{
"primitives": [
{
"targets": {}
}
]
}
]
}
28 changes: 28 additions & 0 deletions src/MagnumPlugins/GltfImporter/Test/mesh-invalid.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,34 @@
"indices": -1
}
]
},
{
"name": "invalid morph target attribute",
"primitives": [
{
"attributes": {},
"targets": [
{
"POSITION": -1
}
]
}
]
},
{
"name": "different vertex count for morph target attribute",
"primitives": [
{
"attributes": {
"POSITION": 0
},
"targets": [
{
"TEXCOORD_0": 1
}
]
}
]
}
],
"accessors": [
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
type = '<'
input = []

type += '3f3f 3f3f 3f3f'
input += [
# positions, # normals
1.5, -1.0, -0.5, 1.0, 0.0, 0.0,
-0.5, 2.5, 0.75, 0.0, 1.0, 0.0,
-2.0, 1.0, 0.3, 0.0, 0.0, 1.0
]

# Morph target 1
type += '3H3H 3H3H 3H3H'
input += [
# positions (deltas), # normals (deltas)
10, 20, 30, 1, 2, 3,
40, 50, 60, 4, 5, 6,
70, 80, 90, 7, 8, 9
]

# Morph target 2
type += '3H 3H 3H'
input += [
# positions (deltas)
100, 200, 300,
400, 500, 600,
700, 800, 900
]

# Morph target 3
type += '3b 3b 3b'
input += [
# normals (deltas)
-1, -2, -3,
-4, -5, -6,
-7, -8, -9
]

# kate: hl python
106 changes: 106 additions & 0 deletions src/MagnumPlugins/GltfImporter/Test/mesh-morph-target-attributes.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
mrxz marked this conversation as resolved.
Show resolved Hide resolved
"asset": {
"version": "2.0"
},
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 3,
"type": "VEC3"
},
{
"bufferView": 0,
"byteOffset": 12,
"componentType": 5126,
"count": 3,
"type": "VEC3"
},
{
"bufferView": 1,
"componentType": 5123,
"count": 3,
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 6,
"componentType": 5122,
"normalized": true,
"count": 3,
"type": "VEC3"
},
{
"bufferView": 2,
"componentType": 5123,
"count": 3,
"type": "VEC3"
},
{
"bufferView": 3,
"componentType": 5120,
"normalized": true,
"count": 3,
"type": "VEC3"
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 72,
"byteStride": 24,
"target": 34962
},
{
"buffer": 0,
"byteLength": 36,
"byteOffset": 72,
"byteStride": 12,
"target": 34962
},
{
"buffer": 0,
"byteLength": 18,
"byteOffset": 108,
"byteStride": 6,
"target": 34962
},
{
"buffer": 0,
"byteLength": 9,
"byteOffset": 126,
"byteStride": 3,
"target": 34962
}
],
"buffers": [
{
"byteLength": 135,
"uri": "mesh-morph-target-attributes.bin"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0,
"NORMAL": 1
},
"targets": [
{
"POSITION": 2,
"NORMAL": 3
},
{
"POSITION": 4
},
{
"NORMAL": 5
}
]
}
]
}
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
type = "<4H 3f h 3B"
type = "<4H 3f h 3B 4f"
input = [
0x1122, 0x3344, 0x5566, 0x7788,
1.0, 2.0, 3.0,
-5602,
3, 16, 166
3, 16, 166,
1.0, 2.0, 3.0, 4.0
]

# kate: hl python
Loading