diff --git a/examples/heidentor.html b/examples/heidentor.html index 8334cc0d..db356af3 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -43,8 +43,6 @@ diff --git a/examples/lion.html b/examples/lion.html index a7cc2030..f1ebba49 100644 --- a/examples/lion.html +++ b/examples/lion.html @@ -18,7 +18,7 @@ - + diff --git a/examples/viewer.html b/examples/viewer.html index 58d74d6b..9cdf1e57 100644 --- a/examples/viewer.html +++ b/examples/viewer.html @@ -40,7 +40,7 @@ diff --git a/examples/vr.html b/examples/vr.html index 9154052c..a9e0ed7a 100644 --- a/examples/vr.html +++ b/examples/vr.html @@ -109,44 +109,44 @@ 2.569661863723081); }); - const controls = new Potree.VRControlls(viewer); - controls.speed = 2; - controls.speedModificationFactor = 4; - viewer.addEventListener("update", (e) => controls.update(e.delta)); + // const controls = new Potree.VRControlls(viewer); + // controls.speed = 2; + // controls.speedModificationFactor = 4; + // viewer.addEventListener("update", (e) => controls.update(e.delta)); diff --git a/libs/three.js/extra/VRButton.js b/libs/three.js/extra/VRButton.js index 182fcaf3..1d7db76f 100644 --- a/libs/three.js/extra/VRButton.js +++ b/libs/three.js/extra/VRButton.js @@ -1,6 +1,24 @@ + +// Adapted from three.js VRButton + + class VRButton { - static createButton( renderer, options ) { + constructor(){ + this.onStartListeners = []; + this.onEndListeners = []; + this.element = null; + } + + onStart(callback){ + this.onStartListeners.push(callback); + } + + onEnd(callback){ + this.onEndListeners.push(callback); + } + + static async createButton( renderer, options ) { if ( options ) { @@ -8,7 +26,24 @@ class VRButton { } - const button = document.createElement( 'button' ); + const button = new VRButton(); + const element = document.createElement( 'button' ); + + button.element = element; + + function setEnter(){ + button.element.innerHTML = ` +
ENTER
+
VR
+ `; + } + + function setExit(){ + button.element.innerHTML = ` +
EXIT
+
VR
+ `; + } function showEnterVR( /*device*/ ) { @@ -18,8 +53,13 @@ class VRButton { session.addEventListener( 'end', onSessionEnded ); + for(let listener of button.onStartListeners){ + listener(); + } + + renderer.xr.setSession( session ); - button.textContent = 'EXIT VR'; + setExit(); currentSession = session; @@ -29,7 +69,11 @@ class VRButton { currentSession.removeEventListener( 'end', onSessionEnded ); - button.textContent = 'ENTER VR'; + for(let listener of button.onEndListeners){ + listener(); + } + + setEnter(); currentSession = null; @@ -37,27 +81,25 @@ class VRButton { // - button.style.display = ''; + button.element.style.display = ''; - button.style.cursor = 'pointer'; - button.style.left = 'calc(50% - 50px)'; - button.style.width = '100px'; + button.element.style.cursor = 'pointer'; - button.textContent = 'ENTER VR'; + setEnter(); - button.onmouseenter = function () { + button.element.onmouseenter = function () { - button.style.opacity = '1.0'; + button.element.style.opacity = '1.0'; }; - button.onmouseleave = function () { + button.element.onmouseleave = function () { - button.style.opacity = '0.5'; + button.element.style.opacity = '0.7'; }; - button.onclick = function () { + button.element.onclick = function () { if ( currentSession === null ) { @@ -81,29 +123,6 @@ class VRButton { } - function disableButton() { - - button.style.display = ''; - - button.style.cursor = 'auto'; - button.style.left = 'calc(50% - 75px)'; - button.style.width = '150px'; - - button.onmouseenter = null; - button.onmouseleave = null; - - button.onclick = null; - - } - - function showWebXRNotFound() { - - disableButton(); - - button.textContent = 'VR NOT SUPPORTED'; - - } - function stylizeElement( element ) { element.style.position = 'absolute'; @@ -115,7 +134,7 @@ class VRButton { element.style.color = '#fff'; element.style.font = 'normal 13px sans-serif'; element.style.textAlign = 'center'; - element.style.opacity = '0.5'; + element.style.opacity = '0.7'; element.style.outline = 'none'; element.style.zIndex = '999'; @@ -123,42 +142,36 @@ class VRButton { if ( 'xr' in navigator ) { - button.id = 'VRButton'; - button.style.display = 'none'; + button.element.id = 'VRButton'; + button.element.style.display = 'none'; - stylizeElement( button ); + stylizeElement( button.element ); - navigator.xr.isSessionSupported( 'immersive-vr' ).then( function ( supported ) { + let supported = await navigator.xr.isSessionSupported( 'immersive-vr' ); - supported ? showEnterVR() : showWebXRNotFound(); + if(supported){ + showEnterVR(); - } ); - - return button; + return button; + }else{ + return null; + } } else { - const message = document.createElement( 'a' ); - if ( window.isSecureContext === false ) { - message.href = document.location.href.replace( /^http:/, 'https:' ); - message.innerHTML = 'WEBXR NEEDS HTTPS'; // TODO Improve message + console.log("WEBXR NEEDS HTTPS"); } else { - message.href = 'https://immersiveweb.dev/'; - message.innerHTML = 'WEBXR NOT AVAILABLE'; + console.log("WEBXR not available"); } - message.style.left = 'calc(50% - 90px)'; - message.style.width = '180px'; - message.style.textDecoration = 'none'; + return null; - stylizeElement( message ); - return message; } diff --git a/src/Potree.js b/src/Potree.js index 186a5920..016803d8 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -73,7 +73,7 @@ export {OrbitControls} from "./navigation/OrbitControls.js"; export {FirstPersonControls} from "./navigation/FirstPersonControls.js"; export {EarthControls} from "./navigation/EarthControls.js"; export {DeviceOrientationControls} from "./navigation/DeviceOrientationControls.js"; -export {VRControlls} from "./navigation/VRControlls.js"; +export {VRControls} from "./navigation/VRControls.js"; import "./extensions/OrthographicCamera.js"; import "./extensions/PerspectiveCamera.js"; diff --git a/src/materials/shaders/pointcloud.fs b/src/materials/shaders/pointcloud.fs index 58477f11..4accf1c6 100644 --- a/src/materials/shaders/pointcloud.fs +++ b/src/materials/shaders/pointcloud.fs @@ -37,63 +37,65 @@ float specularStrength = 1.0; void main() { - vec3 color = vColor; - float depth = gl_FragCoord.z; + gl_FragColor = vec4(vColor, 1.0); - #if defined(circle_point_shape) || defined(paraboloid_point_shape) - float u = 2.0 * gl_PointCoord.x - 1.0; - float v = 2.0 * gl_PointCoord.y - 1.0; - #endif + // vec3 color = vColor; + // float depth = gl_FragCoord.z; + + // #if defined(circle_point_shape) || defined(paraboloid_point_shape) + // float u = 2.0 * gl_PointCoord.x - 1.0; + // float v = 2.0 * gl_PointCoord.y - 1.0; + // #endif - #if defined(circle_point_shape) - float cc = u*u + v*v; - if(cc > 1.0){ - discard; - } - #endif + // #if defined(circle_point_shape) + // float cc = u*u + v*v; + // if(cc > 1.0){ + // discard; + // } + // #endif - #if defined color_type_indices - gl_FragColor = vec4(color, uPCIndex / 255.0); - #else - gl_FragColor = vec4(color, uOpacity); - #endif + // #if defined color_type_indices + // gl_FragColor = vec4(color, uPCIndex / 255.0); + // #else + // gl_FragColor = vec4(color, uOpacity); + // #endif - #if defined paraboloid_point_shape - float wi = 0.0 - ( u*u + v*v); - vec4 pos = vec4(vViewPosition, 1.0); - pos.z += wi * vRadius; - float linearDepth = -pos.z; - pos = projectionMatrix * pos; - pos = pos / pos.w; - float expDepth = pos.z; - depth = (pos.z + 1.0) / 2.0; - gl_FragDepthEXT = depth; + // #if defined paraboloid_point_shape + // float wi = 0.0 - ( u*u + v*v); + // vec4 pos = vec4(vViewPosition, 1.0); + // pos.z += wi * vRadius; + // float linearDepth = -pos.z; + // pos = projectionMatrix * pos; + // pos = pos / pos.w; + // float expDepth = pos.z; + // depth = (pos.z + 1.0) / 2.0; + // gl_FragDepthEXT = depth; - #if defined(color_type_depth) - color.r = linearDepth; - color.g = expDepth; - #endif + // #if defined(color_type_depth) + // color.r = linearDepth; + // color.g = expDepth; + // #endif - #if defined(use_edl) - gl_FragColor.a = log2(linearDepth); - #endif + // #if defined(use_edl) + // gl_FragColor.a = log2(linearDepth); + // #endif - #else - #if defined(use_edl) - gl_FragColor.a = vLogDepth; - #endif - #endif + // #else + // #if defined(use_edl) + // gl_FragColor.a = vLogDepth; + // #endif + // #endif - #if defined(weighted_splats) - float distance = 2.0 * length(gl_PointCoord.xy - 0.5); - float weight = max(0.0, 1.0 - distance); - weight = pow(weight, 1.5); + // #if defined(weighted_splats) + // float distance = 2.0 * length(gl_PointCoord.xy - 0.5); + // float weight = max(0.0, 1.0 - distance); + // weight = pow(weight, 1.5); - gl_FragColor.a = weight; - gl_FragColor.xyz = gl_FragColor.xyz * weight; - #endif + // gl_FragColor.a = weight; + // gl_FragColor.xyz = gl_FragColor.xyz * weight; + // #endif - //gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0); + // //gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0); } diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index e6e918c3..06c8deb1 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -130,731 +130,731 @@ varying float vRadius; varying float vPointSize; -float round(float number){ - return floor(number + 0.5); -} +// float round(float number){ +// return floor(number + 0.5); +// } -// -// ### ######## ### ######## ######## #### ## ## ######## ###### #### ######## ######## ###### -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## ######## ## ## ## ## ###### ###### ## ## ###### ###### -// ######### ## ## ######### ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ######## ## ## ## ## #### ### ######## ###### #### ######## ######## ###### -// +// // +// // ### ######## ### ######## ######## #### ## ## ######## ###### #### ######## ######## ###### +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## ######## ## ## ## ## ###### ###### ## ## ###### ###### +// // ######### ## ## ######### ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ######## ## ## ## ## #### ### ######## ###### #### ######## ######## ###### +// // -// --------------------- -// OCTREE -// --------------------- +// // --------------------- +// // OCTREE +// // --------------------- -#if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_octree) -/** - * number of 1-bits up to inclusive index position - * number is treated as if it were an integer in the range 0-255 - * - */ -int numberOfOnes(int number, int index){ - int numOnes = 0; - int tmp = 128; - for(int i = 7; i >= 0; i--){ +// #if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_octree) +// /** +// * number of 1-bits up to inclusive index position +// * number is treated as if it were an integer in the range 0-255 +// * +// */ +// int numberOfOnes(int number, int index){ +// int numOnes = 0; +// int tmp = 128; +// for(int i = 7; i >= 0; i--){ - if(number >= tmp){ - number = number - tmp; +// if(number >= tmp){ +// number = number - tmp; - if(i <= index){ - numOnes++; - } - } +// if(i <= index){ +// numOnes++; +// } +// } - tmp = tmp / 2; - } +// tmp = tmp / 2; +// } - return numOnes; -} +// return numOnes; +// } -/** - * checks whether the bit at index is 1 - * number is treated as if it were an integer in the range 0-255 - * - */ -bool isBitSet(int number, int index){ +// /** +// * checks whether the bit at index is 1 +// * number is treated as if it were an integer in the range 0-255 +// * +// */ +// bool isBitSet(int number, int index){ - // weird multi else if due to lack of proper array, int and bitwise support in WebGL 1.0 - int powi = 1; - if(index == 0){ - powi = 1; - }else if(index == 1){ - powi = 2; - }else if(index == 2){ - powi = 4; - }else if(index == 3){ - powi = 8; - }else if(index == 4){ - powi = 16; - }else if(index == 5){ - powi = 32; - }else if(index == 6){ - powi = 64; - }else if(index == 7){ - powi = 128; - }else{ - return false; - } +// // weird multi else if due to lack of proper array, int and bitwise support in WebGL 1.0 +// int powi = 1; +// if(index == 0){ +// powi = 1; +// }else if(index == 1){ +// powi = 2; +// }else if(index == 2){ +// powi = 4; +// }else if(index == 3){ +// powi = 8; +// }else if(index == 4){ +// powi = 16; +// }else if(index == 5){ +// powi = 32; +// }else if(index == 6){ +// powi = 64; +// }else if(index == 7){ +// powi = 128; +// }else{ +// return false; +// } - int ndp = number / powi; +// int ndp = number / powi; - return mod(float(ndp), 2.0) != 0.0; -} +// return mod(float(ndp), 2.0) != 0.0; +// } -/** - * find the LOD at the point position - */ -float getLOD(){ +// /** +// * find the LOD at the point position +// */ +// float getLOD(){ - vec3 offset = vec3(0.0, 0.0, 0.0); - int iOffset = int(uVNStart); - float depth = uLevel; - for(float i = 0.0; i <= 30.0; i++){ - float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0); +// vec3 offset = vec3(0.0, 0.0, 0.0); +// int iOffset = int(uVNStart); +// float depth = uLevel; +// for(float i = 0.0; i <= 30.0; i++){ +// float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0); - vec3 index3d = (position-offset) / nodeSizeAtLevel; - index3d = floor(index3d + 0.5); - int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z)); +// vec3 index3d = (position-offset) / nodeSizeAtLevel; +// index3d = floor(index3d + 0.5); +// int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z)); - vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0)); - int mask = int(round(value.r * 255.0)); +// vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0)); +// int mask = int(round(value.r * 255.0)); - if(isBitSet(mask, index)){ - // there are more visible child nodes at this position - int advanceG = int(round(value.g * 255.0)) * 256; - int advanceB = int(round(value.b * 255.0)); - int advanceChild = numberOfOnes(mask, index - 1); - int advance = advanceG + advanceB + advanceChild; +// if(isBitSet(mask, index)){ +// // there are more visible child nodes at this position +// int advanceG = int(round(value.g * 255.0)) * 256; +// int advanceB = int(round(value.b * 255.0)); +// int advanceChild = numberOfOnes(mask, index - 1); +// int advance = advanceG + advanceB + advanceChild; - iOffset = iOffset + advance; +// iOffset = iOffset + advance; - depth++; - }else{ - // no more visible child nodes at this position - //return value.a * 255.0; +// depth++; +// }else{ +// // no more visible child nodes at this position +// //return value.a * 255.0; - float lodOffset = (255.0 * value.a) / 10.0 - 10.0; +// float lodOffset = (255.0 * value.a) / 10.0 - 10.0; - return depth + lodOffset; - } +// return depth + lodOffset; +// } - offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; - } +// offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; +// } - return depth; -} +// return depth; +// } -float getSpacing(){ - vec3 offset = vec3(0.0, 0.0, 0.0); - int iOffset = int(uVNStart); - float depth = uLevel; - float spacing = uNodeSpacing; - for(float i = 0.0; i <= 30.0; i++){ - float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0); +// float getSpacing(){ +// vec3 offset = vec3(0.0, 0.0, 0.0); +// int iOffset = int(uVNStart); +// float depth = uLevel; +// float spacing = uNodeSpacing; +// for(float i = 0.0; i <= 30.0; i++){ +// float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0); - vec3 index3d = (position-offset) / nodeSizeAtLevel; - index3d = floor(index3d + 0.5); - int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z)); +// vec3 index3d = (position-offset) / nodeSizeAtLevel; +// index3d = floor(index3d + 0.5); +// int index = int(round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z)); - vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0)); - int mask = int(round(value.r * 255.0)); - float spacingFactor = value.a; +// vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0)); +// int mask = int(round(value.r * 255.0)); +// float spacingFactor = value.a; - if(i > 0.0){ - spacing = spacing / (255.0 * spacingFactor); - } +// if(i > 0.0){ +// spacing = spacing / (255.0 * spacingFactor); +// } - if(isBitSet(mask, index)){ - // there are more visible child nodes at this position - int advanceG = int(round(value.g * 255.0)) * 256; - int advanceB = int(round(value.b * 255.0)); - int advanceChild = numberOfOnes(mask, index - 1); - int advance = advanceG + advanceB + advanceChild; +// if(isBitSet(mask, index)){ +// // there are more visible child nodes at this position +// int advanceG = int(round(value.g * 255.0)) * 256; +// int advanceB = int(round(value.b * 255.0)); +// int advanceChild = numberOfOnes(mask, index - 1); +// int advance = advanceG + advanceB + advanceChild; - iOffset = iOffset + advance; +// iOffset = iOffset + advance; - //spacing = spacing / (255.0 * spacingFactor); - //spacing = spacing / 3.0; +// //spacing = spacing / (255.0 * spacingFactor); +// //spacing = spacing / 3.0; - depth++; - }else{ - // no more visible child nodes at this position - return spacing; - } +// depth++; +// }else{ +// // no more visible child nodes at this position +// return spacing; +// } - offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; - } +// offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; +// } - return spacing; -} +// return spacing; +// } -float getPointSizeAttenuation(){ - return pow(2.0, getLOD()); -} +// float getPointSizeAttenuation(){ +// return pow(2.0, getLOD()); +// } -#endif +// #endif -// --------------------- -// KD-TREE -// --------------------- +// // --------------------- +// // KD-TREE +// // --------------------- -#if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_kdtree) +// #if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_kdtree) -float getLOD(){ - vec3 offset = vec3(0.0, 0.0, 0.0); - float iOffset = 0.0; - float depth = 0.0; +// float getLOD(){ +// vec3 offset = vec3(0.0, 0.0, 0.0); +// float iOffset = 0.0; +// float depth = 0.0; - vec3 size = uBBSize; - vec3 pos = position; +// vec3 size = uBBSize; +// vec3 pos = position; - for(float i = 0.0; i <= 1000.0; i++){ +// for(float i = 0.0; i <= 1000.0; i++){ - vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); +// vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); - int children = int(value.r * 255.0); - float next = value.g * 255.0; - int split = int(value.b * 255.0); +// int children = int(value.r * 255.0); +// float next = value.g * 255.0; +// int split = int(value.b * 255.0); - if(next == 0.0){ - return depth; - } +// if(next == 0.0){ +// return depth; +// } - vec3 splitv = vec3(0.0, 0.0, 0.0); - if(split == 1){ - splitv.x = 1.0; - }else if(split == 2){ - splitv.y = 1.0; - }else if(split == 4){ - splitv.z = 1.0; - } +// vec3 splitv = vec3(0.0, 0.0, 0.0); +// if(split == 1){ +// splitv.x = 1.0; +// }else if(split == 2){ +// splitv.y = 1.0; +// }else if(split == 4){ +// splitv.z = 1.0; +// } - iOffset = iOffset + next; +// iOffset = iOffset + next; - float factor = length(pos * splitv / size); - if(factor < 0.5){ - // left - if(children == 0 || children == 2){ - return depth; - } - }else{ - // right - pos = pos - size * splitv * 0.5; - if(children == 0 || children == 1){ - return depth; - } - if(children == 3){ - iOffset = iOffset + 1.0; - } - } - size = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5); +// float factor = length(pos * splitv / size); +// if(factor < 0.5){ +// // left +// if(children == 0 || children == 2){ +// return depth; +// } +// }else{ +// // right +// pos = pos - size * splitv * 0.5; +// if(children == 0 || children == 1){ +// return depth; +// } +// if(children == 3){ +// iOffset = iOffset + 1.0; +// } +// } +// size = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5); - depth++; - } +// depth++; +// } - return depth; -} +// return depth; +// } -float getPointSizeAttenuation(){ - return 0.5 * pow(1.3, getLOD()); -} +// float getPointSizeAttenuation(){ +// return 0.5 * pow(1.3, getLOD()); +// } -#endif +// #endif -// -// ### ######## ######## ######## #### ######## ## ## ######## ######## ###### -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ######## ## ######## ## ## ## ###### ###### -// ######### ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## -// ## ## ## ## ## ## #### ######## ####### ## ######## ###### -// +// // +// // ### ######## ######## ######## #### ######## ## ## ######## ######## ###### +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ######## ## ######## ## ## ## ###### ###### +// // ######### ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +// // ## ## ## ## ## ## #### ######## ####### ## ######## ###### +// // -// formula adapted from: http://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-5-contrast-adjustment/ -float getContrastFactor(float contrast){ - return (1.0158730158730156 * (contrast + 1.0)) / (1.0158730158730156 - contrast); -} +// // formula adapted from: http://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-5-contrast-adjustment/ +// float getContrastFactor(float contrast){ +// return (1.0158730158730156 * (contrast + 1.0)) / (1.0158730158730156 - contrast); +// } -vec3 getRGB(){ - vec3 rgb = color; +// vec3 getRGB(){ +// vec3 rgb = color; - rgb = pow(rgb, vec3(uRGB_gbc.x)); - rgb = rgb + uRGB_gbc.y; - rgb = (rgb - 0.5) * getContrastFactor(uRGB_gbc.z) + 0.5; - rgb = clamp(rgb, 0.0, 1.0); +// rgb = pow(rgb, vec3(uRGB_gbc.x)); +// rgb = rgb + uRGB_gbc.y; +// rgb = (rgb - 0.5) * getContrastFactor(uRGB_gbc.z) + 0.5; +// rgb = clamp(rgb, 0.0, 1.0); - return rgb; -} +// return rgb; +// } -float getIntensity(){ - float w = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x); - w = pow(w, uIntensity_gbc.x); - w = w + uIntensity_gbc.y; - w = (w - 0.5) * getContrastFactor(uIntensity_gbc.z) + 0.5; - w = clamp(w, 0.0, 1.0); +// float getIntensity(){ +// float w = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x); +// w = pow(w, uIntensity_gbc.x); +// w = w + uIntensity_gbc.y; +// w = (w - 0.5) * getContrastFactor(uIntensity_gbc.z) + 0.5; +// w = clamp(w, 0.0, 1.0); - return w; -} +// return w; +// } -vec3 getGpsTime(){ +// vec3 getGpsTime(){ - float w = (gpsTime + uGpsOffset) * uGpsScale; +// float w = (gpsTime + uGpsOffset) * uGpsScale; - vec3 c = texture2D(gradient, vec2(w, 1.0 - w)).rgb; +// vec3 c = texture2D(gradient, vec2(w, 1.0 - w)).rgb; - // vec2 r = uNormalizedGpsBufferRange; - // float w = gpsTime * (r.y - r.x) + r.x; - // w = clamp(w, 0.0, 1.0); - // vec3 c = texture2D(gradient, vec2(w,1.0-w)).rgb; +// // vec2 r = uNormalizedGpsBufferRange; +// // float w = gpsTime * (r.y - r.x) + r.x; +// // w = clamp(w, 0.0, 1.0); +// // vec3 c = texture2D(gradient, vec2(w,1.0-w)).rgb; - return c; -} +// return c; +// } -vec3 getElevation(){ - vec4 world = modelMatrix * vec4( position, 1.0 ); - float w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x); - vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb; +// vec3 getElevation(){ +// vec4 world = modelMatrix * vec4( position, 1.0 ); +// float w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x); +// vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb; - return cElevation; -} +// return cElevation; +// } -vec4 getClassification(){ - vec2 uv = vec2(classification / 255.0, 0.5); - vec4 classColor = texture2D(classificationLUT, uv); +// vec4 getClassification(){ +// vec2 uv = vec2(classification / 255.0, 0.5); +// vec4 classColor = texture2D(classificationLUT, uv); - return classColor; -} +// return classColor; +// } -vec3 getReturns(){ +// vec3 getReturns(){ - // 0b 00_000_111 - float rn = mod(returnNumber, 8.0); - // 0b 00_111_000 - float nr = mod(returnNumber / 8.0, 8.0); +// // 0b 00_000_111 +// float rn = mod(returnNumber, 8.0); +// // 0b 00_111_000 +// float nr = mod(returnNumber / 8.0, 8.0); - if(nr <= 1.0){ - return vec3(1.0, 0.0, 0.0); - }else{ - return vec3(0.0, 1.0, 0.0); - } +// if(nr <= 1.0){ +// return vec3(1.0, 0.0, 0.0); +// }else{ +// return vec3(0.0, 1.0, 0.0); +// } - // return vec3(nr / 4.0, 0.0, 0.0); +// // return vec3(nr / 4.0, 0.0, 0.0); - // if(nr == 1.0){ - // return vec3(1.0, 1.0, 0.0); - // }else{ - // if(rn == 1.0){ - // return vec3(1.0, 0.0, 0.0); - // }else if(rn == nr){ - // return vec3(0.0, 0.0, 1.0); - // }else{ - // return vec3(0.0, 1.0, 0.0); - // } - // } +// // if(nr == 1.0){ +// // return vec3(1.0, 1.0, 0.0); +// // }else{ +// // if(rn == 1.0){ +// // return vec3(1.0, 0.0, 0.0); +// // }else if(rn == nr){ +// // return vec3(0.0, 0.0, 1.0); +// // }else{ +// // return vec3(0.0, 1.0, 0.0); +// // } +// // } - // if(numberOfReturns == 1.0){ - // return vec3(1.0, 1.0, 0.0); - // }else{ - // if(returnNumber == 1.0){ - // return vec3(1.0, 0.0, 0.0); - // }else if(returnNumber == numberOfReturns){ - // return vec3(0.0, 0.0, 1.0); - // }else{ - // return vec3(0.0, 1.0, 0.0); - // } - // } -} +// // if(numberOfReturns == 1.0){ +// // return vec3(1.0, 1.0, 0.0); +// // }else{ +// // if(returnNumber == 1.0){ +// // return vec3(1.0, 0.0, 0.0); +// // }else if(returnNumber == numberOfReturns){ +// // return vec3(0.0, 0.0, 1.0); +// // }else{ +// // return vec3(0.0, 1.0, 0.0); +// // } +// // } +// } -vec3 getReturnNumber(){ - if(numberOfReturns == 1.0){ - return vec3(1.0, 1.0, 0.0); - }else{ - if(returnNumber == 1.0){ - return vec3(1.0, 0.0, 0.0); - }else if(returnNumber == numberOfReturns){ - return vec3(0.0, 0.0, 1.0); - }else{ - return vec3(0.0, 1.0, 0.0); - } - } -} +// vec3 getReturnNumber(){ +// if(numberOfReturns == 1.0){ +// return vec3(1.0, 1.0, 0.0); +// }else{ +// if(returnNumber == 1.0){ +// return vec3(1.0, 0.0, 0.0); +// }else if(returnNumber == numberOfReturns){ +// return vec3(0.0, 0.0, 1.0); +// }else{ +// return vec3(0.0, 1.0, 0.0); +// } +// } +// } -vec3 getNumberOfReturns(){ - float value = numberOfReturns; +// vec3 getNumberOfReturns(){ +// float value = numberOfReturns; - float w = value / 6.0; +// float w = value / 6.0; - vec3 color = texture2D(gradient, vec2(w, 1.0 - w)).rgb; +// vec3 color = texture2D(gradient, vec2(w, 1.0 - w)).rgb; - return color; -} +// return color; +// } -vec3 getSourceID(){ - float w = mod(pointSourceID, 10.0) / 10.0; - return texture2D(gradient, vec2(w,1.0 - w)).rgb; -} +// vec3 getSourceID(){ +// float w = mod(pointSourceID, 10.0) / 10.0; +// return texture2D(gradient, vec2(w,1.0 - w)).rgb; +// } -vec3 getCompositeColor(){ - vec3 c; - float w; +// vec3 getCompositeColor(){ +// vec3 c; +// float w; - c += wRGB * getRGB(); - w += wRGB; +// c += wRGB * getRGB(); +// w += wRGB; - c += wIntensity * getIntensity() * vec3(1.0, 1.0, 1.0); - w += wIntensity; +// c += wIntensity * getIntensity() * vec3(1.0, 1.0, 1.0); +// w += wIntensity; - c += wElevation * getElevation(); - w += wElevation; +// c += wElevation * getElevation(); +// w += wElevation; - c += wReturnNumber * getReturnNumber(); - w += wReturnNumber; +// c += wReturnNumber * getReturnNumber(); +// w += wReturnNumber; - c += wSourceID * getSourceID(); - w += wSourceID; +// c += wSourceID * getSourceID(); +// w += wSourceID; - vec4 cl = wClassification * getClassification(); - c += cl.a * cl.rgb; - w += wClassification * cl.a; +// vec4 cl = wClassification * getClassification(); +// c += cl.a * cl.rgb; +// w += wClassification * cl.a; - c = c / w; +// c = c / w; - if(w == 0.0){ - //c = color; - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - } +// if(w == 0.0){ +// //c = color; +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// } - return c; -} +// return c; +// } -vec3 getNormal(){ - //vec3 n_hsv = vec3( modelMatrix * vec4( normal, 0.0 )) * 0.5 + 0.5; // (n_world.xyz + vec3(1.,1.,1.)) / 2.; - vec3 n_view = normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) ); - return n_view; -} -bool applyBackfaceCulling() { - // Black not facing vertices / Backface culling - vec3 e = normalize(vec3(modelViewMatrix * vec4( position, 1. ))); - vec3 n = getNormal(); // normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) ); +// vec3 getNormal(){ +// //vec3 n_hsv = vec3( modelMatrix * vec4( normal, 0.0 )) * 0.5 + 0.5; // (n_world.xyz + vec3(1.,1.,1.)) / 2.; +// vec3 n_view = normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) ); +// return n_view; +// } +// bool applyBackfaceCulling() { +// // Black not facing vertices / Backface culling +// vec3 e = normalize(vec3(modelViewMatrix * vec4( position, 1. ))); +// vec3 n = getNormal(); // normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) ); - if((uUseOrthographicCamera && n.z <= 0.) || (!uUseOrthographicCamera && dot( n, e ) >= 0.)) { - return true; - } else { - return false; - } -} +// if((uUseOrthographicCamera && n.z <= 0.) || (!uUseOrthographicCamera && dot( n, e ) >= 0.)) { +// return true; +// } else { +// return false; +// } +// } -#if defined(color_type_matcap) -// Matcap Material -vec3 getMatcap(){ - vec3 eye = normalize( vec3( modelViewMatrix * vec4( position, 1. ) ) ); - if(uUseOrthographicCamera) { - eye = vec3(0., 0., -1.); - } - vec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n; - float m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. )); - vec2 vN = r_en.xy / m + .5; - return texture2D(matcapTextureUniform, vN).rgb; -} -#endif +// #if defined(color_type_matcap) +// // Matcap Material +// vec3 getMatcap(){ +// vec3 eye = normalize( vec3( modelViewMatrix * vec4( position, 1. ) ) ); +// if(uUseOrthographicCamera) { +// eye = vec3(0., 0., -1.); +// } +// vec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n; +// float m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. )); +// vec2 vN = r_en.xy / m + .5; +// return texture2D(matcapTextureUniform, vN).rgb; +// } +// #endif -vec3 getExtra(){ +// vec3 getExtra(){ - float w = (aExtra + uExtraOffset) * uExtraScale; - w = clamp(w, 0.0, 1.0); +// float w = (aExtra + uExtraOffset) * uExtraScale; +// w = clamp(w, 0.0, 1.0); - vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb; +// vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb; - // vec2 r = uExtraNormalizedRange; +// // vec2 r = uExtraNormalizedRange; - // float w = aExtra * (r.y - r.x) + r.x; +// // float w = aExtra * (r.y - r.x) + r.x; - // w = (w - uExtraRange.x) / (uExtraRange.y - uExtraRange.x); +// // w = (w - uExtraRange.x) / (uExtraRange.y - uExtraRange.x); - // w = clamp(w, 0.0, 1.0); +// // w = clamp(w, 0.0, 1.0); - // vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb; +// // vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb; - return color; -} +// return color; +// } -vec3 getColor(){ - vec3 color; +// vec3 getColor(){ +// vec3 color; - #ifdef color_type_rgba - color = getRGB(); - #elif defined color_type_height || defined color_type_elevation - color = getElevation(); - #elif defined color_type_rgb_height - vec3 cHeight = getElevation(); - color = (1.0 - uTransition) * getRGB() + uTransition * cHeight; - #elif defined color_type_depth - float linearDepth = gl_Position.w; - float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5; - color = vec3(linearDepth, expDepth, 0.0); - //color = vec3(1.0, 0.5, 0.3); - #elif defined color_type_intensity - float w = getIntensity(); - color = vec3(w, w, w); - #elif defined color_type_gps_time - color = getGpsTime(); - #elif defined color_type_intensity_gradient - float w = getIntensity(); - color = texture2D(gradient, vec2(w,1.0-w)).rgb; - #elif defined color_type_color - color = uColor; - #elif defined color_type_level_of_detail - float depth = getLOD(); - float w = depth / 10.0; - color = texture2D(gradient, vec2(w,1.0-w)).rgb; - #elif defined color_type_indices - color = indices.rgb; - #elif defined color_type_classification - vec4 cl = getClassification(); - color = cl.rgb; - #elif defined color_type_return_number - color = getReturnNumber(); - #elif defined color_type_returns - color = getReturns(); - #elif defined color_type_number_of_returns - color = getNumberOfReturns(); - #elif defined color_type_source_id - color = getSourceID(); - #elif defined color_type_point_source_id - color = getSourceID(); - #elif defined color_type_normal - color = (modelMatrix * vec4(normal, 0.0)).xyz; - #elif defined color_type_phong - color = color; - #elif defined color_type_composite - color = getCompositeColor(); - #elif defined color_type_matcap - color = getMatcap(); - #else - color = getExtra(); - #endif +// #ifdef color_type_rgba +// color = getRGB(); +// #elif defined color_type_height || defined color_type_elevation +// color = getElevation(); +// #elif defined color_type_rgb_height +// vec3 cHeight = getElevation(); +// color = (1.0 - uTransition) * getRGB() + uTransition * cHeight; +// #elif defined color_type_depth +// float linearDepth = gl_Position.w; +// float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5; +// color = vec3(linearDepth, expDepth, 0.0); +// //color = vec3(1.0, 0.5, 0.3); +// #elif defined color_type_intensity +// float w = getIntensity(); +// color = vec3(w, w, w); +// #elif defined color_type_gps_time +// color = getGpsTime(); +// #elif defined color_type_intensity_gradient +// float w = getIntensity(); +// color = texture2D(gradient, vec2(w,1.0-w)).rgb; +// #elif defined color_type_color +// color = uColor; +// #elif defined color_type_level_of_detail +// float depth = getLOD(); +// float w = depth / 10.0; +// color = texture2D(gradient, vec2(w,1.0-w)).rgb; +// #elif defined color_type_indices +// color = indices.rgb; +// #elif defined color_type_classification +// vec4 cl = getClassification(); +// color = cl.rgb; +// #elif defined color_type_return_number +// color = getReturnNumber(); +// #elif defined color_type_returns +// color = getReturns(); +// #elif defined color_type_number_of_returns +// color = getNumberOfReturns(); +// #elif defined color_type_source_id +// color = getSourceID(); +// #elif defined color_type_point_source_id +// color = getSourceID(); +// #elif defined color_type_normal +// color = (modelMatrix * vec4(normal, 0.0)).xyz; +// #elif defined color_type_phong +// color = color; +// #elif defined color_type_composite +// color = getCompositeColor(); +// #elif defined color_type_matcap +// color = getMatcap(); +// #else +// color = getExtra(); +// #endif - if (backfaceCulling && applyBackfaceCulling()) { - color = vec3(0.); - } +// if (backfaceCulling && applyBackfaceCulling()) { +// color = vec3(0.); +// } - return color; -} +// return color; +// } -float getPointSize(){ - float pointSize = 1.0; +// float getPointSize(){ +// float pointSize = 1.0; - float slope = tan(fov / 2.0); - float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z); +// float slope = tan(fov / 2.0); +// float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z); - float r = uOctreeSpacing * 1.7; - vRadius = r; - #if defined fixed_point_size - pointSize = size; - #elif defined attenuated_point_size - if(uUseOrthographicCamera){ - pointSize = size; - }else{ - pointSize = size * spacing * projFactor; - //pointSize = pointSize * projFactor; - } - #elif defined adaptive_point_size - if(uUseOrthographicCamera) { - float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation(); - pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth; - } else { +// float r = uOctreeSpacing * 1.7; +// vRadius = r; +// #if defined fixed_point_size +// pointSize = size; +// #elif defined attenuated_point_size +// if(uUseOrthographicCamera){ +// pointSize = size; +// }else{ +// pointSize = size * spacing * projFactor; +// //pointSize = pointSize * projFactor; +// } +// #elif defined adaptive_point_size +// if(uUseOrthographicCamera) { +// float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation(); +// pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth; +// } else { - // float leafSpacing = 0.122069092 * 8.0; +// // float leafSpacing = 0.122069092 * 8.0; - // bool isLeafNode = getLOD() == 1000.0; - // if(isLeafNode){ - // // pointSize = size * spacing * projFactor; +// // bool isLeafNode = getLOD() == 1000.0; +// // if(isLeafNode){ +// // // pointSize = size * spacing * projFactor; - // float worldSpaceSize = size * leafSpacing; - // pointSize = worldSpaceSize * projFactor; - // }else{ - float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation(); +// // float worldSpaceSize = size * leafSpacing; +// // pointSize = worldSpaceSize * projFactor; +// // }else{ +// float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation(); - // minimum world space size - // worldSpaceSize = max(worldSpaceSize, leafSpacing); +// // minimum world space size +// // worldSpaceSize = max(worldSpaceSize, leafSpacing); - pointSize = worldSpaceSize * projFactor; - // } - } - #endif +// pointSize = worldSpaceSize * projFactor; +// // } +// } +// #endif - pointSize = max(minSize, pointSize); - pointSize = min(maxSize, pointSize); +// pointSize = max(minSize, pointSize); +// pointSize = min(maxSize, pointSize); - vRadius = pointSize / projFactor; +// vRadius = pointSize / projFactor; - return pointSize; -} +// return pointSize; +// } -#if defined(num_clippolygons) && num_clippolygons > 0 -bool pointInClipPolygon(vec3 point, int polyIdx) { +// #if defined(num_clippolygons) && num_clippolygons > 0 +// bool pointInClipPolygon(vec3 point, int polyIdx) { - mat4 wvp = uClipPolygonWVP[polyIdx]; - //vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0); - //screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5; +// mat4 wvp = uClipPolygonWVP[polyIdx]; +// //vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0); +// //screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5; - vec4 pointNDC = wvp * vec4(point, 1.0); - pointNDC.xy = pointNDC.xy / pointNDC.w; +// vec4 pointNDC = wvp * vec4(point, 1.0); +// pointNDC.xy = pointNDC.xy / pointNDC.w; - int j = uClipPolygonVCount[polyIdx] - 1; - bool c = false; - for(int i = 0; i < 8; i++) { - if(i == uClipPolygonVCount[polyIdx]) { - break; - } +// int j = uClipPolygonVCount[polyIdx] - 1; +// bool c = false; +// for(int i = 0; i < 8; i++) { +// if(i == uClipPolygonVCount[polyIdx]) { +// break; +// } - //vec4 verti = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1); - //vec4 vertj = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1); +// //vec4 verti = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1); +// //vec4 vertj = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1); - //verti.xy = verti.xy / verti.w; - //vertj.xy = vertj.xy / vertj.w; +// //verti.xy = verti.xy / verti.w; +// //vertj.xy = vertj.xy / vertj.w; - //verti.xy = verti.xy / verti.w * 0.5 + 0.5; - //vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5; +// //verti.xy = verti.xy / verti.w * 0.5 + 0.5; +// //vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5; - vec3 verti = uClipPolygonVertices[polyIdx * 8 + i]; - vec3 vertj = uClipPolygonVertices[polyIdx * 8 + j]; +// vec3 verti = uClipPolygonVertices[polyIdx * 8 + i]; +// vec3 vertj = uClipPolygonVertices[polyIdx * 8 + j]; - if( ((verti.y > pointNDC.y) != (vertj.y > pointNDC.y)) && - (pointNDC.x < (vertj.x-verti.x) * (pointNDC.y-verti.y) / (vertj.y-verti.y) + verti.x) ) { - c = !c; - } - j = i; - } +// if( ((verti.y > pointNDC.y) != (vertj.y > pointNDC.y)) && +// (pointNDC.x < (vertj.x-verti.x) * (pointNDC.y-verti.y) / (vertj.y-verti.y) + verti.x) ) { +// c = !c; +// } +// j = i; +// } - return c; -} -#endif +// return c; +// } +// #endif -void doClipping(){ +// void doClipping(){ - { - vec4 cl = getClassification(); - if(cl.a == 0.0){ - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// { +// vec4 cl = getClassification(); +// if(cl.a == 0.0){ +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - return; - } - } +// return; +// } +// } - #if defined(clip_return_number_enabled) - { // return number filter - vec2 range = uFilterReturnNumberRange; - if(returnNumber < range.x || returnNumber > range.y){ - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// #if defined(clip_return_number_enabled) +// { // return number filter +// vec2 range = uFilterReturnNumberRange; +// if(returnNumber < range.x || returnNumber > range.y){ +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - return; - } - } - #endif +// return; +// } +// } +// #endif - #if defined(clip_number_of_returns_enabled) - { // number of return filter - vec2 range = uFilterNumberOfReturnsRange; - if(numberOfReturns < range.x || numberOfReturns > range.y){ - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// #if defined(clip_number_of_returns_enabled) +// { // number of return filter +// vec2 range = uFilterNumberOfReturnsRange; +// if(numberOfReturns < range.x || numberOfReturns > range.y){ +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - return; - } - } - #endif +// return; +// } +// } +// #endif - #if defined(clip_gps_enabled) - { // GPS time filter - float time = (gpsTime + uGpsOffset) * uGpsScale; - vec2 range = uFilterGPSTimeClipRange; +// #if defined(clip_gps_enabled) +// { // GPS time filter +// float time = (gpsTime + uGpsOffset) * uGpsScale; +// vec2 range = uFilterGPSTimeClipRange; - if(time < range.x || time > range.y){ - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// if(time < range.x || time > range.y){ +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - return; - } - } - #endif +// return; +// } +// } +// #endif - #if defined(clip_point_source_id_enabled) - { // point source id filter - vec2 range = uFilterPointSourceIDClipRange; - if(pointSourceID < range.x || pointSourceID > range.y){ - gl_Position = vec4(100.0, 100.0, 100.0, 0.0); +// #if defined(clip_point_source_id_enabled) +// { // point source id filter +// vec2 range = uFilterPointSourceIDClipRange; +// if(pointSourceID < range.x || pointSourceID > range.y){ +// gl_Position = vec4(100.0, 100.0, 100.0, 0.0); - return; - } - } - #endif +// return; +// } +// } +// #endif - int clipVolumesCount = 0; - int insideCount = 0; +// int clipVolumesCount = 0; +// int insideCount = 0; - #if defined(num_clipboxes) && num_clipboxes > 0 - for(int i = 0; i < num_clipboxes; i++){ - vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); - bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; - inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; - inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; +// #if defined(num_clipboxes) && num_clipboxes > 0 +// for(int i = 0; i < num_clipboxes; i++){ +// vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); +// bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; +// inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; +// inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; - insideCount = insideCount + (inside ? 1 : 0); - clipVolumesCount++; - } - #endif +// insideCount = insideCount + (inside ? 1 : 0); +// clipVolumesCount++; +// } +// #endif - #if defined(num_clippolygons) && num_clippolygons > 0 - for(int i = 0; i < num_clippolygons; i++) { - bool inside = pointInClipPolygon(position, i); +// #if defined(num_clippolygons) && num_clippolygons > 0 +// for(int i = 0; i < num_clippolygons; i++) { +// bool inside = pointInClipPolygon(position, i); - insideCount = insideCount + (inside ? 1 : 0); - clipVolumesCount++; - } - #endif +// insideCount = insideCount + (inside ? 1 : 0); +// clipVolumesCount++; +// } +// #endif - bool insideAny = insideCount > 0; - bool insideAll = (clipVolumesCount > 0) && (clipVolumesCount == insideCount); +// bool insideAny = insideCount > 0; +// bool insideAll = (clipVolumesCount > 0) && (clipVolumesCount == insideCount); - if(clipMethod == CLIPMETHOD_INSIDE_ANY){ - if(insideAny && clipTask == CLIPTASK_HIGHLIGHT){ - vColor.r += 0.5; - }else if(!insideAny && clipTask == CLIPTASK_SHOW_INSIDE){ - gl_Position = vec4(100.0, 100.0, 100.0, 1.0); - }else if(insideAny && clipTask == CLIPTASK_SHOW_OUTSIDE){ - gl_Position = vec4(100.0, 100.0, 100.0, 1.0); - } - }else if(clipMethod == CLIPMETHOD_INSIDE_ALL){ - if(insideAll && clipTask == CLIPTASK_HIGHLIGHT){ - vColor.r += 0.5; - }else if(!insideAll && clipTask == CLIPTASK_SHOW_INSIDE){ - gl_Position = vec4(100.0, 100.0, 100.0, 1.0); - }else if(insideAll && clipTask == CLIPTASK_SHOW_OUTSIDE){ - gl_Position = vec4(100.0, 100.0, 100.0, 1.0); - } - } -} +// if(clipMethod == CLIPMETHOD_INSIDE_ANY){ +// if(insideAny && clipTask == CLIPTASK_HIGHLIGHT){ +// vColor.r += 0.5; +// }else if(!insideAny && clipTask == CLIPTASK_SHOW_INSIDE){ +// gl_Position = vec4(100.0, 100.0, 100.0, 1.0); +// }else if(insideAny && clipTask == CLIPTASK_SHOW_OUTSIDE){ +// gl_Position = vec4(100.0, 100.0, 100.0, 1.0); +// } +// }else if(clipMethod == CLIPMETHOD_INSIDE_ALL){ +// if(insideAll && clipTask == CLIPTASK_HIGHLIGHT){ +// vColor.r += 0.5; +// }else if(!insideAll && clipTask == CLIPTASK_SHOW_INSIDE){ +// gl_Position = vec4(100.0, 100.0, 100.0, 1.0); +// }else if(insideAll && clipTask == CLIPTASK_SHOW_OUTSIDE){ +// gl_Position = vec4(100.0, 100.0, 100.0, 1.0); +// } +// } +// } @@ -875,111 +875,116 @@ void main() { vLogDepth = log2(-mvPosition.z); // POINT SIZE - float pointSize = getPointSize(); + //float pointSize = getPointSize(); + float pointSize = 2.0; gl_PointSize = pointSize; vPointSize = pointSize; // COLOR - vColor = getColor(); - - //gl_Position = vec4(0.0, 0.0, 0.0, 1.0); - //gl_Position = vec4(position.xzy / 1000.0, 1.0 ); - - //gl_PointSize = 5.0; - //vColor = vec3(1.0, 1.0, 1.0); - - // only for "replacing" approaches - // if(getLOD() != uLevel){ - // gl_Position = vec4(10.0, 10.0, 10.0, 1.0); - // } + // vColor = getColor(); + vColor = vec3(1.0, 0.0, 0.0); - #if defined hq_depth_pass - float originalDepth = gl_Position.w; - float adjustedDepth = originalDepth + 2.0 * vRadius; - float adjust = adjustedDepth / originalDepth; + // return; - mvPosition.xyz = mvPosition.xyz * adjust; - gl_Position = projectionMatrix * mvPosition; - #endif + // //gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + // //gl_Position = vec4(position.xzy / 1000.0, 1.0 ); + + // //gl_PointSize = 5.0; + // //vColor = vec3(1.0, 1.0, 1.0); + + // // only for "replacing" approaches + // // if(getLOD() != uLevel){ + // // gl_Position = vec4(10.0, 10.0, 10.0, 1.0); + // // } - // CLIPPING - doClipping(); + // #if defined hq_depth_pass + // float originalDepth = gl_Position.w; + // float adjustedDepth = originalDepth + 2.0 * vRadius; + // float adjust = adjustedDepth / originalDepth; - #if defined(num_clipspheres) && num_clipspheres > 0 - for(int i = 0; i < num_clipspheres; i++){ - vec4 sphereLocal = uClipSpheres[i] * mvPosition; + // mvPosition.xyz = mvPosition.xyz * adjust; + // gl_Position = projectionMatrix * mvPosition; + // #endif - float distance = length(sphereLocal.xyz); - if(distance < 1.0){ - float w = distance; - vec3 cGradient = texture2D(gradient, vec2(w, 1.0 - w)).rgb; + // // CLIPPING + // doClipping(); + + // #if defined(num_clipspheres) && num_clipspheres > 0 + // for(int i = 0; i < num_clipspheres; i++){ + // vec4 sphereLocal = uClipSpheres[i] * mvPosition; + + // float distance = length(sphereLocal.xyz); + + // if(distance < 1.0){ + // float w = distance; + // vec3 cGradient = texture2D(gradient, vec2(w, 1.0 - w)).rgb; - vColor = cGradient; - //vColor = cGradient * 0.7 + vColor * 0.3; - } - } - #endif + // vColor = cGradient; + // //vColor = cGradient * 0.7 + vColor * 0.3; + // } + // } + // #endif - #if defined(num_shadowmaps) && num_shadowmaps > 0 + // #if defined(num_shadowmaps) && num_shadowmaps > 0 - const float sm_near = 0.1; - const float sm_far = 10000.0; + // const float sm_near = 0.1; + // const float sm_far = 10000.0; - for(int i = 0; i < num_shadowmaps; i++){ - vec3 viewPos = (uShadowWorldView[i] * vec4(position, 1.0)).xyz; - float distanceToLight = abs(viewPos.z); + // for(int i = 0; i < num_shadowmaps; i++){ + // vec3 viewPos = (uShadowWorldView[i] * vec4(position, 1.0)).xyz; + // float distanceToLight = abs(viewPos.z); - vec4 projPos = uShadowProj[i] * uShadowWorldView[i] * vec4(position, 1); - vec3 nc = projPos.xyz / projPos.w; + // vec4 projPos = uShadowProj[i] * uShadowWorldView[i] * vec4(position, 1); + // vec3 nc = projPos.xyz / projPos.w; - float u = nc.x * 0.5 + 0.5; - float v = nc.y * 0.5 + 0.5; + // float u = nc.x * 0.5 + 0.5; + // float v = nc.y * 0.5 + 0.5; - vec2 sampleStep = vec2(1.0 / (2.0*1024.0), 1.0 / (2.0*1024.0)) * 1.5; - vec2 sampleLocations[9]; - sampleLocations[0] = vec2(0.0, 0.0); - sampleLocations[1] = sampleStep; - sampleLocations[2] = -sampleStep; - sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y); - sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y); + // vec2 sampleStep = vec2(1.0 / (2.0*1024.0), 1.0 / (2.0*1024.0)) * 1.5; + // vec2 sampleLocations[9]; + // sampleLocations[0] = vec2(0.0, 0.0); + // sampleLocations[1] = sampleStep; + // sampleLocations[2] = -sampleStep; + // sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y); + // sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y); - sampleLocations[5] = vec2(0.0, sampleStep.y); - sampleLocations[6] = vec2(0.0, -sampleStep.y); - sampleLocations[7] = vec2(sampleStep.x, 0.0); - sampleLocations[8] = vec2(-sampleStep.x, 0.0); + // sampleLocations[5] = vec2(0.0, sampleStep.y); + // sampleLocations[6] = vec2(0.0, -sampleStep.y); + // sampleLocations[7] = vec2(sampleStep.x, 0.0); + // sampleLocations[8] = vec2(-sampleStep.x, 0.0); - float visibleSamples = 0.0; - float numSamples = 0.0; + // float visibleSamples = 0.0; + // float numSamples = 0.0; - float bias = vRadius * 2.0; + // float bias = vRadius * 2.0; - for(int j = 0; j < 9; j++){ - vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]); + // for(int j = 0; j < 9; j++){ + // vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]); - float linearDepthFromSM = depthMapValue.x + bias; - float linearDepthFromViewer = distanceToLight; + // float linearDepthFromSM = depthMapValue.x + bias; + // float linearDepthFromViewer = distanceToLight; - if(linearDepthFromSM > linearDepthFromViewer){ - visibleSamples += 1.0; - } + // if(linearDepthFromSM > linearDepthFromViewer){ + // visibleSamples += 1.0; + // } - numSamples += 1.0; - } + // numSamples += 1.0; + // } - float visibility = visibleSamples / numSamples; + // float visibility = visibleSamples / numSamples; - if(u < 0.0 || u > 1.0 || v < 0.0 || v > 1.0 || nc.x < -1.0 || nc.x > 1.0 || nc.y < -1.0 || nc.y > 1.0 || nc.z < -1.0 || nc.z > 1.0){ - //vColor = vec3(0.0, 0.0, 0.2); - }else{ - //vColor = vec3(1.0, 1.0, 1.0) * visibility + vec3(1.0, 1.0, 1.0) * vec3(0.5, 0.0, 0.0) * (1.0 - visibility); - vColor = vColor * visibility + vColor * uShadowColor * (1.0 - visibility); - } + // if(u < 0.0 || u > 1.0 || v < 0.0 || v > 1.0 || nc.x < -1.0 || nc.x > 1.0 || nc.y < -1.0 || nc.y > 1.0 || nc.z < -1.0 || nc.z > 1.0){ + // //vColor = vec3(0.0, 0.0, 0.2); + // }else{ + // //vColor = vec3(1.0, 1.0, 1.0) * visibility + vec3(1.0, 1.0, 1.0) * vec3(0.5, 0.0, 0.0) * (1.0 - visibility); + // vColor = vColor * visibility + vColor * uShadowColor * (1.0 - visibility); + // } - } + // } - #endif + // #endif } diff --git a/src/navigation/OrbitControls.js b/src/navigation/OrbitControls.js index 246eb4a3..0feaf2f9 100644 --- a/src/navigation/OrbitControls.js +++ b/src/navigation/OrbitControls.js @@ -214,7 +214,7 @@ export class OrbitControls extends EventDispatcher{ this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z; this.scene.view.radius = (1 - t) * startRadius + t * targetRadius; - this.viewer.setMoveSpeed(this.scene.view.radius / 2.5); + this.viewer.setMoveSpeed(this.scene.view.radius); }); tween.onComplete(() => { @@ -276,7 +276,7 @@ export class OrbitControls extends EventDispatcher{ } { - let speed = view.radius / 2.5; + let speed = view.radius; this.viewer.setMoveSpeed(speed); } diff --git a/src/navigation/VRControlls.js b/src/navigation/VRControlls.js deleted file mode 100644 index c4924915..00000000 --- a/src/navigation/VRControlls.js +++ /dev/null @@ -1,607 +0,0 @@ -export class VRControlls{ - - constructor(viewer){ - - this.viewer = viewer; - - this.previousPads = []; - - this.selection = []; - - this.triggerStarts = []; - - this.scaleState = null; - - this.selectionBox = this.createBox(); - this.viewer.scene.scene.add(this.selectionBox); - - this.speed = 1; - this.speedModificationFactor = 50; - - this.snLeft = this.createControllerModel(); - this.snRight = this.createControllerModel(); - - this.viewer.scene.scene.add(this.snLeft.node); - this.viewer.scene.scene.add(this.snRight.node); - //this.viewer.scene.scene.add(this.snLeft.debug); - //this.viewer.scene.scene.add(this.snRight.debug); - - } - - createControllerModel(){ - const geometry = new THREE.SphereGeometry(1, 32, 32); - const material = new THREE.MeshLambertMaterial( { color: 0xff0000, side: THREE.DoubleSide, flatShading: true } ); - const node = new THREE.Mesh(geometry, material); - - node.position.set(0, 0, 0.5); - node.scale.set(0.02, 0.02, 0.02); - node.visible = false; - - viewer.scene.scene.add(node); - - const debug = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial()); - debug.position.set(0, 0, 0.5); - debug.scale.set(0.01, 0.01, 0.01); - debug.visible = false; - - - const controller = { - node: node, - debug: debug, - }; - //viewer.scene.scene.add(node); - - return controller; - } - - createBox(){ - const color = 0xffff00; - - const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] ); - const positions = [ - 1, 1, 1, - 0, 1, 1, - 0, 0, 1, - 1, 0, 1, - 1, 1, 0, - 0, 1, 0, - 0, 0, 0, - 1, 0, 0 - ]; - const geometry = new THREE.BufferGeometry(); - - geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) ); - geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) ); - - geometry.computeBoundingSphere(); - - const mesh = new THREE.LineSegments(geometry, new THREE.LineBasicMaterial( { color: color } ) ); - mesh.visible = false; - - return mesh; - } - - debugLine(start, end, index, color){ - - if(typeof this.debugLines === "undefined"){ - - const geometry = new THREE.SphereGeometry(1, 8, 8); - - this.debugLines = { - geometry: geometry, - }; - } - - const n = 100; - - if(!this.debugLines[index]){ - const geometry = this.debugLines.geometry; - const material = new THREE.MeshBasicMaterial({color: color}); - const nodes = []; - - for(let i = 0; i <= n; i++){ - const u = i / n; - - const node = new THREE.Mesh(geometry, material); - - const position = new THREE.Vector3().addVectors( - start.clone().multiplyScalar(1-u), - end.clone().multiplyScalar(u) - ); - - node.position.copy(position); - node.scale.set(0.002, 0.002, 0.002); - this.viewer.scene.scene.add(node); - nodes.push(node); - } - - const debugLine = { - material: material, - nodes: nodes, - }; - - this.debugLines[index] = debugLine; - }else{ - const debugLine = this.debugLines[index]; - - for(let i = 0; i <= n; i++){ - const node = debugLine.nodes[i]; - const u = i / n; - - const position = new THREE.Vector3().addVectors( - start.clone().multiplyScalar(1-u), - end.clone().multiplyScalar(u) - ); - - node.position.copy(position); - } - } - - - } - - getPointcloudsAt(pointclouds, position){ - - const I = []; - for(const pointcloud of pointclouds){ - - const intersects = pointcloud.intersectsPoint(position); - - if(intersects){ - I.push(pointcloud); - } - } - - return I; - } - - copyPad(pad){ - const axes = pad.axes.map(a => a); - const buttons = pad.buttons.map(b => {return {pressed: b.pressed}}); - - const pose = { - position: new Float32Array(pad.pose.position), - orientation: new Float32Array(pad.pose.orientation), - }; - - const copy = { - axes: axes, - buttons: buttons, - pose: pose, - hand: pad.hand, - index: pad.index, - }; - - return copy; - } - - previousPad(gamepad){ - return this.previousPads.find(c => c.index === gamepad.index); - } - - toScene(position){ - - const vr = viewer.vr; - - vr.node.updateMatrixWorld(); - const world = vr.node.matrixWorld; - - const scenePos = new THREE.Vector3(position.x, -position.z, position.y); - scenePos.applyMatrix4(world); - - return scenePos; - } - - update(delta){ - - const {selection, viewer, snLeft, snRight} = this; - const toScene = this.toScene.bind(this); - const vr = viewer.vr; - - const vrActive = vr && vr.display.isPresenting; - - snLeft.node.visible = vrActive; - snRight.node.visible = vrActive; - - if(!vrActive){ - - return; - } - - const pointclouds = viewer.scene.pointclouds; - - const gamepads = Array.from(navigator.getGamepads()).filter(p => p !== null).map(this.copyPad); - - const getPad = (list, pattern) => list.find(pad => pad.index === pattern.index); - - if(this.previousPads.length !== gamepads.length){ - this.previousPads = gamepads; - } - - const left = gamepads.find(gp => gp.hand && gp.hand === "left"); - const right = gamepads.find(gp => gp.hand && gp.hand === "right"); - - const triggered = gamepads.filter(gamepad => { - return gamepad.buttons[1].pressed; - }); - - const justTriggered = triggered.filter(gamepad => { - const prev = this.previousPad(gamepad); - const previouslyTriggered = prev.buttons[1].pressed; - const currentlyTriggered = gamepad.buttons[1].pressed; - - return !previouslyTriggered && currentlyTriggered; - }); - - const justUntriggered = gamepads.filter(gamepad => { - const prev = this.previousPad(gamepad); - const previouslyTriggered = prev.buttons[1].pressed; - const currentlyTriggered = gamepad.buttons[1].pressed; - - return previouslyTriggered && !currentlyTriggered; - }); - - if(triggered.length === 0){ - - for(const pad of gamepads){ - const position = new THREE.Vector3(...pad.pose.position); - - const I = this.getPointcloudsAt(pointclouds, position); - - let controler = { - "left": snLeft, - "right": snRight, - }[pad.hand]; - - if(I.length > 0){ - controler.node.material.color.setRGB(0, 1, 0); - console.log(pad.hand); - }else{ - controler.node.material.color.setRGB(1, 0, 0); - } - } - }else{ - if(selection.length > 0){ - const pointcloud = selection[0]; - this.selectionBox.scale.copy(pointcloud.boundingBox.max).multiply(pointcloud.scale); - this.selectionBox.position.copy(pointcloud.position); - this.selectionBox.rotation.copy(pointcloud.rotation); - } - } - - if(justTriggered.length > 0){ - - const pad = justTriggered[0]; - const position = toScene(new THREE.Vector3(...pad.pose.position)); - const I = this.getPointcloudsAt(pointclouds, position); - - const pcs = I.map(p => { - return { - node: p, - position: p.position.clone(), - rotation: p.rotation.clone(), - scale: p.scale.clone(), - }; - }); - - const event = { - pad: pad, - pointclouds: pcs, - }; - - this.triggerStarts.push(event); - } - - if(justUntriggered.length > 0){ - for(let untriggeredPad of justUntriggered){ - const p = getPad(this.triggerStarts.map(t => t.pad), untriggeredPad); - this.triggerStarts = this.triggerStarts.filter(e => e.pad !== p); - } - } - - if(triggered.length === 0){ - selection.length = 0; - this.triggerStarts = []; - } - - if(justTriggered.length === 1 && triggered.length === 1){ - // one controller was triggered this frame - const pad = justTriggered[0]; - const position = toScene(new THREE.Vector3(...pad.pose.position)); - const I = this.getPointcloudsAt(pointclouds, position); - - if(I.length > 0){ - selection.length = 0; - selection.push(I[0]); - } - }else if(justTriggered.length === 2 && triggered.length === 2){ - // two controllers were triggered this frame - const pad = justTriggered[0]; - const position = toScene(new THREE.Vector3(...pad.pose.position)); - const I = this.getPointcloudsAt(pointclouds, position); - - if(I.length > 0){ - selection.length = 0; - selection.push(I[0]); - } - } - - if(justTriggered.length > 0 && triggered.length === 2){ - // START SCALE/ROTATE - - const pcs = selection.map(p => ({ - node: p, - position: p.position.clone(), - rotation: p.rotation.clone(), - scale: p.scale.clone(), - })); - - this.scaleState = { - first: triggered[0], - second: triggered[1], - pointclouds: pcs, - }; - }else if(triggered.length < 2){ - // STOP SCALE/ROTATE - this.scaleState = null; - } - - if(this.scaleState){ - // SCALE/ROTATE - - const {first, second, pointclouds} = this.scaleState; - - if(pointclouds.length > 0){ - - const pointcloud = pointclouds[0]; - - const p1Start = toScene(new THREE.Vector3(...first.pose.position)); - const p2Start = toScene(new THREE.Vector3(...second.pose.position)); - - const p1End = toScene(new THREE.Vector3(...getPad(gamepads, first).pose.position)); - const p2End = toScene(new THREE.Vector3(...getPad(gamepads, second).pose.position)); - - const diffStart = new THREE.Vector3().subVectors(p2Start, p1Start); - const diffEnd = new THREE.Vector3().subVectors(p2End, p1End); - - // this.debugLine(p1Start, p2Start, 0, 0xFF0000); - // this.debugLine(p1End, p2End, 1, 0x00FF00); - - // ROTATION - const diffStartG = new THREE.Vector3(diffStart.x, diffStart.y, 0); - const diffEndG = new THREE.Vector3(diffEnd.x, diffEnd.y, 0); - let sign = Math.sign(diffStartG.clone().cross(diffEndG).z); - sign = sign === 0 ? 1 : sign; - const angle = sign * diffStartG.angleTo(diffEndG); - const newAngle = pointcloud.rotation.z + angle; - - // SCALE - const scale = diffEnd.length() / diffStart.length(); - const newScale = pointcloud.scale.clone().multiplyScalar(scale); - - // POSITION - const p1ToP = new THREE.Vector3().subVectors(pointcloud.position, p1Start); - p1ToP.multiplyScalar(scale); - p1ToP.applyAxisAngle(new THREE.Vector3(0, 0, 1), angle); - const newPosition = p1End.clone().add(p1ToP); - - //this.debugLine(pointcloud.position, newPosition, 0, 0xFF0000); - - //console.log(newScale, p1ToP, angle); - - pointcloud.node.rotation.z = newAngle; - pointcloud.node.scale.copy(newScale); - pointcloud.node.position.copy(newPosition); - - pointcloud.node.updateMatrix(); - pointcloud.node.updateMatrixWorld(); - - - - } - - } - - if(triggered.length === 1){ - // TRANSLATE POINT CLOUDS - const pad = triggered[0]; - const prev = this.previousPad(pad); - - const flipWorld = new THREE.Matrix4().fromArray([ - 1, 0, 0, 0, - 0, 0, 1, 0, - 0, -1, 0, 0, - 0, 0, 0, 1 - ]); - const flipView = new THREE.Matrix4().getInverse(flipWorld); - - const p1 = new THREE.Vector3(...pad.pose.position).applyMatrix4(flipWorld); - const p2 = new THREE.Vector3(...prev.pose.position).applyMatrix4(flipWorld); - - p1.applyMatrix4(vr.node.matrixWorld); - p2.applyMatrix4(vr.node.matrixWorld); - - const diff = new THREE.Vector3().subVectors(p1, p2); - - //const diff = toScene(new THREE.Vector3( - // pad.pose.position[0] - prev.pose.position[0], - // pad.pose.position[1] - prev.pose.position[1], - // pad.pose.position[2] - prev.pose.position[2], - //)); - - for(const pc of selection){ - pc.position.add(diff); - } - } - - { // MOVE WITH JOYSTICK - - const flipWorld = new THREE.Matrix4().fromArray([ - 1, 0, 0, 0, - 0, 0, 1, 0, - 0, -1, 0, 0, - 0, 0, 0, 1 - ]); - const flipView = new THREE.Matrix4().getInverse(flipWorld); - const {display, frameData} = vr; - - const computeMove = (pad) => { - const axes = pad.axes; - - const opos = new THREE.Vector3(...pad.pose.position); - const rotation = new THREE.Quaternion(...pad.pose.orientation); - const d = new THREE.Vector3(0, 0, -1); - d.applyQuaternion(rotation); - - const worldPos = toScene(opos); - const worldTarget = toScene(new THREE.Vector3().addVectors(opos, d)); - const dir = new THREE.Vector3().subVectors(worldTarget, worldPos).normalize(); - - const amount = axes[1] * this.speed; - - const move = dir.clone().multiplyScalar(amount); - - return move; - }; - - let flip = 1; - if(display.displayName.includes("Oculus")){ - flip = -1; - } - - let move = null; - - if(left && right){ - move = computeMove(right); - - const leftAdjustAxe = flip * left.axes[1]; - const adjust = this.speedModificationFactor ** leftAdjustAxe; - - move = move.multiplyScalar(adjust); - - - }else if(right){ - move = computeMove(right); - }else if(left){ - move = computeMove(left); - } - - if(move){ - move.multiplyScalar(delta * flip); - - vr.node.position.add(move); - } - - // for(const pad of [left, right].filter(pad => pad)){ - - - - // moves.push(move); - - // // vr.node.position.add(move); - // } - - // if(moves.length === 1){ - // vr.node.position.add(moves[0]); - // }else if(moves.length > 1){ - - // const factor = 10; - // const [adjust, main] = moves; - // // main gives direction, adjust modifies speed between [0, factor] - - // const mMain = main.length(); - - - // let mAdjust = - - - - // const move = mMain.multiplyScalar(adjust); - - - // // const move = moves[0].clone().add(moves[1]); - - // // const amount = (move.length() ** 3) * delta; - // // move.multiplyScalar(amount); - - // // vr.node.position.add(move); - // } - - - // let pad = [right, left].find(pad => pad !== undefined); - - // if(pad){ - - // const axes = pad.axes; - - - // // const leftView = new THREE.Matrix4().fromArray(frameData.leftViewMatrix); - // // const view = new THREE.Matrix4().multiplyMatrices(leftView, flipView); - // // const world = new THREE.Matrix4().getInverse(view); - - // { // move to where the controller points - // const opos = new THREE.Vector3(...right.pose.position); - // const rotation = new THREE.Quaternion(...pad.pose.orientation); - // const d = new THREE.Vector3(0, 0, -1); - // d.applyQuaternion(rotation); - - // const worldPos = toScene(opos); - // const worldTarget = toScene(new THREE.Vector3().addVectors(opos, d)); - // const dir = new THREE.Vector3().subVectors(worldTarget, worldPos).normalize(); - - // const amount = axes[1]; - - // const move = dir.clone().multiplyScalar(delta * amount); - - // //const d = dir.clone().multiplyScalar(delta); - // vr.node.position.add(move); - // } - - // { // move to trigger direction - // // const pos = new THREE.Vector3(0, 0, 0).applyMatrix4(world); - // // const pForward = new THREE.Vector3(0, 0, -1).applyMatrix4(world); - // // const pRight = new THREE.Vector3(1, 0, 0).applyMatrix4(world); - // // const pUp = new THREE.Vector3(0, 1, 0).applyMatrix4(world); - - // // const dForward = new THREE.Vector3().subVectors(pForward, pos).normalize(); - // // const dRight = new THREE.Vector3().subVectors(pRight, pos).normalize(); - // // const dUp = new THREE.Vector3().subVectors(pUp, pos).normalize(); - - // // const dir = new THREE.Vector3().addVectors( - // // dRight.clone().multiplyScalar(axes[0]), - // // dForward.clone().multiplyScalar(axes[1]) - // // ); - - // // const d = dir.clone().multiplyScalar(delta); - // // vr.node.position.add(d); - // } - - // } - - } - - { // MOVE CONTROLLER SCENE NODE - if(right){ - const {node, debug} = snRight; - const opos = new THREE.Vector3(...right.pose.position); - const position = toScene(opos); - - const rotation = new THREE.Quaternion(...right.pose.orientation); - const d = new THREE.Vector3(0, 0, -1); - d.applyQuaternion(rotation); - // const target = toScene(new THREE.Vector3().addVectors(opos, d)); - - node.position.copy(position); - } - - if(left){ - const {node, debug} = snLeft; - - const position = toScene(new THREE.Vector3(...left.pose.position)); - node.position.copy(position); - } - } - - this.previousPads = gamepads; - } -}; \ No newline at end of file diff --git a/src/navigation/VRControls.js b/src/navigation/VRControls.js new file mode 100644 index 00000000..26817bdd --- /dev/null +++ b/src/navigation/VRControls.js @@ -0,0 +1,193 @@ + +import {EventDispatcher} from "../EventDispatcher.js"; + +export class VRControls extends EventDispatcher{ + + constructor(viewer){ + super(viewer); + + this.viewer = viewer; + + this.previousPads = []; + + this.selection = []; + + this.triggerStarts = []; + + this.scaleState = null; + + this.selectionBox = this.createBox(); + this.viewer.scene.scene.add(this.selectionBox); + + this.dbgBox = this.createBox(); + this.viewer.scene.scene.add(this.dbgBox); + + this.speed = 1; + this.speedModificationFactor = 50; + + this.snLeft = this.createControllerModel(); + this.snRight = this.createControllerModel(); + + this.viewer.scene.scene.add(this.snLeft.node); + this.viewer.scene.scene.add(this.snRight.node); + } + + setScene(scene){ + this.scene = scene; + } + + createControllerModel(){ + const geometry = new THREE.SphereGeometry(1, 32, 32); + const material = new THREE.MeshLambertMaterial( { color: 0xff0000, side: THREE.DoubleSide, flatShading: true } ); + const node = new THREE.Mesh(geometry, material); + + node.position.set(0, 0, 0.5); + node.scale.set(0.02, 0.02, 0.02); + node.visible = false; + + this.viewer.scene.scene.add(node); + + const debug = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial()); + debug.position.set(0, 0, 0.5); + debug.scale.set(0.01, 0.01, 0.01); + debug.visible = false; + + + const controller = { + node: node, + debug: debug, + }; + //viewer.scene.scene.add(node); + + return controller; + } + + createBox(){ + const color = 0xffff00; + + const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] ); + const positions = [ + 1, 1, 1, + 0, 1, 1, + 0, 0, 1, + 1, 0, 1, + 1, 1, 0, + 0, 1, 0, + 0, 0, 0, + 1, 0, 0 + ]; + const geometry = new THREE.BufferGeometry(); + + geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) ); + geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) ); + + geometry.computeBoundingSphere(); + + const mesh = new THREE.LineSegments(geometry, new THREE.LineBasicMaterial( { color: color } ) ); + mesh.visible = false; + + return mesh; + } + + debugLine(start, end, index, color){ + + if(typeof this.debugLines === "undefined"){ + + const geometry = new THREE.SphereGeometry(1, 8, 8); + + this.debugLines = { + geometry: geometry, + }; + } + + const n = 100; + + if(!this.debugLines[index]){ + const geometry = this.debugLines.geometry; + const material = new THREE.MeshBasicMaterial({color: color}); + const nodes = []; + + for(let i = 0; i <= n; i++){ + const u = i / n; + + const node = new THREE.Mesh(geometry, material); + + const position = new THREE.Vector3().addVectors( + start.clone().multiplyScalar(1-u), + end.clone().multiplyScalar(u) + ); + + node.position.copy(position); + node.scale.set(0.002, 0.002, 0.002); + this.viewer.scene.scene.add(node); + nodes.push(node); + } + + const debugLine = { + material: material, + nodes: nodes, + }; + + this.debugLines[index] = debugLine; + }else{ + const debugLine = this.debugLines[index]; + + for(let i = 0; i <= n; i++){ + const node = debugLine.nodes[i]; + const u = i / n; + + const position = new THREE.Vector3().addVectors( + start.clone().multiplyScalar(1-u), + end.clone().multiplyScalar(u) + ); + + node.position.copy(position); + } + } + + + } + + getPointcloudsAt(pointclouds, position){ + + const I = []; + for(const pointcloud of pointclouds){ + + const intersects = pointcloud.intersectsPoint(position); + + if(intersects){ + I.push(pointcloud); + } + } + + return I; + } + + + update(delta){ + let {renderer} = this.viewer; + + let cameraVR = renderer.xr.cameraVR; + let view = this.scene.view; + + if(cameraVR == null){ + return; + } + + let vrPos = new THREE.Vector3(); + let vrDir = new THREE.Vector3(); + cameraVR.getWorldPosition(vrPos); + cameraVR.getWorldDirection(vrDir); + + vrDir.normalize().multiplyScalar(this.viewer.getMoveSpeed()); + + let target = vrPos.clone().add(vrDir); + + view.position.copy(vrPos); + view.lookAt(target); + + + + // console.log("update vr controls"); + } +}; \ No newline at end of file diff --git a/src/viewer/potree.css b/src/viewer/potree.css index 90baadf5..8e5b5022 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -131,27 +131,36 @@ color: #8Aa1c4; } +#potree_quick_buttons{ + position: absolute; + left: 4px; + top: 4px; + width: 10px; + height: 10px; + z-index: 10000; + float: left; +} + .potree_menu_toggle{ - position: absolute; float: left; - margin: 8px 8px; + margin: 0; background: none; width: 2.5em; height: 2.5em; z-index: 100; cursor: pointer; + margin: 4px; } #potree_map_toggle{ - position: absolute; float: left; - margin: 8px 8px; + margin: 0; background: none; width: 2.5em; height: 2.5em; z-index: 100; - top: calc(2.5em + 8px); cursor: pointer; + margin: 4px; } #potree_render_area{ diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 4277cbc4..1d15faa7 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -27,8 +27,10 @@ import {OrbitControls} from "../navigation/OrbitControls.js"; import {FirstPersonControls} from "../navigation/FirstPersonControls.js"; import {EarthControls} from "../navigation/EarthControls.js"; import {DeviceOrientationControls} from "../navigation/DeviceOrientationControls.js"; +import {VRControls} from "../navigation/VRControls.js"; import { EventDispatcher } from "../EventDispatcher.js"; import { ClassificationScheme } from "../materials/ClassificationScheme.js"; +import { VRButton } from '../../libs/three.js/extra/VRButton.js'; import JSON5 from "../../libs/json5-2.1.3/json5.mjs"; @@ -77,6 +79,44 @@ export class Viewer extends EventDispatcher{ style="position: absolute; z-index: 100000; width: 100%; height: 100%; pointer-events: none;">`); $(domElement).append(potreeAnnotationContainer); } + + if ($(domElement).find('#potree_quick_buttons').length === 0) { + let potreeMap = $(` +
+
+ `); + + // { + // let imgMenuToggle = document.createElement('img'); + // imgMenuToggle.src = new URL(Potree.resourcePath + '/icons/menu_button.svg').href; + // imgMenuToggle.onclick = this.toggleSidebar; + // // imgMenuToggle.classList.add('potree_menu_toggle'); + + // potreeMap.append(imgMenuToggle); + // } + + // { + // let imgMenuToggle = document.createElement('img'); + // imgMenuToggle.src = new URL(Potree.resourcePath + '/icons/menu_button.svg').href; + // imgMenuToggle.onclick = this.toggleSidebar; + // // imgMenuToggle.classList.add('potree_menu_toggle'); + + // potreeMap.append(imgMenuToggle); + // } + + // { + // let imgMenuToggle = document.createElement('img'); + // imgMenuToggle.src = new URL(Potree.resourcePath + '/icons/menu_button.svg').href; + // imgMenuToggle.onclick = this.toggleSidebar; + // // imgMenuToggle.classList.add('potree_menu_toggle'); + + // potreeMap.append(imgMenuToggle); + // } + + + + $(domElement).append(potreeMap); + } } this.pointCloudLoadedCallback = args.onPointCloudLoaded || function () {}; @@ -124,6 +164,7 @@ export class Viewer extends EventDispatcher{ this.pRenderer = null; this.scene = null; + this.sceneVR = null; this.overlay = null; this.overlayCamera = null; @@ -140,7 +181,6 @@ export class Viewer extends EventDispatcher{ this.background = null; this.initThree(); - this.prepareVR(); if(args.noDragAndDrop){ @@ -189,6 +229,8 @@ export class Viewer extends EventDispatcher{ let scene = new Scene(this.renderer); + this.sceneVR = new THREE.Scene(); + this.setScene(scene); { @@ -381,7 +423,13 @@ export class Viewer extends EventDispatcher{ } getControls () { - return this.controls; + + if(this.renderer.xr.isPresenting){ + return this.vrControls; + }else{ + return this.controls; + } + } getMinNodeSize () { @@ -1083,6 +1131,15 @@ export class Viewer extends EventDispatcher{ this.deviceControls.addEventListener('start', this.disableAnnotations.bind(this)); this.deviceControls.addEventListener('end', this.enableAnnotations.bind(this)); } + + { // create VR CONTROLS + this.vrControls = new VRControls(this); + this.vrControls.enabled = false; + this.vrControls.addEventListener('start', this.disableAnnotations.bind(this)); + this.vrControls.addEventListener('end', this.enableAnnotations.bind(this)); + } + + }; toggleSidebar () { @@ -1148,8 +1205,47 @@ export class Viewer extends EventDispatcher{ imgMapToggle.onclick = e => { this.toggleMap(); }; imgMapToggle.id = 'potree_map_toggle'; - viewer.renderArea.insertBefore(imgMapToggle, viewer.renderArea.children[0]); - viewer.renderArea.insertBefore(imgMenuToggle, viewer.renderArea.children[0]); + + + let elButtons = $("#potree_quick_buttons").get(0); + + elButtons.append(imgMenuToggle); + elButtons.append(imgMapToggle); + + + VRButton.createButton(this.renderer).then(vrButton => { + + if(vrButton == null){ + console.log("VR not supported or active."); + + return; + } + + this.renderer.xr.enabled = true; + + let element = vrButton.element; + + element.style.position = ""; + element.style.bottom = ""; + element.style.left = ""; + element.style.margin = "4px"; + element.style.fontSize = "100%"; + element.style.width = "2.5em"; + element.style.height = "2.5em"; + element.style.padding = "0"; + element.style.textShadow = "black 2px 2px 2px"; + element.style.display = "block"; + + elButtons.append(element); + + vrButton.onStart(() => { + this.dispatchEvent({type: "vr_start"}); + }); + + vrButton.onEnd(() => { + this.dispatchEvent({type: "vr_end"}); + }); + }); this.mapView = new MapView(this); this.mapView.init(); @@ -1354,60 +1450,6 @@ export class Viewer extends EventDispatcher{ } - onVr(callback){ - - if(this.vr){ - callback(); - }else{ - this.onVrListeners.push(callback); - } - - } - - async prepareVR(){ - - if(!navigator.getVRDisplays){ - console.info("browser does not support WebVR"); - - return false; - } - - try{ - let frameData = new VRFrameData(); - let displays = await navigator.getVRDisplays(); - - if(displays.length == 0){ - console.info("no VR display found"); - return false; - } - - let display = displays[displays.length - 1]; - display.depthNear = 0.1; - display.depthFar = 10000.0; - - if(!display.capabilities.canPresent){ - // Not sure why canPresent would ever be false? - console.error("VR display canPresent === false"); - return false; - } - - this.vr = { - frameData: frameData, - display: display, - node: new THREE.Object3D(), - }; - - for(const listener of this.onVrListeners){ - listener(); - } - }catch(err){ - console.error(err); - - return false; - } - - } - updateAnnotations () { if(!this.visibleAnnotations){ @@ -1703,15 +1745,16 @@ export class Viewer extends EventDispatcher{ this.scene.cameraP.fov = this.fov; - if (this.getControls() === this.deviceControls) { + let controls = this.getControls(); + if (controls === this.deviceControls) { this.controls.setScene(scene); this.controls.update(delta); this.scene.cameraP.position.copy(scene.view.position); this.scene.cameraO.position.copy(scene.view.position); - } else if (this.controls !== null) { - this.controls.setScene(scene); - this.controls.update(delta); + } else if (controls !== null) { + controls.setScene(scene); + controls.update(delta); if(typeof debugDisabled === "undefined" ){ this.scene.cameraP.position.copy(scene.view.position); @@ -1851,46 +1894,59 @@ export class Viewer extends EventDispatcher{ renderVR(){ let renderer = this.renderer; - // let pRenderer = this.getPRenderer(); renderer.setClearColor(0x550000, 0); renderer.clear(); let camera = this.scene.getActiveCamera(); - // renderer.render(this.scene.scene, camera); let xr = renderer.xr; + let xrCameras = xr.cameraVR; - // if (!(xr.enabled === true && xr.isPresenting === true)) { - // return; - // } + if(xrCameras.cameras.length !== 2){ + return; + } - let ctmp = camera.clone(); - ctmp.matrixAutoUpdate = false; - ctmp.parent = ctmp; + let copyCam = () => { + let ctmp = camera.clone(); + ctmp.position.set(0, 0, 0); + ctmp.up.set(0, 0, 1); + ctmp.lookAt(new THREE.Vector3(0, -1, 0)); + ctmp.updateMatrix(); + ctmp.updateMatrixWorld(); + ctmp.matrixAutoUpdate = false; + ctmp.parent = ctmp; + return ctmp; + }; + + + let ctmp = copyCam(); { // SKYBOX - let {skybox, scene} = this; + let {skybox} = this; - skybox.camera.rotation.copy(scene.cameraP.rotation); - skybox.camera.fov = scene.cameraP.fov; - skybox.camera.aspect = scene.cameraP.aspect; + skybox.camera.rotation.copy(ctmp.rotation); + skybox.camera.fov = ctmp.fov; + skybox.camera.aspect = ctmp.aspect; skybox.camera.updateProjectionMatrix(); renderer.render(skybox.scene, skybox.camera); } - renderer.render(this.scene.scene, ctmp); + { + let cam = camera.clone(); + cam.up.set(0, 1, 0); + ctmp.updateMatrix(); + ctmp.updateMatrixWorld(); - //let xrCameras = xr.getCamera(ctmp); - let xrCameras = xr.cameraVR; - - - if(xrCameras.cameras.length !== 2){ - return; + renderer.render(this.sceneVR, cam); } + + ctmp = copyCam(); + renderer.render(this.scene.scene, ctmp); + for(let xrCamera of xrCameras.cameras){ @@ -1908,125 +1964,6 @@ export class Viewer extends EventDispatcher{ renderer.bindingStates.reset(); - - // const {display, frameData} = vr; - // let pRenderer = this.getPRenderer(); - - // const leftEye = display.getEyeParameters("left"); - // const rightEye = display.getEyeParameters("right"); - - // let width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2; - // let height = Math.max(leftEye.renderHeight, rightEye.renderHeight); - - // // width *= 0.5; - // // height *= 0.5; - - // this.renderer.setSize(width, height); - - // pRenderer.clear(); - - // //const camera = new THREE.Camera(); - // viewer.scene.cameraMode = CameraMode.VR; - // const camera = viewer.scene.getActiveCamera(); - // { - // camera.near = display.depthNear; - // camera.far = display.depthFar; - // camera.projectionMatrix = new THREE.Matrix4(); - // camera.matrixWorldInverse = new THREE.Matrix4(); - // camera.matrixWorld = new THREE.Matrix4(); - // camera.updateProjectionMatrix = () => {}; - // camera.updateMatrixWorld = () => {}; - // camera.fov = 60; - // }; - - // const flipWorld = new THREE.Matrix4().fromArray([ - // 1, 0, 0, 0, - // 0, 0, 1, 0, - // 0, -1, 0, 0, - // 0, 0, 0, 1 - // ]); - // const flipView = flipWorld.clone().invert(); - - // vr.node.updateMatrixWorld(); - - // {// LEFT - // camera.projectionMatrix.fromArray(frameData.leftProjectionMatrix); - - // const leftView = new THREE.Matrix4().fromArray(frameData.leftViewMatrix); - // const view = new THREE.Matrix4().multiplyMatrices(leftView, flipView); - // const world = view.clone().invert(); - - // { - // const tmp = new THREE.Matrix4().multiplyMatrices(vr.node.matrixWorld, world); - // world.copy(tmp); - // view.copy(world).invert(); - // } - - // camera.matrixWorldInverse.copy(view); - // camera.matrixWorld.copy(world); - - // const viewport = [0, 0, width / 2, height]; - - // this.renderer.setViewport(...viewport); - // pRenderer.render({camera: camera, viewport: viewport}); - // //this.renderer.render(this.overlay, this.overlayCamera); - // } - - // {// RIGHT - - // camera.projectionMatrix.fromArray(frameData.rightProjectionMatrix); - - // const rightView = new THREE.Matrix4().fromArray(frameData.rightViewMatrix); - // const view = new THREE.Matrix4().multiplyMatrices(rightView, flipView); - // const world = view.clone().invert(); - - // { - // const tmp = new THREE.Matrix4().multiplyMatrices(vr.node.matrixWorld, world); - // world.copy(tmp); - // view.copy(world).invert; - // } - - // camera.matrixWorldInverse.copy(view); - // camera.matrixWorld.copy(world); - - // const viewport = [width / 2, 0, width / 2, height]; - - // this.renderer.setViewport(...viewport); - // pRenderer.clearTargets(); - // pRenderer.render({camera: camera, viewport: viewport, debug: 2}); - // //this.renderer.render(this.overlay, this.overlayCamera); - // } - - // { // CENTER - - // { // central view matrix - // // TODO this can't be right...can it? - - // const left = frameData.leftViewMatrix; - // const right = frameData.rightViewMatrix - - // const centerView = new THREE.Matrix4(); - - // for(let i = 0; i < centerView.elements.length; i++){ - // centerView.elements[i] = (left[i] + right[i]) / 2; - // } - - // const view = new THREE.Matrix4().multiplyMatrices(centerView, flipView); - // const world = view.clone().invert(); - - // { - // const tmp = new THREE.Matrix4().multiplyMatrices(vr.node.matrixWorld, world); - // world.copy(tmp); - // view.copy(world).invert; - // } - - // camera.matrixWorldInverse.copy(view); - // camera.matrixWorld.copy(world); - // } - - - // camera.fov = leftEye.fieldOfView.upDegrees; - // } } renderDefault(){ @@ -2186,74 +2123,50 @@ export class Viewer extends EventDispatcher{ } } - async toggleVR(){ - const vrActive = (this.vr && this.vr.display.isPresenting); - - if(vrActive){ - this.stopVR(); - }else{ - this.startVR(); - } - } - - async startVR(){ - - if(this.vr === null){ - return; - } - - let canvas = this.renderer.domElement; - let display = this.vr.display; - - try{ - await display.requestPresent([{ source: canvas }]); - }catch(e){ - console.error(e); - this.postError("requestPresent failed"); - return; - } - - //window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); - //window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); - //window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); - - } - - async stopVR(){ - // TODO shutdown VR - } - loop(timestamp){ if(this.stats){ this.stats.begin(); } - let queryAll; if(Potree.measureTimings){ performance.mark("loop-start"); } - - const vrActive = (this.vr && this.vr.display.isPresenting); - + let vrActive = viewer.renderer.xr.isPresenting; if(vrActive){ - const {display, frameData} = this.vr; - - // display.requestAnimationFrame(this.loop.bind(this)); - - display.getFrameData(frameData); - this.update(this.clock.getDelta(), timestamp); - this.render(); - this.vr.display.submitFrame(); + // let renderer = this.renderer; + // let gl = renderer.getContext(); + // let session = viewer.renderer.xr.getSession(); + // let baseLayer = session.renderState.baseLayer; + + // gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + // // gl.clearColor(1, 0, 1, 1); + // // gl.clear(gl.COLOR_BUFFER_BIT); + + // gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); + // gl.bindFramebuffer(gl.READ_FRAMEBUFFER, baseLayer.framebuffer); + // gl.blitFramebuffer( + // 0, 0, 500, 500, + // 0, 0, 500, 500, + // gl.COLOR_BUFFER_BIT, gl.NEAREST); + + + // gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); + // gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); + // gl.bindFramebuffer(gl.FRAMEBUFFER, baseLayer.framebuffer); + + + + + }else{ - // requestAnimationFrame(this.loop.bind(this)); this.update(this.clock.getDelta(), timestamp); - this.render(); }