Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to deal with "emission.jpg" and "normal.jpg" using trimesh #2211

Open
ydove0324 opened this issue Apr 18, 2024 · 0 comments
Open

how to deal with "emission.jpg" and "normal.jpg" using trimesh #2211

ydove0324 opened this issue Apr 18, 2024 · 0 comments

Comments

@ydove0324
Copy link

the code looks like this

    albedo_image = Image.open(f"{path}/albedo.jpg")
    emission_image = Image.open(f"{path}/emission.jpg")
    normal_image = Image.open(f"{path}/normal.jpg")

    # 创建 mesh 对象
    mesh = trimesh.Trimesh()

    # 提取顶点坐标并转换为 NumPy 数组
    vertices = np.array([list(vertex_coords.values()) for vertex_coords in data["vertices"]], dtype=np.float64)
    mesh.vertices = vertices

    # 提取法线并转换为 NumPy 数组
    normals = np.array([list(normal.values()) for normal in data["normals"]], dtype=np.float64)
    mesh.vertex_normals = normals

    # 提取三角形索引
    triangles = np.array(data["triangles"], dtype=np.int32).reshape(-1, 3)
    mesh.faces = triangles

    # 填充纹理坐标信息
    uvs = np.array([list(uv.values()) for uv in data["uvs"]], dtype=np.float64)
    
    # 创建纹理和材质
    albedo_material = trimesh.visual.texture.SimpleMaterial(image=albedo_image)
    emission_material = trimesh.visual.texture.SimpleMaterial(image=emission_image)
    normal_material = trimesh.visual.texture.SimpleMaterial(image=normal_image)
    
    # 应用纹理
    material = trimesh.visual.material.TextureMaterial(
        diffuse=albedo_image, 
        emissive=emission_image, 
        normal_map=normal_image
    )

although it's a wrong code. But I want to load emission and normal into the mesh

how to use trimesh to deal with them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant