From 5c70ba0441a1cbad58c6195d7e993114b0736e3a Mon Sep 17 00:00:00 2001 From: 06wj <06wj@163.com> Date: Wed, 19 Sep 2018 11:10:02 +0800 Subject: [PATCH 1/2] fixed sprite raycast bug when sizeAttenuation is false --- examples/webgl_raycast_sprite.html | 23 ++++++++++++++++++++++- src/objects/Sprite.js | 6 ++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/examples/webgl_raycast_sprite.html b/examples/webgl_raycast_sprite.html index 9cc1a7936574ad..15988e313ccf29 100644 --- a/examples/webgl_raycast_sprite.html +++ b/examples/webgl_raycast_sprite.html @@ -87,6 +87,26 @@ sprite.material.rotation = Math.PI / 3; group2.add( sprite ); + + var num = 20; + var radius = 10; + while(num --) { + + var x = Math.random() - 0.5; + var y = Math.random() - 0.5; + var z = Math.random() - 0.5; + + var sprite = new THREE.Sprite( new THREE.SpriteMaterial( { color: '#96f' } )); + sprite.position.set( x, y, z ); + sprite.position.normalize(); + sprite.position.multiplyScalar( radius ); + sprite.scale.set(0.05 * Math.random(), 0.05 * Math.random(), 0.05 * Math.random()); + sprite.material.rotation = Math.random() * Math.PI * 2; + sprite.material.sizeAttenuation = false; + group.add( sprite ); + + } + window.addEventListener( 'resize', onWindowResize, false ); window.addEventListener( "mousemove", onDocumentMouseMove, false ); @@ -115,7 +135,7 @@ event.preventDefault(); if ( selectedObject ) { - selectedObject.material.color.set( '#69f' ); + selectedObject.material.color.set( selectedObject.originColor ); selectedObject = null; } @@ -132,6 +152,7 @@ if ( res && res.object ) { selectedObject = res.object; + selectedObject.originColor = selectedObject.material.color.getHex(); selectedObject.material.color.set( '#f00' ); } diff --git a/src/objects/Sprite.js b/src/objects/Sprite.js index e653fc1c464f1a..2b6405c618f822 100644 --- a/src/objects/Sprite.js +++ b/src/objects/Sprite.js @@ -104,6 +104,12 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), { viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld ); mvPosition.setFromMatrixPosition( this.modelViewMatrix ); + if ( ! this.material.sizeAttenuation ) { + + worldScale.multiplyScalar( - mvPosition.z ); + + } + var rotation = this.material.rotation; var sin, cos; if ( rotation !== 0 ) { From b95fb7905cda081613086df360a9256c4f12ef5e Mon Sep 17 00:00:00 2001 From: 06wj <06wj@163.com> Date: Wed, 19 Sep 2018 12:33:12 +0800 Subject: [PATCH 2/2] update the sizeAttenuation check --- src/objects/Sprite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objects/Sprite.js b/src/objects/Sprite.js index 2b6405c618f822..e0a629a8a77e89 100644 --- a/src/objects/Sprite.js +++ b/src/objects/Sprite.js @@ -104,7 +104,7 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), { viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld ); mvPosition.setFromMatrixPosition( this.modelViewMatrix ); - if ( ! this.material.sizeAttenuation ) { + if ( this.material.sizeAttenuation === false ) { worldScale.multiplyScalar( - mvPosition.z );