Browse Source

Update SoftVolumes to newfangled ID properties

pull/56/head
Adam Johnson 8 years ago
parent
commit
4de9ca0727
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 3
      korman/idprops.py
  2. 22
      korman/nodes/node_softvolume.py
  3. 39
      korman/properties/modifiers/region.py
  4. 2
      korman/ui/modifiers/region.py

3
korman/idprops.py

@ -130,5 +130,8 @@ def poll_empty_objects(self, value):
def poll_mesh_objects(self, value):
return value.type == "MESH"
def poll_softvolume_objects(self, value):
return value.plasma_modifiers.softvolume.enabled
def poll_envmap_textures(self, value):
return isinstance(value, bpy.types.EnvironmentMapTexture)

22
korman/nodes/node_softvolume.py

@ -19,6 +19,7 @@ from collections import OrderedDict
from PyHSPlasma import *
from .node_core import PlasmaNodeBase, PlasmaNodeSocketBase, PlasmaTreeOutputNodeBase
from .. import idprops
class PlasmaSoftVolumeOutputNode(PlasmaTreeOutputNodeBase, bpy.types.Node):
bl_category = "SV"
@ -71,7 +72,7 @@ class PlasmaSoftVolumePropertiesNode(PlasmaNodeBase, bpy.types.Node):
softvolume.outsideStrength = self.outside_strength / 100
class PlasmaSoftVolumeReferenceNode(PlasmaNodeBase, bpy.types.Node):
class PlasmaSoftVolumeReferenceNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.types.Node):
bl_category = "SV"
bl_idname = "PlasmaSoftVolumeReferenceNode"
bl_label = "Soft Region"
@ -84,19 +85,24 @@ class PlasmaSoftVolumeReferenceNode(PlasmaNodeBase, bpy.types.Node):
}),
])
soft_object = StringProperty(name="Soft Volume",
description="Object whose Soft Volume modifier we should use")
soft_volume = PointerProperty(name="Soft Volume",
description="Object whose Soft Volume modifier we should use",
type=bpy.types.Object,
poll=idprops.poll_softvolume_objects)
def draw_buttons(self, context, layout):
layout.prop_search(self, "soft_object", bpy.data, "objects", icon="OBJECT_DATA", text="")
layout.prop(self, "soft_volume", text="")
def get_key(self, exporter, so):
softvol = bpy.data.objects.get(self.soft_object, None)
if softvol is None:
self.raise_error("Volume Object '{}' not found".format(self.soft_object))
if self.soft_volume is None:
self.raise_error("Invalid SoftVolume object reference")
# Don't use SO here because that's the tree owner's SO. This soft region will find or create
# its own SceneObject. Yay!
return softvol.plasma_modifiers.softvolume.get_key(exporter)
return self.soft_volume.plasma_modifiers.softvolume.get_key(exporter)
@classmethod
def _idprop_mapping(cls):
return {"soft_volume": "soft_object"}
class PlasmaSoftVolumeInvertNode(PlasmaNodeBase, bpy.types.Node):

39
korman/properties/modifiers/region.py

@ -19,6 +19,7 @@ from PyHSPlasma import *
from ...exporter import ExportError
from ...helpers import TemporaryObject
from ... import idprops
from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz
from .physics import bounds_types
@ -145,7 +146,7 @@ class PlasmaPanicLinkRegion(PlasmaModifierProperties):
return True
class PlasmaSoftVolume(PlasmaModifierProperties):
class PlasmaSoftVolume(idprops.IDPropMixin, PlasmaModifierProperties):
pl_id = "softvolume"
bl_category = "Region"
@ -156,8 +157,9 @@ class PlasmaSoftVolume(PlasmaModifierProperties):
use_nodes = BoolProperty(name="Use Nodes",
description="Make this a node-based Soft Volume",
default=False)
node_tree_name = StringProperty(name="Node Tree",
description="Node Tree detailing soft volume logic")
node_tree = PointerProperty(name="Node Tree",
description="Node Tree detailing soft volume logic",
type=bpy.types.NodeTree)
# Basic
invert = BoolProperty(name="Invert",
@ -179,9 +181,10 @@ class PlasmaSoftVolume(PlasmaModifierProperties):
so = exporter.mgr.find_create_object(plSceneObject, bl=self.id_data)
if self.use_nodes:
output = self.node_tree.find_output("PlasmaSoftVolumeOutputNode")
tree = self.get_node_tree()
output = tree.find_output("PlasmaSoftVolumeOutputNode")
if output is None:
raise ExportError("SoftVolume '{}' Node Tree '{}' has no output node!".format(self.key_name, self.node_tree))
raise ExportError("SoftVolume '{}' Node Tree '{}' has no output node!".format(self.key_name, tree.name))
return output.get_key(exporter, so)
else:
pClass = plSoftVolumeInvert if self.invert else plSoftVolumeSimple
@ -221,13 +224,19 @@ class PlasmaSoftVolume(PlasmaModifierProperties):
sv.volume = isect
def _export_sv_nodes(self, exporter, bo, so):
if self.node_tree_name not in exporter.node_trees_exported:
exporter.node_trees_exported.add(self.node_tree_name)
self.node_tree.export(exporter, bo, so)
@property
def node_tree(self):
tree = bpy.data.node_groups.get(self.node_tree_name, None)
if tree is None:
raise ExportError("SoftVolume '{}': Node Tree '{}' does not exist!".format(self.key_name, self.node_tree_name))
return tree
tree = self.get_node_tree()
if tree.name not in exporter.node_trees_exported:
exporter.node_trees_exported.add(tree.name)
tree.export(exporter, bo, so)
def get_node_tree(self):
if self.node_tree is None:
raise ExportError("SoftVolume '{}' does not specify a valid Node Tree!".format(self.key_name))
return self.node_tree
@classmethod
def _idprop_mapping(cls):
return {"node_tree": "node_tree_name"}
def _idprop_sources(self):
return {"node_tree_name": bpy.data.node_groups}

2
korman/ui/modifiers/region.py

@ -28,7 +28,7 @@ def softvolume(modifier, layout, context):
row = layout.row()
row.prop(modifier, "use_nodes", text="", icon="NODETREE")
if modifier.use_nodes:
row.prop_search(modifier, "node_tree_name", bpy.data, "node_groups")
row.prop(modifier, "node_tree")
else:
row.label("Simple Soft Volume")

Loading…
Cancel
Save