2017-04-08 00:34:45 +02:00
|
|
|
import bpy.types
|
|
|
|
from bpy.props import *
|
2017-03-06 02:29:03 +01:00
|
|
|
from nodeitems_utils import NodeItem
|
2017-12-04 13:22:09 +01:00
|
|
|
import arm.utils
|
2017-03-06 02:29:03 +01:00
|
|
|
|
|
|
|
nodes = []
|
|
|
|
category_items = {}
|
2017-04-10 21:17:17 +02:00
|
|
|
category_items['Logic'] = []
|
2017-03-06 02:29:03 +01:00
|
|
|
category_items['Event'] = []
|
2017-04-10 21:17:17 +02:00
|
|
|
category_items['Action'] = []
|
2017-03-06 02:29:03 +01:00
|
|
|
category_items['Value'] = []
|
2017-04-10 21:17:17 +02:00
|
|
|
category_items['Variable'] = []
|
2017-04-08 00:34:45 +02:00
|
|
|
category_items['Input'] = []
|
2017-11-02 23:28:21 +01:00
|
|
|
category_items['Array'] = []
|
2017-04-10 21:17:17 +02:00
|
|
|
category_items['Animation'] = []
|
2017-04-04 23:11:31 +02:00
|
|
|
category_items['Physics'] = []
|
|
|
|
category_items['Navmesh'] = []
|
2017-04-08 00:34:45 +02:00
|
|
|
category_items['Sound'] = []
|
2017-04-10 21:17:17 +02:00
|
|
|
category_items['Native'] = []
|
2018-01-31 00:31:07 +01:00
|
|
|
category_items['Canvas'] = []
|
2017-04-08 00:34:45 +02:00
|
|
|
|
|
|
|
object_sockets = dict()
|
|
|
|
array_nodes = dict()
|
2017-03-06 02:29:03 +01:00
|
|
|
|
|
|
|
class ArmLogicTreeNode:
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, ntree):
|
|
|
|
return ntree.bl_idname == 'ArmLogicTreeType'
|
|
|
|
|
2017-04-08 20:05:35 +02:00
|
|
|
class ArmActionSocket(bpy.types.NodeSocket):
|
|
|
|
bl_idname = 'ArmNodeSocketAction'
|
|
|
|
bl_label = 'Action Socket'
|
2017-04-08 00:34:45 +02:00
|
|
|
|
|
|
|
def draw(self, context, layout, node, text):
|
|
|
|
layout.label(self.name)
|
|
|
|
|
|
|
|
def draw_color(self, context, node):
|
|
|
|
return (0.8, 0.3, 0.3, 1)
|
|
|
|
|
|
|
|
class ArmObjectSocket(bpy.types.NodeSocket):
|
|
|
|
bl_idname = 'ArmNodeSocketObject'
|
|
|
|
bl_label = 'Object Socket'
|
|
|
|
default_value = StringProperty(name='Object', default='')
|
|
|
|
|
2017-12-04 13:22:09 +01:00
|
|
|
def get_default_value(self):
|
|
|
|
if self.default_value == '':
|
|
|
|
return ''
|
2017-12-06 12:36:39 +01:00
|
|
|
if self.default_value not in bpy.data.objects:
|
|
|
|
return self.default_value
|
2017-12-04 13:22:09 +01:00
|
|
|
return arm.utils.asset_name(bpy.data.objects[self.default_value])
|
|
|
|
|
2017-04-08 00:34:45 +02:00
|
|
|
def __init__(self):
|
|
|
|
global object_sockets
|
|
|
|
# Buckle up..
|
|
|
|
# Match id strings to socket dict to retrieve socket in eyedropper operator
|
|
|
|
object_sockets[str(id(self))] = self
|
|
|
|
|
|
|
|
def draw(self, context, layout, node, text):
|
|
|
|
if self.is_output:
|
|
|
|
layout.label(self.name)
|
2017-04-16 14:46:35 +02:00
|
|
|
elif self.is_linked:
|
|
|
|
layout.label(self.name)
|
2017-04-08 00:34:45 +02:00
|
|
|
else:
|
2017-04-16 14:46:35 +02:00
|
|
|
row = layout.row(align=True)
|
2017-04-08 00:34:45 +02:00
|
|
|
row.prop_search(self, 'default_value', bpy.context.scene, 'objects', icon='NONE', text='')
|
|
|
|
op = row.operator('arm.node_eyedrop', text='', icon='EYEDROPPER', emboss=True)
|
|
|
|
op.socket_index = str(id(self))
|
|
|
|
|
|
|
|
def draw_color(self, context, node):
|
|
|
|
return (0.15, 0.55, 0.75, 1)
|
|
|
|
|
|
|
|
class ArmNodeEyedropButton(bpy.types.Operator):
|
|
|
|
'''Pick selected object'''
|
|
|
|
bl_idname = 'arm.node_eyedrop'
|
|
|
|
bl_label = 'Eyedrop'
|
|
|
|
socket_index = StringProperty(name='Socket Index', default='')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global object_sockets
|
|
|
|
obj = bpy.context.active_object
|
|
|
|
if obj != None:
|
|
|
|
object_sockets[self.socket_index].default_value = obj.name
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-09-08 13:57:34 +02:00
|
|
|
class ArmAnimActionSocket(bpy.types.NodeSocket):
|
|
|
|
bl_idname = 'ArmNodeSocketAnimAction'
|
|
|
|
bl_label = 'Action Socket'
|
|
|
|
default_value = StringProperty(name='Action', default='')
|
|
|
|
|
2017-12-04 13:22:09 +01:00
|
|
|
def get_default_value(self):
|
2017-12-06 12:36:39 +01:00
|
|
|
if self.default_value == '':
|
|
|
|
return ''
|
|
|
|
if self.default_value not in bpy.data.actions:
|
|
|
|
return self.default_value
|
2017-12-04 13:22:09 +01:00
|
|
|
name = arm.utils.asset_name(bpy.data.actions[self.default_value])
|
|
|
|
return arm.utils.safestr(name)
|
|
|
|
|
2017-09-08 13:57:34 +02:00
|
|
|
def draw(self, context, layout, node, text):
|
|
|
|
if self.is_output:
|
|
|
|
layout.label(self.name)
|
|
|
|
elif self.is_linked:
|
|
|
|
layout.label(self.name)
|
|
|
|
else:
|
|
|
|
layout.prop_search(self, 'default_value', bpy.data, 'actions', icon='NONE', text='')
|
|
|
|
|
|
|
|
def draw_color(self, context, node):
|
|
|
|
return (0.8, 0.8, 0.8, 1)
|
|
|
|
|
2017-04-08 00:34:45 +02:00
|
|
|
class ArmNodeAddInputButton(bpy.types.Operator):
|
|
|
|
'''Add new input'''
|
|
|
|
bl_idname = 'arm.node_add_input'
|
|
|
|
bl_label = 'Add Input'
|
|
|
|
node_index = StringProperty(name='Node Index', default='')
|
|
|
|
socket_type = StringProperty(name='Socket Type', default='NodeSocketShader')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global array_nodes
|
2017-04-11 11:28:22 +02:00
|
|
|
inps = array_nodes[self.node_index].inputs
|
|
|
|
inps.new(self.socket_type, 'Input ' + str(len(inps)))
|
2017-04-08 00:34:45 +02:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
class ArmNodeRemoveInputButton(bpy.types.Operator):
|
|
|
|
'''Remove last input'''
|
|
|
|
bl_idname = 'arm.node_remove_input'
|
|
|
|
bl_label = 'Remove Input'
|
|
|
|
node_index = StringProperty(name='Node Index', default='')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global array_nodes
|
2018-02-26 03:43:06 +01:00
|
|
|
node = array_nodes[self.node_index]
|
|
|
|
inps = node.inputs
|
|
|
|
min_inps = 0 if not hasattr(node, 'min_inputs') else node.min_inputs
|
|
|
|
if len(inps) > min_inps:
|
2017-04-08 00:34:45 +02:00
|
|
|
inps.remove(inps.values()[-1])
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-04-11 11:28:22 +02:00
|
|
|
class ArmNodeAddOutputButton(bpy.types.Operator):
|
|
|
|
'''Add new output'''
|
|
|
|
bl_idname = 'arm.node_add_output'
|
|
|
|
bl_label = 'Add Output'
|
|
|
|
node_index = StringProperty(name='Node Index', default='')
|
|
|
|
socket_type = StringProperty(name='Socket Type', default='NodeSocketShader')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global array_nodes
|
|
|
|
outs = array_nodes[self.node_index].outputs
|
|
|
|
outs.new(self.socket_type, 'Output ' + str(len(outs)))
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
class ArmNodeRemoveOutputButton(bpy.types.Operator):
|
|
|
|
'''Remove last output'''
|
|
|
|
bl_idname = 'arm.node_remove_output'
|
|
|
|
bl_label = 'Remove Output'
|
|
|
|
node_index = StringProperty(name='Node Index', default='')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global array_nodes
|
|
|
|
outs = array_nodes[self.node_index].outputs
|
|
|
|
if len(outs) > 0:
|
|
|
|
outs.remove(outs.values()[-1])
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
def add_node(node_class, category):
|
2017-04-08 00:34:45 +02:00
|
|
|
global nodes
|
|
|
|
nodes.append(node_class)
|
|
|
|
category_items[category].append(NodeItem(node_class.bl_idname))
|
|
|
|
|
2017-04-08 20:05:35 +02:00
|
|
|
bpy.utils.register_class(ArmActionSocket)
|
2017-04-08 00:34:45 +02:00
|
|
|
bpy.utils.register_class(ArmObjectSocket)
|
|
|
|
bpy.utils.register_class(ArmNodeEyedropButton)
|
2017-09-08 13:57:34 +02:00
|
|
|
bpy.utils.register_class(ArmAnimActionSocket)
|
2017-04-08 00:34:45 +02:00
|
|
|
bpy.utils.register_class(ArmNodeAddInputButton)
|
|
|
|
bpy.utils.register_class(ArmNodeRemoveInputButton)
|
2017-04-11 11:28:22 +02:00
|
|
|
bpy.utils.register_class(ArmNodeAddOutputButton)
|
|
|
|
bpy.utils.register_class(ArmNodeRemoveOutputButton)
|