Load ammo using eval.
This commit is contained in:
parent
04df49b88f
commit
98bf287985
|
@ -21,11 +21,12 @@ void main() {
|
|||
discard;
|
||||
}
|
||||
|
||||
float accumA = texture(gbuffer1, texCoord).r;
|
||||
// accum.a = texture(gbuffer1, texCoord).r;
|
||||
accum.a = texture(gbuffer1, texCoord).r;
|
||||
|
||||
// fragColor = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), revealage);
|
||||
|
||||
const float epsilon = 0.00001;
|
||||
fragColor = vec4(accum.rgb / max(accumA, epsilon), 1.0 - revealage);
|
||||
// const float epsilon = 0.00001;
|
||||
// fragColor = vec4(accum.rgb / max(accum.a, epsilon), 1.0 - revealage);
|
||||
|
||||
fragColor = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), 1.0 - revealage);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ def with_krom():
|
|||
global krom_found
|
||||
return krom_found
|
||||
|
||||
glslver = None
|
||||
glslver = 110
|
||||
def glsl_version():
|
||||
global glslver
|
||||
return glslver
|
||||
|
@ -139,7 +139,7 @@ def register():
|
|||
if importlib.util.find_spec('barmory') != None:
|
||||
krom_found = True
|
||||
import bgl
|
||||
glslver = bgl.glGetString(bgl.GL_SHADING_LANGUAGE_VERSION).replace('.', '')
|
||||
glslver = int(bgl.glGetString(bgl.GL_SHADING_LANGUAGE_VERSION).replace('.', ''))
|
||||
|
||||
def unregister():
|
||||
pass
|
||||
|
|
|
@ -78,6 +78,10 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
|
|||
if bpy.data.worlds['Arm'].arm_cache_shaders == False:
|
||||
if os.path.isdir('build/html5-resources'):
|
||||
shutil.rmtree('build/html5-resources')
|
||||
if os.path.isdir('build/krom-resources'):
|
||||
shutil.rmtree('build/krom-resources')
|
||||
if os.path.isdir('build/window/krom-resources'):
|
||||
shutil.rmtree('build/window/krom-resources')
|
||||
if os.path.isdir('build/compiled/Shaders'):
|
||||
shutil.rmtree('build/compiled/Shaders')
|
||||
if os.path.isdir('build/compiled/ShaderDatas'):
|
||||
|
@ -116,15 +120,6 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
|
|||
# Write Main.hx - depends on write_khafilejs for writing number of assets
|
||||
write_data.write_main(is_play, in_viewport, is_publish)
|
||||
|
||||
# Copy ammo.js if necessary
|
||||
#if target_name == 'html5':
|
||||
if export_physics and bpy.data.worlds['Arm'].arm_physics == 'Bullet':
|
||||
ammojs_path = sdk_path + '/lib/haxebullet/js/ammo/ammo.js'
|
||||
if not os.path.isfile('build/html5/ammo.js'):
|
||||
shutil.copy(ammojs_path, 'build/html5')
|
||||
if not os.path.isfile('build/debug-html5/ammo.js'):
|
||||
shutil.copy(ammojs_path, 'build/debug-html5')
|
||||
|
||||
def compile_project(target_name=None, is_publish=False, watch=False):
|
||||
sdk_path = armutils.get_sdk_path()
|
||||
ffmpeg_path = armutils.get_ffmpeg_path()
|
||||
|
@ -155,6 +150,18 @@ def compile_project(target_name=None, is_publish=False, watch=False):
|
|||
cmd.append('-g')
|
||||
cmd.append('opengl2')
|
||||
|
||||
if kha_target_name == 'krom':
|
||||
if state.in_viewport:
|
||||
if armutils.glsl_version() >= 330:
|
||||
cmd.append('--shaderversion')
|
||||
cmd.append('330')
|
||||
else:
|
||||
cmd.append('--shaderversion')
|
||||
cmd.append('110')
|
||||
else:
|
||||
cmd.append('--to')
|
||||
cmd.append('build/window')
|
||||
|
||||
# User defined commands
|
||||
cmd_text = wrd.arm_command_line
|
||||
if cmd_text != '':
|
||||
|
@ -216,10 +223,6 @@ def build_project(is_play=False, is_publish=False, in_viewport=False):
|
|||
# Create directories
|
||||
if not os.path.exists('Sources'):
|
||||
os.makedirs('Sources')
|
||||
if not os.path.isdir('build/html5'):
|
||||
os.makedirs('build/html5')
|
||||
if not os.path.isdir('build/debug-html5'):
|
||||
os.makedirs('build/debug-html5')
|
||||
|
||||
# Compile path tracer shaders
|
||||
if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].renderpath_path == 'pathtrace_path':
|
||||
|
@ -319,14 +322,17 @@ def play_project(self, in_viewport):
|
|||
state.compileproc = compile_project(target_name='krom')
|
||||
mode = 'play_viewport'
|
||||
threading.Timer(0.1, watch_compile, [mode]).start()
|
||||
# Krom
|
||||
elif in_viewport == False and wrd.arm_play_runtime == 'Krom':
|
||||
w, h = armutils.get_render_resolution()
|
||||
state.compileproc = compile_project(target_name='krom')
|
||||
mode = 'play'
|
||||
threading.Timer(0.1, watch_compile, [mode]).start()
|
||||
# Electron, Browser
|
||||
else:
|
||||
x = 0
|
||||
y = 0
|
||||
w, h = armutils.get_render_resolution()
|
||||
winoff = 0
|
||||
write_data.write_electronjs(x, y, w, h, winoff, in_viewport)
|
||||
write_data.write_indexhtml(w, h, in_viewport)
|
||||
write_data.write_electronjs(w, h)
|
||||
write_data.write_indexhtml(w, h)
|
||||
state.compileproc = compile_project(target_name='html5')
|
||||
mode = 'play'
|
||||
threading.Timer(0.1, watch_compile, [mode]).start()
|
||||
|
@ -375,6 +381,15 @@ def on_compiled(mode): # build, play, play_viewport, publish
|
|||
t.start()
|
||||
html5_app_path = 'http://localhost:8040/build/html5'
|
||||
webbrowser.open(html5_app_path)
|
||||
elif wrd.arm_play_runtime == 'Krom':
|
||||
if armutils.get_os() == 'win':
|
||||
krom_path = sdk_path + '/win32/resources/app/extensions/krom/Krom/win32/Krom.exe'
|
||||
elif armutils.get_os() == 'mac':
|
||||
krom_path = sdk_path + '/Kode Studio.app/Contents/Resources/app/extensions/krom/Krom/macos/Krom.app/Contents/MacOS/Krom'
|
||||
else:
|
||||
krom_path = sdk_path + '/linux64/resources/app/extensions/krom/Krom/linux/Krom'
|
||||
state.playproc = subprocess.Popen([krom_path, armutils.get_fp() + '/build/window/krom', armutils.get_fp() + '/build/window/krom-resources'], stderr=subprocess.PIPE)
|
||||
watch_play()
|
||||
|
||||
def clean_cache():
|
||||
os.chdir(armutils.get_fp())
|
||||
|
|
|
@ -606,7 +606,10 @@ class ArmoryRenderButton(bpy.types.Operator):
|
|||
def draw_view3d_header(self, context):
|
||||
layout = self.layout
|
||||
if state.playproc == None and state.compileproc == None:
|
||||
layout.operator("arm.play_in_viewport", icon="PLAY")
|
||||
if armutils.with_krom():
|
||||
layout.operator("arm.play_in_viewport", icon="PLAY")
|
||||
else:
|
||||
layout.operator("arm.play", icon="PLAY")
|
||||
else:
|
||||
layout.operator("arm.stop", icon="MESH_PLANE")
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@ project.addSources('Sources');
|
|||
if export_physics:
|
||||
f.write("project.addDefine('arm_physics');\n")
|
||||
f.write(add_armory_library(sdk_path + '/lib/', 'haxebullet'))
|
||||
# TODO: include for js only
|
||||
ammojs_path = sdk_path + '/lib/haxebullet/js/ammo/ammo.js'
|
||||
f.write("project.addAssets('" + ammojs_path + "');\n")
|
||||
|
||||
if dce_full:
|
||||
f.write("project.addParameter('-dce full');")
|
||||
|
@ -99,28 +102,15 @@ class Main {
|
|||
iron.system.CompileTime.importPackage('armory.renderpath');
|
||||
iron.system.CompileTime.importPackage('""" + wrd.arm_project_package + """');
|
||||
#if (js && arm_physics)
|
||||
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);
|
||||
}
|
||||
");
|
||||
""")
|
||||
|
||||
f.write("""
|
||||
untyped loadScript('ammo.js', start);
|
||||
kha.LoaderImpl.loadBlobFromDescription({ files: ["ammo.js"] }, function(b:kha.Blob) {
|
||||
untyped __js__("(1, eval)({0})", b.toString());
|
||||
start();
|
||||
});
|
||||
#else
|
||||
start();
|
||||
#end
|
||||
}
|
||||
static function start() {""")
|
||||
|
||||
f.write("""
|
||||
static function start() {
|
||||
armory.object.Uniforms.register();
|
||||
kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel}, function() {
|
||||
iron.App.init(function() {
|
||||
|
@ -143,7 +133,7 @@ class Main {
|
|||
""")
|
||||
|
||||
# Write electron.js
|
||||
def write_electronjs(x, y, w, h, winoff, in_viewport):
|
||||
def write_electronjs(w, h):
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
with open('build/electron.js', 'w') as f:
|
||||
f.write(
|
||||
|
@ -154,45 +144,11 @@ const app = electron.app;
|
|||
const BrowserWindow = electron.BrowserWindow;
|
||||
let mainWindow;
|
||||
|
||||
function createWindow () { """)
|
||||
|
||||
if in_viewport:
|
||||
f.write(
|
||||
"""
|
||||
let point = electron.screen.getCursorScreenPoint();
|
||||
let targetDisplay = electron.screen.getDisplayNearestPoint(point);
|
||||
""")
|
||||
if armutils.get_os() == 'mac': # Perform scale in python
|
||||
f.write("""let scale = 1;""")
|
||||
else:
|
||||
f.write("""let scale = targetDisplay.scaleFactor;""")
|
||||
|
||||
f.write(
|
||||
"""
|
||||
let _x = Math.floor(""" + str(int(x)) + """ / scale);
|
||||
let _y = Math.floor(""" + str(int(y)) + """ / scale);
|
||||
let _w = Math.floor(""" + str(int(w)) + """ / scale);
|
||||
let _h = Math.floor(""" + str(int(h)) + """ / scale);
|
||||
let _winoff = Math.floor(""" + str(int(winoff)) + """ / scale);
|
||||
let offY = targetDisplay.workAreaSize.height - _winoff;
|
||||
_x = targetDisplay.bounds.x + _x;
|
||||
_y = targetDisplay.bounds.y + _y + offY;
|
||||
mainWindow = new BrowserWindow({x: _x, y: _y, width: _w, height: _h, frame: false, autoHideMenuBar: true, useContentSize: true, movable: false, resizable: false, transparent: true, enableLargerThanScreen: true});
|
||||
mainWindow.setSkipTaskbar(true);
|
||||
mainWindow.setAlwaysOnTop(true);
|
||||
""")
|
||||
else:
|
||||
f.write(
|
||||
"""
|
||||
function createWindow () {
|
||||
mainWindow = new BrowserWindow({width: """ + str(int(w)) + """, height: """ + str(int(h)) + """, autoHideMenuBar: true, useContentSize: true});
|
||||
""")
|
||||
f.write(
|
||||
"""
|
||||
mainWindow.loadURL('file://' + __dirname + '/html5/index.html');
|
||||
//mainWindow.loadURL('http://localhost:8040/build/html5/index.html');
|
||||
mainWindow.on('closed', function() { mainWindow = null; });""")
|
||||
|
||||
f.write("""
|
||||
mainWindow.on('closed', function() { mainWindow = null; });
|
||||
}
|
||||
app.on('ready', createWindow);
|
||||
app.on('window-all-closed', function () { app.quit(); });
|
||||
|
@ -200,7 +156,9 @@ app.on('activate', function () { if (mainWindow === null) { createWindow(); } })
|
|||
""")
|
||||
|
||||
# Write index.html
|
||||
def write_indexhtml(w, h, in_viewport):
|
||||
def write_indexhtml(w, h):
|
||||
if not os.path.exists('build/html5'):
|
||||
os.makedirs('build/html5')
|
||||
with open('build/html5/index.html', 'w') as f:
|
||||
f.write(
|
||||
"""<!DOCTYPE html>
|
||||
|
|
Loading…
Reference in a new issue