KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 316 forks source link

Import: exception when morph targets don't have POSITIONS #293

Closed scurest closed 5 years ago

scurest commented 5 years ago
Traceback (most recent call last):
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/__init__.py", line 473, in execute
    return self.import_gltf2(context)
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/__init__.py", line 492, in import_gltf2
    BlenderGlTF.create(self.gltf_importer)
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py", line 36, in create
    BlenderScene.create(gltf, scene_idx)
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_scene.py", line 84, in create
    BlenderNode.create(gltf, node_idx, None)  # None => No parent
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 76, in create
    BlenderMesh.set_mesh(gltf, gltf.data.meshes[pynode.mesh], mesh, obj)
  File "/home/scurest/.config/blender/2.79/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py", line 127, in set_mesh
    pos = BinaryData.get_data_from_accessor(gltf, prim.targets[i]['POSITION'])
KeyError: 'POSITION'

Test File

julienduroure commented 5 years ago

This is in glTF spec regarding meshes :

Implementation note: When positions are not specified, client implementations should skip primitive's rendering unless its positions are provided by other means (e.g., by extension). This applies to both indexed and non-indexed geometry.

This is in glTF spec regarding morph targets :

Implementation note: The number of morph targets is not limited in glTF. A conformant client implementation must support at least eight morphed attributes. This means that it has to support at least eight morph targets that contain a POSITION attribute, or four morph targets that contain a POSITION and a NORMAL attribute, or two morph targets that contain POSITION, NORMAL and TANGENT attributes. For assets that contain a higher number of morphed attributes, renderers may choose to either fully support them (for example, by performing the morph computations in software), or to only use the eight attributes of the morph targets with the highest weights.

(So this is not explicitly written that POSITION can be omitted in morph target too). So ... How to handle? Ignore this morph target? Create a morph target will same mesh as in primitive?

@donmccurdy any thoughts ?

scurest commented 5 years ago

It just means that the positions are not affected by the morph weights (the normals or tangents might be). I'd just skip creating the shape key since a shape key is basically a morph target for POSITIONs. And then you also need to skip creating actions that animate the weights of an instance of such a mesh.