Browse Source

Ensure PFM-related lights are marked animated.

pull/230/head
Adam Johnson 4 years ago
parent
commit
39a3a88bb8
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 8
      korman/exporter/manager.py
  2. 48
      korman/nodes/node_python.py

8
korman/exporter/manager.py

@ -16,6 +16,7 @@
import bpy import bpy
from pathlib import Path from pathlib import Path
from PyHSPlasma import * from PyHSPlasma import *
from typing import Iterable
import weakref import weakref
from . import explosions from . import explosions
@ -190,6 +191,13 @@ class ExportManager:
else: else:
return plEncryptedStream.kEncXtea return plEncryptedStream.kEncXtea
def find_interfaces(self, pClass, so : plSceneObject) -> Iterable[plObjInterface]:
assert issubclass(pClass, plObjInterface)
for i in (i.object for i in so.interfaces):
if isinstance(i, pClass):
yield i
def find_create_key(self, pClass, bl=None, name=None, so=None): def find_create_key(self, pClass, bl=None, name=None, so=None):
key = self.find_key(pClass, bl, name, so) key = self.find_key(pClass, bl, name, so)
if key is None: if key is None:

48
korman/nodes/node_python.py

@ -256,6 +256,10 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
def export(self, exporter, bo, so): def export(self, exporter, bo, so):
pfm = self.get_key(exporter, so).object pfm = self.get_key(exporter, so).object
# Special PFM-SO handling ahoy - be sure to do it for all objects this PFM is attached to.
# Otherwise, you get non-determinant behavior.
self._export_ancillary_sceneobject(exporter, so)
# No need to continue if the PFM was already generated. # No need to continue if the PFM was already generated.
if pfm.filename: if pfm.filename:
return return
@ -276,7 +280,6 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
# Handle exporting the Python Parameters # Handle exporting the Python Parameters
attrib_sockets = (i for i in self.inputs if i.is_linked) attrib_sockets = (i for i in self.inputs if i.is_linked)
for socket in attrib_sockets: for socket in attrib_sockets:
attrib = socket.attribute_type
from_node = socket.links[0].from_node from_node = socket.links[0].from_node
value = from_node.value if socket.is_simple_value else from_node.get_key(exporter, so) value = from_node.value if socket.is_simple_value else from_node.get_key(exporter, so)
@ -285,26 +288,41 @@ class PlasmaPythonFileNode(PlasmaVersionedNode, bpy.types.Node):
for i in value: for i in value:
param = plPythonParameter() param = plPythonParameter()
param.id = socket.attribute_id param.id = socket.attribute_id
param.valueType = _attrib2param[attrib] param.valueType = _attrib2param[socket.attribute_type]
param.value = i param.value = i
# Key type sanity checking... Because I trust no user.
if not socket.is_simple_value: if not socket.is_simple_value:
if i is None: self._export_key_attrib(exporter, bo, so, i, socket)
msg = "'{}' Node '{}' didn't return a key and therefore will be unavailable to Python".format( pfm.addParameter(param)
self.id_data.name, from_node.name)
exporter.report.warn(msg, indent=3) def _export_ancillary_sceneobject(self, exporter, so : plSceneObject) -> None:
else: # Danger: Special case evil ahoy...
key_type = _attrib_key_types[attrib] # If the key is an object that represents a lamp, we have to assume that the reason it's
# being passed to Python is so it can be turned on/off at will. That means it's technically
# an animated lamp.
for light in exporter.mgr.find_interfaces(plLightInfo, so):
exporter.report.msg("Marking RT light '{}' as animated due to usage in a Python File node",
so.key.name, indent=3)
light.setProperty(plLightInfo.kLPMovable, True)
def _export_key_attrib(self, exporter, bo, so : plSceneObject, key : plKey, socket) -> None:
if key is None:
exporter.report.warn("Attribute '{}' didn't return a key and therefore will be unavailable to Python",
self.id_data.name, socket.links[0].name, indent=3)
return
key_type = _attrib_key_types[socket.attribute_type]
if isinstance(key_type, tuple): if isinstance(key_type, tuple):
good_key = i.type in key_type good_key = key.type in key_type
else: else:
good_key = i.type == key_type good_key = key.type == key_type
if not good_key: if not good_key:
msg = "'{}' Node '{}' returned an unexpected key type '{}'".format( exporter.report.warn("'{}' Node '{}' returned an unexpected key type '{}'",
self.id_data.name, from_node.name, plFactory.ClassName(i.type)) self.id_data.name, socket.links[0].from_node.name,
exporter.report.warn(msg, indent=3) plFactory.ClassName(key.type), indent=3)
pfm.addParameter(param)
if isinstance(key.object, plSceneObject):
self._export_ancillary_sceneobject(exporter, key.object)
def _get_attrib_sockets(self, idx): def _get_attrib_sockets(self, idx):
for i in self.inputs: for i in self.inputs:

Loading…
Cancel
Save