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

Export mesh.weights and mesh.extras.targetNames. #491

Merged
merged 1 commit into from
May 27, 2019
Merged
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
34 changes: 32 additions & 2 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import bpy
from typing import Optional, Dict, List, Any
from .gltf2_blender_export_keys import MORPH
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from io_scene_gltf2.io.com import gltf2_io
from io_scene_gltf2.blender.exp import gltf2_blender_gather_primitives
Expand Down Expand Up @@ -68,8 +69,23 @@ def __gather_extras(blender_mesh: bpy.types.Mesh,
modifiers: Optional[bpy.types.ObjectModifiers],
export_settings
) -> Optional[Dict[Any, Any]]:
extras = {}

if export_settings['gltf_extras']:
return gltf2_blender_generate_extras.generate_extras(blender_mesh)
extras = gltf2_blender_generate_extras.generate_extras(blender_mesh)

if export_settings[MORPH] and blender_mesh.shape_keys:
morph_max = len(blender_mesh.shape_keys.key_blocks) - 1
if morph_max > 0:
target_names = []
for blender_shape_key in blender_mesh.shape_keys.key_blocks:
if blender_shape_key != blender_shape_key.relative_key:
target_names.append(blender_shape_key.name)
extras['targetNames'] = target_names

if extras:
return extras

return None


Expand All @@ -94,4 +110,18 @@ def __gather_weights(blender_mesh: bpy.types.Mesh,
modifiers: Optional[bpy.types.ObjectModifiers],
export_settings
) -> Optional[List[float]]:
return None

if not export_settings[MORPH] or not blender_mesh.shape_keys:
return None

morph_max = len(blender_mesh.shape_keys.key_blocks) - 1
if morph_max <= 0:
return None

weights = []

for blender_shape_key in blender_mesh.shape_keys.key_blocks:
if blender_shape_key != blender_shape_key.relative_key:
weights.append(blender_shape_key.value)

return weights