@volter/blender-engine 0.1.148 → 0.1.150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -5
- package/README.md +4 -11
- package/browser/addons/vrm/LICENSE_(OPTION1)_MIT.txt +22 -0
- package/browser/addons/vrm/LICENSE_(OPTION2)_GPL-3_0.txt +674 -0
- package/browser/addons/vrm/LICENSE_MAIN.txt +1 -0
- package/browser/addons/vrm/README.txt +3 -0
- package/browser/addons/vrm/__init__.py +41 -0
- package/browser/addons/vrm/blender_manifest.toml +16 -0
- package/browser/addons/vrm/common/__init__.py +1 -0
- package/browser/addons/vrm/common/animation.py +58 -0
- package/browser/addons/vrm/common/blender_manifest.py +82 -0
- package/browser/addons/vrm/common/char.py +16 -0
- package/browser/addons/vrm/common/convert.py +287 -0
- package/browser/addons/vrm/common/convert_any.py +48 -0
- package/browser/addons/vrm/common/debug.py +40 -0
- package/browser/addons/vrm/common/deep.py +162 -0
- package/browser/addons/vrm/common/error_dialog.py +274 -0
- package/browser/addons/vrm/common/fs.py +71 -0
- package/browser/addons/vrm/common/gl.py +20 -0
- package/browser/addons/vrm/common/gltf.py +1149 -0
- package/browser/addons/vrm/common/human_bone_mapper/__init__.py +1 -0
- package/browser/addons/vrm/common/human_bone_mapper/biped_mapping.py +84 -0
- package/browser/addons/vrm/common/human_bone_mapper/cats_blender_plugin_fix_model_mapping.py +63 -0
- package/browser/addons/vrm/common/human_bone_mapper/human_bone_mapper.py +203 -0
- package/browser/addons/vrm/common/human_bone_mapper/microsoft_rocketbox_mapping.py +69 -0
- package/browser/addons/vrm/common/human_bone_mapper/mixamo_mapping.py +62 -0
- package/browser/addons/vrm/common/human_bone_mapper/mmd_mapping.py +115 -0
- package/browser/addons/vrm/common/human_bone_mapper/mpfb_mapping.py +120 -0
- package/browser/addons/vrm/common/human_bone_mapper/ready_player_me_mapping.py +65 -0
- package/browser/addons/vrm/common/human_bone_mapper/reallusion_mapping.py +94 -0
- package/browser/addons/vrm/common/human_bone_mapper/rigify_meta_rig_mapping.py +65 -0
- package/browser/addons/vrm/common/human_bone_mapper/structure_based_mapping.py +891 -0
- package/browser/addons/vrm/common/human_bone_mapper/unreal_mapping.py +62 -0
- package/browser/addons/vrm/common/human_bone_mapper/vrm_addon_mapping.py +112 -0
- package/browser/addons/vrm/common/human_bone_mapper/vroid_mapping.py +89 -0
- package/browser/addons/vrm/common/legacy_gltf.py +16 -0
- package/browser/addons/vrm/common/logger.py +84 -0
- package/browser/addons/vrm/common/mtoon0.blend +0 -0
- package/browser/addons/vrm/common/mtoon1.blend +0 -0
- package/browser/addons/vrm/common/mtoon1_outline.blend +0 -0
- package/browser/addons/vrm/common/mtoon_auto_setup.blend +0 -0
- package/browser/addons/vrm/common/mtoon_unversioned.py +62 -0
- package/browser/addons/vrm/common/ops/__init__.py +10 -0
- package/browser/addons/vrm/common/ops/export_scene.py +67 -0
- package/browser/addons/vrm/common/ops/icyp.py +53 -0
- package/browser/addons/vrm/common/ops/import_scene.py +57 -0
- package/browser/addons/vrm/common/ops/vrm.py +2380 -0
- package/browser/addons/vrm/common/ops/wm.py +167 -0
- package/browser/addons/vrm/common/preferences.py +362 -0
- package/browser/addons/vrm/common/progress.py +87 -0
- package/browser/addons/vrm/common/rotation.py +89 -0
- package/browser/addons/vrm/common/safe_removal.py +46 -0
- package/browser/addons/vrm/common/scene_watcher.py +230 -0
- package/browser/addons/vrm/common/shader.py +2243 -0
- package/browser/addons/vrm/common/shape_key_mapper/__init__.py +1 -0
- package/browser/addons/vrm/common/shape_key_mapper/arkit_mapping.py +168 -0
- package/browser/addons/vrm/common/shape_key_mapper/mmd_mapping.py +62 -0
- package/browser/addons/vrm/common/shape_key_mapper/ready_player_me_mapping.py +52 -0
- package/browser/addons/vrm/common/shape_key_mapper/vrchat_mapping.py +17 -0
- package/browser/addons/vrm/common/third_party_user_extension.py +214 -0
- package/browser/addons/vrm/common/transparent_z_write.blend +0 -0
- package/browser/addons/vrm/common/version.py +161 -0
- package/browser/addons/vrm/common/vrm0/__init__.py +1 -0
- package/browser/addons/vrm/common/vrm0/human_bone.py +662 -0
- package/browser/addons/vrm/common/vrm0/material_property.py +346 -0
- package/browser/addons/vrm/common/vrm1/__init__.py +1 -0
- package/browser/addons/vrm/common/vrm1/expression_preset.py +207 -0
- package/browser/addons/vrm/common/vrm1/human_bone.py +822 -0
- package/browser/addons/vrm/common/workspace.py +227 -0
- package/browser/addons/vrm/common/writable_context.py +77 -0
- package/browser/addons/vrm/documentation/en-us/animation/index.md +63 -0
- package/browser/addons/vrm/documentation/en-us/create-humanoid-vrm-from-scratch/index.md +131 -0
- package/browser/addons/vrm/documentation/en-us/create-simple-vrm-from-scratch/index.md +30 -0
- package/browser/addons/vrm/documentation/en-us/development/index.md +136 -0
- package/browser/addons/vrm/documentation/en-us/index.md +41 -0
- package/browser/addons/vrm/documentation/en-us/installation/index.md +152 -0
- package/browser/addons/vrm/documentation/en-us/material-mtoon/index.md +122 -0
- package/browser/addons/vrm/documentation/en-us/material-pbr/index.md +94 -0
- package/browser/addons/vrm/documentation/en-us/scripting-api/index.md +391 -0
- package/browser/addons/vrm/documentation/en-us/ui/export_scene.vrm/index.md +57 -0
- package/browser/addons/vrm/documentation/en-us/ui/export_scene.vrma/index.md +17 -0
- package/browser/addons/vrm/documentation/en-us/ui/import_scene.vrm/index.md +61 -0
- package/browser/addons/vrm/documentation/en-us/ui/import_scene.vrma/index.md +13 -0
- package/browser/addons/vrm/documentation/ja-jp/animation/index.md +57 -0
- package/browser/addons/vrm/documentation/ja-jp/create-humanoid-vrm-from-scratch/index.md +129 -0
- package/browser/addons/vrm/documentation/ja-jp/create-simple-vrm-from-scratch/index.md +29 -0
- package/browser/addons/vrm/documentation/ja-jp/development/index.md +137 -0
- package/browser/addons/vrm/documentation/ja-jp/index.md +37 -0
- package/browser/addons/vrm/documentation/ja-jp/installation/index.md +150 -0
- package/browser/addons/vrm/documentation/ja-jp/material-mtoon/index.md +113 -0
- package/browser/addons/vrm/documentation/ja-jp/material-pbr/index.md +90 -0
- package/browser/addons/vrm/documentation/ja-jp/scripting-api/index.md +389 -0
- package/browser/addons/vrm/documentation/ja-jp/ui/export_scene.vrm/index.md +55 -0
- package/browser/addons/vrm/documentation/ja-jp/ui/export_scene.vrma/index.md +19 -0
- package/browser/addons/vrm/documentation/ja-jp/ui/import_scene.vrm/index.md +56 -0
- package/browser/addons/vrm/documentation/ja-jp/ui/import_scene.vrma/index.md +14 -0
- package/browser/addons/vrm/editor/__init__.py +1 -0
- package/browser/addons/vrm/editor/extension.py +425 -0
- package/browser/addons/vrm/editor/extension_accessor.py +75 -0
- package/browser/addons/vrm/editor/handler.py +84 -0
- package/browser/addons/vrm/editor/khr_character/__init__.py +1 -0
- package/browser/addons/vrm/editor/khr_character/panel.py +69 -0
- package/browser/addons/vrm/editor/khr_character/property_group.py +27 -0
- package/browser/addons/vrm/editor/khr_xmp_json_ld/__init__.py +1 -0
- package/browser/addons/vrm/editor/khr_xmp_json_ld/ops.py +464 -0
- package/browser/addons/vrm/editor/khr_xmp_json_ld/panel.py +136 -0
- package/browser/addons/vrm/editor/khr_xmp_json_ld/property_group.py +83 -0
- package/browser/addons/vrm/editor/khr_xmp_json_ld/ui_list.py +198 -0
- package/browser/addons/vrm/editor/make_armature.py +709 -0
- package/browser/addons/vrm/editor/menu.py +147 -0
- package/browser/addons/vrm/editor/migration.py +297 -0
- package/browser/addons/vrm/editor/mtoon1/__init__.py +1 -0
- package/browser/addons/vrm/editor/mtoon1/handler.py +20 -0
- package/browser/addons/vrm/editor/mtoon1/migration.py +536 -0
- package/browser/addons/vrm/editor/mtoon1/ops.py +304 -0
- package/browser/addons/vrm/editor/mtoon1/panel.py +442 -0
- package/browser/addons/vrm/editor/mtoon1/property_group.py +4977 -0
- package/browser/addons/vrm/editor/mtoon1/scene_watcher.py +381 -0
- package/browser/addons/vrm/editor/node_constraint1/__init__.py +1 -0
- package/browser/addons/vrm/editor/node_constraint1/panel.py +317 -0
- package/browser/addons/vrm/editor/node_constraint1/property_group.py +25 -0
- package/browser/addons/vrm/editor/ops.py +471 -0
- package/browser/addons/vrm/editor/panel.py +315 -0
- package/browser/addons/vrm/editor/property_group.py +888 -0
- package/browser/addons/vrm/editor/search.py +682 -0
- package/browser/addons/vrm/editor/spring_bone1/__init__.py +1 -0
- package/browser/addons/vrm/editor/spring_bone1/handler.py +994 -0
- package/browser/addons/vrm/editor/spring_bone1/menu.py +246 -0
- package/browser/addons/vrm/editor/spring_bone1/migration.py +86 -0
- package/browser/addons/vrm/editor/spring_bone1/ops.py +1679 -0
- package/browser/addons/vrm/editor/spring_bone1/panel.py +605 -0
- package/browser/addons/vrm/editor/spring_bone1/property_group.py +1457 -0
- package/browser/addons/vrm/editor/spring_bone1/ui_list.py +408 -0
- package/browser/addons/vrm/editor/subscription.py +123 -0
- package/browser/addons/vrm/editor/t_pose.py +713 -0
- package/browser/addons/vrm/editor/validation.py +1271 -0
- package/browser/addons/vrm/editor/vrm0/__init__.py +1 -0
- package/browser/addons/vrm/editor/vrm0/gizmo_group.py +63 -0
- package/browser/addons/vrm/editor/vrm0/handler.py +23 -0
- package/browser/addons/vrm/editor/vrm0/menu.py +145 -0
- package/browser/addons/vrm/editor/vrm0/migration.py +761 -0
- package/browser/addons/vrm/editor/vrm0/ops.py +2145 -0
- package/browser/addons/vrm/editor/vrm0/panel.py +1333 -0
- package/browser/addons/vrm/editor/vrm0/property_group.py +1818 -0
- package/browser/addons/vrm/editor/vrm0/ui_list.py +688 -0
- package/browser/addons/vrm/editor/vrm1/__init__.py +1 -0
- package/browser/addons/vrm/editor/vrm1/handler.py +28 -0
- package/browser/addons/vrm/editor/vrm1/menu.py +76 -0
- package/browser/addons/vrm/editor/vrm1/migration.py +321 -0
- package/browser/addons/vrm/editor/vrm1/ops.py +2679 -0
- package/browser/addons/vrm/editor/vrm1/panel.py +1243 -0
- package/browser/addons/vrm/editor/vrm1/property_group.py +2087 -0
- package/browser/addons/vrm/editor/vrm1/scene_watcher.py +90 -0
- package/browser/addons/vrm/editor/vrm1/ui_list.py +533 -0
- package/browser/addons/vrm/exporter/__init__.py +1 -0
- package/browser/addons/vrm/exporter/abstract_base_vrm_exporter.py +628 -0
- package/browser/addons/vrm/exporter/export_scene.py +930 -0
- package/browser/addons/vrm/exporter/gltf2_export_user_extension.py +45 -0
- package/browser/addons/vrm/exporter/khr_character_exporter.py +34 -0
- package/browser/addons/vrm/exporter/vrm0_exporter.py +4020 -0
- package/browser/addons/vrm/exporter/vrm1_exporter.py +3682 -0
- package/browser/addons/vrm/exporter/vrm_animation_exporter.py +1035 -0
- package/browser/addons/vrm/external/__init__.py +1 -0
- package/browser/addons/vrm/external/auto_rig_pro_support.py +3 -0
- package/browser/addons/vrm/external/io_scene_gltf2_support.py +418 -0
- package/browser/addons/vrm/external/rigify_support.py +1 -0
- package/browser/addons/vrm/importer/__init__.py +1 -0
- package/browser/addons/vrm/importer/abstract_base_vrm_importer.py +1548 -0
- package/browser/addons/vrm/importer/file_handler.py +34 -0
- package/browser/addons/vrm/importer/gltf2_import_user_extension.py +268 -0
- package/browser/addons/vrm/importer/import_scene.py +646 -0
- package/browser/addons/vrm/importer/license_validation.py +198 -0
- package/browser/addons/vrm/importer/vrm0_importer.py +1723 -0
- package/browser/addons/vrm/importer/vrm1_importer.py +2014 -0
- package/browser/addons/vrm/importer/vrm_animation_importer.py +763 -0
- package/browser/addons/vrm/importer/vrm_diff.py +316 -0
- package/browser/addons/vrm/locale/__init__.py +1 -0
- package/browser/addons/vrm/locale/ja_jp.py +826 -0
- package/browser/addons/vrm/locale/ruff.toml +8 -0
- package/browser/addons/vrm/locale/translation_dictionary.py +10 -0
- package/browser/addons/vrm/locale/zh_hans.py +928 -0
- package/browser/addons/vrm/registration.py +670 -0
- package/browser/addons/vrm.json +18 -0
- package/browser/blender-emscripten-engine.mts +66 -129
- package/browser/blender-engine.mts +20 -186
- package/browser/blender-wali-engine.mts +37 -81
- package/browser/describe-thrown.mts +3 -6
- package/browser/document-chunks.mts +4 -16
- package/browser/gltf_export.py +3161 -0
- package/browser/heap-growth.mts +23 -0
- package/browser/index.ts +3 -0
- package/browser/protocol.ts +130 -43
- package/browser/pull-job.mts +2 -10
- package/browser/rna.ts +190 -73
- package/browser/runtime.ts +271 -106
- package/browser/session-addons.mts +33 -0
- package/browser/session-frame.mts +5 -24
- package/browser/session.py +1389 -1446
- package/browser/three/attach-presenter.ts +11 -39
- package/browser/three/blender-base64.ts +1 -36
- package/browser/three/blender-corner-normals.ts +1 -23
- package/browser/three/blender-display-shaders.json +1 -1
- package/browser/three/blender-display-shaders.lut +0 -0
- package/browser/three/blender-display-transform.ts +2 -1
- package/browser/three/blender-frame-columns.ts +5 -13
- package/browser/three/blender-graph-material.ts +18 -3
- package/browser/three/blender-node-graph.ts +10 -34
- package/browser/three/blender-physical-material.ts +2 -31
- package/browser/three/blender-runtime-armature.ts +7 -60
- package/browser/three/blender-runtime-frame.ts +9 -23
- package/browser/three/blender-runtime-geometry.ts +22 -26
- package/browser/three/blender-runtime-lighting.ts +48 -178
- package/browser/three/blender-runtime-shadows.ts +187 -1
- package/browser/three/blender-runtime-skeleton.ts +53 -1
- package/browser/three/blender-runtime-view.ts +492 -306
- package/browser/three/blender-runtime-weights.ts +9 -72
- package/browser/three/blender-sky.ts +13 -33
- package/browser/three/blender-triangulate.ts +7 -35
- package/browser/three/blender-viewport-sampling.ts +235 -0
- package/browser/three/blender-workbench-material.ts +25 -29
- package/browser/three/blender-workbench-outline.ts +199 -0
- package/browser/three/blender-world-volume.ts +62 -10
- package/browser/three/presenter.ts +10 -26
- package/browser/three/release.ts +5 -21
- package/browser/three/sky-precompute-worker.ts +1 -18
- package/browser/three/sky-worker.ts +5 -23
- package/browser/three/world-field-sampler.ts +12 -26
- package/browser/volter_three.py +9 -105
- package/browser/worker.ts +195 -180
- package/package.json +5 -2
- package/wasm/BUNDLE.json +17 -17
- package/wasm/DEPENDENCY-LICENSES.txt +14 -0
- package/wasm/blender_browser.data.br +0 -0
- package/wasm/blender_browser.js +1 -1
- package/wasm/blender_browser.wasm.br +0 -0
- package/browser/frame-transfer.mts +0 -19
- package/browser/three/agx-base-srgb.lut +0 -0
- package/browser/three/agx-look-medium-high-contrast.lut +0 -0
- package/browser/three/agx-look-punchy.lut +0 -0
- package/browser/three/blender-agx.ts +0 -235
- package/browser/three/blender-display-lut.ts +0 -145
- package/browser/three/blender-filmic.ts +0 -49
- package/browser/three/blender-standard.ts +0 -68
- package/browser/three/blender-world-visibility.ts +0 -278
- package/browser/three/filmic-srgb.lut +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# This code is auto generated.
|
|
2
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
3
|
+
|
|
4
|
+
from collections.abc import Mapping, Sequence
|
|
5
|
+
from typing import Optional, Union
|
|
6
|
+
|
|
7
|
+
import bpy
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# This code is auto generated.
|
|
11
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
12
|
+
def vrm_gltf2_addon_disabled_warning(
|
|
13
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
14
|
+
) -> set[str]:
|
|
15
|
+
return bpy.ops.wm.vrm_gltf2_addon_disabled_warning( # type: ignore[attr-defined, no-any-return]
|
|
16
|
+
execution_context,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# This code is auto generated.
|
|
21
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
22
|
+
def vrm_export_human_bones_assignment(
|
|
23
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
24
|
+
/,
|
|
25
|
+
*,
|
|
26
|
+
armature_object_name: str = "",
|
|
27
|
+
) -> set[str]:
|
|
28
|
+
return bpy.ops.wm.vrm_export_human_bones_assignment( # type: ignore[attr-defined, no-any-return]
|
|
29
|
+
execution_context,
|
|
30
|
+
armature_object_name=armature_object_name,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# This code is auto generated.
|
|
35
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
36
|
+
def vrm_export_confirmation(
|
|
37
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
38
|
+
/,
|
|
39
|
+
*,
|
|
40
|
+
errors: Optional[Sequence[Mapping[str, Union[str, int, float, bool]]]] = None,
|
|
41
|
+
armature_object_name: str = "",
|
|
42
|
+
export_anyway: bool = False,
|
|
43
|
+
) -> set[str]:
|
|
44
|
+
return bpy.ops.wm.vrm_export_confirmation( # type: ignore[attr-defined, no-any-return]
|
|
45
|
+
execution_context,
|
|
46
|
+
errors=errors if errors is not None else [],
|
|
47
|
+
armature_object_name=armature_object_name,
|
|
48
|
+
export_anyway=export_anyway,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# This code is auto generated.
|
|
53
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
54
|
+
def vrm_export_armature_selection(
|
|
55
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
56
|
+
/,
|
|
57
|
+
*,
|
|
58
|
+
armature_object_name: str = "",
|
|
59
|
+
armature_object_name_candidates: Optional[
|
|
60
|
+
Sequence[Mapping[str, Union[str, int, float, bool]]]
|
|
61
|
+
] = None,
|
|
62
|
+
) -> set[str]:
|
|
63
|
+
return bpy.ops.wm.vrm_export_armature_selection( # type: ignore[attr-defined, no-any-return]
|
|
64
|
+
execution_context,
|
|
65
|
+
armature_object_name=armature_object_name,
|
|
66
|
+
armature_object_name_candidates=armature_object_name_candidates
|
|
67
|
+
if armature_object_name_candidates is not None
|
|
68
|
+
else [],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# This code is auto generated.
|
|
73
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
74
|
+
def vrma_export_prerequisite(
|
|
75
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
76
|
+
/,
|
|
77
|
+
*,
|
|
78
|
+
armature_object_name: str = "",
|
|
79
|
+
armature_object_name_candidates: Optional[
|
|
80
|
+
Sequence[Mapping[str, Union[str, int, float, bool]]]
|
|
81
|
+
] = None,
|
|
82
|
+
) -> set[str]:
|
|
83
|
+
return bpy.ops.wm.vrma_export_prerequisite( # type: ignore[attr-defined, no-any-return]
|
|
84
|
+
execution_context,
|
|
85
|
+
armature_object_name=armature_object_name,
|
|
86
|
+
armature_object_name_candidates=armature_object_name_candidates
|
|
87
|
+
if armature_object_name_candidates is not None
|
|
88
|
+
else [],
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# This code is auto generated.
|
|
93
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
94
|
+
def vrm_error_dialog(
|
|
95
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
96
|
+
/,
|
|
97
|
+
*,
|
|
98
|
+
title: str = "",
|
|
99
|
+
lines: Optional[Sequence[Mapping[str, Union[str, int, float, bool]]]] = None,
|
|
100
|
+
active_line_index: int = 0,
|
|
101
|
+
) -> set[str]:
|
|
102
|
+
return bpy.ops.wm.vrm_error_dialog( # type: ignore[attr-defined, no-any-return]
|
|
103
|
+
execution_context,
|
|
104
|
+
title=title,
|
|
105
|
+
lines=lines if lines is not None else [],
|
|
106
|
+
active_line_index=active_line_index,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# This code is auto generated.
|
|
111
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
112
|
+
def vrm_license_warning(
|
|
113
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
114
|
+
/,
|
|
115
|
+
*,
|
|
116
|
+
filepath: str = "",
|
|
117
|
+
license_confirmations: Optional[
|
|
118
|
+
Sequence[Mapping[str, Union[str, int, float, bool]]]
|
|
119
|
+
] = None,
|
|
120
|
+
import_anyway: bool = False,
|
|
121
|
+
thumbnail_image_name: str = "",
|
|
122
|
+
extract_textures_into_folder: bool = False,
|
|
123
|
+
make_new_texture_folder: bool = False,
|
|
124
|
+
set_shading_type_to_material_on_import: bool = False,
|
|
125
|
+
set_view_transform_to_standard_on_import: bool = False,
|
|
126
|
+
set_armature_display_to_wire: bool = False,
|
|
127
|
+
set_armature_display_to_show_in_front: bool = False,
|
|
128
|
+
set_armature_bone_shape_to_default: bool = False,
|
|
129
|
+
enable_mtoon_outline_preview: bool = False,
|
|
130
|
+
) -> set[str]:
|
|
131
|
+
return bpy.ops.wm.vrm_license_warning( # type: ignore[attr-defined, no-any-return]
|
|
132
|
+
execution_context,
|
|
133
|
+
filepath=filepath,
|
|
134
|
+
license_confirmations=license_confirmations
|
|
135
|
+
if license_confirmations is not None
|
|
136
|
+
else [],
|
|
137
|
+
import_anyway=import_anyway,
|
|
138
|
+
thumbnail_image_name=thumbnail_image_name,
|
|
139
|
+
extract_textures_into_folder=extract_textures_into_folder,
|
|
140
|
+
make_new_texture_folder=make_new_texture_folder,
|
|
141
|
+
set_shading_type_to_material_on_import=set_shading_type_to_material_on_import,
|
|
142
|
+
set_view_transform_to_standard_on_import=set_view_transform_to_standard_on_import,
|
|
143
|
+
set_armature_display_to_wire=set_armature_display_to_wire,
|
|
144
|
+
set_armature_display_to_show_in_front=set_armature_display_to_show_in_front,
|
|
145
|
+
set_armature_bone_shape_to_default=set_armature_bone_shape_to_default,
|
|
146
|
+
enable_mtoon_outline_preview=enable_mtoon_outline_preview,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# This code is auto generated.
|
|
151
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
152
|
+
def vrma_import_prerequisite(
|
|
153
|
+
execution_context: str = "EXEC_DEFAULT",
|
|
154
|
+
/,
|
|
155
|
+
*,
|
|
156
|
+
armature_object_name: str = "",
|
|
157
|
+
armature_object_name_candidates: Optional[
|
|
158
|
+
Sequence[Mapping[str, Union[str, int, float, bool]]]
|
|
159
|
+
] = None,
|
|
160
|
+
) -> set[str]:
|
|
161
|
+
return bpy.ops.wm.vrma_import_prerequisite( # type: ignore[attr-defined, no-any-return]
|
|
162
|
+
execution_context,
|
|
163
|
+
armature_object_name=armature_object_name,
|
|
164
|
+
armature_object_name_candidates=armature_object_name_candidates
|
|
165
|
+
if armature_object_name_candidates is not None
|
|
166
|
+
else [],
|
|
167
|
+
)
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR GPL-3.0-or-later
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
from typing import TYPE_CHECKING, Final, Protocol, TypedDict, Union
|
|
4
|
+
|
|
5
|
+
from bpy.app.translations import pgettext
|
|
6
|
+
from bpy.props import BoolProperty, IntVectorProperty
|
|
7
|
+
from bpy.types import AddonPreferences, Context, Operator, UILayout
|
|
8
|
+
|
|
9
|
+
from . import version
|
|
10
|
+
from .logger import get_logger
|
|
11
|
+
from .shader import (
|
|
12
|
+
add_mtoon1_auto_setup_shader_node_group,
|
|
13
|
+
remove_mtoon1_auto_setup_shader_node_group,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
_logger = get_logger(__name__)
|
|
17
|
+
|
|
18
|
+
ADDON_PACKAGE_NAME: Final[str] = ".".join(__name__.split(".")[:-2])
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ImportPreferencesProtocol(Protocol):
|
|
22
|
+
extract_textures_into_folder: bool
|
|
23
|
+
make_new_texture_folder: bool
|
|
24
|
+
set_shading_type_to_material_on_import: bool
|
|
25
|
+
set_view_transform_to_standard_on_import: bool
|
|
26
|
+
set_armature_display_to_wire: bool
|
|
27
|
+
set_armature_display_to_show_in_front: bool
|
|
28
|
+
set_armature_bone_shape_to_default: bool
|
|
29
|
+
enable_mtoon_outline_preview: bool
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ImportPreferencesDict(TypedDict):
|
|
33
|
+
extract_textures_into_folder: bool
|
|
34
|
+
make_new_texture_folder: bool
|
|
35
|
+
set_shading_type_to_material_on_import: bool
|
|
36
|
+
set_view_transform_to_standard_on_import: bool
|
|
37
|
+
set_armature_display_to_wire: bool
|
|
38
|
+
set_armature_display_to_show_in_front: bool
|
|
39
|
+
set_armature_bone_shape_to_default: bool
|
|
40
|
+
enable_mtoon_outline_preview: bool
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def create_import_preferences_dict(
|
|
44
|
+
source: ImportPreferencesProtocol,
|
|
45
|
+
) -> ImportPreferencesDict:
|
|
46
|
+
return {
|
|
47
|
+
"extract_textures_into_folder": source.extract_textures_into_folder,
|
|
48
|
+
"make_new_texture_folder": source.make_new_texture_folder,
|
|
49
|
+
"set_shading_type_to_material_on_import": (
|
|
50
|
+
source.set_shading_type_to_material_on_import
|
|
51
|
+
),
|
|
52
|
+
"set_view_transform_to_standard_on_import": (
|
|
53
|
+
source.set_view_transform_to_standard_on_import
|
|
54
|
+
),
|
|
55
|
+
"set_armature_display_to_wire": (source.set_armature_display_to_wire),
|
|
56
|
+
"set_armature_display_to_show_in_front": (
|
|
57
|
+
source.set_armature_display_to_show_in_front
|
|
58
|
+
),
|
|
59
|
+
"set_armature_bone_shape_to_default": source.set_armature_bone_shape_to_default,
|
|
60
|
+
"enable_mtoon_outline_preview": source.enable_mtoon_outline_preview,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def copy_import_preferences(
|
|
65
|
+
*, source: ImportPreferencesProtocol, destination: ImportPreferencesProtocol
|
|
66
|
+
) -> None:
|
|
67
|
+
(
|
|
68
|
+
destination.extract_textures_into_folder,
|
|
69
|
+
destination.make_new_texture_folder,
|
|
70
|
+
destination.set_shading_type_to_material_on_import,
|
|
71
|
+
destination.set_view_transform_to_standard_on_import,
|
|
72
|
+
destination.set_armature_display_to_wire,
|
|
73
|
+
destination.set_armature_display_to_show_in_front,
|
|
74
|
+
destination.set_armature_bone_shape_to_default,
|
|
75
|
+
destination.enable_mtoon_outline_preview,
|
|
76
|
+
) = (
|
|
77
|
+
source.extract_textures_into_folder,
|
|
78
|
+
source.make_new_texture_folder,
|
|
79
|
+
source.set_shading_type_to_material_on_import,
|
|
80
|
+
source.set_view_transform_to_standard_on_import,
|
|
81
|
+
source.set_armature_display_to_wire,
|
|
82
|
+
source.set_armature_display_to_show_in_front,
|
|
83
|
+
source.set_armature_bone_shape_to_default,
|
|
84
|
+
source.enable_mtoon_outline_preview,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def draw_import_preferences_layout(
|
|
89
|
+
preferences: ImportPreferencesProtocol, layout: UILayout
|
|
90
|
+
) -> None:
|
|
91
|
+
if not isinstance(preferences, (AddonPreferences, Operator)):
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
layout.prop(preferences, "extract_textures_into_folder")
|
|
95
|
+
if preferences.extract_textures_into_folder:
|
|
96
|
+
layout.prop(preferences, "make_new_texture_folder")
|
|
97
|
+
layout.prop(preferences, "set_shading_type_to_material_on_import")
|
|
98
|
+
layout.prop(preferences, "set_view_transform_to_standard_on_import")
|
|
99
|
+
layout.prop(preferences, "set_armature_display_to_wire")
|
|
100
|
+
layout.prop(preferences, "set_armature_display_to_show_in_front")
|
|
101
|
+
layout.prop(preferences, "set_armature_bone_shape_to_default")
|
|
102
|
+
layout.prop(preferences, "enable_mtoon_outline_preview")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class ExportPreferencesProtocol(Protocol):
|
|
106
|
+
export_invisibles: bool
|
|
107
|
+
export_only_selections: bool
|
|
108
|
+
enable_advanced_preferences: bool
|
|
109
|
+
export_all_influences: bool
|
|
110
|
+
export_lights: bool
|
|
111
|
+
export_gltf_animations: bool
|
|
112
|
+
export_try_sparse_sk: bool
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def copy_export_preferences(
|
|
116
|
+
*, source: ExportPreferencesProtocol, destination: ExportPreferencesProtocol
|
|
117
|
+
) -> None:
|
|
118
|
+
(
|
|
119
|
+
destination.export_invisibles,
|
|
120
|
+
destination.export_only_selections,
|
|
121
|
+
destination.enable_advanced_preferences,
|
|
122
|
+
destination.export_all_influences,
|
|
123
|
+
destination.export_lights,
|
|
124
|
+
destination.export_gltf_animations,
|
|
125
|
+
destination.export_try_sparse_sk,
|
|
126
|
+
) = (
|
|
127
|
+
source.export_invisibles,
|
|
128
|
+
source.export_only_selections,
|
|
129
|
+
source.enable_advanced_preferences,
|
|
130
|
+
source.export_all_influences,
|
|
131
|
+
source.export_lights,
|
|
132
|
+
source.export_gltf_animations,
|
|
133
|
+
source.export_try_sparse_sk,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _draw_advanced_options_description(
|
|
138
|
+
preferences: Union[AddonPreferences, Operator],
|
|
139
|
+
property_name: str,
|
|
140
|
+
layout: UILayout,
|
|
141
|
+
description: str,
|
|
142
|
+
) -> None:
|
|
143
|
+
column = layout.box().column(align=True)
|
|
144
|
+
column.prop(preferences, property_name)
|
|
145
|
+
description_column = column.box().column(align=True)
|
|
146
|
+
for i, line in enumerate(description.splitlines()):
|
|
147
|
+
icon = "ERROR" if i == 0 else "NONE"
|
|
148
|
+
description_column.label(text=line, translate=False, icon=icon)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def draw_export_preferences_layout(
|
|
152
|
+
preferences: ExportPreferencesProtocol,
|
|
153
|
+
layout: UILayout,
|
|
154
|
+
*,
|
|
155
|
+
show_vrm1_options: bool,
|
|
156
|
+
) -> None:
|
|
157
|
+
if not isinstance(preferences, (AddonPreferences, Operator)):
|
|
158
|
+
return
|
|
159
|
+
|
|
160
|
+
layout.prop(preferences, "export_invisibles")
|
|
161
|
+
layout.prop(preferences, "export_only_selections")
|
|
162
|
+
|
|
163
|
+
if not show_vrm1_options:
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
layout.prop(preferences, "enable_advanced_preferences")
|
|
167
|
+
if not preferences.enable_advanced_preferences:
|
|
168
|
+
return
|
|
169
|
+
|
|
170
|
+
advanced_options_column = layout.box().column()
|
|
171
|
+
|
|
172
|
+
# UniVRM 0.115.0 doesn't support `export_try_sparse_sk`
|
|
173
|
+
# https://github.com/saturday06/VRM-Addon-for-Blender/issues/381#issuecomment-1838365762
|
|
174
|
+
_draw_advanced_options_description(
|
|
175
|
+
preferences,
|
|
176
|
+
"export_try_sparse_sk",
|
|
177
|
+
advanced_options_column,
|
|
178
|
+
pgettext(
|
|
179
|
+
"The file size will be reduced,\n"
|
|
180
|
+
+ "but it will no longer be readable by\n"
|
|
181
|
+
+ "older apps with UniVRM 0.115.0 or\n"
|
|
182
|
+
+ "earlier."
|
|
183
|
+
),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
# The upstream says that Models may appear incorrectly in many viewers.
|
|
187
|
+
# https://github.com/KhronosGroup/glTF-Blender-IO/blob/356b3dda976303d3ecce8b3bd1591245e576db38/addons/io_scene_gltf2/__init__.py#L760
|
|
188
|
+
_draw_advanced_options_description(
|
|
189
|
+
preferences,
|
|
190
|
+
"export_all_influences",
|
|
191
|
+
advanced_options_column,
|
|
192
|
+
pgettext(
|
|
193
|
+
"By default, 4 bone influences\n"
|
|
194
|
+
+ "are exported for each vertex. Many\n"
|
|
195
|
+
+ "apps truncate to 4. Increasing it\n"
|
|
196
|
+
+ "may cause jagged meshes."
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
_draw_advanced_options_description(
|
|
201
|
+
preferences,
|
|
202
|
+
"export_lights",
|
|
203
|
+
advanced_options_column,
|
|
204
|
+
pgettext(
|
|
205
|
+
"There is no consensus on how\n"
|
|
206
|
+
+ "to handle lights in VRM, so it is\n"
|
|
207
|
+
+ "impossible to predict what the\n"
|
|
208
|
+
+ "outcome will be."
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
_draw_advanced_options_description(
|
|
213
|
+
preferences,
|
|
214
|
+
"export_gltf_animations",
|
|
215
|
+
advanced_options_column,
|
|
216
|
+
pgettext(
|
|
217
|
+
"UniVRM does not export\n"
|
|
218
|
+
+ "glTF Animations, so it is disabled\n"
|
|
219
|
+
+ "by default. Please consider using\n"
|
|
220
|
+
+ "VRM Animation."
|
|
221
|
+
),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class VrmAddonPreferences(AddonPreferences):
|
|
226
|
+
bl_idname = ADDON_PACKAGE_NAME
|
|
227
|
+
|
|
228
|
+
UNMANAGED_ADDON_VERSION: tuple[int, int, int] = (0, 0, 0)
|
|
229
|
+
|
|
230
|
+
addon_version: IntVectorProperty( # type: ignore[valid-type]
|
|
231
|
+
size=3,
|
|
232
|
+
default=UNMANAGED_ADDON_VERSION,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
def _update_add_mtoon_shader_node_group(self, context: Context) -> None:
|
|
236
|
+
if self.add_mtoon_shader_node_group:
|
|
237
|
+
add_mtoon1_auto_setup_shader_node_group(context)
|
|
238
|
+
else:
|
|
239
|
+
remove_mtoon1_auto_setup_shader_node_group(context)
|
|
240
|
+
|
|
241
|
+
add_mtoon_shader_node_group: BoolProperty( # type: ignore[valid-type]
|
|
242
|
+
name="Add MToon shader node group",
|
|
243
|
+
default=True,
|
|
244
|
+
update=_update_add_mtoon_shader_node_group,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
extract_textures_into_folder: BoolProperty( # type: ignore[valid-type]
|
|
248
|
+
name="Extract texture images into the folder",
|
|
249
|
+
default=False,
|
|
250
|
+
)
|
|
251
|
+
make_new_texture_folder: BoolProperty( # type: ignore[valid-type]
|
|
252
|
+
name="Don't overwrite existing texture image folder",
|
|
253
|
+
default=True,
|
|
254
|
+
)
|
|
255
|
+
set_shading_type_to_material_on_import: BoolProperty( # type: ignore[valid-type]
|
|
256
|
+
name='Set shading type to "Material"',
|
|
257
|
+
default=True,
|
|
258
|
+
)
|
|
259
|
+
set_view_transform_to_standard_on_import: BoolProperty( # type: ignore[valid-type]
|
|
260
|
+
name='Set view transform to "Standard"',
|
|
261
|
+
default=True,
|
|
262
|
+
)
|
|
263
|
+
set_armature_display_to_wire: BoolProperty( # type: ignore[valid-type]
|
|
264
|
+
name='Set an imported armature display to "Wire"',
|
|
265
|
+
default=True,
|
|
266
|
+
)
|
|
267
|
+
set_armature_display_to_show_in_front: BoolProperty( # type: ignore[valid-type]
|
|
268
|
+
name='Set an imported armature display to show "In-Front"',
|
|
269
|
+
default=True,
|
|
270
|
+
)
|
|
271
|
+
set_armature_bone_shape_to_default: BoolProperty( # type: ignore[valid-type]
|
|
272
|
+
name="Set an imported bone shape to default",
|
|
273
|
+
default=True,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
enable_mtoon_outline_preview: BoolProperty( # type: ignore[valid-type]
|
|
277
|
+
name="Enable MToon Outline Preview",
|
|
278
|
+
default=True,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
export_invisibles: BoolProperty( # type: ignore[valid-type]
|
|
282
|
+
name="Export Invisible Objects",
|
|
283
|
+
)
|
|
284
|
+
export_only_selections: BoolProperty( # type: ignore[valid-type]
|
|
285
|
+
name="Export Only Selections",
|
|
286
|
+
)
|
|
287
|
+
enable_advanced_preferences: BoolProperty( # type: ignore[valid-type]
|
|
288
|
+
name="Enable Advanced Options",
|
|
289
|
+
)
|
|
290
|
+
export_all_influences: BoolProperty( # type: ignore[valid-type]
|
|
291
|
+
name="Export All Bone Influences",
|
|
292
|
+
)
|
|
293
|
+
export_lights: BoolProperty( # type: ignore[valid-type]
|
|
294
|
+
name="Export Lights",
|
|
295
|
+
)
|
|
296
|
+
export_gltf_animations: BoolProperty( # type: ignore[valid-type]
|
|
297
|
+
name="Export glTF Animations",
|
|
298
|
+
)
|
|
299
|
+
export_try_sparse_sk: BoolProperty( # type: ignore[valid-type]
|
|
300
|
+
name="Use Sparse Accessors",
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
def draw(self, _context: Context) -> None:
|
|
304
|
+
layout = self.layout
|
|
305
|
+
|
|
306
|
+
warning_message = version.preferences_warning_message()
|
|
307
|
+
if warning_message:
|
|
308
|
+
box = layout.box()
|
|
309
|
+
warning_column = box.column()
|
|
310
|
+
for index, warning_line in enumerate(warning_message.splitlines()):
|
|
311
|
+
warning_column.label(
|
|
312
|
+
text=warning_line,
|
|
313
|
+
translate=False,
|
|
314
|
+
icon="NONE" if index else "ERROR",
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
layout.prop(self, "add_mtoon_shader_node_group")
|
|
318
|
+
|
|
319
|
+
import_box = layout.box()
|
|
320
|
+
import_box.label(text="Import", icon="IMPORT")
|
|
321
|
+
draw_import_preferences_layout(self, import_box)
|
|
322
|
+
|
|
323
|
+
export_box = layout.box()
|
|
324
|
+
export_box.label(text="Export", icon="EXPORT")
|
|
325
|
+
draw_export_preferences_layout(self, export_box, show_vrm1_options=True)
|
|
326
|
+
|
|
327
|
+
if TYPE_CHECKING:
|
|
328
|
+
# This code is auto generated.
|
|
329
|
+
# To regenerate, run the `uv run tools/property_typing.py` command.
|
|
330
|
+
addon_version: Sequence[int] # type: ignore[no-redef]
|
|
331
|
+
add_mtoon_shader_node_group: bool # type: ignore[no-redef]
|
|
332
|
+
extract_textures_into_folder: bool # type: ignore[no-redef]
|
|
333
|
+
make_new_texture_folder: bool # type: ignore[no-redef]
|
|
334
|
+
set_shading_type_to_material_on_import: bool # type: ignore[no-redef]
|
|
335
|
+
set_view_transform_to_standard_on_import: bool # type: ignore[no-redef]
|
|
336
|
+
set_armature_display_to_wire: bool # type: ignore[no-redef]
|
|
337
|
+
set_armature_display_to_show_in_front: bool # type: ignore[no-redef]
|
|
338
|
+
set_armature_bone_shape_to_default: bool # type: ignore[no-redef]
|
|
339
|
+
enable_mtoon_outline_preview: bool # type: ignore[no-redef]
|
|
340
|
+
export_invisibles: bool # type: ignore[no-redef]
|
|
341
|
+
export_only_selections: bool # type: ignore[no-redef]
|
|
342
|
+
enable_advanced_preferences: bool # type: ignore[no-redef]
|
|
343
|
+
export_all_influences: bool # type: ignore[no-redef]
|
|
344
|
+
export_lights: bool # type: ignore[no-redef]
|
|
345
|
+
export_gltf_animations: bool # type: ignore[no-redef]
|
|
346
|
+
export_try_sparse_sk: bool # type: ignore[no-redef]
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def get_preferences(context: Context) -> VrmAddonPreferences:
|
|
350
|
+
addon = context.preferences.addons.get(ADDON_PACKAGE_NAME)
|
|
351
|
+
if not addon:
|
|
352
|
+
message = f"No add-on preferences for {ADDON_PACKAGE_NAME}"
|
|
353
|
+
raise AssertionError(message)
|
|
354
|
+
|
|
355
|
+
preferences = addon.preferences
|
|
356
|
+
if not isinstance(preferences, VrmAddonPreferences):
|
|
357
|
+
raise TypeError(
|
|
358
|
+
f"Add-on preferences for {ADDON_PACKAGE_NAME} is not a VrmAddonPreferences"
|
|
359
|
+
+ f" but {type(preferences)}"
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
return preferences
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR GPL-3.0-or-later
|
|
2
|
+
import math
|
|
3
|
+
from collections.abc import Generator
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from typing import Final, Optional
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
import bpy
|
|
9
|
+
from bpy.types import Context
|
|
10
|
+
|
|
11
|
+
from .logger import get_logger
|
|
12
|
+
|
|
13
|
+
_logger = get_logger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PartialProgress:
|
|
17
|
+
def __init__(
|
|
18
|
+
self, progress: "Progress", partial_start_ratio: float, partial_end_ratio: float
|
|
19
|
+
) -> None:
|
|
20
|
+
self.progress: Final = progress
|
|
21
|
+
self.partial_start_ratio: Final = partial_start_ratio
|
|
22
|
+
self.partial_end_ratio: Final = partial_end_ratio
|
|
23
|
+
|
|
24
|
+
def update(self, ratio: float) -> None:
|
|
25
|
+
ratio = min(max(0.0, ratio), 1.0)
|
|
26
|
+
self.progress.update(
|
|
27
|
+
self.partial_start_ratio
|
|
28
|
+
+ ratio * (self.partial_end_ratio - self.partial_start_ratio)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Progress:
|
|
33
|
+
active_progress_uuid: Optional[str] = None
|
|
34
|
+
|
|
35
|
+
def __init__(self, context: Context, *, show_progress: bool) -> None:
|
|
36
|
+
self.context: Final = context
|
|
37
|
+
self.show_progress: Final = show_progress
|
|
38
|
+
self.uuid: Final = uuid4().hex
|
|
39
|
+
self.last_ratio = 0.0
|
|
40
|
+
|
|
41
|
+
def partial_progress(self, partial_end_ratio: float) -> PartialProgress:
|
|
42
|
+
partial_end_ratio = min(max(0.0, partial_end_ratio), 1.0)
|
|
43
|
+
return PartialProgress(self, self.last_ratio, partial_end_ratio)
|
|
44
|
+
|
|
45
|
+
def update(self, ratio: float) -> None:
|
|
46
|
+
ratio = min(max(0.0, ratio), 1.0)
|
|
47
|
+
self.last_ratio = ratio
|
|
48
|
+
if self.active_progress_uuid != self.uuid:
|
|
49
|
+
_logger.error(
|
|
50
|
+
"Progress.update() called from different progress active=%s self=%s",
|
|
51
|
+
self.active_progress_uuid,
|
|
52
|
+
self.uuid,
|
|
53
|
+
)
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
if not self.show_progress:
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
if bpy.app.version >= (5, 0):
|
|
60
|
+
progress_value = ratio * 9999
|
|
61
|
+
else:
|
|
62
|
+
# The mouse cursor becomes a four-digit number, and there is an area
|
|
63
|
+
# where values from 0 to 9999 can be displayed. However, if the
|
|
64
|
+
# progress rate is directly converted to a number from 0 to 9999, the
|
|
65
|
+
# last two digits will frequently round-trip, making the progress
|
|
66
|
+
# difficult to understand. Therefore, only the last two digits display
|
|
67
|
+
# area is used to show the progress rate as a number from 0 to 99.
|
|
68
|
+
progress_value = math.floor(ratio * 99)
|
|
69
|
+
|
|
70
|
+
self.context.window_manager.progress_update(progress_value)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@contextmanager
|
|
74
|
+
def create_progress(
|
|
75
|
+
context: Context, *, show_progress: bool = True
|
|
76
|
+
) -> Generator[Progress]:
|
|
77
|
+
saved_progress_uuid = Progress.active_progress_uuid
|
|
78
|
+
try:
|
|
79
|
+
if show_progress and Progress.active_progress_uuid is None:
|
|
80
|
+
context.window_manager.progress_begin(0, 9999)
|
|
81
|
+
progress = Progress(context, show_progress=show_progress)
|
|
82
|
+
Progress.active_progress_uuid = progress.uuid
|
|
83
|
+
yield progress
|
|
84
|
+
finally:
|
|
85
|
+
Progress.active_progress_uuid = saved_progress_uuid
|
|
86
|
+
if show_progress and Progress.active_progress_uuid is None:
|
|
87
|
+
context.window_manager.progress_end()
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR GPL-3.0-or-later
|
|
2
|
+
from typing import Final, Union
|
|
3
|
+
|
|
4
|
+
from bpy.types import (
|
|
5
|
+
Object,
|
|
6
|
+
PoseBone,
|
|
7
|
+
)
|
|
8
|
+
from mathutils import Quaternion
|
|
9
|
+
|
|
10
|
+
from .logger import get_logger
|
|
11
|
+
|
|
12
|
+
_logger = get_logger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
ROTATION_MODE_QUATERNION: Final = "QUATERNION"
|
|
16
|
+
ROTATION_MODE_AXIS_ANGLE: Final = "AXIS_ANGLE"
|
|
17
|
+
ROTATION_MODE_EULER: Final = ("XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_rotation_as_quaternion(
|
|
21
|
+
object_or_pose_bone: Union[Object, PoseBone],
|
|
22
|
+
) -> Quaternion:
|
|
23
|
+
if object_or_pose_bone.rotation_mode == ROTATION_MODE_QUATERNION:
|
|
24
|
+
return object_or_pose_bone.rotation_quaternion.copy()
|
|
25
|
+
|
|
26
|
+
if object_or_pose_bone.rotation_mode == ROTATION_MODE_AXIS_ANGLE:
|
|
27
|
+
# https://projects.blender.org/blender/blender/src/tag/v2.93.18/source/blender/makesrna/intern/rna_pose.c#L270-L278
|
|
28
|
+
angle, axis_x, axis_y, axis_z = object_or_pose_bone.rotation_axis_angle
|
|
29
|
+
return Quaternion((axis_x, axis_y, axis_z), angle)
|
|
30
|
+
|
|
31
|
+
if object_or_pose_bone.rotation_mode in ROTATION_MODE_EULER:
|
|
32
|
+
return object_or_pose_bone.rotation_euler.to_quaternion()
|
|
33
|
+
|
|
34
|
+
_logger.error(
|
|
35
|
+
"Unexpected rotation mode for %s %s: %s",
|
|
36
|
+
type(object_or_pose_bone),
|
|
37
|
+
object_or_pose_bone.name,
|
|
38
|
+
object_or_pose_bone.rotation_mode,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return Quaternion()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def set_rotation_without_mode_change(
|
|
45
|
+
object_or_pose_bone: Union[Object, PoseBone], quaternion: Quaternion
|
|
46
|
+
) -> None:
|
|
47
|
+
if object_or_pose_bone.rotation_mode == ROTATION_MODE_QUATERNION:
|
|
48
|
+
object_or_pose_bone.rotation_quaternion = quaternion.copy()
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
if object_or_pose_bone.rotation_mode == ROTATION_MODE_AXIS_ANGLE:
|
|
52
|
+
axis, angle = quaternion.to_axis_angle()
|
|
53
|
+
# https://projects.blender.org/blender/blender/src/tag/v2.93.18/source/blender/makesrna/intern/rna_pose.c#L280-L290
|
|
54
|
+
object_or_pose_bone.rotation_axis_angle = [angle, axis.x, axis.y, axis.z]
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
if object_or_pose_bone.rotation_mode in ROTATION_MODE_EULER:
|
|
58
|
+
object_or_pose_bone.rotation_euler = quaternion.to_euler(
|
|
59
|
+
object_or_pose_bone.rotation_mode
|
|
60
|
+
)
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
_logger.error(
|
|
64
|
+
"Unexpected rotation mode for %s %s: %s",
|
|
65
|
+
type(object_or_pose_bone),
|
|
66
|
+
object_or_pose_bone.name,
|
|
67
|
+
object_or_pose_bone.rotation_mode,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def insert_rotation_keyframe(
|
|
72
|
+
object_or_pose_bone: Union[Object, PoseBone], *, frame: int
|
|
73
|
+
) -> None:
|
|
74
|
+
if object_or_pose_bone.rotation_mode == ROTATION_MODE_QUATERNION:
|
|
75
|
+
data_path = "rotation_quaternion"
|
|
76
|
+
elif object_or_pose_bone.rotation_mode == ROTATION_MODE_AXIS_ANGLE:
|
|
77
|
+
data_path = "rotation_axis_angle"
|
|
78
|
+
elif object_or_pose_bone.rotation_mode in ROTATION_MODE_EULER:
|
|
79
|
+
data_path = "rotation_euler"
|
|
80
|
+
else:
|
|
81
|
+
_logger.error(
|
|
82
|
+
"Unexpected rotation mode for %s %s: %s",
|
|
83
|
+
type(object_or_pose_bone),
|
|
84
|
+
object_or_pose_bone.name,
|
|
85
|
+
object_or_pose_bone.rotation_mode,
|
|
86
|
+
)
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
object_or_pose_bone.keyframe_insert(data_path, frame=frame)
|