three#Raycaster JavaScript Examples
The following examples show how to use
three#Raycaster.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragControls.js From geometry_3d with MIT License | 6 votes |
constructor(_objects, _camera) {
this._objects = _objects;
this._camera = _camera;
this._plane = new Plane();
this._raycaster = new Raycaster();
_mouse = new Vector2();
this._offset = new Vector3();
this._intersection = new Vector3();
this._worldPosition = new Vector3();
this._inverseMatrix = new Matrix4();
this._intersections = [];
this._selected = null;
}
Example #2
Source File: MapViewer.js From BlueMapWeb with MIT License | 5 votes |
/**
* @param element {Element}
* @param events {EventTarget}
*/
constructor(element, events = element) {
Object.defineProperty( this, 'isMapViewer', { value: true } );
this.rootElement = element;
this.events = events;
this.data = {
map: null,
camera: null,
controlsManager: null,
uniforms: {
sunlightStrength: { value: 1 },
ambientLight: { value: 0 },
skyColor: { value: new Color(0.5, 0.5, 1) },
hiresTileMap: {
value: {
map: null,
size: TileManager.tileMapSize,
scale: new Vector2(1, 1),
translate: new Vector2(),
pos: new Vector2(),
}
}
},
superSampling: 1,
loadedCenter: new Vector2(0, 0),
loadedHiresViewDistance: 200,
loadedLowresViewDistance: 2000,
}
this.tileCacheHash = generateCacheHash();
this.stats = new Stats();
this.stats.hide();
// renderer
this.renderer = new WebGLRenderer({
antialias: true,
sortObjects: true,
preserveDrawingBuffer: true,
logarithmicDepthBuffer: true,
});
this.renderer.autoClear = false;
this.renderer.uniforms = this.data.uniforms;
// CSS2D renderer
this.css2dRenderer = new CSS2DRenderer(this.events);
this.skyboxScene = new SkyboxScene(this.data.uniforms);
this.camera = new CombinedCamera(75, 1, 0.1, 10000, 0);
this.skyboxCamera = new PerspectiveCamera(75, 1, 0.1, 10000);
this.controlsManager = new ControlsManager(this, this.camera);
this.raycaster = new Raycaster();
this.raycaster.layers.enableAll();
this.raycaster.params.Line2 = {threshold: 20}
/** @type {Map} */
this.map = null;
this.markers = new MarkerSet("bm-root");
this.lastFrame = 0;
// initialize
this.initializeRootElement();
// handle window resizes
window.addEventListener("resize", this.handleContainerResize);
// start render-loop
requestAnimationFrame(this.renderLoop);
}
Example #3
Source File: Map.js From BlueMapWeb with MIT License | 5 votes |
/**
* @param id {string}
* @param dataUrl {string}
* @param events {EventTarget}
*/
constructor(id, dataUrl, events = null) {
Object.defineProperty( this, 'isMap', { value: true } );
this.events = events;
this.data = {
id: id,
sorting: 0,
dataUrl: dataUrl,
settingsUrl: dataUrl + "settings.json",
texturesUrl: dataUrl + "textures.json",
name: id,
startPos: {x: 0, z: 0},
skyColor: new Color(),
ambientLight: 0,
hires: {
tileSize: {x: 32, z: 32},
scale: {x: 1, z: 1},
translate: {x: 2, z: 2}
},
lowres: {
tileSize: {x: 32, z: 32},
scale: {x: 1, z: 1},
translate: {x: 2, z: 2}
}
};
this.raycaster = new Raycaster();
/** @type {ShaderMaterial[]} */
this.hiresMaterial = null;
/** @type {ShaderMaterial} */
this.lowresMaterial = null;
/** @type {Texture[]} */
this.loadedTextures = [];
/** @type {TileManager} */
this.hiresTileManager = null;
/** @type {TileManager} */
this.lowresTileManager = null;
}
Example #4
Source File: controller.js From architect3d with MIT License | 5 votes |
// filter by normals will only return objects facing the camera
// objects can be an array of objects or a single object
getIntersections(vec2, objects, filterByNormals, onlyVisible, recursive, linePrecision)
{
var vector = this.mouseToVec3(vec2);
onlyVisible = onlyVisible || false;
filterByNormals = filterByNormals || false;
recursive = recursive || false;
linePrecision = linePrecision || 20;
var direction = vector.sub(this.camera.position).normalize();
var raycaster = new Raycaster(this.camera.position, direction);
raycaster.linePrecision = linePrecision;
raycaster = new Raycaster();
raycaster.setFromCamera( this.normalizeVector2(this.alternateMouse), this.camera );
var intersections;
if (objects instanceof Array)
{
intersections = raycaster.intersectObjects(objects, recursive);
}
else
{
intersections = raycaster.intersectObject(objects, recursive);
}
// filter by visible, if true
if (onlyVisible)
{
intersections = Utils.removeIf(intersections, function (intersection) {return !intersection.object.visible;});
}
// filter by normals, if true
if (filterByNormals)
{
intersections = Utils.removeIf(intersections, function (intersection) {var dot = intersection.face.normal.dot(direction);return (dot > 0);});
}
return intersections;
}
Example #5
Source File: DragControls.js From Computer-Graphics with MIT License | 5 votes |
_raycaster = new Raycaster()
Example #6
Source File: b3dmExample.js From 3DTilesRendererJS with Apache License 2.0 | 4 votes |
function init() {
infoEl = document.getElementById( 'info' );
scene = new Scene();
// primary camera view
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x151c1f );
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFSoftShadowMap;
renderer.outputEncoding = sRGBEncoding;
document.body.appendChild( renderer.domElement );
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
camera.position.set( 400, 400, 400 );
// controls
controls = new OrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = false;
controls.minDistance = 1;
controls.maxDistance = 2000;
// lights
dirLight = new DirectionalLight( 0xffffff, 1.25 );
dirLight.position.set( 1, 2, 3 ).multiplyScalar( 40 );
dirLight.castShadow = true;
dirLight.shadow.bias = - 0.01;
dirLight.shadow.mapSize.setScalar( 2048 );
const shadowCam = dirLight.shadow.camera;
shadowCam.left = - 200;
shadowCam.bottom = - 200;
shadowCam.right = 200;
shadowCam.top = 200;
shadowCam.updateProjectionMatrix();
scene.add( dirLight );
const ambLight = new AmbientLight( 0xffffff, 0.05 );
scene.add( ambLight );
offsetGroup = new Group();
scene.add( offsetGroup );
new B3DMLoader()
.load( 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.0/TilesetWithRequestVolume/city/lr.b3dm' )
.then( res => {
console.log( res );
model = res.scene;
offsetGroup.add( model );
const box = new Box3();
box.setFromObject( model );
box.getCenter( offsetGroup.position ).multiplyScalar( - 1 );
// reassign the material to use the batchid highlight variant.
// in practice this should copy over any needed uniforms from the
// original material.
model.traverse( c => {
if ( c.isMesh ) {
c.material = new ShaderMaterial( batchIdHighlightShaderMixin( ShaderLib.standard ) );
}
} );
} );
raycaster = new Raycaster();
mouse = new Vector2();
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
renderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
}
Example #7
Source File: index.js From 3DTilesRendererJS with Apache License 2.0 | 4 votes |
function init() {
scene = new Scene();
// primary camera view
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x151c1f );
renderer.outputEncoding = sRGBEncoding;
document.body.appendChild( renderer.domElement );
renderer.domElement.tabIndex = 1;
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
camera.position.set( 400, 400, 400 );
cameraHelper = new CameraHelper( camera );
scene.add( cameraHelper );
orthoCamera = new OrthographicCamera();
orthoCameraHelper = new CameraHelper( orthoCamera );
scene.add( orthoCameraHelper );
// secondary camera view
secondCamera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
secondCamera.position.set( 400, 400, - 400 );
secondCamera.lookAt( 0, 0, 0 );
secondRenderer = new WebGLRenderer( { antialias: true } );
secondRenderer.setPixelRatio( window.devicePixelRatio );
secondRenderer.setSize( window.innerWidth, window.innerHeight );
secondRenderer.setClearColor( 0x151c1f );
secondRenderer.outputEncoding = sRGBEncoding;
document.body.appendChild( secondRenderer.domElement );
secondRenderer.domElement.style.position = 'absolute';
secondRenderer.domElement.style.right = '0';
secondRenderer.domElement.style.top = '0';
secondRenderer.domElement.style.outline = '#0f1416 solid 2px';
secondRenderer.domElement.tabIndex = 1;
secondControls = new FlyOrbitControls( secondCamera, secondRenderer.domElement );
secondControls.screenSpacePanning = false;
secondControls.minDistance = 1;
secondControls.maxDistance = 2000;
secondCameraHelper = new CameraHelper( secondCamera );
scene.add( secondCameraHelper );
// Third person camera view
thirdPersonCamera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
thirdPersonCamera.position.set( 50, 40, 40 );
thirdPersonCamera.lookAt( 0, 0, 0 );
thirdPersonRenderer = new WebGLRenderer( { antialias: true } );
thirdPersonRenderer.setPixelRatio( window.devicePixelRatio );
thirdPersonRenderer.setSize( window.innerWidth, window.innerHeight );
thirdPersonRenderer.setClearColor( 0x0f1416 );
thirdPersonRenderer.outputEncoding = sRGBEncoding;
document.body.appendChild( thirdPersonRenderer.domElement );
thirdPersonRenderer.domElement.style.position = 'fixed';
thirdPersonRenderer.domElement.style.left = '5px';
thirdPersonRenderer.domElement.style.bottom = '5px';
thirdPersonRenderer.domElement.tabIndex = 1;
thirdPersonControls = new FlyOrbitControls( thirdPersonCamera, thirdPersonRenderer.domElement );
thirdPersonControls.screenSpacePanning = false;
thirdPersonControls.minDistance = 1;
thirdPersonControls.maxDistance = 2000;
// controls
controls = new FlyOrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = false;
controls.minDistance = 1;
controls.maxDistance = 2000;
// lights
const dirLight = new DirectionalLight( 0xffffff );
dirLight.position.set( 1, 2, 3 );
scene.add( dirLight );
const ambLight = new AmbientLight( 0xffffff, 0.2 );
scene.add( ambLight );
box = new Box3();
sphere = new Sphere();
offsetParent = new Group();
scene.add( offsetParent );
// Raycasting init
raycaster = new Raycaster();
mouse = new Vector2();
rayIntersect = new Group();
const rayIntersectMat = new MeshBasicMaterial( { color: 0xe91e63 } );
const rayMesh = new Mesh( new CylinderBufferGeometry( 0.25, 0.25, 6 ), rayIntersectMat );
rayMesh.rotation.x = Math.PI / 2;
rayMesh.position.z += 3;
rayIntersect.add( rayMesh );
const rayRing = new Mesh( new TorusBufferGeometry( 1.5, 0.2, 16, 100 ), rayIntersectMat );
rayIntersect.add( rayRing );
scene.add( rayIntersect );
rayIntersect.visible = false;
reinstantiateTiles();
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
renderer.domElement.addEventListener( 'pointermove', onPointerMove, false );
renderer.domElement.addEventListener( 'pointerdown', onPointerDown, false );
renderer.domElement.addEventListener( 'pointerup', onPointerUp, false );
renderer.domElement.addEventListener( 'pointerleave', onPointerLeave, false );
secondRenderer.domElement.addEventListener( 'pointermove', onPointerMove, false );
secondRenderer.domElement.addEventListener( 'pointerdown', onPointerDown, false );
secondRenderer.domElement.addEventListener( 'pointerup', onPointerUp, false );
secondRenderer.domElement.addEventListener( 'pointerleave', onPointerLeave, false );
// GUI
const gui = new GUI();
gui.width = 300;
const tileOptions = gui.addFolder( 'Tiles Options' );
tileOptions.add( params, 'loadSiblings' );
tileOptions.add( params, 'stopAtEmptyTiles' );
tileOptions.add( params, 'displayActiveTiles' );
tileOptions.add( params, 'errorTarget' ).min( 0 ).max( 50 );
tileOptions.add( params, 'errorThreshold' ).min( 0 ).max( 1000 );
tileOptions.add( params, 'maxDepth' ).min( 1 ).max( 100 );
tileOptions.add( params, 'up', [ '+Y', '+Z', '-Z' ] );
tileOptions.open();
const debug = gui.addFolder( 'Debug Options' );
debug.add( params, 'displayBoxBounds' );
debug.add( params, 'colorMode', {
NONE,
SCREEN_ERROR,
GEOMETRIC_ERROR,
DISTANCE,
DEPTH,
RELATIVE_DEPTH,
IS_LEAF,
RANDOM_COLOR,
RANDOM_NODE_COLOR,
CUSTOM_COLOR
} );
debug.open();
const exampleOptions = gui.addFolder( 'Example Options' );
exampleOptions.add( params, 'resolutionScale' ).min( 0.01 ).max( 2.0 ).step( 0.01 ).onChange( onWindowResize );
exampleOptions.add( params, 'orthographic' );
exampleOptions.add( params, 'showThirdPerson' );
exampleOptions.add( params, 'showSecondView' ).onChange( onWindowResize );
exampleOptions.add( params, 'enableUpdate' ).onChange( v => {
tiles.parseQueue.autoUpdate = v;
tiles.downloadQueue.autoUpdate = v;
if ( v ) {
tiles.parseQueue.scheduleJobRun();
tiles.downloadQueue.scheduleJobRun();
}
} );
exampleOptions.add( params, 'raycast', { NONE, ALL_HITS, FIRST_HIT_ONLY } );
exampleOptions.add( params, 'optimizeRaycast', );
exampleOptions.add( params, 'enableCacheDisplay' );
exampleOptions.add( params, 'enableRendererStats' );
exampleOptions.open();
gui.add( params, 'reload' );
gui.open();
statsContainer = document.createElement( 'div' );
statsContainer.style.position = 'absolute';
statsContainer.style.top = 0;
statsContainer.style.left = 0;
statsContainer.style.color = 'white';
statsContainer.style.width = '100%';
statsContainer.style.textAlign = 'center';
statsContainer.style.padding = '5px';
statsContainer.style.pointerEvents = 'none';
statsContainer.style.lineHeight = '1.5em';
document.body.appendChild( statsContainer );
// Stats
stats = new Stats();
stats.showPanel( 0 );
document.body.appendChild( stats.dom );
}
Example #8
Source File: ionExample.js From 3DTilesRendererJS with Apache License 2.0 | 4 votes |
function init() {
scene = new Scene();
// primary camera view
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x151c1f );
renderer.outputEncoding = sRGBEncoding;
document.body.appendChild( renderer.domElement );
renderer.domElement.tabIndex = 1;
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
camera.position.set( 400, 400, 400 );
cameraHelper = new CameraHelper( camera );
scene.add( cameraHelper );
orthoCamera = new OrthographicCamera();
orthoCameraHelper = new CameraHelper( orthoCamera );
scene.add( orthoCameraHelper );
// secondary camera view
secondCamera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
secondCamera.position.set( 400, 400, - 400 );
secondCamera.lookAt( 0, 0, 0 );
secondRenderer = new WebGLRenderer( { antialias: true } );
secondRenderer.setPixelRatio( window.devicePixelRatio );
secondRenderer.setSize( window.innerWidth, window.innerHeight );
secondRenderer.setClearColor( 0x151c1f );
secondRenderer.outputEncoding = sRGBEncoding;
document.body.appendChild( secondRenderer.domElement );
secondRenderer.domElement.style.position = 'absolute';
secondRenderer.domElement.style.right = '0';
secondRenderer.domElement.style.top = '0';
secondRenderer.domElement.style.outline = '#0f1416 solid 2px';
secondRenderer.domElement.tabIndex = 1;
secondControls = new FlyOrbitControls( secondCamera, secondRenderer.domElement );
secondControls.screenSpacePanning = false;
secondControls.minDistance = 1;
secondControls.maxDistance = 2000;
secondCameraHelper = new CameraHelper( secondCamera );
scene.add( secondCameraHelper );
// Third person camera view
thirdPersonCamera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
thirdPersonCamera.position.set( 50, 40, 40 );
thirdPersonCamera.lookAt( 0, 0, 0 );
thirdPersonRenderer = new WebGLRenderer( { antialias: true } );
thirdPersonRenderer.setPixelRatio( window.devicePixelRatio );
thirdPersonRenderer.setSize( window.innerWidth, window.innerHeight );
thirdPersonRenderer.setClearColor( 0x0f1416 );
thirdPersonRenderer.outputEncoding = sRGBEncoding;
document.body.appendChild( thirdPersonRenderer.domElement );
thirdPersonRenderer.domElement.style.position = 'fixed';
thirdPersonRenderer.domElement.style.left = '5px';
thirdPersonRenderer.domElement.style.bottom = '5px';
thirdPersonRenderer.domElement.tabIndex = 1;
thirdPersonControls = new FlyOrbitControls( thirdPersonCamera, thirdPersonRenderer.domElement );
thirdPersonControls.screenSpacePanning = false;
thirdPersonControls.minDistance = 1;
thirdPersonControls.maxDistance = 2000;
// controls
controls = new FlyOrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = false;
controls.minDistance = 1;
controls.maxDistance = 2000;
// lights
const dirLight = new DirectionalLight( 0xffffff );
dirLight.position.set( 1, 2, 3 );
scene.add( dirLight );
const ambLight = new AmbientLight( 0xffffff, 0.2 );
scene.add( ambLight );
offsetParent = new Group();
scene.add( offsetParent );
// Raycasting init
raycaster = new Raycaster();
mouse = new Vector2();
rayIntersect = new Group();
const rayIntersectMat = new MeshBasicMaterial( { color: 0xe91e63 } );
const rayMesh = new Mesh( new CylinderBufferGeometry( 0.25, 0.25, 6 ), rayIntersectMat );
rayMesh.rotation.x = Math.PI / 2;
rayMesh.position.z += 3;
rayIntersect.add( rayMesh );
const rayRing = new Mesh( new TorusBufferGeometry( 1.5, 0.2, 16, 100 ), rayIntersectMat );
rayIntersect.add( rayRing );
scene.add( rayIntersect );
rayIntersect.visible = false;
reinstantiateTiles();
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
renderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
renderer.domElement.addEventListener( 'mousedown', onMouseDown, false );
renderer.domElement.addEventListener( 'mouseup', onMouseUp, false );
renderer.domElement.addEventListener( 'mouseleave', onMouseLeave, false );
secondRenderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
secondRenderer.domElement.addEventListener( 'mousedown', onMouseDown, false );
secondRenderer.domElement.addEventListener( 'mouseup', onMouseUp, false );
secondRenderer.domElement.addEventListener( 'mouseleave', onMouseLeave, false );
// GUI
const gui = new GUI();
gui.width = 300;
const ionOptions = gui.addFolder( 'Ion' );
ionOptions.add( params, 'ionAssetId' );
ionOptions.add( params, 'ionAccessToken' );
ionOptions.add( params, 'reload' );
ionOptions.open();
const tileOptions = gui.addFolder( 'Tiles Options' );
tileOptions.add( params, 'loadSiblings' );
tileOptions.add( params, 'stopAtEmptyTiles' );
tileOptions.add( params, 'displayActiveTiles' );
tileOptions.add( params, 'errorTarget' ).min( 0 ).max( 50 );
tileOptions.add( params, 'errorThreshold' ).min( 0 ).max( 1000 );
tileOptions.add( params, 'maxDepth' ).min( 1 ).max( 100 );
tileOptions.add( params, 'up', [ '+Y', '+Z', '-Z' ] );
const debug = gui.addFolder( 'Debug Options' );
debug.add( params, 'displayBoxBounds' );
debug.add( params, 'colorMode', {
NONE,
SCREEN_ERROR,
GEOMETRIC_ERROR,
DISTANCE,
DEPTH,
RELATIVE_DEPTH,
IS_LEAF,
RANDOM_COLOR,
} );
const exampleOptions = gui.addFolder( 'Example Options' );
exampleOptions.add( params, 'resolutionScale' ).min( 0.01 ).max( 2.0 ).step( 0.01 ).onChange( onWindowResize );
exampleOptions.add( params, 'orthographic' );
exampleOptions.add( params, 'showThirdPerson' );
exampleOptions.add( params, 'showSecondView' ).onChange( onWindowResize );
exampleOptions.add( params, 'enableUpdate' ).onChange( v => {
tiles.parseQueue.autoUpdate = v;
tiles.downloadQueue.autoUpdate = v;
if ( v ) {
tiles.parseQueue.scheduleJobRun();
tiles.downloadQueue.scheduleJobRun();
}
} );
exampleOptions.add( params, 'raycast', { NONE, ALL_HITS, FIRST_HIT_ONLY } );
exampleOptions.add( params, 'enableCacheDisplay' );
exampleOptions.add( params, 'enableRendererStats' );
gui.open();
statsContainer = document.createElement( 'div' );
document.getElementById( 'info' ).appendChild( statsContainer );
// Stats
stats = new Stats();
stats.showPanel( 0 );
document.body.appendChild( stats.dom );
}
Example #9
Source File: vr.js From 3DTilesRendererJS with Apache License 2.0 | 4 votes |
function init() {
scene = new Scene();
// primary camera view
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0xbbbbbb );
renderer.outputEncoding = sRGBEncoding;
renderer.xr.enabled = true;
document.body.appendChild( renderer.domElement );
renderer.domElement.tabIndex = 1;
renderer.setAnimationLoop( animate );
// create workspace
workspace = new Group();
scene.add( workspace );
grid = new GridHelper( 10, 10, 0xffffff, 0xffffff );
grid.material.transparent = true;
grid.material.opacity = 0.5;
grid.material.depthWrite = false;
workspace.add( grid );
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 4000 );
camera.position.set( 0, 1, 0 );
workspace.add( camera );
// lights
const dirLight = new DirectionalLight( 0xffffff );
dirLight.position.set( 1, 2, 3 );
scene.add( dirLight );
const ambLight = new AmbientLight( 0xffffff, 0.2 );
scene.add( ambLight );
// tile set
box = new Box3();
sphere = new Sphere();
// parent for centering the tileset
offsetParent = new Group();
offsetParent.rotation.x = Math.PI / 2;
offsetParent.position.y = 32;
scene.add( offsetParent );
tiles = new TilesRenderer( 'https://raw.githubusercontent.com/NASA-AMMOS/3DTilesSampleData/master/msl-dingo-gap/0528_0260184_to_s64o256_colorize/scene-tileset.json' );
offsetParent.add( tiles.group );
// We set camera for tileset
tiles.setCamera( camera );
tiles.setResolutionFromRenderer( camera, renderer );
// We define a custom scheduling callback to handle also active WebXR sessions
const tilesSchedulingCB = func => {
tasks.push( func );
};
// We set our scheduling callback for tiles downloading and parsing
tiles.downloadQueue.schedulingCallback = tilesSchedulingCB;
tiles.parseQueue.schedulingCallback = tilesSchedulingCB;
tiles.lruCache.maxSize = 1200;
tiles.lruCache.minSize = 900;
// Raycasting init
raycaster = new Raycaster();
fwdVector = new Vector3( 0, 0, 1 );
const rayIntersectMat = new MeshBasicMaterial( { color: 0xb2dfdb } );
intersectRing = new Mesh( new TorusBufferGeometry( 1.5, 0.2, 16, 100 ), rayIntersectMat );
intersectRing.visible = false;
scene.add( intersectRing );
// vr setup
document.body.appendChild( VRButton.createButton( renderer ) );
controller = renderer.xr.getController( 0 );
controller.addEventListener( 'selectstart', () => {
if ( intersectRing.visible ) {
workspace.position.copy( intersectRing.position );
}
} );
controller.addEventListener( 'connected', function ( event ) {
this.controllerActive = true;
this.add( buildController( event.data ) );
} );
controller.addEventListener( 'disconnected', function () {
this.controllerActive = false;
this.remove( this.children[ 0 ] );
} );
workspace.add( controller );
// controller models
const controllerModelFactory = new XRControllerModelFactory();
controllerGrip = renderer.xr.getControllerGrip( 0 );
controllerGrip.add( controllerModelFactory.createControllerModel( controllerGrip ) );
workspace.add( controllerGrip );
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
// GUI
const gui = new GUI();
gui.width = 300;
gui.add( params, 'displayGrid' );
gui.add( params, 'displayBoxBounds' );
gui.add( params, 'colorMode', {
NONE,
SCREEN_ERROR,
GEOMETRIC_ERROR,
DISTANCE,
DEPTH,
RELATIVE_DEPTH,
IS_LEAF,
RANDOM_COLOR,
} );
gui.open();
}