Browse Source

Implement VisRegions

pull/23/head
Adam Johnson 9 years ago
parent
commit
c57407573a
  1. 2
      korman/exporter/mesh.py
  2. 18
      korman/exporter/rtlight.py
  3. 81
      korman/properties/modifiers/render.py
  4. 35
      korman/ui/modifiers/render.py

2
korman/exporter/mesh.py

@ -264,7 +264,7 @@ class MeshConverter:
# Create the DrawInterface # Create the DrawInterface
if drawables: if drawables:
diface = self._mgr.add_object(pl=plDrawInterface, bl=bo) diface = self._mgr.find_create_object(plDrawInterface, bl=bo)
for dspan_key, idx in drawables: for dspan_key, idx in drawables:
diface.addDrawable(dspan_key, idx) diface.addDrawable(dspan_key, idx)

18
korman/exporter/rtlight.py

@ -89,18 +89,11 @@ class LightConverter:
def _convert_sun_lamp(self, bl, pl): def _convert_sun_lamp(self, bl, pl):
print(" [DirectionalLightInfo '{}']".format(bl.name)) print(" [DirectionalLightInfo '{}']".format(bl.name))
def _create_light_key(self, bo, bl_light, so):
try:
xlate = _BL2PL[bl_light.type]
return self.mgr.find_create_key(xlate, bl=bo, so=so)
except LookupError:
raise BlenderOptionNotSupported("Object ('{}') lamp type '{}'".format(bo.name, bl_light.type))
def export_rtlight(self, so, bo): def export_rtlight(self, so, bo):
bl_light = bo.data bl_light = bo.data
# The specifics be here... # The specifics be here...
pl_light = self._create_light_key(bo, bl_light, so).object pl_light = self.get_light_key(bo, bl_light, so).object
self._converter_funcs[bl_light.type](bl_light, pl_light) self._converter_funcs[bl_light.type](bl_light, pl_light)
# Light color nonsense # Light color nonsense
@ -188,7 +181,7 @@ class LightConverter:
continue continue
# This is probably where PermaLight vs PermaProj should be sorted out... # This is probably where PermaLight vs PermaProj should be sorted out...
pl_light = self._create_light_key(obj, lamp, None) pl_light = self.get_light_key(obj, lamp, None)
if self._is_projection_lamp(lamp): if self._is_projection_lamp(lamp):
print(" [{}] PermaProj '{}'".format(lamp.type, obj.name)) print(" [{}] PermaProj '{}'".format(lamp.type, obj.name))
permaProj.append(pl_light) permaProj.append(pl_light)
@ -200,6 +193,13 @@ class LightConverter:
return (permaLights, permaProjs) return (permaLights, permaProjs)
def get_light_key(self, bo, bl_light, so):
try:
xlate = _BL2PL[bl_light.type]
return self.mgr.find_create_key(xlate, bl=bo, so=so)
except LookupError:
raise BlenderOptionNotSupported("Object ('{}') lamp type '{}'".format(bo.name, bl_light.type))
def _is_projection_lamp(self, bl_light): def _is_projection_lamp(self, bl_light):
for tex in bl_light.texture_slots: for tex in bl_light.texture_slots:
if tex is None or tex.texture is None: if tex is None or tex.texture is None:

81
korman/properties/modifiers/render.py

@ -172,6 +172,87 @@ class PlasmaViewFaceMod(PlasmaModifierProperties):
def requires_actor(self): def requires_actor(self):
return True return True
class PlasmaVisControl(PlasmaModifierProperties):
pl_id = "visregion"
bl_category = "Render"
bl_label = "Visibility Control"
bl_description = "Controls object visibility using VisRegions"
mode = EnumProperty(name="Mode",
description="Purpose of the VisRegion",
items=[("normal", "Normal", "Objects are only visible when the camera is inside this region"),
("exclude", "Exclude", "Objects are only visible when the camera is outside this region"),
("fx", "Special FX", "This is a list of objects used for special effects only")])
softvolume = StringProperty(name="Region",
description="Object defining the SoftVolume for this VisRegion")
replace_normal = BoolProperty(name="Hide Drawables",
description="Hides drawables attached to this region",
default=True)
def export(self, exporter, bo, so):
rgn = exporter.mgr.find_create_object(plVisRegion, bl=bo, so=so)
rgn.setProperty(plVisRegion.kReplaceNormal, self.replace_normal)
if self.mode == "fx":
rgn.setProperty(plVisRegion.kDisable, True)
else:
this_sv = bo.plasma_modifiers.softvolume
if this_sv.enabled:
print(" [VisRegion] I'm a SoftVolume myself :)")
rgn.region = this_sv.get_key(exporter, so)
else:
print(" [VisRegion] SoftVolume '{}'".format(self.softvolume))
sv_bo = bpy.data.objects.get(self.softvolume, None)
if sv_bo is None:
raise ExportError("'{}': Invalid object '{}' for VisControl soft volume".format(bo.name, self.softvolume))
sv = sv_bo.plasma_modifiers.softvolume
if not sv.enabled:
raise ExportError("'{}': '{}' is not a SoftVolume".format(bo.name, self.softvolume))
rgn.region = sv.get_key(exporter)
rgn.setProperty(plVisRegion.kIsNot, self.mode == "exclude")
class VisRegion(bpy.types.PropertyGroup):
enabled = BoolProperty(default=True)
region_name = StringProperty(name="Control",
description="Object defining a Plasma Visibility Control")
class PlasmaVisibilitySet(PlasmaModifierProperties):
pl_id = "visibility"
bl_category = "Render"
bl_label = "Visibility Set"
bl_description = "Defines areas where this object is visible"
regions = CollectionProperty(name="Visibility Regions",
type=VisRegion)
active_region_index = IntProperty(options={"HIDDEN"})
def export(self, exporter, bo, so):
if not self.regions:
# TODO: Log message about how this modifier is totally worthless
return
# Currently, this modifier is valid for meshes and lamps
if bo.type == "MESH":
diface = exporter.mgr.find_create_object(plDrawInterface, bl=bo, so=so)
addRegion = diface.addRegion
elif bo.type == "LAMP":
light = exporter.light.get_light_key(bo, bo.data, so)
addRegion = light.object.addVisRegion
for region in self.regions:
if not region.enabled:
continue
rgn_bo = bpy.data.objects.get(region.region_name, None)
if rgn_bo is None:
raise ExportError("{}: Invalid VisControl '{}' in VisSet modifier".format(bo.name, region.region_name))
addRegion(exporter.mgr.find_create_key(plVisRegion, bl=rgn_bo))
class PlasmaFollowMod(PlasmaModifierProperties): class PlasmaFollowMod(PlasmaModifierProperties):
pl_id = "followmod" pl_id = "followmod"

35
korman/ui/modifiers/render.py

@ -56,6 +56,41 @@ def viewfacemod(modifier, layout, context):
col.enabled = modifier.offset col.enabled = modifier.offset
col.prop(modifier, "offset_coord") col.prop(modifier, "offset_coord")
class VisRegionListUI(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_property, index=0, flt_flag=0):
myIcon = "ERROR" if bpy.data.objects.get(item.region_name, None) is None else "OBJECT_DATA"
label = item.region_name if item.region_name else "[No Object Specified]"
layout.label(label, icon=myIcon)
layout.prop(item, "enabled", text="")
def visibility(modifier, layout, context):
row = layout.row()
row.template_list("VisRegionListUI", "regions", modifier, "regions", modifier, "active_region_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "regions"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "regions"
op.index = modifier.active_region_index
if modifier.regions:
layout.prop_search(modifier.regions[modifier.active_region_index], "region_name", bpy.data, "objects")
def visregion(modifier, layout, context):
layout.prop(modifier, "mode")
# Only allow SoftVolume spec if this is not an FX and this object is not an SV itself
sv = modifier.id_data.plasma_modifiers.softvolume
if modifier.mode != "fx" and not sv.enabled:
layout.prop_search(modifier, "softvolume", bpy.data, "objects")
# Other settings
layout.prop(modifier, "replace_normal")
def followmod(modifier, layout, context): def followmod(modifier, layout, context):
layout.row().prop(modifier, "follow_mode", expand=True) layout.row().prop(modifier, "follow_mode", expand=True)
layout.prop(modifier, "leader_type") layout.prop(modifier, "leader_type")

Loading…
Cancel
Save