Skip to content

Commit

Permalink
feat: Export >4 bone influences
Browse files Browse the repository at this point in the history
Ported from
#346
  • Loading branch information
saturday06 committed Dec 12, 2023
1 parent 8ec8bfd commit 6092733
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/io_scene_vrm/common/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ExportPreferencesProtocol(Protocol):
export_only_selections: bool
enable_advanced_preferences: bool
export_fb_ngon_encoding: bool
export_all_influences: bool


def copy_export_preferences(
Expand All @@ -62,11 +63,13 @@ def copy_export_preferences(
destination.export_only_selections,
destination.enable_advanced_preferences,
destination.export_fb_ngon_encoding,
destination.export_all_influences,
) = (
source.export_invisibles,
source.export_only_selections,
source.enable_advanced_preferences,
source.export_fb_ngon_encoding,
source.export_all_influences,
)


Expand All @@ -82,6 +85,7 @@ def draw_export_preferences_layout(
if preferences.enable_advanced_preferences:
advanced_options_box = layout.box()
advanced_options_box.prop(preferences, "export_fb_ngon_encoding")
advanced_options_box.prop(preferences, "export_all_influences")


class VrmAddonPreferences(AddonPreferences):
Expand Down Expand Up @@ -124,6 +128,10 @@ class VrmAddonPreferences(AddonPreferences):
name="Try the FB_ngon_encoding under development"
+ " (Exported meshes can be corrupted)",
)
export_all_influences: BoolProperty( # type: ignore[valid-type]
name="Export All Bone Influences (Don't limit to 4, most viewers truncate to 4, so bone movement may cause jagged meshes)",
default=True,
)

def draw(self, _context: Context) -> None:
layout = self.layout
Expand Down Expand Up @@ -159,6 +167,7 @@ def draw(self, _context: Context) -> None:
export_only_selections: bool # type: ignore[no-redef]
enable_advanced_preferences: bool # type: ignore[no-redef]
export_fb_ngon_encoding: bool # type: ignore[no-redef]
export_all_influences: bool # type: ignore[no-redef]


def get_preferences(context: Context) -> VrmAddonPreferences:
Expand Down
10 changes: 9 additions & 1 deletion src/io_scene_vrm/exporter/export_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class EXPORT_SCENE_OT_vrm(Operator, ExportHelper):
+ " (Exported meshes can be corrupted)",
update=export_vrm_update_addon_preferences,
)
export_all_influences: BoolProperty( # type: ignore[valid-type]
name="Export All Bone Influences (Don't limit to 4, most viewers truncate to 4, so bone movement may cause jagged meshes)",
update=export_vrm_update_addon_preferences,
default=True,
)

errors: CollectionProperty( # type: ignore[valid-type]
type=validation.VrmValidationError,
Expand Down Expand Up @@ -140,7 +145,9 @@ def execute(self, context: Context) -> set[str]:

if is_vrm1:
vrm_exporter: AbstractBaseVrmExporter = Gltf2AddonVrmExporter(
context, export_objects
context,
export_objects,
self.export_all_influences,
)
else:
vrm_exporter = LegacyVrmExporter(
Expand Down Expand Up @@ -258,6 +265,7 @@ def draw(self, _context: Context) -> None:
export_only_selections: bool # type: ignore[no-redef]
enable_advanced_preferences: bool # type: ignore[no-redef]
export_fb_ngon_encoding: bool # type: ignore[no-redef]
export_all_influences: bool # type: ignore[no-redef]
errors: CollectionPropertyProtocol[VrmValidationError] # type: ignore[no-redef]
armature_object_name: str # type: ignore[no-redef]
ignore_warning: bool # type: ignore[no-redef]
Expand Down
3 changes: 3 additions & 0 deletions src/io_scene_vrm/exporter/gltf2_addon_vrm_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ def __init__(
self,
context: Context,
export_objects: list[Object],
export_all_influences: bool,
) -> None:
super().__init__(context)
self.export_objects = export_objects
self.export_all_influences = export_all_influences

armatures = [obj for obj in export_objects if obj.type == "ARMATURE"]
if not armatures:
Expand Down Expand Up @@ -2042,6 +2044,7 @@ def export_vrm(self) -> Optional[bytes]:
use_selection=True,
export_animations=True,
export_rest_position_armature=False,
export_all_influences=self.export_all_influences, # Models may appear incorrectly in many viewers
# UniVRM 0.115.0 doesn't support `export_try_sparse_sk`
# https://github.com/saturday06/VRM-Addon-for-Blender/issues/381#issuecomment-1838365762
export_try_sparse_sk=False,
Expand Down
4 changes: 4 additions & 0 deletions src/io_scene_vrm/external/io_scene_gltf2_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ExportSceneGltfArguments:
use_selection: bool
export_animations: bool
export_rest_position_armature: bool
export_all_influences: bool
export_try_sparse_sk: bool


Expand All @@ -138,6 +139,7 @@ def __invoke_export_scene_gltf(arguments: ExportSceneGltfArguments) -> set[str]:
export_current_frame=arguments.export_current_frame,
use_selection=arguments.use_selection,
export_animations=arguments.export_animations,
export_all_influences=arguments.export_all_influences,
)

if bpy.app.version < (4,):
Expand All @@ -150,6 +152,7 @@ def __invoke_export_scene_gltf(arguments: ExportSceneGltfArguments) -> set[str]:
use_selection=arguments.use_selection,
export_animations=arguments.export_animations,
export_rest_position_armature=arguments.export_rest_position_armature,
export_all_influences=arguments.export_all_influences,
)

return bpy.ops.export_scene.gltf(
Expand All @@ -162,6 +165,7 @@ def __invoke_export_scene_gltf(arguments: ExportSceneGltfArguments) -> set[str]:
export_animations=arguments.export_animations,
export_rest_position_armature=arguments.export_rest_position_armature,
export_try_sparse_sk=arguments.export_try_sparse_sk,
export_all_influences=arguments.export_all_influences,
)


Expand Down
4 changes: 4 additions & 0 deletions src/io_scene_vrm/locale/ja_jp.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
+ " (Exported meshes can be corrupted)",
): "開発中のFB_ngon_encodingエクステンションを試してみる"
+ "(エクスポートされるメッシュが壊れることがあります)",
(
"*",
"Export All Bone Influences (Don't limit to 4, most viewers truncate to 4, so bone movement may cause jagged meshes)",
): "全てのボーンウェイトをエクスポートする(4つに制限しない。多くのビューアは4つに制限するため、ボーンの動きがメッシュを乱す可能性があります)",
(
"*",
"No error. Ready for export VRM",
Expand Down

0 comments on commit 6092733

Please sign in to comment.