three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Update Line.js

Open hlfkyo opened this issue 1 year ago • 7 comments

Modify a bug in ray intersection for line objects

Related issue: #If a sub object of a group object contains polylines, and the group object is scaled larger by the thi.scale parameter, the threshold parameter applied during ray intersection is not synchronously scaled larger, resulting in errors in ray intersection to many line segments.Sorry, my English is very poor.

Description Calculate the correct threshold value using the scaling factor of the matrixWorld. Previously, we used the scaling factor of the local matrix, but there was no valid scaling factor for the children nodes in the local matrix. The original scaling calculation method was too rough and inaccurate: 'const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );'

The new way is: const scaleMax = matrixWorld.getMaxScaleOnAxis();// const localThreshold = threshold / scaleMax;

Use the world matrix and find the maximum coefficient

hlfkyo avatar Oct 17 '24 08:10 hlfkyo

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 690.8
171.12
690.78
171.13
-23 B
+10 B
WebGPU 816.43
220.08
816.41
220.09
-23 B
+10 B
WebGPU Nodes 815.94
219.95
815.92
219.96
-23 B
+10 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 463.45
111.9
463.45
111.9
+0 B
+0 B
WebGPU 538.61
145.41
538.61
145.41
+0 B
+0 B
WebGPU Nodes 494.73
135.28
494.73
135.28
+0 B
+0 B

github-actions[bot] avatar Oct 17 '24 08:10 github-actions[bot]

The modified content is: modifyTo

Error examples: 微信图片_20241017165851

hlfkyo avatar Oct 17 '24 09:10 hlfkyo

Do you mind sharing a fiddle that demonstrates the limitations of current approach?

Mugen87 avatar Oct 19 '24 08:10 Mugen87

Do you mind sharing a fiddle that demonstrates the limitations of current approach?

I'm not sure how to create a Fiddle. I'll write a code snippet for you, could you please run this snippet and check the results?

hlfkyo avatar Oct 30 '24 12:10 hlfkyo

This may be related: https://github.com/mrdoob/three.js/pull/12520.

See the discussion -- particularly the comments regarding non-uniform scale.

WestLangley avatar Oct 30 '24 14:10 WestLangley

This may be related: #12520.

See the discussion -- particularly the comments regarding non-uniform scale.

Yes, they are the same type of problem, and finding the average is not the most important. I would use the maximum value instead for more accuracy. If more precision is needed, the average can be calculated based on the weight of each axis. The most important thing is to consider the scaling of the parent node.

hlfkyo avatar Oct 31 '24 07:10 hlfkyo

I'm wondering if it makes sense to switch the Line raycasting method to use the same type of screen space method that Line2 uses. It would require Line to be aware of the renderer resolution and the raycaster to have a camera but the current world-space capsule sizing used for screen space 1-pixel sized lines isn't so intuitive and causees issues like this. I suppose the downside is that what to do with raycasting when the lines are offscreen isn't so obvious but maybe we can come up with something.

gkjohnson avatar Jan 20 '25 08:01 gkjohnson