drake icon indicating copy to clipboard operation
drake copied to clipboard

[meshcat] meshes set through SetTriangleMesh and SetTriangleColorMesh are all black

Open RussTedrake opened this issue 3 years ago • 1 comments

What happened?

mu = 1.0
height = .3
N = 50
t = np.linspace(0, 2*np.pi, N)
vertices = np.vstack((height*mu*np.sin(t), height*mu*np.cos(t), height + 0*t))
vertices = np.append(np.array([[0], [0], [height]]), vertices, axis=1)
vertices = np.append(np.zeros((3,1)), vertices, axis=1)
faces = []
for i in range(N):
    faces.append([0, i+2, i+3])
    faces.append([0, i+3, i+2])
    faces.append([1, i+2, i+3])
    faces.append([1, i+3, i+2])
faces = np.asarray(faces, dtype=int).T
meshcat.SetTriangleMesh("my_cone", vertices, faces, rgba=Rgba(0, 0, 1, 1))

produces a black cone. I was hoping for a blue one.

I was not able to resolve this using SetTriangleColorMesh. These methods are not very welll covered in meshcat_manual_test. And the units of the color matrix in SetTriangleColorMesh are not properly documented. [0,1]? [0, 255]? (Sorry! The fault is mine!)

There is a test that uses the TriangleSurfaceMesh (which calls these methods), and renders the color properly.

Version

No response

What operating system are you using?

No response

What installation option are you using?

No response

Relevant log output

No response

RussTedrake avatar Oct 13 '22 01:10 RussTedrake

Update: I resolved the color issue. I had 2 faces listed twice. I'm not sure why that broke everything, but the follow code works:

meshcat.Delete()

mu = 1.0
height = .3
N = 50
t = np.linspace(0, 2*np.pi, N)
vertices = np.vstack((height*mu*np.sin(t), height*mu*np.cos(t), height + 0*t))
vertices = np.append(np.array([[0], [0], [height]]), vertices, axis=1)
vertices = np.append(np.zeros((3,1)), vertices, axis=1)
faces = []
for i in range(N-1):
    faces.append([0, i+2, i+3])
    faces.append([1, i+3, i+2])
faces = np.asarray(faces, dtype=int).T
meshcat.SetTriangleMesh("my_cone", vertices, faces, rgba=Rgba(0, 0, 1, 1))

RussTedrake avatar Oct 13 '22 10:10 RussTedrake