@cognite/reveal 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /*!
3
3
  * Copyright 2021 Cognite AS
4
4
  */
5
- function r(e,t){if(t(e))for(let n=0;n<e.children.length;n++)r(e.children[n],t)}function o(e,t){if(void 0===e)return;const{position:n,target:r}=e;return n.applyMatrix4(t),r.applyMatrix4(t),{position:n,target:r}}n.d(t,"t",(function(){return r})),n.d(t,"s",(function(){return o})),n.d(t,"d",(function(){return d})),n.d(t,"l",(function(){return s})),n.d(t,"k",(function(){return l})),n.d(t,"h",(function(){return c})),n.d(t,"m",(function(){return u})),n.d(t,"e",(function(){return g})),n.d(t,"q",(function(){return b})),n.d(t,"c",(function(){return I})),n.d(t,"a",(function(){return P})),n.d(t,"b",(function(){return R})),n.d(t,"o",(function(){return A})),n.d(t,"p",(function(){return D})),n.d(t,"i",(function(){return z})),n.d(t,"j",(function(){return B})),n.d(t,"f",(function(){return L})),n.d(t,"g",(function(){return G})),n.d(t,"n",(function(){return V})),n.d(t,"r",(function(){return O}));var i=n(0);
5
+ function r(e,t){if(t(e))for(let n=0;n<e.children.length;n++)r(e.children[n],t)}function o(e,t){if(void 0===e)return;const{position:n,target:r}=e;return n.applyMatrix4(t),r.applyMatrix4(t),{position:n,target:r}}n.d(t,"t",(function(){return r})),n.d(t,"s",(function(){return o})),n.d(t,"d",(function(){return d})),n.d(t,"l",(function(){return s})),n.d(t,"k",(function(){return l})),n.d(t,"h",(function(){return c})),n.d(t,"m",(function(){return u})),n.d(t,"e",(function(){return x})),n.d(t,"q",(function(){return b})),n.d(t,"c",(function(){return I})),n.d(t,"a",(function(){return N})),n.d(t,"b",(function(){return R})),n.d(t,"o",(function(){return A})),n.d(t,"p",(function(){return D})),n.d(t,"i",(function(){return z})),n.d(t,"j",(function(){return B})),n.d(t,"f",(function(){return L})),n.d(t,"g",(function(){return G})),n.d(t,"n",(function(){return V})),n.d(t,"r",(function(){return O}));var i=n(0);
6
6
  /*!
7
7
  * Copyright 2021 Cognite AS
8
8
  */class a{static color(e){const t=a._colors.get(e);if(void 0!==t)return t;const n=a.generateRandomColor();return a._colors.set(e,n),n}static colorRGB(e){const t=a.color(e);return[Math.floor(255*t.r),Math.floor(255*t.g),Math.floor(255*t.b)]}static colorCSS(e){const[t,n,r]=a.colorRGB(e);return`rgb(${t}, ${n}, ${r})`}static generateRandomColor(){const e=Math.random(),t=.4+.6*Math.random(),n=.3+.4*Math.random();return(new i.Color).setHSL(e,t,n)}}
@@ -21,13 +21,13 @@ function s(e,t){const n=t.getBoundingClientRect();if(e instanceof MouseEvent)ret
21
21
  */function l(e,t){throw new Error(t||"Unexpected object: "+e)}
22
22
  /*!
23
23
  * Copyright 2021 Cognite AS
24
- */class c{constructor(e,t){if(t<0)throw new Error("Range cannot have negative number of elements");this.from=e,this.count=t,this.toInclusive=e+t-1}static createFromInterval(e,t){return new c(e,t-e+1)}*values(){for(let e=this.from;e<=this.toInclusive;++e)yield e}toArray(){return Array.from(this.values())}equal(e){return this.from===e.from&&this.count===e.count}contains(e){return e>=this.from&&e<=this.toInclusive}intersects(e){return this.from<=e.toInclusive&&this.toInclusive>=e.from}intersectsOrCoinciding(e){return this.from<=e.toInclusive+1&&this.toInclusive+1>=e.from}intersectionWith(e){return this.intersects(e)?c.createFromInterval(Math.max(this.from,e.from),Math.min(this.toInclusive,e.toInclusive)):void 0}isInside(e){return this.from>=e.from&&this.toInclusive<=e.toInclusive}union(e){return c.createFromInterval(Math.min(this.from,e.from),Math.max(this.toInclusive,e.toInclusive))}forEach(e){for(let t=this.from;t<=this.toInclusive;++t)e(t)}toString(){return"("+this.from+", "+this.toInclusive+")"}}
24
+ */class c{constructor(e,t){if(t<0)throw new Error("Range cannot have negative number of elements");this.from=e,this.count=t,this.toInclusive=e+t-1}static createFromInterval(e,t){return new c(e,t-e+1)}*values(){for(let e=this.from;e<=this.toInclusive;++e)yield e}toArray(){return Array.from(this.values())}equal(e){return this.from===e.from&&this.count===e.count}contains(e){return e>=this.from&&e<=this.toInclusive}intersects(e){return this.from<=e.toInclusive&&this.toInclusive>=e.from}intersectsOrCoinciding(e){return this.from<=e.toInclusive+1&&this.toInclusive+1>=e.from}intersectionWith(e){return this.intersects(e)?c.createFromInterval(Math.max(this.from,e.from),Math.min(this.toInclusive,e.toInclusive)):void 0}isInside(e){return this.from>=e.from&&this.toInclusive<=e.toInclusive}union(e){return c.createFromInterval(Math.min(this.from,e.from),Math.max(this.toInclusive,e.toInclusive))}forEach(e){for(let t=this.from;t<=this.toInclusive;++t)e(t)}toString(){return"("+this.from+", "+this.toInclusive+")"}static isNumericRange(e){if(!e)return!1;const t=e;return void 0!==t.from&&void 0!==t.count&&void 0!==t.toInclusive}}
25
25
  /*!
26
26
  * Copyright 2021 Cognite AS
27
- */function u(e){const t=Math.max(1,m(Math.sqrt(e)));return{width:t,height:Math.max(1,m(e/t))}}const p=Math.log(2);function m(e){return Math.pow(2,Math.ceil(Math.log(e)/p))}var h=n(7),f=n.n(h);class v{constructor(e,t){this.left=e,this.right=t,this.maxSubtreeDepth=Math.max(this.left.maxSubtreeDepth,this.right.maxSubtreeDepth)+1,this.range=c.createFromInterval(this.left.range.from,this.right.range.toInclusive),this.count=this.left.count+this.right.count}static fromIndexNodesAndBalance(e,t){return e.range.from>t.range.toInclusive+1?new v(t,e).balance():e.range.toInclusive+1<t.range.from?new v(e,t).balance():void f()(!1,"Internal error in IndexSet: Overlapping nodes")}traverse(e){this.left.traverse(e),this.right.traverse(e)}contains(e){return!!this.range.contains(e)&&(this.left.contains(e)||this.right.contains(e))}addRange(e){if(!e.intersectsOrCoinciding(this.range)){if(e.from<this.range.from){const t=this.left.addRange(e);return v.fromIndexNodesAndBalance(t,this.right)}{const t=this.right.addRange(e);return v.fromIndexNodesAndBalance(this.left,t)}}const t=e.intersectsOrCoinciding(this.left.range),n=e.intersectsOrCoinciding(this.right.range);if(t&&n){const[t,n]=this.left.soak(e),[r,o]=this.right.soak(e),i=n.union(o);if(void 0===t&&void 0===r)return new x(i);if(void 0===t&&void 0!==r)return r.addRange(i);if(void 0===r&&void 0!==t)return t.addRange(i);return v.fromIndexNodesAndBalance(t,r).addRange(i)}return t?v.fromIndexNodesAndBalance(this.left.addRange(e),this.right):n?v.fromIndexNodesAndBalance(this.left,this.right.addRange(e)):this.left.maxSubtreeDepth<this.right.maxSubtreeDepth?v.fromIndexNodesAndBalance(this.left.addRange(e),this.right):v.fromIndexNodesAndBalance(this.left,this.right.addRange(e))}removeRange(e){if(!e.intersects(this.range))return this;const[t,n]=this.soak(e);let r=void 0,o=void 0;if(n.from<e.from&&(r=c.createFromInterval(n.from,e.from-1)),n.toInclusive>e.toInclusive&&(o=c.createFromInterval(e.toInclusive+1,n.toInclusive)),void 0===t)return void 0!==r&&void 0!==o?v.fromIndexNodesAndBalance(new x(r),new x(o)):null!=r?new x(r):null!=o?new x(o):void 0;{let e=t;return void 0!==r&&(e=e.addRange(r)),void 0!==o&&(e=e.addRange(o)),e}}balance(){const e=this.left.maxSubtreeDepth,t=this.right.maxSubtreeDepth;if(t+2<=e){const e=this.left.rotateSmallerRight();return new v(e,this.right).rotateRight().balance()}if(e+2<=t){const e=this.right.rotateSmallerLeft();return new v(this.left,e).rotateLeft().balance()}return this}clone(){return v.fromIndexNodesAndBalance(this.left.clone(),this.right.clone())}hasIntersectionWith(e){return!!e.range.intersects(this.range)&&(this.range.isInside(e.range)?e.hasIntersectionWith(this):!(!this.left.range.intersects(e.range)||!this.left.hasIntersectionWith(e))||!(!this.right.range.intersects(e.range)||!this.right.hasIntersectionWith(e)))}soak(e){let[t,n]=[this.left,e],[r,o]=[this.right,e];if(this.right.range.isInside(e)&&this.left.range.isInside(e))return[void 0,e];this.left.range.intersectsOrCoinciding(e)&&([t,n]=this.left.soak(e)),this.right.range.intersectsOrCoinciding(e)&&([r,o]=this.right.soak(e));const i=n.union(o);if(null==r)return[t,i];if(null==t)return[r,i];return[v.fromIndexNodesAndBalance(t,r),i]}rotateRight(){return"right"in this.left?new v(this.left.left,new v(this.left.right,this.right)):this}rotateLeft(){return"left"in this.right?new v(new v(this.left,this.right.left),this.right.right):this}rotateSmallerLeft(){if(this.left.maxSubtreeDepth>this.right.maxSubtreeDepth){let e=this.rotateRight();return e=e.rotateSmallerLeft(),e}return this}rotateSmallerRight(){if(this.right.maxSubtreeDepth>this.left.maxSubtreeDepth){let e=this.rotateLeft();return e=e.rotateSmallerRight(),e}return this}}
27
+ */function u(e){const t=Math.max(1,m(Math.sqrt(e)));return{width:t,height:Math.max(1,m(e/t))}}const p=Math.log(2);function m(e){return Math.pow(2,Math.ceil(Math.log(e)/p))}var h=n(7),f=n.n(h);class v{constructor(e,t){this.left=e,this.right=t,this.maxSubtreeDepth=Math.max(this.left.maxSubtreeDepth,this.right.maxSubtreeDepth)+1,this.range=c.createFromInterval(this.left.range.from,this.right.range.toInclusive),this.count=this.left.count+this.right.count}static fromIndexNodesAndBalance(e,t){return e.range.from>t.range.toInclusive+1?new v(t,e).balance():e.range.toInclusive+1<t.range.from?new v(e,t).balance():void f()(!1,"Internal error in IndexSet: Overlapping nodes")}traverse(e){this.left.traverse(e),this.right.traverse(e)}contains(e){return!!this.range.contains(e)&&(this.left.contains(e)||this.right.contains(e))}addRange(e){if(!e.intersectsOrCoinciding(this.range)){if(e.from<this.range.from){const t=this.left.addRange(e);return v.fromIndexNodesAndBalance(t,this.right)}{const t=this.right.addRange(e);return v.fromIndexNodesAndBalance(this.left,t)}}const t=e.intersectsOrCoinciding(this.left.range),n=e.intersectsOrCoinciding(this.right.range);if(t&&n){const[t,n]=this.left.soak(e),[r,o]=this.right.soak(e),i=n.union(o);if(void 0===t&&void 0===r)return new g(i);if(void 0===t&&void 0!==r)return r.addRange(i);if(void 0===r&&void 0!==t)return t.addRange(i);return v.fromIndexNodesAndBalance(t,r).addRange(i)}return t?v.fromIndexNodesAndBalance(this.left.addRange(e),this.right):n?v.fromIndexNodesAndBalance(this.left,this.right.addRange(e)):this.left.maxSubtreeDepth<this.right.maxSubtreeDepth?v.fromIndexNodesAndBalance(this.left.addRange(e),this.right):v.fromIndexNodesAndBalance(this.left,this.right.addRange(e))}removeRange(e){if(!e.intersects(this.range))return this;const[t,n]=this.soak(e);let r=void 0,o=void 0;if(n.from<e.from&&(r=c.createFromInterval(n.from,e.from-1)),n.toInclusive>e.toInclusive&&(o=c.createFromInterval(e.toInclusive+1,n.toInclusive)),void 0===t)return void 0!==r&&void 0!==o?v.fromIndexNodesAndBalance(new g(r),new g(o)):null!=r?new g(r):null!=o?new g(o):void 0;{let e=t;return void 0!==r&&(e=e.addRange(r)),void 0!==o&&(e=e.addRange(o)),e}}balance(){const e=this.left.maxSubtreeDepth,t=this.right.maxSubtreeDepth;if(t+2<=e){const e=this.left.rotateSmallerRight();return new v(e,this.right).rotateRight().balance()}if(e+2<=t){const e=this.right.rotateSmallerLeft();return new v(this.left,e).rotateLeft().balance()}return this}clone(){return v.fromIndexNodesAndBalance(this.left.clone(),this.right.clone())}hasIntersectionWith(e){return!!e.range.intersects(this.range)&&(this.range.isInside(e.range)?e.hasIntersectionWith(this):!(!this.left.range.intersects(e.range)||!this.left.hasIntersectionWith(e))||!(!this.right.range.intersects(e.range)||!this.right.hasIntersectionWith(e)))}soak(e){let[t,n]=[this.left,e],[r,o]=[this.right,e];if(this.right.range.isInside(e)&&this.left.range.isInside(e))return[void 0,e];this.left.range.intersectsOrCoinciding(e)&&([t,n]=this.left.soak(e)),this.right.range.intersectsOrCoinciding(e)&&([r,o]=this.right.soak(e));const i=n.union(o);if(null==r)return[t,i];if(null==t)return[r,i];return[v.fromIndexNodesAndBalance(t,r),i]}rotateRight(){return"right"in this.left?new v(this.left.left,new v(this.left.right,this.right)):this}rotateLeft(){return"left"in this.right?new v(new v(this.left,this.right.left),this.right.right):this}rotateSmallerLeft(){if(this.left.maxSubtreeDepth>this.right.maxSubtreeDepth){let e=this.rotateRight();return e=e.rotateSmallerLeft(),e}return this}rotateSmallerRight(){if(this.right.maxSubtreeDepth>this.left.maxSubtreeDepth){let e=this.rotateLeft();return e=e.rotateSmallerRight(),e}return this}}
28
28
  /*!
29
29
  * Copyright 2021 Cognite AS../NumericRange
30
- */class x{constructor(e){this.range=e,this.maxSubtreeDepth=0,this.count=e.count}static fromInterval(e,t){return new x(c.createFromInterval(e,t))}traverse(e){e(this.range)}contains(e){return this.range.contains(e)}addRange(e){return this.range.intersectsOrCoinciding(e)?new x(this.range.union(e)):v.fromIndexNodesAndBalance(this,new x(e))}removeRange(e){if(!e.intersects(this.range))return this;if(this.range.isInside(e))return;let t=void 0,n=void 0;return this.range.from<e.from&&(t=c.createFromInterval(this.range.from,e.from-1)),this.range.toInclusive>e.toInclusive&&(n=c.createFromInterval(e.toInclusive+1,this.range.toInclusive)),null!=t&&null!=n?v.fromIndexNodesAndBalance(new x(t),new x(n)):null!=t?new x(t):null!=n?new x(n):void 0}hasIntersectionWith(e){return e.range.intersects(this.range)}soak(e){return this.range.intersectsOrCoinciding(e)?[void 0,this.range.union(e)]:[this,e]}clone(){return new x(this.range)}}class g{constructor(e){if(null==e)this.rootNode=void 0;else if(e instanceof c)this.addRange(e);else for(const t of e)this.add(t)}forEachRange(e){this.rootNode&&this.rootNode.traverse(e)}add(e){const t=new c(e,1);this.addRange(t)}addRange(e){this.rootNode?this.rootNode=this.rootNode.addRange(e):this.rootNode=new x(e)}remove(e){const t=new c(e,1);this.removeRange(t)}removeRange(e){this.rootNode&&(this.rootNode=this.rootNode.removeRange(e))}contains(e){return!!this.rootNode&&this.rootNode.contains(e)}get count(){return this.rootNode?this.rootNode.count:0}toRangeArray(){const e=[];return this.forEachRange(t=>{e.push(t)}),e}toIndexArray(){const e=[];return this.rootNode&&this.forEachRange(t=>{t.forEach(t=>{e.push(t)})}),e}toPlainSet(){const e=this.toIndexArray();return new Set(e)}invertedRanges(){const e=this.toRangeArray(),t=[];for(let n=0;n<e.length-1;n++)e[n].toInclusive+1>=e[n+1].from||t.push(c.createFromInterval(e[n].toInclusive+1,e[n+1].from-1));return t}unionWith(e){return this.rootNode?e.forEachRange(e=>{this.rootNode=this.rootNode.addRange(e)}):this.rootNode=e.rootNode,this}differenceWith(e){return this.rootNode&&e.forEachRange(e=>{var t;this.rootNode=null===(t=this.rootNode)||void 0===t?void 0:t.removeRange(e)}),this}hasIntersectionWith(e){if(e instanceof g)return void 0!==this.rootNode&&void 0!==e.rootNode&&this.rootNode.hasIntersectionWith(e.rootNode);for(const t of e)if(this.contains(t))return!0;return!1}intersectWith(e){if(this.rootNode&&e.rootNode){if(this.rootNode.range.from<e.rootNode.range.from){const t=c.createFromInterval(this.rootNode.range.from,e.rootNode.range.from-1);if(this.rootNode=this.rootNode.removeRange(t),!this.rootNode)return this}if(this.rootNode.range.toInclusive>e.rootNode.range.toInclusive){const t=c.createFromInterval(e.rootNode.range.toInclusive+1,this.rootNode.range.toInclusive);this.rootNode=this.rootNode.removeRange(t)}e.invertedRanges().forEach(e=>{this.rootNode&&(this.rootNode=this.rootNode.removeRange(e))})}else this.rootNode&&(this.rootNode=void 0);return this}clear(){this.rootNode=void 0}clone(){const e=new g;return this.rootNode&&(e.rootNode=this.rootNode.clone()),e}}
30
+ */class g{constructor(e){this.range=e,this.maxSubtreeDepth=0,this.count=e.count}static fromInterval(e,t){return new g(c.createFromInterval(e,t))}traverse(e){e(this.range)}contains(e){return this.range.contains(e)}addRange(e){return this.range.intersectsOrCoinciding(e)?new g(this.range.union(e)):v.fromIndexNodesAndBalance(this,new g(e))}removeRange(e){if(!e.intersects(this.range))return this;if(this.range.isInside(e))return;let t=void 0,n=void 0;return this.range.from<e.from&&(t=c.createFromInterval(this.range.from,e.from-1)),this.range.toInclusive>e.toInclusive&&(n=c.createFromInterval(e.toInclusive+1,this.range.toInclusive)),null!=t&&null!=n?v.fromIndexNodesAndBalance(new g(t),new g(n)):null!=t?new g(t):null!=n?new g(n):void 0}hasIntersectionWith(e){return e.range.intersects(this.range)}soak(e){return this.range.intersectsOrCoinciding(e)?[void 0,this.range.union(e)]:[this,e]}clone(){return new g(this.range)}}class x{constructor(e){if(null==e)this.rootNode=void 0;else if(c.isNumericRange(e))this.addRange(e);else for(const t of e)this.add(t)}forEachRange(e){this.rootNode&&this.rootNode.traverse(e)}add(e){const t=new c(e,1);this.addRange(t)}addRange(e){this.rootNode?this.rootNode=this.rootNode.addRange(e):this.rootNode=new g(e)}remove(e){const t=new c(e,1);this.removeRange(t)}removeRange(e){this.rootNode&&(this.rootNode=this.rootNode.removeRange(e))}contains(e){return!!this.rootNode&&this.rootNode.contains(e)}get count(){return this.rootNode?this.rootNode.count:0}toRangeArray(){const e=[];return this.forEachRange(t=>{e.push(t)}),e}toIndexArray(){const e=[];return this.rootNode&&this.forEachRange(t=>{t.forEach(t=>{e.push(t)})}),e}toPlainSet(){const e=this.toIndexArray();return new Set(e)}invertedRanges(){const e=this.toRangeArray(),t=[];for(let n=0;n<e.length-1;n++)e[n].toInclusive+1>=e[n+1].from||t.push(c.createFromInterval(e[n].toInclusive+1,e[n+1].from-1));return t}unionWith(e){return this.rootNode?e.forEachRange(e=>{this.rootNode=this.rootNode.addRange(e)}):this.rootNode=e.rootNode,this}differenceWith(e){return this.rootNode&&e.forEachRange(e=>{var t;this.rootNode=null===(t=this.rootNode)||void 0===t?void 0:t.removeRange(e)}),this}hasIntersectionWith(e){if(e instanceof x)return void 0!==this.rootNode&&void 0!==e.rootNode&&this.rootNode.hasIntersectionWith(e.rootNode);for(const t of e)if(this.contains(t))return!0;return!1}intersectWith(e){if(this.rootNode&&e.rootNode){if(this.rootNode.range.from<e.rootNode.range.from){const t=c.createFromInterval(this.rootNode.range.from,e.rootNode.range.from-1);if(this.rootNode=this.rootNode.removeRange(t),!this.rootNode)return this}if(this.rootNode.range.toInclusive>e.rootNode.range.toInclusive){const t=c.createFromInterval(e.rootNode.range.toInclusive+1,this.rootNode.range.toInclusive);this.rootNode=this.rootNode.removeRange(t)}e.invertedRanges().forEach(e=>{this.rootNode&&(this.rootNode=this.rootNode.removeRange(e))})}else this.rootNode&&(this.rootNode=void 0);return this}clear(){this.rootNode=void 0}clone(){const e=new x;return this.rootNode&&(e.rootNode=this.rootNode.clone()),e}}
31
31
  /*!
32
32
  * Copyright 2021 Cognite AS
33
33
  */function b(e,t,n){const r=M(e);if(0==r)return;const o=y(0,-e);let i=w(C(r));const a=r/_(i);a<1&&(i-=1),i+=127,t[n]=128*o+w(i*_(-1)),t[n+1]=128*T(i,2)+T(w(128*a),128),t[n+2]=w(T(w(a*_(15)),_(8))),t[n+3]=w(_(23)*T(a,_(-15)))}function y(e,t){return t<e?0:1}function _(e){return Math.pow(2,e)}function T(e,t){return e-t*w(e/t)}function w(e){return Math.floor(e)}function C(e){return Math.log(e)/Math.log(2)}function M(e){return Math.abs(e)}
@@ -36,10 +36,10 @@ function s(e,t){const n=t.getBoundingClientRect();if(e instanceof MouseEvent)ret
36
36
  */class I{constructor(e,t){this._numFilled=0,this._batchIdCounter=0,this._batchMap=new Map,this._type=t;const n=Math.pow(2,Math.ceil(Math.log2(e)));this._buffer=new t(n)}get length(){return this._numFilled}get buffer(){return this._buffer}add(e){let t=!1;if(this._numFilled+e.length>this._buffer.length){const n=Math.pow(2,Math.ceil(Math.log2(this._numFilled+e.length)));this.allocateNewBuffer(n),t=!0}this._buffer.set(e,this._numFilled);const n=this.createBatch(e);return this._numFilled+=e.length,{batchId:n,bufferIsReallocated:t}}remove(e){const t=this._batchMap.get(e);if(!t)throw new Error("batch does not exist in buffer");this._buffer.copyWithin(t.from,t.from+t.count,this.buffer.length),this._numFilled-=t.count,this._currentTail===t&&(this._currentTail=t.prev);const n=t.prev,r=t.next;n&&(n.next=r),r&&(r.prev=n);let o=r;for(;o;)o.from-=t.count,o=o.next;this._batchMap.delete(e)}createBatch(e){const t={from:this._numFilled,count:e.length,prev:this._currentTail,next:void 0};this._currentTail&&(this._currentTail.next=t),this._currentTail=t;const n=this._batchIdCounter;return this._batchIdCounter++,this._batchMap.set(n,t),n}allocateNewBuffer(e){const t=new this._type(e);t.set(this._buffer),this._buffer=t}}
37
37
  /*!
38
38
  * Copyright 2021 Cognite AS
39
- */const S=new i.BufferGeometry;class P extends i.Group{constructor(){super(...arguments),this._isDisposed=!1,this._referenceCount=0}reference(){this.ensureNotDisposed(),this._referenceCount++}dereference(){if(this.ensureNotDisposed(),0===this._referenceCount)throw new Error("No references");0==--this._referenceCount&&this.dispose()}dispose(){this.ensureNotDisposed(),this._isDisposed=!0;const e=this.children.filter(e=>e instanceof i.Mesh).map(e=>e);for(const t of e)void 0!==t.geometry&&(t.geometry.dispose(),t.geometry=S)}ensureNotDisposed(){if(this._isDisposed)throw new Error("Already disposed/dereferenced")}}
39
+ */const S=new i.BufferGeometry;class N extends i.Group{constructor(){super(...arguments),this._isDisposed=!1,this._referenceCount=0}reference(){this.ensureNotDisposed(),this._referenceCount++}dereference(){if(this.ensureNotDisposed(),0===this._referenceCount)throw new Error("No references");0==--this._referenceCount&&this.dispose()}dispose(){this.ensureNotDisposed(),this._isDisposed=!0;const e=this.children.filter(e=>e instanceof i.Mesh).map(e=>e);for(const t of e)void 0!==t.geometry&&(t.geometry.dispose(),t.geometry=S)}ensureNotDisposed(){if(this._isDisposed)throw new Error("Already disposed/dereferenced")}}
40
40
  /*!
41
41
  * Copyright 2021 Cognite AS
42
- */const N={camPos:new i.Vector3,bounds:new i.Box3};class R extends i.Object3D{constructor(e){super(),this._activeLevel=0,this._levels=[],this.isLOD=!0,this.autoUpdate=!0,this._boundingBox=e.clone(),this.type="BoundingBoxLOD"}setBoundingBox(e){this._boundingBox.copy(e)}addLevel(e,t=0){this._levels.push({object:e,distance:Math.abs(t)}),this._levels.sort((e,t)=>t.distance-e.distance),e.visible=!1,this.add(e)}getCurrentLevel(){return this._levels.length>0?this._levels.length-this._activeLevel-1:0}update(e){this.updateCurrentLevel(e)}updateCurrentLevel(e){const t=this._levels,{camPos:n,bounds:r}=N;r.copy(this._boundingBox).applyMatrix4(this.matrixWorld);const o=e instanceof i.PerspectiveCamera?e.zoom:1;if(t.length>0){n.setFromMatrixPosition(e.matrixWorld);const i=r.distanceToPoint(n)/o;t[this._activeLevel].object.visible=!1,this._activeLevel=t.findIndex(e=>i>=e.distance),this._activeLevel=this._activeLevel>=0?this._activeLevel:t.length-1,t[this._activeLevel].object.visible=!0}}}
42
+ */const P={camPos:new i.Vector3,bounds:new i.Box3};class R extends i.Object3D{constructor(e){super(),this._activeLevel=0,this._levels=[],this.isLOD=!0,this.autoUpdate=!0,this._boundingBox=e.clone(),this.type="BoundingBoxLOD"}setBoundingBox(e){this._boundingBox.copy(e)}addLevel(e,t=0){this._levels.push({object:e,distance:Math.abs(t)}),this._levels.sort((e,t)=>t.distance-e.distance),e.visible=!1,this.add(e)}getCurrentLevel(){return this._levels.length>0?this._levels.length-this._activeLevel-1:0}update(e){this.updateCurrentLevel(e)}updateCurrentLevel(e){const t=this._levels,{camPos:n,bounds:r}=P;r.copy(this._boundingBox).applyMatrix4(this.matrixWorld);const o=e instanceof i.PerspectiveCamera?e.zoom:1;if(t.length>0){n.setFromMatrixPosition(e.matrixWorld);const i=r.distanceToPoint(n)/o;t[this._activeLevel].object.visible=!1,this._activeLevel=t.findIndex(e=>i>=e.distance),this._activeLevel=this._activeLevel>=0?this._activeLevel:t.length-1,t[this._activeLevel].object.visible=!0}}}
43
43
  /*!
44
44
  * Copyright 2021 Cognite AS
45
45
  */function A(e){return[new i.Vector3(e.min.x,e.min.y,e.min.z),new i.Vector3(e.min.x,e.min.y,e.max.z),new i.Vector3(e.min.x,e.max.y,e.min.z),new i.Vector3(e.min.x,e.max.y,e.max.z),new i.Vector3(e.max.x,e.min.y,e.min.z),new i.Vector3(e.max.x,e.min.y,e.max.z),new i.Vector3(e.max.x,e.max.y,e.min.z),new i.Vector3(e.max.x,e.max.y,e.max.z)]}
@@ -69,7 +69,7 @@ function s(e,t){const n=t.getBoundingClientRect();if(e instanceof MouseEvent)ret
69
69
  */function V(){this.array=null}
70
70
  /*!
71
71
  * Copyright 2021 Cognite AS
72
- */},function(e,t,n){"use strict";n.d(t,"a",(function(){return l})),n.d(t,"b",(function(){return u})),n.d(t,"g",(function(){return f})),n.d(t,"f",(function(){return v})),n.d(t,"e",(function(){return x})),n.d(t,"c",(function(){return g})),n.d(t,"d",(function(){return p})),n.d(t,"n",(function(){return C})),n.d(t,"o",(function(){return M})),n.d(t,"p",(function(){return S})),n.d(t,"q",(function(){return I})),n.d(t,"m",(function(){return N})),n.d(t,"i",(function(){return R})),n.d(t,"t",(function(){return D})),n.d(t,"k",(function(){return F})),n.d(t,"x",(function(){return E})),n.d(t,"r",(function(){return G})),n.d(t,"w",(function(){return k})),n.d(t,"j",(function(){return A})),n.d(t,"u",(function(){return z})),n.d(t,"v",(function(){return L})),n.d(t,"s",(function(){return V})),n.d(t,"h",(function(){return c})),n.d(t,"l",(function(){return U}));var r=n(0),o=n(1),i=n(24),a=n.n(i);
72
+ */},function(e,t,n){"use strict";n.d(t,"a",(function(){return l})),n.d(t,"b",(function(){return u})),n.d(t,"g",(function(){return f})),n.d(t,"f",(function(){return v})),n.d(t,"e",(function(){return g})),n.d(t,"c",(function(){return x})),n.d(t,"d",(function(){return p})),n.d(t,"n",(function(){return C})),n.d(t,"o",(function(){return M})),n.d(t,"p",(function(){return S})),n.d(t,"q",(function(){return I})),n.d(t,"m",(function(){return P})),n.d(t,"i",(function(){return R})),n.d(t,"t",(function(){return D})),n.d(t,"k",(function(){return F})),n.d(t,"x",(function(){return E})),n.d(t,"r",(function(){return G})),n.d(t,"w",(function(){return k})),n.d(t,"j",(function(){return A})),n.d(t,"u",(function(){return z})),n.d(t,"v",(function(){return L})),n.d(t,"s",(function(){return V})),n.d(t,"h",(function(){return c})),n.d(t,"l",(function(){return U}));var r=n(0),o=n(1),i=n(24),a=n.n(i);
73
73
  /*!
74
74
  * Copyright 2021 Cognite AS
75
75
  */
@@ -99,10 +99,10 @@ class f{createSectorScene(e,t,n,r){h()(8===e,"Only version 8 is currently suppor
99
99
  class v extends r.Group{constructor(e,t,n){super(),this._lod=p.Discarded,this._updatedTimestamp=Date.now(),this.name=`Sector ${t} [id=${e}]`,this.sectorId=e,this.sectorPath=t,this.bounds=n,this.depth=function(e){let t=0;for(let n=0;n<e.length;++n)t+="/"===e[n]?1:0;return t-1}
100
100
  /*!
101
101
  * Copyright 2021 Cognite AS
102
- */(t)}get levelOfDetail(){return this._lod}get group(){return this._group}get updatedTimestamp(){return this._updatedTimestamp}updateGeometry(e,t){this.resetGeometry(),this._group=e,void 0!==this._group&&this._group.reference(),this._lod=t,this._updatedTimestamp=Date.now(),this.visible=this._lod!==p.Discarded,this.updateMatrixWorld(!0)}resetGeometry(){void 0!==this._group&&(this._group.dereference(),this.remove(this._group)),this._group=void 0,this._lod=p.Discarded,this._updatedTimestamp=Date.now()}}class x extends v{constructor(e){const t=e.scene.root.bounds.clone();t.applyMatrix4(e.modelMatrix),super(0,"/",t);const{scene:n,modelMatrix:r}=e;this.sectorNodeMap=new Map,function e(t,n,r,o){const i=t.bounds.clone();i.applyMatrix4(o);const a=new v(t.id,t.path,i);a.name="Sector "+t.id,n.add(a),a.matrixAutoUpdate=!1,a.updateMatrixWorld(!0),r.set(t.id,a);for(const n of t.children)e(n,a,r,o)}
102
+ */(t)}get levelOfDetail(){return this._lod}get group(){return this._group}get updatedTimestamp(){return this._updatedTimestamp}updateGeometry(e,t){this.resetGeometry(),this._group=e,void 0!==this._group&&this._group.reference(),this._lod=t,this._updatedTimestamp=Date.now(),this.visible=this._lod!==p.Discarded,this.updateMatrixWorld(!0)}resetGeometry(){void 0!==this._group&&(this._group.dereference(),this.remove(this._group)),this._group=void 0,this._lod=p.Discarded,this._updatedTimestamp=Date.now()}}class g extends v{constructor(e){const t=e.scene.root.bounds.clone();t.applyMatrix4(e.modelMatrix),super(0,"/",t);const{scene:n,modelMatrix:r}=e;this.sectorNodeMap=new Map,function e(t,n,r,o){const i=t.bounds.clone();i.applyMatrix4(o);const a=new v(t.id,t.path,i);a.name="Sector "+t.id,n.add(a),a.matrixAutoUpdate=!1,a.updateMatrixWorld(!0),r.set(t.id,a);for(const n of t.children)e(n,a,r,o)}
103
103
  /*!
104
104
  * Copyright 2021 Cognite AS
105
- */(n.root,this,this.sectorNodeMap,r),this.matrixAutoUpdate=!1,this.setModelTransformation(r)}setModelTransformation(e){this.matrix.copy(e),this.updateMatrixWorld(!0)}getModelTransformation(e=new r.Matrix4){return e.copy(this.matrix)}}class g{constructor(e=o.j.defaultPool){this.workerPool=e}parseI3D(e){return this.parseDetailed(e)}parseF3D(e){return this.parseSimple(e)}parseCTM(e){return this.parseCtm(e)}async parseSimple(e){return this.workerPool.postWorkToAvailable(async t=>t.parseQuads(e))}async parseDetailed(e){return this.workerPool.postWorkToAvailable(async t=>t.parseSector(e))}async parseCtm(e){return this.workerPool.postWorkToAvailable(async t=>t.parseCtm(e))}}
105
+ */(n.root,this,this.sectorNodeMap,r),this.matrixAutoUpdate=!1,this.setModelTransformation(r)}setModelTransformation(e){this.matrix.copy(e),this.updateMatrixWorld(!0)}getModelTransformation(e=new r.Matrix4){return e.copy(this.matrix)}}class x{constructor(e=o.j.defaultPool){this.workerPool=e}parseI3D(e){return this.parseDetailed(e)}parseF3D(e){return this.parseSimple(e)}parseCTM(e){return this.parseCtm(e)}async parseSimple(e){return this.workerPool.postWorkToAvailable(async t=>t.parseQuads(e))}async parseDetailed(e){return this.workerPool.postWorkToAvailable(async t=>t.parseSector(e))}async parseCtm(e){return this.workerPool.postWorkToAvailable(async t=>t.parseCtm(e))}}
106
106
  /*!
107
107
  * Copyright 2021 Cognite AS
108
108
  */const b={centerA:new r.Vector3,centerB:new r.Vector3,sphere:new r.Sphere,box:new r.Box3};const y={vertex1:new r.Vector3,vertex2:new r.Vector3,vertex3:new r.Vector3,vertex4:new r.Vector3};const _={instanceMatrix:new r.Matrix4};const T={center:new r.Vector3,size:new r.Vector3};
@@ -113,7 +113,7 @@ function w(e,t,n,o){const i=Array.from(t.values()).reduce((e,t)=>Math.max(e,t.of
113
113
  /*!
114
114
  * Copyright 2021 Cognite AS
115
115
  */
116
- const P={p:new r.Vector3,instanceMatrix:new r.Matrix4,baseBounds:new r.Box3,instanceBounds:new r.Box3};function N(e,t,n,r){if(null===r)return n;const{p:o,instanceMatrix:i,baseBounds:a,instanceBounds:s}=P;a.makeEmpty();for(let r=n.triangleOffset;r<n.triangleOffset+n.triangleCount;++r){const n=t[3*r+0],i=t[3*r+1],s=t[3*r+2];o.set(e[n+0],e[n+1],e[n+2]),a.expandByPoint(o),o.set(e[i+0],e[i+1],e[i+2]),a.expandByPoint(o),o.set(e[s+0],e[s+1],e[s+2]),a.expandByPoint(o)}let d=0;const l=n.treeIndices.length,c=new Float32Array(n.instanceMatrices.length),u=new Float32Array(l),p=new Uint8Array(4*l);for(let e=0;e<l;++e)if(m=n.instanceMatrices,h=e,i.set(m[h+0],m[h+4],m[h+8],m[h+12],m[h+1],m[h+5],m[h+9],m[h+13],m[h+2],m[h+6],m[h+10],m[h+14],m[h+3],m[h+7],m[h+11],m[h+15]),s.copy(a).applyMatrix4(i),r.intersectsBox(s)){const t=n.instanceMatrices.subarray(16*e,16*(e+1)),r=n.colors.subarray(4*e,4*(e+1)),o=n.treeIndices[e];c.set(t,16*d),p.set(r,4*d),u[d]=o,d++}var m,h;if(l===d)return n;return{triangleCount:n.triangleCount,triangleOffset:n.triangleOffset,instanceMatrices:c.slice(0,16*d),colors:p.slice(0,4*d),treeIndices:u.slice(0,d)}}
116
+ const N={p:new r.Vector3,instanceMatrix:new r.Matrix4,baseBounds:new r.Box3,instanceBounds:new r.Box3};function P(e,t,n,r){if(null===r)return n;const{p:o,instanceMatrix:i,baseBounds:a,instanceBounds:s}=N;a.makeEmpty();for(let r=n.triangleOffset;r<n.triangleOffset+n.triangleCount;++r){const n=t[3*r+0],i=t[3*r+1],s=t[3*r+2];o.set(e[n+0],e[n+1],e[n+2]),a.expandByPoint(o),o.set(e[i+0],e[i+1],e[i+2]),a.expandByPoint(o),o.set(e[s+0],e[s+1],e[s+2]),a.expandByPoint(o)}let d=0;const l=n.treeIndices.length,c=new Float32Array(n.instanceMatrices.length),u=new Float32Array(l),p=new Uint8Array(4*l);for(let e=0;e<l;++e)if(m=n.instanceMatrices,h=e,i.set(m[h+0],m[h+4],m[h+8],m[h+12],m[h+1],m[h+5],m[h+9],m[h+13],m[h+2],m[h+6],m[h+10],m[h+14],m[h+3],m[h+7],m[h+11],m[h+15]),s.copy(a).applyMatrix4(i),r.intersectsBox(s)){const t=n.instanceMatrices.subarray(16*e,16*(e+1)),r=n.colors.subarray(4*e,4*(e+1)),o=n.treeIndices[e];c.set(t,16*d),p.set(r,4*d),u[d]=o,d++}var m,h;if(l===d)return n;return{triangleCount:n.triangleCount,triangleOffset:n.triangleOffset,instanceMatrices:c.slice(0,16*d),colors:p.slice(0,4*d),treeIndices:u.slice(0,d)}}
117
117
  /*!
118
118
  * Copyright 2021 Cognite AS
119
119
  */const{boxGeometry:R,boxGeometryBoundingBox:A}=(()=>{const e=new r.BoxBufferGeometry(1,1,1,1,1,1);try{const t={index:e.getIndex(),position:e.getAttribute("position"),normal:e.getAttribute("normal")};return e.computeBoundingBox(),{boxGeometry:t,boxGeometryBoundingBox:e.boundingBox}}finally{e.dispose()}})(),{quadGeometry:D,quadGeometryBoundingBox:z}=(()=>{const e=new r.PlaneBufferGeometry(1,1,1,1);try{const t={index:e.getIndex(),position:e.getAttribute("position"),normal:e.getAttribute("normal")};return e.computeBoundingBox(),{quadGeometry:t,quadGeometryBoundingBox:e.boundingBox}}finally{e.dispose()}})(),{trapeziumGeometry:E,trapeziumGeometryBoundingBox:O}=(()=>{const e=[0,0,0,1,1,1,2,2,2,3,3,3];return{trapeziumGeometry:{index:new r.BufferAttribute(new Uint16Array([0,1,3,0,3,2]),1),position:new r.BufferAttribute(new Float32Array(e),3)},trapeziumGeometryBoundingBox:(new r.Box3).setFromArray(e)}})(),{coneGeometry:F,coneGeometryBoundingBox:B}=(()=>{const e=[];e.push(-1,1,-1),e.push(-1,-1,-1),e.push(1,1,-1),e.push(1,-1,-1),e.push(1,1,1),e.push(1,-1,1);const t=new Uint16Array([1,2,0,1,3,2,3,4,2,3,5,4]);return{coneGeometry:{index:new r.BufferAttribute(t,1),position:new r.BufferAttribute(new Float32Array(e),3)},coneGeometryBoundingBox:(new r.Box3).setFromArray(e)}})(),{torusLodGeometries:k,torusGeometryBoundingBox:L}=(()=>{const e=(e,t)=>[e,2*t*Math.PI],t=[{tubularSegments:9,radialSegments:18},{tubularSegments:5,radialSegments:12},{tubularSegments:4,radialSegments:5}].map(({tubularSegments:t,radialSegments:n})=>function(e,t,n=((e,t)=>[e,t,0])){const o=[],i=[],a=1/e,s=1/t;for(let r=0;r<=t;r++)for(let t=0;t<=e;t++){const[e,i,d]=n(t*a,r*s);o.push(e||0,i||0,d||0)}for(let n=1;n<=t;n++)for(let t=1;t<=e;t++){const r=(e+1)*n+t-1,o=(e+1)*(n-1)+t-1,a=(e+1)*(n-1)+t,s=(e+1)*n+t;i.push(r,o,s),i.push(o,a,s)}return{index:new r.Uint16BufferAttribute(i,1),position:new r.Float32BufferAttribute(o,3)}}(n,t,e));return{torusLodGeometries:t,torusGeometryBoundingBox:(new r.Box3).setFromArray(t[t.length-1].position.array)}})(),{nutGeometry:G,nutGeometryBoundingBox:V}=(()=>{const e=new r.CylinderBufferGeometry(.5,.5,1,6);try{e.applyMatrix4((new r.Matrix4).makeRotationX(-Math.PI/2));const t={index:e.getIndex(),position:e.getAttribute("position"),normal:e.getAttribute("normal")};return{nutGeometry:t,nutGeometryBoundingBox:(new r.Box3).setFromArray(t.position.array)}}finally{e.dispose()}})();
@@ -154,7 +154,7 @@ const s=(new a.Matrix4).set(1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1);function d(e,t){sw
154
154
  */class v{getModelUri(e){if(!(e instanceof f))throw new Error(`Model must be a ${f.name}, but got ${e.toString()}`);return Promise.resolve(`${location.origin}/${e.localPath}`)}async getModelMatrix(e){if(!(e instanceof f))throw new Error(`Model must be a ${f.name}, but got ${e.toString()}`);const t=new a.Matrix4;return d(t,i.RevealCadModel),t}getModelCamera(e){if(!(e instanceof f))throw new Error(`Model must be a ${f.name}, but got ${e.toString()}`);return Promise.resolve(void 0)}}
155
155
  /*!
156
156
  * Copyright 2021 Cognite AS
157
- */},function(e,t){e.exports=require("assert")},function(e,t,n){"use strict";n.d(t,"a",(function(){return d}));var r=n(12),o=n.n(r),i=n(10);const{VERSION:a,MIXPANEL_TOKEN:s}={VERSION:"2.2.1",WORKER_VERSION:"1.2.0",MIXPANEL_TOKEN:"8c900bdfe458e32b768450c20750853d",IS_DEVELOPMENT_MODE:!1};class d{constructor(e,t,n){o.a.init(s,{disable_cookie:!0,disable_persistence:!0,ip:!1,property_blacklist:["$city","$region","mp_country_code","$geo_source","$timezone","mp_lib","$lib_version","$device_id","$user_id","$current_url","$screen_width","$screen_height","$referrer","$referring_domain","$initial_referrer","$initial_referring_domain"]}),o.a.reset(),o.a.identify("reveal-single-user"),this._sessionProps={VERSION:a,project:"unknown",application:"unknown",sessionId:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e&&(this._sessionProps.project=e),t&&(this._sessionProps.application=t),this.innerTrackEvent("init",n)}static init(e,t,n,r){if(void 0===globalThis.revealMetricsLogger&&e){const e=new d(t,n,r);globalThis.revealMetricsLogger={metricsLogger:e}}}innerTrackEvent(e,t){const n={...this._sessionProps,...t};o.a.track(e,n)}static trackEvent(e,t){globalThis.revealMetricsLogger&&globalThis.revealMetricsLogger.metricsLogger.innerTrackEvent(e,t)}static trackCreateTool(e){d.trackEvent("toolCreated",{toolName:e})}static trackLoadModel(e,t){d.trackEvent("loadModel",{...e,modelIdentifier:t})}static trackCadModelStyled(e,t){d.trackEvent("cadModelStyleAssigned",{nodeCollectionClassToken:e,style:t})}static trackError(e,t){i.a.error(e),this.trackEvent("error",{message:e.message,name:e.name,stack:e.stack,...t})}static trackCameraNavigation(e){d.trackEvent("cameraNavigated",e)}}
157
+ */},function(e,t){e.exports=require("assert")},function(e,t,n){"use strict";n.d(t,"a",(function(){return d}));var r=n(12),o=n.n(r),i=n(10);const{VERSION:a,MIXPANEL_TOKEN:s}={VERSION:"2.2.2",WORKER_VERSION:"1.2.0",MIXPANEL_TOKEN:"8c900bdfe458e32b768450c20750853d",IS_DEVELOPMENT_MODE:!1};class d{constructor(e,t,n){o.a.init(s,{disable_cookie:!0,disable_persistence:!0,ip:!1,property_blacklist:["$city","$region","mp_country_code","$geo_source","$timezone","mp_lib","$lib_version","$device_id","$user_id","$current_url","$screen_width","$screen_height","$referrer","$referring_domain","$initial_referrer","$initial_referring_domain"]}),o.a.reset(),o.a.identify("reveal-single-user"),this._sessionProps={VERSION:a,project:"unknown",application:"unknown",sessionId:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e&&(this._sessionProps.project=e),t&&(this._sessionProps.application=t),this.innerTrackEvent("init",n)}static init(e,t,n,r){if(void 0===globalThis.revealMetricsLogger&&e){const e=new d(t,n,r);globalThis.revealMetricsLogger={metricsLogger:e}}}innerTrackEvent(e,t){const n={...this._sessionProps,...t};o.a.track(e,n)}static trackEvent(e,t){globalThis.revealMetricsLogger&&globalThis.revealMetricsLogger.metricsLogger.innerTrackEvent(e,t)}static trackCreateTool(e){d.trackEvent("toolCreated",{toolName:e})}static trackLoadModel(e,t){d.trackEvent("loadModel",{...e,modelIdentifier:t})}static trackCadModelStyled(e,t){d.trackEvent("cadModelStyleAssigned",{nodeCollectionClassToken:e,style:t})}static trackError(e,t){i.a.error(e),this.trackEvent("error",{message:e.message,name:e.name,stack:e.stack,...t})}static trackCameraNavigation(e){d.trackEvent("cameraNavigated",e)}}
158
158
  /*!
159
159
  * Copyright 2021 Cognite AS
160
160
  */},function(e,t){e.exports=require("@cognite/potree-core")},function(e,t,n){"use strict";var r=n(23);
@@ -171,7 +171,7 @@ const o={renderSize:new r.Vector2,position:new r.Vector3};function i(e,t,n=new r
171
171
  /*!
172
172
  * Copyright 2021 Cognite AS
173
173
  */
174
- class o{constructor(e){this._clippingPlanes=[new r.Plane,new r.Plane,new r.Plane,new r.Plane,new r.Plane,new r.Plane],this._box=e||new r.Box3,this.updatePlanes()}set minX(e){this._box.min.x=e,this.updatePlanes()}get minX(){return this._box.min.x}set minY(e){this._box.min.y=e,this.updatePlanes()}get minY(){return this._box.min.y}set minZ(e){this._box.min.z=e,this.updatePlanes()}get minZ(){return this._box.min.z}set maxX(e){this._box.max.x=e,this.updatePlanes()}get maxX(){return this._box.max.x}set maxY(e){this._box.max.y=e,this.updatePlanes()}get maxY(){return this._box.max.y}set maxZ(e){this._box.max.z=e,this.updatePlanes()}get maxZ(){return this._box.max.z}updatePlanes(){this._clippingPlanes[0].setFromNormalAndCoplanarPoint(new r.Vector3(1,0,0),new r.Vector3(this.minX,0,0)),this._clippingPlanes[1].setFromNormalAndCoplanarPoint(new r.Vector3(-1,0,0),new r.Vector3(this.maxX,0,0)),this._clippingPlanes[2].setFromNormalAndCoplanarPoint(new r.Vector3(0,1,0),new r.Vector3(0,this.minY,0)),this._clippingPlanes[3].setFromNormalAndCoplanarPoint(new r.Vector3(0,-1,0),new r.Vector3(0,this.maxY,0)),this._clippingPlanes[4].setFromNormalAndCoplanarPoint(new r.Vector3(0,0,1),new r.Vector3(0,0,this.minZ)),this._clippingPlanes[5].setFromNormalAndCoplanarPoint(new r.Vector3(0,0,-1),new r.Vector3(0,0,this.maxZ))}get clippingPlanes(){return this._clippingPlanes}}},function(e,t){e.exports=require("lodash/debounce")},function(e,t){e.exports=require("lodash/range")},,function(e,t){e.exports=require("comlink")},function(e,t){e.exports=require("loglevel")},function(e,t){e.exports=require("skmeans")},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_normal;\nvarying vec3 v_color;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\nvarying vec3 v_normal;\nvarying vec3 v_color;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize;\nuniform sampler2D transformOverrideTexture;\n\nvoid main()\n{\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * instanceMatrix * vec4(normalize(normal), 0.0)).xyz;\n //v_normal = normal;\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(transformed, 1.0);\n vViewPosition = modelViewPosition.xyz;\n gl_Position = projectionMatrix * modelViewPosition;\n}"},function(e,t){e.exports=require("@cognite/sdk")},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n"},function(e,t){e.exports=require("lodash/omit")},function(e,t){e.exports=require("lodash/chunk")},function(e,t){e.exports=require("lodash/throttle")},,function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n updateFragmentColor(renderMode, color, v_treeIndex, v_normal, gl_FragCoord.z, matCapTexture, GeometryType.Quad);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec3 color;\nattribute float treeIndex;\nattribute vec4 matrix0;\nattribute vec4 matrix1;\nattribute vec4 matrix2;\nattribute vec4 matrix3;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n \n mat4 treeIndexWorldTransform = determineMatrixOverride(\n treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_treeIndex = treeIndex;\n v_color = color;\n v_normal = normalize(normalMatrix * (inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(normal), 0.0)).xyz);\n mat4 instanceMatrix = mat4(matrix0, matrix1, matrix2, matrix3);\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 derivateNormal(vec3 v_viewPosition) {\n vec3 fdx = vec3(dFdx(v_viewPosition.x), dFdx(v_viewPosition.y), dFdx(v_viewPosition.z));\n vec3 fdy = vec3(dFdy(v_viewPosition.x), dFdy(v_viewPosition.y), dFdy(v_viewPosition.z));\n vec3 normal = normalize(cross(fdx, fdy));\n return normal;\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform int renderMode;\n\nvoid main()\n{\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, v_viewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = derivateNormal(v_viewPosition);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.TriangleMesh);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nattribute vec3 color;\nattribute float treeIndex; \n\nvarying vec3 v_color;\nvarying float v_treeIndex;\nvarying vec3 v_viewPosition;\n\nuniform vec2 treeIndexTextureSize;\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize;\nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n v_color = color;\n v_treeIndex = treeIndex;\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(position, 1.0);\n v_viewPosition = modelViewPosition.xyz;\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 derivateNormal(vec3 v_viewPosition) {\n vec3 fdx = vec3(dFdx(v_viewPosition.x), dFdx(v_viewPosition.y), dFdx(v_viewPosition.z));\n vec3 fdy = vec3(dFdy(v_viewPosition.x), dFdy(v_viewPosition.y), dFdy(v_viewPosition.z));\n vec3 normal = normalize(cross(fdx, fdy));\n return normal;\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, v_viewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = derivateNormal(v_viewPosition);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.InstancedMesh);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main()\n{\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_color = a_color;\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 modelViewPosition = viewMatrix * modelMatrix * vec4(transformed, 1.0);\n v_viewPosition = modelViewPosition.xyz;\n v_treeIndex = a_treeIndex;\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec2 v_xy;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n float dist = dot(v_xy, v_xy);\n vec3 normal = normalize( v_normal );\n if (dist > 0.25)\n discard;\n \n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_normal;\n\nvarying vec2 v_xy;\nvarying vec3 v_color;\nvarying vec3 v_normal;\nvarying float v_treeIndex;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n v_xy = vec2(position.x, position.y);\n v_treeIndex = a_treeIndex;\n\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n v_color = a_color;\n\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(a_normal), 0.0)).xyz;\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\n\nvarying vec4 v_centerB;\n\nvarying vec4 v_W;\nvarying vec4 v_U;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec4 v_centerA;\nvarying vec4 v_V;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec3 normal = normalize( v_normal );\n vec4 color = determineColor(v_color, appearance);\n\n float R1 = v_centerB.w;\n vec4 U = v_U;\n vec4 W = v_W;\n vec4 V = v_V;\n float height = length(v_centerA.xyz - v_centerB.xyz);\n float R2 = v_centerA.w;\n float dR = R2 - R1;\n\n mat3 basis = mat3(U.xyz, V.xyz, W.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, W.w);\n vec3 rayTarget = surfacePoint;\n\n #if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n #else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n #endif\n\n vec3 diff = rayTarget - v_centerB.xyz;\n vec3 E = diff * basis;\n vec3 D = rayDirection * basis;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy) - R1*R1;\n\n if (R1 != R2) {\n // Additional terms if radii are different\n float dRLInv = dR / height;\n float dRdRL2Inv = dRLInv * dRLInv;\n a -= D.z * D.z * dRdRL2Inv;\n b -= dRLInv * (E.z * D.z * dRLInv + R1 * D.z);\n c -= dRLInv * (E.z * E.z * dRLInv + 2.0 * R1 * E.z);\n }\n\n // Calculate a dicriminant of the above quadratic equation\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long cone\n if (d < 0.0) {\n discard;\n }\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n vec3 intersectionPoint = E + dist * D;\n float theta = atan(intersectionPoint.y, intersectionPoint.x);\n if (theta < v_angle) theta += 2.0 * PI;\n\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n bool isInner = false;\n\n if (intersectionPoint.z <= 0.0 ||\n intersectionPoint.z > height ||\n theta > v_angle + v_arcAngle ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n isInner = true;\n dist = dist2;\n intersectionPoint = E + dist * D;\n theta = atan(intersectionPoint.y, intersectionPoint.x);\n p = rayTarget + dist*rayDirection;\n if (theta < v_angle) theta += 2.0 * PI;\n if (intersectionPoint.z <= 0.0 ||\n intersectionPoint.z > height ||\n theta > v_angle + v_arcAngle ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n #if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n if (R1 != R2)\n {\n // Find normal vector\n vec3 n = -normalize(W.xyz);\n vec3 P1 = v_centerB.xyz;\n vec3 P2 = v_centerA.xyz;\n vec3 A = cross(P1 - p, P2 - p);\n\n vec3 t = normalize(cross(n, A));\n vec3 o1 = P1 + R1 * t;\n vec3 o2 = P2 + R2 * t;\n vec3 B = o2-o1;\n normal = normalize(cross(A, B));\n }\n else\n {\n // Regular cylinder has simpler normal vector in camera space\n vec3 p_local = p - v_centerB.xyz;\n normal = normalize(p_local - W.xyz * dot(p_local, W.xyz));\n }\n #endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radiusA;\nattribute float a_radiusB;\nattribute vec3 a_color;\n// segment attributes\nattribute vec3 a_localXAxis;\nattribute float a_angle;\nattribute float a_arcAngle;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 v_U;\nvarying vec4 v_W;\n\nvarying vec4 v_centerA;\nvarying vec4 v_V;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 center = 0.5 * (centerA + centerB);\n float halfHeight = 0.5 * length(centerA - centerB);\n vec3 dir = normalize(centerA - centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n float maxRadius = max(a_radiusA, a_radiusB);\n float leftUpScale = maxRadius;\n\n vec3 lDir = dir;\n if (dot(objectToCameraModelSpace, dir) < 0.0) { // direction vector looks away, flip it\n lDir = -lDir;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (maxRadius * (position.x + 1.0) * 0.0025 / halfHeight);\n#endif\n\n vec3 surfacePoint = center + mat3(halfHeight*lDir, leftUpScale*left, leftUpScale*up) * newPosition;\n vec3 transformed = surfacePoint;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // varying data\n v_treeIndex = a_treeIndex;\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n // compute basis for cone\n v_W.xyz = dir;\n v_U.xyz = (modelTransformOffset * vec4(a_localXAxis, 0.0)).xyz;\n v_W.xyz = normalize(normalMatrix * v_W.xyz);\n v_U.xyz = normalize(normalMatrix * v_U.xyz);\n // We pack surfacePoint as w-components of U and W\n v_W.w = surfacePoint.z;\n v_U.w = surfacePoint.x;\n\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n\n float radiusB = length((modelToTransformOffset * vec4(a_localXAxis * a_radiusB, 0.0)).xyz);\n float radiusA = length((modelToTransformOffset * vec4(a_localXAxis * a_radiusA, 0.0)).xyz);\n\n // We pack radii as w-components of v_centerB\n v_centerB.xyz = mul3(modelViewMatrix, centerB);\n v_centerB.w = radiusB;\n\n v_V.xyz = -cross(v_U.xyz, v_W.xyz);\n v_V.w = surfacePoint.y;\n\n v_centerA.xyz = mul3(modelViewMatrix, centerA);\n v_centerA.w = radiusA;\n\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\n\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 axis;\n\nvarying vec4 v_centerA;\nvarying vec4 v_centerB;\nvarying float height;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = normalize( v_normal );\n mat3 basis = mat3(U.xyz, V.xyz, axis.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, axis.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - v_centerA.xyz;\n vec3 E = diff * basis;\n float L = height;\n vec3 D = rayDirection * basis;\n\n float R1 = v_centerA.w;\n float R2 = v_centerB.w;\n float dR = R2 - R1;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy)-R1*R1;\n float L2Inv = 1.0/(L*L);\n\n if (R1 != R2) {\n // Additional terms if radii are different\n float dRLInv = dR/L;\n float dRdRL2Inv = dRLInv*dRLInv;\n a -= D.z*D.z*dRdRL2Inv;\n b -= dRLInv*(E.z*D.z*dRLInv + R1*D.z);\n c -= dRLInv*(E.z*E.z*dRLInv + 2.0*R1*E.z);\n }\n\n // Additional terms when one of the center points is displaced orthogonal to normal vector\n vec2 displacement = ((v_centerB.xyz-v_centerA.xyz)*basis).xy; // In the basis where displacement is in XY only\n float displacementLengthSquared = dot(displacement, displacement);\n a += D.z*(D.z*displacementLengthSquared - 2.0*L*dot(D.xy, displacement))*L2Inv;\n b += (D.z*E.z*displacementLengthSquared - L*(D.x*E.z*displacement.x + D.y*E.z*displacement.y + D.z*E.x*displacement.x + D.z*E.y*displacement.y))*L2Inv;\n c += E.z*(E.z*displacementLengthSquared - 2.*L*dot(E.xy, displacement))*L2Inv;\n\n // Calculate a dicriminant of the above quadratic equation (factor 2 removed from all b-terms above)\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long eccentric cone\n if (d < 0.0) {\n discard;\n }\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n // Check the smallest root, it is closest camera. Only test if the z-component is outside the truncated eccentric cone\n float dist = dist1;\n float intersectionPointZ = E.z + dist*D.z;\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n bool isInner = false;\n\n if (intersectionPointZ <= 0.0 ||\n intersectionPointZ >= L ||\n isClipped(appearance, p)\n ) {\n // Either intersection point is behind starting point (happens inside the cone),\n // or the intersection point is outside the end caps. This is not a valid solution.\n isInner = true;\n dist = dist2;\n intersectionPointZ = E.z + dist*D.z;\n p = rayTarget + dist*rayDirection;\n\n if (intersectionPointZ <= 0.0 ||\n intersectionPointZ >= L ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Find normal vector\n vec3 n = normalize(-axis.xyz);\n vec3 v_centerA = v_centerA.xyz;\n vec3 v_centerB = v_centerB.xyz;\n vec3 A = cross(v_centerA - p, v_centerB - p);\n\n vec3 t = normalize(cross(n, A));\n vec3 o1 = v_centerA + R1 * t;\n vec3 o2 = v_centerB + R2 * t;\n vec3 B = o2-o1;\n normal = normalize(cross(A, B));\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radiusA;\nattribute float a_radiusB;\nattribute vec3 a_normal;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerA;\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 axis;\nvarying float height;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 normalWithOffset = normalize((modelTransformOffset * vec4(a_normal, 0)).xyz);\n\n float uniformScaleFactor = length(mul3(modelMatrix, normalize(vec3(1.0))));\n\n height = dot(centerA - centerB, normalWithOffset) * uniformScaleFactor;\n\n vec3 lDir;\n vec3 center = 0.5 * (centerA + centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n // Find the coordinates of centerA and centerB projected down to the end cap plane\n vec3 maxCenterProjected = centerA - dot(centerA, normalWithOffset) * normalWithOffset;\n vec3 minCenterProjected = centerB - dot(centerB, normalWithOffset) * normalWithOffset;\n float distanceBetweenProjectedCenters = length(maxCenterProjected - minCenterProjected);\n\n lDir = normalWithOffset;\n float dirSign = 1.0;\n if (dot(objectToCameraModelSpace, lDir) < 0.0) { // direction vector looks away, flip it\n dirSign = -1.0;\n lDir *= -1.;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n // compute basis for cone\n axis.xyz = -normalWithOffset;\n U.xyz = cross(objectToCameraModelSpace, axis.xyz);\n V.xyz = cross(U.xyz, axis.xyz);\n // Transform to camera space\n axis.xyz = normalize(normalMatrix * axis.xyz);\n U.xyz = normalize(normalMatrix * U.xyz);\n V.xyz = normalize(normalMatrix * V.xyz);\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_radiusA * (position.x + 1.0) * 0.0025 / height);\n#endif\n\n v_centerA.xyz = mul3(viewMatrix, mul3(modelMatrix, centerA));\n v_centerB.xyz = mul3(viewMatrix, mul3(modelMatrix, centerB));\n\n float radiusA = length((modelToTransformOffset * vec4(normalize(vec3(1.0)) * a_radiusA, 0.0)).xyz);\n float radiusB = length((modelToTransformOffset * vec4(normalize(vec3(1.0)) * a_radiusB, 0.0)).xyz);\n\n // Pack radii as w components of v_centerA and v_centerB\n v_centerA.w = radiusA;\n v_centerB.w = radiusB;\n\n float radiusIncludedDisplacement = 0.5*(2.0*max(a_radiusA, a_radiusB) + distanceBetweenProjectedCenters);\n vec3 surfacePoint = center + mat3(0.5 * height * lDir * (1.0 / uniformScaleFactor), radiusIncludedDisplacement*left, radiusIncludedDisplacement*up) * newPosition;\n vec3 transformed = surfacePoint;\n\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // We pack surfacePoint as w-components of U, V and axis\n U.w = surfacePoint.x;\n V.w = surfacePoint.y;\n axis.w = surfacePoint.z;\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\nvarying vec4 center;\nvarying float hRadius;\nvarying float height;\n\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 sphereNormal;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = normalize(sphereNormal.xyz);\n\n float vRadius = center.w;\n float ratio = vRadius / hRadius;\n mat3 basis = mat3(U.xyz, V.xyz, sphereNormal.xyz);\n mat3 scaledBasis = mat3(ratio * U.xyz, ratio * V.xyz, sphereNormal.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, sphereNormal.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - center.xyz;\n vec3 E = diff * scaledBasis;\n vec3 D = rayDirection * scaledBasis;\n\n float a = dot(D, D);\n float b = dot(E, D);\n float c = dot(E, E) - vRadius*vRadius;\n\n // discriminant of sphere equation (factor 2 removed from b above)\n float d = b*b - a*c;\n if(d < 0.0)\n discard;\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n float intersectionPointZ = E.z + dist*D.z;\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n if (intersectionPointZ <= vRadius - height ||\n intersectionPointZ > vRadius ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n\n dist = dist2;\n intersectionPointZ = E.z + dist*D.z;\n p = rayTarget + dist*rayDirection;\n if (intersectionPointZ <= vRadius - height ||\n intersectionPointZ > vRadius ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Find normal vector in local space\n normal = vec3(p - center.xyz) * basis;\n normal.z = normal.z * (hRadius / vRadius) * (hRadius / vRadius);\n // Transform into camera space\n normal = normalize(basis * normal);\n if (dot(normal, rayDirection) > 0.) {\n normal = -normal;\n }\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\nuniform mat4 inverseNormalMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_center;\nattribute vec3 a_normal;\nattribute float a_horizontalRadius;\nattribute float a_verticalRadius;\nattribute float a_height;\n\nvarying float v_treeIndex;\n// We pack vRadius as w-component of center\nvarying vec4 center;\nvarying float hRadius;\nvarying float height;\n\n// U, V, axis represent the 3x3 sphere basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 sphereNormal;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerWithOffset = mul3(modelTransformOffset, a_center).xyz;\n\n vec3 normalWithOffset = (modelTransformOffset * vec4(a_normal, 0)).xyz;\n\n vec3 lDir;\n float distanceToCenterOfSegment = a_verticalRadius - a_height * 0.5;\n vec3 centerOfSegment = centerWithOffset + normalWithOffset * distanceToCenterOfSegment;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 objectToCameraModelSpace = inverseNormalMatrix * vec3(0.0, 0.0, 1.0);\n#else\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - centerOfSegment;\n#endif\n\n vec3 newPosition = position;\n\n float bb = dot(objectToCameraModelSpace, normalWithOffset);\n if (bb < 0.0) { // direction vector looks away, flip it\n lDir = -normalWithOffset;\n } else { // direction vector already looks in my direction\n lDir = normalWithOffset;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_verticalRadius * (position.x + 1.0) * 0.0025 / a_height);\n#endif\n\n // Negative angle means height larger than radius,\n // so we should have full size so we can render the largest part of the ellipsoid segment\n float ratio = max(0.0, 1.0 - a_height / a_verticalRadius);\n // maxRadiusOfSegment is the radius of the circle (projected ellipsoid) when ellipsoid segment is seen from above\n float maxRadiusOfSegment = a_horizontalRadius * sqrt(1.0 - ratio * ratio);\n\n vec3 displacement = vec3(newPosition.x*a_height*0.5, maxRadiusOfSegment*newPosition.y, maxRadiusOfSegment*newPosition.z);\n vec3 surfacePoint = centerOfSegment + mat3(lDir, left, up) * displacement;\n vec3 transformed = surfacePoint;\n\n v_treeIndex = a_treeIndex;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n center.xyz = mul3(modelViewMatrix, centerWithOffset);\n center.w = a_verticalRadius; // Pack radius into w-component\n hRadius = a_horizontalRadius;\n height = a_height;\n v_color = a_color;\n\n // compute basis\n sphereNormal.xyz = normalMatrix * normalWithOffset;\n U.xyz = normalMatrix * up;\n V.xyz = normalMatrix * left;\n\n // We pack surfacePoint as w-components of U, V and axis\n U.w = surfacePoint.x;\n V.w = surfacePoint.y;\n sphereNormal.w = surfacePoint.z;\n\n // TODO should perhaps be a different normal?\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n'},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\n// TODO general cylinder and cone are very similar and used\n// the same shader in the old code. Consider de-duplicating\n// parts of this code\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform float dataTextureWidth;\nuniform float dataTextureHeight;\nuniform mat4 projectionMatrix;\n\nvarying vec4 v_centerB;\n\nvarying vec4 v_W;\nvarying vec4 v_U;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying float v_surfacePointY;\n\nvarying vec4 v_planeA;\nvarying vec4 v_planeB;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize( v_normal );\n\n float R1 = v_centerB.w;\n vec4 U = v_U;\n vec4 W = v_W;\n vec4 V = vec4(normalize(cross(W.xyz, U.xyz)), v_surfacePointY);\n\n mat3 basis = mat3(U.xyz, V.xyz, W.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, W.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - v_centerB.xyz;\n vec3 E = diff * basis;\n vec3 D = rayDirection * basis;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy) - R1*R1;\n\n // Calculate a dicriminant of the above quadratic equation\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long cone\n if (d < 0.0)\n discard;\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n vec3 intersectionPoint = E + dist * D;\n float theta = atan(intersectionPoint.y, intersectionPoint.x);\n if (theta < v_angle) theta += 2.0 * PI;\n\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n vec3 planeACenter = vec3(0.0, 0.0, v_planeA.w);\n vec3 planeANormal = v_planeA.xyz;\n vec3 planeBCenter = vec3(0.0, 0.0, v_planeB.w);\n vec3 planeBNormal = v_planeB.xyz;\n bool isInner = false;\n\n if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||\n dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||\n theta > v_arcAngle + v_angle ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n isInner = true;\n dist = dist2;\n intersectionPoint = E + dist * D;\n theta = atan(intersectionPoint.y, intersectionPoint.x);\n p = rayTarget + dist*rayDirection;\n if (theta < v_angle) theta += 2.0 * PI;\n if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||\n dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||\n theta > v_arcAngle + v_angle || isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Regular cylinder has simpler normal vector in camera space\n vec3 p_local = p - v_centerB.xyz;\n normal = normalize(p_local - W.xyz * dot(p_local, W.xyz));\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radius;\nattribute vec3 a_color;\n// slicing plane attributes\nattribute vec4 a_planeA;\nattribute vec4 a_planeB;\n// segment attributes\nattribute vec3 a_localXAxis;\nattribute float a_angle;\nattribute float a_arcAngle;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 v_U;\nvarying vec4 v_W;\n\nvarying vec4 v_planeA;\nvarying vec4 v_planeB;\n\nvarying float v_surfacePointY;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n \n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 center = 0.5 * (centerA + centerB);\n float halfHeight = 0.5 * length(centerA - centerB);\n vec3 dir = normalize(centerA - centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n float leftUpScale = a_radius;\n\n vec3 lDir = dir;\n if (dot(objectToCameraModelSpace, dir) < 0.0) { // direction vector looks away, flip it\n lDir = -lDir;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_radius * (position.x + 1.0) * 0.0025 / halfHeight);\n#endif\n\n vec3 surfacePoint = center + mat3(halfHeight*lDir, leftUpScale*left, leftUpScale*up) * newPosition;\n vec3 transformed = surfacePoint;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // varying data\n v_treeIndex = a_treeIndex;\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n // compute basis for cone\n v_W.xyz = dir;\n v_U.xyz = (modelTransformOffset * vec4(a_localXAxis, 0)).xyz;\n v_W.xyz = normalize(normalMatrix * v_W.xyz);\n v_U.xyz = normalize(normalMatrix * v_U.xyz);\n // We pack surfacePoint as w-components of U and W\n v_W.w = surfacePoint.z;\n v_U.w = surfacePoint.x;\n\n // We pack radii as w-components of v_centerB\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n float radius = length((modelToTransformOffset * vec4(a_localXAxis * a_radius, 0.0)).xyz);\n\n centerB = centerB - dir;\n v_centerB.xyz = mul3(modelViewMatrix, centerB);\n v_centerB.w = radius;\n\n vec4 planeA = a_planeA;\n planeA.w = length((modelToTransformOffset * vec4(planeA.xyz * planeA.w, 0.0)).xyz);\n\n vec4 planeB = a_planeB;\n planeB.w = length((modelToTransformOffset * vec4(planeB.xyz * planeB.w, 0.0)).xyz);\n\n v_planeA = planeA;\n v_planeB = planeB;\n v_surfacePointY = surfacePoint.y;\n v_centerB.w = radius;\n\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nvarying float v_oneMinusThicknessSqr;\nvarying vec2 v_xy;\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n float dist = dot(v_xy, v_xy);\n float theta = atan(v_xy.y, v_xy.x);\n vec3 normal = normalize( v_normal );\n if (theta < v_angle) {\n theta += 2.0 * PI;\n }\n if (dist > 0.25 || dist < 0.25 * v_oneMinusThicknessSqr || theta >= v_angle + v_arcAngle) {\n discard;\n }\n\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute float a_angle;\nattribute float a_arcAngle;\nattribute float a_thickness;\nattribute vec3 a_normal;\n\nvarying float v_treeIndex;\nvarying float v_oneMinusThicknessSqr;\nvarying vec2 v_xy;\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n v_treeIndex = a_treeIndex;\n v_oneMinusThicknessSqr = (1.0 - a_thickness) * (1.0 - a_thickness);\n v_xy = vec2(position.x, position.y);\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n v_color = a_color;\n\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(a_normal), 0.0)).xyz;\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute float a_arcAngle;\nattribute float a_radius;\nattribute float a_tubeRadius;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n // normalized theta and phi are packed into positions\n float theta = position.x * a_arcAngle;\n float phi = position.y;\n float cosTheta = cos(theta);\n float sinTheta = sin(theta);\n vec3 pos3 = vec3(0);\n\n pos3.x = (a_radius + a_tubeRadius*cos(phi)) * cosTheta;\n pos3.y = (a_radius + a_tubeRadius*cos(phi)) * sinTheta;\n pos3.z = a_tubeRadius*sin(phi);\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n \n vec3 transformed = (instanceMatrix * vec4(pos3, 1.0)).xyz;\n\n // Calculate normal vectors if we're not picking\n vec3 center = (instanceMatrix * vec4(a_radius * cosTheta, a_radius * sinTheta, 0.0, 1.0)).xyz;\n vec3 objectNormal = normalize(transformed.xyz - center);\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(objectNormal, 0.0)).xyz;\n\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(transformed, 1.0);\n\n vViewPosition = modelViewPosition.xyz;\n\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_vertex1;\nattribute vec3 a_vertex2;\nattribute vec3 a_vertex3;\nattribute vec3 a_vertex4;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n vec3 transformed;\n // reduce the avarage branchings\n if (position.x < 1.5) {\n transformed = position.x == 0.0 ? a_vertex1 : a_vertex2;\n } else {\n transformed = position.x == 2.0 ? a_vertex3 : a_vertex4;\n }\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 objectNormal = cross(a_vertex1 - a_vertex2, a_vertex1 - a_vertex3);\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(objectNormal, 0.0)).xyz;\n\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \nmat3 G[9];\n// hard coded matrix values!!!! as suggested in https://github.com/neilmendoza/ofxPostProcessing/blob/master/src/EdgePass.cpp#L45\nconst mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );\nconst mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );\nconst mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );\nconst mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );\nconst mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );\nconst mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );\nconst mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );\nconst mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );\nconst mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );\n\nfloat edgeDetectionFilter(sampler2D baseTexture, vec2 uv, vec2 resolution) {\n\n vec2 texel = vec2(1.0 / resolution.x, 1.0 / resolution.y);\n\n\tG[0] = g0,\n\tG[1] = g1,\n\tG[2] = g2,\n\tG[3] = g3,\n\tG[4] = g4,\n\tG[5] = g5,\n\tG[6] = g6,\n\tG[7] = g7,\n\tG[8] = g8;\n\n\tmat3 I;\n\tfloat cnv[9];\n\tvec3 neighbour;\n\n\t/* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */\n\tfor (int i=0; i<3; i++) {\n\t\tfor (int j=0; j<3; j++) {\n\t\t\tneighbour = texture2D(baseTexture, uv + texel * vec2(float(i)-1.0,float(j)-1.0) ).rgb;\n\t\t\tI[i][j] = length(neighbour);\n\t\t}\n\t}\n\n\t/* calculate the convolution values for all the masks */\n\tfor (int i=0; i<9; i++) {\n\t\tfloat dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);\n\t\tcnv[i] = dp3 * dp3;\n\t}\n\n\tfloat M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);\n\tfloat S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);\n\n float edgeStrength = sqrt(M/S);\n\n return edgeStrength;\n}\n\n#include <packing>\n\nvarying vec2 vUv;\n\nvarying vec2 vUv0;\nvarying vec2 vUv1;\nvarying vec2 vUv2;\nvarying vec2 vUv3;\n\nuniform sampler2D tFront;\nuniform sampler2D tFrontDepth;\n\nuniform sampler2D tBack;\nuniform sampler2D tBackDepth;\n\nuniform sampler2D tCustom;\nuniform sampler2D tCustomDepth;\n\nuniform sampler2D tGhost;\nuniform sampler2D tGhostDepth;\n\nuniform sampler2D tOutlineColors;\n\nuniform float cameraNear;\nuniform float cameraFar;\n\nuniform vec2 resolution;\n\nuniform float edgeStrengthMultiplier;\nuniform float edgeGrayScaleIntensity;\n\nconst float infinity = 1e20;\n\nfloat computeFloatEncodedOutlineIndex(float bitEncodedFloat){\n return floatBitsSubset(floor((bitEncodedFloat * 255.0) + 0.5), 5, 8);\n}\n\nvec4 computeNeighborOutlineIndices(sampler2D colorTexture){\n float outlineIndex0 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv0).a);\n float outlineIndex1 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv1).a);\n float outlineIndex2 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv2).a);\n float outlineIndex3 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv3).a);\n\n return vec4(outlineIndex0, outlineIndex1, outlineIndex2, outlineIndex3);\n}\n\nfloat toViewZ(float depth, float near, float far){\n float normalizedDepth = depth * 2.0 - 1.0;\n return 2.0 * near * far / (far + near - normalizedDepth * (far - near)); \n}\n\nvec4 computeNeighborAlphas(sampler2D colorTexture){\n float alpha0 = texture2D(colorTexture, vUv0).a;\n float alpha1 = texture2D(colorTexture, vUv1).a;\n float alpha2 = texture2D(colorTexture, vUv2).a;\n float alpha3 = texture2D(colorTexture, vUv3).a;\n\n return vec4(alpha0, alpha1, alpha2, alpha3);\n}\n\nvoid main() {\n vec4 frontAlbedo = texture2D(tFront, vUv);\n vec4 backAlbedo = texture2D(tBack, vUv);\n vec4 customAlbedo = texture2D(tCustom, vUv);\n vec4 ghostAlbedo = texture2D(tGhost, vUv);\n\n float frontDepth = texture2D(tFrontDepth, vUv).r;\n float backDepth = texture2D(tBackDepth, vUv).r; \n float customDepth = texture2D(tCustomDepth, vUv).r;\n float ghostDepth = texture2D(tGhostDepth, vUv).r;\n\n // This is a hack to make sure that all textures are initialized\n // If a texture is unused, it will have a clear value of 0.0.\n // Without this we've seen issues with MSAA where resizing render targets\n // causes depth to cleared to either 1 or 0 depending on the device/browser\n customDepth = customDepth > 0.0 ? customDepth : 1.0; \n backDepth = backDepth > 0.0 ? backDepth : 1.0;\n ghostDepth = ghostDepth > 0.0 ? ghostDepth : 1.0;\n frontDepth = frontDepth > 0.0 ? frontDepth : 1.0; \n\n if(all(greaterThanEqual(vec4(backDepth, customDepth, ghostDepth, frontDepth), vec4(1.0)))){\n discard;\n }\n \n // Decompose and clamp \"ghost\" color\n vec4 clampedGhostAlbedo = vec4(max(ghostAlbedo.rgb, 0.5), min(ghostAlbedo.a, 0.8));\n\n float frontOutlineIndex = computeFloatEncodedOutlineIndex(frontAlbedo.a);\n vec4 frontNeighborIndices = computeNeighborOutlineIndices(tFront);\n\n // There exsists fragments of rendered objects within the edge width that should have border\n if(any(equal(frontNeighborIndices, vec4(0.0))) && frontOutlineIndex > 0.0) \n { \n float borderColorIndex = max(max(frontNeighborIndices.x, frontNeighborIndices.y), max(frontNeighborIndices.z, frontNeighborIndices.w));\n gl_FragColor = texture2D(tOutlineColors, vec2(0.125 * borderColorIndex + (0.125 / 2.0), 0.5));\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = frontDepth;\n#endif\n return;\n }\n\n // texture has drawn fragment\n if(frontDepth < 1.0){\n float customDepthTest = step(customDepth, backDepth); // zero if back is in front\n\n float a = customDepthTest > 0.0 ? ceil(customAlbedo.a) * 0.5 : ceil(backAlbedo.a) * 0.5;\n\n gl_FragColor = vec4(frontAlbedo.rgb, 1.0) * (1.0 - a) + (vec4(backAlbedo.rgb, 1.0) * (1.0 - customDepthTest) + vec4(customAlbedo.rgb, 1.0) * customDepthTest) * a;\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = texture2D(tFrontDepth, vUv).r;\n#endif\n return;\n }\n\n if (customDepth >= backDepth) {\n float backOutlineIndex = computeFloatEncodedOutlineIndex(backAlbedo.a);\n vec4 backNeighborIndices = computeNeighborOutlineIndices(tBack);\n\n if( any(equal(backNeighborIndices, vec4(0.0))) && backOutlineIndex > 0.0) \n { \n float borderColorIndex = max(max(backNeighborIndices.x, backNeighborIndices.y), max(backNeighborIndices.z, backNeighborIndices.w));\n gl_FragColor = texture2D(tOutlineColors, vec2(0.125 * borderColorIndex + (0.125 / 2.0), 0.5));\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth)\n gl_FragDepthEXT = texture2D(tBackDepth, vUv).r;\n#endif\n return;\n }\n }\n \n float edgeStrength = 0.0;\n#if defined(EDGES)\n if (!any(equal(computeNeighborAlphas(tBack), vec4(0.0)))) {\n float depthEdge = toViewZ(backDepth, cameraNear, cameraFar);\n edgeStrength = (1.0 - smoothstep(10.0, 40.0, depthEdge)) * edgeDetectionFilter(tBack, vUv, resolution) * edgeStrengthMultiplier;\n }\n#endif\n\n // Combine color from ghost, back and custom object\n vec4 color = backAlbedo;\n float depth = backDepth;\n if (customDepth < backDepth && ghostDepth == 1.0) {\n color = vec4(customAlbedo.rgb * customAlbedo.a + (1.0 - customAlbedo.a) * backAlbedo.rgb, 1.0);\n depth = customDepth;\n edgeStrength = 0.0;\n } else if (customDepth < backDepth && ghostDepth < 1.0) {\n float s = (1.0 - step(backDepth, ghostDepth)) * clampedGhostAlbedo.a;\n vec3 modelAlbedo = mix(backAlbedo.rgb, clampedGhostAlbedo.rgb, s);\n color = vec4(customAlbedo.rgb * customAlbedo.a + (1.0 - customAlbedo.a) * modelAlbedo.rgb, 1.0);\n depth = customDepth;\n edgeStrength = 0.0;\n } else {\n float s = (1.0 - step(backDepth, ghostDepth)) * clampedGhostAlbedo.a;\n color = vec4(mix(backAlbedo.rgb, clampedGhostAlbedo.rgb, s), backAlbedo.a);\n depth = mix(backDepth, ghostDepth, s);\n }\n \n gl_FragColor = color * (1.0 - edgeStrength) + vec4(vec3(edgeGrayScaleIntensity) * edgeStrength, 1.0);\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = depth;\n#endif\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvarying vec2 vUv;\n\n// selection outline\nuniform vec2 texelSize;\nvarying vec2 vUv0;\nvarying vec2 vUv1;\nvarying vec2 vUv2;\nvarying vec2 vUv3;\n\nvoid main() {\n vUv = uv;\n\n // selection outline\n vUv0 = vec2(uv.x + texelSize.x, uv.y);\n vUv1 = vec2(uv.x - texelSize.x, uv.y);\n vUv2 = vec2(uv.x, uv.y + texelSize.y);\n vUv3 = vec2(uv.x, uv.y - texelSize.y);\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/*!\n *\n * Adapted from:\n * https://github.com/mattdesl/three-shader-fxaa\n * MIT License (MIT) Copyright (c) 2014 Matt DesLauriers\n *\n */\n\nvarying vec2 v_uv;\nvarying vec2 v_fragCoord;\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nuniform vec2 inverseResolution;\nuniform vec2 resolution;\nuniform sampler2D tDiffuse;\nuniform sampler2D tDepth;\n\n#ifndef FXAA_REDUCE_MIN\n #define FXAA_REDUCE_MIN (1.0/ 128.0)\n#endif\n#ifndef FXAA_REDUCE_MUL\n #define FXAA_REDUCE_MUL (1.0 / 8.0)\n#endif\n#ifndef FXAA_SPAN_MAX\n #define FXAA_SPAN_MAX 8.0\n#endif\n\nvec4 fxaa(sampler2D tex, vec2 fragCoord,\n vec2 resolution, vec2 inverseResolution,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n\n vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\n vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\n vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\n vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\n vec4 texColor = texture2D(tex, v_rgbM);\n vec3 rgbM = texColor.xyz;\n\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n mediump vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin));\n\n vec4 rgbA = 0.5 * (\n texture2D(tex, inverseResolution * (v_fragCoord + dir * (1.0 / 3.0 - 0.5))) +\n texture2D(tex, inverseResolution * (v_fragCoord + dir * (2.0 / 3.0 - 0.5))));\n vec4 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(tex, inverseResolution * (v_fragCoord + dir * -0.5)) +\n texture2D(tex, inverseResolution * (v_fragCoord + dir * 0.5)));\n\n float lumaB = dot(rgbB.rgb, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n color = rgbA;\n } else {\n color = rgbB;\n }\n return color;\n}\n\nvoid main() {\n gl_FragColor = fxaa(tDiffuse, v_fragCoord, \n resolution, inverseResolution, \n v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth)\n gl_FragDepthEXT = texture2D(tDepth, v_uv).r;\n#endif\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/*!\n *\n * Adapted from:\n * https://github.com/mattdesl/three-shader-fxaa\n * MIT License (MIT) Copyright (c) 2014 Matt DesLauriers\n *\n */\n\nuniform vec2 resolution;\nuniform vec2 inverseResolution;\n\nvarying vec2 v_uv;\nvarying vec2 v_fragCoord;\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvoid main() {\n v_fragCoord = uv * resolution;\n v_rgbNW = (v_fragCoord + vec2(-1.0, -1.0)) * inverseResolution;\n v_rgbNE = (v_fragCoord + vec2(1.0, -1.0)) * inverseResolution;\n v_rgbSW = (v_fragCoord + vec2(-1.0, 1.0)) * inverseResolution;\n v_rgbSE = (v_fragCoord + vec2(1.0, 1.0)) * inverseResolution;\n v_rgbM = vec2(v_fragCoord * inverseResolution);\n v_uv = uv;\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// From http://www.science-and-fiction.org/rendering/noise.html\nfloat rand2d(in vec2 co){\n return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);\n}\n\nvarying vec2 vUv;\n\nuniform mat4 projMatrix;\nuniform mat4 inverseProjectionMatrix;\n\nuniform vec3 kernel[MAX_KERNEL_SIZE];\n\nuniform sampler2D tDepth;\n\nuniform vec2 resolution;\n\nuniform float sampleRadius;\nuniform float bias;\n\nvec3 viewPosFromDepth(float depth, vec2 uv) {\n // Depth to clip space: [0, 1] -> [-1, 1]\n float z = depth * 2.0 - 1.0;\n\n // Fragment in clip space\n vec4 clipSpacePosition = vec4(uv * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = inverseProjectionMatrix * clipSpacePosition;\n\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n\n return viewSpacePosition.xyz;\n}\n\nvec3 computeWorldNormalFromDepth(sampler2D depthTexture, vec2 resolution, vec2 uv, float sampleDepth){\n float dx = 1.0 / resolution.x;\n float dy = 1.0 / resolution.y;\n\n vec2 uv1 = uv + vec2(dx, 0.0); // right\n float d1 = texture2D(depthTexture, uv1).r; \n\n vec2 uv2 = uv + vec2(0.0, dy); // up\n float d2 = texture2D(depthTexture, uv2).r;\n\n vec2 uv3 = uv + vec2(-dx, 0.0); // left\n float d3 = texture2D(depthTexture, uv3).r;\n\n vec2 uv4 = uv + vec2(0.0, -dy); // down\n float d4 = texture2D(depthTexture, uv4).r;\n\n bool horizontalSampleCondition = abs(d1 - sampleDepth) < abs(d3 - sampleDepth);\n\n float horizontalSampleDepth = horizontalSampleCondition ? d1 : d3;\n vec2 horizontalSampleUv = horizontalSampleCondition ? uv1 : uv3;\n\n bool verticalSampleCondition = abs(d2 - sampleDepth) < abs(d4 - sampleDepth);\n\n float verticalSampleDepth = verticalSampleCondition ? d2 : d4;\n vec2 verticalSampleUv = verticalSampleCondition ? uv2 : uv4;\n\n vec3 viewPos = viewPosFromDepth(sampleDepth, vUv);\n \n vec3 viewPos1 = (horizontalSampleCondition == verticalSampleCondition) ? viewPosFromDepth(horizontalSampleDepth, horizontalSampleUv) : viewPosFromDepth(verticalSampleDepth, verticalSampleUv);\n vec3 viewPos2 = (horizontalSampleCondition == verticalSampleCondition) ? viewPosFromDepth(verticalSampleDepth, verticalSampleUv) : viewPosFromDepth(horizontalSampleDepth, horizontalSampleUv);\n\n return normalize(cross(viewPos1 - viewPos, viewPos2 - viewPos));\n}\n\nvoid main(){\n float d = texture2D(tDepth, vUv).r;\n\n vec3 viewNormal = computeWorldNormalFromDepth(tDepth, resolution, vUv, d);\n\n vec3 viewPosition = viewPosFromDepth(d, vUv);\n\n vec3 randomVec = normalize(vec3(rand2d(vUv), rand2d(vUv * 3.0), rand2d(vUv * 5.0)));\n\n vec3 tangent = normalize(randomVec - viewNormal * dot(randomVec, viewNormal));\n\n vec3 bitangent = cross(viewNormal, tangent);\n\n mat3 TBN = mat3(tangent, bitangent, viewNormal);\n\n float occlusion = 0.0;\n\n for (int i = 0; i < MAX_KERNEL_SIZE; i++){\n \n vec3 sampleVector = TBN * kernel[i];\n sampleVector = viewPosition + sampleVector * sampleRadius;\n\n vec4 offset = projMatrix * vec4(sampleVector, 1.0);\n offset.xyz /= offset.w;\n offset.xyz = offset.xyz * 0.5 + 0.5;\n\n float realDepth = texture2D(tDepth, offset.xy).r;\n vec3 realPos = viewPosFromDepth(realDepth, offset.xy);\n\n float rangeCheck = smoothstep(0.0, 1.0, sampleRadius / length(viewPosition - realPos));\n\n occlusion += (realPos.z >= sampleVector.z + bias ? 1.0 : 0.0) * rangeCheck;\n }\n\n float occlusionFactor = 1.0 - clamp(occlusion / float(MAX_KERNEL_SIZE), 0.0, 1.0);\n\n gl_FragColor = vec4(vec3(occlusionFactor), 1.0);\n}"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Copyright Cognite (C) 2021 Cognite\n//\n// Efficient Gaussian blur based on technique described by Daniel Rákos in\n// http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/\n// generalized for two dimensions\n\nvarying vec2 vUv;\n\nuniform sampler2D tDiffuse;\nuniform sampler2D tAmbientOcclusion;\n\nuniform vec2 resolution;\n\nvoid main() {\n float blurredAO =\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, -3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, -3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, -1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, -1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, -3.1111111) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, -1.3333333) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, -3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, -3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, -1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, -1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 0.0000000) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 0.0000000) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, 1.3333333) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, 3.1111111) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 0.0000000) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 0.0000000) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv).r * 0.0747681;\n\n gl_FragColor = vec4(texture2D(tDiffuse, vUv).rgb * blurredAO, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// From http://www.science-and-fiction.org/rendering/noise.html\nfloat rand2d(in vec2 co){\n return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying mediump vec3 v_color;\nvarying lowp float v_coverageFactor;\nvarying lowp float v_visible;\nvarying lowp vec2 v_seed;\n\nvarying vec3 v_viewPosition;\n \nconst NodeAppearance dummyNodeAppearance = NodeAppearance(vec4(0.0), false, false, false);\n\nvoid main() {\n if(v_visible != 1.0 || isClipped(dummyNodeAppearance, v_viewPosition)){\n discard;\n }\n\n float v = rand2d(gl_FragCoord.xy + v_seed);\n if (v >= v_coverageFactor) {\n discard;\n }\n\n gl_FragColor = vec4(v_color, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nattribute mediump float a_sectorId;\nattribute lowp vec3 a_coverageFactor;\nattribute lowp float a_visible;\n\nvarying mediump vec3 v_color;\nvarying lowp float v_coverageFactor;\nvarying lowp vec2 v_seed;\nvarying lowp float v_visible;\n\nvarying vec3 v_viewPosition;\n\nvoid main()\n{\n v_visible = a_visible;\n v_color = packIntToColor(a_sectorId);\n v_coverageFactor = abs(dot(a_coverageFactor, normal));\n // A seed to ensure that two overlapping sectors A and B \n // doesn't produce the same noise pattern\n v_seed = vec2(a_sectorId / 255.0, a_sectorId / 65025.0);\n\n vec4 mvPosition = modelViewMatrix * instanceMatrix * vec4( position, 1.0 );\n\n v_viewPosition = mvPosition.xyz;\n\n gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);\n}\n"},,function(e,t,n){"use strict";n.r(t),n.d(t,"NodeAppearanceProvider",(function(){return x})),n.d(t,"NodeOutlineColor",(function(){return r})),n.d(t,"NodeCollectionBase",(function(){return s})),n.d(t,"TreeIndexNodeCollection",(function(){return u})),n.d(t,"IntersectionNodeCollection",(function(){return c})),n.d(t,"UnionNodeCollection",(function(){return l})),n.d(t,"revealEnv",(function(){return a.r})),n.d(t,"IndexSet",(function(){return a.e})),n.d(t,"NumericRange",(function(){return a.h})),n.d(t,"BoundingBoxClipper",(function(){return rn.a})),n.d(t,"Cognite3DModel",(function(){return U})),n.d(t,"Cognite3DViewer",(function(){return yn})),n.d(t,"CognitePointCloudModel",(function(){return j})),n.d(t,"PotreePointShape",(function(){return gt})),n.d(t,"PotreePointColorType",(function(){return yt})),n.d(t,"PotreePointSizeType",(function(){return Tt})),n.d(t,"WellKnownAsprsPointClassCodes",(function(){return Ct})),n.d(t,"NotSupportedInMigrationWrapperError",(function(){return F})),n.d(t,"PropertyFilterNodeCollection",(function(){return te})),n.d(t,"SinglePropertyFilterNodeCollection",(function(){return re})),n.d(t,"AssetNodeCollection",(function(){return J})),n.d(t,"InvertedNodeCollection",(function(){return ne})),n.d(t,"registerCustomNodeCollectionType",(function(){return se})),n.d(t,"THREE",(function(){return y})),n.d(t,"DefaultNodeAppearance",(function(){return h}));var r,o=n(7),i=n.n(o),a=n(1);
174
+ class o{constructor(e){this._clippingPlanes=[new r.Plane,new r.Plane,new r.Plane,new r.Plane,new r.Plane,new r.Plane],this._box=e||new r.Box3,this.updatePlanes()}set minX(e){this._box.min.x=e,this.updatePlanes()}get minX(){return this._box.min.x}set minY(e){this._box.min.y=e,this.updatePlanes()}get minY(){return this._box.min.y}set minZ(e){this._box.min.z=e,this.updatePlanes()}get minZ(){return this._box.min.z}set maxX(e){this._box.max.x=e,this.updatePlanes()}get maxX(){return this._box.max.x}set maxY(e){this._box.max.y=e,this.updatePlanes()}get maxY(){return this._box.max.y}set maxZ(e){this._box.max.z=e,this.updatePlanes()}get maxZ(){return this._box.max.z}updatePlanes(){this._clippingPlanes[0].setFromNormalAndCoplanarPoint(new r.Vector3(1,0,0),new r.Vector3(this.minX,0,0)),this._clippingPlanes[1].setFromNormalAndCoplanarPoint(new r.Vector3(-1,0,0),new r.Vector3(this.maxX,0,0)),this._clippingPlanes[2].setFromNormalAndCoplanarPoint(new r.Vector3(0,1,0),new r.Vector3(0,this.minY,0)),this._clippingPlanes[3].setFromNormalAndCoplanarPoint(new r.Vector3(0,-1,0),new r.Vector3(0,this.maxY,0)),this._clippingPlanes[4].setFromNormalAndCoplanarPoint(new r.Vector3(0,0,1),new r.Vector3(0,0,this.minZ)),this._clippingPlanes[5].setFromNormalAndCoplanarPoint(new r.Vector3(0,0,-1),new r.Vector3(0,0,this.maxZ))}get clippingPlanes(){return this._clippingPlanes}}},function(e,t){e.exports=require("lodash/debounce")},function(e,t){e.exports=require("lodash/range")},,function(e,t){e.exports=require("comlink")},function(e,t){e.exports=require("loglevel")},function(e,t){e.exports=require("skmeans")},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_normal;\nvarying vec3 v_color;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\nvarying vec3 v_normal;\nvarying vec3 v_color;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize;\nuniform sampler2D transformOverrideTexture;\n\nvoid main()\n{\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * instanceMatrix * vec4(normalize(normal), 0.0)).xyz;\n //v_normal = normal;\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(transformed, 1.0);\n vViewPosition = modelViewPosition.xyz;\n gl_Position = projectionMatrix * modelViewPosition;\n}"},function(e,t){e.exports=require("@cognite/sdk")},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n"},function(e,t){e.exports=require("lodash/omit")},function(e,t){e.exports=require("lodash/chunk")},function(e,t){e.exports=require("lodash/throttle")},,function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n updateFragmentColor(renderMode, color, v_treeIndex, v_normal, gl_FragCoord.z, matCapTexture, GeometryType.Quad);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec3 color;\nattribute float treeIndex;\nattribute vec4 matrix0;\nattribute vec4 matrix1;\nattribute vec4 matrix2;\nattribute vec4 matrix3;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n \n mat4 treeIndexWorldTransform = determineMatrixOverride(\n treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_treeIndex = treeIndex;\n v_color = color;\n v_normal = normalize(normalMatrix * (inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(normal), 0.0)).xyz);\n mat4 instanceMatrix = mat4(matrix0, matrix1, matrix2, matrix3);\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 derivateNormal(vec3 v_viewPosition) {\n vec3 fdx = vec3(dFdx(v_viewPosition.x), dFdx(v_viewPosition.y), dFdx(v_viewPosition.z));\n vec3 fdy = vec3(dFdy(v_viewPosition.x), dFdy(v_viewPosition.y), dFdy(v_viewPosition.z));\n vec3 normal = normalize(cross(fdx, fdy));\n return normal;\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform int renderMode;\n\nvoid main()\n{\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, v_viewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = derivateNormal(v_viewPosition);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.TriangleMesh);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nattribute vec3 color;\nattribute float treeIndex; \n\nvarying vec3 v_color;\nvarying float v_treeIndex;\nvarying vec3 v_viewPosition;\n\nuniform vec2 treeIndexTextureSize;\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize;\nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n v_color = color;\n v_treeIndex = treeIndex;\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(position, 1.0);\n v_viewPosition = modelViewPosition.xyz;\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 derivateNormal(vec3 v_viewPosition) {\n vec3 fdx = vec3(dFdx(v_viewPosition.x), dFdx(v_viewPosition.y), dFdx(v_viewPosition.z));\n vec3 fdy = vec3(dFdy(v_viewPosition.x), dFdy(v_viewPosition.y), dFdy(v_viewPosition.z));\n vec3 normal = normalize(cross(fdx, fdy));\n return normal;\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, v_viewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = derivateNormal(v_viewPosition);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.InstancedMesh);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_viewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main()\n{\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n v_color = a_color;\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 modelViewPosition = viewMatrix * modelMatrix * vec4(transformed, 1.0);\n v_viewPosition = modelViewPosition.xyz;\n v_treeIndex = a_treeIndex;\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec2 v_xy;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n float dist = dot(v_xy, v_xy);\n vec3 normal = normalize( v_normal );\n if (dist > 0.25)\n discard;\n \n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_normal;\n\nvarying vec2 v_xy;\nvarying vec3 v_color;\nvarying vec3 v_normal;\nvarying float v_treeIndex;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n v_xy = vec2(position.x, position.y);\n v_treeIndex = a_treeIndex;\n\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n v_color = a_color;\n\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(a_normal), 0.0)).xyz;\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\n\nvarying vec4 v_centerB;\n\nvarying vec4 v_W;\nvarying vec4 v_U;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec4 v_centerA;\nvarying vec4 v_V;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec3 normal = normalize( v_normal );\n vec4 color = determineColor(v_color, appearance);\n\n float R1 = v_centerB.w;\n vec4 U = v_U;\n vec4 W = v_W;\n vec4 V = v_V;\n float height = length(v_centerA.xyz - v_centerB.xyz);\n float R2 = v_centerA.w;\n float dR = R2 - R1;\n\n mat3 basis = mat3(U.xyz, V.xyz, W.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, W.w);\n vec3 rayTarget = surfacePoint;\n\n #if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n #else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n #endif\n\n vec3 diff = rayTarget - v_centerB.xyz;\n vec3 E = diff * basis;\n vec3 D = rayDirection * basis;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy) - R1*R1;\n\n if (R1 != R2) {\n // Additional terms if radii are different\n float dRLInv = dR / height;\n float dRdRL2Inv = dRLInv * dRLInv;\n a -= D.z * D.z * dRdRL2Inv;\n b -= dRLInv * (E.z * D.z * dRLInv + R1 * D.z);\n c -= dRLInv * (E.z * E.z * dRLInv + 2.0 * R1 * E.z);\n }\n\n // Calculate a dicriminant of the above quadratic equation\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long cone\n if (d < 0.0) {\n discard;\n }\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n vec3 intersectionPoint = E + dist * D;\n float theta = atan(intersectionPoint.y, intersectionPoint.x);\n if (theta < v_angle) theta += 2.0 * PI;\n\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n bool isInner = false;\n\n if (intersectionPoint.z <= 0.0 ||\n intersectionPoint.z > height ||\n theta > v_angle + v_arcAngle ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n isInner = true;\n dist = dist2;\n intersectionPoint = E + dist * D;\n theta = atan(intersectionPoint.y, intersectionPoint.x);\n p = rayTarget + dist*rayDirection;\n if (theta < v_angle) theta += 2.0 * PI;\n if (intersectionPoint.z <= 0.0 ||\n intersectionPoint.z > height ||\n theta > v_angle + v_arcAngle ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n #if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n if (R1 != R2)\n {\n // Find normal vector\n vec3 n = -normalize(W.xyz);\n vec3 P1 = v_centerB.xyz;\n vec3 P2 = v_centerA.xyz;\n vec3 A = cross(P1 - p, P2 - p);\n\n vec3 t = normalize(cross(n, A));\n vec3 o1 = P1 + R1 * t;\n vec3 o2 = P2 + R2 * t;\n vec3 B = o2-o1;\n normal = normalize(cross(A, B));\n }\n else\n {\n // Regular cylinder has simpler normal vector in camera space\n vec3 p_local = p - v_centerB.xyz;\n normal = normalize(p_local - W.xyz * dot(p_local, W.xyz));\n }\n #endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radiusA;\nattribute float a_radiusB;\nattribute vec3 a_color;\n// segment attributes\nattribute vec3 a_localXAxis;\nattribute float a_angle;\nattribute float a_arcAngle;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 v_U;\nvarying vec4 v_W;\n\nvarying vec4 v_centerA;\nvarying vec4 v_V;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 center = 0.5 * (centerA + centerB);\n float halfHeight = 0.5 * length(centerA - centerB);\n vec3 dir = normalize(centerA - centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n float maxRadius = max(a_radiusA, a_radiusB);\n float leftUpScale = maxRadius;\n\n vec3 lDir = dir;\n if (dot(objectToCameraModelSpace, dir) < 0.0) { // direction vector looks away, flip it\n lDir = -lDir;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (maxRadius * (position.x + 1.0) * 0.0025 / halfHeight);\n#endif\n\n vec3 surfacePoint = center + mat3(halfHeight*lDir, leftUpScale*left, leftUpScale*up) * newPosition;\n vec3 transformed = surfacePoint;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // varying data\n v_treeIndex = a_treeIndex;\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n // compute basis for cone\n v_W.xyz = dir;\n v_U.xyz = (modelTransformOffset * vec4(a_localXAxis, 0.0)).xyz;\n v_W.xyz = normalize(normalMatrix * v_W.xyz);\n v_U.xyz = normalize(normalMatrix * v_U.xyz);\n // We pack surfacePoint as w-components of U and W\n v_W.w = surfacePoint.z;\n v_U.w = surfacePoint.x;\n\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n\n float radiusB = length((modelToTransformOffset * vec4(a_localXAxis * a_radiusB, 0.0)).xyz);\n float radiusA = length((modelToTransformOffset * vec4(a_localXAxis * a_radiusA, 0.0)).xyz);\n\n // We pack radii as w-components of v_centerB\n v_centerB.xyz = mul3(modelViewMatrix, centerB);\n v_centerB.w = radiusB;\n\n v_V.xyz = -cross(v_U.xyz, v_W.xyz);\n v_V.w = surfacePoint.y;\n\n v_centerA.xyz = mul3(modelViewMatrix, centerA);\n v_centerA.w = radiusA;\n\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\n\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 axis;\n\nvarying vec4 v_centerA;\nvarying vec4 v_centerB;\nvarying float height;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = normalize( v_normal );\n mat3 basis = mat3(U.xyz, V.xyz, axis.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, axis.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - v_centerA.xyz;\n vec3 E = diff * basis;\n float L = height;\n vec3 D = rayDirection * basis;\n\n float R1 = v_centerA.w;\n float R2 = v_centerB.w;\n float dR = R2 - R1;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy)-R1*R1;\n float L2Inv = 1.0/(L*L);\n\n if (R1 != R2) {\n // Additional terms if radii are different\n float dRLInv = dR/L;\n float dRdRL2Inv = dRLInv*dRLInv;\n a -= D.z*D.z*dRdRL2Inv;\n b -= dRLInv*(E.z*D.z*dRLInv + R1*D.z);\n c -= dRLInv*(E.z*E.z*dRLInv + 2.0*R1*E.z);\n }\n\n // Additional terms when one of the center points is displaced orthogonal to normal vector\n vec2 displacement = ((v_centerB.xyz-v_centerA.xyz)*basis).xy; // In the basis where displacement is in XY only\n float displacementLengthSquared = dot(displacement, displacement);\n a += D.z*(D.z*displacementLengthSquared - 2.0*L*dot(D.xy, displacement))*L2Inv;\n b += (D.z*E.z*displacementLengthSquared - L*(D.x*E.z*displacement.x + D.y*E.z*displacement.y + D.z*E.x*displacement.x + D.z*E.y*displacement.y))*L2Inv;\n c += E.z*(E.z*displacementLengthSquared - 2.*L*dot(E.xy, displacement))*L2Inv;\n\n // Calculate a dicriminant of the above quadratic equation (factor 2 removed from all b-terms above)\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long eccentric cone\n if (d < 0.0) {\n discard;\n }\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n // Check the smallest root, it is closest camera. Only test if the z-component is outside the truncated eccentric cone\n float dist = dist1;\n float intersectionPointZ = E.z + dist*D.z;\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n bool isInner = false;\n\n if (intersectionPointZ <= 0.0 ||\n intersectionPointZ >= L ||\n isClipped(appearance, p)\n ) {\n // Either intersection point is behind starting point (happens inside the cone),\n // or the intersection point is outside the end caps. This is not a valid solution.\n isInner = true;\n dist = dist2;\n intersectionPointZ = E.z + dist*D.z;\n p = rayTarget + dist*rayDirection;\n\n if (intersectionPointZ <= 0.0 ||\n intersectionPointZ >= L ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Find normal vector\n vec3 n = normalize(-axis.xyz);\n vec3 v_centerA = v_centerA.xyz;\n vec3 v_centerB = v_centerB.xyz;\n vec3 A = cross(v_centerA - p, v_centerB - p);\n\n vec3 t = normalize(cross(n, A));\n vec3 o1 = v_centerA + R1 * t;\n vec3 o2 = v_centerB + R2 * t;\n vec3 B = o2-o1;\n normal = normalize(cross(A, B));\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radiusA;\nattribute float a_radiusB;\nattribute vec3 a_normal;\nattribute vec3 a_color;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerA;\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 axis;\nvarying float height;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 normalWithOffset = normalize((modelTransformOffset * vec4(a_normal, 0)).xyz);\n\n float uniformScaleFactor = length(mul3(modelMatrix, normalize(vec3(1.0))));\n\n height = dot(centerA - centerB, normalWithOffset) * uniformScaleFactor;\n\n vec3 lDir;\n vec3 center = 0.5 * (centerA + centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n // Find the coordinates of centerA and centerB projected down to the end cap plane\n vec3 maxCenterProjected = centerA - dot(centerA, normalWithOffset) * normalWithOffset;\n vec3 minCenterProjected = centerB - dot(centerB, normalWithOffset) * normalWithOffset;\n float distanceBetweenProjectedCenters = length(maxCenterProjected - minCenterProjected);\n\n lDir = normalWithOffset;\n float dirSign = 1.0;\n if (dot(objectToCameraModelSpace, lDir) < 0.0) { // direction vector looks away, flip it\n dirSign = -1.0;\n lDir *= -1.;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n // compute basis for cone\n axis.xyz = -normalWithOffset;\n U.xyz = cross(objectToCameraModelSpace, axis.xyz);\n V.xyz = cross(U.xyz, axis.xyz);\n // Transform to camera space\n axis.xyz = normalize(normalMatrix * axis.xyz);\n U.xyz = normalize(normalMatrix * U.xyz);\n V.xyz = normalize(normalMatrix * V.xyz);\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_radiusA * (position.x + 1.0) * 0.0025 / height);\n#endif\n\n v_centerA.xyz = mul3(viewMatrix, mul3(modelMatrix, centerA));\n v_centerB.xyz = mul3(viewMatrix, mul3(modelMatrix, centerB));\n\n float radiusA = length((modelToTransformOffset * vec4(normalize(vec3(1.0)) * a_radiusA, 0.0)).xyz);\n float radiusB = length((modelToTransformOffset * vec4(normalize(vec3(1.0)) * a_radiusB, 0.0)).xyz);\n\n // Pack radii as w components of v_centerA and v_centerB\n v_centerA.w = radiusA;\n v_centerB.w = radiusB;\n\n float radiusIncludedDisplacement = 0.5*(2.0*max(a_radiusA, a_radiusB) + distanceBetweenProjectedCenters);\n vec3 surfacePoint = center + mat3(0.5 * height * lDir * (1.0 / uniformScaleFactor), radiusIncludedDisplacement*left, radiusIncludedDisplacement*up) * newPosition;\n vec3 transformed = surfacePoint;\n\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // We pack surfacePoint as w-components of U, V and axis\n U.w = surfacePoint.x;\n V.w = surfacePoint.y;\n axis.w = surfacePoint.z;\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform mat4 projectionMatrix;\nvarying vec4 center;\nvarying float hRadius;\nvarying float height;\n\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 sphereNormal;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n vec3 normal = normalize(sphereNormal.xyz);\n\n float vRadius = center.w;\n float ratio = vRadius / hRadius;\n mat3 basis = mat3(U.xyz, V.xyz, sphereNormal.xyz);\n mat3 scaledBasis = mat3(ratio * U.xyz, ratio * V.xyz, sphereNormal.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, sphereNormal.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - center.xyz;\n vec3 E = diff * scaledBasis;\n vec3 D = rayDirection * scaledBasis;\n\n float a = dot(D, D);\n float b = dot(E, D);\n float c = dot(E, E) - vRadius*vRadius;\n\n // discriminant of sphere equation (factor 2 removed from b above)\n float d = b*b - a*c;\n if(d < 0.0)\n discard;\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n float intersectionPointZ = E.z + dist*D.z;\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n if (intersectionPointZ <= vRadius - height ||\n intersectionPointZ > vRadius ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n\n dist = dist2;\n intersectionPointZ = E.z + dist*D.z;\n p = rayTarget + dist*rayDirection;\n if (intersectionPointZ <= vRadius - height ||\n intersectionPointZ > vRadius ||\n isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Find normal vector in local space\n normal = vec3(p - center.xyz) * basis;\n normal.z = normal.z * (hRadius / vRadius) * (hRadius / vRadius);\n // Transform into camera space\n normal = normalize(basis * normal);\n if (dot(normal, rayDirection) > 0.) {\n normal = -normal;\n }\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\nuniform mat4 inverseNormalMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_center;\nattribute vec3 a_normal;\nattribute float a_horizontalRadius;\nattribute float a_verticalRadius;\nattribute float a_height;\n\nvarying float v_treeIndex;\n// We pack vRadius as w-component of center\nvarying vec4 center;\nvarying float hRadius;\nvarying float height;\n\n// U, V, axis represent the 3x3 sphere basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 U;\nvarying vec4 V;\nvarying vec4 sphereNormal;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerWithOffset = mul3(modelTransformOffset, a_center).xyz;\n\n vec3 normalWithOffset = (modelTransformOffset * vec4(a_normal, 0)).xyz;\n\n vec3 lDir;\n float distanceToCenterOfSegment = a_verticalRadius - a_height * 0.5;\n vec3 centerOfSegment = centerWithOffset + normalWithOffset * distanceToCenterOfSegment;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 objectToCameraModelSpace = inverseNormalMatrix * vec3(0.0, 0.0, 1.0);\n#else\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - centerOfSegment;\n#endif\n\n vec3 newPosition = position;\n\n float bb = dot(objectToCameraModelSpace, normalWithOffset);\n if (bb < 0.0) { // direction vector looks away, flip it\n lDir = -normalWithOffset;\n } else { // direction vector already looks in my direction\n lDir = normalWithOffset;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_verticalRadius * (position.x + 1.0) * 0.0025 / a_height);\n#endif\n\n // Negative angle means height larger than radius,\n // so we should have full size so we can render the largest part of the ellipsoid segment\n float ratio = max(0.0, 1.0 - a_height / a_verticalRadius);\n // maxRadiusOfSegment is the radius of the circle (projected ellipsoid) when ellipsoid segment is seen from above\n float maxRadiusOfSegment = a_horizontalRadius * sqrt(1.0 - ratio * ratio);\n\n vec3 displacement = vec3(newPosition.x*a_height*0.5, maxRadiusOfSegment*newPosition.y, maxRadiusOfSegment*newPosition.z);\n vec3 surfacePoint = centerOfSegment + mat3(lDir, left, up) * displacement;\n vec3 transformed = surfacePoint;\n\n v_treeIndex = a_treeIndex;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n center.xyz = mul3(modelViewMatrix, centerWithOffset);\n center.w = a_verticalRadius; // Pack radius into w-component\n hRadius = a_horizontalRadius;\n height = a_height;\n v_color = a_color;\n\n // compute basis\n sphereNormal.xyz = normalMatrix * normalWithOffset;\n U.xyz = normalMatrix * up;\n V.xyz = normalMatrix * left;\n\n // We pack surfacePoint as w-components of U, V and axis\n U.w = surfacePoint.x;\n V.w = surfacePoint.y;\n sphereNormal.w = surfacePoint.z;\n\n // TODO should perhaps be a different normal?\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n'},function(e,t,n){"use strict";n.r(t),t.default='#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\nfloat displaceScalar(vec3 point, float scalar, \n float treeIndex, vec3 cameraPosition, mat4 inverseModelMatrix) {\n\n // Displaces a scalar based on distance to camera to avoid z-fighting\n vec3 cameraPositionModelSpace = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 pointToCamera = cameraPositionModelSpace - point;\n\n // "Random" number in the range [0, 1], based on treeIndex\n float rnd = mod(treeIndex, 64.) / 64.;\n // Compute distance to camera, but cap it\n float maxDistanceToCamera = 50.;\n float distanceToCamera = min(length(pointToCamera), maxDistanceToCamera);\n\n float maxDisplacement = 0.01;\n float scaleFactor = 0.01;\n float displacement = min(maxDisplacement, scaleFactor * rnd * distanceToCamera / maxDistanceToCamera);\n return scalar + displacement;\n}\n\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\n// TODO general cylinder and cone are very similar and used\n// the same shader in the old code. Consider de-duplicating\n// parts of this code\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform float dataTextureWidth;\nuniform float dataTextureHeight;\nuniform mat4 projectionMatrix;\n\nvarying vec4 v_centerB;\n\nvarying vec4 v_W;\nvarying vec4 v_U;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying float v_surfacePointY;\n\nvarying vec4 v_planeA;\nvarying vec4 v_planeB;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform int renderMode;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize( v_normal );\n\n float R1 = v_centerB.w;\n vec4 U = v_U;\n vec4 W = v_W;\n vec4 V = vec4(normalize(cross(W.xyz, U.xyz)), v_surfacePointY);\n\n mat3 basis = mat3(U.xyz, V.xyz, W.xyz);\n vec3 surfacePoint = vec3(U.w, V.w, W.w);\n vec3 rayTarget = surfacePoint;\n\n#if defined(COGNITE_ORTHOGRAPHIC_CAMERA)\n vec3 rayDirection = vec3(0.0, 0.0, -1.0);\n#else\n vec3 rayDirection = normalize(rayTarget); // rayOrigin is (0,0,0) in camera space\n#endif\n\n vec3 diff = rayTarget - v_centerB.xyz;\n vec3 E = diff * basis;\n vec3 D = rayDirection * basis;\n\n float a = dot(D.xy, D.xy);\n float b = dot(E.xy, D.xy);\n float c = dot(E.xy, E.xy) - R1*R1;\n\n // Calculate a dicriminant of the above quadratic equation\n float d = b*b - a*c;\n\n // d < 0.0 means the ray hits outside an infinitely long cone\n if (d < 0.0)\n discard;\n\n float sqrtd = sqrt(d);\n float dist1 = (-b - sqrtd)/a;\n float dist2 = (-b + sqrtd)/a;\n\n // Make sure dist1 is the smaller one\n if (dist2 < dist1) {\n float tmp = dist1;\n dist1 = dist2;\n dist2 = tmp;\n }\n\n float dist = dist1;\n vec3 intersectionPoint = E + dist * D;\n float theta = atan(intersectionPoint.y, intersectionPoint.x);\n if (theta < v_angle) theta += 2.0 * PI;\n\n // Intersection point in camera space\n vec3 p = rayTarget + dist*rayDirection;\n\n vec3 planeACenter = vec3(0.0, 0.0, v_planeA.w);\n vec3 planeANormal = v_planeA.xyz;\n vec3 planeBCenter = vec3(0.0, 0.0, v_planeB.w);\n vec3 planeBNormal = v_planeB.xyz;\n bool isInner = false;\n\n if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||\n dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||\n theta > v_arcAngle + v_angle ||\n isClipped(appearance, p)\n ) {\n // Missed the first point, check the other point\n isInner = true;\n dist = dist2;\n intersectionPoint = E + dist * D;\n theta = atan(intersectionPoint.y, intersectionPoint.x);\n p = rayTarget + dist*rayDirection;\n if (theta < v_angle) theta += 2.0 * PI;\n if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||\n dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||\n theta > v_arcAngle + v_angle || isClipped(appearance, p)\n ) {\n // Missed the other point too\n discard;\n }\n }\n\n#if !defined(COGNITE_RENDER_COLOR_ID) && !defined(COGNITE_RENDER_DEPTH)\n // Regular cylinder has simpler normal vector in camera space\n vec3 p_local = p - v_centerB.xyz;\n normal = normalize(p_local - W.xyz * dot(p_local, W.xyz));\n#endif\n\n float fragDepth = updateFragmentDepth(p, projectionMatrix);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, fragDepth, matCapTexture, GeometryType.Primitive);\n}\n'},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 mul3(mat4 M, vec3 v) {\n vec4 u = M * vec4(v, 1.0);\n return u.xyz / u.w;\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_centerA;\nattribute vec3 a_centerB;\nattribute float a_radius;\nattribute vec3 a_color;\n// slicing plane attributes\nattribute vec4 a_planeA;\nattribute vec4 a_planeB;\n// segment attributes\nattribute vec3 a_localXAxis;\nattribute float a_angle;\nattribute float a_arcAngle;\n\nvarying float v_treeIndex;\n// We pack the radii into w-components\nvarying vec4 v_centerB;\n\n// U, V, axis represent the 3x3 cone basis.\n// They are vec4 to pack extra data into the w-component\n// since Safari on iOS only supports 8 varying vec4 registers.\nvarying vec4 v_U;\nvarying vec4 v_W;\n\nvarying vec4 v_planeA;\nvarying vec4 v_planeB;\n\nvarying float v_surfacePointY;\n\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n \n mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix;\n\n vec3 centerA = mul3(modelTransformOffset, a_centerA);\n vec3 centerB = mul3(modelTransformOffset, a_centerB);\n\n vec3 center = 0.5 * (centerA + centerB);\n float halfHeight = 0.5 * length(centerA - centerB);\n vec3 dir = normalize(centerA - centerB);\n vec3 newPosition = position;\n\n vec3 rayOrigin = (inverseModelMatrix * vec4(cameraPosition, 1.0)).xyz;\n vec3 objectToCameraModelSpace = rayOrigin - center;\n\n float leftUpScale = a_radius;\n\n vec3 lDir = dir;\n if (dot(objectToCameraModelSpace, dir) < 0.0) { // direction vector looks away, flip it\n lDir = -lDir;\n }\n\n vec3 left = normalize(cross(objectToCameraModelSpace, lDir));\n vec3 up = normalize(cross(left, lDir));\n\n#ifndef GL_EXT_frag_depth\n // make sure the billboard will not overlap with cap geometry (flickering effect), not important if we write to depth buffer\n newPosition.x *= 1.0 - (a_radius * (position.x + 1.0) * 0.0025 / halfHeight);\n#endif\n\n vec3 surfacePoint = center + mat3(halfHeight*lDir, leftUpScale*left, leftUpScale*up) * newPosition;\n vec3 transformed = surfacePoint;\n surfacePoint = mul3(modelViewMatrix, surfacePoint);\n\n // varying data\n v_treeIndex = a_treeIndex;\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n // compute basis for cone\n v_W.xyz = dir;\n v_U.xyz = (modelTransformOffset * vec4(a_localXAxis, 0)).xyz;\n v_W.xyz = normalize(normalMatrix * v_W.xyz);\n v_U.xyz = normalize(normalMatrix * v_U.xyz);\n // We pack surfacePoint as w-components of U and W\n v_W.w = surfacePoint.z;\n v_U.w = surfacePoint.x;\n\n // We pack radii as w-components of v_centerB\n mat4 modelToTransformOffset = modelMatrix * modelTransformOffset;\n float radius = length((modelToTransformOffset * vec4(a_localXAxis * a_radius, 0.0)).xyz);\n\n centerB = centerB - dir;\n v_centerB.xyz = mul3(modelViewMatrix, centerB);\n v_centerB.w = radius;\n\n vec4 planeA = a_planeA;\n planeA.w = length((modelToTransformOffset * vec4(planeA.xyz * planeA.w, 0.0)).xyz);\n\n vec4 planeB = a_planeB;\n planeB.w = length((modelToTransformOffset * vec4(planeB.xyz * planeB.w, 0.0)).xyz);\n\n v_planeA = planeA;\n v_planeB = planeB;\n v_surfacePointY = surfacePoint.y;\n v_centerB.w = radius;\n\n v_color = a_color;\n v_normal = normalMatrix * normal;\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat computeFragmentDepth(vec3 p, mat4 projectionMatrix) {\n // Anders Hafreager comments:\n // Depth value can be calculated by transforming the z-component of the intersection point to projection space.\n // The w-component is also needed to scale projection space into clip space.\n // However, the 4th column of the projection matrix is (0, 0, const, 0), so we can exploit this when computing w-value.\n float projected_intersection_z=projectionMatrix[0][2]*p.x+projectionMatrix[1][2]*p.y+projectionMatrix[2][2]*p.z+projectionMatrix[3][2];\n\n // If we want to use orthographic camera, the full w-component is found as\n float projected_intersection_w=projectionMatrix[0][3]*p.x+projectionMatrix[1][3]*p.y+projectionMatrix[2][3]*p.z+projectionMatrix[3][3];\n // float projected_intersection_w = projectionMatrix[2][3]*newPoint.z; // Optimized for perspective camera\n return ((gl_DepthRange.diff * (projected_intersection_z / projected_intersection_w)) + gl_DepthRange.near + gl_DepthRange.far) * .5;\n}\n\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n\nfloat updateFragmentDepth(vec3 p,mat4 projectionMatrix) {\n gl_FragDepthEXT = computeFragmentDepth(p, projectionMatrix);\n return gl_FragDepthEXT;\n}\n\n#else\n\nfloat updateFragmentDepth(vec3 p, mat4 projectionMatrix){\n // Extension not available - not much we can do.\n return computeFragmentDepth(p, projectionMatrix);\n}\n\n#endif\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_0) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_0) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_0));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_1 || renderMode == RenderTypeEffects_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_1) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_1) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_1) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_1) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_1) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n\nvarying float v_oneMinusThicknessSqr;\nvarying vec2 v_xy;\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance);\n float dist = dot(v_xy, v_xy);\n float theta = atan(v_xy.y, v_xy.x);\n vec3 normal = normalize( v_normal );\n if (theta < v_angle) {\n theta += 2.0 * PI;\n }\n if (dist > 0.25 || dist < 0.25 * v_oneMinusThicknessSqr || theta >= v_angle + v_arcAngle) {\n discard;\n }\n\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute float a_angle;\nattribute float a_arcAngle;\nattribute float a_thickness;\nattribute vec3 a_normal;\n\nvarying float v_treeIndex;\nvarying float v_oneMinusThicknessSqr;\nvarying vec2 v_xy;\nvarying float v_angle;\nvarying float v_arcAngle;\n\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n\n v_treeIndex = a_treeIndex;\n v_oneMinusThicknessSqr = (1.0 - a_thickness) * (1.0 - a_thickness);\n v_xy = vec2(position.x, position.y);\n v_angle = a_angle;\n v_arcAngle = a_arcAngle;\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 transformed = (instanceMatrix * vec4(position, 1.0)).xyz;\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n v_color = a_color;\n\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(normalize(a_normal), 0.0)).xyz;\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Not using the w-component to support using vec3 and vec4 as input\nmat4 constructMatrix(vec4 column_0, vec4 column_1, vec4 column_2, vec4 column_3) {\n return mat4(\n vec4(column_0.xyz, 0.0),\n vec4(column_1.xyz, 0.0),\n vec4(column_2.xyz, 0.0),\n vec4(column_3.xyz, 1.0)\n );\n}\n\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute vec4 a_instanceMatrix_column_0;\nattribute vec4 a_instanceMatrix_column_1;\nattribute vec4 a_instanceMatrix_column_2;\nattribute vec4 a_instanceMatrix_column_3;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute float a_arcAngle;\nattribute float a_radius;\nattribute float a_tubeRadius;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n mat4 instanceMatrix = constructMatrix(\n a_instanceMatrix_column_0,\n a_instanceMatrix_column_1,\n a_instanceMatrix_column_2,\n a_instanceMatrix_column_3\n );\n // normalized theta and phi are packed into positions\n float theta = position.x * a_arcAngle;\n float phi = position.y;\n float cosTheta = cos(theta);\n float sinTheta = sin(theta);\n vec3 pos3 = vec3(0);\n\n pos3.x = (a_radius + a_tubeRadius*cos(phi)) * cosTheta;\n pos3.y = (a_radius + a_tubeRadius*cos(phi)) * sinTheta;\n pos3.z = a_tubeRadius*sin(phi);\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n \n vec3 transformed = (instanceMatrix * vec4(pos3, 1.0)).xyz;\n\n // Calculate normal vectors if we're not picking\n vec3 center = (instanceMatrix * vec4(a_radius * cosTheta, a_radius * sinTheta, 0.0, 1.0)).xyz;\n vec3 objectNormal = normalize(transformed.xyz - center);\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(objectNormal, 0.0)).xyz;\n\n vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(transformed, 1.0);\n\n vViewPosition = modelViewPosition.xyz;\n\n gl_Position = projectionMatrix * modelViewPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nstruct GeometryTypeEnum {\n int Quad;\n int Primitive;\n int TriangleMesh;\n int InstancedMesh;\n};\n\nconst GeometryTypeEnum GeometryType = GeometryTypeEnum(1,2,3,4);\n\nconst int RenderTypeColor_0 = 1;\nconst int RenderTypeNormal_0 = 2;\nconst int RenderTypeTreeIndex_0 = 3;\nconst int RenderTypePackColorAndNormal_0 = 4;\nconst int RenderTypeDepth_0 = 5;\nconst int RenderTypeEffects_0 = 6;\nconst int RenderTypeGhost_0 = 7;\nconst int RenderTypeLOD = 8;\nconst int RenderTypeDepthBufferOnly = 9;\nconst int RenderTypeGeometryType = 10;\n\n#include <packing>\n\nvec3 packNormalToRgb( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvoid updateFragmentColor(\n int renderMode, vec4 color, float treeIndex, \n vec3 normal, float depth, sampler2D matCapTexture, \n int geometryType) {\n if (renderMode == RenderTypeColor_0 || renderMode == RenderTypeEffects_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n hsv.z = min(0.5 * hsv.z + 0.5, 1.0);\n vec3 colorRGB = hsv2rgb(hsv);\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n vec4 albedo = vec4(colorRGB * (0.4 + 0.6 * amplitude), 1.0);\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec4 mc = vec4(texture2D(matCapTexture, cap).rgb, 1.0);\n \n gl_FragColor = vec4(albedo.rgb * mc.rgb * 1.7, color.a);\n } else if (renderMode == RenderTypeGhost_0) {\n float amplitude = max(0.0, dot(normal, vec3(0.0, 0.0, 1.0)));\n float s = 0.4 + 0.6 * amplitude;\n gl_FragColor = vec4(vec3(s), 0.3);\n } else if (renderMode == RenderTypeDepthBufferOnly) {\n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n } else if (renderMode == RenderTypePackColorAndNormal_0) {\n vec3 hsv = rgb2hsv(color.rgb);\n float a = 0.0;\n if (hsv.y > 0.01) {\n if (hsv.z > 0.5) {\n // light color\n a = (0.55 + hsv.x * 0.45);\n } else {\n // dark color\n a = (0.1 + hsv.x * 0.45);\n }\n } else {\n // no saturation - grayscale\n a = hsv.z * 0.09;\n }\n gl_FragColor = vec4(packNormalToRgb(normal.rgb), a);\n } else if (renderMode == RenderTypeNormal_0) {\n gl_FragColor = vec4(packNormalToRgb(normal), 1.0);\n } else if (renderMode == RenderTypeTreeIndex_0) {\n gl_FragColor = vec4(packIntToColor(treeIndex), 1.0);\n } else if (renderMode == RenderTypeDepth_0) {\n gl_FragColor = packDepthToRGBA(depth);\n } else if (renderMode == RenderTypeLOD) {\n bool isHighDetail = geometryType != GeometryType.Quad;\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n gl_FragColor = isHighDetail ? vec4(vec3(0.0, 1.0, 0.0) * mc, color.a) : vec4(vec3(1.0, 1.0, 0.0) * mc, color.a);\n } else if (renderMode == RenderTypeGeometryType) {\n vec2 cap = normal.xy * 0.5 + 0.5;\n vec3 mc = texture2D(matCapTexture, cap).rgb * 1.5;\n vec3 geometryColor = \n float(geometryType == 1) * vec3(1.0, 0.0, 0.0) + // Quads\n float(geometryType == 2) * vec3(0.0, 1.0, 0.0) + // Primitives\n float(geometryType == 3) * vec3(0.0, 0.0, 1.0) + // Triangle meshes\n float(geometryType == 4) * vec3(1.0, 1.0, 0.0); // Instance meshes\n gl_FragColor = vec4(geometryColor * mc, color.a);\n } else {\n // Unknown render mode - should not happen. \n gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n }\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \n\nNodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, float treeIndex) {\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = textureSize.x;\n float dataTextureHeight = textureSize.y;\n\n float u = mod(treeIndex, dataTextureWidth);\n float v = floor(treeIndex / dataTextureWidth);\n float uCoord = (u + 0.5) / dataTextureWidth;\n float vCoord = (v + 0.5) / dataTextureHeight;\n vec2 treeIndexUv = vec2(uCoord, vCoord);\n \n vec4 texel = texture2D(nodeAppearanceTexture, treeIndexUv);\n float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);\n\n bool isVisible = floatBitsSubset(alphaUnwrapped, 0, 1) == 1.0;\n bool renderInFront = floatBitsSubset(alphaUnwrapped, 1, 2) == 1.0;\n bool renderGhosted = floatBitsSubset(alphaUnwrapped, 2, 3) == 1.0;\n\n return NodeAppearance(texel, isVisible, renderInFront, renderGhosted);\n}\n\nconst int RenderTypeColor_1 = 1;\nconst int RenderTypeNormal_1 = 2;\nconst int RenderTypeTreeIndex_1 = 3;\nconst int RenderTypePackColorAndNormal_1 = 4;\nconst int RenderTypeDepth_1 = 5;\nconst int RenderTypeEffects_1 = 6;\nconst int RenderTypeGhost_1 = 7;\n\nbool determineVisibility(NodeAppearance nodeAppearance, int renderMode) {\n return \n // In ghost mode\n ((renderMode == RenderTypeGhost_1) && nodeAppearance.isVisible && nodeAppearance.renderGhosted) ||\n // Not ghost mode\n ((renderMode != RenderTypeGhost_1) && \n !nodeAppearance.renderGhosted && nodeAppearance.isVisible && (nodeAppearance.renderInFront || renderMode != RenderTypeEffects_1));\n}\n\nvec4 determineColor(vec3 originalColor, NodeAppearance nodeAppearance) {\n vec4 overrideColor = nodeAppearance.colorTexel;\n if (any(greaterThan(overrideColor.rgb, vec3(0.0)))) {\n return overrideColor;\n }\n return vec4(originalColor.rgb, overrideColor.a);\n}\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nuniform sampler2D colorDataTexture;\nuniform sampler2D overrideVisibilityPerTreeIndex;\nuniform sampler2D matCapTexture;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform int renderMode;\n\nvarying vec3 vViewPosition;\n\nvoid main() {\n NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);\n if (!determineVisibility(appearance, renderMode)) {\n discard;\n }\n if (isClipped(appearance, vViewPosition)) {\n discard;\n }\n\n vec4 color = determineColor(v_color, appearance); \n vec3 normal = normalize(v_normal);\n updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// https://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float @ Arjan\nfloat unpackVec4ToFloat( vec4 packedFloat)\n{\n vec4 rgba = packedFloat;\n float sign = 1.0 - step(128.0, rgba.x) * 2.0;\n float exponent = 2.0 * mod(rgba.x, 128.0) + step(128.0, rgba.y) - 127.0;\n if (exponent == -127.0) return 0.0;\n float mantissa = mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;\n return sign * exp2(exponent - 23.0) * mantissa; \n}\n\nfloat unpackFloatFromRGBATexel(vec4 texel){\n float byteValueR = floor((texel.r * 255.0) + 0.5);\n float byteValueG = floor((texel.g * 255.0) + 0.5);\n float byteValueB = floor((texel.b * 255.0) + 0.5);\n float byteValueA = floor((texel.a * 255.0) + 0.5);\n\n return unpackVec4ToFloat(vec4(byteValueR, byteValueG, byteValueB, byteValueA));\n}\n\nmat4 determineMatrixOverride(\n float treeIndex, \n vec2 treeIndexTextureSize, \n sampler2D transformOverrideIndexTexture, \n vec2 transformOverrideTextureSize, \n sampler2D transformOverrideTexture\n) {\n\n treeIndex = floor(treeIndex + 0.5);\n float dataTextureWidth = treeIndexTextureSize.x;\n float dataTextureHeight = treeIndexTextureSize.y;\n\n float xTreeIndexTextureCoord = mod(treeIndex, dataTextureWidth);\n float yTreeIndexTextureCoord = floor(treeIndex / dataTextureWidth);\n\n vec2 indexUV = vec2((xTreeIndexTextureCoord + 0.5) / dataTextureWidth, (yTreeIndexTextureCoord + 0.5) / dataTextureHeight);\n\n vec3 indexTexel = texture2D(transformOverrideIndexTexture, indexUV).rgb;\n\n float index = floor(indexTexel.r * 256.0) * 65536.0 + floor(indexTexel.g * 256.0) * 256.0 + floor(indexTexel.b * 256.0);\n \n \n if(index == 0.0){\n return mat4(\n 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0, 0.0,\n 0.0, 0.0, 0.0, 1.0\n );\n }\n\n index = index - 1.0;\n float overridesPerRow = transformOverrideTextureSize.x / 16.0;\n\n float xOverrideTextureCoord = mod(index, overridesPerRow);\n float yOverrideTextureCoord = floor(index / overridesPerRow);\n\n float cellWidth = 1.0 / transformOverrideTextureSize.x;\n float cellHeight = 1.0 / transformOverrideTextureSize.y;\n\n float overrideU = (xOverrideTextureCoord / overridesPerRow) + cellWidth / 2.0;\n float overrideV = (yOverrideTextureCoord / transformOverrideTextureSize.y) + cellHeight / 2.0;\n\n vec2 overrideUV = vec2(overrideU, overrideV); \n\n float matrixElements[12];\n\n for(int i = 0; i < 12; i++){\n matrixElements[i] = unpackFloatFromRGBATexel(texture2D(transformOverrideTexture, overrideUV + vec2(float(i) * cellWidth, 0.0)));\n }\n \n return mat4(\n matrixElements[0], matrixElements[4], matrixElements[8], 0,\n matrixElements[1], matrixElements[5], matrixElements[9], 0,\n matrixElements[2], matrixElements[6], matrixElements[10], 0,\n matrixElements[3], matrixElements[7], matrixElements[11], 1\n );\n}\n\nuniform mat4 inverseModelMatrix;\n\nattribute float a_treeIndex;\nattribute vec3 a_color;\nattribute vec3 a_vertex1;\nattribute vec3 a_vertex2;\nattribute vec3 a_vertex3;\nattribute vec3 a_vertex4;\n\nvarying float v_treeIndex;\nvarying vec3 v_color;\nvarying vec3 v_normal;\n\nvarying vec3 vViewPosition;\n\nuniform vec2 treeIndexTextureSize;\n\nuniform sampler2D transformOverrideIndexTexture;\n\nuniform vec2 transformOverrideTextureSize; \nuniform sampler2D transformOverrideTexture;\n\nvoid main() {\n vec3 transformed;\n // reduce the avarage branchings\n if (position.x < 1.5) {\n transformed = position.x == 0.0 ? a_vertex1 : a_vertex2;\n } else {\n transformed = position.x == 2.0 ? a_vertex3 : a_vertex4;\n }\n\n mat4 treeIndexWorldTransform = determineMatrixOverride(\n a_treeIndex, \n treeIndexTextureSize, \n transformOverrideIndexTexture, \n transformOverrideTextureSize, \n transformOverrideTexture\n );\n\n vec3 objectNormal = cross(a_vertex1 - a_vertex2, a_vertex1 - a_vertex3);\n\n v_treeIndex = a_treeIndex;\n v_color = a_color;\n v_normal = normalMatrix * normalize(inverseModelMatrix * treeIndexWorldTransform * modelMatrix * vec4(objectNormal, 0.0)).xyz;\n\n vec4 mvPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4( transformed, 1.0 );\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nfloat floatBitsSubset(float inNumber, int fromLeastSignificantBitIndex, int toMostSignificantBitIndex) {\n float r = float(fromLeastSignificantBitIndex);\n float l = float(toMostSignificantBitIndex);\n\n float bitShift = pow(2.0, r);\n return mod(((inNumber - mod(inNumber, bitShift)) / bitShift), pow(2.0, l - r));\n}\n\n/*\n\nExample:\n\nGet the value from bit 2 to 4 (not inclusive)\n\ninput:\ninNumber = 173 = 1010_1101 , from=2, to=4\n\nexpected output = 1010_|11|01 = 3\n\n1) subtract any bits in the least significant bit-subset\n\n mod(inNumber=173, pow(2.0, from=2)) = mod(inNumber, 4) = 1\n \n inNumber - 1 = 172\n\n2) bitshift such that we remove the least significant bit-subset\n this is guaranteed to be devisible since we subtracted the remainder\n\n (inNumber=172) / pow(2.0, from=2) = 172 / 4 = 43 = 0010_1011\n\n3) lastly, remove the most significant bit-subset\n\n mod((inNumber=43), pow(2.0, to=4 - from=2) = mod(43, 4)\n\n mod(43, 4) = 3\n\n or in binary notation: 0000_0011 which is the expected result.\n\n*/ \nmat3 G[9];\n// hard coded matrix values!!!! as suggested in https://github.com/neilmendoza/ofxPostProcessing/blob/master/src/EdgePass.cpp#L45\nconst mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );\nconst mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );\nconst mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );\nconst mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );\nconst mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );\nconst mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );\nconst mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );\nconst mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );\nconst mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );\n\nfloat edgeDetectionFilter(sampler2D baseTexture, vec2 uv, vec2 resolution) {\n\n vec2 texel = vec2(1.0 / resolution.x, 1.0 / resolution.y);\n\n\tG[0] = g0,\n\tG[1] = g1,\n\tG[2] = g2,\n\tG[3] = g3,\n\tG[4] = g4,\n\tG[5] = g5,\n\tG[6] = g6,\n\tG[7] = g7,\n\tG[8] = g8;\n\n\tmat3 I;\n\tfloat cnv[9];\n\tvec3 neighbour;\n\n\t/* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */\n\tfor (int i=0; i<3; i++) {\n\t\tfor (int j=0; j<3; j++) {\n\t\t\tneighbour = texture2D(baseTexture, uv + texel * vec2(float(i)-1.0,float(j)-1.0) ).rgb;\n\t\t\tI[i][j] = length(neighbour);\n\t\t}\n\t}\n\n\t/* calculate the convolution values for all the masks */\n\tfor (int i=0; i<9; i++) {\n\t\tfloat dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);\n\t\tcnv[i] = dp3 * dp3;\n\t}\n\n\tfloat M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);\n\tfloat S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);\n\n float edgeStrength = sqrt(M/S);\n\n return edgeStrength;\n}\n\n#include <packing>\n\nvarying vec2 vUv;\n\nvarying vec2 vUv0;\nvarying vec2 vUv1;\nvarying vec2 vUv2;\nvarying vec2 vUv3;\n\nuniform sampler2D tFront;\nuniform sampler2D tFrontDepth;\n\nuniform sampler2D tBack;\nuniform sampler2D tBackDepth;\n\nuniform sampler2D tCustom;\nuniform sampler2D tCustomDepth;\n\nuniform sampler2D tGhost;\nuniform sampler2D tGhostDepth;\n\nuniform sampler2D tOutlineColors;\n\nuniform float cameraNear;\nuniform float cameraFar;\n\nuniform vec2 resolution;\n\nuniform float edgeStrengthMultiplier;\nuniform float edgeGrayScaleIntensity;\n\nconst float infinity = 1e20;\n\nfloat computeFloatEncodedOutlineIndex(float bitEncodedFloat){\n return floatBitsSubset(floor((bitEncodedFloat * 255.0) + 0.5), 5, 8);\n}\n\nvec4 computeNeighborOutlineIndices(sampler2D colorTexture){\n float outlineIndex0 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv0).a);\n float outlineIndex1 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv1).a);\n float outlineIndex2 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv2).a);\n float outlineIndex3 = computeFloatEncodedOutlineIndex(texture2D(colorTexture, vUv3).a);\n\n return vec4(outlineIndex0, outlineIndex1, outlineIndex2, outlineIndex3);\n}\n\nfloat toViewZ(float depth, float near, float far){\n float normalizedDepth = depth * 2.0 - 1.0;\n return 2.0 * near * far / (far + near - normalizedDepth * (far - near)); \n}\n\nvec4 computeNeighborAlphas(sampler2D colorTexture){\n float alpha0 = texture2D(colorTexture, vUv0).a;\n float alpha1 = texture2D(colorTexture, vUv1).a;\n float alpha2 = texture2D(colorTexture, vUv2).a;\n float alpha3 = texture2D(colorTexture, vUv3).a;\n\n return vec4(alpha0, alpha1, alpha2, alpha3);\n}\n\nvoid main() {\n vec4 frontAlbedo = texture2D(tFront, vUv);\n vec4 backAlbedo = texture2D(tBack, vUv);\n vec4 customAlbedo = texture2D(tCustom, vUv);\n vec4 ghostAlbedo = texture2D(tGhost, vUv);\n\n float frontDepth = texture2D(tFrontDepth, vUv).r;\n float backDepth = texture2D(tBackDepth, vUv).r; \n float customDepth = texture2D(tCustomDepth, vUv).r;\n float ghostDepth = texture2D(tGhostDepth, vUv).r;\n\n // This is a hack to make sure that all textures are initialized\n // If a texture is unused, it will have a clear value of 0.0.\n // Without this we've seen issues with MSAA where resizing render targets\n // causes depth to cleared to either 1 or 0 depending on the device/browser\n customDepth = customDepth > 0.0 ? customDepth : 1.0; \n backDepth = backDepth > 0.0 ? backDepth : 1.0;\n ghostDepth = ghostDepth > 0.0 ? ghostDepth : 1.0;\n frontDepth = frontDepth > 0.0 ? frontDepth : 1.0; \n\n if(all(greaterThanEqual(vec4(backDepth, customDepth, ghostDepth, frontDepth), vec4(1.0)))){\n discard;\n }\n \n // Decompose and clamp \"ghost\" color\n vec4 clampedGhostAlbedo = vec4(max(ghostAlbedo.rgb, 0.5), min(ghostAlbedo.a, 0.8));\n\n float frontOutlineIndex = computeFloatEncodedOutlineIndex(frontAlbedo.a);\n vec4 frontNeighborIndices = computeNeighborOutlineIndices(tFront);\n\n // There exsists fragments of rendered objects within the edge width that should have border\n if(any(equal(frontNeighborIndices, vec4(0.0))) && frontOutlineIndex > 0.0) \n { \n float borderColorIndex = max(max(frontNeighborIndices.x, frontNeighborIndices.y), max(frontNeighborIndices.z, frontNeighborIndices.w));\n gl_FragColor = texture2D(tOutlineColors, vec2(0.125 * borderColorIndex + (0.125 / 2.0), 0.5));\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = frontDepth;\n#endif\n return;\n }\n\n // texture has drawn fragment\n if(frontDepth < 1.0){\n float customDepthTest = step(customDepth, backDepth); // zero if back is in front\n\n float a = customDepthTest > 0.0 ? ceil(customAlbedo.a) * 0.5 : ceil(backAlbedo.a) * 0.5;\n\n gl_FragColor = vec4(frontAlbedo.rgb, 1.0) * (1.0 - a) + (vec4(backAlbedo.rgb, 1.0) * (1.0 - customDepthTest) + vec4(customAlbedo.rgb, 1.0) * customDepthTest) * a;\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = texture2D(tFrontDepth, vUv).r;\n#endif\n return;\n }\n\n if (customDepth >= backDepth) {\n float backOutlineIndex = computeFloatEncodedOutlineIndex(backAlbedo.a);\n vec4 backNeighborIndices = computeNeighborOutlineIndices(tBack);\n\n if( any(equal(backNeighborIndices, vec4(0.0))) && backOutlineIndex > 0.0) \n { \n float borderColorIndex = max(max(backNeighborIndices.x, backNeighborIndices.y), max(backNeighborIndices.z, backNeighborIndices.w));\n gl_FragColor = texture2D(tOutlineColors, vec2(0.125 * borderColorIndex + (0.125 / 2.0), 0.5));\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth)\n gl_FragDepthEXT = texture2D(tBackDepth, vUv).r;\n#endif\n return;\n }\n }\n \n float edgeStrength = 0.0;\n#if defined(EDGES)\n if (!any(equal(computeNeighborAlphas(tBack), vec4(0.0)))) {\n float depthEdge = toViewZ(backDepth, cameraNear, cameraFar);\n edgeStrength = (1.0 - smoothstep(10.0, 40.0, depthEdge)) * edgeDetectionFilter(tBack, vUv, resolution) * edgeStrengthMultiplier;\n }\n#endif\n\n // Combine color from ghost, back and custom object\n vec4 color = backAlbedo;\n float depth = backDepth;\n if (customDepth < backDepth && ghostDepth == 1.0) {\n color = vec4(customAlbedo.rgb * customAlbedo.a + (1.0 - customAlbedo.a) * backAlbedo.rgb, 1.0);\n depth = customDepth;\n edgeStrength = 0.0;\n } else if (customDepth < backDepth && ghostDepth < 1.0) {\n float s = (1.0 - step(backDepth, ghostDepth)) * clampedGhostAlbedo.a;\n vec3 modelAlbedo = mix(backAlbedo.rgb, clampedGhostAlbedo.rgb, s);\n color = vec4(customAlbedo.rgb * customAlbedo.a + (1.0 - customAlbedo.a) * modelAlbedo.rgb, 1.0);\n depth = customDepth;\n edgeStrength = 0.0;\n } else {\n float s = (1.0 - step(backDepth, ghostDepth)) * clampedGhostAlbedo.a;\n color = vec4(mix(backAlbedo.rgb, clampedGhostAlbedo.rgb, s), backAlbedo.a);\n depth = mix(backDepth, ghostDepth, s);\n }\n \n gl_FragColor = color * (1.0 - edgeStrength) + vec4(vec3(edgeGrayScaleIntensity) * edgeStrength, 1.0);\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth) \n gl_FragDepthEXT = depth;\n#endif\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\nvarying vec2 vUv;\n\n// selection outline\nuniform vec2 texelSize;\nvarying vec2 vUv0;\nvarying vec2 vUv1;\nvarying vec2 vUv2;\nvarying vec2 vUv3;\n\nvoid main() {\n vUv = uv;\n\n // selection outline\n vUv0 = vec2(uv.x + texelSize.x, uv.y);\n vUv1 = vec2(uv.x - texelSize.x, uv.y);\n vUv2 = vec2(uv.x, uv.y + texelSize.y);\n vUv3 = vec2(uv.x, uv.y - texelSize.y);\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/*!\n *\n * Adapted from:\n * https://github.com/mattdesl/three-shader-fxaa\n * MIT License (MIT) Copyright (c) 2014 Matt DesLauriers\n *\n */\n\nvarying vec2 v_uv;\nvarying vec2 v_fragCoord;\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nuniform vec2 inverseResolution;\nuniform vec2 resolution;\nuniform sampler2D tDiffuse;\nuniform sampler2D tDepth;\n\n#ifndef FXAA_REDUCE_MIN\n #define FXAA_REDUCE_MIN (1.0/ 128.0)\n#endif\n#ifndef FXAA_REDUCE_MUL\n #define FXAA_REDUCE_MUL (1.0 / 8.0)\n#endif\n#ifndef FXAA_SPAN_MAX\n #define FXAA_SPAN_MAX 8.0\n#endif\n\nvec4 fxaa(sampler2D tex, vec2 fragCoord,\n vec2 resolution, vec2 inverseResolution,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n\n vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\n vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\n vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\n vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\n vec4 texColor = texture2D(tex, v_rgbM);\n vec3 rgbM = texColor.xyz;\n\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n mediump vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin));\n\n vec4 rgbA = 0.5 * (\n texture2D(tex, inverseResolution * (v_fragCoord + dir * (1.0 / 3.0 - 0.5))) +\n texture2D(tex, inverseResolution * (v_fragCoord + dir * (2.0 / 3.0 - 0.5))));\n vec4 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(tex, inverseResolution * (v_fragCoord + dir * -0.5)) +\n texture2D(tex, inverseResolution * (v_fragCoord + dir * 0.5)));\n\n float lumaB = dot(rgbB.rgb, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n color = rgbA;\n } else {\n color = rgbB;\n }\n return color;\n}\n\nvoid main() {\n gl_FragColor = fxaa(tDiffuse, v_fragCoord, \n resolution, inverseResolution, \n v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n#if defined(gl_FragDepthEXT) || defined(GL_EXT_frag_depth)\n gl_FragDepthEXT = texture2D(tDepth, v_uv).r;\n#endif\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/*!\n *\n * Adapted from:\n * https://github.com/mattdesl/three-shader-fxaa\n * MIT License (MIT) Copyright (c) 2014 Matt DesLauriers\n *\n */\n\nuniform vec2 resolution;\nuniform vec2 inverseResolution;\n\nvarying vec2 v_uv;\nvarying vec2 v_fragCoord;\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvoid main() {\n v_fragCoord = uv * resolution;\n v_rgbNW = (v_fragCoord + vec2(-1.0, -1.0)) * inverseResolution;\n v_rgbNE = (v_fragCoord + vec2(1.0, -1.0)) * inverseResolution;\n v_rgbSW = (v_fragCoord + vec2(-1.0, 1.0)) * inverseResolution;\n v_rgbSE = (v_fragCoord + vec2(1.0, 1.0)) * inverseResolution;\n v_rgbM = vec2(v_fragCoord * inverseResolution);\n v_uv = uv;\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// From http://www.science-and-fiction.org/rendering/noise.html\nfloat rand2d(in vec2 co){\n return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);\n}\n\nvarying vec2 vUv;\n\nuniform mat4 projMatrix;\nuniform mat4 inverseProjectionMatrix;\n\nuniform vec3 kernel[MAX_KERNEL_SIZE];\n\nuniform sampler2D tDepth;\n\nuniform vec2 resolution;\n\nuniform float sampleRadius;\nuniform float bias;\n\nvec3 viewPosFromDepth(float depth, vec2 uv) {\n // Depth to clip space: [0, 1] -> [-1, 1]\n float z = depth * 2.0 - 1.0;\n\n // Fragment in clip space\n vec4 clipSpacePosition = vec4(uv * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = inverseProjectionMatrix * clipSpacePosition;\n\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n\n return viewSpacePosition.xyz;\n}\n\nvec3 computeWorldNormalFromDepth(sampler2D depthTexture, vec2 resolution, vec2 uv, float sampleDepth){\n float dx = 1.0 / resolution.x;\n float dy = 1.0 / resolution.y;\n\n vec2 uv1 = uv + vec2(dx, 0.0); // right\n float d1 = texture2D(depthTexture, uv1).r; \n\n vec2 uv2 = uv + vec2(0.0, dy); // up\n float d2 = texture2D(depthTexture, uv2).r;\n\n vec2 uv3 = uv + vec2(-dx, 0.0); // left\n float d3 = texture2D(depthTexture, uv3).r;\n\n vec2 uv4 = uv + vec2(0.0, -dy); // down\n float d4 = texture2D(depthTexture, uv4).r;\n\n bool horizontalSampleCondition = abs(d1 - sampleDepth) < abs(d3 - sampleDepth);\n\n float horizontalSampleDepth = horizontalSampleCondition ? d1 : d3;\n vec2 horizontalSampleUv = horizontalSampleCondition ? uv1 : uv3;\n\n bool verticalSampleCondition = abs(d2 - sampleDepth) < abs(d4 - sampleDepth);\n\n float verticalSampleDepth = verticalSampleCondition ? d2 : d4;\n vec2 verticalSampleUv = verticalSampleCondition ? uv2 : uv4;\n\n vec3 viewPos = viewPosFromDepth(sampleDepth, vUv);\n \n vec3 viewPos1 = (horizontalSampleCondition == verticalSampleCondition) ? viewPosFromDepth(horizontalSampleDepth, horizontalSampleUv) : viewPosFromDepth(verticalSampleDepth, verticalSampleUv);\n vec3 viewPos2 = (horizontalSampleCondition == verticalSampleCondition) ? viewPosFromDepth(verticalSampleDepth, verticalSampleUv) : viewPosFromDepth(horizontalSampleDepth, horizontalSampleUv);\n\n return normalize(cross(viewPos1 - viewPos, viewPos2 - viewPos));\n}\n\nvoid main(){\n float d = texture2D(tDepth, vUv).r;\n\n vec3 viewNormal = computeWorldNormalFromDepth(tDepth, resolution, vUv, d);\n\n vec3 viewPosition = viewPosFromDepth(d, vUv);\n\n vec3 randomVec = normalize(vec3(rand2d(vUv), rand2d(vUv * 3.0), rand2d(vUv * 5.0)));\n\n vec3 tangent = normalize(randomVec - viewNormal * dot(randomVec, viewNormal));\n\n vec3 bitangent = cross(viewNormal, tangent);\n\n mat3 TBN = mat3(tangent, bitangent, viewNormal);\n\n float occlusion = 0.0;\n\n for (int i = 0; i < MAX_KERNEL_SIZE; i++){\n \n vec3 sampleVector = TBN * kernel[i];\n sampleVector = viewPosition + sampleVector * sampleRadius;\n\n vec4 offset = projMatrix * vec4(sampleVector, 1.0);\n offset.xyz /= offset.w;\n offset.xyz = offset.xyz * 0.5 + 0.5;\n\n float realDepth = texture2D(tDepth, offset.xy).r;\n vec3 realPos = viewPosFromDepth(realDepth, offset.xy);\n\n float rangeCheck = smoothstep(0.0, 1.0, sampleRadius / length(viewPosition - realPos));\n\n occlusion += (realPos.z >= sampleVector.z + bias ? 1.0 : 0.0) * rangeCheck;\n }\n\n float occlusionFactor = 1.0 - clamp(occlusion / float(MAX_KERNEL_SIZE), 0.0, 1.0);\n\n gl_FragColor = vec4(vec3(occlusionFactor), 1.0);\n}"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// Copyright Cognite (C) 2021 Cognite\n//\n// Efficient Gaussian blur based on technique described by Daniel Rákos in\n// http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/\n// generalized for two dimensions\n\nvarying vec2 vUv;\n\nuniform sampler2D tDiffuse;\nuniform sampler2D tAmbientOcclusion;\n\nuniform vec2 resolution;\n\nvoid main() {\n float blurredAO =\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, -3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, -3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, -1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, -1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, -3.1111111) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, -1.3333333) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, -3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, -3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, -1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, -1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 0.0000000) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 0.0000000) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(-3.1111111, 3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(-1.3333333, 3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, 1.3333333) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(0.0000000, 3.1111111) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 1.3333333) / resolution).r * 0.1076660 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 1.3333333) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 3.1111111) / resolution).r * 0.0115356 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 3.1111111) / resolution).r * 0.0012360 +\n texture2D(tAmbientOcclusion, vUv + vec2(1.3333333, 0.0000000) / resolution).r * 0.0897217 +\n texture2D(tAmbientOcclusion, vUv + vec2(3.1111111, 0.0000000) / resolution).r * 0.0096130 +\n texture2D(tAmbientOcclusion, vUv).r * 0.0747681;\n\n gl_FragColor = vec4(texture2D(tDiffuse, vUv).rgb * blurredAO, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n// From http://www.science-and-fiction.org/rendering/noise.html\nfloat rand2d(in vec2 co){\n return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);\n}\n\nstruct NodeAppearance {\n vec4 colorTexel;\n bool isVisible;\n bool renderInFront;\n bool renderGhosted;\n};\n\n#if NUM_CLIPPING_PLANES > 0\nuniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif\n\nbool isClipped(NodeAppearance nodeAppearance, vec3 point) {\n#if NUM_CLIPPING_PLANES > 0\n vec3 pointFlipped = -point;\n vec4 plane;\n\n for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {\n plane = clippingPlanes[i];\n if (dot(pointFlipped, plane.xyz) > plane.w) return true;\n }\n#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;\n }\n if ( clipped ) return true;\n#endif\n#endif\n return false;\n}\n\nvarying mediump vec3 v_color;\nvarying lowp float v_coverageFactor;\nvarying lowp float v_visible;\nvarying lowp vec2 v_seed;\n\nvarying vec3 v_viewPosition;\n \nconst NodeAppearance dummyNodeAppearance = NodeAppearance(vec4(0.0), false, false, false);\n\nvoid main() {\n if(v_visible != 1.0 || isClipped(dummyNodeAppearance, v_viewPosition)){\n discard;\n }\n\n float v = rand2d(gl_FragCoord.xy + v_seed);\n if (v >= v_coverageFactor) {\n discard;\n }\n\n gl_FragColor = vec4(v_color, 1.0);\n}\n"},function(e,t,n){"use strict";n.r(t),t.default="#define GLSLIFY 1\n/**\n * Packs the integer part of the number given to a RGB color.\n */\nvec3 packIntToColor(float number) {\n float r = floor(number / (255.0 * 255.0)) / 255.0;\n float g = mod(floor(number / 255.0), 255.0) / 255.0;\n float b = mod(number, 255.0) / 255.0;\n return vec3(r, g, b);\n}\n\nattribute mediump float a_sectorId;\nattribute lowp vec3 a_coverageFactor;\nattribute lowp float a_visible;\n\nvarying mediump vec3 v_color;\nvarying lowp float v_coverageFactor;\nvarying lowp vec2 v_seed;\nvarying lowp float v_visible;\n\nvarying vec3 v_viewPosition;\n\nvoid main()\n{\n v_visible = a_visible;\n v_color = packIntToColor(a_sectorId);\n v_coverageFactor = abs(dot(a_coverageFactor, normal));\n // A seed to ensure that two overlapping sectors A and B \n // doesn't produce the same noise pattern\n v_seed = vec2(a_sectorId / 255.0, a_sectorId / 65025.0);\n\n vec4 mvPosition = modelViewMatrix * instanceMatrix * vec4( position, 1.0 );\n\n v_viewPosition = mvPosition.xyz;\n\n gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);\n}\n"},,function(e,t,n){"use strict";n.r(t),n.d(t,"NodeAppearanceProvider",(function(){return g})),n.d(t,"NodeOutlineColor",(function(){return r})),n.d(t,"NodeCollectionBase",(function(){return s})),n.d(t,"TreeIndexNodeCollection",(function(){return u})),n.d(t,"IntersectionNodeCollection",(function(){return c})),n.d(t,"UnionNodeCollection",(function(){return l})),n.d(t,"revealEnv",(function(){return a.r})),n.d(t,"IndexSet",(function(){return a.e})),n.d(t,"NumericRange",(function(){return a.h})),n.d(t,"BoundingBoxClipper",(function(){return rn.a})),n.d(t,"Cognite3DModel",(function(){return U})),n.d(t,"Cognite3DViewer",(function(){return _n})),n.d(t,"CognitePointCloudModel",(function(){return j})),n.d(t,"PotreePointShape",(function(){return xt})),n.d(t,"PotreePointColorType",(function(){return yt})),n.d(t,"PotreePointSizeType",(function(){return Tt})),n.d(t,"WellKnownAsprsPointClassCodes",(function(){return Ct})),n.d(t,"NotSupportedInMigrationWrapperError",(function(){return F})),n.d(t,"PropertyFilterNodeCollection",(function(){return te})),n.d(t,"SinglePropertyFilterNodeCollection",(function(){return re})),n.d(t,"AssetNodeCollection",(function(){return J})),n.d(t,"InvertedNodeCollection",(function(){return ne})),n.d(t,"registerCustomNodeCollectionType",(function(){return se})),n.d(t,"THREE",(function(){return y})),n.d(t,"DefaultNodeAppearance",(function(){return h}));var r,o=n(7),i=n.n(o),a=n(1);
175
175
  /*!
176
176
  * Copyright 2021 Cognite AS
177
177
  */
@@ -179,14 +179,14 @@ class s{constructor(e){this._changedEvent=new a.d,this._classToken=e}get classTo
179
179
  /*!
180
180
  * Copyright 2021 Cognite AS
181
181
  */
182
- class u extends s{constructor(e){super(u.classToken),e instanceof a.e?this._treeIndices=e:(a.h,this._treeIndices=new a.e(e))}updateSet(e){this._treeIndices=e,this.notifyChanged()}clear(){this._treeIndices=new a.e,this.notifyChanged()}getIndexSet(){return this._treeIndices}get isLoading(){return!1}serialize(){return{token:this.classToken,state:this._treeIndices.toRangeArray()}}}u.classToken="TreeIndexNodeCollection",function(e){e[e.NoOutline=0]="NoOutline",e[e.White=1]="White",e[e.Black=2]="Black",e[e.Cyan=3]="Cyan",e[e.Blue=4]="Blue",e[e.Green=5]="Green",e[e.Red=6]="Red",e[e.Orange=7]="Orange"}(r||(r={}));const p={visible:!0,outlineColor:r.White},m={visible:!0,renderInFront:!0},h={Default:{visible:!0,renderGhosted:!1,renderInFront:!1,outlineColor:r.NoOutline,color:[0,0,0]},Outlined:p,Hidden:{visible:!1},InFront:m,Ghosted:{visible:!0,renderGhosted:!0},Highlighted:{...m,visible:!0,color:[100,100,255],...p}};var f=n(19),v=n.n(f);
182
+ class u extends s{constructor(e){super(u.classToken),e instanceof a.e?this._treeIndices=e:(a.h.isNumericRange(e),this._treeIndices=new a.e(e))}updateSet(e){this._treeIndices=e,this.notifyChanged()}clear(){this._treeIndices=new a.e,this.notifyChanged()}getIndexSet(){return this._treeIndices}get isLoading(){return!1}serialize(){return{token:this.classToken,state:this._treeIndices.toRangeArray()}}}u.classToken="TreeIndexNodeCollection",function(e){e[e.NoOutline=0]="NoOutline",e[e.White=1]="White",e[e.Black=2]="Black",e[e.Cyan=3]="Cyan",e[e.Blue=4]="Blue",e[e.Green=5]="Green",e[e.Red=6]="Red",e[e.Orange=7]="Orange"}(r||(r={}));const p={visible:!0,outlineColor:r.White},m={visible:!0,renderInFront:!0},h={Default:{visible:!0,renderGhosted:!1,renderInFront:!1,outlineColor:r.NoOutline,color:[0,0,0]},Outlined:p,Hidden:{visible:!1},InFront:m,Ghosted:{visible:!0,renderGhosted:!0},Highlighted:{...m,visible:!0,color:[100,100,255],...p}};var f=n(19),v=n.n(f);
183
183
  /*!
184
184
  * Copyright 2021 Cognite AS
185
185
  */
186
- class x{constructor(){this._styledCollections=new Array,this._events={changed:new a.d,loadingStateChanged:new a.d},this.scheduleNotifyChanged=v()(()=>this.notifyChanged(),0)}on(e,t){switch(e){case"changed":this._events.changed.subscribe(t);break;case"loadingStateChanged":this._events.loadingStateChanged.subscribe(t);break;default:Object(a.k)(e,`Unsupported event: '${e}'`)}}off(e,t){switch(e){case"changed":this._events.changed.unsubscribe(t);break;case"loadingStateChanged":this._events.loadingStateChanged.unsubscribe(t);break;default:Object(a.k)(e,`Unsupported event: '${e}'`)}}assignStyledNodeCollection(e,t){const n=this._styledCollections.find(t=>t.nodeCollection===e);if(void 0!==n)n.appearance=t,this.handleNodeCollectionChanged(n);else{const n={nodeCollection:e,appearance:t,handleNodeCollectionChangedListener:()=>{this.handleNodeCollectionChanged(n)}};this._styledCollections.push(n),e.on("changed",n.handleNodeCollectionChangedListener),this.scheduleNotifyChanged()}}unassignStyledNodeCollection(e){const t=this._styledCollections.findIndex(t=>t.nodeCollection===e);if(-1===t)throw new Error("NodeCollection not added");const n=this._styledCollections[t];this._styledCollections.splice(t,1),e.off("changed",n.handleNodeCollectionChangedListener),this.scheduleNotifyChanged()}applyStyles(e){this._styledCollections.forEach(t=>{const n=t.nodeCollection.getIndexSet();e(n,t.appearance)})}clear(){for(const e of this._styledCollections){e.nodeCollection.off("changed",e.handleNodeCollectionChangedListener)}this._styledCollections.splice(0),this.scheduleNotifyChanged()}get isLoading(){return this._styledCollections.some(e=>e.nodeCollection.isLoading)}notifyChanged(){this._events.changed.fire()}notifyLoadingStateChanged(){this._lastFiredLoadingState!==this.isLoading&&(this._lastFiredLoadingState=this.isLoading,this._events.loadingStateChanged.fire(this.isLoading))}handleNodeCollectionChanged(e){this.scheduleNotifyChanged(),this.notifyLoadingStateChanged()}}
186
+ class g{constructor(){this._styledCollections=new Array,this._events={changed:new a.d,loadingStateChanged:new a.d},this.scheduleNotifyChanged=v()(()=>this.notifyChanged(),0)}on(e,t){switch(e){case"changed":this._events.changed.subscribe(t);break;case"loadingStateChanged":this._events.loadingStateChanged.subscribe(t);break;default:Object(a.k)(e,`Unsupported event: '${e}'`)}}off(e,t){switch(e){case"changed":this._events.changed.unsubscribe(t);break;case"loadingStateChanged":this._events.loadingStateChanged.unsubscribe(t);break;default:Object(a.k)(e,`Unsupported event: '${e}'`)}}assignStyledNodeCollection(e,t){const n=this._styledCollections.find(t=>t.nodeCollection===e);if(void 0!==n)n.appearance=t,this.handleNodeCollectionChanged(n);else{const n={nodeCollection:e,appearance:t,handleNodeCollectionChangedListener:()=>{this.handleNodeCollectionChanged(n)}};this._styledCollections.push(n),e.on("changed",n.handleNodeCollectionChangedListener),this.scheduleNotifyChanged()}}unassignStyledNodeCollection(e){const t=this._styledCollections.findIndex(t=>t.nodeCollection===e);if(-1===t)throw new Error("NodeCollection not added");const n=this._styledCollections[t];this._styledCollections.splice(t,1),e.off("changed",n.handleNodeCollectionChangedListener),this.scheduleNotifyChanged()}applyStyles(e){this._styledCollections.forEach(t=>{const n=t.nodeCollection.getIndexSet();e(n,t.appearance)})}clear(){for(const e of this._styledCollections){e.nodeCollection.off("changed",e.handleNodeCollectionChangedListener)}this._styledCollections.splice(0),this.scheduleNotifyChanged()}get isLoading(){return this._styledCollections.some(e=>e.nodeCollection.isLoading)}notifyChanged(){this._events.changed.fire()}notifyLoadingStateChanged(){this._lastFiredLoadingState!==this.isLoading&&(this._lastFiredLoadingState=this.isLoading,this._events.loadingStateChanged.fire(this.isLoading))}handleNodeCollectionChanged(e){this.scheduleNotifyChanged(),this.notifyLoadingStateChanged()}}
187
187
  /*!
188
188
  * Copyright 2021 Cognite AS
189
- */var g,b,y=n(0),_=n(11),T=n.n(_),w=n(29),C=n.n(w),M=n(4);!function(e){e[e.NoAA=0]="NoAA",e[e.FXAA=1]="FXAA"}(g||(g={})),function(e){e[e.Medium=32]="Medium",e[e.High=64]="High",e[e.VeryHigh=128]="VeryHigh",e[e.None=1]="None",e[e.Default=32]="Default"}(b||(b={}));const I={antiAliasing:g.FXAA,multiSampleCountHint:1,ssaoRenderParameters:{sampleSize:b.Default,sampleRadius:1,depthCheckBias:.0125},edgeDetectionParameters:{enabled:!0}};var S,P=n(8),N=n(13);!function(e){e[e.Color=1]="Color",e[e.Normal=2]="Normal",e[e.TreeIndex=3]="TreeIndex",e[e.PackColorAndNormal=4]="PackColorAndNormal",e[e.Depth=5]="Depth",e[e.Effects=6]="Effects",e[e.Ghost=7]="Ghost",e[e.LOD=8]="LOD",e[e.DepthBufferOnly=9]="DepthBufferOnly",e[e.GeometryType=10]="GeometryType"}(S||(S={}));
189
+ */var x,b,y=n(0),_=n(11),T=n.n(_),w=n(29),C=n.n(w),M=n(4);!function(e){e[e.NoAA=0]="NoAA",e[e.FXAA=1]="FXAA"}(x||(x={})),function(e){e[e.Medium=32]="Medium",e[e.High=64]="High",e[e.VeryHigh=128]="VeryHigh",e[e.None=1]="None",e[e.Default=32]="Default"}(b||(b={}));const I={antiAliasing:x.FXAA,multiSampleCountHint:1,ssaoRenderParameters:{sampleSize:b.Default,sampleRadius:1,depthCheckBias:.0125},edgeDetectionParameters:{enabled:!0}};var S,N=n(8),P=n(13);!function(e){e[e.Color=1]="Color",e[e.Normal=2]="Normal",e[e.TreeIndex=3]="TreeIndex",e[e.PackColorAndNormal=4]="PackColorAndNormal",e[e.Depth=5]="Depth",e[e.Effects=6]="Effects",e[e.Ghost=7]="Ghost",e[e.LOD=8]="LOD",e[e.DepthBufferOnly=9]="DepthBufferOnly",e[e.GeometryType=10]="GeometryType"}(S||(S={}));
190
190
  /*!
191
191
  * Copyright 2021 Cognite AS
192
192
  */
@@ -205,14 +205,14 @@ const R=new y.Color("black");function A(e,t){const{camera:n,normalizedCoords:r,r
205
205
  */async function G(e,t,n,r=15e3){let o=e;return new Promise(e=>{!function i(){for(let e=0;e<r&&o<=t;e++)n(o++);o<=t?setTimeout(i):e()}()})}var V=n(2);
206
206
  /*!
207
207
  * Copyright 2021 Cognite AS
208
- */class U extends y.Object3D{constructor(e,t,n,r){super(),this.type="cad",this._styledNodeCollections=[],this.modelId=e,this.revisionId=t,this.cadModel=n.cadModelMetadata,this.nodesApiClient=r,this.nodeIdAndTreeIndexMaps=new L(e,t,this.nodesApiClient),this.cadNode=n,this.add(this.cadNode),Object.defineProperty(this,"visible",{get:()=>this.cadNode.visible,set:e=>{this.cadNode.visible=e}})}get nodeTransformProvider(){return this.cadNode.nodeTransformProvider}get modelUnit(){return this.cadNode.cadModelMetadata.scene.unit}get modelUnitToMetersFactor(){return V.h.get(this.modelUnit)}setDefaultNodeAppearance(e){this.cadNode.defaultNodeAppearance=e}getDefaultNodeAppearance(){return this.cadNode.defaultNodeAppearance}get styledNodeCollections(){return[...this._styledNodeCollections]}assignStyledNodeCollection(e,t){P.a.trackCadModelStyled(e.classToken,t);if(-1!==this._styledNodeCollections.findIndex(t=>t.nodeCollection===e))throw new Error("Node collection as already been assigned, use updateStyledNodeCollection() to update the appearance");this._styledNodeCollections.push({nodeCollection:e,appearance:t}),this.cadNode.nodeAppearanceProvider.assignStyledNodeCollection(e,t)}updateStyledNodeCollection(e,t){const n=this._styledNodeCollections.findIndex(t=>t.nodeCollection===e);if(-1===n)throw new Error("The node collection provide has not been assigned previously");this._styledNodeCollections[n].appearance=t,this.cadNode.nodeAppearanceProvider.assignStyledNodeCollection(e,t)}unassignStyledNodeCollection(e){const t=this._styledNodeCollections.findIndex(t=>t.nodeCollection===e);if(-1===t)throw new Error("Node collection has not been assigned to model");this._styledNodeCollections.splice(t,1),this.cadNode.nodeAppearanceProvider.unassignStyledNodeCollection(e)}removeAllStyledNodeCollections(){this._styledNodeCollections.splice(0),this.cadNode.nodeAppearanceProvider.clear()}setNodeTransform(e,t){this.nodeTransformProvider.setNodeTransform(e,t)}resetNodeTransform(e){this.nodeTransformProvider.resetNodeTransform(e)}mapFromCdfToModelCoordinates(e,t){return(t=void 0!==t?t:new y.Vector3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.modelMatrix),t}mapPositionFromModelToCdfCoordinates(e,t){return(t=void 0!==t?t:new y.Vector3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.inverseModelMatrix),t}mapBoxFromModelToCdfCoordinates(e,t){return(t=null!=t?t:new y.Box3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.inverseModelMatrix),t}dispose(){this.children=[]}async getSubtreeTreeIndices(e){return this.determineTreeIndices(e,!0)}async getAncestorTreeIndices(e,t){const n=await this.mapTreeIndexToNodeId(e),r=await this.nodesApiClient.determineNodeAncestorsByNodeId(this.modelId,this.revisionId,n,t);return new a.h(r.treeIndex,r.subtreeSize)}getModelBoundingBox(e,t){const n=t?this.cadModel.scene.getBoundsOfMostGeometry():this.cadModel.scene.root.bounds;return(e=e||new y.Box3).copy(n),e.applyMatrix4(this.cadModel.modelMatrix),e}getCameraConfiguration(){return this.cadModel.cameraConfiguration}setModelTransformation(e){this.cadNode.setModelTransformation(e)}getModelTransformation(e){return this.cadNode.getModelTransformation(e)}async getBoundingBoxByNodeId(e,t){try{return(t=await this.nodesApiClient.getBoundingBoxByNodeId(this.modelId,this.revisionId,e,t)).applyMatrix4(this.cadModel.modelMatrix),t}catch(e){throw P.a.trackError(e,{moduleName:"Cognite3DModel",methodName:"getBoundingBoxByNodeId"}),e}}async getBoundingBoxByTreeIndex(e,t){const n=await this.nodeIdAndTreeIndexMaps.getNodeId(e);return this.getBoundingBoxByNodeId(n,t)}iterateNodesByTreeIndex(e){return G(0,this.cadModel.scene.maxTreeIndex,e)}get nodeCount(){return this.cadModel.scene.maxTreeIndex+1}async iterateSubtreeByTreeIndex(e,t){const n=await this.determineTreeIndices(e,!0);return G(n.from,n.toInclusive,t)}async setNodeTransformByTreeIndex(e,t,n=!0){const r=await this.determineTreeIndices(e,n);return this.nodeTransformProvider.setNodeTransform(r,t),r.count}async resetNodeTransformByTreeIndex(e,t=!0){const n=await this.determineTreeIndices(e,t);return this.nodeTransformProvider.resetNodeTransform(n),n.count}async mapNodeIdsToTreeIndices(e){return this.nodeIdAndTreeIndexMaps.getTreeIndices(e)}async mapNodeIdToTreeIndex(e){return this.nodeIdAndTreeIndexMaps.getTreeIndex(e)}async mapTreeIndicesToNodeIds(e){return this.nodeIdAndTreeIndexMaps.getNodeIds(e)}async mapTreeIndexToNodeId(e){return this.nodeIdAndTreeIndexMaps.getNodeId(e)}async determineTreeIndices(e,t){let n=1;if(t){const t=await this.nodeIdAndTreeIndexMaps.getSubtreeSize(e);n=t||1}return new a.h(e,n)}}
208
+ */class U extends y.Object3D{constructor(e,t,n,r){super(),this.type="cad",this._styledNodeCollections=[],this.modelId=e,this.revisionId=t,this.cadModel=n.cadModelMetadata,this.nodesApiClient=r,this.nodeIdAndTreeIndexMaps=new L(e,t,this.nodesApiClient),this.cadNode=n,this.add(this.cadNode),Object.defineProperty(this,"visible",{get:()=>this.cadNode.visible,set:e=>{this.cadNode.visible=e}})}get nodeTransformProvider(){return this.cadNode.nodeTransformProvider}get modelUnit(){return this.cadNode.cadModelMetadata.scene.unit}get modelUnitToMetersFactor(){return V.h.get(this.modelUnit)}setDefaultNodeAppearance(e){this.cadNode.defaultNodeAppearance=e}getDefaultNodeAppearance(){return this.cadNode.defaultNodeAppearance}get styledNodeCollections(){return[...this._styledNodeCollections]}assignStyledNodeCollection(e,t){N.a.trackCadModelStyled(e.classToken,t);if(-1!==this._styledNodeCollections.findIndex(t=>t.nodeCollection===e))throw new Error("Node collection as already been assigned, use updateStyledNodeCollection() to update the appearance");this._styledNodeCollections.push({nodeCollection:e,appearance:t}),this.cadNode.nodeAppearanceProvider.assignStyledNodeCollection(e,t)}updateStyledNodeCollection(e,t){const n=this._styledNodeCollections.findIndex(t=>t.nodeCollection===e);if(-1===n)throw new Error("The node collection provide has not been assigned previously");this._styledNodeCollections[n].appearance=t,this.cadNode.nodeAppearanceProvider.assignStyledNodeCollection(e,t)}unassignStyledNodeCollection(e){const t=this._styledNodeCollections.findIndex(t=>t.nodeCollection===e);if(-1===t)throw new Error("Node collection has not been assigned to model");this._styledNodeCollections.splice(t,1),this.cadNode.nodeAppearanceProvider.unassignStyledNodeCollection(e)}removeAllStyledNodeCollections(){this._styledNodeCollections.splice(0),this.cadNode.nodeAppearanceProvider.clear()}setNodeTransform(e,t){this.nodeTransformProvider.setNodeTransform(e,t)}resetNodeTransform(e){this.nodeTransformProvider.resetNodeTransform(e)}mapFromCdfToModelCoordinates(e,t){return(t=void 0!==t?t:new y.Vector3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.modelMatrix),t}mapPositionFromModelToCdfCoordinates(e,t){return(t=void 0!==t?t:new y.Vector3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.inverseModelMatrix),t}mapBoxFromModelToCdfCoordinates(e,t){return(t=null!=t?t:new y.Box3)!==e&&t.copy(e),t.applyMatrix4(this.cadModel.inverseModelMatrix),t}dispose(){this.children=[]}async getSubtreeTreeIndices(e){return this.determineTreeIndices(e,!0)}async getAncestorTreeIndices(e,t){const n=await this.mapTreeIndexToNodeId(e),r=await this.nodesApiClient.determineNodeAncestorsByNodeId(this.modelId,this.revisionId,n,t);return new a.h(r.treeIndex,r.subtreeSize)}getModelBoundingBox(e,t){const n=t?this.cadModel.scene.getBoundsOfMostGeometry():this.cadModel.scene.root.bounds;return(e=e||new y.Box3).copy(n),e.applyMatrix4(this.cadModel.modelMatrix),e}getCameraConfiguration(){return this.cadModel.cameraConfiguration}setModelTransformation(e){this.cadNode.setModelTransformation(e)}getModelTransformation(e){return this.cadNode.getModelTransformation(e)}async getBoundingBoxByNodeId(e,t){try{return(t=await this.nodesApiClient.getBoundingBoxByNodeId(this.modelId,this.revisionId,e,t)).applyMatrix4(this.cadModel.modelMatrix),t}catch(e){throw N.a.trackError(e,{moduleName:"Cognite3DModel",methodName:"getBoundingBoxByNodeId"}),e}}async getBoundingBoxByTreeIndex(e,t){const n=await this.nodeIdAndTreeIndexMaps.getNodeId(e);return this.getBoundingBoxByNodeId(n,t)}iterateNodesByTreeIndex(e){return G(0,this.cadModel.scene.maxTreeIndex,e)}get nodeCount(){return this.cadModel.scene.maxTreeIndex+1}async iterateSubtreeByTreeIndex(e,t){const n=await this.determineTreeIndices(e,!0);return G(n.from,n.toInclusive,t)}async setNodeTransformByTreeIndex(e,t,n=!0){const r=await this.determineTreeIndices(e,n);return this.nodeTransformProvider.setNodeTransform(r,t),r.count}async resetNodeTransformByTreeIndex(e,t=!0){const n=await this.determineTreeIndices(e,t);return this.nodeTransformProvider.resetNodeTransform(n),n.count}async mapNodeIdsToTreeIndices(e){return this.nodeIdAndTreeIndexMaps.getTreeIndices(e)}async mapNodeIdToTreeIndex(e){return this.nodeIdAndTreeIndexMaps.getTreeIndex(e)}async mapTreeIndicesToNodeIds(e){return this.nodeIdAndTreeIndexMaps.getNodeIds(e)}async mapTreeIndexToNodeId(e){return this.nodeIdAndTreeIndexMaps.getNodeId(e)}async determineTreeIndices(e,t){let n=1;if(t){const t=await this.nodeIdAndTreeIndexMaps.getSubtreeSize(e);n=t||1}return new a.h(e,n)}}
209
209
  /*!
210
210
  * Copyright 2021 Cognite AS
211
211
  */class j extends y.Object3D{constructor(e,t,n){super(),this.type="pointcloud",this.modelId=e,this.revisionId=t,this.pointCloudNode=n,this.add(n)}dispose(){this.children=[]}getModelBoundingBox(e){return this.pointCloudNode.getBoundingBox(e)}getCameraConfiguration(){return this.pointCloudNode.cameraConfiguration}setModelTransformation(e){this.pointCloudNode.setModelTransformation(e)}getModelTransformation(e){return this.pointCloudNode.getModelTransformation(e)}setClassVisible(e,t){this.pointCloudNode.setClassVisible(e,t)}isClassVisible(e){return this.pointCloudNode.isClassVisible(e)}hasClass(e){return this.pointCloudNode.hasClass(e)}getClasses(){return this.pointCloudNode.getClasses()}get visiblePointCount(){return this.pointCloudNode.visiblePointCount}get pointColorType(){return this.pointCloudNode.pointColorType}set pointColorType(e){this.pointCloudNode.pointColorType=e}get pointSize(){return this.pointCloudNode.pointSize}set pointSize(e){this.pointCloudNode.pointSize=e}get pointShape(){return this.pointCloudNode.pointShape}set pointShape(e){this.pointCloudNode.pointShape=e}}
212
212
  /*!
213
213
  * Copyright 2021 Cognite AS
214
214
  */
215
- class W{constructor(e){this._loading=!1,W.loadStyles(),this.el=document.createElement("div"),this.el.title=W.titles.idle,this.el.className=W.classnames.base,this.el.classList.add(W.classnames.topLeft),this.el.innerHTML='<svg fill="none" xmlns="http://www.w3.org/2000/svg" width="64" height="38" viewBox="0 0 64 38">\n <path id="reveal-spinner-top-1" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-28.2275 5.9674-28.7378 6.0661-29.2355 6.1624h-.0001c-1.3944.2698-2.6891.5203-3.9772.7036v-6.3583c-.0652-1.475-1.2799-2.6372-2.7563-2.6372s-2.6911 1.1622-2.7563 2.6372v7.1072z"/>\n <path id="reveal-spinner-top-2" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-16.8452 3.375-17.0189 3.4183-17.1711 3.506-1.7276.3694-3.3435.7389-4.9594 1.1083l-.0571.013V7.6106c-.0465-1.48876-1.2668-2.67155-2.7563-2.67155S22.8005 6.12184 22.754 7.6106v13.5866z"/>\n <path id="reveal-spinner-top-3" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-7.274 1.2593-9.1537 1.6344-11.0347 2.0095V2.74337c-.0338-1.54541-1.3116-2.7721267-2.8571-2.74285692h-.0134C35.0327.00556379 33.8015 1.2272 33.7846 2.74337V18.7098z"/>\n <path id="reveal-spinner-top-4" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288v-3.2274c0-1.5594-1.2642-2.82358-2.8236-2.82358s-2.8235 1.26418-2.8235 2.82358v4.4z"/>\n <path id="reveal-spinner-center" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288C5.46324 23.6926 1.83164 23.4439 1.45248 22.3172c-.773329-1.6548 3.63593-3.8942 5.79662-4.9915.28489-.1447.53068-.2695.72036-.3706v-.1237h-.12505c-1.62823.6226-8.646718 3.4958-7.768735 5.9832.875294 2.7456 11.653125 3.4958 34.086725-1.9939 18.7926-4.6145 27.4393-5.4925 28.3173-3.7446.6266 1.4952-4.0121 4.3644-8.5217 6.3597-.0966.0984-.1427.2357-.125.3724l.002.002c.1243.1244.2474.2475.3745.1231 1.6268-.6266 10.1499-4.238 9.7721-7.2323-.3738-1.9935-4.8842-2.6175-13.5274-1.3722z"/>\n <path id="reveal-spinner-bot-1" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M11.7557 30.5551v-2.0894c1.8291-.1048 3.6511-.3108 5.4575-.6171v2.7065c-.033 1.4835-1.245 2.6689-2.7288 2.6689s-2.6958-1.1854-2.7287-2.6689z"/>\n <path id="reveal-spinner-bot-2" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M22.7715 26.9222v7.602c-.0132 1.496 1.1804 2.7238 2.6762 2.7529 1.4957.0291 2.7362-1.1513 2.7813-2.6467v-8.8309c-1.7953.4821-3.6177.857-5.4575 1.1227z"/>\n <path id="reveal-spinner-bot-3" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M33.87 24.7193h-.3764v5.3419c.066 1.5151 1.3136 2.7095 2.8302 2.7095s2.7642-1.1944 2.8303-2.7095v-6.5883c-.3876.0886-.7821.1771-1.1838.2671l-.0007.0002c-1.2926.2897-2.6585.5959-4.0996.9764v.0027z"/>\n <path id="reveal-spinner-bot-4" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M44.5094 22.2377c2.1383-.3726 4.0242-.7438 5.6578-1.1137v4.3375c-.0249 1.5094-1.2534 2.7212-2.763 2.7254h-.0162c-.7432.0206-1.4641-.255-2.004-.7662-.54-.5112-.8546-1.216-.8746-1.9592v-3.2238z"/>\n</svg>\n',e.style.position="relative",e.appendChild(this.el)}static loadStyles(){if(document.getElementById(W.stylesId))return;const e=document.createElement("style");e.id=W.stylesId,e.appendChild(document.createTextNode(".reveal-viewer-spinner-top-left {\n top: 10px;\n left: 10px;\n}\n\n.reveal-viewer-spinner-top-right {\n top: 10px;\n right: 10px;\n}\n\n.reveal-viewer-spinner-bottom-left {\n bottom: 10px;\n left: 10px;\n}\n\n.reveal-viewer-spinner-bottom-right {\n bottom: 10px;\n right: 10px;\n}\n\n.reveal-viewer-spinner {\n position: absolute;\n color: white;\n}\n.reveal-viewer-spinner--dark {\n color: black;\n}\n\n.reveal-viewer-spinner--loading #reveal-spinner-bot-1,\n.reveal-viewer-spinner--loading #reveal-spinner-top-1 {\n animation: reveal-loading-opacity 0.8s ease-out infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-2,\n.reveal-viewer-spinner--loading #reveal-spinner-top-2 {\n animation: reveal-loading-opacity 0.8s ease-out 0.2s infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-3,\n.reveal-viewer-spinner--loading #reveal-spinner-top-3 {\n animation: reveal-loading-opacity 0.8s ease-out 0.4s infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-4,\n.reveal-viewer-spinner--loading #reveal-spinner-top-4 {\n animation: reveal-loading-opacity 0.8s ease-out 0.6s infinite alternate;\n}\n\n.reveal-viewer-spinner--loading #center {\n transform-origin: center;\n animation: reveal-loading-scale 1.6s ease-out infinite 0.8s alternate,\n reveal-loading-opacity 1.6s ease-out infinite alternate;\n}\n\n@keyframes reveal-loading-opacity {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0.2;\n }\n}\n\n@keyframes reveal-loading-scale {\n 100% {\n transform: scaleY(1.2) translateY(0.6px);\n }\n}\n")),document.head.appendChild(e)}set placement(e){switch(this.el.classList.remove(W.classnames.bottomLeft,W.classnames.bottomRight,W.classnames.topLeft,W.classnames.topRight),e){case"topLeft":this.el.classList.add(W.classnames.topLeft);break;case"topRight":this.el.classList.add(W.classnames.topRight);break;case"bottomLeft":this.el.classList.add(W.classnames.bottomLeft);break;case"bottomRight":this.el.classList.add(W.classnames.bottomRight);break;default:Object(a.k)(e,"Invalid placement: "+e)}}set opacity(e){this.el.style.opacity=""+e}get loading(){return this._loading}set loading(e){this._loading=e,e?(this.el.classList.add(W.classnames.loading),this.el.title=W.titles.loading):(this.el.classList.remove(W.classnames.loading),this.el.title=W.titles.idle)}updateBackgroundColor(e){const{l:t}=e.getHSL({h:0,s:0,l:0});t>.5?this.el.classList.add(W.classnames.dark):this.el.classList.remove(W.classnames.dark)}dispose(){this.el.remove();const e=document.getElementById(W.stylesId);e&&e.remove()}}W.stylesId="reveal-viewer-spinner-styles",W.classnames={base:"reveal-viewer-spinner",topLeft:"reveal-viewer-spinner-top-left",topRight:"reveal-viewer-spinner-top-right",bottomLeft:"reveal-viewer-spinner-bottom-left",bottomRight:"reveal-viewer-spinner-bottom-right",loading:"reveal-viewer-spinner--loading",dark:"reveal-viewer-spinner--dark"},W.titles={idle:"2.2.1",loading:"2.2.1 Loading..."};var q=n(9);
215
+ class W{constructor(e){this._loading=!1,W.loadStyles(),this.el=document.createElement("div"),this.el.title=W.titles.idle,this.el.className=W.classnames.base,this.el.classList.add(W.classnames.topLeft),this.el.innerHTML='<svg fill="none" xmlns="http://www.w3.org/2000/svg" width="64" height="38" viewBox="0 0 64 38">\n <path id="reveal-spinner-top-1" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-28.2275 5.9674-28.7378 6.0661-29.2355 6.1624h-.0001c-1.3944.2698-2.6891.5203-3.9772.7036v-6.3583c-.0652-1.475-1.2799-2.6372-2.7563-2.6372s-2.6911 1.1622-2.7563 2.6372v7.1072z"/>\n <path id="reveal-spinner-top-2" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-16.8452 3.375-17.0189 3.4183-17.1711 3.506-1.7276.3694-3.3435.7389-4.9594 1.1083l-.0571.013V7.6106c-.0465-1.48876-1.2668-2.67155-2.7563-2.67155S22.8005 6.12184 22.754 7.6106v13.5866z"/>\n <path id="reveal-spinner-top-3" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288c-7.274 1.2593-9.1537 1.6344-11.0347 2.0095V2.74337c-.0338-1.54541-1.3116-2.7721267-2.8571-2.74285692h-.0134C35.0327.00556379 33.8015 1.2272 33.7846 2.74337V18.7098z"/>\n <path id="reveal-spinner-top-4" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288v-3.2274c0-1.5594-1.2642-2.82358-2.8236-2.82358s-2.8235 1.26418-2.8235 2.82358v4.4z"/>\n <path id="reveal-spinner-center" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M50.4542 15.3288C5.46324 23.6926 1.83164 23.4439 1.45248 22.3172c-.773329-1.6548 3.63593-3.8942 5.79662-4.9915.28489-.1447.53068-.2695.72036-.3706v-.1237h-.12505c-1.62823.6226-8.646718 3.4958-7.768735 5.9832.875294 2.7456 11.653125 3.4958 34.086725-1.9939 18.7926-4.6145 27.4393-5.4925 28.3173-3.7446.6266 1.4952-4.0121 4.3644-8.5217 6.3597-.0966.0984-.1427.2357-.125.3724l.002.002c.1243.1244.2474.2475.3745.1231 1.6268-.6266 10.1499-4.238 9.7721-7.2323-.3738-1.9935-4.8842-2.6175-13.5274-1.3722z"/>\n <path id="reveal-spinner-bot-1" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M11.7557 30.5551v-2.0894c1.8291-.1048 3.6511-.3108 5.4575-.6171v2.7065c-.033 1.4835-1.245 2.6689-2.7288 2.6689s-2.6958-1.1854-2.7287-2.6689z"/>\n <path id="reveal-spinner-bot-2" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M22.7715 26.9222v7.602c-.0132 1.496 1.1804 2.7238 2.6762 2.7529 1.4957.0291 2.7362-1.1513 2.7813-2.6467v-8.8309c-1.7953.4821-3.6177.857-5.4575 1.1227z"/>\n <path id="reveal-spinner-bot-3" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M33.87 24.7193h-.3764v5.3419c.066 1.5151 1.3136 2.7095 2.8302 2.7095s2.7642-1.1944 2.8303-2.7095v-6.5883c-.3876.0886-.7821.1771-1.1838.2671l-.0007.0002c-1.2926.2897-2.6585.5959-4.0996.9764v.0027z"/>\n <path id="reveal-spinner-bot-4" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor" d="M44.5094 22.2377c2.1383-.3726 4.0242-.7438 5.6578-1.1137v4.3375c-.0249 1.5094-1.2534 2.7212-2.763 2.7254h-.0162c-.7432.0206-1.4641-.255-2.004-.7662-.54-.5112-.8546-1.216-.8746-1.9592v-3.2238z"/>\n</svg>\n',e.style.position="relative",e.appendChild(this.el)}static loadStyles(){if(document.getElementById(W.stylesId))return;const e=document.createElement("style");e.id=W.stylesId,e.appendChild(document.createTextNode(".reveal-viewer-spinner-top-left {\n top: 10px;\n left: 10px;\n}\n\n.reveal-viewer-spinner-top-right {\n top: 10px;\n right: 10px;\n}\n\n.reveal-viewer-spinner-bottom-left {\n bottom: 10px;\n left: 10px;\n}\n\n.reveal-viewer-spinner-bottom-right {\n bottom: 10px;\n right: 10px;\n}\n\n.reveal-viewer-spinner {\n position: absolute;\n color: white;\n}\n.reveal-viewer-spinner--dark {\n color: black;\n}\n\n.reveal-viewer-spinner--loading #reveal-spinner-bot-1,\n.reveal-viewer-spinner--loading #reveal-spinner-top-1 {\n animation: reveal-loading-opacity 0.8s ease-out infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-2,\n.reveal-viewer-spinner--loading #reveal-spinner-top-2 {\n animation: reveal-loading-opacity 0.8s ease-out 0.2s infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-3,\n.reveal-viewer-spinner--loading #reveal-spinner-top-3 {\n animation: reveal-loading-opacity 0.8s ease-out 0.4s infinite alternate;\n}\n.reveal-viewer-spinner--loading #reveal-spinner-bot-4,\n.reveal-viewer-spinner--loading #reveal-spinner-top-4 {\n animation: reveal-loading-opacity 0.8s ease-out 0.6s infinite alternate;\n}\n\n.reveal-viewer-spinner--loading #center {\n transform-origin: center;\n animation: reveal-loading-scale 1.6s ease-out infinite 0.8s alternate,\n reveal-loading-opacity 1.6s ease-out infinite alternate;\n}\n\n@keyframes reveal-loading-opacity {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0.2;\n }\n}\n\n@keyframes reveal-loading-scale {\n 100% {\n transform: scaleY(1.2) translateY(0.6px);\n }\n}\n")),document.head.appendChild(e)}set placement(e){switch(this.el.classList.remove(W.classnames.bottomLeft,W.classnames.bottomRight,W.classnames.topLeft,W.classnames.topRight),e){case"topLeft":this.el.classList.add(W.classnames.topLeft);break;case"topRight":this.el.classList.add(W.classnames.topRight);break;case"bottomLeft":this.el.classList.add(W.classnames.bottomLeft);break;case"bottomRight":this.el.classList.add(W.classnames.bottomRight);break;default:Object(a.k)(e,"Invalid placement: "+e)}}set opacity(e){this.el.style.opacity=""+e}get loading(){return this._loading}set loading(e){this._loading=e,e?(this.el.classList.add(W.classnames.loading),this.el.title=W.titles.loading):(this.el.classList.remove(W.classnames.loading),this.el.title=W.titles.idle)}updateBackgroundColor(e){const{l:t}=e.getHSL({h:0,s:0,l:0});t>.5?this.el.classList.add(W.classnames.dark):this.el.classList.remove(W.classnames.dark)}dispose(){this.el.remove();const e=document.getElementById(W.stylesId);e&&e.remove()}}W.stylesId="reveal-viewer-spinner-styles",W.classnames={base:"reveal-viewer-spinner",topLeft:"reveal-viewer-spinner-top-left",topRight:"reveal-viewer-spinner-top-right",bottomLeft:"reveal-viewer-spinner-bottom-left",bottomRight:"reveal-viewer-spinner-bottom-right",loading:"reveal-viewer-spinner--loading",dark:"reveal-viewer-spinner--dark"},W.titles={idle:"2.2.2",loading:"2.2.2 Loading..."};var q=n(9);
216
216
  /*!
217
217
  * Copyright 2021 Cognite AS
218
218
  */const H=new y.Vector2,K=new y.Raycaster;function X(e,t,n=.05){const{normalizedCoords:r,camera:o}=t;H.set(r.x,r.y),K.setFromCamera(r,o),K.params.Points={threshold:n};return K.intersectObjects(e,!0).filter(e=>function(e,t){let n=!0;for(let r=0;n&&r<t.length;++r)n=t[r].distanceToPoint(e)>=0;return n}
@@ -242,7 +242,7 @@ class re extends s{constructor(e,t,n={}){super(re.classToken),this._indexSet=new
242
242
  */class le{constructor(e){this._geometryClipBox=e}createClippedModel(e){const t=function e(t,n){const r=t.bounds,o=t.bounds.clone();if(o.intersect(n),o.isEmpty())return;{const i=[];for(let r=0;r<t.children.length;r++){const o=e(t.children[r],n);void 0!==o&&i.push(o)}const a=ue(o)/ue(r),s=Math.min(1,1-1/(1+10*a));return{...t,children:i,estimatedDrawCallCount:Math.ceil(s*t.estimatedDrawCallCount),estimatedRenderCost:Math.ceil(s*t.estimatedRenderCost),bounds:o}}}(e.scene.root,this._geometryClipBox);if(void 0===t)throw new Error("No sectors inside provided geometry clip box");const n=new Map;Object(a.t)(t,e=>(n.set(e.id,e),!0));const r=(new V.g).createSectorScene(e.scene.version,e.scene.maxTreeIndex,e.scene.unit,t);return{...e,scene:r,geometryClipBox:this._geometryClipBox.clone()}}}const ce={size:new y.Vector3};function ue(e){const{size:t}=ce;return e.getSize(t),t.x*t.y*t.z}
243
243
  /*!
244
244
  * Copyright 2021 Cognite AS
245
- */class pe{constructor(e,t,n,r){this._cadModelMap=new Map,this._subscription=new M.Subscription,this._needsRedraw=!1,this._markNeedsRedrawBound=this.markNeedsRedraw.bind(this),this._materialsChangedListener=this.handleMaterialsChanged.bind(this),this._materialManager=e,this._cadModelMetadataRepository=t,this._cadModelFactory=n,this._cadModelUpdateHandler=r,this._materialManager.on("materialsChanged",this._materialsChangedListener);this._subscription.add(this._cadModelUpdateHandler.consumedSectorObservable().subscribe({next:e=>{const t=this._cadModelMap.get(e.modelIdentifier);if(!t)return;e.instancedMeshes&&e.levelOfDetail===V.d.Detailed?t.updateInstancedMeshes(e.instancedMeshes,e.modelIdentifier,e.metadata.id):e.levelOfDetail!==V.d.Simple&&e.levelOfDetail!==V.d.Discarded||t.discardInstancedMeshes(e.metadata.id);const n=t.rootSector.sectorNodeMap.get(e.metadata.id);if(!n)throw new Error(`Could not find 3D node for sector ${e.metadata.id} - invalid id?`);e.group&&n.add(e.group),n.updateGeometry(e.group,e.levelOfDetail),this.markNeedsRedraw()},error:e=>{P.a.trackError(e,{moduleName:"CadManager",methodName:"constructor"})}}))}get materialManager(){return this._materialManager}get budget(){return this._cadModelUpdateHandler.budget}set budget(e){this._cadModelUpdateHandler.budget=e}get loadedStatistics(){return this._cadModelUpdateHandler.lastBudgetSpendage}dispose(){this._cadModelUpdateHandler.dispose(),this._subscription.unsubscribe(),this._materialManager.off("materialsChanged",this._materialsChangedListener)}requestRedraw(){this._needsRedraw=!0}resetRedraw(){this._needsRedraw=!1}get needsRedraw(){return this._needsRedraw}updateCamera(e){this._cadModelUpdateHandler.updateCamera(e),this._needsRedraw=!0}get clippingPlanes(){return this._materialManager.clippingPlanes}set clippingPlanes(e){this._materialManager.clippingPlanes=e,this._cadModelUpdateHandler.clippingPlanes=e,this._needsRedraw=!0}get renderMode(){return this._materialManager.getRenderMode()}set renderMode(e){this._materialManager.setRenderMode(e)}async addModel(e,t){const n=await this._cadModelMetadataRepository.loadData(e);if(this._cadModelMap.has(n.modelIdentifier))throw new Error(`Model ${e} has already been added`);const r=function(e,t){if(null===t)return e;return new le(t).createClippedModel(e)}
245
+ */class pe{constructor(e,t,n,r){this._cadModelMap=new Map,this._subscription=new M.Subscription,this._needsRedraw=!1,this._markNeedsRedrawBound=this.markNeedsRedraw.bind(this),this._materialsChangedListener=this.handleMaterialsChanged.bind(this),this._materialManager=e,this._cadModelMetadataRepository=t,this._cadModelFactory=n,this._cadModelUpdateHandler=r,this._materialManager.on("materialsChanged",this._materialsChangedListener);this._subscription.add(this._cadModelUpdateHandler.consumedSectorObservable().subscribe({next:e=>{const t=this._cadModelMap.get(e.modelIdentifier);if(!t)return;e.instancedMeshes&&e.levelOfDetail===V.d.Detailed?t.updateInstancedMeshes(e.instancedMeshes,e.modelIdentifier,e.metadata.id):e.levelOfDetail!==V.d.Simple&&e.levelOfDetail!==V.d.Discarded||t.discardInstancedMeshes(e.metadata.id);const n=t.rootSector.sectorNodeMap.get(e.metadata.id);if(!n)throw new Error(`Could not find 3D node for sector ${e.metadata.id} - invalid id?`);e.group&&n.add(e.group),n.updateGeometry(e.group,e.levelOfDetail),this.markNeedsRedraw()},error:e=>{N.a.trackError(e,{moduleName:"CadManager",methodName:"constructor"})}}))}get materialManager(){return this._materialManager}get budget(){return this._cadModelUpdateHandler.budget}set budget(e){this._cadModelUpdateHandler.budget=e}get loadedStatistics(){return this._cadModelUpdateHandler.lastBudgetSpendage}dispose(){this._cadModelUpdateHandler.dispose(),this._subscription.unsubscribe(),this._materialManager.off("materialsChanged",this._materialsChangedListener)}requestRedraw(){this._needsRedraw=!0}resetRedraw(){this._needsRedraw=!1}get needsRedraw(){return this._needsRedraw}updateCamera(e){this._cadModelUpdateHandler.updateCamera(e),this._needsRedraw=!0}get clippingPlanes(){return this._materialManager.clippingPlanes}set clippingPlanes(e){this._materialManager.clippingPlanes=e,this._cadModelUpdateHandler.clippingPlanes=e,this._needsRedraw=!0}get renderMode(){return this._materialManager.getRenderMode()}set renderMode(e){this._materialManager.setRenderMode(e)}async addModel(e,t){const n=await this._cadModelMetadataRepository.loadData(e);if(this._cadModelMap.has(n.modelIdentifier))throw new Error(`Model ${e} has already been added`);const r=function(e,t){if(null===t)return e;return new le(t).createClippedModel(e)}
246
246
  /*!
247
247
  * Copyright 2021 Cognite AS
248
248
  */(n,function(e,t){if(void 0===e||void 0===e.boundingBox)return null;if(!e.isBoundingBoxInModelCoordinates)return e.boundingBox;const n=e.boundingBox.clone();return n.applyMatrix4(t.inverseModelMatrix),n}(t,n)),o=this._cadModelFactory.createModel(r);return o.addEventListener("update",this._markNeedsRedrawBound),this._cadModelMap.set(n.modelIdentifier,o),this._cadModelUpdateHandler.addModel(o),o}removeModel(e){const t=e.cadModelMetadata;if(!this._cadModelMap.delete(t.modelIdentifier))throw new Error(`Could not remove model ${t.modelIdentifier} because it's not added`);e.removeEventListener("update",this._markNeedsRedrawBound),this._cadModelUpdateHandler.removeModel(e)}getLoadingStateObserver(){return this._cadModelUpdateHandler.getLoadingStateObserver()}markNeedsRedraw(){this._needsRedraw=!0}handleMaterialsChanged(){this.requestRedraw()}}
@@ -255,18 +255,18 @@ class me{constructor(e,t){this._materialManager=t,this._instancedGeometryMap=new
255
255
  */class ve{constructor(e){this._materialManager=e}createModel(e){const{modelIdentifier:t,scene:n}=e,r=new he(e,this._materialManager);if(this._materialManager.addModelMaterials(t,n.maxTreeIndex),null!==e.geometryClipBox){const t=function(e,t){const n=e.min.clone().applyMatrix4(t.modelMatrix),r=e.max.clone().applyMatrix4(t.modelMatrix);return(new y.Box3).setFromPoints([n,r])}
256
256
  /*!
257
257
  * Copyright 2021 Cognite AS
258
- */(e.geometryClipBox,e),n=new fe.a(t).clippingPlanes;this._materialManager.setModelClippingPlanes(e.modelIdentifier,n)}return r}}const xe=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,.5,.5,0,-.5,.5,0,-.5,-.5,0]),ge=new y.Float32BufferAttribute(xe.buffer,3),be=(new y.Box3).setFromArray(xe),ye=new Map([["color",{offset:0,size:12}],["treeIndex",{offset:12,size:4}],["normal",{offset:16,size:12}],["instanceMatrix",{offset:28,size:64}]]);
258
+ */(e.geometryClipBox,e),n=new fe.a(t).clippingPlanes;this._materialManager.setModelClippingPlanes(e.modelIdentifier,n)}return r}}const ge=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,.5,.5,0,-.5,.5,0,-.5,-.5,0]),xe=new y.Float32BufferAttribute(ge.buffer,3),be=(new y.Box3).setFromArray(ge),ye=new Map([["color",{offset:0,size:12}],["treeIndex",{offset:12,size:4}],["normal",{offset:16,size:12}],["instanceMatrix",{offset:28,size:64}]]);
259
259
  /*!
260
260
  * Copyright 2021 Cognite AS
261
261
  */
262
- function*_e(e,t,n,r=null){const o=e.primitives;if(Te(o.boxCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.j,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.i.index),i.setAttribute("position",V.i.position),i.setAttribute("normal",V.i.normal),we(i,o,t,a),Ne(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (Boxes)",a}(o.boxCollection,o.boxAttributes,t.box,r)),Te(o.circleCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),i.setAttribute("normal",V.t.position),we(i,o,t,a),Ne(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (Circles)",a}(o.circleCollection,o.circleAttributes,t.circle,r)),Te(o.coneCollection)&&(yield function(e,t,n,r,o){const i=Object(V.o)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (Cones)",s}(o.coneCollection,o.coneAttributes,t.cone,n,r)),Te(o.eccentricConeCollection)&&(yield function(e,t,n,r,o){const i=Object(V.o)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EccentricCones)",s}(o.eccentricConeCollection,o.eccentricConeAttributes,t.eccentricCone,n,r)),Te(o.ellipsoidSegmentCollection)&&(yield function(e,t,n,r,o){const i=Object(V.p)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EllipsoidSegments)",s}(o.ellipsoidSegmentCollection,o.ellipsoidSegmentAttributes,t.ellipsoidSegment,n,r)),Te(o.generalCylinderCollection)){const e=function(e,t,n,r,o){const i=Object(V.o)(e,t,o,"radius","radius");if(0===i.length)return null;const a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (GeneralCylinders)",s}(o.generalCylinderCollection,o.generalCylinderAttributes,t.generalCylinder,n,r);e&&(yield e)}Te(o.generalRingCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),we(i,o,t,a),Ne(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (GeneralRings)",a}(o.generalRingCollection,o.generalRingAttributes,t.generalRing,r)),Te(o.quadCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),i.setAttribute("normal",V.t.normal),we(i,o,t,a),Ne(i),a.name="Primitives (Quads)",a}(o.quadCollection,o.quadAttributes,t.quad,r)),Te(o.sphericalSegmentCollection)&&(yield function(e,t,n,r,o){const i=Object(V.p)(e,t,o,"radius","radius"),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),a.setAttribute("a_horizontalRadius",a.getAttribute("a_radius")),a.setAttribute("a_verticalRadius",a.getAttribute("a_radius")),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EllipsoidSegments)",s}(o.sphericalSegmentCollection,o.sphericalSegmentAttributes,t.sphericalSegment,n,r)),Te(o.torusSegmentCollection)&&(yield function(e,t,n,r){const o=function(e,t){const n=Array.from(t.values()).reduce((e,t)=>e+t.size,0),r=e.length/n;let o=0;const i=new DataView(e.buffer),a=t.get("size").offset;for(let e=0;e<r;e++)o=Math.max(o,i.getFloat32(e*n+a,!0));return o}(Object(V.n)(e,t,V.v,r),t),i=new a.b(new y.Box3);i.name="Primitives (TorusSegments)";let s=null,d=null;for(const[r,a]of V.w.entries()){const l=new y.InstancedBufferGeometry,c=new y.Mesh(l,n);if(l.setIndex(a.index),l.setAttribute("position",a.position),we(l,e,t,c),null===s){const e=Pe(l);s=e.boundingBox,d=e.boundingSphere,i.setBoundingBox(s)}l.boundingBox=s,l.boundingSphere=d,c.name="Primitives (TorusSegments) - LOD "+r,i.addLevel(c,Ce(o,r)),c.onBeforeRender=()=>Me(n,c.matrixWorld)}return i}(o.torusSegmentCollection,o.torusSegmentAttributes,t.torusSegment,r)),Te(o.trapeziumCollection)&&(yield function(e,t,n,r){const o=Object(V.q)(e,t,r),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.x.index),a.setAttribute("position",V.x.position),we(a,o,t,s),function(e){const{bbox:t,p:n}=Re;t.makeEmpty();const r=e.getAttribute("a_vertex1"),o=e.getAttribute("a_vertex2"),a=e.getAttribute("a_vertex3"),s=e.getAttribute("a_vertex4");i()(void 0!==r&&void 0!==o&&void 0!==a&&void 0!==s);for(let e=0;e<r.count;++e)n.set(r.getX(e),r.getY(e),r.getZ(e)),t.expandByPoint(n),n.set(o.getX(e),o.getY(e),o.getZ(e)),t.expandByPoint(n),n.set(a.getX(e),a.getY(e),a.getZ(e)),t.expandByPoint(n),n.set(s.getX(e),s.getY(e),s.getZ(e)),t.expandByPoint(n);e.boundingBox=t,e.boundingSphere=e.boundingSphere||new y.Sphere,e.boundingBox.getBoundingSphere(e.boundingSphere)}
262
+ function*_e(e,t,n,r=null){const o=e.primitives;if(Te(o.boxCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.j,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.i.index),i.setAttribute("position",V.i.position),i.setAttribute("normal",V.i.normal),we(i,o,t,a),Pe(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (Boxes)",a}(o.boxCollection,o.boxAttributes,t.box,r)),Te(o.circleCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),i.setAttribute("normal",V.t.position),we(i,o,t,a),Pe(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (Circles)",a}(o.circleCollection,o.circleAttributes,t.circle,r)),Te(o.coneCollection)&&(yield function(e,t,n,r,o){const i=Object(V.o)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (Cones)",s}(o.coneCollection,o.coneAttributes,t.cone,n,r)),Te(o.eccentricConeCollection)&&(yield function(e,t,n,r,o){const i=Object(V.o)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EccentricCones)",s}(o.eccentricConeCollection,o.eccentricConeAttributes,t.eccentricCone,n,r)),Te(o.ellipsoidSegmentCollection)&&(yield function(e,t,n,r,o){const i=Object(V.p)(e,t,o),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EllipsoidSegments)",s}(o.ellipsoidSegmentCollection,o.ellipsoidSegmentAttributes,t.ellipsoidSegment,n,r)),Te(o.generalCylinderCollection)){const e=function(e,t,n,r,o){const i=Object(V.o)(e,t,o,"radius","radius");if(0===i.length)return null;const a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (GeneralCylinders)",s}(o.generalCylinderCollection,o.generalCylinderAttributes,t.generalCylinder,n,r);e&&(yield e)}Te(o.generalRingCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),we(i,o,t,a),Pe(i),a.onBeforeRender=()=>Me(n,a.matrixWorld),a.name="Primitives (GeneralRings)",a}(o.generalRingCollection,o.generalRingAttributes,t.generalRing,r)),Te(o.quadCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.u,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.t.index),i.setAttribute("position",V.t.position),i.setAttribute("normal",V.t.normal),we(i,o,t,a),Pe(i),a.name="Primitives (Quads)",a}(o.quadCollection,o.quadAttributes,t.quad,r)),Te(o.sphericalSegmentCollection)&&(yield function(e,t,n,r,o){const i=Object(V.p)(e,t,o,"radius","radius"),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.k.index),a.setAttribute("position",V.k.position),we(a,i,t,s),Ie(a,r),a.setAttribute("a_horizontalRadius",a.getAttribute("a_radius")),a.setAttribute("a_verticalRadius",a.getAttribute("a_radius")),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (EllipsoidSegments)",s}(o.sphericalSegmentCollection,o.sphericalSegmentAttributes,t.sphericalSegment,n,r)),Te(o.torusSegmentCollection)&&(yield function(e,t,n,r){const o=function(e,t){const n=Array.from(t.values()).reduce((e,t)=>e+t.size,0),r=e.length/n;let o=0;const i=new DataView(e.buffer),a=t.get("size").offset;for(let e=0;e<r;e++)o=Math.max(o,i.getFloat32(e*n+a,!0));return o}(Object(V.n)(e,t,V.v,r),t),i=new a.b(new y.Box3);i.name="Primitives (TorusSegments)";let s=null,d=null;for(const[r,a]of V.w.entries()){const l=new y.InstancedBufferGeometry,c=new y.Mesh(l,n);if(l.setIndex(a.index),l.setAttribute("position",a.position),we(l,e,t,c),null===s){const e=Ne(l);s=e.boundingBox,d=e.boundingSphere,i.setBoundingBox(s)}l.boundingBox=s,l.boundingSphere=d,c.name="Primitives (TorusSegments) - LOD "+r,i.addLevel(c,Ce(o,r)),c.onBeforeRender=()=>Me(n,c.matrixWorld)}return i}(o.torusSegmentCollection,o.torusSegmentAttributes,t.torusSegment,r)),Te(o.trapeziumCollection)&&(yield function(e,t,n,r){const o=Object(V.q)(e,t,r),a=new y.InstancedBufferGeometry,s=new y.Mesh(a,n);return a.setIndex(V.x.index),a.setAttribute("position",V.x.position),we(a,o,t,s),function(e){const{bbox:t,p:n}=Re;t.makeEmpty();const r=e.getAttribute("a_vertex1"),o=e.getAttribute("a_vertex2"),a=e.getAttribute("a_vertex3"),s=e.getAttribute("a_vertex4");i()(void 0!==r&&void 0!==o&&void 0!==a&&void 0!==s);for(let e=0;e<r.count;++e)n.set(r.getX(e),r.getY(e),r.getZ(e)),t.expandByPoint(n),n.set(o.getX(e),o.getY(e),o.getZ(e)),t.expandByPoint(n),n.set(a.getX(e),a.getY(e),a.getZ(e)),t.expandByPoint(n),n.set(s.getX(e),s.getY(e),s.getZ(e)),t.expandByPoint(n);e.boundingBox=t,e.boundingSphere=e.boundingSphere||new y.Sphere,e.boundingBox.getBoundingSphere(e.boundingSphere)}
263
263
  /*!
264
264
  * Copyright 2021 Cognite AS
265
- */(a),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (Trapeziums)",s}(o.trapeziumCollection,o.trapeziumAttributes,t.trapezium,r)),Te(o.nutCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.s,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.r.index),i.setAttribute("position",V.r.position),i.setAttribute("normal",V.r.normal),we(i,o,t,a),Ne(i),a.name="Primitives (Nuts)",a}(o.nutCollection,o.nutAttributes,t.nut,r))}function Te(e){return e.length>0}function we(e,t,n,r){const o=Array.from(n.values()).reduce((e,t)=>e+t.size,0);!function(e){const t=e.get("instanceMatrix");if(!t)return;const n=t.size/4;for(let r=0;r<4;r++){const o={size:n,offset:t.offset+n*r};e.set("instanceMatrix_column_"+r,o)}e.delete("instanceMatrix")}(n);const i=new y.InstancedInterleavedBuffer(t,o),s=new y.InstancedInterleavedBuffer(new Float32Array(t.buffer),o/4);for(const[t,r]of n){const n="color"===t,o=n?i:s,a=n?r.size:r.size/4,d=n?r.offset:r.offset/4;e.setAttribute("a_"+t,new y.InterleavedBufferAttribute(o,a,d,n))}r.onAfterRender=()=>{a.n.bind(s)(),a.n.bind(i)(),r.onAfterRender=()=>{}},e.instanceCount=t.length/o,function(){const i=new DataView(t.buffer),a=n.get("treeIndex").offset,s=new Set;for(let t=0;t<e.instanceCount;t++)s.add(i.getFloat32(t*o+a,!0));r.userData.treeIndices=s}()}function Ce(e,t){if(0===t)return 0;return e*5**t}function Me(e,t){e.uniforms.inverseModelMatrix.value.copy(t).invert()}function Ie(e,t){e.boundingSphere=e.boundingSphere||new y.Sphere,t.getBoundingSphere(e.boundingSphere)}const Se={baseBoundingBox:new y.Box3,instanceBoundingBox:new y.Box3,instanceMatrix:new y.Matrix4,p:new y.Vector3};function Pe(e){const{baseBoundingBox:t,instanceBoundingBox:n,instanceMatrix:r,p:o}=Se;t.makeEmpty();const a=new y.Box3,s=e.getAttribute("position");for(let e=0;e<s.count;++e)o.set(s.getX(e),s.getY(e),s.getZ(e)),t.expandByPoint(o);const d=e.getAttribute("a_instanceMatrix_column_0"),l=e.getAttribute("a_instanceMatrix_column_1"),c=e.getAttribute("a_instanceMatrix_column_2"),u=e.getAttribute("a_instanceMatrix_column_3");i()(void 0!==d&&void 0!==l&&void 0!==c&&void 0!==u);for(let e=0;e<d.count;++e)r.set(d.getX(e),l.getX(e),c.getX(e),u.getX(e),d.getY(e),l.getY(e),c.getY(e),u.getY(e),d.getZ(e),l.getZ(e),c.getZ(e),u.getZ(e),d.getW(e),l.getW(e),c.getW(e),u.getW(e)),n.copy(t).applyMatrix4(r),a.expandByPoint(n.min),a.expandByPoint(n.max);return{boundingBox:a,boundingSphere:a.getBoundingSphere(new y.Sphere)}}function Ne(e){const{boundingBox:t,boundingSphere:n}=Pe(e);e.boundingBox=t,e.boundingSphere=n}const Re={bbox:new y.Box3,p:new y.Vector3};function Ae(e,t,n,r){const o=new a.a;if(o.name="Quads",0===e.buffer.byteLength)return{sectorMeshes:new a.a,instancedMeshes:[]};const i=function(e,t,n,r){const o=new Uint8Array(e.buffer),i=Object(V.n)(o,ye,be,r);if(0===i.byteLength)return;const s=new Float32Array(i.buffer);if(i.byteLength%23!=0)throw new Error("Expected buffer size to be multiple of 23, but got "+s.byteLength);const d=new y.InstancedBufferGeometry,l=new y.InstancedInterleavedBuffer(s,23),c=new y.InterleavedBufferAttribute(l,3,0,!0),u=new y.InterleavedBufferAttribute(l,1,3,!1),p=new y.InterleavedBufferAttribute(l,3,4,!0),m=new y.InterleavedBufferAttribute(l,4,7,!1),h=new y.InterleavedBufferAttribute(l,4,11,!1),f=new y.InterleavedBufferAttribute(l,4,15,!1),v=new y.InterleavedBufferAttribute(l,4,19,!1);d.setAttribute("position",ge),d.setAttribute("color",c),d.setAttribute("treeIndex",u),d.setAttribute("normal",p),d.setAttribute("matrix0",m),d.setAttribute("matrix1",h),d.setAttribute("matrix2",f),d.setAttribute("matrix3",v);const x=new y.Mesh(d,t.simple);return x.name="Low detail geometry",x.onAfterRender=()=>{a.n.bind(l)(),x.onAfterRender=()=>{}},x.onBeforeRender=()=>{t.simple.uniforms.inverseModelMatrix.value.copy(x.matrixWorld).invert()},function(){const t=new Set;for(let n=0;n<e.length/23;n++)t.add(e[23*n+3]);x.userData.treeIndices=t}(),x.geometry.boundingSphere=new y.Sphere,n.getBoundingSphere(x.geometry.boundingSphere),x}(e.buffer,n,t,r);return void 0!==i&&o.add(i),{sectorMeshes:o,instancedMeshes:[]}}
265
+ */(a),s.onBeforeRender=()=>Me(n,s.matrixWorld),s.name="Primitives (Trapeziums)",s}(o.trapeziumCollection,o.trapeziumAttributes,t.trapezium,r)),Te(o.nutCollection)&&(yield function(e,t,n,r){const o=Object(V.n)(e,t,V.s,r),i=new y.InstancedBufferGeometry,a=new y.Mesh(i,n);return i.setIndex(V.r.index),i.setAttribute("position",V.r.position),i.setAttribute("normal",V.r.normal),we(i,o,t,a),Pe(i),a.name="Primitives (Nuts)",a}(o.nutCollection,o.nutAttributes,t.nut,r))}function Te(e){return e.length>0}function we(e,t,n,r){const o=Array.from(n.values()).reduce((e,t)=>e+t.size,0);!function(e){const t=e.get("instanceMatrix");if(!t)return;const n=t.size/4;for(let r=0;r<4;r++){const o={size:n,offset:t.offset+n*r};e.set("instanceMatrix_column_"+r,o)}e.delete("instanceMatrix")}(n);const i=new y.InstancedInterleavedBuffer(t,o),s=new y.InstancedInterleavedBuffer(new Float32Array(t.buffer),o/4);for(const[t,r]of n){const n="color"===t,o=n?i:s,a=n?r.size:r.size/4,d=n?r.offset:r.offset/4;e.setAttribute("a_"+t,new y.InterleavedBufferAttribute(o,a,d,n))}r.onAfterRender=()=>{a.n.bind(s)(),a.n.bind(i)(),r.onAfterRender=()=>{}},e.instanceCount=t.length/o,function(){const i=new DataView(t.buffer),a=n.get("treeIndex").offset,s=new Set;for(let t=0;t<e.instanceCount;t++)s.add(i.getFloat32(t*o+a,!0));r.userData.treeIndices=s}()}function Ce(e,t){if(0===t)return 0;return e*5**t}function Me(e,t){e.uniforms.inverseModelMatrix.value.copy(t).invert()}function Ie(e,t){e.boundingSphere=e.boundingSphere||new y.Sphere,t.getBoundingSphere(e.boundingSphere)}const Se={baseBoundingBox:new y.Box3,instanceBoundingBox:new y.Box3,instanceMatrix:new y.Matrix4,p:new y.Vector3};function Ne(e){const{baseBoundingBox:t,instanceBoundingBox:n,instanceMatrix:r,p:o}=Se;t.makeEmpty();const a=new y.Box3,s=e.getAttribute("position");for(let e=0;e<s.count;++e)o.set(s.getX(e),s.getY(e),s.getZ(e)),t.expandByPoint(o);const d=e.getAttribute("a_instanceMatrix_column_0"),l=e.getAttribute("a_instanceMatrix_column_1"),c=e.getAttribute("a_instanceMatrix_column_2"),u=e.getAttribute("a_instanceMatrix_column_3");i()(void 0!==d&&void 0!==l&&void 0!==c&&void 0!==u);for(let e=0;e<d.count;++e)r.set(d.getX(e),l.getX(e),c.getX(e),u.getX(e),d.getY(e),l.getY(e),c.getY(e),u.getY(e),d.getZ(e),l.getZ(e),c.getZ(e),u.getZ(e),d.getW(e),l.getW(e),c.getW(e),u.getW(e)),n.copy(t).applyMatrix4(r),a.expandByPoint(n.min),a.expandByPoint(n.max);return{boundingBox:a,boundingSphere:a.getBoundingSphere(new y.Sphere)}}function Pe(e){const{boundingBox:t,boundingSphere:n}=Ne(e);e.boundingBox=t,e.boundingSphere=n}const Re={bbox:new y.Box3,p:new y.Vector3};function Ae(e,t,n,r){const o=new a.a;if(o.name="Quads",0===e.buffer.byteLength)return{sectorMeshes:new a.a,instancedMeshes:[]};const i=function(e,t,n,r){const o=new Uint8Array(e.buffer),i=Object(V.n)(o,ye,be,r);if(0===i.byteLength)return;const s=new Float32Array(i.buffer);if(i.byteLength%23!=0)throw new Error("Expected buffer size to be multiple of 23, but got "+s.byteLength);const d=new y.InstancedBufferGeometry,l=new y.InstancedInterleavedBuffer(s,23),c=new y.InterleavedBufferAttribute(l,3,0,!0),u=new y.InterleavedBufferAttribute(l,1,3,!1),p=new y.InterleavedBufferAttribute(l,3,4,!0),m=new y.InterleavedBufferAttribute(l,4,7,!1),h=new y.InterleavedBufferAttribute(l,4,11,!1),f=new y.InterleavedBufferAttribute(l,4,15,!1),v=new y.InterleavedBufferAttribute(l,4,19,!1);d.setAttribute("position",xe),d.setAttribute("color",c),d.setAttribute("treeIndex",u),d.setAttribute("normal",p),d.setAttribute("matrix0",m),d.setAttribute("matrix1",h),d.setAttribute("matrix2",f),d.setAttribute("matrix3",v);const g=new y.Mesh(d,t.simple);return g.name="Low detail geometry",g.onAfterRender=()=>{a.n.bind(l)(),g.onAfterRender=()=>{}},g.onBeforeRender=()=>{t.simple.uniforms.inverseModelMatrix.value.copy(g.matrixWorld).invert()},function(){const t=new Set;for(let n=0;n<e.length/23;n++)t.add(e[23*n+3]);g.userData.treeIndices=t}(),g.geometry.boundingSphere=new y.Sphere,n.getBoundingSphere(g.geometry.boundingSphere),g}(e.buffer,n,t,r);return void 0!==i&&o.add(i),{sectorMeshes:o,instancedMeshes:[]}}
266
266
  /*!
267
267
  * Copyright 2021 Cognite AS
268
268
  */
269
- class De{constructor(e){this.materialManager=e}transformSimpleSector(e,t,n,r){const o=this.materialManager.getModelMaterials(e);return i()(void 0!==o,"Could not find materials for model '"+e),Promise.resolve(Ae(n,t.bounds,o,r))}transformDetailedSector(e,t,n,r){const o=this.materialManager.getModelMaterials(e);return i()(void 0!==o,"Could not find materials for model '"+e),Promise.resolve(function(e,t,n,r){const o=t.bounds;null!==r&&r.containsBox(o)&&(r=null);const i=new a.a;for(const t of _e(e,n,o,r))i.add(t);const s=Object(V.l)(e.triangleMeshes,o,n.triangleMesh,r);for(const e of s)i.add(e);return{sectorMeshes:i,instancedMeshes:e.instanceMeshes.map(e=>{const t=e.instances.map(t=>Object(V.m)(e.vertices,e.indices,t,r)).filter(e=>e.treeIndices.length>0);return{fileId:e.fileId,vertices:e.vertices,indices:e.indices,instances:t}}).filter(e=>e.instances.length>0)}}(n,t,o,r))}}
269
+ class De{constructor(e){this.materialManager=e}transformSimpleSector(e,t,n,r){const o=this.materialManager.getModelMaterials(e);return i()(void 0!==o,"Could not find materials for model '"+e),Promise.resolve(Ae(n,t.bounds,o,r))}transformDetailedSector(e,t,n,r){const o=this.materialManager.getModelMaterials(e);return i()(void 0!==o,"Could not find materials for model '"+e),Promise.resolve(function(e,t,n,r){const o=t.bounds;null!==r&&function(e,t,n=1e-4){const r=e,o=t;return r.min.x-o.min.x>=n&&o.max.x-r.max.x>=n&&r.min.y-o.min.y>=n&&o.max.y-r.max.y>=n&&r.min.z-o.min.z>=n&&o.max.z-r.max.z>=n}(r,o)&&(r=null);const i=new a.a;for(const t of _e(e,n,o,r))i.add(t);const s=Object(V.l)(e.triangleMeshes,o,n.triangleMesh,r);for(const e of s)i.add(e);return{sectorMeshes:i,instancedMeshes:e.instanceMeshes.map(e=>{const t=e.instances.map(t=>Object(V.m)(e.vertices,e.indices,t,r)).filter(e=>e.treeIndices.length>0);return{fileId:e.fileId,vertices:e.vertices,indices:e.indices,instances:t}}).filter(e=>e.instances.length>0)}}(n,t,o,r))}}
270
270
  /*!
271
271
  * Copyright 2021 Cognite AS
272
272
  */function*ze(e){const t=new Array(e.length);for(let n=0;n<e.length;++n)t[n]={fileId:e[n],index:n};t.sort((e,t)=>e.fileId-t.fileId);let n=0;for(;n<t.length;){const e=t[n].fileId,r=Ee(t,e,n,e=>e.fileId),o=new Array(r+1-n);for(let e=n;e<r+1;e++)o[e-n]=t[e].index;yield{id:e,meshIndices:o},n=r+1}}function Ee(e,t,n,r){let o=n,i=e.length-1,a=e.length;for(;o<=i;){const n=Math.floor((o+i)/2),s=r(e[n]);s>t?i=n-1:(s<t||(a=n),o=n+1)}return a}
@@ -275,7 +275,7 @@ class De{constructor(e){this.materialManager=e}transformSimpleSector(e,t,n,r){co
275
275
  */function Oe(e){const t=new Array(e.length);return e.forEach((n,r)=>{t[r]=r>0?t[r-1]+e[r-1]:0}),t}
276
276
  /*!
277
277
  * Copyright 2021 Cognite AS
278
- */class Fe{constructor(e,t,n){this._modelSectorProvider=e,this._modelDataParser=t,this._modelDataTransformer=n,this._consumedSectorCache=new a.f(50,e=>{void 0!==e.group&&e.group.dereference()}),this._ctmFileCache=new a.g(10)}clear(){this._consumedSectorCache.clear(),this._ctmFileCache.clear()}async loadSector(e){var t,n;const r=this.wantedSectorCacheKey(e);try{if(this._consumedSectorCache.has(r))return this._consumedSectorCache.get(r);switch(e.levelOfDetail){case V.d.Detailed:{const n=await this.loadDetailedSectorFromNetwork(e);return this._consumedSectorCache.forceInsert(r,n),null===(t=null==n?void 0:n.group)||void 0===t||t.reference(),n}case V.d.Simple:{const t=await this.loadSimpleSectorFromNetwork(e);return this._consumedSectorCache.forceInsert(r,t),null===(n=null==t?void 0:t.group)||void 0===n||n.reference(),t}case V.d.Discarded:return{modelIdentifier:e.modelIdentifier,metadata:e.metadata,levelOfDetail:e.levelOfDetail,instancedMeshes:[],group:void 0};default:Object(a.k)(e.levelOfDetail)}}catch(e){throw this._consumedSectorCache.remove(r),P.a.trackError(e,{methodName:"loadSector",moduleName:"CachedRepository"}),e}}async loadSimpleSectorFromNetwork(e){const t=await this._modelSectorProvider.getBinaryFile(e.modelBaseUrl,e.metadata.facesFile.fileName),n=await this._modelDataParser.parseF3D(new Uint8Array(t)),r=await this._modelDataTransformer.transformSimpleSector(e.modelIdentifier,e.metadata,n,e.geometryClipBox);return{...e,group:r.sectorMeshes,instancedMeshes:r.instancedMeshes}}async loadI3DFromNetwork(e,t){const n=await this._modelSectorProvider.getBinaryFile(e,t);return this._modelDataParser.parseI3D(new Uint8Array(n))}async loadCtmsFromNetwork(e,t){const n=await Promise.all(t.map(t=>this.loadCtmFileFromNetwork(e,t)));return t.reduce((e,t,r)=>e.set(t,n[r]),new Map)}async loadDetailedSectorFromNetwork(e){const t=e.metadata.indexFile,n=this.loadI3DFromNetwork(e.modelBaseUrl,t.fileName),r=this.loadCtmsFromNetwork(e.modelBaseUrl,t.peripheralFiles),o=await n,i=await r,a=this.finalizeDetailed(o,i),s=await this._modelDataTransformer.transformDetailedSector(e.modelIdentifier,e.metadata,a,e.geometryClipBox);return{...e,group:s.sectorMeshes,instancedMeshes:s.instancedMeshes}}async loadCtmFileFromNetwork(e,t){const n=this.ctmFileCacheKey(e,t),r=this._ctmFileCache.get(n);if(void 0!==r)return r;const o=this._modelSectorProvider.getBinaryFile(e,t).then(e=>this._modelDataParser.parseCTM(new Uint8Array(e)));return this._ctmFileCache.set(n,o),o}finalizeDetailed(e,t){const{instanceMeshes:n,triangleMeshes:r}=e,o=(()=>{const{fileIds:e,colors:n,triangleCounts:o,treeIndices:i}=r,a=[];for(const{id:r,meshIndices:s}of ze(e)){const e=s.map(e=>o[e]),d=Oe(e),l=`mesh_${r}.ctm`,{indices:c,vertices:u,normals:p}=t.get(l),m=new Uint8Array(3*c.length),h=new Float32Array(c.length);for(let t=0;t<s.length;t++){const r=s[t],o=i[r],a=d[t],l=e[t],[u,p,f]=[n[4*r+0],n[4*r+1],n[4*r+2]];for(let e=a;e<a+l;e++)for(let t=0;t<3;t++){const n=c[3*e+t];h[n]=o,m[3*n]=u,m[3*n+1]=p,m[3*n+2]=f}}const f={colors:m,fileId:r,treeIndices:h,indices:c,vertices:u,normals:p};a.push(f)}return a})(),i=(()=>{const{fileIds:e,colors:r,treeIndices:o,triangleCounts:i,triangleOffsets:a,instanceMatrices:s}=n,d=[];for(const{id:n,meshIndices:l}of ze(e)){const e=`mesh_${n}.ctm`,c=t.get(e),u=c.indices,p=c.vertices,m=[],h=new Float64Array(l.map(e=>a[e])),f=new Float64Array(l.map(e=>i[e]));for(const{id:e,meshIndices:t}of ze(h)){const n=f[t[0]],i=new Float32Array(16*t.length),a=new Float32Array(t.length),d=new Uint8Array(4*t.length);for(let e=0;e<t.length;e++){const n=l[t[e]],c=o[n],u=s.subarray(16*n,16*n+16);i.set(u,16*e),a[e]=c;const p=r.subarray(4*n,4*n+4);d.set(p,4*e)}m.push({triangleCount:n,triangleOffset:e,instanceMatrices:i,colors:d,treeIndices:a})}const v={fileId:n,indices:u,vertices:p,instances:m};d.push(v)}return d})();return{treeIndexToNodeIdMap:e.treeIndexToNodeIdMap,nodeIdToTreeIndexMap:e.nodeIdToTreeIndexMap,primitives:e.primitives,instanceMeshes:i,triangleMeshes:o}}wantedSectorCacheKey(e){return e.modelIdentifier+"."+e.metadata.id+"."+e.levelOfDetail}ctmFileCacheKey(e,t){return e+"."+t}}
278
+ */class Fe{constructor(e,t,n){this._modelSectorProvider=e,this._modelDataParser=t,this._modelDataTransformer=n,this._consumedSectorCache=new a.f(50,e=>{void 0!==e.group&&e.group.dereference()}),this._ctmFileCache=new a.g(10)}clear(){this._consumedSectorCache.clear(),this._ctmFileCache.clear()}async loadSector(e){var t,n;const r=this.wantedSectorCacheKey(e);try{if(this._consumedSectorCache.has(r))return this._consumedSectorCache.get(r);switch(e.levelOfDetail){case V.d.Detailed:{const n=await this.loadDetailedSectorFromNetwork(e);return this._consumedSectorCache.forceInsert(r,n),null===(t=null==n?void 0:n.group)||void 0===t||t.reference(),n}case V.d.Simple:{const t=await this.loadSimpleSectorFromNetwork(e);return this._consumedSectorCache.forceInsert(r,t),null===(n=null==t?void 0:t.group)||void 0===n||n.reference(),t}case V.d.Discarded:return{modelIdentifier:e.modelIdentifier,metadata:e.metadata,levelOfDetail:e.levelOfDetail,instancedMeshes:[],group:void 0};default:Object(a.k)(e.levelOfDetail)}}catch(e){throw this._consumedSectorCache.remove(r),N.a.trackError(e,{methodName:"loadSector",moduleName:"CachedRepository"}),e}}async loadSimpleSectorFromNetwork(e){const t=await this._modelSectorProvider.getBinaryFile(e.modelBaseUrl,e.metadata.facesFile.fileName),n=await this._modelDataParser.parseF3D(new Uint8Array(t)),r=await this._modelDataTransformer.transformSimpleSector(e.modelIdentifier,e.metadata,n,e.geometryClipBox);return{...e,group:r.sectorMeshes,instancedMeshes:r.instancedMeshes}}async loadI3DFromNetwork(e,t){const n=await this._modelSectorProvider.getBinaryFile(e,t);return this._modelDataParser.parseI3D(new Uint8Array(n))}async loadCtmsFromNetwork(e,t){const n=await Promise.all(t.map(t=>this.loadCtmFileFromNetwork(e,t)));return t.reduce((e,t,r)=>e.set(t,n[r]),new Map)}async loadDetailedSectorFromNetwork(e){const t=e.metadata.indexFile,n=this.loadI3DFromNetwork(e.modelBaseUrl,t.fileName),r=this.loadCtmsFromNetwork(e.modelBaseUrl,t.peripheralFiles),o=await n,i=await r,a=this.finalizeDetailed(o,i),s=await this._modelDataTransformer.transformDetailedSector(e.modelIdentifier,e.metadata,a,e.geometryClipBox);return{...e,group:s.sectorMeshes,instancedMeshes:s.instancedMeshes}}async loadCtmFileFromNetwork(e,t){const n=this.ctmFileCacheKey(e,t),r=this._ctmFileCache.get(n);if(void 0!==r)return r;const o=this._modelSectorProvider.getBinaryFile(e,t).then(e=>this._modelDataParser.parseCTM(new Uint8Array(e)));return this._ctmFileCache.set(n,o),o}finalizeDetailed(e,t){const{instanceMeshes:n,triangleMeshes:r}=e,o=(()=>{const{fileIds:e,colors:n,triangleCounts:o,treeIndices:i}=r,a=[];for(const{id:r,meshIndices:s}of ze(e)){const e=s.map(e=>o[e]),d=Oe(e),l=`mesh_${r}.ctm`,{indices:c,vertices:u,normals:p}=t.get(l),m=new Uint8Array(3*c.length),h=new Float32Array(c.length);for(let t=0;t<s.length;t++){const r=s[t],o=i[r],a=d[t],l=e[t],[u,p,f]=[n[4*r+0],n[4*r+1],n[4*r+2]];for(let e=a;e<a+l;e++)for(let t=0;t<3;t++){const n=c[3*e+t];h[n]=o,m[3*n]=u,m[3*n+1]=p,m[3*n+2]=f}}const f={colors:m,fileId:r,treeIndices:h,indices:c,vertices:u,normals:p};a.push(f)}return a})(),i=(()=>{const{fileIds:e,colors:r,treeIndices:o,triangleCounts:i,triangleOffsets:a,instanceMatrices:s}=n,d=[];for(const{id:n,meshIndices:l}of ze(e)){const e=`mesh_${n}.ctm`,c=t.get(e),u=c.indices,p=c.vertices,m=[],h=new Float64Array(l.map(e=>a[e])),f=new Float64Array(l.map(e=>i[e]));for(const{id:e,meshIndices:t}of ze(h)){const n=f[t[0]],i=new Float32Array(16*t.length),a=new Float32Array(t.length),d=new Uint8Array(4*t.length);for(let e=0;e<t.length;e++){const n=l[t[e]],c=o[n],u=s.subarray(16*n,16*n+16);i.set(u,16*e),a[e]=c;const p=r.subarray(4*n,4*n+4);d.set(p,4*e)}m.push({triangleCount:n,triangleOffset:e,instanceMatrices:i,colors:d,treeIndices:a})}const v={fileId:n,indices:u,vertices:p,instances:m};d.push(v)}return d})();return{treeIndexToNodeIdMap:e.treeIndexToNodeIdMap,nodeIdToTreeIndexMap:e.nodeIdToTreeIndexMap,primitives:e.primitives,instanceMeshes:i,triangleMeshes:o}}wantedSectorCacheKey(e){return e.modelIdentifier+"."+e.metadata.id+"."+e.levelOfDetail}ctmFileCacheKey(e,t){return e+"."+t}}
279
279
  /*!
280
280
  * Copyright 2021 Cognite AS
281
281
  */function Be(e){return Object(M.pipe)(Object(k.switchMap)(t=>function(e){return Object(M.of)(!1).pipe(Object(k.delay)(e),Object(k.startWith)(!0))}
@@ -315,22 +315,22 @@ class pt{constructor(e,t){this.sectors=[],this._totalCost={downloadSize:0,drawCa
315
315
  /*!
316
316
  * Copyright 2021 Cognite AS
317
317
  */
318
- function xt(e,t,n,r,o,i){const a=new V.a,s=new V.b(e,t,a),d=new ve(r),l=new V.c,c=new De(r),u=new Fe(t,l,c),{internal:p}=i,m=p&&p.sectorCuller?p.sectorCuller:function(e,t){const n=new lt({renderer:e,occludingGeometryProvider:t});return new ft({renderer:e,coverageUtil:n})}(n,o),h=new Xe(u,m);return new pe(r,s,d,h)}
318
+ function gt(e,t,n,r,o,i){const a=new V.a,s=new V.b(e,t,a),d=new ve(r),l=new V.c,c=new De(r),u=new Fe(t,l,c),{internal:p}=i,m=p&&p.sectorCuller?p.sectorCuller:function(e,t){const n=new lt({renderer:e,occludingGeometryProvider:t});return new ft({renderer:e,coverageUtil:n})}(n,o),h=new Xe(u,m);return new pe(r,s,d,h)}
319
319
  /*!
320
320
  * Copyright 2021 Cognite AS
321
- */var gt,bt,yt,_t,Tt,wt,Ct;(bt=gt||(gt={}))[bt.Circle=q.PointShape.CIRCLE]="Circle",bt[bt.Square=q.PointShape.SQUARE]="Square",(_t=yt||(yt={}))[_t.Rgb=q.PointColorType.RGB]="Rgb",_t[_t.Depth=q.PointColorType.DEPTH]="Depth",_t[_t.Height=q.PointColorType.HEIGHT]="Height",_t[_t.PointIndex=q.PointColorType.POINT_INDEX]="PointIndex",_t[_t.LevelOfDetail=q.PointColorType.LOD]="LevelOfDetail",_t[_t.Classification=q.PointColorType.CLASSIFICATION]="Classification",_t[_t.Intensity=q.PointColorType.INTENSITY]="Intensity",(wt=Tt||(Tt={}))[wt.Adaptive=q.PointSizeType.ADAPTIVE]="Adaptive",wt[wt.Fixed=q.PointSizeType.FIXED]="Fixed",function(e){e[e.Default=-1]="Default",e[e.Created=0]="Created",e[e.Unclassified=1]="Unclassified",e[e.Ground=2]="Ground",e[e.LowVegetation=3]="LowVegetation",e[e.MedVegetation=4]="MedVegetation",e[e.HighVegetation=5]="HighVegetation",e[e.Building=6]="Building",e[e.LowPoint=7]="LowPoint",e[e.ReservedOrHighPoint=8]="ReservedOrHighPoint",e[e.Water=9]="Water",e[e.Rail=10]="Rail",e[e.RoadSurface=11]="RoadSurface",e[e.ReservedOrBridgeDeck=12]="ReservedOrBridgeDeck",e[e.WireGuard=13]="WireGuard",e[e.WireConductor=14]="WireConductor",e[e.TransmissionTower=15]="TransmissionTower",e[e.WireStructureConnector=16]="WireStructureConnector",e[e.BridgeDeck=17]="BridgeDeck",e[e.HighNoise=18]="HighNoise",e[e.OverheadStructure=19]="OverheadStructure",e[e.IgnoredGround=20]="IgnoredGround",e[e.Snow=21]="Snow",e[e.TemporalExclusion=22]="TemporalExclusion",e[e.UserDefinableOffset=64]="UserDefinableOffset"}(Ct||(Ct={}));class Mt extends y.Group{constructor(e,t,n){super(),this.name="PointCloudNode",this._potreeGroup=e,this._potreeNode=t,this._cameraConfiguration=n,this.add(this._potreeGroup),this.matrixAutoUpdate=!1}get potreeGroup(){return this._potreeGroup}get potreeNode(){return this._potreeNode}get hasCameraConfiguration(){return void 0!==this._cameraConfiguration}get cameraConfiguration(){return this._cameraConfiguration}get needsRedraw(){return this._potreeGroup.needsRedraw}requestRedraw(){this._potreeGroup.requestRedraw()}get pointSize(){return this._potreeNode.pointSize}set pointSize(e){this._potreeNode.pointSize=e}get pointSizeType(){return this._potreeNode.pointSizeType}set pointSizeType(e){this._potreeNode.pointSizeType=e}get pointBudget(){return this._potreeNode.pointBudget}set pointBudget(e){this._potreeNode.pointBudget=e}get visiblePointCount(){return this._potreeNode.visiblePointCount}get pointColorType(){return this._potreeNode.pointColorType}set pointColorType(e){this._potreeNode.pointColorType=e}get pointShape(){return this._potreeNode.pointShape}set pointShape(e){this._potreeNode.pointShape=e}setClassVisible(e,t){if(!this.hasClass(e))throw new Error("Point cloud model doesn't have class "+e);const n=It(e);this._potreeNode.classification[n].w=t?1:0,this._potreeNode.recomputeClassification()}isClassVisible(e){if(!this.hasClass(e))throw new Error("Point cloud model doesn't have class "+e);const t=It(e);return 0!==this._potreeNode.classification[t].w}hasClass(e){const t=It(e);return void 0!==this._potreeNode.classification[t]}getClasses(){return Object.keys(this._potreeNode.classification).map(e=>"DEFAULT"===e?-1:parseInt(e,10)).sort((e,t)=>e-t)}getBoundingBox(e){return(e=e||new y.Box3).copy(this._potreeNode.boundingBox),e.applyMatrix4(this.matrixWorld),e}setModelTransformation(e){this.matrix.copy(e),this.updateMatrixWorld(!0)}getModelTransformation(e=new y.Matrix4){return e.copy(this.matrix)}}function It(e){return e===Ct.Default?"DEFAULT":e}
321
+ */var xt,bt,yt,_t,Tt,wt,Ct;(bt=xt||(xt={}))[bt.Circle=q.PointShape.CIRCLE]="Circle",bt[bt.Square=q.PointShape.SQUARE]="Square",(_t=yt||(yt={}))[_t.Rgb=q.PointColorType.RGB]="Rgb",_t[_t.Depth=q.PointColorType.DEPTH]="Depth",_t[_t.Height=q.PointColorType.HEIGHT]="Height",_t[_t.PointIndex=q.PointColorType.POINT_INDEX]="PointIndex",_t[_t.LevelOfDetail=q.PointColorType.LOD]="LevelOfDetail",_t[_t.Classification=q.PointColorType.CLASSIFICATION]="Classification",_t[_t.Intensity=q.PointColorType.INTENSITY]="Intensity",(wt=Tt||(Tt={}))[wt.Adaptive=q.PointSizeType.ADAPTIVE]="Adaptive",wt[wt.Fixed=q.PointSizeType.FIXED]="Fixed",function(e){e[e.Default=-1]="Default",e[e.Created=0]="Created",e[e.Unclassified=1]="Unclassified",e[e.Ground=2]="Ground",e[e.LowVegetation=3]="LowVegetation",e[e.MedVegetation=4]="MedVegetation",e[e.HighVegetation=5]="HighVegetation",e[e.Building=6]="Building",e[e.LowPoint=7]="LowPoint",e[e.ReservedOrHighPoint=8]="ReservedOrHighPoint",e[e.Water=9]="Water",e[e.Rail=10]="Rail",e[e.RoadSurface=11]="RoadSurface",e[e.ReservedOrBridgeDeck=12]="ReservedOrBridgeDeck",e[e.WireGuard=13]="WireGuard",e[e.WireConductor=14]="WireConductor",e[e.TransmissionTower=15]="TransmissionTower",e[e.WireStructureConnector=16]="WireStructureConnector",e[e.BridgeDeck=17]="BridgeDeck",e[e.HighNoise=18]="HighNoise",e[e.OverheadStructure=19]="OverheadStructure",e[e.IgnoredGround=20]="IgnoredGround",e[e.Snow=21]="Snow",e[e.TemporalExclusion=22]="TemporalExclusion",e[e.UserDefinableOffset=64]="UserDefinableOffset"}(Ct||(Ct={}));class Mt extends y.Group{constructor(e,t,n){super(),this.name="PointCloudNode",this._potreeGroup=e,this._potreeNode=t,this._cameraConfiguration=n,this.add(this._potreeGroup),this.matrixAutoUpdate=!1}get potreeGroup(){return this._potreeGroup}get potreeNode(){return this._potreeNode}get hasCameraConfiguration(){return void 0!==this._cameraConfiguration}get cameraConfiguration(){return this._cameraConfiguration}get needsRedraw(){return this._potreeGroup.needsRedraw}requestRedraw(){this._potreeGroup.requestRedraw()}get pointSize(){return this._potreeNode.pointSize}set pointSize(e){this._potreeNode.pointSize=e}get pointSizeType(){return this._potreeNode.pointSizeType}set pointSizeType(e){this._potreeNode.pointSizeType=e}get pointBudget(){return this._potreeNode.pointBudget}set pointBudget(e){this._potreeNode.pointBudget=e}get visiblePointCount(){return this._potreeNode.visiblePointCount}get pointColorType(){return this._potreeNode.pointColorType}set pointColorType(e){this._potreeNode.pointColorType=e}get pointShape(){return this._potreeNode.pointShape}set pointShape(e){this._potreeNode.pointShape=e}setClassVisible(e,t){if(!this.hasClass(e))throw new Error("Point cloud model doesn't have class "+e);const n=It(e);this._potreeNode.classification[n].w=t?1:0,this._potreeNode.recomputeClassification()}isClassVisible(e){if(!this.hasClass(e))throw new Error("Point cloud model doesn't have class "+e);const t=It(e);return 0!==this._potreeNode.classification[t].w}hasClass(e){const t=It(e);return void 0!==this._potreeNode.classification[t]}getClasses(){return Object.keys(this._potreeNode.classification).map(e=>"DEFAULT"===e?-1:parseInt(e,10)).sort((e,t)=>e-t)}getBoundingBox(e){return(e=e||new y.Box3).copy(this._potreeNode.boundingBox),e.applyMatrix4(this.matrixWorld),e}setModelTransformation(e){this.matrix.copy(e),this.updateMatrixWorld(!0)}getModelTransformation(e=new y.Matrix4){return e.copy(this.matrix)}}function It(e){return e===Ct.Default?"DEFAULT":e}
322
322
  /*!
323
323
  * Copyright 2021 Cognite AS
324
- */class St extends y.Object3D{constructor(e=200){super(),this._needsRedraw=!1,this._lastDrawPointBuffersHash=0,this._forceLoadingSubject=new M.Subject,this.nodes=[],this.numNodesLoadingAfterLastRedraw=0,this.numChildrenAfterLastRedraw=0,this.potreeGroup=new q.Group,this.potreeGroup.name="Potree.Group",this.name="Potree point cloud wrapper",this.add(this.potreeGroup);const t=new y.Mesh(new y.BufferGeometry);t.name="onAfterRender trigger (no geometry)",t.frustumCulled=!1,t.onAfterRender=()=>{this.resetRedraw(),this._lastDrawPointBuffersHash=this.pointBuffersHash},this.add(t),this._loadingObservable=this.createLoadingStateObservable(e),this._lastDrawPointBuffersHash=this.pointBuffersHash,this.pointBudget=2e6}get needsRedraw(){return this._needsRedraw||this._lastDrawPointBuffersHash!==this.pointBuffersHash||q.Global.numNodesLoading!==this.numNodesLoadingAfterLastRedraw||this.numChildrenAfterLastRedraw!==this.potreeGroup.children.length||this.nodes.some(e=>e.needsRedraw)}get pointBudget(){return this.potreeGroup.pointBudget}set pointBudget(e){this.potreeGroup.pointBudget=e}getLoadingStateObserver(){return this._loadingObservable}addPointCloud(e){this.potreeGroup.add(e.octtree),this.nodes.push(e),this._forceLoadingSubject.next(),this.requestRedraw()}removePointCloud(e){const t=this.nodes.indexOf(e);if(-1===t)throw new Error("Point cloud is not added - cannot remove it");this.potreeGroup.remove(e.octtree),this.nodes.splice(t,1)}requestRedraw(){this._needsRedraw=!0}resetRedraw(){this._needsRedraw=!1,this.numNodesLoadingAfterLastRedraw=q.Global.numNodesLoading,this.numChildrenAfterLastRedraw=this.potreeGroup.children.length,this.nodes.forEach(e=>e.resetRedraw())}createLoadingStateObservable(e){const t=this._forceLoadingSubject.pipe((n=5*e,Object(M.pipe)(Object(k.switchMap)(()=>Object(M.of)(!1).pipe(Object(k.delay)(n),Object(k.startWith)(!0))),Object(k.distinctUntilChanged)())));var n;return Object(M.combineLatest)([Object(M.interval)(e).pipe(Object(k.map)(Pt),Object(k.distinctUntilChanged)((e,t)=>e.isLoading===t.isLoading&&e.itemsLoaded===t.itemsLoaded&&e.itemsRequested===t.itemsRequested)),t]).pipe(Object(k.map)(e=>{const[t,n]=e;return n&&!t.isLoading?{isLoading:!0,itemsLoaded:0,itemsRequested:1,itemsCulled:0}:t}),Object(k.startWith)({isLoading:!1,itemsLoaded:0,itemsRequested:0,itemsCulled:0}),Object(k.distinctUntilChanged)(),Object(k.share)())}get pointBuffersHash(){const e=this.potreeGroup.pointclouds;let t=3131961357;for(const n of e)n.traverseVisible(e=>{if(e.isPoints){const n=e.geometry;t^=n.getAttribute("position").count}}),t^=n.id;return t}}function Pt(){return{isLoading:q.Global.numNodesLoading>0,itemsLoaded:0,itemsRequested:q.Global.numNodesLoading,itemsCulled:0}}
324
+ */class St extends y.Object3D{constructor(e=200){super(),this._needsRedraw=!1,this._lastDrawPointBuffersHash=0,this._forceLoadingSubject=new M.Subject,this.nodes=[],this.numNodesLoadingAfterLastRedraw=0,this.numChildrenAfterLastRedraw=0,this.potreeGroup=new q.Group,this.potreeGroup.name="Potree.Group",this.name="Potree point cloud wrapper",this.add(this.potreeGroup);const t=new y.Mesh(new y.BufferGeometry);t.name="onAfterRender trigger (no geometry)",t.frustumCulled=!1,t.onAfterRender=()=>{this.resetRedraw(),this._lastDrawPointBuffersHash=this.pointBuffersHash},this.add(t),this._loadingObservable=this.createLoadingStateObservable(e),this._lastDrawPointBuffersHash=this.pointBuffersHash,this.pointBudget=2e6}get needsRedraw(){return this._needsRedraw||this._lastDrawPointBuffersHash!==this.pointBuffersHash||q.Global.numNodesLoading!==this.numNodesLoadingAfterLastRedraw||this.numChildrenAfterLastRedraw!==this.potreeGroup.children.length||this.nodes.some(e=>e.needsRedraw)}get pointBudget(){return this.potreeGroup.pointBudget}set pointBudget(e){this.potreeGroup.pointBudget=e}getLoadingStateObserver(){return this._loadingObservable}addPointCloud(e){this.potreeGroup.add(e.octtree),this.nodes.push(e),this._forceLoadingSubject.next(),this.requestRedraw()}removePointCloud(e){const t=this.nodes.indexOf(e);if(-1===t)throw new Error("Point cloud is not added - cannot remove it");this.potreeGroup.remove(e.octtree),this.nodes.splice(t,1)}requestRedraw(){this._needsRedraw=!0}resetRedraw(){this._needsRedraw=!1,this.numNodesLoadingAfterLastRedraw=q.Global.numNodesLoading,this.numChildrenAfterLastRedraw=this.potreeGroup.children.length,this.nodes.forEach(e=>e.resetRedraw())}createLoadingStateObservable(e){const t=this._forceLoadingSubject.pipe((n=5*e,Object(M.pipe)(Object(k.switchMap)(()=>Object(M.of)(!1).pipe(Object(k.delay)(n),Object(k.startWith)(!0))),Object(k.distinctUntilChanged)())));var n;return Object(M.combineLatest)([Object(M.interval)(e).pipe(Object(k.map)(Nt),Object(k.distinctUntilChanged)((e,t)=>e.isLoading===t.isLoading&&e.itemsLoaded===t.itemsLoaded&&e.itemsRequested===t.itemsRequested)),t]).pipe(Object(k.map)(e=>{const[t,n]=e;return n&&!t.isLoading?{isLoading:!0,itemsLoaded:0,itemsRequested:1,itemsCulled:0}:t}),Object(k.startWith)({isLoading:!1,itemsLoaded:0,itemsRequested:0,itemsCulled:0}),Object(k.distinctUntilChanged)(),Object(k.share)())}get pointBuffersHash(){const e=this.potreeGroup.pointclouds;let t=3131961357;for(const n of e)n.traverseVisible(e=>{if(e.isPoints){const n=e.geometry;t^=n.getAttribute("position").count}}),t^=n.id;return t}}function Nt(){return{isLoading:q.Global.numNodesLoading>0,itemsLoaded:0,itemsRequested:q.Global.numNodesLoading,itemsCulled:0}}
325
325
  /*!
326
326
  * Copyright 2021 Cognite AS
327
- */class Nt{constructor(e,t){this._pointCloudMetadataRepository=e,this._pointCloudFactory=t,this._pointCloudGroupWrapper=new St}requestRedraw(){this._pointCloudGroupWrapper.requestRedraw()}resetRedraw(){this._pointCloudGroupWrapper.resetRedraw()}get pointBudget(){return this._pointCloudGroupWrapper.pointBudget}set pointBudget(e){this._pointCloudGroupWrapper.pointBudget=e}get needsRedraw(){return this._pointCloudGroupWrapper.needsRedraw}set clippingPlanes(e){this._pointCloudGroupWrapper.traverse(t=>{if(t.material){const n=t.material;n.clipping=!0,n.clipIntersection=!1,n.clippingPlanes=e}})}getLoadingStateObserver(){return this._pointCloudGroupWrapper.getLoadingStateObserver()}updateCamera(e){}async addModel(e){const t=await this._pointCloudMetadataRepository.loadData(e),n=this._pointCloudFactory.createModel(t);this._pointCloudGroupWrapper.addPointCloud(n);const r=new Mt(this._pointCloudGroupWrapper,n,t.cameraConfiguration);return r.setModelTransformation(t.modelMatrix),r}removeModel(e){this._pointCloudGroupWrapper.removePointCloud(e.potreeNode)}}
327
+ */class Pt{constructor(e,t){this._pointCloudMetadataRepository=e,this._pointCloudFactory=t,this._pointCloudGroupWrapper=new St}requestRedraw(){this._pointCloudGroupWrapper.requestRedraw()}resetRedraw(){this._pointCloudGroupWrapper.resetRedraw()}get pointBudget(){return this._pointCloudGroupWrapper.pointBudget}set pointBudget(e){this._pointCloudGroupWrapper.pointBudget=e}get needsRedraw(){return this._pointCloudGroupWrapper.needsRedraw}set clippingPlanes(e){this._pointCloudGroupWrapper.traverse(t=>{if(t.material){const n=t.material;n.clipping=!0,n.clipIntersection=!1,n.clippingPlanes=e}})}getLoadingStateObserver(){return this._pointCloudGroupWrapper.getLoadingStateObserver()}updateCamera(e){}async addModel(e){const t=await this._pointCloudMetadataRepository.loadData(e),n=this._pointCloudFactory.createModel(t);this._pointCloudGroupWrapper.addPointCloud(n);const r=new Mt(this._pointCloudGroupWrapper,n,t.cameraConfiguration);return r.setModelTransformation(t.modelMatrix),r}removeModel(e){this._pointCloudGroupWrapper.removePointCloud(e.potreeNode)}}
328
328
  /*!
329
329
  * Copyright 2021 Cognite AS
330
330
  */const Rt=(new y.Matrix4).identity();class At{constructor(e,t,n="ept.json"){this._modelMetadataProvider=e,this._modelDataProvider=t,this._blobFileName=n}async loadData(e){const t=this._modelMetadataProvider.getModelUri(e),n=this._modelMetadataProvider.getModelMatrix(e),r=this._modelMetadataProvider.getModelCamera(e),o=await t,i=await n,s=await this._modelDataProvider.getJsonFile(o,this._blobFileName),d=await r;return{modelBaseUrl:o,modelMatrix:i,cameraConfiguration:Object(a.s)(d,Rt),scene:s}}}
331
331
  /*!
332
332
  * Copyright 2021 Cognite AS
333
- */class Dt{constructor(e){this._needsRedraw=!1,this.octtree=e,this.pointSize=2,this.pointSizeType=Tt.Adaptive,this.pointColorType=yt.Rgb,this.pointShape=gt.Circle,this.pointBudget=1/0}get needsRedraw(){return this._needsRedraw}get pointSize(){return this.octtree.material.size}set pointSize(e){this.octtree.material.size=e,this._needsRedraw=!0}get pointSizeType(){return this.octtree.material.pointSizeType}set pointSizeType(e){this.octtree.material.pointSizeType=e,this._needsRedraw=!0}get pointBudget(){return this.octtree.pointBudget}set pointBudget(e){this.octtree.pointBudget=e,this._needsRedraw=!0}get visiblePointCount(){return this.octtree.numVisiblePoints||0}get boundingBox(){const e=this.octtree.pcoGeometry.tightBoundingBox||this.octtree.pcoGeometry.boundingBox||this.octtree.boundingBox,t=new y.Vector3(e.min.x,e.min.z,-e.min.y),n=new y.Vector3(e.max.x,e.max.z,-e.max.y);return(new y.Box3).setFromPoints([t,n])}get pointColorType(){return this.octtree.material.pointColorType}set pointColorType(e){this.octtree.material.pointColorType=e,this._needsRedraw=!0}get pointShape(){return this.octtree.material.shape}set pointShape(e){this.octtree.material.shape=e,this._needsRedraw=!0}get classification(){return this.octtree.material.classification}recomputeClassification(){this.octtree.material.recomputeClassification()}resetRedraw(){this._needsRedraw=!1}}
333
+ */class Dt{constructor(e){this._needsRedraw=!1,this.octtree=e,this.pointSize=2,this.pointSizeType=Tt.Adaptive,this.pointColorType=yt.Rgb,this.pointShape=xt.Circle,this.pointBudget=1/0}get needsRedraw(){return this._needsRedraw}get pointSize(){return this.octtree.material.size}set pointSize(e){this.octtree.material.size=e,this._needsRedraw=!0}get pointSizeType(){return this.octtree.material.pointSizeType}set pointSizeType(e){this.octtree.material.pointSizeType=e,this._needsRedraw=!0}get pointBudget(){return this.octtree.pointBudget}set pointBudget(e){this.octtree.pointBudget=e,this._needsRedraw=!0}get visiblePointCount(){return this.octtree.numVisiblePoints||0}get boundingBox(){const e=this.octtree.pcoGeometry.tightBoundingBox||this.octtree.pcoGeometry.boundingBox||this.octtree.boundingBox,t=new y.Vector3(e.min.x,e.min.z,-e.min.y),n=new y.Vector3(e.max.x,e.max.z,-e.max.y);return(new y.Box3).setFromPoints([t,n])}get pointColorType(){return this.octtree.material.pointColorType}set pointColorType(e){this.octtree.material.pointColorType=e,this._needsRedraw=!0}get pointShape(){return this.octtree.material.shape}set pointShape(e){this.octtree.material.shape=e,this._needsRedraw=!0}get classification(){return this.octtree.material.classification}recomputeClassification(){this.octtree.material.recomputeClassification()}resetRedraw(){this._needsRedraw=!1}}
334
334
  /*!
335
335
  * Copyright 2021 Cognite AS
336
336
  */class zt{constructor(e){this._httpHeadersProvider=e}createModel(e){this.initializePointCloudXhrRequestHeaders();const{modelBaseUrl:t,scene:n}=e,r=new q.PointCloudEptGeometry(t+"/",n),o=r.offset.x,i=r.offset.y,a=r.offset.z,s=new q.PointCloudEptGeometryNode(r,r.boundingBox,0,o,i,a);r.root=s,r.root.load();const d=new q.PointCloudOctree(r);d.name="PointCloudOctree: "+t;return new Dt(d)}initializePointCloudXhrRequestHeaders(){const e=this._httpHeadersProvider.headers;let t=q.XHRFactory.config.customHeaders;for(const[n,r]of Object.entries(e))t=t.filter(e=>e.header!==n),t.push({header:n,value:r});q.XHRFactory.config.customHeaders=t.filter(e=>e.header)}}
@@ -340,7 +340,7 @@ function xt(e,t,n,r,o,i){const a=new V.a,s=new V.b(e,t,a),d=new ve(r),l=new V.c,
340
340
  /*!
341
341
  * Copyright 2021 Cognite AS
342
342
  */
343
- class Et{constructor(e,t,n){this._lastCamera={position:new y.Vector3(NaN,NaN,NaN),quaternion:new y.Quaternion(NaN,NaN,NaN,NaN),zoom:NaN},this._isDisposed=!1,this._subscriptions=new M.Subscription,this._events={loadingStateChanged:new a.d},this._effectRenderManager=t,this._cadManager=e,this._pointCloudManager=n,this.initLoadingStateObserver(this._cadManager,this._pointCloudManager),this._updateSubject=new M.Subject,this._updateSubject.pipe(Object(k.auditTime)(5e3),Object(k.tap)(()=>{P.a.trackCameraNavigation({moduleName:"RevealManager",methodName:"update"})})).subscribe()}dispose(){this._isDisposed||(this._cadManager.dispose(),this._subscriptions.unsubscribe(),this._isDisposed=!0)}requestRedraw(){this._cadManager.requestRedraw(),this._pointCloudManager.requestRedraw()}resetRedraw(){this._cadManager.resetRedraw(),this._pointCloudManager.resetRedraw()}get debugRenderTiming(){return this._effectRenderManager.debugRenderTimings}set debugRenderTiming(e){this._effectRenderManager.debugRenderTimings=e}get renderOptions(){return this._effectRenderManager.renderOptions}set renderOptions(e){this._effectRenderManager.renderOptions=null!=e?e:I}get needsRedraw(){return this._cadManager.needsRedraw||this._pointCloudManager.needsRedraw}update(e){(this._lastCamera.zoom!==e.zoom||!this._lastCamera.position.equals(e.position)||!this._lastCamera.quaternion.equals(e.quaternion))&&(this._lastCamera.position.copy(e.position),this._lastCamera.quaternion.copy(e.quaternion),this._lastCamera.zoom=e.zoom,this._cadManager.updateCamera(e),this._updateSubject.next())}get cadBudget(){return this._cadManager.budget}set cadBudget(e){this._cadManager.budget=e}get cadLoadedStatistics(){return this._cadManager.loadedStatistics}get cadRenderMode(){return this._cadManager.renderMode}set cadRenderMode(e){this._cadManager.renderMode=e}get pointCloudBudget(){return{numberOfPoints:this._pointCloudManager.pointBudget}}set pointCloudBudget(e){this._pointCloudManager.pointBudget=e.numberOfPoints}set clippingPlanes(e){this._cadManager.clippingPlanes=e,this._pointCloudManager.clippingPlanes=e}get clippingPlanes(){return this._cadManager.clippingPlanes}on(e,t){switch(e){case"loadingStateChanged":this._events.loadingStateChanged.subscribe(t);break;default:throw new Error(`Unsupported event '${e}'`)}}off(e,t){switch(e){case"loadingStateChanged":this._events.loadingStateChanged.unsubscribe(t);break;default:throw new Error(`Unsupported event '${e}'`)}}render(e){this._effectRenderManager.render(e),this.resetRedraw()}setRenderTarget(e,t=!0){this._effectRenderManager.setRenderTarget(e),this._effectRenderManager.setRenderTargetAutoSize(t)}async addModel(e,t,n){switch(P.a.trackLoadModel({type:e},t),e){case"cad":return this._cadManager.addModel(t,null==n?void 0:n.geometryFilter);case"pointcloud":return this._pointCloudManager.addModel(t);default:throw new Error(`Model type '${e}' is not supported`)}}removeModel(e,t){switch(e){case"cad":this._cadManager.removeModel(t);break;case"pointcloud":this._pointCloudManager.removeModel(t);break;default:Object(a.k)(e)}}addUiObject(e,t,n){this._effectRenderManager.addUiObject(e,t,n),this.requestRedraw()}removeUiObject(e){this._effectRenderManager.removeUiObject(e),this.requestRedraw()}notifyLoadingStateChanged(e){this._events.loadingStateChanged.fire(e)}initLoadingStateObserver(e,t){this._subscriptions.add(Object(M.combineLatest)([e.getLoadingStateObserver(),t.getLoadingStateObserver()]).pipe(Object(k.observeOn)(M.asyncScheduler),Object(k.subscribeOn)(M.asyncScheduler),Object(k.map)(([e,t])=>({isLoading:e.isLoading||t.isLoading,itemsLoaded:e.itemsLoaded+t.itemsLoaded,itemsRequested:e.itemsRequested+t.itemsRequested,itemsCulled:e.itemsCulled+t.itemsCulled})),Object(k.distinctUntilChanged)((e,t)=>e.itemsLoaded===t.itemsLoaded&&e.itemsRequested===t.itemsRequested)).subscribe(this.notifyLoadingStateChanged.bind(this),e=>P.a.trackError(e,{moduleName:"RevealManager",methodName:"constructor"})))}}
343
+ class Et{constructor(e,t,n){this._lastCamera={position:new y.Vector3(NaN,NaN,NaN),quaternion:new y.Quaternion(NaN,NaN,NaN,NaN),zoom:NaN},this._isDisposed=!1,this._subscriptions=new M.Subscription,this._events={loadingStateChanged:new a.d},this._effectRenderManager=t,this._cadManager=e,this._pointCloudManager=n,this.initLoadingStateObserver(this._cadManager,this._pointCloudManager),this._updateSubject=new M.Subject,this._updateSubject.pipe(Object(k.auditTime)(5e3),Object(k.tap)(()=>{N.a.trackCameraNavigation({moduleName:"RevealManager",methodName:"update"})})).subscribe()}dispose(){this._isDisposed||(this._cadManager.dispose(),this._subscriptions.unsubscribe(),this._isDisposed=!0)}requestRedraw(){this._cadManager.requestRedraw(),this._pointCloudManager.requestRedraw()}resetRedraw(){this._cadManager.resetRedraw(),this._pointCloudManager.resetRedraw()}get debugRenderTiming(){return this._effectRenderManager.debugRenderTimings}set debugRenderTiming(e){this._effectRenderManager.debugRenderTimings=e}get renderOptions(){return this._effectRenderManager.renderOptions}set renderOptions(e){this._effectRenderManager.renderOptions=null!=e?e:I}get needsRedraw(){return this._cadManager.needsRedraw||this._pointCloudManager.needsRedraw}update(e){(this._lastCamera.zoom!==e.zoom||!this._lastCamera.position.equals(e.position)||!this._lastCamera.quaternion.equals(e.quaternion))&&(this._lastCamera.position.copy(e.position),this._lastCamera.quaternion.copy(e.quaternion),this._lastCamera.zoom=e.zoom,this._cadManager.updateCamera(e),this._updateSubject.next())}get cadBudget(){return this._cadManager.budget}set cadBudget(e){this._cadManager.budget=e}get cadLoadedStatistics(){return this._cadManager.loadedStatistics}get cadRenderMode(){return this._cadManager.renderMode}set cadRenderMode(e){this._cadManager.renderMode=e}get pointCloudBudget(){return{numberOfPoints:this._pointCloudManager.pointBudget}}set pointCloudBudget(e){this._pointCloudManager.pointBudget=e.numberOfPoints}set clippingPlanes(e){this._cadManager.clippingPlanes=e,this._pointCloudManager.clippingPlanes=e}get clippingPlanes(){return this._cadManager.clippingPlanes}on(e,t){switch(e){case"loadingStateChanged":this._events.loadingStateChanged.subscribe(t);break;default:throw new Error(`Unsupported event '${e}'`)}}off(e,t){switch(e){case"loadingStateChanged":this._events.loadingStateChanged.unsubscribe(t);break;default:throw new Error(`Unsupported event '${e}'`)}}render(e){this._effectRenderManager.render(e),this.resetRedraw()}setRenderTarget(e,t=!0){this._effectRenderManager.setRenderTarget(e),this._effectRenderManager.setRenderTargetAutoSize(t)}async addModel(e,t,n){switch(N.a.trackLoadModel({type:e},t),e){case"cad":return this._cadManager.addModel(t,null==n?void 0:n.geometryFilter);case"pointcloud":return this._pointCloudManager.addModel(t);default:throw new Error(`Model type '${e}' is not supported`)}}removeModel(e,t){switch(e){case"cad":this._cadManager.removeModel(t);break;case"pointcloud":this._pointCloudManager.removeModel(t);break;default:Object(a.k)(e)}}addUiObject(e,t,n){this._effectRenderManager.addUiObject(e,t,n),this.requestRedraw()}removeUiObject(e){this._effectRenderManager.removeUiObject(e),this.requestRedraw()}notifyLoadingStateChanged(e){this._events.loadingStateChanged.fire(e)}initLoadingStateObserver(e,t){this._subscriptions.add(Object(M.combineLatest)([e.getLoadingStateObserver(),t.getLoadingStateObserver()]).pipe(Object(k.observeOn)(M.asyncScheduler),Object(k.subscribeOn)(M.asyncScheduler),Object(k.map)(([e,t])=>({isLoading:e.isLoading||t.isLoading,itemsLoaded:e.itemsLoaded+t.itemsLoaded,itemsRequested:e.itemsRequested+t.itemsRequested,itemsCulled:e.itemsCulled+t.itemsCulled})),Object(k.distinctUntilChanged)((e,t)=>e.itemsLoaded===t.itemsLoaded&&e.itemsRequested===t.itemsRequested)).subscribe(this.notifyLoadingStateChanged.bind(this),e=>N.a.trackError(e,{moduleName:"RevealManager",methodName:"constructor"})))}}
344
344
  /*!
345
345
  * Copyright 2021 Cognite AS
346
346
  */class Ot{constructor(e){this._renderManager=e}renderOccludingGeometry(e,t){const n={renderTarget:this._renderManager.getRenderTarget(),autoSize:this._renderManager.getRenderTargetAutoSize()};try{this._renderManager.setRenderTarget(e),this._renderManager.renderDetailedToDepthOnly(t)}finally{this._renderManager.setRenderTarget(n.renderTarget),this._renderManager.setRenderTargetAutoSize(n.autoSize)}}}
@@ -366,23 +366,23 @@ class Lt{constructor(e,t){this._needsUpdate=!1,this._handleTransformChangedBound
366
366
  /*!
367
367
  * Copyright 2021 Cognite AS
368
368
  */
369
- class Kt{constructor(){this._events={materialsChanged:new a.d},this._renderMode=S.Color,this.materialsMap=new Map,this._clippingPlanes=[]}get clippingPlanes(){return this._clippingPlanes}set clippingPlanes(e){this._clippingPlanes=e;for(const e of this.materialsMap.keys())this.updateClippingPlanesForModel(e);this.triggerMaterialsChanged()}on(e,t){switch(e){case"materialsChanged":this._events.materialsChanged.subscribe(t);break;default:Object(a.k)(e,"Unexpected event '"+e)}}off(e,t){switch(e){case"materialsChanged":this._events.materialsChanged.unsubscribe(t);break;default:Object(a.k)(e,"Unexpected event '"+e)}}addModelMaterials(e,t){const n=new x,r=new Ft(t+1,n);r.build();const o=new Vt,i=new Lt(t+1,o);i.build();const a=Ht()(()=>this.updateMaterials(e),75,{leading:!0,trailing:!0}),s=()=>this.updateTransforms(e);n.on("changed",a),o.on("changed",s);const d=function(e,t,n,r,o){const i=new y.Texture(jt);i.needsUpdate=!0;const a=new y.ShaderMaterial({name:"Primitives (Box)",clipping:!0,clippingPlanes:t,extensions:{fragDepth:!0},vertexShader:nt.boxPrimitive.vertex,fragmentShader:nt.boxPrimitive.fragment,side:y.DoubleSide,uniforms:{inverseModelMatrix:{value:new y.Matrix4}}}),s=new y.ShaderMaterial({name:"Primitives (Circle)",clipping:!0,clippingPlanes:t,extensions:{fragDepth:!0},vertexShader:nt.circlePrimitive.vertex,fragmentShader:nt.circlePrimitive.fragment,side:y.DoubleSide,uniforms:{inverseModelMatrix:{value:new y.Matrix4}}}),d=new y.ShaderMaterial({name:"Primitives (Nuts)",clipping:!0,clippingPlanes:t,vertexShader:nt.nutPrimitive.vertex,fragmentShader:nt.nutPrimitive.fragment,side:y.DoubleSide}),l=new y.ShaderMaterial({name:"Primitives (Quads)",clipping:!0,clippingPlanes:t,vertexShader:nt.quadPrimitive.vertex,fragmentShader:nt.quadPrimitive.fragment,side:y.DoubleSide}),c=new y.ShaderMaterial({name:"Primitives (General rings)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.generalRingPrimitive.vertex,fragmentShader:nt.generalRingPrimitive.fragment,side:y.DoubleSide}),u=new y.ShaderMaterial({name:"Primitives (Cone)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.conePrimitive.vertex,fragmentShader:nt.conePrimitive.fragment,side:y.DoubleSide}),p=new y.ShaderMaterial({name:"Primitives (Eccentric cone)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.eccentricConePrimitive.vertex,fragmentShader:nt.eccentricConePrimitive.fragment,side:y.DoubleSide}),m=new y.ShaderMaterial({name:"Primitives (Ellipsoid segments)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.ellipsoidSegmentPrimitive.vertex,fragmentShader:nt.ellipsoidSegmentPrimitive.fragment,side:y.DoubleSide}),h=new y.ShaderMaterial({name:"Primitives (General cylinder)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.generalCylinderPrimitive.vertex,fragmentShader:nt.generalCylinderPrimitive.fragment,side:y.DoubleSide}),f=new y.ShaderMaterial({name:"Primitives (Trapezium)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.trapeziumPrimitive.vertex,fragmentShader:nt.trapeziumPrimitive.fragment,side:y.DoubleSide}),v=new y.ShaderMaterial({name:"Primitives (Torus segment)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0,derivatives:!0},vertexShader:nt.torusSegmentPrimitive.vertex,fragmentShader:nt.torusSegmentPrimitive.fragment,side:y.DoubleSide}),x=new y.ShaderMaterial({name:"Primitives (Spherical segment)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.ellipsoidSegmentPrimitive.vertex,fragmentShader:nt.ellipsoidSegmentPrimitive.fragment,side:y.DoubleSide}),g=new y.ShaderMaterial({name:"Triangle meshes",clipping:!0,clippingPlanes:t,extensions:{derivatives:!0},side:y.DoubleSide,fragmentShader:nt.detailedMesh.fragment,vertexShader:nt.detailedMesh.vertex}),b={box:a,circle:s,nut:d,generalRing:c,quad:l,cone:u,eccentricCone:p,sphericalSegment:x,torusSegment:v,generalCylinder:h,trapezium:f,ellipsoidSegment:m,instancedMesh:new y.ShaderMaterial({name:"Instanced meshes",clipping:!0,clippingPlanes:t,extensions:{derivatives:!0},side:y.DoubleSide,fragmentShader:nt.instancedMesh.fragment,vertexShader:nt.instancedMesh.vertex}),triangleMesh:g,simple:new y.ShaderMaterial({name:"Low detail material",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},side:y.FrontSide,fragmentShader:nt.simpleMesh.fragment,vertexShader:nt.simpleMesh.vertex})};for(const t of Object.values(b))Wt(t,n,r,o,i,e);return{...b}}(this._renderMode,this._clippingPlanes,r.overrideColorPerTreeIndexTexture,i.overrideTransformIndexTexture,i.transformLookupTexture);this.materialsMap.set(e,{materials:d,perModelClippingPlanes:[],nodeAppearanceProvider:n,nodeTransformProvider:o,nodeAppearanceTextureBuilder:r,nodeTransformTextureBuilder:i,updateMaterialsCallback:a,updateTransformsCallback:s}),this.updateClippingPlanesForModel(e)}getModelMaterials(e){return this.getModelMaterialsWrapper(e).materials}getModelNodeAppearanceProvider(e){return this.getModelMaterialsWrapper(e).nodeAppearanceProvider}getModelNodeTransformProvider(e){return this.getModelMaterialsWrapper(e).nodeTransformProvider}getModelDefaultNodeAppearance(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.getDefaultAppearance()}setModelClippingPlanes(e,t){const n=this.materialsMap.get(e);if(void 0===n)throw new Error(`Materials for model ${e} has not been added, call ${this.addModelMaterials.name} first`);n.perModelClippingPlanes=t,this.updateClippingPlanesForModel(e),this.triggerMaterialsChanged()}updateClippingPlanesForModel(e){const t=this.materialsMap.get(e);if(void 0===t)throw new Error(`Materials for model ${e} has not been added, call ${this.addModelMaterials.name} first`);const n=[...t.perModelClippingPlanes,...this.clippingPlanes];Xt(t.materials,e=>{e.clipping=!0,e.clipIntersection=!1,e.clippingPlanes=n})}setModelDefaultNodeAppearance(e,t){this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.setDefaultAppearance(t),this.updateMaterials(e)}getModelBackTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.regularNodeTreeIndices}getModelInFrontTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.infrontNodeTreeIndices}getModelGhostedTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.ghostedNodeTreeIndices}setRenderMode(e){this._renderMode=e;const t=e!==S.DepthBufferOnly;this.applyToAllMaterials(n=>{n.uniforms.renderMode.value=e,n.colorWrite=t})}getRenderMode(){return this._renderMode}updateMaterials(e){const t=this.getModelMaterialsWrapper(e);if(t.nodeAppearanceTextureBuilder.needsUpdate){const{nodeAppearanceTextureBuilder:e}=t;e.build()}this.triggerMaterialsChanged()}updateTransforms(e){const t=this.getModelMaterialsWrapper(e);if(t.nodeTransformTextureBuilder.needsUpdate){const{nodeTransformTextureBuilder:e,materials:n}=t;e.build();const r=e.transformLookupTexture,o=new y.Vector2(r.image.width,r.image.height);Xt(n,e=>{e.uniforms.transformOverrideTexture.value=r,e.uniforms.transformOverrideTextureSize.value=o})}this.triggerMaterialsChanged()}getModelMaterialsWrapper(e){const t=this.materialsMap.get(e);if(void 0===t)throw new Error(`Model ${e} has not been added to MaterialManager`);return t}applyToAllMaterials(e){for(const t of this.materialsMap.values()){Xt(t.materials,e)}}triggerMaterialsChanged(){this._events.materialsChanged.fire()}}function Xt(e,t){t(e.box),t(e.circle),t(e.generalRing),t(e.nut),t(e.quad),t(e.cone),t(e.eccentricCone),t(e.sphericalSegment),t(e.torusSegment),t(e.generalCylinder),t(e.trapezium),t(e.ellipsoidSegment),t(e.instancedMesh),t(e.triangleMesh),t(e.simple)}
369
+ class Kt{constructor(){this._events={materialsChanged:new a.d},this._renderMode=S.Color,this.materialsMap=new Map,this._clippingPlanes=[]}get clippingPlanes(){return this._clippingPlanes}set clippingPlanes(e){this._clippingPlanes=e;for(const e of this.materialsMap.keys())this.updateClippingPlanesForModel(e);this.triggerMaterialsChanged()}on(e,t){switch(e){case"materialsChanged":this._events.materialsChanged.subscribe(t);break;default:Object(a.k)(e,"Unexpected event '"+e)}}off(e,t){switch(e){case"materialsChanged":this._events.materialsChanged.unsubscribe(t);break;default:Object(a.k)(e,"Unexpected event '"+e)}}addModelMaterials(e,t){const n=new g,r=new Ft(t+1,n);r.build();const o=new Vt,i=new Lt(t+1,o);i.build();const a=Ht()(()=>this.updateMaterials(e),75,{leading:!0,trailing:!0}),s=()=>this.updateTransforms(e);n.on("changed",a),o.on("changed",s);const d=function(e,t,n,r,o){const i=new y.Texture(jt);i.needsUpdate=!0;const a=new y.ShaderMaterial({name:"Primitives (Box)",clipping:!0,clippingPlanes:t,extensions:{fragDepth:!0},vertexShader:nt.boxPrimitive.vertex,fragmentShader:nt.boxPrimitive.fragment,side:y.DoubleSide,uniforms:{inverseModelMatrix:{value:new y.Matrix4}}}),s=new y.ShaderMaterial({name:"Primitives (Circle)",clipping:!0,clippingPlanes:t,extensions:{fragDepth:!0},vertexShader:nt.circlePrimitive.vertex,fragmentShader:nt.circlePrimitive.fragment,side:y.DoubleSide,uniforms:{inverseModelMatrix:{value:new y.Matrix4}}}),d=new y.ShaderMaterial({name:"Primitives (Nuts)",clipping:!0,clippingPlanes:t,vertexShader:nt.nutPrimitive.vertex,fragmentShader:nt.nutPrimitive.fragment,side:y.DoubleSide}),l=new y.ShaderMaterial({name:"Primitives (Quads)",clipping:!0,clippingPlanes:t,vertexShader:nt.quadPrimitive.vertex,fragmentShader:nt.quadPrimitive.fragment,side:y.DoubleSide}),c=new y.ShaderMaterial({name:"Primitives (General rings)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.generalRingPrimitive.vertex,fragmentShader:nt.generalRingPrimitive.fragment,side:y.DoubleSide}),u=new y.ShaderMaterial({name:"Primitives (Cone)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.conePrimitive.vertex,fragmentShader:nt.conePrimitive.fragment,side:y.DoubleSide}),p=new y.ShaderMaterial({name:"Primitives (Eccentric cone)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.eccentricConePrimitive.vertex,fragmentShader:nt.eccentricConePrimitive.fragment,side:y.DoubleSide}),m=new y.ShaderMaterial({name:"Primitives (Ellipsoid segments)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.ellipsoidSegmentPrimitive.vertex,fragmentShader:nt.ellipsoidSegmentPrimitive.fragment,side:y.DoubleSide}),h=new y.ShaderMaterial({name:"Primitives (General cylinder)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.generalCylinderPrimitive.vertex,fragmentShader:nt.generalCylinderPrimitive.fragment,side:y.DoubleSide}),f=new y.ShaderMaterial({name:"Primitives (Trapezium)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.trapeziumPrimitive.vertex,fragmentShader:nt.trapeziumPrimitive.fragment,side:y.DoubleSide}),v=new y.ShaderMaterial({name:"Primitives (Torus segment)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0,derivatives:!0},vertexShader:nt.torusSegmentPrimitive.vertex,fragmentShader:nt.torusSegmentPrimitive.fragment,side:y.DoubleSide}),g=new y.ShaderMaterial({name:"Primitives (Spherical segment)",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},extensions:{fragDepth:!0},vertexShader:nt.ellipsoidSegmentPrimitive.vertex,fragmentShader:nt.ellipsoidSegmentPrimitive.fragment,side:y.DoubleSide}),x=new y.ShaderMaterial({name:"Triangle meshes",clipping:!0,clippingPlanes:t,extensions:{derivatives:!0},side:y.DoubleSide,fragmentShader:nt.detailedMesh.fragment,vertexShader:nt.detailedMesh.vertex}),b={box:a,circle:s,nut:d,generalRing:c,quad:l,cone:u,eccentricCone:p,sphericalSegment:g,torusSegment:v,generalCylinder:h,trapezium:f,ellipsoidSegment:m,instancedMesh:new y.ShaderMaterial({name:"Instanced meshes",clipping:!0,clippingPlanes:t,extensions:{derivatives:!0},side:y.DoubleSide,fragmentShader:nt.instancedMesh.fragment,vertexShader:nt.instancedMesh.vertex}),triangleMesh:x,simple:new y.ShaderMaterial({name:"Low detail material",clipping:!0,clippingPlanes:t,uniforms:{inverseModelMatrix:{value:new y.Matrix4}},side:y.FrontSide,fragmentShader:nt.simpleMesh.fragment,vertexShader:nt.simpleMesh.vertex})};for(const t of Object.values(b))Wt(t,n,r,o,i,e);return{...b}}(this._renderMode,this._clippingPlanes,r.overrideColorPerTreeIndexTexture,i.overrideTransformIndexTexture,i.transformLookupTexture);this.materialsMap.set(e,{materials:d,perModelClippingPlanes:[],nodeAppearanceProvider:n,nodeTransformProvider:o,nodeAppearanceTextureBuilder:r,nodeTransformTextureBuilder:i,updateMaterialsCallback:a,updateTransformsCallback:s}),this.updateClippingPlanesForModel(e)}getModelMaterials(e){return this.getModelMaterialsWrapper(e).materials}getModelNodeAppearanceProvider(e){return this.getModelMaterialsWrapper(e).nodeAppearanceProvider}getModelNodeTransformProvider(e){return this.getModelMaterialsWrapper(e).nodeTransformProvider}getModelDefaultNodeAppearance(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.getDefaultAppearance()}setModelClippingPlanes(e,t){const n=this.materialsMap.get(e);if(void 0===n)throw new Error(`Materials for model ${e} has not been added, call ${this.addModelMaterials.name} first`);n.perModelClippingPlanes=t,this.updateClippingPlanesForModel(e),this.triggerMaterialsChanged()}updateClippingPlanesForModel(e){const t=this.materialsMap.get(e);if(void 0===t)throw new Error(`Materials for model ${e} has not been added, call ${this.addModelMaterials.name} first`);const n=[...t.perModelClippingPlanes,...this.clippingPlanes];Xt(t.materials,e=>{e.clipping=!0,e.clipIntersection=!1,e.clippingPlanes=n})}setModelDefaultNodeAppearance(e,t){this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.setDefaultAppearance(t),this.updateMaterials(e)}getModelBackTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.regularNodeTreeIndices}getModelInFrontTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.infrontNodeTreeIndices}getModelGhostedTreeIndices(e){return this.getModelMaterialsWrapper(e).nodeAppearanceTextureBuilder.ghostedNodeTreeIndices}setRenderMode(e){this._renderMode=e;const t=e!==S.DepthBufferOnly;this.applyToAllMaterials(n=>{n.uniforms.renderMode.value=e,n.colorWrite=t})}getRenderMode(){return this._renderMode}updateMaterials(e){const t=this.getModelMaterialsWrapper(e);if(t.nodeAppearanceTextureBuilder.needsUpdate){const{nodeAppearanceTextureBuilder:e}=t;e.build()}this.triggerMaterialsChanged()}updateTransforms(e){const t=this.getModelMaterialsWrapper(e);if(t.nodeTransformTextureBuilder.needsUpdate){const{nodeTransformTextureBuilder:e,materials:n}=t;e.build();const r=e.transformLookupTexture,o=new y.Vector2(r.image.width,r.image.height);Xt(n,e=>{e.uniforms.transformOverrideTexture.value=r,e.uniforms.transformOverrideTextureSize.value=o})}this.triggerMaterialsChanged()}getModelMaterialsWrapper(e){const t=this.materialsMap.get(e);if(void 0===t)throw new Error(`Model ${e} has not been added to MaterialManager`);return t}applyToAllMaterials(e){for(const t of this.materialsMap.values()){Xt(t.materials,e)}}triggerMaterialsChanged(){this._events.materialsChanged.fire()}}function Xt(e,t){t(e.box),t(e.circle),t(e.generalRing),t(e.nut),t(e.quad),t(e.cone),t(e.eccentricCone),t(e.sphericalSegment),t(e.torusSegment),t(e.generalCylinder),t(e.trapezium),t(e.ellipsoidSegment),t(e.instancedMesh),t(e.triangleMesh),t(e.simple)}
370
370
  /*!
371
371
  * Copyright 2021 Cognite AS
372
372
  */class Yt{}Yt.Black=new y.Color("rgb(0, 0, 0)"),Yt.White=new y.Color("rgb(255, 255, 255)"),Yt.Cyan=new y.Color("rgb(102, 213, 234)"),Yt.Blue=new y.Color("rgb(77, 106, 242)"),Yt.Purple=new y.Color("rgb(186, 82, 212)"),Yt.Pink=new y.Color("rgb(232, 64, 117)"),Yt.Orange=new y.Color("rgb(238, 113, 53)"),Yt.Yellow=new y.Color("rgb(246, 189, 65)"),Yt.VeryLightGray=new y.Color("rgb(247, 246, 245)"),Yt.LightGray=new y.Color("rgb(242, 241, 240)");class Zt{}Zt.Red=new y.Color("rgb(235,0,4)"),Zt.Green=new y.Color("rgb(46,164,79)");
373
373
  /*!
374
374
  * Copyright 2021 Cognite AS
375
375
  */
376
- class Qt{constructor(e,t,n,r){var o,i;this._lastFrameSceneState={hasBackElements:!0,hasInFrontElements:!0,hasGhostElements:!0,hasCustomObjects:!0},this._rootSectorNodeBuffer=new Set,this._outlineTexelSize=2,this._autoSetTargetSize=!1,this._debugRenderTimings=!1,this._uiObjects=[],this._deepFlushRendererArgs={buffer:new ArrayBuffer(4)},this._renderer=e,this._renderOptions=r,this._materialManager=n,this._orthographicCamera=new y.OrthographicCamera(-1,1,1,-1,-1,1),this._renderTarget=null,this._originalScene=t,this._cadScene=new y.Scene,this._cadScene.autoUpdate=!1,this._normalScene=new y.Scene,this._normalScene.autoUpdate=!1,this._inFrontScene=new y.Scene,this._inFrontScene.autoUpdate=!1,this._compositionScene=new y.Scene,this._compositionScene.autoUpdate=!1,this._fxaaScene=new y.Scene,this._fxaaScene.autoUpdate=!1,this._ssaoScene=new y.Scene,this._ssaoScene.autoUpdate=!1,this._ssaoBlurCombineScene=new y.Scene,this._ssaoBlurCombineScene.autoUpdate=!1,this._emptyScene=new y.Scene,this._emptyScene.autoUpdate=!1;const a=e.capabilities.isWebGL2,s=this.createOutlineColorTexture();this._inFrontRenderedCadModelTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._inFrontRenderedCadModelTarget.depthTexture=new y.DepthTexture(0,0),this._inFrontRenderedCadModelTarget.depthTexture.format=y.DepthFormat,this._inFrontRenderedCadModelTarget.depthTexture.type=y.UnsignedIntType,this._normalRenderedCadModelTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._normalRenderedCadModelTarget.depthTexture=new y.DepthTexture(0,0),this._normalRenderedCadModelTarget.depthTexture.format=y.DepthFormat,this._normalRenderedCadModelTarget.depthTexture.type=y.UnsignedIntType,this._ghostObjectRenderTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._ghostObjectRenderTarget.depthTexture=new y.DepthTexture(0,0),this._ghostObjectRenderTarget.depthTexture.format=y.DepthFormat,this._ghostObjectRenderTarget.depthTexture.type=y.UnsignedIntType,this._customObjectRenderTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._customObjectRenderTarget.depthTexture=new y.DepthTexture(0,0),this._customObjectRenderTarget.depthTexture.format=y.DepthFormat,this._customObjectRenderTarget.depthTexture.type=y.UnsignedIntType,this._compositionTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._compositionTarget.depthTexture=new y.DepthTexture(0,0),this._compositionTarget.depthTexture.format=y.DepthFormat,this._compositionTarget.depthTexture.type=y.UnsignedIntType,this._ssaoTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._ssaoTarget.depthTexture=new y.DepthTexture(0,0),this._ssaoTarget.depthTexture.format=y.DepthFormat,this._ssaoTarget.depthTexture.type=y.UnsignedIntType,this._ssaoBlurCombineTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._ssaoBlurCombineTarget.depthTexture=new y.DepthTexture(0,0),this._ssaoBlurCombineTarget.depthTexture.format=y.DepthFormat,this._ssaoBlurCombineTarget.depthTexture.type=y.UnsignedIntType,this._combineOutlineDetectionMaterial=new y.ShaderMaterial({vertexShader:rt.vertex,fragmentShader:rt.fragment,uniforms:{tFront:{value:this._inFrontRenderedCadModelTarget.texture},tFrontDepth:{value:this._inFrontRenderedCadModelTarget.depthTexture},tBack:{value:this._normalRenderedCadModelTarget.texture},tBackDepth:{value:this._normalRenderedCadModelTarget.depthTexture},tCustom:{value:this._customObjectRenderTarget.texture},tCustomDepth:{value:this._customObjectRenderTarget.depthTexture},tGhost:{value:this._ghostObjectRenderTarget.texture},tGhostDepth:{value:this._ghostObjectRenderTarget.depthTexture},tOutlineColors:{value:s},resolution:{value:new y.Vector2(0,0)},texelSize:{value:new y.Vector2(0,0)},cameraNear:{value:.1},cameraFar:{value:1e4},edgeStrengthMultiplier:{value:2.5},edgeGrayScaleIntensity:{value:.1}},extensions:{fragDepth:!0},defines:{EDGES:null!==(i=null===(o=this._renderOptions.edgeDetectionParameters)||void 0===o?void 0:o.enabled)&&void 0!==i?i:I.edgeDetectionParameters.enabled}});const d=this.ssaoParameters(this._renderOptions),l=d.sampleSize,c=this.createKernel(l),u=d.sampleRadius,p=d.depthCheckBias;this._ssaoMaterial=new y.ShaderMaterial({uniforms:{tDepth:{value:this._compositionTarget.depthTexture},kernel:{value:c},sampleRadius:{value:u},bias:{value:p},projMatrix:{value:new y.Matrix4},inverseProjectionMatrix:{value:new y.Matrix4},resolution:{value:new y.Vector2}},defines:{MAX_KERNEL_SIZE:l},vertexShader:it.vertex,fragmentShader:it.fragment}),this._ssaoBlurCombineMaterial=new y.ShaderMaterial({uniforms:{tDiffuse:{value:this._compositionTarget.texture},tAmbientOcclusion:{value:this._ssaoTarget.texture},resolution:{value:new y.Vector2}},vertexShader:at.vertex,fragmentShader:at.fragment});const m=this.supportsSsao(d)?this._ssaoBlurCombineTarget.texture:this._compositionTarget.texture;this._fxaaMaterial=new y.ShaderMaterial({uniforms:{tDiffuse:{value:m},tDepth:{value:this._compositionTarget.depthTexture},resolution:{value:new y.Vector2},inverseResolution:{value:new y.Vector2}},vertexShader:ot.vertex,fragmentShader:ot.fragment,extensions:{fragDepth:!0}}),this.setupCompositionScene(),this.setupSsaoScene(),this.setupSsaoBlurCombineScene(),this.setupFxaaScene(),this._normalSceneBuilder=new en(this._normalScene),this._inFrontSceneBuilder=new en(this._inFrontScene)}set renderOptions(e){const t=this.ssaoParameters(e),n={...t};this.setSsaoParameters(n),this._renderOptions={...e,ssaoRenderParameters:{...t}}}set debugRenderTimings(e){this._debugRenderTimings=e}get debugRenderTimings(){return this._debugRenderTimings}addUiObject(e,t,n){this._uiObjects.push({object:e,screenPos:t,width:n.x,height:n.y})}removeUiObject(e){this._uiObjects=this._uiObjects.filter(t=>{const n=t.object;return e!==n})}ssaoParameters(e){var t;return null!==(t=null==e?void 0:e.ssaoRenderParameters)&&void 0!==t?t:{...I.ssaoRenderParameters}}get antiAliasingMode(){const{antiAliasing:e=I.antiAliasing}=this._renderOptions;return e}get multiSampleCountHint(){const{multiSampleCountHint:e=I.multiSampleCountHint}=this._renderOptions;return e}supportsSsao(e){return!Object(a.p)()&&(this._renderer.capabilities.isWebGL2||this._renderer.extensions.has("EXT_frag_depth"))&&e.sampleSize!==b.None}renderDetailedToDepthOnly(e){const t={renderMode:this._materialManager.getRenderMode()},n=new a.i(this._renderer);this._materialManager.setRenderMode(S.DepthBufferOnly);try{n.setRenderTarget(this._renderTarget),this.setVisibilityOfSectors(V.d.Simple,!1),this.traverseForRootSectorNode(this._originalScene),this.extractCadNodes(this._originalScene),this.clearTarget(this._renderTarget);const{hasBackElements:r,hasInFrontElements:o,hasGhostElements:i}=this.splitToScenes();r&&!i?this.renderNormalCadModelsFromBaseScene(e,this._renderTarget):r&&i&&(this.renderNormalCadModels(e,this._renderTarget),this._normalSceneBuilder.restoreOriginalScene()),o&&(this.renderInFrontCadModels(e),this._inFrontSceneBuilder.restoreOriginalScene())}finally{this._materialManager.setRenderMode(t.renderMode),n.resetState(),this.restoreCadNodes(),this.setVisibilityOfSectors(V.d.Simple,!0)}}render(e){this.setupRenderTargetSpectorDebugging(),this._debugRenderTimings&&Ue.a.debug("============== RENDER BEGIN ==============");const t=this._renderer,n=this._originalScene,r=new a.i(t),o={autoClear:t.autoClear,clearAlpha:t.getClearAlpha(),renderMode:this._materialManager.getRenderMode()};t.info.autoReset=!1,t.info.reset(),r.autoClear=!1;try{r.setRenderTarget(this._renderTarget),this.updateRenderSize(t),t.info.autoReset=!1,t.info.reset(),r.autoClear=!1,this.traverseForRootSectorNode(n),this.extractCadNodes(n),this.clearTarget(this._ghostObjectRenderTarget),this.clearTarget(this._compositionTarget),this.clearTarget(this._customObjectRenderTarget),t.setClearAlpha(0),this.clearTarget(this._normalRenderedCadModelTarget),this.clearTarget(this._inFrontRenderedCadModelTarget),t.setClearAlpha(o.clearAlpha);const i={...this._lastFrameSceneState},{hasBackElements:a,hasInFrontElements:s,hasGhostElements:d}=this.splitToScenes(),l=n.children.length>0;this._lastFrameSceneState={hasBackElements:a,hasInFrontElements:s,hasGhostElements:d,hasCustomObjects:l},a&&!d?this.renderNormalCadModelsFromBaseScene(e):a&&d?(this.renderNormalCadModels(e),this._normalSceneBuilder.restoreOriginalScene(),this.renderGhostedCadModelsFromBaseScene(e)):!a&&d&&this.renderGhostedCadModelsFromBaseScene(e),s&&(this.renderInFrontCadModels(e),this._inFrontSceneBuilder.restoreOriginalScene()),l&&this.renderCustomObjects(n,e),t.capabilities.isWebGL2&&(!a&&i.hasBackElements&&this.explicitFlushRender(e,this._normalRenderedCadModelTarget),!d&&i.hasGhostElements&&this.explicitFlushRender(e,this._ghostObjectRenderTarget),!s&&i.hasInFrontElements&&this.explicitFlushRender(e,this._inFrontRenderedCadModelTarget),!l&&i.hasInFrontElements&&this.explicitFlushRender(e,this._customObjectRenderTarget));const c=this.supportsSsao(this.ssaoParameters(this._renderOptions));switch(this.antiAliasingMode){case g.FXAA:this.renderComposition(e,this._compositionTarget),r.autoClear=o.autoClear,c&&(this.renderSsao(this._ssaoTarget,e),this.renderPostProcessStep("ssao-blur-combine",this._ssaoBlurCombineTarget,this._ssaoBlurCombineScene)),this.renderPostProcessStep("fxaa",this._renderTarget,this._fxaaScene);break;case g.NoAA:t.autoClear=o.autoClear,c?(this.renderComposition(e,this._compositionTarget),this.renderSsao(this._ssaoTarget,e),this.renderPostProcessStep("ssao-blur-combine",this._renderTarget,this._ssaoBlurCombineScene)):this.renderComposition(e,this._renderTarget);break;default:throw new Error("Unsupported anti-aliasing mode: "+this.antiAliasingMode)}}finally{r.resetState(),this._materialManager.setRenderMode(o.renderMode),this.restoreCadNodes(),this._debugRenderTimings&&Ue.a.debug("=============== RENDER END ===============")}}restoreCadNodes(){this._rootSectorNodeBuffer.forEach(e=>{e[1].add(e[0])}),this._rootSectorNodeBuffer.clear()}extractCadNodes(e){this._rootSectorNodeBuffer.forEach(t=>{if(t[1].parent!==e&&null!==t[1].parent&&t[1].parent.parent!==e)throw new Error("CadNode must be put at scene root");this._cadScene.add(t[0])})}setRenderTarget(e){this._renderTarget=e}getRenderTarget(){return this._renderTarget}setRenderTargetAutoSize(e){this._autoSetTargetSize=e}getRenderTargetAutoSize(){return this._autoSetTargetSize}clearTarget(e){this._renderer.setRenderTarget(e),this._renderer.clear()}explicitFlushRender(e,t){this._renderer.setRenderTarget(t),this.renderStep("flushRender",this._emptyScene,e)}splitToScenes(){const e={hasBackElements:!1,hasInFrontElements:!1,hasGhostElements:!1};this._rootSectorNodeBuffer.forEach(t=>{const n=t[1],r=this._materialManager.getModelBackTreeIndices(n.cadModelMetadata.modelIdentifier),o=this._materialManager.getModelInFrontTreeIndices(n.cadModelMetadata.modelIdentifier),i=this._materialManager.getModelGhostedTreeIndices(n.cadModelMetadata.modelIdentifier),a=r.count>0,s=o.count>0,d=i.count>0;e.hasBackElements=e.hasBackElements||a,e.hasInFrontElements=e.hasInFrontElements||s,e.hasGhostElements=e.hasGhostElements||d});const{hasBackElements:t,hasInFrontElements:n,hasGhostElements:r}=e;return this._rootSectorNodeBuffer.forEach(e=>{const o=e[0],i=e[1],a=this._materialManager.getModelBackTreeIndices(i.cadModelMetadata.modelIdentifier),s=this._materialManager.getModelInFrontTreeIndices(i.cadModelMetadata.modelIdentifier),d=new y.Object3D;d.applyMatrix4(o.matrix),t&&r&&this._normalScene.add(d);const l=new y.Object3D;l.applyMatrix4(o.matrix),n&&this._inFrontScene.add(l);const c=[e[0]];for(;c.length>0;){const e=c.pop(),o=e.userData.treeIndices;o?(n&&s.hasIntersectionWith(o)&&this._inFrontSceneBuilder.addElement(e,l),t&&!r||r&&a.hasIntersectionWith(o)&&this._normalSceneBuilder.addElement(e,d)):c.push(...e.children)}}),e}renderNormalCadModels(e,t=this._normalRenderedCadModelTarget){this._normalSceneBuilder.populateTemporaryScene(),this._renderer.setRenderTarget(t),this.renderStep("normal",this._normalScene,e)}renderNormalCadModelsFromBaseScene(e,t=this._normalRenderedCadModelTarget){this._renderer.setRenderTarget(t),this.renderStep("normalCadModelsFromBaseScene",this._cadScene,e)}renderInFrontCadModels(e,t=this._inFrontRenderedCadModelTarget){this._inFrontSceneBuilder.populateTemporaryScene(),this._renderer.setRenderTarget(t),this._materialManager.setRenderMode(S.Effects),this.renderStep("infront",this._inFrontScene,e)}renderGhostedCadModelsFromBaseScene(e){this._renderer.setRenderTarget(this._ghostObjectRenderTarget),this._materialManager.setRenderMode(S.Ghost),this.renderStep("ghosted",this._cadScene,e)}renderCustomObjects(e,t){const n=e.autoUpdate;try{e.autoUpdate=!0,this._renderer.setRenderTarget(this._customObjectRenderTarget),this.renderStep("customobjects",e,t)}finally{e.autoUpdate=n}}updateRenderSize(e){const t=new y.Vector2;return e.getSize(t),this._renderTarget&&this._autoSetTargetSize&&t.x!==this._renderTarget.width&&t.y!==this._renderTarget.height&&this._renderTarget.setSize(t.x,t.y),t.x===this._normalRenderedCadModelTarget.width&&t.y===this._normalRenderedCadModelTarget.height||(this._normalRenderedCadModelTarget.setSize(t.x,t.y),this._inFrontRenderedCadModelTarget.setSize(t.x,t.y),this._customObjectRenderTarget.setSize(t.x,t.y),this._ghostObjectRenderTarget.setSize(t.x,t.y),this._compositionTarget.setSize(t.x,t.y),this._ssaoTarget.setSize(t.x,t.y),this._ssaoBlurCombineTarget.setSize(t.x,t.y),this._combineOutlineDetectionMaterial.uniforms.texelSize.value=new y.Vector2(this._outlineTexelSize/t.x,this._outlineTexelSize/t.y),this._combineOutlineDetectionMaterial.uniforms.resolution.value=t,this._ssaoMaterial.uniforms.resolution.value=t,this._ssaoBlurCombineMaterial.uniforms.resolution.value=t,this._fxaaMaterial.uniforms.resolution.value=t,this._fxaaMaterial.uniforms.inverseResolution.value=new y.Vector2(1/t.x,1/t.y)),t}renderComposition(e,t){this._combineOutlineDetectionMaterial.uniforms.cameraNear.value=e.near,this._combineOutlineDetectionMaterial.uniforms.cameraFar.value=e.far,this.renderPostProcessStep("composition",t,this._compositionScene)}setSsaoParameters(e){var t;const n=I.ssaoRenderParameters;if(this._ssaoMaterial.uniforms.sampleRadius.value=e.sampleRadius,this._ssaoMaterial.uniforms.bias.value=e.depthCheckBias,e.sampleSize!==this.ssaoParameters(this._renderOptions).sampleSize){const r=null!==(t=null==e?void 0:e.sampleSize)&&void 0!==t?t:n.sampleSize,o=this.createKernel(r);this._fxaaMaterial.uniforms.tDiffuse.value=e.sampleSize!==b.None?this._ssaoBlurCombineTarget.texture:this._compositionTarget.texture,this._ssaoMaterial.uniforms.kernel.value=o,this._ssaoMaterial.defines={MAX_KERNEL_SIZE:r},this._ssaoMaterial.needsUpdate=!0}}renderPostProcessStep(e,t,n){const r=this._renderer;if(r.setRenderTarget(t),this.renderStep(e,n,this._orthographicCamera),t===this._renderTarget){const e=r.getSize(new y.Vector2),t=new y.Vector2(r.domElement.clientWidth,r.domElement.clientHeight),n=new y.Vector2(e.x/t.x,e.y/t.y);r.autoClear=!1,this._uiObjects.forEach(e=>{const t=new y.Scene;t.add(e.object);const o=e.screenPos.clone().multiply(n),i=e.width*n.x,a=e.height*n.y;r.setViewport(o.x,o.y,i,a),r.clearDepth(),r.render(t,this._orthographicCamera)}),r.setViewport(0,0,e.x,e.y),r.autoClear=!0}}renderSsao(e,t){this._ssaoMaterial.uniforms.inverseProjectionMatrix.value=t.projectionMatrixInverse,this._ssaoMaterial.uniforms.projMatrix.value=t.projectionMatrix,this.renderPostProcessStep("ssao",e,this._ssaoScene)}renderStep(e,t,n){if(!this._debugRenderTimings)return void this._renderer.render(t,n);this.deepFlushRenderer();const r=performance.now();this._renderer.render(t,n),this.deepFlushRenderer(),Ue.a.log(`Render stage '${e}' took ${performance.now()-r} ms`)}deepFlushRenderer(){const{buffer:e}=this._deepFlushRendererArgs,t=this._renderer.getContext(),n=this._renderer.getRenderTarget();t.flush(),t.finish(),null!==n&&this._renderer.readRenderTargetPixels(n,0,0,1,1,e)}createOutlineColorTexture(){const e=new Uint8Array(32),t=new y.DataTexture(e,8,1);return $t(t.image.data,r.White,Yt.White),$t(t.image.data,r.Black,Yt.Black),$t(t.image.data,r.Cyan,Yt.Cyan),$t(t.image.data,r.Blue,Yt.Blue),$t(t.image.data,r.Green,Zt.Green),$t(t.image.data,r.Red,Zt.Red),$t(t.image.data,r.Orange,Yt.Orange),t}setupCompositionScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._combineOutlineDetectionMaterial);this._compositionScene.add(t)}setupFxaaScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._fxaaMaterial);this._fxaaScene.add(t)}setupSsaoScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._ssaoMaterial);this._ssaoScene.add(t)}setupSsaoBlurCombineScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._ssaoBlurCombineMaterial);this._ssaoBlurCombineScene.add(t)}createKernel(e){const t=[];for(let r=0;r<e;r++){const o=new y.Vector3;for(;o.length()<.5;)o.x=2*Math.random()-1,o.y=2*Math.random()-1,o.z=Math.random();o.normalize();let i=r/e;i=n(.1,1,i*i),o.multiplyScalar(i),t.push(o)}return t;function n(e,t,n){return e+(t-e)*(n=(n=n<0?0:n)>1?1:n)}}createRenderTriangle(){const e=new y.BufferGeometry,t=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),n=new Float32Array([0,0,2,0,0,2]);return e.setAttribute("position",new y.BufferAttribute(t,3)),e.setAttribute("uv",new y.BufferAttribute(n,2)),e}traverseForRootSectorNode(e){const t=[e];for(;t.length>0;){const e=t.pop();if(e instanceof V.e){const t=e.parent;t.visible&&this._rootSectorNodeBuffer.add([e,t])}else e instanceof y.Group||t.push(...e.children)}}setVisibilityOfSectors(e,t){this._originalScene.traverse(n=>{n instanceof V.f&&n.levelOfDetail===e&&(n.visible=t)})}setupRenderTargetSpectorDebugging(){!1}assignSpectorJsMetadataToRenderTarget(e,t){const n=this._renderer.getRenderTarget();try{this._renderer.setRenderTarget(e);const r=this._renderer.getContext();r.getParameter(r.FRAMEBUFFER_BINDING).__SPECTOR_Metadata=t}finally{this._renderer.setRenderTarget(n)}}}function Jt(e,t,n){if(e&&t>1){const e=new y.WebGLMultisampleRenderTarget(0,0,n);return e.samples=t,e}return new y.WebGLRenderTarget(0,0,n)}function $t(e,t,n){e[4*t+0]=Math.floor(255*n.r),e[4*t+1]=Math.floor(255*n.g),e[4*t+2]=Math.floor(255*n.b),e[4*t+3]=255}class en{constructor(e){this.buffer=[],this.temporaryScene=e}addElement(e,t){this.buffer.push({object:e,parent:e.parent,sceneParent:t})}populateTemporaryScene(){this.buffer.forEach(e=>e.sceneParent.add(e.object))}restoreOriginalScene(){this.buffer.forEach(e=>{e.parent.add(e.object)}),this.buffer.length=0,this.temporaryScene.remove(...this.temporaryScene.children)}}var tn=n(6);function nn(e,t,n,r,o,i,a={}){P.a.init(!1!==a.logMetrics,e,t,{constructorOptions:a});const s=a.renderOptions||{},d=new Kt,l=new Qt(o,i,d,s),c=xt(n,r,o,d,new Ot(l),a),u=function(e,t){const n=new At(e,t),r=new zt(t);return new Nt(n,r)}(n,r);return new Et(c,l,u)}var rn=n(17);
376
+ class Qt{constructor(e,t,n,r){var o,i;this._lastFrameSceneState={hasBackElements:!0,hasInFrontElements:!0,hasGhostElements:!0,hasCustomObjects:!0},this._rootSectorNodeBuffer=new Set,this._outlineTexelSize=2,this._autoSetTargetSize=!1,this._debugRenderTimings=!1,this._uiObjects=[],this._deepFlushRendererArgs={buffer:new ArrayBuffer(4)},this._renderer=e,this._renderOptions=r,this._materialManager=n,this._orthographicCamera=new y.OrthographicCamera(-1,1,1,-1,-1,1),this._renderTarget=null,this._originalScene=t,this._cadScene=new y.Scene,this._cadScene.autoUpdate=!1,this._normalScene=new y.Scene,this._normalScene.autoUpdate=!1,this._inFrontScene=new y.Scene,this._inFrontScene.autoUpdate=!1,this._compositionScene=new y.Scene,this._compositionScene.autoUpdate=!1,this._fxaaScene=new y.Scene,this._fxaaScene.autoUpdate=!1,this._ssaoScene=new y.Scene,this._ssaoScene.autoUpdate=!1,this._ssaoBlurCombineScene=new y.Scene,this._ssaoBlurCombineScene.autoUpdate=!1,this._emptyScene=new y.Scene,this._emptyScene.autoUpdate=!1;const a=e.capabilities.isWebGL2,s=this.createOutlineColorTexture();this._inFrontRenderedCadModelTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._inFrontRenderedCadModelTarget.depthTexture=new y.DepthTexture(0,0),this._inFrontRenderedCadModelTarget.depthTexture.format=y.DepthFormat,this._inFrontRenderedCadModelTarget.depthTexture.type=y.UnsignedIntType,this._normalRenderedCadModelTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._normalRenderedCadModelTarget.depthTexture=new y.DepthTexture(0,0),this._normalRenderedCadModelTarget.depthTexture.format=y.DepthFormat,this._normalRenderedCadModelTarget.depthTexture.type=y.UnsignedIntType,this._ghostObjectRenderTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._ghostObjectRenderTarget.depthTexture=new y.DepthTexture(0,0),this._ghostObjectRenderTarget.depthTexture.format=y.DepthFormat,this._ghostObjectRenderTarget.depthTexture.type=y.UnsignedIntType,this._customObjectRenderTarget=Jt(a,this.multiSampleCountHint,{stencilBuffer:!1}),this._customObjectRenderTarget.depthTexture=new y.DepthTexture(0,0),this._customObjectRenderTarget.depthTexture.format=y.DepthFormat,this._customObjectRenderTarget.depthTexture.type=y.UnsignedIntType,this._compositionTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._compositionTarget.depthTexture=new y.DepthTexture(0,0),this._compositionTarget.depthTexture.format=y.DepthFormat,this._compositionTarget.depthTexture.type=y.UnsignedIntType,this._ssaoTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._ssaoTarget.depthTexture=new y.DepthTexture(0,0),this._ssaoTarget.depthTexture.format=y.DepthFormat,this._ssaoTarget.depthTexture.type=y.UnsignedIntType,this._ssaoBlurCombineTarget=new y.WebGLRenderTarget(0,0,{stencilBuffer:!1}),this._ssaoBlurCombineTarget.depthTexture=new y.DepthTexture(0,0),this._ssaoBlurCombineTarget.depthTexture.format=y.DepthFormat,this._ssaoBlurCombineTarget.depthTexture.type=y.UnsignedIntType,this._combineOutlineDetectionMaterial=new y.ShaderMaterial({vertexShader:rt.vertex,fragmentShader:rt.fragment,uniforms:{tFront:{value:this._inFrontRenderedCadModelTarget.texture},tFrontDepth:{value:this._inFrontRenderedCadModelTarget.depthTexture},tBack:{value:this._normalRenderedCadModelTarget.texture},tBackDepth:{value:this._normalRenderedCadModelTarget.depthTexture},tCustom:{value:this._customObjectRenderTarget.texture},tCustomDepth:{value:this._customObjectRenderTarget.depthTexture},tGhost:{value:this._ghostObjectRenderTarget.texture},tGhostDepth:{value:this._ghostObjectRenderTarget.depthTexture},tOutlineColors:{value:s},resolution:{value:new y.Vector2(0,0)},texelSize:{value:new y.Vector2(0,0)},cameraNear:{value:.1},cameraFar:{value:1e4},edgeStrengthMultiplier:{value:2.5},edgeGrayScaleIntensity:{value:.1}},extensions:{fragDepth:!0},defines:{EDGES:null!==(i=null===(o=this._renderOptions.edgeDetectionParameters)||void 0===o?void 0:o.enabled)&&void 0!==i?i:I.edgeDetectionParameters.enabled}});const d=this.ssaoParameters(this._renderOptions),l=d.sampleSize,c=this.createKernel(l),u=d.sampleRadius,p=d.depthCheckBias;this._ssaoMaterial=new y.ShaderMaterial({uniforms:{tDepth:{value:this._compositionTarget.depthTexture},kernel:{value:c},sampleRadius:{value:u},bias:{value:p},projMatrix:{value:new y.Matrix4},inverseProjectionMatrix:{value:new y.Matrix4},resolution:{value:new y.Vector2}},defines:{MAX_KERNEL_SIZE:l},vertexShader:it.vertex,fragmentShader:it.fragment}),this._ssaoBlurCombineMaterial=new y.ShaderMaterial({uniforms:{tDiffuse:{value:this._compositionTarget.texture},tAmbientOcclusion:{value:this._ssaoTarget.texture},resolution:{value:new y.Vector2}},vertexShader:at.vertex,fragmentShader:at.fragment});const m=this.supportsSsao(d)?this._ssaoBlurCombineTarget.texture:this._compositionTarget.texture;this._fxaaMaterial=new y.ShaderMaterial({uniforms:{tDiffuse:{value:m},tDepth:{value:this._compositionTarget.depthTexture},resolution:{value:new y.Vector2},inverseResolution:{value:new y.Vector2}},vertexShader:ot.vertex,fragmentShader:ot.fragment,extensions:{fragDepth:!0}}),this.setupCompositionScene(),this.setupSsaoScene(),this.setupSsaoBlurCombineScene(),this.setupFxaaScene(),this._normalSceneBuilder=new en(this._normalScene),this._inFrontSceneBuilder=new en(this._inFrontScene)}set renderOptions(e){const t=this.ssaoParameters(e),n={...t};this.setSsaoParameters(n),this._renderOptions={...e,ssaoRenderParameters:{...t}}}set debugRenderTimings(e){this._debugRenderTimings=e}get debugRenderTimings(){return this._debugRenderTimings}addUiObject(e,t,n){this._uiObjects.push({object:e,screenPos:t,width:n.x,height:n.y})}removeUiObject(e){this._uiObjects=this._uiObjects.filter(t=>{const n=t.object;return e!==n})}ssaoParameters(e){var t;return null!==(t=null==e?void 0:e.ssaoRenderParameters)&&void 0!==t?t:{...I.ssaoRenderParameters}}get antiAliasingMode(){const{antiAliasing:e=I.antiAliasing}=this._renderOptions;return e}get multiSampleCountHint(){const{multiSampleCountHint:e=I.multiSampleCountHint}=this._renderOptions;return e}supportsSsao(e){return!Object(a.p)()&&(this._renderer.capabilities.isWebGL2||this._renderer.extensions.has("EXT_frag_depth"))&&e.sampleSize!==b.None}renderDetailedToDepthOnly(e){const t={renderMode:this._materialManager.getRenderMode()},n=new a.i(this._renderer);this._materialManager.setRenderMode(S.DepthBufferOnly);try{n.setRenderTarget(this._renderTarget),this.setVisibilityOfSectors(V.d.Simple,!1),this.traverseForRootSectorNode(this._originalScene),this.extractCadNodes(this._originalScene),this.clearTarget(this._renderTarget);const{hasBackElements:r,hasInFrontElements:o,hasGhostElements:i}=this.splitToScenes();r&&!i?this.renderNormalCadModelsFromBaseScene(e,this._renderTarget):r&&i&&(this.renderNormalCadModels(e,this._renderTarget),this._normalSceneBuilder.restoreOriginalScene()),o&&(this.renderInFrontCadModels(e),this._inFrontSceneBuilder.restoreOriginalScene())}finally{this._materialManager.setRenderMode(t.renderMode),n.resetState(),this.restoreCadNodes(),this.setVisibilityOfSectors(V.d.Simple,!0)}}render(e){this.setupRenderTargetSpectorDebugging(),this._debugRenderTimings&&Ue.a.debug("============== RENDER BEGIN ==============");const t=this._renderer,n=this._originalScene,r=new a.i(t),o={autoClear:t.autoClear,clearAlpha:t.getClearAlpha(),renderMode:this._materialManager.getRenderMode()};t.info.autoReset=!1,t.info.reset(),r.autoClear=!1;try{r.setRenderTarget(this._renderTarget),this.updateRenderSize(t),t.info.autoReset=!1,t.info.reset(),r.autoClear=!1,this.traverseForRootSectorNode(n),this.extractCadNodes(n),this.clearTarget(this._ghostObjectRenderTarget),this.clearTarget(this._compositionTarget),this.clearTarget(this._customObjectRenderTarget),t.setClearAlpha(0),this.clearTarget(this._normalRenderedCadModelTarget),this.clearTarget(this._inFrontRenderedCadModelTarget),t.setClearAlpha(o.clearAlpha);const i={...this._lastFrameSceneState},{hasBackElements:a,hasInFrontElements:s,hasGhostElements:d}=this.splitToScenes(),l=n.children.length>0;this._lastFrameSceneState={hasBackElements:a,hasInFrontElements:s,hasGhostElements:d,hasCustomObjects:l},a&&!d?this.renderNormalCadModelsFromBaseScene(e):a&&d?(this.renderNormalCadModels(e),this._normalSceneBuilder.restoreOriginalScene(),this.renderGhostedCadModelsFromBaseScene(e)):!a&&d&&this.renderGhostedCadModelsFromBaseScene(e),s&&(this.renderInFrontCadModels(e),this._inFrontSceneBuilder.restoreOriginalScene()),l&&this.renderCustomObjects(n,e),t.capabilities.isWebGL2&&(!a&&i.hasBackElements&&this.explicitFlushRender(e,this._normalRenderedCadModelTarget),!d&&i.hasGhostElements&&this.explicitFlushRender(e,this._ghostObjectRenderTarget),!s&&i.hasInFrontElements&&this.explicitFlushRender(e,this._inFrontRenderedCadModelTarget),!l&&i.hasInFrontElements&&this.explicitFlushRender(e,this._customObjectRenderTarget));const c=this.supportsSsao(this.ssaoParameters(this._renderOptions));switch(this.antiAliasingMode){case x.FXAA:this.renderComposition(e,this._compositionTarget),r.autoClear=o.autoClear,c&&(this.renderSsao(this._ssaoTarget,e),this.renderPostProcessStep("ssao-blur-combine",this._ssaoBlurCombineTarget,this._ssaoBlurCombineScene)),this.renderPostProcessStep("fxaa",this._renderTarget,this._fxaaScene);break;case x.NoAA:t.autoClear=o.autoClear,c?(this.renderComposition(e,this._compositionTarget),this.renderSsao(this._ssaoTarget,e),this.renderPostProcessStep("ssao-blur-combine",this._renderTarget,this._ssaoBlurCombineScene)):this.renderComposition(e,this._renderTarget);break;default:throw new Error("Unsupported anti-aliasing mode: "+this.antiAliasingMode)}}finally{r.resetState(),this._materialManager.setRenderMode(o.renderMode),this.restoreCadNodes(),this._debugRenderTimings&&Ue.a.debug("=============== RENDER END ===============")}}restoreCadNodes(){this._rootSectorNodeBuffer.forEach(e=>{e[1].add(e[0])}),this._rootSectorNodeBuffer.clear()}extractCadNodes(e){this._rootSectorNodeBuffer.forEach(t=>{if(t[1].parent!==e&&null!==t[1].parent&&t[1].parent.parent!==e)throw new Error("CadNode must be put at scene root");this._cadScene.add(t[0])})}setRenderTarget(e){this._renderTarget=e}getRenderTarget(){return this._renderTarget}setRenderTargetAutoSize(e){this._autoSetTargetSize=e}getRenderTargetAutoSize(){return this._autoSetTargetSize}clearTarget(e){this._renderer.setRenderTarget(e),this._renderer.clear()}explicitFlushRender(e,t){this._renderer.setRenderTarget(t),this.renderStep("flushRender",this._emptyScene,e)}splitToScenes(){const e={hasBackElements:!1,hasInFrontElements:!1,hasGhostElements:!1};this._rootSectorNodeBuffer.forEach(t=>{const n=t[1],r=this._materialManager.getModelBackTreeIndices(n.cadModelMetadata.modelIdentifier),o=this._materialManager.getModelInFrontTreeIndices(n.cadModelMetadata.modelIdentifier),i=this._materialManager.getModelGhostedTreeIndices(n.cadModelMetadata.modelIdentifier),a=r.count>0,s=o.count>0,d=i.count>0;e.hasBackElements=e.hasBackElements||a,e.hasInFrontElements=e.hasInFrontElements||s,e.hasGhostElements=e.hasGhostElements||d});const{hasBackElements:t,hasInFrontElements:n,hasGhostElements:r}=e;return this._rootSectorNodeBuffer.forEach(e=>{const o=e[0],i=e[1],a=this._materialManager.getModelBackTreeIndices(i.cadModelMetadata.modelIdentifier),s=this._materialManager.getModelInFrontTreeIndices(i.cadModelMetadata.modelIdentifier),d=new y.Object3D;d.applyMatrix4(o.matrix),t&&r&&this._normalScene.add(d);const l=new y.Object3D;l.applyMatrix4(o.matrix),n&&this._inFrontScene.add(l);const c=[e[0]];for(;c.length>0;){const e=c.pop(),o=e.userData.treeIndices;o?(n&&s.hasIntersectionWith(o)&&this._inFrontSceneBuilder.addElement(e,l),t&&!r||r&&a.hasIntersectionWith(o)&&this._normalSceneBuilder.addElement(e,d)):c.push(...e.children)}}),e}renderNormalCadModels(e,t=this._normalRenderedCadModelTarget){this._normalSceneBuilder.populateTemporaryScene(),this._renderer.setRenderTarget(t),this.renderStep("normal",this._normalScene,e)}renderNormalCadModelsFromBaseScene(e,t=this._normalRenderedCadModelTarget){this._renderer.setRenderTarget(t),this.renderStep("normalCadModelsFromBaseScene",this._cadScene,e)}renderInFrontCadModels(e,t=this._inFrontRenderedCadModelTarget){this._inFrontSceneBuilder.populateTemporaryScene(),this._renderer.setRenderTarget(t),this._materialManager.setRenderMode(S.Effects),this.renderStep("infront",this._inFrontScene,e)}renderGhostedCadModelsFromBaseScene(e){this._renderer.setRenderTarget(this._ghostObjectRenderTarget),this._materialManager.setRenderMode(S.Ghost),this.renderStep("ghosted",this._cadScene,e)}renderCustomObjects(e,t){const n=e.autoUpdate;try{e.autoUpdate=!0,this._renderer.setRenderTarget(this._customObjectRenderTarget),this.renderStep("customobjects",e,t)}finally{e.autoUpdate=n}}updateRenderSize(e){const t=new y.Vector2;return e.getSize(t),this._renderTarget&&this._autoSetTargetSize&&t.x!==this._renderTarget.width&&t.y!==this._renderTarget.height&&this._renderTarget.setSize(t.x,t.y),t.x===this._normalRenderedCadModelTarget.width&&t.y===this._normalRenderedCadModelTarget.height||(this._normalRenderedCadModelTarget.setSize(t.x,t.y),this._inFrontRenderedCadModelTarget.setSize(t.x,t.y),this._customObjectRenderTarget.setSize(t.x,t.y),this._ghostObjectRenderTarget.setSize(t.x,t.y),this._compositionTarget.setSize(t.x,t.y),this._ssaoTarget.setSize(t.x,t.y),this._ssaoBlurCombineTarget.setSize(t.x,t.y),this._combineOutlineDetectionMaterial.uniforms.texelSize.value=new y.Vector2(this._outlineTexelSize/t.x,this._outlineTexelSize/t.y),this._combineOutlineDetectionMaterial.uniforms.resolution.value=t,this._ssaoMaterial.uniforms.resolution.value=t,this._ssaoBlurCombineMaterial.uniforms.resolution.value=t,this._fxaaMaterial.uniforms.resolution.value=t,this._fxaaMaterial.uniforms.inverseResolution.value=new y.Vector2(1/t.x,1/t.y)),t}renderComposition(e,t){this._combineOutlineDetectionMaterial.uniforms.cameraNear.value=e.near,this._combineOutlineDetectionMaterial.uniforms.cameraFar.value=e.far,this.renderPostProcessStep("composition",t,this._compositionScene)}setSsaoParameters(e){var t;const n=I.ssaoRenderParameters;if(this._ssaoMaterial.uniforms.sampleRadius.value=e.sampleRadius,this._ssaoMaterial.uniforms.bias.value=e.depthCheckBias,e.sampleSize!==this.ssaoParameters(this._renderOptions).sampleSize){const r=null!==(t=null==e?void 0:e.sampleSize)&&void 0!==t?t:n.sampleSize,o=this.createKernel(r);this._fxaaMaterial.uniforms.tDiffuse.value=e.sampleSize!==b.None?this._ssaoBlurCombineTarget.texture:this._compositionTarget.texture,this._ssaoMaterial.uniforms.kernel.value=o,this._ssaoMaterial.defines={MAX_KERNEL_SIZE:r},this._ssaoMaterial.needsUpdate=!0}}renderPostProcessStep(e,t,n){const r=this._renderer;if(r.setRenderTarget(t),this.renderStep(e,n,this._orthographicCamera),t===this._renderTarget){const e=r.getSize(new y.Vector2),t=new y.Vector2(r.domElement.clientWidth,r.domElement.clientHeight),n=new y.Vector2(e.x/t.x,e.y/t.y);r.autoClear=!1,this._uiObjects.forEach(e=>{const t=new y.Scene;t.add(e.object);const o=e.screenPos.clone().multiply(n),i=e.width*n.x,a=e.height*n.y;r.setViewport(o.x,o.y,i,a),r.clearDepth(),r.render(t,this._orthographicCamera)}),r.setViewport(0,0,e.x,e.y),r.autoClear=!0}}renderSsao(e,t){this._ssaoMaterial.uniforms.inverseProjectionMatrix.value=t.projectionMatrixInverse,this._ssaoMaterial.uniforms.projMatrix.value=t.projectionMatrix,this.renderPostProcessStep("ssao",e,this._ssaoScene)}renderStep(e,t,n){if(!this._debugRenderTimings)return void this._renderer.render(t,n);this.deepFlushRenderer();const r=performance.now();this._renderer.render(t,n),this.deepFlushRenderer(),Ue.a.log(`Render stage '${e}' took ${performance.now()-r} ms`)}deepFlushRenderer(){const{buffer:e}=this._deepFlushRendererArgs,t=this._renderer.getContext(),n=this._renderer.getRenderTarget();t.flush(),t.finish(),null!==n&&this._renderer.readRenderTargetPixels(n,0,0,1,1,e)}createOutlineColorTexture(){const e=new Uint8Array(32),t=new y.DataTexture(e,8,1);return $t(t.image.data,r.White,Yt.White),$t(t.image.data,r.Black,Yt.Black),$t(t.image.data,r.Cyan,Yt.Cyan),$t(t.image.data,r.Blue,Yt.Blue),$t(t.image.data,r.Green,Zt.Green),$t(t.image.data,r.Red,Zt.Red),$t(t.image.data,r.Orange,Yt.Orange),t}setupCompositionScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._combineOutlineDetectionMaterial);this._compositionScene.add(t)}setupFxaaScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._fxaaMaterial);this._fxaaScene.add(t)}setupSsaoScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._ssaoMaterial);this._ssaoScene.add(t)}setupSsaoBlurCombineScene(){const e=this.createRenderTriangle(),t=new y.Mesh(e,this._ssaoBlurCombineMaterial);this._ssaoBlurCombineScene.add(t)}createKernel(e){const t=[];for(let r=0;r<e;r++){const o=new y.Vector3;for(;o.length()<.5;)o.x=2*Math.random()-1,o.y=2*Math.random()-1,o.z=Math.random();o.normalize();let i=r/e;i=n(.1,1,i*i),o.multiplyScalar(i),t.push(o)}return t;function n(e,t,n){return e+(t-e)*(n=(n=n<0?0:n)>1?1:n)}}createRenderTriangle(){const e=new y.BufferGeometry,t=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),n=new Float32Array([0,0,2,0,0,2]);return e.setAttribute("position",new y.BufferAttribute(t,3)),e.setAttribute("uv",new y.BufferAttribute(n,2)),e}traverseForRootSectorNode(e){const t=[e];for(;t.length>0;){const e=t.pop();if(e instanceof V.e){const t=e.parent;t.visible&&this._rootSectorNodeBuffer.add([e,t])}else e instanceof y.Group||t.push(...e.children)}}setVisibilityOfSectors(e,t){this._originalScene.traverse(n=>{n instanceof V.f&&n.levelOfDetail===e&&(n.visible=t)})}setupRenderTargetSpectorDebugging(){!1}assignSpectorJsMetadataToRenderTarget(e,t){const n=this._renderer.getRenderTarget();try{this._renderer.setRenderTarget(e);const r=this._renderer.getContext();r.getParameter(r.FRAMEBUFFER_BINDING).__SPECTOR_Metadata=t}finally{this._renderer.setRenderTarget(n)}}}function Jt(e,t,n){if(e&&t>1){const e=new y.WebGLMultisampleRenderTarget(0,0,n);return e.samples=t,e}return new y.WebGLRenderTarget(0,0,n)}function $t(e,t,n){e[4*t+0]=Math.floor(255*n.r),e[4*t+1]=Math.floor(255*n.g),e[4*t+2]=Math.floor(255*n.b),e[4*t+3]=255}class en{constructor(e){this.buffer=[],this.temporaryScene=e}addElement(e,t){this.buffer.push({object:e,parent:e.parent,sceneParent:t})}populateTemporaryScene(){this.buffer.forEach(e=>e.sceneParent.add(e.object))}restoreOriginalScene(){this.buffer.forEach(e=>{e.parent.add(e.object)}),this.buffer.length=0,this.temporaryScene.remove(...this.temporaryScene.children)}}var tn=n(6);function nn(e,t,n,r,o,i,a={}){N.a.init(!1!==a.logMetrics,e,t,{constructorOptions:a});const s=a.renderOptions||{},d=new Kt,l=new Qt(o,i,d,s),c=gt(n,r,o,d,new Ot(l),a),u=function(e,t){const n=new At(e,t),r=new zt(t);return new Pt(n,r)}(n,r);return new Et(c,l,u)}var rn=n(17);
377
377
  /*!
378
378
  * Copyright 2021 Cognite AS
379
379
  */class on{constructor(e,t){switch(this._revealManager=t,e){case"cdf":this.addCadModel=e=>on.addCdfCadModel(e,t),this.addPointCloudModel=e=>on.addCdfPointCloudModel(e,t);break;case"local":this.addCadModel=e=>on.addLocalCadModel(e,t),this.addPointCloudModel=()=>{throw new Error("Local point cloud models are not supported")};break;default:Object(a.k)(e)}}static createLocalHelper(e,t,n){const r=function(e,t,n={}){return nn("local","local-dataSource-appId",new tn.h,new tn.f,e,t,n)}(e,t,n);return new on("local",r)}static createCdfHelper(e,t,n,r){const o=function(e,t,n,r={}){const o=e.getDefaultRequestHeaders()["x-cdp-app"]||"unknown",i=new tn.c(e),a=new tn.a(e);return nn(e.project,o,i,a,t,n,r)}(r,e,t,n);return new on("cdf",o)}static createCustomDataSourceHelper(e,t,n,r){const o=nn("custom-datasource","custom-datasource-app",r.getModelMetadataProvider(),r.getModelDataProvider(),e,t,n);return new on("cdf",o)}get revealManager(){return this._revealManager}static addLocalCadModel(e,t){if(void 0===e.localPath)throw new Error("addLocalCadModel only works with local models");const n=new tn.g(e.localPath);return t.addModel("cad",n,{geometryFilter:e.geometryFilter})}static addCdfCadModel(e,t){if(-1===e.modelId||-1===e.revisionId)throw new Error("addCdfCadModel only works with local models");const n=new tn.b(e.modelId,e.revisionId,tn.e.RevealCadModel);return t.addModel("cad",n,{geometryFilter:e.geometryFilter})}static addCdfPointCloudModel(e,t){if(-1===e.modelId||-1===e.revisionId)throw new Error("addCdfPointCloudModel only works with local models");const n=new tn.b(e.modelId,e.revisionId,tn.e.EptPointCloud);return t.addModel("pointcloud",n)}}
380
380
  /*!
381
381
  * Copyright 2021 Cognite AS
382
- */const an={16:"shift",17:"ctrl",18:"alt",27:"escape",32:"space",37:"left",38:"up",39:"right",40:"down",65:"a",68:"d",69:"e",81:"q",83:"s",87:"w"};class sn{constructor(){this.keys={},this._disabled=!1,this.addEventListeners=()=>{this.clearPressedKeys(),window.addEventListener("keydown",this.onKeydown),window.addEventListener("keyup",this.onKeyup),window.addEventListener("blur",this.clearPressedKeys)},this.removeEventListeners=()=>{window.removeEventListener("keydown",this.onKeydown),window.removeEventListener("keyup",this.onKeyup),window.removeEventListener("blur",this.clearPressedKeys)},this.onKeydown=e=>{e.metaKey||e.altKey||e.ctrlKey||e.keyCode in an&&(0===this.keys[an[e.keyCode]]&&(this.keys[an[e.keyCode]]=2),e.preventDefault())},this.onKeyup=e=>{e.keyCode in an&&(this.keys[an[e.keyCode]]=0)},this.clearPressedKeys=()=>{Object.keys(an).forEach(e=>{this.keys[an[e]]=0})},this.addEventListeners()}get disabled(){return this._disabled}set disabled(e){this._disabled=e,e?this.removeEventListeners():this.addEventListeners()}isPressed(e){return this.keys[e]>=1}comsumePressed(e){const t=2===this.keys[e];return t&&(this.keys[e]=1),t}}
382
+ */const an={16:"shift",17:"ctrl",18:"alt",27:"escape",32:"space",37:"left",38:"up",39:"right",40:"down",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",81:"q",83:"s",87:"w"};class sn{constructor(){this.keys={},this._disabled=!1,this.addEventListeners=()=>{this.clearPressedKeys(),window.addEventListener("keydown",this.onKeydown),window.addEventListener("keyup",this.onKeyup),window.addEventListener("blur",this.clearPressedKeys)},this.removeEventListeners=()=>{window.removeEventListener("keydown",this.onKeydown),window.removeEventListener("keyup",this.onKeyup),window.removeEventListener("blur",this.clearPressedKeys)},this.onKeydown=e=>{e.metaKey||e.altKey||e.ctrlKey||e.keyCode in an&&(0===this.keys[an[e.keyCode]]&&(this.keys[an[e.keyCode]]=2),e.preventDefault())},this.onKeyup=e=>{e.keyCode in an&&(this.keys[an[e.keyCode]]=0)},this.clearPressedKeys=()=>{Object.keys(an).forEach(e=>{this.keys[an[e]]=0})},this.addEventListeners()}get disabled(){return this._disabled}set disabled(e){this._disabled=e,e?this.removeEventListeners():this.addEventListeners()}isPressed(e){return this.keys[e]>=1}comsumePressed(e){const t=2===this.keys[e];return t&&(this.keys[e]=1),t}}
383
383
  /*!
384
384
  * Copyright 2021 Cognite AS
385
- */const dn=-1!==navigator.userAgent.toLowerCase().indexOf("firefox");function ln(e,t,n){return new y.Vector2(t-e.offsetLeft,n-e.offsetTop)}function cn(e,t){if(2!==t.length)throw new Error("getPinchInfo only works if touches.length === 2");const n=[t[0],t[1]].map(({clientX:t,clientY:n})=>ln(e,t,n));return{center:n[0].clone().add(n[1]).multiplyScalar(.5),distance:n[0].distanceTo(n[1]),offsets:n}}const un=Math.PI/360,pn=10*un;class mn extends y.EventDispatcher{constructor(e,t){super(),this.enabled=!0,this.enableDamping=!0,this.dampingFactor=.2,this.dynamicTarget=!0,this.minDistance=1,this.maxDistance=1/0,this.dollyFactor=.98,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.panDollyMinDistanceFactor=10,this.firstPersonRotationFactor=.4,this.pointerRotationSpeedAzimuth=un,this.pointerRotationSpeedPolar=un,this.enableKeyboardNavigation=!0,this.keyboardRotationSpeedAzimuth=pn,this.keyboardRotationSpeedPolar=pn,this.mouseFirstPersonRotationSpeed=2*un,this.keyboardDollySpeed=2,this.keyboardPanSpeed=10,this.keyboardSpeedFactor=3,this.pinchEpsilon=2,this.pinchPanSpeed=1,this.EPSILON=.003,this.minZoom=0,this.maxZoom=1/0,this.orthographicCameraDollyFactor=.3,this.temporarilyDisableDamping=!1,this.firstPersonMode=!1,this.reusableVector3=new y.Vector3,this._accumulatedMouseMove=new y.Vector2,this.target=new y.Vector3,this.targetEnd=new y.Vector3,this.spherical=new y.Spherical,this.sphericalEnd=new y.Spherical,this.deltaTarget=new y.Vector3,this.keyboard=new sn,this.offsetVector=new y.Vector3,this.panVector=new y.Vector3,this.raycaster=new y.Raycaster,this.targetFPS=30,this.targetFPSOverActualFPS=1,this.isFocused=!1,this.update=e=>{const{camera:t,target:n,targetEnd:r,spherical:o,sphericalEnd:i,deltaTarget:a,handleKeyboard:s,enableDamping:d,dampingFactor:l,EPSILON:c,targetFPS:u,enabled:p}=this;if(!p)return!1;const m=Math.min(1/e,u);this.targetFPSOverActualFPS=u/m,s(),this._accumulatedMouseMove.lengthSq()>0&&(this.rotate(this._accumulatedMouseMove.x,this._accumulatedMouseMove.y),this._accumulatedMouseMove.set(0,0));let h=0;this.firstPersonMode?h+=this.calculateShortestDeltaTheta(i.theta,o.theta):h=i.theta-o.theta;const f=i.phi-o.phi,v=i.radius-o.radius;a.subVectors(r,n);let x=!1;const g=d&&!this.temporarilyDisableDamping?Math.min(l*this.targetFPSOverActualFPS,1):1;return this.temporarilyDisableDamping=!1,Math.abs(h)>c||Math.abs(f)>c||Math.abs(v)>c||Math.abs(a.x)>c||Math.abs(a.y)>c||Math.abs(a.z)>c?(o.set(o.radius+v*g,o.phi+f*g,o.theta+h*g),n.add(a.multiplyScalar(g)),x=!0):(i.copy(o),n.copy(r)),o.makeSafe(),t.position.setFromSpherical(o).add(n),t.lookAt(n),x&&this.triggerCameraChangeEvent(),x},this.getState=()=>{const{target:e,camera:t}=this;return{target:e.clone(),position:t.position.clone()}},this.setState=(e,t)=>{const n=e.clone().sub(t);this.targetEnd.copy(t),this.sphericalEnd.setFromVector3(n),this.target.copy(this.targetEnd),this.spherical.copy(this.sphericalEnd),this.update(1e3/this.targetFPS),this.triggerCameraChangeEvent()},this.triggerCameraChangeEvent=()=>{const{camera:e,target:t}=this;this.dispatchEvent({type:"cameraChange",camera:{position:e.position,target:t}})},this.onMouseDown=e=>{if(this.enabled)switch(this.firstPersonMode=!1,this.sphericalEnd.copy(this.spherical),e.button){case y.MOUSE.LEFT:this.startMouseRotation(e);break;case y.MOUSE.RIGHT:e.preventDefault(),this.startMousePan(e)}},this.onMouseUp=e=>{this._accumulatedMouseMove.set(0,0)},this.onMouseWheel=e=>{if(!this.enabled)return;e.preventDefault();let t=0;if(e.wheelDelta)t=-e.wheelDelta/40;else if(e.detail)t=e.detail;else if(e.deltaY){const n=dn?1:40;t=e.deltaY/n}const{domElement:n}=this;let r=e.offsetX,o=e.offsetY;r=r/n.clientWidth*2-1,o=o/n.clientHeight*-2+1;const i=t<0,a=this.camera.isPerspectiveCamera?this.getDollyDeltaDistance(i,Math.abs(t)):Math.sign(t)*this.orthographicCameraDollyFactor;this.dolly(r,o,a)},this.onTouchStart=e=>{if(this.enabled)switch(e.preventDefault(),this.firstPersonMode=!1,this.sphericalEnd.copy(this.spherical),e.touches.length){case 1:this.startTouchRotation(e);break;case 2:this.startTouchPinch(e)}},this.onFocusChanged=e=>{this.isFocused="blur"!==e.type&&(e.target===this.domElement||document.activeElement===this.domElement),this.keyboard.disabled=!this.isFocused},this.onContextMenu=e=>{this.enabled&&e.preventDefault()},this.rotate=(e,t)=>{if(0===e&&0===t)return;const n=(this.firstPersonMode?this.mouseFirstPersonRotationSpeed:this.pointerRotationSpeedAzimuth)*e,r=(this.firstPersonMode?this.mouseFirstPersonRotationSpeed:this.pointerRotationSpeedPolar)*t;this.firstPersonMode?(this.temporarilyDisableDamping=!0,this.rotateFirstPersonMode(n,r)):this.rotateSpherical(n,r)},this.startMouseRotation=e=>{let t=ln(this.domElement,e.clientX,e.clientY);const n=e=>{const n=ln(this.domElement,e.clientX,e.clientY),r=t.clone().sub(n);this._accumulatedMouseMove.add(r),t=n},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",n,{passive:!1}),window.addEventListener("mouseup",r,{passive:!1})},this.startMousePan=e=>{let t=ln(this.domElement,e.clientX,e.clientY);const n=e=>{const n=ln(this.domElement,e.clientX,e.clientY),r=n.x-t.x,o=n.y-t.y;t=n,this.pan(r,o)},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",n,{passive:!1}),window.addEventListener("mouseup",r,{passive:!1})},this.startTouchRotation=e=>{const{domElement:t}=this;let n=ln(t,e.touches[0].clientX,e.touches[0].clientY);const r=e=>{if(1!==e.touches.length)return;const r=ln(t,e.touches[0].clientX,e.touches[0].clientY);this.rotate(n.x-r.x,n.y-r.y),n=r},o=e=>{1!==e.touches.length&&a()},i=()=>{a()},a=()=>{document.removeEventListener("touchstart",o),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",i)};document.addEventListener("touchstart",o),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",i,{passive:!1})},this.startTouchPinch=e=>{const{domElement:t}=this;let n=cn(t,e.touches);const r=cn(t,e.touches),o=this.spherical.radius,i=e=>{if(2!==e.touches.length)return;const i=cn(t,e.touches),a=r.distance/i.distance;this.sphericalEnd.radius=Math.max(a*o,this.minDistance/5);const s=i.center.clone().sub(n.center);s.length()>this.pinchEpsilon&&(s.multiplyScalar(this.pinchPanSpeed),this.pan(s.x,s.y)),n=i},a=e=>{2!==e.touches.length&&d()},s=()=>{d()},d=()=>{document.removeEventListener("touchstart",a),document.removeEventListener("touchmove",i),document.removeEventListener("touchend",s)};document.addEventListener("touchstart",a),document.addEventListener("touchmove",i),document.addEventListener("touchend",s)},this.handleKeyboard=()=>{if(!this.enabled||!this.enableKeyboardNavigation||!this.isFocused)return;const{keyboard:e,keyboardDollySpeed:t,keyboardPanSpeed:n,keyboardSpeedFactor:r}=this,o=this.keyboardRotationSpeedAzimuth*(Number(e.isPressed("left"))-Number(e.isPressed("right")));let i=this.keyboardRotationSpeedPolar*(Number(e.isPressed("up"))-Number(e.isPressed("down")));if(0!==o||0!==i){this.firstPersonMode=!0;const{sphericalEnd:e}=this,t=e.phi;e.phi+=i,e.makeSafe(),i=e.phi-t,e.phi=t,this.rotateFirstPersonMode(o,i)}const a=e.isPressed("shift")?r:1,s=!!e.isPressed("w")||!e.isPressed("s")&&void 0;void 0!==s&&(this.firstPersonMode=!0,this.dolly(0,0,this.getDollyDeltaDistance(s,t*a)));const d=Number(e.isPressed("a"))-Number(e.isPressed("d")),l=Number(e.isPressed("e"))-Number(e.isPressed("q"));0===d&&0===l||(this.firstPersonMode=!0,this.pan(a*n*d,a*n*l))},this.rotateSpherical=(e,t)=>{const{sphericalEnd:n}=this,r=y.MathUtils.clamp(n.theta+e,this.minAzimuthAngle,this.maxAzimuthAngle),o=y.MathUtils.clamp(n.phi+t,this.minPolarAngle,this.maxPolarAngle);n.theta=r,n.phi=o,n.makeSafe()},this.rotateFirstPersonMode=(e,t)=>{const{firstPersonRotationFactor:n,reusableCamera:r,reusableVector3:o,sphericalEnd:i,targetEnd:a}=this;r.position.setFromSpherical(i).add(a),r.lookAt(a),r.rotateX(n*t),r.rotateY(n*e);const s=a.distanceTo(r.position);r.getWorldDirection(o),a.addVectors(r.position,o.multiplyScalar(s)),i.setFromVector3(o.subVectors(r.position,a)),i.makeSafe()},this.pan=(e,t)=>{const{domElement:n,camera:r,offsetVector:o,target:i}=this;o.copy(r.position).sub(i);let a=o.length();a=Math.max(a,this.panDollyMinDistanceFactor*this.minDistance),r.isPerspectiveCamera&&(a*=Math.tan(r.fov/2*Math.PI/180)),this.panLeft(2*e*a/n.clientHeight),this.panUp(2*t*a/n.clientHeight)},this.dollyOrthographicCamera=(e,t,n)=>{const r=this.camera;r.zoom*=1-n,r.zoom=y.MathUtils.clamp(r.zoom,this.minZoom,this.maxZoom),r.updateProjectionMatrix()},this.dollyPerspectiveCamera=(e,t,n)=>{const{dynamicTarget:r,minDistance:o,raycaster:i,reusableVector3:a,sphericalEnd:s,targetEnd:d,camera:l,reusableCamera:c}=this,u=Math.tan(y.MathUtils.degToRad(90-.5*l.fov)),p=Math.sqrt(u*u+e*e+t*t)/u,m=a.setFromSpherical(s).length();c.copy(l),c.position.setFromSpherical(s).add(d),c.lookAt(d),i.setFromCamera({x:e,y:t},c);const h=a;let f=m+n;f<o&&(f=o,r?(c.getWorldDirection(h),d.add(h.normalize().multiplyScalar(Math.abs(n)))):n=m-f);const v=-n*p;s.radius=f,c.getWorldDirection(h),h.normalize().multiplyScalar(n);const x=i.ray.direction.normalize().multiplyScalar(v).add(h);d.add(x)},this.dolly=(e,t,n)=>{const{camera:r}=this;r.isOrthographicCamera?this.dollyOrthographicCamera(e,t,n):r.isPerspectiveCamera&&this.dollyPerspectiveCamera(e,t,n)},this.getDollyDeltaDistance=(e,t=1)=>{const{sphericalEnd:n,dollyFactor:r}=this,o=r**t,i=e?o:1/o;return Math.max(n.radius,this.panDollyMinDistanceFactor*this.minDistance)*(i-1)},this.panLeft=e=>{const{camera:t,targetEnd:n,panVector:r}=this;r.setFromMatrixColumn(t.matrix,0),r.multiplyScalar(-e),n.add(r)},this.panUp=e=>{const{camera:t,targetEnd:n,panVector:r}=this;r.setFromMatrixColumn(t.matrix,1),r.multiplyScalar(e),n.add(r)},this.camera=e,this.reusableCamera=e.clone(),this.domElement=t,this.spherical.setFromVector3(e.position),this.sphericalEnd.copy(this.spherical),t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("touchstart",this.onTouchStart),t.addEventListener("wheel",this.onMouseWheel),t.addEventListener("contextmenu",this.onContextMenu),t.addEventListener("focus",this.onFocusChanged),t.addEventListener("blur",this.onFocusChanged),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("mousedown",this.onFocusChanged),window.addEventListener("touchstart",this.onFocusChanged),this.dispose=()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("wheel",this.onMouseWheel),t.removeEventListener("touchstart",this.onTouchStart),t.removeEventListener("contextmenu",this.onContextMenu),t.removeEventListener("focus",this.onFocusChanged),t.removeEventListener("blur",this.onFocusChanged),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("mousedown",this.onFocusChanged),window.removeEventListener("touchstart",this.onFocusChanged)}}calculateShortestDeltaTheta(e,t){const n=e%(2*Math.PI)-t%(2*Math.PI);let r=Math.min(Math.abs(n),2*Math.PI-Math.abs(n));return r*=(r===Math.abs(n)?1:-1)*Math.sign(n),r}}
385
+ */const dn=-1!==navigator.userAgent.toLowerCase().indexOf("firefox");function ln(e,t,n){return new y.Vector2(t-e.offsetLeft,n-e.offsetTop)}function cn(e,t){if(2!==t.length)throw new Error("getPinchInfo only works if touches.length === 2");const n=[t[0],t[1]].map(({clientX:t,clientY:n})=>ln(e,t,n));return{center:n[0].clone().add(n[1]).multiplyScalar(.5),distance:n[0].distanceTo(n[1]),offsets:n}}const un=Math.PI/360,pn=10*un;class mn extends y.EventDispatcher{constructor(e,t){super(),this.enabled=!0,this.enableDamping=!0,this.dampingFactor=.25,this.dynamicTarget=!0,this.minDistance=.1,this.maxDistance=1/0,this.dollyFactor=.98,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.panDollyMinDistanceFactor=10,this.firstPersonRotationFactor=.4,this.pointerRotationSpeedAzimuth=un,this.pointerRotationSpeedPolar=un,this.enableKeyboardNavigation=!0,this.keyboardRotationSpeedAzimuth=pn,this.keyboardRotationSpeedPolar=pn,this.mouseFirstPersonRotationSpeed=2*un,this.keyboardDollySpeed=2,this.keyboardPanSpeed=10,this.keyboardSpeedFactor=3,this.pinchEpsilon=2,this.pinchPanSpeed=1,this.EPSILON=.001,this.minZoom=0,this.maxZoom=1/0,this.orthographicCameraDollyFactor=.3,this.lookAtViewTarget=!1,this.useScrollTarget=!1,this.zoomToCursor=!0,this.minDeltaRatio=1,this.maxDeltaRatio=8,this.minDeltaDownscaleCoefficient=.1,this.maxDeltaDownscaleCoefficient=1,this._temporarilyDisableDamping=!1,this._firstPersonMode=!1,this._reusableVector3=new y.Vector3,this._accumulatedMouseMove=new y.Vector2,this._target=new y.Vector3,this._viewTarget=new y.Vector3,this._scrollTarget=new y.Vector3,this._targetEnd=new y.Vector3,this._spherical=new y.Spherical,this._sphericalEnd=new y.Spherical,this._deltaTarget=new y.Vector3,this._keyboard=new sn,this._offsetVector=new y.Vector3,this._panVector=new y.Vector3,this._raycaster=new y.Raycaster,this._targetFPS=30,this._targetFPSOverActualFPS=1,this._isFocused=!1,this.update=e=>{const{_camera:t,_target:n,_targetEnd:r,_spherical:o,_sphericalEnd:i,_deltaTarget:a,handleKeyboard:s,enableDamping:d,dampingFactor:l,EPSILON:c,_targetFPS:u,enabled:p}=this;if(!p)return!1;const m=Math.min(1/e,u);this._targetFPSOverActualFPS=u/m,s(),this._accumulatedMouseMove.lengthSq()>0&&(this.rotate(this._accumulatedMouseMove.x,this._accumulatedMouseMove.y),this._accumulatedMouseMove.set(0,0));let h=0;this._firstPersonMode?h+=this.calculateShortestDeltaTheta(i.theta,o.theta):h=i.theta-o.theta;const f=i.phi-o.phi,v=i.radius-o.radius;a.subVectors(r,n);let g=!1;const x=d&&!this._temporarilyDisableDamping?Math.min(l*this._targetFPSOverActualFPS,1):1;return this._temporarilyDisableDamping=!1,Math.abs(h)>c||Math.abs(f)>c||Math.abs(v)>c||Math.abs(a.x)>c||Math.abs(a.y)>c||Math.abs(a.z)>c?(o.set(o.radius+v*x,o.phi+f*x,o.theta+h*x),n.add(a.multiplyScalar(x)),g=!0):(o.copy(i),n.copy(r)),o.makeSafe(),t.position.setFromSpherical(o).add(n),t.lookAt(this.lookAtViewTarget?this._viewTarget:n),g&&this.triggerCameraChangeEvent(),g},this.getState=()=>{const{_target:e,_camera:t}=this;return{target:e.clone(),position:t.position.clone()}},this.setState=(e,t)=>{const n=e.clone().sub(t);this._targetEnd.copy(t),this._sphericalEnd.setFromVector3(n),this._target.copy(this._targetEnd),this._scrollTarget.copy(t),this._spherical.copy(this._sphericalEnd),this.update(1e3/this._targetFPS),this.triggerCameraChangeEvent()},this.setViewTarget=e=>{this._viewTarget.copy(e)},this.setScrollTarget=e=>{this._scrollTarget.copy(e)},this.triggerCameraChangeEvent=()=>{const{_camera:e,_target:t}=this;this.dispatchEvent({type:"cameraChange",camera:{position:e.position,target:t}})},this.convertPixelCoordinatesToNormalized=(e,t)=>({x:e/this._domElement.clientWidth*2-1,y:t/this._domElement.clientHeight*-2+1}),this.onMouseDown=e=>{if(this.enabled)switch(this._firstPersonMode=!1,this._sphericalEnd.copy(this._spherical),e.button){case y.MOUSE.LEFT:this.startMouseRotation(e);break;case y.MOUSE.RIGHT:e.preventDefault(),this.startMousePan(e)}},this.onMouseUp=e=>{this._accumulatedMouseMove.set(0,0)},this.onMouseWheel=e=>{if(!this.enabled)return;e.preventDefault();let t=0;if(e.wheelDelta)t=-e.wheelDelta/40;else if(e.detail)t=e.detail;else if(e.deltaY){const n=dn?1:40;t=e.deltaY/n}const{x:n,y:r}=this.convertPixelCoordinatesToNormalized(e.offsetX,e.offsetY),o=t<0,i=this._camera.isPerspectiveCamera?this.getDollyDeltaDistance(o,Math.abs(t)):Math.sign(t)*this.orthographicCameraDollyFactor;this.dolly(n,r,i,!1)},this.onTouchStart=e=>{if(this.enabled)switch(e.preventDefault(),this._firstPersonMode=!1,this._sphericalEnd.copy(this._spherical),e.touches.length){case 1:this.startTouchRotation(e);break;case 2:this.startTouchPinch(e)}},this.onFocusChanged=e=>{this._isFocused="blur"!==e.type&&(e.target===this._domElement||document.activeElement===this._domElement),this._keyboard.disabled=!this._isFocused},this.onContextMenu=e=>{this.enabled&&e.preventDefault()},this.rotate=(e,t)=>{if(0===e&&0===t)return;const n=(this._firstPersonMode?this.mouseFirstPersonRotationSpeed:this.pointerRotationSpeedAzimuth)*e,r=(this._firstPersonMode?this.mouseFirstPersonRotationSpeed:this.pointerRotationSpeedPolar)*t;this._firstPersonMode?(this._temporarilyDisableDamping=!0,this.rotateFirstPersonMode(n,r)):this.rotateSpherical(n,r)},this.startMouseRotation=e=>{let t=ln(this._domElement,e.clientX,e.clientY);const n=e=>{const n=ln(this._domElement,e.clientX,e.clientY),r=t.clone().sub(n);this._accumulatedMouseMove.add(r),t=n},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",n,{passive:!1}),window.addEventListener("mouseup",r,{passive:!1})},this.startMousePan=e=>{let t=ln(this._domElement,e.clientX,e.clientY);const n=e=>{const n=ln(this._domElement,e.clientX,e.clientY),r=n.x-t.x,o=n.y-t.y;t=n,this.pan(r,o)},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",n,{passive:!1}),window.addEventListener("mouseup",r,{passive:!1})},this.startTouchRotation=e=>{const{_domElement:t}=this;let n=ln(t,e.touches[0].clientX,e.touches[0].clientY);const r=e=>{if(1!==e.touches.length)return;const r=ln(t,e.touches[0].clientX,e.touches[0].clientY);this.rotate(n.x-r.x,n.y-r.y),n=r},o=e=>{1!==e.touches.length&&a()},i=()=>{a()},a=()=>{document.removeEventListener("touchstart",o),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",i)};document.addEventListener("touchstart",o),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",i,{passive:!1})},this.startTouchPinch=e=>{const{_domElement:t}=this;let n=cn(t,e.touches);const r=cn(t,e.touches),o=this._spherical.radius,i=e=>{if(2!==e.touches.length)return;const i=cn(t,e.touches),a=r.distance/i.distance;this._sphericalEnd.radius=Math.max(a*o,this.minDistance/5);const s=i.center.clone().sub(n.center);s.length()>this.pinchEpsilon&&(s.multiplyScalar(this.pinchPanSpeed),this.pan(s.x,s.y)),n=i},a=e=>{2!==e.touches.length&&d()},s=()=>{d()},d=()=>{document.removeEventListener("touchstart",a),document.removeEventListener("touchmove",i),document.removeEventListener("touchend",s)};document.addEventListener("touchstart",a),document.addEventListener("touchmove",i),document.addEventListener("touchend",s)},this.handleKeyboard=()=>{if(!this.enabled||!this.enableKeyboardNavigation||!this._isFocused)return;const{_keyboard:e,keyboardDollySpeed:t,keyboardPanSpeed:n,keyboardSpeedFactor:r}=this,o=this.keyboardRotationSpeedAzimuth*(Number(e.isPressed("left"))-Number(e.isPressed("right")));let i=this.keyboardRotationSpeedPolar*(Number(e.isPressed("up"))-Number(e.isPressed("down")));if(0!==o||0!==i){this._firstPersonMode=!0;const{_sphericalEnd:e}=this,t=e.phi;e.phi+=i,e.makeSafe(),i=e.phi-t,e.phi=t,this.rotateFirstPersonMode(o,i)}const a=e.isPressed("shift")?r:1,s=!!e.isPressed("w")||!e.isPressed("s")&&void 0;void 0!==s&&(this.dolly(0,0,this.getDollyDeltaDistance(s,t*a),!0),this._firstPersonMode=!0);const d=Number(e.isPressed("a"))-Number(e.isPressed("d")),l=Number(e.isPressed("e"))-Number(e.isPressed("q"));0===d&&0===l||(this._firstPersonMode=!0,this.pan(a*n*d,a*n*l))},this.rotateSpherical=(e,t)=>{const{_sphericalEnd:n}=this,r=y.MathUtils.clamp(n.theta+e,this.minAzimuthAngle,this.maxAzimuthAngle),o=y.MathUtils.clamp(n.phi+t,this.minPolarAngle,this.maxPolarAngle);n.theta=r,n.phi=o,n.makeSafe()},this.rotateFirstPersonMode=(e,t)=>{const{firstPersonRotationFactor:n,_reusableCamera:r,_reusableVector3:o,_sphericalEnd:i,_targetEnd:a}=this;r.position.setFromSpherical(i).add(a),r.lookAt(a),r.rotateX(n*t),r.rotateY(n*e);const s=a.distanceTo(r.position);r.getWorldDirection(o),a.addVectors(r.position,o.multiplyScalar(s)),i.setFromVector3(o.subVectors(r.position,a)),i.makeSafe()},this.pan=(e,t)=>{const{_domElement:n,_camera:r,_offsetVector:o,_target:i}=this;o.copy(r.position).sub(i);let a=Math.max(o.length(),this.panDollyMinDistanceFactor*this.minDistance);r.isPerspectiveCamera&&(a*=Math.tan(r.fov/2*Math.PI/180)),this.panLeft(2*e*a/n.clientHeight),this.panUp(2*t*a/n.clientHeight)},this.dollyOrthographicCamera=(e,t,n)=>{const r=this._camera;r.zoom*=1-n,r.zoom=y.MathUtils.clamp(r.zoom,this.minZoom,this.maxZoom),r.updateProjectionMatrix()},this.calculateNewRadiusAndTargetOffsetLerp=(e,t,n,r)=>{const{dynamicTarget:o,minDistance:i,_raycaster:a,_targetEnd:s,_reusableCamera:d}=this,l=Math.tan(y.MathUtils.degToRad(90-.5*this._camera.fov)),c=Math.sqrt(l*l+e*e+t*t)/l,u=r.length();a.setFromCamera({x:e,y:t},d);let p=u+n;p<i&&(p=i,o?(d.getWorldDirection(r),s.add(r.normalize().multiplyScalar(Math.abs(n)))):n=u-p);const m=-n*c;d.getWorldDirection(r),r.normalize().multiplyScalar(n);return{targetOffset:a.ray.direction.normalize().multiplyScalar(m).add(r),radius:p}},this.clampedMap=(e,t,n,r,o)=>e=e<t?r:e>n?o:y.MathUtils.mapLinear(e,t,n,r,o),this.calculateNewRadiusAndTargetOffsetScrollTarget=(e,t)=>{const{minDistance:n,_reusableVector3:r,_target:o,_scrollTarget:i,_camera:a,minDeltaRatio:s,maxDeltaRatio:d,minDeltaDownscaleCoefficient:l,maxDeltaDownscaleCoefficient:c}=this,u=t.length(),p=e>0;p&&this.setScrollTarget(o);const m=r.subVectors(i,o).normalize(),h=(new y.Vector3).subVectors(o,a.position),f=(new y.Vector3).subVectors(i,a.position),v=h.angleTo(f),g=m.negate().angleTo(f.negate());let x=e*(Math.sin(v)/Math.sin(g));const b=Math.abs(x/e),_=this.clampedMap(b,s,d,c,l);x*=_;let T=u+(e*=_);T<n&&(this._temporarilyDisableDamping=!0,i.distanceTo(o)<n&&(T=n,x=0));return{targetOffset:m.multiplyScalar(p?0:x),radius:T}},this.dollyWithWheelScroll=(e,t,n,r)=>{const{_targetEnd:o,_sphericalEnd:i,useScrollTarget:a,zoomToCursor:s}=this,d=n<0,l=new y.Vector3;let c=i.radius;if(s)if(a&&d){const{radius:e,targetOffset:t}=this.calculateNewRadiusAndTargetOffsetScrollTarget(n,r);c=e,l.copy(t)}else{const{radius:o,targetOffset:i}=this.calculateNewRadiusAndTargetOffsetLerp(e,t,n,r);c=o,l.copy(i)}else{const{radius:e,targetOffset:t}=this.calculateNewRadiusAndTargetOffsetLerp(0,0,n,r);c=e,l.copy(t)}o.add(l),i.radius=c},this.dollyPerspectiveCamera=(e,t,n,r=!1)=>{const{_reusableVector3:o,_targetEnd:i,_reusableCamera:a,_sphericalEnd:s,_camera:d}=this;a.copy(d),a.position.setFromSpherical(s).add(i),a.lookAt(i);const l=o.setFromSpherical(s);r?(a.getWorldDirection(l),i.add(l.normalize().multiplyScalar(-n))):this.dollyWithWheelScroll(e,t,n,l)},this.dolly=(e,t,n,r)=>{const{_camera:o}=this;o.isOrthographicCamera?this.dollyOrthographicCamera(e,t,n):o.isPerspectiveCamera&&this.dollyPerspectiveCamera(e,t,n,r)},this.getDollyDeltaDistance=(e,t=1)=>{const{_sphericalEnd:n,dollyFactor:r}=this,o=r**t,i=e?o:1/o;return Math.max(n.radius,this.panDollyMinDistanceFactor*this.minDistance)*(i-1)},this.panLeft=e=>{const{_camera:t,_targetEnd:n,_panVector:r}=this;r.setFromMatrixColumn(t.matrix,0),r.multiplyScalar(-e),n.add(r)},this.panUp=e=>{const{_camera:t,_targetEnd:n,_panVector:r}=this;r.setFromMatrixColumn(t.matrix,1),r.multiplyScalar(e),n.add(r)},this._camera=e,this._reusableCamera=e.clone(),this._domElement=t,this._spherical.setFromVector3(e.position),this._sphericalEnd.copy(this._spherical),t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("touchstart",this.onTouchStart),t.addEventListener("wheel",this.onMouseWheel),t.addEventListener("contextmenu",this.onContextMenu),t.addEventListener("focus",this.onFocusChanged),t.addEventListener("blur",this.onFocusChanged),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("mousedown",this.onFocusChanged),window.addEventListener("touchstart",this.onFocusChanged),this.dispose=()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("wheel",this.onMouseWheel),t.removeEventListener("touchstart",this.onTouchStart),t.removeEventListener("contextmenu",this.onContextMenu),t.removeEventListener("focus",this.onFocusChanged),t.removeEventListener("blur",this.onFocusChanged),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("mousedown",this.onFocusChanged),window.removeEventListener("touchstart",this.onFocusChanged)}}calculateShortestDeltaTheta(e,t){const n=e%(2*Math.PI)-t%(2*Math.PI);let r=Math.min(Math.abs(n),2*Math.PI-Math.abs(n));return r*=(r===Math.abs(n)?1:-1)*Math.sign(n),r}}
386
386
  /*!
387
387
  * Copyright 2021 Cognite AS
388
388
  */var hn=n(27);
@@ -391,13 +391,13 @@ class Qt{constructor(e,t,n,r){var o,i;this._lastFrameSceneState={hasBackElements
391
391
  */class fn{constructor(e){this._client=e}async mapTreeIndicesToNodeIds(e,t,n){const r=[...vn(n,fn.MaxItemsPerRequest)].map(async n=>this.postByTreeIndicesRequest(e,t,n));return(await Promise.all(r)).flat()}async mapNodeIdsToTreeIndices(e,t,n){const r=[...vn(n,fn.MaxItemsPerRequest)].map(async n=>this.postByNodeIdsRequest(e,t,n));return(await Promise.all(r)).flat()}async determineTreeIndexAndSubtreeSizesByNodeIds(e,t,n){const r=n.map(e=>({id:e}));return(await this._client.revisions3D.retrieve3DNodes(e,t,r)).map(e=>({treeIndex:e.treeIndex,subtreeSize:e.subtreeSize}))}async determineNodeAncestorsByNodeId(e,t,n,r){const o=await this._client.revisions3D.list3DNodeAncestors(e,t,n,{limit:1e3}),a=o.items.find(e=>e.id===n);i()(void 0!==a,"Could not find ancestor for node with nodeId "+n),r=Math.min(a.depth,r);const s=o.items.find(e=>e.depth===a.depth-r);return i()(void 0!==a,`Could not find ancestor for node with nodeId ${n} at 'generation' ${r}`),{treeIndex:s.treeIndex,subtreeSize:s.subtreeSize}}async getBoundingBoxByNodeId(e,t,n,r){const o=await this._client.revisions3D.retrieve3DNodes(e,t,[{id:n}]);if(o.length<1)throw new Error("NodeId not found");const i=o[0].boundingBox;if(void 0===i)throw new Error(`Node ${n} doesn't have a defined bounding box`);const a=i.min,s=i.max,d=r||new y.Box3;return d.min.set(a[0],a[1],a[2]),d.max.set(s[0],s[1],s[2]),d}async postByTreeIndicesRequest(e,t,n){console.assert(n.length<=fn.MaxItemsPerRequest);const r=`${this._client.getBaseUrl()}/api/v1/projects/${this._client.project}/3d/models/${e}/revisions/${t}/nodes/internalids/bytreeindices`,o=await this._client.post(r,{data:{items:n}});if(200===o.status)return o.data.items;throw new hn.HttpError(o.status,o.data,o.headers)}async postByNodeIdsRequest(e,t,n){console.assert(n.length<=fn.MaxItemsPerRequest);const r=`${this._client.getBaseUrl()}/api/v1/projects/${this._client.project}/3d/models/${e}/revisions/${t}/nodes/treeindices/byinternalids`,o=await this._client.post(r,{data:{items:n}});if(200===o.status)return o.data.items;throw new hn.HttpError(o.status,o.data,o.headers)}}function*vn(e,t){let n=0;for(;n<e.length;){const r=Math.min(e.length-n,t);yield e.slice(n,n+r),n+=r}}
392
392
  /*!
393
393
  * Copyright 2021 Cognite AS
394
- */fn.MaxItemsPerRequest=1e3;class xn{constructor(){}mapTreeIndicesToNodeIds(e,t,n){return Promise.resolve(n)}mapNodeIdsToTreeIndices(e,t,n){return Promise.resolve(n)}determineTreeIndexAndSubtreeSizesByNodeIds(e,t,n){throw new Error("Not supported for local models")}determineNodeAncestorsByNodeId(e,t,n,r){throw new Error("Not supported for local models")}getBoundingBoxByNodeId(e,t,n,r){throw new Error("Not supported for local models")}}class gn{constructor(e){this._metadataProvider=new tn.c(e),this._nodesApiClient=new fn(e),this._modelDataClient=new tn.a(e)}getNodesApiClient(){return this._nodesApiClient}getModelDataProvider(){return this._modelDataClient}getModelMetadataProvider(){return this._metadataProvider}}
394
+ */fn.MaxItemsPerRequest=1e3;class gn{constructor(){}mapTreeIndicesToNodeIds(e,t,n){return Promise.resolve(n)}mapNodeIdsToTreeIndices(e,t,n){return Promise.resolve(n)}determineTreeIndexAndSubtreeSizesByNodeIds(e,t,n){throw new Error("Not supported for local models")}determineNodeAncestorsByNodeId(e,t,n,r){throw new Error("Not supported for local models")}getBoundingBoxByNodeId(e,t,n,r){throw new Error("Not supported for local models")}}class xn{constructor(e){this._metadataProvider=new tn.c(e),this._nodesApiClient=new fn(e),this._modelDataClient=new tn.a(e)}getNodesApiClient(){return this._nodesApiClient}getModelDataProvider(){return this._modelDataClient}getModelMetadataProvider(){return this._metadataProvider}}
395
395
  /*!
396
396
  * Copyright 2021 Cognite AS
397
- */class bn{getNodesApiClient(){return new xn}getModelDataProvider(){return new tn.f}getModelMetadataProvider(){throw new tn.h}}
397
+ */class bn{getNodesApiClient(){return new gn}getModelDataProvider(){return new tn.f}getModelMetadataProvider(){throw new tn.h}}
398
398
  /*!
399
399
  * Copyright 2021 Cognite AS
400
- */class yn{constructor(e){var t,n,r,o,i,s;this._subscription=new M.Subscription,this._boundAnimate=this.animate.bind(this),this._events={cameraChange:new a.d,click:new a.d,hover:new a.d,sceneRendered:new a.d,disposed:new a.d},this._models=[],this._extraObjects=[],this.isDisposed=!1,this.latestRequestId=-1,this.clock=new y.Clock,this._clippingNeedsUpdate=!1,this._updateNearAndFarPlaneBuffers={combinedBbox:new y.Box3,bbox:new y.Box3,cameraPosition:new y.Vector3,cameraDirection:new y.Vector3,nearPlaneCoplanarPoint:new y.Vector3,nearPlane:new y.Plane,corners:new Array(new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3)},this.startPointerEventListeners=()=>{const e=this.canvas;let t=!1,n=0,r=!1;const o=v()(t=>{this._events.hover.fire(Object(a.l)(t,e))},100),i=n=>{const{offsetX:o,offsetY:i}=Object(a.l)(n,e),{offsetX:s,offsetY:d}=Object(a.l)(n,e);t&&r&&Math.abs(o-s)+Math.abs(i-d)>4&&(r=!1)},s=d=>{const l=d.timeStamp-n;t&&r&&l<250&&this._events.click.fire(Object(a.l)(d,e)),t=!1,r=!1,e.removeEventListener("mousemove",i),e.removeEventListener("touchmove",i),e.removeEventListener("mouseup",s),e.removeEventListener("touchend",s),e.addEventListener("mousemove",o)},d=a=>{event=a,t=!0,r=!0,n=a.timeStamp,e.addEventListener("mousemove",i),e.addEventListener("touchmove",i),e.addEventListener("mouseup",s),e.addEventListener("touchend",s),e.removeEventListener("mousemove",o)};e.addEventListener("mousedown",d),e.addEventListener("touchstart",d),e.addEventListener("mousemove",o)},this._renderer=e.renderer||new y.WebGLRenderer,this._renderer.localClippingEnabled=!0,this._automaticNearFarPlane=void 0===e.automaticCameraNearFar||e.automaticCameraNearFar,this._automaticControlsSensitivity=void 0===e.automaticControlsSensitivity||e.automaticControlsSensitivity,this.canvas.style.width="640px",this.canvas.style.height="480px",this.canvas.style.minWidth="100%",this.canvas.style.minHeight="100%",this.canvas.style.maxWidth="100%",this.canvas.style.maxHeight="100%",this._domElement=e.domElement||function(){const e=document.createElementNS("http://www.w3.org/1999/xhtml","div");return e.style.width="100%",e.style.height="100%",e}(),this._domElement.appendChild(this.canvas),this.spinner=new W(this.domElement),this.spinner.placement=null!==(n=null===(t=e.loadingIndicatorStyle)||void 0===t?void 0:t.placement)&&void 0!==n?n:"topLeft",this.spinner.opacity=Math.max(.2,null!==(o=null===(r=e.loadingIndicatorStyle)||void 0===r?void 0:r.opacity)&&void 0!==o?o:1),this.camera=new y.PerspectiveCamera(60,void 0,.1,1e4),this.camera.position.x=30,this.camera.position.y=10,this.camera.position.z=50,this.camera.lookAt(new y.Vector3),this.scene=new y.Scene,this.scene.autoUpdate=!1,this.controls=new mn(this.camera,this.canvas),this.controls.dollyFactor=.992,this.controls.minDistance=1,this.controls.maxDistance=100,this.controls.addEventListener("cameraChange",e=>{const{position:t,target:n}=e.camera;this._events.cameraChange.fire(t.clone(),n.clone())});const d=function(e){var t;const n={internal:{}};n.internal={sectorCuller:e._sectorCuller};const{antiAliasing:r,multiSampleCount:o}=function(e){switch(e=e||"fxaa"){case"disabled":return{antiAliasing:g.NoAA,multiSampleCount:1};case"fxaa":return{antiAliasing:g.FXAA,multiSampleCount:1};case"msaa2":return{antiAliasing:g.NoAA,multiSampleCount:2};case"msaa4":return{antiAliasing:g.NoAA,multiSampleCount:4};case"msaa8":return{antiAliasing:g.NoAA,multiSampleCount:8};case"msaa16":return{antiAliasing:g.NoAA,multiSampleCount:16};case"msaa2+fxaa":return{antiAliasing:g.FXAA,multiSampleCount:2};case"msaa4+fxaa":return{antiAliasing:g.FXAA,multiSampleCount:4};case"msaa8+fxaa":return{antiAliasing:g.FXAA,multiSampleCount:8};case"msaa16+fxaa":return{antiAliasing:g.FXAA,multiSampleCount:16};default:Object(a.k)(e,"Unsupported anti-aliasing mode: "+e)}}(e.antiAliasingHint),i=function(e){const t={...I.ssaoRenderParameters};switch(e){case void 0:break;case"medium":t.sampleSize=b.Medium;break;case"high":t.sampleSize=b.High;break;case"veryhigh":t.sampleSize=b.VeryHigh;break;case"disabled":t.sampleSize=b.None;break;default:Object(a.k)(e,`Unexpected SSAO quality mode: '${e}'`)}return t}
400
+ */const yn={mouseWheelAction:"zoomPastCursor",onClickTargetChange:!1};class _n{constructor(e){var t,n,r,o,i,s,d,l;this._subscription=new M.Subscription,this._boundAnimate=this.animate.bind(this),this._onClick=void 0,this._onWheel=void 0,this._events={cameraChange:new a.d,click:new a.d,hover:new a.d,sceneRendered:new a.d,disposed:new a.d},this._cameraControlsOptions={...yn},this._models=[],this._extraObjects=[],this._animationDuration=600,this._minDefaultAnimationDuration=600,this._maxDefaultAnimationDuration=2500,this._minDistanceDefault=.1,this.raycaster=new y.Raycaster,this.isDisposed=!1,this.latestRequestId=-1,this.clock=new y.Clock,this._clippingNeedsUpdate=!1,this._updateNearAndFarPlaneBuffers={combinedBbox:new y.Box3,bbox:new y.Box3,cameraPosition:new y.Vector3,cameraDirection:new y.Vector3,nearPlaneCoplanarPoint:new y.Vector3,nearPlane:new y.Plane,corners:new Array(new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3)},this.startPointerEventListeners=()=>{const e=this.canvas;let t=!1,n=0,r=!1;const o=v()(t=>{this._events.hover.fire(Object(a.l)(t,e))},100),i=n=>{const{offsetX:o,offsetY:i}=Object(a.l)(n,e),{offsetX:s,offsetY:d}=Object(a.l)(n,e);t&&r&&Math.abs(o-s)+Math.abs(i-d)>4&&(r=!1)},s=d=>{const l=d.timeStamp-n;t&&r&&l<250&&this._events.click.fire(Object(a.l)(d,e)),t=!1,r=!1,e.removeEventListener("mousemove",i),e.removeEventListener("touchmove",i),e.removeEventListener("mouseup",s),e.removeEventListener("touchend",s),e.addEventListener("mousemove",o)},d=a=>{event=a,t=!0,r=!0,n=a.timeStamp,e.addEventListener("mousemove",i),e.addEventListener("touchmove",i),e.addEventListener("mouseup",s),e.addEventListener("touchend",s),e.removeEventListener("mousemove",o)};e.addEventListener("mousedown",d),e.addEventListener("touchstart",d),e.addEventListener("mousemove",o)},this._renderer=e.renderer||new y.WebGLRenderer,this._renderer.localClippingEnabled=!0,this._automaticNearFarPlane=null===(t=e.automaticCameraNearFar)||void 0===t||t,this._automaticControlsSensitivity=null!==(n=e.automaticControlsSensitivity)&&void 0!==n&&n,this.canvas.style.width="640px",this.canvas.style.height="480px",this.canvas.style.minWidth="100%",this.canvas.style.minHeight="100%",this.canvas.style.maxWidth="100%",this.canvas.style.maxHeight="100%",this._domElement=e.domElement||function(){const e=document.createElementNS("http://www.w3.org/1999/xhtml","div");return e.style.width="100%",e.style.height="100%",e}(),this._domElement.appendChild(this.canvas),this.spinner=new W(this.domElement),this.spinner.placement=null!==(o=null===(r=e.loadingIndicatorStyle)||void 0===r?void 0:r.placement)&&void 0!==o?o:"topLeft",this.spinner.opacity=Math.max(.2,null!==(s=null===(i=e.loadingIndicatorStyle)||void 0===i?void 0:i.opacity)&&void 0!==s?s:1),this.camera=new y.PerspectiveCamera(60,void 0,.1,1e4),this.camera.position.x=30,this.camera.position.y=10,this.camera.position.z=50,this.camera.lookAt(new y.Vector3),this.scene=new y.Scene,this.scene.autoUpdate=!1,this.controls=new mn(this.camera,this.canvas),this.controls.dollyFactor=.992,this.controls.minDistance=.15,this.controls.maxDistance=100,this.setCameraControlsOptions(this._cameraControlsOptions),this.controls.addEventListener("cameraChange",e=>{const{position:t,target:n}=e.camera;this._events.cameraChange.fire(t.clone(),n.clone())});const c=function(e){var t;const n={internal:{}};n.internal={sectorCuller:e._sectorCuller};const{antiAliasing:r,multiSampleCount:o}=function(e){switch(e=e||"fxaa"){case"disabled":return{antiAliasing:x.NoAA,multiSampleCount:1};case"fxaa":return{antiAliasing:x.FXAA,multiSampleCount:1};case"msaa2":return{antiAliasing:x.NoAA,multiSampleCount:2};case"msaa4":return{antiAliasing:x.NoAA,multiSampleCount:4};case"msaa8":return{antiAliasing:x.NoAA,multiSampleCount:8};case"msaa16":return{antiAliasing:x.NoAA,multiSampleCount:16};case"msaa2+fxaa":return{antiAliasing:x.FXAA,multiSampleCount:2};case"msaa4+fxaa":return{antiAliasing:x.FXAA,multiSampleCount:4};case"msaa8+fxaa":return{antiAliasing:x.FXAA,multiSampleCount:8};case"msaa16+fxaa":return{antiAliasing:x.FXAA,multiSampleCount:16};default:Object(a.k)(e,"Unsupported anti-aliasing mode: "+e)}}(e.antiAliasingHint),i=function(e){const t={...I.ssaoRenderParameters};switch(e){case void 0:break;case"medium":t.sampleSize=b.Medium;break;case"high":t.sampleSize=b.High;break;case"veryhigh":t.sampleSize=b.VeryHigh;break;case"disabled":t.sampleSize=b.None;break;default:Object(a.k)(e,`Unexpected SSAO quality mode: '${e}'`)}return t}
401
401
  /*!
402
402
  * Copyright 2021 Cognite AS
403
403
  */
@@ -412,5 +412,5 @@ class Qt{constructor(e,t,n,r){var o,i;this._lastFrameSceneState={hasBackElements
412
412
  */
413
413
  /*!
414
414
  * Copyright 2021 Cognite AS
415
- */(e.ssaoQualityHint),s={enabled:null!==(t=e.enableEdges)&&void 0!==t?t:I.edgeDetectionParameters.enabled};return n.logMetrics=e.logMetrics,n.renderOptions={antiAliasing:r,multiSampleCountHint:o,ssaoRenderParameters:i,edgeDetectionParameters:s},n}(e);!0===e._localModels?(this._dataSource=new bn,this._cdfSdkClient=void 0,this._revealManagerHelper=on.createLocalHelper(this._renderer,this.scene,d)):void 0!==e.customDataSource?(this._dataSource=e.customDataSource,this._revealManagerHelper=on.createCustomDataSourceHelper(this._renderer,this.scene,d,e.customDataSource)):(this._dataSource=new gn(e.sdk),this._cdfSdkClient=e.sdk,this._revealManagerHelper=on.createCdfHelper(this._renderer,this.scene,d,e.sdk)),this.renderController=new B(this.camera),this.startPointerEventListeners(),this.revealManager.setRenderTarget((null===(i=e.renderTargetOptions)||void 0===i?void 0:i.target)||null,null===(s=e.renderTargetOptions)||void 0===s?void 0:s.autoSetSize),this._subscription.add(Object(M.fromEventPattern)(e=>this.revealManager.on("loadingStateChanged",e),e=>this.revealManager.off("loadingStateChanged",e)).subscribe(t=>{this.spinner.loading=t.itemsLoaded!=t.itemsRequested,e.onLoading&&e.onLoading(t.itemsLoaded,t.itemsRequested,t.itemsCulled)},e=>P.a.trackError(e,{moduleName:"Cognite3DViewer",methodName:"constructor"}))),this.animate(0),P.a.trackEvent("construct3dViewer",{constructorOptions:C()(e,["sdk","domElement","renderer","renderTargetOptions","onLoading","_sectorCuller"])})}get canvas(){return this.renderer.domElement}static isBrowserSupported(){return!0}get domElement(){return this._domElement}get renderer(){return this._renderer}get revealManager(){return this._revealManagerHelper.revealManager}get cadBudget(){return this.revealManager.cadBudget}set cadBudget(e){this.revealManager.cadBudget=e}get pointCloudBudget(){return this.revealManager.pointCloudBudget}set pointCloudBudget(e){this.revealManager.pointCloudBudget=e}get models(){return this._models.slice()}get cadLoadedStatistics(){return this.revealManager.cadLoadedStatistics}getVersion(){return"2.2.1"}setLogLevel(e){switch(e){case"none":this.setLogLevel("silent");break;default:Ue.a.setLevel(e)}}dispose(){if(!this.isDisposed){this.isDisposed=!0,void 0!==this.latestRequestId&&cancelAnimationFrame(this.latestRequestId),this._subscription.unsubscribe(),this.revealManager.dispose(),this.domElement.removeChild(this.canvas),this.renderer.dispose();for(const e of this._models.values())e.dispose();this._models.splice(0),this.spinner.dispose(),this._events.disposed.fire()}}on(e,t){switch(e){case"click":this._events.click.subscribe(t);break;case"hover":this._events.hover.subscribe(t);break;case"cameraChange":this._events.cameraChange.subscribe(t);break;case"sceneRendered":this._events.sceneRendered.subscribe(t);break;case"disposed":this._events.disposed.subscribe(t);break;default:Object(a.k)(e)}}off(e,t){switch(e){case"click":this._events.click.unsubscribe(t);break;case"hover":this._events.hover.unsubscribe(t);break;case"cameraChange":this._events.cameraChange.unsubscribe(t);break;case"sceneRendered":this._events.sceneRendered.unsubscribe(t);break;case"disposed":this._events.disposed.unsubscribe(t);break;default:Object(a.k)(e)}}getViewState(){return this.createViewStateHelper().getCurrentState()}setViewState(e){const t=this.createViewStateHelper();return this.models.filter(e=>e instanceof U).map(e=>e).forEach(e=>e.removeAllStyledNodeCollections()),t.setState(e)}async addModel(e){if(void 0!==e.localPath)throw new Error("addModel() only supports CDF hosted models. Use addCadModel() and addPointCloudModel() to use self-hosted models");switch(await this.determineModelType(e.modelId,e.revisionId)){case"cad":return this.addCadModel(e);case"pointcloud":return this.addPointCloudModel(e);default:throw new Error("Model is not supported")}}async addCadModel(e){const t=this._dataSource.getNodesApiClient(),{modelId:n,revisionId:r}=e,o=await this._revealManagerHelper.addCadModel(e),i=new U(n,r,o,t);return this._models.push(i),this.scene.add(i),i}async addPointCloudModel(e){if(e.localPath)throw new F("localPath is not supported");if(e.geometryFilter)throw new F("geometryFilter is not supported for point clouds");const{modelId:t,revisionId:n}=e,r=await this._revealManagerHelper.addPointCloudModel(e),o=new j(t,n,r);return this._models.push(o),this.scene.add(o),o}removeModel(e){const t=this._models.indexOf(e);if(-1===t)throw new Error("Model is not added to viewer");switch(this._models.splice(t,1),this.scene.remove(e),this.renderController.redraw(),e.type){case"cad":const t=e;return void this.revealManager.removeModel(e.type,t.cadNode);case"pointcloud":const n=e;return void this.revealManager.removeModel(e.type,n.pointCloudNode);default:Object(a.k)(e.type,`Model type ${e.type} cannot be removed`)}}async determineModelType(e,t){if(void 0===this._cdfSdkClient)throw new Error(this.determineModelType.name+"() is only supported when connecting to Cognite Data Fusion");const n=new tn.b(e,t,tn.e.AnyFormat),r=new tn.d(this._cdfSdkClient),o=await r.getOutputs(n);return void 0!==o.findMostRecentOutput(tn.e.RevealCadModel)?"cad":void 0!==o.findMostRecentOutput(tn.e.EptPointCloud)?"pointcloud":""}addObject3D(e){this.isDisposed||(this.scene.add(e),e.updateMatrixWorld(!0),this._extraObjects.push(e),this.renderController.redraw(),this.updateCameraNearAndFar(this.camera))}removeObject3D(e){if(this.isDisposed)return;this.scene.remove(e);const t=this._extraObjects.indexOf(e);t>=0&&this._extraObjects.splice(t,1),this.renderController.redraw(),this.updateCameraNearAndFar(this.camera)}addUiObject(e,t,n){this.isDisposed||this.revealManager.addUiObject(e,t,n)}removeUiObject(e){this.isDisposed||this.revealManager.removeUiObject(e)}setBackgroundColor(e){this.isDisposed||(this.renderer.setClearColor(e),this.spinner.updateBackgroundColor(e),this.requestRedraw())}setClippingPlanes(e){this.revealManager.clippingPlanes=e,this._clippingNeedsUpdate=!0}setSlicingPlanes(e){this.setClippingPlanes(e)}getClippingPlanes(){return this.revealManager.clippingPlanes}getCamera(){return this.camera}getScene(){return this.scene}getCameraPosition(){return this.isDisposed?new y.Vector3(-1/0,-1/0,-1/0):this.controls.getState().position.clone()}getCameraTarget(){return this.isDisposed?new y.Vector3(-1/0,-1/0,-1/0):this.controls.getState().target.clone()}setCameraPosition(e){this.isDisposed||this.controls.setState(e,this.getCameraTarget())}setCameraTarget(e){this.isDisposed||this.controls.setState(this.getCameraPosition(),e)}get cameraControls(){return this.controls}get cameraControlsEnabled(){return this.controls.enabled}set cameraControlsEnabled(e){this.controls.enabled=e}loadCameraFromModel(e){const t=e.getCameraConfiguration();t?this.controls.setState(t.position,t.target):this.fitCameraToModel(e,0)}fitCameraToModel(e,t){const n=e.getModelBoundingBox(new y.Box3,!0);this.fitCameraToBoundingBox(n,t)}fitCameraToBoundingBox(e,t,n=2){const r=(new y.Vector3).lerpVectors(e.min,e.max,.5),o=.5*(new y.Vector3).subVectors(e.max,e.min).length(),i=new y.Sphere(r,o),a=i.center,s=i.radius*n,d=new y.Vector3(0,0,-1);d.applyQuaternion(this.camera.quaternion);const l=new y.Vector3;l.copy(d).multiplyScalar(-s).add(a),this.moveCameraTo(l,a,t)}requestRedraw(){this.revealManager.requestRedraw()}enableKeyboardNavigation(){this.controls.enableKeyboardNavigation=!0}disableKeyboardNavigation(){this.controls.enableKeyboardNavigation=!1}worldToScreen(e,t){this.camera.updateMatrixWorld();const n=new y.Vector3;return t?Object(N.a)(this.camera,e,n):Object(N.b)(this.renderer,this.camera,e,n),n.x<0||n.x>1||n.y<0||n.y>1||n.z<0||n.z>1?null:new y.Vector2(n.x,n.y)}async getScreenshot(e=this.canvas.width,t=this.canvas.height){if(this.isDisposed)throw new Error("Viewer is disposed");const{width:n,height:r}=this.canvas,o=this.camera.clone();_n(o,e,t),this.renderer.setSize(e,t),this.renderer.render(this.scene,o),this.revealManager.render(o);const i=this.renderer.domElement.toDataURL();return this.renderer.setSize(n,r),this.renderer.render(this.scene,this.camera),this.requestRedraw(),i}async getIntersectionFromPixel(e,t,n){const r=this.getModels("cad"),o=this.getModels("pointcloud"),i=r.map(e=>e.cadNode),a=o.map(e=>e.pointCloudNode),s={normalizedCoords:{x:e/this.renderer.domElement.clientWidth*2-1,y:t/this.renderer.domElement.clientHeight*-2+1},camera:this.camera,renderer:this.renderer,clippingPlanes:this.getClippingPlanes(),domElement:this.renderer.domElement},d=function(e,t){const n=[];for(const r of e){const e=A(r,t);e&&n.push(e)}return n.sort((e,t)=>e.distance-t.distance)}(i,s),l=X(a,s,null==n?void 0:n.pointIntersectionThreshold),c=[];if(l.length>0){const e=l[0];for(const t of o)if(t.pointCloudNode===e.pointCloudNode){const n={type:"pointcloud",model:t,point:e.point,pointIndex:e.pointIndex,distanceToCamera:e.distance};c.push(n);break}}if(d.length>0){const e=d[0];for(const t of r)if(t.cadNode===e.cadNode){const n={type:"cad",model:t,treeIndex:e.treeIndex,point:e.point,distanceToCamera:e.distance};c.push(n)}}return c.sort((e,t)=>e.distanceToCamera-t.distanceToCamera),c.length>0?c[0]:null}getModels(e){return this._models.filter(t=>t.type===e)}moveCameraTo(e,t,n){if(this.isDisposed)return;const{camera:r}=this;if(null==n){n=125*e.distanceTo(r.position),n=Math.min(Math.max(n,600),2500)}const o=new y.Raycaster;o.setFromCamera(new y.Vector2(0,0),r);const i=t.distanceTo(r.position),a=o.ray.direction.clone().multiplyScalar(i),s=o.ray.origin.clone().add(a),d={x:r.position.x,y:r.position.y,z:r.position.z,targetX:s.x,targetY:s.y,targetZ:s.z},l={x:e.x,y:e.y,z:e.z,targetX:t.x,targetY:t.y,targetZ:t.z},c=new T.a.Tween(d),u=e=>{if(this.isDisposed)return document.removeEventListener("keydown",u),void c.stop();("keydown"!==e.type||this.controls.enableKeyboardNavigation)&&(c.stop(),this.canvas.removeEventListener("pointerdown",u),this.canvas.removeEventListener("wheel",u),document.removeEventListener("keydown",u))};this.canvas.addEventListener("pointerdown",u),this.canvas.addEventListener("wheel",u),document.addEventListener("keydown",u);const p=new y.Vector3,m=new y.Vector3;c.to(l,n).easing(e=>T.a.Easing.Circular.Out(e)).onUpdate(()=>{this.isDisposed||(m.set(d.x,d.y,d.z),p.set(d.targetX,d.targetY,d.targetZ),this.camera&&(this.setCameraPosition(m),this.setCameraTarget(p)))}).onComplete(()=>{this.isDisposed||this.canvas.removeEventListener("pointerdown",u)}).start(T.a.now()).update(T.a.now())}createViewStateHelper(){if(void 0===this._cdfSdkClient)throw new Error(this.setViewState.name+"() is only supported when connecting to Cognite Data Fusion");return new de(this,this._cdfSdkClient)}async animate(e){if(this.isDisposed)return;this.latestRequestId=requestAnimationFrame(this._boundAnimate);const{display:t,visibility:n}=window.getComputedStyle(this.canvas);if("visible"===n&&"none"!==t){const{renderController:t}=this;T.a.update(e);if(this.resizeIfNecessary()&&this.requestRedraw(),this.controls.update(this.clock.getDelta()),t.update(),this.revealManager.update(this.camera),t.needsRedraw||this.revealManager.needsRedraw||this._clippingNeedsUpdate){const e=this.renderer.info.render.frame,n=Date.now();this.updateCameraNearAndFar(this.camera),this.revealManager.render(this.camera),t.clearNeedsRedraw(),this.revealManager.resetRedraw(),this._clippingNeedsUpdate=!1;const r=Date.now()-n;this._events.sceneRendered.fire({frameNumber:e,renderTime:r,renderer:this.renderer,camera:this.camera})}}}updateCameraNearAndFar(e){if(this.isDisposed)return;if(!this._automaticControlsSensitivity&&!this._automaticNearFarPlane)return;const{combinedBbox:t,bbox:n,cameraPosition:r,cameraDirection:o,corners:i,nearPlane:a,nearPlaneCoplanarPoint:s}=this._updateNearAndFarPlaneBuffers;t.makeEmpty(),this._models.forEach(e=>{e.getModelBoundingBox(n),n.isEmpty()||(t.expandByPoint(n.min),t.expandByPoint(n.max))}),this._extraObjects.forEach(e=>{n.setFromObject(e),n.isEmpty()||(t.expandByPoint(n.min),t.expandByPoint(n.max))}),function(e,t){if(8!==(t=t||[new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3]).length)throw new Error(`outBuffer must hold exactly 8 elements, but holds ${t.length} elemnents`);const n=e.min,r=e.max;t[0].set(n.x,n.y,n.z),t[1].set(r.x,n.y,n.z),t[2].set(n.x,r.y,n.z),t[3].set(n.x,n.y,r.z),t[4].set(r.x,r.y,n.z),t[5].set(r.x,r.y,r.z),t[6].set(r.x,n.y,r.z),t[7].set(n.x,r.y,r.z)}(t,i),e.getWorldPosition(r),e.getWorldDirection(o);let d=t.distanceToPoint(r);d/=Math.sqrt(1+Math.tan(e.fov/180*Math.PI/2)**2*(e.aspect**2+1)),d=Math.max(.1,d),s.copy(r).addScaledVector(o,d),a.setFromNormalAndCoplanarPoint(o,s);let l=-1/0;for(let e=0;e<8;++e)if(a.distanceToPoint(i[e])>=0){const t=i[e].distanceTo(r);l=Math.max(l,t)}l=Math.max(2*d,l);const c=t.min.distanceTo(t.max);t.containsPoint(r)&&(d=Math.min(.1,l/1e3)),this._automaticNearFarPlane&&(e.near=d,e.far=l,e.updateProjectionMatrix()),this._automaticControlsSensitivity&&(this.controls.minDistance=Math.min(Math.max(.02*c,.1*d),10))}resizeIfNecessary(){if(this.isDisposed)return!1;const e=this.renderer.getSize(new y.Vector2),t=e.width,n=e.height,r=0!==this.domElement.clientWidth?this.domElement.clientWidth:this.canvas.clientWidth,o=0!==this.domElement.clientHeight?this.domElement.clientHeight:this.canvas.clientHeight,i=this.renderer.getPixelRatio()*r,a=this.renderer.getPixelRatio()*o,s=i*a,d=s>14e5?Math.sqrt(14e5/s):1,l=i*d,c=a*d;return!(Math.abs(t-l)<.1&&Math.abs(n-c)<.1)&&(this.renderer.setSize(l,c),_n(this.camera,l,c),this.camera instanceof y.OrthographicCamera&&(this.controls.orthographicCameraDollyFactor=20/l,this.controls.keyboardDollySpeed=2/l),!0)}}function _n(e,t,n){e instanceof y.PerspectiveCamera?(e.aspect=t/n,e.updateProjectionMatrix()):e instanceof y.OrthographicCamera&&(e.left=-t,e.right=t,e.top=n,e.bottom=-n)}}])}));
415
+ */(e.ssaoQualityHint),s={enabled:null!==(t=e.enableEdges)&&void 0!==t?t:I.edgeDetectionParameters.enabled};return n.logMetrics=e.logMetrics,n.renderOptions={antiAliasing:r,multiSampleCountHint:o,ssaoRenderParameters:i,edgeDetectionParameters:s},n}(e);!0===e._localModels?(this._dataSource=new bn,this._cdfSdkClient=void 0,this._revealManagerHelper=on.createLocalHelper(this._renderer,this.scene,c)):void 0!==e.customDataSource?(this._dataSource=e.customDataSource,this._revealManagerHelper=on.createCustomDataSourceHelper(this._renderer,this.scene,c,e.customDataSource)):(this._dataSource=new xn(e.sdk),this._cdfSdkClient=e.sdk,this._revealManagerHelper=on.createCdfHelper(this._renderer,this.scene,c,e.sdk)),this.renderController=new B(this.camera),this.startPointerEventListeners(),this.revealManager.setRenderTarget((null===(d=e.renderTargetOptions)||void 0===d?void 0:d.target)||null,null===(l=e.renderTargetOptions)||void 0===l?void 0:l.autoSetSize),this._subscription.add(Object(M.fromEventPattern)(e=>this.revealManager.on("loadingStateChanged",e),e=>this.revealManager.off("loadingStateChanged",e)).subscribe(t=>{this.spinner.loading=t.itemsLoaded!=t.itemsRequested,e.onLoading&&e.onLoading(t.itemsLoaded,t.itemsRequested,t.itemsCulled)},e=>N.a.trackError(e,{moduleName:"Cognite3DViewer",methodName:"constructor"}))),this.animate(0),N.a.trackEvent("construct3dViewer",{constructorOptions:C()(e,["sdk","domElement","renderer","renderTargetOptions","onLoading","_sectorCuller"])})}get canvas(){return this.renderer.domElement}static isBrowserSupported(){return!0}get domElement(){return this._domElement}get renderer(){return this._renderer}get revealManager(){return this._revealManagerHelper.revealManager}convertPixelCoordinatesToNormalized(e,t){return{x:e/this._domElement.clientWidth*2-1,y:t/this._domElement.clientHeight*-2+1}}calculateMissedRaycast(e){const t=this._models[0].getModelBoundingBox(new y.Box3),n=t.min.distanceTo(t.max);this.raycaster.setFromCamera(e,this.camera);return this.raycaster.ray.direction.clone().normalize().multiplyScalar(Math.max(this.camera.position.distanceTo(t.getCenter(new y.Vector3)),n)).add(this.camera.position)}teardownControls(){void 0!==this._onClick&&(this.off("click",this._onClick),this._onClick=void 0),void 0!==this._onWheel&&(this._domElement.removeEventListener("wheel",this._onWheel),this._onWheel=void 0)}setupControls(){let e=!1;const t=new y.Clock,n=e=>{this.controls.enableKeyboardNavigation=!1,this.changeTarget(e)},r=async n=>{const r=t.getDelta();e&&n.deltaY<0?(e=!1,this.changeScrollTarget(n)):r>.1&&(e=!0)};switch(this._cameraControlsOptions.mouseWheelAction){case"zoomToTarget":this.controls.zoomToCursor=!1;break;case"zoomPastCursor":this.controls.useScrollTarget=!1,this.controls.zoomToCursor=!0;break;case"zoomToCursor":this.controls.setScrollTarget(this.controls.getState().target),this.controls.useScrollTarget=!0,this.controls.zoomToCursor=!0;break;default:Object(a.k)(this._cameraControlsOptions.mouseWheelAction)}this._cameraControlsOptions.onClickTargetChange&&(this.on("click",n),this._onClick=n),"zoomToCursor"===this._cameraControlsOptions.mouseWheelAction&&(this._domElement.addEventListener("wheel",r),this._onWheel=r)}async changeTarget(e){var t;const{offsetX:n,offsetY:r}=e,{x:o,y:i}=this.convertPixelCoordinatesToNormalized(n,r),a=await this.getIntersectionFromPixel(n,r),s=null!==(t=null==a?void 0:a.point)&&void 0!==t?t:this.calculateMissedRaycast({x:o,y:i});this.setCameraTarget(s,!0)}async changeScrollTarget(e){var t;const{offsetX:n,offsetY:r}=e,{x:o,y:i}=this.convertPixelCoordinatesToNormalized(n,r),a=await this.getIntersectionFromPixel(n,r),s=null!==(t=null==a?void 0:a.point)&&void 0!==t?t:this.calculateMissedRaycast({x:o,y:i});this.controls.setScrollTarget(s)}get cadBudget(){return this.revealManager.cadBudget}set cadBudget(e){this.revealManager.cadBudget=e}get pointCloudBudget(){return this.revealManager.pointCloudBudget}set pointCloudBudget(e){this.revealManager.pointCloudBudget=e}get models(){return this._models.slice()}get cadLoadedStatistics(){return this.revealManager.cadLoadedStatistics}getVersion(){return"2.2.2"}setLogLevel(e){switch(e){case"none":this.setLogLevel("silent");break;default:Ue.a.setLevel(e)}}dispose(){if(!this.isDisposed){this.isDisposed=!0,void 0!==this.latestRequestId&&cancelAnimationFrame(this.latestRequestId),this._subscription.unsubscribe(),this.revealManager.dispose(),this.domElement.removeChild(this.canvas),this.renderer.dispose();for(const e of this._models.values())e.dispose();this._models.splice(0),this.spinner.dispose(),this._events.disposed.fire()}}on(e,t){switch(e){case"click":this._events.click.subscribe(t);break;case"hover":this._events.hover.subscribe(t);break;case"cameraChange":this._events.cameraChange.subscribe(t);break;case"sceneRendered":this._events.sceneRendered.subscribe(t);break;case"disposed":this._events.disposed.subscribe(t);break;default:Object(a.k)(e)}}off(e,t){switch(e){case"click":this._events.click.unsubscribe(t);break;case"hover":this._events.hover.unsubscribe(t);break;case"cameraChange":this._events.cameraChange.unsubscribe(t);break;case"sceneRendered":this._events.sceneRendered.unsubscribe(t);break;case"disposed":this._events.disposed.unsubscribe(t);break;default:Object(a.k)(e)}}setCameraControlsOptions(e){this._cameraControlsOptions={...yn,...e},this.teardownControls(),this.setupControls()}getCameraControlsOptions(){return this._cameraControlsOptions}getViewState(){return this.createViewStateHelper().getCurrentState()}setViewState(e){const t=this.createViewStateHelper();return this.models.filter(e=>e instanceof U).map(e=>e).forEach(e=>e.removeAllStyledNodeCollections()),t.setState(e)}async addModel(e){if(void 0!==e.localPath)throw new Error("addModel() only supports CDF hosted models. Use addCadModel() and addPointCloudModel() to use self-hosted models");switch(await this.determineModelType(e.modelId,e.revisionId)){case"cad":return this.addCadModel(e);case"pointcloud":return this.addPointCloudModel(e);default:throw new Error("Model is not supported")}}async addCadModel(e){const t=this._dataSource.getNodesApiClient(),{modelId:n,revisionId:r}=e,o=await this._revealManagerHelper.addCadModel(e),i=new U(n,r,o,t);return this._models.push(i),this.scene.add(i),i}async addPointCloudModel(e){if(e.localPath)throw new F("localPath is not supported");if(e.geometryFilter)throw new F("geometryFilter is not supported for point clouds");const{modelId:t,revisionId:n}=e,r=await this._revealManagerHelper.addPointCloudModel(e),o=new j(t,n,r);return this._models.push(o),this.scene.add(o),o}removeModel(e){const t=this._models.indexOf(e);if(-1===t)throw new Error("Model is not added to viewer");switch(this._models.splice(t,1),this.scene.remove(e),this.renderController.redraw(),e.type){case"cad":const t=e;return void this.revealManager.removeModel(e.type,t.cadNode);case"pointcloud":const n=e;return void this.revealManager.removeModel(e.type,n.pointCloudNode);default:Object(a.k)(e.type,`Model type ${e.type} cannot be removed`)}}async determineModelType(e,t){if(void 0===this._cdfSdkClient)throw new Error(this.determineModelType.name+"() is only supported when connecting to Cognite Data Fusion");const n=new tn.b(e,t,tn.e.AnyFormat),r=new tn.d(this._cdfSdkClient),o=await r.getOutputs(n);return void 0!==o.findMostRecentOutput(tn.e.RevealCadModel)?"cad":void 0!==o.findMostRecentOutput(tn.e.EptPointCloud)?"pointcloud":""}addObject3D(e){this.isDisposed||(this.scene.add(e),e.updateMatrixWorld(!0),this._extraObjects.push(e),this.renderController.redraw(),this.updateCameraNearAndFar(this.camera))}removeObject3D(e){if(this.isDisposed)return;this.scene.remove(e);const t=this._extraObjects.indexOf(e);t>=0&&this._extraObjects.splice(t,1),this.renderController.redraw(),this.updateCameraNearAndFar(this.camera)}addUiObject(e,t,n){this.isDisposed||this.revealManager.addUiObject(e,t,n)}removeUiObject(e){this.isDisposed||this.revealManager.removeUiObject(e)}setBackgroundColor(e){this.isDisposed||(this.renderer.setClearColor(e),this.spinner.updateBackgroundColor(e),this.requestRedraw())}setClippingPlanes(e){this.revealManager.clippingPlanes=e,this._clippingNeedsUpdate=!0}setSlicingPlanes(e){this.setClippingPlanes(e)}getClippingPlanes(){return this.revealManager.clippingPlanes}getCamera(){return this.camera}getScene(){return this.scene}getCameraPosition(){return this.isDisposed?new y.Vector3(-1/0,-1/0,-1/0):this.controls.getState().position.clone()}getCameraTarget(){return this.isDisposed?new y.Vector3(-1/0,-1/0,-1/0):this.controls.getState().target.clone()}setCameraPosition(e){this.isDisposed||this.controls.setState(e,this.getCameraTarget())}setCameraTarget(e,t=!1){if(this.isDisposed)return;const n=t?this._animationDuration:0;this.moveCameraTargetTo(e,n)}get cameraControls(){return this.controls}get cameraControlsEnabled(){return this.controls.enabled}set cameraControlsEnabled(e){this.controls.enabled=e}loadCameraFromModel(e){const t=e.getCameraConfiguration();t?this.controls.setState(t.position,t.target):this.fitCameraToModel(e,0)}fitCameraToModel(e,t){const n=e.getModelBoundingBox(new y.Box3,!0);this.fitCameraToBoundingBox(n,t)}fitCameraToBoundingBox(e,t,n=2){const r=e.getBoundingSphere(new y.Sphere),o=r.center,i=r.radius*n,a=new y.Vector3(0,0,-1);a.applyQuaternion(this.camera.quaternion);const s=new y.Vector3;s.copy(a).multiplyScalar(-i).add(o),this.moveCameraTo(s,o,t)}requestRedraw(){this.revealManager.requestRedraw()}enableKeyboardNavigation(){this.controls.enableKeyboardNavigation=!0}disableKeyboardNavigation(){this.controls.enableKeyboardNavigation=!1}worldToScreen(e,t){this.camera.updateMatrixWorld();const n=new y.Vector3;return t?Object(P.a)(this.camera,e,n):Object(P.b)(this.renderer,this.camera,e,n),n.x<0||n.x>1||n.y<0||n.y>1||n.z<0||n.z>1?null:new y.Vector2(n.x,n.y)}async getScreenshot(e=this.canvas.width,t=this.canvas.height){if(this.isDisposed)throw new Error("Viewer is disposed");const{width:n,height:r}=this.canvas,o=this.camera.clone();Tn(o,e,t),this.renderer.setSize(e,t),this.renderer.render(this.scene,o),this.revealManager.render(o);const i=this.renderer.domElement.toDataURL();return this.renderer.setSize(n,r),this.renderer.render(this.scene,this.camera),this.requestRedraw(),i}async getIntersectionFromPixel(e,t,n){const r=this.getModels("cad"),o=this.getModels("pointcloud"),i=r.map(e=>e.cadNode),a=o.map(e=>e.pointCloudNode),s={normalizedCoords:{x:e/this.renderer.domElement.clientWidth*2-1,y:t/this.renderer.domElement.clientHeight*-2+1},camera:this.camera,renderer:this.renderer,clippingPlanes:this.getClippingPlanes(),domElement:this.renderer.domElement},d=function(e,t){const n=[];for(const r of e){const e=A(r,t);e&&n.push(e)}return n.sort((e,t)=>e.distance-t.distance)}(i,s),l=X(a,s,null==n?void 0:n.pointIntersectionThreshold),c=[];if(l.length>0){const e=l[0];for(const t of o)if(t.pointCloudNode===e.pointCloudNode){const n={type:"pointcloud",model:t,point:e.point,pointIndex:e.pointIndex,distanceToCamera:e.distance};c.push(n);break}}if(d.length>0){const e=d[0];for(const t of r)if(t.cadNode===e.cadNode){const n={type:"cad",model:t,treeIndex:e.treeIndex,point:e.point,distanceToCamera:e.distance};c.push(n)}}return c.sort((e,t)=>e.distanceToCamera-t.distanceToCamera),c.length>0?c[0]:null}getModels(e){return this._models.filter(t=>t.type===e)}calculateDefaultDuration(e){let t=125*e;return t=Math.min(Math.max(t,this._minDefaultAnimationDuration),this._maxDefaultAnimationDuration),t}moveCameraTargetTo(e,t){if(this.isDisposed)return;if(0===t)return void this.controls.setState(this.getCameraPosition(),e);const{camera:n,raycaster:r}=this;t=null!=t?t:this.calculateDefaultDuration(e.distanceTo(n.position)),r.setFromCamera(new y.Vector2,n);const o=e.distanceTo(n.position),i=r.ray.direction.clone().multiplyScalar(o),a=r.ray.origin.clone().add(i),s={targetX:a.x,targetY:a.y,targetZ:a.z},d={targetX:e.x,targetY:e.y,targetZ:e.z},l=new T.a.Tween(s),c=e=>{if(this.isDisposed)return document.removeEventListener("keydown",c),void l.stop();this.controls.lookAtViewTarget=!1,("keydown"!==e.type||this.controls.enableKeyboardNavigation)&&(l.stop(),this.canvas.removeEventListener("pointerdown",c),this.canvas.removeEventListener("wheel",c),document.removeEventListener("keydown",c))};this.canvas.addEventListener("pointerdown",c),this._domElement.addEventListener("wheel",c),document.addEventListener("keydown",c);const u=new y.Vector3;l.to(d,t).easing(e=>T.a.Easing.Circular.Out(e)).onStart(()=>{this.controls.lookAtViewTarget=!0,this.controls.setState(this.camera.position,e)}).onUpdate(()=>{this.isDisposed||(u.set(s.targetX,s.targetY,s.targetZ),this.camera&&("zoomToCursor"===this._cameraControlsOptions.mouseWheelAction&&this.controls.setScrollTarget(u),this.controls.setViewTarget(u)))}).onStop(()=>{this.controls.lookAtViewTarget=!1,this.controls.setState(this.camera.position,u)}).onComplete(()=>{this.isDisposed||(this.controls.lookAtViewTarget=!1,this.controls.enableKeyboardNavigation=!0,this.controls.setState(this.camera.position,u),this._domElement.removeEventListener("pointerdown",c))}).start(T.a.now()).update(T.a.now())}moveCameraTo(e,t,n){if(this.isDisposed)return;const{camera:r,raycaster:o}=this;void 0===n&&(n=this.calculateDefaultDuration(t.distanceTo(r.position))),o.setFromCamera(new y.Vector2,r);const i=t.distanceTo(r.position),a=o.ray.direction.clone().multiplyScalar(i),s=o.ray.origin.clone().add(a),d={x:r.position.x,y:r.position.y,z:r.position.z,targetX:s.x,targetY:s.y,targetZ:s.z},l={x:e.x,y:e.y,z:e.z,targetX:t.x,targetY:t.y,targetZ:t.z},c=new T.a.Tween(d),u=e=>{if(this.isDisposed)return document.removeEventListener("keydown",u),void c.stop();("keydown"!==e.type||this.controls.enableKeyboardNavigation)&&(c.stop(),this.canvas.removeEventListener("pointerdown",u),this.canvas.removeEventListener("wheel",u),document.removeEventListener("keydown",u))};this.canvas.addEventListener("pointerdown",u),this.canvas.addEventListener("wheel",u),document.addEventListener("keydown",u);const p=new y.Vector3,m=new y.Vector3;c.to(l,n).easing(e=>T.a.Easing.Circular.Out(e)).onUpdate(()=>{this.isDisposed||(m.set(d.x,d.y,d.z),p.set(d.targetX,d.targetY,d.targetZ),this.camera&&this.controls.setState(m,p))}).onStop(()=>{this.controls.setState(m,p)}).onComplete(()=>{this.isDisposed||this.canvas.removeEventListener("pointerdown",u)}).start(T.a.now()).update(T.a.now())}createViewStateHelper(){if(void 0===this._cdfSdkClient)throw new Error(this.setViewState.name+"() is only supported when connecting to Cognite Data Fusion");return new de(this,this._cdfSdkClient)}async animate(e){if(this.isDisposed)return;this.latestRequestId=requestAnimationFrame(this._boundAnimate);const{display:t,visibility:n}=window.getComputedStyle(this.canvas);if("visible"===n&&"none"!==t){const{renderController:t}=this;T.a.update(e);if(this.resizeIfNecessary()&&this.requestRedraw(),this.controls.update(this.clock.getDelta()),t.update(),this.revealManager.update(this.camera),t.needsRedraw||this.revealManager.needsRedraw||this._clippingNeedsUpdate){const e=this.renderer.info.render.frame,n=Date.now();this.updateCameraNearAndFar(this.camera),this.revealManager.render(this.camera),t.clearNeedsRedraw(),this.revealManager.resetRedraw(),this._clippingNeedsUpdate=!1;const r=Date.now()-n;this._events.sceneRendered.fire({frameNumber:e,renderTime:r,renderer:this.renderer,camera:this.camera})}}}updateCameraNearAndFar(e){if(this.isDisposed)return;if(!this._automaticControlsSensitivity&&!this._automaticNearFarPlane)return;const{combinedBbox:t,bbox:n,cameraPosition:r,cameraDirection:o,corners:i,nearPlane:a,nearPlaneCoplanarPoint:s}=this._updateNearAndFarPlaneBuffers;t.makeEmpty(),this._models.forEach(e=>{e.getModelBoundingBox(n),n.isEmpty()||t.union(n)}),this._extraObjects.forEach(e=>{n.setFromObject(e),n.isEmpty()||t.union(n)}),function(e,t){if(8!==(t=t||[new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3,new y.Vector3]).length)throw new Error(`outBuffer must hold exactly 8 elements, but holds ${t.length} elemnents`);const n=e.min,r=e.max;t[0].set(n.x,n.y,n.z),t[1].set(r.x,n.y,n.z),t[2].set(n.x,r.y,n.z),t[3].set(n.x,n.y,r.z),t[4].set(r.x,r.y,n.z),t[5].set(r.x,r.y,r.z),t[6].set(r.x,n.y,r.z),t[7].set(n.x,r.y,r.z)}(t,i),e.getWorldPosition(r),e.getWorldDirection(o);let d=t.distanceToPoint(r);d/=Math.sqrt(1+Math.tan(e.fov/180*Math.PI/2)**2*(e.aspect**2+1)),d=Math.max(.1,d),s.copy(r).addScaledVector(o,d),a.setFromNormalAndCoplanarPoint(o,s);let l=-1/0;for(let e=0;e<8;++e)if(a.distanceToPoint(i[e])>=0){const t=i[e].distanceTo(r);l=Math.max(l,t)}l=Math.max(2*d,l);const c=t.min.distanceTo(t.max);t.containsPoint(r)&&(d=Math.min(.1,l/1e3)),this._automaticNearFarPlane&&(e.near=d,e.far=l,e.updateProjectionMatrix()),this._automaticControlsSensitivity&&(this.controls.minDistance=Math.min(Math.max(.02*c,.1*d),this._minDistanceDefault))}resizeIfNecessary(){if(this.isDisposed)return!1;const e=this.renderer.getSize(new y.Vector2),t=e.width,n=e.height,r=0!==this.domElement.clientWidth?this.domElement.clientWidth:this.canvas.clientWidth,o=0!==this.domElement.clientHeight?this.domElement.clientHeight:this.canvas.clientHeight,i=this.renderer.getPixelRatio()*r,a=this.renderer.getPixelRatio()*o,s=i*a,d=s>14e5?Math.sqrt(14e5/s):1,l=i*d,c=a*d;return!(Math.abs(t-l)<.1&&Math.abs(n-c)<.1)&&(this.renderer.setSize(l,c),Tn(this.camera,l,c),this.camera instanceof y.OrthographicCamera&&(this.controls.orthographicCameraDollyFactor=20/l,this.controls.keyboardDollySpeed=2/l),!0)}}function Tn(e,t,n){e instanceof y.PerspectiveCamera?(e.aspect=t/n,e.updateProjectionMatrix()):e instanceof y.OrthographicCamera&&(e.left=-t,e.right=t,e.top=n,e.bottom=-n)}}])}));
416
416
  //# sourceMappingURL=index.map