Exemple #1
0
def watch_patch(mode):
    state.compileproc.wait()
    log.print_progress(100)
    # result = state.compileproc.poll()
    state.compileproc = None
    state.compileproc_finished = True
    on_compiled(mode)
Exemple #2
0
def watch_compile(mode):
    state.compileproc.wait()
    log.print_progress(100)
    if state.compileproc == None: ##
        return
    result = state.compileproc.poll()
    state.compileproc = None
    state.compileproc_finished = True
    if result == 0:
        state.compileproc_success = True
        on_compiled(mode)
    else:
        state.compileproc_success = False
        log.print_info('Build failed, check console')
Exemple #3
0
def watch_compile(mode):
    state.compileproc.wait()
    log.print_progress(100)
    if state.compileproc == None: ##
        return
    result = state.compileproc.poll()
    state.compileproc = None
    state.compileproc_finished = True
    if result == 0:
        bpy.data.worlds['Arm'].arm_recompile = False
        state.compileproc_success = True
        on_compiled(mode)
    else:
        state.compileproc_success = False
        log.print_info('Build failed, check console')
Exemple #4
0
def build_project(is_play=False, is_publish=False, in_viewport=False, target=None):
    wrd = bpy.data.worlds['Arm']

    # Set target
    if target == None:
        state.target = wrd.arm_project_target.lower()

    # Clear flag
    state.in_viewport = False

    # Save blend
    if armutils.get_save_on_build():
        bpy.ops.wm.save_mainfile()
    
    log.clear()

    # Set camera in active scene
    active_scene = bpy.context.screen.scene if wrd.arm_play_active_scene else bpy.data.scenes[wrd.arm_project_scene]
    if active_scene.camera == None:
        for o in active_scene.objects:
            if o.type == 'CAMERA':
                active_scene.camera = o
                break

    # Get paths
    sdk_path = armutils.get_sdk_path()
    raw_shaders_path = sdk_path + '/armory/Shaders/'
    
    # Set dir
    fp = armutils.get_fp()
    os.chdir(fp)

    # Create directories
    sources_path = 'Sources/' + wrd.arm_project_package
    if not os.path.exists(sources_path):
        os.makedirs(sources_path)

    # Compile path tracer shaders
    if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].renderpath_path == 'pathtrace_path':
        path_tracer.compile(raw_shaders_path + 'pt_trace_pass/pt_trace_pass.frag.glsl')

    # Save external scripts edited inside Blender
    write_texts = False
    for text in bpy.data.texts:
        if text.filepath != '' and text.is_dirty:
            write_texts = True
            break
    if write_texts:
        area = bpy.context.area
        old_type = area.type
        area.type = 'TEXT_EDITOR'
        for text in bpy.data.texts:
            if text.filepath != '' and text.is_dirty and os.path.isfile(text.filepath):
                area.spaces[0].text = text
                bpy.ops.text.save()
        area.type = old_type

    # Save internal Haxe scripts
    for text in bpy.data.texts:
        if text.filepath == '' and text.name[-3:] == '.hx':
            with open('Sources/' + bpy.data.worlds['Arm'].arm_project_package + '/' + text.name, 'w') as f:
                f.write(text.as_string())

    # Export data
    export_data(fp, sdk_path, is_play=is_play, is_publish=is_publish, in_viewport=in_viewport)

    if state.playproc == None:
        log.print_progress(50)
Exemple #5
0
def build_project(is_play=False, is_publish=False, in_viewport=False, target=None):
    wrd = bpy.data.worlds['Arm']

    # Set target
    if target == None:
        state.target = wrd.arm_project_target.lower()

    # Clear flag
    state.in_viewport = False

    # Save blend
    bpy.ops.wm.save_mainfile()
    log.clear()

    # Set camera in active scene
    active_scene = bpy.context.screen.scene if wrd.arm_play_active_scene else bpy.data.scenes[wrd.arm_project_scene]
    if active_scene.camera == None:
        for o in active_scene.objects:
            if o.type == 'CAMERA':
                active_scene.camera = o
                break

    # Get paths
    sdk_path = armutils.get_sdk_path()
    raw_shaders_path = sdk_path + '/armory/Shaders/'
    
    # Set dir
    fp = armutils.get_fp()
    os.chdir(fp)

    # Create directories
    if not os.path.exists('Sources'):
        os.makedirs('Sources')

    # Compile path tracer shaders
    if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].renderpath_path == 'pathtrace_path':
        path_tracer.compile(raw_shaders_path + 'pt_trace_pass/pt_trace_pass.frag.glsl')

    # Save external scripts edited inside Blender
    write_texts = False
    for text in bpy.data.texts:
        if text.filepath != '' and text.is_dirty:
            write_texts = True
            break
    if write_texts:
        area = bpy.context.area
        old_type = area.type
        area.type = 'TEXT_EDITOR'
        for text in bpy.data.texts:
            if text.filepath != '' and text.is_dirty:
                area.spaces[0].text = text
                bpy.ops.text.save()
        area.type = old_type

    # Save internal Haxe scripts
    for text in bpy.data.texts:
        if text.filepath == '' and text.name[-3:] == '.hx':
            with open('Sources/' + bpy.data.worlds['Arm'].arm_project_package + '/' + text.name, 'w') as f:
                f.write(text.as_string())

    # Export data
    export_data(fp, sdk_path, is_play=is_play, is_publish=is_publish, in_viewport=in_viewport)

    if state.playproc == None:
        log.print_progress(50)
def gibbsSamplingInformative(x0, y0, beta_tilde, c, T, T0):
    '''
    Performs Gibb's sampling for Zelner's Informative prior
    @params:
        x0 (np.array): array of input data
        y0 (np.array): array of training data
        beta_tilde (np.array): prior hyperparameter
        T (int): numder of samples to take
        T0 (int): "burn in" samples to ignore
    '''
    T = int(T)
    T0 = int(T0)
    (N, K) = x0.shape
    x = np.zeros((N, K + 1)) + 1
    x[:, 1:] = x0  #Expanding with a colomn of ones for bias terms

    zeller_evid = np.zeros(2)
    gammas = np.zeros(T)
    post_informative = np.zeros((2**K, 2))
    beta_evidence = np.zeros((K))
    post_informative[:, 0] = range(2**K)

    gam_index = random.randint(0, 2**K)
    (t_gamma0, q) = util.getGammaIndexes(K, int(gam_index))

    log.log("Staring Zeller Informative Prior Gibb's sampling")
    log.warning("This will take a while...")

    for i in range(T):

        if (i % 100 == 0):
            log.print_progress(i, T)

        for j in range(K):
            gam_i0 = gam_index
            gam_i1 = gam_index
            if (int(gam_index / 2**j) % 2 == 0):
                gam_i1 = gam_index + 2**j  #With current model parameter
            else:
                gam_i0 = gam_index - 2**j  #With out current model parameter

            for i0, gam0 in enumerate([int(gam_i0), int(gam_i1)]):
                (t_gamma, q) = util.getGammaIndexes(K, gam0)
                x_g = x[:, t_gamma]
                bt_g = beta_tilde[t_gamma]

                xtxi = np.linalg.inv(x_g.T.dot(x_g))
                c0 = y0.T.dot(x_g.dot(xtxi).dot(x_g.T)).dot(y0)
                c1 = y0.T.dot(y0)-c/(c+1.0)*c0+1/(c+1.0)*bt_g.T.dot(x_g.T.dot(x_g)).dot(bt_g) -\
                    2.0/(c+1.0)*y0.T.dot(x_g).dot(bt_g)

                zeller_evid[i0] = (c + 1.0)**(-0.5 * (q + 1)) * c1**(-0.5 * N)

            zeller_evid_norm = zeller_evid[0] / np.sum(zeller_evid, 0)
            if (random.random() < zeller_evid_norm):
                gam_index = gam_i0
            else:
                gam_index = gam_i1
        gammas[i] = gam_index

    log.print_progress(T, T)
    log.sucess("Gibb's Sampling for informative prior complete!")
    log.log("Calculating Model Evidence")

    #Count all instances of a certain model to get model evidence
    for i in range(2**K):
        count = np.count_nonzero(gammas[T0:T] == i)
        post_informative[i, 1] = count / (T - T0 + 1.0)

    post_informative_sort = post_informative[post_informative[:, 1].argsort()
                                             [::-1]]

    #Count all instances of a certain certain to get variable evidence
    for i in range(K):
        count = np.where((gammas[T0:T] / (2**i)).astype(int) %
                         2 == 1)[0].shape[0]
        beta_evidence[i] = count / (T - T0 + 1.0)

    return post_informative_sort, beta_evidence