Exemplo n.º 1
0
def send_operator(op):
    # Try to translate operator directly to armory
    if armutils.with_krom() and hasattr(
            bpy.context, 'object') and bpy.context.object != None:
        objname = bpy.context.object.name
        if op.name == 'Translate':
            vec = bpy.context.object.location
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.loc.set(' + str(
                vec[0]) + ', ' + str(vec[1]) + ', ' + str(
                    vec[2]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
        elif op.name == 'Resize':
            vec = bpy.context.object.scale
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.scale.set(' + str(
                vec[0]) + ', ' + str(vec[1]) + ', ' + str(
                    vec[2]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
        elif op.name == 'Rotate':
            vec = bpy.context.object.rotation_euler.to_quaternion()
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.rot.set(' + str(
                vec[1]) + ', ' + str(vec[2]) + ', ' + str(vec[3]) + ' ,' + str(
                    vec[0]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
    return False
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def draw_view3d_header(self, context):
    layout = self.layout
    if state.playproc == None and state.compileproc == None:
        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")
Exemplo n.º 4
0
def draw_view3d_header(self, context):
    layout = self.layout
    if state.playproc == None and state.compileproc == None:
        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")
Exemplo n.º 5
0
def register():
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='Window', space_type='EMPTY', region_type="WINDOW")
    km.keymap_items.new(props_ui.ArmoryPlayButton.bl_idname, type='F5', value='PRESS')
    if armutils.with_krom():
    	km.keymap_items.new(props_ui.ArmoryPlayInViewportButton.bl_idname, type='P', value='PRESS')
    else:
    	km.keymap_items.new(props_ui.ArmoryPlayButton.bl_idname, type='P', value='PRESS')
    arm_keymaps.append(km)
Exemplo n.º 6
0
def init_properties_on_load():
    global arm_ver

    if not "Arm" in bpy.data.worlds:
        init_properties()

    armutils.fetch_script_names()

    wrd = bpy.data.worlds["Arm"]

    # Outdated project
    if int(wrd.arm_version.replace(".", "")) < int(arm_ver.replace(".", "")):
        wrd.arm_version = arm_ver

    # Set url for embedded player
    if armutils.with_krom():
        barmory.set_files_location(armutils.get_fp() + "/build/krom")
Exemplo n.º 7
0
    def draw(self, context):
        layout = self.layout
        wrd = bpy.data.worlds['Arm']

        row = layout.row(align=True)
        row.alignment = 'EXPAND'
        if state.playproc == None and state.compileproc == None:
            row.operator("arm.play", icon="PLAY")
        else:
            row.operator("arm.stop", icon="MESH_PLANE")
        if state.playproc == None and state.krom_running == False:
            row.operator("arm.build")
        else:
            row.operator("arm.patch")
        row.operator("arm.clean_menu")
        
        layout.prop(wrd, 'arm_play_runtime')
        layout.prop(wrd, 'arm_play_viewport_camera')
        if wrd.arm_play_viewport_camera:
            layout.prop(wrd, 'arm_play_viewport_navigation')

        layout.prop(wrd, 'arm_play_advanced')
        if wrd.arm_play_advanced:
            # layout.prop(wrd, make_utils.runtime_to_gapi())
            layout.prop(wrd, 'arm_play_console')
            if armutils.with_krom():
                row = layout.row(align=True)
                row.prop(wrd, 'arm_play_live_patch')
                if wrd.arm_play_live_patch:
                    row.prop(wrd, 'arm_play_auto_build')
            layout.operator("arm.render", icon="RENDER_STILL")

            row = layout.row(align=True)
            row.prop(wrd, 'arm_cache_shaders')
            row.prop(wrd, 'arm_cache_compiler')
            row = layout.row(align=True)
            row.prop(wrd, 'arm_minimize')
            row.prop(wrd, 'arm_optimize_mesh')
            row = layout.row(align=True)
            row.prop(wrd, 'arm_gpu_processing')
            row.prop(wrd, 'arm_sampled_animation')
            layout.prop(wrd, 'arm_deinterleaved_buffers')
            layout.label('Libraries')
            layout.prop(wrd, 'arm_physics')
            layout.prop(wrd, 'arm_navigation')
            layout.prop(wrd, 'arm_ui')
Exemplo n.º 8
0
def init_properties_on_load():
    global arm_ver

    if not 'Arm' in bpy.data.worlds:
        init_properties()

    armutils.fetch_script_names()

    wrd = bpy.data.worlds['Arm']

    # Outdated project
    if int(wrd.arm_version.replace(".", "")[:4]) < int(
            arm_ver.replace(".", "")[:4]):
        # 17.01 - 17.01.1
        wrd.arm_version = arm_ver

    # Set url for embedded player
    if armutils.with_krom():
        barmory.set_files_location(armutils.get_fp() + '/build/krom')
Exemplo n.º 9
0
def send_operator(op):
    # Try to translate operator directly to armory
    if armutils.with_krom() and bpy.context.object != None:
        objname = bpy.context.object.name
        if op.name == 'Translate':
            vec = bpy.context.object.location
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.loc.set(' + str(vec[0]) + ', ' + str(vec[1]) + ', ' + str(vec[2]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
        elif op.name == 'Resize':
            vec = bpy.context.object.scale
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.scale.set(' + str(vec[0]) + ', ' + str(vec[1]) + ', ' + str(vec[2]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
        elif op.name == 'Rotate':
            vec = bpy.context.object.rotation_euler.to_quaternion()
            js_source = 'var o = armory.Scene.active.getChild("' + objname + '"); o.transform.rot.set(' + str(vec[1]) + ', ' + str(vec[2]) + ', ' + str(vec[3]) + ' ,' + str(vec[0]) + '); o.transform.dirty = true;'
            barmory.call_js(js_source)
            return True
    return False
Exemplo n.º 10
0
    def draw(self, context):
        layout = self.layout
        wrd = bpy.data.worlds['Arm']
        if state.playproc == None and state.compileproc == None:
            layout.operator("arm.play", icon="PLAY")
        else:
            layout.operator("arm.stop", icon="MESH_PLANE")
        layout.prop(wrd, 'arm_play_runtime')
        layout.prop(wrd, 'arm_play_viewport_camera')
        if wrd.arm_play_viewport_camera:
            layout.prop(wrd, 'arm_play_viewport_navigation')

        layout.prop(wrd, 'arm_play_advanced')
        if wrd.arm_play_advanced:
            layout.prop(wrd, 'arm_play_console')
            if armutils.with_krom():
                layout.prop(wrd, 'arm_play_live_patch')
                if wrd.arm_play_live_patch:
                    layout.prop(wrd, 'arm_play_auto_build')
            layout.operator("arm.render", icon="RENDER_STILL")
        layout.operator("arm.help")
Exemplo n.º 11
0
def unregister():
    if armutils.with_krom():
        bpy.utils.unregister_module(__name__)
Exemplo n.º 12
0
def unregister():
    if armutils.with_krom():
        bpy.utils.unregister_module(__name__)
Exemplo n.º 13
0
def on_scene_update_post(context):
    global last_time
    # global last_update_time
    global last_operator
    global redraw_ui
    global redraw_progress

    # Redraw at the start of 'next' frame
    if redraw_ui and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
                if area.type == 'VIEW_3D' or area.type == 'PROPERTIES':
                    area.tag_redraw()
        redraw_ui = False
    if redraw_progress and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
            if area.type == 'INFO':
                area.tag_redraw()
                break
        redraw_progress = False

    # New operator
    ops = bpy.context.window_manager.operators
    operators_changed = False
    if len(ops) > 0 and last_operator != ops[-1]:
        last_operator = ops[-1]
        operators_changed = True
    # Undo was performed - Blender clears the complete operator stack, undo last known operator atleast
    # if len(ops) == 0 and last_operator != None:
        # if hasattr(bpy.context, 'object'):
            # op_changed(last_operator, bpy.context.object)
        # last_operator = None

    # Player running
    state.krom_running = False
    if not state.is_paused and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
            if area.type == 'VIEW_ARMORY':
                state.krom_running = True
                break

    # Auto patch on every operator change
    wrd = bpy.data.worlds['Arm']
    if state.krom_running and \
       wrd.arm_play_live_patch and \
       wrd.arm_play_auto_build and \
       operators_changed:
        # Otherwise rebuild scene
        if bridge.send_operator(last_operator) == False:
            make.play_project(in_viewport=True)

    # Use frame rate for update frequency for now
    if time.time() - last_time >= (1 / bpy.context.scene.render.fps):
        last_time = time.time()

        if state.krom_running:
            # Read krom console
            if barmory.get_console_updated() == 1:
                log.print_player(barmory.get_console())
            # Read operator console
            if barmory.get_operator_updated() == 1:
                bridge.parse_operator(barmory.get_operator())
            # Tag redraw
            if bpy.context.screen != None:
                for area in bpy.context.screen.areas:
                    if area.type == 'VIEW_ARMORY':
                        area.tag_redraw()
                        break

        # New output has been logged
        if log.tag_redraw and bpy.context.screen != None:
            log.tag_redraw = False
            redraw_progress = True

        # Player finished, redraw play buttons
        if state.playproc_finished and bpy.context.screen != None:
            state.playproc_finished = False
            redraw_ui = True

        # Compilation finished
        if state.compileproc_finished and bpy.context.screen != None:
            state.compileproc_finished = False
            redraw_ui = True
            # Compilation succesfull
            if state.compileproc_success:
                # Notify embedded player
                if state.krom_running:
                    barmory.call_js('armory.Scene.patch();')
                # Or switch to armory space
                elif armutils.with_krom() and state.in_viewport:
                    state.play_area.type = 'VIEW_ARMORY'
                    # Prevent immediate operator patch
                    if len(ops) > 0:
                        last_operator = ops[-1]

    # No attribute when using multiple windows?
    if hasattr(bpy.context, 'edit_object'):
        edit_obj = bpy.context.edit_object
        if edit_obj != None and edit_obj.is_updated_data:
            if edit_obj.type == 'MESH':
                edit_obj.data.mesh_cached = False
            elif edit_obj.type == 'ARMATURE':
                edit_obj.data.data_cached = False

    if hasattr(bpy.context, 'object'):
        obj = bpy.context.object
        if obj != None:
            if operators_changed:
                op_changed(ops[-1], obj)
            if obj.active_material != None and obj.active_material.is_updated:
                if obj.active_material.lock_cache == True: # is_cached was set to true
                    obj.active_material.lock_cache = False
                else:
                    obj.active_material.is_cached = False
Exemplo n.º 14
0
def clear():
    props_ui.ArmoryProjectPanel.info_text = ''
    if armutils.with_krom():
        space_armory.ArmorySpaceHeader.info_text = ''
Exemplo n.º 15
0
Arquivo: make.py Projeto: 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)
Exemplo n.º 16
0
def on_scene_update_post(context):
    global last_time
    # global last_update_time
    global last_operator
    global redraw_ui
    global redraw_progress

    # Redraw at the start of 'next' frame
    if redraw_ui and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
                if area.type == 'VIEW_3D' or area.type == 'PROPERTIES':
                    area.tag_redraw()
        redraw_ui = False
    if redraw_progress and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
            if area.type == 'INFO':
                area.tag_redraw()
                break
        redraw_progress = False

    # New operator
    ops = bpy.context.window_manager.operators
    operators_changed = False
    if len(ops) > 0 and last_operator != ops[-1]:
        last_operator = ops[-1]
        operators_changed = True

    # Player running
    state.krom_running = False
    if not state.is_paused and bpy.context.screen != None:
        for area in bpy.context.screen.areas:
            if area.type == 'VIEW_ARMORY':
                state.krom_running = True
                break

    # Auto patch on every operator change
    if state.krom_running and \
       bpy.data.worlds['Arm'].arm_play_live_patch and \
       bpy.data.worlds['Arm'].arm_play_auto_build and \
       operators_changed:
        # Otherwise rebuild scene
        if bridge.send_operator(last_operator) == False:
            make.patch_project()
            make.compile_project(target_name="krom", patch=True)

    # Use frame rate for update frequency for now
    if time.time() - last_time >= (1 / bpy.context.scene.render.fps):
        last_time = time.time()

        if state.krom_running:
            # Read krom console
            if barmory.get_console_updated() == 1:
                log.print_player(barmory.get_console())
            # Read operator console
            if barmory.get_operator_updated() == 1:
                bridge.parse_operator(barmory.get_operator())
            # Tag redraw
            if bpy.context.screen != None:
                for area in bpy.context.screen.areas:
                    if area.type == 'VIEW_ARMORY':
                        area.tag_redraw()
                        break

        # New output has been logged
        if log.tag_redraw and bpy.context.screen != None:
            log.tag_redraw = False
            redraw_progress = True

        # Player finished, redraw play buttons
        if state.playproc_finished and bpy.context.screen != None:
            state.playproc_finished = False
            redraw_ui = True

        # Compilation finished
        if state.compileproc_finished and bpy.context.screen != None:
            state.compileproc_finished = False
            redraw_ui = True
            # Compilation succesfull
            if state.compileproc_success:
                # Notify embedded player
                if state.krom_running:
                    barmory.call_js('armory.Scene.patch();')
                # Or switch to armory space
                elif armutils.with_krom() and state.in_viewport:
                    state.play_area.type = 'VIEW_ARMORY'
                    # Prevent immediate operator patch
                    if len(ops) > 0:
                        last_operator = ops[-1]

    # No attribute when using multiple windows?
    if hasattr(bpy.context, 'edit_object'):
        edit_obj = bpy.context.edit_object
        if edit_obj != None and edit_obj.is_updated_data:
            if edit_obj.type == 'MESH':
                edit_obj.data.mesh_cached = False
            elif edit_obj.type == 'ARMATURE':
                edit_obj.data.data_cached = False

    obj = bpy.context.object
    if obj != None:
        if operators_changed:
            # Modifier was added/removed, recache mesh
            if ops[-1].bl_idname == 'OBJECT_OT_modifier_add' or ops[-1].bl_idname == 'OBJECT_OT_modifier_remove':
                obj.data.mesh_cached = False
        if obj.active_material != None and obj.active_material.is_updated:
            obj.active_material.is_cached = False