2020-08-10 00:19:15 +02:00
|
|
|
import json
|
|
|
|
import os
|
2015-10-30 13:23:09 +01:00
|
|
|
import shutil
|
2017-03-15 12:30:14 +01:00
|
|
|
import subprocess
|
2018-03-25 12:00:43 +02:00
|
|
|
import webbrowser
|
2020-08-10 00:19:15 +02:00
|
|
|
|
|
|
|
from bpy.types import NodeTree
|
2018-11-13 14:51:02 +01:00
|
|
|
import bpy.utils.previews
|
2020-08-10 00:19:15 +02:00
|
|
|
|
|
|
|
import arm.make as make
|
2017-07-24 02:27:22 +02:00
|
|
|
from arm.props_traits_props import *
|
2020-08-10 00:23:26 +02:00
|
|
|
import arm.proxy as proxy
|
2017-03-15 12:30:14 +01:00
|
|
|
import arm.utils
|
|
|
|
import arm.write_data as write_data
|
2020-08-10 00:19:15 +02:00
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-10-19 10:10:20 +02:00
|
|
|
def trigger_recompile(self, context):
|
|
|
|
wrd = bpy.data.worlds['Arm']
|
|
|
|
wrd.arm_recompile = True
|
|
|
|
|
2017-12-11 00:55:26 +01:00
|
|
|
def update_trait_group(self, context):
|
2019-01-28 22:52:29 +01:00
|
|
|
o = context.object if self.is_object else context.scene
|
2017-12-11 00:55:26 +01:00
|
|
|
if o == None:
|
|
|
|
return
|
|
|
|
i = o.arm_traitlist_index
|
|
|
|
if i >= 0 and i < len(o.arm_traitlist):
|
|
|
|
t = o.arm_traitlist[i]
|
2017-12-11 19:00:32 +01:00
|
|
|
if t.type_prop == 'Haxe Script' or t.type_prop == 'Bundled Script':
|
2017-12-11 00:55:26 +01:00
|
|
|
t.name = t.class_name_prop
|
|
|
|
elif t.type_prop == 'WebAssembly':
|
|
|
|
t.name = t.webassembly_prop
|
|
|
|
elif t.type_prop == 'UI Canvas':
|
|
|
|
t.name = t.canvas_name_prop
|
|
|
|
elif t.type_prop == 'Logic Nodes':
|
2019-01-04 20:13:29 +01:00
|
|
|
if t.node_tree_prop != None:
|
|
|
|
t.name = t.node_tree_prop.name
|
2017-12-11 19:00:32 +01:00
|
|
|
# Fetch props
|
|
|
|
if t.type_prop == 'Bundled Script' and t.name != '':
|
|
|
|
file_path = arm.utils.get_sdk_path() + '/armory/Sources/armory/trait/' + t.name + '.hx'
|
|
|
|
if os.path.exists(file_path):
|
|
|
|
arm.utils.fetch_script_props(file_path)
|
|
|
|
arm.utils.fetch_prop(o)
|
2019-02-05 12:59:34 +01:00
|
|
|
# Show trait users as collections
|
2019-02-05 13:04:27 +01:00
|
|
|
if self.is_object:
|
|
|
|
for col in bpy.data.collections:
|
|
|
|
if col.name.startswith('Trait|') and o.name in col.objects:
|
|
|
|
col.objects.unlink(o)
|
|
|
|
for t in o.arm_traitlist:
|
|
|
|
if 'Trait|' + t.name not in bpy.data.collections:
|
|
|
|
col = bpy.data.collections.new('Trait|' + t.name)
|
|
|
|
else:
|
|
|
|
col = bpy.data.collections['Trait|' + t.name]
|
2020-08-10 00:18:27 +02:00
|
|
|
try:
|
|
|
|
col.objects.link(o)
|
|
|
|
except RuntimeError:
|
|
|
|
# Object is already in that collection. This can
|
|
|
|
# happen when multiple same traits are copied with
|
|
|
|
# bpy.ops.arm.copy_traits_to_active
|
|
|
|
pass
|
2016-07-10 00:51:39 +02:00
|
|
|
|
2017-12-11 00:55:26 +01:00
|
|
|
class ArmTraitListItem(bpy.types.PropertyGroup):
|
2018-12-18 23:48:38 +01:00
|
|
|
name: StringProperty(name="Name", description="A name for this item", default="")
|
|
|
|
enabled_prop: BoolProperty(name="", description="A name for this item", default=True, update=trigger_recompile)
|
2019-01-28 22:52:29 +01:00
|
|
|
is_object: BoolProperty(name="", default=True)
|
2020-04-10 20:43:59 +02:00
|
|
|
fake_user: BoolProperty(name="Fake User", description="Export this trait even if it is deactivated", default=False)
|
2018-12-18 23:48:38 +01:00
|
|
|
type_prop: EnumProperty(
|
2018-03-15 23:24:48 +01:00
|
|
|
items = [('Haxe Script', 'Haxe', 'Haxe Script'),
|
2018-04-17 12:23:55 +02:00
|
|
|
('WebAssembly', 'Wasm', 'WebAssembly'),
|
2018-03-15 23:24:48 +01:00
|
|
|
('UI Canvas', 'UI', 'UI Canvas'),
|
|
|
|
('Bundled Script', 'Bundled', 'Bundled Script'),
|
|
|
|
('Logic Nodes', 'Nodes', 'Logic Nodes')
|
2017-08-21 12:17:55 +02:00
|
|
|
],
|
|
|
|
name = "Type")
|
2018-12-18 23:48:38 +01:00
|
|
|
class_name_prop: StringProperty(name="Class", description="A name for this item", default="", update=update_trait_group)
|
|
|
|
canvas_name_prop: StringProperty(name="Canvas", description="A name for this item", default="", update=update_trait_group)
|
|
|
|
webassembly_prop: StringProperty(name="Module", description="A name for this item", default="", update=update_trait_group)
|
2019-01-04 20:13:29 +01:00
|
|
|
node_tree_prop: PointerProperty(type=NodeTree, update=update_trait_group)
|
2018-12-18 23:48:38 +01:00
|
|
|
arm_traitpropslist: CollectionProperty(type=ArmTraitPropListItem)
|
|
|
|
arm_traitpropslist_index: IntProperty(name="Index for my_list", default=0)
|
2020-01-07 13:15:21 +01:00
|
|
|
arm_traitpropswarnings: CollectionProperty(type=ArmTraitPropWarning)
|
2017-08-21 12:17:55 +02:00
|
|
|
|
2019-03-29 14:55:42 +01:00
|
|
|
class ARM_UL_TraitList(bpy.types.UIList):
|
2015-10-30 13:23:09 +01:00
|
|
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
2018-11-13 14:51:02 +01:00
|
|
|
custom_icon = "NONE"
|
|
|
|
custom_icon_value = 0
|
|
|
|
if item.type_prop == "Haxe Script":
|
|
|
|
custom_icon_value = icons_dict["haxe"].icon_id
|
|
|
|
elif item.type_prop == "WebAssembly":
|
|
|
|
custom_icon_value = icons_dict["wasm"].icon_id
|
|
|
|
elif item.type_prop == "UI Canvas":
|
2018-12-19 13:33:17 +01:00
|
|
|
custom_icon = "OBJECT_DATAMODE"
|
2018-11-13 14:51:02 +01:00
|
|
|
elif item.type_prop == "Bundled Script":
|
2020-10-25 05:51:16 +01:00
|
|
|
custom_icon_value = icons_dict["bundle"].icon_id
|
2018-11-13 14:51:02 +01:00
|
|
|
elif item.type_prop == "Logic Nodes":
|
|
|
|
custom_icon = 'NODETREE'
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
# Make sure your code supports all 3 layout types
|
|
|
|
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
|
|
|
layout.prop(item, "enabled_prop")
|
2020-04-10 20:43:59 +02:00
|
|
|
# Display " " for props without a name to right-align the
|
|
|
|
# fake_user button
|
|
|
|
layout.label(text=item.name if item.name != "" else " ", icon=custom_icon, icon_value=custom_icon_value)
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
elif self.layout_type in {'GRID'}:
|
|
|
|
layout.alignment = 'CENTER'
|
2018-11-13 14:51:02 +01:00
|
|
|
layout.label(text="", icon=custom_icon, icon_value=custom_icon_value)
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2020-04-10 20:43:59 +02:00
|
|
|
layout.prop(item, "fake_user", text="", icon="FAKE_USER_ON" if item.fake_user else "FAKE_USER_OFF")
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmTraitListNewItem(bpy.types.Operator):
|
|
|
|
bl_idname = "arm_traitlist.new_item"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_label = "New Trait Item"
|
|
|
|
bl_description = "Add a new trait item to the list"
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2020-08-04 14:19:09 +02:00
|
|
|
is_object: BoolProperty(name="Object Trait", description="Whether this is an object or scene trait", default=False)
|
2018-12-18 23:48:38 +01:00
|
|
|
type_prop: EnumProperty(
|
2018-11-13 14:51:02 +01:00
|
|
|
items = [('Haxe Script', 'Haxe', 'Haxe Script'),
|
|
|
|
('WebAssembly', 'Wasm', 'WebAssembly'),
|
|
|
|
('UI Canvas', 'UI', 'UI Canvas'),
|
|
|
|
('Bundled Script', 'Bundled', 'Bundled Script'),
|
|
|
|
('Logic Nodes', 'Nodes', 'Logic Nodes')
|
|
|
|
],
|
|
|
|
name = "Type")
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
wm = context.window_manager
|
|
|
|
return wm.invoke_props_dialog(self)
|
|
|
|
|
2020-08-04 14:19:09 +02:00
|
|
|
def draw(self, context):
|
2018-11-13 14:51:02 +01:00
|
|
|
layout = self.layout
|
2020-08-04 14:19:09 +02:00
|
|
|
# Todo: show is_object property when called from operator search menu
|
|
|
|
# layout.prop(self, "is_object")
|
2018-11-13 14:51:02 +01:00
|
|
|
layout.prop(self, "type_prop", expand=True)
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
def execute(self, context):
|
2017-08-26 18:41:36 +02:00
|
|
|
if self.is_object:
|
|
|
|
obj = bpy.context.object
|
2017-08-27 12:50:09 +02:00
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2017-08-26 18:41:36 +02:00
|
|
|
trait = obj.arm_traitlist.add()
|
2019-01-28 22:52:29 +01:00
|
|
|
trait.is_object = self.is_object
|
2018-11-13 14:51:02 +01:00
|
|
|
trait.type_prop = self.type_prop
|
2017-08-26 18:41:36 +02:00
|
|
|
obj.arm_traitlist_index = len(obj.arm_traitlist) - 1
|
2017-10-19 10:10:20 +02:00
|
|
|
trigger_recompile(None, None)
|
2015-10-30 13:23:09 +01:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmTraitListDeleteItem(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Delete the selected item from the list"""
|
2017-08-21 12:17:55 +02:00
|
|
|
bl_idname = "arm_traitlist.delete_item"
|
2015-10-30 13:23:09 +01:00
|
|
|
bl_label = "Deletes an item"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_options = {'INTERNAL'}
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
@classmethod
|
|
|
|
def poll(self, context):
|
|
|
|
""" Enable if there's something in the list """
|
2017-09-06 13:28:59 +02:00
|
|
|
obj = bpy.context.object
|
2017-08-26 18:41:36 +02:00
|
|
|
if obj == None:
|
2017-08-22 12:08:44 +02:00
|
|
|
return False
|
2017-08-26 18:41:36 +02:00
|
|
|
return len(obj.arm_traitlist) > 0
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2017-09-06 13:28:59 +02:00
|
|
|
obj = bpy.context.object
|
|
|
|
lst = obj.arm_traitlist
|
2017-08-26 18:41:36 +02:00
|
|
|
index = obj.arm_traitlist_index
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-09-06 13:28:59 +02:00
|
|
|
if len(lst) <= index:
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
lst.remove(index)
|
2017-12-11 00:55:26 +01:00
|
|
|
update_trait_group(self, context)
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
if index > 0:
|
|
|
|
index = index - 1
|
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
obj.arm_traitlist_index = index
|
2015-10-30 13:23:09 +01:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-09-06 13:28:59 +02:00
|
|
|
class ArmTraitListDeleteItemScene(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Delete the selected item from the list"""
|
2017-09-06 13:28:59 +02:00
|
|
|
bl_idname = "arm_traitlist.delete_item_scene"
|
|
|
|
bl_label = "Deletes an item"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_options = {'INTERNAL'}
|
2017-09-06 13:28:59 +02:00
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2017-09-06 13:28:59 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(self, context):
|
|
|
|
""" Enable if there's something in the list """
|
|
|
|
obj = bpy.context.scene
|
|
|
|
if obj == None:
|
|
|
|
return False
|
|
|
|
return len(obj.arm_traitlist) > 0
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
obj = bpy.context.scene
|
|
|
|
lst = obj.arm_traitlist
|
|
|
|
index = obj.arm_traitlist_index
|
|
|
|
|
|
|
|
if len(lst) <= index:
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
lst.remove(index)
|
|
|
|
|
|
|
|
if index > 0:
|
|
|
|
index = index - 1
|
|
|
|
|
|
|
|
obj.arm_traitlist_index = index
|
|
|
|
return{'FINISHED'}
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmTraitListMoveItem(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Move an item in the list"""
|
2017-08-21 12:17:55 +02:00
|
|
|
bl_idname = "arm_traitlist.move_item"
|
2015-10-30 13:23:09 +01:00
|
|
|
bl_label = "Move an item in the list"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_options = {'INTERNAL'}
|
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
direction: EnumProperty(
|
2015-10-30 13:23:09 +01:00
|
|
|
items=(
|
|
|
|
('UP', 'Up', ""),
|
|
|
|
('DOWN', 'Down', ""),))
|
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
def move_index(self):
|
|
|
|
# Move index of an item render queue while clamping it
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
2017-08-26 18:41:36 +02:00
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
|
|
|
index = obj.arm_traitlist_index
|
|
|
|
list_length = len(obj.arm_traitlist) - 1
|
2015-10-30 13:23:09 +01:00
|
|
|
new_index = 0
|
|
|
|
|
|
|
|
if self.direction == 'UP':
|
|
|
|
new_index = index - 1
|
|
|
|
elif self.direction == 'DOWN':
|
|
|
|
new_index = index + 1
|
|
|
|
|
|
|
|
new_index = max(0, min(new_index, list_length))
|
2018-11-20 22:13:58 +01:00
|
|
|
obj.arm_traitlist.move(index, new_index)
|
|
|
|
obj.arm_traitlist_index = new_index
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
2017-08-26 18:41:36 +02:00
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
|
|
|
list = obj.arm_traitlist
|
|
|
|
index = obj.arm_traitlist_index
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
if self.direction == 'DOWN':
|
|
|
|
neighbor = index + 1
|
|
|
|
self.move_index()
|
|
|
|
|
|
|
|
elif self.direction == 'UP':
|
|
|
|
neighbor = index - 1
|
|
|
|
self.move_index()
|
|
|
|
else:
|
|
|
|
return{'CANCELLED'}
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmEditScriptButton(bpy.types.Operator):
|
2016-07-10 00:51:39 +02:00
|
|
|
bl_idname = 'arm.edit_script'
|
|
|
|
bl_label = 'Edit Script'
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_description = 'Edit script in the text editor'
|
|
|
|
bl_options = {'INTERNAL'}
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def execute(self, context):
|
2018-08-07 08:56:48 +02:00
|
|
|
|
2019-01-17 21:36:42 +01:00
|
|
|
arm.utils.check_default_props()
|
|
|
|
|
2020-10-31 01:41:53 +01:00
|
|
|
if not os.path.exists(os.path.join(arm.utils.get_fp(), "khafile.js")):
|
2019-09-11 21:04:09 +02:00
|
|
|
print('Generating Krom project for IDE build configuration')
|
2019-01-17 21:36:42 +01:00
|
|
|
make.build('krom')
|
2018-08-07 08:56:48 +02:00
|
|
|
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
2017-08-26 18:41:36 +02:00
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2019-09-11 21:04:09 +02:00
|
|
|
|
2017-08-27 12:50:09 +02:00
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
2017-05-13 17:17:43 +02:00
|
|
|
pkg = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package)
|
2019-01-31 13:37:54 +01:00
|
|
|
# Replace the haxe package syntax with the os-dependent path syntax for opening
|
2020-10-31 01:41:53 +01:00
|
|
|
hx_path = os.path.join(arm.utils.get_fp(), 'Sources', pkg, item.class_name_prop.replace('.', os.sep) + '.hx')
|
2019-09-11 21:04:09 +02:00
|
|
|
arm.utils.open_editor(hx_path)
|
2016-07-10 00:51:39 +02:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmEditBundledScriptButton(bpy.types.Operator):
|
2017-02-24 21:29:49 +01:00
|
|
|
bl_idname = 'arm.edit_bundled_script'
|
|
|
|
bl_label = 'Edit Script'
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_description = 'Copy script to project and edit in the text editor'
|
|
|
|
bl_options = {'INTERNAL'}
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-02-24 21:29:49 +01:00
|
|
|
def execute(self, context):
|
2018-08-07 08:56:48 +02:00
|
|
|
if not arm.utils.check_saved(self):
|
|
|
|
return {'CANCELLED'}
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2017-03-15 12:30:14 +01:00
|
|
|
sdk_path = arm.utils.get_sdk_path()
|
|
|
|
project_path = arm.utils.get_fp()
|
2017-05-13 17:17:43 +02:00
|
|
|
pkg = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package)
|
2019-06-23 12:56:32 +02:00
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
2020-10-31 01:41:53 +01:00
|
|
|
source_hx_path = os.path.join(sdk_path , 'armory', 'Sources', 'armory', 'trait', item.class_name_prop + '.hx')
|
|
|
|
target_hx_path = os.path.join(project_path, 'Sources', pkg, item.class_name_prop + '.hx')
|
2017-02-24 21:29:49 +01:00
|
|
|
|
|
|
|
if not os.path.isfile(target_hx_path):
|
|
|
|
# Rewrite package and copy
|
2020-10-18 17:50:35 +02:00
|
|
|
sf = open(source_hx_path, encoding="utf-8")
|
2017-02-24 21:29:49 +01:00
|
|
|
sf.readline()
|
2020-10-18 17:50:35 +02:00
|
|
|
tf = open(target_hx_path, 'w', encoding="utf-8")
|
2017-02-24 21:29:49 +01:00
|
|
|
tf.write('package ' + pkg + ';\n')
|
|
|
|
shutil.copyfileobj(sf, tf)
|
|
|
|
sf.close()
|
|
|
|
tf.close()
|
2017-03-15 12:30:14 +01:00
|
|
|
arm.utils.fetch_script_names()
|
2017-02-24 21:29:49 +01:00
|
|
|
|
|
|
|
# From bundled to script
|
|
|
|
item.type_prop = 'Haxe Script'
|
|
|
|
|
2020-10-31 01:41:53 +01:00
|
|
|
# Open the trait in the code editor
|
2017-09-10 21:47:00 +02:00
|
|
|
bpy.ops.arm.edit_script('EXEC_DEFAULT', is_object=self.is_object)
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-02-24 21:29:49 +01:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
class ArmoryGenerateNavmeshButton(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Generate navmesh from selected meshes"""
|
2019-08-07 17:02:36 +02:00
|
|
|
bl_idname = 'arm.generate_navmesh'
|
|
|
|
bl_label = 'Generate Navmesh'
|
2020-02-22 17:41:39 +01:00
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
def execute(self, context):
|
|
|
|
obj = context.active_object
|
2019-09-11 20:58:53 +02:00
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
if obj.type != 'MESH':
|
|
|
|
return{'CANCELLED'}
|
|
|
|
|
2019-08-11 16:49:06 +02:00
|
|
|
if not arm.utils.check_saved(self):
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
if not arm.utils.check_sdkpath(self):
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
2019-10-14 00:46:22 +02:00
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
armature = obj.find_armature()
|
|
|
|
apply_modifiers = not armature
|
|
|
|
|
|
|
|
obj_eval = obj.evaluated_get(depsgraph) if apply_modifiers else obj
|
2020-02-22 17:41:39 +01:00
|
|
|
export_mesh = obj_eval.to_mesh()
|
2019-08-07 17:02:36 +02:00
|
|
|
# TODO: build tilecache here
|
2019-08-11 16:49:06 +02:00
|
|
|
print("Started visualization generation")
|
2019-08-07 17:02:36 +02:00
|
|
|
# For visualization
|
|
|
|
nav_full_path = arm.utils.get_fp_build() + '/compiled/Assets/navigation'
|
|
|
|
if not os.path.exists(nav_full_path):
|
|
|
|
os.makedirs(nav_full_path)
|
2019-12-15 15:33:37 +01:00
|
|
|
|
2019-10-14 00:46:22 +02:00
|
|
|
nav_mesh_name = 'nav_' + obj_eval.data.name
|
2019-08-07 17:02:36 +02:00
|
|
|
mesh_path = nav_full_path + '/' + nav_mesh_name + '.obj'
|
2019-09-11 20:58:53 +02:00
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
with open(mesh_path, 'w') as f:
|
2020-02-22 17:41:39 +01:00
|
|
|
for v in export_mesh.vertices:
|
2019-10-14 00:46:22 +02:00
|
|
|
f.write("v %.4f " % (v.co[0] * obj_eval.scale.x))
|
|
|
|
f.write("%.4f " % (v.co[2] * obj_eval.scale.z))
|
|
|
|
f.write("%.4f\n" % (v.co[1] * obj_eval.scale.y)) # Flipped
|
2020-02-22 17:41:39 +01:00
|
|
|
for p in export_mesh.polygons:
|
2019-08-07 17:02:36 +02:00
|
|
|
f.write("f")
|
|
|
|
for i in reversed(p.vertices): # Flipped normals
|
|
|
|
f.write(" %d" % (i + 1))
|
|
|
|
f.write("\n")
|
2019-09-11 20:58:53 +02:00
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
buildnavjs_path = arm.utils.get_sdk_path() + '/lib/haxerecast/buildnavjs'
|
|
|
|
|
|
|
|
# append config values
|
|
|
|
nav_config = {}
|
2020-02-22 17:41:39 +01:00
|
|
|
for trait in obj.arm_traitlist:
|
2019-08-07 17:02:36 +02:00
|
|
|
# check if trait is navmesh here
|
2020-02-22 17:41:39 +01:00
|
|
|
if trait.arm_traitpropslist and trait.class_name_prop == 'NavMesh':
|
|
|
|
for prop in trait.arm_traitpropslist: # Append props
|
|
|
|
name = prop.name
|
2020-02-22 17:57:29 +01:00
|
|
|
value = prop.get_value()
|
2019-08-07 17:02:36 +02:00
|
|
|
nav_config[name] = value
|
|
|
|
nav_config_json = json.dumps(nav_config)
|
|
|
|
|
2019-10-14 00:46:22 +02:00
|
|
|
args = [arm.utils.get_node_path(), buildnavjs_path, nav_mesh_name, nav_config_json]
|
|
|
|
proc = subprocess.Popen(args, cwd=nav_full_path)
|
2019-08-07 17:02:36 +02:00
|
|
|
proc.wait()
|
|
|
|
|
|
|
|
navmesh = bpy.ops.import_scene.obj(filepath=mesh_path)
|
|
|
|
navmesh = bpy.context.selected_objects[0]
|
|
|
|
|
|
|
|
navmesh.name = nav_mesh_name
|
2020-02-22 17:41:39 +01:00
|
|
|
navmesh.rotation_euler = (0, 0, 0)
|
|
|
|
navmesh.location = (obj.location.x, obj.location.y, obj.location.z)
|
2019-08-07 17:02:36 +02:00
|
|
|
navmesh.arm_export = False
|
2019-09-11 20:58:53 +02:00
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
bpy.context.view_layer.objects.active = navmesh
|
|
|
|
bpy.ops.object.editmode_toggle()
|
|
|
|
bpy.ops.mesh.select_all(action='SELECT')
|
|
|
|
bpy.ops.mesh.remove_doubles()
|
|
|
|
bpy.ops.object.editmode_toggle()
|
|
|
|
|
2019-10-14 00:46:22 +02:00
|
|
|
obj_eval.to_mesh_clear()
|
|
|
|
|
2019-08-11 16:49:06 +02:00
|
|
|
print("Finished visualization generation")
|
|
|
|
|
2019-08-07 17:02:36 +02:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmEditCanvasButton(bpy.types.Operator):
|
2017-05-26 16:05:14 +02:00
|
|
|
bl_idname = 'arm.edit_canvas'
|
|
|
|
bl_label = 'Edit Canvas'
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_description = 'Edit UI Canvas'
|
|
|
|
bl_options = {'INTERNAL'}
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
is_object: BoolProperty(name="", description="A name for this item", default=False)
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-05-26 16:05:14 +02:00
|
|
|
def execute(self, context):
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2017-05-26 16:05:14 +02:00
|
|
|
project_path = arm.utils.get_fp()
|
2017-08-27 12:50:09 +02:00
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
2017-05-26 16:05:14 +02:00
|
|
|
canvas_path = project_path + '/Bundled/canvas/' + item.canvas_name_prop + '.json'
|
|
|
|
sdk_path = arm.utils.get_sdk_path()
|
2019-07-15 09:21:23 +02:00
|
|
|
ext = 'd3d11' if arm.utils.get_os() == 'win' else 'opengl'
|
|
|
|
armory2d_path = sdk_path + '/lib/armory_tools/armory2d/' + ext
|
|
|
|
krom_location, krom_path = arm.utils.krom_paths()
|
2017-07-25 17:37:46 +02:00
|
|
|
os.chdir(krom_location)
|
2018-07-02 10:29:16 +02:00
|
|
|
cpath = canvas_path.replace('\\', '/')
|
|
|
|
uiscale = str(arm.utils.get_ui_scale())
|
2019-12-15 15:33:37 +01:00
|
|
|
cmd = [krom_path, armory2d_path, armory2d_path, cpath, uiscale]
|
|
|
|
if arm.utils.get_os() == 'win':
|
|
|
|
cmd.append('--consolepid')
|
|
|
|
cmd.append(str(os.getpid()))
|
|
|
|
subprocess.Popen(cmd)
|
2017-05-26 16:05:14 +02:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmNewScriptDialog(bpy.types.Operator):
|
2016-07-10 00:51:39 +02:00
|
|
|
bl_idname = "arm.new_script"
|
|
|
|
bl_label = "New Script"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_description = 'Create a blank script'
|
|
|
|
bl_options = {'INTERNAL'}
|
2019-06-23 12:57:39 +02:00
|
|
|
|
2019-06-23 16:58:06 +02:00
|
|
|
is_object: BoolProperty(name="Object trait", description="Is this an object trait?", default=False)
|
2019-06-23 12:57:39 +02:00
|
|
|
class_name: StringProperty(name="Name", description="The class name")
|
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def execute(self, context):
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2016-07-10 00:51:39 +02:00
|
|
|
self.class_name = self.class_name.replace(' ', '')
|
|
|
|
write_data.write_traithx(self.class_name)
|
2017-03-15 12:30:14 +01:00
|
|
|
arm.utils.fetch_script_names()
|
2019-06-23 12:56:32 +02:00
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
item.class_name_prop = self.class_name
|
2016-07-10 00:51:39 +02:00
|
|
|
return {'FINISHED'}
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def invoke(self, context, event):
|
2017-03-15 12:30:14 +01:00
|
|
|
if not arm.utils.check_saved(self):
|
2016-12-08 14:38:04 +01:00
|
|
|
return {'CANCELLED'}
|
2016-07-10 00:51:39 +02:00
|
|
|
self.class_name = 'MyTrait'
|
|
|
|
return context.window_manager.invoke_props_dialog(self)
|
|
|
|
|
2019-06-23 12:57:39 +02:00
|
|
|
def draw(self, context):
|
|
|
|
self.layout.prop(self, "class_name")
|
|
|
|
|
2020-09-11 11:18:31 +02:00
|
|
|
class ArmNewTreeNodeDialog(bpy.types.Operator):
|
|
|
|
bl_idname = "arm.new_treenode"
|
|
|
|
bl_label = "New Node Tree"
|
|
|
|
bl_description = 'Create a blank Node Tree'
|
|
|
|
bl_options = {'INTERNAL'}
|
|
|
|
|
|
|
|
is_object: BoolProperty(name="Object Node Tree", description="Is this an object Node Tree?", default=False)
|
|
|
|
class_name: StringProperty(name="Name", description="The Node Tree name")
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
if self.is_object:
|
|
|
|
obj = context.object
|
|
|
|
else:
|
|
|
|
obj = context.scene
|
|
|
|
self.class_name = self.class_name.replace(' ', '')
|
|
|
|
# Create new node tree
|
|
|
|
node_tree = bpy.data.node_groups.new(self.class_name, 'ArmLogicTreeType')
|
|
|
|
# Set new node tree
|
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
if item.node_tree_prop is None:
|
|
|
|
item.node_tree_prop = node_tree
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
if not arm.utils.check_saved(self):
|
|
|
|
return {'CANCELLED'}
|
|
|
|
self.class_name = 'MyNodeTree'
|
|
|
|
return context.window_manager.invoke_props_dialog(self)
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
self.layout.prop(self, "class_name")
|
2020-10-18 17:50:35 +02:00
|
|
|
|
2020-09-11 11:18:31 +02:00
|
|
|
class ArmEditTreeNodeDialog(bpy.types.Operator):
|
|
|
|
bl_idname = "arm.edit_treenode"
|
|
|
|
bl_label = "Edit Node Tree"
|
|
|
|
bl_description = 'Edit this Node Tree in the Logic Node Editor'
|
|
|
|
bl_options = {'INTERNAL'}
|
|
|
|
|
|
|
|
is_object: BoolProperty(name="Object Node Tree", description="Is this an object Node Tree?", default=False)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
if self.is_object:
|
|
|
|
obj = context.object
|
|
|
|
else:
|
|
|
|
obj = context.scene
|
|
|
|
# Check len node tree list
|
|
|
|
if len(obj.arm_traitlist) > 0:
|
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
# Loop for all spaces
|
|
|
|
context_screen = context.screen
|
|
|
|
if item is not None and context_screen is not None:
|
|
|
|
areas = context_screen.areas
|
|
|
|
for area in areas:
|
|
|
|
for space in area.spaces:
|
|
|
|
if space.type == 'NODE_EDITOR':
|
|
|
|
if space.tree_type == 'ArmLogicTreeType':
|
|
|
|
# Set Node Tree
|
|
|
|
space.node_tree = item.node_tree_prop
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
class ArmGetTreeNodeDialog(bpy.types.Operator):
|
|
|
|
bl_idname = "arm.get_treenode"
|
|
|
|
bl_label = "From Node Editor"
|
|
|
|
bl_description = 'Use the Node Tree from the opened Node Tree Editor for this trait'
|
|
|
|
bl_options = {'INTERNAL'}
|
|
|
|
|
|
|
|
is_object: BoolProperty(name="Object Node Tree", description="Is this an object Node Tree?", default=False)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
if self.is_object:
|
|
|
|
obj = context.object
|
|
|
|
else:
|
|
|
|
obj = context.scene
|
|
|
|
# Check len node tree list
|
|
|
|
if len(obj.arm_traitlist) > 0:
|
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
# Loop for all spaces
|
|
|
|
context_screen = context.screen
|
|
|
|
if item is not None and context_screen is not None:
|
|
|
|
areas = context_screen.areas
|
|
|
|
for area in areas:
|
|
|
|
for space in area.spaces:
|
|
|
|
if space.type == 'NODE_EDITOR':
|
|
|
|
if space.tree_type == 'ArmLogicTreeType' and space.node_tree is not None:
|
|
|
|
# Set Node Tree in Item
|
|
|
|
item.node_tree_prop = space.node_tree
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmNewCanvasDialog(bpy.types.Operator):
|
2017-05-26 16:05:14 +02:00
|
|
|
bl_idname = "arm.new_canvas"
|
|
|
|
bl_label = "New Canvas"
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_description = 'Create a blank canvas'
|
|
|
|
bl_options = {'INTERNAL'}
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2019-06-23 16:58:06 +02:00
|
|
|
is_object: BoolProperty(name="Object trait", description="Is this an object trait?", default=False)
|
2019-06-23 14:51:44 +02:00
|
|
|
canvas_name: StringProperty(name="Name", description="The canvas name")
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-05-26 16:05:14 +02:00
|
|
|
def execute(self, context):
|
2017-08-27 12:50:09 +02:00
|
|
|
if self.is_object:
|
|
|
|
obj = bpy.context.object
|
|
|
|
else:
|
|
|
|
obj = bpy.context.scene
|
2017-05-26 16:05:14 +02:00
|
|
|
self.canvas_name = self.canvas_name.replace(' ', '')
|
|
|
|
write_data.write_canvasjson(self.canvas_name)
|
|
|
|
arm.utils.fetch_script_names()
|
2020-08-04 14:30:05 +02:00
|
|
|
# Todo: create new trait item when called from operator search
|
|
|
|
# menu, then remove 'INTERNAL' from bl_options
|
2019-06-23 12:56:32 +02:00
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
item.canvas_name_prop = self.canvas_name
|
2017-05-26 16:05:14 +02:00
|
|
|
return {'FINISHED'}
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-05-26 16:05:14 +02:00
|
|
|
def invoke(self, context, event):
|
|
|
|
if not arm.utils.check_saved(self):
|
|
|
|
return {'CANCELLED'}
|
|
|
|
self.canvas_name = 'MyCanvas'
|
|
|
|
return context.window_manager.invoke_props_dialog(self)
|
|
|
|
|
2019-06-23 14:51:44 +02:00
|
|
|
def draw(self, context):
|
|
|
|
self.layout.prop(self, "canvas_name")
|
|
|
|
|
2018-04-15 11:55:42 +02:00
|
|
|
class ArmNewWasmButton(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Create new WebAssembly module"""
|
2018-04-15 11:55:42 +02:00
|
|
|
bl_idname = 'arm.new_wasm'
|
|
|
|
bl_label = 'New Module'
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2018-04-15 11:55:42 +02:00
|
|
|
def execute(self, context):
|
|
|
|
webbrowser.open('https://webassembly.studio/')
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmRefreshScriptsButton(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Fetch all script names"""
|
2017-08-08 19:56:47 +02:00
|
|
|
bl_idname = 'arm.refresh_scripts'
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_label = 'Refresh Traits'
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def execute(self, context):
|
2017-03-15 12:30:14 +01:00
|
|
|
arm.utils.fetch_bundled_script_names()
|
2017-12-11 19:00:32 +01:00
|
|
|
arm.utils.fetch_bundled_trait_props()
|
2017-03-15 12:30:14 +01:00
|
|
|
arm.utils.fetch_script_names()
|
2017-07-24 02:27:22 +02:00
|
|
|
arm.utils.fetch_trait_props()
|
2018-04-15 11:55:42 +02:00
|
|
|
arm.utils.fetch_wasm_names()
|
2016-07-10 00:51:39 +02:00
|
|
|
return{'FINISHED'}
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmRefreshCanvasListButton(bpy.types.Operator):
|
2020-08-04 14:19:09 +02:00
|
|
|
"""Fetch all canvas names"""
|
2017-05-26 16:05:14 +02:00
|
|
|
bl_idname = 'arm.refresh_canvas_list'
|
2020-08-04 14:19:09 +02:00
|
|
|
bl_label = 'Refresh Canvas Traits'
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-05-26 16:05:14 +02:00
|
|
|
def execute(self, context):
|
|
|
|
arm.utils.fetch_script_names()
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2019-03-29 14:55:42 +01:00
|
|
|
class ARM_PT_TraitPanel(bpy.types.Panel):
|
2016-07-10 00:51:39 +02:00
|
|
|
bl_label = "Armory Traits"
|
2015-10-30 13:23:09 +01:00
|
|
|
bl_space_type = "PROPERTIES"
|
|
|
|
bl_region_type = "WINDOW"
|
|
|
|
bl_context = "object"
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
2018-12-19 13:33:17 +01:00
|
|
|
layout.use_property_split = True
|
2018-12-19 20:10:34 +01:00
|
|
|
layout.use_property_decorate = False
|
2015-10-30 13:23:09 +01:00
|
|
|
obj = bpy.context.object
|
2017-08-26 18:41:36 +02:00
|
|
|
draw_traits(layout, obj, is_object=True)
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2019-03-29 14:55:42 +01:00
|
|
|
class ARM_PT_SceneTraitPanel(bpy.types.Panel):
|
2019-03-01 09:55:54 +01:00
|
|
|
bl_label = "Armory Scene Traits"
|
2017-08-26 18:41:36 +02:00
|
|
|
bl_space_type = "PROPERTIES"
|
|
|
|
bl_region_type = "WINDOW"
|
|
|
|
bl_context = "scene"
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
def draw(self, context):
|
2018-12-19 13:33:17 +01:00
|
|
|
layout = self.layout
|
|
|
|
layout.use_property_split = True
|
2018-12-19 20:10:34 +01:00
|
|
|
layout.use_property_decorate = False
|
2017-08-26 18:41:36 +02:00
|
|
|
obj = bpy.context.scene
|
|
|
|
draw_traits(layout, obj, is_object=False)
|
|
|
|
|
2020-08-10 00:23:26 +02:00
|
|
|
class ARM_OT_CopyTraitsFromActive(bpy.types.Operator):
|
|
|
|
bl_label = 'Copy Traits from Active Object'
|
|
|
|
bl_idname = 'arm.copy_traits_to_active'
|
|
|
|
bl_description = 'Copies the traits of the active object to all other selected objects'
|
|
|
|
|
|
|
|
overwrite: BoolProperty(name="Overwrite", default=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return context.active_object is not None and len(context.selected_objects) > 1
|
|
|
|
|
|
|
|
def draw_message_box(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
layout = layout.column(align=True)
|
|
|
|
layout.alignment = 'EXPAND'
|
|
|
|
|
2020-08-10 14:39:21 +02:00
|
|
|
layout.label(text='Warning: At least one target object already has', icon='ERROR')
|
2020-08-10 00:23:26 +02:00
|
|
|
layout.label(text='traits assigned to it!', icon='BLANK1')
|
|
|
|
layout.separator()
|
|
|
|
layout.label(text='Do you want to overwrite the already existing traits', icon='BLANK1')
|
|
|
|
layout.label(text='or append to them?', icon='BLANK1')
|
|
|
|
layout.separator()
|
|
|
|
|
|
|
|
row = layout.row(align=True)
|
|
|
|
row.active_default = True
|
|
|
|
row.operator('arm.copy_traits_to_active', text='Overwrite').overwrite = True
|
|
|
|
row.active_default = False
|
|
|
|
row.operator('arm.copy_traits_to_active', text='Append').overwrite = False
|
|
|
|
row.operator('arm.discard_popup', text='Cancel')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
source_obj = bpy.context.active_object
|
|
|
|
|
|
|
|
for target_obj in bpy.context.selected_objects:
|
|
|
|
if source_obj == target_obj:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Offset for trait iteration when appending traits
|
|
|
|
offset = 0
|
|
|
|
if not self.overwrite:
|
|
|
|
offset = len(target_obj.arm_traitlist)
|
|
|
|
|
|
|
|
# Make use of proxy functions here
|
|
|
|
proxy.sync_collection(
|
|
|
|
source_obj.arm_traitlist, target_obj.arm_traitlist, clear_dst=self.overwrite)
|
|
|
|
|
|
|
|
for i in range(len(source_obj.arm_traitlist)):
|
|
|
|
proxy.sync_collection(
|
|
|
|
source_obj.arm_traitlist[i].arm_traitpropslist,
|
|
|
|
target_obj.arm_traitlist[i + offset].arm_traitpropslist
|
|
|
|
)
|
|
|
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
show_dialog = False
|
|
|
|
|
|
|
|
# Test if there is a target object which has traits that would
|
|
|
|
# get overwritten
|
|
|
|
source_obj = bpy.context.active_object
|
|
|
|
for target_object in bpy.context.selected_objects:
|
|
|
|
if source_obj == target_object:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if target_object.arm_traitlist:
|
|
|
|
show_dialog = True
|
|
|
|
|
|
|
|
if show_dialog:
|
|
|
|
context.window_manager.popover(self.__class__.draw_message_box, ui_units_x=16)
|
|
|
|
else:
|
|
|
|
bpy.ops.arm.copy_traits_to_active()
|
|
|
|
|
|
|
|
return {'INTERFACE'}
|
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
def draw_traits(layout, obj, is_object):
|
|
|
|
rows = 2
|
|
|
|
if len(obj.arm_traitlist) > 1:
|
|
|
|
rows = 4
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
row = layout.row()
|
2019-03-29 14:55:42 +01:00
|
|
|
row.template_list("ARM_UL_TraitList", "The_List", obj, "arm_traitlist", obj, "arm_traitlist_index", rows=rows)
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
col = row.column(align=True)
|
2018-12-18 23:48:38 +01:00
|
|
|
op = col.operator("arm_traitlist.new_item", icon='ADD', text="")
|
2017-08-26 18:41:36 +02:00
|
|
|
op.is_object = is_object
|
2017-09-06 13:28:59 +02:00
|
|
|
if is_object:
|
2018-12-18 23:48:38 +01:00
|
|
|
op = col.operator("arm_traitlist.delete_item", icon='REMOVE', text="")#.all = False
|
2017-09-06 13:28:59 +02:00
|
|
|
else:
|
2018-12-18 23:48:38 +01:00
|
|
|
op = col.operator("arm_traitlist.delete_item_scene", icon='REMOVE', text="")#.all = False
|
2017-08-26 18:41:36 +02:00
|
|
|
op.is_object = is_object
|
|
|
|
|
|
|
|
if len(obj.arm_traitlist) > 1:
|
|
|
|
col.separator()
|
2017-09-01 15:24:46 +02:00
|
|
|
op = col.operator("arm_traitlist.move_item", icon='TRIA_UP', text="")
|
|
|
|
op.direction = 'UP'
|
2017-08-26 18:41:36 +02:00
|
|
|
op.is_object = is_object
|
2017-09-01 15:24:46 +02:00
|
|
|
op = col.operator("arm_traitlist.move_item", icon='TRIA_DOWN', text="")
|
|
|
|
op.direction = 'DOWN'
|
2017-08-26 18:41:36 +02:00
|
|
|
op.is_object = is_object
|
|
|
|
|
|
|
|
if obj.arm_traitlist_index >= 0 and len(obj.arm_traitlist) > 0:
|
|
|
|
item = obj.arm_traitlist[obj.arm_traitlist_index]
|
|
|
|
|
2020-04-10 20:44:35 +02:00
|
|
|
if item.type_prop == 'Haxe Script' or item.type_prop == 'Bundled Script':
|
2017-08-26 18:41:36 +02:00
|
|
|
if item.type_prop == 'Haxe Script':
|
2017-08-09 00:14:30 +02:00
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
2017-08-26 18:41:36 +02:00
|
|
|
if item.class_name_prop == '':
|
2017-08-09 00:14:30 +02:00
|
|
|
column.enabled = False
|
2018-03-15 23:24:48 +01:00
|
|
|
op = column.operator("arm.edit_script", icon="FILE_SCRIPT")
|
2017-08-27 12:50:09 +02:00
|
|
|
op.is_object = is_object
|
|
|
|
op = row.operator("arm.new_script")
|
|
|
|
op.is_object = is_object
|
2020-08-04 14:19:09 +02:00
|
|
|
op = row.operator("arm.refresh_scripts", text="Refresh")
|
2017-08-26 18:41:36 +02:00
|
|
|
else: # Bundled
|
2019-08-07 17:02:36 +02:00
|
|
|
if item.class_name_prop == 'NavMesh':
|
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
op = layout.operator("arm.generate_navmesh")
|
2017-12-11 19:00:32 +01:00
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
2019-08-07 17:02:36 +02:00
|
|
|
if not item.class_name_prop == 'NavMesh':
|
|
|
|
op = column.operator("arm.edit_bundled_script", icon="FILE_SCRIPT")
|
|
|
|
op.is_object = is_object
|
2020-08-04 14:19:09 +02:00
|
|
|
op = row.operator("arm.refresh_scripts", text="Refresh")
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2020-04-10 20:44:35 +02:00
|
|
|
# Default props
|
|
|
|
item.name = item.class_name_prop
|
|
|
|
row = layout.row()
|
|
|
|
if item.type_prop == 'Haxe Script':
|
|
|
|
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_scripts_list", text="Class")
|
|
|
|
else:
|
|
|
|
# Bundled scripts not yet fetched
|
|
|
|
if not bpy.data.worlds['Arm'].arm_bundled_scripts_list:
|
|
|
|
arm.utils.fetch_bundled_script_names()
|
|
|
|
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_bundled_scripts_list", text="Class")
|
|
|
|
|
2017-09-20 14:45:09 +02:00
|
|
|
elif item.type_prop == 'WebAssembly':
|
2018-04-15 11:55:42 +02:00
|
|
|
item.name = item.webassembly_prop
|
|
|
|
row = layout.row()
|
2018-09-05 10:20:02 +02:00
|
|
|
row.prop_search(item, "webassembly_prop", bpy.data.worlds['Arm'], "arm_wasm_list", text="Module")
|
2018-04-15 11:55:42 +02:00
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
|
|
|
if item.class_name_prop == '':
|
|
|
|
column.enabled = False
|
|
|
|
# op = column.operator("arm.edit_script", icon="FILE_SCRIPT")
|
|
|
|
# op.is_object = is_object
|
|
|
|
op = row.operator("arm.new_wasm")
|
|
|
|
# op.is_object = is_object
|
2020-08-04 14:19:09 +02:00
|
|
|
op = row.operator("arm.refresh_scripts", text="Refresh")
|
2017-05-26 16:05:14 +02:00
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
elif item.type_prop == 'UI Canvas':
|
|
|
|
item.name = item.canvas_name_prop
|
2019-06-23 12:56:32 +02:00
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
|
|
|
if item.canvas_name_prop == '':
|
|
|
|
column.enabled = False
|
2018-03-15 23:24:48 +01:00
|
|
|
op = column.operator("arm.edit_canvas", icon="FILE_SCRIPT")
|
2017-08-27 12:50:09 +02:00
|
|
|
op.is_object = is_object
|
|
|
|
op = row.operator("arm.new_canvas")
|
|
|
|
op.is_object = is_object
|
2020-08-04 14:19:09 +02:00
|
|
|
op = row.operator("arm.refresh_canvas_list", text="Refresh")
|
2017-08-26 18:41:36 +02:00
|
|
|
|
2020-04-10 20:44:35 +02:00
|
|
|
row = layout.row()
|
|
|
|
row.prop_search(item, "canvas_name_prop", bpy.data.worlds['Arm'], "arm_canvas_list", text="Canvas")
|
|
|
|
|
2017-08-26 18:41:36 +02:00
|
|
|
elif item.type_prop == 'Logic Nodes':
|
2020-09-11 11:18:31 +02:00
|
|
|
# Row for buttons
|
|
|
|
row = layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
# New
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
|
|
|
op = column.operator("arm.new_treenode", text="New Node Tree", icon="ADD")
|
|
|
|
op.is_object = is_object
|
|
|
|
# At least one check is active Logic Node Editor
|
2020-10-18 17:50:35 +02:00
|
|
|
is_check_logic_node_editor = False
|
2020-09-11 11:18:31 +02:00
|
|
|
context_screen = bpy.context.screen
|
|
|
|
# Loop for all spaces
|
|
|
|
if context_screen is not None:
|
|
|
|
areas = context_screen.areas
|
|
|
|
for area in areas:
|
|
|
|
for space in area.spaces:
|
|
|
|
if space.type == 'NODE_EDITOR':
|
|
|
|
if space.tree_type == 'ArmLogicTreeType' and space.node_tree is not None:
|
|
|
|
is_check_logic_node_editor = True
|
|
|
|
break
|
|
|
|
if is_check_logic_node_editor:
|
|
|
|
break
|
|
|
|
# Edit
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
|
|
|
if item.node_tree_prop is None:
|
|
|
|
column.enabled = False
|
|
|
|
else:
|
|
|
|
column.enabled = is_check_logic_node_editor
|
|
|
|
op = column.operator("arm.edit_treenode", text="Edit Node Tree", icon="NODETREE")
|
|
|
|
op.is_object = is_object
|
|
|
|
# Get from Node Tree Editor
|
|
|
|
column = row.column(align=True)
|
|
|
|
column.alignment = 'EXPAND'
|
|
|
|
if item is None:
|
|
|
|
column.enabled = False
|
|
|
|
else:
|
2020-10-18 17:50:35 +02:00
|
|
|
column.enabled = is_check_logic_node_editor
|
2020-09-11 11:18:31 +02:00
|
|
|
op = column.operator("arm.get_treenode", text="From Node Editor", icon="IMPORT")
|
|
|
|
op.is_object = is_object
|
|
|
|
|
|
|
|
# Row for search
|
2017-08-26 18:41:36 +02:00
|
|
|
row = layout.row()
|
2018-12-21 23:16:20 +01:00
|
|
|
row.prop_search(item, "node_tree_prop", bpy.data, "node_groups", text="Tree")
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2020-04-10 20:44:35 +02:00
|
|
|
if item.type_prop == 'Haxe Script' or item.type_prop == 'Bundled Script':
|
|
|
|
# Props
|
|
|
|
if item.arm_traitpropslist:
|
|
|
|
layout.label(text="Trait Properties:")
|
|
|
|
if item.arm_traitpropswarnings:
|
|
|
|
box = layout.box()
|
|
|
|
box.label(text=f"Warnings ({len(item.arm_traitpropswarnings)}):", icon="ERROR")
|
|
|
|
|
|
|
|
for warning in item.arm_traitpropswarnings:
|
|
|
|
box.label(text=warning.warning)
|
|
|
|
|
|
|
|
propsrow = layout.row()
|
|
|
|
propsrows = max(len(item.arm_traitpropslist), 6)
|
|
|
|
row = layout.row()
|
|
|
|
row.template_list("ARM_UL_PropList", "The_List", item, "arm_traitpropslist", item, "arm_traitpropslist_index", rows=propsrows)
|
|
|
|
|
2018-11-13 14:51:02 +01:00
|
|
|
def register():
|
|
|
|
global icons_dict
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmTraitListItem)
|
2019-03-29 14:55:42 +01:00
|
|
|
bpy.utils.register_class(ARM_UL_TraitList)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmTraitListNewItem)
|
|
|
|
bpy.utils.register_class(ArmTraitListDeleteItem)
|
2017-09-06 13:28:59 +02:00
|
|
|
bpy.utils.register_class(ArmTraitListDeleteItemScene)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmTraitListMoveItem)
|
|
|
|
bpy.utils.register_class(ArmEditScriptButton)
|
|
|
|
bpy.utils.register_class(ArmEditBundledScriptButton)
|
2019-08-07 17:02:36 +02:00
|
|
|
bpy.utils.register_class(ArmoryGenerateNavmeshButton)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmEditCanvasButton)
|
|
|
|
bpy.utils.register_class(ArmNewScriptDialog)
|
2020-09-11 11:18:31 +02:00
|
|
|
bpy.utils.register_class(ArmNewTreeNodeDialog)
|
|
|
|
bpy.utils.register_class(ArmEditTreeNodeDialog)
|
|
|
|
bpy.utils.register_class(ArmGetTreeNodeDialog)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmNewCanvasDialog)
|
2018-04-15 11:55:42 +02:00
|
|
|
bpy.utils.register_class(ArmNewWasmButton)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmRefreshScriptsButton)
|
|
|
|
bpy.utils.register_class(ArmRefreshCanvasListButton)
|
2019-03-29 14:55:42 +01:00
|
|
|
bpy.utils.register_class(ARM_PT_TraitPanel)
|
|
|
|
bpy.utils.register_class(ARM_PT_SceneTraitPanel)
|
2020-08-10 00:23:26 +02:00
|
|
|
bpy.utils.register_class(ARM_OT_CopyTraitsFromActive)
|
|
|
|
|
2018-12-18 23:48:38 +01:00
|
|
|
bpy.types.Object.arm_traitlist = CollectionProperty(type=ArmTraitListItem)
|
|
|
|
bpy.types.Object.arm_traitlist_index = IntProperty(name="Index for arm_traitlist", default=0)
|
|
|
|
bpy.types.Scene.arm_traitlist = CollectionProperty(type=ArmTraitListItem)
|
|
|
|
bpy.types.Scene.arm_traitlist_index = IntProperty(name="Index for arm_traitlist", default=0)
|
2020-08-10 00:23:26 +02:00
|
|
|
|
2018-11-13 14:51:02 +01:00
|
|
|
icons_dict = bpy.utils.previews.new()
|
|
|
|
icons_dir = os.path.join(os.path.dirname(__file__), "custom_icons")
|
|
|
|
icons_dict.load("haxe", os.path.join(icons_dir, "haxe.png"), 'IMAGE')
|
|
|
|
icons_dict.load("wasm", os.path.join(icons_dir, "wasm.png"), 'IMAGE')
|
2020-10-25 05:51:16 +01:00
|
|
|
icons_dict.load("bundle", os.path.join(icons_dir, "bundle.png"), 'IMAGE')
|
2017-03-15 12:30:14 +01:00
|
|
|
|
2015-12-07 20:04:23 +01:00
|
|
|
def unregister():
|
2018-11-13 14:51:02 +01:00
|
|
|
global icons_dict
|
2020-08-10 00:23:26 +02:00
|
|
|
bpy.utils.unregister_class(ARM_OT_CopyTraitsFromActive)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmTraitListItem)
|
2019-03-29 14:55:42 +01:00
|
|
|
bpy.utils.unregister_class(ARM_UL_TraitList)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmTraitListNewItem)
|
|
|
|
bpy.utils.unregister_class(ArmTraitListDeleteItem)
|
2017-09-06 13:28:59 +02:00
|
|
|
bpy.utils.unregister_class(ArmTraitListDeleteItemScene)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmTraitListMoveItem)
|
|
|
|
bpy.utils.unregister_class(ArmEditScriptButton)
|
|
|
|
bpy.utils.unregister_class(ArmEditBundledScriptButton)
|
2019-08-07 17:02:36 +02:00
|
|
|
bpy.utils.unregister_class(ArmoryGenerateNavmeshButton)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmEditCanvasButton)
|
|
|
|
bpy.utils.unregister_class(ArmNewScriptDialog)
|
2020-09-11 11:18:31 +02:00
|
|
|
bpy.utils.unregister_class(ArmGetTreeNodeDialog)
|
|
|
|
bpy.utils.unregister_class(ArmEditTreeNodeDialog)
|
|
|
|
bpy.utils.unregister_class(ArmNewTreeNodeDialog)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmNewCanvasDialog)
|
2018-04-15 11:55:42 +02:00
|
|
|
bpy.utils.unregister_class(ArmNewWasmButton)
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmRefreshScriptsButton)
|
|
|
|
bpy.utils.unregister_class(ArmRefreshCanvasListButton)
|
2019-03-29 14:55:42 +01:00
|
|
|
bpy.utils.unregister_class(ARM_PT_TraitPanel)
|
|
|
|
bpy.utils.unregister_class(ARM_PT_SceneTraitPanel)
|
2018-11-13 14:51:02 +01:00
|
|
|
bpy.utils.previews.remove(icons_dict)
|