Ejemplo n.º 1
0
Archivo: make.py Proyecto: daela/armory
def on_compiled(mode): # build, play, play_viewport, publish
    log.clear()
    sdk_path = armutils.get_sdk_path()
    wrd = bpy.data.worlds['Arm']

    # Print info
    if mode == 'publish':
        target_name = make_utils.get_kha_target(wrd.arm_project_target)
        print('Project published')
        files_path = armutils.get_fp() + '/build/' + target_name
        if target_name == 'html5':
            print('HTML5 files are located in ' + files_path)
        elif target_name == 'ios' or target_name == 'osx': # TODO: to macos
            print('XCode project files are located in ' + files_path + '-build')
        elif target_name == 'windows':
            print('VisualStudio 2015 project files are located in ' + files_path + '-build')
        elif target_name == 'android-native':
            print('Android Studio project files are located in ' + files_path + '-build/' + wrd.arm_project_name)
        else:
            print('Makefiles are located in ' + files_path + '-build')
        return

    # Launch project in new window
    elif mode =='play':
        if wrd.arm_play_runtime == 'Electron':
            electron_app_path = './build/electron.js'

            if armutils.get_os() == 'win':
                electron_path = sdk_path + 'win32/Kode Studio.exe'
            elif armutils.get_os() == 'mac':
                electron_path = sdk_path + 'Kode Studio.app/Contents/MacOS/Electron'
            else:
                electron_path = sdk_path + 'linux64/kodestudio'

            state.playproc = subprocess.Popen([electron_path, '--chromedebug', '--remote-debugging-port=9222', '--enable-logging', electron_app_path], stderr=subprocess.PIPE)
            watch_play()
        elif wrd.arm_play_runtime == 'Browser':
            # Start server
            os.chdir(armutils.get_fp())
            t = threading.Thread(name='localserver', target=lib.server.run)
            t.daemon = True
            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_location = sdk_path + '/win32/Krom/win32'
                krom_path = krom_location + '/Krom.exe'
            elif armutils.get_os() == 'mac':
                krom_location = sdk_path + '/Kode Studio.app/Contents/Krom/macos/Krom.app/Contents/MacOS'
                krom_path = krom_location + '/Krom'
            else:
                krom_location = sdk_path + '/linux64/Krom/linux'
                krom_path = krom_location + '/Krom'
            os.chdir(krom_location)
            state.playproc = subprocess.Popen([krom_path, armutils.get_fp() + '/build/window/krom', armutils.get_fp() + '/build/window/krom-resources'], stderr=subprocess.PIPE)
            watch_play()
Ejemplo n.º 2
0
def on_compiled(mode): # build, play, play_viewport, publish
    log.clear()
    sdk_path = armutils.get_sdk_path()

    # Print info
    if mode == 'publish':
        target_name = make_utils.get_kha_target(bpy.data.worlds['Arm'].arm_project_target)
        print('Project published')
        files_path = armutils.get_fp() + '/build/' + target_name
        if target_name == 'html5':
            print('HTML5 files are located in ' + files_path)
        elif target_name == 'ios' or target_name == 'osx': # TODO: to macos
            print('XCode project files are located in ' + files_path + '-build')
        elif target_name == 'windows':
            print('VisualStudio 2015 project files are located in ' + files_path + '-build')
        elif target_name == 'android-native':
            print('Android Studio project files are located in ' + files_path + '-build')
        else:
            print('Makefiles are located in ' + files_path + '-build')
        return

    # Launch project in new window
    elif mode =='play':
        wrd = bpy.data.worlds['Arm']
        if wrd.arm_play_runtime == 'Electron':
            electron_app_path = './build/electron.js'

            if armutils.get_os() == 'win':
                electron_path = sdk_path + 'win32/Kode Studio.exe'
            elif armutils.get_os() == 'mac':
                electron_path = sdk_path + 'Kode Studio.app/Contents/MacOS/Electron'
            else:
                electron_path = sdk_path + 'linux64/kodestudio'

            state.playproc = subprocess.Popen([electron_path, '--chromedebug', '--remote-debugging-port=9222', '--enable-logging', electron_app_path], stderr=subprocess.PIPE)
            watch_play()
        elif wrd.arm_play_runtime == 'Browser':
            # Start server
            os.chdir(armutils.get_fp())
            t = threading.Thread(name='localserver', target=lib.server.run)
            t.daemon = True
            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_location = sdk_path + '/win32/Krom/win32'
                krom_path = krom_location + '/Krom.exe'
            elif armutils.get_os() == 'mac':
                krom_location = sdk_path + '/Kode Studio.app/Contents/Krom/macos/Krom.app/Contents/MacOS'
                krom_path = krom_location + '/Krom'
            else:
                krom_location = sdk_path + '/linux64/Krom/linux'
                krom_path = krom_location + '/Krom'
            os.chdir(krom_location)
            state.playproc = subprocess.Popen([krom_path, armutils.get_fp() + '/build/window/krom', armutils.get_fp() + '/build/window/krom-resources'], stderr=subprocess.PIPE)
            watch_play()
Ejemplo n.º 3
0
def kode_studio():
    sdk_path = armutils.get_sdk_path()
    project_path = armutils.get_fp()

    if armutils.get_os() == 'win':
        kode_path = sdk_path + '/win32/Kode Studio.exe'
        subprocess.Popen([kode_path, armutils.get_fp()])
    elif armutils.get_os() == 'mac':
        kode_path = '"' + sdk_path + '/Kode Studio.app/Contents/MacOS/Electron"'
        subprocess.Popen([kode_path + ' ' + armutils.get_fp()], shell=True)
    else:
        kode_path = sdk_path + '/linux64/kodestudio'
        subprocess.Popen([kode_path, armutils.get_fp()])
Ejemplo n.º 4
0
def kode_studio():
    sdk_path = armutils.get_sdk_path()
    project_path = armutils.get_fp()

    if armutils.get_os() == 'win':
        kode_path = sdk_path + '/win32/Kode Studio.exe'
        subprocess.Popen([kode_path, armutils.get_fp()])
    elif armutils.get_os() == 'mac':
        kode_path = '"' + sdk_path + '/Kode Studio.app/Contents/MacOS/Electron"'
        subprocess.Popen([kode_path + ' ' + armutils.get_fp()], shell=True)
    else:
        kode_path = sdk_path + '/linux64/kodestudio'
        subprocess.Popen([kode_path, armutils.get_fp()])
Ejemplo n.º 5
0
def register():
    bpy.app.handlers.scene_update_post.append(on_scene_update_post)
    bpy.app.handlers.save_pre.append(on_save_pre)
    bpy.app.handlers.load_post.append(on_load_post)
    # On windows, on_load_post is not called when opening .blend file from explorer
    if armutils.get_os() == 'win' and armutils.get_fp() != '':
        on_load_post(None)
Ejemplo n.º 6
0
    def execute(self, context):
        project_path = armutils.get_fp()
        item = context.object.my_traitlist[context.object.traitlist_index]  
        hx_path = project_path + '/Sources/' + bpy.data.worlds['Arm'].arm_project_package + '/' + item.class_name_prop + '.hx'

        sdk_path = armutils.get_sdk_path()
        if armutils.get_os() == 'win':
            kode_path = sdk_path + '/win32/Kode Studio.exe'
            subprocess.Popen([kode_path, armutils.get_fp(), hx_path])
        elif armutils.get_os() == 'mac':
            kode_path = '"' + sdk_path + '/Kode Studio.app/Contents/MacOS/Electron"'
            subprocess.Popen([kode_path + ' ' + armutils.get_fp() + ' ' + hx_path], shell=True)
        else:
            kode_path = sdk_path + '/linux64/kodestudio'
            subprocess.Popen([kode_path, armutils.get_fp(), hx_path])
        
        return{'FINISHED'}
Ejemplo n.º 7
0
    def execute(self, context):
        project_path = armutils.get_fp()
        item = context.object.my_traitlist[context.object.traitlist_index]
        hx_path = project_path + '/Sources/' + bpy.data.worlds[
            'Arm'].arm_project_package + '/' + item.class_name_prop + '.hx'

        sdk_path = armutils.get_sdk_path()
        if armutils.get_os() == 'win':
            kode_path = sdk_path + '/win32/Kode Studio.exe'
            subprocess.Popen([kode_path, armutils.get_fp(), hx_path])
        elif armutils.get_os() == 'mac':
            kode_path = '"' + sdk_path + '/Kode Studio.app/Contents/MacOS/Electron"'
            subprocess.Popen(
                [kode_path + ' ' + armutils.get_fp() + ' ' + hx_path],
                shell=True)
        else:
            kode_path = sdk_path + '/linux64/kodestudio'
            subprocess.Popen([kode_path, armutils.get_fp(), hx_path])

        return {'FINISHED'}
Ejemplo n.º 8
0
def target_to_gapi():
    # TODO: align target names
    wrd = bpy.data.worlds['Arm']
    if wrd.arm_project_target == 'krom':
        return 'arm_gapi_' + armutils.get_os()
    elif wrd.arm_project_target == 'macos':
        return 'arm_gapi_mac'
    elif wrd.arm_project_target == 'windows':
        return 'arm_gapi_win'
    elif wrd.arm_project_target == 'android-native':
        return 'arm_gapi_android'
    else:
        return 'arm_gapi_' + wrd.arm_project_target
Ejemplo n.º 9
0
def make_texture(image_node, tex_name, matname=None):
    wrd = bpy.data.worlds['Arm']
    tex = {}
    tex['name'] = tex_name
    tex['file'] = ''
    image = image_node.image
    if matname == None:
        matname = mat_state.material.name

    if image == None:
        return None

    if image.filepath == '':
        log.warn(matname + '/' + image.name + ' - file path not found')
        return None

    # Reference image name
    tex['file'] = armutils.extract_filename(image.filepath)
    tex['file'] = armutils.safefilename(tex['file'])
    s = tex['file'].rsplit('.', 1)

    if len(s) == 1:
        log.warn(matname + '/' + image.name +
                 ' - file extension required for image name')
        return None

    ext = s[1].lower()
    do_convert = ext != 'jpg' and ext != 'png' and ext != 'hdr' and ext != 'mp4'  # Convert image
    if do_convert:
        tex['file'] = tex['file'].rsplit('.', 1)[0] + '.jpg'
        # log.warn(matname + '/' + image.name + ' - image format is not (jpg/png/hdr), converting to jpg.')

    if image.packed_file != None:
        # Extract packed data
        unpack_path = armutils.get_fp() + '/build/compiled/Assets/unpacked'
        if not os.path.exists(unpack_path):
            os.makedirs(unpack_path)
        unpack_filepath = unpack_path + '/' + tex['file']

        if do_convert:
            if not os.path.isfile(unpack_filepath):
                armutils.write_image(image, unpack_filepath)

        # Write bytes if size is different or file does not exist yet
        elif os.path.isfile(unpack_filepath) == False or os.path.getsize(
                unpack_filepath) != image.packed_file.size:
            with open(unpack_filepath, 'wb') as f:
                f.write(image.packed_file.data)

        assets.add(unpack_filepath)

    else:
        if not os.path.isfile(armutils.safe_assetpath(image.filepath)):
            log.warn('Material ' + matname + '/' + image.name +
                     ' - file not found(' + image.filepath + ')')
            return None

        if do_convert:
            converted_path = armutils.get_fp(
            ) + '/build/compiled/Assets/unpacked/' + tex['file']
            # TODO: delete cache when file changes
            if not os.path.isfile(converted_path):
                armutils.write_image(image, converted_path)
            assets.add(converted_path)
        else:
            # Link image path to assets
            # TODO: Khamake converts .PNG to .jpg? Convert ext to lowercase on windows
            if armutils.get_os() == 'win':
                s = image.filepath.rsplit('.', 1)
                assets.add(armutils.safe_assetpath(s[0] + '.' + s[1].lower()))
            else:
                assets.add(armutils.safe_assetpath(image.filepath))

    # if image_format != 'RGBA32':
    # tex['format'] = image_format

    interpolation = image_node.interpolation
    aniso = wrd.anisotropic_filtering_state
    if aniso == 'On':
        interpolation = 'Smart'
    elif aniso == 'Off' and interpolation == 'Smart':
        interpolation = 'Linear'

    # TODO: Blender seems to load full images on size request, cache size instead
    powimage = is_pow(image.size[0]) and is_pow(image.size[1])

    # Pow2 required to generate mipmaps
    if powimage == True:
        if interpolation == 'Cubic':  # Mipmap linear
            tex['mipmap_filter'] = 'linear'
            tex['generate_mipmaps'] = True
        elif interpolation == 'Smart':  # Mipmap anisotropic
            tex['min_filter'] = 'anisotropic'
            tex['mipmap_filter'] = 'linear'
            tex['generate_mipmaps'] = True
    elif (image_node.interpolation == 'Cubic'
          or image_node.interpolation == 'Smart'):
        log.warn(matname + '/' + image.name +
                 ' - power of 2 texture required for ' +
                 image_node.interpolation + ' interpolation')

    if image_node.extension != 'REPEAT':  # Extend or clip
        tex['u_addressing'] = 'clamp'
        tex['v_addressing'] = 'clamp'
    else:
        if state.target == 'html5' and powimage == False:
            log.warn(
                matname + '/' + image.name +
                ' - non power of 2 texture can not use repeat mode on HTML5 target'
            )
            tex['u_addressing'] = 'clamp'
            tex['v_addressing'] = 'clamp'

    if image.source == 'MOVIE':  # Just append movie texture trait for now
        movie_trait = {}
        movie_trait['type'] = 'Script'
        movie_trait['class_name'] = 'armory.trait.internal.MovieTexture'
        movie_trait['parameters'] = [tex['file']]
        for o in mat_state.mat_armusers[mat_state.material]:
            o['traits'].append(movie_trait)
        tex['source'] = 'movie'
        tex['file'] = ''  # MovieTexture will load the video

    return tex
Ejemplo n.º 10
0
def runtime_to_gapi():
    wrd = bpy.data.worlds['Arm']
    if wrd.arm_play_runtime == 'Krom' or wrd.arm_play_runtime == 'Native':
        return 'arm_gapi_' + armutils.get_os()
    else:
        return 'arm_gapi_html5'
Ejemplo n.º 11
0
def write_probes(image_filepath, disable_hdr, cached_num_mips, generate_radiance=True):
    if not os.path.exists('build/compiled/Assets/envmaps'):
        os.makedirs('build/compiled/Assets/envmaps')

    base_name = image_filepath.rsplit(os.path.sep, 1)[1].rsplit('.', 1)[0] # Extract file name without extension
    
    # Assets to be generated
    output_file_irr = 'build/compiled/Assets/envmaps/' + base_name + '_irradiance'
    if generate_radiance:
        output_file_rad = 'build/compiled/Assets/envmaps/' + base_name + '_radiance'
        rad_format = 'jpg' if disable_hdr else 'hdr'

    # Irradiance exists, keep cache
    if os.path.exists('build/compiled/Assets/envmaps/' + base_name + '_irradiance.arm'):
        add_irr_assets(output_file_irr)
        if generate_radiance:
            add_rad_assets(output_file_rad, rad_format, cached_num_mips)
        return cached_num_mips
    
    # Get paths
    sdk_path = armutils.get_sdk_path()

    if armutils.get_os() == 'win':
        cmft_path = sdk_path + '/armory/tools/cmft/cmft.exe'
        kraffiti_path = sdk_path + '/win32/resources/app/extensions/kha/Kha/Kore/Tools/kraffiti/kraffiti.exe'
    elif armutils.get_os() == 'mac':
        cmft_path = sdk_path + '/armory/tools/cmft/cmft-osx'
        kraffiti_path = sdk_path + '/"Kode Studio.app"/Contents/Resources/app/extensions/kha/Kha/Kore/Tools/kraffiti/kraffiti-osx'
    else:
        cmft_path = sdk_path + '/armory/tools/cmft/cmft-linux64'
        kraffiti_path = sdk_path + '/linux64/resources/app/extensions/kha/Kha/Kore/Tools/kraffiti/kraffiti-linux64'
    
    output_gama_numerator = '1.0' if disable_hdr else '2.2'
    input_file = armutils.safe_assetpath(image_filepath)
    
    # Scale map
    wrd = bpy.data.worlds['Arm']
    target_w = int(wrd.generate_radiance_size)
    target_h = int(target_w / 2)
    scaled_file = output_file_rad + '.' + rad_format

    if armutils.get_os() == 'win':
        output = subprocess.check_output([ \
            kraffiti_path,
            'from=' + input_file,
            'to=' + scaled_file,
            'format=' + rad_format,
            'width=' + str(target_w),
            'height=' + str(target_h)])
    else:
        output = subprocess.check_output([ \
            kraffiti_path + \
            ' from=' + input_file + \
            ' to=' + scaled_file + \
            ' format=' + rad_format + \
            ' width=' + str(target_w) + \
            ' height=' + str(target_h)], shell=True)

    # Generate irradiance
    # gama_options = ''
    # if disable_hdr:
        # gama_options = \
        # ' --inputGammaNumerator 2.2' + \
        # ' --inputGammaDenominator 1.0' + \
        # ' --outputGammaNumerator 1.0' + \
        # ' --outputGammaDenominator ' + output_gama_numerator
    
    # Irradiance spherical harmonics
    if armutils.get_os() == 'win':
        subprocess.call([ \
            cmft_path,
            '--input', scaled_file,
            '--filter', 'shcoeffs',
            #gama_options + \
            '--outputNum', '1',
            '--output0', output_file_irr])
    else:
        subprocess.call([ \
            cmft_path + \
            ' --input ' + scaled_file + \
            ' --filter shcoeffs' + \
            #gama_options + \
            ' --outputNum 1' + \
            ' --output0 ' + output_file_irr], shell=True)

    sh_to_json(output_file_irr)
    add_irr_assets(output_file_irr)
    
    # Mip-mapped radiance
    if generate_radiance == False:
        return cached_num_mips

    # 4096 = 256 face
    # 2048 = 128 face
    # 1024 = 64 face
    face_size = target_w / 8
    if target_w == 2048:
        mip_count = 9
    elif target_w == 1024:
        mip_count = 8
    else:
        mip_count = 7
    
    if armutils.get_os() == 'win':
        subprocess.call([ \
            cmft_path,
            '--input', input_file,
            '--filter radiance',
            '--dstFaceSize', str(face_size),
            '--srcFaceSize', str(face_size),
            '--excludeBase', 'false',
            # '--mipCount', str(mip_count),
            '--glossScale', '7',
            '--glossBias', '3',
            '--lightingModel', 'blinnbrdf',
            '--edgeFixup', 'none',
            '--numCpuProcessingThreads', '4',
            '--useOpenCL', 'true',
            '--clVendor', 'anyGpuVendor',
            '--deviceType', 'gpu',
            '--deviceIndex', '0',
            '--generateMipChain', 'true',
            '--inputGammaNumerator', '2.2',
            '--inputGammaDenominator', '1.0',
            '--outputGammaNumerator', '1.0',
            '--outputGammaDenominator', output_gama_numerator,
            '--outputNum', '1',
            '--output0', output_file_rad,
            '--output0params', 'hdr,rgbe,latlong'])
    else:
        subprocess.call([ \
            cmft_path + \
            ' --input ' + input_file + \
            ' --filter radiance' + \
            ' --dstFaceSize ' + str(face_size) + \
            ' --srcFaceSize ' + str(face_size) + \
            ' --excludeBase false' + \
            #' --mipCount ' + str(mip_count) + \
            ' --glossScale 7' + \
            ' --glossBias 3' + \
            ' --lightingModel blinnbrdf' + \
            ' --edgeFixup none' + \
            ' --numCpuProcessingThreads 4' + \
            ' --useOpenCL true' + \
            ' --clVendor anyGpuVendor' + \
            ' --deviceType gpu' + \
            ' --deviceIndex 0' + \
            ' --generateMipChain true' + \
            ' --inputGammaNumerator 2.2' + \
            ' --inputGammaDenominator 1.0' + \
            ' --outputGammaNumerator 1.0' + \
            ' --outputGammaDenominator ' + output_gama_numerator + \
            ' --outputNum 1' + \
            ' --output0 ' + output_file_rad + \
            ' --output0params hdr,rgbe,latlong'], shell=True)

    # Remove size extensions in file name
    mip_w = int(face_size * 4)
    mip_base = output_file_rad + '_'
    mip_num = 0
    while mip_w >= 4:
        mip_name = mip_base + str(mip_num)
        os.rename(
            mip_name + '_' + str(mip_w) + 'x' + str(int(mip_w / 2)) + '.hdr',
            mip_name + '.hdr')
        mip_w = int(mip_w / 2)
        mip_num += 1

    # Append mips       
    generated_files = []
    for i in range(0, mip_count):
        generated_files.append(output_file_rad + '_' + str(i))
    
    # Convert to jpgs
    if disable_hdr is True:
        for f in generated_files:
            if armutils.get_os() == 'win':
                subprocess.call([ \
                    kraffiti_path,
                    'from=' + f + '.hdr',
                    'to=' + f + '.jpg',
                    'format=jpg'])
            else:
                subprocess.call([ \
                    kraffiti_path + \
                    ' from=' + f + '.hdr' + \
                    ' to=' + f + '.jpg' + \
                    ' format=jpg'], shell=True)
            os.remove(f + '.hdr')
    
    # Scale from (4x2 to 1x1>
    for i in range (0, 2):
        last = generated_files[-1]
        out = output_file_rad + '_' + str(mip_count + i)
        if armutils.get_os() == 'win':
            subprocess.call([ \
                kraffiti_path,
                'from=' + last + '.' + rad_format,
                'to=' + out + '.' + rad_format,
                'scale=0.5',
                'format=' + rad_format], shell=True)
        else:
            subprocess.call([ \
                kraffiti_path + \
                ' from=' + last + '.' + rad_format + \
                ' to=' + out + '.' + rad_format + \
                ' scale=0.5' + \
                ' format=' + rad_format], shell=True)
        generated_files.append(out)
    
    mip_count += 2

    add_rad_assets(output_file_rad, rad_format, mip_count)

    return mip_count
Ejemplo n.º 12
0
Archivo: make.py Proyecto: daela/armory
def compile_project(target_name=None, is_publish=False, watch=False, patch=False):
    wrd = bpy.data.worlds['Arm']

    # Set build command
    if target_name == None:
        target_name = wrd.arm_project_target
    elif target_name == 'native':
        target_name = ''

    node_path = armutils.get_node_path()
    khamake_path = armutils.get_khamake_path()
    
    kha_target_name = make_utils.get_kha_target(target_name)
    cmd = [node_path, khamake_path, kha_target_name]

    ffmpeg_path = armutils.get_ffmpeg_path() # Path to binary
    if ffmpeg_path != '':
        cmd.append('--ffmpeg')
        cmd.append(ffmpeg_path) # '"' + ffmpeg_path + '"'

    if target_name == '' or target_name == '--run':
        cmd.append('-g')
        cmd.append(getattr(wrd, 'arm_gapi_' + armutils.get_os()))

    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 != '':
        for s in bpy.data.texts[cmd_text].as_string().split(' '):
            cmd.append(s)

    if patch:
        if state.compileproc == None:
            # Quick build - disable krafix and haxe
            cmd.append('--nohaxe')
            cmd.append('--noshaders')
            cmd.append('--noproject')
            state.compileproc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
            if state.playproc == None:
                if state.in_viewport:
                    mode = 'play_viewport'
                else:
                    mode = 'play'
            else:
                mode = 'build'
            threading.Timer(0.1, watch_patch, [mode]).start()
            return state.compileproc
    elif watch:
        state.compileproc = subprocess.Popen(cmd)
        threading.Timer(0.1, watch_compile, ['build']).start()
        return state.compileproc
    else:
        return subprocess.Popen(cmd)
Ejemplo n.º 13
0
def compile_project(target_name=None, is_publish=False, watch=False, patch=False):
    sdk_path =  armutils.get_sdk_path()
    ffmpeg_path = armutils.get_ffmpeg_path()
    wrd = bpy.data.worlds['Arm']

    # Set build command
    if target_name == None:
        target_name = wrd.arm_project_target

    if armutils.get_os() == 'win':
        node_path = sdk_path + '/nodejs/node.exe'
        khamake_path = sdk_path + '/win32/Kha/make'
    elif armutils.get_os() == 'mac':
        node_path = sdk_path + '/nodejs/node-osx'
        khamake_path = sdk_path + '/Kode Studio.app/Contents/Kha/make'
    else:
        node_path = sdk_path + '/nodejs/node-linux64'
        khamake_path = sdk_path + '/linux64/Kha/make'
    
    kha_target_name = make_utils.get_kha_target(target_name)
    cmd = [node_path, khamake_path, kha_target_name]

    if ffmpeg_path != '':
        cmd.append('--ffmpeg')
        cmd.append('"' + ffmpeg_path + '"')

    if armutils.get_os() == 'win': # OpenGL for now
        cmd.append('-g')
        cmd.append('opengl2')

    if kha_target_name == 'krom':
        if state.in_viewport or patch:
            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 != '':
        for s in bpy.data.texts[cmd_text].as_string().split(' '):
            cmd.append(s)

    if state.krom_running:
        if state.compileproc == None: # Already compiling
            # Patch running game, stay silent, disable krafix and haxe
            # cmd.append('--silent')
            cmd.append('--noproject')
            cmd.append('--haxe')
            cmd.append('""')
            cmd.append('--krafix')
            cmd.append('""')
            # Khamake throws error when krafix is not found, hide for now
            state.compileproc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
            threading.Timer(0.1, watch_patch).start()
            return state.compileproc
    elif watch == True:
        state.compileproc = subprocess.Popen(cmd)
        threading.Timer(0.1, watch_compile, ['build']).start()
        return state.compileproc
    else:
        return subprocess.Popen(cmd)
Ejemplo n.º 14
0
def write_probes(image_filepath,
                 disable_hdr,
                 cached_num_mips,
                 generate_radiance=True):
    envpath = 'build/compiled/Assets/envmaps'

    if not os.path.exists(envpath):
        os.makedirs(envpath)

    base_name = armutils.extract_filename(image_filepath).rsplit('.', 1)[0]

    # Assets to be generated
    output_file_irr = envpath + '/' + base_name + '_irradiance'
    if generate_radiance:
        output_file_rad = envpath + '/' + base_name + '_radiance'
        rad_format = 'jpg' if disable_hdr else 'hdr'

    # Radiance & irradiance exists, keep cache
    basep = envpath + '/' + base_name
    if os.path.exists(basep + '_irradiance.arm'):
        if not generate_radiance or os.path.exists(basep + '_radiance_0.' +
                                                   rad_format):
            add_irr_assets(output_file_irr)
            if generate_radiance:
                add_rad_assets(output_file_rad, rad_format, cached_num_mips)
            return cached_num_mips

    # Get paths
    sdk_path = armutils.get_sdk_path()

    if armutils.get_os() == 'win':
        cmft_path = sdk_path + '/armory/tools/cmft/cmft.exe'
        kraffiti_path = sdk_path + '/win32/Kha/Kore/Tools/kraffiti/kraffiti.exe'
    elif armutils.get_os() == 'mac':
        cmft_path = '"' + sdk_path + '/armory/tools/cmft/cmft-osx"'
        kraffiti_path = '"' + sdk_path + '/Kode Studio.app/Contents/Kha/Kore/Tools/kraffiti/kraffiti-osx"'
    else:
        cmft_path = '"' + sdk_path + '/armory/tools/cmft/cmft-linux64"'
        kraffiti_path = '"' + sdk_path + '/linux64/Kha/Kore/Tools/kraffiti/kraffiti-linux64"'

    output_gama_numerator = '1.0' if disable_hdr else '2.2'
    input_file = armutils.safe_assetpath(image_filepath)

    # Scale map
    wrd = bpy.data.worlds['Arm']
    target_w = int(wrd.generate_radiance_size)
    target_h = int(target_w / 2)
    scaled_file = output_file_rad + '.' + rad_format

    if armutils.get_os() == 'win':
        output = subprocess.check_output([ \
            kraffiti_path,
            'from=' + input_file.replace(' ', '\ '),
            'to=' + scaled_file.replace(' ', '\ '),
            'format=' + rad_format,
            'width=' + str(target_w),
            'height=' + str(target_h)])
    else:
        output = subprocess.check_output([ \
            kraffiti_path + \
            ' from="' + input_file + '"' + \
            ' to="' + scaled_file + '"' + \
            ' format=' + rad_format + \
            ' width=' + str(target_w) + \
            ' height=' + str(target_h)], shell=True)

    # Generate irradiance
    # gama_options = ''
    # if disable_hdr:
    # gama_options = \
    # ' --inputGammaNumerator 2.2' + \
    # ' --inputGammaDenominator 1.0' + \
    # ' --outputGammaNumerator 1.0' + \
    # ' --outputGammaDenominator ' + output_gama_numerator

    # Irradiance spherical harmonics
    if armutils.get_os() == 'win':
        subprocess.call([ \
            cmft_path,
            '--input', scaled_file.replace(' ', '\ '),
            '--filter', 'shcoeffs',
            #gama_options + \
            '--outputNum', '1',
            '--output0', output_file_irr])
    else:
        subprocess.call([ \
            cmft_path + \
            ' --input ' + '"' + scaled_file + '"' + \
            ' --filter shcoeffs' + \
            #gama_options + \
            ' --outputNum 1' + \
            ' --output0 ' + output_file_irr], shell=True)

    sh_to_json(output_file_irr)
    add_irr_assets(output_file_irr)

    # Mip-mapped radiance
    if generate_radiance == False:
        return cached_num_mips

    # 4096 = 256 face
    # 2048 = 128 face
    # 1024 = 64 face
    face_size = target_w / 8
    if target_w == 2048:
        mip_count = 9
    elif target_w == 1024:
        mip_count = 8
    else:
        mip_count = 7

    use_opencl = 'true' if wrd.arm_gpu_processing else 'false'

    if armutils.get_os() == 'win':
        subprocess.call([ \
            cmft_path,
            '--input', input_file.replace(' ', '\ '),
            '--filter', 'radiance',
            '--dstFaceSize', str(face_size),
            '--srcFaceSize', str(face_size),
            '--excludeBase', 'false',
            # '--mipCount', str(mip_count),
            '--glossScale', '7',
            '--glossBias', '3',
            '--lightingModel', 'blinnbrdf',
            '--edgeFixup', 'none',
            '--numCpuProcessingThreads', '4',
            '--useOpenCL', use_opencl,
            '--clVendor', 'anyGpuVendor',
            '--deviceType', 'gpu',
            '--deviceIndex', '0',
            '--generateMipChain', 'true',
            '--inputGammaNumerator', '2.2',
            '--inputGammaDenominator', '1.0',
            '--outputGammaNumerator', '1.0',
            '--outputGammaDenominator', output_gama_numerator,
            '--outputNum', '1',
            '--output0', output_file_rad.replace(' ', '\ '),
            '--output0params', 'hdr,rgbe,latlong'])
    else:
        subprocess.call([ \
            cmft_path + \
            ' --input "' + input_file + '"' + \
            ' --filter radiance' + \
            ' --dstFaceSize ' + str(face_size) + \
            ' --srcFaceSize ' + str(face_size) + \
            ' --excludeBase false' + \
            #' --mipCount ' + str(mip_count) + \
            ' --glossScale 7' + \
            ' --glossBias 3' + \
            ' --lightingModel blinnbrdf' + \
            ' --edgeFixup none' + \
            ' --numCpuProcessingThreads 4' + \
            ' --useOpenCL ' + use_opencl + \
            ' --clVendor anyGpuVendor' + \
            ' --deviceType gpu' + \
            ' --deviceIndex 0' + \
            ' --generateMipChain true' + \
            ' --inputGammaNumerator 2.2' + \
            ' --inputGammaDenominator 1.0' + \
            ' --outputGammaNumerator 1.0' + \
            ' --outputGammaDenominator ' + output_gama_numerator + \
            ' --outputNum 1' + \
            ' --output0 "' + output_file_rad + '"' + \
            ' --output0params hdr,rgbe,latlong'], shell=True)

    # Remove size extensions in file name
    mip_w = int(face_size * 4)
    mip_base = output_file_rad + '_'
    mip_num = 0
    while mip_w >= 4:
        mip_name = mip_base + str(mip_num)
        os.rename(
            mip_name + '_' + str(mip_w) + 'x' + str(int(mip_w / 2)) + '.hdr',
            mip_name + '.hdr')
        mip_w = int(mip_w / 2)
        mip_num += 1

    # Append mips
    generated_files = []
    for i in range(0, mip_count):
        generated_files.append(output_file_rad + '_' + str(i))

    # Convert to jpgs
    if disable_hdr is True:
        for f in generated_files:
            if armutils.get_os() == 'win':
                subprocess.call([ \
                    kraffiti_path,
                    'from=' + f + '.hdr',
                    'to=' + f + '.jpg',
                    'format=jpg'])
            else:
                subprocess.call([ \
                    kraffiti_path + \
                    ' from=' + f + '.hdr' + \
                    ' to=' + f + '.jpg' + \
                    ' format=jpg'], shell=True)
            os.remove(f + '.hdr')

    # Scale from (4x2 to 1x1>
    for i in range(0, 2):
        last = generated_files[-1]
        out = output_file_rad + '_' + str(mip_count + i)
        if armutils.get_os() == 'win':
            subprocess.call([ \
                kraffiti_path,
                'from=' + last + '.' + rad_format,
                'to=' + out + '.' + rad_format,
                'scale=0.5',
                'format=' + rad_format], shell=True)
        else:
            subprocess.call([ \
                kraffiti_path + \
                ' from=' + last + '.' + rad_format + \
                ' to=' + out + '.' + rad_format + \
                ' scale=0.5' + \
                ' format=' + rad_format], shell=True)
        generated_files.append(out)

    mip_count += 2

    add_rad_assets(output_file_rad, rad_format, mip_count)

    return mip_count