@xeokit/xeokit-sdk 2.6.65 → 2.6.66
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/dist/xeokit-sdk.cjs.js +155 -68
- package/dist/xeokit-sdk.es.js +155 -68
- package/dist/xeokit-sdk.es5.js +82 -58
- package/dist/xeokit-sdk.min.cjs.js +5 -5
- package/dist/xeokit-sdk.min.es.js +5 -5
- package/dist/xeokit-sdk.min.es5.js +4 -4
- package/package.json +1 -1
- package/src/extras/PointerCircle/PointerCircle.js +1 -1
- package/src/plugins/SectionPlanesPlugin/Control.js +11 -12
- package/src/viewer/scene/model/SceneModel.js +1 -0
- package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js +4 -1
- package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js +4 -1
- package/src/viewer/scene/sectionPlane/SectionPlane.js +79 -1
- package/src/viewer/scene/webgl/Renderer.js +9 -3
- package/types/extras/PointerCircle/PointerCircle.d.ts +50 -0
- package/types/extras/PointerCircle/index.d.ts +1 -0
- package/types/plugins/index.d.ts +1 -0
- package/types/plugins/lib/ui/index.d.ts +12 -0
package/dist/xeokit-sdk.es5.js
CHANGED
|
@@ -453,7 +453,7 @@ this._lensCanvas.height// destination height
|
|
|
453
453
|
*/function get(){return this._visible;}/**
|
|
454
454
|
* Destroys this PointerLens.
|
|
455
455
|
*/,set:function set(visible){this._visible=visible;this._updateActiveVisible();}},{key:"destroy",value:function destroy(){if(!this._destroyed){this.viewer.scene.off(this._onViewerRendering);this._lensContainer.removeChild(this._lensCanvas);document.body.removeChild(this._lensContainer);this._destroyed=true;}}}]);return PointerLens;}();// Some temporary vars to help avoid garbage collection
|
|
456
|
-
var doublePrecision=true;var FloatArrayType=doublePrecision?Float64Array:Float32Array;var tempVec3a$
|
|
456
|
+
var doublePrecision=true;var FloatArrayType=doublePrecision?Float64Array:Float32Array;var tempVec3a$O=new FloatArrayType(3);var tempMat1=new FloatArrayType(16);var tempMat2=new FloatArrayType(16);var tempVec4$2=new FloatArrayType(4);/**
|
|
457
457
|
* @private
|
|
458
458
|
*/var math={setDoublePrecisionEnabled:function setDoublePrecisionEnabled(enable){doublePrecision=enable;FloatArrayType=doublePrecision?Float64Array:Float32Array;},getDoublePrecisionEnabled:function getDoublePrecisionEnabled(){return doublePrecision;},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:10000000,/**
|
|
459
459
|
* The number of radiians in a degree (0.0174532925).
|
|
@@ -1457,7 +1457,7 @@ if(edge.face2!==undefined){normal1=faces[edge.face1].normal;normal2=faces[edge.f
|
|
|
1457
1457
|
* @param {number} positions Flat array of 3D positions.
|
|
1458
1458
|
* @param {number} numElementsPerPosition Number of elements perposition - usually either 3 or 4.
|
|
1459
1459
|
* @returns {boolean}
|
|
1460
|
-
*/math.planeClipsPositions3=function(pos,dir,positions){var numElementsPerPosition=arguments.length>3&&arguments[3]!==undefined?arguments[3]:3;for(var _i26=0,len=positions.length;_i26<len;_i26+=numElementsPerPosition){tempVec3a$
|
|
1460
|
+
*/math.planeClipsPositions3=function(pos,dir,positions){var numElementsPerPosition=arguments.length>3&&arguments[3]!==undefined?arguments[3]:3;for(var _i26=0,len=positions.length;_i26<len;_i26+=numElementsPerPosition){tempVec3a$O[0]=positions[_i26+0]-pos[0];tempVec3a$O[1]=positions[_i26+1]-pos[1];tempVec3a$O[2]=positions[_i26+2]-pos[2];var dotProduct=tempVec3a$O[0]*dir[0]+tempVec3a$O[1]*dir[1]+tempVec3a$O[2]*dir[2];if(dotProduct<0){return true;}}return false;};var MAX_KD_TREE_DEPTH$1=15;// Increase if greater precision needed
|
|
1461
1461
|
var kdTreeDimLength$1=new Float32Array(3);/**
|
|
1462
1462
|
* Automatically indexes a {@link Viewer}'s {@link Entity}s in a 3D k-d tree
|
|
1463
1463
|
* to support fast collision detection with 3D World-space axis-aligned boundaries (AABBs) and frustums.
|
|
@@ -1979,11 +1979,11 @@ return component;}},{key:"_checkComponent",value:function _checkComponent(expect
|
|
|
1979
1979
|
*/this.fire("destroyed",this.destroyed=true);// Must fire before we blow away subscription maps, below
|
|
1980
1980
|
// Unsubscribe from child components and destroy then
|
|
1981
1981
|
var id;var attachment;var component;var subs;var i;var len;if(this._attachments){for(id in this._attachments){if(this._attachments.hasOwnProperty(id)){attachment=this._attachments[id];component=attachment.component;subs=attachment.subs;for(i=0,len=subs.length;i<len;i++){component.off(subs[i]);}if(attachment.managingLifecycle){component.destroy();}}}}if(this._ownedComponents){for(id in this._ownedComponents){if(this._ownedComponents.hasOwnProperty(id)){component=this._ownedComponents[id];component.destroy();delete this._ownedComponents[id];}}}this.scene._removeComponent(this);// Memory leak avoidance
|
|
1982
|
-
this._attached={};this._attachments=null;this._subIdMap=null;this._subIdEvents=null;this._eventSubs=null;this._events=null;this._eventCallDepth=0;this._ownedComponents=null;this._updateScheduled=false;}}]);return Component;}();var tempVec3a$
|
|
1982
|
+
this._attached={};this._attachments=null;this._subIdMap=null;this._subIdEvents=null;this._eventSubs=null;this._events=null;this._eventCallDepth=0;this._ownedComponents=null;this._updateScheduled=false;}}]);return Component;}();var tempVec3a$N=math.vec3();var tempVec3b$B=math.vec3();var tempMat4a$s=math.mat4();/**
|
|
1983
1983
|
* @private
|
|
1984
1984
|
*/var FrustumPlane=/*#__PURE__*/function(){function FrustumPlane(){_classCallCheck(this,FrustumPlane);this.normal=math.vec3();this.offset=0;this.testVertex=math.vec3();}_createClass(FrustumPlane,[{key:"set",value:function set(nx,ny,nz,offset){var s=1.0/Math.sqrt(nx*nx+ny*ny+nz*nz);this.normal[0]=nx*s;this.normal[1]=ny*s;this.normal[2]=nz*s;this.offset=offset*s;this.testVertex[0]=this.normal[0]>=0.0?1:0;this.testVertex[1]=this.normal[1]>=0.0?1:0;this.testVertex[2]=this.normal[2]>=0.0?1:0;}}]);return FrustumPlane;}();/**
|
|
1985
1985
|
* @private
|
|
1986
|
-
*/var Frustum$1=/*#__PURE__*/_createClass(function Frustum$1(){_classCallCheck(this,Frustum$1);this.planes=[new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane()];});Frustum$1.INSIDE=0;Frustum$1.INTERSECT=1;Frustum$1.OUTSIDE=2;/** @private */function setFrustum(frustum,viewMat,projMat){var m=math.mulMat4(projMat,viewMat,tempMat4a$s);var m0=m[0];var m1=m[1];var m2=m[2];var m3=m[3];var m4=m[4];var m5=m[5];var m6=m[6];var m7=m[7];var m8=m[8];var m9=m[9];var m10=m[10];var m11=m[11];var m12=m[12];var m13=m[13];var m14=m[14];var m15=m[15];frustum.planes[0].set(m3-m0,m7-m4,m11-m8,m15-m12);frustum.planes[1].set(m3+m0,m7+m4,m11+m8,m15+m12);frustum.planes[2].set(m3-m1,m7-m5,m11-m9,m15-m13);frustum.planes[3].set(m3+m1,m7+m5,m11+m9,m15+m13);frustum.planes[4].set(m3-m2,m7-m6,m11-m10,m15-m14);frustum.planes[5].set(m3+m2,m7+m6,m11+m10,m15+m14);}/** @private */function frustumIntersectsAABB3(frustum,aabb){var ret=Frustum$1.INSIDE;var min=tempVec3a$
|
|
1986
|
+
*/var Frustum$1=/*#__PURE__*/_createClass(function Frustum$1(){_classCallCheck(this,Frustum$1);this.planes=[new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane()];});Frustum$1.INSIDE=0;Frustum$1.INTERSECT=1;Frustum$1.OUTSIDE=2;/** @private */function setFrustum(frustum,viewMat,projMat){var m=math.mulMat4(projMat,viewMat,tempMat4a$s);var m0=m[0];var m1=m[1];var m2=m[2];var m3=m[3];var m4=m[4];var m5=m[5];var m6=m[6];var m7=m[7];var m8=m[8];var m9=m[9];var m10=m[10];var m11=m[11];var m12=m[12];var m13=m[13];var m14=m[14];var m15=m[15];frustum.planes[0].set(m3-m0,m7-m4,m11-m8,m15-m12);frustum.planes[1].set(m3+m0,m7+m4,m11+m8,m15+m12);frustum.planes[2].set(m3-m1,m7-m5,m11-m9,m15-m13);frustum.planes[3].set(m3+m1,m7+m5,m11+m9,m15+m13);frustum.planes[4].set(m3-m2,m7-m6,m11-m10,m15-m14);frustum.planes[5].set(m3+m2,m7+m6,m11+m10,m15+m14);}/** @private */function frustumIntersectsAABB3(frustum,aabb){var ret=Frustum$1.INSIDE;var min=tempVec3a$N;var max=tempVec3b$B;min[0]=aabb[0];min[1]=aabb[1];min[2]=aabb[2];max[0]=aabb[3];max[1]=aabb[4];max[2]=aabb[5];var bminmax=[min,max];for(var _i27=0;_i27<6;++_i27){var plane=frustum.planes[_i27];if(plane.normal[0]*bminmax[plane.testVertex[0]][0]+plane.normal[1]*bminmax[plane.testVertex[1]][1]+plane.normal[2]*bminmax[plane.testVertex[2]][2]+plane.offset<0.0){return Frustum$1.OUTSIDE;}if(plane.normal[0]*bminmax[1-plane.testVertex[0]][0]+plane.normal[1]*bminmax[1-plane.testVertex[1]][1]+plane.normal[2]*bminmax[1-plane.testVertex[2]][2]+plane.offset<0.0){ret=Frustum$1.INTERSECT;}}return ret;}/**
|
|
1987
1987
|
* Picks a {@link Viewer}'s {@link Entity}s with a canvas-space 2D marquee box.
|
|
1988
1988
|
*
|
|
1989
1989
|
* [<img src="https://xeokit.github.io/xeokit-sdk/assets/images/MarqueeSelect.gif">](https://xeokit.github.io/xeokit-sdk/examples/picking/#marqueePick_select)
|
|
@@ -2181,7 +2181,7 @@ return;}if(!isMouseDown){return;}clearTimeout(mouseDownTimer);if(!isMouseDraggin
|
|
|
2181
2181
|
*/function PointerCircle(viewer){var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,PointerCircle);this.viewer=viewer;this.scene=this.viewer.scene;this._circleDiv=document.createElement('div');this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv,this.viewer.scene.canvas.canvas);this._circleDiv.style.backgroundColor="transparent";this._circleDiv.style.border="2px solid green";this._circleDiv.style.borderRadius="50px";this._circleDiv.style.width="50px";this._circleDiv.style.height="50px";this._circleDiv.style.margin="-200px -200px";this._circleDiv.style.zIndex="100000";this._circleDiv.style.position="absolute";this._circleDiv.style.pointerEvents="none";this._circlePos=null;this._circleMaxRadius=200;this._circleMinRadius=2;this._active=cfg.active!==false;this._visible=false;this._running=false;this._destroyed=false;}/**
|
|
2182
2182
|
* Show the circle at the given canvas coordinates and begin shrinking it.
|
|
2183
2183
|
*/_createClass(PointerCircle,[{key:"start",value:function start(circlePos){var _this12=this;if(this._destroyed){return;}this._circlePos=circlePos;this._running=false;this._circleRadius=this._circleMaxRadius;this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px");this._circleDiv.style.marginLeft="".concat(this._circlePos[0]-this._circleRadius,"px");this._circleDiv.style.marginTop="".concat(this._circlePos[1]-this._circleRadius,"px");var startValue=this._circleMaxRadius;var endValue=2;var startTime;var duration=300;var animateCircle=function animateCircle(currentTime){if(!_this12._running){return;}if(!startTime){startTime=currentTime;}var elapsedTime=currentTime-startTime;var progress=Math.min(elapsedTime/duration,1);var interpolatedValue=startValue+(endValue-startValue)*progress;_this12._circleRadius=interpolatedValue;_this12._circleDiv.style.width="".concat(_this12._circleRadius,"px");_this12._circleDiv.style.height="".concat(_this12._circleRadius,"px");_this12._circleDiv.style.marginLeft="".concat(_this12._circlePos[0]-_this12._circleRadius/2,"px");_this12._circleDiv.style.marginTop="".concat(_this12._circlePos[1]-_this12._circleRadius/2,"px");if(progress<1){requestAnimationFrame(animateCircle);}};this._running=true;requestAnimationFrame(animateCircle);this._circleDiv.style.visibility="visible";}/**
|
|
2184
|
-
* Stop the
|
|
2184
|
+
* Stop the shrinking circle and hide it.
|
|
2185
2185
|
*/},{key:"stop",value:function stop(){if(this._destroyed){return;}this._running=false;this._circleRadius=this._circleMaxRadius;this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px");this._circleDiv.style.visibility="hidden";}/**
|
|
2186
2186
|
* Sets the zoom factor for the lens.
|
|
2187
2187
|
*
|
|
@@ -2287,7 +2287,7 @@ navigator.mxMaxTouchPoints>0//works for older microsoft touch devices
|
|
|
2287
2287
|
function addContextMenuListener(elem,callback){var failCallback=arguments.length>2&&arguments[2]!==undefined?arguments[2]:function(){};if(!elem||!callback)return;var timeout=null;var longPressTimer=500;var MOVE_THRESHOLD=3;var startX,startY;var touchStartHandler=function touchStartHandler(event){event.preventDefault();if(timeout){clearTimeout(timeout);timeout=null;}// If more than one finger touches the screen, cancel the timeout
|
|
2288
2288
|
if(event.touches.length>1)return;var touch=event.touches[0];startX=touch.clientX;startY=touch.clientY;timeout=setTimeout(function(){event.clientX=touch.clientX;event.clientY=touch.clientY;callback(event);clearTimeout(timeout);timeout=null;},longPressTimer);};var globalTouchStartHandler=function globalTouchStartHandler(event){// Cancel timeout if multiple touches are detected anywhere on the screen
|
|
2289
2289
|
if(event.touches.length>1&&timeout){clearTimeout(timeout);timeout=null;}};var touchMoveHandler=function touchMoveHandler(event){if(!timeout)return;var touch=event.touches[0];var deltaX=Math.abs(touch.clientX-startX);var deltaY=Math.abs(touch.clientY-startY);if(deltaX>MOVE_THRESHOLD||deltaY>MOVE_THRESHOLD){clearTimeout(timeout);timeout=null;}};var touchEndHandler=function touchEndHandler(event){event.preventDefault();if(timeout){failCallback(event);clearTimeout(timeout);timeout=null;}};var contextMenuHandler=function contextMenuHandler(event){callback(event);event.preventDefault();event.stopPropagation();};if(os.isIphoneSafari()){elem.addEventListener('touchstart',touchStartHandler);elem.addEventListener('touchmove',touchMoveHandler);elem.addEventListener('touchend',touchEndHandler);window.addEventListener('touchstart',globalTouchStartHandler);}else{elem.addEventListener('contextmenu',contextMenuHandler);}return function removeContextMenuListener(){if(os.isIphoneSafari()){elem.removeEventListener('touchstart',touchStartHandler);elem.removeEventListener('touchmove',touchMoveHandler);elem.removeEventListener('touchend',touchEndHandler);window.removeEventListener('touchstart',globalTouchStartHandler);}else{elem.removeEventListener('contextmenu',contextMenuHandler);}};}/** @private */var Dot=/*#__PURE__*/function(){function Dot(parentElement){var _this13=this;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,Dot);this._highlightClass="viewer-ruler-dot-highlighted";this._x=0;this._y=0;this._dot=document.createElement('div');this._dot.className+=this._dot.className?' viewer-ruler-dot':'viewer-ruler-dot';this._dotClickable=document.createElement('div');this._dotClickable.className+=this._dotClickable.className?' viewer-ruler-dot-clickable':'viewer-ruler-dot-clickable';this._visible=cfg.visible!==false;this._culled=false;var dot=this._dot;var dotStyle=dot.style;dotStyle["border-radius"]=25+"px";dotStyle.border="solid 2px white";dotStyle.background="lightgreen";dotStyle.position="absolute";dotStyle["z-index"]=cfg.zIndex===undefined?"40000005":cfg.zIndex;dotStyle.width=8+"px";dotStyle.height=8+"px";dotStyle.visibility=this._visible?"visible":"hidden";dotStyle.top=0+"px";dotStyle.left=0+"px";dotStyle["box-shadow"]="0 2px 5px 0 #182A3D;";dotStyle["opacity"]=1.0;dotStyle["pointer-events"]="none";if(cfg.onContextMenu);parentElement.appendChild(dot);var dotClickable=this._dotClickable;var dotClickableStyle=dotClickable.style;dotClickableStyle["border-radius"]=35+"px";dotClickableStyle.border="solid 10px white";dotClickableStyle.position="absolute";dotClickableStyle["z-index"]=cfg.zIndex===undefined?"40000007":cfg.zIndex+1;dotClickableStyle.width=8+"px";dotClickableStyle.height=8+"px";dotClickableStyle.visibility="visible";dotClickableStyle.top=0+"px";dotClickableStyle.left=0+"px";dotClickableStyle["opacity"]=0.0;dotClickableStyle["pointer-events"]="none";if(cfg.onContextMenu);parentElement.appendChild(dotClickable);dotClickable.addEventListener('click',function(event){parentElement.dispatchEvent(new MouseEvent('mouseover',event));});if(cfg.onMouseOver){dotClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this13);parentElement.dispatchEvent(new MouseEvent('mouseover',event));});}if(cfg.onMouseLeave){dotClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this13);});}if(cfg.onMouseWheel){dotClickable.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this13);});}if(cfg.onMouseDown){dotClickable.addEventListener('mousedown',function(event){cfg.onMouseDown(event,_this13);});}if(cfg.onMouseUp){dotClickable.addEventListener('mouseup',function(event){cfg.onMouseUp(event,_this13);});}if(cfg.onMouseMove){dotClickable.addEventListener('mousemove',function(event){cfg.onMouseMove(event,_this13);});}if(cfg.onTouchstart){dotClickable.addEventListener('touchstart',function(event){cfg.onTouchstart(event,_this13);});}if(cfg.onTouchmove){dotClickable.addEventListener('touchmove',function(event){cfg.onTouchmove(event,_this13);});}if(cfg.onTouchend){dotClickable.addEventListener('touchend',function(event){cfg.onTouchend(event,_this13);});}if(cfg.onContextMenu){var contextMenuCallback=function contextMenuCallback(event){cfg.onContextMenu(event,_this13);};addContextMenuListener(dotClickable,contextMenuCallback);}this.setPos(cfg.x||0,cfg.y||0);this.setFillColor(cfg.fillColor);this.setBorderColor(cfg.borderColor);}_createClass(Dot,[{key:"setPos",value:function setPos(x,y){this._x=x;this._y=y;var dotStyle=this._dot.style;dotStyle["left"]=Math.round(x)-6+'px';dotStyle["top"]=Math.round(y)-6+'px';var dotClickableStyle=this._dotClickable.style;dotClickableStyle["left"]=Math.round(x)-14+'px';dotClickableStyle["top"]=Math.round(y)-14+'px';}},{key:"setFillColor",value:function setFillColor(color){this._dot.style.background=color||"lightgreen";}},{key:"setBorderColor",value:function setBorderColor(color){this._dot.style.border="solid 2px"+(color||"black");}},{key:"setOpacity",value:function setOpacity(opacity){this._dot.style.opacity=opacity;}},{key:"_updateVisibility",value:function _updateVisibility(){this._dot.style.visibility=this._dotClickable.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._updateVisibility();}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._updateVisibility();}},{key:"setClickable",value:function setClickable(clickable){this._dotClickable.style["pointer-events"]=clickable?"all":"none";}},{key:"setHighlighted",value:function setHighlighted(highlighted){if(this._highlighted===highlighted){return;}this._highlighted=!!highlighted;if(this._highlighted){this._dot.classList.add(this._highlightClass);}else{this._dot.classList.remove(this._highlightClass);}}},{key:"destroy",value:function destroy(){this.setVisible(false);if(this._dot.parentElement){this._dot.parentElement.removeChild(this._dot);}if(this._dotClickable.parentElement){this._dotClickable.parentElement.removeChild(this._dotClickable);}}}]);return Dot;}();/** @private */var Label=/*#__PURE__*/function(){function Label(parentElement){var _this14=this;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,Label);this._highlightClass="viewer-ruler-label-highlighted";this._prefix=cfg.prefix||"";this._x=0;this._y=0;this._visible=true;this._culled=false;this._label=document.createElement('div');this._label.className+=this._label.className?' viewer-ruler-label':'viewer-ruler-label';this._timeout=null;var label=this._label;var style=label.style;style["border-radius"]=5+"px";style.color="white";style.padding="4px";style.border="solid 1px";style.background="lightgreen";style.position="absolute";style["z-index"]=cfg.zIndex===undefined?"5000005":cfg.zIndex;style.width="auto";style.height="auto";style.visibility="visible";style.top=0+"px";style.left=0+"px";style["pointer-events"]="all";style["opacity"]=1.0;if(cfg.onContextMenu);label.innerText="";parentElement.appendChild(label);this.setPos(cfg.x||0,cfg.y||0);this.setFillColor(cfg.fillColor);this.setBorderColor(cfg.fillColor);this.setText(cfg.text);if(cfg.onMouseOver){label.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this14);event.preventDefault();});}if(cfg.onMouseLeave){label.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this14);event.preventDefault();});}if(cfg.onMouseWheel){label.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this14);});}if(cfg.onMouseDown){label.addEventListener('mousedown',function(event){cfg.onMouseDown(event,_this14);event.stopPropagation();});}if(cfg.onMouseUp){label.addEventListener('mouseup',function(event){cfg.onMouseUp(event,_this14);event.stopPropagation();});}if(cfg.onMouseMove){label.addEventListener('mousemove',function(event){cfg.onMouseMove(event,_this14);});}if(cfg.onContextMenu){var contextMenuCallback=function contextMenuCallback(event){cfg.onContextMenu(event,_this14);};addContextMenuListener(label,contextMenuCallback);}}_createClass(Label,[{key:"setPos",value:function setPos(x,y){this._x=x;this._y=y;var style=this._label.style;style["left"]=Math.round(x)-20+'px';style["top"]=Math.round(y)-12+'px';}},{key:"setPosOnWire",value:function setPosOnWire(x1,y1,x2,y2){var x=x1+(x2-x1)*0.5;var y=y1+(y2-y1)*0.5;var style=this._label.style;style["left"]=Math.round(x)-20+'px';style["top"]=Math.round(y)-12+'px';}},{key:"setPosBetweenWires",value:function setPosBetweenWires(x1,y1,x2,y2,x3,y3){var x=(x1+x2+x3)/3;var y=(y1+y2+y3)/3;var style=this._label.style;style["left"]=Math.round(x)-20+'px';style["top"]=Math.round(y)-12+'px';}},{key:"setText",value:function setText(text){this._label.innerHTML=this._prefix+(text||"");}},{key:"setFillColor",value:function setFillColor(color){this._fillColor=color||"lightgreen";this._label.style.background=this._fillColor;}},{key:"setBorderColor",value:function setBorderColor(color){this._borderColor=color||"black";this._label.style.border="solid 1px "+this._borderColor;}},{key:"setOpacity",value:function setOpacity(opacity){this._label.style.opacity=opacity;}},{key:"_updateVisibility",value:function _updateVisibility(){this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._updateVisibility();}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._updateVisibility();}},{key:"setHighlighted",value:function setHighlighted(highlighted){if(this._highlighted===highlighted){return;}this._highlighted=!!highlighted;if(this._highlighted){this._label.classList.add(this._highlightClass);}else{this._label.classList.remove(this._highlightClass);}}},{key:"setClickable",value:function setClickable(clickable){this._label.style["pointer-events"]=clickable?"all":"none";}},{key:"setPrefix",value:function setPrefix(prefix){if(this._prefix===prefix){return;}this._prefix=prefix;}},{key:"destroy",value:function destroy(){if(this._label.parentElement){this._label.parentElement.removeChild(this._label);}}}]);return Label;}();/** @private */var Wire=/*#__PURE__*/function(){function Wire(parentElement){var _this15=this;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,Wire);this._color=cfg.color||"black";this._highlightClass="viewer-ruler-wire-highlighted";this._wire=document.createElement('div');this._wire.className+=this._wire.className?' viewer-ruler-wire':'viewer-ruler-wire';this._wireClickable=document.createElement('div');this._wireClickable.className+=this._wireClickable.className?' viewer-ruler-wire-clickable':'viewer-ruler-wire-clickable';this._thickness=cfg.thickness||1.0;this._thicknessClickable=cfg.thicknessClickable||6.0;this._visible=true;this._culled=false;var wire=this._wire;var wireStyle=wire.style;wireStyle.border="solid "+this._thickness+"px "+this._color;wireStyle.position="absolute";wireStyle["z-index"]=cfg.zIndex===undefined?"2000001":cfg.zIndex;wireStyle.width=0+"px";wireStyle.height=0+"px";wireStyle.visibility="visible";wireStyle.top=0+"px";wireStyle.left=0+"px";wireStyle['-webkit-transform-origin']="0 0";wireStyle['-moz-transform-origin']="0 0";wireStyle['-ms-transform-origin']="0 0";wireStyle['-o-transform-origin']="0 0";wireStyle['transform-origin']="0 0";wireStyle['-webkit-transform']='rotate(0deg)';wireStyle['-moz-transform']='rotate(0deg)';wireStyle['-ms-transform']='rotate(0deg)';wireStyle['-o-transform']='rotate(0deg)';wireStyle['transform']='rotate(0deg)';wireStyle["opacity"]=1.0;wireStyle["pointer-events"]="none";if(cfg.onContextMenu);parentElement.appendChild(wire);var wireClickable=this._wireClickable;var wireClickableStyle=wireClickable.style;wireClickableStyle.border="solid "+this._thicknessClickable+"px "+this._color;wireClickableStyle.position="absolute";wireClickableStyle["z-index"]=cfg.zIndex===undefined?"2000002":cfg.zIndex+1;wireClickableStyle.width=0+"px";wireClickableStyle.height=0+"px";wireClickableStyle.visibility="visible";wireClickableStyle.top=0+"px";wireClickableStyle.left=0+"px";// wireClickableStyle["pointer-events"] = "none";
|
|
2290
|
-
wireClickableStyle['-webkit-transform-origin']="0 0";wireClickableStyle['-moz-transform-origin']="0 0";wireClickableStyle['-ms-transform-origin']="0 0";wireClickableStyle['-o-transform-origin']="0 0";wireClickableStyle['transform-origin']="0 0";wireClickableStyle['-webkit-transform']='rotate(0deg)';wireClickableStyle['-moz-transform']='rotate(0deg)';wireClickableStyle['-ms-transform']='rotate(0deg)';wireClickableStyle['-o-transform']='rotate(0deg)';wireClickableStyle['transform']='rotate(0deg)';wireClickableStyle["opacity"]=0.0;wireClickableStyle["pointer-events"]="none";if(cfg.onContextMenu);parentElement.appendChild(wireClickable);if(cfg.onMouseOver){wireClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this15);});}if(cfg.onMouseLeave){wireClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this15);});}if(cfg.onMouseWheel){wireClickable.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this15);});}if(cfg.onMouseDown){wireClickable.addEventListener('mousedown',function(event){cfg.onMouseDown(event,_this15);});}if(cfg.onMouseUp){wireClickable.addEventListener('mouseup',function(event){cfg.onMouseUp(event,_this15);});}if(cfg.onMouseMove){wireClickable.addEventListener('mousemove',function(event){cfg.onMouseMove(event,_this15);});}if(cfg.onContextMenu){var contextMenuCallback=function contextMenuCallback(event){cfg.onContextMenu(event,_this15);};addContextMenuListener(wireClickable,contextMenuCallback);}this._x1=0;this._y1=0;this._x2=0;this._y2=0;this._update();}_createClass(Wire,[{key:"visible",get:function get(){return this._wire.style.visibility==="visible";}},{key:"_update",value:function _update(){var length=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2)));var angle=Math.atan2(this._y2-this._y1,this._x2-this._x1)*180.0/Math.PI;var wireStyle=this._wire.style;wireStyle["width"]=Math.round(length)+'px';wireStyle["left"]=Math.round(this._x1)+'px';wireStyle["top"]=Math.round(this._y1)+'px';wireStyle['-webkit-transform']=wireStyle['-moz-transform']=wireStyle['-ms-transform']=wireStyle['-o-transform']=wireStyle['transform']='rotate('+angle+'deg) translate(-'+this._thickness+'px, -'+this._thickness+'px)';var wireClickableStyle=this._wireClickable.style;wireClickableStyle["width"]=Math.round(length)+'px';wireClickableStyle["left"]=Math.round(this._x1)+'px';wireClickableStyle["top"]=Math.round(this._y1)+'px';wireClickableStyle['-webkit-transform']=wireClickableStyle['-moz-transform']=wireClickableStyle['-ms-transform']=wireClickableStyle['-o-transform']=wireClickableStyle['transform']='rotate('+angle+'deg) translate(-'+this._thicknessClickable+'px, -'+this._thicknessClickable+'px)';}},{key:"setStartAndEnd",value:function setStartAndEnd(x1,y1,x2,y2){this._x1=x1;this._y1=y1;this._x2=x2;this._y2=y2;this._update();}},{key:"setColor",value:function setColor(color){this._color=color||"black";this._wire.style.border="solid "+this._thickness+"px "+this._color;}},{key:"setOpacity",value:function setOpacity(opacity){this._wire.style.opacity=opacity;}},{key:"_updateVisibility",value:function _updateVisibility(){this._wire.style.visibility=this._wireClickable.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._updateVisibility();}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._updateVisibility();}},{key:"setClickable",value:function setClickable(clickable){this._wireClickable.style["pointer-events"]=clickable?"all":"none";}},{key:"setHighlighted",value:function setHighlighted(highlighted){if(this._highlighted===highlighted){return;}this._highlighted=!!highlighted;if(this._highlighted){this._wire.classList.add(this._highlightClass);}else{this._wire.classList.remove(this._highlightClass);}}},{key:"destroy",value:function destroy(visible){if(this._wire.parentElement){this._wire.parentElement.removeChild(this._wire);}if(this._wireClickable.parentElement){this._wireClickable.parentElement.removeChild(this._wireClickable);}}}]);return Wire;}();var tempVec3a$
|
|
2290
|
+
wireClickableStyle['-webkit-transform-origin']="0 0";wireClickableStyle['-moz-transform-origin']="0 0";wireClickableStyle['-ms-transform-origin']="0 0";wireClickableStyle['-o-transform-origin']="0 0";wireClickableStyle['transform-origin']="0 0";wireClickableStyle['-webkit-transform']='rotate(0deg)';wireClickableStyle['-moz-transform']='rotate(0deg)';wireClickableStyle['-ms-transform']='rotate(0deg)';wireClickableStyle['-o-transform']='rotate(0deg)';wireClickableStyle['transform']='rotate(0deg)';wireClickableStyle["opacity"]=0.0;wireClickableStyle["pointer-events"]="none";if(cfg.onContextMenu);parentElement.appendChild(wireClickable);if(cfg.onMouseOver){wireClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this15);});}if(cfg.onMouseLeave){wireClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this15);});}if(cfg.onMouseWheel){wireClickable.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this15);});}if(cfg.onMouseDown){wireClickable.addEventListener('mousedown',function(event){cfg.onMouseDown(event,_this15);});}if(cfg.onMouseUp){wireClickable.addEventListener('mouseup',function(event){cfg.onMouseUp(event,_this15);});}if(cfg.onMouseMove){wireClickable.addEventListener('mousemove',function(event){cfg.onMouseMove(event,_this15);});}if(cfg.onContextMenu){var contextMenuCallback=function contextMenuCallback(event){cfg.onContextMenu(event,_this15);};addContextMenuListener(wireClickable,contextMenuCallback);}this._x1=0;this._y1=0;this._x2=0;this._y2=0;this._update();}_createClass(Wire,[{key:"visible",get:function get(){return this._wire.style.visibility==="visible";}},{key:"_update",value:function _update(){var length=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2)));var angle=Math.atan2(this._y2-this._y1,this._x2-this._x1)*180.0/Math.PI;var wireStyle=this._wire.style;wireStyle["width"]=Math.round(length)+'px';wireStyle["left"]=Math.round(this._x1)+'px';wireStyle["top"]=Math.round(this._y1)+'px';wireStyle['-webkit-transform']=wireStyle['-moz-transform']=wireStyle['-ms-transform']=wireStyle['-o-transform']=wireStyle['transform']='rotate('+angle+'deg) translate(-'+this._thickness+'px, -'+this._thickness+'px)';var wireClickableStyle=this._wireClickable.style;wireClickableStyle["width"]=Math.round(length)+'px';wireClickableStyle["left"]=Math.round(this._x1)+'px';wireClickableStyle["top"]=Math.round(this._y1)+'px';wireClickableStyle['-webkit-transform']=wireClickableStyle['-moz-transform']=wireClickableStyle['-ms-transform']=wireClickableStyle['-o-transform']=wireClickableStyle['transform']='rotate('+angle+'deg) translate(-'+this._thicknessClickable+'px, -'+this._thicknessClickable+'px)';}},{key:"setStartAndEnd",value:function setStartAndEnd(x1,y1,x2,y2){this._x1=x1;this._y1=y1;this._x2=x2;this._y2=y2;this._update();}},{key:"setColor",value:function setColor(color){this._color=color||"black";this._wire.style.border="solid "+this._thickness+"px "+this._color;}},{key:"setOpacity",value:function setOpacity(opacity){this._wire.style.opacity=opacity;}},{key:"_updateVisibility",value:function _updateVisibility(){this._wire.style.visibility=this._wireClickable.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._updateVisibility();}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._updateVisibility();}},{key:"setClickable",value:function setClickable(clickable){this._wireClickable.style["pointer-events"]=clickable?"all":"none";}},{key:"setHighlighted",value:function setHighlighted(highlighted){if(this._highlighted===highlighted){return;}this._highlighted=!!highlighted;if(this._highlighted){this._wire.classList.add(this._highlightClass);}else{this._wire.classList.remove(this._highlightClass);}}},{key:"destroy",value:function destroy(visible){if(this._wire.parentElement){this._wire.parentElement.removeChild(this._wire);}if(this._wireClickable.parentElement){this._wireClickable.parentElement.removeChild(this._wireClickable);}}}]);return Wire;}();var tempVec3a$M=math.vec3();var tempVec4$1=math.vec4();/**
|
|
2291
2291
|
* Given a view matrix and a relative-to-center (RTC) coordinate origin, returns a view matrix
|
|
2292
2292
|
* to transform RTC coordinates to View-space.
|
|
2293
2293
|
*
|
|
@@ -2321,7 +2321,7 @@ wireClickableStyle['-webkit-transform-origin']="0 0";wireClickableStyle['-moz-tr
|
|
|
2321
2321
|
* @returns {Boolean} ````True```` if the positions actually needed conversion to RTC, else ````false````. When
|
|
2322
2322
|
* ````false````, we can safely ignore the data returned in ````rtcPositions```` and ````rtcCenter````,
|
|
2323
2323
|
* since ````rtcCenter```` will equal ````[0,0,0]````, and ````rtcPositions```` will contain identical values to ````positions````.
|
|
2324
|
-
*/function worldToRTCPositions(worldPositions,rtcPositions,rtcCenter){var cellSize=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1000;var center=math.getPositionsCenter(worldPositions,tempVec3a$
|
|
2324
|
+
*/function worldToRTCPositions(worldPositions,rtcPositions,rtcCenter){var cellSize=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1000;var center=math.getPositionsCenter(worldPositions,tempVec3a$M);var rtcCenterX=Math.round(center[0]/cellSize)*cellSize;var rtcCenterY=Math.round(center[1]/cellSize)*cellSize;var rtcCenterZ=Math.round(center[2]/cellSize)*cellSize;rtcCenter[0]=rtcCenterX;rtcCenter[1]=rtcCenterY;rtcCenter[2]=rtcCenterZ;var rtcNeeded=rtcCenter[0]!==0||rtcCenter[1]!==0||rtcCenter[2]!==0;if(rtcNeeded){for(var _i29=0,len=worldPositions.length;_i29<len;_i29+=3){rtcPositions[_i29+0]=worldPositions[_i29+0]-rtcCenterX;rtcPositions[_i29+1]=worldPositions[_i29+1]-rtcCenterY;rtcPositions[_i29+2]=worldPositions[_i29+2]-rtcCenterZ;}}return rtcNeeded;}/**
|
|
2325
2325
|
* Converts an RTC 3D position to World-space.
|
|
2326
2326
|
*
|
|
2327
2327
|
* @private
|
|
@@ -2338,7 +2338,7 @@ wireClickableStyle['-webkit-transform-origin']="0 0";wireClickableStyle['-moz-tr
|
|
|
2338
2338
|
* @param rtcCenter
|
|
2339
2339
|
* @param rtcPlanePos
|
|
2340
2340
|
* @returns {*}
|
|
2341
|
-
*/function getPlaneRTCPos(dist,dir,rtcOrigin,rtcPlanePos,originMatrix){var rtcCenter=originMatrix?(tempVec4$1.set(rtcOrigin,0),tempVec4$1[3]=1,math.mulMat4v4(originMatrix,tempVec4$1,tempVec4$1)):rtcOrigin;var rtcCenterToPlaneDist=math.dotVec3(dir,rtcCenter)+dist;var dirNormalized=math.normalizeVec3(dir,tempVec3a$
|
|
2341
|
+
*/function getPlaneRTCPos(dist,dir,rtcOrigin,rtcPlanePos,originMatrix){var rtcCenter=originMatrix?(tempVec4$1.set(rtcOrigin,0),tempVec4$1[3]=1,math.mulMat4v4(originMatrix,tempVec4$1,tempVec4$1)):rtcOrigin;var rtcCenterToPlaneDist=math.dotVec3(dir,rtcCenter)+dist;var dirNormalized=math.normalizeVec3(dir,tempVec3a$M);math.mulVec3Scalar(dirNormalized,-rtcCenterToPlaneDist,rtcPlanePos);return rtcPlanePos;}/**
|
|
2342
2342
|
* @private
|
|
2343
2343
|
* @type {{PICKABLE: number, CLIPPABLE: number, BACKFACES: number, VISIBLE: number, SELECTED: number, OUTLINED: number, CULLED: number, RECEIVE_SHADOW: number, COLLIDABLE: number, XRAYED: number, CAST_SHADOW: number, EDGES: number, HIGHLIGHTED: number}}
|
|
2344
2344
|
*/var ENTITY_FLAGS={VISIBLE:1,CULLED:1<<2,PICKABLE:1<<3,CLIPPABLE:1<<4,COLLIDABLE:1<<5,CAST_SHADOW:1<<6,RECEIVE_SHADOW:1<<7,XRAYED:1<<8,HIGHLIGHTED:1<<9,SELECTED:1<<10,EDGES:1<<11,BACKFACES:1<<12,TRANSPARENT:1<<13};var tempFloatRGB=new Float32Array([0,0,0]);var tempIntRGB=new Uint16Array([0,0,0]);math.OBB3();/**
|
|
@@ -2581,7 +2581,7 @@ if(lastOpacityQuantized===opacityQuantized){return;}}else{opacityQuantized=255.0
|
|
|
2581
2581
|
* SceneModelEntity contains triangle meshes; returns `0` otherwise.
|
|
2582
2582
|
*
|
|
2583
2583
|
* @returns {number}
|
|
2584
|
-
*/},{key:"surfaceArea",get:function get(){var surfaceArea=0;for(var _i43=0,len=this.meshes.length;_i43<len;_i43++){var _meshSurfaceArea=this.meshes[_i43].surfaceArea;if(_meshSurfaceArea>=0){surfaceArea+=_meshSurfaceArea;}}return surfaceArea>0?surfaceArea:-1;}},{key:"_getFlag",value:function _getFlag(flag){return!!(this._flags&flag);}},{key:"_finalize",value:function _finalize(){var scene=this.model.scene;if(this._isObject){if(this.visible){scene._objectVisibilityUpdated(this);}if(this.highlighted){scene._objectHighlightedUpdated(this);}if(this.xrayed){scene._objectXRayedUpdated(this);}if(this.selected){scene._objectSelectedUpdated(this);}}for(var _i44=0,len=this.meshes.length;_i44<len;_i44++){this.meshes[_i44]._finalize(this._flags);}}},{key:"_finalize2",value:function _finalize2(){for(var _i45=0,len=this.meshes.length;_i45<len;_i45++){this.meshes[_i45]._finalize2();}}},{key:"_destroy",value:function _destroy(){var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(this.visible){scene._deRegisterVisibleObject(this);}if(this.xrayed){scene._deRegisterXRayedObject(this);}if(this.selected){scene._deRegisterSelectedObject(this);}if(this.highlighted){scene._deRegisterHighlightedObject(this);}if(this._colorizeUpdated){this.scene._deRegisterColorizedObject(this);}if(this._opacityUpdated){this.scene._deRegisterOpacityObject(this);}if(this._offset&&(this._offset[0]!==0||this._offset[1]!==0||this._offset[2]!==0)){this.scene._deRegisterOffsetObject(this);}}for(var _i46=0,len=this.meshes.length;_i46<len;_i46++){this.meshes[_i46]._destroy();}scene._aabbDirty=true;}}]);return SceneModelEntity;}();var tempVec4a$
|
|
2584
|
+
*/},{key:"surfaceArea",get:function get(){var surfaceArea=0;for(var _i43=0,len=this.meshes.length;_i43<len;_i43++){var _meshSurfaceArea=this.meshes[_i43].surfaceArea;if(_meshSurfaceArea>=0){surfaceArea+=_meshSurfaceArea;}}return surfaceArea>0?surfaceArea:-1;}},{key:"_getFlag",value:function _getFlag(flag){return!!(this._flags&flag);}},{key:"_finalize",value:function _finalize(){var scene=this.model.scene;if(this._isObject){if(this.visible){scene._objectVisibilityUpdated(this);}if(this.highlighted){scene._objectHighlightedUpdated(this);}if(this.xrayed){scene._objectXRayedUpdated(this);}if(this.selected){scene._objectSelectedUpdated(this);}}for(var _i44=0,len=this.meshes.length;_i44<len;_i44++){this.meshes[_i44]._finalize(this._flags);}}},{key:"_finalize2",value:function _finalize2(){for(var _i45=0,len=this.meshes.length;_i45<len;_i45++){this.meshes[_i45]._finalize2();}}},{key:"_destroy",value:function _destroy(){var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(this.visible){scene._deRegisterVisibleObject(this);}if(this.xrayed){scene._deRegisterXRayedObject(this);}if(this.selected){scene._deRegisterSelectedObject(this);}if(this.highlighted){scene._deRegisterHighlightedObject(this);}if(this._colorizeUpdated){this.scene._deRegisterColorizedObject(this);}if(this._opacityUpdated){this.scene._deRegisterOpacityObject(this);}if(this._offset&&(this._offset[0]!==0||this._offset[1]!==0||this._offset[2]!==0)){this.scene._deRegisterOffsetObject(this);}}for(var _i46=0,len=this.meshes.length;_i46<len;_i46++){this.meshes[_i46]._destroy();}scene._aabbDirty=true;}}]);return SceneModelEntity;}();var tempVec4a$c=math.vec4();var tempVec4b$7=math.vec4();/**
|
|
2585
2585
|
* @desc Tracks the World, View and Canvas coordinates, and visibility, of a position within a {@link Scene}.
|
|
2586
2586
|
*
|
|
2587
2587
|
* ## Position
|
|
@@ -2693,7 +2693,7 @@ if(lastOpacityQuantized===opacityQuantized){return;}}else{opacityQuantized=255.0
|
|
|
2693
2693
|
* @param {Boolean} [cfg.occludable=false] Indicates whether or not this Marker is hidden (ie. {@link Marker#visible} is ````false```` whenever occluded by {@link Entity}s in the {@link Scene}.
|
|
2694
2694
|
* @param {Number[]} [cfg.worldPos=[0,0,0]] World-space 3D Marker position.
|
|
2695
2695
|
*/function Marker(owner,cfg){var _this16;_classCallCheck(this,Marker);_this16=_super4.call(this,owner,cfg);_this16._entity=null;_this16._visible=null;_this16._worldPos=math.vec3();_this16._origin=math.vec3();_this16._rtcPos=math.vec3();_this16._viewPos=math.vec3();_this16._canvasPos=math.vec2();_this16._occludable=false;_this16._onCameraViewMatrix=_this16.scene.camera.on("matrix",function(){_this16._viewPosDirty=true;_this16._needUpdate();});_this16._onCameraProjMatrix=_this16.scene.camera.on("projMatrix",function(){_this16._canvasPosDirty=true;_this16._needUpdate();});_this16._onEntityDestroyed=null;_this16._onEntityModelDestroyed=null;_this16._renderer.addMarker(_assertThisInitialized(_this16));_this16.entity=cfg.entity;_this16.worldPos=cfg.worldPos;_this16.occludable=cfg.occludable;return _this16;}_createClass(Marker,[{key:"_update",value:function _update(){// this._needUpdate() schedules this for next tick
|
|
2696
|
-
if(this._viewPosDirty){math.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos);this._viewPosDirty=false;this._canvasPosDirty=true;this.fire("viewPos",this._viewPos);}if(this._canvasPosDirty){tempVec4a$
|
|
2696
|
+
if(this._viewPosDirty){math.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos);this._viewPosDirty=false;this._canvasPosDirty=true;this.fire("viewPos",this._viewPos);}if(this._canvasPosDirty){tempVec4a$c.set(this._viewPos);tempVec4a$c[3]=1.0;math.transformPoint4(this.scene.camera.projMatrix,tempVec4a$c,tempVec4b$7);var aabb=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+tempVec4b$7[0]/tempVec4b$7[3])*aabb[2]/2);this._canvasPos[1]=Math.floor((1-tempVec4b$7[1]/tempVec4b$7[3])*aabb[3]/2);this._canvasPosDirty=false;this.fire("canvasPos",this._canvasPos);}}},{key:"_setVisible",value:function _setVisible(visible){// Called by VisibilityTester and this._entity.on("destroyed"..)
|
|
2697
2697
|
if(this._visible===visible);this._visible=visible;this.fire("visible",this._visible);}/**
|
|
2698
2698
|
* Sets the {@link Entity} this Marker is associated with.
|
|
2699
2699
|
*
|
|
@@ -3454,7 +3454,7 @@ enableCameraNavigation();break;case WAITING_FOR_TARGET_QUICK_TOUCH_END$1:{if(num
|
|
|
3454
3454
|
* @param {boolean} [handleTouchEvents] Whether to hangle touch input.
|
|
3455
3455
|
*/function AngleMeasurementEditControl(measurement,cfg,handleMouseEvents,handleTouchEvents){var _this29;_classCallCheck(this,AngleMeasurementEditControl);var viewer=measurement.plugin.viewer;_this29=_super11.call(this,viewer.scene);var cleanup=activateDraggableDots({viewer:viewer,handleMouseEvents:handleMouseEvents,handleTouchEvents:handleTouchEvents,pointerLens:cfg.pointerLens,dots:[measurement.origin,measurement.corner,measurement.target],ray2WorldPos:function ray2WorldPos(orig,dir,canvasPos){var tryPickWorldPos=function tryPickWorldPos(snap){var pickResult=viewer.scene.pick({canvasPos:canvasPos,snapToEdge:snap,snapToVertex:snap,pickSurface:true// <<------ This causes picking to find the intersection point on the entity
|
|
3456
3456
|
});// If - when snapping - no pick found, then try w/o snapping
|
|
3457
|
-
return pickResult&&pickResult.worldPos?pickResult.worldPos:snap&&tryPickWorldPos(false);};return tryPickWorldPos(!!cfg.snapping);},onEnd:function onEnd(initPos,dot){var changed=!math.compareVec3(initPos,dot.worldPos);if(changed){_this29.fire("edited");}return changed;}});var destroyCb=measurement.on("destroyed",cleanup);_this29._deactivate=function(){measurement.off("destroyed",destroyCb);cleanup();};return _this29;}_createClass(AngleMeasurementEditControl,[{key:"deactivate",value:function deactivate(){this._deactivate();_get(_getPrototypeOf(AngleMeasurementEditControl.prototype),"destroy",this).call(this);}}]);return AngleMeasurementEditControl;}(Component);var AngleMeasurementEditMouseControl=/*#__PURE__*/function(_AngleMeasurementEdit){_inherits(AngleMeasurementEditMouseControl,_AngleMeasurementEdit);var _super12=_createSuper(AngleMeasurementEditMouseControl);function AngleMeasurementEditMouseControl(zone,cfg){_classCallCheck(this,AngleMeasurementEditMouseControl);return _super12.call(this,zone,cfg,true,false);}return _createClass(AngleMeasurementEditMouseControl);}(AngleMeasurementEditControl);var AngleMeasurementEditTouchControl=/*#__PURE__*/function(_AngleMeasurementEdit2){_inherits(AngleMeasurementEditTouchControl,_AngleMeasurementEdit2);var _super13=_createSuper(AngleMeasurementEditTouchControl);function AngleMeasurementEditTouchControl(zone,cfg){_classCallCheck(this,AngleMeasurementEditTouchControl);return _super13.call(this,zone,cfg,false,true);}return _createClass(AngleMeasurementEditTouchControl);}(AngleMeasurementEditControl);var tempVec3a$
|
|
3457
|
+
return pickResult&&pickResult.worldPos?pickResult.worldPos:snap&&tryPickWorldPos(false);};return tryPickWorldPos(!!cfg.snapping);},onEnd:function onEnd(initPos,dot){var changed=!math.compareVec3(initPos,dot.worldPos);if(changed){_this29.fire("edited");}return changed;}});var destroyCb=measurement.on("destroyed",cleanup);_this29._deactivate=function(){measurement.off("destroyed",destroyCb);cleanup();};return _this29;}_createClass(AngleMeasurementEditControl,[{key:"deactivate",value:function deactivate(){this._deactivate();_get(_getPrototypeOf(AngleMeasurementEditControl.prototype),"destroy",this).call(this);}}]);return AngleMeasurementEditControl;}(Component);var AngleMeasurementEditMouseControl=/*#__PURE__*/function(_AngleMeasurementEdit){_inherits(AngleMeasurementEditMouseControl,_AngleMeasurementEdit);var _super12=_createSuper(AngleMeasurementEditMouseControl);function AngleMeasurementEditMouseControl(zone,cfg){_classCallCheck(this,AngleMeasurementEditMouseControl);return _super12.call(this,zone,cfg,true,false);}return _createClass(AngleMeasurementEditMouseControl);}(AngleMeasurementEditControl);var AngleMeasurementEditTouchControl=/*#__PURE__*/function(_AngleMeasurementEdit2){_inherits(AngleMeasurementEditTouchControl,_AngleMeasurementEdit2);var _super13=_createSuper(AngleMeasurementEditTouchControl);function AngleMeasurementEditTouchControl(zone,cfg){_classCallCheck(this,AngleMeasurementEditTouchControl);return _super13.call(this,zone,cfg,false,true);}return _createClass(AngleMeasurementEditTouchControl);}(AngleMeasurementEditControl);var tempVec3a$L=math.vec3();var tempVec3b$A=math.vec3();var tempVec3c$v=math.vec3();/**
|
|
3458
3458
|
* A {@link Marker} with an HTML label attached to it, managed by an {@link AnnotationsPlugin}.
|
|
3459
3459
|
*
|
|
3460
3460
|
* See {@link AnnotationsPlugin} for more info.
|
|
@@ -3501,7 +3501,7 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
|
|
|
3501
3501
|
* Sets the Marker's worldPos and entity properties based on passed {@link PickResult}
|
|
3502
3502
|
*
|
|
3503
3503
|
* @param {PickResult} pickResult A PickResult to position the Marker at.
|
|
3504
|
-
*/},{key:"setFromPickResult",value:function setFromPickResult(pickResult){if(!pickResult.worldPos||!pickResult.worldNormal){this.error("Param 'pickResult' does not have both worldPos and worldNormal");}else{var normalizedWorldNormal=math.normalizeVec3(pickResult.worldNormal,tempVec3a$
|
|
3504
|
+
*/},{key:"setFromPickResult",value:function setFromPickResult(pickResult){if(!pickResult.worldPos||!pickResult.worldNormal){this.error("Param 'pickResult' does not have both worldPos and worldNormal");}else{var normalizedWorldNormal=math.normalizeVec3(pickResult.worldNormal,tempVec3a$L);var offset=this.plugin&&this.plugin.surfaceOffset||0;var offsetVec=math.mulVec3Scalar(normalizedWorldNormal,offset,tempVec3b$A);var offsetWorldPos=math.addVec3(pickResult.worldPos,offsetVec,tempVec3c$v);this.entity=pickResult.entity;this.worldPos=offsetWorldPos;}}/**
|
|
3505
3505
|
* Sets the horizontal alignment of the Annotation's marker HTML.
|
|
3506
3506
|
*
|
|
3507
3507
|
* @param {String} align Either "left", "center", "right" (default "left")
|
|
@@ -4720,7 +4720,7 @@ this._buildPositions();this.positionsDirty=false;this.aabbDirty=true;this.vbosDi
|
|
|
4720
4720
|
this.positionsBuf.setData(new Float32Array(this.positions));// Indices don't need updating
|
|
4721
4721
|
return;}this.positionsBuf.destroy();this.positionsBuf=null;this.indicesBuf.destroy();this.indicesBuf=null;}var gl=this.scene.canvas.gl;var lenPositions=this.numMarkers*3;var lenIndices=this.numMarkers;this.positionsBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this.positions),lenPositions,3,gl.STATIC_DRAW);this.indicesBuf=new ArrayBuf(gl,gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),lenIndices,1,gl.STATIC_DRAW);this.lenPositionsBuf=this.positions.length;}},{key:"_buildOcclusionTestList",value:function _buildOcclusionTestList(){var canvas=this.scene.canvas;var near=this.scene.camera.perspective.near;// Assume near enough to ortho near
|
|
4722
4722
|
var boundary=canvas.boundary;var canvasWidth=boundary[2];var canvasHeight=boundary[3];var lenPixels=0;this.lenOcclusionTestList=0;for(var _i53=0;_i53<this.numMarkers;_i53++){var marker=this.markerList[_i53];var _viewPos=marker.viewPos;if(_viewPos[2]>-near){// Clipped by near plane
|
|
4723
|
-
marker._setVisible(false);continue;}var _canvasPos2=marker.canvasPos;var canvasX=_canvasPos2[0];var canvasY=_canvasPos2[1];if(canvasX+10<0||canvasY+10<0||canvasX-10>canvasWidth||canvasY-10>canvasHeight){marker._setVisible(false);continue;}if(marker.entity&&!marker.entity.visible){marker._setVisible(false);continue;}if(marker.occludable){this.occlusionTestList[this.lenOcclusionTestList++]=marker;this.pixels[lenPixels++]=canvasX;this.pixels[lenPixels++]=canvasY;continue;}marker._setVisible(true);}}},{key:"_updateActiveSectionPlanes",value:function _updateActiveSectionPlanes(){var sectionPlanes=this.scene._sectionPlanesState.sectionPlanes;var numSectionPlanes=sectionPlanes.length;if(numSectionPlanes>0){for(var _i54=0;_i54<numSectionPlanes;_i54++){var sectionPlane=sectionPlanes[_i54];if(!sectionPlane.active){this.sectionPlanesActive[_i54]=false;}else{var intersect=math.planeAABB3Intersect(sectionPlane.dir,sectionPlane.dist,this.aabb);var outside=intersect===-1;if(outside){this.culledBySectionPlanes=true;return;}var intersecting=intersect===0;this.sectionPlanesActive[_i54]=intersecting;}}}this.culledBySectionPlanes=false;}},{key:"destroy",value:function destroy(){this.markers={};this.markerList.length=0;if(this.positionsBuf){this.positionsBuf.destroy();}if(this.indicesBuf){this.indicesBuf.destroy();}}}]);return OcclusionLayer;}();var MARKER_COLOR=math.vec3([1.0,0.0,0.0]);var POINT_SIZE=20;var tempVec3a$
|
|
4723
|
+
marker._setVisible(false);continue;}var _canvasPos2=marker.canvasPos;var canvasX=_canvasPos2[0];var canvasY=_canvasPos2[1];if(canvasX+10<0||canvasY+10<0||canvasX-10>canvasWidth||canvasY-10>canvasHeight){marker._setVisible(false);continue;}if(marker.entity&&!marker.entity.visible){marker._setVisible(false);continue;}if(marker.occludable){this.occlusionTestList[this.lenOcclusionTestList++]=marker;this.pixels[lenPixels++]=canvasX;this.pixels[lenPixels++]=canvasY;continue;}marker._setVisible(true);}}},{key:"_updateActiveSectionPlanes",value:function _updateActiveSectionPlanes(){var sectionPlanes=this.scene._sectionPlanesState.sectionPlanes;var numSectionPlanes=sectionPlanes.length;if(numSectionPlanes>0){for(var _i54=0;_i54<numSectionPlanes;_i54++){var sectionPlane=sectionPlanes[_i54];if(!sectionPlane.active){this.sectionPlanesActive[_i54]=false;}else{var intersect=math.planeAABB3Intersect(sectionPlane.dir,sectionPlane.dist,this.aabb);var outside=intersect===-1;if(outside){this.culledBySectionPlanes=true;return;}var intersecting=intersect===0;this.sectionPlanesActive[_i54]=intersecting;}}}this.culledBySectionPlanes=false;}},{key:"destroy",value:function destroy(){this.markers={};this.markerList.length=0;if(this.positionsBuf){this.positionsBuf.destroy();}if(this.indicesBuf){this.indicesBuf.destroy();}}}]);return OcclusionLayer;}();var MARKER_COLOR=math.vec3([1.0,0.0,0.0]);var POINT_SIZE=20;var tempVec3a$K=math.vec3();/**
|
|
4724
4724
|
* Manages occlusion testing. Private member of a Renderer.
|
|
4725
4725
|
* @private
|
|
4726
4726
|
*/var OcclusionTester=/*#__PURE__*/function(){function OcclusionTester(scene,renderBufferManager){var _this36=this;_classCallCheck(this,OcclusionTester);this._scene=scene;this._renderBufferManager=renderBufferManager;this._occlusionLayers={};this._occlusionLayersList=[];this._occlusionLayersListDirty=false;this._shaderSource=null;this._program=null;this._shaderSourceHash=null;this._shaderSourceDirty=true;// Need to build shader source code ?
|
|
@@ -4743,7 +4743,7 @@ this._markersToOcclusionLayersMap={};this._onCameraViewMatrix=scene.camera.on("v
|
|
|
4743
4743
|
* then calls drawMarkers() and doOcclusionTest().
|
|
4744
4744
|
*/},{key:"bindRenderBuf",value:function bindRenderBuf(){var shaderSourceHash=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(shaderSourceHash!==this._shaderSourceHash){this._shaderSourceHash=shaderSourceHash;this._shaderSourceDirty=true;}if(this._shaderSourceDirty){this._buildShaderSource();this._shaderSourceDirty=false;this._programDirty=true;}if(this._programDirty){this._buildProgram();this._programDirty=false;this._occlusionTestListDirty=true;}if(this._occlusionLayersListDirty){this._buildOcclusionLayersList();this._occlusionLayersListDirty=false;}if(this._occlusionTestListDirty){for(var _i55=0,len=this._occlusionLayersList.length;_i55<len;_i55++){var occlusionLayer=this._occlusionLayersList[_i55];occlusionLayer.occlusionTestListDirty=true;}this._occlusionTestListDirty=false;}{this._readPixelBuf=this._renderBufferManager.getRenderBuffer("occlusionReadPix");this._readPixelBuf.bind();this._readPixelBuf.clear();}}},{key:"_buildOcclusionLayersList",value:function _buildOcclusionLayersList(){var numOcclusionLayers=0;for(var originHash in this._occlusionLayers){if(this._occlusionLayers.hasOwnProperty(originHash)){this._occlusionLayersList[numOcclusionLayers++]=this._occlusionLayers[originHash];}}this._occlusionLayersList.length=numOcclusionLayers;}},{key:"_buildShaderSource",value:function _buildShaderSource(){this._shaderSource={vertex:this._buildVertexShaderSource(),fragment:this._buildFragmentShaderSource()};}},{key:"_buildVertexShaderSource",value:function _buildVertexShaderSource(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// OcclusionTester vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");}src.push("void main(void) {");src.push("vec4 worldPosition = vec4(position, 1.0); ");src.push(" vec4 viewPosition = viewMatrix * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push(" vec4 clipPos = projMatrix * viewPosition;");src.push(" gl_PointSize = "+POINT_SIZE+".0;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}else{if(scene.markerZOffset<0.000){src.push("clipPos.z += "+scene.markerZOffset+";");}}src.push(" gl_Position = clipPos;");src.push("}");return src;}},{key:"_buildFragmentShaderSource",value:function _buildFragmentShaderSource(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// OcclusionTester fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");for(var _i56=0;_i56<sectionPlanesState.sectionPlanes.length;_i56++){src.push("uniform bool sectionPlaneActive"+_i56+";");src.push("uniform vec3 sectionPlanePos"+_i56+";");src.push("uniform vec3 sectionPlaneDir"+_i56+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" float dist = 0.0;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("if (sectionPlaneActive"+i+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); ");src.push("}");return src;}},{key:"_buildProgram",value:function _buildProgram(){if(this._program){this._program.destroy();}var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var sectionPlanes=sectionPlanesState.sectionPlanes;for(var _i57=0,len=sectionPlanes.length;_i57<len;_i57++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i57),pos:program.getLocation("sectionPlanePos"+_i57),dir:program.getLocation("sectionPlaneDir"+_i57)});}this._aPosition=program.getAttribute("position");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}/**
|
|
4745
4745
|
* Draws {@link Marker}s to the render buffer.
|
|
4746
|
-
*/},{key:"drawMarkers",value:function drawMarkers(){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var sectionPlanesState=scene._sectionPlanesState;var camera=scene.camera;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,camera._project._state.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}for(var _i58=0,len=this._occlusionLayersList.length;_i58<len;_i58++){var occlusionLayer=this._occlusionLayersList[_i58];occlusionLayer.update();if(occlusionLayer.culledBySectionPlanes){continue;}var origin=occlusionLayer.origin;gl.uniformMatrix4fv(this._uViewMatrix,false,createRTCViewMat(camera.viewMatrix,origin));var numSectionPlanes=sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=sectionPlanesState.sectionPlanes;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=occlusionLayer.sectionPlanesActive[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
4746
|
+
*/},{key:"drawMarkers",value:function drawMarkers(){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var sectionPlanesState=scene._sectionPlanesState;var camera=scene.camera;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,camera._project._state.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}for(var _i58=0,len=this._occlusionLayersList.length;_i58<len;_i58++){var occlusionLayer=this._occlusionLayersList[_i58];occlusionLayer.update();if(occlusionLayer.culledBySectionPlanes){continue;}var origin=occlusionLayer.origin;gl.uniformMatrix4fv(this._uViewMatrix,false,createRTCViewMat(camera.viewMatrix,origin));var numSectionPlanes=sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=sectionPlanesState.sectionPlanes;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=occlusionLayer.sectionPlanesActive[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$K));gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}this._aPosition.bindArrayBuffer(occlusionLayer.positionsBuf);var indicesBuf=occlusionLayer.indicesBuf;indicesBuf.bind();gl.drawElements(gl.POINTS,indicesBuf.numItems,indicesBuf.itemType,0);}}/**
|
|
4747
4747
|
* Sets visibilities of {@link Marker}s according to whether or not they are obscured by anything in the render buffer.
|
|
4748
4748
|
*/},{key:"doOcclusionTest",value:function doOcclusionTest(){{var resolutionScale=this._scene.canvas.resolutionScale;var markerR=MARKER_COLOR[0]*255;var markerG=MARKER_COLOR[1]*255;var markerB=MARKER_COLOR[2]*255;for(var _i59=0,len=this._occlusionLayersList.length;_i59<len;_i59++){var occlusionLayer=this._occlusionLayersList[_i59];for(var _i60=0;_i60<occlusionLayer.lenOcclusionTestList;_i60++){var marker=occlusionLayer.occlusionTestList[_i60];var j=_i60*2;var _color=this._readPixelBuf.read(Math.round(occlusionLayer.pixels[j]*resolutionScale),Math.round(occlusionLayer.pixels[j+1]*resolutionScale));var visible=_color[0]===markerR&&_color[1]===markerG&&_color[2]===markerB;marker._setVisible(visible);}}}}/**
|
|
4749
4749
|
* Unbinds render buffer.
|
|
@@ -4870,12 +4870,12 @@ if(selectedFillTransparentBinLen>0){for(i=0;i<selectedFillTransparentBinLen;i++)
|
|
|
4870
4870
|
for(var _ii=0;_ii<numVertexAttribs;_ii++){gl.disableVertexAttribArray(_ii);}}/**
|
|
4871
4871
|
* Picks an Entity.
|
|
4872
4872
|
* @private
|
|
4873
|
-
*/this.pick=function(){var tempVec3a=math.vec3();math.mat4();var tempMat4b=math.mat4();var randomVec3=math.vec3();var up=math.vec3([0,1,0]);var _pickResult=new PickResult();var nearAndFar=math.vec2();var canvasPos=math.vec3();var worldRayOrigin=math.vec3();var worldRayDir=math.vec3();math.vec3();math.vec3();return function(params){var pickResult=arguments.length>1&&arguments[1]!==undefined?arguments[1]:_pickResult;pickResult.reset();updateDrawlist();var look;var pickViewMatrix=null;var pickProjMatrix=null;var projection=null;pickResult.pickSurface=params.pickSurface;if(params.canvasPos){canvasPos[0]=params.canvasPos[0];canvasPos[1]=params.canvasPos[1];pickViewMatrix=scene.camera.viewMatrix;pickProjMatrix=scene.camera.projMatrix;projection=scene.camera.projection;pickResult.canvasPos=params.canvasPos;}else{// Picking with arbitrary World-space ray
|
|
4873
|
+
*/this.pick=function(){var tempVec3a=math.vec3();math.mat4();var tempMat4b=math.mat4();var randomVec3=math.vec3();var up=math.vec3([0,1,0]);var _pickResult=new PickResult();var nearAndFar=math.vec2();var canvasPos=math.vec3();var worldRayOrigin=math.vec3();var worldRayDir=math.vec3();math.vec3();math.vec3();return function(params){var pickResult=arguments.length>1&&arguments[1]!==undefined?arguments[1]:_pickResult;pickResult.reset();updateDrawlist();var look;var pickViewMatrix=null;var pickProjMatrix=null;var projection=null;pickResult.pickSurface=params.pickSurface;if(params.canvasPos){canvasPos[0]=params.canvasPos[0];canvasPos[1]=params.canvasPos[1];pickViewMatrix=scene.camera.viewMatrix;pickProjMatrix=scene.camera.projMatrix;projection=scene.camera.projection;nearAndFar[0]=scene.camera.project.near;nearAndFar[1]=scene.camera.project.far;pickResult.canvasPos=params.canvasPos;}else{// Picking with arbitrary World-space ray
|
|
4874
4874
|
// Align camera along ray and fire ray through center of canvas
|
|
4875
|
-
if(params.matrix){pickViewMatrix=params.matrix;pickProjMatrix=scene.camera.projMatrix;projection=scene.camera.projection;}else{worldRayOrigin.set(params.origin||[0,0,0]);worldRayDir.set(params.direction||[0,0,1]);look=math.addVec3(worldRayOrigin,worldRayDir,tempVec3a);randomVec3[0]=Math.random();randomVec3[1]=Math.random();randomVec3[2]=Math.random();math.normalizeVec3(randomVec3);math.cross3Vec3(worldRayDir,randomVec3,up);pickViewMatrix=math.lookAtMat4v(worldRayOrigin,look,up,tempMat4b);// pickProjMatrix = scene.camera.projMatrix;
|
|
4876
|
-
pickProjMatrix=scene.camera.ortho.matrix;projection="ortho";pickResult.origin=worldRayOrigin;pickResult.direction=worldRayDir;}canvasPos[0]=canvas.clientWidth*0.5;canvasPos[1]=canvas.clientHeight*0.5;}for(var type in drawableTypeInfo){if(drawableTypeInfo.hasOwnProperty(type)){var drawableList=drawableTypeInfo[type].drawableList;for(var _i71=0,len=drawableList.length;_i71<len;_i71++){var drawable=drawableList[_i71];if(drawable.setPickMatrices){// Eg. SceneModel, which needs pre-loading into texture
|
|
4875
|
+
if(params.matrix){pickViewMatrix=params.matrix;pickProjMatrix=scene.camera.projMatrix;projection=scene.camera.projection;nearAndFar[0]=scene.camera.project.near;nearAndFar[1]=scene.camera.project.far;}else{worldRayOrigin.set(params.origin||[0,0,0]);worldRayDir.set(params.direction||[0,0,1]);look=math.addVec3(worldRayOrigin,worldRayDir,tempVec3a);randomVec3[0]=Math.random();randomVec3[1]=Math.random();randomVec3[2]=Math.random();math.normalizeVec3(randomVec3);math.cross3Vec3(worldRayDir,randomVec3,up);pickViewMatrix=math.lookAtMat4v(worldRayOrigin,look,up,tempMat4b);// pickProjMatrix = scene.camera.projMatrix;
|
|
4876
|
+
pickProjMatrix=scene.camera.ortho.matrix;projection="ortho";nearAndFar[0]=scene.camera.ortho.near;nearAndFar[1]=scene.camera.ortho.far;pickResult.origin=worldRayOrigin;pickResult.direction=worldRayDir;}canvasPos[0]=canvas.clientWidth*0.5;canvasPos[1]=canvas.clientHeight*0.5;}for(var type in drawableTypeInfo){if(drawableTypeInfo.hasOwnProperty(type)){var drawableList=drawableTypeInfo[type].drawableList;for(var _i71=0,len=drawableList.length;_i71<len;_i71++){var drawable=drawableList[_i71];if(drawable.setPickMatrices){// Eg. SceneModel, which needs pre-loading into texture
|
|
4877
4877
|
drawable.setPickMatrices(pickViewMatrix,pickProjMatrix);}}}}var pickBuffer=renderBufferManager.getRenderBuffer("pick",{size:[1,1]});pickBuffer.bind();var pickable=gpuPickPickable(pickBuffer,canvasPos,pickViewMatrix,pickProjMatrix,params,pickResult);if(!pickable){pickBuffer.unbind();return null;}var pickedEntity=pickable.delegatePickedEntity?pickable.delegatePickedEntity():pickable;if(!pickedEntity){pickBuffer.unbind();return null;}if(params.pickSurface){// GPU-based ray-picking
|
|
4878
|
-
if(pickable.canPickTriangle&&pickable.canPickTriangle()){gpuPickTriangle(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult);pickable.pickTriangleSurface(pickViewMatrix,pickProjMatrix,projection,pickResult);pickResult.pickSurfacePrecision=false;}else{if(pickable.canPickWorldPos&&pickable.canPickWorldPos()){
|
|
4878
|
+
if(pickable.canPickTriangle&&pickable.canPickTriangle()){gpuPickTriangle(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult);pickable.pickTriangleSurface(pickViewMatrix,pickProjMatrix,projection,pickResult);pickResult.pickSurfacePrecision=false;}else{if(pickable.canPickWorldPos&&pickable.canPickWorldPos()){gpuPickWorldPos(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,nearAndFar,pickResult);if(params.pickSurfaceNormal!==false){gpuPickWorldNormal(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult);}pickResult.pickSurfacePrecision=false;}}}pickBuffer.unbind();pickResult.entity=pickedEntity;return pickResult;};}();function gpuPickPickable(pickBuffer,canvasPos,pickViewMatrix,pickProjMatrix,params,pickResult){var resolutionScale=scene.canvas.resolutionScale;frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
|
|
4879
4879
|
frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;frameCtx.pickProjMatrix=pickProjMatrix;frameCtx.pickInvisible=!!params.pickInvisible;frameCtx.pickClipPos=[getClipPosX(canvasPos[0]*resolutionScale,gl.drawingBufferWidth),getClipPosY(canvasPos[1]*resolutionScale,gl.drawingBufferHeight)];gl.viewport(0,0,1,1);gl.depthMask(true);gl.enable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);var includeEntityIds=params.includeEntityIds;var excludeEntityIds=params.excludeEntityIds;for(var _i72=0,len=postCullDrawableList.length;_i72<len;_i72++){var drawable=postCullDrawableList[_i72];if(drawable.culled===true||drawable.visible===false){continue;}if(!drawable.drawPickMesh||params.pickInvisible!==true&&drawable.visible===false||drawable.pickable===false){continue;}if(includeEntityIds&&!includeEntityIds[drawable.id]){// TODO: push this logic into drawable
|
|
4880
4880
|
continue;}if(excludeEntityIds&&excludeEntityIds[drawable.id]){continue;}drawable.drawPickMesh(frameCtx);}var pix=pickBuffer.read(0,0);var pickID=pix[0]+(pix[1]<<8)+(pix[2]<<16)+(pix[3]<<24);if(pickID<0){return;}var pickable=pickIDs.items[pickID];return pickable;}function gpuPickTriangle(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult){if(!pickable.drawPickTriangles){return;}var resolutionScale=scene.canvas.resolutionScale;frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
|
|
4881
4881
|
frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;// Can be null
|
|
@@ -6182,7 +6182,7 @@ _this45.left=cfg.left;_this45.right=cfg.right;_this45.bottom=cfg.bottom;_this45.
|
|
|
6182
6182
|
* @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates.
|
|
6183
6183
|
*/},{key:"unproject",value:function unproject(canvasPos,screenZ,screenPos,viewPos,worldPos){var canvas=this.scene.canvas.canvas;var halfCanvasWidth=canvas.offsetWidth/2.0;var halfCanvasHeight=canvas.offsetHeight/2.0;screenPos[0]=(canvasPos[0]-halfCanvasWidth)/halfCanvasWidth;screenPos[1]=(canvasPos[1]-halfCanvasHeight)/halfCanvasHeight;screenPos[2]=screenZ;screenPos[3]=1.0;math.mulMat4v4(this.inverseMatrix,screenPos,viewPos);math.mulVec3Scalar(viewPos,1.0/viewPos[3]);viewPos[3]=1.0;viewPos[1]*=-1;math.mulMat4v4(this.camera.inverseViewMatrix,viewPos,worldPos);return worldPos;}/** @private
|
|
6184
6184
|
*
|
|
6185
|
-
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(CustomProjection.prototype),"destroy",this).call(this);this._state.destroy();}}]);return CustomProjection;}(Component);var tempVec3$6=math.vec3();var tempVec3b$
|
|
6185
|
+
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(CustomProjection.prototype),"destroy",this).call(this);this._state.destroy();}}]);return CustomProjection;}(Component);var tempVec3$6=math.vec3();var tempVec3b$z=math.vec3();var tempVec3c$u=math.vec3();var tempVec3d$d=math.vec3();var tempVec3e$2=math.vec3();var tempVec3f$2=math.vec3();var tempVec4a$b=math.vec4();var tempVec4b$6=math.vec4();var tempVec4c$2=math.vec4();var tempMat=math.mat4();var tempMatb=math.mat4();var eyeLookVec=math.vec3();var eyeLookVecNorm=math.vec3();var eyeLookOffset=math.vec3();var offsetEye=math.vec3();/**
|
|
6186
6186
|
* @desc Manages viewing and projection transforms for its {@link Scene}.
|
|
6187
6187
|
*
|
|
6188
6188
|
* * One Camera per {@link Scene}
|
|
@@ -6385,29 +6385,29 @@ var eye;if(this.projection==="ortho"){math.subVec3(this._eye,this._look,eyeLookV
|
|
|
6385
6385
|
* Rotates {@link Camera#eye} about {@link Camera#look}, around the {@link Camera#up} vector
|
|
6386
6386
|
*
|
|
6387
6387
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
6388
|
-
*/},{key:"orbitYaw",value:function orbitYaw(angleInc){var lookEyeVec=math.subVec3(this._eye,this._look,tempVec3$6);math.rotationMat4v(angleInc*0.0174532925,this._gimbalLock?this._worldUp:this._up,tempMat);lookEyeVec=math.transformPoint3(tempMat,lookEyeVec,tempVec3b$
|
|
6388
|
+
*/},{key:"orbitYaw",value:function orbitYaw(angleInc){var lookEyeVec=math.subVec3(this._eye,this._look,tempVec3$6);math.rotationMat4v(angleInc*0.0174532925,this._gimbalLock?this._worldUp:this._up,tempMat);lookEyeVec=math.transformPoint3(tempMat,lookEyeVec,tempVec3b$z);this.eye=math.addVec3(this._look,lookEyeVec,tempVec3c$u);// Set eye position as 'look' plus 'eye' vector
|
|
6389
6389
|
this.up=math.transformPoint3(tempMat,this._up,tempVec3d$d);// Rotate 'up' vector
|
|
6390
6390
|
}/**
|
|
6391
6391
|
* Rotates {@link Camera#eye} about {@link Camera#look} around the right axis (orthogonal to {@link Camera#up} and "look").
|
|
6392
6392
|
*
|
|
6393
6393
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
6394
|
-
*/},{key:"orbitPitch",value:function orbitPitch(angleInc){if(this._constrainPitch){angleInc=math.dotVec3(this._up,this._worldUp)/math.DEGTORAD;if(angleInc<1){return;}}var eye2=math.subVec3(this._eye,this._look,tempVec3$6);var left=math.cross3Vec3(math.normalizeVec3(eye2,tempVec3b$
|
|
6394
|
+
*/},{key:"orbitPitch",value:function orbitPitch(angleInc){if(this._constrainPitch){angleInc=math.dotVec3(this._up,this._worldUp)/math.DEGTORAD;if(angleInc<1){return;}}var eye2=math.subVec3(this._eye,this._look,tempVec3$6);var left=math.cross3Vec3(math.normalizeVec3(eye2,tempVec3b$z),math.normalizeVec3(this._up,tempVec3c$u));math.rotationMat4v(angleInc*0.0174532925,left,tempMat);eye2=math.transformPoint3(tempMat,eye2,tempVec3d$d);this.up=math.transformPoint3(tempMat,this._up,tempVec3e$2);this.eye=math.addVec3(eye2,this._look,tempVec3f$2);}/**
|
|
6395
6395
|
* Rotates {@link Camera#look} about {@link Camera#eye}, around the {@link Camera#up} vector.
|
|
6396
6396
|
*
|
|
6397
6397
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
6398
|
-
*/},{key:"yaw",value:function yaw(angleInc){var look2=math.subVec3(this._look,this._eye,tempVec3$6);math.rotationMat4v(angleInc*0.0174532925,this._gimbalLock?this._worldUp:this._up,tempMat);look2=math.transformPoint3(tempMat,look2,tempVec3b$
|
|
6398
|
+
*/},{key:"yaw",value:function yaw(angleInc){var look2=math.subVec3(this._look,this._eye,tempVec3$6);math.rotationMat4v(angleInc*0.0174532925,this._gimbalLock?this._worldUp:this._up,tempMat);look2=math.transformPoint3(tempMat,look2,tempVec3b$z);this.look=math.addVec3(look2,this._eye,tempVec3c$u);if(this._gimbalLock){this.up=math.transformPoint3(tempMat,this._up,tempVec3d$d);}}/**
|
|
6399
6399
|
* Rotates {@link Camera#look} about {@link Camera#eye}, around the right axis (orthogonal to {@link Camera#up} and "look").
|
|
6400
6400
|
|
|
6401
6401
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
6402
|
-
*/},{key:"pitch",value:function pitch(angleInc){if(this._constrainPitch){angleInc=math.dotVec3(this._up,this._worldUp)/math.DEGTORAD;if(angleInc<1){return;}}var look2=math.subVec3(this._look,this._eye,tempVec3$6);var left=math.cross3Vec3(math.normalizeVec3(look2,tempVec3b$
|
|
6402
|
+
*/},{key:"pitch",value:function pitch(angleInc){if(this._constrainPitch){angleInc=math.dotVec3(this._up,this._worldUp)/math.DEGTORAD;if(angleInc<1){return;}}var look2=math.subVec3(this._look,this._eye,tempVec3$6);var left=math.cross3Vec3(math.normalizeVec3(look2,tempVec3b$z),math.normalizeVec3(this._up,tempVec3c$u));math.rotationMat4v(angleInc*0.0174532925,left,tempMat);this.up=math.transformPoint3(tempMat,this._up,tempVec3f$2);look2=math.transformPoint3(tempMat,look2,tempVec3d$d);this.look=math.addVec3(look2,this._eye,tempVec3e$2);}/**
|
|
6403
6403
|
* Pans the Camera along its local X, Y and Z axis.
|
|
6404
6404
|
*
|
|
6405
6405
|
* @param pan The pan vector
|
|
6406
|
-
*/},{key:"pan",value:function pan(_pan){var eye2=math.subVec3(this._eye,this._look,tempVec3$6);var vec=[0,0,0];var v;if(_pan[0]!==0){var left=math.cross3Vec3(math.normalizeVec3(eye2,[]),math.normalizeVec3(this._up,tempVec3b$
|
|
6406
|
+
*/},{key:"pan",value:function pan(_pan){var eye2=math.subVec3(this._eye,this._look,tempVec3$6);var vec=[0,0,0];var v;if(_pan[0]!==0){var left=math.cross3Vec3(math.normalizeVec3(eye2,[]),math.normalizeVec3(this._up,tempVec3b$z));v=math.mulVec3Scalar(left,_pan[0]);vec[0]+=v[0];vec[1]+=v[1];vec[2]+=v[2];}if(_pan[1]!==0){v=math.mulVec3Scalar(math.normalizeVec3(this._up,tempVec3c$u),_pan[1]);vec[0]+=v[0];vec[1]+=v[1];vec[2]+=v[2];}if(_pan[2]!==0){v=math.mulVec3Scalar(math.normalizeVec3(eye2,tempVec3d$d),_pan[2]);vec[0]+=v[0];vec[1]+=v[1];vec[2]+=v[2];}this.eye=math.addVec3(this._eye,vec,tempVec3e$2);this.look=math.addVec3(this._look,vec,tempVec3f$2);}/**
|
|
6407
6407
|
* Increments/decrements the Camera's zoom factor, which is the distance between {@link Camera#eye} and {@link Camera#look}.
|
|
6408
6408
|
*
|
|
6409
6409
|
* @param {Number} delta Zoom factor increment.
|
|
6410
|
-
*/},{key:"zoom",value:function zoom(delta){var vec=math.subVec3(this._eye,this._look,tempVec3$6);var lenLook=Math.abs(math.lenVec3(vec,tempVec3b$
|
|
6410
|
+
*/},{key:"zoom",value:function zoom(delta){var vec=math.subVec3(this._eye,this._look,tempVec3$6);var lenLook=Math.abs(math.lenVec3(vec,tempVec3b$z));var newLenLook=Math.abs(lenLook+delta);if(newLenLook<0.5){return;}var dir=math.normalizeVec3(vec,tempVec3c$u);this.eye=math.addVec3(this._look,math.mulVec3Scalar(dir,newLenLook),tempVec3d$d);}/**
|
|
6411
6411
|
* Sets the position of the Camera's eye.
|
|
6412
6412
|
*
|
|
6413
6413
|
* Default value is ````[0,0,10]````.
|
|
@@ -6629,7 +6629,7 @@ this.fire("dirty");this.fire("projection",this._projectionType);this.fire("projM
|
|
|
6629
6629
|
*
|
|
6630
6630
|
* @param {[number, number, number]} worldPos
|
|
6631
6631
|
* @returns {[number, number]} the canvas position
|
|
6632
|
-
*/},{key:"projectWorldPos",value:function projectWorldPos(worldPos){var _worldPos=tempVec4a$
|
|
6632
|
+
*/},{key:"projectWorldPos",value:function projectWorldPos(worldPos){var _worldPos=tempVec4a$b;var viewPos=tempVec4b$6;var screenPos=tempVec4c$2;_worldPos[0]=worldPos[0];_worldPos[1]=worldPos[1];_worldPos[2]=worldPos[2];_worldPos[3]=1;math.mulMat4v4(this.viewMatrix,_worldPos,viewPos);math.mulMat4v4(this.projMatrix,viewPos,screenPos);math.mulVec3Scalar(screenPos,1.0/screenPos[3]);screenPos[3]=1.0;screenPos[1]*=-1;var canvas=this.scene.canvas.canvas;var halfCanvasWidth=canvas.offsetWidth/2.0;var halfCanvasHeight=canvas.offsetHeight/2.0;var canvasPos=[screenPos[0]*halfCanvasWidth+halfCanvasWidth,screenPos[1]*halfCanvasHeight+halfCanvasHeight];return canvasPos;}/**
|
|
6633
6633
|
* Destroys this Camera.
|
|
6634
6634
|
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(Camera.prototype),"destroy",this).call(this);this._state.destroy();}}]);return Camera;}(Component);/**
|
|
6635
6635
|
* @desc A dynamic light source within a {@link Scene}.
|
|
@@ -6739,7 +6739,7 @@ this.fire("dirty");this.fire("projection",this._projectionType);this.fire("projM
|
|
|
6739
6739
|
* @param {Number} [cfg.intensity=1.0] The intensity of this DirLight, as a factor in range ````[0..1]````.
|
|
6740
6740
|
* @param {String} [cfg.space="view"] The coordinate system the DirLight is defined in - ````"view"```` or ````"space"````.
|
|
6741
6741
|
* @param {Boolean} [cfg.castsShadow=false] Flag which indicates if this DirLight casts a castsShadow.
|
|
6742
|
-
*/function DirLight(owner){var _this48;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,DirLight);_this48=_super26.call(this,owner,cfg);_this48._shadowRenderBuf=null;_this48._shadowViewMatrix=null;_this48._shadowProjMatrix=null;_this48._shadowViewMatrixDirty=true;_this48._shadowProjMatrixDirty=true;var camera=_this48.scene.camera;var canvas=_this48.scene.canvas;_this48._onCameraViewMatrix=camera.on("viewMatrix",function(){_this48._shadowViewMatrixDirty=true;});_this48._onCameraProjMatrix=camera.on("projMatrix",function(){_this48._shadowProjMatrixDirty=true;});_this48._onCanvasBoundary=canvas.on("boundary",function(){_this48._shadowProjMatrixDirty=true;});_this48._state=new RenderState({type:"dir",dir:math.vec3([1.0,1.0,1.0]),color:math.vec3([0.7,0.7,0.8]),intensity:1.0,space:cfg.space||"view",castsShadow:false,getShadowViewMatrix:function getShadowViewMatrix(){if(_this48._shadowViewMatrixDirty){if(!_this48._shadowViewMatrix){_this48._shadowViewMatrix=math.identityMat4();}var _camera=_this48.scene.camera;var dir=_this48._state.dir;var look=_camera.look;var eye=[look[0]-dir[0],look[1]-dir[1],look[2]-dir[2]];var
|
|
6742
|
+
*/function DirLight(owner){var _this48;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,DirLight);_this48=_super26.call(this,owner,cfg);_this48._shadowRenderBuf=null;_this48._shadowViewMatrix=null;_this48._shadowProjMatrix=null;_this48._shadowViewMatrixDirty=true;_this48._shadowProjMatrixDirty=true;var camera=_this48.scene.camera;var canvas=_this48.scene.canvas;_this48._onCameraViewMatrix=camera.on("viewMatrix",function(){_this48._shadowViewMatrixDirty=true;});_this48._onCameraProjMatrix=camera.on("projMatrix",function(){_this48._shadowProjMatrixDirty=true;});_this48._onCanvasBoundary=canvas.on("boundary",function(){_this48._shadowProjMatrixDirty=true;});_this48._state=new RenderState({type:"dir",dir:math.vec3([1.0,1.0,1.0]),color:math.vec3([0.7,0.7,0.8]),intensity:1.0,space:cfg.space||"view",castsShadow:false,getShadowViewMatrix:function getShadowViewMatrix(){if(_this48._shadowViewMatrixDirty){if(!_this48._shadowViewMatrix){_this48._shadowViewMatrix=math.identityMat4();}var _camera=_this48.scene.camera;var dir=_this48._state.dir;var look=_camera.look;var eye=[look[0]-dir[0],look[1]-dir[1],look[2]-dir[2]];var _up=[0,1,0];math.lookAtMat4v(eye,look,_up,_this48._shadowViewMatrix);_this48._shadowViewMatrixDirty=false;}return _this48._shadowViewMatrix;},getShadowProjMatrix:function getShadowProjMatrix(){if(_this48._shadowProjMatrixDirty){// TODO: Set when canvas resizes
|
|
6743
6743
|
if(!_this48._shadowProjMatrix){_this48._shadowProjMatrix=math.identityMat4();}math.orthoMat4c(-40,40,-40,40,-40.0,80,_this48._shadowProjMatrix);// left, right, bottom, top, near, far, dest
|
|
6744
6744
|
_this48._shadowProjMatrixDirty=false;}return _this48._shadowProjMatrix;},getShadowRenderBuf:function getShadowRenderBuf(){if(!_this48._shadowRenderBuf){_this48._shadowRenderBuf=new RenderBuffer(_this48.scene.canvas.canvas,_this48.scene.canvas.gl,{size:[1024,1024]});// Super old mobile devices have a limit of 1024x1024 textures
|
|
6745
6745
|
}return _this48._shadowRenderBuf;}});_this48.dir=cfg.dir;_this48.color=cfg.color;_this48.intensity=cfg.intensity;_this48.castsShadow=cfg.castsShadow;_this48.scene._lightCreated(_assertThisInitialized(_this48));return _this48;}/**
|
|
@@ -10341,9 +10341,9 @@ if(phongMaterial){src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbien
|
|
|
10341
10341
|
//--------------------------------------------------------------------------------
|
|
10342
10342
|
src.push("ambientColor *= (lightAmbient.rgb * lightAmbient.a);");src.push("vec3 outgoingLight = emissiveColor + ambientColor;");}src.push("vec4 fragColor = vec4(outgoingLight, alpha) * colorize;");if(gammaOutput){src.push("fragColor = linearToGamma(fragColor, gammaFactor);");}src.push("outColor = fragColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}/**
|
|
10343
10343
|
* @author xeolabs / https://github.com/xeolabs
|
|
10344
|
-
*/var tempVec3a$
|
|
10344
|
+
*/var tempVec3a$J=math.vec3();var ids$2=new Map$1({});/**
|
|
10345
10345
|
* @private
|
|
10346
|
-
*/var DrawRenderer=function DrawRenderer(hash,mesh){this.id=ids$2.addItem({});this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new DrawShaderSource(mesh);this._allocate(mesh);};var drawRenderers={};DrawRenderer.get=function(mesh){var scene=mesh.scene;var hash=[scene.canvas.canvas.id,(scene.gammaInput?"gi;":";")+(scene.gammaOutput?"go":""),scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._material._state.hash,mesh._state.drawHash].join(";");var renderer=drawRenderers[hash];if(!renderer){renderer=new DrawRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}drawRenderers[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};DrawRenderer.prototype.put=function(){if(--this._useCount===0){ids$2.removeItem(this.id);if(this._program){this._program.destroy();}delete drawRenderers[this._hash];stats.memory.programs--;}};DrawRenderer.prototype.webglContextRestored=function(){this._program=null;};DrawRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=mesh.scene;var material=mesh._material;var gl=scene.canvas.gl;var program=this._program;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var camera=scene.camera;var origin=mesh.origin;var background=meshState.background;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;if(background){gl.depthFunc(gl.LEQUAL);}this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$I);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}if(materialState.id!==this._lastMaterialId){frameCtx.textureUnit=this._baseTextureUnit;var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}var frontface=materialState.frontface;if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}if(frameCtx.lineWidth!==materialState.lineWidth){gl.lineWidth(materialState.lineWidth);frameCtx.lineWidth=materialState.lineWidth;}if(this._uPointSize){gl.uniform1f(this._uPointSize,materialState.pointSize);}switch(materialState.type){case"LambertMaterial":if(this._uMaterialAmbient){gl.uniform3fv(this._uMaterialAmbient,materialState.ambient);}if(this._uMaterialColor){gl.uniform4f(this._uMaterialColor,materialState.color[0],materialState.color[1],materialState.color[2],materialState.alpha);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}break;case"PhongMaterial":if(this._uMaterialShininess){gl.uniform1f(this._uMaterialShininess,materialState.shininess);}if(this._uMaterialAmbient){gl.uniform3fv(this._uMaterialAmbient,materialState.ambient);}if(this._uMaterialDiffuse){gl.uniform3fv(this._uMaterialDiffuse,materialState.diffuse);}if(this._uMaterialSpecular){gl.uniform3fv(this._uMaterialSpecular,materialState.specular);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0);}if(material._ambientMap&&material._ambientMap._state.texture&&this._uMaterialAmbientMap){program.bindTexture(this._uMaterialAmbientMap,material._ambientMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMaterialAmbientMapMatrix){gl.uniformMatrix4fv(this._uMaterialAmbientMapMatrix,false,material._ambientMap._state.matrix);}}if(material._diffuseMap&&material._diffuseMap._state.texture&&this._uDiffuseMap){program.bindTexture(this._uDiffuseMap,material._diffuseMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uDiffuseMapMatrix){gl.uniformMatrix4fv(this._uDiffuseMapMatrix,false,material._diffuseMap._state.matrix);}}if(material._specularMap&&material._specularMap._state.texture&&this._uSpecularMap){program.bindTexture(this._uSpecularMap,material._specularMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularMapMatrix){gl.uniformMatrix4fv(this._uSpecularMapMatrix,false,material._specularMap._state.matrix);}}if(material._emissiveMap&&material._emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,material._emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,material._emissiveMap._state.matrix);}}if(material._alphaMap&&material._alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,material._alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,material._alphaMap._state.matrix);}}if(material._reflectivityMap&&material._reflectivityMap._state.texture&&this._uReflectivityMap){program.bindTexture(this._uReflectivityMap,material._reflectivityMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;if(this._uReflectivityMapMatrix){gl.uniformMatrix4fv(this._uReflectivityMapMatrix,false,material._reflectivityMap._state.matrix);}}if(material._normalMap&&material._normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,material._normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,material._normalMap._state.matrix);}}if(material._occlusionMap&&material._occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,material._occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,material._occlusionMap._state.matrix);}}if(material._diffuseFresnel){if(this._uDiffuseFresnelEdgeBias){gl.uniform1f(this._uDiffuseFresnelEdgeBias,material._diffuseFresnel.edgeBias);}if(this._uDiffuseFresnelCenterBias){gl.uniform1f(this._uDiffuseFresnelCenterBias,material._diffuseFresnel.centerBias);}if(this._uDiffuseFresnelEdgeColor){gl.uniform3fv(this._uDiffuseFresnelEdgeColor,material._diffuseFresnel.edgeColor);}if(this._uDiffuseFresnelCenterColor){gl.uniform3fv(this._uDiffuseFresnelCenterColor,material._diffuseFresnel.centerColor);}if(this._uDiffuseFresnelPower){gl.uniform1f(this._uDiffuseFresnelPower,material._diffuseFresnel.power);}}if(material._specularFresnel){if(this._uSpecularFresnelEdgeBias){gl.uniform1f(this._uSpecularFresnelEdgeBias,material._specularFresnel.edgeBias);}if(this._uSpecularFresnelCenterBias){gl.uniform1f(this._uSpecularFresnelCenterBias,material._specularFresnel.centerBias);}if(this._uSpecularFresnelEdgeColor){gl.uniform3fv(this._uSpecularFresnelEdgeColor,material._specularFresnel.edgeColor);}if(this._uSpecularFresnelCenterColor){gl.uniform3fv(this._uSpecularFresnelCenterColor,material._specularFresnel.centerColor);}if(this._uSpecularFresnelPower){gl.uniform1f(this._uSpecularFresnelPower,material._specularFresnel.power);}}if(material._alphaFresnel){if(this._uAlphaFresnelEdgeBias){gl.uniform1f(this._uAlphaFresnelEdgeBias,material._alphaFresnel.edgeBias);}if(this._uAlphaFresnelCenterBias){gl.uniform1f(this._uAlphaFresnelCenterBias,material._alphaFresnel.centerBias);}if(this._uAlphaFresnelEdgeColor){gl.uniform3fv(this._uAlphaFresnelEdgeColor,material._alphaFresnel.edgeColor);}if(this._uAlphaFresnelCenterColor){gl.uniform3fv(this._uAlphaFresnelCenterColor,material._alphaFresnel.centerColor);}if(this._uAlphaFresnelPower){gl.uniform1f(this._uAlphaFresnelPower,material._alphaFresnel.power);}}if(material._reflectivityFresnel){if(this._uReflectivityFresnelEdgeBias){gl.uniform1f(this._uReflectivityFresnelEdgeBias,material._reflectivityFresnel.edgeBias);}if(this._uReflectivityFresnelCenterBias){gl.uniform1f(this._uReflectivityFresnelCenterBias,material._reflectivityFresnel.centerBias);}if(this._uReflectivityFresnelEdgeColor){gl.uniform3fv(this._uReflectivityFresnelEdgeColor,material._reflectivityFresnel.edgeColor);}if(this._uReflectivityFresnelCenterColor){gl.uniform3fv(this._uReflectivityFresnelCenterColor,material._reflectivityFresnel.centerColor);}if(this._uReflectivityFresnelPower){gl.uniform1f(this._uReflectivityFresnelPower,material._reflectivityFresnel.power);}}if(material._emissiveFresnel){if(this._uEmissiveFresnelEdgeBias){gl.uniform1f(this._uEmissiveFresnelEdgeBias,material._emissiveFresnel.edgeBias);}if(this._uEmissiveFresnelCenterBias){gl.uniform1f(this._uEmissiveFresnelCenterBias,material._emissiveFresnel.centerBias);}if(this._uEmissiveFresnelEdgeColor){gl.uniform3fv(this._uEmissiveFresnelEdgeColor,material._emissiveFresnel.edgeColor);}if(this._uEmissiveFresnelCenterColor){gl.uniform3fv(this._uEmissiveFresnelCenterColor,material._emissiveFresnel.centerColor);}if(this._uEmissiveFresnelPower){gl.uniform1f(this._uEmissiveFresnelPower,material._emissiveFresnel.power);}}break;case"MetallicMaterial":if(this._uBaseColor){gl.uniform3fv(this._uBaseColor,materialState.baseColor);}if(this._uMaterialMetallic){gl.uniform1f(this._uMaterialMetallic,materialState.metallic);}if(this._uMaterialRoughness){gl.uniform1f(this._uMaterialRoughness,materialState.roughness);}if(this._uMaterialSpecularF0){gl.uniform1f(this._uMaterialSpecularF0,materialState.specularF0);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0.0);}var baseColorMap=material._baseColorMap;if(baseColorMap&&baseColorMap._state.texture&&this._uBaseColorMap){program.bindTexture(this._uBaseColorMap,baseColorMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uBaseColorMapMatrix){gl.uniformMatrix4fv(this._uBaseColorMapMatrix,false,baseColorMap._state.matrix);}}var metallicMap=material._metallicMap;if(metallicMap&&metallicMap._state.texture&&this._uMetallicMap){program.bindTexture(this._uMetallicMap,metallicMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMetallicMapMatrix){gl.uniformMatrix4fv(this._uMetallicMapMatrix,false,metallicMap._state.matrix);}}var roughnessMap=material._roughnessMap;if(roughnessMap&&roughnessMap._state.texture&&this._uRoughnessMap){program.bindTexture(this._uRoughnessMap,roughnessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uRoughnessMapMatrix){gl.uniformMatrix4fv(this._uRoughnessMapMatrix,false,roughnessMap._state.matrix);}}var metallicRoughnessMap=material._metallicRoughnessMap;if(metallicRoughnessMap&&metallicRoughnessMap._state.texture&&this._uMetallicRoughnessMap){program.bindTexture(this._uMetallicRoughnessMap,metallicRoughnessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMetallicRoughnessMapMatrix){gl.uniformMatrix4fv(this._uMetallicRoughnessMapMatrix,false,metallicRoughnessMap._state.matrix);}}var emissiveMap=material._emissiveMap;if(emissiveMap&&emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,emissiveMap._state.matrix);}}var occlusionMap=material._occlusionMap;if(occlusionMap&&material._occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,occlusionMap._state.matrix);}}var alphaMap=material._alphaMap;if(alphaMap&&alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,alphaMap._state.matrix);}}var normalMap=material._normalMap;if(normalMap&&normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,normalMap._state.matrix);}}break;case"SpecularMaterial":if(this._uMaterialDiffuse){gl.uniform3fv(this._uMaterialDiffuse,materialState.diffuse);}if(this._uMaterialSpecular){gl.uniform3fv(this._uMaterialSpecular,materialState.specular);}if(this._uMaterialGlossiness){gl.uniform1f(this._uMaterialGlossiness,materialState.glossiness);}if(this._uMaterialReflectivity){gl.uniform1f(this._uMaterialReflectivity,materialState.reflectivity);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0.0);}var diffuseMap=material._diffuseMap;if(diffuseMap&&diffuseMap._state.texture&&this._uDiffuseMap){program.bindTexture(this._uDiffuseMap,diffuseMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uDiffuseMapMatrix){gl.uniformMatrix4fv(this._uDiffuseMapMatrix,false,diffuseMap._state.matrix);}}var specularMap=material._specularMap;if(specularMap&&specularMap._state.texture&&this._uSpecularMap){program.bindTexture(this._uSpecularMap,specularMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularMapMatrix){gl.uniformMatrix4fv(this._uSpecularMapMatrix,false,specularMap._state.matrix);}}var glossinessMap=material._glossinessMap;if(glossinessMap&&glossinessMap._state.texture&&this._uGlossinessMap){program.bindTexture(this._uGlossinessMap,glossinessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uGlossinessMapMatrix){gl.uniformMatrix4fv(this._uGlossinessMapMatrix,false,glossinessMap._state.matrix);}}var specularGlossinessMap=material._specularGlossinessMap;if(specularGlossinessMap&&specularGlossinessMap._state.texture&&this._uSpecularGlossinessMap){program.bindTexture(this._uSpecularGlossinessMap,specularGlossinessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularGlossinessMapMatrix){gl.uniformMatrix4fv(this._uSpecularGlossinessMapMatrix,false,specularGlossinessMap._state.matrix);}}var emissiveMap=material._emissiveMap;if(emissiveMap&&emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,emissiveMap._state.matrix);}}var occlusionMap=material._occlusionMap;if(occlusionMap&&occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,occlusionMap._state.matrix);}}var alphaMap=material._alphaMap;if(alphaMap&&alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,alphaMap._state.matrix);}}var normalMap=material._normalMap;if(normalMap&&normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,normalMap._state.matrix);}}break;}this._lastMaterialId=materialState.id;}gl.uniformMatrix4fv(this._uModelMatrix,gl.FALSE,mesh.worldMatrix);if(this._uModelNormalMatrix){gl.uniformMatrix4fv(this._uModelNormalMatrix,gl.FALSE,mesh.worldNormalMatrix);}if(this._uClippable){gl.uniform1i(this._uClippable,meshState.clippable);}if(this._uColorize){var colorize=meshState.colorize;var lastColorize=this._lastColorize;if(lastColorize[0]!==colorize[0]||lastColorize[1]!==colorize[1]||lastColorize[2]!==colorize[2]||lastColorize[3]!==colorize[3]){gl.uniform4fv(this._uColorize,colorize);lastColorize[0]=colorize[0];lastColorize[1]=colorize[1];lastColorize[2]=colorize[2];lastColorize[3]=colorize[3];}}gl.uniform3fv(this._uOffset,meshState.offset);// Bind VBOs
|
|
10346
|
+
*/var DrawRenderer=function DrawRenderer(hash,mesh){this.id=ids$2.addItem({});this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new DrawShaderSource(mesh);this._allocate(mesh);};var drawRenderers={};DrawRenderer.get=function(mesh){var scene=mesh.scene;var hash=[scene.canvas.canvas.id,(scene.gammaInput?"gi;":";")+(scene.gammaOutput?"go":""),scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._material._state.hash,mesh._state.drawHash].join(";");var renderer=drawRenderers[hash];if(!renderer){renderer=new DrawRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}drawRenderers[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};DrawRenderer.prototype.put=function(){if(--this._useCount===0){ids$2.removeItem(this.id);if(this._program){this._program.destroy();}delete drawRenderers[this._hash];stats.memory.programs--;}};DrawRenderer.prototype.webglContextRestored=function(){this._program=null;};DrawRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=mesh.scene;var material=mesh._material;var gl=scene.canvas.gl;var program=this._program;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var camera=scene.camera;var origin=mesh.origin;var background=meshState.background;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;if(background){gl.depthFunc(gl.LEQUAL);}this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$J);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}if(materialState.id!==this._lastMaterialId){frameCtx.textureUnit=this._baseTextureUnit;var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}var frontface=materialState.frontface;if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}if(frameCtx.lineWidth!==materialState.lineWidth){gl.lineWidth(materialState.lineWidth);frameCtx.lineWidth=materialState.lineWidth;}if(this._uPointSize){gl.uniform1f(this._uPointSize,materialState.pointSize);}switch(materialState.type){case"LambertMaterial":if(this._uMaterialAmbient){gl.uniform3fv(this._uMaterialAmbient,materialState.ambient);}if(this._uMaterialColor){gl.uniform4f(this._uMaterialColor,materialState.color[0],materialState.color[1],materialState.color[2],materialState.alpha);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}break;case"PhongMaterial":if(this._uMaterialShininess){gl.uniform1f(this._uMaterialShininess,materialState.shininess);}if(this._uMaterialAmbient){gl.uniform3fv(this._uMaterialAmbient,materialState.ambient);}if(this._uMaterialDiffuse){gl.uniform3fv(this._uMaterialDiffuse,materialState.diffuse);}if(this._uMaterialSpecular){gl.uniform3fv(this._uMaterialSpecular,materialState.specular);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0);}if(material._ambientMap&&material._ambientMap._state.texture&&this._uMaterialAmbientMap){program.bindTexture(this._uMaterialAmbientMap,material._ambientMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMaterialAmbientMapMatrix){gl.uniformMatrix4fv(this._uMaterialAmbientMapMatrix,false,material._ambientMap._state.matrix);}}if(material._diffuseMap&&material._diffuseMap._state.texture&&this._uDiffuseMap){program.bindTexture(this._uDiffuseMap,material._diffuseMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uDiffuseMapMatrix){gl.uniformMatrix4fv(this._uDiffuseMapMatrix,false,material._diffuseMap._state.matrix);}}if(material._specularMap&&material._specularMap._state.texture&&this._uSpecularMap){program.bindTexture(this._uSpecularMap,material._specularMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularMapMatrix){gl.uniformMatrix4fv(this._uSpecularMapMatrix,false,material._specularMap._state.matrix);}}if(material._emissiveMap&&material._emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,material._emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,material._emissiveMap._state.matrix);}}if(material._alphaMap&&material._alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,material._alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,material._alphaMap._state.matrix);}}if(material._reflectivityMap&&material._reflectivityMap._state.texture&&this._uReflectivityMap){program.bindTexture(this._uReflectivityMap,material._reflectivityMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;if(this._uReflectivityMapMatrix){gl.uniformMatrix4fv(this._uReflectivityMapMatrix,false,material._reflectivityMap._state.matrix);}}if(material._normalMap&&material._normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,material._normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,material._normalMap._state.matrix);}}if(material._occlusionMap&&material._occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,material._occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,material._occlusionMap._state.matrix);}}if(material._diffuseFresnel){if(this._uDiffuseFresnelEdgeBias){gl.uniform1f(this._uDiffuseFresnelEdgeBias,material._diffuseFresnel.edgeBias);}if(this._uDiffuseFresnelCenterBias){gl.uniform1f(this._uDiffuseFresnelCenterBias,material._diffuseFresnel.centerBias);}if(this._uDiffuseFresnelEdgeColor){gl.uniform3fv(this._uDiffuseFresnelEdgeColor,material._diffuseFresnel.edgeColor);}if(this._uDiffuseFresnelCenterColor){gl.uniform3fv(this._uDiffuseFresnelCenterColor,material._diffuseFresnel.centerColor);}if(this._uDiffuseFresnelPower){gl.uniform1f(this._uDiffuseFresnelPower,material._diffuseFresnel.power);}}if(material._specularFresnel){if(this._uSpecularFresnelEdgeBias){gl.uniform1f(this._uSpecularFresnelEdgeBias,material._specularFresnel.edgeBias);}if(this._uSpecularFresnelCenterBias){gl.uniform1f(this._uSpecularFresnelCenterBias,material._specularFresnel.centerBias);}if(this._uSpecularFresnelEdgeColor){gl.uniform3fv(this._uSpecularFresnelEdgeColor,material._specularFresnel.edgeColor);}if(this._uSpecularFresnelCenterColor){gl.uniform3fv(this._uSpecularFresnelCenterColor,material._specularFresnel.centerColor);}if(this._uSpecularFresnelPower){gl.uniform1f(this._uSpecularFresnelPower,material._specularFresnel.power);}}if(material._alphaFresnel){if(this._uAlphaFresnelEdgeBias){gl.uniform1f(this._uAlphaFresnelEdgeBias,material._alphaFresnel.edgeBias);}if(this._uAlphaFresnelCenterBias){gl.uniform1f(this._uAlphaFresnelCenterBias,material._alphaFresnel.centerBias);}if(this._uAlphaFresnelEdgeColor){gl.uniform3fv(this._uAlphaFresnelEdgeColor,material._alphaFresnel.edgeColor);}if(this._uAlphaFresnelCenterColor){gl.uniform3fv(this._uAlphaFresnelCenterColor,material._alphaFresnel.centerColor);}if(this._uAlphaFresnelPower){gl.uniform1f(this._uAlphaFresnelPower,material._alphaFresnel.power);}}if(material._reflectivityFresnel){if(this._uReflectivityFresnelEdgeBias){gl.uniform1f(this._uReflectivityFresnelEdgeBias,material._reflectivityFresnel.edgeBias);}if(this._uReflectivityFresnelCenterBias){gl.uniform1f(this._uReflectivityFresnelCenterBias,material._reflectivityFresnel.centerBias);}if(this._uReflectivityFresnelEdgeColor){gl.uniform3fv(this._uReflectivityFresnelEdgeColor,material._reflectivityFresnel.edgeColor);}if(this._uReflectivityFresnelCenterColor){gl.uniform3fv(this._uReflectivityFresnelCenterColor,material._reflectivityFresnel.centerColor);}if(this._uReflectivityFresnelPower){gl.uniform1f(this._uReflectivityFresnelPower,material._reflectivityFresnel.power);}}if(material._emissiveFresnel){if(this._uEmissiveFresnelEdgeBias){gl.uniform1f(this._uEmissiveFresnelEdgeBias,material._emissiveFresnel.edgeBias);}if(this._uEmissiveFresnelCenterBias){gl.uniform1f(this._uEmissiveFresnelCenterBias,material._emissiveFresnel.centerBias);}if(this._uEmissiveFresnelEdgeColor){gl.uniform3fv(this._uEmissiveFresnelEdgeColor,material._emissiveFresnel.edgeColor);}if(this._uEmissiveFresnelCenterColor){gl.uniform3fv(this._uEmissiveFresnelCenterColor,material._emissiveFresnel.centerColor);}if(this._uEmissiveFresnelPower){gl.uniform1f(this._uEmissiveFresnelPower,material._emissiveFresnel.power);}}break;case"MetallicMaterial":if(this._uBaseColor){gl.uniform3fv(this._uBaseColor,materialState.baseColor);}if(this._uMaterialMetallic){gl.uniform1f(this._uMaterialMetallic,materialState.metallic);}if(this._uMaterialRoughness){gl.uniform1f(this._uMaterialRoughness,materialState.roughness);}if(this._uMaterialSpecularF0){gl.uniform1f(this._uMaterialSpecularF0,materialState.specularF0);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0.0);}var baseColorMap=material._baseColorMap;if(baseColorMap&&baseColorMap._state.texture&&this._uBaseColorMap){program.bindTexture(this._uBaseColorMap,baseColorMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uBaseColorMapMatrix){gl.uniformMatrix4fv(this._uBaseColorMapMatrix,false,baseColorMap._state.matrix);}}var metallicMap=material._metallicMap;if(metallicMap&&metallicMap._state.texture&&this._uMetallicMap){program.bindTexture(this._uMetallicMap,metallicMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMetallicMapMatrix){gl.uniformMatrix4fv(this._uMetallicMapMatrix,false,metallicMap._state.matrix);}}var roughnessMap=material._roughnessMap;if(roughnessMap&&roughnessMap._state.texture&&this._uRoughnessMap){program.bindTexture(this._uRoughnessMap,roughnessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uRoughnessMapMatrix){gl.uniformMatrix4fv(this._uRoughnessMapMatrix,false,roughnessMap._state.matrix);}}var metallicRoughnessMap=material._metallicRoughnessMap;if(metallicRoughnessMap&&metallicRoughnessMap._state.texture&&this._uMetallicRoughnessMap){program.bindTexture(this._uMetallicRoughnessMap,metallicRoughnessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uMetallicRoughnessMapMatrix){gl.uniformMatrix4fv(this._uMetallicRoughnessMapMatrix,false,metallicRoughnessMap._state.matrix);}}var emissiveMap=material._emissiveMap;if(emissiveMap&&emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,emissiveMap._state.matrix);}}var occlusionMap=material._occlusionMap;if(occlusionMap&&material._occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,occlusionMap._state.matrix);}}var alphaMap=material._alphaMap;if(alphaMap&&alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,alphaMap._state.matrix);}}var normalMap=material._normalMap;if(normalMap&&normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,normalMap._state.matrix);}}break;case"SpecularMaterial":if(this._uMaterialDiffuse){gl.uniform3fv(this._uMaterialDiffuse,materialState.diffuse);}if(this._uMaterialSpecular){gl.uniform3fv(this._uMaterialSpecular,materialState.specular);}if(this._uMaterialGlossiness){gl.uniform1f(this._uMaterialGlossiness,materialState.glossiness);}if(this._uMaterialReflectivity){gl.uniform1f(this._uMaterialReflectivity,materialState.reflectivity);}if(this._uMaterialEmissive){gl.uniform3fv(this._uMaterialEmissive,materialState.emissive);}if(this._uAlphaModeCutoff){gl.uniform4f(this._uAlphaModeCutoff,1.0*materialState.alpha,materialState.alphaMode===1?1.0:0.0,materialState.alphaCutoff,0.0);}var diffuseMap=material._diffuseMap;if(diffuseMap&&diffuseMap._state.texture&&this._uDiffuseMap){program.bindTexture(this._uDiffuseMap,diffuseMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uDiffuseMapMatrix){gl.uniformMatrix4fv(this._uDiffuseMapMatrix,false,diffuseMap._state.matrix);}}var specularMap=material._specularMap;if(specularMap&&specularMap._state.texture&&this._uSpecularMap){program.bindTexture(this._uSpecularMap,specularMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularMapMatrix){gl.uniformMatrix4fv(this._uSpecularMapMatrix,false,specularMap._state.matrix);}}var glossinessMap=material._glossinessMap;if(glossinessMap&&glossinessMap._state.texture&&this._uGlossinessMap){program.bindTexture(this._uGlossinessMap,glossinessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uGlossinessMapMatrix){gl.uniformMatrix4fv(this._uGlossinessMapMatrix,false,glossinessMap._state.matrix);}}var specularGlossinessMap=material._specularGlossinessMap;if(specularGlossinessMap&&specularGlossinessMap._state.texture&&this._uSpecularGlossinessMap){program.bindTexture(this._uSpecularGlossinessMap,specularGlossinessMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uSpecularGlossinessMapMatrix){gl.uniformMatrix4fv(this._uSpecularGlossinessMapMatrix,false,specularGlossinessMap._state.matrix);}}var emissiveMap=material._emissiveMap;if(emissiveMap&&emissiveMap._state.texture&&this._uEmissiveMap){program.bindTexture(this._uEmissiveMap,emissiveMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uEmissiveMapMatrix){gl.uniformMatrix4fv(this._uEmissiveMapMatrix,false,emissiveMap._state.matrix);}}var occlusionMap=material._occlusionMap;if(occlusionMap&&occlusionMap._state.texture&&this._uOcclusionMap){program.bindTexture(this._uOcclusionMap,occlusionMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uOcclusionMapMatrix){gl.uniformMatrix4fv(this._uOcclusionMapMatrix,false,occlusionMap._state.matrix);}}var alphaMap=material._alphaMap;if(alphaMap&&alphaMap._state.texture&&this._uAlphaMap){program.bindTexture(this._uAlphaMap,alphaMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uAlphaMapMatrix){gl.uniformMatrix4fv(this._uAlphaMapMatrix,false,alphaMap._state.matrix);}}var normalMap=material._normalMap;if(normalMap&&normalMap._state.texture&&this._uNormalMap){program.bindTexture(this._uNormalMap,normalMap._state.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;if(this._uNormalMapMatrix){gl.uniformMatrix4fv(this._uNormalMapMatrix,false,normalMap._state.matrix);}}break;}this._lastMaterialId=materialState.id;}gl.uniformMatrix4fv(this._uModelMatrix,gl.FALSE,mesh.worldMatrix);if(this._uModelNormalMatrix){gl.uniformMatrix4fv(this._uModelNormalMatrix,gl.FALSE,mesh.worldNormalMatrix);}if(this._uClippable){gl.uniform1i(this._uClippable,meshState.clippable);}if(this._uColorize){var colorize=meshState.colorize;var lastColorize=this._lastColorize;if(lastColorize[0]!==colorize[0]||lastColorize[1]!==colorize[1]||lastColorize[2]!==colorize[2]||lastColorize[3]!==colorize[3]){gl.uniform4fv(this._uColorize,colorize);lastColorize[0]=colorize[0];lastColorize[1]=colorize[1];lastColorize[2]=colorize[2];lastColorize[3]=colorize[3];}}gl.uniform3fv(this._uOffset,meshState.offset);// Bind VBOs
|
|
10347
10347
|
if(geometryState.id!==this._lastGeometryId){if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,geometryState.uvDecodeMatrix);}if(this._aPosition){this._aPosition.bindArrayBuffer(geometryState.positionsBuf);frameCtx.bindArray++;}if(this._aNormal){this._aNormal.bindArrayBuffer(geometryState.normalsBuf);frameCtx.bindArray++;}if(this._aUV){this._aUV.bindArrayBuffer(geometryState.uvBuf);frameCtx.bindArray++;}if(this._aColor){this._aColor.bindArrayBuffer(geometryState.colorsBuf);frameCtx.bindArray++;}if(this._aFlags){this._aFlags.bindArrayBuffer(geometryState.flagsBuf);frameCtx.bindArray++;}if(geometryState.indicesBuf){geometryState.indicesBuf.bind();frameCtx.bindArray++;}this._lastGeometryId=geometryState.id;}// Draw (indices bound in prev step)
|
|
10348
10348
|
if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positions){gl.drawArrays(gl.TRIANGLES,0,geometryState.positions.numItems);frameCtx.drawArrays++;}if(background){gl.depthFunc(gl.LESS);}};DrawRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;var material=mesh._material;var lightsState=scene._lightsState;var sectionPlanesState=scene._sectionPlanesState;var materialState=mesh._material._state;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uModelNormalMatrix=program.getLocation("modelNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=[];this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];this._uShadowViewMatrix=[];this._uShadowProjMatrix=[];if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}var lights=lightsState.lights;var light;for(var i=0,len=lights.length;i<len;i++){light=lights[i];switch(light.type){case"ambient":this._uLightAmbient[i]=program.getLocation("lightAmbient");break;case"dir":this._uLightColor[i]=program.getLocation("lightColor"+i);this._uLightPos[i]=null;this._uLightDir[i]=program.getLocation("lightDir"+i);break;case"point":this._uLightColor[i]=program.getLocation("lightColor"+i);this._uLightPos[i]=program.getLocation("lightPos"+i);this._uLightDir[i]=null;this._uLightAttenuation[i]=program.getLocation("lightAttenuation"+i);break;case"spot":this._uLightColor[i]=program.getLocation("lightColor"+i);this._uLightPos[i]=program.getLocation("lightPos"+i);this._uLightDir[i]=program.getLocation("lightDir"+i);this._uLightAttenuation[i]=program.getLocation("lightAttenuation"+i);break;}if(light.castsShadow){this._uShadowViewMatrix[i]=program.getLocation("shadowViewMatrix"+i);this._uShadowProjMatrix[i]=program.getLocation("shadowProjMatrix"+i);}}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}if(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}this._uSectionPlanes=[];var sectionPlanes=sectionPlanesState.sectionPlanes;for(var i=0,len=sectionPlanes.length;i<len;i++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+i),pos:program.getLocation("sectionPlanePos"+i),dir:program.getLocation("sectionPlaneDir"+i)});}this._uPointSize=program.getLocation("pointSize");switch(materialState.type){case"LambertMaterial":this._uMaterialColor=program.getLocation("materialColor");this._uMaterialEmissive=program.getLocation("materialEmissive");this._uAlphaModeCutoff=program.getLocation("materialAlphaModeCutoff");break;case"PhongMaterial":this._uMaterialAmbient=program.getLocation("materialAmbient");this._uMaterialDiffuse=program.getLocation("materialDiffuse");this._uMaterialSpecular=program.getLocation("materialSpecular");this._uMaterialEmissive=program.getLocation("materialEmissive");this._uAlphaModeCutoff=program.getLocation("materialAlphaModeCutoff");this._uMaterialShininess=program.getLocation("materialShininess");if(material._ambientMap){this._uMaterialAmbientMap="ambientMap";this._uMaterialAmbientMapMatrix=program.getLocation("ambientMapMatrix");}if(material._diffuseMap){this._uDiffuseMap="diffuseMap";this._uDiffuseMapMatrix=program.getLocation("diffuseMapMatrix");}if(material._specularMap){this._uSpecularMap="specularMap";this._uSpecularMapMatrix=program.getLocation("specularMapMatrix");}if(material._emissiveMap){this._uEmissiveMap="emissiveMap";this._uEmissiveMapMatrix=program.getLocation("emissiveMapMatrix");}if(material._alphaMap){this._uAlphaMap="alphaMap";this._uAlphaMapMatrix=program.getLocation("alphaMapMatrix");}if(material._reflectivityMap){this._uReflectivityMap="reflectivityMap";this._uReflectivityMapMatrix=program.getLocation("reflectivityMapMatrix");}if(material._normalMap){this._uNormalMap="normalMap";this._uNormalMapMatrix=program.getLocation("normalMapMatrix");}if(material._occlusionMap){this._uOcclusionMap="occlusionMap";this._uOcclusionMapMatrix=program.getLocation("occlusionMapMatrix");}if(material._diffuseFresnel){this._uDiffuseFresnelEdgeBias=program.getLocation("diffuseFresnelEdgeBias");this._uDiffuseFresnelCenterBias=program.getLocation("diffuseFresnelCenterBias");this._uDiffuseFresnelEdgeColor=program.getLocation("diffuseFresnelEdgeColor");this._uDiffuseFresnelCenterColor=program.getLocation("diffuseFresnelCenterColor");this._uDiffuseFresnelPower=program.getLocation("diffuseFresnelPower");}if(material._specularFresnel){this._uSpecularFresnelEdgeBias=program.getLocation("specularFresnelEdgeBias");this._uSpecularFresnelCenterBias=program.getLocation("specularFresnelCenterBias");this._uSpecularFresnelEdgeColor=program.getLocation("specularFresnelEdgeColor");this._uSpecularFresnelCenterColor=program.getLocation("specularFresnelCenterColor");this._uSpecularFresnelPower=program.getLocation("specularFresnelPower");}if(material._alphaFresnel){this._uAlphaFresnelEdgeBias=program.getLocation("alphaFresnelEdgeBias");this._uAlphaFresnelCenterBias=program.getLocation("alphaFresnelCenterBias");this._uAlphaFresnelEdgeColor=program.getLocation("alphaFresnelEdgeColor");this._uAlphaFresnelCenterColor=program.getLocation("alphaFresnelCenterColor");this._uAlphaFresnelPower=program.getLocation("alphaFresnelPower");}if(material._reflectivityFresnel){this._uReflectivityFresnelEdgeBias=program.getLocation("reflectivityFresnelEdgeBias");this._uReflectivityFresnelCenterBias=program.getLocation("reflectivityFresnelCenterBias");this._uReflectivityFresnelEdgeColor=program.getLocation("reflectivityFresnelEdgeColor");this._uReflectivityFresnelCenterColor=program.getLocation("reflectivityFresnelCenterColor");this._uReflectivityFresnelPower=program.getLocation("reflectivityFresnelPower");}if(material._emissiveFresnel){this._uEmissiveFresnelEdgeBias=program.getLocation("emissiveFresnelEdgeBias");this._uEmissiveFresnelCenterBias=program.getLocation("emissiveFresnelCenterBias");this._uEmissiveFresnelEdgeColor=program.getLocation("emissiveFresnelEdgeColor");this._uEmissiveFresnelCenterColor=program.getLocation("emissiveFresnelCenterColor");this._uEmissiveFresnelPower=program.getLocation("emissiveFresnelPower");}break;case"MetallicMaterial":this._uBaseColor=program.getLocation("materialBaseColor");this._uMaterialMetallic=program.getLocation("materialMetallic");this._uMaterialRoughness=program.getLocation("materialRoughness");this._uMaterialSpecularF0=program.getLocation("materialSpecularF0");this._uMaterialEmissive=program.getLocation("materialEmissive");this._uAlphaModeCutoff=program.getLocation("materialAlphaModeCutoff");if(material._baseColorMap){this._uBaseColorMap="baseColorMap";this._uBaseColorMapMatrix=program.getLocation("baseColorMapMatrix");}if(material._metallicMap){this._uMetallicMap="metallicMap";this._uMetallicMapMatrix=program.getLocation("metallicMapMatrix");}if(material._roughnessMap){this._uRoughnessMap="roughnessMap";this._uRoughnessMapMatrix=program.getLocation("roughnessMapMatrix");}if(material._metallicRoughnessMap){this._uMetallicRoughnessMap="metallicRoughnessMap";this._uMetallicRoughnessMapMatrix=program.getLocation("metallicRoughnessMapMatrix");}if(material._emissiveMap){this._uEmissiveMap="emissiveMap";this._uEmissiveMapMatrix=program.getLocation("emissiveMapMatrix");}if(material._occlusionMap){this._uOcclusionMap="occlusionMap";this._uOcclusionMapMatrix=program.getLocation("occlusionMapMatrix");}if(material._alphaMap){this._uAlphaMap="alphaMap";this._uAlphaMapMatrix=program.getLocation("alphaMapMatrix");}if(material._normalMap){this._uNormalMap="normalMap";this._uNormalMapMatrix=program.getLocation("normalMapMatrix");}break;case"SpecularMaterial":this._uMaterialDiffuse=program.getLocation("materialDiffuse");this._uMaterialSpecular=program.getLocation("materialSpecular");this._uMaterialGlossiness=program.getLocation("materialGlossiness");this._uMaterialReflectivity=program.getLocation("reflectivityFresnel");this._uMaterialEmissive=program.getLocation("materialEmissive");this._uAlphaModeCutoff=program.getLocation("materialAlphaModeCutoff");if(material._diffuseMap){this._uDiffuseMap="diffuseMap";this._uDiffuseMapMatrix=program.getLocation("diffuseMapMatrix");}if(material._specularMap){this._uSpecularMap="specularMap";this._uSpecularMapMatrix=program.getLocation("specularMapMatrix");}if(material._glossinessMap){this._uGlossinessMap="glossinessMap";this._uGlossinessMapMatrix=program.getLocation("glossinessMapMatrix");}if(material._specularGlossinessMap){this._uSpecularGlossinessMap="materialSpecularGlossinessMap";this._uSpecularGlossinessMapMatrix=program.getLocation("materialSpecularGlossinessMapMatrix");}if(material._emissiveMap){this._uEmissiveMap="emissiveMap";this._uEmissiveMapMatrix=program.getLocation("emissiveMapMatrix");}if(material._occlusionMap){this._uOcclusionMap="occlusionMap";this._uOcclusionMapMatrix=program.getLocation("occlusionMapMatrix");}if(material._alphaMap){this._uAlphaMap="alphaMap";this._uAlphaMapMatrix=program.getLocation("alphaMapMatrix");}if(material._normalMap){this._uNormalMap="normalMap";this._uNormalMapMatrix=program.getLocation("normalMapMatrix");}break;}this._aPosition=program.getAttribute("position");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._uClippable=program.getLocation("clippable");this._uColorize=program.getLocation("colorize");this._uOffset=program.getLocation("offset");this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;this._lastColorize=new Float32Array(4);this._baseTextureUnit=0;};DrawRenderer.prototype._bindProgram=function(frameCtx){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var project=scene.camera.project;var light;var program=this._program;program.bind();frameCtx.useProgram++;frameCtx.textureUnit=0;this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;this._lastColorize[0]=-1;this._lastColorize[1]=-1;this._lastColorize[2]=-1;this._lastColorize[3]=-1;gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}for(var i=0,len=lightsState.lights.length;i<len;i++){light=lightsState.lights[i];if(this._uLightAmbient[i]){gl.uniform4f(this._uLightAmbient[i],light.color[0],light.color[1],light.color[2],light.intensity);}else{if(this._uLightColor[i]){gl.uniform4f(this._uLightColor[i],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[i]){gl.uniform3fv(this._uLightPos[i],light.pos);if(this._uLightAttenuation[i]){gl.uniform1f(this._uLightAttenuation[i],light.attenuation);}}if(this._uLightDir[i]){gl.uniform3fv(this._uLightDir[i],light.dir);}if(light.castsShadow){if(this._uShadowViewMatrix[i]){gl.uniformMatrix4fv(this._uShadowViewMatrix[i],false,light.getShadowViewMatrix());}if(this._uShadowProjMatrix[i]){gl.uniformMatrix4fv(this._uShadowProjMatrix[i],false,light.getShadowProjMatrix());}var shadowRenderBuf=light.getShadowRenderBuf();if(shadowRenderBuf){program.bindTexture("shadowMap"+i,shadowRenderBuf.getTexture(),frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}}}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._uGammaFactor){gl.uniform1f(this._uGammaFactor,scene.gammaFactor);}this._baseTextureUnit=frameCtx.textureUnit;};/**
|
|
10349
10349
|
* @private
|
|
@@ -10352,47 +10352,47 @@ if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometrySta
|
|
|
10352
10352
|
src.push("vColor = vec4(reflectedColor * fillColor.rgb, fillColor.a);");//src.push("vColor = vec4(reflectedColor + fillColor.rgb, fillColor.a);");
|
|
10353
10353
|
if(clipping){src.push("vWorldPosition = worldPosition;");}if(mesh._geometry._state.primitiveName==="points"){src.push("gl_PointSize = pointSize;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");return src;}function hasNormals(mesh){var primitive=mesh._geometry._state.primitiveName;if((mesh._geometry._state.autoVertexNormals||mesh._geometry._state.normalsBuf)&&(primitive==="triangles"||primitive==="triangle-strip"||primitive==="triangle-fan")){return true;}return false;}function buildFragment$5(mesh){var scene=mesh.scene;var sectionPlanesState=mesh.scene._sectionPlanesState;var gammaOutput=mesh.scene.gammaOutput;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Lambertian drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(gammaOutput){src.push("uniform float gammaFactor;");src.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {");src.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("uniform bool clippable;");for(var _i112=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i112<len;_i112++){src.push("uniform bool sectionPlaneActive"+_i112+";");src.push("uniform vec3 sectionPlanePos"+_i112+";");src.push("uniform vec3 sectionPlaneDir"+_i112+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var _i113=0,_len16=sectionPlanesState.getNumAllocatedSectionPlanes();_i113<_len16;_i113++){src.push("if (sectionPlaneActive"+_i113+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i113+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i113+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(mesh._geometry._state.primitiveName==="points"){src.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;");src.push("float r = dot(cxy, cxy);");src.push("if (r > 1.0) {");src.push(" discard;");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}if(gammaOutput){src.push("outColor = linearToGamma(vColor, gammaFactor);");}else{src.push("outColor = vColor;");}src.push("}");return src;}/**
|
|
10354
10354
|
* @author xeolabs / https://github.com/xeolabs
|
|
10355
|
-
*/var ids$1=new Map$1({});var tempVec3a$
|
|
10355
|
+
*/var ids$1=new Map$1({});var tempVec3a$I=math.vec3();/**
|
|
10356
10356
|
* @private
|
|
10357
10357
|
*/var EmphasisFillRenderer=function EmphasisFillRenderer(hash,mesh){this.id=ids$1.addItem({});this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new EmphasisFillShaderSource(mesh);this._allocate(mesh);};var xrayFillRenderers={};EmphasisFillRenderer.get=function(mesh){var hash=[mesh.scene.id,mesh.scene.gammaOutput?"go":"",// Gamma input not needed
|
|
10358
|
-
mesh.scene._sectionPlanesState.getHash(),!!mesh._geometry._state.normalsBuf?"n":"",mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=xrayFillRenderers[hash];if(!renderer){renderer=new EmphasisFillRenderer(hash,mesh);xrayFillRenderers[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};EmphasisFillRenderer.prototype.put=function(){if(--this._useCount===0){ids$1.removeItem(this.id);if(this._program){this._program.destroy();}delete xrayFillRenderers[this._hash];stats.memory.programs--;}};EmphasisFillRenderer.prototype.webglContextRestored=function(){this._program=null;};EmphasisFillRenderer.prototype.drawMesh=function(frameCtx,mesh,mode){if(!this._program){this._allocate(mesh);}var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var materialState=mode===0?mesh._xrayMaterial._state:mode===1?mesh._highlightMaterial._state:mesh._selectedMaterial._state;var meshState=mesh._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
10358
|
+
mesh.scene._sectionPlanesState.getHash(),!!mesh._geometry._state.normalsBuf?"n":"",mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=xrayFillRenderers[hash];if(!renderer){renderer=new EmphasisFillRenderer(hash,mesh);xrayFillRenderers[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};EmphasisFillRenderer.prototype.put=function(){if(--this._useCount===0){ids$1.removeItem(this.id);if(this._program){this._program.destroy();}delete xrayFillRenderers[this._hash];stats.memory.programs--;}};EmphasisFillRenderer.prototype.webglContextRestored=function(){this._program=null;};EmphasisFillRenderer.prototype.drawMesh=function(frameCtx,mesh,mode){if(!this._program){this._allocate(mesh);}var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var materialState=mode===0?mesh._xrayMaterial._state:mode===1?mesh._highlightMaterial._state:mesh._selectedMaterial._state;var meshState=mesh._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$I);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}if(materialState.id!==this._lastMaterialId){var fillColor=materialState.fillColor;var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}gl.uniform4f(this._uFillColor,fillColor[0],fillColor[1],fillColor[2],materialState.fillAlpha);this._lastMaterialId=materialState.id;}gl.uniformMatrix4fv(this._uModelMatrix,gl.FALSE,mesh.worldMatrix);if(this._uModelNormalMatrix){gl.uniformMatrix4fv(this._uModelNormalMatrix,gl.FALSE,mesh.worldNormalMatrix);}if(this._uClippable){gl.uniform1i(this._uClippable,meshState.clippable);}gl.uniform3fv(this._uOffset,meshState.offset);// Bind VBOs
|
|
10359
10359
|
if(geometryState.id!==this._lastGeometryId){if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,geometryState.uvDecodeMatrix);}if(this._aPosition){this._aPosition.bindArrayBuffer(geometryState.positionsBuf);frameCtx.bindArray++;}if(this._aNormal){this._aNormal.bindArrayBuffer(geometryState.normalsBuf);frameCtx.bindArray++;}if(geometryState.indicesBuf){geometryState.indicesBuf.bind();frameCtx.bindArray++;// gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0);
|
|
10360
10360
|
// frameCtx.drawElements++;
|
|
10361
10361
|
}else if(geometryState.positionsBuf);this._lastGeometryId=geometryState.id;}if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positionsBuf){gl.drawArrays(gl.TRIANGLES,0,geometryState.positionsBuf.numItems);frameCtx.drawArrays++;}};EmphasisFillRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var lightsState=scene._lightsState;var sectionPlanesState=scene._sectionPlanesState;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uModelNormalMatrix=program.getLocation("modelNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uLightAmbient=[];this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];for(var _i114=0,len=lightsState.lights.length;_i114<len;_i114++){var light=lightsState.lights[_i114];switch(light.type){case"ambient":this._uLightAmbient[_i114]=program.getLocation("lightAmbient");break;case"dir":this._uLightColor[_i114]=program.getLocation("lightColor"+_i114);this._uLightPos[_i114]=null;this._uLightDir[_i114]=program.getLocation("lightDir"+_i114);break;case"point":this._uLightColor[_i114]=program.getLocation("lightColor"+_i114);this._uLightPos[_i114]=program.getLocation("lightPos"+_i114);this._uLightDir[_i114]=null;this._uLightAttenuation[_i114]=program.getLocation("lightAttenuation"+_i114);break;}}this._uSectionPlanes=[];for(var _i115=0,_len17=sectionPlanesState.getNumAllocatedSectionPlanes();_i115<_len17;_i115++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i115),pos:program.getLocation("sectionPlanePos"+_i115),dir:program.getLocation("sectionPlaneDir"+_i115)});}this._uFillColor=program.getLocation("fillColor");this._aPosition=program.getAttribute("position");this._aNormal=program.getAttribute("normal");this._uClippable=program.getLocation("clippable");this._uGammaFactor=program.getLocation("gammaFactor");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;};EmphasisFillRenderer.prototype._bindProgram=function(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var camera=scene.camera;var project=camera.project;var program=this._program;program.bind();frameCtx.useProgram++;frameCtx.textureUnit=0;this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;this._lastIndicesBufId=null;gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.normalMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}for(var _i116=0,len=lightsState.lights.length;_i116<len;_i116++){var light=lightsState.lights[_i116];if(this._uLightAmbient[_i116]){gl.uniform4f(this._uLightAmbient[_i116],light.color[0],light.color[1],light.color[2],light.intensity);}else{if(this._uLightColor[_i116]){gl.uniform4f(this._uLightColor[_i116],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i116]){gl.uniform3fv(this._uLightPos[_i116],light.pos);if(this._uLightAttenuation[_i116]){gl.uniform1f(this._uLightAttenuation[_i116],light.attenuation);}}if(this._uLightDir[_i116]){gl.uniform3fv(this._uLightDir[_i116],light.dir);}}}if(this._uGammaFactor){gl.uniform1f(this._uGammaFactor,scene.gammaFactor);}};/**
|
|
10362
10362
|
* @private
|
|
10363
10363
|
*/var EmphasisEdgesShaderSource=/*#__PURE__*/_createClass(function EmphasisEdgesShaderSource(mesh){_classCallCheck(this,EmphasisEdgesShaderSource);this.vertex=buildVertex$4(mesh);this.fragment=buildFragment$4(mesh);});function buildVertex$4(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push("#version 300 es");src.push("// Edges drawing vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform vec4 edgeColor;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");}src.push("out vec4 vColor;");if(billboard==="spherical"||billboard==="cylindrical"){src.push("void billboard(inout mat4 mat) {");src.push(" mat[0][0] = 1.0;");src.push(" mat[0][1] = 0.0;");src.push(" mat[0][2] = 0.0;");if(billboard==="spherical"){src.push(" mat[1][0] = 0.0;");src.push(" mat[1][1] = 1.0;");src.push(" mat[1][2] = 0.0;");}src.push(" mat[2][0] = 0.0;");src.push(" mat[2][1] = 0.0;");src.push(" mat[2][2] =1.0;");src.push("}");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");src.push("vec4 worldPosition;");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("mat4 viewMatrix2 = viewMatrix;");src.push("mat4 modelMatrix2 = modelMatrix;");if(stationary){src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");src.push("billboard(modelMatrix2);");src.push("billboard(viewMatrix2);");src.push("billboard(modelViewMatrix);");src.push("worldPosition = modelMatrix2 * localPosition;");src.push("worldPosition.xyz = worldPosition.xyz + offset;");src.push("vec4 viewPosition = modelViewMatrix * localPosition;");}else{src.push("worldPosition = modelMatrix2 * localPosition;");src.push("worldPosition.xyz = worldPosition.xyz + offset;");src.push("vec4 viewPosition = viewMatrix2 * worldPosition; ");}src.push("vColor = edgeColor;");if(clipping){src.push("vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");return src;}function buildFragment$4(mesh){var scene=mesh.scene;var sectionPlanesState=mesh.scene._sectionPlanesState;var gammaOutput=mesh.scene.gammaOutput;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Edges drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(gammaOutput){src.push("uniform float gammaFactor;");src.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {");src.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("uniform bool clippable;");for(var _i117=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i117<len;_i117++){src.push("uniform bool sectionPlaneActive"+_i117+";");src.push("uniform vec3 sectionPlanePos"+_i117+";");src.push("uniform vec3 sectionPlaneDir"+_i117+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var _i118=0,_len18=sectionPlanesState.getNumAllocatedSectionPlanes();_i118<_len18;_i118++){src.push("if (sectionPlaneActive"+_i118+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i118+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i118+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}if(gammaOutput){src.push("outColor = linearToGamma(vColor, gammaFactor);");}else{src.push("outColor = vColor;");}src.push("}");return src;}/**
|
|
10364
10364
|
* @author xeolabs / https://github.com/xeolabs
|
|
10365
|
-
*/var ids=new Map$1({});var tempVec3a$
|
|
10365
|
+
*/var ids=new Map$1({});var tempVec3a$H=math.vec3();/**
|
|
10366
10366
|
* @private
|
|
10367
10367
|
*/var EmphasisEdgesRenderer=function EmphasisEdgesRenderer(hash,mesh){this.id=ids.addItem({});this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new EmphasisEdgesShaderSource(mesh);this._allocate(mesh);};var renderers$4={};EmphasisEdgesRenderer.get=function(mesh){var hash=[mesh.scene.id,mesh.scene.gammaOutput?"go":"",// Gamma input not needed
|
|
10368
|
-
mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=renderers$4[hash];if(!renderer){renderer=new EmphasisEdgesRenderer(hash,mesh);renderers$4[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};EmphasisEdgesRenderer.prototype.put=function(){if(--this._useCount===0){ids.removeItem(this.id);if(this._program){this._program.destroy();}delete renderers$4[this._hash];stats.memory.programs--;}};EmphasisEdgesRenderer.prototype.webglContextRestored=function(){this._program=null;};EmphasisEdgesRenderer.prototype.drawMesh=function(frameCtx,mesh,mode){if(!this._program){this._allocate(mesh);}var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var materialState;var meshState=mesh._state;var geometry=mesh._geometry;var geometryState=geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
10368
|
+
mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=renderers$4[hash];if(!renderer){renderer=new EmphasisEdgesRenderer(hash,mesh);renderers$4[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};EmphasisEdgesRenderer.prototype.put=function(){if(--this._useCount===0){ids.removeItem(this.id);if(this._program){this._program.destroy();}delete renderers$4[this._hash];stats.memory.programs--;}};EmphasisEdgesRenderer.prototype.webglContextRestored=function(){this._program=null;};EmphasisEdgesRenderer.prototype.drawMesh=function(frameCtx,mesh,mode){if(!this._program){this._allocate(mesh);}var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var materialState;var meshState=mesh._state;var geometry=mesh._geometry;var geometryState=geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$H);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}switch(mode){case 0:materialState=mesh._xrayMaterial._state;break;case 1:materialState=mesh._highlightMaterial._state;break;case 2:materialState=mesh._selectedMaterial._state;break;case 3:default:materialState=mesh._edgeMaterial._state;break;}if(materialState.id!==this._lastMaterialId){var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}if(frameCtx.lineWidth!==materialState.edgeWidth){gl.lineWidth(materialState.edgeWidth);frameCtx.lineWidth=materialState.edgeWidth;}if(this._uEdgeColor){var edgeColor=materialState.edgeColor;var edgeAlpha=materialState.edgeAlpha;gl.uniform4f(this._uEdgeColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}this._lastMaterialId=materialState.id;}gl.uniformMatrix4fv(this._uModelMatrix,gl.FALSE,mesh.worldMatrix);if(this._uClippable){gl.uniform1i(this._uClippable,meshState.clippable);}gl.uniform3fv(this._uOffset,meshState.offset);// Bind VBOs
|
|
10369
10369
|
var indicesBuf;if(geometryState.primitive===gl.TRIANGLES){indicesBuf=geometry._getEdgeIndices();}else if(geometryState.primitive===gl.LINES){indicesBuf=geometryState.indicesBuf;}if(indicesBuf){if(geometryState.id!==this._lastGeometryId){if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);}if(this._aPosition){this._aPosition.bindArrayBuffer(geometryState.positionsBuf,geometryState.compressGeometry?gl.UNSIGNED_SHORT:gl.FLOAT);frameCtx.bindArray++;}indicesBuf.bind();frameCtx.bindArray++;this._lastGeometryId=geometryState.id;}gl.drawElements(gl.LINES,indicesBuf.numItems,indicesBuf.itemType,0);frameCtx.drawElements++;}};EmphasisEdgesRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i119=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i119<len;_i119++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i119),pos:program.getLocation("sectionPlanePos"+_i119),dir:program.getLocation("sectionPlaneDir"+_i119)});}this._uEdgeColor=program.getLocation("edgeColor");this._aPosition=program.getAttribute("position");this._uClippable=program.getLocation("clippable");this._uGammaFactor=program.getLocation("gammaFactor");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;};EmphasisEdgesRenderer.prototype._bindProgram=function(frameCtx){var program=this._program;var scene=this._scene;var gl=scene.canvas.gl;var camera=scene.camera;var project=camera.project;program.bind();frameCtx.useProgram++;this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uGammaFactor){gl.uniform1f(this._uGammaFactor,scene.gammaFactor);}};/**
|
|
10370
10370
|
* @author xeolabs / https://github.com/xeolabs
|
|
10371
10371
|
*/ /**
|
|
10372
10372
|
* @private
|
|
10373
10373
|
*/var PickMeshShaderSource=/*#__PURE__*/_createClass(function PickMeshShaderSource(mesh){_classCallCheck(this,PickMeshShaderSource);this.vertex=buildVertex$3(mesh);this.fragment=buildFragment$3(mesh);});function buildVertex$3(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push('#version 300 es');src.push("// Mesh picking vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("out vec4 vViewPosition;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(clipping){src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("void billboard(inout mat4 mat) {");src.push(" mat[0][0] = 1.0;");src.push(" mat[0][1] = 0.0;");src.push(" mat[0][2] = 0.0;");if(billboard==="spherical"){src.push(" mat[1][0] = 0.0;");src.push(" mat[1][1] = 1.0;");src.push(" mat[1][2] = 0.0;");}src.push(" mat[2][0] = 0.0;");src.push(" mat[2][1] = 0.0;");src.push(" mat[2][2] =1.0;");src.push("}");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("mat4 viewMatrix2 = viewMatrix;");src.push("mat4 modelMatrix2 = modelMatrix;");if(stationary){src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");src.push("billboard(modelMatrix2);");src.push("billboard(viewMatrix2);");}src.push(" vec4 worldPosition = modelMatrix2 * localPosition;");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix2 * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");return src;}function buildFragment$3(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push('#version 300 es');src.push("// Mesh picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform vec4 pickColor;");if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("if (sectionPlaneActive"+i+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = pickColor; ");src.push("}");return src;}/**
|
|
10374
10374
|
* @author xeolabs / https://github.com/xeolabs
|
|
10375
|
-
*/var tempVec3a$
|
|
10375
|
+
*/var tempVec3a$G=math.vec3();// No ID, because there is exactly one PickMeshRenderer per scene
|
|
10376
10376
|
/**
|
|
10377
10377
|
* @private
|
|
10378
|
-
*/var PickMeshRenderer=function PickMeshRenderer(hash,mesh){this._hash=hash;this._shaderSource=new PickMeshShaderSource(mesh);this._scene=mesh.scene;this._useCount=0;this._allocate(mesh);};var renderers$3={};PickMeshRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._state.hash].join(";");var renderer=renderers$3[hash];if(!renderer){renderer=new PickMeshRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$3[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickMeshRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$3[this._hash];stats.memory.programs--;}};PickMeshRenderer.prototype.webglContextRestored=function(){this._program=null;};PickMeshRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
10378
|
+
*/var PickMeshRenderer=function PickMeshRenderer(hash,mesh){this._hash=hash;this._shaderSource=new PickMeshShaderSource(mesh);this._scene=mesh.scene;this._useCount=0;this._allocate(mesh);};var renderers$3={};PickMeshRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._state.hash].join(";");var renderer=renderers$3[hash];if(!renderer){renderer=new PickMeshRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$3[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickMeshRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$3[this._hash];stats.memory.programs--;}};PickMeshRenderer.prototype.webglContextRestored=function(){this._program=null;};PickMeshRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$G);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}if(materialState.id!==this._lastMaterialId){var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}var frontface=materialState.frontface;if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}this._lastMaterialId=materialState.id;}gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniformMatrix4fv(this._uModelMatrix,false,mesh.worldMatrix);if(this._uClippable){gl.uniform1i(this._uClippable,mesh._state.clippable);}gl.uniform3fv(this._uOffset,mesh._state.offset);if(geometryState.id!==this._lastGeometryId){if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);}if(this._aPosition){this._aPosition.bindArrayBuffer(geometryState.positionsBuf,geometryState.compressGeometry?gl.UNSIGNED_SHORT:gl.FLOAT);frameCtx.bindArray++;}if(geometryState.indicesBuf){geometryState.indicesBuf.bind();frameCtx.bindArray++;}this._lastGeometryId=geometryState.id;}// Mesh-indexed color
|
|
10379
10379
|
var pickID=mesh._state.pickID;var a=pickID>>24&0xFF;var b=pickID>>16&0xFF;var g=pickID>>8&0xFF;var r=pickID&0xFF;gl.uniform4f(this._uPickColor,r/255,g/255,b/255,a/255);gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positions){gl.drawArrays(gl.TRIANGLES,0,geometryState.positions.numItems);}};PickMeshRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=scene._sectionPlanesState.sectionPlanes;for(var _i120=0,len=clips.length;_i120<len;_i120++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i120),pos:program.getLocation("sectionPlanePos"+_i120),dir:program.getLocation("sectionPlaneDir"+_i120)});}this._aPosition=program.getAttribute("position");this._uClippable=program.getLocation("clippable");this._uPickColor=program.getLocation("pickColor");this._uPickClipPos=program.getLocation("pickClipPos");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._lastMaterialId=null;this._lastGeometryId=null;};PickMeshRenderer.prototype._bindProgram=function(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();frameCtx.useProgram++;if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}this._lastMaterialId=null;this._lastGeometryId=null;};/**
|
|
10380
10380
|
* @private
|
|
10381
10381
|
*/var PickTriangleShaderSource=/*#__PURE__*/_createClass(function PickTriangleShaderSource(mesh){_classCallCheck(this,PickTriangleShaderSource);this.vertex=buildVertex$2(mesh);this.fragment=buildFragment$2(mesh);});function buildVertex$2(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var src=[];src.push('#version 300 es');src.push("// Surface picking vertex shader");src.push("in vec3 position;");src.push("in vec4 color;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform vec3 offset;");if(clipping){src.push("uniform bool clippable;");src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("out vec4 vColor;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push(" vec4 worldPosition = modelMatrix * localPosition; ");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push(" vColor = color;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");return src;}function buildFragment$2(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push('#version 300 es');src.push("// Surface picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");src.push("in vec4 vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var _i121=0;_i121<sectionPlanesState.getNumAllocatedSectionPlanes();_i121++){src.push("uniform bool sectionPlaneActive"+_i121+";");src.push("uniform vec3 sectionPlanePos"+_i121+";");src.push("uniform vec3 sectionPlaneDir"+_i121+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var _i122=0;_i122<sectionPlanesState.getNumAllocatedSectionPlanes();_i122++){src.push("if (sectionPlaneActive"+_i122+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i122+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i122+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vColor;");src.push("}");return src;}/**
|
|
10382
10382
|
* @author xeolabs / https://github.com/xeolabs
|
|
10383
|
-
*/var tempVec3a$
|
|
10383
|
+
*/var tempVec3a$F=math.vec3();/**
|
|
10384
10384
|
* @private
|
|
10385
|
-
*/var PickTriangleRenderer=function PickTriangleRenderer(hash,mesh){this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new PickTriangleShaderSource(mesh);this._allocate(mesh);};var renderers$2={};PickTriangleRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=renderers$2[hash];if(!renderer){renderer=new PickTriangleRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$2[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickTriangleRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$2[this._hash];stats.memory.programs--;}};PickTriangleRenderer.prototype.webglContextRestored=function(){this._program=null;};PickTriangleRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometry=mesh._geometry;var geometryState=mesh._geometry._state;var origin=mesh.origin;var backfaces=materialState.backfaces;var frontface=materialState.frontface;var project=scene.camera.project;var positionsBuf=geometry._getPickTrianglePositions();var pickColorsBuf=geometry._getPickTriangleColors();this._program.bind();frameCtx.useProgram++;if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
10385
|
+
*/var PickTriangleRenderer=function PickTriangleRenderer(hash,mesh){this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new PickTriangleShaderSource(mesh);this._allocate(mesh);};var renderers$2={};PickTriangleRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=renderers$2[hash];if(!renderer){renderer=new PickTriangleRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$2[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickTriangleRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$2[this._hash];stats.memory.programs--;}};PickTriangleRenderer.prototype.webglContextRestored=function(){this._program=null;};PickTriangleRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometry=mesh._geometry;var geometryState=mesh._geometry._state;var origin=mesh.origin;var backfaces=materialState.backfaces;var frontface=materialState.frontface;var project=scene.camera.project;var positionsBuf=geometry._getPickTrianglePositions();var pickColorsBuf=geometry._getPickTriangleColors();this._program.bind();frameCtx.useProgram++;if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$F);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){gl.uniform1f(this._uZFar,scene.camera.project.far);}if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}gl.uniformMatrix4fv(this._uModelMatrix,false,mesh.worldMatrix);if(this._uClippable){gl.uniform1i(this._uClippable,mesh._state.clippable);}gl.uniform3fv(this._uOffset,mesh._state.offset);if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(positionsBuf,geometryState.compressGeometry?gl.UNSIGNED_SHORT:gl.FLOAT);}else{this._aPosition.bindArrayBuffer(positionsBuf);}gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);pickColorsBuf.bind();gl.enableVertexAttribArray(this._aColor.location);gl.vertexAttribPointer(this._aColor.location,pickColorsBuf.itemSize,pickColorsBuf.itemType,true,0,0);// Normalize
|
|
10386
10386
|
gl.drawArrays(geometryState.primitive,0,positionsBuf.numItems/3);};PickTriangleRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);this._useCount=0;if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var sectionPlanes=scene._sectionPlanesState.sectionPlanes;for(var _i123=0,len=sectionPlanes.length;_i123<len;_i123++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i123),pos:program.getLocation("sectionPlanePos"+_i123),dir:program.getLocation("sectionPlaneDir"+_i123)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._uPickClipPos=program.getLocation("pickClipPos");this._uClippable=program.getLocation("clippable");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}};/**
|
|
10387
10387
|
* @author xeolabs / https://github.com/xeolabs
|
|
10388
10388
|
*/ /**
|
|
10389
10389
|
* @private
|
|
10390
10390
|
*/var OcclusionShaderSource=/*#__PURE__*/_createClass(function OcclusionShaderSource(mesh){_classCallCheck(this,OcclusionShaderSource);this.vertex=buildVertex$1(mesh);this.fragment=buildFragment$1(mesh);});function buildVertex$1(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push('#version 300 es');src.push("// Mesh occlusion vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(clipping){src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("void billboard(inout mat4 mat) {");src.push(" mat[0][0] = 1.0;");src.push(" mat[0][1] = 0.0;");src.push(" mat[0][2] = 0.0;");if(billboard==="spherical"){src.push(" mat[1][0] = 0.0;");src.push(" mat[1][1] = 1.0;");src.push(" mat[1][2] = 0.0;");}src.push(" mat[2][0] = 0.0;");src.push(" mat[2][1] = 0.0;");src.push(" mat[2][2] =1.0;");src.push("}");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");src.push("vec4 worldPosition;");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("mat4 viewMatrix2 = viewMatrix;");src.push("mat4 modelMatrix2 = modelMatrix;");if(stationary){src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");src.push("billboard(modelMatrix2);");src.push("billboard(viewMatrix2);");src.push("billboard(modelViewMatrix);");src.push("worldPosition = modelMatrix2 * localPosition;");src.push("worldPosition.xyz = worldPosition.xyz + offset;");src.push("vec4 viewPosition = modelViewMatrix * localPosition;");}else{src.push("worldPosition = modelMatrix2 * localPosition;");src.push("worldPosition.xyz = worldPosition.xyz + offset;");src.push("vec4 viewPosition = viewMatrix2 * worldPosition; ");}if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");return src;}function buildFragment$1(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push('#version 300 es');src.push("// Mesh occlusion fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("if (sectionPlaneActive"+i+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); ");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}/**
|
|
10391
10391
|
* @author xeolabs / https://github.com/xeolabs
|
|
10392
|
-
*/var tempVec3a$
|
|
10392
|
+
*/var tempVec3a$E=math.vec3();// No ID, because there is exactly one PickMeshRenderer per scene
|
|
10393
10393
|
/**
|
|
10394
10394
|
* @private
|
|
10395
|
-
*/var OcclusionRenderer=function OcclusionRenderer(hash,mesh){this._hash=hash;this._shaderSource=new OcclusionShaderSource(mesh);this._scene=mesh.scene;this._useCount=0;this._allocate(mesh);};var renderers$1={};OcclusionRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._state.occlusionHash].join(";");var renderer=renderers$1[hash];if(!renderer){renderer=new OcclusionRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$1[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};OcclusionRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$1[this._hash];stats.memory.programs--;}};OcclusionRenderer.prototype.webglContextRestored=function(){this._program=null;};OcclusionRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var materialState=mesh._material._state;var meshState=mesh._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(materialState.alpha<1.0){return;}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(materialState.id!==this._lastMaterialId){var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}var frontface=materialState.frontface;if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}this._lastMaterialId=materialState.id;}var camera=scene.camera;gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
10395
|
+
*/var OcclusionRenderer=function OcclusionRenderer(hash,mesh){this._hash=hash;this._shaderSource=new OcclusionShaderSource(mesh);this._scene=mesh.scene;this._useCount=0;this._allocate(mesh);};var renderers$1={};OcclusionRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._state.occlusionHash].join(";");var renderer=renderers$1[hash];if(!renderer){renderer=new OcclusionRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$1[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};OcclusionRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$1[this._hash];stats.memory.programs--;}};OcclusionRenderer.prototype.webglContextRestored=function(){this._program=null;};OcclusionRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var materialState=mesh._material._state;var meshState=mesh._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(materialState.alpha<1.0){return;}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(materialState.id!==this._lastMaterialId){var backfaces=materialState.backfaces;if(frameCtx.backfaces!==backfaces){if(backfaces){gl.disable(gl.CULL_FACE);}else{gl.enable(gl.CULL_FACE);}frameCtx.backfaces=backfaces;}var frontface=materialState.frontface;if(frameCtx.frontface!==frontface){if(frontface){gl.frontFace(gl.CCW);}else{gl.frontFace(gl.CW);}frameCtx.frontface=frontface;}this._lastMaterialId=materialState.id;}var camera=scene.camera;gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$E);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}gl.uniformMatrix4fv(this._uProjMatrix,false,camera._project._state.matrix);gl.uniformMatrix4fv(this._uModelMatrix,gl.FALSE,mesh.worldMatrix);if(this._uClippable){gl.uniform1i(this._uClippable,mesh._state.clippable);}gl.uniform3fv(this._uOffset,mesh._state.offset);if(geometryState.id!==this._lastGeometryId){if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometryState.positionsDecodeMatrix);}if(this._aPosition){this._aPosition.bindArrayBuffer(geometryState.positionsBuf,geometryState.compressGeometry?gl.UNSIGNED_SHORT:gl.FLOAT);frameCtx.bindArray++;}if(geometryState.indicesBuf){geometryState.indicesBuf.bind();frameCtx.bindArray++;}this._lastGeometryId=geometryState.id;}if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positions){gl.drawArrays(gl.TRIANGLES,0,geometryState.positions.numItems);}};OcclusionRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=scene._sectionPlanesState.sectionPlanes;for(var _i124=0,len=clips.length;_i124<len;_i124++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i124),pos:program.getLocation("sectionPlanePos"+_i124),dir:program.getLocation("sectionPlaneDir"+_i124)});}this._aPosition=program.getAttribute("position");this._uClippable=program.getLocation("clippable");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;};OcclusionRenderer.prototype._bindProgram=function(frameCtx){var scene=this._scene;var project=scene.camera.project;var gl=scene.canvas.gl;this._program.bind();frameCtx.useProgram++;gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}this._lastMaterialId=null;this._lastVertexBufsId=null;this._lastGeometryId=null;};/**
|
|
10396
10396
|
* @private
|
|
10397
10397
|
*/var ShadowShaderSource=/*#__PURE__*/_createClass(function ShadowShaderSource(mesh){_classCallCheck(this,ShadowShaderSource);this.vertex=buildVertex(mesh);this.fragment=buildFragment(mesh);});function buildVertex(mesh){var scene=mesh.scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var src=[];src.push("// Mesh shadow vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(clipping){src.push("out vec4 vWorldPosition;");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");src.push("vec4 worldPosition;");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("worldPosition = modelMatrix * localPosition;");src.push("worldPosition.xyz = worldPosition.xyz + offset;");src.push("vec4 viewPosition = shadowViewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");}src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push("}");return src;}function buildFragment(mesh){var scene=mesh.scene;scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("// Mesh shadow fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("vec4 encodeFloat( const in float depth ) {");src.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);");src.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);");src.push(" vec4 comp = fract(depth * bitShift);");src.push(" comp -= comp.xxyz * bitMask;");src.push(" return comp;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i<sectionPlanesState.getNumAllocatedSectionPlanes();i++){src.push("if (sectionPlaneActive"+i+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push("outColor = encodeFloat(gl_FragCoord.z);");src.push("}");return src;}/**
|
|
10398
10398
|
* @private
|
|
@@ -11464,7 +11464,7 @@ geometry:new ReadableGeometry(axisGizmoScene,buildVectorTextGeometry({text:"Z",s
|
|
|
11464
11464
|
* @param visible
|
|
11465
11465
|
*/_createClass(AxisGizmoPlugin,[{key:"setVisible",value:function setVisible(visible){for(var _i130=0;_i130<this._meshes.length;_i130++){this._meshes[_i130].visible=visible;}}/**
|
|
11466
11466
|
* Destroys this AxisGizmoPlugin.
|
|
11467
|
-
*/},{key:"destroy",value:function destroy(){this._axisGizmoCanvas=null;this._axisGizmoScene.destroy();this._axisGizmoScene=null;_get(_getPrototypeOf(AxisGizmoPlugin.prototype),"destroy",this).call(this);}}]);return AxisGizmoPlugin;}(Plugin);math.vec3();/**
|
|
11467
|
+
*/},{key:"destroy",value:function destroy(){this._axisGizmoCanvas=null;this._axisGizmoScene.destroy();this._axisGizmoScene=null;_get(_getPrototypeOf(AxisGizmoPlugin.prototype),"destroy",this).call(this);}}]);return AxisGizmoPlugin;}(Plugin);var tempVec3a$D=math.vec3();var tempVec3b$y=math.vec3();var tempVec4a$a=math.vec4();var front=math.vec3([0,0,-1]);var back=math.vec3([0,0,1]);var up=math.vec3([0,1,0]);/**
|
|
11468
11468
|
* @desc An arbitrarily-aligned World-space clipping plane.
|
|
11469
11469
|
*
|
|
11470
11470
|
* * Slices portions off objects to create cross-section views or reveal interiors.
|
|
@@ -11516,7 +11516,7 @@ geometry:new ReadableGeometry(axisGizmoScene,buildVectorTextGeometry({text:"Z",s
|
|
|
11516
11516
|
* @param {Boolean} [cfg.active=true] Indicates whether or not this SectionPlane is active.
|
|
11517
11517
|
* @param {Number[]} [cfg.pos=[0,0,0]] World-space position of the SectionPlane.
|
|
11518
11518
|
* @param {Number[]} [cfg.dir=[0,0,-1]] Vector perpendicular to the plane surface, indicating the SectionPlane plane orientation.
|
|
11519
|
-
*/function SectionPlane(owner){var _this64;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,SectionPlane);_this64=_super42.call(this,owner,cfg);_this64._state=new RenderState({active:true,pos:math.vec3(),dir:math.vec3(),dist:0});_this64.active=cfg.active;_this64.pos=cfg.pos;_this64.dir=cfg.dir;_this64.scene._sectionPlaneCreated(_assertThisInitialized(_this64));return _this64;}/**
|
|
11519
|
+
*/function SectionPlane(owner){var _this64;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,SectionPlane);_this64=_super42.call(this,owner,cfg);_this64._state=new RenderState({active:true,pos:math.vec3(),quaternion:math.vec4(),roll:0,dir:math.vec3(),dist:0});_this64.active=cfg.active;_this64.pos=cfg.pos;_this64.dir=cfg.dir;_this64.scene._sectionPlaneCreated(_assertThisInitialized(_this64));return _this64;}/**
|
|
11520
11520
|
* Sets if this SectionPlane is active or not.
|
|
11521
11521
|
*
|
|
11522
11522
|
* Default value is ````true````.
|
|
@@ -11543,12 +11543,36 @@ geometry:new ReadableGeometry(axisGizmoScene,buildVectorTextGeometry({text:"Z",s
|
|
|
11543
11543
|
*
|
|
11544
11544
|
* @returns {Number[]} Current position.
|
|
11545
11545
|
*/function get(){return this._state.pos;}/**
|
|
11546
|
+
* Sets the quaternion of this SectionPlane's plane.
|
|
11547
|
+
*
|
|
11548
|
+
* Default value is ````[0, -1, 0, 0]````.
|
|
11549
|
+
*
|
|
11550
|
+
* @param {Number[]} value New quaternion.
|
|
11551
|
+
*/,set:function set(value){this._state.pos.set(value||[0,0,0]);this._state.dist=-math.dotVec3(this._state.pos,this._state.dir);this.fire("pos",this._state.pos);this.scene.fire("sectionPlaneUpdated",this);}},{key:"quaternion",get:/**
|
|
11552
|
+
* Gets the quaternion of this SectionPlane's plane.
|
|
11553
|
+
*
|
|
11554
|
+
* Default value is ````[0, -1, 0, 0]````.
|
|
11555
|
+
*
|
|
11556
|
+
* @returns {Number[]} value Current quaternion.
|
|
11557
|
+
*/function get(){return this._state.quaternion;}/**
|
|
11558
|
+
* Sets the roll of this SectionPlane's plane.
|
|
11559
|
+
*
|
|
11560
|
+
* Default value is ````0````.
|
|
11561
|
+
*
|
|
11562
|
+
* @param {Number[]} value New roll.
|
|
11563
|
+
*/,set:function set(value){this._state.quaternion.set(value||[0,0,0,-1]);math.vec3ApplyQuaternion(this._state.quaternion,back,this._state.dir);var quatUp=math.vec3ApplyQuaternion(this._state.quaternion,up,tempVec3a$D);var dirOnlyQ=math.vec3PairToQuaternion(back,this._state.dir,tempVec4a$a);var dirOnlyUp=math.vec3ApplyQuaternion(dirOnlyQ,up,tempVec3b$y);var angle=Math.acos(Math.min(1,math.dotVec3(quatUp,dirOnlyUp)));var sign=Math.sign(math.dotVec3(this._state.dir,math.cross3Vec3(quatUp,dirOnlyUp,tempVec3b$y)));this._state.roll=sign*angle;this._onDirUpdated();}},{key:"roll",get:/**
|
|
11564
|
+
* Gets the roll of this SectionPlane's plane.
|
|
11565
|
+
*
|
|
11566
|
+
* Default value is ````0````.
|
|
11567
|
+
*
|
|
11568
|
+
* @returns {Number[]} value Current roll.
|
|
11569
|
+
*/function get(){return this._state.roll;}/**
|
|
11546
11570
|
* Sets the direction of this SectionPlane's plane.
|
|
11547
11571
|
*
|
|
11548
11572
|
* Default value is ````[0, 0, -1]````.
|
|
11549
11573
|
*
|
|
11550
11574
|
* @param {Number[]} value New direction.
|
|
11551
|
-
*/,set:function set(value){this._state.
|
|
11575
|
+
*/,set:function set(value){this._state.roll=value||0;this._onDirRollUpdated();}},{key:"dir",get:/**
|
|
11552
11576
|
* Gets the direction of this SectionPlane's plane.
|
|
11553
11577
|
*
|
|
11554
11578
|
* Default value is ````[0, 0, -1]````.
|
|
@@ -11561,7 +11585,7 @@ geometry:new ReadableGeometry(axisGizmoScene,buildVectorTextGeometry({text:"Z",s
|
|
|
11561
11585
|
* each time either of two properties are updated.
|
|
11562
11586
|
*
|
|
11563
11587
|
* @returns {Number}
|
|
11564
|
-
*/,set:function set(value){this._state.dir.set(value||[0
|
|
11588
|
+
*/,set:function set(value){this._state.dir.set(value||front);this._onDirRollUpdated();}},{key:"_onDirRollUpdated",value:function _onDirRollUpdated(){math.vec3PairToQuaternion(back,this._state.dir,this._state.quaternion);tempVec4a$a[0]=0;tempVec4a$a[1]=0;tempVec4a$a[2]=-1;tempVec4a$a[3]=this._state.roll;math.angleAxisToQuaternion(tempVec4a$a,tempVec4a$a);math.mulQuaternions(this._state.quaternion,tempVec4a$a,this._state.quaternion);this._onDirUpdated();}},{key:"_onDirUpdated",value:function _onDirUpdated(){this._state.dist=-math.dotVec3(this._state.pos,this._state.dir);this.glRedraw();this.fire("dir",this._state.dir);this.scene.fire("sectionPlaneUpdated",this);}},{key:"dist",get:function get(){return this._state.dist;}/**
|
|
11565
11589
|
* Inverts the direction of {@link SectionPlane#dir}.
|
|
11566
11590
|
*/},{key:"flipDir",value:function flipDir(){math.mulVec3Scalar(this._state.dir,-1.0,this._state.dir);this.dir=this._state.dir;}/**
|
|
11567
11591
|
* @destroy
|
|
@@ -14870,7 +14894,7 @@ gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(t
|
|
|
14870
14894
|
*/var TrianglesColorRenderer$1=/*#__PURE__*/function(_TrianglesBatchingRen){_inherits(TrianglesColorRenderer$1,_TrianglesBatchingRen);var _super52=_createSuper(TrianglesColorRenderer$1);function TrianglesColorRenderer$1(){_classCallCheck(this,TrianglesColorRenderer$1);return _super52.apply(this,arguments);}_createClass(TrianglesColorRenderer$1,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_get(_getPrototypeOf(TrianglesColorRenderer$1.prototype),"drawLayer",this).call(this,frameCtx,layer,renderPass,{incrementDrawState:true});}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var light;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(var _i170=0,len=lightsState.lights.length;_i170<len;_i170++){light=lightsState.lights[_i170];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+_i170+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+_i170+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+_i170+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+_i170+";");src.push("uniform vec3 lightDir"+_i170+";");}}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
14871
14895
|
// renderPass = COLOR_OPAQUE
|
|
14872
14896
|
src.push("int colorFlag = int(flags) & 0xF;");src.push("if (colorFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
14873
|
-
src.push("} else {");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push("worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");src.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");src.push("float lambertian = 1.0;");for(var _i171=0,_len21=lightsState.lights.length;_i171<_len21;_i171++){light=lightsState.lights[_i171];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i171+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i171+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+_i171+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+_i171+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i171+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i171+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i171+".rgb * lightColor"+_i171+".a);");}src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(this._withSAO){src.push("uniform sampler2D uOcclusionTexture;");src.push("uniform vec4 uSAOParams;");src.push("const float packUpscale = 256. / 255.;");src.push("const float unpackDownScale = 255. / 256.;");src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");src.push("float unpackRGBToFloat( const in vec4 v ) {");src.push(" return dot( v, unPackFactors );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i172=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i172<len;_i172++){src.push("uniform bool sectionPlaneActive"+_i172+";");src.push("uniform vec3 sectionPlanePos"+_i172+";");src.push("uniform vec3 sectionPlaneDir"+_i172+";");}src.push("uniform float sliceThickness;");src.push("uniform vec4 sliceColor;");}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");src.push(" vec4 newColor;");src.push(" newColor = vColor;");if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i173=0,_len22=sectionPlanesState.getNumAllocatedSectionPlanes();_i173<_len22;_i173++){src.push("if (sectionPlaneActive"+_i173+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i173+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i173+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > sliceThickness) { ");src.push(" discard;");src.push(" }");src.push(" if (dist > 0.0) { ");src.push(" newColor = sliceColor;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
14897
|
+
src.push("} else {");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push("worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");src.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");src.push("float lambertian = 1.0;");for(var _i171=0,_len21=lightsState.lights.length;_i171<_len21;_i171++){light=lightsState.lights[_i171];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i171+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i171+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+_i171+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+_i171+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i171+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i171+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i171+".rgb * lightColor"+_i171+".a);");}src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(this._withSAO){src.push("uniform sampler2D uOcclusionTexture;");src.push("uniform vec4 uSAOParams;");src.push("const float packUpscale = 256. / 255.;");src.push("const float unpackDownScale = 255. / 256.;");src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");src.push("float unpackRGBToFloat( const in vec4 v ) {");src.push(" return dot( v, unPackFactors );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i172=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i172<len;_i172++){src.push("uniform bool sectionPlaneActive"+_i172+";");src.push("uniform vec3 sectionPlanePos"+_i172+";");src.push("uniform vec3 sectionPlaneDir"+_i172+";");}src.push("uniform float sliceThickness;");src.push("uniform vec4 sliceColor;");}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");src.push(" vec4 newColor;");src.push(" newColor = vColor;");if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i173=0,_len22=sectionPlanesState.getNumAllocatedSectionPlanes();_i173<_len22;_i173++){src.push("if (sectionPlaneActive"+_i173+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i173+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i173+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > sliceThickness) { ");src.push(" discard;");src.push(" }");src.push(" if (dist > 0.0) { ");src.push(" newColor = sliceColor;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" float dx = dFdx(vFragDepth);");src.push(" float dy = dFdy(vFragDepth);");src.push(" float diff = sqrt(dx*dx+dy*dy);");src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;");}if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
14874
14898
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
14875
14899
|
src.push(" float viewportWidth = uSAOParams[0];");src.push(" float viewportHeight = uSAOParams[1];");src.push(" float blendCutoff = uSAOParams[2];");src.push(" float blendFactor = uSAOParams[3];");src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" outColor = vec4(newColor.rgb * ambient, 1.0);");}else{src.push(" outColor = newColor;");}src.push("}");return src;}}]);return TrianglesColorRenderer$1;}(TrianglesBatchingRenderer);/**
|
|
14876
14900
|
* @private
|
|
@@ -15202,7 +15226,7 @@ math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&wo
|
|
|
15202
15226
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("in vec4 modelNormalMatrixCol0;");src.push("in vec4 modelNormalMatrixCol1;");src.push("in vec4 modelNormalMatrixCol2;");this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(i=0,len=lightsState.lights.length;i<len;i++){light=lightsState.lights[i];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+i+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+i+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+i+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+i+";");src.push("uniform vec3 lightDir"+i+";");}}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
15203
15227
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
15204
15228
|
src.push("int colorFlag = int(flags) & 0xF;");src.push("if (colorFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
15205
|
-
src.push("} else {");src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push("worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");src.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);");src.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);");src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");src.push("float lambertian = 1.0;");for(i=0,len=lightsState.lights.length;i<len;i++){light=lightsState.lights[i];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+i+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+i+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+i+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+i+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+i+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+i+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+i+".rgb * lightColor"+i+".a);");}src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(this._withSAO){src.push("uniform sampler2D uOcclusionTexture;");src.push("uniform vec4 uSAOParams;");src.push("const float packUpscale = 256. / 255.;");src.push("const float unpackDownScale = 255. / 256.;");src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");src.push("float unpackRGBToFloat( const in vec4 v ) {");src.push(" return dot( v, unPackFactors );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i225=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i225<len;_i225++){src.push("uniform bool sectionPlaneActive"+_i225+";");src.push("uniform vec3 sectionPlanePos"+_i225+";");src.push("uniform vec3 sectionPlaneDir"+_i225+";");}src.push("uniform float sliceThickness;");src.push("uniform vec4 sliceColor;");}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");src.push(" vec4 newColor;");src.push(" newColor = vColor;");if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i226=0,_len44=sectionPlanesState.getNumAllocatedSectionPlanes();_i226<_len44;_i226++){src.push("if (sectionPlaneActive"+_i226+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i226+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i226+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > sliceThickness) { ");src.push(" discard;");src.push(" }");src.push(" if (dist > 0.0) { ");src.push(" newColor = sliceColor;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
15229
|
+
src.push("} else {");src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push("worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");src.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);");src.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);");src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");src.push("float lambertian = 1.0;");for(i=0,len=lightsState.lights.length;i<len;i++){light=lightsState.lights[i];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+i+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+i+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+i+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+i+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+i+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+i+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+i+".rgb * lightColor"+i+".a);");}src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(this._withSAO){src.push("uniform sampler2D uOcclusionTexture;");src.push("uniform vec4 uSAOParams;");src.push("const float packUpscale = 256. / 255.;");src.push("const float unpackDownScale = 255. / 256.;");src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");src.push("float unpackRGBToFloat( const in vec4 v ) {");src.push(" return dot( v, unPackFactors );");src.push("}");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i225=0,len=sectionPlanesState.getNumAllocatedSectionPlanes();_i225<len;_i225++){src.push("uniform bool sectionPlaneActive"+_i225+";");src.push("uniform vec3 sectionPlanePos"+_i225+";");src.push("uniform vec3 sectionPlaneDir"+_i225+";");}src.push("uniform float sliceThickness;");src.push("uniform vec4 sliceColor;");}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");src.push(" vec4 newColor;");src.push(" newColor = vColor;");if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i226=0,_len44=sectionPlanesState.getNumAllocatedSectionPlanes();_i226<_len44;_i226++){src.push("if (sectionPlaneActive"+_i226+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i226+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i226+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > sliceThickness) { ");src.push(" discard;");src.push(" }");src.push(" if (dist > 0.0) { ");src.push(" newColor = sliceColor;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" float dx = dFdx(vFragDepth);");src.push(" float dy = dFdy(vFragDepth);");src.push(" float diff = sqrt(dx*dx+dy*dy);");src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;");}// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
15206
15230
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
15207
15231
|
if(this._withSAO){src.push(" float viewportWidth = uSAOParams[0];");src.push(" float viewportHeight = uSAOParams[1];");src.push(" float blendCutoff = uSAOParams[2];");src.push(" float blendFactor = uSAOParams[3];");src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" outColor = vec4(newColor.rgb * ambient, 1.0);");}else{src.push(" outColor = newColor;");}src.push("}");return src;}}]);return TrianglesColorRenderer;}(TrianglesInstancingRenderer);/**
|
|
15208
15232
|
* @private
|
|
@@ -18636,7 +18660,7 @@ var defaultColorTexture=new SceneModelTexture({id:DEFAULT_COLOR_TEXTURE_ID,textu
|
|
|
18636
18660
|
* Gets the SceneModel's local modeling rotation transform matrix.
|
|
18637
18661
|
*
|
|
18638
18662
|
* @type {Number[]}
|
|
18639
|
-
*/,set:function set(value){this._matrix.set(value||DEFAULT_MATRIX);math.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale);this._matrixDirty=false;this._setWorldMatrixDirty();this._sceneModelDirty();this.glRedraw();}},{key:"rotationMatrix",get:function get(){this._rebuildMatrices();return this._worldRotationMatrix;}},{key:"_rebuildMatrices",value:function _rebuildMatrices(){if(this._matrixDirty){math.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix);math.conjugateQuaternion(this._quaternion,this._conjugateQuaternion);math.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate);math.scaleMat4v(this._scale,this._worldRotationMatrix);math.scaleMat4v(this._scale,this._worldRotationMatrixConjugate);this._matrix.set(this._worldRotationMatrix);math.translateMat4v(this._position,this._matrix);this._matrixDirty=false;this._viewMatrixDirty=true;}}/**
|
|
18663
|
+
*/,set:function set(value){this._matrix.set(value||DEFAULT_MATRIX);math.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale);math.quaternionToEuler(this._quaternion,"XYZ",this._rotation);this._matrixDirty=false;this._setWorldMatrixDirty();this._sceneModelDirty();this.glRedraw();}},{key:"rotationMatrix",get:function get(){this._rebuildMatrices();return this._worldRotationMatrix;}},{key:"_rebuildMatrices",value:function _rebuildMatrices(){if(this._matrixDirty){math.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix);math.conjugateQuaternion(this._quaternion,this._conjugateQuaternion);math.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate);math.scaleMat4v(this._scale,this._worldRotationMatrix);math.scaleMat4v(this._scale,this._worldRotationMatrixConjugate);this._matrix.set(this._worldRotationMatrix);math.translateMat4v(this._position,this._matrix);this._matrixDirty=false;this._viewMatrixDirty=true;}}/**
|
|
18640
18664
|
* Gets the conjugate of the SceneModel's local modeling rotation transform matrix.
|
|
18641
18665
|
*
|
|
18642
18666
|
* This is used for RTC view matrix management in renderers.
|
|
@@ -19620,8 +19644,8 @@ lookDirection=YToZ(lookDirection);eye=YToZ(eye);up=YToZ(up);}var camera_view_poi
|
|
|
19620
19644
|
var sectionPlanes=scene.sectionPlanes;for(var id in sectionPlanes){if(sectionPlanes.hasOwnProperty(id)){var sectionPlane=sectionPlanes[id];if(!sectionPlane.active){continue;}var location=sectionPlane.pos;var _direction=void 0;if(reverseClippingPlanes){_direction=math.negateVec3(sectionPlane.dir,math.vec3());}else{_direction=sectionPlane.dir;}if(camera.yUp){// BCF is Z up
|
|
19621
19645
|
location=YToZ(location);_direction=YToZ(_direction);}math.addVec3(location,realWorldOffset);location=xyzArrayToObject(location);_direction=xyzArrayToObject(_direction);if(!bcfViewpoint.clipping_planes){bcfViewpoint.clipping_planes=[];}bcfViewpoint.clipping_planes.push({location:location,direction:_direction});}}// Lines
|
|
19622
19646
|
var lineSets=scene.lineSets;for(var _id2 in lineSets){if(lineSets.hasOwnProperty(_id2)){var lineSet=lineSets[_id2];if(!bcfViewpoint.lines){bcfViewpoint.lines=[];}var positions=lineSet.positions;var indices=lineSet.indices;for(var _i464=0,len=indices.length/2;_i464<len;_i464++){var _a5=indices[_i464*2];var b=indices[_i464*2+1];bcfViewpoint.lines.push({start_point:{x:positions[_a5*3+0],y:positions[_a5*3+1],z:positions[_a5*3+2]},end_point:{x:positions[b*3+0],y:positions[b*3+1],z:positions[b*3+2]}});}}}// Bitmaps
|
|
19623
|
-
var bitmaps=scene.bitmaps;for(var _id3 in bitmaps){if(bitmaps.hasOwnProperty(_id3)){var bitmap=bitmaps[_id3];var _location=bitmap.pos;var normal=bitmap.normal;var
|
|
19624
|
-
_location=YToZ(_location);normal=YToZ(normal);
|
|
19647
|
+
var bitmaps=scene.bitmaps;for(var _id3 in bitmaps){if(bitmaps.hasOwnProperty(_id3)){var bitmap=bitmaps[_id3];var _location=bitmap.pos;var normal=bitmap.normal;var _up2=bitmap.up;if(camera.yUp){// BCF is Z up
|
|
19648
|
+
_location=YToZ(_location);normal=YToZ(normal);_up2=YToZ(_up2);}math.addVec3(_location,realWorldOffset);if(!bcfViewpoint.bitmaps){bcfViewpoint.bitmaps=[];}bcfViewpoint.bitmaps.push({bitmap_type:bitmap.type,bitmap_data:bitmap.imageData,location:xyzArrayToObject(_location),normal:xyzArrayToObject(normal),up:xyzArrayToObject(_up2),height:bitmap.height});}}// Entity states
|
|
19625
19649
|
bcfViewpoint.components={visibility:{view_setup_hints:{spaces_visible:!!options.spacesVisible,space_boundaries_visible:!!options.spaceBoundariesVisible,openings_visible:!!options.openingsVisible,spaces_translucent:!!options.spaces_translucent,space_boundaries_translucent:!!options.space_boundaries_translucent,openings_translucent:!!options.openings_translucent}}};var opacityObjectIds=new Set(scene.opacityObjectIds);var xrayedObjectIds=new Set(scene.xrayedObjectIds);var colorizedObjectIds=new Set(scene.colorizedObjectIds);var coloringMap=Object.values(scene.objects).filter(function(entity){return opacityObjectIds.has(entity.id)||colorizedObjectIds.has(entity.id)||xrayedObjectIds.has(entity.id);}).reduce(function(coloringMap,entity){var color=colorizeToRGB(entity.colorize);var alpha;if(entity.xrayed){if(scene.xrayMaterial.fillAlpha===0.0&&scene.xrayMaterial.edgeAlpha!==0.0){// BCF can't deal with edges. If xRay is implemented only with edges, set an arbitrary opacity
|
|
19626
19650
|
alpha=0.1;}else{alpha=scene.xrayMaterial.fillAlpha;}alpha=Math.round(alpha*255).toString(16).padStart(2,"0");color=alpha+color;}else if(opacityObjectIds.has(entity.id)){alpha=Math.round(entity.opacity*255).toString(16).padStart(2,"0");color=alpha+color;}if(!coloringMap[color]){coloringMap[color]=[];}var objectId=entity.id;var originalSystemId=entity.originalSystemId;var component={ifc_guid:originalSystemId,originating_system:_this87.originatingSystem};if(originalSystemId!==objectId){component.authoring_tool_id=objectId;}coloringMap[color].push(component);return coloringMap;},{});var coloringArray=Object.entries(coloringMap).map(function(_ref16){var _ref17=_slicedToArray(_ref16,2),color=_ref17[0],components=_ref17[1];return{color:color,components:components};});bcfViewpoint.components.coloring=coloringArray;var objectIds=scene.objectIds;var visibleObjects=scene.visibleObjects;var visibleObjectIds=scene.visibleObjectIds;var invisibleObjectIds=objectIds.filter(function(id){return!visibleObjects[id];});var selectedObjectIds=scene.selectedObjectIds;if(options.defaultInvisible||visibleObjectIds.length<invisibleObjectIds.length){bcfViewpoint.components.visibility.exceptions=this._createBCFComponents(visibleObjectIds);bcfViewpoint.components.visibility.default_visibility=false;}else{bcfViewpoint.components.visibility.exceptions=this._createBCFComponents(invisibleObjectIds);bcfViewpoint.components.visibility.default_visibility=true;}bcfViewpoint.components.selection=this._createBCFComponents(selectedObjectIds);bcfViewpoint.components.translucency=this._createBCFComponents(scene.xrayedObjectIds);if(options.snapshot!==false){bcfViewpoint.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})};}return bcfViewpoint;}},{key:"_createBCFComponents",value:function _createBCFComponents(objectIds){var scene=this.viewer.scene;var components=[];for(var _i465=0,len=objectIds.length;_i465<len;_i465++){var objectId=objectIds[_i465];var entity=scene.objects[objectId];if(entity){var component={ifc_guid:entity.originalSystemId,originating_system:this.originatingSystem};if(entity.originalSystemId!==objectId){component.authoring_tool_id=objectId;}components.push(component);}}return components;}/**
|
|
19627
19651
|
* Sets viewer state to the given BCF viewpoint.
|
|
@@ -19647,8 +19671,8 @@ alpha=0.1;}else{alpha=scene.xrayMaterial.fillAlpha;}alpha=Math.round(alpha*255).
|
|
|
19647
19671
|
* then this method will apply the updates to objects within those composites.
|
|
19648
19672
|
*/},{key:"setViewpoint",value:function setViewpoint(bcfViewpoint){var _this88=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(!bcfViewpoint){return;}var viewer=this.viewer;var scene=viewer.scene;var camera=scene.camera;var rayCast=options.rayCast!==false;var immediate=options.immediate!==false;var reset=options.reset!==false;var realWorldOffset=scene.realWorldOffset;var reverseClippingPlanes=options.reverseClippingPlanes===true;scene.clearSectionPlanes();if(bcfViewpoint.clipping_planes&&bcfViewpoint.clipping_planes.length>0){bcfViewpoint.clipping_planes.forEach(function(e){var pos=xyzObjectToArray(e.location,tempVec3$5);var dir=xyzObjectToArray(e.direction,tempVec3$5);if(reverseClippingPlanes){math.negateVec3(dir);}math.subVec3(pos,realWorldOffset);if(camera.yUp){pos=ZToY(pos);dir=ZToY(dir);}new SectionPlane(scene,{pos:pos,dir:dir});});}scene.clearLines();if(bcfViewpoint.lines&&bcfViewpoint.lines.length>0){var positions=[];var indices=[];var _i466=0;bcfViewpoint.lines.forEach(function(e){if(!e.start_point){return;}if(!e.end_point){return;}positions.push(e.start_point.x);positions.push(e.start_point.y);positions.push(e.start_point.z);positions.push(e.end_point.x);positions.push(e.end_point.y);positions.push(e.end_point.z);indices.push(_i466++);indices.push(_i466++);});new LineSet(scene,{positions:positions,indices:indices,clippable:false,collidable:true});}scene.clearBitmaps();if(bcfViewpoint.bitmaps&&bcfViewpoint.bitmaps.length>0){bcfViewpoint.bitmaps.forEach(function(e){var bitmap_type=e.bitmap_type||"jpg";// "jpg" | "png"
|
|
19649
19673
|
var bitmap_data=e.bitmap_data;// base64
|
|
19650
|
-
var location=xyzObjectToArray(e.location,tempVec3a$9);var normal=xyzObjectToArray(e.normal,tempVec3b$6);var up=xyzObjectToArray(e.up,tempVec3c$4);var height=e.height||1;if(!bitmap_type){return;}if(!bitmap_data){return;}if(!location){return;}if(!normal){return;}if(!up){return;}if(camera.yUp){location=ZToY(location);normal=ZToY(normal);up=ZToY(up);}new Bitmap(scene,{src:bitmap_data,type:bitmap_type,pos:location,normal:normal,up:up,clippable:false,collidable:true,height:height});});}if(reset){scene.setObjectsXRayed(scene.xrayedObjectIds,false);scene.setObjectsHighlighted(scene.highlightedObjectIds,false);scene.setObjectsSelected(scene.selectedObjectIds,false);}if(bcfViewpoint.components){if(bcfViewpoint.components.visibility){if(!bcfViewpoint.components.visibility.default_visibility){scene.setObjectsVisible(scene.objectIds,false);if(bcfViewpoint.components.visibility.exceptions){bcfViewpoint.components.visibility.exceptions.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.visible=true;});});}}else{scene.setObjectsVisible(scene.objectIds,true);if(bcfViewpoint.components.visibility.exceptions){bcfViewpoint.components.visibility.exceptions.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.visible=false;});});}}var view_setup_hints=bcfViewpoint.components.visibility.view_setup_hints;if(view_setup_hints){if(view_setup_hints.spaces_visible===false){scene.setObjectsVisible(viewer.metaScene.getObjectIDsByType("IfcSpace"),false);}if(view_setup_hints.spaces_translucent!==undefined){scene.setObjectsXRayed(viewer.metaScene.getObjectIDsByType("IfcSpace"),true);}if(view_setup_hints.space_boundaries_visible!==undefined);if(view_setup_hints.openings_visible===false){scene.setObjectsVisible(viewer.metaScene.getObjectIDsByType("IfcOpening"),true);}if(view_setup_hints.space_boundaries_translucent!==undefined);if(view_setup_hints.openings_translucent!==undefined){scene.setObjectsXRayed(viewer.metaScene.getObjectIDsByType("IfcOpening"),true);}}}if(bcfViewpoint.components.selection){scene.setObjectsSelected(scene.selectedObjectIds,false);bcfViewpoint.components.selection.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.selected=true;});});}if(bcfViewpoint.components.translucency){scene.setObjectsXRayed(scene.xrayedObjectIds,false);bcfViewpoint.components.translucency.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.xrayed=true;});});}if(bcfViewpoint.components.coloring){bcfViewpoint.components.coloring.forEach(function(coloring){var color=coloring.color;var alpha=0;var alphaDefined=false;if(color.length===8){alpha=parseInt(color.substring(0,2),16)/256;if(alpha<=1.0&&alpha>=0.95){alpha=1.0;}color=color.substring(2);alphaDefined=true;}var colorize=[parseInt(color.substring(0,2),16)/256,parseInt(color.substring(2,4),16)/256,parseInt(color.substring(4,6),16)/256];coloring.components.map(function(component){return _this88._withBCFComponent(options,component,function(entity){entity.colorize=colorize;if(alphaDefined){entity.opacity=alpha;}});});});}}if(bcfViewpoint.perspective_camera||bcfViewpoint.orthogonal_camera){var eye;var look;var
|
|
19651
|
-
origin:eye,direction:look});look=hit?hit.worldPos:math.addVec3(eye,look,tempVec3$5);}else{look=math.addVec3(eye,look,tempVec3$5);}if(immediate){camera.eye=eye;camera.look=look;camera.up=
|
|
19674
|
+
var location=xyzObjectToArray(e.location,tempVec3a$9);var normal=xyzObjectToArray(e.normal,tempVec3b$6);var up=xyzObjectToArray(e.up,tempVec3c$4);var height=e.height||1;if(!bitmap_type){return;}if(!bitmap_data){return;}if(!location){return;}if(!normal){return;}if(!up){return;}if(camera.yUp){location=ZToY(location);normal=ZToY(normal);up=ZToY(up);}new Bitmap(scene,{src:bitmap_data,type:bitmap_type,pos:location,normal:normal,up:up,clippable:false,collidable:true,height:height});});}if(reset){scene.setObjectsXRayed(scene.xrayedObjectIds,false);scene.setObjectsHighlighted(scene.highlightedObjectIds,false);scene.setObjectsSelected(scene.selectedObjectIds,false);}if(bcfViewpoint.components){if(bcfViewpoint.components.visibility){if(!bcfViewpoint.components.visibility.default_visibility){scene.setObjectsVisible(scene.objectIds,false);if(bcfViewpoint.components.visibility.exceptions){bcfViewpoint.components.visibility.exceptions.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.visible=true;});});}}else{scene.setObjectsVisible(scene.objectIds,true);if(bcfViewpoint.components.visibility.exceptions){bcfViewpoint.components.visibility.exceptions.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.visible=false;});});}}var view_setup_hints=bcfViewpoint.components.visibility.view_setup_hints;if(view_setup_hints){if(view_setup_hints.spaces_visible===false){scene.setObjectsVisible(viewer.metaScene.getObjectIDsByType("IfcSpace"),false);}if(view_setup_hints.spaces_translucent!==undefined){scene.setObjectsXRayed(viewer.metaScene.getObjectIDsByType("IfcSpace"),true);}if(view_setup_hints.space_boundaries_visible!==undefined);if(view_setup_hints.openings_visible===false){scene.setObjectsVisible(viewer.metaScene.getObjectIDsByType("IfcOpening"),true);}if(view_setup_hints.space_boundaries_translucent!==undefined);if(view_setup_hints.openings_translucent!==undefined){scene.setObjectsXRayed(viewer.metaScene.getObjectIDsByType("IfcOpening"),true);}}}if(bcfViewpoint.components.selection){scene.setObjectsSelected(scene.selectedObjectIds,false);bcfViewpoint.components.selection.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.selected=true;});});}if(bcfViewpoint.components.translucency){scene.setObjectsXRayed(scene.xrayedObjectIds,false);bcfViewpoint.components.translucency.forEach(function(component){return _this88._withBCFComponent(options,component,function(entity){return entity.xrayed=true;});});}if(bcfViewpoint.components.coloring){bcfViewpoint.components.coloring.forEach(function(coloring){var color=coloring.color;var alpha=0;var alphaDefined=false;if(color.length===8){alpha=parseInt(color.substring(0,2),16)/256;if(alpha<=1.0&&alpha>=0.95){alpha=1.0;}color=color.substring(2);alphaDefined=true;}var colorize=[parseInt(color.substring(0,2),16)/256,parseInt(color.substring(2,4),16)/256,parseInt(color.substring(4,6),16)/256];coloring.components.map(function(component){return _this88._withBCFComponent(options,component,function(entity){entity.colorize=colorize;if(alphaDefined){entity.opacity=alpha;}});});});}}if(bcfViewpoint.perspective_camera||bcfViewpoint.orthogonal_camera){var eye;var look;var _up3;var projection;if(bcfViewpoint.perspective_camera){eye=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_view_point,tempVec3$5);look=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_direction,tempVec3$5);_up3=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_up_vector,tempVec3$5);camera.perspective.fov=bcfViewpoint.perspective_camera.field_of_view;projection="perspective";}else{eye=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_view_point,tempVec3$5);look=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_direction,tempVec3$5);_up3=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_up_vector,tempVec3$5);camera.ortho.scale=bcfViewpoint.orthogonal_camera.view_to_world_scale;projection="ortho";}math.subVec3(eye,realWorldOffset);if(camera.yUp){eye=ZToY(eye);look=ZToY(look);_up3=ZToY(_up3);}if(rayCast){var hit=scene.pick({pickSurface:true,// <<------ This causes picking to find the intersection point on the entity
|
|
19675
|
+
origin:eye,direction:look});look=hit?hit.worldPos:math.addVec3(eye,look,tempVec3$5);}else{look=math.addVec3(eye,look,tempVec3$5);}if(immediate){camera.eye=eye;camera.look=look;camera.up=_up3;camera.projection=projection;}else{viewer.cameraFlight.flyTo({eye:eye,look:look,up:_up3,duration:options.duration,projection:projection});}}}},{key:"_withBCFComponent",value:function _withBCFComponent(options,component,callback){var viewer=this.viewer;var scene=viewer.scene;if(component.authoring_tool_id&&component.originating_system===this.originatingSystem){var id=component.authoring_tool_id;var entity=scene.objects[id];if(entity){callback(entity);return;}if(options.updateCompositeObjects){var metaObject=viewer.metaScene.metaObjects[id];if(metaObject){scene.withObjects(viewer.metaScene.getObjectIDsInSubtree(id),callback);return;}}}if(component.ifc_guid){var originalSystemId=component.ifc_guid;var _entity2=scene.objects[originalSystemId];if(_entity2){callback(_entity2);return;}if(options.updateCompositeObjects){var _metaObject=viewer.metaScene.metaObjects[originalSystemId];if(_metaObject){scene.withObjects(viewer.metaScene.getObjectIDsInSubtree(originalSystemId),callback);return;}}Object.keys(scene.models).forEach(function(modelId){var id=math.globalizeObjectId(modelId,originalSystemId);var entity=scene.objects[id];if(entity){callback(entity);return;}if(options.updateCompositeObjects){var _metaObject2=viewer.metaScene.metaObjects[id];if(_metaObject2){scene.withObjects(viewer.metaScene.getObjectIDsInSubtree(id),callback);}}});}}/**
|
|
19652
19676
|
* Destroys this BCFViewpointsPlugin.
|
|
19653
19677
|
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(BCFViewpointsPlugin.prototype),"destroy",this).call(this);}}]);return BCFViewpointsPlugin;}(Plugin);function xyzArrayToObject(arr){return{"x":arr[0],"y":arr[1],"z":arr[2]};}function xyzObjectToArray(xyz,arry){arry=new Float64Array(3);arry[0]=xyz.x;arry[1]=xyz.y;arry[2]=xyz.z;return arry;}function YToZ(vec){return new Float64Array([vec[0],-vec[2],vec[1]]);}function ZToY(vec){return new Float64Array([vec[0],vec[2],-vec[1]]);}function colorizeToRGB(color){var rgb="";rgb+=Math.round(color[0]*255).toString(16).padStart(2,"0");rgb+=Math.round(color[1]*255).toString(16).padStart(2,"0");rgb+=Math.round(color[2]*255).toString(16).padStart(2,"0");return rgb;}var tmpVec3a=math.vec3();var tmpVec3b=math.vec3();var tmpVec3c=math.vec3();math.vec4();math.vec4();math.vec4();/**
|
|
19654
19678
|
* @desc Measures the distance between two 3D points.
|
|
@@ -21528,7 +21552,7 @@ t/=d;return-c*t*(t-2)+b;}},{key:"_easeInCubic",value:function _easeInCubic(t,b,c
|
|
|
21528
21552
|
* @param {Number} frameIdx Index of the frame to scrub to.
|
|
21529
21553
|
*/},{key:"scrubToFrame",value:function scrubToFrame(frameIdx){var cameraPath=this._cameraPath;if(!cameraPath){return;}var camera=this.scene.camera;if(!camera){return;}var frame=cameraPath.frames[frameIdx];if(!frame){this.error("playToFrame - frame index out of range: "+frameIdx);return;}cameraPath.loadFrame(this._t);this.state=CameraPathAnimation.SCRUBBING;}/**
|
|
21530
21554
|
* Stops playing this CameraPathAnimation.
|
|
21531
|
-
*/},{key:"stop",value:function stop(){this.state=CameraPathAnimation.SCRUBBING;this.fire("stopped");}},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(CameraPathAnimation.prototype),"destroy",this).call(this);this.scene.off(this._tick);}}]);return CameraPathAnimation;}(Component);CameraPathAnimation.STOPPED=0;CameraPathAnimation.SCRUBBING=1;CameraPathAnimation.PLAYING=2;CameraPathAnimation.PLAYING_TO=3;var tempVec3$3=math.vec3();var tempVec3b$5=math.vec3();math.vec3();var zeroVec$
|
|
21555
|
+
*/},{key:"stop",value:function stop(){this.state=CameraPathAnimation.SCRUBBING;this.fire("stopped");}},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(CameraPathAnimation.prototype),"destroy",this).call(this);this.scene.off(this._tick);}}]);return CameraPathAnimation;}(Component);CameraPathAnimation.STOPPED=0;CameraPathAnimation.SCRUBBING=1;CameraPathAnimation.PLAYING=2;CameraPathAnimation.PLAYING_TO=3;var tempVec3$3=math.vec3();var tempVec3b$5=math.vec3();math.vec3();var zeroVec$1=math.vec3([0,-1,0]);var tempQuat=math.vec4([0,0,0,1]);/**
|
|
21532
21556
|
* @desc A plane-shaped 3D object containing a bitmap image.
|
|
21533
21557
|
*
|
|
21534
21558
|
* Use ````ImagePlane```` to embed bitmap images in your scenes.
|
|
@@ -21764,7 +21788,7 @@ t/=d;return-c*t*(t-2)+b;}},{key:"_easeInCubic",value:function _easeInCubic(t,b,c
|
|
|
21764
21788
|
* Default is ````true````.
|
|
21765
21789
|
*
|
|
21766
21790
|
* @type {Boolean}
|
|
21767
|
-
*/,set:function set(dir){this._dir.set(dir||[0,0,-1]);if(dir){var origin=this.scene.center;var negDir=[-this._dir[0],-this._dir[1],-this._dir[2]];math.subVec3(origin,this.position,tempVec3$3);var dist=-math.dotVec3(negDir,tempVec3$3);math.normalizeVec3(negDir);math.mulVec3Scalar(negDir,dist,tempVec3b$5);math.vec3PairToQuaternion(zeroVec$
|
|
21791
|
+
*/,set:function set(dir){this._dir.set(dir||[0,0,-1]);if(dir){var origin=this.scene.center;var negDir=[-this._dir[0],-this._dir[1],-this._dir[2]];math.subVec3(origin,this.position,tempVec3$3);var dist=-math.dotVec3(negDir,tempVec3$3);math.normalizeVec3(negDir);math.mulVec3Scalar(negDir,dist,tempVec3b$5);math.vec3PairToQuaternion(zeroVec$1,dir,tempQuat);this._node.quaternion=tempQuat;}}},{key:"collidable",get:/**
|
|
21768
21792
|
* Gets if this ````ImagePlane```` is included in boundary calculations.
|
|
21769
21793
|
*
|
|
21770
21794
|
* Default is ````true````.
|
|
@@ -21915,7 +21939,7 @@ t/=d;return-c*t*(t-2)+b;}},{key:"_easeInCubic",value:function _easeInCubic(t,b,c
|
|
|
21915
21939
|
* @param {Number} [cfg.quadraticAttenuation=0]Quadratic attenuation factor.
|
|
21916
21940
|
* @param {String} [cfg.space="view"]The coordinate system this PointLight is defined in - "view" or "world".
|
|
21917
21941
|
* @param {Boolean} [cfg.castsShadow=false] Flag which indicates if this PointLight casts a castsShadow.
|
|
21918
|
-
*/function PointLight(owner){var _this107;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,PointLight);_this107=_super136.call(this,owner,cfg);var self=_assertThisInitialized(_this107);_this107._shadowRenderBuf=null;_this107._shadowViewMatrix=null;_this107._shadowProjMatrix=null;_this107._shadowViewMatrixDirty=true;_this107._shadowProjMatrixDirty=true;var camera=_this107.scene.camera;var canvas=_this107.scene.canvas;_this107._onCameraViewMatrix=camera.on("viewMatrix",function(){_this107._shadowViewMatrixDirty=true;});_this107._onCameraProjMatrix=camera.on("projMatrix",function(){_this107._shadowProjMatrixDirty=true;});_this107._onCanvasBoundary=canvas.on("boundary",function(){_this107._shadowProjMatrixDirty=true;});_this107._state=new RenderState({type:"point",pos:math.vec3([1.0,1.0,1.0]),color:math.vec3([0.7,0.7,0.8]),intensity:1.0,attenuation:[0.0,0.0,0.0],space:cfg.space||"view",castsShadow:false,getShadowViewMatrix:function getShadowViewMatrix(){if(self._shadowViewMatrixDirty){if(!self._shadowViewMatrix){self._shadowViewMatrix=math.identityMat4();}var eye=self._state.pos;var look=camera.look;var
|
|
21942
|
+
*/function PointLight(owner){var _this107;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,PointLight);_this107=_super136.call(this,owner,cfg);var self=_assertThisInitialized(_this107);_this107._shadowRenderBuf=null;_this107._shadowViewMatrix=null;_this107._shadowProjMatrix=null;_this107._shadowViewMatrixDirty=true;_this107._shadowProjMatrixDirty=true;var camera=_this107.scene.camera;var canvas=_this107.scene.canvas;_this107._onCameraViewMatrix=camera.on("viewMatrix",function(){_this107._shadowViewMatrixDirty=true;});_this107._onCameraProjMatrix=camera.on("projMatrix",function(){_this107._shadowProjMatrixDirty=true;});_this107._onCanvasBoundary=canvas.on("boundary",function(){_this107._shadowProjMatrixDirty=true;});_this107._state=new RenderState({type:"point",pos:math.vec3([1.0,1.0,1.0]),color:math.vec3([0.7,0.7,0.8]),intensity:1.0,attenuation:[0.0,0.0,0.0],space:cfg.space||"view",castsShadow:false,getShadowViewMatrix:function getShadowViewMatrix(){if(self._shadowViewMatrixDirty){if(!self._shadowViewMatrix){self._shadowViewMatrix=math.identityMat4();}var eye=self._state.pos;var look=camera.look;var _up4=camera.up;math.lookAtMat4v(eye,look,_up4,self._shadowViewMatrix);self._shadowViewMatrixDirty=false;}return self._shadowViewMatrix;},getShadowProjMatrix:function getShadowProjMatrix(){if(self._shadowProjMatrixDirty){// TODO: Set when canvas resizes
|
|
21919
21943
|
if(!self._shadowProjMatrix){self._shadowProjMatrix=math.identityMat4();}var _canvas4=self.scene.canvas.canvas;math.perspectiveMat4(70*(Math.PI/180.0),_canvas4.clientWidth/_canvas4.clientHeight,0.1,500.0,self._shadowProjMatrix);self._shadowProjMatrixDirty=false;}return self._shadowProjMatrix;},getShadowRenderBuf:function getShadowRenderBuf(){if(!self._shadowRenderBuf){self._shadowRenderBuf=new RenderBuffer(self.scene.canvas.canvas,self.scene.canvas.gl,{size:[1024,1024]});// Super old mobile devices have a limit of 1024x1024 textures
|
|
21920
21944
|
}return self._shadowRenderBuf;}});_this107.pos=cfg.pos;_this107.color=cfg.color;_this107.intensity=cfg.intensity;_this107.constantAttenuation=cfg.constantAttenuation;_this107.linearAttenuation=cfg.linearAttenuation;_this107.quadraticAttenuation=cfg.quadraticAttenuation;_this107.castsShadow=cfg.castsShadow;_this107.scene._lightCreated(_assertThisInitialized(_this107));return _this107;}/**
|
|
21921
21945
|
* Sets the position of this PointLight.
|
|
@@ -25899,7 +25923,7 @@ console.warn('loadFile: HTTP Status 0 received.');if(ok){ok(response);}}else{if(
|
|
|
25899
25923
|
*/_createClass(OBJLoaderPlugin,[{key:"load",value:function load(){var _this140=this;var params=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(params.id&&this.viewer.scene.components[params.id]){this.error("Component with this ID already exists in viewer: "+params.id+" - will autogenerate this ID");delete params.id;}var modelNode=new Node$2(this.viewer.scene,utils.apply(params,{isModel:true}));var modelId=modelNode.id;// In case ID was auto-generated
|
|
25900
25924
|
var src=params.src;if(!src){this.error("load() param expected: src");return modelNode;}if(params.metaModelSrc){var metaModelSrc=params.metaModelSrc;utils.loadJSON(metaModelSrc,function(modelMetadata){_this140.viewer.metaScene.createMetaModel(modelId,modelMetadata);_this140._sceneGraphLoader.load(modelNode,src,params);},function(errMsg){_this140.error("load(): Failed to load model modelMetadata for model '".concat(modelId," from '").concat(metaModelSrc,"' - ").concat(errMsg));});}else{this._sceneGraphLoader.load(modelNode,src,params);}modelNode.once("destroyed",function(){_this140.viewer.metaScene.destroyMetaModel(modelId);});return modelNode;}/**
|
|
25901
25925
|
* Destroys this OBJLoaderPlugin.
|
|
25902
|
-
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(OBJLoaderPlugin.prototype),"destroy",this).call(this);}}]);return OBJLoaderPlugin;}(Plugin)
|
|
25926
|
+
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(OBJLoaderPlugin.prototype),"destroy",this).call(this);}}]);return OBJLoaderPlugin;}(Plugin);/**
|
|
25903
25927
|
* Controls a {@link SectionPlane} with mouse and touch input.
|
|
25904
25928
|
*
|
|
25905
25929
|
* @private
|
|
@@ -25915,8 +25939,8 @@ var NO_STATE_INHERIT=false;var arrowLength=1.0;var handleRadius=0.09;var tubeRad
|
|
|
25915
25939
|
position:[0,0,0],scale:[5,5,5],isObject:false});var pos=math.vec3();var setPos=function(){var origin=math.vec3();var rtcPos=math.vec3();return function(p){pos.set(p);worldToRTCPos(p,origin,rtcPos);rootNode.origin=origin;rootNode.position=rtcPos;};}();var arrowGeometry=function arrowGeometry(radiusBottom,height){return new ReadableGeometry(rootNode,buildCylinderGeometry({radiusTop:0.001,radiusBottom:radiusBottom,radialSegments:32,heightSegments:1,height:height,openEnded:false}));};var tubeGeometry=function tubeGeometry(radius,height,radialSegments){return new ReadableGeometry(rootNode,buildCylinderGeometry({radiusTop:radius,radiusBottom:radius,radialSegments:radialSegments,heightSegments:1,height:height,openEnded:false}));};var torusGeometry=function torusGeometry(tube,arcFraction,tubeSegments){return new ReadableGeometry(rootNode,buildTorusGeometry({radius:arrowLength-0.2,tube:tube,radialSegments:64,tubeSegments:tubeSegments,arc:Math.PI*2.0*arcFraction}));};var shapes={// Reusable geometries
|
|
25916
25940
|
curve:torusGeometry(tubeRadius,0.25,14),curveHandle:torusGeometry(handleRadius,0.25,14),hoop:torusGeometry(tubeRadius,1,8),arrowHead:arrowGeometry(0.07,0.2),arrowHeadBig:arrowGeometry(0.09,0.25),arrowHeadHandle:tubeGeometry(handleRadius,0.37,8),axis:tubeGeometry(tubeRadius,arrowLength,20),axisHandle:tubeGeometry(handleRadius,arrowLength,20)};var colorMaterial=function colorMaterial(rgb){return new PhongMaterial(rootNode,{diffuse:rgb,emissive:rgb,ambient:[0.0,0.0,0.0],specular:[.6,.6,.3],shininess:80,lineWidth:2});};var highlightMaterial=function highlightMaterial(rgb,fillAlpha){return new EmphasisMaterial(rootNode,{edges:false,fill:true,fillColor:rgb,fillAlpha:fillAlpha});};var pickableMaterial=new PhongMaterial(rootNode,{// Invisible material for pickable handles, which define a pickable 3D area
|
|
25917
25941
|
diffuse:[1,1,0],alpha:0,// Invisible
|
|
25918
|
-
alphaMode:"blend"});var handlers={};var addAxis=function addAxis(rgb,
|
|
25919
|
-
var _s2=(v0-d01*v1)/det;math.addVec3(P,math.mulVec3Scalar(D,_s2,dst),dst);return true;}else{return false;}};}();var initOffset=math.vec3();var tempVec3=math.vec3();handlers[arrowHandle.id]=handlers[shaftHandle.id]={setActivated:function setActivated(a){return bigArrowHead.visible=a;},initDragAction:function initDragAction(initCanvasPos){return closestPointOnAxis(initCanvasPos,initOffset)&&math.subVec3(initOffset,pos,initOffset)&&function(canvasPos){if(closestPointOnAxis(canvasPos,tempVec3)){math.subVec3(tempVec3,initOffset,tempVec3);setPos(tempVec3);if(_this141._sectionPlane){_this141._sectionPlane.pos=tempVec3;}}};}};handlers[rotateHandle.id]={setActivated:function setActivated(a){return hoop.visible=a;},initDragAction:function initDragAction(initCanvasPos){var rotationFromCanvasPos=function(){var planeCanvasPos=camera.projectWorldPos(pos);localToWorldVec(rgb,tempVec3);math.transformVec3(camera.normalMatrix,tempVec3,tempVec3);var axisCoeff=Math.sign(tempVec3[2]);return function(canvasPos){var dx=canvasPos[0]-planeCanvasPos[0];var dy=canvasPos[1]-planeCanvasPos[1];return axisCoeff*Math.atan2(-dy,dx);};}();var lastRotation=rotationFromCanvasPos(initCanvasPos);return function(canvasPos){var rotation=rotationFromCanvasPos(canvasPos);rootNode.rotate(rgb,(rotation-lastRotation)*180/Math.PI);if(_this141._sectionPlane){ignoreNextSectionPlaneDirUpdate=true;_this141._sectionPlane.
|
|
25942
|
+
alphaMode:"blend"});var handlers={};var addAxis=function addAxis(rgb,hoopRot){math.mulVec3Scalar(rgb,-1,math.vec3());var material=colorMaterial(rgb);var hoopMatrix=math.quaternionToRotationMat4(hoopRot,math.identityMat4());math.mulMat4(math.rotationMat4v(Math.PI,[0,1,0],math.mat4()),hoopMatrix,hoopMatrix);var scale=math.scaleMat4v([0.6,0.6,0.6],math.identityMat4());var scaledArrowMatrix=function scaledArrowMatrix(t,matR){var matT=math.translateMat4v(t,math.identityMat4());var ret=math.identityMat4();math.mulMat4(matT,matR,ret);math.mulMat4(hoopMatrix,ret,ret);return math.mulMat4(ret,scale,math.identityMat4());};var curve=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.curve,material:material,matrix:hoopMatrix,pickable:false,collidable:true,clippable:false,backfaces:true,visible:false,isObject:false}),NO_STATE_INHERIT);var rotateHandle=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.curveHandle,material:pickableMaterial,matrix:hoopMatrix,pickable:true,collidable:true,clippable:false,backfaces:true,visible:false,isObject:false}),NO_STATE_INHERIT);var arrow1=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.arrowHead,material:material,matrix:scaledArrowMatrix([.8,.07,0],math.rotationMat4v(180*math.DEGTORAD,[0,0,1],math.identityMat4())),pickable:true,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var arrow2=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.arrowHead,material:material,matrix:scaledArrowMatrix([.07,.8,0],math.rotationMat4v(90*math.DEGTORAD,[0,0,1],math.identityMat4())),pickable:true,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var hoop=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.hoop,material:material,highlighted:true,highlightMaterial:highlightMaterial(rgb,0.6),matrix:hoopMatrix,pickable:false,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var axisRotation=math.quaternionToRotationMat4(math.vec3PairToQuaternion([0,1,0],rgb),math.identityMat4());math.mulMat4(math.rotationMat4v(Math.PI,[0,1,0],math.mat4()),axisRotation,axisRotation);var translatedAxisMatrix=function translatedAxisMatrix(yOffset){return math.mulMat4(axisRotation,math.translateMat4c(0,yOffset,0,math.identityMat4()),math.identityMat4());};var arrowMatrix=translatedAxisMatrix(arrowLength+.1);var shaftMatrix=translatedAxisMatrix(arrowLength/2);var arrow=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.arrowHead,material:material,matrix:arrowMatrix,pickable:false,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var arrowHandle=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.arrowHeadHandle,material:pickableMaterial,matrix:arrowMatrix,pickable:true,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var shaft=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.axis,material:material,matrix:shaftMatrix,pickable:false,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var shaftHandle=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.axisHandle,material:pickableMaterial,matrix:shaftMatrix,pickable:true,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var bigArrowHead=rootNode.addChild(new Mesh(rootNode,{geometry:shapes.arrowHeadBig,material:material,matrix:arrowMatrix,pickable:false,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT);var localToWorldVec=function localToWorldVec(localVec,worldVec){return math.vec3ApplyQuaternion(rootNode.quaternion,localVec,worldVec);};var closestPointOnAxis=function(){var worldAxis=math.vec3();var org=math.vec3();var dir=math.vec3();return function(canvasPos,dst){localToWorldVec(rgb,worldAxis);var P=pos;var D=worldAxis;math.canvasPosToWorldRay(canvas,scene.camera.viewMatrix,scene.camera.projMatrix,scene.camera.projection,canvasPos,org,dir);var d01=math.dotVec3(D,dir);var v=math.subVec3(org,P,dst);var v0=math.dotVec3(v,D);var v1=math.dotVec3(v,dir);var det=1-d01*d01;if(Math.abs(det)>1e-10){// if lines are not parallel
|
|
25943
|
+
var _s2=(v0-d01*v1)/det;math.addVec3(P,math.mulVec3Scalar(D,_s2,dst),dst);return true;}else{return false;}};}();var initOffset=math.vec3();var tempVec3=math.vec3();handlers[arrowHandle.id]=handlers[shaftHandle.id]={setActivated:function setActivated(a){return bigArrowHead.visible=a;},initDragAction:function initDragAction(initCanvasPos){return closestPointOnAxis(initCanvasPos,initOffset)&&math.subVec3(initOffset,pos,initOffset)&&function(canvasPos){if(closestPointOnAxis(canvasPos,tempVec3)){math.subVec3(tempVec3,initOffset,tempVec3);setPos(tempVec3);if(_this141._sectionPlane){_this141._sectionPlane.pos=tempVec3;}}};}};handlers[rotateHandle.id]={setActivated:function setActivated(a){return hoop.visible=a;},initDragAction:function initDragAction(initCanvasPos){var rotationFromCanvasPos=function(){var planeCanvasPos=camera.projectWorldPos(pos);localToWorldVec(rgb,tempVec3);math.transformVec3(camera.normalMatrix,tempVec3,tempVec3);var axisCoeff=Math.sign(tempVec3[2]);return function(canvasPos){var dx=canvasPos[0]-planeCanvasPos[0];var dy=canvasPos[1]-planeCanvasPos[1];return axisCoeff*Math.atan2(-dy,dx);};}();var lastRotation=rotationFromCanvasPos(initCanvasPos);return function(canvasPos){var rotation=rotationFromCanvasPos(canvasPos);rootNode.rotate(rgb,(rotation-lastRotation)*180/Math.PI);if(_this141._sectionPlane){ignoreNextSectionPlaneDirUpdate=true;_this141._sectionPlane.quaternion=rootNode.quaternion;}lastRotation=rotation;};}};return{set visible(v){arrow.visible=arrowHandle.visible=shaft.visible=shaftHandle.visible=curve.visible=rotateHandle.visible=arrow1.visible=arrow2.visible=v;if(!v){bigArrowHead.visible=v;hoop.visible=v;}},set culled(c){arrow.culled=arrowHandle.culled=shaft.culled=shaftHandle.culled=curve.culled=rotateHandle.culled=arrow1.culled=arrow2.culled=c;if(!c){bigArrowHead.culled=c;hoop.culled=c;}}};};this._displayMeshes=[// Meshes that are always visible
|
|
25920
25944
|
rootNode.addChild(new Mesh(rootNode,{// plane
|
|
25921
25945
|
geometry:new ReadableGeometry(rootNode,{primitive:"triangles",positions:[0.5,0.5,0.0,0.5,-0.5,0.0,// 0
|
|
25922
25946
|
-0.5,-0.5,0.0,-0.5,0.5,0.0,// 1
|
|
@@ -25928,10 +25952,10 @@ highlightMaterial:new EmphasisMaterial(rootNode,{edges:false,edgeColor:[0.0,0.0,
|
|
|
25928
25952
|
geometry:new ReadableGeometry(rootNode,buildSphereGeometry({radius:0.05})),material:new PhongMaterial(rootNode,{diffuse:[0.0,0.0,0.0],emissive:[0,0,0],ambient:[0.0,0.0,0.0],specular:[.6,.6,.3],shininess:80}),pickable:false,collidable:true,clippable:false,visible:false,isObject:false}),NO_STATE_INHERIT),//----------------------------------------------------------------------------------------------------------
|
|
25929
25953
|
//
|
|
25930
25954
|
//----------------------------------------------------------------------------------------------------------
|
|
25931
|
-
addAxis([1,0,0],[1,0,0],[
|
|
25955
|
+
addAxis([1,0,0],math.vec3PairToQuaternion([1,0,0],[0,0,1])),addAxis([0,1,0],math.eulerToQuaternion([90,0,0],"XYZ")),addAxis([0,0,1],math.identityQuaternion())];var cleanups=[];{// Keep gizmo screen size constant
|
|
25932
25956
|
var lastDist=-1;var setRootNodeScale=function setRootNodeScale(size){return rootNode.scale=[size,size,size];};var onSceneTick=scene.on("tick",function(){var dist=Math.abs(math.distVec3(camera.eye,pos));if(camera.projection==="perspective"){if(dist!==lastDist){setRootNodeScale(0.07*dist*Math.tan(camera.perspective.fov*math.DEGTORAD));}}else if(camera.projection==="ortho"){setRootNodeScale(camera.ortho.scale/10);}lastDist=dist;});cleanups.push(function(){return scene.off(onSceneTick);});}{var deactivateActive=null;var currentDrag=null;cleanups.push(function(){if(currentDrag){currentDrag.cleanup();}});var _canvasPos3=math.vec2();var copyCanvasPos=function copyCanvasPos(event,vec2){vec2[0]=event.clientX;vec2[1]=event.clientY;transformToNode(canvas.ownerDocument.documentElement,canvas,vec2);};var pickHandler=function pickHandler(e){copyCanvasPos(e,_canvasPos3);var pickResult=viewer.scene.pick({canvasPos:_canvasPos3});var pickEntity=pickResult&&pickResult.entity;var pickId=pickEntity&&pickEntity.id;return pickId in handlers&&handlers[pickId];};var startDrag=function startDrag(event,matchesEvent){var handler=pickHandler(matchesEvent(event));if(handler){if(currentDrag){currentDrag.cleanup();}var dragAction=handler.initDragAction(_canvasPos3);if(dragAction){cameraControl.pointerEnabled=false;// or .active = false ?
|
|
25933
25957
|
handler.setActivated(true);currentDrag={onChange:function onChange(event){var e=matchesEvent(event);if(e){copyCanvasPos(e,_canvasPos3);dragAction(_canvasPos3);}},cleanup:function cleanup(){currentDrag=null;cameraControl.pointerEnabled=true;// or .active = true ?
|
|
25934
|
-
handler.setActivated(false);}};}}};var addCanvasEventListener=function addCanvasEventListener(type,listener){canvas.addEventListener(type,listener);cleanups.push(function(){return canvas.removeEventListener(type,listener);});};addCanvasEventListener("mousedown",function(e){e.preventDefault();if(e.which===1){startDrag(e,function(event){return event.which===1&&event;});}});addCanvasEventListener("mousemove",function(e){if(currentDrag){currentDrag.onChange(e);}else{if(deactivateActive){deactivateActive();}var handler=pickHandler(e);if(handler){handler.setActivated(true);deactivateActive=function deactivateActive(){return handler.setActivated(false);};}else{deactivateActive=null;}}});addCanvasEventListener("mouseup",function(e){if(currentDrag){currentDrag.onChange(e);currentDrag.cleanup();}});addCanvasEventListener("touchstart",function(event){event.preventDefault();if(event.touches.length===1){var touchStartId=event.touches[0].identifier;startDrag(event,function(event){return _toConsumableArray(event.changedTouches).find(function(e){return e.identifier===touchStartId;});});}});addCanvasEventListener("touchmove",function(event){event.preventDefault();currentDrag&¤tDrag.onChange(event);});addCanvasEventListener("touchend",function(event){event.preventDefault();if(currentDrag){currentDrag.onChange(event);currentDrag.cleanup();}});}this._unbindSectionPlane=function(){};this.__setSectionPlane=function(sectionPlane){_this141.id=sectionPlane.id;_this141._sectionPlane=sectionPlane;var setPosFromSectionPlane=function setPosFromSectionPlane(){return setPos(sectionPlane.pos);};var setDirFromSectionPlane=function setDirFromSectionPlane(){return rootNode.quaternion=
|
|
25958
|
+
handler.setActivated(false);}};}}};var addCanvasEventListener=function addCanvasEventListener(type,listener){canvas.addEventListener(type,listener);cleanups.push(function(){return canvas.removeEventListener(type,listener);});};addCanvasEventListener("mousedown",function(e){e.preventDefault();if(e.which===1){startDrag(e,function(event){return event.which===1&&event;});}});addCanvasEventListener("mousemove",function(e){if(currentDrag){currentDrag.onChange(e);}else{if(deactivateActive){deactivateActive();}var handler=pickHandler(e);if(handler){handler.setActivated(true);deactivateActive=function deactivateActive(){return handler.setActivated(false);};}else{deactivateActive=null;}}});addCanvasEventListener("mouseup",function(e){if(currentDrag){currentDrag.onChange(e);currentDrag.cleanup();}});addCanvasEventListener("touchstart",function(event){event.preventDefault();if(event.touches.length===1){var touchStartId=event.touches[0].identifier;startDrag(event,function(event){return _toConsumableArray(event.changedTouches).find(function(e){return e.identifier===touchStartId;});});}});addCanvasEventListener("touchmove",function(event){event.preventDefault();currentDrag&¤tDrag.onChange(event);});addCanvasEventListener("touchend",function(event){event.preventDefault();if(currentDrag){currentDrag.onChange(event);currentDrag.cleanup();}});}this._unbindSectionPlane=function(){};this.__setSectionPlane=function(sectionPlane){_this141.id=sectionPlane.id;_this141._sectionPlane=sectionPlane;var setPosFromSectionPlane=function setPosFromSectionPlane(){return setPos(sectionPlane.pos);};var setDirFromSectionPlane=function setDirFromSectionPlane(){return rootNode.quaternion=sectionPlane.quaternion;};setPosFromSectionPlane();setDirFromSectionPlane();var onSectionPlanePos=sectionPlane.on("pos",setPosFromSectionPlane);var onSectionPlaneDir=sectionPlane.on("dir",function(){if(!ignoreNextSectionPlaneDirUpdate){setDirFromSectionPlane();}else{ignoreNextSectionPlaneDirUpdate=false;}});_this141._unbindSectionPlane=function(){_this141.id=null;_this141._sectionPlane=null;sectionPlane.off(onSectionPlanePos);sectionPlane.off(onSectionPlaneDir);_this141._unbindSectionPlane=function(){};};};this.__destroy=function(){cleanups.forEach(function(c){return c();});_this141._unbindSectionPlane();rootNode.destroy();_this141._displayMeshes=[];for(var id in handlers){delete handlers[id];}};}_createClass(Control,[{key:"_destroy",value:function _destroy(){this.__destroy();}/**
|
|
25935
25959
|
* Called by SectionPlanesPlugin to assign this Control to a SectionPlane.
|
|
25936
25960
|
* SectionPlanesPlugin keeps SectionPlaneControls in a reuse pool.
|
|
25937
25961
|
* Call with a null or undefined value to disconnect the Control ffrom whatever SectionPlane it was assigned to.
|