2015-12-07 21:05:27 +01:00
|
|
|
import bpy
|
|
|
|
import os
|
|
|
|
|
|
|
|
# Write khafile.js
|
2016-02-08 17:28:05 +01:00
|
|
|
def write_khafilejs(shader_references, asset_references):
|
2016-01-17 22:38:46 +01:00
|
|
|
|
|
|
|
# Merge duplicates and sort
|
|
|
|
shader_references = sorted(list(set(shader_references)))
|
2016-02-08 17:28:05 +01:00
|
|
|
asset_references = sorted(list(set(asset_references)))
|
2016-01-17 22:38:46 +01:00
|
|
|
|
2015-12-07 21:05:27 +01:00
|
|
|
with open('khafile.js', 'w') as f:
|
|
|
|
f.write(
|
|
|
|
"""// Auto-generated
|
|
|
|
var project = new Project('""" + bpy.data.worlds[0]['CGProjectName'] + """');
|
|
|
|
|
|
|
|
project.addSources('Sources');
|
|
|
|
project.addShaders('Sources/Shaders/**');
|
|
|
|
project.addAssets('Assets/**');
|
|
|
|
|
2016-01-11 13:07:44 +01:00
|
|
|
project.addLibrary('cyclesgame');
|
2015-12-07 21:05:27 +01:00
|
|
|
""")
|
|
|
|
|
2016-02-08 17:28:05 +01:00
|
|
|
for ref in shader_references: # Shaders
|
|
|
|
f.write("project.addShaders('" + ref + ".frag.glsl');\n")
|
|
|
|
f.write("project.addShaders('" + ref + ".vert.glsl');\n")
|
|
|
|
|
|
|
|
for ref in asset_references: # Assets
|
|
|
|
f.write("project.addAssets('" + ref + "');\n")
|
2016-01-11 13:07:44 +01:00
|
|
|
|
2016-01-11 13:50:54 +01:00
|
|
|
if bpy.data.worlds[0]['CGPhysics'] != 0:
|
|
|
|
f.write("\nproject.addDefine('WITH_PHYSICS')\n")
|
|
|
|
f.write("project.addLibrary('haxebullet')\n")
|
2016-04-12 22:59:06 +02:00
|
|
|
|
|
|
|
config_text = bpy.data.worlds[0]['CGKhafileConfig']
|
|
|
|
if config_text != '':
|
|
|
|
f.write(bpy.data.texts[config_text].as_string())
|
2016-01-11 13:50:54 +01:00
|
|
|
|
2016-04-12 22:59:06 +02:00
|
|
|
f.write("\n\nreturn project;\n")
|
2016-01-11 13:07:44 +01:00
|
|
|
|
2015-12-07 21:05:27 +01:00
|
|
|
# Write Main.hx
|
|
|
|
def write_main():
|
|
|
|
#if not os.path.isfile('Sources/Main.hx'):
|
|
|
|
with open('Sources/Main.hx', 'w') as f:
|
|
|
|
f.write(
|
|
|
|
"""// Auto-generated
|
|
|
|
package ;
|
|
|
|
class Main {
|
2016-01-11 21:10:33 +01:00
|
|
|
public static inline var projectName = '""" + bpy.data.worlds[0]['CGProjectName'] + """';
|
|
|
|
public static inline var projectPackage = '""" + bpy.data.worlds[0]['CGProjectPackage'] + """';
|
2015-12-07 21:05:27 +01:00
|
|
|
static inline var projectWidth = """ + str(bpy.data.worlds[0]['CGProjectWidth']) + """;
|
|
|
|
static inline var projectHeight = """ + str(bpy.data.worlds[0]['CGProjectHeight']) + """;
|
2016-02-17 01:26:07 +01:00
|
|
|
static inline var projectSamplesPerPixel = """ + str(bpy.data.worlds[0]['CGProjectSamplesPerPixel']) + """;
|
2016-01-25 16:46:13 +01:00
|
|
|
public static inline var projectScene = '""" + str(bpy.data.worlds[0]['CGProjectScene']) + """';
|
2016-04-08 16:17:57 +02:00
|
|
|
public static inline var texEnvironment = '""" + bpy.data.cameras[0].world_envtex_name.rsplit('.', 1)[0] + """';
|
|
|
|
public static inline var texEnvironmentMipmaps = """ + str(bpy.data.cameras[0].world_envtex_num_mips) + """;
|
2015-12-07 21:05:27 +01:00
|
|
|
public static function main() {
|
|
|
|
lue.sys.CompileTime.importPackage('lue.trait');
|
|
|
|
lue.sys.CompileTime.importPackage('cycles.trait');
|
2015-12-08 23:57:00 +01:00
|
|
|
lue.sys.CompileTime.importPackage('""" + bpy.data.worlds[0]['CGProjectPackage'] + """');
|
2016-01-11 13:50:54 +01:00
|
|
|
#if (js && WITH_PHYSICS)
|
2015-12-07 21:05:27 +01:00
|
|
|
untyped __js__("
|
|
|
|
function loadScript(url, callback) {
|
|
|
|
var head = document.getElementsByTagName('head')[0];
|
|
|
|
var script = document.createElement('script');
|
|
|
|
script.type = 'text/javascript';
|
|
|
|
script.src = url;
|
|
|
|
script.onreadystatechange = callback;
|
|
|
|
script.onload = callback;
|
|
|
|
head.appendChild(script);
|
|
|
|
}
|
|
|
|
");
|
|
|
|
untyped loadScript('ammo.js', start);
|
|
|
|
#else
|
|
|
|
start();
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
static function start() {
|
2016-02-17 01:26:07 +01:00
|
|
|
kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel}, function() {
|
2015-12-07 21:05:27 +01:00
|
|
|
new lue.App(cycles.Root);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|