Add slicer to layer when first import

This commit is contained in:
2025-04-11 16:10:13 +08:00
parent 35e405acd8
commit 1c49fbb813
4 changed files with 48 additions and 31 deletions

View File

@@ -95,7 +95,7 @@ def add_layers(layers: list[Layer],
if len(output_node.inputs[0].links) == 0: if len(output_node.inputs[0].links) == 0:
node_group.links.new(fetch_node.outputs[0], node_group.links.new(fetch_node.outputs[0],
output_node.inputs[0]) output_node.inputs[0])
move_node_to_node(fetch_node, output_node, (-600, 0)) move_node_to_node(fetch_node, output_node, (-900, 0))
else: else:
move_node_to_node(fetch_node, output_node, (0, -100 * (i+1))) move_node_to_node(fetch_node, output_node, (0, -100 * (i+1)))

View File

@@ -5,10 +5,12 @@ import threading
import numpy as np import numpy as np
from pathlib import Path from pathlib import Path
from ..exceptions import CancelledByUser from ..exceptions import CancelledByUser
from ..props import BIOXELNODES_Series from ..props import BIOXELNODES_Series
from ..bioxelutils.node import add_node_to_graph
from ..bioxelutils.common import (get_all_layer_objs, get_container_obj, from ..bioxelutils.common import (get_all_layer_objs, get_container_obj,
get_layer_obj, is_incompatible) get_layer_obj, get_nodes_by_type, get_output_node, is_incompatible, move_node_to_node)
from ..bioxelutils.container import (Container, from ..bioxelutils.container import (Container,
add_layers, add_layers,
container_to_obj) container_to_obj)
@@ -16,7 +18,7 @@ from ..bioxel.layer import Layer
from ..bioxel.parse import (DICOM_EXTS, SUPPORT_EXTS, from ..bioxel.parse import (DICOM_EXTS, SUPPORT_EXTS,
get_ext, parse_volumetric_data) get_ext, parse_volumetric_data)
from ..utils import (get_cache_dir, from ..utils import (get_cache_dir, get_use_link,
progress_update, progress_bar, progress_update, progress_bar,
select_object) select_object)
@@ -666,7 +668,7 @@ class ImportVolumetricDataDialog(bpy.types.Operator):
# Gamma Correct # Gamma Correct
# data = data ** 2.2 # data = data ** 2.2
name = self.layer_name or "Color" name = self.layer_name or "Color"
if data.shape[4] == 1: if data.shape[4] == 1:
data = np.repeat(data, repeats=3, axis=4) data = np.repeat(data, repeats=3, axis=4)
@@ -854,9 +856,46 @@ class ImportVolumetricDataDialog(bpy.types.Operator):
# Change render setting for better result # Change render setting for better result
if is_first_import: if is_first_import:
bpy.ops.bioxelnodes.render_setting_preset('EXEC_DEFAULT', try:
preset="balance")
bpy.context.scene.render.engine = 'CYCLES' node_group = container_obj.modifiers[0].node_group
layer_node = get_nodes_by_type(
node_group, "BioxelNodes_FetchLayer")[0]
center_node = add_node_to_graph("ReCenter",
node_group,
use_link=get_use_link())
output_node = get_output_node(node_group)
node_group.links.new(layer_node.outputs[0],
center_node.inputs[0])
node_group.links.new(center_node.outputs[0],
output_node.inputs[0])
move_node_to_node(center_node, layer_node, (300, 0))
bpy.ops.bioxelnodes.add_slicer('EXEC_DEFAULT')
except:
self.report({"WARNING"}, "Fail to create slicer.")
try:
bpy.ops.bioxelnodes.render_setting_preset('EXEC_DEFAULT',
preset="balance")
bpy.ops.bioxelnodes.add_eevee_env('EXEC_DEFAULT')
bpy.context.scene.eevee.use_taa_reprojection = False
bpy.context.scene.render.engine = 'BLENDER_EEVEE_NEXT'
view_3d = None
if context.area.type == 'VIEW_3D':
view_3d = context.area
else:
for area in context.screen.areas:
if area.type == 'VIEW_3D':
view_3d = area
break
if view_3d:
view_3d.spaces[0].shading.type = 'RENDERED'
except:
self.report({"WARNING"}, "Fail to change render setting.")
self.report({"INFO"}, "Successfully Imported") self.report({"INFO"}, "Successfully Imported")
return {'FINISHED'} return {'FINISHED'}

View File

@@ -296,28 +296,6 @@ class AddEeveeEnv(bpy.types.Operator):
directory=f"{str(LATEST_NODE_LIB_PATH)}/Object", directory=f"{str(LATEST_NODE_LIB_PATH)}/Object",
filename="EeveeEnv" filename="EeveeEnv"
) )
# bpy.ops.object.light_add(
# type='POINT', align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
# light_obj = bpy.context.active_object
# light_obj.name = "EeveeEnv"
# light_obj.data.shadow_soft_size = 100
# light_obj.data.energy = 1e+06
# light_obj.data.color = (0.1, 0.1, 0.1)
# light_obj.data.use_shadow = False
# light_obj.data.diffuse_factor = 0
# light_obj.data.specular_factor = 0
# light_obj.data.transmission_factor = 0
# light_obj.hide_select = True
# light_obj.lock_location[0] = True
# light_obj.lock_location[1] = True
# light_obj.lock_location[2] = True
# light_obj.lock_rotation[0] = True
# light_obj.lock_rotation[1] = True
# light_obj.lock_rotation[2] = True
# light_obj.lock_scale[0] = True
# light_obj.lock_scale[1] = True
# light_obj.lock_scale[2] = True
bpy.context.scene.eevee.use_shadows = True bpy.context.scene.eevee.use_shadows = True
bpy.context.scene.eevee.use_volumetric_shadows = True bpy.context.scene.eevee.use_volumetric_shadows = True