allenai / Holodeck

CVPR 2024: Language Guided Generation of 3D Embodied AI Environments.
https://yueyang1996.github.io/holodeck
Apache License 2.0
304 stars 25 forks source link

How to map the material files back to the assets? #23

Closed wungsui closed 4 months ago

wungsui commented 4 months ago

l used your code to map the material files back to the assets the step is: 1.use your code to transfer the pkl.gz to obj,and I get a obj file 2.open blender and import this objthen create a material in the material properties 3.create a new script in blender and copy the function :create_and_assign_textures ,and run,but it turned out false

the blender script is:

import bpy

def create_and_assign_textures(material, asset_id):
    albedo_path = f"/home/ubuntu/guojingyi/Holodeck/data/objaverse_holodeck/09_23_combine_scale/processed_2023_09_23_combine_scale/{asset_id}/albedo.jpg"
    emission_path = f"/home/ubuntu/guojingyi/Holodeck/data/objaverse_holodeck/09_23_combine_scale/processed_2023_09_23_combine_scale/{asset_id}/emission.jpg"
    normal_path = f"/home/ubuntu/guojingyi/Holodeck/data/objaverse_holodeck/09_23_combine_scale/processed_2023_09_23_combine_scale/{asset_id}/normal.jpg"
    # Enable 'Use Nodes'
    material.use_nodes = True
    nodes = material.node_tree.nodes

    # Find or create Principled BSDF node
    bsdf = next((node for node in nodes if node.type == 'BSDF_PRINCIPLED'), None)
    if not bsdf:
        bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
        bsdf.location = (0, 0)

    # Function to create or get an image texture node
    def get_image_node(img_path, location):
        for node in nodes:
            if node.type == 'TEX_IMAGE' and node.image and node.image.filepath == img_path:
                return node
        new_node = nodes.new('ShaderNodeTexImage')
        new_node.image = bpy.data.images.load(img_path)
        new_node.location = location
        return new_node

    # Create or get Albedo Texture node
    albedo_tex = get_image_node(albedo_path, (-300, 100))
    material.node_tree.links.new(bsdf.inputs['Base Color'], albedo_tex.outputs['Color'])

    # Create or get Normal Map node
    normal_map = next((node for node in nodes if node.type == 'NORMAL_MAP'), None)
    if not normal_map:
        normal_map = nodes.new('ShaderNodeNormalMap')
        normal_map.location = (-300, -300)
    normal_tex = get_image_node(normal_path, (-500, -300))
    material.node_tree.links.new(normal_map.inputs['Color'], normal_tex.outputs['Color'])
    material.node_tree.links.new(bsdf.inputs['Normal'], normal_map.outputs['Normal'])

material = bpy.data.materials['Material.007']
create_and_assign_textures(material, '0a7d9f70a6774519810c3cc027cb7740')
sunfanyunn commented 4 months ago

Could you elaborate on what you meant by it turns out to be false? I could try to help if you can paste the error message here.

wungsui commented 4 months ago

The code run successfully and don't throw error message,but the material are not mapped correctly, do I need modify the param in your function "create_and_assign_textures"? 捕获

wungsui commented 4 months ago

If I want to import the room in blender,as you said,I should import the fbx to blender ,then using bpy to programmatically map the texture files back by using your code,it sounds like a hard work