Initial commit
This commit is contained in:
362
HTML/ThreeJS/node_modules/three/examples/js/interactive/HTMLMesh.js
generated
vendored
Normal file
362
HTML/ThreeJS/node_modules/three/examples/js/interactive/HTMLMesh.js
generated
vendored
Normal file
@@ -0,0 +1,362 @@
|
||||
( function () {
|
||||
|
||||
class HTMLMesh extends THREE.Mesh {
|
||||
|
||||
constructor( dom ) {
|
||||
|
||||
const texture = new HTMLTexture( dom );
|
||||
const geometry = new THREE.PlaneGeometry( texture.image.width * 0.001, texture.image.height * 0.001 );
|
||||
const material = new THREE.MeshBasicMaterial( {
|
||||
map: texture,
|
||||
toneMapped: false
|
||||
} );
|
||||
super( geometry, material );
|
||||
|
||||
function onEvent( event ) {
|
||||
|
||||
material.map.dispatchDOMEvent( event );
|
||||
|
||||
}
|
||||
|
||||
this.addEventListener( 'mousedown', onEvent );
|
||||
this.addEventListener( 'mousemove', onEvent );
|
||||
this.addEventListener( 'mouseup', onEvent );
|
||||
this.addEventListener( 'click', onEvent );
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
geometry.dispose();
|
||||
material.dispose();
|
||||
material.map.dispose();
|
||||
this.removeEventListener( 'mousedown', onEvent );
|
||||
this.removeEventListener( 'mousemove', onEvent );
|
||||
this.removeEventListener( 'mouseup', onEvent );
|
||||
this.removeEventListener( 'click', onEvent );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class HTMLTexture extends THREE.CanvasTexture {
|
||||
|
||||
constructor( dom ) {
|
||||
|
||||
super( html2canvas( dom ) );
|
||||
this.dom = dom;
|
||||
this.anisotropy = 16;
|
||||
this.encoding = THREE.sRGBEncoding;
|
||||
this.minFilter = THREE.LinearFilter;
|
||||
this.magFilter = THREE.LinearFilter; // Create an observer on the DOM, and run html2canvas update in the next loop
|
||||
|
||||
const observer = new MutationObserver( () => {
|
||||
|
||||
if ( ! this.scheduleUpdate ) {
|
||||
|
||||
// ideally should use xr.requestAnimationFrame, here setTimeout to avoid passing the renderer
|
||||
this.scheduleUpdate = setTimeout( () => this.update(), 16 );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
const config = {
|
||||
attributes: true,
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true
|
||||
};
|
||||
observer.observe( dom, config );
|
||||
this.observer = observer;
|
||||
|
||||
}
|
||||
|
||||
dispatchDOMEvent( event ) {
|
||||
|
||||
if ( event.data ) {
|
||||
|
||||
htmlevent( this.dom, event.type, event.data.x, event.data.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
this.image = html2canvas( this.dom );
|
||||
this.needsUpdate = true;
|
||||
this.scheduleUpdate = null;
|
||||
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
||||
if ( this.observer ) {
|
||||
|
||||
this.observer.disconnect();
|
||||
|
||||
}
|
||||
|
||||
this.scheduleUpdate = clearTimeout( this.scheduleUpdate );
|
||||
super.dispose();
|
||||
|
||||
}
|
||||
|
||||
} //
|
||||
|
||||
|
||||
const canvases = new WeakMap();
|
||||
|
||||
function html2canvas( element ) {
|
||||
|
||||
const range = document.createRange();
|
||||
|
||||
function Clipper( context ) {
|
||||
|
||||
const clips = [];
|
||||
let isClipping = false;
|
||||
|
||||
function doClip() {
|
||||
|
||||
if ( isClipping ) {
|
||||
|
||||
isClipping = false;
|
||||
context.restore();
|
||||
|
||||
}
|
||||
|
||||
if ( clips.length === 0 ) return;
|
||||
let minX = - Infinity,
|
||||
minY = - Infinity;
|
||||
let maxX = Infinity,
|
||||
maxY = Infinity;
|
||||
|
||||
for ( let i = 0; i < clips.length; i ++ ) {
|
||||
|
||||
const clip = clips[ i ];
|
||||
minX = Math.max( minX, clip.x );
|
||||
minY = Math.max( minY, clip.y );
|
||||
maxX = Math.min( maxX, clip.x + clip.width );
|
||||
maxY = Math.min( maxY, clip.y + clip.height );
|
||||
|
||||
}
|
||||
|
||||
context.save();
|
||||
context.beginPath();
|
||||
context.rect( minX, minY, maxX - minX, maxY - minY );
|
||||
context.clip();
|
||||
isClipping = true;
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
add: function ( clip ) {
|
||||
|
||||
clips.push( clip );
|
||||
doClip();
|
||||
|
||||
},
|
||||
remove: function () {
|
||||
|
||||
clips.pop();
|
||||
doClip();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function drawText( style, x, y, string ) {
|
||||
|
||||
if ( string !== '' ) {
|
||||
|
||||
if ( style.textTransform === 'uppercase' ) {
|
||||
|
||||
string = string.toUpperCase();
|
||||
|
||||
}
|
||||
|
||||
context.font = style.fontSize + ' ' + style.fontFamily;
|
||||
context.textBaseline = 'top';
|
||||
context.fillStyle = style.color;
|
||||
context.fillText( string, x, y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawBorder( style, which, x, y, width, height ) {
|
||||
|
||||
const borderWidth = style[ which + 'Width' ];
|
||||
const borderStyle = style[ which + 'Style' ];
|
||||
const borderColor = style[ which + 'Color' ];
|
||||
|
||||
if ( borderWidth !== '0px' && borderStyle !== 'none' && borderColor !== 'transparent' && borderColor !== 'rgba(0, 0, 0, 0)' ) {
|
||||
|
||||
context.strokeStyle = borderColor;
|
||||
context.beginPath();
|
||||
context.moveTo( x, y );
|
||||
context.lineTo( x + width, y + height );
|
||||
context.stroke();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawElement( element, style ) {
|
||||
|
||||
let x = 0,
|
||||
y = 0,
|
||||
width = 0,
|
||||
height = 0;
|
||||
|
||||
if ( element.nodeType === 3 ) {
|
||||
|
||||
// text
|
||||
range.selectNode( element );
|
||||
const rect = range.getBoundingClientRect();
|
||||
x = rect.left - offset.left - 0.5;
|
||||
y = rect.top - offset.top - 0.5;
|
||||
width = rect.width;
|
||||
height = rect.height;
|
||||
drawText( style, x, y, element.nodeValue.trim() );
|
||||
|
||||
} else if ( element instanceof HTMLCanvasElement ) {
|
||||
|
||||
// Canvas element
|
||||
if ( element.style.display === 'none' ) return;
|
||||
context.save();
|
||||
const dpr = window.devicePixelRatio;
|
||||
context.scale( 1 / dpr, 1 / dpr );
|
||||
context.drawImage( element, 0, 0 );
|
||||
context.restore();
|
||||
|
||||
} else {
|
||||
|
||||
if ( element.style.display === 'none' ) return;
|
||||
const rect = element.getBoundingClientRect();
|
||||
x = rect.left - offset.left - 0.5;
|
||||
y = rect.top - offset.top - 0.5;
|
||||
width = rect.width;
|
||||
height = rect.height;
|
||||
style = window.getComputedStyle( element );
|
||||
const backgroundColor = style.backgroundColor;
|
||||
|
||||
if ( backgroundColor !== 'transparent' && backgroundColor !== 'rgba(0, 0, 0, 0)' ) {
|
||||
|
||||
context.fillStyle = backgroundColor;
|
||||
context.fillRect( x, y, width, height );
|
||||
|
||||
}
|
||||
|
||||
drawBorder( style, 'borderTop', x, y, width, 0 );
|
||||
drawBorder( style, 'borderLeft', x, y, 0, height );
|
||||
drawBorder( style, 'borderBottom', x, y + height, width, 0 );
|
||||
drawBorder( style, 'borderRight', x + width, y, 0, height );
|
||||
|
||||
if ( element.type === 'color' || element.type === 'text' || element.type === 'number' ) {
|
||||
|
||||
clipper.add( {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
} );
|
||||
drawText( style, x + parseInt( style.paddingLeft ), y + parseInt( style.paddingTop ), element.value );
|
||||
clipper.remove();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
// debug
|
||||
context.strokeStyle = '#' + Math.random().toString( 16 ).slice( - 3 );
|
||||
context.strokeRect( x - 0.5, y - 0.5, width + 1, height + 1 );
|
||||
*/
|
||||
|
||||
|
||||
const isClipping = style.overflow === 'auto' || style.overflow === 'hidden';
|
||||
if ( isClipping ) clipper.add( {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
} );
|
||||
|
||||
for ( let i = 0; i < element.childNodes.length; i ++ ) {
|
||||
|
||||
drawElement( element.childNodes[ i ], style );
|
||||
|
||||
}
|
||||
|
||||
if ( isClipping ) clipper.remove();
|
||||
|
||||
}
|
||||
|
||||
const offset = element.getBoundingClientRect();
|
||||
let canvas;
|
||||
|
||||
if ( canvases.has( element ) ) {
|
||||
|
||||
canvas = canvases.get( element );
|
||||
|
||||
} else {
|
||||
|
||||
canvas = document.createElement( 'canvas' );
|
||||
canvas.width = offset.width;
|
||||
canvas.height = offset.height;
|
||||
|
||||
}
|
||||
|
||||
const context = canvas.getContext( '2d'
|
||||
/*, { alpha: false }*/
|
||||
);
|
||||
const clipper = new Clipper( context ); // console.time( 'drawElement' );
|
||||
|
||||
drawElement( element ); // console.timeEnd( 'drawElement' );
|
||||
|
||||
return canvas;
|
||||
|
||||
}
|
||||
|
||||
function htmlevent( element, event, x, y ) {
|
||||
|
||||
const mouseEventInit = {
|
||||
clientX: x * element.offsetWidth + element.offsetLeft,
|
||||
clientY: y * element.offsetHeight + element.offsetTop,
|
||||
view: element.ownerDocument.defaultView
|
||||
};
|
||||
window.dispatchEvent( new MouseEvent( event, mouseEventInit ) );
|
||||
const rect = element.getBoundingClientRect();
|
||||
x = x * rect.width + rect.left;
|
||||
y = y * rect.height + rect.top;
|
||||
|
||||
function traverse( element ) {
|
||||
|
||||
if ( element.nodeType !== 3 ) {
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
|
||||
if ( x > rect.left && x < rect.right && y > rect.top && y < rect.bottom ) {
|
||||
|
||||
element.dispatchEvent( new MouseEvent( event, mouseEventInit ) );
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0; i < element.childNodes.length; i ++ ) {
|
||||
|
||||
traverse( element.childNodes[ i ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
traverse( element );
|
||||
|
||||
}
|
||||
|
||||
THREE.HTMLMesh = HTMLMesh;
|
||||
|
||||
} )();
|
||||
100
HTML/ThreeJS/node_modules/three/examples/js/interactive/InteractiveGroup.js
generated
vendored
Normal file
100
HTML/ThreeJS/node_modules/three/examples/js/interactive/InteractiveGroup.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
( function () {
|
||||
|
||||
const _pointer = new THREE.Vector2();
|
||||
|
||||
const _event = {
|
||||
type: '',
|
||||
data: _pointer
|
||||
};
|
||||
|
||||
class InteractiveGroup extends THREE.Group {
|
||||
|
||||
constructor( renderer, camera ) {
|
||||
|
||||
super();
|
||||
const scope = this;
|
||||
const raycaster = new THREE.Raycaster();
|
||||
const tempMatrix = new THREE.Matrix4(); // Pointer Events
|
||||
|
||||
const element = renderer.domElement;
|
||||
|
||||
function onPointerEvent( event ) {
|
||||
|
||||
event.stopPropagation();
|
||||
_pointer.x = event.clientX / element.clientWidth * 2 - 1;
|
||||
_pointer.y = - ( event.clientY / element.clientHeight ) * 2 + 1;
|
||||
raycaster.setFromCamera( _pointer, camera );
|
||||
const intersects = raycaster.intersectObjects( scope.children, false );
|
||||
|
||||
if ( intersects.length > 0 ) {
|
||||
|
||||
const intersection = intersects[ 0 ];
|
||||
const object = intersection.object;
|
||||
const uv = intersection.uv;
|
||||
_event.type = event.type;
|
||||
|
||||
_event.data.set( uv.x, 1 - uv.y );
|
||||
|
||||
object.dispatchEvent( _event );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
element.addEventListener( 'pointerdown', onPointerEvent );
|
||||
element.addEventListener( 'pointerup', onPointerEvent );
|
||||
element.addEventListener( 'pointermove', onPointerEvent );
|
||||
element.addEventListener( 'mousedown', onPointerEvent );
|
||||
element.addEventListener( 'mouseup', onPointerEvent );
|
||||
element.addEventListener( 'mousemove', onPointerEvent );
|
||||
element.addEventListener( 'click', onPointerEvent ); // WebXR Controller Events
|
||||
// TODO: Dispatch pointerevents too
|
||||
|
||||
const events = {
|
||||
'move': 'mousemove',
|
||||
'select': 'click',
|
||||
'selectstart': 'mousedown',
|
||||
'selectend': 'mouseup'
|
||||
};
|
||||
|
||||
function onXRControllerEvent( event ) {
|
||||
|
||||
const controller = event.target;
|
||||
tempMatrix.identity().extractRotation( controller.matrixWorld );
|
||||
raycaster.ray.origin.setFromMatrixPosition( controller.matrixWorld );
|
||||
raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix );
|
||||
const intersections = raycaster.intersectObjects( scope.children, false );
|
||||
|
||||
if ( intersections.length > 0 ) {
|
||||
|
||||
const intersection = intersections[ 0 ];
|
||||
const object = intersection.object;
|
||||
const uv = intersection.uv;
|
||||
_event.type = events[ event.type ];
|
||||
|
||||
_event.data.set( uv.x, 1 - uv.y );
|
||||
|
||||
object.dispatchEvent( _event );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const controller1 = renderer.xr.getController( 0 );
|
||||
controller1.addEventListener( 'move', onXRControllerEvent );
|
||||
controller1.addEventListener( 'select', onXRControllerEvent );
|
||||
controller1.addEventListener( 'selectstart', onXRControllerEvent );
|
||||
controller1.addEventListener( 'selectend', onXRControllerEvent );
|
||||
const controller2 = renderer.xr.getController( 1 );
|
||||
controller2.addEventListener( 'move', onXRControllerEvent );
|
||||
controller2.addEventListener( 'select', onXRControllerEvent );
|
||||
controller2.addEventListener( 'selectstart', onXRControllerEvent );
|
||||
controller2.addEventListener( 'selectend', onXRControllerEvent );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
THREE.InteractiveGroup = InteractiveGroup;
|
||||
|
||||
} )();
|
||||
262
HTML/ThreeJS/node_modules/three/examples/js/interactive/SelectionBox.js
generated
vendored
Normal file
262
HTML/ThreeJS/node_modules/three/examples/js/interactive/SelectionBox.js
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
( function () {
|
||||
|
||||
/**
|
||||
* This is a class to check whether objects are in a selection area in 3D space
|
||||
*/
|
||||
|
||||
const _frustum = new THREE.Frustum();
|
||||
|
||||
const _center = new THREE.Vector3();
|
||||
|
||||
const _tmpPoint = new THREE.Vector3();
|
||||
|
||||
const _vecNear = new THREE.Vector3();
|
||||
|
||||
const _vecTopLeft = new THREE.Vector3();
|
||||
|
||||
const _vecTopRight = new THREE.Vector3();
|
||||
|
||||
const _vecDownRight = new THREE.Vector3();
|
||||
|
||||
const _vecDownLeft = new THREE.Vector3();
|
||||
|
||||
const _vecFarTopLeft = new THREE.Vector3();
|
||||
|
||||
const _vecFarTopRight = new THREE.Vector3();
|
||||
|
||||
const _vecFarDownRight = new THREE.Vector3();
|
||||
|
||||
const _vecFarDownLeft = new THREE.Vector3();
|
||||
|
||||
const _vectemp1 = new THREE.Vector3();
|
||||
|
||||
const _vectemp2 = new THREE.Vector3();
|
||||
|
||||
const _vectemp3 = new THREE.Vector3();
|
||||
|
||||
const _matrix = new THREE.Matrix4();
|
||||
|
||||
const _quaternion = new THREE.Quaternion();
|
||||
|
||||
const _scale = new THREE.Vector3();
|
||||
|
||||
class SelectionBox {
|
||||
|
||||
constructor( camera, scene, deep = Number.MAX_VALUE ) {
|
||||
|
||||
this.camera = camera;
|
||||
this.scene = scene;
|
||||
this.startPoint = new THREE.Vector3();
|
||||
this.endPoint = new THREE.Vector3();
|
||||
this.collection = [];
|
||||
this.instances = {};
|
||||
this.deep = deep;
|
||||
|
||||
}
|
||||
|
||||
select( startPoint, endPoint ) {
|
||||
|
||||
this.startPoint = startPoint || this.startPoint;
|
||||
this.endPoint = endPoint || this.endPoint;
|
||||
this.collection = [];
|
||||
this.updateFrustum( this.startPoint, this.endPoint );
|
||||
this.searchChildInFrustum( _frustum, this.scene );
|
||||
return this.collection;
|
||||
|
||||
}
|
||||
|
||||
updateFrustum( startPoint, endPoint ) {
|
||||
|
||||
startPoint = startPoint || this.startPoint;
|
||||
endPoint = endPoint || this.endPoint; // Avoid invalid frustum
|
||||
|
||||
if ( startPoint.x === endPoint.x ) {
|
||||
|
||||
endPoint.x += Number.EPSILON;
|
||||
|
||||
}
|
||||
|
||||
if ( startPoint.y === endPoint.y ) {
|
||||
|
||||
endPoint.y += Number.EPSILON;
|
||||
|
||||
}
|
||||
|
||||
this.camera.updateProjectionMatrix();
|
||||
this.camera.updateMatrixWorld();
|
||||
|
||||
if ( this.camera.isPerspectiveCamera ) {
|
||||
|
||||
_tmpPoint.copy( startPoint );
|
||||
|
||||
_tmpPoint.x = Math.min( startPoint.x, endPoint.x );
|
||||
_tmpPoint.y = Math.max( startPoint.y, endPoint.y );
|
||||
endPoint.x = Math.max( startPoint.x, endPoint.x );
|
||||
endPoint.y = Math.min( startPoint.y, endPoint.y );
|
||||
|
||||
_vecNear.setFromMatrixPosition( this.camera.matrixWorld );
|
||||
|
||||
_vecTopLeft.copy( _tmpPoint );
|
||||
|
||||
_vecTopRight.set( endPoint.x, _tmpPoint.y, 0 );
|
||||
|
||||
_vecDownRight.copy( endPoint );
|
||||
|
||||
_vecDownLeft.set( _tmpPoint.x, endPoint.y, 0 );
|
||||
|
||||
_vecTopLeft.unproject( this.camera );
|
||||
|
||||
_vecTopRight.unproject( this.camera );
|
||||
|
||||
_vecDownRight.unproject( this.camera );
|
||||
|
||||
_vecDownLeft.unproject( this.camera );
|
||||
|
||||
_vectemp1.copy( _vecTopLeft ).sub( _vecNear );
|
||||
|
||||
_vectemp2.copy( _vecTopRight ).sub( _vecNear );
|
||||
|
||||
_vectemp3.copy( _vecDownRight ).sub( _vecNear );
|
||||
|
||||
_vectemp1.normalize();
|
||||
|
||||
_vectemp2.normalize();
|
||||
|
||||
_vectemp3.normalize();
|
||||
|
||||
_vectemp1.multiplyScalar( this.deep );
|
||||
|
||||
_vectemp2.multiplyScalar( this.deep );
|
||||
|
||||
_vectemp3.multiplyScalar( this.deep );
|
||||
|
||||
_vectemp1.add( _vecNear );
|
||||
|
||||
_vectemp2.add( _vecNear );
|
||||
|
||||
_vectemp3.add( _vecNear );
|
||||
|
||||
const planes = _frustum.planes;
|
||||
planes[ 0 ].setFromCoplanarPoints( _vecNear, _vecTopLeft, _vecTopRight );
|
||||
planes[ 1 ].setFromCoplanarPoints( _vecNear, _vecTopRight, _vecDownRight );
|
||||
planes[ 2 ].setFromCoplanarPoints( _vecDownRight, _vecDownLeft, _vecNear );
|
||||
planes[ 3 ].setFromCoplanarPoints( _vecDownLeft, _vecTopLeft, _vecNear );
|
||||
planes[ 4 ].setFromCoplanarPoints( _vecTopRight, _vecDownRight, _vecDownLeft );
|
||||
planes[ 5 ].setFromCoplanarPoints( _vectemp3, _vectemp2, _vectemp1 );
|
||||
planes[ 5 ].normal.multiplyScalar( - 1 );
|
||||
|
||||
} else if ( this.camera.isOrthographicCamera ) {
|
||||
|
||||
const left = Math.min( startPoint.x, endPoint.x );
|
||||
const top = Math.max( startPoint.y, endPoint.y );
|
||||
const right = Math.max( startPoint.x, endPoint.x );
|
||||
const down = Math.min( startPoint.y, endPoint.y );
|
||||
|
||||
_vecTopLeft.set( left, top, - 1 );
|
||||
|
||||
_vecTopRight.set( right, top, - 1 );
|
||||
|
||||
_vecDownRight.set( right, down, - 1 );
|
||||
|
||||
_vecDownLeft.set( left, down, - 1 );
|
||||
|
||||
_vecFarTopLeft.set( left, top, 1 );
|
||||
|
||||
_vecFarTopRight.set( right, top, 1 );
|
||||
|
||||
_vecFarDownRight.set( right, down, 1 );
|
||||
|
||||
_vecFarDownLeft.set( left, down, 1 );
|
||||
|
||||
_vecTopLeft.unproject( this.camera );
|
||||
|
||||
_vecTopRight.unproject( this.camera );
|
||||
|
||||
_vecDownRight.unproject( this.camera );
|
||||
|
||||
_vecDownLeft.unproject( this.camera );
|
||||
|
||||
_vecFarTopLeft.unproject( this.camera );
|
||||
|
||||
_vecFarTopRight.unproject( this.camera );
|
||||
|
||||
_vecFarDownRight.unproject( this.camera );
|
||||
|
||||
_vecFarDownLeft.unproject( this.camera );
|
||||
|
||||
const planes = _frustum.planes;
|
||||
planes[ 0 ].setFromCoplanarPoints( _vecTopLeft, _vecFarTopLeft, _vecFarTopRight );
|
||||
planes[ 1 ].setFromCoplanarPoints( _vecTopRight, _vecFarTopRight, _vecFarDownRight );
|
||||
planes[ 2 ].setFromCoplanarPoints( _vecFarDownRight, _vecFarDownLeft, _vecDownLeft );
|
||||
planes[ 3 ].setFromCoplanarPoints( _vecFarDownLeft, _vecFarTopLeft, _vecTopLeft );
|
||||
planes[ 4 ].setFromCoplanarPoints( _vecTopRight, _vecDownRight, _vecDownLeft );
|
||||
planes[ 5 ].setFromCoplanarPoints( _vecFarDownRight, _vecFarTopRight, _vecFarTopLeft );
|
||||
planes[ 5 ].normal.multiplyScalar( - 1 );
|
||||
|
||||
} else {
|
||||
|
||||
console.error( 'THREE.SelectionBox: Unsupported camera type.' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
searchChildInFrustum( frustum, object ) {
|
||||
|
||||
if ( object.isMesh || object.isLine || object.isPoints ) {
|
||||
|
||||
if ( object.isInstancedMesh ) {
|
||||
|
||||
this.instances[ object.uuid ] = [];
|
||||
|
||||
for ( let instanceId = 0; instanceId < object.count; instanceId ++ ) {
|
||||
|
||||
object.getMatrixAt( instanceId, _matrix );
|
||||
|
||||
_matrix.decompose( _center, _quaternion, _scale );
|
||||
|
||||
_center.applyMatrix4( object.matrixWorld );
|
||||
|
||||
if ( frustum.containsPoint( _center ) ) {
|
||||
|
||||
this.instances[ object.uuid ].push( instanceId );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( object.geometry.boundingSphere === null ) object.geometry.computeBoundingSphere();
|
||||
|
||||
_center.copy( object.geometry.boundingSphere.center );
|
||||
|
||||
_center.applyMatrix4( object.matrixWorld );
|
||||
|
||||
if ( frustum.containsPoint( _center ) ) {
|
||||
|
||||
this.collection.push( object );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( object.children.length > 0 ) {
|
||||
|
||||
for ( let x = 0; x < object.children.length; x ++ ) {
|
||||
|
||||
this.searchChildInFrustum( frustum, object.children[ x ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
THREE.SelectionBox = SelectionBox;
|
||||
|
||||
} )();
|
||||
89
HTML/ThreeJS/node_modules/three/examples/js/interactive/SelectionHelper.js
generated
vendored
Normal file
89
HTML/ThreeJS/node_modules/three/examples/js/interactive/SelectionHelper.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
( function () {
|
||||
|
||||
class SelectionHelper {
|
||||
|
||||
constructor( selectionBox, renderer, cssClassName ) {
|
||||
|
||||
this.element = document.createElement( 'div' );
|
||||
this.element.classList.add( cssClassName );
|
||||
this.element.style.pointerEvents = 'none';
|
||||
this.renderer = renderer;
|
||||
this.startPoint = new THREE.Vector2();
|
||||
this.pointTopLeft = new THREE.Vector2();
|
||||
this.pointBottomRight = new THREE.Vector2();
|
||||
this.isDown = false;
|
||||
|
||||
this.onPointerDown = function ( event ) {
|
||||
|
||||
this.isDown = true;
|
||||
this.onSelectStart( event );
|
||||
|
||||
}.bind( this );
|
||||
|
||||
this.onPointerMove = function ( event ) {
|
||||
|
||||
if ( this.isDown ) {
|
||||
|
||||
this.onSelectMove( event );
|
||||
|
||||
}
|
||||
|
||||
}.bind( this );
|
||||
|
||||
this.onPointerUp = function () {
|
||||
|
||||
this.isDown = false;
|
||||
this.onSelectOver();
|
||||
|
||||
}.bind( this );
|
||||
|
||||
this.renderer.domElement.addEventListener( 'pointerdown', this.onPointerDown );
|
||||
this.renderer.domElement.addEventListener( 'pointermove', this.onPointerMove );
|
||||
this.renderer.domElement.addEventListener( 'pointerup', this.onPointerUp );
|
||||
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
||||
this.renderer.domElement.removeEventListener( 'pointerdown', this.onPointerDown );
|
||||
this.renderer.domElement.removeEventListener( 'pointermove', this.onPointerMove );
|
||||
this.renderer.domElement.removeEventListener( 'pointerup', this.onPointerUp );
|
||||
|
||||
}
|
||||
|
||||
onSelectStart( event ) {
|
||||
|
||||
this.renderer.domElement.parentElement.appendChild( this.element );
|
||||
this.element.style.left = event.clientX + 'px';
|
||||
this.element.style.top = event.clientY + 'px';
|
||||
this.element.style.width = '0px';
|
||||
this.element.style.height = '0px';
|
||||
this.startPoint.x = event.clientX;
|
||||
this.startPoint.y = event.clientY;
|
||||
|
||||
}
|
||||
|
||||
onSelectMove( event ) {
|
||||
|
||||
this.pointBottomRight.x = Math.max( this.startPoint.x, event.clientX );
|
||||
this.pointBottomRight.y = Math.max( this.startPoint.y, event.clientY );
|
||||
this.pointTopLeft.x = Math.min( this.startPoint.x, event.clientX );
|
||||
this.pointTopLeft.y = Math.min( this.startPoint.y, event.clientY );
|
||||
this.element.style.left = this.pointTopLeft.x + 'px';
|
||||
this.element.style.top = this.pointTopLeft.y + 'px';
|
||||
this.element.style.width = this.pointBottomRight.x - this.pointTopLeft.x + 'px';
|
||||
this.element.style.height = this.pointBottomRight.y - this.pointTopLeft.y + 'px';
|
||||
|
||||
}
|
||||
|
||||
onSelectOver() {
|
||||
|
||||
this.element.parentElement.removeChild( this.element );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
THREE.SelectionHelper = SelectionHelper;
|
||||
|
||||
} )();
|
||||
Reference in New Issue
Block a user