2016-06-30 13:22:05 +02:00
|
|
|
import bpy
|
|
|
|
import json
|
|
|
|
import os
|
2016-07-10 00:51:39 +02:00
|
|
|
import glob
|
2016-07-20 17:33:17 +02:00
|
|
|
import lib.umsgpack
|
2016-08-12 02:29:09 +02:00
|
|
|
import platform
|
2016-06-30 13:22:05 +02:00
|
|
|
|
2016-07-20 17:33:17 +02:00
|
|
|
def write_arm(filepath, output):
|
2016-09-02 23:11:04 +02:00
|
|
|
if bpy.data.worlds['Arm'].ArmMinimize:
|
2016-07-20 17:33:17 +02:00
|
|
|
with open(filepath, 'wb') as f:
|
|
|
|
f.write(lib.umsgpack.dumps(output))
|
|
|
|
else:
|
|
|
|
with open(filepath, 'w') as f:
|
|
|
|
# f.write(json.dumps(output, separators=(',',':')))
|
|
|
|
f.write(json.dumps(output, sort_keys=True, indent=4))
|
2016-06-30 13:22:05 +02:00
|
|
|
|
|
|
|
def get_fp():
|
|
|
|
s = bpy.data.filepath.split(os.path.sep)
|
|
|
|
s.pop()
|
|
|
|
return os.path.sep.join(s)
|
|
|
|
|
2016-08-12 02:29:09 +02:00
|
|
|
def get_os():
|
|
|
|
s = platform.system()
|
|
|
|
if s == 'Windows':
|
|
|
|
return 'win'
|
|
|
|
elif s == 'Darwin':
|
|
|
|
return 'mac'
|
|
|
|
else:
|
|
|
|
return 'linux'
|
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def fetch_script_names():
|
|
|
|
user_preferences = bpy.context.user_preferences
|
|
|
|
addon_prefs = user_preferences.addons['armory'].preferences
|
|
|
|
sdk_path = addon_prefs.sdk_path
|
2016-09-02 23:11:04 +02:00
|
|
|
wrd = bpy.data.worlds['Arm']
|
2016-07-10 00:51:39 +02:00
|
|
|
wrd.bundled_scripts_list.clear()
|
|
|
|
os.chdir(sdk_path + '/armory/Sources/armory/trait')
|
|
|
|
for file in glob.glob('*.hx'):
|
|
|
|
wrd.bundled_scripts_list.add().name = file.rsplit('.')[0]
|
|
|
|
wrd.scripts_list.clear()
|
2016-08-15 01:59:49 +02:00
|
|
|
sources_path = get_fp() + '/Sources/' + wrd.ArmProjectPackage
|
2016-07-10 00:51:39 +02:00
|
|
|
if os.path.isdir(sources_path):
|
|
|
|
os.chdir(sources_path)
|
|
|
|
for file in glob.glob('*.hx'):
|
|
|
|
wrd.scripts_list.add().name = file.rsplit('.')[0]
|
|
|
|
os.chdir(get_fp())
|
2016-07-17 23:29:30 +02:00
|
|
|
|
|
|
|
def to_hex(val):
|
|
|
|
return '#%02x%02x%02x%02x' % (int(val[3] * 255), int(val[0] * 255), int(val[1] * 255), int(val[2] * 255))
|
2016-07-27 14:25:01 +02:00
|
|
|
|
2016-09-02 23:11:04 +02:00
|
|
|
def color_to_int(val):
|
|
|
|
return (int(val[3] * 255) << 24) + (int(val[0] * 255) << 16) + (int(val[1] * 255) << 8) + int(val[2] * 255)
|
|
|
|
|
2016-07-27 14:25:01 +02:00
|
|
|
def safe_filename(s):
|
2016-09-14 11:49:32 +02:00
|
|
|
# s = s.replace('.', '_').replace('-', '_').replace(' ', '_')
|
|
|
|
# if s[0].isdigit(): # Prefix _ if first char is digit
|
|
|
|
# s = '_' + s
|
2016-08-22 21:56:28 +02:00
|
|
|
return s
|
|
|
|
|
|
|
|
def safe_assetpath(s):
|
|
|
|
return s[2:] # Remove leading '//'
|
|
|
|
|
2016-09-14 11:49:32 +02:00
|
|
|
def extract_filename(s):
|
|
|
|
return s.rsplit('/', 1)[1]
|
|
|
|
|
|
|
|
# def extract_filename_noext(s):
|
|
|
|
# return s.rsplit('/', 1)[1].rsplit('.', 1)[0] # Extract file name without extension
|
2016-08-15 23:45:03 +02:00
|
|
|
|
|
|
|
def get_render_resolution(scene_index=0):
|
|
|
|
render = bpy.data.scenes[scene_index].render
|
|
|
|
scale = render.resolution_percentage / 100
|
|
|
|
return int(render.resolution_x * scale), int(render.resolution_y * scale)
|
2016-09-08 14:08:31 +02:00
|
|
|
|
|
|
|
def get_project_scene_name():
|
|
|
|
wrd = bpy.data.worlds['Arm']
|
|
|
|
if wrd.ArmPlayActiveScene:
|
|
|
|
return safe_filename(bpy.context.screen.scene.name)
|
|
|
|
else:
|
|
|
|
return safe_filename(wrd.ArmProjectScene)
|
2016-09-12 02:24:20 +02:00
|
|
|
|
|
|
|
def with_chromium():
|
|
|
|
return with_chromium.module_found
|
|
|
|
with_chromium.module_found = False
|
|
|
|
|
|
|
|
def register():
|
|
|
|
import importlib.util
|
|
|
|
if importlib.util.find_spec('bgame') != None:
|
|
|
|
with_chromium.module_found = True
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
pass
|