Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_scene_gltf2/blender/imp')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_animation_node.py5
-rw-r--r--io_scene_gltf2/blender/imp/gltf2_blender_animation_weight.py6
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_camera.py6
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_image.py6
-rw-r--r--io_scene_gltf2/blender/imp/gltf2_blender_light.py6
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_material.py5
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_mesh.py6
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_node.py16
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_scene.py8
-rw-r--r--io_scene_gltf2/blender/imp/gltf2_blender_texture.py6
10 files changed, 64 insertions, 6 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
index 642515aa..03f8592c 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
@@ -18,6 +18,7 @@ from mathutils import Vector
from ...io.imp.gltf2_io_binary import BinaryData
from .gltf2_blender_animation_utils import make_fcurve
from .gltf2_blender_vnode import VNode
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderNodeAnim():
@@ -46,6 +47,8 @@ class BlenderNodeAnim():
vnode = gltf.vnodes[node_idx]
path = channel.target.path
+ import_user_extensions('gather_import_animation_channel_before_hook', gltf, animation, vnode, path, channel)
+
action = BlenderNodeAnim.get_or_create_action(gltf, node_idx, animation.track_name)
keys = BinaryData.get_data_from_accessor(gltf, animation.samplers[channel.sampler].input)
@@ -152,6 +155,8 @@ class BlenderNodeAnim():
interpolation=animation.samplers[channel.sampler].interpolation,
)
+ import_user_extensions('gather_import_animation_channel_after_hook', gltf, animation, vnode, path, channel, action)
+
@staticmethod
def get_or_create_action(gltf, node_idx, anim_name):
vnode = gltf.vnodes[node_idx]
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_weight.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_weight.py
index 19723ed9..3b864d6b 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_weight.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_weight.py
@@ -16,6 +16,7 @@ import bpy
from ...io.imp.gltf2_io_binary import BinaryData
from .gltf2_blender_animation_utils import make_fcurve
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderWeightAnim():
@@ -29,6 +30,9 @@ class BlenderWeightAnim():
vnode = gltf.vnodes[vnode_id]
node_idx = vnode.mesh_node_idx
+
+ import_user_extensions('gather_import_animation_weight_before_hook', gltf, vnode, gltf.data.animations[anim_idx])
+
if node_idx is None:
return
@@ -90,3 +94,5 @@ class BlenderWeightAnim():
max_weight = max(coords[1:2])
if min_weight < kb.slider_min: kb.slider_min = min_weight
if max_weight > kb.slider_max: kb.slider_max = max_weight
+
+ import_user_extensions('gather_import_animation_weight_after_hook', gltf, vnode, animation)
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
index cc73a690..e5f6e3d1 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
@@ -14,6 +14,7 @@
import bpy
from ..com.gltf2_blender_extras import set_extras
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderCamera():
@@ -22,10 +23,12 @@ class BlenderCamera():
raise RuntimeError("%s should not be instantiated" % cls)
@staticmethod
- def create(gltf, camera_id):
+ def create(gltf, vnode, camera_id):
"""Camera creation."""
pycamera = gltf.data.cameras[camera_id]
+ import_user_extensions('gather_import_camera_before_hook', gltf, vnode, pycamera)
+
if not pycamera.name:
pycamera.name = "Camera"
@@ -55,5 +58,4 @@ class BlenderCamera():
# Infinite projection
cam.clip_end = 1e12 # some big number
-
return cam
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_image.py b/io_scene_gltf2/blender/imp/gltf2_blender_image.py
index 3acf1786..0df6dc0e 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_image.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_image.py
@@ -20,6 +20,7 @@ import urllib.parse
import re
from ...io.imp.gltf2_io_binary import BinaryData
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
# Note that Image is not a glTF2.0 object
@@ -32,6 +33,9 @@ class BlenderImage():
def create(gltf, img_idx):
"""Image creation."""
img = gltf.data.images[img_idx]
+
+ import_user_extensions('gather_import_image_before_hook', gltf, img)
+
img_name = img.name
if img.blender_image_name is not None:
@@ -90,6 +94,8 @@ class BlenderImage():
if not is_placeholder and needs_pack:
blender_image.pack()
+ import_user_extensions('gather_import_image_after_hook', gltf, img, blender_image)
+
def _placeholder_image(name, path):
image = bpy.data.images.new(name, 128, 128)
# allow the path to be resolved later
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_light.py b/io_scene_gltf2/blender/imp/gltf2_blender_light.py
index 71990eb3..9e6b8a96 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_light.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_light.py
@@ -16,6 +16,7 @@ import bpy
from math import pi
from ..com.gltf2_blender_extras import set_extras
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderLight():
@@ -24,9 +25,12 @@ class BlenderLight():
raise RuntimeError("%s should not be instantiated" % cls)
@staticmethod
- def create(gltf, light_id):
+ def create(gltf, vnode, light_id):
"""Light creation."""
pylight = gltf.data.extensions['KHR_lights_punctual']['lights'][light_id]
+
+ import_user_extensions('gather_import_light_before_hook', gltf, vnode, pylight)
+
if pylight['type'] == "directional":
light = BlenderLight.create_directional(gltf, light_id)
elif pylight['type'] == "point":
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_material.py b/io_scene_gltf2/blender/imp/gltf2_blender_material.py
index 077f5af6..1a5be06f 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_material.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_material.py
@@ -18,6 +18,7 @@ from ..com.gltf2_blender_extras import set_extras
from .gltf2_blender_pbrMetallicRoughness import MaterialHelper, pbr_metallic_roughness
from .gltf2_blender_KHR_materials_pbrSpecularGlossiness import pbr_specular_glossiness
from .gltf2_blender_KHR_materials_unlit import unlit
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderMaterial():
@@ -30,6 +31,8 @@ class BlenderMaterial():
"""Material creation."""
pymaterial = gltf.data.materials[material_idx]
+ import_user_extensions('gather_import_material_before_hook', gltf, pymaterial, vertex_color)
+
name = pymaterial.name
if name is None:
name = "Material_" + str(material_idx)
@@ -56,6 +59,8 @@ class BlenderMaterial():
else:
pbr_metallic_roughness(mh)
+ import_user_extensions('gather_import_material_after_hook', gltf, pymaterial, vertex_color, mat)
+
@staticmethod
def set_double_sided(pymaterial, mat):
mat.use_backface_culling = (pymaterial.double_sided != True)
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
index bbff340c..41dd4d03 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
@@ -21,6 +21,7 @@ from ..com.gltf2_blender_extras import set_extras
from .gltf2_blender_material import BlenderMaterial
from ...io.com.gltf2_io_debug import print_console
from .gltf2_io_draco_compression_extension import decode_primitive
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderMesh():
@@ -41,6 +42,9 @@ COLOR_MAX = 8
def create_mesh(gltf, mesh_idx, skin_idx):
pymesh = gltf.data.meshes[mesh_idx]
+
+ import_user_extensions('gather_import_mesh_before_hook', gltf, pymesh)
+
name = pymesh.name or 'Mesh_%d' % mesh_idx
mesh = bpy.data.meshes.new(name)
@@ -56,6 +60,8 @@ def create_mesh(gltf, mesh_idx, skin_idx):
if tmp_ob:
bpy.data.objects.remove(tmp_ob)
+ import_user_extensions('gather_import_mesh_after_hook', gltf, pymesh, mesh)
+
return mesh
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/io_scene_gltf2/blender/imp/gltf2_blender_node.py
index ed164a1e..2fdbcfa5 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_node.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_node.py
@@ -19,6 +19,7 @@ from .gltf2_blender_mesh import BlenderMesh
from .gltf2_blender_camera import BlenderCamera
from .gltf2_blender_light import BlenderLight
from .gltf2_blender_vnode import VNode
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderNode():
"""Blender Node."""
@@ -35,7 +36,10 @@ class BlenderNode():
gltf.log.critical("Node %d of %d (id %s)", gltf.display_current_node, len(gltf.vnodes), vnode_id)
if vnode.type == VNode.Object:
- BlenderNode.create_object(gltf, vnode_id)
+ gltf_node = gltf.data.nodes[vnode_id] if isinstance(vnode_id, int) else None
+ import_user_extensions('gather_import_node_before_hook', gltf, vnode, gltf_node)
+ obj = BlenderNode.create_object(gltf, vnode_id)
+ import_user_extensions('gather_import_node_after_hook', gltf, vnode, gltf_node, obj)
if vnode.is_arma:
BlenderNode.create_bones(gltf, vnode_id)
@@ -59,16 +63,22 @@ class BlenderNode():
elif vnode.camera_node_idx is not None:
pynode = gltf.data.nodes[vnode.camera_node_idx]
- cam = BlenderCamera.create(gltf, pynode.camera)
+ cam = BlenderCamera.create(gltf, vnode, pynode.camera)
name = vnode.name or cam.name
obj = bpy.data.objects.new(name, cam)
+ # Since we create the actual Blender object after the create call, we call the hook here
+ import_user_extensions('gather_import_camera_after_hook', gltf, vnode, obj, cam)
+
elif vnode.light_node_idx is not None:
pynode = gltf.data.nodes[vnode.light_node_idx]
- light = BlenderLight.create(gltf, pynode.extensions['KHR_lights_punctual']['light'])
+ light = BlenderLight.create(gltf, vnode, pynode.extensions['KHR_lights_punctual']['light'])
name = vnode.name or light.name
obj = bpy.data.objects.new(name, light)
+ # Since we create the actual Blender object after the create call, we call the hook here
+ import_user_extensions('gather_import_light_after_hook', gltf, vnode, obj, light)
+
elif vnode.is_arma:
armature = bpy.data.armatures.new(vnode.arma_name)
name = vnode.name or armature.name
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
index 05520228..57c53527 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
@@ -18,6 +18,7 @@ from .gltf2_blender_node import BlenderNode
from .gltf2_blender_animation import BlenderAnimation
from .gltf2_blender_vnode import VNode, compute_vnodes
from ..com.gltf2_blender_extras import set_extras
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
class BlenderScene():
@@ -36,6 +37,7 @@ class BlenderScene():
scene.render.engine = "BLENDER_EEVEE"
if gltf.data.scene is not None:
+ import_user_extensions('gather_import_scene_before_hook', gltf, gltf.data.scenes[gltf.data.scene], scene)
pyscene = gltf.data.scenes[gltf.data.scene]
set_extras(scene, pyscene.extras)
@@ -44,8 +46,14 @@ class BlenderScene():
gltf.display_current_node = 0 # for debugging
BlenderNode.create_vnode(gltf, 'root')
+ # User extensions before scene creation
+ import_user_extensions('gather_import_scene_after_nodes_hook', gltf, gltf.data.scenes[gltf.data.scene], scene)
+
+ # User extensions after scene creation
BlenderScene.create_animations(gltf)
+ import_user_extensions('gather_import_scene_after_animation_hook', gltf, gltf.data.scenes[gltf.data.scene], scene)
+
if bpy.context.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
BlenderScene.select_imported_objects(gltf)
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_texture.py b/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
index ddeb5bfc..2a41c28e 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_texture.py
@@ -18,6 +18,7 @@ from .gltf2_blender_image import BlenderImage
from ..com.gltf2_blender_conversion import texture_transform_gltf_to_blender
from io_scene_gltf2.io.com.gltf2_io import Sampler
from io_scene_gltf2.io.com.gltf2_io_constants import TextureFilter, TextureWrap
+from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions
def texture(
mh,
@@ -31,6 +32,9 @@ def texture(
"""Creates nodes for a TextureInfo and hooks up the color/alpha outputs."""
x, y = location
pytexture = mh.gltf.data.textures[tex_info.index]
+
+ import_user_extensions('gather_import_texture_before_hook', mh.gltf, pytexture, mh, tex_info, location, label, color_socket, alpha_socket, is_data)
+
if pytexture.sampler is not None:
pysampler = mh.gltf.data.samplers[pytexture.sampler]
else:
@@ -166,6 +170,8 @@ def texture(
# Outputs
mh.node_tree.links.new(uv_socket, uv_map.outputs[0])
+ import_user_extensions('gather_import_texture_after_hook', mh.gltf, pytexture, mh.node_tree, mh, tex_info, location, label, color_socket, alpha_socket, is_data)
+
def set_filtering(tex_img, pysampler):
"""Set the filtering/interpolation on an Image Texture from the glTf sampler."""
minf = pysampler.min_filter