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

Color mesh faces by #39

Open
guy4261 opened this issue Oct 27, 2019 · 1 comment
Open

Color mesh faces by #39

guy4261 opened this issue Oct 27, 2019 · 1 comment

Comments

@guy4261
Copy link

guy4261 commented Oct 27, 2019

I'm creating a coordinate frame using o3d.create_mesh_coordinate_frame(). If I'd display it in open3d (http://www.open3d.org/), it would look like this:

Screen Shot 2019-10-27 at 12 20 40

However, their Jupyter viewer does not work, which is why for Jupyter I'm visualizing using k3d. The conversion to a k3d.mesh object is straightforward for vertices and indices. However, I can't understand how coloring work. Can't I just make faces get the average of the triangle's colors? Seems like this is the way it's implemented in open3d... But perhaps I am missing something?

Thanks!

@barche
Copy link
Contributor

barche commented Oct 28, 2019

Hi,

To add face colors, you need to create a face attribute array, Python code suitable for a MeshModifierScript would be e.g.:

#python

import k3d

# Shallow-copy everything
context.output.copy(context.input)

# Get a modifiable version of the first polyhedron
output_poly = k3d.polyhedron.validate(context.output, context.output.primitives()[0])

# Create a per-face color array
Cs = output_poly.face_attributes().create("Cs", "k3d::color")

# Loop over the number of faces, adding a color for each
nb_faces = len(output_poly.face_first_loops())
for i in range(nb_faces):
	Cs.append(k3d.color(1,0,float(i)/nb_faces))

Here is a document with this script applied to a grid and the OpenGLColorFacePainter set up:
coloredfaces.k3d.zip

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

2 participants