@volter/blender-engine 0.1.148 → 0.1.149

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.
Files changed (245) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +4 -11
  3. package/browser/addons/vrm/LICENSE_(OPTION1)_MIT.txt +22 -0
  4. package/browser/addons/vrm/LICENSE_(OPTION2)_GPL-3_0.txt +674 -0
  5. package/browser/addons/vrm/LICENSE_MAIN.txt +1 -0
  6. package/browser/addons/vrm/README.txt +3 -0
  7. package/browser/addons/vrm/__init__.py +41 -0
  8. package/browser/addons/vrm/blender_manifest.toml +16 -0
  9. package/browser/addons/vrm/common/__init__.py +1 -0
  10. package/browser/addons/vrm/common/animation.py +58 -0
  11. package/browser/addons/vrm/common/blender_manifest.py +82 -0
  12. package/browser/addons/vrm/common/char.py +16 -0
  13. package/browser/addons/vrm/common/convert.py +287 -0
  14. package/browser/addons/vrm/common/convert_any.py +48 -0
  15. package/browser/addons/vrm/common/debug.py +40 -0
  16. package/browser/addons/vrm/common/deep.py +162 -0
  17. package/browser/addons/vrm/common/error_dialog.py +274 -0
  18. package/browser/addons/vrm/common/fs.py +71 -0
  19. package/browser/addons/vrm/common/gl.py +20 -0
  20. package/browser/addons/vrm/common/gltf.py +1149 -0
  21. package/browser/addons/vrm/common/human_bone_mapper/__init__.py +1 -0
  22. package/browser/addons/vrm/common/human_bone_mapper/biped_mapping.py +84 -0
  23. package/browser/addons/vrm/common/human_bone_mapper/cats_blender_plugin_fix_model_mapping.py +63 -0
  24. package/browser/addons/vrm/common/human_bone_mapper/human_bone_mapper.py +203 -0
  25. package/browser/addons/vrm/common/human_bone_mapper/microsoft_rocketbox_mapping.py +69 -0
  26. package/browser/addons/vrm/common/human_bone_mapper/mixamo_mapping.py +62 -0
  27. package/browser/addons/vrm/common/human_bone_mapper/mmd_mapping.py +115 -0
  28. package/browser/addons/vrm/common/human_bone_mapper/mpfb_mapping.py +120 -0
  29. package/browser/addons/vrm/common/human_bone_mapper/ready_player_me_mapping.py +65 -0
  30. package/browser/addons/vrm/common/human_bone_mapper/reallusion_mapping.py +94 -0
  31. package/browser/addons/vrm/common/human_bone_mapper/rigify_meta_rig_mapping.py +65 -0
  32. package/browser/addons/vrm/common/human_bone_mapper/structure_based_mapping.py +891 -0
  33. package/browser/addons/vrm/common/human_bone_mapper/unreal_mapping.py +62 -0
  34. package/browser/addons/vrm/common/human_bone_mapper/vrm_addon_mapping.py +112 -0
  35. package/browser/addons/vrm/common/human_bone_mapper/vroid_mapping.py +89 -0
  36. package/browser/addons/vrm/common/legacy_gltf.py +16 -0
  37. package/browser/addons/vrm/common/logger.py +84 -0
  38. package/browser/addons/vrm/common/mtoon0.blend +0 -0
  39. package/browser/addons/vrm/common/mtoon1.blend +0 -0
  40. package/browser/addons/vrm/common/mtoon1_outline.blend +0 -0
  41. package/browser/addons/vrm/common/mtoon_auto_setup.blend +0 -0
  42. package/browser/addons/vrm/common/mtoon_unversioned.py +62 -0
  43. package/browser/addons/vrm/common/ops/__init__.py +10 -0
  44. package/browser/addons/vrm/common/ops/export_scene.py +67 -0
  45. package/browser/addons/vrm/common/ops/icyp.py +53 -0
  46. package/browser/addons/vrm/common/ops/import_scene.py +57 -0
  47. package/browser/addons/vrm/common/ops/vrm.py +2380 -0
  48. package/browser/addons/vrm/common/ops/wm.py +167 -0
  49. package/browser/addons/vrm/common/preferences.py +362 -0
  50. package/browser/addons/vrm/common/progress.py +87 -0
  51. package/browser/addons/vrm/common/rotation.py +89 -0
  52. package/browser/addons/vrm/common/safe_removal.py +46 -0
  53. package/browser/addons/vrm/common/scene_watcher.py +230 -0
  54. package/browser/addons/vrm/common/shader.py +2243 -0
  55. package/browser/addons/vrm/common/shape_key_mapper/__init__.py +1 -0
  56. package/browser/addons/vrm/common/shape_key_mapper/arkit_mapping.py +168 -0
  57. package/browser/addons/vrm/common/shape_key_mapper/mmd_mapping.py +62 -0
  58. package/browser/addons/vrm/common/shape_key_mapper/ready_player_me_mapping.py +52 -0
  59. package/browser/addons/vrm/common/shape_key_mapper/vrchat_mapping.py +17 -0
  60. package/browser/addons/vrm/common/third_party_user_extension.py +214 -0
  61. package/browser/addons/vrm/common/transparent_z_write.blend +0 -0
  62. package/browser/addons/vrm/common/version.py +161 -0
  63. package/browser/addons/vrm/common/vrm0/__init__.py +1 -0
  64. package/browser/addons/vrm/common/vrm0/human_bone.py +662 -0
  65. package/browser/addons/vrm/common/vrm0/material_property.py +346 -0
  66. package/browser/addons/vrm/common/vrm1/__init__.py +1 -0
  67. package/browser/addons/vrm/common/vrm1/expression_preset.py +207 -0
  68. package/browser/addons/vrm/common/vrm1/human_bone.py +822 -0
  69. package/browser/addons/vrm/common/workspace.py +227 -0
  70. package/browser/addons/vrm/common/writable_context.py +77 -0
  71. package/browser/addons/vrm/documentation/en-us/animation/index.md +63 -0
  72. package/browser/addons/vrm/documentation/en-us/create-humanoid-vrm-from-scratch/index.md +131 -0
  73. package/browser/addons/vrm/documentation/en-us/create-simple-vrm-from-scratch/index.md +30 -0
  74. package/browser/addons/vrm/documentation/en-us/development/index.md +136 -0
  75. package/browser/addons/vrm/documentation/en-us/index.md +41 -0
  76. package/browser/addons/vrm/documentation/en-us/installation/index.md +152 -0
  77. package/browser/addons/vrm/documentation/en-us/material-mtoon/index.md +122 -0
  78. package/browser/addons/vrm/documentation/en-us/material-pbr/index.md +94 -0
  79. package/browser/addons/vrm/documentation/en-us/scripting-api/index.md +391 -0
  80. package/browser/addons/vrm/documentation/en-us/ui/export_scene.vrm/index.md +57 -0
  81. package/browser/addons/vrm/documentation/en-us/ui/export_scene.vrma/index.md +17 -0
  82. package/browser/addons/vrm/documentation/en-us/ui/import_scene.vrm/index.md +61 -0
  83. package/browser/addons/vrm/documentation/en-us/ui/import_scene.vrma/index.md +13 -0
  84. package/browser/addons/vrm/documentation/ja-jp/animation/index.md +57 -0
  85. package/browser/addons/vrm/documentation/ja-jp/create-humanoid-vrm-from-scratch/index.md +129 -0
  86. package/browser/addons/vrm/documentation/ja-jp/create-simple-vrm-from-scratch/index.md +29 -0
  87. package/browser/addons/vrm/documentation/ja-jp/development/index.md +137 -0
  88. package/browser/addons/vrm/documentation/ja-jp/index.md +37 -0
  89. package/browser/addons/vrm/documentation/ja-jp/installation/index.md +150 -0
  90. package/browser/addons/vrm/documentation/ja-jp/material-mtoon/index.md +113 -0
  91. package/browser/addons/vrm/documentation/ja-jp/material-pbr/index.md +90 -0
  92. package/browser/addons/vrm/documentation/ja-jp/scripting-api/index.md +389 -0
  93. package/browser/addons/vrm/documentation/ja-jp/ui/export_scene.vrm/index.md +55 -0
  94. package/browser/addons/vrm/documentation/ja-jp/ui/export_scene.vrma/index.md +19 -0
  95. package/browser/addons/vrm/documentation/ja-jp/ui/import_scene.vrm/index.md +56 -0
  96. package/browser/addons/vrm/documentation/ja-jp/ui/import_scene.vrma/index.md +14 -0
  97. package/browser/addons/vrm/editor/__init__.py +1 -0
  98. package/browser/addons/vrm/editor/extension.py +425 -0
  99. package/browser/addons/vrm/editor/extension_accessor.py +75 -0
  100. package/browser/addons/vrm/editor/handler.py +84 -0
  101. package/browser/addons/vrm/editor/khr_character/__init__.py +1 -0
  102. package/browser/addons/vrm/editor/khr_character/panel.py +69 -0
  103. package/browser/addons/vrm/editor/khr_character/property_group.py +27 -0
  104. package/browser/addons/vrm/editor/khr_xmp_json_ld/__init__.py +1 -0
  105. package/browser/addons/vrm/editor/khr_xmp_json_ld/ops.py +464 -0
  106. package/browser/addons/vrm/editor/khr_xmp_json_ld/panel.py +136 -0
  107. package/browser/addons/vrm/editor/khr_xmp_json_ld/property_group.py +83 -0
  108. package/browser/addons/vrm/editor/khr_xmp_json_ld/ui_list.py +198 -0
  109. package/browser/addons/vrm/editor/make_armature.py +709 -0
  110. package/browser/addons/vrm/editor/menu.py +147 -0
  111. package/browser/addons/vrm/editor/migration.py +297 -0
  112. package/browser/addons/vrm/editor/mtoon1/__init__.py +1 -0
  113. package/browser/addons/vrm/editor/mtoon1/handler.py +20 -0
  114. package/browser/addons/vrm/editor/mtoon1/migration.py +536 -0
  115. package/browser/addons/vrm/editor/mtoon1/ops.py +304 -0
  116. package/browser/addons/vrm/editor/mtoon1/panel.py +442 -0
  117. package/browser/addons/vrm/editor/mtoon1/property_group.py +4977 -0
  118. package/browser/addons/vrm/editor/mtoon1/scene_watcher.py +381 -0
  119. package/browser/addons/vrm/editor/node_constraint1/__init__.py +1 -0
  120. package/browser/addons/vrm/editor/node_constraint1/panel.py +317 -0
  121. package/browser/addons/vrm/editor/node_constraint1/property_group.py +25 -0
  122. package/browser/addons/vrm/editor/ops.py +471 -0
  123. package/browser/addons/vrm/editor/panel.py +315 -0
  124. package/browser/addons/vrm/editor/property_group.py +888 -0
  125. package/browser/addons/vrm/editor/search.py +682 -0
  126. package/browser/addons/vrm/editor/spring_bone1/__init__.py +1 -0
  127. package/browser/addons/vrm/editor/spring_bone1/handler.py +994 -0
  128. package/browser/addons/vrm/editor/spring_bone1/menu.py +246 -0
  129. package/browser/addons/vrm/editor/spring_bone1/migration.py +86 -0
  130. package/browser/addons/vrm/editor/spring_bone1/ops.py +1679 -0
  131. package/browser/addons/vrm/editor/spring_bone1/panel.py +605 -0
  132. package/browser/addons/vrm/editor/spring_bone1/property_group.py +1457 -0
  133. package/browser/addons/vrm/editor/spring_bone1/ui_list.py +408 -0
  134. package/browser/addons/vrm/editor/subscription.py +123 -0
  135. package/browser/addons/vrm/editor/t_pose.py +713 -0
  136. package/browser/addons/vrm/editor/validation.py +1271 -0
  137. package/browser/addons/vrm/editor/vrm0/__init__.py +1 -0
  138. package/browser/addons/vrm/editor/vrm0/gizmo_group.py +63 -0
  139. package/browser/addons/vrm/editor/vrm0/handler.py +23 -0
  140. package/browser/addons/vrm/editor/vrm0/menu.py +145 -0
  141. package/browser/addons/vrm/editor/vrm0/migration.py +761 -0
  142. package/browser/addons/vrm/editor/vrm0/ops.py +2145 -0
  143. package/browser/addons/vrm/editor/vrm0/panel.py +1333 -0
  144. package/browser/addons/vrm/editor/vrm0/property_group.py +1818 -0
  145. package/browser/addons/vrm/editor/vrm0/ui_list.py +688 -0
  146. package/browser/addons/vrm/editor/vrm1/__init__.py +1 -0
  147. package/browser/addons/vrm/editor/vrm1/handler.py +28 -0
  148. package/browser/addons/vrm/editor/vrm1/menu.py +76 -0
  149. package/browser/addons/vrm/editor/vrm1/migration.py +321 -0
  150. package/browser/addons/vrm/editor/vrm1/ops.py +2679 -0
  151. package/browser/addons/vrm/editor/vrm1/panel.py +1243 -0
  152. package/browser/addons/vrm/editor/vrm1/property_group.py +2087 -0
  153. package/browser/addons/vrm/editor/vrm1/scene_watcher.py +90 -0
  154. package/browser/addons/vrm/editor/vrm1/ui_list.py +533 -0
  155. package/browser/addons/vrm/exporter/__init__.py +1 -0
  156. package/browser/addons/vrm/exporter/abstract_base_vrm_exporter.py +628 -0
  157. package/browser/addons/vrm/exporter/export_scene.py +930 -0
  158. package/browser/addons/vrm/exporter/gltf2_export_user_extension.py +45 -0
  159. package/browser/addons/vrm/exporter/khr_character_exporter.py +34 -0
  160. package/browser/addons/vrm/exporter/vrm0_exporter.py +4020 -0
  161. package/browser/addons/vrm/exporter/vrm1_exporter.py +3682 -0
  162. package/browser/addons/vrm/exporter/vrm_animation_exporter.py +1035 -0
  163. package/browser/addons/vrm/external/__init__.py +1 -0
  164. package/browser/addons/vrm/external/auto_rig_pro_support.py +3 -0
  165. package/browser/addons/vrm/external/io_scene_gltf2_support.py +418 -0
  166. package/browser/addons/vrm/external/rigify_support.py +1 -0
  167. package/browser/addons/vrm/importer/__init__.py +1 -0
  168. package/browser/addons/vrm/importer/abstract_base_vrm_importer.py +1548 -0
  169. package/browser/addons/vrm/importer/file_handler.py +34 -0
  170. package/browser/addons/vrm/importer/gltf2_import_user_extension.py +268 -0
  171. package/browser/addons/vrm/importer/import_scene.py +646 -0
  172. package/browser/addons/vrm/importer/license_validation.py +198 -0
  173. package/browser/addons/vrm/importer/vrm0_importer.py +1723 -0
  174. package/browser/addons/vrm/importer/vrm1_importer.py +2014 -0
  175. package/browser/addons/vrm/importer/vrm_animation_importer.py +763 -0
  176. package/browser/addons/vrm/importer/vrm_diff.py +316 -0
  177. package/browser/addons/vrm/locale/__init__.py +1 -0
  178. package/browser/addons/vrm/locale/ja_jp.py +826 -0
  179. package/browser/addons/vrm/locale/ruff.toml +8 -0
  180. package/browser/addons/vrm/locale/translation_dictionary.py +10 -0
  181. package/browser/addons/vrm/locale/zh_hans.py +928 -0
  182. package/browser/addons/vrm/registration.py +670 -0
  183. package/browser/addons/vrm.json +18 -0
  184. package/browser/blender-emscripten-engine.mts +60 -128
  185. package/browser/blender-engine.mts +20 -186
  186. package/browser/blender-wali-engine.mts +35 -81
  187. package/browser/describe-thrown.mts +3 -6
  188. package/browser/document-chunks.mts +4 -16
  189. package/browser/gltf_export.py +3161 -0
  190. package/browser/heap-growth.mts +23 -0
  191. package/browser/index.ts +2 -0
  192. package/browser/protocol.ts +119 -35
  193. package/browser/pull-job.mts +2 -10
  194. package/browser/rna.ts +190 -73
  195. package/browser/runtime.ts +197 -82
  196. package/browser/session-addons.mts +33 -0
  197. package/browser/session-frame.mts +5 -24
  198. package/browser/session.py +1338 -1427
  199. package/browser/three/attach-presenter.ts +11 -39
  200. package/browser/three/blender-base64.ts +1 -36
  201. package/browser/three/blender-corner-normals.ts +1 -23
  202. package/browser/three/blender-display-shaders.json +1 -1
  203. package/browser/three/blender-display-shaders.lut +0 -0
  204. package/browser/three/blender-display-transform.ts +2 -1
  205. package/browser/three/blender-frame-columns.ts +5 -13
  206. package/browser/three/blender-graph-material.ts +18 -3
  207. package/browser/three/blender-node-graph.ts +10 -34
  208. package/browser/three/blender-physical-material.ts +2 -31
  209. package/browser/three/blender-runtime-armature.ts +7 -60
  210. package/browser/three/blender-runtime-frame.ts +9 -23
  211. package/browser/three/blender-runtime-geometry.ts +22 -26
  212. package/browser/three/blender-runtime-lighting.ts +48 -178
  213. package/browser/three/blender-runtime-shadows.ts +187 -1
  214. package/browser/three/blender-runtime-skeleton.ts +53 -1
  215. package/browser/three/blender-runtime-view.ts +505 -283
  216. package/browser/three/blender-runtime-weights.ts +9 -72
  217. package/browser/three/blender-sky.ts +13 -33
  218. package/browser/three/blender-triangulate.ts +7 -35
  219. package/browser/three/blender-viewport-sampling.ts +235 -0
  220. package/browser/three/blender-workbench-material.ts +25 -29
  221. package/browser/three/blender-workbench-outline.ts +199 -0
  222. package/browser/three/blender-world-volume.ts +62 -10
  223. package/browser/three/presenter.ts +10 -26
  224. package/browser/three/release.ts +5 -21
  225. package/browser/three/sky-precompute-worker.ts +1 -18
  226. package/browser/three/sky-worker.ts +5 -23
  227. package/browser/three/world-field-sampler.ts +12 -26
  228. package/browser/volter_three.py +9 -105
  229. package/browser/worker.ts +156 -151
  230. package/package.json +5 -2
  231. package/wasm/BUNDLE.json +17 -17
  232. package/wasm/DEPENDENCY-LICENSES.txt +14 -0
  233. package/wasm/blender_browser.data.br +0 -0
  234. package/wasm/blender_browser.js +1 -1
  235. package/wasm/blender_browser.wasm.br +0 -0
  236. package/browser/frame-transfer.mts +0 -19
  237. package/browser/three/agx-base-srgb.lut +0 -0
  238. package/browser/three/agx-look-medium-high-contrast.lut +0 -0
  239. package/browser/three/agx-look-punchy.lut +0 -0
  240. package/browser/three/blender-agx.ts +0 -235
  241. package/browser/three/blender-display-lut.ts +0 -145
  242. package/browser/three/blender-filmic.ts +0 -49
  243. package/browser/three/blender-standard.ts +0 -68
  244. package/browser/three/blender-world-visibility.ts +0 -278
  245. package/browser/three/filmic-srgb.lut +0 -0
@@ -0,0 +1,646 @@
1
+ # SPDX-License-Identifier: MIT OR GPL-3.0-or-later
2
+ import traceback
3
+ from os import environ
4
+ from pathlib import Path
5
+ from typing import TYPE_CHECKING, ClassVar
6
+
7
+ import bpy
8
+ from bpy.app.translations import pgettext
9
+ from bpy.props import BoolProperty, CollectionProperty, StringProperty
10
+ from bpy.types import (
11
+ Armature,
12
+ Context,
13
+ Event,
14
+ Operator,
15
+ Panel,
16
+ PropertyGroup,
17
+ SpaceFileBrowser,
18
+ )
19
+ from bpy_extras.io_utils import ImportHelper
20
+
21
+ from ..common import ops, version
22
+ from ..common.error_dialog import show_error_dialog
23
+ from ..common.logger import get_logger
24
+ from ..common.preferences import (
25
+ ImportPreferencesProtocol,
26
+ copy_import_preferences,
27
+ create_import_preferences_dict,
28
+ draw_import_preferences_layout,
29
+ get_preferences,
30
+ )
31
+ from ..editor import search
32
+ from ..editor.extension_accessor import get_armature_extension
33
+ from ..editor.ops import VRM_OT_open_url_in_web_browser, layout_operator
34
+ from ..editor.property_group import CollectionPropertyProtocol, StringPropertyGroup
35
+ from .abstract_base_vrm_importer import AbstractBaseVrmImporter, parse_vrm_json
36
+ from .license_validation import LicenseConfirmationRequiredError
37
+ from .vrm0_importer import Vrm0Importer
38
+ from .vrm1_importer import Vrm1Importer
39
+ from .vrm_animation_importer import VrmAnimationImporter
40
+
41
+ _logger = get_logger(__name__)
42
+
43
+
44
+ class LicenseConfirmation(PropertyGroup):
45
+ message: StringProperty() # type: ignore[valid-type]
46
+ url: StringProperty() # type: ignore[valid-type]
47
+ json_key: StringProperty() # type: ignore[valid-type]
48
+
49
+ if TYPE_CHECKING:
50
+ # This code is auto generated.
51
+ # To regenerate, run the `uv run tools/property_typing.py` command.
52
+ message: str # type: ignore[no-redef]
53
+ url: str # type: ignore[no-redef]
54
+ json_key: str # type: ignore[no-redef]
55
+
56
+
57
+ def _import_vrm_update_addon_preferences(
58
+ import_op: "IMPORT_SCENE_OT_vrm", context: Context
59
+ ) -> None:
60
+ if import_op.use_addon_preferences:
61
+ copy_import_preferences(source=import_op, destination=get_preferences(context))
62
+
63
+
64
+ class IMPORT_SCENE_OT_vrm(Operator, ImportHelper):
65
+ bl_idname = "import_scene.vrm"
66
+ bl_label = "Open"
67
+ bl_description = "import VRM"
68
+ bl_options: ClassVar = {"REGISTER", "UNDO"}
69
+
70
+ filename_ext = ".vrm"
71
+ filter_glob: StringProperty( # type: ignore[valid-type]
72
+ default="*.vrm",
73
+ options={"HIDDEN"},
74
+ )
75
+
76
+ use_addon_preferences: BoolProperty( # type: ignore[valid-type]
77
+ name="Import using add-on preferences",
78
+ description="Import using add-on preferences instead of operator arguments",
79
+ )
80
+
81
+ extract_textures_into_folder: BoolProperty( # type: ignore[valid-type]
82
+ name="Extract texture images into the folder",
83
+ update=_import_vrm_update_addon_preferences,
84
+ default=False,
85
+ )
86
+ make_new_texture_folder: BoolProperty( # type: ignore[valid-type]
87
+ name="Don't overwrite existing texture image folder",
88
+ update=_import_vrm_update_addon_preferences,
89
+ default=True,
90
+ )
91
+ set_shading_type_to_material_on_import: BoolProperty( # type: ignore[valid-type]
92
+ name='Set shading type to "Material"',
93
+ update=_import_vrm_update_addon_preferences,
94
+ default=True,
95
+ )
96
+ set_view_transform_to_standard_on_import: BoolProperty( # type: ignore[valid-type]
97
+ name='Set view transform to "Standard"',
98
+ update=_import_vrm_update_addon_preferences,
99
+ default=True,
100
+ )
101
+ set_armature_display_to_wire: BoolProperty( # type: ignore[valid-type]
102
+ name='Set an imported armature display to "Wire"',
103
+ update=_import_vrm_update_addon_preferences,
104
+ default=True,
105
+ )
106
+ set_armature_display_to_show_in_front: BoolProperty( # type: ignore[valid-type]
107
+ name='Set an imported armature display to show "In-Front"',
108
+ update=_import_vrm_update_addon_preferences,
109
+ default=True,
110
+ )
111
+ set_armature_bone_shape_to_default: BoolProperty( # type: ignore[valid-type]
112
+ name="Set an imported bone shape to default",
113
+ update=_import_vrm_update_addon_preferences,
114
+ default=True,
115
+ )
116
+ enable_mtoon_outline_preview: BoolProperty( # type: ignore[valid-type]
117
+ name="Enable MToon Outline Preview",
118
+ default=True,
119
+ )
120
+
121
+ def execute(self, context: Context) -> set[str]:
122
+ try:
123
+ filepath = Path(self.filepath)
124
+ if not filepath.is_file():
125
+ return {"CANCELLED"}
126
+
127
+ if self.use_addon_preferences:
128
+ copy_import_preferences(
129
+ source=get_preferences(context), destination=self
130
+ )
131
+
132
+ license_error = None
133
+ try:
134
+ return import_vrm(
135
+ filepath,
136
+ self,
137
+ context,
138
+ license_validation=True,
139
+ )
140
+ except LicenseConfirmationRequiredError as e:
141
+ license_error = e # Prevent traceback dump on another exception
142
+ except Exception:
143
+ show_error_dialog(
144
+ pgettext("Failed to import VRM."),
145
+ traceback.format_exc(),
146
+ )
147
+ raise
148
+
149
+ _logger.warning(license_error.description())
150
+
151
+ thumbnail_image_name = None
152
+ try:
153
+ thumbnail_image_name = parse_vrm_json(
154
+ filepath,
155
+ license_validation=False,
156
+ ).load_thumbnail_image(context)
157
+ except Exception:
158
+ show_error_dialog(
159
+ pgettext("Failed to import VRM."),
160
+ traceback.format_exc(),
161
+ )
162
+ raise
163
+
164
+ execution_context = "INVOKE_DEFAULT"
165
+ import_anyway = False
166
+ if environ.get("BLENDER_VRM_AUTOMATIC_LICENSE_CONFIRMATION") == "true":
167
+ execution_context = "EXEC_DEFAULT"
168
+ import_anyway = True
169
+
170
+ return ops.wm.vrm_license_warning(
171
+ execution_context,
172
+ import_anyway=import_anyway,
173
+ license_confirmations=license_error.license_confirmations(),
174
+ filepath=str(filepath),
175
+ thumbnail_image_name=thumbnail_image_name or "",
176
+ **create_import_preferences_dict(self),
177
+ )
178
+
179
+ def invoke(self, context: Context, event: Event) -> set[str]:
180
+ self.use_addon_preferences = True
181
+ copy_import_preferences(source=get_preferences(context), destination=self)
182
+
183
+ if "gltf" not in dir(bpy.ops.import_scene):
184
+ return ops.wm.vrm_gltf2_addon_disabled_warning("INVOKE_DEFAULT")
185
+ return ImportHelper.invoke(self, context, event)
186
+
187
+ def draw(self, _context: Context) -> None:
188
+ pass # Is needed to get panels available
189
+
190
+ if TYPE_CHECKING:
191
+ # This code is auto generated.
192
+ # To regenerate, run the `uv run tools/property_typing.py` command.
193
+ filter_glob: str # type: ignore[no-redef]
194
+ use_addon_preferences: bool # type: ignore[no-redef]
195
+ extract_textures_into_folder: bool # type: ignore[no-redef]
196
+ make_new_texture_folder: bool # type: ignore[no-redef]
197
+ set_shading_type_to_material_on_import: bool # type: ignore[no-redef]
198
+ set_view_transform_to_standard_on_import: bool # type: ignore[no-redef]
199
+ set_armature_display_to_wire: bool # type: ignore[no-redef]
200
+ set_armature_display_to_show_in_front: bool # type: ignore[no-redef]
201
+ set_armature_bone_shape_to_default: bool # type: ignore[no-redef]
202
+ enable_mtoon_outline_preview: bool # type: ignore[no-redef]
203
+
204
+
205
+ class VRM_PT_import_file_browser_tool_props(Panel):
206
+ bl_idname = "VRM_PT_import_file_browser_tool_props"
207
+ bl_space_type = "FILE_BROWSER"
208
+ bl_region_type = "TOOL_PROPS"
209
+ bl_parent_id = "FILE_PT_operator"
210
+ bl_label = ""
211
+ bl_options: ClassVar = {"HIDE_HEADER"}
212
+
213
+ @classmethod
214
+ def poll(cls, context: Context) -> bool:
215
+ space_data = context.space_data
216
+ if not isinstance(space_data, SpaceFileBrowser):
217
+ return False
218
+ return space_data.active_operator.bl_idname == "IMPORT_SCENE_OT_vrm"
219
+
220
+ def draw(self, context: Context) -> None:
221
+ space_data = context.space_data
222
+ if not isinstance(space_data, SpaceFileBrowser):
223
+ return
224
+
225
+ operator = space_data.active_operator
226
+ if not isinstance(operator, IMPORT_SCENE_OT_vrm):
227
+ return
228
+
229
+ layout = self.layout
230
+ draw_import_preferences_layout(operator, layout)
231
+
232
+
233
+ class VRM_PT_import_unsupported_blender_version_warning(Panel):
234
+ bl_idname = "VRM_PT_import_unsupported_blender_version_warning"
235
+ bl_space_type = "FILE_BROWSER"
236
+ bl_region_type = "TOOL_PROPS"
237
+ bl_parent_id = "FILE_PT_operator"
238
+ bl_label = ""
239
+ bl_options: ClassVar = {"HIDE_HEADER"}
240
+
241
+ @classmethod
242
+ def poll(cls, context: Context) -> bool:
243
+ space_data = context.space_data
244
+ if not isinstance(space_data, SpaceFileBrowser):
245
+ return False
246
+ if space_data.active_operator.bl_idname != "IMPORT_SCENE_OT_vrm":
247
+ return False
248
+ return bool(version.panel_warning_message())
249
+
250
+ def draw(self, _context: Context) -> None:
251
+ warning_message = version.panel_warning_message()
252
+ if warning_message is None:
253
+ return
254
+
255
+ box = self.layout.box()
256
+ warning_column = box.column(align=True)
257
+ for index, warning_line in enumerate(warning_message.splitlines()):
258
+ warning_column.label(
259
+ text=warning_line,
260
+ translate=False,
261
+ icon="NONE" if index else "ERROR",
262
+ )
263
+
264
+
265
+ class WM_OT_vrm_license_confirmation(Operator):
266
+ bl_label = "VRM License Confirmation"
267
+ bl_idname = "wm.vrm_license_warning"
268
+ bl_options: ClassVar = {"REGISTER"}
269
+
270
+ filepath: StringProperty( # type: ignore[valid-type]
271
+ subtype="FILE_PATH",
272
+ )
273
+
274
+ license_confirmations: CollectionProperty(type=LicenseConfirmation) # type: ignore[valid-type]
275
+ import_anyway: BoolProperty( # type: ignore[valid-type]
276
+ name="Import Anyway",
277
+ )
278
+ thumbnail_image_name: StringProperty() # type: ignore[valid-type]
279
+
280
+ extract_textures_into_folder: BoolProperty() # type: ignore[valid-type]
281
+ make_new_texture_folder: BoolProperty() # type: ignore[valid-type]
282
+ set_shading_type_to_material_on_import: BoolProperty() # type: ignore[valid-type]
283
+ set_view_transform_to_standard_on_import: BoolProperty() # type: ignore[valid-type]
284
+ set_armature_display_to_wire: BoolProperty() # type: ignore[valid-type]
285
+ set_armature_display_to_show_in_front: BoolProperty() # type: ignore[valid-type]
286
+ set_armature_bone_shape_to_default: BoolProperty() # type: ignore[valid-type]
287
+ enable_mtoon_outline_preview: BoolProperty() # type: ignore[valid-type]
288
+
289
+ def remove_thumbnail_image(self, context: Context) -> None:
290
+ thumbnail_image = context.blend_data.images.get(self.thumbnail_image_name)
291
+ if not thumbnail_image:
292
+ return
293
+
294
+ if thumbnail_image.users > 0:
295
+ return
296
+
297
+ context.blend_data.images.remove(thumbnail_image)
298
+
299
+ def execute(self, context: Context) -> set[str]:
300
+ self.remove_thumbnail_image(context)
301
+ try:
302
+ filepath = Path(self.filepath)
303
+ if not filepath.is_file():
304
+ return {"CANCELLED"}
305
+ if not self.import_anyway:
306
+ return {"CANCELLED"}
307
+ return import_vrm(
308
+ filepath,
309
+ self,
310
+ context,
311
+ license_validation=False,
312
+ )
313
+ except Exception:
314
+ show_error_dialog(
315
+ pgettext("Failed to import VRM."),
316
+ traceback.format_exc(),
317
+ )
318
+ raise
319
+
320
+ def cancel(self, context: Context) -> None:
321
+ self.remove_thumbnail_image(context)
322
+
323
+ def invoke(self, context: Context, _event: Event) -> set[str]:
324
+ return context.window_manager.invoke_props_dialog(self, width=600)
325
+
326
+ def draw(self, context: Context) -> None:
327
+ layout = self.layout
328
+ layout.label(text=self.filepath, translate=False)
329
+
330
+ thumbnail_image = context.blend_data.images.get(self.thumbnail_image_name)
331
+ if thumbnail_image:
332
+ icon_id = layout.icon(thumbnail_image)
333
+ layout.template_icon(icon_id, scale=5)
334
+
335
+ for license_confirmation in self.license_confirmations:
336
+ box = layout.box()
337
+ for line in license_confirmation.message.split("\n"):
338
+ box.label(text=line, translate=False, icon="INFO")
339
+ if license_confirmation.json_key:
340
+ box.label(
341
+ text=pgettext("For more information please check following URL.")
342
+ )
343
+ if VRM_OT_open_url_in_web_browser.supported(license_confirmation.url):
344
+ split = box.split(factor=0.85, align=True)
345
+ split.prop(
346
+ license_confirmation,
347
+ "url",
348
+ text=license_confirmation.json_key,
349
+ translate=False,
350
+ )
351
+ op = layout_operator(split, VRM_OT_open_url_in_web_browser)
352
+ op.url = license_confirmation.url
353
+ else:
354
+ box.prop(
355
+ license_confirmation,
356
+ "url",
357
+ text=license_confirmation.json_key,
358
+ translate=False,
359
+ )
360
+
361
+ layout.prop(self, "import_anyway")
362
+
363
+ if TYPE_CHECKING:
364
+ # This code is auto generated.
365
+ # To regenerate, run the `uv run tools/property_typing.py` command.
366
+ filepath: str # type: ignore[no-redef]
367
+ license_confirmations: CollectionPropertyProtocol[ # type: ignore[no-redef]
368
+ LicenseConfirmation
369
+ ]
370
+ import_anyway: bool # type: ignore[no-redef]
371
+ thumbnail_image_name: str # type: ignore[no-redef]
372
+ extract_textures_into_folder: bool # type: ignore[no-redef]
373
+ make_new_texture_folder: bool # type: ignore[no-redef]
374
+ set_shading_type_to_material_on_import: bool # type: ignore[no-redef]
375
+ set_view_transform_to_standard_on_import: bool # type: ignore[no-redef]
376
+ set_armature_display_to_wire: bool # type: ignore[no-redef]
377
+ set_armature_display_to_show_in_front: bool # type: ignore[no-redef]
378
+ set_armature_bone_shape_to_default: bool # type: ignore[no-redef]
379
+ enable_mtoon_outline_preview: bool # type: ignore[no-redef]
380
+
381
+
382
+ def import_vrm(
383
+ filepath: Path,
384
+ preferences: ImportPreferencesProtocol,
385
+ context: Context,
386
+ *,
387
+ license_validation: bool,
388
+ ) -> set[str]:
389
+ parse_result = parse_vrm_json(filepath, license_validation=license_validation)
390
+ if parse_result.spec_version_number >= (1,):
391
+ vrm_importer: AbstractBaseVrmImporter = Vrm1Importer(
392
+ context,
393
+ parse_result,
394
+ preferences,
395
+ )
396
+ else:
397
+ vrm_importer = Vrm0Importer(
398
+ context,
399
+ parse_result,
400
+ preferences,
401
+ )
402
+
403
+ vrm_importer.import_vrm()
404
+
405
+ return {"FINISHED"}
406
+
407
+
408
+ def menu_import(
409
+ menu_op: Operator, _context: Context
410
+ ) -> None: # Same as test/blender_io.py for now
411
+ vrm_import_op = layout_operator(
412
+ menu_op.layout, IMPORT_SCENE_OT_vrm, text="VRM (.vrm)"
413
+ )
414
+ vrm_import_op.use_addon_preferences = True
415
+
416
+ vrma_import_op = layout_operator(
417
+ menu_op.layout, IMPORT_SCENE_OT_vrma, text="VRM Animation (.vrma)"
418
+ )
419
+ vrma_import_op.armature_object_name = ""
420
+
421
+
422
+ class IMPORT_SCENE_OT_vrma(Operator, ImportHelper):
423
+ bl_idname = "import_scene.vrma"
424
+ bl_label = "Open"
425
+ bl_description = "Import VRM Animation"
426
+ bl_options: ClassVar = {"REGISTER", "UNDO"}
427
+
428
+ filename_ext = ".vrma"
429
+ filter_glob: StringProperty( # type: ignore[valid-type]
430
+ default="*.vrma",
431
+ options={"HIDDEN"},
432
+ )
433
+
434
+ armature_object_name: StringProperty( # type: ignore[valid-type]
435
+ options={"HIDDEN"},
436
+ )
437
+
438
+ def execute(self, context: Context) -> set[str]:
439
+ try:
440
+ errors = WM_OT_vrma_import_prerequisite.detect_errors(
441
+ context, self.armature_object_name
442
+ )
443
+ if errors:
444
+ for error in errors:
445
+ _logger.error(error)
446
+ return {"CANCELLED"}
447
+
448
+ filepath = Path(self.filepath)
449
+ if not filepath.is_file():
450
+ return {"CANCELLED"}
451
+
452
+ armature = None
453
+ if self.armature_object_name:
454
+ armature = context.blend_data.objects.get(self.armature_object_name)
455
+ if not armature:
456
+ return {"CANCELLED"}
457
+
458
+ if not armature:
459
+ armature = search.current_armature(context)
460
+
461
+ if not armature:
462
+ added = ops.icyp.make_basic_armature()
463
+ if added != {"FINISHED"}:
464
+ return added
465
+ armature = search.current_armature(context)
466
+ if not armature:
467
+ return {"CANCELLED"}
468
+ armature_data = armature.data
469
+ if not isinstance(armature_data, Armature):
470
+ return {"CANCELLED"}
471
+ ext = get_armature_extension(armature_data)
472
+ ext.spec_version = ext.SPEC_VERSION_VRM1
473
+
474
+ return VrmAnimationImporter.execute(context, filepath, armature)
475
+ except Exception:
476
+ show_error_dialog(
477
+ pgettext("Failed to import VRM Animation."),
478
+ traceback.format_exc(),
479
+ )
480
+ raise
481
+
482
+ def invoke(self, context: Context, event: Event) -> set[str]:
483
+ if WM_OT_vrma_import_prerequisite.detect_errors(
484
+ context, self.armature_object_name
485
+ ):
486
+ return ops.wm.vrma_import_prerequisite(
487
+ "INVOKE_DEFAULT",
488
+ armature_object_name=self.armature_object_name,
489
+ )
490
+ return ImportHelper.invoke(self, context, event)
491
+
492
+ if TYPE_CHECKING:
493
+ # This code is auto generated.
494
+ # To regenerate, run the `uv run tools/property_typing.py` command.
495
+ filter_glob: str # type: ignore[no-redef]
496
+ armature_object_name: str # type: ignore[no-redef]
497
+
498
+
499
+ class WM_OT_vrma_import_prerequisite(Operator):
500
+ bl_label = "VRM Animation Import Prerequisite"
501
+ bl_idname = "wm.vrma_import_prerequisite"
502
+ bl_options: ClassVar = {"REGISTER", "UNDO"}
503
+
504
+ armature_object_name: StringProperty( # type: ignore[valid-type]
505
+ options={"HIDDEN"},
506
+ )
507
+ armature_object_name_candidates: CollectionProperty( # type: ignore[valid-type]
508
+ type=StringPropertyGroup,
509
+ options={"HIDDEN"},
510
+ )
511
+
512
+ @staticmethod
513
+ def detect_errors(context: Context, armature_object_name: str) -> list[str]:
514
+ error_messages: list[str] = []
515
+
516
+ if not armature_object_name:
517
+ armature = search.current_armature(context)
518
+ else:
519
+ armature = context.blend_data.objects.get(armature_object_name)
520
+
521
+ if not armature:
522
+ return error_messages
523
+
524
+ armature_data = armature.data
525
+ if not isinstance(armature_data, Armature):
526
+ return error_messages
527
+
528
+ ext = get_armature_extension(armature_data)
529
+ if get_armature_extension(armature_data).is_vrm1():
530
+ humanoid = ext.vrm1.humanoid
531
+ if not humanoid.human_bones.bones_are_correctly_assigned():
532
+ error_messages.append(pgettext("Please assign required human bones"))
533
+ else:
534
+ error_messages.append(pgettext("Please set the version of VRM to 1.0"))
535
+
536
+ return error_messages
537
+
538
+ def execute(self, _context: Context) -> set[str]:
539
+ return ops.import_scene.vrma(
540
+ "INVOKE_DEFAULT", armature_object_name=self.armature_object_name
541
+ )
542
+
543
+ def invoke(self, context: Context, _event: Event) -> set[str]:
544
+ if not self.armature_object_name:
545
+ armature_object = search.current_armature(context)
546
+ if armature_object:
547
+ self.armature_object_name = armature_object.name
548
+ self.armature_object_name_candidates.clear()
549
+ for obj in context.blend_data.objects:
550
+ if obj.type != "ARMATURE":
551
+ continue
552
+ candidate = self.armature_object_name_candidates.add()
553
+ candidate.value = obj.name
554
+ return context.window_manager.invoke_props_dialog(self, width=800)
555
+
556
+ def draw(self, context: Context) -> None:
557
+ layout = self.layout
558
+
559
+ layout.label(
560
+ text="VRM Animation import requires a VRM 1.0 armature",
561
+ icon="INFO",
562
+ )
563
+
564
+ error_messages = WM_OT_vrma_import_prerequisite.detect_errors(
565
+ context, self.armature_object_name
566
+ )
567
+
568
+ layout.prop_search(
569
+ self,
570
+ "armature_object_name",
571
+ self,
572
+ "armature_object_name_candidates",
573
+ icon="OUTLINER_OB_ARMATURE",
574
+ text="Armature to be animated",
575
+ )
576
+
577
+ if error_messages:
578
+ error_column = layout.box().column(align=True)
579
+ for error_message in error_messages:
580
+ error_column.label(text=error_message, icon="ERROR", translate=False)
581
+
582
+ open_op = layout_operator(
583
+ layout,
584
+ VRM_OT_open_url_in_web_browser,
585
+ icon="URL",
586
+ text="Open help in a Web Browser",
587
+ )
588
+ open_op.url = pgettext("https://vrm-addon-for-blender.info/en-us/animation/")
589
+
590
+ if TYPE_CHECKING:
591
+ # This code is auto generated.
592
+ # To regenerate, run the `uv run tools/property_typing.py` command.
593
+ armature_object_name: str # type: ignore[no-redef]
594
+ armature_object_name_candidates: CollectionPropertyProtocol[ # type: ignore[no-redef]
595
+ StringPropertyGroup
596
+ ]
597
+
598
+
599
+ class VRM_OT_import_vrm_via_file_handler(Operator):
600
+ bl_idname = "vrm.import_vrm_via_file_handler"
601
+ bl_label = "Import VRM via FileHandler"
602
+
603
+ filepath: StringProperty( # type: ignore[valid-type]
604
+ subtype="FILE_PATH",
605
+ options={"SKIP_SAVE"},
606
+ )
607
+
608
+ @classmethod
609
+ def poll(cls, _context: Context) -> bool:
610
+ return True
611
+
612
+ def execute(self, _context: Context) -> set[str]:
613
+ return ops.import_scene.vrm(filepath=self.filepath, use_addon_preferences=True)
614
+
615
+ def invoke(self, context: Context, _event: Event) -> set[str]:
616
+ return self.execute(context)
617
+
618
+ if TYPE_CHECKING:
619
+ # This code is auto generated.
620
+ # To regenerate, run the `uv run tools/property_typing.py` command.
621
+ filepath: str # type: ignore[no-redef]
622
+
623
+
624
+ class VRM_OT_import_vrma_via_file_handler(Operator):
625
+ bl_idname = "vrm.import_vrma_via_file_handler"
626
+ bl_label = "Import VRMA via FileHandler"
627
+
628
+ filepath: StringProperty( # type: ignore[valid-type]
629
+ subtype="FILE_PATH",
630
+ options={"SKIP_SAVE"},
631
+ )
632
+
633
+ @classmethod
634
+ def poll(cls, _context: Context) -> bool:
635
+ return True
636
+
637
+ def execute(self, _context: Context) -> set[str]:
638
+ return ops.import_scene.vrma(filepath=self.filepath)
639
+
640
+ def invoke(self, context: Context, _event: Event) -> set[str]:
641
+ return self.execute(context)
642
+
643
+ if TYPE_CHECKING:
644
+ # This code is auto generated.
645
+ # To regenerate, run the `uv run tools/property_typing.py` command.
646
+ filepath: str # type: ignore[no-redef]