2015-12-07 21:05:27 +01:00
|
|
|
import bpy
|
|
|
|
import os
|
2017-03-20 13:23:31 +01:00
|
|
|
import shutil
|
2017-03-15 12:30:14 +01:00
|
|
|
import arm.utils
|
|
|
|
import arm.assets as assets
|
|
|
|
import arm.make_state as state
|
2015-12-07 21:05:27 +01:00
|
|
|
|
2017-04-16 17:43:07 +02:00
|
|
|
check_dot_path = False
|
|
|
|
|
2016-08-12 02:29:09 +02:00
|
|
|
def add_armory_library(sdk_path, name):
|
2017-01-28 20:00:04 +01:00
|
|
|
return ('project.addLibrary("' + sdk_path + '/' + name + '");\n').replace('\\', '/')
|
2016-08-12 02:29:09 +02:00
|
|
|
|
2017-04-16 17:43:07 +02:00
|
|
|
def add_assets(path):
|
|
|
|
global check_dot_path
|
|
|
|
if check_dot_path and '/.' in path: # Redirect path to local copy
|
2017-05-23 01:03:44 +02:00
|
|
|
armpath = arm.utils.build_dir() + '/compiled/ArmoryAssets/'
|
2017-04-16 17:43:07 +02:00
|
|
|
if not os.path.exists(armpath):
|
|
|
|
os.makedirs(armpath)
|
|
|
|
localpath = armpath + path.rsplit('/')[-1]
|
|
|
|
if not os.path.isfile(localpath):
|
|
|
|
shutil.copy(path, localpath)
|
|
|
|
path = localpath
|
|
|
|
return 'project.addAssets("' + path + '");\n'
|
|
|
|
|
2015-12-07 21:05:27 +01:00
|
|
|
# Write khafile.js
|
2016-12-07 10:37:08 +01:00
|
|
|
def write_khafilejs(is_play, export_physics, export_navigation, dce_full=False):
|
2017-04-16 17:43:07 +02:00
|
|
|
global check_dot_path
|
|
|
|
|
2017-03-15 12:30:14 +01:00
|
|
|
sdk_path = arm.utils.get_sdk_path()
|
2016-06-30 13:22:05 +02:00
|
|
|
|
|
|
|
# Merge duplicates and sort
|
2016-09-28 00:00:59 +02:00
|
|
|
shader_references = sorted(list(set(assets.shaders)))
|
|
|
|
shader_data_references = sorted(list(set(assets.shader_datas)))
|
|
|
|
asset_references = sorted(list(set(assets.assets)))
|
2016-10-12 17:52:27 +02:00
|
|
|
wrd = bpy.data.worlds['Arm']
|
2016-01-17 22:38:46 +01:00
|
|
|
|
2016-06-30 13:22:05 +02:00
|
|
|
with open('khafile.js', 'w') as f:
|
|
|
|
f.write(
|
2015-12-07 21:05:27 +01:00
|
|
|
"""// Auto-generated
|
2017-05-13 17:17:43 +02:00
|
|
|
let project = new Project('""" + arm.utils.safestr(wrd.arm_project_name) + """');
|
2015-12-07 21:05:27 +01:00
|
|
|
|
|
|
|
project.addSources('Sources');
|
|
|
|
""")
|
2017-02-13 13:23:43 +01:00
|
|
|
|
2017-04-18 13:37:51 +02:00
|
|
|
# TODO: Move to khamake
|
2017-04-19 11:48:30 +02:00
|
|
|
f.write("project.addDefine('arm_" + arm.utils.get_gapi() + "');\n")
|
2017-04-18 13:37:51 +02:00
|
|
|
|
2017-04-16 17:43:07 +02:00
|
|
|
# TODO: Khamake bug workaround - assets & shaders located in folder starting with '.' get discarded - copy them to project
|
|
|
|
check_dot_path = False
|
|
|
|
if '/.' in sdk_path:
|
|
|
|
check_dot_path = True
|
2017-05-23 01:03:44 +02:00
|
|
|
if not os.path.exists(arm.utils.build_dir() + '/compiled/KhaShaders'):
|
2017-04-16 17:43:07 +02:00
|
|
|
kha_shaders_path = arm.utils.get_kha_path() + '/Sources/Shaders'
|
2017-05-23 01:03:44 +02:00
|
|
|
shutil.copytree(kha_shaders_path, arm.utils.build_dir() + '/compiled/KhaShaders')
|
|
|
|
f.write("project.addShaders('" + arm.utils.build_dir() + "/compiled/KhaShaders/**');\n")
|
2017-04-16 17:43:07 +02:00
|
|
|
|
2017-02-13 13:23:43 +01:00
|
|
|
# Auto-add assets located in Bundled directory
|
|
|
|
if os.path.exists('Bundled'):
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets("Bundled/**"))
|
2017-02-13 13:23:43 +01:00
|
|
|
|
2017-02-09 00:33:19 +01:00
|
|
|
if os.path.exists('Libraries/armory'):
|
|
|
|
f.write('project.addLibrary("armory")')
|
|
|
|
else:
|
|
|
|
f.write(add_armory_library(sdk_path, 'armory'))
|
|
|
|
|
|
|
|
if os.path.exists('Libraries/iron'):
|
|
|
|
f.write('project.addLibrary("iron")')
|
|
|
|
else:
|
|
|
|
f.write(add_armory_library(sdk_path, 'iron'))
|
2017-03-06 02:29:03 +01:00
|
|
|
|
|
|
|
# Project libraries
|
|
|
|
for lib in wrd.my_librarytraitlist:
|
|
|
|
if lib.enabled_prop:
|
|
|
|
f.write('project.addLibrary("{0}");\n'.format(lib.name))
|
2016-06-30 13:22:05 +02:00
|
|
|
|
2016-09-08 14:08:31 +02:00
|
|
|
if export_physics:
|
2016-10-12 18:26:56 +02:00
|
|
|
f.write("project.addDefine('arm_physics');\n")
|
2016-08-21 20:00:37 +02:00
|
|
|
f.write(add_armory_library(sdk_path + '/lib/', 'haxebullet'))
|
2016-11-30 11:40:28 +01:00
|
|
|
if state.target == 'krom' or state.target == 'html5':
|
|
|
|
ammojs_path = sdk_path + '/lib/haxebullet/js/ammo/ammo.js'
|
|
|
|
ammojs_path = ammojs_path.replace('\\', '/')
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets(ammojs_path))
|
2016-08-21 20:00:37 +02:00
|
|
|
|
2016-12-07 02:01:42 +01:00
|
|
|
if export_navigation:
|
|
|
|
f.write("project.addDefine('arm_navigation');\n")
|
|
|
|
f.write(add_armory_library(sdk_path + '/lib/', 'haxerecast'))
|
|
|
|
if state.target == 'krom' or state.target == 'html5':
|
|
|
|
recastjs_path = sdk_path + '/lib/haxerecast/js/recast/recast.js'
|
|
|
|
recastjs_path = recastjs_path.replace('\\', '/')
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets(recastjs_path))
|
2016-12-07 02:01:42 +01:00
|
|
|
|
2016-10-09 16:06:18 +02:00
|
|
|
if dce_full:
|
|
|
|
f.write("project.addParameter('-dce full');")
|
|
|
|
|
2017-05-24 23:04:24 +02:00
|
|
|
if wrd.arm_cache_compiler and (is_play or (state.target == 'html5' and not is_publish)):
|
|
|
|
# Load shaders manually
|
|
|
|
f.write("project.addDefine('arm_debug');\n")
|
|
|
|
|
2016-09-28 00:00:59 +02:00
|
|
|
for ref in shader_references:
|
|
|
|
f.write("project.addShaders('" + ref + "');\n")
|
2017-03-20 13:23:31 +01:00
|
|
|
|
2016-09-28 00:00:59 +02:00
|
|
|
for ref in shader_data_references:
|
|
|
|
ref = ref.replace('\\', '/')
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets(ref))
|
2016-09-28 00:00:59 +02:00
|
|
|
|
|
|
|
for ref in asset_references:
|
2016-08-13 14:02:12 +02:00
|
|
|
ref = ref.replace('\\', '/')
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets(ref))
|
2015-12-07 21:05:27 +01:00
|
|
|
|
2016-10-17 00:02:51 +02:00
|
|
|
if wrd.arm_play_console:
|
2016-10-12 18:26:56 +02:00
|
|
|
f.write("project.addDefine('arm_profile');\n")
|
2017-01-02 22:46:18 +01:00
|
|
|
|
2017-02-13 13:23:43 +01:00
|
|
|
if wrd.arm_play_console or wrd.arm_ui:
|
2017-02-28 13:48:19 +01:00
|
|
|
f.write(add_armory_library(sdk_path, 'lib/zui'))
|
|
|
|
p = sdk_path + '/armory/Assets/droid_sans.ttf'
|
2017-04-16 17:43:07 +02:00
|
|
|
f.write(add_assets(p.replace('\\', '/')))
|
2016-07-20 17:33:17 +02:00
|
|
|
|
2017-04-08 00:34:45 +02:00
|
|
|
if wrd.arm_hscript:
|
|
|
|
f.write(add_armory_library(sdk_path, 'lib/hscript'))
|
|
|
|
|
2016-10-17 00:02:51 +02:00
|
|
|
if wrd.arm_minimize == False:
|
2016-10-12 18:26:56 +02:00
|
|
|
f.write("project.addDefine('arm_json');\n")
|
2016-08-07 23:12:14 +02:00
|
|
|
|
2016-10-17 00:02:51 +02:00
|
|
|
if wrd.arm_deinterleaved_buffers == True:
|
2016-10-12 18:26:56 +02:00
|
|
|
f.write("project.addDefine('arm_deinterleaved');\n")
|
2016-08-07 23:12:14 +02:00
|
|
|
|
2017-03-12 17:29:22 +01:00
|
|
|
if wrd.arm_batch_meshes == True:
|
|
|
|
f.write("project.addDefine('arm_batch');\n")
|
|
|
|
|
2017-05-14 09:27:47 +02:00
|
|
|
if wrd.arm_stream_scene:
|
|
|
|
f.write("project.addDefine('arm_stream');\n")
|
|
|
|
|
2016-10-12 17:52:27 +02:00
|
|
|
if wrd.generate_gpu_skin == False:
|
2016-10-12 18:26:56 +02:00
|
|
|
f.write("project.addDefine('arm_cpu_skin');\n")
|
2016-08-23 22:55:46 +02:00
|
|
|
|
2016-07-28 13:21:27 +02:00
|
|
|
for d in assets.khafile_defs:
|
|
|
|
f.write("project.addDefine('" + d + "');\n")
|
|
|
|
|
2016-10-17 00:02:51 +02:00
|
|
|
config_text = wrd.arm_khafile
|
2016-06-30 13:22:05 +02:00
|
|
|
if config_text != '':
|
|
|
|
f.write(bpy.data.texts[config_text].as_string())
|
2016-01-11 13:50:54 +01:00
|
|
|
|
2016-08-04 22:38:56 +02:00
|
|
|
f.write("\n\nresolve(project);\n")
|
2016-01-11 13:07:44 +01:00
|
|
|
|
2015-12-07 21:05:27 +01:00
|
|
|
# Write Main.hx
|
2016-10-17 00:02:51 +02:00
|
|
|
def write_main(is_play, in_viewport, is_publish):
|
2016-09-02 23:11:04 +02:00
|
|
|
wrd = bpy.data.worlds['Arm']
|
2017-03-15 12:30:14 +01:00
|
|
|
resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene())
|
|
|
|
scene_name = arm.utils.get_project_scene_name()
|
2016-10-17 00:02:51 +02:00
|
|
|
scene_ext = '.zip' if (bpy.data.scenes[scene_name].data_compressed and is_publish) else ''
|
2016-06-30 13:22:05 +02:00
|
|
|
#if not os.path.isfile('Sources/Main.hx'):
|
|
|
|
with open('Sources/Main.hx', 'w') as f:
|
|
|
|
f.write(
|
2015-12-07 21:05:27 +01:00
|
|
|
"""// Auto-generated
|
|
|
|
package ;
|
|
|
|
class Main {
|
2017-05-13 17:17:43 +02:00
|
|
|
public static inline var projectName = '""" + arm.utils.safestr(wrd.arm_project_name) + """';
|
|
|
|
public static inline var projectPackage = '""" + arm.utils.safestr(wrd.arm_project_package) + """';
|
2016-11-07 23:06:08 +01:00
|
|
|
public static inline var projectAssets = """ + str(len(assets.assets)) + """;
|
2016-08-15 23:45:03 +02:00
|
|
|
static inline var projectWidth = """ + str(resx) + """;
|
|
|
|
static inline var projectHeight = """ + str(resy) + """;
|
2016-12-08 16:38:21 +01:00
|
|
|
static inline var projectSamplesPerPixel = """ + str(int(wrd.arm_samples_per_pixel)) + """;
|
2017-05-12 23:18:49 +02:00
|
|
|
static inline var projectVSync = """ + ('true' if wrd.arm_vsync else 'false') + """;
|
2017-05-13 17:17:43 +02:00
|
|
|
static inline var projectScene = '""" + arm.utils.safestr(scene_name) + scene_ext + """';
|
2016-12-07 02:01:42 +01:00
|
|
|
static var state:Int;
|
2016-12-10 14:20:16 +01:00
|
|
|
#if js
|
2016-12-07 02:01:42 +01:00
|
|
|
static function loadLib(name:String) {
|
|
|
|
kha.LoaderImpl.loadBlobFromDescription({ files: [name] }, function(b:kha.Blob) {
|
|
|
|
untyped __js__("(1, eval)({0})", b.toString());
|
|
|
|
state--;
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
}
|
2016-12-10 14:20:16 +01:00
|
|
|
#end
|
2016-06-30 13:22:05 +02:00
|
|
|
public static function main() {
|
2016-09-23 00:34:42 +02:00
|
|
|
iron.system.CompileTime.importPackage('armory.trait');
|
|
|
|
iron.system.CompileTime.importPackage('armory.renderpath');
|
2017-05-13 17:17:43 +02:00
|
|
|
iron.system.CompileTime.importPackage('""" + arm.utils.safestr(wrd.arm_project_package) + """');
|
2016-12-07 02:01:42 +01:00
|
|
|
state = 1;
|
|
|
|
#if (js && arm_physics) state++; loadLib("ammo.js"); #end
|
|
|
|
#if (js && arm_navigation) state++; loadLib("recast.js"); #end
|
|
|
|
state--; start();
|
2016-06-30 13:22:05 +02:00
|
|
|
}
|
2016-11-24 17:35:12 +01:00
|
|
|
static function start() {
|
2016-12-07 02:01:42 +01:00
|
|
|
if (state > 0) return;
|
2016-10-15 15:08:25 +02:00
|
|
|
armory.object.Uniforms.register();
|
2017-05-12 23:18:49 +02:00
|
|
|
kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel, vSync: projectVSync}, function() {
|
2016-08-22 21:56:28 +02:00
|
|
|
iron.App.init(function() {
|
2016-11-07 23:06:08 +01:00
|
|
|
""")
|
|
|
|
if is_publish and wrd.arm_loadbar:
|
|
|
|
f.write("""iron.App.notifyOnRender2D(armory.trait.internal.LoadBar.render);""")
|
|
|
|
|
|
|
|
f.write("""
|
2016-09-23 00:34:42 +02:00
|
|
|
iron.Scene.setActive(projectScene, function(object:iron.object.Object) {""")
|
2017-03-15 12:30:14 +01:00
|
|
|
# if arm.utils.with_krom() and in_viewport and is_play:
|
2017-05-24 13:06:48 +02:00
|
|
|
if is_play or (state.target == 'html5' and not is_publish):
|
2016-09-23 00:34:42 +02:00
|
|
|
f.write("""
|
2016-11-23 15:34:59 +01:00
|
|
|
object.addTrait(new armory.trait.internal.SpaceArmory());""")
|
2016-09-23 00:34:42 +02:00
|
|
|
f.write("""
|
2016-08-29 09:56:34 +02:00
|
|
|
});
|
2016-08-22 21:56:28 +02:00
|
|
|
});
|
2016-06-30 13:22:05 +02:00
|
|
|
});
|
|
|
|
}
|
2015-12-07 21:05:27 +01:00
|
|
|
}
|
|
|
|
""")
|
2016-07-10 00:51:39 +02:00
|
|
|
|
|
|
|
# Write electron.js
|
2016-11-24 17:35:12 +01:00
|
|
|
def write_electronjs(w, h):
|
2016-09-02 23:11:04 +02:00
|
|
|
wrd = bpy.data.worlds['Arm']
|
2017-05-23 01:03:44 +02:00
|
|
|
with open(arm.utils.build_dir() + '/electron.js', 'w') as f:
|
2016-07-10 00:51:39 +02:00
|
|
|
f.write(
|
|
|
|
"""// Auto-generated
|
|
|
|
'use strict';
|
|
|
|
const electron = require('electron');
|
|
|
|
const app = electron.app;
|
|
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
|
|
let mainWindow;
|
|
|
|
|
2016-11-24 17:35:12 +01:00
|
|
|
function createWindow () {
|
2016-07-10 00:51:39 +02:00
|
|
|
mainWindow = new BrowserWindow({width: """ + str(int(w)) + """, height: """ + str(int(h)) + """, autoHideMenuBar: true, useContentSize: true});
|
2016-07-28 13:21:27 +02:00
|
|
|
mainWindow.loadURL('file://' + __dirname + '/html5/index.html');
|
2017-05-23 01:03:44 +02:00
|
|
|
//mainWindow.loadURL('http://localhost:8040/""" + arm.utils.build_dir() + """/html5/index.html');
|
2016-11-24 17:35:12 +01:00
|
|
|
mainWindow.on('closed', function() { mainWindow = null; });
|
2016-07-10 00:51:39 +02:00
|
|
|
}
|
|
|
|
app.on('ready', createWindow);
|
|
|
|
app.on('window-all-closed', function () { app.quit(); });
|
|
|
|
app.on('activate', function () { if (mainWindow === null) { createWindow(); } });
|
|
|
|
""")
|
|
|
|
|
|
|
|
# Write index.html
|
2016-11-24 17:35:12 +01:00
|
|
|
def write_indexhtml(w, h):
|
2017-05-23 01:03:44 +02:00
|
|
|
if not os.path.exists(arm.utils.build_dir() + '/html5'):
|
|
|
|
os.makedirs(arm.utils.build_dir() + '/html5')
|
|
|
|
with open(arm.utils.build_dir() + '/html5/index.html', 'w') as f:
|
2016-07-10 00:51:39 +02:00
|
|
|
f.write(
|
|
|
|
"""<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2017-04-26 14:21:22 +02:00
|
|
|
<meta charset="utf-8"/>""")
|
|
|
|
if bpy.data.cameras[0].rp_stereo:
|
|
|
|
f.write("""
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
""")
|
|
|
|
f.write("""
|
2016-08-04 22:38:56 +02:00
|
|
|
<title>Armory</title>
|
2016-07-10 00:51:39 +02:00
|
|
|
</head>
|
2017-05-12 21:49:42 +02:00
|
|
|
<body style="margin: 0; padding: 0;">
|
2017-04-16 14:46:35 +02:00
|
|
|
""")
|
|
|
|
if bpy.data.cameras[0].rp_stereo:
|
|
|
|
f.write("""
|
2017-04-26 14:21:22 +02:00
|
|
|
<canvas style="width: 100vw; height: 100vh; display: block;" id='khanvas'></canvas>
|
2017-04-16 14:46:35 +02:00
|
|
|
""")
|
|
|
|
else:
|
|
|
|
f.write("""
|
2017-04-26 14:21:22 +02:00
|
|
|
<p align="center"><canvas align="center" style="outline: none;" id='khanvas' width='""" + str(w) + """' height='""" + str(h) + """'></canvas></p>
|
2017-04-16 14:46:35 +02:00
|
|
|
""")
|
|
|
|
f.write("""
|
2016-07-10 00:51:39 +02:00
|
|
|
<script src='kha.js'></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""")
|
|
|
|
|
2016-09-02 23:11:04 +02:00
|
|
|
def write_compiledglsl():
|
|
|
|
clip_start = bpy.data.cameras[0].clip_start # Same clip values for all cameras for now
|
|
|
|
clip_end = bpy.data.cameras[0].clip_end
|
|
|
|
shadowmap_size = bpy.data.worlds['Arm'].shadowmap_size
|
|
|
|
wrd = bpy.data.worlds['Arm']
|
2017-05-23 01:03:44 +02:00
|
|
|
with open(arm.utils.build_dir() + '/compiled/Shaders/compiled.glsl', 'w') as f:
|
2016-07-10 00:51:39 +02:00
|
|
|
f.write(
|
2016-10-17 17:39:40 +02:00
|
|
|
"""#ifndef _COMPILED_GLSL_
|
|
|
|
#define _COMPILED_GLSL_
|
|
|
|
const float PI = 3.1415926535;
|
2016-07-10 00:51:39 +02:00
|
|
|
const float PI2 = PI * 2.0;
|
2016-07-17 20:29:53 +02:00
|
|
|
const vec2 cameraPlane = vec2(""" + str(round(clip_start * 100) / 100) + """, """ + str(round(clip_end * 100) / 100) + """);
|
2016-07-10 00:51:39 +02:00
|
|
|
const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);
|
2017-05-22 15:55:34 +02:00
|
|
|
const float shadowmapCubePcfSize = """ + str(round(wrd.lamp_omni_shadows_cubemap_pcfsize * 10000) / 10000) + """;
|
2016-07-12 00:09:02 +02:00
|
|
|
""")
|
|
|
|
if wrd.generate_clouds:
|
|
|
|
f.write(
|
2016-07-17 20:29:53 +02:00
|
|
|
"""const float cloudsDensity = """ + str(round(wrd.generate_clouds_density * 100) / 100) + """;
|
|
|
|
const float cloudsSize = """ + str(round(wrd.generate_clouds_size * 100) / 100) + """;
|
|
|
|
const float cloudsLower = """ + str(round(wrd.generate_clouds_lower * 1000)) + """;
|
|
|
|
const float cloudsUpper = """ + str(round(wrd.generate_clouds_upper * 1000)) + """;
|
|
|
|
const vec2 cloudsWind = vec2(""" + str(round(wrd.generate_clouds_wind[0] * 1000) / 1000) + """, """ + str(round(wrd.generate_clouds_wind[1] * 1000) / 1000) + """);
|
|
|
|
const float cloudsSecondary = """ + str(round(wrd.generate_clouds_secondary * 100) / 100) + """;
|
|
|
|
const float cloudsPrecipitation = """ + str(round(wrd.generate_clouds_precipitation * 100) / 100) + """;
|
|
|
|
const float cloudsEccentricity = """ + str(round(wrd.generate_clouds_eccentricity * 100) / 100) + """;
|
|
|
|
""")
|
|
|
|
if wrd.generate_ocean:
|
|
|
|
f.write(
|
|
|
|
"""const float seaLevel = """ + str(round(wrd.generate_ocean_level * 100) / 100) + """;
|
|
|
|
const float seaMaxAmplitude = """ + str(round(wrd.generate_ocean_amplitude * 100) / 100) + """;
|
|
|
|
const float seaHeight = """ + str(round(wrd.generate_ocean_height * 100) / 100) + """;
|
|
|
|
const float seaChoppy = """ + str(round(wrd.generate_ocean_choppy * 100) / 100) + """;
|
|
|
|
const float seaSpeed = """ + str(round(wrd.generate_ocean_speed * 100) / 100) + """;
|
|
|
|
const float seaFreq = """ + str(round(wrd.generate_ocean_freq * 100) / 100) + """;
|
|
|
|
const vec3 seaBaseColor = vec3(""" + str(round(wrd.generate_ocean_base_color[0] * 100) / 100) + """, """ + str(round(wrd.generate_ocean_base_color[1] * 100) / 100) + """, """ + str(round(wrd.generate_ocean_base_color[2] * 100) / 100) + """);
|
|
|
|
const vec3 seaWaterColor = vec3(""" + str(round(wrd.generate_ocean_water_color[0] * 100) / 100) + """, """ + str(round(wrd.generate_ocean_water_color[1] * 100) / 100) + """, """ + str(round(wrd.generate_ocean_water_color[2] * 100) / 100) + """);
|
2016-07-27 14:25:01 +02:00
|
|
|
const float seaFade = """ + str(round(wrd.generate_ocean_fade * 100) / 100) + """;
|
2016-07-17 20:29:53 +02:00
|
|
|
""")
|
|
|
|
if wrd.generate_ssao:
|
2017-03-14 20:43:54 +01:00
|
|
|
scale = 0.5 if wrd.generate_ssao_half_res else 1.0
|
2016-07-17 20:29:53 +02:00
|
|
|
f.write(
|
|
|
|
"""const float ssaoSize = """ + str(round(wrd.generate_ssao_size * 100) / 100) + """;
|
|
|
|
const float ssaoStrength = """ + str(round(wrd.generate_ssao_strength * 100) / 100) + """;
|
2017-03-14 20:43:54 +01:00
|
|
|
const float ssaoTextureScale = """ + str(scale) + """;
|
2016-07-17 20:29:53 +02:00
|
|
|
""")
|
2016-07-18 20:28:52 +02:00
|
|
|
if wrd.generate_bloom:
|
|
|
|
f.write(
|
2016-11-21 16:49:32 +01:00
|
|
|
"""const float bloomThreshold = """ + str(round(wrd.generate_bloom_threshold * 100) / 100) + """;
|
2016-08-07 01:43:21 +02:00
|
|
|
const float bloomStrength = """ + str(round(wrd.generate_bloom_strength * 100) / 100) + """;
|
2016-10-21 19:36:08 +02:00
|
|
|
const float bloomRadius = """ + str(round(wrd.generate_bloom_radius * 100) / 100) + """;
|
2016-07-18 20:28:52 +02:00
|
|
|
""")
|
|
|
|
if wrd.generate_motion_blur:
|
|
|
|
f.write(
|
|
|
|
"""const float motionBlurIntensity = """ + str(round(wrd.generate_motion_blur_intensity * 100) / 100) + """;
|
|
|
|
""")
|
|
|
|
if wrd.generate_ssr:
|
|
|
|
f.write(
|
|
|
|
"""const float ssrRayStep = """ + str(round(wrd.generate_ssr_ray_step * 100) / 100) + """;
|
|
|
|
const float ssrMinRayStep = """ + str(round(wrd.generate_ssr_min_ray_step * 100) / 100) + """;
|
|
|
|
const float ssrSearchDist = """ + str(round(wrd.generate_ssr_search_dist * 100) / 100) + """;
|
|
|
|
const float ssrFalloffExp = """ + str(round(wrd.generate_ssr_falloff_exp * 100) / 100) + """;
|
|
|
|
const float ssrJitter = """ + str(round(wrd.generate_ssr_jitter * 100) / 100) + """;
|
2017-01-17 14:48:47 +01:00
|
|
|
""")
|
|
|
|
|
|
|
|
if wrd.generate_ssrs:
|
|
|
|
f.write(
|
|
|
|
"""const float ssrsRayStep = """ + str(round(wrd.generate_ssrs_ray_step * 100) / 100) + """;
|
2016-09-08 14:08:31 +02:00
|
|
|
""")
|
|
|
|
|
|
|
|
if wrd.generate_volumetric_light:
|
|
|
|
f.write(
|
|
|
|
"""const float volumAirTurbidity = """ + str(round(wrd.generate_volumetric_light_air_turbidity * 100) / 100) + """;
|
|
|
|
const vec3 volumAirColor = vec3(""" + str(round(wrd.generate_volumetric_light_air_color[0] * 100) / 100) + """, """ + str(round(wrd.generate_volumetric_light_air_color[1] * 100) / 100) + """, """ + str(round(wrd.generate_volumetric_light_air_color[2] * 100) / 100) + """);
|
|
|
|
""")
|
|
|
|
|
2016-12-01 18:28:07 +01:00
|
|
|
if wrd.generate_pcss_state == 'On':
|
2016-09-08 14:08:31 +02:00
|
|
|
f.write(
|
|
|
|
"""const int pcssRings = """ + str(wrd.generate_pcss_rings) + """;
|
2016-08-15 23:45:03 +02:00
|
|
|
""")
|
|
|
|
|
2016-08-23 22:55:46 +02:00
|
|
|
# Compositor
|
2016-08-15 23:45:03 +02:00
|
|
|
if wrd.generate_letterbox:
|
|
|
|
f.write(
|
|
|
|
"""const float compoLetterboxSize = """ + str(round(wrd.generate_letterbox_size * 100) / 100) + """;
|
|
|
|
""")
|
|
|
|
|
|
|
|
if wrd.generate_grain:
|
|
|
|
f.write(
|
|
|
|
"""const float compoGrainStrength = """ + str(round(wrd.generate_grain_strength * 100) / 100) + """;
|
|
|
|
""")
|
|
|
|
|
|
|
|
if bpy.data.scenes[0].cycles.film_exposure != 1.0:
|
|
|
|
f.write(
|
|
|
|
"""const float compoExposureStrength = """ + str(round(bpy.data.scenes[0].cycles.film_exposure * 100) / 100) + """;
|
|
|
|
""")
|
|
|
|
|
|
|
|
if wrd.generate_fog:
|
|
|
|
f.write(
|
|
|
|
"""const float compoFogAmountA = """ + str(round(wrd.generate_fog_amounta * 100) / 100) + """;
|
|
|
|
const float compoFogAmountB = """ + str(round(wrd.generate_fog_amountb * 100) / 100) + """;
|
|
|
|
const vec3 compoFogColor = vec3(""" + str(round(wrd.generate_fog_color[0] * 100) / 100) + """, """ + str(round(wrd.generate_fog_color[1] * 100) / 100) + """, """ + str(round(wrd.generate_fog_color[2] * 100) / 100) + """);
|
|
|
|
""")
|
|
|
|
|
2016-10-21 19:36:08 +02:00
|
|
|
if bpy.data.cameras[0].dof_distance > 0.0:
|
2016-08-15 23:45:03 +02:00
|
|
|
f.write(
|
|
|
|
"""const float compoDOFDistance = """ + str(round(bpy.data.cameras[0].dof_distance * 100) / 100) + """;
|
2016-10-21 19:36:08 +02:00
|
|
|
const float compoDOFFstop = """ + str(round(bpy.data.cameras[0].gpu_dof.fstop * 100) / 100) + """;
|
2017-02-28 13:48:19 +01:00
|
|
|
const float compoDOFLength = 160.0;
|
|
|
|
""") # str(round(bpy.data.cameras[0].lens * 100) / 100)
|
2017-02-22 15:50:19 +01:00
|
|
|
|
|
|
|
if bpy.data.cameras[0].rp_voxelgi:
|
|
|
|
f.write(
|
|
|
|
"""const vec3 voxelgiResolution = ivec3(""" + str(round(bpy.data.cameras[0].rp_voxelgi_resolution[0])) + """, """ + str(round(bpy.data.cameras[0].rp_voxelgi_resolution[1])) + """, """ + str(round(bpy.data.cameras[0].rp_voxelgi_resolution[2])) + """);
|
|
|
|
const vec3 voxelgiDimensions = ivec3(""" + str(round(wrd.generate_voxelgi_dimensions[0])) + """, """ + str(round(wrd.generate_voxelgi_dimensions[1])) + """, """ + str(round(wrd.generate_voxelgi_dimensions[2])) + """);
|
2017-05-17 23:02:36 +02:00
|
|
|
const float voxelgiDiff = """ + str(round(wrd.voxelgi_diff * 100) / 100) + """;
|
|
|
|
const float voxelgiSpec = """ + str(round(wrd.voxelgi_spec * 100) / 100) + """;
|
|
|
|
const float voxelgiOcc = """ + str(round(wrd.voxelgi_occ * 100) / 100) + """;
|
|
|
|
const float voxelgiEnv = """ + str(round(wrd.voxelgi_env * 100) / 100) + """;
|
2017-05-20 19:07:15 +02:00
|
|
|
const float voxelgiStep = """ + str(round(wrd.voxelgi_step * 100) / 100) + """;
|
|
|
|
const float voxelgiRange = """ + str(round(wrd.voxelgi_range * 100) / 100) + """;
|
2017-05-23 15:01:56 +02:00
|
|
|
""")
|
|
|
|
|
|
|
|
if bpy.data.cameras[0].rp_sss_state == 'On':
|
|
|
|
f.write(
|
|
|
|
"""const float sssWidth = """ + str(wrd.sss_width / 10.0) + """;
|
2016-08-23 22:55:46 +02:00
|
|
|
""")
|
|
|
|
|
|
|
|
# Skinning
|
|
|
|
if wrd.generate_gpu_skin:
|
|
|
|
f.write(
|
|
|
|
"""const int skinMaxBones = """ + str(wrd.generate_gpu_skin_max_bones) + """;
|
2016-07-10 00:51:39 +02:00
|
|
|
""")
|
|
|
|
|
2017-02-22 15:50:19 +01:00
|
|
|
f.write("""#endif // _COMPILED_GLSL_
|
|
|
|
""")
|
2016-10-17 17:39:40 +02:00
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
def write_traithx(class_name):
|
2016-09-02 23:11:04 +02:00
|
|
|
wrd = bpy.data.worlds['Arm']
|
2017-05-13 17:17:43 +02:00
|
|
|
package_path = arm.utils.get_fp() + '/Sources/' + arm.utils.safestr(wrd.arm_project_package)
|
2016-12-08 14:38:04 +01:00
|
|
|
if not os.path.exists(package_path):
|
|
|
|
os.makedirs(package_path)
|
|
|
|
with open(package_path + '/' + class_name + '.hx', 'w') as f:
|
2016-07-10 00:51:39 +02:00
|
|
|
f.write(
|
2017-05-13 17:17:43 +02:00
|
|
|
"""package """ + arm.utils.safestr(wrd.arm_project_package) + """;
|
2016-07-10 00:51:39 +02:00
|
|
|
|
2016-09-02 23:11:04 +02:00
|
|
|
class """ + class_name + """ extends armory.Trait {
|
2016-07-10 00:51:39 +02:00
|
|
|
public function new() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
// notifyOnInit(function() {
|
|
|
|
// });
|
|
|
|
|
|
|
|
// notifyOnUpdate(function() {
|
|
|
|
// });
|
|
|
|
|
|
|
|
// notifyOnRemove(function() {
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|