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

Changing point color dynamically #65

Open
mghildiy opened this issue May 4, 2018 · 3 comments
Open

Changing point color dynamically #65

mghildiy opened this issue May 4, 2018 · 3 comments

Comments

@mghildiy
Copy link

mghildiy commented May 4, 2018

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
Copy link
Owner

verma commented May 4, 2018

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
Copy link
Author

mghildiy commented May 5, 2018

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
Copy link
Owner

verma commented May 5, 2018

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?

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