Esempio n. 1
0
def build_node_tree(cam, node_group):
    build_node_tree.cam = cam
    output = {}
    dat = {}
    output['renderpath_datas'] = [dat]
    
    path = 'build/compiled/Assets/renderpaths/'
    node_group_name = node_group.name.replace('.', '_')
    
    rn = get_root_node(node_group)
    if rn == None:
        return

    dat['name'] = node_group_name

    # Store main context names
    dat['mesh_context'] = 'mesh'
    dat['shadows_context'] = 'shadowmap'
    
    dat['render_targets'], dat['depth_buffers'] = preprocess_renderpath(rn, node_group)
    dat['stages'] = []
    
    buildNode(dat['stages'], rn, node_group)

    asset_path = path + node_group_name + '.arm'
    armutils.write_arm(asset_path, output)
    assets.add(asset_path)
Esempio n. 2
0
def build_node_tree(cam, node_group):
    build_node_tree.cam = cam
    output = {}
    dat = {}
    output['renderpath_datas'] = [dat]

    path = 'build/compiled/Assets/renderpaths/'
    node_group_name = node_group.name.replace('.', '_')

    rn = get_root_node(node_group)
    if rn == None:
        return

    dat['name'] = node_group_name

    # Store main context names
    dat['mesh_context'] = 'mesh'
    dat['shadows_context'] = 'shadowmap'

    dat['render_targets'], dat['depth_buffers'] = preprocess_renderpath(
        rn, node_group)
    dat['stages'] = []

    buildNode(dat['stages'], rn, node_group)

    asset_path = path + node_group_name + '.arm'
    armutils.write_arm(asset_path, output)
    assets.add(asset_path)
Esempio n. 3
0
def save_data(path, base_name, subset, res):
    res_name = base_name
    for s in subset:
        res_name += s

    r = {}
    r['shader_datas'] = [res['shader_datas'][-1]]
    armutils.write_arm(path + '/' + res_name + '.arm', r)
Esempio n. 4
0
def write_color_irradiance(base_name, col):
    # Constant color
    irradiance_floats = [col[0], col[1], col[2]]
    for i in range(0, 24):
        irradiance_floats.append(0.0)
    
    if not os.path.exists('build/compiled/Assets/envmaps'):
        os.makedirs('build/compiled/Assets/envmaps')
    
    output_file = 'build/compiled/Assets/envmaps/' + base_name + '_irradiance'
    
    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(output_file + '.arm', sh_json)

    assets.add(output_file + '.arm')
Esempio n. 5
0
def write_output(output):
    # Add datas to khafile
    dir_name = 'world'
    # Append world defs
    wrd = bpy.data.worlds['Arm']
    data_name = 'world' + wrd.world_defs + wrd.rp_defs

    # Reference correct shader context
    dat = output['material_datas'][0]
    dat['shader'] = data_name + '/' + data_name
    assets.add_shader2(dir_name, data_name)

    # Write material json
    path = 'build/compiled/Assets/materials/'
    asset_path = path + dat['name'] + '.arm'
    armutils.write_arm(asset_path, output)
    assets.add(asset_path)
Esempio n. 6
0
def write_color_irradiance(base_name, col):
    # Constant color
    irradiance_floats = [col[0], col[1], col[2]]
    for i in range(0, 24):
        irradiance_floats.append(0.0)

    envpath = 'build/compiled/Assets/envmaps'
    if not os.path.exists(envpath):
        os.makedirs(envpath)

    output_file = envpath + '/' + base_name + '_irradiance'

    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(output_file + '.arm', sh_json)

    assets.add(output_file + '.arm')
Esempio n. 7
0
def sh_to_json(sh_file):
    with open(sh_file + '.c') as f:
        sh_lines = f.read().splitlines()
    band0_line = sh_lines[5]
    band1_line = sh_lines[6]
    band2_line = sh_lines[7]

    irradiance_floats = []
    parse_band_floats(irradiance_floats, band0_line)
    parse_band_floats(irradiance_floats, band1_line)
    parse_band_floats(irradiance_floats, band2_line)
    
    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(sh_file + '.arm', sh_json)
    
    # Clean up .c
    os.remove(sh_file + '.c')
Esempio n. 8
0
def sh_to_json(sh_file):
    with open(sh_file + '.c') as f:
        sh_lines = f.read().splitlines()
    band0_line = sh_lines[5]
    band1_line = sh_lines[6]
    band2_line = sh_lines[7]

    irradiance_floats = []
    parse_band_floats(irradiance_floats, band0_line)
    parse_band_floats(irradiance_floats, band1_line)
    parse_band_floats(irradiance_floats, band2_line)

    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(sh_file + '.arm', sh_json)

    # Clean up .c
    os.remove(sh_file + '.c')
Esempio n. 9
0
def write_sky_irradiance(base_name):
    wrd = bpy.data.worlds['Arm']

    if wrd.generate_radiance_sky_type == 'Hosek':
        # Hosek spherical harmonics
        irradiance_floats = [
            1.5519331988822218, 2.3352207154503266, 2.997277451988076,
            0.2673894962434794, 0.4305630474135794, 0.11331825259716752,
            -0.04453633521758638, -0.038753175134160295, -0.021302768541875794,
            0.00055858020486499, 0.000371654770334503, 0.000126606145406403,
            -0.000135708721978705, -0.000787399554583089,
            -0.001550090690860059, 0.021947399048903773, 0.05453650591711572,
            0.08783641266630278, 0.17053593578630663, 0.14734127083304463,
            0.07775404698816404, -2.6924363189795e-05, -7.9350169701934e-05,
            -7.559914435231e-05, 0.27035455385870993, 0.23122918445556914,
            0.12158817295211832
        ]
        for i in range(0, len(irradiance_floats)):
            irradiance_floats[i] /= 2
    else:  # Fake
        irradiance_floats = [
            0.5282714503101548, 0.6576873502619733, 1.0692444882409775,
            0.17108712865136044, -0.08840906601412168, -0.5016437779078063,
            -0.05123227009753221, -0.06724088656181595, -0.07651659183264257,
            -0.09740705087869408, -0.19569235551561795, -0.3087497307203731,
            0.056717192983076405, 0.1109186355691673, 0.20616582000220154,
            0.013898321643280141, 0.05985657405787638, 0.12638202463080392,
            -0.003224443014484806, 0.013764449325286695, 0.04288850064700093,
            0.1796545401960917, 0.21595731080039757, 0.29144356515614844,
            0.10152875101705996, 0.2651761450155488, 0.4778582813756466
        ]

    envpath = 'build/compiled/Assets/envmaps'
    if not os.path.exists(envpath):
        os.makedirs(envpath)

    output_file = envpath + '/' + base_name + '_irradiance'

    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(output_file + '.arm', sh_json)

    assets.add(output_file + '.arm')
Esempio n. 10
0
def write_sky_irradiance(base_name):
    wrd = bpy.data.worlds['Arm']

    if wrd.generate_radiance_sky_type == 'Hosek':
        # Hosek spherical harmonics
        irradiance_floats = [1.5519331988822218,2.3352207154503266,2.997277451988076,0.2673894962434794,0.4305630474135794,0.11331825259716752,-0.04453633521758638,-0.038753175134160295,-0.021302768541875794,0.00055858020486499,0.000371654770334503,0.000126606145406403,-0.000135708721978705,-0.000787399554583089,-0.001550090690860059,0.021947399048903773,0.05453650591711572,0.08783641266630278,0.17053593578630663,0.14734127083304463,0.07775404698816404,-2.6924363189795e-05,-7.9350169701934e-05,-7.559914435231e-05,0.27035455385870993,0.23122918445556914,0.12158817295211832]
        for i in range(0, len(irradiance_floats)):
            irradiance_floats[i] /= 2;
    else: # Fake
        irradiance_floats = [0.5282714503101548,0.6576873502619733,1.0692444882409775,0.17108712865136044,-0.08840906601412168,-0.5016437779078063,-0.05123227009753221,-0.06724088656181595,-0.07651659183264257,-0.09740705087869408,-0.19569235551561795,-0.3087497307203731,0.056717192983076405,0.1109186355691673,0.20616582000220154,0.013898321643280141,0.05985657405787638,0.12638202463080392,-0.003224443014484806,0.013764449325286695,0.04288850064700093,0.1796545401960917,0.21595731080039757,0.29144356515614844,0.10152875101705996,0.2651761450155488,0.4778582813756466]

    if not os.path.exists('build/compiled/Assets/envmaps'):
        os.makedirs('build/compiled/Assets/envmaps')
    
    output_file = 'build/compiled/Assets/envmaps/' + base_name + '_irradiance'
    
    sh_json = {}
    sh_json['irradiance'] = irradiance_floats
    armutils.write_arm(output_file + '.arm', sh_json)

    assets.add(output_file + '.arm')
Esempio n. 11
0
def parse(material, mat_data, mat_users, rid):
    wrd = bpy.data.worlds['Arm']
    mat_state.material = material
    mat_state.nodes = material.node_tree.nodes
    mat_state.mat_data = mat_data
    mat_state.mat_users = mat_users
    mat_state.output_node = cycles.node_by_type(mat_state.nodes, 'OUTPUT_MATERIAL')
    if mat_state.output_node == None:
        return None
    matname = armutils.safe_source_name(material.name)
    mat_state.path = armutils.get_fp() + '/build/compiled/ShaderRaws/' + matname
    if not os.path.exists(mat_state.path):
        os.makedirs(mat_state.path)

    mat_state.data = ShaderData(material)
    mat_state.data.add_elem('pos', 3)
    mat_state.data.add_elem('nor', 3)

    if mat_users != None:
        for bo in mat_users[material]:
            # GPU Skinning
            if bo.find_armature() and armutils.is_bone_animation_enabled(bo) and wrd.generate_gpu_skin == True:
                mat_state.data.add_elem('bone', 4)
                mat_state.data.add_elem('weight', 4)
            
            # Instancing
            if bo.instanced_children or len(bo.particle_systems) > 0:
                mat_state.data.add_elem('off', 3)

    rpasses = mat_utils.get_rpasses(material)

    for rp in rpasses:
        c = {}
        c['name'] = rp
        c['bind_constants'] = []
        c['bind_textures'] = []
        mat_state.mat_data['contexts'].append(c)
        mat_state.mat_context = c

        if rp == 'mesh':
            const = {}
            const['name'] = 'receiveShadow'
            const['bool'] = material.receive_shadow
            c['bind_constants'].append(const)
            con = make_mesh.make(rp, rid)

        elif rp == 'shadowmap':
            con = make_shadowmap.make(rp, rpasses)

        elif rp == 'translucent':
            const = {}
            const['name'] = 'receiveShadow'
            const['bool'] = material.receive_shadow
            c['bind_constants'].append(const)
            con = make_transluc.make(rp)

        elif rp == 'overlay':
            con = make_overlay.make(rp)

        elif rp == 'decal':
            con = make_decal.make(rp)

        elif rp == 'depth':
            con = make_depth.make(rp)
        
        write_shaders(con, rp)

    armutils.write_arm(mat_state.path + '/' + matname + '_data.arm', mat_state.data.get())

    shader_data_name = matname + '_data'
    shader_data_path = 'build/compiled/ShaderRaws/' + matname + '/' + shader_data_name + '.arm'
    assets.add_shader_data(shader_data_path)
    mat_data['shader'] = shader_data_name + '/' + shader_data_name

    return mat_state.data.sd
Esempio n. 12
0
def parse(material, mat_data, mat_users, mat_armusers, rid):
    wrd = bpy.data.worlds['Arm']
    mat_state.material = material
    mat_state.nodes = material.node_tree.nodes
    mat_state.mat_data = mat_data
    mat_state.mat_users = mat_users
    mat_state.mat_armusers = mat_armusers
    mat_state.output_node = cycles.node_by_type(mat_state.nodes,
                                                'OUTPUT_MATERIAL')
    if mat_state.output_node == None:
        return None
    matname = armutils.safe_source_name(material.name)
    mat_state.rel_path = 'build/compiled/ShaderRaws/' + matname
    mat_state.path = armutils.get_fp() + '/' + mat_state.rel_path
    if not os.path.exists(mat_state.path):
        os.makedirs(mat_state.path)

    mat_state.data = ShaderData(material)
    mat_state.data.add_elem('pos', 3)
    mat_state.data.add_elem('nor', 3)

    if mat_users != None:
        for bo in mat_users[material]:
            # GPU Skinning
            if bo.find_armature() and armutils.is_bone_animation_enabled(
                    bo) and wrd.generate_gpu_skin == True:
                mat_state.data.add_elem('bone', 4)
                mat_state.data.add_elem('weight', 4)

            # Instancing
            if bo.instanced_children or len(bo.particle_systems) > 0:
                mat_state.data.add_elem('off', 3)

    rpasses = mat_utils.get_rpasses(material)

    for rp in rpasses:
        c = {}
        c['name'] = rp
        c['bind_constants'] = []
        c['bind_textures'] = []
        mat_state.mat_data['contexts'].append(c)
        mat_state.mat_context = c

        if rp == 'mesh':
            const = {}
            const['name'] = 'receiveShadow'
            const['bool'] = material.receive_shadow
            c['bind_constants'].append(const)
            con = mesh_make(rp, rid)

        elif rp == 'shadowmap':
            con = make_shadowmap.make(rp, rpasses)

        elif rp == 'translucent':
            const = {}
            const['name'] = 'receiveShadow'
            const['bool'] = material.receive_shadow
            c['bind_constants'].append(const)
            con = make_transluc.make(rp)

        elif rp == 'overlay':
            con = make_overlay.make(rp)

        elif rp == 'decal':
            con = make_decal.make(rp)

        elif rp == 'depth':
            con = make_depth.make(rp)

        elif rp == 'voxel':
            con = make_voxel.make(rp)

        elif rpass_hook != None:
            con = rpass_hook(rp)

        write_shaders(con, rp)

    armutils.write_arm(mat_state.path + '/' + matname + '_data.arm',
                       mat_state.data.get())

    shader_data_name = matname + '_data'
    shader_data_path = 'build/compiled/ShaderRaws/' + matname + '/' + shader_data_name + '.arm'
    assets.add_shader_data(shader_data_path)
    mat_data['shader'] = shader_data_name + '/' + shader_data_name

    return mat_state.data.sd, 'translucent' in rpasses, 'overlay' in rpasses, 'decal' in rpasses