2016-10-19 13:28:06 +02:00
|
|
|
# Translating operators from/to Armory player
|
2017-10-04 11:31:24 +02:00
|
|
|
from mathutils import Matrix
|
2016-10-19 13:28:06 +02:00
|
|
|
import bpy
|
2017-03-15 12:30:14 +01:00
|
|
|
import arm.utils
|
2017-10-04 11:31:24 +02:00
|
|
|
import arm.make_state as state
|
2016-10-26 09:56:26 +02:00
|
|
|
try:
|
|
|
|
import barmory
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2016-10-19 13:28:06 +02:00
|
|
|
|
|
|
|
def parse_operator(text):
|
|
|
|
if text == None:
|
|
|
|
return
|
2016-11-23 15:34:59 +01:00
|
|
|
cmd = text.split('|')
|
|
|
|
# Reflect commands from Armory player in Blender
|
|
|
|
if cmd[0] == '__arm':
|
|
|
|
if cmd[1] == 'quit':
|
|
|
|
bpy.ops.arm.space_stop('EXEC_DEFAULT')
|
2017-10-04 11:31:24 +02:00
|
|
|
# Copy view matrix
|
|
|
|
if len(cmd) > 2 and bpy.data.worlds['Arm'].arm_play_camera == 'Viewport Shared':
|
|
|
|
arstr = cmd[2][1:-1] # Remove []
|
|
|
|
ar = arstr.split(',')
|
|
|
|
mat = [float(i) for i in ar]
|
|
|
|
set_view_mat(mat)
|
|
|
|
|
2016-11-23 15:34:59 +01:00
|
|
|
elif cmd[1] == 'setx':
|
|
|
|
bpy.context.scene.objects[cmd[2]].location.x = float(cmd[3])
|
|
|
|
elif cmd[1] == 'select':
|
2017-02-22 13:24:31 +01:00
|
|
|
if hasattr(bpy.context, 'object') and bpy.context.object != None:
|
2016-10-19 13:28:06 +02:00
|
|
|
bpy.context.object.select = False
|
2016-11-23 15:34:59 +01:00
|
|
|
bpy.context.scene.objects[cmd[2]].select = True
|
|
|
|
bpy.context.scene.objects.active = bpy.context.scene.objects[cmd[2]]
|
2016-10-19 13:28:06 +02:00
|
|
|
|
|
|
|
def send_operator(op):
|
|
|
|
# Try to translate operator directly to armory
|
2017-03-15 12:30:14 +01:00
|
|
|
if arm.utils.with_krom() and hasattr(bpy.context, 'object') and bpy.context.object != None:
|
2016-10-19 13:28:06 +02:00
|
|
|
objname = bpy.context.object.name
|
|
|
|
if op.name == 'Translate':
|
|
|
|
vec = bpy.context.object.location
|
|
|
|
js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.loc.set(' + str(vec[0]) + ', ' + str(vec[1]) + ', ' + str(vec[2]) + '); o.transform.dirty = true;'
|
|
|
|
barmory.call_js(js_source)
|
|
|
|
return True
|
|
|
|
elif op.name == 'Resize':
|
|
|
|
vec = bpy.context.object.scale
|
|
|
|
js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.scale.set(' + str(vec[0]) + ', ' + str(vec[1]) + ', ' + str(vec[2]) + '); o.transform.dirty = true;'
|
|
|
|
barmory.call_js(js_source)
|
|
|
|
return True
|
|
|
|
elif op.name == 'Rotate':
|
|
|
|
vec = bpy.context.object.rotation_euler.to_quaternion()
|
|
|
|
js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.rot.set(' + str(vec[1]) + ', ' + str(vec[2]) + ', ' + str(vec[3]) + ' ,' + str(vec[0]) + '); o.transform.dirty = true;'
|
|
|
|
barmory.call_js(js_source)
|
|
|
|
return True
|
|
|
|
return False
|
2017-10-04 11:31:24 +02:00
|
|
|
|
|
|
|
def set_view_mat(mat):
|
|
|
|
if state.play_area == None:
|
|
|
|
return
|
|
|
|
for space in state.play_area.spaces:
|
|
|
|
if space.type == 'VIEW_3D':
|
|
|
|
m = Matrix()
|
|
|
|
m[0][0] = mat[0]
|
|
|
|
m[0][1] = mat[1]
|
|
|
|
m[0][2] = mat[2]
|
|
|
|
m[0][3] = mat[3]
|
|
|
|
m[1][0] = mat[4]
|
|
|
|
m[1][1] = mat[5]
|
|
|
|
m[1][2] = mat[6]
|
|
|
|
m[1][3] = mat[7]
|
|
|
|
m[2][0] = mat[8]
|
|
|
|
m[2][1] = mat[9]
|
|
|
|
m[2][2] = mat[10]
|
|
|
|
m[2][3] = mat[11]
|
|
|
|
m[3][0] = mat[12]
|
|
|
|
m[3][1] = mat[13]
|
|
|
|
m[3][2] = mat[14]
|
|
|
|
m[3][3] = mat[15]
|
|
|
|
space.region_3d.view_matrix = m
|
|
|
|
break
|