Compare commits
38 Commits
v0.1.0-bet
...
v0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fefc9285e1 | ||
| 322b84cc70 | |||
| f3be5d8660 | |||
| 470cdab4f6 | |||
|
|
b35c816c25 | ||
| 0e2d6fe1a2 | |||
|
|
e0c46e95f8 | ||
| 2528d984ad | |||
|
|
56606fd721 | ||
| f21f7d6357 | |||
| fa031e63f8 | |||
|
|
e929013183 | ||
| d380cf7036 | |||
| 05a61527e7 | |||
|
|
2c80c9ed81 | ||
|
|
8e8b176e11 | ||
| c1886f95f8 | |||
| 5e8d12c564 | |||
| 1990a16972 | |||
| eeca79e681 | |||
|
|
8b45de4a4d | ||
| 2c3d9e5791 | |||
|
|
32b69575b1 | ||
| d663bfd290 | |||
|
|
a1aa776725 | ||
| 6b18b4e9fa | |||
| a579b24f9a | |||
|
|
8b3ab61467 | ||
|
|
084031c496 | ||
| 15b24b61b5 | |||
|
|
81dae0631a | ||
|
|
38d2e52c93 | ||
| cf6ccb1743 | |||
| f889b61494 | |||
|
|
436288df7c | ||
|
|
7967f144f1 | ||
|
|
ba4c6c1dee | ||
| ca9df9065e |
37
.github/workflows/upload-assets.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
# id: draft_release
|
||||
# uses: cardinalby/git-get-release-action@1.2.4
|
||||
# with:
|
||||
# releaseName: Draft
|
||||
# releaseName: Upload
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
@@ -70,5 +70,38 @@ jobs:
|
||||
with:
|
||||
upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||
asset_path: ./package.zip
|
||||
asset_name: BioxelNodes_${{ needs.draft_release.outputs.version }}.zip
|
||||
asset_name: BioxelNodes_Addon_${{ needs.draft_release.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
upload_blender_extension:
|
||||
name: Upload Blender Extension
|
||||
needs: draft_release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: 'true'
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
- name: Zip Extension
|
||||
run: |
|
||||
pip download SimpleITK --dest bioxelnodes/wheels --only-binary=:all: --python-version=3.11 --platform=macosx_11_0_arm64
|
||||
pip download SimpleITK --dest bioxelnodes/wheels --only-binary=:all: --python-version=3.11 --platform=win_amd64
|
||||
rm -r bioxelnodes/externalpackage
|
||||
cp extension/__init__.py bioxelnodes/__init__.py
|
||||
cp extension/preferences.py bioxelnodes/preferences.py
|
||||
cp extension/blender_manifest.toml bioxelnodes/blender_manifest.toml
|
||||
zip -r package.zip bioxelnodes
|
||||
- name: Upload Release Asset
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||
asset_path: ./package.zip
|
||||
asset_name: BioxelNodes_Extension_${{ needs.draft_release.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
11
.prettierrc
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.md",
|
||||
"options": {
|
||||
"tabWidth": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 OmooLab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
59
README.md
@@ -1,3 +1,58 @@
|
||||
# BioxelNodes
|
||||
BioxelNodes is a blender add-on for better volume data visualization with cycles.
|
||||
[中文文档](https://uj6xfhbzp0.feishu.cn/wiki/Qx3VwHuNPimeI8kr6nDcvl1DnHf?from=from_copylink)
|
||||
|
||||
# Bioxel Nodes
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
Bioxel Nodes is a Blender add-on for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes | Cycles to process and render volumetric data.
|
||||
|
||||
## About
|
||||
|
||||
Before us, there have been many tutorials and add-ons for importing volumetric data into Blender. However, we found that there were many details that were not addressed in place, some scientific facts were ignored, and the volume rendering was not pretty enough. With Bioxel Nodes, you can easily import the volumetric data into Blender, and more importantly, it can quickly make a beautiful realistic rendering of it.
|
||||
|
||||
Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail:
|
||||
|
||||

|
||||
|
||||
The "Bioxel" in "Bioxel Nodes", is a combination of the words "Bio-" and "Voxel". Bioxel is a voxel that stores biological data. We are developing a toolkit around Bioxel for better biological data visualization. but before its release, we made this Blender version of bioxels toolkit first, in order to let more people to have fun with volumetric data. [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started)
|
||||
|
||||
## Supported Format
|
||||
|
||||
| Format | EXT | Test |
|
||||
| ------ | ---------------------------------------- | ------- |
|
||||
| DICOM | .dcm, .DICOM | ✅ pass |
|
||||
| BMP | .bmp, .BMP | ✅ pass |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG | ✅ pass |
|
||||
| PNG | .png, .PNG | ✅ pass |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF | ✅ pass |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz | ✅ pass |
|
||||
| Nrrd | .nrrd, .nhdr | ✅ pass |
|
||||
| Meta | .mha, .mhd | yet |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 | ✅ pass |
|
||||
| VTK | .vtk | yet |
|
||||
| BioRad | .PIC, .pic | yet |
|
||||
| Gipl | .gipl, .gipl.gz | yet |
|
||||
| LSM | .lsm, .LSM | yet |
|
||||
| MINC | .mnc, .MNC | yet |
|
||||
| MRC | .mrc, .rec | yet |
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- Sections cannot be generated (will be supported soon)
|
||||
- Time sequence volume not supported (will be supported soon)
|
||||
|
||||
## To Upgrade Add-on
|
||||
|
||||
To upgrade from an older version of the add-on to the latest, you need to do the following:
|
||||
|
||||
1. Remove the old version of Bioxel Nodes at Preferences > Add-ons
|
||||
2. Add the new version and restart Blender.
|
||||
|
||||
It is not support editing the same blender file across add-on versions. In order to make sure that the previous file works properly. You need to save the staged data before upgrading ( read the last section of [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started/#share-your-file) ).
|
||||
|
||||
But even then, there is still no guarantee that the new version of the add-on will work on the old blender file. Therefore, it is highly recommended to open a new blender file to start the creating, not based on the old one.
|
||||
|
||||
Alternatively, objects from the old file that have nothing to do with Bioxel Nodes could be append to the new blender file.
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
from .nodes import custom_nodes
|
||||
from . import auto_load
|
||||
from . import menu
|
||||
|
||||
import bpy
|
||||
|
||||
from . import auto_load
|
||||
from . import menus
|
||||
|
||||
|
||||
bl_info = {
|
||||
"name": "BiovelNodes",
|
||||
"name": "Bioxel Nodes",
|
||||
"author": "Ma Nan",
|
||||
"description": "",
|
||||
"blender": (4, 0, 0),
|
||||
"version": (0, 1, 0),
|
||||
"version": (0, 2, 0),
|
||||
"location": "File -> Import",
|
||||
"warning": "",
|
||||
"category": "Import-Export"
|
||||
"category": "Node"
|
||||
}
|
||||
|
||||
auto_load.init()
|
||||
@@ -21,14 +20,14 @@ auto_load.init()
|
||||
|
||||
def register():
|
||||
auto_load.register()
|
||||
custom_nodes.register()
|
||||
menu.create_menu()
|
||||
menus.add()
|
||||
bpy.types.Scene.bioxel_layer_dir = bpy.props.StringProperty(
|
||||
name="Bioxel Layers Directory",
|
||||
subtype='DIR_PATH',
|
||||
default="//"
|
||||
)
|
||||
|
||||
|
||||
def unregister():
|
||||
try:
|
||||
menu.remove_menu()
|
||||
custom_nodes.unregister()
|
||||
auto_load.unregister()
|
||||
except RuntimeError:
|
||||
pass
|
||||
menus.remove()
|
||||
auto_load.unregister()
|
||||
|
||||
BIN
bioxelnodes/assets/Nodes.blend
LFS
BIN
bioxelnodes/assets/Nodes/BioxelNodes_4.0.blend
LFS
Normal file
BIN
bioxelnodes/assets/Nodes/BioxelNodes_4.1.blend
LFS
Normal file
@@ -16,6 +16,7 @@ blender_version = bpy.app.version
|
||||
modules = None
|
||||
ordered_classes = None
|
||||
|
||||
|
||||
def init():
|
||||
global modules
|
||||
global ordered_classes
|
||||
@@ -23,6 +24,7 @@ def init():
|
||||
modules = get_all_submodules(Path(__file__).parent)
|
||||
ordered_classes = get_ordered_classes_to_register(modules)
|
||||
|
||||
|
||||
def register():
|
||||
for cls in ordered_classes:
|
||||
bpy.utils.register_class(cls)
|
||||
@@ -33,27 +35,36 @@ def register():
|
||||
if hasattr(module, "register"):
|
||||
module.register()
|
||||
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(ordered_classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
try:
|
||||
bpy.utils.unregister_class(cls)
|
||||
except Exception as e:
|
||||
print(f"Fail to unregister {cls}, skiped")
|
||||
|
||||
for module in modules:
|
||||
if module.__name__ == __name__:
|
||||
continue
|
||||
if hasattr(module, "unregister"):
|
||||
module.unregister()
|
||||
try:
|
||||
if module.__name__ == __name__:
|
||||
continue
|
||||
if hasattr(module, "unregister"):
|
||||
module.unregister()
|
||||
except Exception as e:
|
||||
print(f"Fail to unregister {module}, skiped")
|
||||
|
||||
|
||||
# Import modules
|
||||
#################################################
|
||||
|
||||
def get_all_submodules(directory):
|
||||
return list(iter_submodules(directory, directory.name))
|
||||
return list(iter_submodules(directory, __package__))
|
||||
|
||||
|
||||
def iter_submodules(path, package_name):
|
||||
for name in sorted(iter_submodule_names(path)):
|
||||
yield importlib.import_module("." + name, package_name)
|
||||
|
||||
|
||||
def iter_submodule_names(path, root=""):
|
||||
for _, module_name, is_package in pkgutil.iter_modules([str(path)]):
|
||||
if is_package:
|
||||
@@ -70,19 +81,24 @@ def iter_submodule_names(path, root=""):
|
||||
def get_ordered_classes_to_register(modules):
|
||||
return toposort(get_register_deps_dict(modules))
|
||||
|
||||
|
||||
def get_register_deps_dict(modules):
|
||||
my_classes = set(iter_my_classes(modules))
|
||||
my_classes_by_idname = {cls.bl_idname : cls for cls in my_classes if hasattr(cls, "bl_idname")}
|
||||
my_classes_by_idname = {
|
||||
cls.bl_idname: cls for cls in my_classes if hasattr(cls, "bl_idname")}
|
||||
|
||||
deps_dict = {}
|
||||
for cls in my_classes:
|
||||
deps_dict[cls] = set(iter_my_register_deps(cls, my_classes, my_classes_by_idname))
|
||||
deps_dict[cls] = set(iter_my_register_deps(
|
||||
cls, my_classes, my_classes_by_idname))
|
||||
return deps_dict
|
||||
|
||||
|
||||
def iter_my_register_deps(cls, my_classes, my_classes_by_idname):
|
||||
yield from iter_my_deps_from_annotations(cls, my_classes)
|
||||
yield from iter_my_deps_from_parent_id(cls, my_classes_by_idname)
|
||||
|
||||
|
||||
def iter_my_deps_from_annotations(cls, my_classes):
|
||||
for value in typing.get_type_hints(cls, {}, {}).values():
|
||||
dependency = get_dependency_from_annotation(value)
|
||||
@@ -90,6 +106,7 @@ def iter_my_deps_from_annotations(cls, my_classes):
|
||||
if dependency in my_classes:
|
||||
yield dependency
|
||||
|
||||
|
||||
def get_dependency_from_annotation(value):
|
||||
if blender_version >= (2, 93):
|
||||
if isinstance(value, bpy.props._PropertyDeferred):
|
||||
@@ -100,6 +117,7 @@ def get_dependency_from_annotation(value):
|
||||
return value[1]["type"]
|
||||
return None
|
||||
|
||||
|
||||
def iter_my_deps_from_parent_id(cls, my_classes_by_idname):
|
||||
if bpy.types.Panel in cls.__bases__:
|
||||
parent_idname = getattr(cls, "bl_parent_id", None)
|
||||
@@ -108,6 +126,7 @@ def iter_my_deps_from_parent_id(cls, my_classes_by_idname):
|
||||
if parent_cls is not None:
|
||||
yield parent_cls
|
||||
|
||||
|
||||
def iter_my_classes(modules):
|
||||
base_types = get_register_base_types()
|
||||
for cls in get_classes_in_modules(modules):
|
||||
@@ -115,6 +134,7 @@ def iter_my_classes(modules):
|
||||
if not getattr(cls, "is_registered", False):
|
||||
yield cls
|
||||
|
||||
|
||||
def get_classes_in_modules(modules):
|
||||
classes = set()
|
||||
for module in modules:
|
||||
@@ -122,11 +142,13 @@ def get_classes_in_modules(modules):
|
||||
classes.add(cls)
|
||||
return classes
|
||||
|
||||
|
||||
def iter_classes_in_module(module):
|
||||
for value in module.__dict__.values():
|
||||
if inspect.isclass(value):
|
||||
yield value
|
||||
|
||||
|
||||
def get_register_base_types():
|
||||
return set(getattr(bpy.types, name) for name in [
|
||||
"Panel", "Operator", "PropertyGroup", "FileHandler",
|
||||
@@ -134,7 +156,7 @@ def get_register_base_types():
|
||||
"Node", "NodeSocket", "NodeTree",
|
||||
"UIList", "RenderEngine",
|
||||
"Gizmo", "GizmoGroup",
|
||||
])
|
||||
] if hasattr(bpy.types, name))
|
||||
|
||||
|
||||
# Find order to register to solve dependencies
|
||||
@@ -151,5 +173,6 @@ def toposort(deps_dict):
|
||||
sorted_values.add(value)
|
||||
else:
|
||||
unsorted.append(value)
|
||||
deps_dict = {value : deps_dict[value] - sorted_values for value in unsorted}
|
||||
deps_dict = {value: deps_dict[value] -
|
||||
sorted_values for value in unsorted}
|
||||
return sorted_list
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import bpy
|
||||
from .utils import get_bioxels_obj
|
||||
|
||||
|
||||
class ConvertToMesh(bpy.types.Operator):
|
||||
bl_idname = "bioxelnodes.convert_to_mesh"
|
||||
bl_label = "Bioxels To Mesh"
|
||||
bl_description = "Convert Bioxels To Mesh."
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
bioxels_objs = []
|
||||
|
||||
for obj in bpy.context.selected_objects:
|
||||
bioxels_obj = get_bioxels_obj(obj)
|
||||
if bioxels_obj:
|
||||
bioxels_objs.append(bioxels_obj)
|
||||
|
||||
if len(bioxels_objs)==0:
|
||||
self.report({"WARNING"}, "Cannot find any bioxels.")
|
||||
return {'FINISHED'}
|
||||
|
||||
for bioxels_obj in bioxels_objs:
|
||||
bpy.ops.mesh.primitive_cube_add(
|
||||
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
|
||||
mesh_obj = bpy.context.active_object
|
||||
|
||||
mesh_obj.name = f"{bioxels_obj.parent.name}_Mesh"
|
||||
bpy.ops.node.new_geometry_nodes_modifier()
|
||||
modifier = mesh_obj.modifiers[0]
|
||||
nodes = modifier.node_group.nodes
|
||||
links = modifier.node_group.links
|
||||
|
||||
output_node = nodes.get("Group Output")
|
||||
object_node = nodes.new("GeometryNodeObjectInfo")
|
||||
realize_nodes = nodes.new("GeometryNodeRealizeInstances")
|
||||
object_node.inputs[0].default_value = bioxels_obj
|
||||
object_node.transform_space = 'RELATIVE'
|
||||
|
||||
links.new(object_node.outputs['Geometry'], realize_nodes.inputs[0])
|
||||
links.new(realize_nodes.outputs[0], output_node.inputs[0])
|
||||
bpy.ops.object.convert(target='MESH')
|
||||
bpy.context.object.active_material_index = 1
|
||||
bpy.ops.object.material_slot_remove()
|
||||
|
||||
return {'FINISHED'}
|
||||
@@ -1 +0,0 @@
|
||||
from .node_menu import CustomNodes
|
||||
1
bioxelnodes/customnodes/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .menus import CustomNodes
|
||||
@@ -1,8 +1,60 @@
|
||||
import shutil
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
from .nodes import AddCustomNode
|
||||
|
||||
|
||||
class SaveAllNodes(bpy.types.Operator):
|
||||
bl_idname = "customnodes.save_all_nodes"
|
||||
bl_label = "Save All Custom Nodes"
|
||||
bl_description = "Save All Custom Nodes to Directory."
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
files = []
|
||||
for classname in dir(bpy.types):
|
||||
if "CUSTOMNODES_MT_NODES_" in classname:
|
||||
cls = getattr(bpy.types, classname)
|
||||
files.append(cls.nodes_file)
|
||||
files = list(set(files))
|
||||
|
||||
for file in files:
|
||||
file_name = Path(file).name
|
||||
# "//"
|
||||
custom_nodes_dir = bpy.path.abspath(context.scene.custom_nodes_dir)
|
||||
|
||||
output_path: Path = Path(custom_nodes_dir, file_name).resolve()
|
||||
source_path: Path = Path(file).resolve()
|
||||
|
||||
if output_path != source_path:
|
||||
shutil.copy(source_path, output_path)
|
||||
|
||||
for lib in bpy.data.libraries:
|
||||
lib_path = str(Path(bpy.path.abspath(lib.filepath)).resolve())
|
||||
if lib_path == file:
|
||||
blend_path = Path(bpy.path.abspath("//")).resolve()
|
||||
lib.filepath = bpy.path.relpath(
|
||||
str(output_path), start=str(blend_path))
|
||||
|
||||
self.report({"INFO"}, f"Successfully saved to {output_path}")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class CUSTOMNODES_PT_CustomNodes(bpy.types.Panel):
|
||||
bl_idname = "CUSTOMNODES_PT_CustomNodes"
|
||||
bl_label = "Custom Nodes"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "scene"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
layout.prop(scene, 'custom_nodes_dir')
|
||||
layout.operator(SaveAllNodes.bl_idname)
|
||||
|
||||
|
||||
class CustomNodes():
|
||||
def __init__(
|
||||
self,
|
||||
@@ -12,10 +64,10 @@ class CustomNodes():
|
||||
root_icon='NONE'
|
||||
) -> None:
|
||||
if not Path(nodes_file).is_file():
|
||||
raise FileNotFoundError(Path(nodes_file).resolve().as_posix())
|
||||
raise FileNotFoundError(str(Path(nodes_file).resolve()))
|
||||
|
||||
self.menu_items = menu_items
|
||||
self.nodes_file = Path(nodes_file).resolve().as_posix()
|
||||
self.nodes_file = str(Path(nodes_file).resolve())
|
||||
|
||||
self.root_label = root_label
|
||||
self.root_icon = root_icon
|
||||
@@ -28,7 +80,7 @@ class CustomNodes():
|
||||
)
|
||||
self.menu_classes = menu_classes
|
||||
|
||||
idname = f"CUSTOMNODES_MT_NODES__{root_label.replace(' ', '').upper()}"
|
||||
idname = f"CUSTOMNODES_MT_NODES_{root_label.replace(' ', '').upper()}"
|
||||
|
||||
def add_node_menu(self, context):
|
||||
if ('GeometryNodeTree' == bpy.context.area.spaces[0].tree_type):
|
||||
@@ -40,7 +92,7 @@ class CustomNodes():
|
||||
|
||||
def _create_menu_class(self, menu_classes, items, label='CustomNodes', icon=0, idname_namespace=None):
|
||||
nodes_file = self.nodes_file
|
||||
idname_namespace = idname_namespace or "CUSTOMNODES_MT_NODES_"
|
||||
idname_namespace = idname_namespace or "CUSTOMNODES_MT_NODES"
|
||||
idname = f"{idname_namespace}_{label.replace(' ', '').upper()}"
|
||||
|
||||
# create submenu class if item is menu.
|
||||
@@ -60,6 +112,7 @@ class CustomNodes():
|
||||
class Menu(bpy.types.Menu):
|
||||
bl_idname = idname
|
||||
bl_label = label
|
||||
nodes_file = self.nodes_file
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
@@ -93,10 +146,13 @@ class CustomNodes():
|
||||
def _find_item(self, found_items, menu_items, node_type: str):
|
||||
|
||||
for item in menu_items:
|
||||
if item == 'separator':
|
||||
continue
|
||||
|
||||
if item.get("node_type") == node_type:
|
||||
found_items.append(item)
|
||||
|
||||
item_items = item.get('items') if item != 'separator' else None
|
||||
item_items = item.get('items')
|
||||
if item_items:
|
||||
self._find_item(found_items, item_items, node_type)
|
||||
|
||||
@@ -107,28 +163,35 @@ class CustomNodes():
|
||||
|
||||
def add_node(self, node_tree, node_type: str):
|
||||
item = self.find_item(node_type)
|
||||
op = AddCustomNode()
|
||||
op.nodes_file = self.nodes_file
|
||||
op.node_type = node_type
|
||||
if item:
|
||||
op = AddCustomNode()
|
||||
op.nodes_file = self.nodes_file
|
||||
op.node_type = item['node_type']
|
||||
op.node_label = item.get('label') or ""
|
||||
op.node_link = item.get('link') or True
|
||||
op.node_callback = item.get('node_callback') or ""
|
||||
return op.add_node(node_tree)
|
||||
else:
|
||||
raise RuntimeError("No custom node type found.")
|
||||
op.node_label = ""
|
||||
op.node_link = True
|
||||
op.node_callback = ""
|
||||
return op.add_node(node_tree)
|
||||
|
||||
def register(self):
|
||||
for cls in self.menu_classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
bpy.types.NODE_MT_add.append(self.add_node_menu)
|
||||
bpy.types.Scene.custom_nodes_dir = bpy.props.StringProperty(
|
||||
name="Nodes Directory",
|
||||
subtype='DIR_PATH',
|
||||
default="//"
|
||||
)
|
||||
|
||||
def unregister(self):
|
||||
bpy.types.NODE_MT_add.remove(self.add_node_menu)
|
||||
try:
|
||||
for cls in reversed(self.menu_classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
bpy.types.NODE_MT_add.remove(self.add_node_menu)
|
||||
except RuntimeError:
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
from .preferences import ExternalPackagePreferences
|
||||
2
bioxelnodes/externalpackage/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .preferences import ExternalPackagePreferences
|
||||
from .package import PackageInstaller
|
||||
@@ -42,12 +42,13 @@ class InstallationError(Exception):
|
||||
class PackageInstaller():
|
||||
def __init__(
|
||||
self,
|
||||
log_dir: str,
|
||||
requirements_dir: str,
|
||||
log_dir: str = None,
|
||||
pypi_mirror_provider='Default',
|
||||
) -> None:
|
||||
self.pypi_mirror_provider = pypi_mirror_provider
|
||||
self.log_path: Path = Path(log_dir)
|
||||
self.log_path: Path = Path(log_dir) if log_dir \
|
||||
else Path.home() / '.externalpackage' / 'logs'
|
||||
self.requirements_path: Path = Path(requirements_dir)
|
||||
|
||||
def start_logging(self, logfile_name: str = 'side-packages-install') -> logging.Logger:
|
||||
@@ -75,7 +76,8 @@ class PackageInstaller():
|
||||
|
||||
# Set up logging configuration
|
||||
logfile_path = Path(self.log_path, f"{logfile_name}.log")
|
||||
logging.basicConfig(filename=logfile_path, level=logging.INFO)
|
||||
logging.basicConfig(filename=logfile_path,
|
||||
level=logging.INFO, encoding='utf-8')
|
||||
|
||||
# Return logger object
|
||||
return logging.getLogger()
|
||||
@@ -231,7 +233,7 @@ class PackageInstaller():
|
||||
"""
|
||||
|
||||
# path to python.exe
|
||||
python_exe = Path(sys.executable).resolve().as_posix()
|
||||
python_exe = str(Path(sys.executable).resolve())
|
||||
|
||||
# build the command list
|
||||
cmd_list = [python_exe] + cmd_list
|
||||
@@ -247,13 +249,16 @@ class PackageInstaller():
|
||||
result = subprocess.run(cmd_list, timeout=timeout,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
if result.returncode != 0:
|
||||
log.error('Command failed: %s', cmd_list)
|
||||
log.error('stdout: %s', result.stdout.decode())
|
||||
log.error('stderr: %s', result.stderr.decode())
|
||||
else:
|
||||
log.info('Command succeeded: %s', cmd_list)
|
||||
log.info('stdout: %s', result.stdout.decode())
|
||||
try:
|
||||
if result.returncode != 0:
|
||||
log.error('Command failed: %s', cmd_list)
|
||||
log.error('stdout: %s', result.stdout.decode())
|
||||
log.error('stderr: %s', result.stderr.decode(errors='ignore'))
|
||||
else:
|
||||
log.info('Command succeeded: %s', cmd_list)
|
||||
log.info('stdout: %s', result.stdout.decode())
|
||||
except:
|
||||
...
|
||||
# return the command list, return code, stdout, and stderr as a tuple
|
||||
return result
|
||||
|
||||
@@ -350,6 +355,7 @@ class EXTERNALPACKAGE_OT_Install_Package(bpy.types.Operator):
|
||||
name='Python Package',
|
||||
description='Python Package to Install'
|
||||
) # type: ignore
|
||||
|
||||
version: bpy.props.StringProperty(
|
||||
name='Python Package',
|
||||
description='Python Package to Install'
|
||||
@@ -373,7 +379,7 @@ class EXTERNALPACKAGE_OT_Install_Package(bpy.types.Operator):
|
||||
)
|
||||
|
||||
result = installer.install_package(f"{self.package}=={self.version}")
|
||||
if result.returncode == 0 and installer.is_installed(self.package):
|
||||
if result.returncode == 0 or installer.is_installed(self.package):
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Successfully installed {self.package} v{self.version}"
|
||||
@@ -381,9 +387,7 @@ class EXTERNALPACKAGE_OT_Install_Package(bpy.types.Operator):
|
||||
else:
|
||||
self.report(
|
||||
{'ERROR'},
|
||||
f"""
|
||||
Error installing package. Please check the log files
|
||||
in {preferences.log_dir}.
|
||||
"""
|
||||
f"""Error installing package. Please check the log files
|
||||
in {preferences.log_dir}."""
|
||||
)
|
||||
return {'FINISHED'}
|
||||
@@ -1,4 +1,5 @@
|
||||
import bpy
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from .package import PackageInstaller, PYPI_MIRROR
|
||||
|
||||
@@ -10,17 +11,36 @@ def get_pypi_mirrors(self, context, edit_text):
|
||||
return PYPI_MIRROR.keys()
|
||||
|
||||
|
||||
class RebootBlender(bpy.types.Operator):
|
||||
bl_idname = "externalpackage.reboot_blender"
|
||||
bl_label = "Reboot Blender"
|
||||
bl_description = "Reboot Blender"
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
context.window_manager.invoke_confirm(self, event)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def execute(self, context):
|
||||
blender_launcher = Path(
|
||||
bpy.app.binary_path).parent / "blender-launcher.exe"
|
||||
subprocess.run([str(blender_launcher), "-con", "--python-expr",
|
||||
"import bpy; bpy.ops.wm.recover_last_session()"])
|
||||
bpy.ops.wm.quit_blender()
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class ExternalPackagePreferences():
|
||||
requirements_dir: bpy.props.StringProperty(
|
||||
name="requirements.txt Directory",
|
||||
subtype='DIR_PATH',
|
||||
default=Path(__file__).parent.as_posix()
|
||||
default=str(Path(__file__).parent)
|
||||
) # type: ignore
|
||||
|
||||
log_dir: bpy.props.StringProperty(
|
||||
name="Python Log Directory",
|
||||
subtype='DIR_PATH',
|
||||
default=Path(Path.home(), '.externalpackage', 'logs').as_posix()
|
||||
default=str(Path(Path.home(), '.externalpackage', 'logs'))
|
||||
) # type: ignore
|
||||
|
||||
pypi_mirror_provider: bpy.props.StringProperty(
|
||||
@@ -34,13 +54,13 @@ class ExternalPackagePreferences():
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text="Install the required packages.")
|
||||
layout.label(
|
||||
text='**Install the required packages, then hit "Reboot Blender"**')
|
||||
|
||||
col_main = layout.column(heading='', align=False)
|
||||
row_import = col_main.row()
|
||||
row_import.prop(self, 'pypi_mirror_provider', text='Set PyPI Mirror')
|
||||
row_import.prop(self, 'pypi_mirror_provider', text='PyPI Mirror')
|
||||
|
||||
|
||||
installer = PackageInstaller(
|
||||
pypi_mirror_provider=self.pypi_mirror_provider,
|
||||
log_dir=self.log_dir,
|
||||
@@ -71,3 +91,5 @@ class ExternalPackagePreferences():
|
||||
op.package = name
|
||||
op.version = version
|
||||
op.description = f'Install required python package: {name}'
|
||||
|
||||
layout.operator(RebootBlender.bl_idname)
|
||||
25
bioxelnodes/io_points.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# TODO: WIP
|
||||
import bpy
|
||||
import bmesh
|
||||
|
||||
|
||||
def create_points_obj(points, name="points"):
|
||||
bpy.ops.mesh.primitive_cube_add(
|
||||
enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)
|
||||
)
|
||||
obj = bpy.context.active_object
|
||||
mesh = obj.data
|
||||
|
||||
bm = bmesh.new()
|
||||
value_layer = bm.verts.layers.float.new('value')
|
||||
|
||||
for point in points:
|
||||
pos = point['pos']
|
||||
value = point['value']
|
||||
vert = bm.verts.new(pos) # add a new vert
|
||||
vert[value_layer] = value
|
||||
|
||||
# make the bmesh the object's mesh
|
||||
bm.to_mesh(mesh)
|
||||
bm.free() # always do this when finished
|
||||
return obj
|
||||
@@ -1,33 +0,0 @@
|
||||
import bpy
|
||||
from .convert import ConvertToMesh
|
||||
from .io import ExportVDB, ImportDICOM
|
||||
|
||||
|
||||
def TOPBAR_FILE_IMPORT(self, context):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator(ImportDICOM.bl_idname)
|
||||
|
||||
|
||||
def TOPBAR_FILE_EXPORT(self, context):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator(ExportVDB.bl_idname)
|
||||
|
||||
|
||||
def VIEW3D_OBJECT(self, context):
|
||||
layout = self.layout
|
||||
layout.operator(ConvertToMesh.bl_idname)
|
||||
layout.separator()
|
||||
|
||||
|
||||
def create_menu():
|
||||
bpy.types.TOPBAR_MT_file_import.append(TOPBAR_FILE_IMPORT)
|
||||
bpy.types.TOPBAR_MT_file_export.append(TOPBAR_FILE_EXPORT)
|
||||
bpy.types.VIEW3D_MT_object_context_menu.prepend(VIEW3D_OBJECT)
|
||||
|
||||
|
||||
def remove_menu():
|
||||
bpy.types.TOPBAR_MT_file_import.remove(TOPBAR_FILE_IMPORT)
|
||||
bpy.types.TOPBAR_MT_file_export.remove(TOPBAR_FILE_EXPORT)
|
||||
bpy.types.VIEW3D_MT_object_context_menu.remove(VIEW3D_OBJECT)
|
||||
67
bioxelnodes/menus.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import bpy
|
||||
from .operators import ConvertToMesh, JoinLayers
|
||||
from .io import ExportVDB, ImportVolumeData, AddVolumeData
|
||||
from .misc import SaveBioxelLayers
|
||||
|
||||
|
||||
class View3DBioxelsMenu(bpy.types.Menu):
|
||||
bl_idname = "BIOXELNODES_MT_VIEW3D"
|
||||
bl_label = "Bioxel Nodes"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator(ConvertToMesh.bl_idname)
|
||||
layout.operator(AddVolumeData.bl_idname)
|
||||
layout.separator()
|
||||
layout.operator(SaveBioxelLayers.bl_idname)
|
||||
|
||||
|
||||
class OutlinerBioxelsMenu(bpy.types.Menu):
|
||||
bl_idname = "BIOXELNODES_MT_OUTLINER"
|
||||
bl_label = "Bioxel Nodes"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator(JoinLayers.bl_idname)
|
||||
layout.operator(ConvertToMesh.bl_idname)
|
||||
layout.operator(AddVolumeData.bl_idname)
|
||||
layout.separator()
|
||||
layout.operator(SaveBioxelLayers.bl_idname)
|
||||
|
||||
|
||||
def TOPBAR_FILE_IMPORT(self, context):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator(ImportVolumeData.bl_idname)
|
||||
|
||||
|
||||
def TOPBAR_FILE_EXPORT(self, context):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator(ExportVDB.bl_idname)
|
||||
|
||||
|
||||
def VIEW3D_OBJECT(self, context):
|
||||
layout = self.layout
|
||||
layout.menu(View3DBioxelsMenu.bl_idname)
|
||||
layout.separator()
|
||||
|
||||
|
||||
def OUTLINER_OBJECT(self, context):
|
||||
layout = self.layout
|
||||
layout.menu(OutlinerBioxelsMenu.bl_idname)
|
||||
layout.separator()
|
||||
|
||||
|
||||
def add():
|
||||
bpy.types.TOPBAR_MT_file_import.append(TOPBAR_FILE_IMPORT)
|
||||
bpy.types.TOPBAR_MT_file_export.append(TOPBAR_FILE_EXPORT)
|
||||
bpy.types.OUTLINER_MT_object.prepend(OUTLINER_OBJECT)
|
||||
bpy.types.VIEW3D_MT_object_context_menu.prepend(VIEW3D_OBJECT)
|
||||
|
||||
|
||||
def remove():
|
||||
bpy.types.TOPBAR_MT_file_import.remove(TOPBAR_FILE_IMPORT)
|
||||
bpy.types.TOPBAR_MT_file_export.remove(TOPBAR_FILE_EXPORT)
|
||||
bpy.types.OUTLINER_MT_object.remove(OUTLINER_OBJECT)
|
||||
bpy.types.VIEW3D_MT_object_context_menu.remove(VIEW3D_OBJECT)
|
||||
92
bioxelnodes/misc.py
Normal file
@@ -0,0 +1,92 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from .utils import get_all_layers, get_container, get_container_layers
|
||||
|
||||
|
||||
def save_layer(layer, output_dir):
|
||||
name = layer.name
|
||||
|
||||
# "//"
|
||||
output_dir = bpy.path.abspath(output_dir)
|
||||
source_dir = bpy.path.abspath(layer.data.filepath)
|
||||
|
||||
output_path: Path = Path(output_dir, f"{name}.vdb").resolve()
|
||||
source_path: Path = Path(source_dir).resolve()
|
||||
|
||||
if output_path != source_path:
|
||||
shutil.copy(source_path, output_path)
|
||||
|
||||
blend_path = Path(bpy.path.abspath("//")).resolve()
|
||||
layer.data.filepath = bpy.path.relpath(
|
||||
str(output_path), start=str(blend_path))
|
||||
|
||||
|
||||
class SaveBioxelLayers(bpy.types.Operator):
|
||||
bl_idname = "bioxelnodes.save_bioxel_layers"
|
||||
bl_label = "Save Bioxel Layers"
|
||||
bl_description = "Save Bioxel Layers to Directory."
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
container = get_container(bpy.context.active_object)
|
||||
return True if container else False
|
||||
|
||||
def execute(self, context):
|
||||
container = get_container(bpy.context.active_object)
|
||||
|
||||
if not container:
|
||||
self.report({"WARNING"}, "Cannot find any bioxel container.")
|
||||
return {'FINISHED'}
|
||||
|
||||
for layer in get_container_layers(container):
|
||||
try:
|
||||
save_layer(layer, context.scene.bioxel_layer_dir)
|
||||
except:
|
||||
self.report(
|
||||
{"WARNING"}, f"Fail to save {layer.name}, skiped")
|
||||
|
||||
self.report({"INFO"}, f"Successfully saved bioxel layers.")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class SaveAllBioxelLayers(bpy.types.Operator):
|
||||
bl_idname = "bioxelnodes.save_all_bioxel_layers"
|
||||
bl_label = "Save All Bioxel Layers"
|
||||
bl_description = "Save All Bioxel Layers to Directory."
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
layers = get_all_layers()
|
||||
|
||||
if len(layers) == 0:
|
||||
self.report({"WARNING"}, "Cannot find any bioxel layer.")
|
||||
return {'FINISHED'}
|
||||
|
||||
for layer in layers:
|
||||
try:
|
||||
save_layer(layer, context.scene.bioxel_layer_dir)
|
||||
except:
|
||||
self.report(
|
||||
{"WARNING"}, f"Fail to save {layer.name}, skiped")
|
||||
|
||||
self.report({"INFO"}, f"Successfully saved bioxel layers.")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class BIOXELNODES_PT_Bioxels(bpy.types.Panel):
|
||||
bl_idname = "BIOXELNODES_PT_Bioxels"
|
||||
bl_label = "Bioxel Nodes"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "scene"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
layout.prop(scene, 'bioxel_layer_dir')
|
||||
layout.operator(SaveAllBioxelLayers.bl_idname)
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
from pathlib import Path
|
||||
from .custom_nodes import CustomNodes
|
||||
from .customnodes import CustomNodes
|
||||
import bpy
|
||||
|
||||
|
||||
def add_driver_to_node_factory(source_prop, target_prop):
|
||||
callback_str = f"""
|
||||
import bpy
|
||||
from bioxelnodes.utils import add_direct_driver, get_bioxels_obj
|
||||
from .utils import add_direct_driver, get_bioxels_obj
|
||||
bioxels_obj = get_bioxels_obj(bpy.context.active_object)
|
||||
container_obj = bioxels_obj.parent
|
||||
if bioxels_obj:
|
||||
container_obj = bioxels_obj.parent
|
||||
add_direct_driver(
|
||||
target=node,
|
||||
target_prop='{target_prop}',
|
||||
@@ -26,121 +26,289 @@ else:
|
||||
def set_prop_to_node_factory(source_prop, target_prop):
|
||||
callback_str = f"""
|
||||
import bpy
|
||||
from bioxelnodes.utils import get_bioxels_obj
|
||||
from .utils import get_bioxels_obj
|
||||
bioxels_obj = get_bioxels_obj(bpy.context.active_object)
|
||||
container_obj = bioxels_obj.parent
|
||||
if bioxels_obj:
|
||||
node.inputs.get('{target_prop}').default_value = container_obj.get('{source_prop}')
|
||||
container_obj = bioxels_obj.parent
|
||||
node.inputs.get('{target_prop}').default_value = container_obj.get(
|
||||
'{source_prop}')
|
||||
else:
|
||||
print('Cannot find any bioxels.')
|
||||
"""
|
||||
return callback_str
|
||||
|
||||
|
||||
MENU_ITEMS = [
|
||||
{
|
||||
'label': 'Present',
|
||||
'icon': 'MESH_MONKEY',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Segment',
|
||||
'icon': 'OUTLINER_OB_META',
|
||||
'node_type': 'BioxelNodes_Segment',
|
||||
'node_description': '',
|
||||
'node_callback': "\n".join([
|
||||
set_prop_to_node_factory("bioxel_size", "Detail Size"),
|
||||
set_prop_to_node_factory("bioxels_offset", "Offset"),
|
||||
])
|
||||
},
|
||||
{
|
||||
'label': 'Anatomy',
|
||||
'icon': 'OUTLINER_OB_META',
|
||||
'node_type': 'BioxelNodes_Anatomy',
|
||||
'node_description': '',
|
||||
'node_callback': "\n".join([
|
||||
set_prop_to_node_factory("bioxel_size", "Detail Size"),
|
||||
set_prop_to_node_factory("bioxels_offset", "Offset"),
|
||||
])
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Segment',
|
||||
'icon': 'OUTLINER_DATA_VOLUME',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Segment by Level',
|
||||
'icon': 'AREA_JOIN',
|
||||
'node_type': 'BioxelNodes_SegmentByLevel',
|
||||
'node_description': '',
|
||||
'node_callback': "\n".join([
|
||||
set_prop_to_node_factory("bioxel_size", "Detail Size"),
|
||||
set_prop_to_node_factory("bioxels_offset", "Offset"),
|
||||
])
|
||||
},
|
||||
{
|
||||
'label': 'Segment by Range',
|
||||
'icon': 'AREA_SWAP',
|
||||
'node_type': 'BioxelNodes_SegmentByRange',
|
||||
'node_description': '',
|
||||
'node_callback': "\n".join([
|
||||
set_prop_to_node_factory("bioxel_size", "Detail Size"),
|
||||
set_prop_to_node_factory("bioxels_offset", "Offset"),
|
||||
])
|
||||
},
|
||||
{
|
||||
'label': 'Segment by Layers',
|
||||
'icon': 'OUTLINER_OB_FORCE_FIELD',
|
||||
'node_type': 'BioxelNodes_SegmentsByLayers',
|
||||
'node_description': '',
|
||||
'node_callback': "\n".join([
|
||||
set_prop_to_node_factory("bioxel_size", "Detail Size"),
|
||||
set_prop_to_node_factory("bioxels_offset", "Offset"),
|
||||
])
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Shader',
|
||||
'icon': 'SHADING_RENDERED',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Segment Shader',
|
||||
'icon': 'OUTLINER_OB_VOLUME',
|
||||
'node_type': 'BioxelNodes_SegmentShader',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Slicer',
|
||||
'icon': 'CLIPUV_DEHLT',
|
||||
'items': [
|
||||
{
|
||||
'label': 'RAS Slicer',
|
||||
'icon': 'EMPTY_DATA',
|
||||
'node_type': 'BioxelNodes_RAS-Slicer',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Axis Slicer',
|
||||
'icon': 'OUTLINER_OB_EMPTY',
|
||||
'node_type': 'BioxelNodes_AxisSlicer',
|
||||
'node_description': '',
|
||||
},
|
||||
{
|
||||
'label': 'Box Slicer',
|
||||
'icon': 'MOD_WIREFRAME',
|
||||
'node_type': 'BioxelNodes_BoxSlicer',
|
||||
'node_description': '',
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
if bpy.app.version >= (4, 1, 0):
|
||||
NODE_FILE = "BioxelNodes_4.1"
|
||||
|
||||
MENU_ITEMS = [
|
||||
{
|
||||
'label': 'Methods',
|
||||
'icon': 'OUTLINER_DATA_VOLUME',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Mask by Threshold',
|
||||
'icon': 'EMPTY_SINGLE_ARROW',
|
||||
'node_type': 'BioxelNodes_MaskByThreshold',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Mask by Range',
|
||||
'icon': 'IPO_CONSTANT',
|
||||
'node_type': 'BioxelNodes_MaskByRange',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Mask by Label',
|
||||
'icon': 'MESH_CAPSULE',
|
||||
'node_type': 'BioxelNodes_MaskByLabel',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Shaders',
|
||||
'icon': 'SHADING_RENDERED',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Solid Shader',
|
||||
'icon': 'SHADING_SOLID',
|
||||
'node_type': 'BioxelNodes_AssignSolidShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Slime Shader',
|
||||
'icon': 'OUTLINER_OB_META',
|
||||
'node_type': 'BioxelNodes_AssignSlimeShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Volume Shader',
|
||||
'icon': 'OUTLINER_OB_VOLUME',
|
||||
'node_type': 'BioxelNodes_AssignVolumeShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Universal Shader',
|
||||
'icon': 'SHADING_RENDERED',
|
||||
'node_type': 'BioxelNodes_AssignUniversalShader',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Colors',
|
||||
'icon': 'COLOR',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Color Presets',
|
||||
'icon': 'COLOR',
|
||||
'node_type': 'BioxelNodes_SetColorPresets',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 2',
|
||||
'icon': 'IPO_QUAD',
|
||||
'node_type': 'BioxelNodes_SetColorRamp2',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 3',
|
||||
'icon': 'IPO_CUBIC',
|
||||
'node_type': 'BioxelNodes_SetColorRamp3',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 4',
|
||||
'icon': 'IPO_QUART',
|
||||
'node_type': 'BioxelNodes_SetColorRamp4',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 5',
|
||||
'icon': 'IPO_QUINT',
|
||||
'node_type': 'BioxelNodes_SetColorRamp5',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Cutters',
|
||||
'icon': 'MOD_BEVEL',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Cut',
|
||||
'icon': 'MOD_BEVEL',
|
||||
'node_type': 'BioxelNodes_Cut',
|
||||
'node_description': ''
|
||||
},
|
||||
"separator",
|
||||
{
|
||||
'label': 'Plane Cutter',
|
||||
'icon': 'MOD_LATTICE',
|
||||
'node_type': 'BioxelNodes_PlaneCutter',
|
||||
'node_description': '',
|
||||
},
|
||||
{
|
||||
'label': 'Plane Object Cutter',
|
||||
'icon': 'OUTLINER_OB_LATTICE',
|
||||
'node_type': 'BioxelNodes_PlaneObjectCutter',
|
||||
'node_description': '',
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Utils',
|
||||
'icon': 'MODIFIER',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Join Component',
|
||||
'icon': 'CONSTRAINT_BONE',
|
||||
'node_type': 'BioxelNodes_JoinComponent',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
else:
|
||||
NODE_FILE = "BioxelNodes_4.0"
|
||||
MENU_ITEMS = [
|
||||
{
|
||||
'label': 'Methods',
|
||||
'icon': 'OUTLINER_DATA_VOLUME',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Mask by Threshold',
|
||||
'icon': 'EMPTY_SINGLE_ARROW',
|
||||
'node_type': 'BioxelNodes_MaskByThreshold',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Mask by Range',
|
||||
'icon': 'IPO_CONSTANT',
|
||||
'node_type': 'BioxelNodes_MaskByRange',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Mask by Label',
|
||||
'icon': 'MESH_CAPSULE',
|
||||
'node_type': 'BioxelNodes_MaskByLabel',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Shaders',
|
||||
'icon': 'SHADING_RENDERED',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Solid Shader',
|
||||
'icon': 'SHADING_SOLID',
|
||||
'node_type': 'BioxelNodes_AssignSolidShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Slime Shader',
|
||||
'icon': 'OUTLINER_OB_META',
|
||||
'node_type': 'BioxelNodes_AssignSlimeShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Volume Shader',
|
||||
'icon': 'OUTLINER_OB_VOLUME',
|
||||
'node_type': 'BioxelNodes_AssignVolumeShader',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Universal Shader',
|
||||
'icon': 'SHADING_RENDERED',
|
||||
'node_type': 'BioxelNodes_AssignUniversalShader',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Colors',
|
||||
'icon': 'COLOR',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Color Ramp 2',
|
||||
'icon': 'IPO_QUAD',
|
||||
'node_type': 'BioxelNodes_SetColorRamp2',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 3',
|
||||
'icon': 'IPO_CUBIC',
|
||||
'node_type': 'BioxelNodes_SetColorRamp3',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 4',
|
||||
'icon': 'IPO_QUART',
|
||||
'node_type': 'BioxelNodes_SetColorRamp4',
|
||||
'node_description': ''
|
||||
},
|
||||
{
|
||||
'label': 'Color Ramp 5',
|
||||
'icon': 'IPO_QUINT',
|
||||
'node_type': 'BioxelNodes_SetColorRamp5',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Cutters',
|
||||
'icon': 'MOD_BEVEL',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Cut',
|
||||
'icon': 'MOD_BEVEL',
|
||||
'node_type': 'BioxelNodes_Cut',
|
||||
'node_description': ''
|
||||
},
|
||||
"separator",
|
||||
{
|
||||
'label': 'Plane Cutter',
|
||||
'icon': 'MOD_LATTICE',
|
||||
'node_type': 'BioxelNodes_PlaneCutter',
|
||||
'node_description': '',
|
||||
},
|
||||
{
|
||||
'label': 'Plane Object Cutter',
|
||||
'icon': 'OUTLINER_OB_LATTICE',
|
||||
'node_type': 'BioxelNodes_PlaneObjectCutter',
|
||||
'node_description': '',
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'Utils',
|
||||
'icon': 'MODIFIER',
|
||||
'items': [
|
||||
{
|
||||
'label': 'Join Component',
|
||||
'icon': 'CONSTRAINT_BONE',
|
||||
'node_type': 'BioxelNodes_JoinComponent',
|
||||
'node_description': ''
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
custom_nodes = CustomNodes(
|
||||
menu_items=MENU_ITEMS,
|
||||
nodes_file=Path(__file__).parent/"assets/Nodes.blend",
|
||||
root_label='BioxelNodes',
|
||||
nodes_file=Path(__file__).parent / f"assets/Nodes/{NODE_FILE}.blend",
|
||||
root_label='Bioxel Nodes',
|
||||
root_icon="FILE_VOLUME",
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
custom_nodes.register()
|
||||
|
||||
|
||||
def unregister():
|
||||
custom_nodes.unregister()
|
||||
|
||||
226
bioxelnodes/operators.py
Normal file
@@ -0,0 +1,226 @@
|
||||
from pathlib import Path
|
||||
import bpy
|
||||
import pyopenvdb as vdb
|
||||
from uuid import uuid4
|
||||
from .nodes import custom_nodes
|
||||
from .utils import (get_container, get_container_layers,
|
||||
get_layer, get_node_by_type, hide_in_ray, lock_transform)
|
||||
|
||||
|
||||
def get_scalar_layer_selection(self, context):
|
||||
items = [("None", "None", "")]
|
||||
base_layer = bpy.data.objects[self.base_layer]
|
||||
container = base_layer.parent
|
||||
for layer in get_container_layers(container):
|
||||
if layer.get("bioxel_layer_type") == "scalar":
|
||||
items.append((
|
||||
layer.name,
|
||||
layer.name,
|
||||
""
|
||||
))
|
||||
|
||||
return items
|
||||
|
||||
|
||||
def get_label_layer_selection(self, context):
|
||||
items = [("None", "None", "")]
|
||||
base_layer = bpy.data.objects[self.base_layer]
|
||||
container = base_layer.parent
|
||||
for layer in get_container_layers(container):
|
||||
if layer.get("bioxel_layer_type") == "label":
|
||||
items.append((
|
||||
layer.name,
|
||||
layer.name,
|
||||
""
|
||||
))
|
||||
|
||||
return items
|
||||
|
||||
|
||||
class JoinLayers(bpy.types.Operator):
|
||||
bl_idname = "bioxelnodes.join_layers"
|
||||
bl_label = "Join Additinal Layers"
|
||||
bl_description = "Join Layers"
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
base_layer: bpy.props.StringProperty(
|
||||
options={"HIDDEN"}
|
||||
) # type: ignore
|
||||
|
||||
scalar_layer: bpy.props.EnumProperty(
|
||||
name="Scaler Layer",
|
||||
items=get_scalar_layer_selection
|
||||
) # type: ignore
|
||||
|
||||
label_layer: bpy.props.EnumProperty(
|
||||
name="Label Layer",
|
||||
items=get_label_layer_selection
|
||||
) # type: ignore
|
||||
# color_layer: bpy.props.StringProperty() # type: ignore
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
layer = get_layer(bpy.context.active_object)
|
||||
return True if layer else False
|
||||
|
||||
def execute(self, context):
|
||||
base_layer = bpy.data.objects[self.base_layer]
|
||||
|
||||
if not base_layer:
|
||||
self.report({"WARNING"}, "Cannot find any bioxel layer as base.")
|
||||
return {'FINISHED'}
|
||||
|
||||
base_layer_dir = bpy.path.abspath(base_layer.data.filepath)
|
||||
base_grids, base_metadata = vdb.readAll(base_layer_dir)
|
||||
|
||||
preferences = context.preferences.addons[__package__].preferences
|
||||
cache_dir = Path(preferences.cache_dir, 'VDBs')
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
layers = []
|
||||
if self.scalar_layer != "None":
|
||||
scalar_layer = bpy.data.objects[self.scalar_layer]
|
||||
layers.append(scalar_layer)
|
||||
|
||||
if self.label_layer != "None":
|
||||
label_layer = bpy.data.objects[self.label_layer]
|
||||
layers.append(label_layer)
|
||||
|
||||
# TODO: add color and vector
|
||||
|
||||
if len(layers) == 0:
|
||||
self.report({"WARNING"}, "No additinal layers setted.")
|
||||
return {'FINISHED'}
|
||||
|
||||
for layer in layers:
|
||||
layer_dir = bpy.path.abspath(layer.data.filepath)
|
||||
grids, metadata = vdb.readAll(layer_dir)
|
||||
base_grids.extend(grids)
|
||||
|
||||
vdb_path = Path(cache_dir, f"{uuid4()}.vdb")
|
||||
print(f"Storing the VDB file ({str(vdb_path)})...")
|
||||
vdb.write(str(vdb_path), grids=base_grids)
|
||||
|
||||
# Read VDB
|
||||
print(f"Loading the cache to Blender scene...")
|
||||
bpy.ops.object.volume_import(
|
||||
filepath=str(vdb_path), align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
|
||||
|
||||
joined_layer = bpy.context.active_object
|
||||
|
||||
base_layer_node = base_layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
|
||||
bioxel_size = base_layer_node.inputs['Bioxel Size'].default_value
|
||||
layer_shape = base_layer_node.inputs['Shape'].default_value
|
||||
layer_origin = base_layer_node.inputs['Origin'].default_value
|
||||
layer_rotation = base_layer_node.inputs['Rotation'].default_value
|
||||
scalar_offset = base_layer_node.inputs['Scalar Offset'].default_value
|
||||
scalar_min = base_layer_node.inputs['Scalar Min'].default_value
|
||||
scalar_max = base_layer_node.inputs['Scalar Max'].default_value
|
||||
|
||||
if self.scalar_layer != "None":
|
||||
scalar_layer_node = scalar_layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
|
||||
scalar_offset = scalar_layer_node.inputs['Scalar Offset'].default_value
|
||||
scalar_min = scalar_layer_node.inputs['Scalar Min'].default_value
|
||||
scalar_max = scalar_layer_node.inputs['Scalar Max'].default_value
|
||||
|
||||
bpy.ops.node.new_geometry_nodes_modifier()
|
||||
node_tree = joined_layer.modifiers[0].node_group
|
||||
nodes = node_tree.nodes
|
||||
links = node_tree.links
|
||||
|
||||
input_node = get_node_by_type(nodes, 'NodeGroupInput')[0]
|
||||
output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0]
|
||||
|
||||
|
||||
joined_layer_node = custom_nodes.add_node(
|
||||
nodes, "BioxelNodes__ConvertToLayer")
|
||||
|
||||
|
||||
links.new(input_node.outputs[0], joined_layer_node.inputs[0])
|
||||
links.new(joined_layer_node.outputs[0], output_node.inputs[0])
|
||||
|
||||
joined_layer_node.inputs['Bioxel Size'].default_value = bioxel_size
|
||||
joined_layer_node.inputs['Shape'].default_value = layer_shape
|
||||
joined_layer_node.inputs['Origin'].default_value = layer_origin
|
||||
joined_layer_node.inputs['Rotation'].default_value = layer_rotation
|
||||
joined_layer_node.inputs['Scalar Offset'].default_value = scalar_offset
|
||||
joined_layer_node.inputs['Scalar Min'].default_value = scalar_min
|
||||
joined_layer_node.inputs['Scalar Max'].default_value = scalar_max
|
||||
|
||||
# Set props to VDB object
|
||||
joined_layer.name = f"{base_layer.name}_Joined"
|
||||
joined_layer.data.name = f"{base_layer.name}_Joined"
|
||||
|
||||
lock_transform(joined_layer)
|
||||
hide_in_ray(joined_layer)
|
||||
joined_layer.hide_select = True
|
||||
joined_layer.hide_render = True
|
||||
joined_layer.hide_viewport = True
|
||||
joined_layer.data.display.use_slice = True
|
||||
joined_layer.data.display.density = 1e-05
|
||||
|
||||
joined_layer['bioxel_layer'] = True
|
||||
joined_layer.parent = base_layer.parent
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
base_layer = get_layer(bpy.context.active_object)
|
||||
self.base_layer = base_layer.name
|
||||
context.window_manager.invoke_props_dialog(self, width=400)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
|
||||
class ConvertToMesh(bpy.types.Operator):
|
||||
bl_idname = "bioxelnodes.convert_to_mesh"
|
||||
bl_label = "Bioxel Components To Mesh"
|
||||
bl_description = "Convert Bioxel Components To Mesh"
|
||||
bl_options = {'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
container = get_container(bpy.context.active_object)
|
||||
return True if container else False
|
||||
|
||||
def execute(self, context):
|
||||
container = get_container(bpy.context.active_object)
|
||||
|
||||
if not container:
|
||||
self.report({"WARNING"}, "Cannot find any bioxel container.")
|
||||
return {'FINISHED'}
|
||||
|
||||
bpy.ops.mesh.primitive_cube_add(
|
||||
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
|
||||
mesh = bpy.context.active_object
|
||||
|
||||
mesh.name = f"Mesh_{container.name}"
|
||||
|
||||
bpy.ops.object.constraint_add(type='COPY_TRANSFORMS')
|
||||
mesh.constraints[0].target = container
|
||||
|
||||
bpy.ops.node.new_geometry_nodes_modifier()
|
||||
modifier = mesh.modifiers[0]
|
||||
nodes = modifier.node_group.nodes
|
||||
links = modifier.node_group.links
|
||||
|
||||
output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0]
|
||||
object_node = nodes.new("GeometryNodeObjectInfo")
|
||||
realize_nodes = nodes.new("GeometryNodeRealizeInstances")
|
||||
separate_node = custom_nodes.add_node(
|
||||
nodes, "BioxelNodes__SeparateComponent")
|
||||
|
||||
object_node.inputs[0].default_value = container
|
||||
separate_node.inputs[1].default_value = 1
|
||||
|
||||
links.new(object_node.outputs['Geometry'], separate_node.inputs[0])
|
||||
links.new(separate_node.outputs[0], realize_nodes.inputs[0])
|
||||
links.new(realize_nodes.outputs[0], output_node.inputs[0])
|
||||
|
||||
bpy.ops.object.convert(target='MESH')
|
||||
bpy.ops.constraint.apply(constraint="Copy Transforms", owner='OBJECT')
|
||||
bpy.context.object.active_material_index = 1
|
||||
bpy.ops.object.material_slot_remove()
|
||||
|
||||
self.report({"INFO"}, f"Successfully convert to mesh")
|
||||
|
||||
return {'FINISHED'}
|
||||
@@ -1,23 +1,29 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
from .external_package import ExternalPackagePreferences
|
||||
from .externalpackage import ExternalPackagePreferences
|
||||
|
||||
|
||||
class BioxelNodesPreferences(bpy.types.AddonPreferences, ExternalPackagePreferences):
|
||||
bl_idname = __package__
|
||||
|
||||
|
||||
cache_dir: bpy.props.StringProperty(
|
||||
name="Python Log Directory",
|
||||
name="Set Cache Directory",
|
||||
subtype='DIR_PATH',
|
||||
default=Path(Path.home(), '.bioxelnodes').as_posix()
|
||||
default=str(Path(Path.home(), '.bioxelnodes'))
|
||||
) # type: ignore
|
||||
|
||||
do_change_render_setting: bpy.props.BoolProperty(
|
||||
name="Change Render Setting",
|
||||
default=True,
|
||||
) # type: ignore
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text="Configuration")
|
||||
layout.prop(self, 'cache_dir', text='Set Cache Directory')
|
||||
|
||||
|
||||
# ExternalPackagePreferences Config
|
||||
self.requirements_dir = Path(__file__).parent.as_posix()
|
||||
self.requirements_dir = str(Path(__file__).parent)
|
||||
super().draw(context)
|
||||
|
||||
layout.label(text="Configuration")
|
||||
layout.prop(self, 'cache_dir')
|
||||
layout.prop(self, "do_change_render_setting")
|
||||
|
||||
5
bioxelnodes/props.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import bpy
|
||||
|
||||
class BIOXELNODES_Series(bpy.types.PropertyGroup):
|
||||
id: bpy.props.StringProperty() # type: ignore
|
||||
label: bpy.props.StringProperty() # type: ignore
|
||||
@@ -2,6 +2,14 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
|
||||
def get_type(cls):
|
||||
return type(cls).__name__
|
||||
|
||||
|
||||
def get_node_by_type(nodes, type_name: str):
|
||||
return [node for node in nodes if get_type(node) == type_name]
|
||||
|
||||
|
||||
def show_message(message="", title="Message Box", icon='INFO'):
|
||||
|
||||
def draw(self, context):
|
||||
@@ -60,25 +68,60 @@ def calc_bbox_verts(origin, size):
|
||||
return bbox_verts
|
||||
|
||||
|
||||
def get_bioxels_obj(current_obj):
|
||||
bioxels_obj = None
|
||||
if current_obj.get('bioxels_container'):
|
||||
bioxels_values = []
|
||||
for obj in bpy.data.objects:
|
||||
if obj.parent == current_obj and obj.get('bioxels'):
|
||||
bioxels_values.append(obj)
|
||||
|
||||
if len(bioxels_values) > 0:
|
||||
bioxels_obj = bioxels_values[0]
|
||||
|
||||
elif current_obj.get('bioxels') and current_obj.parent:
|
||||
if current_obj.parent.get('bioxels_container'):
|
||||
bioxels_obj = current_obj
|
||||
|
||||
return bioxels_obj
|
||||
def lock_transform(obj):
|
||||
obj.lock_location[0] = True
|
||||
obj.lock_location[1] = True
|
||||
obj.lock_location[2] = True
|
||||
obj.lock_rotation[0] = True
|
||||
obj.lock_rotation[1] = True
|
||||
obj.lock_rotation[2] = True
|
||||
obj.lock_scale[0] = True
|
||||
obj.lock_scale[1] = True
|
||||
obj.lock_scale[2] = True
|
||||
|
||||
|
||||
def extract_last_number(text):
|
||||
def hide_in_ray(obj):
|
||||
obj.visible_camera = False
|
||||
obj.visible_diffuse = False
|
||||
obj.visible_glossy = False
|
||||
obj.visible_transmission = False
|
||||
obj.visible_volume_scatter = False
|
||||
obj.visible_shadow = False
|
||||
|
||||
|
||||
def get_container(current_obj):
|
||||
if current_obj:
|
||||
return current_obj if current_obj.get('bioxel_container') else None
|
||||
return None
|
||||
|
||||
|
||||
def get_layer(current_obj):
|
||||
if current_obj:
|
||||
if current_obj.get('bioxel_layer') and current_obj.parent:
|
||||
if current_obj.parent.get('bioxel_container'):
|
||||
return current_obj
|
||||
return None
|
||||
|
||||
|
||||
def get_container_layers(container):
|
||||
layers = []
|
||||
for obj in bpy.data.objects:
|
||||
if obj.parent == container and get_layer(obj):
|
||||
layers.append(obj)
|
||||
|
||||
return layers
|
||||
|
||||
|
||||
def get_all_layers():
|
||||
layers = []
|
||||
for obj in bpy.data.objects:
|
||||
if get_layer(obj):
|
||||
layers.append(obj)
|
||||
|
||||
return layers
|
||||
|
||||
|
||||
def get_text_index_str(text):
|
||||
# Initialize an empty string to store the digits
|
||||
digits = ""
|
||||
|
||||
@@ -97,7 +140,7 @@ def extract_last_number(text):
|
||||
# Reverse the digits string to get the correct order
|
||||
last_number = digits[::-1]
|
||||
|
||||
return int(last_number)
|
||||
return last_number
|
||||
|
||||
|
||||
def add_driver(target_prop, var_sources, expression):
|
||||
|
||||
BIN
docs/assets/cover.png
Normal file
|
After Width: | Height: | Size: 2.0 MiB |
BIN
docs/assets/features_as-scalar.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
docs/assets/features_concept.png
Normal file
|
After Width: | Height: | Size: 148 KiB |
BIN
docs/assets/features_container.png
Normal file
|
After Width: | Height: | Size: 423 KiB |
BIN
docs/assets/features_import-others.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
docs/assets/features_resample.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
docs/assets/gallery.png
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
BIN
docs/assets/getting-started_dependency.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/assets/getting-started_graph.png
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
docs/assets/getting-started_importing.png
Normal file
|
After Width: | Height: | Size: 252 KiB |
BIN
docs/assets/getting-started_result.png
Normal file
|
After Width: | Height: | Size: 770 KiB |
BIN
docs/assets/getting-started_share-file.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
docs/assets/logo.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
docs/assets/nodes_bake.png
Normal file
|
After Width: | Height: | Size: 174 KiB |
BIN
docs/assets/nodes_color-presets.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
docs/assets/nodes_color-ramp-2.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
docs/assets/nodes_color-ramp-3.png
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
docs/assets/nodes_color-ramp-4.png
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
docs/assets/nodes_color-ramp-5.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
docs/assets/nodes_concept.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
docs/assets/nodes_cut.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
docs/assets/nodes_example.png
Normal file
|
After Width: | Height: | Size: 140 KiB |
BIN
docs/assets/nodes_join-component.png
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
docs/assets/nodes_mask-by-label.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
docs/assets/nodes_mask-by-range.png
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
docs/assets/nodes_mask-by-threshold.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
docs/assets/nodes_plane-cutter.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
docs/assets/nodes_plane-object-cutter.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
docs/assets/nodes_separate-component.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
docs/assets/nodes_slime-shader.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
docs/assets/nodes_solid-shader.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
docs/assets/nodes_universal-shader.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
docs/assets/nodes_volume-shader.png
Normal file
|
After Width: | Height: | Size: 59 KiB |
81
docs/features.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Features & Options
|
||||
|
||||
## Bioxel Design Concept
|
||||
|
||||
According to Bioxel design concept, Bioxel Nodes imports volume data and put it into a **Container** as a **Layer**. One container may has more than one layer, and each layer stores the information of different fields under the same location, which is similar to the view layers in map app, except that here it is in 3D space. In order to render the volume the way we want it to, we need to build renderable objects from layers. We call those objects **Component**. The following diagram shows the relationship of **Container**, **Layer**, and **Component**:
|
||||
|
||||

|
||||
|
||||
Bioxel Nodes staging the layer as an openvdb file. The process of building from layers to a component is taking place in blender geometry nodes graph with blender native geometry nodes. Therefore, **the blender file works without Bioxel Nodes.**
|
||||
|
||||
## Container Structure
|
||||
|
||||
In Blender, container structure is like this:
|
||||
|
||||
```bash
|
||||
Case_0000 # Container
|
||||
|-- Case_0000_CT # Layer
|
||||
|-- Case_0000_Label_1 # Layer
|
||||
`-- Case_0000_Label_2 # Layer
|
||||
```
|
||||
|
||||
The container also stores the build process in geometry nodes:
|
||||
|
||||

|
||||
|
||||
The layer is categorized into these by data type:
|
||||
|
||||
- Scalar
|
||||
- Label
|
||||
- Vector (Not implemented yet)
|
||||
- Color (Not implemented yet)
|
||||
|
||||
## First Time Import Volume Data
|
||||
|
||||
File > Import > Volume Data as Bioxel Layer
|
||||
|
||||
### Resample
|
||||
|
||||

|
||||
|
||||
Sometimes the original data is too big, or the spacing in the original data is not reasonable, you can modify the `Bioxel Size` and `Original Spacing` to adjust the Shape of the layer.
|
||||
|
||||
A bioxel is like a pixel, the larger the `Bioxel Size`, the lower the resolution of the image, Original Spacing will be read from the original data record, but sometimes the image doesn't have original spacing, you may need to input it manually to get the correct shape.
|
||||
|
||||
### Read as
|
||||
|
||||
- as Scalar
|
||||
|
||||

|
||||
|
||||
In some cases the environment value is higher than the value of the target object, you can check `Invert Scalar` to adjust the value for better result.
|
||||
|
||||
- as Labels
|
||||
|
||||
Many AI segmentation task datasets, provide segmentation data, which are often an integer value representing a layer of segmentation labels. You can set it to `Labels` to load them.
|
||||
|
||||
- _as Vector (Not implemented yet)_
|
||||
|
||||
- _as Color (Not implemented yet)_
|
||||
|
||||
### Others
|
||||
|
||||

|
||||
|
||||
`Scene Scale` determines how many units of length in the Blender world correspond to one unit of length in the Bioxel world. Since Blender defaults to meters, and the default size of blender primitives are around 1 blender unit. Therefore `Scene Scale` set to 0.01 is appropriate.
|
||||
|
||||
`Orient to RAS` determines whether the layer should be converted to the RAS coordinate system. Regardless of the format of the medical image data, the coordinate system is mostly the LPS coordinate system. Bioxel, however, are in the RAS coordinate system and therefore need to be transformed in most cases.
|
||||
|
||||
## Adding Volume Data to an existing container
|
||||
|
||||
In 3D view or outliner panel, select the container and right click, Bioxel Nodes > Add Volume Data to Container.
|
||||
The import settings are the same as for the first time import.
|
||||
|
||||
## Convert Bioxel Components to Mesh
|
||||
|
||||
In 3D view or outliner panel, select the container and right click, Bioxel Nodes > Bioxel Components To Mesh
|
||||
Once it has been turned into a mesh model, you can perform any traditional 3D editing operations on it, such as sculpting, boolean, etc.
|
||||
|
||||
## Export Biovel Layer as VDB
|
||||
|
||||
File > Export > Biovel Layer as VDB
|
||||
72
docs/getting-started.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# Getting Started
|
||||
|
||||
Currently only support Blender 4.0 or above, make sure you have the correct version of Blender.
|
||||
|
||||
## Add-on Installation
|
||||
|
||||
#### For Blender 4.2 or higher
|
||||
|
||||
Download the **Extension** version `BioxelNodes_Extension_{version}.zip` from https://github.com/OmooLab/BioxelNodes/releases/latest
|
||||
In Blender, Edit > Preferences > Extensions > Install from Disk, select the zip file you just downloaded.
|
||||
|
||||
Thats it!
|
||||
|
||||
> If it cannot be enable, just reboot blender.
|
||||
|
||||
#### For Blender 4.0 or 4.1
|
||||
|
||||
Download the **Addon** version `BioxelNodes_Addon_{version}.zip` from https://github.com/OmooLab/BioxelNodes/releases/latest
|
||||
In Blender, Edit > Preferences > Add-ons > Install, select the zip file you just downloaded.
|
||||
|
||||
The add-on requires a third-party python dependency called SimpleITK, click `Install SimpleITK` button below to install the dependency. After clicking, blender may get stuck, it is downloading and installing, just wait for a moment. After that, click `Reboot Blender` button.
|
||||
|
||||

|
||||
|
||||
This step may have failed due to network factors, just click "Set PyPI Mirror" to change the mirror.
|
||||
|
||||
## Prepare Your Data
|
||||
|
||||
First you need to have your volumetric data ready. If not, you can access open research data from list below.
|
||||
|
||||
> Note that just because they are open and available for download does not mean you can use them for anything! Be sure to look at the description of the available scopes from website.
|
||||
|
||||
| Source | Object |
|
||||
| ------------------------------------------------------------------------------------ | ------------------ |
|
||||
| [Dryad](https://datadryad.org) | Open Research Data |
|
||||
| [OpenOrganelle](https://openorganelle.janelia.org/datasets) | Cells |
|
||||
| [Embodi3D](https://www.embodi3d.com/files/category/37-medical-scans/) | Medical Images |
|
||||
| [Github](https://github.com/sfikas/medical-imaging-datasets) | Medical Images |
|
||||
| [NIHR](https://nhsx.github.io/open-source-imaging-data-sets/) | Medical Images |
|
||||
| [Medical Segmentation Decathlon](http://medicaldecathlon.com/) | Medical Images |
|
||||
| [Allen Cell Explorer](https://www.allencell.org/3d-cell-viewer.html) | Cells |
|
||||
| [Visible Human Project](https://www.nlm.nih.gov/research/visible/visible_human.html) | Medical Images |
|
||||
|
||||
## Import Volume Data
|
||||
|
||||
File > Import > Volume Data as Bioxel Layer, select **one** of the .dcm files and click on "Volume Data as Bioxel Layer" (you can also drag one of the .dcm files directly into the 3D viewport to trigger the import)
|
||||
|
||||

|
||||
|
||||
It may take a while to read data. After finishing reading, it will pop up a dialog box. Ignore all the options, just click OK (we will tell about these options later).
|
||||
|
||||
After importing the data, the add-on will automatically add the necessary nodes to build the component. Click on the new created object in outliner, open the geometry nodes panel, set `Threshold` in "Mask by Threshold" node to 200, and then connect a Slime Shader node (Add > Bioxel Nodes > Slime Shader) after it. The node graph should be as following:
|
||||
|
||||

|
||||
|
||||
and then turned on the cycles rendering to directly see the result.
|
||||
|
||||

|
||||
|
||||
You can change the "Threshold" to modify the preview model, or change the "Color", "Density" to modify the shader effect. All the parameters are straightforward, you can understand them by changing the values.
|
||||
|
||||
## Share Your File
|
||||
|
||||
The VDB cache and the Bioxel nodes are not reachable to other computers if you don't save them. If you want to give your blender file to someone else, you will need to perform the following steps first:
|
||||
|
||||
1. Save your blender file
|
||||
2. Click Scene > Bioxels > Save All Bioxels in the properties panel.
|
||||
3. Click Scene > Custom Nodes > Save All Custom Nodes in the properties panel.
|
||||
|
||||

|
||||
|
||||
After that, both the VDB cache and the Bioxel nodes are restored in relative locations. When you share this file with someone, pack the entire directory so that the resources will be not lost. The other person will be able to open it correctly, regardless of whether they have Bioxel Nodes installed or not.
|
||||
56
docs/index.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Bioxel Nodes
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
Bioxel Nodes is a Blender add-on for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes | Cycles to process and render volumetric data.
|
||||
|
||||
## About
|
||||
|
||||
Before us, there have been many tutorials and add-ons for importing volumetric data into Blender. However, we found that there were many details that were not addressed in place, some scientific facts were ignored, and the volume rendering was not pretty enough. With Bioxel Nodes, you can easily import the volumetric data into Blender, and more importantly, it can quickly make a beautiful realistic rendering of it.
|
||||
|
||||
Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail:
|
||||
|
||||

|
||||
|
||||
The "Bioxel" in "Bioxel Nodes", is a combination of the words "Bio-" and "Voxel". Bioxel is a voxel that stores biological data. We are developing a toolkit around Bioxel for better biological data visualization. but before its release, we made this Blender version of bioxels toolkit first, in order to let more people to have fun with volumetric data. [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started)
|
||||
|
||||
## Supported Format
|
||||
|
||||
| Format | EXT | Test |
|
||||
| ------ | ---------------------------------------- | ------- |
|
||||
| DICOM | .dcm, .DICOM | ✅ pass |
|
||||
| BMP | .bmp, .BMP | ✅ pass |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG | ✅ pass |
|
||||
| PNG | .png, .PNG | ✅ pass |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF | ✅ pass |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz | ✅ pass |
|
||||
| Nrrd | .nrrd, .nhdr | ✅ pass |
|
||||
| Meta | .mha, .mhd | yet |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 | ✅ pass |
|
||||
| VTK | .vtk | yet |
|
||||
| BioRad | .PIC, .pic | yet |
|
||||
| Gipl | .gipl, .gipl.gz | yet |
|
||||
| LSM | .lsm, .LSM | yet |
|
||||
| MINC | .mnc, .MNC | yet |
|
||||
| MRC | .mrc, .rec | yet |
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- Sections cannot be generated (will be supported soon)
|
||||
- Time sequence volume not supported (will be supported soon)
|
||||
|
||||
## To Upgrade Add-on
|
||||
|
||||
To upgrade from an older version of the add-on to the latest, you need to do the following:
|
||||
|
||||
1. Remove the old version of Bioxel Nodes at Preferences > Add-ons
|
||||
2. Add the new version and restart Blender.
|
||||
|
||||
It is not support editing the same blender file across add-on versions. In order to make sure that the previous file works properly. You need to save the staged data before upgrading ( read the last section of [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started/#share-your-file) ).
|
||||
|
||||
But even then, there is still no guarantee that the new version of the add-on will work on the old blender file. Therefore, it is highly recommended to open a new blender file to start the creating, not based on the old one.
|
||||
|
||||
Alternatively, objects from the old file that have nothing to do with Bioxel Nodes could be append to the new blender file.
|
||||
20
docs/misc.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Future Features
|
||||
|
||||
- Support more volumetric data formats (.map, .txm...)
|
||||
- Generate sections
|
||||
- More segmentation methods, e.g. AI segmentation.
|
||||
- Even better shader for volumetric rendering
|
||||
|
||||
### Bioxels
|
||||
|
||||
Bioxels is based on the RAS coordinate system, Right Aanterior Superior, which was chosen over LPS because it is more compatible with most 3D CG software coordinate systems, and is in line with the 3D artist's understanding of space.
|
||||
|
||||
All distances within Bioxels are in Units, and are specified in Meter pre unit. However, when Bioxels is imported into 3D CG software, its size in the software is not scaled by reading the Meter pre unit directly. The reason for this is that many 3D operations in software require that the primtives not be too large or too small.
|
||||
|
||||
### Based on OpenVDB
|
||||
|
||||
Bioxels is based entirely on OpenVDB for storage and rendering. The main reason for choosing OpenVDB is that as a volumetric data format, it is the fastest way to work with most CG renderers.
|
||||
|
||||
### Based on Geometry Nodes
|
||||
|
||||
Bioxel Nodes relies on Blender Geometry Nodes to reconstruct and render volumetric data. Node-based operations ensure that the original data is not permanently altered during reconstruction and rendering operations. The fact that the processing is based on Geometry Nodes without any additional dependencies also ensures that Blender can open files without this plugin installed. Look for more support for OpenVDB in GeometryNodes so that Bioxel Nodes can do more in the future.
|
||||
391
docs/nodes.md
Normal file
@@ -0,0 +1,391 @@
|
||||
# Nodes
|
||||
|
||||
## Nodes Design Concept
|
||||
|
||||
In order to build a component, the general process is to first use a "Mask Method" node to build the surface of the component based on its layers, and then connect to a "Assign Shader" node to add the material physical properties. Finally, if you need to cut the cross-section, then connect to a "Cut" node. The whole process is shown in the following diagram
|
||||
|
||||

|
||||
|
||||
A typical example looks like this:
|
||||
|
||||

|
||||
|
||||
The "Mask Method" node tends to be very computationally intensive, and if it consumes too much time, then you can bake it with a "Bake" node after it (but you need to save the Blender file first).
|
||||
|
||||

|
||||
|
||||
## Mask Methods
|
||||
|
||||
This type of node is responsible for culling out the extent of the component that does not need to be rendered, forming the interface between the object and the object, or the surface of the object (i.e., the interface between the object and the air)
|
||||
|
||||
### ⬆️ Mask by Threshold
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Generate a mask by keeping only the positions that exceed the threshold (this only works with scalar)
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Layer**, _the input scalar_
|
||||
- **Threshold**, _the threshold value_
|
||||
- Preview
|
||||
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
|
||||
- (Label Mask)
|
||||
- **Layer**, _the input label_
|
||||
- **Invert**, _invert mask_
|
||||
- **Sample Size**, _the mask sample size_
|
||||
- (Replacement)
|
||||
- **Joined**, _the joined layer_
|
||||
|
||||
</div>
|
||||
|
||||
### ↕ Mask by Range
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Generate a mask by keeping only the positions that in range (this only works with scalar)
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Layer**, _the input scalar_
|
||||
- **Fram Min**, _the lower limit_
|
||||
- **Fram Max**, _the upper limit_
|
||||
- Preview
|
||||
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
|
||||
- (Label Mask)
|
||||
- **Layer**, _the input label_
|
||||
- **Invert**, _invert mask_
|
||||
- **Sample Size**, _the mask sample size_
|
||||
- (Replacement)
|
||||
- **Joined**, _the joined layer_
|
||||
|
||||
</div>
|
||||
|
||||
### 🔤 Mask by Label
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Generate a mask by keeping only the positions that in label (this only works with label)
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Layer**, _the input label_
|
||||
- Preview
|
||||
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
|
||||
- (Replacement)
|
||||
- **Joined**, _the joined layer_
|
||||
|
||||
</div>
|
||||
|
||||
## Shaders
|
||||
|
||||
This type of node is responsible for setting material physical properties to the component to reflect the differences in rendering effects of different components.
|
||||
|
||||
### 🥚 Solid Shader
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Assign a opaque shader based on a preview mesh with no inclusions visible. Fastest rendering speed. Does not support cross-section and color ramp.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- Base
|
||||
- **Color**, _albedo or emission color_
|
||||
- **Subsurface**, _the subsurface scale_
|
||||
- **Opacity**, _the opacity of all_
|
||||
- Specular
|
||||
- **Specular**, _the specular of surface_
|
||||
- **Roughness**, _the roughness of surface_
|
||||
- Emission
|
||||
- **Emission**, _the emission strength_
|
||||
|
||||
</div>
|
||||
|
||||
### 🦠 Slime Shader
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Assign a semi-transparent shader based on the preview mesh with visible inclusions. Does not support cross-section and color ramp.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- Base
|
||||
- **Color**, _albedo or emission color_
|
||||
- **Density**, _the degree of solidity_
|
||||
- **Anisotropy**, _the anisotropy of scatting_
|
||||
- Specular
|
||||
- **Specular**, _the specular of surface_
|
||||
- **Roughness**, _the roughness of surface_
|
||||
- Emission
|
||||
- **Emission**, _the emission strength_
|
||||
|
||||
</div>
|
||||
|
||||
### ☁️ Volume Shader
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Assign a volume-based shader with support for cross-section and color ramp.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- Base
|
||||
- **Color**, _albedo or emission color_
|
||||
- **Density**, _the degree of solidity_
|
||||
- **Anisotropy**, _the anisotropy of scatting_
|
||||
- Emission
|
||||
- **Emission**, _the emission strength_
|
||||
|
||||
</div>
|
||||
|
||||
### 🔬 Universal Shader
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Assign a ultimate shader, supporting all features of Bioxel Nodes. Of course, the price is slow rendering, which can be greatly improved by adjusting the Volumes > Step Rate to 100 in the Render Settings Panel.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- Base
|
||||
- **Color**, _albedo or emission color_
|
||||
- **Density**, _the degree of solidity_
|
||||
- **Anisotropy**, _the anisotropy of scatting_
|
||||
- Specular
|
||||
- **Specular**, _the specular of surface_
|
||||
- **Roughness**, _the roughness of surface_
|
||||
- Emission
|
||||
- **Emission**, _the emission strength_
|
||||
|
||||
</div>
|
||||
|
||||
## Cutters
|
||||
|
||||
This type of node is responsible for cutting components to present cross-section
|
||||
|
||||
### 🪚 Cut
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Execute all cutters on one component.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Cutter 0~4**, _the cutters_
|
||||
- **Hide Guide**, _hide the cutter guide_
|
||||
|
||||
</div>
|
||||
|
||||
### 🧀 Plane Cutter
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Flat plane cutter, cuts off above Z-axis in local.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Origin**, _plane cutter position_
|
||||
- **Direction**, _plane cutter orientation_
|
||||
- Guide
|
||||
- **Show**, _show the cutter guide_
|
||||
- **Scale**, _scale the cutter guide_
|
||||
|
||||
</div>
|
||||
|
||||
### 🧀 Plane Object Cutter
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Also a plane cutter, but origin and direction are based on exist object.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Plane**, _the plane object_
|
||||
- Guide
|
||||
- **Show**, _show the cutter guide_
|
||||
- **Scale**, _scale the cutter guide_
|
||||
|
||||
</div>
|
||||
|
||||
## Colors
|
||||
|
||||
This type of node is responsible for setting the color properties of the shader
|
||||
|
||||
### 🎨 Color Presents
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Set color from presets.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Presets**, _select color presents_
|
||||
- **Fram Min**, _ramp factor lower limit_
|
||||
- **Fram Max**, _ramp factor upper limit_
|
||||
|
||||
</div>
|
||||
|
||||
### 2️⃣ Color Ramp 2
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Set color ramp base on scalar value.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Fram Min**, _ramp factor lower limit_
|
||||
- **Fram Max**, _ramp factor upper limit_
|
||||
- Ramp
|
||||
- **Pos0 Color**, _position 0% Color_
|
||||
- **Pos1 Color**, _position 100% Color_
|
||||
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
|
||||
- **Contrast**, _the larger the contrast, the harder color ramp will be_
|
||||
|
||||
</div>
|
||||
|
||||
### 3️⃣ Color Ramp 3
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Set color ramp base on scalar value.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Fram Min**, _ramp factor lower limit_
|
||||
- **Fram Max**, _ramp factor upper limit_
|
||||
- Ramp
|
||||
- **Pos0 Color**, _position 0% Color_
|
||||
- **Pos1 Color**, _position 50% Color_
|
||||
- **Pos2 Color**, _position 100% Color_
|
||||
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
|
||||
- **Contrast**, _the larger the contrast, the harder color ramp will be_
|
||||
|
||||
</div>
|
||||
|
||||
### 4️⃣ Color Ramp 4
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Set color ramp base on scalar value.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Fram Min**, _ramp factor lower limit_
|
||||
- **Fram Max**, _ramp factor upper limit_
|
||||
- Ramp
|
||||
- **Pos0 Color**, _position 0% Color_
|
||||
- **Pos1 Color**, _position 33.3% Color_
|
||||
- **Pos2 Color**, _position 66.6% Color_
|
||||
- **Pos3 Color**, _position 100% Color_
|
||||
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
|
||||
- **Contrast**, _the larger the contrast, the harder color ramp will be_
|
||||
|
||||
</div>
|
||||
|
||||
### 5️⃣ Color Ramp 5
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Set color ramp base on scalar value.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component**, _the upstream component_
|
||||
- **Fram Min**, _ramp factor lower limit_
|
||||
- **Fram Max**, _ramp factor upper limit_
|
||||
- Ramp
|
||||
- **Pos0 Color**, _position 0% Color_
|
||||
- **Pos1 Color**, _position 25% Color_
|
||||
- **Pos2 Color**, _position 50% Color_
|
||||
- **Pos3 Color**, _position 75% Color_
|
||||
- **Pos4 Color**, _position 100% Color_
|
||||
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
|
||||
- **Contrast**, _the larger the contrast, the harder color ramp will be_
|
||||
|
||||
</div>
|
||||
|
||||
## Utils
|
||||
|
||||
### 📦 Join Component
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- 
|
||||
|
||||
- Components' combination should not be done by "Join Geometry" node because Blender Cycles can't render volumes in the same position, so the node will slightly offset all components randomly to avoid this problem.
|
||||
|
||||
***
|
||||
|
||||
Node Parameter:
|
||||
|
||||
- **Component 0~4**, _the components_
|
||||
|
||||
</div>
|
||||
20
docs/stylesheets/extra.css
Normal file
@@ -0,0 +1,20 @@
|
||||
[data-md-color-scheme="slate"] {
|
||||
--md-code-hl-string-color: #8b8b8b;
|
||||
--md-code-hl-keyword-color: white;
|
||||
--md-code-hl-number-color: white;
|
||||
--md-typeset-a-color: white;
|
||||
}
|
||||
|
||||
[data-md-color-scheme="default"] {
|
||||
--md-code-hl-string-color: #444444;
|
||||
--md-code-hl-keyword-color: black;
|
||||
--md-code-hl-number-color: black;
|
||||
}
|
||||
|
||||
[data-md-color-scheme=slate][data-md-color-primary=black] {
|
||||
--md-typeset-a-color: white;
|
||||
}
|
||||
|
||||
[data-md-color-scheme=default][data-md-color-primary=black] {
|
||||
--md-typeset-a-color: black;
|
||||
}
|
||||
22
extension/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import bpy
|
||||
|
||||
from . import auto_load
|
||||
from . import menus
|
||||
|
||||
|
||||
auto_load.init()
|
||||
|
||||
|
||||
def register():
|
||||
auto_load.register()
|
||||
menus.add()
|
||||
bpy.types.Scene.bioxel_layer_dir = bpy.props.StringProperty(
|
||||
name="Bioxel Layers Directory",
|
||||
subtype='DIR_PATH',
|
||||
default="//"
|
||||
)
|
||||
|
||||
|
||||
def unregister():
|
||||
menus.remove()
|
||||
auto_load.unregister()
|
||||
56
extension/blender_manifest.toml
Normal file
@@ -0,0 +1,56 @@
|
||||
schema_version = "1.0.0"
|
||||
|
||||
# Example of manifest file for a Blender extension
|
||||
# Change the values according to your extension
|
||||
id = "bioxelnodes"
|
||||
version = "0.2.0"
|
||||
name = "Bioxel Nodes"
|
||||
tagline = "For scientific volumetric data visualization in Blender"
|
||||
maintainer = "Ma Nan <icrdr2010@outlook.com>"
|
||||
# Supported types: "add-on", "theme"
|
||||
type = "add-on"
|
||||
|
||||
# Optional: add-ons can list which resources they will require:
|
||||
# * "files" (for access of any filesystem operations)
|
||||
# * "network" (for internet access)
|
||||
# * "clipboard" (to read and/or write the system clipboard)
|
||||
# * "camera" (to capture photos and videos)
|
||||
# * "microphone" (to capture audio)
|
||||
permissions = ["files"]
|
||||
|
||||
# Optional link to documentation, support, source files, etc
|
||||
website = "https://omoolab.github.io/BioxelNodes/latest"
|
||||
|
||||
# Optional list defined by Blender and server, see:
|
||||
# https://docs.blender.org/manual/en/dev/extensions/tags.html
|
||||
tags = ["Geometry Nodes", "Render", "Material"]
|
||||
|
||||
blender_version_min = "4.2.0"
|
||||
# Optional: maximum supported Blender version
|
||||
# blender_version_max = "5.1.0"
|
||||
|
||||
# License conforming to https://spdx.org/licenses/ (use "SPDX: prefix)
|
||||
# https://docs.blender.org/manual/en/dev/extensions/licenses.html
|
||||
license = ["SPDX:MIT"]
|
||||
# Optional: required by some licenses.
|
||||
copyright = ["2024 OmooLab"]
|
||||
|
||||
# Optional list of supported platforms. If omitted, the extension will be available in all operating systems.
|
||||
platforms = ["windows-amd64", "macos-x86_64"]
|
||||
# Other supported platforms: "windows-arm64", "macos-x86_64"
|
||||
|
||||
# TODO: externalpackage to wheels
|
||||
# Optional: bundle 3rd party Python modules.
|
||||
# https://docs.blender.org/manual/en/dev/extensions/python_wheels.html
|
||||
wheels = [
|
||||
"./wheels/SimpleITK-2.3.1-cp311-cp311-win_amd64.whl",
|
||||
"./wheels/SimpleITK-2.3.1-cp311-cp311-macosx_11_0_arm64.whl",
|
||||
]
|
||||
|
||||
# Optional: build setting.
|
||||
# https://docs.blender.org/manual/en/dev/extensions/command_line_arguments.html#command-line-args-extension-build
|
||||
# [build]
|
||||
# paths_exclude_pattern = [
|
||||
# "/.git/"
|
||||
# "__pycache__/"
|
||||
# ]
|
||||
23
extension/preferences.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
|
||||
class BioxelNodesPreferences(bpy.types.AddonPreferences):
|
||||
bl_idname = __package__
|
||||
|
||||
cache_dir: bpy.props.StringProperty(
|
||||
name="Set Cache Directory",
|
||||
subtype='DIR_PATH',
|
||||
default=str(Path(Path.home(), '.bioxelnodes'))
|
||||
) # type: ignore
|
||||
|
||||
do_change_render_setting: bpy.props.BoolProperty(
|
||||
name="Change Render Setting",
|
||||
default=True,
|
||||
) # type: ignore
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.label(text="Configuration")
|
||||
layout.prop(self, 'cache_dir')
|
||||
layout.prop(self, "do_change_render_setting")
|
||||
85
mkdocs.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
site_name: Bioxel Nodes Docs
|
||||
site_url: https://omoolab.github.io/BioxelNodes/
|
||||
site_author: OmooLab
|
||||
site_description: Bioxel Nodes is a Blender add-on for scientific volumetric data visualization.
|
||||
|
||||
repo_name: OmooLab/BioxelNodes
|
||||
repo_url: https://github.com/OmooLab/BioxelNodes
|
||||
|
||||
nav:
|
||||
- BioxelNodes:
|
||||
- index.md
|
||||
- Getting Started: getting-started.md
|
||||
- Features & Options: features.md
|
||||
- Nodes: nodes.md
|
||||
- Future Features: misc.md
|
||||
|
||||
theme:
|
||||
name: material
|
||||
logo: assets/logo.png
|
||||
language: en
|
||||
font:
|
||||
text: Open Sans
|
||||
code: Cascadia Code
|
||||
palette:
|
||||
# Palette toggle for automatic mode
|
||||
- media: "(prefers-color-scheme)"
|
||||
primary: black
|
||||
toggle:
|
||||
icon: fontawesome/solid/circle-half-stroke
|
||||
name: Switch to light mode
|
||||
|
||||
# Palette toggle for light mode
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: default
|
||||
primary: black
|
||||
toggle:
|
||||
icon: fontawesome/regular/moon
|
||||
name: Switch to dark mode
|
||||
|
||||
# Palette toggle for dark mode
|
||||
- media: "(prefers-color-scheme: dark)"
|
||||
scheme: slate
|
||||
primary: black
|
||||
toggle:
|
||||
icon: fontawesome/solid/moon
|
||||
name: Switch to system preference
|
||||
features:
|
||||
- header.autohide
|
||||
- navigation.footer
|
||||
- navigation.indexes
|
||||
- navigation.sections
|
||||
- navigation.tabs
|
||||
- navigation.tabs.sticky
|
||||
- content.code.copy
|
||||
- content.code.select
|
||||
|
||||
extra:
|
||||
version:
|
||||
provider: mike
|
||||
default: latest
|
||||
|
||||
extra_css:
|
||||
- stylesheets/extra.css
|
||||
|
||||
copyright: Copyright © 2020 - 2024 Omoolab
|
||||
|
||||
plugins:
|
||||
- search
|
||||
- mkdocstrings
|
||||
|
||||
markdown_extensions:
|
||||
- attr_list
|
||||
- md_in_html
|
||||
- mkdocs-click
|
||||
- admonition
|
||||
- pymdownx.highlight:
|
||||
anchor_linenums: true
|
||||
line_spans: __span
|
||||
pygments_lang_class: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.details
|
||||
- pymdownx.superfences
|
||||
- pymdownx.tabbed:
|
||||
alternate_style: true
|
||||
1966
poetry.lock
generated
Normal file
29
pyproject.toml
Normal file
@@ -0,0 +1,29 @@
|
||||
[tool.poetry]
|
||||
name = "bioxelnodes"
|
||||
version = "0.2.0"
|
||||
description = ""
|
||||
authors = ["Ma Nan <icrdr2010@outlook.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "~=3.10.0"
|
||||
bpy = "~=4.0"
|
||||
simpleitk = "^2.3.1"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ipykernel = "^6.25.2"
|
||||
pytest = "^7.4.2"
|
||||
pytest-dependency = "^0.5.1"
|
||||
mkdocs = "^1.5.3"
|
||||
mkdocs-material = "^9.4.6"
|
||||
mkdocstrings = { extras = ["python"], version = "^0.23.0" }
|
||||
mkdocs-click = "^0.8.1"
|
||||
autopep8 = "^2.0.4"
|
||||
pytest-cov = "^4.1.0"
|
||||
mike = "^2.0.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||