diff --git a/examples/webgl_texture_raycast.html b/examples/webgl_texture_raycast.html index f66c56bbe761d17f806613d4c0edfc7d94e3a63c..b60f4dffba340199fe7341bd76395ba454ae1b71 100644 --- a/examples/webgl_texture_raycast.html +++ b/examples/webgl_texture_raycast.html @@ -21,249 +21,295 @@ top: 0px; width: 100%; padding: 5px; } + + #controls { + position: absolute; + text-align:left; + top: 40px; + left: 5px; + padding: 5px; + } + + .control { + margin-bottom: 3px; + } + + input { + width: 50px; + }
three.js - texture intersection
Left to right: buffer geometry - geometry - indexed buffer geometry
- - +
+ Circle +
+ WrapS : +
+
+ WrapT : +
+
+ Offset : X + Y
+
+
+ Repeat : X + Y +
+
+ - + diff --git a/src/objects/Mesh.js b/src/objects/Mesh.js index 3badf27706c78289f2fd51e35e4e61b9150bf6a7..bdf3e9e93b72b3ac0deea2c972b6d7c8e55808ea 100644 --- a/src/objects/Mesh.js +++ b/src/objects/Mesh.js @@ -173,7 +173,7 @@ THREE.Mesh.prototype.raycast = ( function () { if ( intersectionPoint === null ) continue; - pInter.copy(intersectionPoint); + pInter.copy( intersectionPoint ); intersectionPoint.applyMatrix4( this.matrixWorld ); var distance = raycaster.ray.origin.distanceTo( intersectionPoint ); @@ -229,7 +229,7 @@ THREE.Mesh.prototype.raycast = ( function () { if ( intersectionPoint === null ) continue; - pInter.copy(intersectionPoint); + pInter.copy( intersectionPoint ); intersectionPoint.applyMatrix4( this.matrixWorld ); var distance = raycaster.ray.origin.distanceTo( intersectionPoint ); @@ -331,7 +331,7 @@ THREE.Mesh.prototype.raycast = ( function () { if ( intersectionPoint === null ) continue; - pInter.copy(intersectionPoint); + pInter.copy( intersectionPoint ); intersectionPoint.applyMatrix4( this.matrixWorld ); var distance = raycaster.ray.origin.distanceTo( intersectionPoint ); diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 44e5f7fb080d500e2a86b95ad25e4e6c00eab878..44a57efc569a85f64ef90d03ece77a0c4b88fe08 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -189,52 +189,79 @@ THREE.Texture.prototype = { transformUv: function ( uv ) { - if ( this.mapping !== THREE.UVMapping ) { - return; - } + if ( this.mapping !== THREE.UVMapping ) return; uv.multiply( this.repeat ); uv.add( this.offset ); if ( uv.x < 0 || uv.x > 1 ) { + switch ( this.wrapS ) { + case THREE.RepeatWrapping: + uv.x = uv.x - Math.floor( uv.x ); break; + case THREE.ClampToEdgeWrapping: + uv.x = uv.x < 0 ? 0 : 1; break; + case THREE.MirroredRepeatWrapping: - if ( Math.abs(Math.floor( uv.x ) % 2) === 1 ) { + + if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) { + uv.x = Math.ceil( uv.x ) - uv.x; + } else { + uv.x = uv.x - Math.floor( uv.x ); + } - break; + break; + } + } if ( uv.y < 0 || uv.y > 1 ) { + switch ( this.wrapT ) { + case THREE.RepeatWrapping: + uv.y = uv.y - Math.floor( uv.y ); break; + case THREE.ClampToEdgeWrapping: + uv.y = uv.y < 0 ? 0 : 1; break; + case THREE.MirroredRepeatWrapping: + if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) { + uv.y = Math.ceil( uv.y ) - uv.y; + } else { + uv.y = uv.y - Math.floor( uv.y ); + } break; + } + } if ( this.flipY ) { + uv.y = 1 - uv.y; + } + } };