verma / plasio

Drag-n-drop In-browser LAS/LAZ point cloud viewer. http://plas.io
http://plas.io
MIT License
507 stars 131 forks source link

Changing point color dynamically #65

Open mghildiy opened 6 years ago

mghildiy commented 6 years ago

I want to change colors of some points dynamically. I do following for point at location j:

geometry.attributes.color.array[3*j] = r; geometry.attributes.color.array[3*j+1] = g; geometry.attributes.color.array[3*j+2] = b; geometry.attributes.color.needsUpdate = true;

But change is not reflected. What else would I need to do to achieve it?

verma commented 6 years ago

I see a couple of problem with this code. I am not sure what the context this code is in or where you got the geometry variable. Could you clarify that a bit?

It seems to me you're setting assigning the color components to a single slot within the array (just the r channel), I would think that you'd need [3*j+1] and [3*j+2] to assign the green and the blue channels.

Also, if my memory serves me right, I am not sure there's an explicit array field under these buffers, e.g. look at this code here:

https://github.com/verma/plasio/blob/master/js/render.js#L1795

May be try playing with that code first and see if you can get the color to change etc.?

mghildiy commented 6 years ago

I do change all three channels. That was a typo from me, post edited. And, variable 'colors' manipulated in line #1795 is initially defined as:

var colors = geometry.attributes.color.array; We do have an array for color channels.

verma commented 6 years ago

Ah, that makes sense, thanks for clearing it up. I do see the colors definition now, your code seems correct.

That should have done it, three.js should have handled that. May be try a simpler example and see if you can get it to work, like a small three.js program may be?