Open philliptay opened 4 years ago
This is how I have been setting colors on a Points
object. Maybe it helps?
import pythreejs as p3
import numpy as np
N = 1000
geometry = p3.BufferGeometry(
attributes={
'position':
p3.BufferAttribute(array=20.0 * (np.random.random((N, 3)) - 0.5).astype('float32')),
'color':
p3.BufferAttribute(array=np.zeros([N, 3], dtype='float32'))
})
material = p3.PointsMaterial(vertexColors='VertexColors')
points = p3.Points(geometry=geometry, material=material)
width = 800
height = 500
camera = p3.PerspectiveCamera(position=[40.0, 0, 0], aspect=width / height)
scene = p3.Scene(children=[camera, points], background="#f0f0f0")
controls = p3.OrbitControls(controlling=camera)
renderer = p3.Renderer(camera=camera,
scene=scene,
controls=[controls],
width=width,
height=height)
renderer
Initially all the points are black:
Then, by setting the array
of the color attribute,
geometry.attributes["color"].array = np.random.random((N, 3)).astype('float32')
I get
I am trying to change the color of the face of a mesh with buffer geometry when it is clicked on, but nothing I've tried seems to have any effect on the display. Here is my code so far, with the
on_picked
function attempting to change the color of a picked face. Many of my tries are commented out, from trying to exec the three.js methods to set attributes, to modifying the array of the buffer attribute within python, to changing the entire dict of the buffer geometry - all to no avail. Any guidance would be appreciated.