Skip to content

Commit

Permalink
Merge pull request NASA-AMMOS#228 from NASA-AMMOS/vr-mars-update
Browse files Browse the repository at this point in the history
Switch to the mars scene tileset for the vr demo
  • Loading branch information
gkjohnson authored Nov 27, 2021
2 parents 26f4353 + a535fb0 commit 3344957
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions example/vr.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ let offsetParent;
let controller, controllerGrip;
let xrSession = null;
let tasks = [];
const upVector = new Vector3( 0, 1, 0 );

let params = {

Expand All @@ -63,7 +64,7 @@ function init() {
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x151c1f );
renderer.setClearColor( 0xbbbbbb );
renderer.outputEncoding = sRGBEncoding;
renderer.xr.enabled = true;

Expand Down Expand Up @@ -100,9 +101,11 @@ function init() {

// parent for centering the tileset
offsetParent = new Group();
offsetParent.rotation.x = Math.PI / 2;
offsetParent.position.y = 32;
scene.add( offsetParent );

tiles = new TilesRenderer( '../data/tileset.json' );
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
Expand All @@ -121,6 +124,8 @@ function init() {
tiles.downloadQueue.schedulingCallback = tilesSchedulingCB;
tiles.parseQueue.schedulingCallback = tilesSchedulingCB;

tiles.lruCache.maxSize = 1200;
tiles.lruCache.minSize = 900;

// Raycasting init
raycaster = new Raycaster();
Expand All @@ -137,7 +142,11 @@ function init() {
controller = renderer.xr.getController( 0 );
controller.addEventListener( 'selectstart', () => {

workspace.position.copy( intersectRing.position );
if ( intersectRing.visible ) {

workspace.position.copy( intersectRing.position );

}

} );
controller.addEventListener( 'connected', function ( event ) {
Expand Down Expand Up @@ -340,6 +349,13 @@ function animate() {
const scale = workspace.position.distanceTo( intersectRing.position ) * camera.fov / 4000;
intersectRing.scale.setScalar( scale );

// only teleport to mostly horizontal surfaces
if ( hit.face.normal.dot( upVector ) < 0.15 ) {

intersectRing.visible = false;

}

} else {

intersectRing.visible = false;
Expand Down

0 comments on commit 3344957

Please sign in to comment.