コード例 #1
0
ファイル: make.py プロジェクト: armory3d/armory
def play_project(self, in_viewport):
    wrd = bpy.data.worlds['Arm']

    # Store area
    if armutils.with_krom() and in_viewport and bpy.context.area.type == 'VIEW_3D':
        state.play_area = bpy.context.area

    # Set target
    if in_viewport or wrd.arm_play_runtime == 'Krom':
        state.target = 'krom'
    elif wrd.arm_play_runtime == 'Native':
        state.target = 'native'
    else:
        state.target = 'html5'

    # Build data
    build_project(is_play=True, in_viewport=in_viewport, target=state.target)
    state.in_viewport = in_viewport

    # Compile
    mode = 'play'
    if state.target == 'native':
        state.compileproc = compile_project(target_name='--run')
    elif state.target == 'krom':
        if in_viewport:
            mode = 'play_viewport'
        state.compileproc = compile_project(target_name='krom')
    else: # Electron, Browser
        w, h = armutils.get_render_resolution()
        write_data.write_electronjs(w, h)
        write_data.write_indexhtml(w, h)
        state.compileproc = compile_project(target_name='html5')

    threading.Timer(0.1, watch_compile, [mode]).start()
コード例 #2
0
ファイル: write_data.py プロジェクト: armory3d/armory
def write_main(is_play, in_viewport, is_publish):
    wrd = bpy.data.worlds['Arm']
    resx, resy = armutils.get_render_resolution()
    scene_name = armutils.get_project_scene_name()
    scene_ext = '.zip' if (bpy.data.scenes[scene_name].data_compressed and is_publish) else ''
    #if not os.path.isfile('Sources/Main.hx'):
    with open('Sources/Main.hx', 'w') as f:
        f.write(
"""// Auto-generated
package ;
class Main {
    public static inline var projectName = '""" + wrd.arm_project_name + """';
    public static inline var projectPackage = '""" + wrd.arm_project_package + """';
    public static inline var projectAssets = """ + str(len(assets.assets)) + """;
    static inline var projectWidth = """ + str(resx) + """;
    static inline var projectHeight = """ + str(resy) + """;
    static inline var projectSamplesPerPixel = """ + str(int(wrd.arm_samples_per_pixel)) + """;
    static inline var projectScene = '""" + scene_name + scene_ext + """';
    static var state:Int;
    #if js
    static function loadLib(name:String) {
        kha.LoaderImpl.loadBlobFromDescription({ files: [name] }, function(b:kha.Blob) {
            untyped __js__("(1, eval)({0})", b.toString());
            state--;
            start();
        });
    }
    #end
    public static function main() {
        iron.system.CompileTime.importPackage('armory.trait');
        iron.system.CompileTime.importPackage('armory.renderpath');
        iron.system.CompileTime.importPackage('""" + wrd.arm_project_package + """');
        state = 1;
        #if (js && arm_physics) state++; loadLib("ammo.js"); #end
        #if (js && arm_navigation) state++; loadLib("recast.js"); #end
        state--; start();
    }
    static function start() {
        if (state > 0) return;
        armory.object.Uniforms.register();
        kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel}, function() {
            iron.App.init(function() {
""")
        if is_publish and wrd.arm_loadbar:
            f.write("""iron.App.notifyOnRender2D(armory.trait.internal.LoadBar.render);""")

        f.write("""
                iron.Scene.setActive(projectScene, function(object:iron.object.Object) {""")
        # if armutils.with_krom() and in_viewport and is_play:
        if is_play:
            f.write("""
                    object.addTrait(new armory.trait.internal.SpaceArmory());""")
        f.write("""
                });
            });
        });
    }
}
""")
コード例 #3
0
def write_main(is_play, in_viewport, is_publish):
    wrd = bpy.data.worlds['Arm']
    resx, resy = armutils.get_render_resolution(armutils.get_active_scene())
    scene_name = armutils.get_project_scene_name()
    scene_ext = '.zip' if (bpy.data.scenes[scene_name].data_compressed and is_publish) else ''
    #if not os.path.isfile('Sources/Main.hx'):
    with open('Sources/Main.hx', 'w') as f:
        f.write(
"""// Auto-generated
package ;
class Main {
    public static inline var projectName = '""" + wrd.arm_project_name + """';
    public static inline var projectPackage = '""" + wrd.arm_project_package + """';
    public static inline var projectAssets = """ + str(len(assets.assets)) + """;
    static inline var projectWidth = """ + str(resx) + """;
    static inline var projectHeight = """ + str(resy) + """;
    static inline var projectSamplesPerPixel = """ + str(int(wrd.arm_samples_per_pixel)) + """;
    static inline var projectScene = '""" + scene_name + scene_ext + """';
    static var state:Int;
    #if js
    static function loadLib(name:String) {
        kha.LoaderImpl.loadBlobFromDescription({ files: [name] }, function(b:kha.Blob) {
            untyped __js__("(1, eval)({0})", b.toString());
            state--;
            start();
        });
    }
    #end
    public static function main() {
        iron.system.CompileTime.importPackage('armory.trait');
        iron.system.CompileTime.importPackage('armory.renderpath');
        iron.system.CompileTime.importPackage('""" + wrd.arm_project_package + """');
        state = 1;
        #if (js && arm_physics) state++; loadLib("ammo.js"); #end
        #if (js && arm_navigation) state++; loadLib("recast.js"); #end
        state--; start();
    }
    static function start() {
        if (state > 0) return;
        armory.object.Uniforms.register();
        kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel}, function() {
            iron.App.init(function() {
""")
        if is_publish and wrd.arm_loadbar:
            f.write("""iron.App.notifyOnRender2D(armory.trait.internal.LoadBar.render);""")

        f.write("""
                iron.Scene.setActive(projectScene, function(object:iron.object.Object) {""")
        # if armutils.with_krom() and in_viewport and is_play:
        if is_play:
            f.write("""
                    object.addTrait(new armory.trait.internal.SpaceArmory());""")
        f.write("""
                });
            });
        });
    }
}
""")
コード例 #4
0
ファイル: make.py プロジェクト: daela/armory
def play_project(in_viewport):
    global scripts_mtime
    wrd = bpy.data.worlds['Arm']

    # Store area
    if armutils.with_krom() and in_viewport and bpy.context.area != None and bpy.context.area.type == 'VIEW_3D':
        state.play_area = bpy.context.area

    state.target = runtime_to_target(in_viewport)

    # Build data
    build_project(is_play=True, in_viewport=in_viewport, target=state.target)
    state.in_viewport = in_viewport

    khajs_path = get_khajs_path(in_viewport, state.target)
    if wrd.arm_recompile or \
       wrd.arm_recompile_trigger or \
       not wrd.arm_cache_compiler or \
       not wrd.arm_cache_shaders or \
       not os.path.isfile(khajs_path) or \
       state.last_target != state.target or \
       state.last_in_viewport != state.in_viewport:
        wrd.arm_recompile = True

    wrd.arm_recompile_trigger = False
    state.last_target = state.target
    state.last_in_viewport = state.in_viewport

    # Trait sources modified
    script_path = armutils.get_fp() + '/Sources/' + wrd.arm_project_package
    if os.path.isdir(script_path):
        for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True):
            mtime = os.path.getmtime(fn)
            if scripts_mtime < mtime:
                scripts_mtime = mtime
                wrd.arm_recompile = True

    # New compile requred - traits or materials changed
    if wrd.arm_recompile or state.target == 'native':

        # Unable to live-patch, stop player
        if state.krom_running:
            bpy.ops.arm.space_stop('EXEC_DEFAULT')
            # play_project(in_viewport=True) # Restart
            return

        mode = 'play'
        if state.target == 'native':
            state.compileproc = compile_project(target_name='--run')
        elif state.target == 'krom':
            if in_viewport:
                mode = 'play_viewport'
            state.compileproc = compile_project(target_name='krom')
        else: # Electron, Browser
            w, h = armutils.get_render_resolution(armutils.get_active_scene())
            write_data.write_electronjs(w, h)
            write_data.write_indexhtml(w, h)
            state.compileproc = compile_project(target_name='html5')
        threading.Timer(0.1, watch_compile, [mode]).start()
    else: # kha.js up to date
        compile_project(target_name=state.target, patch=True)