K-3D/k3d

Color mesh faces by

guy4261 opened this issue · 1 comments

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!

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