LineSegmentsGeometry: Calling "setPositions" twice does not update the lines correctly
See original GitHub issueDescribe the bug
Calling LineSegmentsGeometry.setPositions
a second time with more line segments still only renders the amount of line segments specified in the first call. Everything works as expected if you call “dispose” before calling “setPositions” again.
I’m not exactly sure why it’s happening. Perhaps it’s an issue related to instanced geometry rendering?
To Reproduce
Steps to reproduce the behavior:
- Create a
LineSegments2
object - Call
line.geometry.setPositions
with 1 line segment - See that it renders 1 line
- 1 second later call
line.geometry.setPositions
with 2 line segments - See that it only renders the first of the two lines
Code
line = new LineSegments2();
line.geometry.setPositions( [ 0, -0.5, 0, 0, 0.5, 0 ] );
setTimeout( () => {
// uncomment to display both lines
// line.geometry.dispose();
line.geometry.setPositions( [
0, -0.5, 0, -0.5, 0.5, 0,
0, 0, 0, 0.5, 0, 0,
] );
}, 1000 );
Live example
https://jsfiddle.net/rhjeL01n/
Expected behavior
The correct amount of lines are rendered after calling “setPositions”.
Screenshots
If applicable, add screenshots to help explain your problem (drag and drop the image).
Platform:
- Device: Desktop
- OS: Windows
- Browser: Chrome
- Three.js version: latest (r126)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
threejs linewidth property with LineSegmentsGeometry and ...
I'm trying to make lines that are wider than one pixel using the LineMaterial and LineSegments2 classes that are included with the threejs ......
Read more >[SOLVED ] Problem with Line Renderer Positions? - Unity Forum
In short the line renderer isn't drawing a line in the correct place and it appears ... Start is called before the first...
Read more >Out of control memory when updating position of lines within ...
Hello, I was wondering if the following problem is a result of user error or if it is a bug. When updating the...
Read more >three Float32BufferAttribute JavaScript Examples
You can vote up the ones you like or vote down the ones you don't like, ... probably can't create line materials correctly,...
Read more >Multiplayer racing game for AP CSP Create task - Jonathan Lam
socketId === socket.id).name = name; // tell sockets to update names ... false) { // only do if room exists (room may not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gkjohnson
Could you create a sufficiently-large buffer and then set
InstancedBufferGeometry.instanceCount
? That would be one way to resize.Yes,
_maxInstanceCount
is a bit hacky. We knew that when it was added.I agree it is hard to update the values in the buffers because the indexing is complex. I would welcome API improvements in that regard.
You should modify the existing buffers. Not overwrite them (with new sizes). Nowhere in the examples is your pattern demonstrated.
If you need to change the size, dispose the geometry (since you can’t dispose buffer attributes) and create a new one. Feel free to clarify this in the documentation.