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

Painting faces instead of vertices for meshes #1087

Closed
lucabergamini opened this issue Jul 23, 2019 · 12 comments
Closed

Painting faces instead of vertices for meshes #1087

lucabergamini opened this issue Jul 23, 2019 · 12 comments

Comments

@lucabergamini
Copy link

Is your feature request related to a problem? Please describe.
Currently, it's only possible to colour meshes via the vertex_colors attribute. However, this may introduces artifacts due to interpolation between the 3 points of a face if the colour source is related to faces instead of vertices (as a Blender's material).

ScreenCapture_2019-07-23-19-13-39

ScreenCapture_2019-07-23-19-19-25

Describe the solution you'd like
It would be great to have the possibility to set the colour for faces along with vertices (two different modes maybe?).

Describe alternatives you've considered
As the issue is related with the size of the faces, subdividing the mesh's triangles reduces its magnitude but also increases computation.

@yxlao
Copy link
Collaborator

yxlao commented Jul 23, 2019

Mesh is colored by vertices in open3d. To support "pure-color face", we can create 3 vertices for each triangle, and assign the same color to all 3 vertices for each triangle. That is, we'll end up with N triangles and exactly 3N vertices.

@griegler
Copy link
Contributor

@yxlao The problem with this approach is that it then isn't a triangle mesh anymore, but a triangle soup. Hence, algorithms like filtering will not work as expected. We should consider facet colors in our new design of the geometry classes.

@lucabergamini
Copy link
Author

What @yxlao proposes does work in fact, but as @griegler points out the mesh's triangles are no longer connected.

ScreenCapture_2019-07-24-12-13-13

Still, it's the only fix at the moment and should be enough for what I'm trying to do.
Here is a quick implementation to convert a mesh in independent triangles apt to be colourised as faces:

def split_triangles(mesh: o3d.TriangleMesh) -> o3d.TriangleMesh:
    """
    Split the mesh in independent triangles    
    """
    triangles = np.asarray(mesh.triangles).copy()
    vertices = np.asarray(mesh.vertices).copy()

    triangles_3 = np.zeros_like(triangles)
    vertices_3 = np.zeros((len(triangles) * 3, 3), dtype=vertices.dtype)

    for index_triangle, t in enumerate(triangles):
        index_vertex = index_triangle * 3
        vertices_3[index_vertex] = vertices[t[0]]
        vertices_3[index_vertex + 1] = vertices[t[1]]
        vertices_3[index_vertex + 2] = vertices[t[2]]

        triangles_3[index_triangle] = np.arange(index_vertex, index_vertex + 3)

    mesh_return = deepcopy(mesh)
    mesh_return.triangles = o3d.Vector3iVector(triangles_3)
    mesh_return.vertices = o3d.Vector3dVector(vertices_3)
    return mesh_return

@yxlao
Copy link
Collaborator

yxlao commented Jul 24, 2019

@griegler Right, this will become a triangle soup. So it's a temporary workaround.

@errissa
Copy link
Collaborator

errissa commented Nov 2, 2020

This feature is planned for 0.12 release.

@rubenverhack
Copy link

This feature is planned for 0.12 release.

Is there any news on this? For me this makes open3d unusable for my use case.

@germanros1987
Copy link
Contributor

@errissa is this available now?

@errissa
Copy link
Collaborator

errissa commented Dec 3, 2021

This is available now. The visualizer supports per-face colors. However, only t::geometry::TriangleMesh supports setting colors per-face using Set/GetTriangleColors. Also, if a TriangleMesh has both vertex and triangle colors the visualizer will use the vertex colors.

@errissa errissa closed this as completed Dec 16, 2021
@andy-beer
Copy link

andy-beer commented Aug 21, 2022

@errissa, Is there a python binding for SetTriangleColors?

@errissa
Copy link
Collaborator

errissa commented Aug 22, 2022

@andy-beer SetTriangleColors is a convenience function in C++ that isn't really necessary in Python. In Python the following is the exact equivalent of using SetTriangleColors:

mesh.triangle["colors"] = o3d.core.Tensor(...)

@Jerrypiglet
Copy link

@errissa Thanks for the info! However I found open3d.geometry.TriangleMesh has no property named 'triangle' as indicated here http://www.open3d.org/docs/release/python_api/open3d.geometry.TriangleMesh.html# Any ideas?

@cwreynolds cwreynolds mentioned this issue Apr 4, 2023
3 tasks
@lucagrementieri
Copy link

The property triangle exists for the object open3d.t.geometry.TriangleMesh based on tensors, see http://www.open3d.org/docs/release/python_api/open3d.t.geometry.TriangleMesh.html#open3d.t.geometry.TriangleMesh

The comment refers to a mesh object from this class, the color assignment works and colors can be visualized correctly using o3d.visualization.draw.

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

No branches or pull requests

10 participants