feat: cylinder primitive & fixed GN previews
Re-added the cylinder primitive (it's quite important), including an appropriate asset `.blend`. Also finished (I think?) a quick cleanup round from the enhanced `ManagedBLModifier`, which now owns the mesh and doesn't need a seperate `ManagedBLMesh`. This seems faster for some reason, but more importantly, it simplifies a bunch of the previewing code. Finally, fixed a small issue with the extract data node where its `ExprSocket` still had the `FlowKind.Array`, causing it to not be able to be connected to the whole math system. So, yeah.main
parent
2d26ea6ce8
commit
7ac6b615de
BIN
src/blender_maxwell/assets/internal/structure/_structure_primitive_cylinder.blend (Stored with Git LFS)
100644
BIN
src/blender_maxwell/assets/internal/structure/_structure_primitive_cylinder.blend (Stored with Git LFS)
100644
Binary file not shown.
|
@ -61,7 +61,9 @@ class ExtractDataNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
output_socket_sets: typ.ClassVar = {
|
output_socket_sets: typ.ClassVar = {
|
||||||
'Sim Data': {'Monitor Data': sockets.MaxwellMonitorDataSocketDef()},
|
'Sim Data': {'Monitor Data': sockets.MaxwellMonitorDataSocketDef()},
|
||||||
'Monitor Data': {'Expr': sockets.ExprSocketDef(active_kind=ct.FlowKind.Array)},
|
'Monitor Data': {
|
||||||
|
'Expr': sockets.ExprSocketDef(active_kind=ct.FlowKind.LazyArrayRange)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
|
|
@ -222,9 +222,9 @@ class EHFieldMonitorNode(base.MaxwellSimNode):
|
||||||
)
|
)
|
||||||
def on_inputs_changed(
|
def on_inputs_changed(
|
||||||
self,
|
self,
|
||||||
managed_objs: dict,
|
managed_objs,
|
||||||
input_sockets: dict,
|
input_sockets,
|
||||||
unit_systems: dict,
|
unit_systems,
|
||||||
):
|
):
|
||||||
# Push Input Values to GeoNodes Modifier
|
# Push Input Values to GeoNodes Modifier
|
||||||
managed_objs['modifier'].bl_modifier(
|
managed_objs['modifier'].bl_modifier(
|
||||||
|
|
|
@ -65,7 +65,6 @@ class SimDomainNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
|
|
||||||
managed_obj_types: typ.ClassVar = {
|
managed_obj_types: typ.ClassVar = {
|
||||||
'mesh': managed_objs.ManagedBLMesh,
|
|
||||||
'modifier': managed_objs.ManagedBLModifier,
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,19 +94,17 @@ class SimDomainNode(base.MaxwellSimNode):
|
||||||
# - Preview
|
# - Preview
|
||||||
####################
|
####################
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
prop_name='preview_active',
|
prop_name='preview_active',
|
||||||
run_on_init=True,
|
# Loaded
|
||||||
|
managed_objs={'modifier'},
|
||||||
props={'preview_active'},
|
props={'preview_active'},
|
||||||
managed_objs={'mesh'},
|
|
||||||
)
|
)
|
||||||
def on_preview_changed(self, props, managed_objs) -> None:
|
def on_preview_changed(self, managed_objs, props):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
|
|
||||||
# Push Preview State to Managed Mesh
|
|
||||||
if props['preview_active']:
|
if props['preview_active']:
|
||||||
mesh.show_preview()
|
managed_objs['modifier'].show_preview()
|
||||||
else:
|
else:
|
||||||
mesh.hide_preview()
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
## Trigger
|
## Trigger
|
||||||
|
@ -115,7 +112,7 @@ class SimDomainNode(base.MaxwellSimNode):
|
||||||
run_on_init=True,
|
run_on_init=True,
|
||||||
# Loaded
|
# Loaded
|
||||||
input_sockets={'Center', 'Size'},
|
input_sockets={'Center', 'Size'},
|
||||||
managed_objs={'mesh', 'modifier'},
|
managed_objs={'modifier'},
|
||||||
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
||||||
scale_input_sockets={
|
scale_input_sockets={
|
||||||
'Center': 'BlenderUnits',
|
'Center': 'BlenderUnits',
|
||||||
|
@ -127,21 +124,17 @@ class SimDomainNode(base.MaxwellSimNode):
|
||||||
input_sockets,
|
input_sockets,
|
||||||
unit_systems,
|
unit_systems,
|
||||||
):
|
):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
modifier = managed_objs['modifier']
|
|
||||||
center = input_sockets['Center']
|
|
||||||
size = input_sockets['Size']
|
|
||||||
unit_system = unit_systems['BlenderUnits']
|
|
||||||
|
|
||||||
# Push Loose Input Values to GeoNodes Modifier
|
# Push Loose Input Values to GeoNodes Modifier
|
||||||
modifier.bl_modifier(
|
managed_objs['modifier'].bl_modifier(
|
||||||
mesh.bl_object(location=center),
|
|
||||||
'NODES',
|
'NODES',
|
||||||
{
|
{
|
||||||
'node_group': import_geonodes(GeoNodes.SimulationSimDomain),
|
'node_group': import_geonodes(GeoNodes.SimulationSimDomain),
|
||||||
'inputs': {'Size': size},
|
'unit_system': unit_systems['BlenderUnits'],
|
||||||
'unit_system': unit_system,
|
'inputs': {
|
||||||
|
'Size': input_sockets['Size'],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,6 @@ class GaussianBeamSourceNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
|
|
||||||
managed_obj_types: typ.ClassVar = {
|
managed_obj_types: typ.ClassVar = {
|
||||||
'mesh': managed_objs.ManagedBLMesh,
|
|
||||||
'modifier': managed_objs.ManagedBLModifier,
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,18 +169,14 @@ class GaussianBeamSourceNode(base.MaxwellSimNode):
|
||||||
# Trigger
|
# Trigger
|
||||||
prop_name='preview_active',
|
prop_name='preview_active',
|
||||||
# Loaded
|
# Loaded
|
||||||
managed_objs={'mesh'},
|
managed_objs={'modifier'},
|
||||||
props={'preview_active'},
|
props={'preview_active'},
|
||||||
)
|
)
|
||||||
def on_preview_changed(self, managed_objs, props):
|
def on_preview_changed(self, managed_objs, props):
|
||||||
"""Enables/disables previewing of the GeoNodes-driven mesh, regardless of whether a particular GeoNodes tree is chosen."""
|
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
|
|
||||||
# Push Preview State to Managed Mesh
|
|
||||||
if props['preview_active']:
|
if props['preview_active']:
|
||||||
mesh.show_preview()
|
managed_objs['modifier'].show_preview()
|
||||||
else:
|
else:
|
||||||
mesh.hide_preview()
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
# Trigger
|
# Trigger
|
||||||
|
@ -196,7 +191,7 @@ class GaussianBeamSourceNode(base.MaxwellSimNode):
|
||||||
prop_name={'injection_axis', 'injection_direction'},
|
prop_name={'injection_axis', 'injection_direction'},
|
||||||
run_on_init=True,
|
run_on_init=True,
|
||||||
# Loaded
|
# Loaded
|
||||||
managed_objs={'mesh', 'modifier'},
|
managed_objs={'modifier'},
|
||||||
props={'injection_axis', 'injection_direction'},
|
props={'injection_axis', 'injection_direction'},
|
||||||
input_sockets={
|
input_sockets={
|
||||||
'Temporal Shape',
|
'Temporal Shape',
|
||||||
|
@ -222,7 +217,6 @@ class GaussianBeamSourceNode(base.MaxwellSimNode):
|
||||||
|
|
||||||
# Push Input Values to GeoNodes Modifier
|
# Push Input Values to GeoNodes Modifier
|
||||||
managed_objs['modifier'].bl_modifier(
|
managed_objs['modifier'].bl_modifier(
|
||||||
managed_objs['mesh'].bl_object(location=input_sockets['Center']),
|
|
||||||
'NODES',
|
'NODES',
|
||||||
{
|
{
|
||||||
'node_group': import_geonodes(GeoNodes.SourceGaussianBeam),
|
'node_group': import_geonodes(GeoNodes.SourceGaussianBeam),
|
||||||
|
@ -240,6 +234,7 @@ class GaussianBeamSourceNode(base.MaxwellSimNode):
|
||||||
'Waist Radius': input_sockets['Waist Radius'],
|
'Waist Radius': input_sockets['Waist Radius'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ class PointDipoleSourceNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
|
|
||||||
managed_obj_types: typ.ClassVar = {
|
managed_obj_types: typ.ClassVar = {
|
||||||
'mesh': managed_objs.ManagedBLMesh,
|
|
||||||
'modifier': managed_objs.ManagedBLModifier,
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,27 +105,24 @@ class PointDipoleSourceNode(base.MaxwellSimNode):
|
||||||
# - Preview
|
# - Preview
|
||||||
####################
|
####################
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
prop_name='preview_active',
|
prop_name='preview_active',
|
||||||
run_on_init=True,
|
# Loaded
|
||||||
|
managed_objs={'modifier'},
|
||||||
props={'preview_active'},
|
props={'preview_active'},
|
||||||
managed_objs={'mesh'},
|
|
||||||
)
|
)
|
||||||
def on_preview_changed(self, props, managed_objs) -> None:
|
def on_preview_changed(self, managed_objs, props):
|
||||||
"""Enables/disables previewing of the GeoNodes-driven mesh, regardless of whether a particular GeoNodes tree is chosen."""
|
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
|
|
||||||
# Push Preview State to Managed Mesh
|
|
||||||
if props['preview_active']:
|
if props['preview_active']:
|
||||||
mesh.show_preview()
|
managed_objs['modifier'].show_preview()
|
||||||
else:
|
else:
|
||||||
mesh.hide_preview()
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
socket_name={'Center'},
|
socket_name={'Center'},
|
||||||
prop_name='pol_axis',
|
prop_name='pol_axis',
|
||||||
run_on_init=True,
|
run_on_init=True,
|
||||||
# Pass Data
|
# Pass Data
|
||||||
managed_objs={'mesh', 'modifier'},
|
managed_objs={'modifier'},
|
||||||
props={'pol_axis'},
|
props={'pol_axis'},
|
||||||
input_sockets={'Center'},
|
input_sockets={'Center'},
|
||||||
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
||||||
|
@ -135,9 +131,7 @@ class PointDipoleSourceNode(base.MaxwellSimNode):
|
||||||
def on_inputs_changed(
|
def on_inputs_changed(
|
||||||
self, managed_objs, props, input_sockets, unit_systems
|
self, managed_objs, props, input_sockets, unit_systems
|
||||||
) -> None:
|
) -> None:
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
modifier = managed_objs['modifier']
|
modifier = managed_objs['modifier']
|
||||||
center = input_sockets['Center']
|
|
||||||
unit_system = unit_systems['BlenderUnits']
|
unit_system = unit_systems['BlenderUnits']
|
||||||
axis = {
|
axis = {
|
||||||
ct.SimSpaceAxis.X: 0,
|
ct.SimSpaceAxis.X: 0,
|
||||||
|
@ -147,13 +141,13 @@ class PointDipoleSourceNode(base.MaxwellSimNode):
|
||||||
|
|
||||||
# Push Loose Input Values to GeoNodes Modifier
|
# Push Loose Input Values to GeoNodes Modifier
|
||||||
modifier.bl_modifier(
|
modifier.bl_modifier(
|
||||||
mesh.bl_object(location=center),
|
|
||||||
'NODES',
|
'NODES',
|
||||||
{
|
{
|
||||||
'node_group': import_geonodes(GeoNodes.SourcePointDipole),
|
'node_group': import_geonodes(GeoNodes.SourcePointDipole),
|
||||||
'inputs': {'Axis': axis},
|
'inputs': {'Axis': axis},
|
||||||
'unit_system': unit_system,
|
'unit_system': unit_system,
|
||||||
},
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,15 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# from . import cylinder_structure
|
from . import box_structure, cylinder_structure, sphere_structure
|
||||||
from . import box_structure, sphere_structure
|
|
||||||
|
|
||||||
BL_REGISTER = [
|
BL_REGISTER = [
|
||||||
*box_structure.BL_REGISTER,
|
*box_structure.BL_REGISTER,
|
||||||
# *cylinder_structure.BL_REGISTER,
|
*cylinder_structure.BL_REGISTER,
|
||||||
*sphere_structure.BL_REGISTER,
|
*sphere_structure.BL_REGISTER,
|
||||||
]
|
]
|
||||||
BL_NODES = {
|
BL_NODES = {
|
||||||
**box_structure.BL_NODES,
|
**box_structure.BL_NODES,
|
||||||
# **cylinder_structure.BL_NODES,
|
**cylinder_structure.BL_NODES,
|
||||||
**sphere_structure.BL_NODES,
|
**sphere_structure.BL_NODES,
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,15 +43,11 @@ class BoxStructureNode(base.MaxwellSimNode):
|
||||||
'Medium': sockets.MaxwellMediumSocketDef(),
|
'Medium': sockets.MaxwellMediumSocketDef(),
|
||||||
'Center': sockets.ExprSocketDef(
|
'Center': sockets.ExprSocketDef(
|
||||||
size=spux.NumberSize1D.Vec3,
|
size=spux.NumberSize1D.Vec3,
|
||||||
mathtype=spux.MathType.Real,
|
|
||||||
physical_type=spux.PhysicalType.Length,
|
|
||||||
default_unit=spu.micrometer,
|
default_unit=spu.micrometer,
|
||||||
default_value=sp.Matrix([0, 0, 0]),
|
default_value=sp.Matrix([0, 0, 0]),
|
||||||
),
|
),
|
||||||
'Size': sockets.ExprSocketDef(
|
'Size': sockets.ExprSocketDef(
|
||||||
size=spux.NumberSize1D.Vec3,
|
size=spux.NumberSize1D.Vec3,
|
||||||
mathtype=spux.MathType.Real,
|
|
||||||
physical_type=spux.PhysicalType.Length,
|
|
||||||
default_unit=spu.nanometer,
|
default_unit=spu.nanometer,
|
||||||
default_value=sp.Matrix([500, 500, 500]),
|
default_value=sp.Matrix([500, 500, 500]),
|
||||||
abs_min=0.001,
|
abs_min=0.001,
|
||||||
|
@ -62,7 +58,6 @@ class BoxStructureNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
|
|
||||||
managed_obj_types: typ.ClassVar = {
|
managed_obj_types: typ.ClassVar = {
|
||||||
'mesh': managed_objs.ManagedBLMesh,
|
|
||||||
'modifier': managed_objs.ManagedBLModifier,
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,25 +86,25 @@ class BoxStructureNode(base.MaxwellSimNode):
|
||||||
# - Preview
|
# - Preview
|
||||||
####################
|
####################
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
prop_name='preview_active',
|
prop_name='preview_active',
|
||||||
run_on_init=True,
|
# Loaded
|
||||||
|
managed_objs={'modifier'},
|
||||||
props={'preview_active'},
|
props={'preview_active'},
|
||||||
managed_objs={'mesh'},
|
|
||||||
)
|
)
|
||||||
def on_preview_changed(self, props, managed_objs) -> None:
|
def on_preview_changed(self, managed_objs, props):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
|
|
||||||
# Push Preview State to Managed Mesh
|
|
||||||
if props['preview_active']:
|
if props['preview_active']:
|
||||||
mesh.show_preview()
|
managed_objs['modifier'].show_preview()
|
||||||
else:
|
else:
|
||||||
mesh.hide_preview()
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
socket_name={'Center', 'Size'},
|
socket_name={'Center', 'Size'},
|
||||||
run_on_init=True,
|
run_on_init=True,
|
||||||
|
# Loaded
|
||||||
input_sockets={'Center', 'Size'},
|
input_sockets={'Center', 'Size'},
|
||||||
managed_objs={'mesh', 'modifier'},
|
managed_objs={'modifier'},
|
||||||
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
||||||
scale_input_sockets={
|
scale_input_sockets={
|
||||||
'Center': 'BlenderUnits',
|
'Center': 'BlenderUnits',
|
||||||
|
@ -121,21 +116,17 @@ class BoxStructureNode(base.MaxwellSimNode):
|
||||||
input_sockets,
|
input_sockets,
|
||||||
unit_systems,
|
unit_systems,
|
||||||
):
|
):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
modifier = managed_objs['modifier']
|
|
||||||
center = input_sockets['Center']
|
|
||||||
size = input_sockets['Size']
|
|
||||||
unit_system = unit_systems['BlenderUnits']
|
|
||||||
|
|
||||||
# Push Loose Input Values to GeoNodes Modifier
|
# Push Loose Input Values to GeoNodes Modifier
|
||||||
modifier.bl_modifier(
|
managed_objs['modifier'].bl_modifier(
|
||||||
mesh.bl_object(location=center),
|
|
||||||
'NODES',
|
'NODES',
|
||||||
{
|
{
|
||||||
'node_group': import_geonodes(GeoNodes.StructurePrimitiveBox),
|
'node_group': import_geonodes(GeoNodes.StructurePrimitiveBox),
|
||||||
'inputs': {'Size': size},
|
'unit_system': unit_systems['BlenderUnits'],
|
||||||
'unit_system': unit_system,
|
'inputs': {
|
||||||
|
'Size': input_sockets['Size'],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,62 +14,127 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import typing as typ
|
||||||
|
|
||||||
|
import sympy as sp
|
||||||
import sympy.physics.units as spu
|
import sympy.physics.units as spu
|
||||||
import tidy3d as td
|
import tidy3d as td
|
||||||
|
|
||||||
from .... import contracts, sockets
|
from blender_maxwell.assets.geonodes import GeoNodes, import_geonodes
|
||||||
|
from blender_maxwell.utils import extra_sympy_units as spux
|
||||||
|
from blender_maxwell.utils import logger
|
||||||
|
|
||||||
|
from .... import contracts as ct
|
||||||
|
from .... import managed_objs, sockets
|
||||||
from ... import base, events
|
from ... import base, events
|
||||||
|
|
||||||
|
log = logger.get(__name__)
|
||||||
|
|
||||||
class CylinderStructureNode(base.MaxwellSimTreeNode):
|
|
||||||
node_type = contracts.NodeType.CylinderStructure
|
class CylinderStructureNode(base.MaxwellSimNode):
|
||||||
|
node_type = ct.NodeType.CylinderStructure
|
||||||
bl_label = 'Cylinder Structure'
|
bl_label = 'Cylinder Structure'
|
||||||
# bl_icon = ...
|
use_sim_node_name = True
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# - Sockets
|
# - Sockets
|
||||||
####################
|
####################
|
||||||
input_sockets = {
|
input_sockets: typ.ClassVar = {
|
||||||
'medium': sockets.MaxwellMediumSocketDef(
|
'Medium': sockets.MaxwellMediumSocketDef(),
|
||||||
label='Medium',
|
'Center': sockets.ExprSocketDef(
|
||||||
|
size=spux.NumberSize1D.Vec3,
|
||||||
|
default_unit=spu.micrometer,
|
||||||
|
default_value=sp.Matrix([0, 0, 0]),
|
||||||
),
|
),
|
||||||
'center': sockets.PhysicalPoint3DSocketDef(
|
'Radius': sockets.ExprSocketDef(
|
||||||
label='Center',
|
default_unit=spu.nanometer,
|
||||||
|
default_value=150,
|
||||||
),
|
),
|
||||||
'radius': sockets.PhysicalLengthSocketDef(
|
'Height': sockets.ExprSocketDef(
|
||||||
label='Radius',
|
default_unit=spu.nanometer,
|
||||||
),
|
default_value=500,
|
||||||
'height': sockets.PhysicalLengthSocketDef(
|
|
||||||
label='Height',
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
output_sockets = {
|
output_sockets: typ.ClassVar = {
|
||||||
'structure': sockets.MaxwellStructureSocketDef(
|
'Structure': sockets.MaxwellStructureSocketDef(),
|
||||||
label='Structure',
|
}
|
||||||
),
|
|
||||||
|
managed_obj_types: typ.ClassVar = {
|
||||||
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# - Output Socket Computation
|
# - Output Socket Computation
|
||||||
####################
|
####################
|
||||||
@events.computes_output_socket('structure')
|
@events.computes_output_socket(
|
||||||
def compute_simulation(self: contracts.NodeTypeProtocol) -> td.Box:
|
'Structure',
|
||||||
medium = self.compute_input('medium')
|
input_sockets={'Center', 'Radius', 'Medium', 'Height'},
|
||||||
_center = self.compute_input('center')
|
unit_systems={'Tidy3DUnits': ct.UNITS_TIDY3D},
|
||||||
_radius = self.compute_input('radius')
|
scale_input_sockets={
|
||||||
_height = self.compute_input('height')
|
'Center': 'Tidy3DUnits',
|
||||||
|
'Radius': 'Tidy3DUnits',
|
||||||
center = tuple(spu.convert_to(_center, spu.um) / spu.um)
|
'Height': 'Tidy3DUnits',
|
||||||
radius = spu.convert_to(_radius, spu.um) / spu.um
|
},
|
||||||
height = spu.convert_to(_height, spu.um) / spu.um
|
)
|
||||||
|
def compute_structure(self, input_sockets, unit_systems) -> td.Box:
|
||||||
return td.Structure(
|
return td.Structure(
|
||||||
geometry=td.Cylinder(
|
geometry=td.Cylinder(
|
||||||
radius=radius,
|
radius=input_sockets['Radius'],
|
||||||
center=center,
|
center=input_sockets['Center'],
|
||||||
length=height,
|
length=input_sockets['Height'],
|
||||||
),
|
),
|
||||||
medium=medium,
|
medium=input_sockets['Medium'],
|
||||||
|
)
|
||||||
|
|
||||||
|
####################
|
||||||
|
# - Preview
|
||||||
|
####################
|
||||||
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
|
prop_name='preview_active',
|
||||||
|
# Loaded
|
||||||
|
managed_objs={'modifier'},
|
||||||
|
props={'preview_active'},
|
||||||
|
)
|
||||||
|
def on_preview_changed(self, managed_objs, props):
|
||||||
|
if props['preview_active']:
|
||||||
|
managed_objs['modifier'].show_preview()
|
||||||
|
else:
|
||||||
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
|
socket_name={'Center', 'Radius', 'Medium', 'Height'},
|
||||||
|
run_on_init=True,
|
||||||
|
# Loaded
|
||||||
|
input_sockets={'Center', 'Radius', 'Medium', 'Height'},
|
||||||
|
managed_objs={'modifier'},
|
||||||
|
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
||||||
|
scale_input_sockets={
|
||||||
|
'Center': 'BlenderUnits',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def on_inputs_changed(
|
||||||
|
self,
|
||||||
|
managed_objs,
|
||||||
|
input_sockets,
|
||||||
|
unit_systems,
|
||||||
|
):
|
||||||
|
modifier = managed_objs['modifier']
|
||||||
|
unit_system = unit_systems['BlenderUnits']
|
||||||
|
|
||||||
|
# Push Loose Input Values to GeoNodes Modifier
|
||||||
|
modifier.bl_modifier(
|
||||||
|
'NODES',
|
||||||
|
{
|
||||||
|
'node_group': import_geonodes(GeoNodes.StructurePrimitiveCylinder),
|
||||||
|
'inputs': {
|
||||||
|
'Radius': input_sockets['Radius'],
|
||||||
|
'Height': input_sockets['Height'],
|
||||||
|
},
|
||||||
|
'unit_system': unit_system,
|
||||||
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,7 +145,5 @@ BL_REGISTER = [
|
||||||
CylinderStructureNode,
|
CylinderStructureNode,
|
||||||
]
|
]
|
||||||
BL_NODES = {
|
BL_NODES = {
|
||||||
contracts.NodeType.CylinderStructure: (
|
ct.NodeType.CylinderStructure: (ct.NodeCategory.MAXWELLSIM_STRUCTURES_PRIMITIVES)
|
||||||
contracts.NodeCategory.MAXWELLSIM_STRUCTURES_PRIMITIVES
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ class SphereStructureNode(base.MaxwellSimNode):
|
||||||
}
|
}
|
||||||
|
|
||||||
managed_obj_types: typ.ClassVar = {
|
managed_obj_types: typ.ClassVar = {
|
||||||
'mesh': managed_objs.ManagedBLMesh,
|
|
||||||
'modifier': managed_objs.ManagedBLModifier,
|
'modifier': managed_objs.ManagedBLModifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,25 +84,25 @@ class SphereStructureNode(base.MaxwellSimNode):
|
||||||
# - Preview
|
# - Preview
|
||||||
####################
|
####################
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
prop_name='preview_active',
|
prop_name='preview_active',
|
||||||
run_on_init=True,
|
# Loaded
|
||||||
|
managed_objs={'modifier'},
|
||||||
props={'preview_active'},
|
props={'preview_active'},
|
||||||
managed_objs={'mesh'},
|
|
||||||
)
|
)
|
||||||
def on_preview_changed(self, props, managed_objs) -> None:
|
def on_preview_changed(self, managed_objs, props):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
|
|
||||||
# Push Preview State to Managed Mesh
|
|
||||||
if props['preview_active']:
|
if props['preview_active']:
|
||||||
mesh.show_preview()
|
managed_objs['modifier'].show_preview()
|
||||||
else:
|
else:
|
||||||
mesh.hide_preview()
|
managed_objs['modifier'].hide_preview()
|
||||||
|
|
||||||
@events.on_value_changed(
|
@events.on_value_changed(
|
||||||
|
# Trigger
|
||||||
socket_name={'Center', 'Radius'},
|
socket_name={'Center', 'Radius'},
|
||||||
run_on_init=True,
|
run_on_init=True,
|
||||||
|
# Loaded
|
||||||
input_sockets={'Center', 'Radius'},
|
input_sockets={'Center', 'Radius'},
|
||||||
managed_objs={'mesh', 'modifier'},
|
managed_objs={'modifier'},
|
||||||
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
unit_systems={'BlenderUnits': ct.UNITS_BLENDER},
|
||||||
scale_input_sockets={
|
scale_input_sockets={
|
||||||
'Center': 'BlenderUnits',
|
'Center': 'BlenderUnits',
|
||||||
|
@ -115,21 +114,20 @@ class SphereStructureNode(base.MaxwellSimNode):
|
||||||
input_sockets,
|
input_sockets,
|
||||||
unit_systems,
|
unit_systems,
|
||||||
):
|
):
|
||||||
mesh = managed_objs['mesh']
|
|
||||||
modifier = managed_objs['modifier']
|
modifier = managed_objs['modifier']
|
||||||
center = input_sockets['Center']
|
|
||||||
radius = input_sockets['Radius']
|
|
||||||
unit_system = unit_systems['BlenderUnits']
|
unit_system = unit_systems['BlenderUnits']
|
||||||
|
|
||||||
# Push Loose Input Values to GeoNodes Modifier
|
# Push Loose Input Values to GeoNodes Modifier
|
||||||
modifier.bl_modifier(
|
modifier.bl_modifier(
|
||||||
mesh.bl_object(location=center),
|
|
||||||
'NODES',
|
'NODES',
|
||||||
{
|
{
|
||||||
'node_group': import_geonodes(GeoNodes.StructurePrimitiveSphere),
|
'node_group': import_geonodes(GeoNodes.StructurePrimitiveSphere),
|
||||||
'inputs': {'Radius': radius},
|
'inputs': {
|
||||||
|
'Radius': input_sockets['Radius'],
|
||||||
|
},
|
||||||
'unit_system': unit_system,
|
'unit_system': unit_system,
|
||||||
},
|
},
|
||||||
|
location=input_sockets['Center'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,13 @@
|
||||||
import bpy
|
import bpy
|
||||||
import tidy3d as td
|
import tidy3d as td
|
||||||
|
|
||||||
|
from blender_maxwell.utils import bl_cache, logger
|
||||||
|
|
||||||
from ... import contracts as ct
|
from ... import contracts as ct
|
||||||
from .. import base
|
from .. import base
|
||||||
|
|
||||||
|
log = logger.get(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MaxwellSimGridBLSocket(base.MaxwellSimSocket):
|
class MaxwellSimGridBLSocket(base.MaxwellSimSocket):
|
||||||
socket_type = ct.SocketType.MaxwellSimGrid
|
socket_type = ct.SocketType.MaxwellSimGrid
|
||||||
|
@ -28,17 +32,7 @@ class MaxwellSimGridBLSocket(base.MaxwellSimSocket):
|
||||||
####################
|
####################
|
||||||
# - Properties
|
# - Properties
|
||||||
####################
|
####################
|
||||||
min_steps_per_wl: bpy.props.FloatProperty(
|
min_steps_per_wl: float = bl_cache.BLField(10.0, abs_min=0.01, float_prec=2)
|
||||||
name='Minimum Steps per Wavelength',
|
|
||||||
description='How many grid steps to ensure per wavelength',
|
|
||||||
default=10.0,
|
|
||||||
min=0.01,
|
|
||||||
# step=10,
|
|
||||||
precision=2,
|
|
||||||
update=(
|
|
||||||
lambda self, context: self.on_prop_changed('min_steps_per_wl', context)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# - Socket UI
|
# - Socket UI
|
||||||
|
@ -50,7 +44,7 @@ class MaxwellSimGridBLSocket(base.MaxwellSimSocket):
|
||||||
col.label(text='min. stp/λ')
|
col.label(text='min. stp/λ')
|
||||||
|
|
||||||
col = split.column(align=True)
|
col = split.column(align=True)
|
||||||
col.prop(self, 'min_steps_per_wl', text='')
|
col.prop(self, self.blfields['min_steps_per_wl'], text='')
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# - Computation of Default Value
|
# - Computation of Default Value
|
||||||
|
|
Loading…
Reference in New Issue