@xeokit/xeokit-sdk 2.4.0-alpha-19 → 2.4.0-alpha-21
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 +243 -206
- package/dist/xeokit-sdk.es.js +243 -206
- package/dist/xeokit-sdk.es5.js +174 -174
- package/dist/xeokit-sdk.min.cjs.js +3 -3
- package/dist/xeokit-sdk.min.es.js +3 -3
- package/dist/xeokit-sdk.min.es5.js +2 -2
- package/package.json +1 -1
package/dist/xeokit-sdk.es5.js
CHANGED
|
@@ -2160,7 +2160,7 @@ return false;}/**
|
|
|
2160
2160
|
* @type {Boolean}
|
|
2161
2161
|
* @abstract
|
|
2162
2162
|
*/},{key:"saoEnabled",get:function get(){return this.model.saoEnabled;}},{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 _i32=0,len=this.meshes.length;_i32<len;_i32++){this.meshes[_i32]._finalize(this._flags);}}},{key:"_finalize2",value:function _finalize2(){for(var _i33=0,len=this.meshes.length;_i33<len;_i33++){this.meshes[_i33]._finalize2();}}},{key:"_destroy",value:function _destroy(){// Called by VBOSceneModel
|
|
2163
|
-
var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(this.visible){scene._objectVisibilityUpdated(this,false);}if(this.xrayed){scene._objectXRayedUpdated(this);}if(this.selected){scene._objectSelectedUpdated(this);}if(this.highlighted){scene._objectHighlightedUpdated(this);}if(this._opacityUpdated){this.scene._objectColorizeUpdated(this,false);}if(this._opacityUpdated){this.scene._objectOpacityUpdated(this,false);}this.scene._objectOffsetUpdated(this,false);}for(var _i34=0,len=this.meshes.length;_i34<len;_i34++){this.meshes[_i34]._destroy();}scene._aabbDirty=true;}}]);return VBOSceneModelNode;}();var tempVec3a$
|
|
2163
|
+
var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(this.visible){scene._objectVisibilityUpdated(this,false);}if(this.xrayed){scene._objectXRayedUpdated(this);}if(this.selected){scene._objectSelectedUpdated(this);}if(this.highlighted){scene._objectHighlightedUpdated(this);}if(this._opacityUpdated){this.scene._objectColorizeUpdated(this,false);}if(this._opacityUpdated){this.scene._objectOpacityUpdated(this,false);}this.scene._objectOffsetUpdated(this,false);}for(var _i34=0,len=this.meshes.length;_i34<len;_i34++){this.meshes[_i34]._destroy();}scene._aabbDirty=true;}}]);return VBOSceneModelNode;}();var tempVec3a$1i=math.vec3();/**
|
|
2164
2164
|
* Given a view matrix and a relative-to-center (RTC) coordinate origin, returns a view matrix
|
|
2165
2165
|
* to transform RTC coordinates to View-space.
|
|
2166
2166
|
*
|
|
@@ -2194,7 +2194,7 @@ var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(t
|
|
|
2194
2194
|
* @returns {Boolean} ````True```` if the positions actually needed conversion to RTC, else ````false````. When
|
|
2195
2195
|
* ````false````, we can safely ignore the data returned in ````rtcPositions```` and ````rtcCenter````,
|
|
2196
2196
|
* since ````rtcCenter```` will equal ````[0,0,0]````, and ````rtcPositions```` will contain identical values to ````positions````.
|
|
2197
|
-
*/function worldToRTCPositions(worldPositions,rtcPositions,rtcCenter){var cellSize=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1000;var center=math.getPositionsCenter(worldPositions,tempVec3a$
|
|
2197
|
+
*/function worldToRTCPositions(worldPositions,rtcPositions,rtcCenter){var cellSize=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1000;var center=math.getPositionsCenter(worldPositions,tempVec3a$1i);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 _i35=0,len=worldPositions.length;_i35<len;_i35+=3){rtcPositions[_i35+0]=worldPositions[_i35+0]-rtcCenterX;rtcPositions[_i35+1]=worldPositions[_i35+1]-rtcCenterY;rtcPositions[_i35+2]=worldPositions[_i35+2]-rtcCenterZ;}}return rtcNeeded;}/**
|
|
2198
2198
|
* Given a 3D plane defined by distance from origin and direction, and an RTC center position,
|
|
2199
2199
|
* return a plane position that is relative to the RTC center.
|
|
2200
2200
|
*
|
|
@@ -2204,7 +2204,7 @@ var scene=this.model.scene;if(this._isObject){scene._deregisterObject(this);if(t
|
|
|
2204
2204
|
* @param rtcCenter
|
|
2205
2205
|
* @param rtcPlanePos
|
|
2206
2206
|
* @returns {*}
|
|
2207
|
-
*/function getPlaneRTCPos(dist,dir,rtcCenter,rtcPlanePos){var rtcCenterToPlaneDist=math.dotVec3(dir,rtcCenter)+dist;var dirNormalized=math.normalizeVec3(dir,tempVec3a$
|
|
2207
|
+
*/function getPlaneRTCPos(dist,dir,rtcCenter,rtcPlanePos){var rtcCenterToPlaneDist=math.dotVec3(dir,rtcCenter)+dist;var dirNormalized=math.normalizeVec3(dir,tempVec3a$1i);math.mulVec3Scalar(dirNormalized,-rtcCenterToPlaneDist,rtcPlanePos);return rtcPlanePos;}var tempVec4a$c=math.vec4();var tempVec4b$c=math.vec4();/**
|
|
2208
2208
|
* @desc Tracks the World, View and Canvas coordinates, and visibility, of a position within a {@link Scene}.
|
|
2209
2209
|
*
|
|
2210
2210
|
* ## Position
|
|
@@ -2405,7 +2405,7 @@ _this7._onEntityModelDestroyed=null;});}else{this._onEntityDestroyed=this._entit
|
|
|
2405
2405
|
*/},{key:"visible",get:function get(){return!!this._visible;}/**
|
|
2406
2406
|
* Destroys this Marker.
|
|
2407
2407
|
*/},{key:"destroy",value:function destroy(){this.fire("destroyed",true);this.scene.camera.off(this._onCameraViewMatrix);this.scene.camera.off(this._onCameraProjMatrix);if(this._entity){if(this._onEntityDestroyed!==null){this._entity.off(this._onEntityDestroyed);}if(this._onEntityModelDestroyed!==null){this._entity.model.off(this._onEntityModelDestroyed);}}this._renderer.removeMarker(this);_get(_getPrototypeOf(Marker.prototype),"destroy",this).call(this);}}]);return Marker;}(Component);/** @private */var Wire=/*#__PURE__*/function(){function Wire(parentElement){var _this8=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;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";
|
|
2408
|
-
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"]="all";if(cfg.onContextMenu);parentElement.appendChild(wireClickable);if(cfg.onMouseOver){wireClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this8);});}if(cfg.onMouseLeave){wireClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this8);});}if(cfg.onContextMenu){wireClickable.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this8);event.preventDefault();});}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']='rotate('+angle+'deg)';wireStyle['-moz-transform']='rotate('+angle+'deg)';wireStyle['-ms-transform']='rotate('+angle+'deg)';wireStyle['-o-transform']='rotate('+angle+'deg)';wireStyle['transform']='rotate('+angle+'deg)';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']='rotate('+angle+'deg)';wireClickableStyle['-moz-transform']='rotate('+angle+'deg)';wireClickableStyle['-ms-transform']='rotate('+angle+'deg)';wireClickableStyle['-o-transform']='rotate('+angle+'deg)';wireClickableStyle['transform']='rotate('+angle+'deg)';}},{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:"setVisible",value:function setVisible(visible){visible=!!visible;if(this._visible===visible){return;}this._wire.style.visibility=visible?"visible":"hidden";}},{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){this._wire.parentElement.removeChild(this._wire);this._wireClickable.parentElement.removeChild(this._wireClickable);}}]);return Wire;}();/** @private */var Dot=/*#__PURE__*/function(){function Dot(parentElement){var _this9=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._visible=true;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';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=cfg.visible!==false?"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);if(cfg.onMouseOver){dotClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this9);});}if(cfg.onMouseLeave){dotClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this9);});}if(cfg.onContextMenu){dotClickable.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this9);event.preventDefault();});}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)-4+'px';dotStyle["top"]=Math.round(y)-4+'px';var dotClickableStyle=this._dotClickable.style;dotClickableStyle["left"]=Math.round(x)-9+'px';dotClickableStyle["top"]=Math.round(y)-9+'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:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._dot.style.visibility=this._visible?"visible":"hidden";}},{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);this._dot.parentElement.removeChild(this._dot);this._dotClickable.parentElement.removeChild(this._dotClickable);}}]);return Dot;}();/** @private */var Label=/*#__PURE__*/function(){function Label(parentElement){var _this10=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';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,_this10);event.preventDefault();});}if(cfg.onMouseLeave){label.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this10);event.preventDefault();});}if(cfg.onContextMenu){label.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this10);event.preventDefault();});}}_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:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{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:"destroy",value:function destroy(){this._label.parentElement.removeChild(this._label);}}]);return Label;}();var originVec=math.vec3();var targetVec=math.vec3();/**
|
|
2408
|
+
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"]="all";if(cfg.onContextMenu);parentElement.appendChild(wireClickable);if(cfg.onMouseOver){wireClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this8);});}if(cfg.onMouseLeave){wireClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this8);});}if(cfg.onMouseWheel){wireClickable.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this8);});}if(cfg.onContextMenu){wireClickable.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this8);event.preventDefault();});}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']='rotate('+angle+'deg)';wireStyle['-moz-transform']='rotate('+angle+'deg)';wireStyle['-ms-transform']='rotate('+angle+'deg)';wireStyle['-o-transform']='rotate('+angle+'deg)';wireStyle['transform']='rotate('+angle+'deg)';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']='rotate('+angle+'deg)';wireClickableStyle['-moz-transform']='rotate('+angle+'deg)';wireClickableStyle['-ms-transform']='rotate('+angle+'deg)';wireClickableStyle['-o-transform']='rotate('+angle+'deg)';wireClickableStyle['transform']='rotate('+angle+'deg)';}},{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:"setVisible",value:function setVisible(visible){visible=!!visible;if(this._visible===visible){return;}this._wire.style.visibility=visible?"visible":"hidden";}},{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){this._wire.parentElement.removeChild(this._wire);this._wireClickable.parentElement.removeChild(this._wireClickable);}}]);return Wire;}();/** @private */var Dot=/*#__PURE__*/function(){function Dot(parentElement){var _this9=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._visible=true;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';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=cfg.visible!==false?"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);if(cfg.onMouseOver){dotClickable.addEventListener('mouseover',function(event){cfg.onMouseOver(event,_this9);});}if(cfg.onMouseLeave){dotClickable.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this9);});}if(cfg.onMouseWheel){dotClickable.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this9);});}if(cfg.onContextMenu){dotClickable.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this9);event.preventDefault();});}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)-4+'px';dotStyle["top"]=Math.round(y)-4+'px';var dotClickableStyle=this._dotClickable.style;dotClickableStyle["left"]=Math.round(x)-9+'px';dotClickableStyle["top"]=Math.round(y)-9+'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:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._dot.style.visibility=this._visible?"visible":"hidden";}},{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);this._dot.parentElement.removeChild(this._dot);this._dotClickable.parentElement.removeChild(this._dotClickable);}}]);return Dot;}();/** @private */var Label=/*#__PURE__*/function(){function Label(parentElement){var _this10=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';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,_this10);event.preventDefault();});}if(cfg.onMouseLeave){label.addEventListener('mouseleave',function(event){cfg.onMouseLeave(event,_this10);event.preventDefault();});}if(cfg.onMouseWheel){label.addEventListener('wheel',function(event){cfg.onMouseWheel(event,_this10);});}if(cfg.onContextMenu){label.addEventListener('contextmenu',function(event){cfg.onContextMenu(event,_this10);event.preventDefault();});}}_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:"setVisible",value:function setVisible(visible){if(this._visible===visible){return;}this._visible=!!visible;this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{key:"setCulled",value:function setCulled(culled){if(this._culled===culled){return;}this._culled=!!culled;this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden";}},{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:"destroy",value:function destroy(){this._label.parentElement.removeChild(this._label);}}]);return Label;}();var originVec=math.vec3();var targetVec=math.vec3();/**
|
|
2409
2409
|
* @desc Measures the angle indicated by three 3D points.
|
|
2410
2410
|
*
|
|
2411
2411
|
* See {@link AngleMeasurementsPlugin} for more info.
|
|
@@ -2930,7 +2930,7 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
|
|
|
2930
2930
|
* Destroys this Annotation.
|
|
2931
2931
|
*
|
|
2932
2932
|
* You can also call {@link AnnotationsPlugin#destroyAnnotation}.
|
|
2933
|
-
*/},{key:"destroy",value:function destroy(){if(this._marker){if(!this._markerExternal){this._marker.parentNode.removeChild(this._marker);}else{this._marker.removeEventListener("click",this._onMouseClickedExternalMarker);this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker);this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker);this._marker=null;}}if(this._label){if(!this._labelExternal){this._label.parentNode.removeChild(this._label);}this._label=null;}this.scene.off(this._onTick);_get(_getPrototypeOf(Annotation.prototype),"destroy",this).call(this);}}]);return Annotation;}(Marker);var tempVec3a$
|
|
2933
|
+
*/},{key:"destroy",value:function destroy(){if(this._marker){if(!this._markerExternal){this._marker.parentNode.removeChild(this._marker);}else{this._marker.removeEventListener("click",this._onMouseClickedExternalMarker);this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker);this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker);this._marker=null;}}if(this._label){if(!this._labelExternal){this._label.parentNode.removeChild(this._label);}this._label=null;}this.scene.off(this._onTick);_get(_getPrototypeOf(Annotation.prototype),"destroy",this).call(this);}}]);return Annotation;}(Marker);var tempVec3a$1h=math.vec3();var tempVec3b$d=math.vec3();var tempVec3c$9=math.vec3();/**
|
|
2934
2934
|
* {@link Viewer} plugin that creates {@link Annotation}s.
|
|
2935
2935
|
*
|
|
2936
2936
|
* [<img src="https://user-images.githubusercontent.com/83100/58403089-26589280-8062-11e9-8652-aed61a4e8c64.gif">](https://xeokit.github.io/xeokit-sdk/examples/#annotations_clickFlyToPosition)
|
|
@@ -3349,7 +3349,7 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
|
|
|
3349
3349
|
* @param {Number[]} [params.up] Optional World-space position for {@link Camera#up}, used when this Annotation is associated with a {@link Camera} position.
|
|
3350
3350
|
* @param {String} [params.projection] Optional projection type for {@link Camera#projection}, used when this Annotation is associated with a {@link Camera} position.
|
|
3351
3351
|
* @returns {Annotation} The new {@link Annotation}.
|
|
3352
|
-
*/,set:function set(surfaceOffset){if(surfaceOffset===undefined||surfaceOffset===null){surfaceOffset=0.3;}this._surfaceOffset=surfaceOffset;}},{key:"createAnnotation",value:function createAnnotation(params){var _this19=this;if(this.viewer.scene.components[params.id]){this.error("Viewer component with this ID already exists: "+params.id);delete params.id;}var worldPos;var entity;params.pickResult=params.pickResult||params.pickRecord;if(params.pickResult){var pickResult=params.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$
|
|
3352
|
+
*/,set:function set(surfaceOffset){if(surfaceOffset===undefined||surfaceOffset===null){surfaceOffset=0.3;}this._surfaceOffset=surfaceOffset;}},{key:"createAnnotation",value:function createAnnotation(params){var _this19=this;if(this.viewer.scene.components[params.id]){this.error("Viewer component with this ID already exists: "+params.id);delete params.id;}var worldPos;var entity;params.pickResult=params.pickResult||params.pickRecord;if(params.pickResult){var pickResult=params.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$1h);var offsetVec=math.mulVec3Scalar(normalizedWorldNormal,this._surfaceOffset,tempVec3b$d);var offsetWorldPos=math.addVec3(pickResult.worldPos,offsetVec,tempVec3c$9);worldPos=offsetWorldPos;entity=pickResult.entity;}}else{worldPos=params.worldPos;entity=params.entity;}var markerElement=null;if(params.markerElementId){markerElement=document.getElementById(params.markerElementId);if(!markerElement){this.error("Can't find DOM element for 'markerElementId' value '"+params.markerElementId+"' - defaulting to internally-generated empty DIV");}}var labelElement=null;if(params.labelElementId){labelElement=document.getElementById(params.labelElementId);if(!labelElement){this.error("Can't find DOM element for 'labelElementId' value '"+params.labelElementId+"' - defaulting to internally-generated empty DIV");}}var annotation=new Annotation(this.viewer.scene,{id:params.id,plugin:this,entity:entity,worldPos:worldPos,container:this._container,markerElement:markerElement,labelElement:labelElement,markerHTML:params.markerHTML||this._markerHTML,labelHTML:params.labelHTML||this._labelHTML,occludable:params.occludable,values:utils.apply(params.values,utils.apply(this._values,{})),markerShown:params.markerShown,labelShown:params.labelShown,eye:params.eye,look:params.look,up:params.up,projection:params.projection,visible:params.visible!==false});this.annotations[annotation.id]=annotation;annotation.on("destroyed",function(){delete _this19.annotations[annotation.id];_this19.fire("annotationDestroyed",annotation.id);});this.fire("annotationCreated",annotation.id);return annotation;}/**
|
|
3353
3353
|
* Destroys an {@link Annotation}.
|
|
3354
3354
|
*
|
|
3355
3355
|
* @param {String} id ID of Annotation to destroy.
|
|
@@ -4032,7 +4032,7 @@ this.positionsBuf.setData(this.positions);// Indices don't need updating
|
|
|
4032
4032
|
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
|
|
4033
4033
|
var boundary=canvas.boundary;var canvasWidth=boundary[2];var canvasHeight=boundary[3];var lenPixels=0;this.lenOcclusionTestList=0;for(var _i41=0;_i41<this.numMarkers;_i41++){var marker=this.markerList[_i41];var _viewPos=marker.viewPos;if(_viewPos[2]>-near){// Clipped by near plane
|
|
4034
4034
|
marker._setVisible(false);continue;}var _canvasPos=marker.canvasPos;var canvasX=_canvasPos[0];var canvasY=_canvasPos[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 _i42=0;_i42<numSectionPlanes;_i42++){var sectionPlane=sectionPlanes[_i42];if(!sectionPlane.active){this.sectionPlanesActive[_i42]=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[_i42]=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 MARKER_SPRITE_CLIPZ_OFFSET=-0.001;// Amount that we offset sprite clip Z coords to raise them from surfaces
|
|
4035
|
-
var tempVec3a$
|
|
4035
|
+
var tempVec3a$1g=math.vec3();/**
|
|
4036
4036
|
* Manages occlusion testing. Private member of a Renderer.
|
|
4037
4037
|
*/var OcclusionTester=/*#__PURE__*/function(){function OcclusionTester(scene,renderBufferManager){var _this22=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 ?
|
|
4038
4038
|
this._programDirty=false;// Need to build shader program ?
|
|
@@ -4054,7 +4054,7 @@ this._markersToOcclusionLayersMap={};this._onCameraViewMatrix=scene.camera.on("v
|
|
|
4054
4054
|
* then calls drawMarkers() and doOcclusionTest().
|
|
4055
4055
|
*/},{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 _i43=0,len=this._occlusionLayersList.length;_i43<len;_i43++){var occlusionLayer=this._occlusionLayersList[_i43];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{src.push("clipPos.z += "+MARKER_SPRITE_CLIPZ_OFFSET+";");}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 _i44=0;_i44<sectionPlanesState.sectionPlanes.length;_i44++){src.push("uniform bool sectionPlaneActive"+_i44+";");src.push("uniform vec3 sectionPlanePos"+_i44+";");src.push("uniform vec3 sectionPlaneDir"+_i44+";");}}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 _i45=0,len=sectionPlanes.length;_i45<len;_i45++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i45),pos:program.getLocation("sectionPlanePos"+_i45),dir:program.getLocation("sectionPlaneDir"+_i45)});}this._aPosition=program.getAttribute("position");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}/**
|
|
4056
4056
|
* Draws {@link Marker}s to the render buffer.
|
|
4057
|
-
*/},{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 _i46=0,len=this._occlusionLayersList.length;_i46<len;_i46++){var occlusionLayer=this._occlusionLayersList[_i46];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$
|
|
4057
|
+
*/},{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 _i46=0,len=this._occlusionLayersList.length;_i46<len;_i46++){var occlusionLayer=this._occlusionLayersList[_i46];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$1g));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);}}/**
|
|
4058
4058
|
* Sets visibilities of {@link Marker}s according to whether or not they are obscured by anything in the render buffer.
|
|
4059
4059
|
*/},{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 _i47=0,len=this._occlusionLayersList.length;_i47<len;_i47++){var occlusionLayer=this._occlusionLayersList[_i47];for(var _i48=0;_i48<occlusionLayer.lenOcclusionTestList;_i48++){var marker=occlusionLayer.occlusionTestList[_i48];var j=_i48*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);}}}}/**
|
|
4060
4060
|
* Unbinds render buffer.
|
|
@@ -4902,7 +4902,7 @@ _this27.left=cfg.left;_this27.right=cfg.right;_this27.bottom=cfg.bottom;_this27.
|
|
|
4902
4902
|
* @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates.
|
|
4903
4903
|
*/},{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
|
|
4904
4904
|
*
|
|
4905
|
-
*/},{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$
|
|
4905
|
+
*/},{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$c=math.vec3();var tempVec3c$8=math.vec3();var tempVec3d$4=math.vec3();var tempVec3e$3=math.vec3();var tempVec3f$3=math.vec3();var tempMat=math.mat4();var tempMatb=math.mat4();var eyeLookVec=math.vec3();var eyeLookVecNorm=math.vec3();var eyeLookOffset=math.vec3();var offsetEye=math.vec3();/**
|
|
4906
4906
|
* @desc Manages viewing and projection transforms for its {@link Scene}.
|
|
4907
4907
|
*
|
|
4908
4908
|
* * One Camera per {@link Scene}
|
|
@@ -5105,29 +5105,29 @@ var eye;if(this.projection==="ortho"){math.subVec3(this._eye,this._look,eyeLookV
|
|
|
5105
5105
|
* Rotates {@link Camera#eye} about {@link Camera#look}, around the {@link Camera#up} vector
|
|
5106
5106
|
*
|
|
5107
5107
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
5108
|
-
*/},{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$
|
|
5108
|
+
*/},{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$c);this.eye=math.addVec3(this._look,lookEyeVec,tempVec3c$8);// Set eye position as 'look' plus 'eye' vector
|
|
5109
5109
|
this.up=math.transformPoint3(tempMat,this._up,tempVec3d$4);// Rotate 'up' vector
|
|
5110
5110
|
}/**
|
|
5111
5111
|
* Rotates {@link Camera#eye} about {@link Camera#look} around the right axis (orthogonal to {@link Camera#up} and "look").
|
|
5112
5112
|
*
|
|
5113
5113
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
5114
|
-
*/},{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$
|
|
5114
|
+
*/},{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$c),math.normalizeVec3(this._up,tempVec3c$8));math.rotationMat4v(angleInc*0.0174532925,left,tempMat);eye2=math.transformPoint3(tempMat,eye2,tempVec3d$4);this.up=math.transformPoint3(tempMat,this._up,tempVec3e$3);this.eye=math.addVec3(eye2,this._look,tempVec3f$3);}/**
|
|
5115
5115
|
* Rotates {@link Camera#look} about {@link Camera#eye}, around the {@link Camera#up} vector.
|
|
5116
5116
|
*
|
|
5117
5117
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
5118
|
-
*/},{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$
|
|
5118
|
+
*/},{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$c);this.look=math.addVec3(look2,this._eye,tempVec3c$8);if(this._gimbalLock){this.up=math.transformPoint3(tempMat,this._up,tempVec3d$4);}}/**
|
|
5119
5119
|
* Rotates {@link Camera#look} about {@link Camera#eye}, around the right axis (orthogonal to {@link Camera#up} and "look").
|
|
5120
5120
|
|
|
5121
5121
|
* @param {Number} angleInc Angle of rotation in degrees
|
|
5122
|
-
*/},{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$
|
|
5122
|
+
*/},{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$c),math.normalizeVec3(this._up,tempVec3c$8));math.rotationMat4v(angleInc*0.0174532925,left,tempMat);this.up=math.transformPoint3(tempMat,this._up,tempVec3f$3);look2=math.transformPoint3(tempMat,look2,tempVec3d$4);this.look=math.addVec3(look2,this._eye,tempVec3e$3);}/**
|
|
5123
5123
|
* Pans the Camera along its local X, Y and Z axis.
|
|
5124
5124
|
*
|
|
5125
5125
|
* @param pan The pan vector
|
|
5126
|
-
*/},{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$
|
|
5126
|
+
*/},{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$c));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$8),_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$4),_pan[2]);vec[0]+=v[0];vec[1]+=v[1];vec[2]+=v[2];}this.eye=math.addVec3(this._eye,vec,tempVec3e$3);this.look=math.addVec3(this._look,vec,tempVec3f$3);}/**
|
|
5127
5127
|
* Increments/decrements the Camera's zoom factor, which is the distance between {@link Camera#eye} and {@link Camera#look}.
|
|
5128
5128
|
*
|
|
5129
5129
|
* @param {Number} delta Zoom factor increment.
|
|
5130
|
-
*/},{key:"zoom",value:function zoom(delta){var vec=math.subVec3(this._eye,this._look,tempVec3$6);var lenLook=Math.abs(math.lenVec3(vec,tempVec3b$
|
|
5130
|
+
*/},{key:"zoom",value:function zoom(delta){var vec=math.subVec3(this._eye,this._look,tempVec3$6);var lenLook=Math.abs(math.lenVec3(vec,tempVec3b$c));var newLenLook=Math.abs(lenLook+delta);if(newLenLook<0.5){return;}var dir=math.normalizeVec3(vec,tempVec3c$8);this.eye=math.addVec3(this._look,math.mulVec3Scalar(dir,newLenLook),tempVec3d$4);}/**
|
|
5131
5131
|
* Sets the position of the Camera's eye.
|
|
5132
5132
|
*
|
|
5133
5133
|
* Default value is ````[0,0,10]````.
|
|
@@ -5346,9 +5346,9 @@ this.fire("look",this._look);}},{key:"up",get:/**
|
|
|
5346
5346
|
*/,set:function set(value){value=value||"perspective";if(this._projectionType===value){return;}if(value==="perspective"){this._project=this._perspective;}else if(value==="ortho"){this._project=this._ortho;}else if(value==="frustum"){this._project=this._frustum;}else if(value==="customProjection"){this._project=this._customProjection;}else{this.error("Unsupported value for 'projection': "+value+" defaulting to 'perspective'");this._project=this._perspective;value="perspective";}this._project._update();this._projectionType=value;this.glRedraw();this._update();// Need to rebuild lookat matrix with full eye, look & up
|
|
5347
5347
|
this.fire("dirty");this.fire("projection",this._projectionType);this.fire("projMatrix",this._project.matrix);}},{key:"project",get:function get(){return this._project;}/**
|
|
5348
5348
|
* Destroys this Camera.
|
|
5349
|
-
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(Camera.prototype),"destroy",this).call(this);this._state.destroy();}}]);return Camera;}(Component);var tempVec4$9=math.vec4();var tempVec3a$
|
|
5349
|
+
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(Camera.prototype),"destroy",this).call(this);this._state.destroy();}}]);return Camera;}(Component);var tempVec4$9=math.vec4();var tempVec3a$1f=math.vec3();/**
|
|
5350
5350
|
* @private
|
|
5351
|
-
*/var TrianglesDataTextureColorRenderer=/*#__PURE__*/function(){function TrianglesDataTextureColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesDataTextureColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5351
|
+
*/var TrianglesDataTextureColorRenderer=/*#__PURE__*/function(){function TrianglesDataTextureColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesDataTextureColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1f);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5352
5352
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5353
5353
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5354
5354
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i68=0,len=lights.length;_i68<len;_i68++){light=lights[_i68];switch(light.type){case"dir":this._uLightColor[_i68]=program.getLocation("lightColor"+_i68);this._uLightPos[_i68]=null;this._uLightDir[_i68]=program.getLocation("lightDir"+_i68);break;case"point":this._uLightColor[_i68]=program.getLocation("lightColor"+_i68);this._uLightPos[_i68]=program.getLocation("lightPos"+_i68);this._uLightDir[_i68]=null;this._uLightAttenuation[_i68]=program.getLocation("lightAttenuation"+_i68);break;case"spot":this._uLightColor[_i68]=program.getLocation("lightColor"+_i68);this._uLightPos[_i68]=program.getLocation("lightPos"+_i68);this._uLightDir[_i68]=program.getLocation("lightDir"+_i68);this._uLightAttenuation[_i68]=program.getLocation("lightAttenuation"+_i68);break;}}this._uSectionPlanes=[];for(var _i69=0,_len6=scene._sectionPlanesState.sectionPlanes.length;_i69<_len6;_i69++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i69),pos:program.getLocation("sectionPlanePos"+_i69),dir:program.getLocation("sectionPlaneDir"+_i69)});}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5398,9 +5398,9 @@ src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_Ver
|
|
|
5398
5398
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");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 _i72=0,_len7=lightsState.lights.length;_i72<_len7;_i72++){light=lightsState.lights[_i72];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i72+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i72+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+_i72+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+_i72+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i72+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i72+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i72+".rgb * lightColor"+_i72+".a);");}src.push("vec3 rgb = vec3(color.rgb) / 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("vFlags2 = flags2.r;");}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.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture 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("flat in uint vFlags2;");for(var _i73=0,len=sectionPlanesState.sectionPlanes.length;_i73<len;_i73++){src.push("uniform bool sectionPlaneActive"+_i73+";");src.push("uniform vec3 sectionPlanePos"+_i73+";");src.push("uniform vec3 sectionPlaneDir"+_i73+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i74=0,_len8=sectionPlanesState.sectionPlanes.length;_i74<_len8;_i74++){src.push("if (sectionPlaneActive"+_i74+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i74+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i74+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
|
|
5399
5399
|
src.push(" gl_FragDepth = 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
|
|
5400
5400
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
5401
|
-
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureColorRenderer;}();var defaultColor$6=new Float32Array([1,1,1]);math.vec4();var tempVec3a$
|
|
5401
|
+
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureColorRenderer;}();var defaultColor$6=new Float32Array([1,1,1]);math.vec4();var tempVec3a$1e=math.vec3();/**
|
|
5402
5402
|
* @private
|
|
5403
|
-
*/var TrianglesDataTextureSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesDataTextureSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,TrianglesDataTextureSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES$1.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES$1.SILHOUETTE_HIGHLIGHTED){var _material=scene.highlightMaterial._state;var _fillColor=_material.fillColor;var _fillAlpha=_material.fillAlpha;gl.uniform4f(this._uColor,_fillColor[0],_fillColor[1],_fillColor[2],_fillAlpha);}else if(renderPass===RENDER_PASSES$1.SILHOUETTE_SELECTED){var _material2=scene.selectedMaterial._state;var _fillColor2=_material2.fillColor;var _fillAlpha2=_material2.fillAlpha;gl.uniform4f(this._uColor,_fillColor2[0],_fillColor2[1],_fillColor2[2],_fillAlpha2);}else{gl.uniform4fv(this._uColor,defaultColor$6);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5403
|
+
*/var TrianglesDataTextureSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesDataTextureSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,TrianglesDataTextureSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES$1.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES$1.SILHOUETTE_HIGHLIGHTED){var _material=scene.highlightMaterial._state;var _fillColor=_material.fillColor;var _fillAlpha=_material.fillAlpha;gl.uniform4f(this._uColor,_fillColor[0],_fillColor[1],_fillColor[2],_fillAlpha);}else if(renderPass===RENDER_PASSES$1.SILHOUETTE_SELECTED){var _material2=scene.selectedMaterial._state;var _fillColor2=_material2.fillColor;var _fillAlpha2=_material2.fillAlpha;gl.uniform4f(this._uColor,_fillColor2[0],_fillColor2[1],_fillColor2[2],_fillAlpha2);}else{gl.uniform4fv(this._uColor,defaultColor$6);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1e);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5404
5404
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5405
5405
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5406
5406
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uColor=program.getLocation("color");this._uSectionPlanes=[];for(var _i75=0,len=scene._sectionPlanesState.sectionPlanes.length;_i75<len;_i75++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i75),pos:program.getLocation("sectionPlanePos"+_i75),dir:program.getLocation("sectionPlaneDir"+_i75)});}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5443,9 +5443,9 @@ src.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(i
|
|
|
5443
5443
|
src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");// when the geometry is not solid, if needed, flip the triangle winding
|
|
5444
5444
|
src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("viewNormal = -viewNormal;");src.push("}");src.push("} else {");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("viewNormal = -viewNormal;");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5445
5445
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");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("vFlags2 = flags2.r;");}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.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture 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("varying float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i76=0,len=sectionPlanesState.sectionPlanes.length;_i76<len;_i76++){src.push("uniform bool sectionPlaneActive"+_i76+";");src.push("uniform vec3 sectionPlanePos"+_i76+";");src.push("uniform vec3 sectionPlaneDir"+_i76+";");}}src.push("uniform vec4 color;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i77=0,_len9=sectionPlanesState.sectionPlanes.length;_i77<_len9;_i77++){src.push("if (sectionPlaneActive"+_i77+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i77+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i77+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
|
|
5446
|
-
src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = color;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureSilhouetteRenderer;}();var tempVec3a$
|
|
5446
|
+
src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = color;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureSilhouetteRenderer;}();var tempVec3a$1d=math.vec3();var defaultColor$5=new Float32Array([0,0,0,1]);/**
|
|
5447
5447
|
* @private
|
|
5448
|
-
*/var TrianglesDataTextureEdgesRenderer=/*#__PURE__*/function(){function TrianglesDataTextureEdgesRenderer(scene){_classCallCheck(this,TrianglesDataTextureEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES$1.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES$1.EDGES_HIGHLIGHTED){var _material3=scene.highlightMaterial._state;var _edgeColor=_material3.edgeColor;var _edgeAlpha=_material3.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor[0],_edgeColor[1],_edgeColor[2],_edgeAlpha);}else if(renderPass===RENDER_PASSES$1.EDGES_SELECTED){var _material4=scene.selectedMaterial._state;var _edgeColor2=_material4.edgeColor;var _edgeAlpha2=_material4.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor2[0],_edgeColor2[1],_edgeColor2[2],_edgeAlpha2);}else{gl.uniform4fv(this._uColor,defaultColor$5);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5448
|
+
*/var TrianglesDataTextureEdgesRenderer=/*#__PURE__*/function(){function TrianglesDataTextureEdgesRenderer(scene){_classCallCheck(this,TrianglesDataTextureEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES$1.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES$1.EDGES_HIGHLIGHTED){var _material3=scene.highlightMaterial._state;var _edgeColor=_material3.edgeColor;var _edgeAlpha=_material3.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor[0],_edgeColor[1],_edgeColor[2],_edgeAlpha);}else if(renderPass===RENDER_PASSES$1.EDGES_SELECTED){var _material4=scene.selectedMaterial._state;var _edgeColor2=_material4.edgeColor;var _edgeAlpha2=_material4.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor2[0],_edgeColor2[1],_edgeColor2[2],_edgeAlpha2);}else{gl.uniform4fv(this._uColor,defaultColor$5);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1d);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numEdgeIndices8Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8// 8 bits edge indices
|
|
5449
5449
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices8Bits);}if(state.numEdgeIndices16Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16// 16 bits edge indices
|
|
5450
5450
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices16Bits);}if(state.numEdgeIndices32Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32// 32 bits edge indices
|
|
5451
5451
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uColor=program.getLocation("color");this._uSectionPlanes=[];for(var _i78=0,len=scene._sectionPlanesState.sectionPlanes.length;_i78<len;_i78++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i78),pos:program.getLocation("sectionPlanePos"+_i78),dir:program.getLocation("sectionPlaneDir"+_i78)});}//this._aOffset = program.getAttribute("offset");
|
|
@@ -5483,9 +5483,9 @@ src.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(obj
|
|
|
5483
5483
|
src.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);");// chipmunk
|
|
5484
5484
|
// get position
|
|
5485
5485
|
src.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5486
|
-
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry edges drawing fragment shader");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}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("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i79=0,len=sectionPlanesState.sectionPlanes.length;_i79<len;_i79++){src.push("uniform bool sectionPlaneActive"+_i79+";");src.push("uniform vec3 sectionPlanePos"+_i79+";");src.push("uniform vec3 sectionPlaneDir"+_i79+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i80=0,_len10=sectionPlanesState.sectionPlanes.length;_i80<_len10;_i80++){src.push("if (sectionPlaneActive"+_i80+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i80+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i80+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureEdgesRenderer;}();var tempVec3a$
|
|
5486
|
+
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry edges drawing fragment shader");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}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("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i79=0,len=sectionPlanesState.sectionPlanes.length;_i79<len;_i79++){src.push("uniform bool sectionPlaneActive"+_i79+";");src.push("uniform vec3 sectionPlanePos"+_i79+";");src.push("uniform vec3 sectionPlaneDir"+_i79+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i80=0,_len10=sectionPlanesState.sectionPlanes.length;_i80<_len10;_i80++){src.push("if (sectionPlaneActive"+_i80+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i80+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i80+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureEdgesRenderer;}();var tempVec3a$1c=math.vec3();/**
|
|
5487
5487
|
* @private
|
|
5488
|
-
*/var TrianglesDataTextureEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesDataTextureEdgesColorRenderer(scene){_classCallCheck(this,TrianglesDataTextureEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);}gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5488
|
+
*/var TrianglesDataTextureEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesDataTextureEdgesColorRenderer(scene){_classCallCheck(this,TrianglesDataTextureEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);}gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1c);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numEdgeIndices8Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8// 8 bits edge indices
|
|
5489
5489
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices8Bits);}if(state.numEdgeIndices16Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16// 16 bits edge indices
|
|
5490
5490
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices16Bits);}if(state.numEdgeIndices32Bits>0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32// 32 bits edge indices
|
|
5491
5491
|
);gl.drawArrays(gl.LINES,0,state.numEdgeIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uSectionPlanes=[];for(var _i81=0,len=scene._sectionPlanesState.sectionPlanes.length;_i81<len;_i81++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i81),pos:program.getLocation("sectionPlanePos"+_i81),dir:program.getLocation("sectionPlaneDir"+_i81)});}//this._aOffset = program.getAttribute("offset");
|
|
@@ -5527,10 +5527,10 @@ src.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(obj
|
|
|
5527
5527
|
src.push("if (color.a == 0u) {");src.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);");// Cull vertex
|
|
5528
5528
|
src.push(" return;");src.push("};");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5529
5529
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}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("vec4 rgb = vec4(color.rgba);");//src.push("vColor = vec4(float(color.r-100.0) / 255.0, float(color.g-100.0) / 255.0, float(color.b-100.0) / 255.0, float(color.a) / 255.0);");
|
|
5530
|
-
src.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry edges drawing fragment shader");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}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("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i82=0,len=sectionPlanesState.sectionPlanes.length;_i82<len;_i82++){src.push("uniform bool sectionPlaneActive"+_i82+";");src.push("uniform vec3 sectionPlanePos"+_i82+";");src.push("uniform vec3 sectionPlaneDir"+_i82+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i83=0,_len11=sectionPlanesState.sectionPlanes.length;_i83<_len11;_i83++){src.push("if (sectionPlaneActive"+_i83+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i83+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i83+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureEdgesColorRenderer;}();var tempVec3a$
|
|
5530
|
+
src.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry edges drawing fragment shader");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}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("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i82=0,len=sectionPlanesState.sectionPlanes.length;_i82<len;_i82++){src.push("uniform bool sectionPlaneActive"+_i82+";");src.push("uniform vec3 sectionPlanePos"+_i82+";");src.push("uniform vec3 sectionPlaneDir"+_i82+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i83=0,_len11=sectionPlanesState.sectionPlanes.length;_i83<_len11;_i83++){src.push("if (sectionPlaneActive"+_i83+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i83+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i83+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureEdgesColorRenderer;}();var tempVec3a$1b=math.vec3();/**
|
|
5531
5531
|
* @private
|
|
5532
5532
|
*/var TrianglesDataTexturePickMeshRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickMeshRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
5533
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5533
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1b);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5534
5534
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5535
5535
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5536
5536
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uSectionPlanes=[];for(var _i84=0,len=scene._sectionPlanesState.sectionPlanes.length;_i84<len;_i84++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i84),pos:program.getLocation("sectionPlanePos"+_i84),dir:program.getLocation("sectionPlaneDir"+_i84)});}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5577,10 +5577,10 @@ src.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2
|
|
|
5577
5577
|
src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");// when the geometry is not solid, if needed, flip the triangle winding
|
|
5578
5578
|
src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("} else {");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5579
5579
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry 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;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uvec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outPickColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
|
|
5580
|
-
src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outPickColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickMeshRenderer;}();var tempVec3a$
|
|
5580
|
+
src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outPickColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickMeshRenderer;}();var tempVec3a$1a=math.vec3();/**
|
|
5581
5581
|
* @private
|
|
5582
5582
|
*/var TrianglesDataTexturePickDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickDepthRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
5583
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5583
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$1a);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5584
5584
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5585
5585
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5586
5586
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uSectionPlanes=[];for(var _i85=0,len=scene._sectionPlanesState.sectionPlanes.length;_i85<len;_i85++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i85),pos:program.getLocation("sectionPlanePos"+_i85),dir:program.getLocation("sectionPlaneDir"+_i85)});}this._aPackedVertexId=program.getAttribute("packedVertexId");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5625,10 +5625,10 @@ src.push(" return;");src.push("};");// get normal
|
|
|
5625
5625
|
src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");// when the geometry is not solid, if needed, flip the triangle winding
|
|
5626
5626
|
src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("} else {");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5627
5627
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}src.push("vViewPosition = viewPosition;");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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick depth 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 float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 packDepth(const in float depth) {");src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);");src.push(" vec4 res = fract(depth * bitShift);");src.push(" res -= res.xxyz * bitMask;");src.push(" return res;");src.push("}");src.push("out vec4 outPackedDepth;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outPackedDepth = packDepth(zNormalizedDepth); ");// Must be linear depth
|
|
5628
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickDepthRenderer;}();var tempVec3a$
|
|
5628
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickDepthRenderer;}();var tempVec3a$19=math.vec3();/**
|
|
5629
5629
|
* @private
|
|
5630
5630
|
*/var TrianglesDataTexturePickNormalsRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickNormalsRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix?
|
|
5631
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5631
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$19);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5632
5632
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5633
5633
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5634
5634
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uSectionPlanes=[];for(var _i86=0,len=scene._sectionPlanesState.sectionPlanes.length;_i86<len;_i86++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i86),pos:program.getLocation("sectionPlanePos"+_i86),dir:program.getLocation("sectionPlaneDir"+_i86)});}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5678,9 +5678,9 @@ src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.pu
|
|
|
5678
5678
|
// Only opaque objects can be occluders
|
|
5679
5679
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
5680
5680
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("vFragDepth = 1.0 + clipPos.w;");}else{src.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;");src.push("clipPos.z *= clipPos.w;");}src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}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.sectionPlanes.length>0;var src=[];src.push("// Triangles dataTexture occlusion fragment shader");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("#extension GL_EXT_frag_depth : enable");}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&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("varying float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("varying float vFragDepth;");}if(clipping){src.push("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");for(var _i88=0;_i88<sectionPlanesState.sectionPlanes.length;_i88++){src.push("uniform bool sectionPlaneActive"+_i88+";");src.push("uniform vec3 sectionPlanePos"+_i88+";");src.push("uniform vec3 sectionPlaneDir"+_i88+";");}}src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i89=0;_i89<sectionPlanesState.sectionPlanes.length;_i89++){src.push(" if (sectionPlaneActive"+_i89+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i89+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i89+".xyz), 0.0, 1000.0);");src.push(" }");}src.push(" if (dist > 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); ");// Occluders are blue
|
|
5681
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureOcclusionRenderer;}();math.vec4();var tempVec3a$
|
|
5681
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureOcclusionRenderer;}();math.vec4();var tempVec3a$18=math.vec3();/**
|
|
5682
5682
|
* @private
|
|
5683
|
-
*/var TrianglesDataTextureDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTextureDepthRenderer(scene){_classCallCheck(this,TrianglesDataTextureDepthRenderer);this._scene=scene;this._allocate();this._hash=this._getHash();}_createClass(TrianglesDataTextureDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5683
|
+
*/var TrianglesDataTextureDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTextureDepthRenderer(scene){_classCallCheck(this,TrianglesDataTextureDepthRenderer);this._scene=scene;this._allocate();this._hash=this._getHash();}_createClass(TrianglesDataTextureDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,state);}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var cameraEye=camera.eye;if(frameCtx.pickViewMatrix){textureState.bindPickCameraTexture(this._program,this._uTextureCameraMatrices);cameraEye=frameCtx.pickOrigin||cameraEye;}var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$18);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}if(state.numIndices8Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices
|
|
5684
5684
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices
|
|
5685
5685
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices
|
|
5686
5686
|
);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i90=0,len=scene._sectionPlanesState.sectionPlanes.length;_i90<len;_i90++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i90),pos:program.getLocation("sectionPlanePos"+_i90),dir:program.getLocation("sectionPlaneDir"+_i90)});}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix";// chipmunk
|
|
@@ -5727,9 +5727,9 @@ src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1
|
|
|
5727
5727
|
src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("viewNormal = -viewNormal;");src.push("}");src.push("} else {");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("viewNormal = -viewNormal;");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset
|
|
5728
5728
|
src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");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("vFlags2 = flags2.r;");}src.push("gl_Position = clipPos;");src.push("vHighPrecisionZW = gl_Position.zw;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture 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");src.push("in highp vec2 vHighPrecisionZW;");src.push("out vec4 outColor;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i91=0,len=sectionPlanesState.sectionPlanes.length;_i91<len;_i91++){src.push("uniform bool sectionPlaneActive"+_i91+";");src.push("uniform vec3 sectionPlanePos"+_i91+";");src.push("uniform vec3 sectionPlaneDir"+_i91+";");}}src.push("void main(void) {");if(clipping){src.push(" bool clippable = vFlags2 > 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i92=0,_len12=sectionPlanesState.sectionPlanes.length;_i92<_len12;_i92++){src.push("if (sectionPlaneActive"+_i92+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i92+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i92+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
|
|
5729
5729
|
src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");// src.push(" outColor = vec4(1.0, 1.0, 1.0, 1.0); ");
|
|
5730
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureDepthRenderer;}();var tempVec3a$
|
|
5730
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureDepthRenderer;}();var tempVec3a$17=math.vec3();/**
|
|
5731
5731
|
* @private
|
|
5732
|
-
*/var TrianglesDataTextureNormalsRenderer=/*#__PURE__*/function(){function TrianglesDataTextureNormalsRenderer(scene){_classCallCheck(this,TrianglesDataTextureNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(dataTextureLayer);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5732
|
+
*/var TrianglesDataTextureNormalsRenderer=/*#__PURE__*/function(){function TrianglesDataTextureNormalsRenderer(scene){_classCallCheck(this,TrianglesDataTextureNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(dataTextureLayer);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$17);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,dataTextureLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);this._aOffset.bindArrayBuffer(state.offsetsBuf);this._aNormal.bindArrayBuffer(state.normalsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);// Needed for masking out transparent entities using alpha channel
|
|
5733
5733
|
this._aFlags.bindArrayBuffer(state.flagsBuf);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i93=0,len=scene._sectionPlanesState.sectionPlanes.length;_i93<len;_i93++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i93),pos:program.getLocation("sectionPlanePos"+_i93),dir:program.getLocation("sectionPlaneDir"+_i93)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");if(this._aFlags2){// Won't be in shader when not clipping
|
|
5734
5734
|
this._aFlags2=program.getAttribute("flags2");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("// Batched geometry normals vertex shader");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("#extension GL_EXT_frag_depth : enable");}src.push("uniform int renderPass;");src.push("attribute vec3 position;");if(scene.entityOffsetsEnabled){src.push("attribute vec3 offset;");}src.push("attribute vec3 normal;");src.push("attribute vec4 color;");src.push("attribute vec4 flags;");src.push("attribute vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("varying float vFragDepth;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("varying float isPerspective;");}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("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");}src.push("varying vec3 vViewNormal;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
5735
5735
|
// renderPass = COLOR_OPAQUE
|
|
@@ -5738,9 +5738,9 @@ src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4
|
|
|
5738
5738
|
*
|
|
5739
5739
|
* @private
|
|
5740
5740
|
*/var TrianglesDataTextureShadowRenderer=/*#__PURE__*/function(){function TrianglesDataTextureShadowRenderer(scene){_classCallCheck(this,TrianglesDataTextureShadowRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureShadowRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer){return;// TODO
|
|
5741
|
-
}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uShadowViewMatrix=program.getLocation("shadowViewMatrix");this._uShadowProjMatrix=program.getLocation("shadowProjMatrix");if(scene.logarithmicDepthBufferEnabled){this._uZFar=program.getLocation("zFar");}this._uSectionPlanes=[];var sectionPlanes=sectionPlanesState.sectionPlanes;for(var _i95=0,len=sectionPlanes.length;_i95<len;_i95++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i95),pos:program.getLocation("sectionPlanePos"+_i95),dir:program.getLocation("sectionPlaneDir"+_i95)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniformMatrix4fv(this._uShadowViewMatrix,false,frameCtx.shadowViewMatrix);gl.uniformMatrix4fv(this._uShadowProjMatrix,false,frameCtx.shadowProjMatrix);this._lastLightId=null;}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("// Batched geometry shadow vertex shader");src.push("attribute vec3 position;");if(scene.entityOffsetsEnabled){src.push("attribute vec3 offset;");}src.push("attribute vec4 color;");src.push("attribute vec4 flags;");src.push("attribute vec4 flags2;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(clipping){src.push("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");}src.push("varying vec4 vViewPosition;");src.push("void main(void) {");src.push(" bool visible = (float(flags.x) > 0.0);");src.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);");src.push(" if (!visible || transparent) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");src.push(" } else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewPosition = viewPosition;");src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("// Batched geometry 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("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");for(var _i96=0;_i96<sectionPlanesState.sectionPlanes.length;_i96++){src.push("uniform bool sectionPlaneActive"+_i96+";");src.push("uniform vec3 sectionPlanePos"+_i96+";");src.push("uniform vec3 sectionPlaneDir"+_i96+";");}}src.push("varying vec4 vViewPosition;");src.push("vec4 encodeFloat( const in float v ) {");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(v * bitShift);");src.push(" comp -= comp.xxyz * bitMask;");src.push(" return comp;");src.push("}");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}src.push(" gl_FragColor = encodeFloat( gl_FragCoord.z); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureShadowRenderer;}();var tempVec4$8=math.vec4();var tempVec3a$
|
|
5741
|
+
}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uShadowViewMatrix=program.getLocation("shadowViewMatrix");this._uShadowProjMatrix=program.getLocation("shadowProjMatrix");if(scene.logarithmicDepthBufferEnabled){this._uZFar=program.getLocation("zFar");}this._uSectionPlanes=[];var sectionPlanes=sectionPlanesState.sectionPlanes;for(var _i95=0,len=sectionPlanes.length;_i95<len;_i95++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i95),pos:program.getLocation("sectionPlanePos"+_i95),dir:program.getLocation("sectionPlaneDir"+_i95)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniformMatrix4fv(this._uShadowViewMatrix,false,frameCtx.shadowViewMatrix);gl.uniformMatrix4fv(this._uShadowProjMatrix,false,frameCtx.shadowProjMatrix);this._lastLightId=null;}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("// Batched geometry shadow vertex shader");src.push("attribute vec3 position;");if(scene.entityOffsetsEnabled){src.push("attribute vec3 offset;");}src.push("attribute vec4 color;");src.push("attribute vec4 flags;");src.push("attribute vec4 flags2;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(clipping){src.push("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");}src.push("varying vec4 vViewPosition;");src.push("void main(void) {");src.push(" bool visible = (float(flags.x) > 0.0);");src.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);");src.push(" if (!visible || transparent) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");src.push(" } else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewPosition = viewPosition;");src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("// Batched geometry 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("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");for(var _i96=0;_i96<sectionPlanesState.sectionPlanes.length;_i96++){src.push("uniform bool sectionPlaneActive"+_i96+";");src.push("uniform vec3 sectionPlanePos"+_i96+";");src.push("uniform vec3 sectionPlaneDir"+_i96+";");}}src.push("varying vec4 vViewPosition;");src.push("vec4 encodeFloat( const in float v ) {");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(v * bitShift);");src.push(" comp -= comp.xxyz * bitMask;");src.push(" return comp;");src.push("}");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}src.push(" gl_FragColor = encodeFloat( gl_FragCoord.z); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureShadowRenderer;}();var tempVec4$8=math.vec4();var tempVec3a$16=math.vec3();var TEXTURE_DECODE_FUNCS$2={"linear":"linearToLinear","sRGB":"sRGBToLinear","gamma":"gammaToLinear"};/**
|
|
5742
5742
|
* @private
|
|
5743
|
-
*/var TrianglesDataTextureColorQualityRenderer=/*#__PURE__*/function(){function TrianglesDataTextureColorQualityRenderer(scene,withSAO){_classCallCheck(this,TrianglesDataTextureColorQualityRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureColorQualityRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$15);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,dataTextureLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aMetallicRoughness){this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i97=0,len=lights.length;_i97<len;_i97++){light=lights[_i97];switch(light.type){case"dir":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=null;this._uLightDir[_i97]=program.getLocation("lightDir"+_i97);break;case"point":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=program.getLocation("lightPos"+_i97);this._uLightDir[_i97]=null;this._uLightAttenuation[_i97]=program.getLocation("lightAttenuation"+_i97);break;case"spot":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=program.getLocation("lightPos"+_i97);this._uLightDir[_i97]=program.getLocation("lightDir"+_i97);this._uLightAttenuation[_i97]=program.getLocation("lightAttenuation"+_i97);break;}}if(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i98=0,_len13=scene._sectionPlanesState.sectionPlanes.length;_i98<_len13;_i98++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i98),pos:program.getLocation("sectionPlanePos"+_i98),dir:program.getLocation("sectionPlaneDir"+_i98)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i99=0,len=lights.length;_i99<len;_i99++){var light=lights[_i99];if(this._uLightColor[_i99]){gl.uniform4f(this._uLightColor[_i99],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i99]){gl.uniform3fv(this._uLightPos[_i99],light.pos);if(this._uLightAttenuation[_i99]){gl.uniform1f(this._uLightAttenuation[_i99],light.attenuation);}}if(this._uLightDir[_i99]){gl.uniform3fv(this._uLightDir[_i99],light.dir);}}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(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(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$8[0]=viewportWidth;tempVec4$8[1]=viewportHeight;tempVec4$8[2]=sao.blendCutoff;tempVec4$8[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$8);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var clippingCaps=sectionPlanesState.clippingCaps;var src=[];src.push("// Triangles dataTexture quality draw vertex shader");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("#extension GL_EXT_frag_depth : enable");}src.push("uniform int renderPass;");src.push("attribute vec3 position;");src.push("attribute vec3 normal;");src.push("attribute vec4 color;");src.push("attribute vec2 metallicRoughness;");src.push("attribute vec4 flags;");src.push("attribute vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("attribute vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("varying float vFragDepth;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("varying float isPerspective;");}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("}");src.push("varying vec4 vViewPosition;");src.push("varying vec3 vViewNormal;");src.push("varying vec4 vColor;");src.push("varying vec2 vMetallicRoughness;");if(lightsState.lightMaps.length>0){src.push("varying vec3 vWorldNormal;");}if(clipping){src.push("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");if(clippingCaps){src.push("varying vec4 vClipPosition;");}}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
5743
|
+
*/var TrianglesDataTextureColorQualityRenderer=/*#__PURE__*/function(){function TrianglesDataTextureColorQualityRenderer(scene,withSAO){_classCallCheck(this,TrianglesDataTextureColorQualityRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureColorQualityRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=dataTextureLayer.model;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$16);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,dataTextureLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aMetallicRoughness){this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i97=0,len=lights.length;_i97<len;_i97++){light=lights[_i97];switch(light.type){case"dir":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=null;this._uLightDir[_i97]=program.getLocation("lightDir"+_i97);break;case"point":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=program.getLocation("lightPos"+_i97);this._uLightDir[_i97]=null;this._uLightAttenuation[_i97]=program.getLocation("lightAttenuation"+_i97);break;case"spot":this._uLightColor[_i97]=program.getLocation("lightColor"+_i97);this._uLightPos[_i97]=program.getLocation("lightPos"+_i97);this._uLightDir[_i97]=program.getLocation("lightDir"+_i97);this._uLightAttenuation[_i97]=program.getLocation("lightAttenuation"+_i97);break;}}if(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i98=0,_len13=scene._sectionPlanesState.sectionPlanes.length;_i98<_len13;_i98++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i98),pos:program.getLocation("sectionPlanePos"+_i98),dir:program.getLocation("sectionPlaneDir"+_i98)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i99=0,len=lights.length;_i99<len;_i99++){var light=lights[_i99];if(this._uLightColor[_i99]){gl.uniform4f(this._uLightColor[_i99],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i99]){gl.uniform3fv(this._uLightPos[_i99],light.pos);if(this._uLightAttenuation[_i99]){gl.uniform1f(this._uLightAttenuation[_i99],light.attenuation);}}if(this._uLightDir[_i99]){gl.uniform3fv(this._uLightDir[_i99],light.dir);}}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(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(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$8[0]=viewportWidth;tempVec4$8[1]=viewportHeight;tempVec4$8[2]=sao.blendCutoff;tempVec4$8[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$8);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var clippingCaps=sectionPlanesState.clippingCaps;var src=[];src.push("// Triangles dataTexture quality draw vertex shader");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("#extension GL_EXT_frag_depth : enable");}src.push("uniform int renderPass;");src.push("attribute vec3 position;");src.push("attribute vec3 normal;");src.push("attribute vec4 color;");src.push("attribute vec2 metallicRoughness;");src.push("attribute vec4 flags;");src.push("attribute vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("attribute vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("varying float vFragDepth;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("varying float isPerspective;");}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("}");src.push("varying vec4 vViewPosition;");src.push("varying vec3 vViewNormal;");src.push("varying vec4 vColor;");src.push("varying vec2 vMetallicRoughness;");if(lightsState.lightMaps.length>0){src.push("varying vec3 vWorldNormal;");}if(clipping){src.push("varying vec4 vWorldPosition;");src.push("varying vec4 vFlags2;");if(clippingCaps){src.push("varying vec4 vClipPosition;");}}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
5744
5744
|
// renderPass = COLOR_OPAQUE
|
|
5745
5745
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
5746
5746
|
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("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("vFragDepth = 1.0 + clipPos.w;");}else{src.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;");src.push("clipPos.z *= clipPos.w;");}}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");if(clippingCaps){src.push("vClipPosition = clipPos;");}}src.push("vViewPosition = viewPosition;");src.push("vViewNormal = viewNormal;");src.push("vColor = color;");src.push("vMetallicRoughness = metallicRoughness;");if(lightsState.lightMaps.length>0){src.push("vWorldNormal = worldNormal.xyz;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var gammaOutput=scene.gammaOutput;// If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
|
|
@@ -5755,13 +5755,13 @@ src.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {");
|
|
|
5755
5755
|
src.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {");src.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));");src.push(" vec3 irradiance = dotNL * incidentLight.color * PI;");src.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);");src.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);");src.push("}");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i102=0,_len15=sectionPlanesState.sectionPlanes.length;_i102<_len15;_i102++){src.push("if (sectionPlaneActive"+_i102+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i102+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i102+".xyz), 0.0, 1000.0);");src.push("}");}if(clippingCaps){src.push(" if (dist > (0.002 * vClipPosition.w)) {");src.push(" discard;");src.push(" }");src.push(" if (dist > 0.0) { ");src.push(" gl_FragColor=vec4(1.0, 0.0, 0.0, 1.0);");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push(" gl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" return;");src.push("}");}else{src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");}src.push("}");}src.push("IncidentLight light;");src.push("Material material;");src.push("Geometry geometry;");src.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));");src.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));");src.push("float alpha = float(vColor.a) / 255.0;");src.push("vec3 diffuseColor = rgb;");src.push("float specularF0 = 1.0;");src.push("float metallic = float(vMetallicRoughness.r) / 255.0;");src.push("float roughness = float(vMetallicRoughness.g) / 255.0;");src.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;");src.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);");src.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);");src.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);");src.push("geometry.position = vViewPosition.xyz;");src.push("geometry.viewNormal = -normalize(vViewNormal);");src.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);");if(lightsState.lightMaps.length>0){src.push("geometry.worldNormal = normalize(vWorldNormal);");}if(lightsState.lightMaps.length>0||lightsState.reflectionMaps.length>0){src.push("computePBRLightMapping(geometry, material, reflectedLight);");}for(var _i103=0,_len16=lightsState.lights.length;_i103<_len16;_i103++){var _light=lightsState.lights[_i103];if(_light.type==="ambient"){continue;}if(_light.type==="dir"){if(_light.space==="view"){src.push("light.direction = normalize(lightDir"+_i103+");");}else{src.push("light.direction = normalize((viewMatrix * vec4(lightDir"+_i103+", 0.0)).xyz);");}}else if(_light.type==="point"){if(_light.space==="view"){src.push("light.direction = normalize(lightPos"+_i103+" - vViewPosition.xyz);");}else{src.push("light.direction = normalize((viewMatrix * vec4(lightPos"+_i103+", 0.0)).xyz);");}}else if(_light.type==="spot"){if(_light.space==="view"){src.push("light.direction = normalize(lightDir"+_i103+");");}else{src.push("light.direction = normalize((viewMatrix * vec4(lightDir"+_i103+", 0.0)).xyz);");}}else{continue;}src.push("light.color = lightColor"+_i103+".rgb * lightColor"+_i103+".a;");// a is intensity
|
|
5756
5756
|
src.push("computePBRLighting(light, geometry, material, reflectedLight);");}src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular);");src.push("vec4 fragColor;");if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
5757
5757
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
5758
|
-
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, unpackRGBAToDepth(texture2D(uOcclusionTexture, uv))) * blendFactor;");src.push(" fragColor = vec4(outgoingLight.rgb * ambient, alpha);");}else{src.push(" fragColor = vec4(outgoingLight.rgb, alpha);");}if(gammaOutput){src.push("fragColor = linearToGamma(fragColor, gammaFactor);");}src.push("gl_FragColor = fragColor;");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureColorQualityRenderer;}();var tempVec3a$
|
|
5758
|
+
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, unpackRGBAToDepth(texture2D(uOcclusionTexture, uv))) * blendFactor;");src.push(" fragColor = vec4(outgoingLight.rgb * ambient, alpha);");}else{src.push(" fragColor = vec4(outgoingLight.rgb, alpha);");}if(gammaOutput){src.push("fragColor = linearToGamma(fragColor, gammaFactor);");}src.push("gl_FragColor = fragColor;");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureColorQualityRenderer;}();var tempVec3a$15=math.vec3();/**
|
|
5759
5759
|
* @private
|
|
5760
5760
|
*/var TrianglesDataTexturePickNormalsFlatRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickNormalsFlatRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickNormalsFlatRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickNormalsFlatRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdPositionsDecodeMatrix);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},1);// chipmunk
|
|
5761
5761
|
this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerVertexIdCoordinates);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},2);// chipmunk
|
|
5762
5762
|
this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdColorsAndFlags);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},3);// chipmunk
|
|
5763
5763
|
gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix?
|
|
5764
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
5764
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$15);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}//=============================================================
|
|
5765
5765
|
// TODO: Use drawElements count and offset to draw only one entity
|
|
5766
5766
|
//=============================================================
|
|
5767
5767
|
if(state.numIndices8Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds8Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);// chipmunk
|
|
@@ -6234,7 +6234,7 @@ texArray.set(instanceMatrices[i],i*32+16);}var texture=gl.createTexture();gl.bin
|
|
|
6234
6234
|
*/var INDICES_EDGE_INDICES_ALIGNEMENT_SIZE=8;/**
|
|
6235
6235
|
* Number of maximum allowed per-object flags update per render frame
|
|
6236
6236
|
* before switching to batch update mode.
|
|
6237
|
-
*/var MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE=10;var identityMatrix=math.identityMat4();math.mat4();math.mat4();var tempVec4a$b=math.vec4([0,0,0,1]);var tempVec4b$b=math.vec4([0,0,0,1]);var tempVec4c$8=math.vec4([0,0,0,1]);var tempOBB3$3=math.OBB3();var tempUint8Array4=new Uint8Array(4);var tempFloat32Array3=new Float32Array(3);var tempVec3a$
|
|
6237
|
+
*/var MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE=10;var identityMatrix=math.identityMat4();math.mat4();math.mat4();var tempVec4a$b=math.vec4([0,0,0,1]);var tempVec4b$b=math.vec4([0,0,0,1]);var tempVec4c$8=math.vec4([0,0,0,1]);var tempOBB3$3=math.OBB3();var tempUint8Array4=new Uint8Array(4);var tempFloat32Array3=new Float32Array(3);var tempVec3a$14=math.vec3();var tempVec3b$b=math.vec3();var tempVec3c$7=math.vec3();var tempVec3d$3=math.vec3();var tempVec3e$2=math.vec3();var tempVec3f$2=math.vec3();var tempVec3g$2=math.vec3();var _numberOfLayers=0;/**
|
|
6238
6238
|
* @private
|
|
6239
6239
|
*/var TrianglesDataTextureLayer=/*#__PURE__*/function(){/**
|
|
6240
6240
|
* @param {DataTextureSceneModel} model
|
|
@@ -6454,7 +6454,7 @@ gl.RGB,gl.FLOAT,tempFloat32Array3);// gl.bindTexture (gl.TEXTURE_2D, null);
|
|
|
6454
6454
|
},{key:"drawOcclusion",value:function drawOcclusion(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._dataTextureRenderers.occlusionRenderer){this._dataTextureRenderers.occlusionRenderer.drawLayer(frameCtx,this,RENDER_PASSES$1.COLOR_OPAQUE);}}// ---------------------- SHADOW BUFFER RENDERING -----------------------------------
|
|
6455
6455
|
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._dataTextureRenderers.shadowRenderer){this._dataTextureRenderers.shadowRenderer.drawLayer(frameCtx,this,RENDER_PASSES$1.COLOR_OPAQUE);}}//---- PICKING ----------------------------------------------------------------------------------------------------
|
|
6456
6456
|
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._dataTextureRenderers.pickMeshRenderer){this._dataTextureRenderers.pickMeshRenderer.drawLayer(frameCtx,this,RENDER_PASSES$1.PICK);}}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._dataTextureRenderers.pickDepthRenderer){this._dataTextureRenderers.pickDepthRenderer.drawLayer(frameCtx,this,RENDER_PASSES$1.PICK);}}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._dataTextureRenderers.pickNormalsRenderer){this._dataTextureRenderers.pickNormalsRenderer.drawLayer(frameCtx,this,RENDER_PASSES$1.PICK);}}//------------------------------------------------------------------------------------------------
|
|
6457
|
-
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}var positions=portion.quantizedPositions;var indices=portion.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$
|
|
6457
|
+
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}var positions=portion.quantizedPositions;var indices=portion.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$14;var rtcRayDir=tempVec3b$b;rtcRayOrigin.set(origin?math.subVec3(worldRayOrigin,origin,tempVec3c$7):worldRayOrigin);// World -> RTC
|
|
6458
6458
|
rtcRayDir.set(worldRayDir);if(offset){math.subVec3(rtcRayOrigin,offset);}math.transformRay(this.model.worldNormalMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);// RTC -> local
|
|
6459
6459
|
var a=tempVec3d$3;var b=tempVec3e$2;var c=tempVec3f$2;var gotIntersect=false;var closestDist=0;var closestIntersectPos=tempVec3g$2;for(var _i131=0,len=indices.length;_i131<len;_i131+=3){var ia=indices[_i131]*3;var ib=indices[_i131+1]*3;var ic=indices[_i131+2]*3;a[0]=positions[ia];a[1]=positions[ia+1];a[2]=positions[ia+2];b[0]=positions[ib];b[1]=positions[ib+1];b[2]=positions[ib+2];c[0]=positions[ic];c[1]=positions[ic+1];c[2]=positions[ic+2];math.decompressPosition(a,state.positionsDecodeMatrix);math.decompressPosition(b,state.positionsDecodeMatrix);math.decompressPosition(c,state.positionsDecodeMatrix);if(math.rayTriangleIntersect(rtcRayOrigin,rtcRayDir,a,b,c,closestIntersectPos)){math.transformPoint3(this.model.worldMatrix,closestIntersectPos,closestIntersectPos);if(offset){math.addVec3(closestIntersectPos,offset);}if(origin){math.addVec3(closestIntersectPos,origin);}var dist=Math.abs(math.lenVec3(math.subVec3(closestIntersectPos,worldRayOrigin,[])));if(!gotIntersect||dist>closestDist){closestDist=dist;worldSurfacePos.set(closestIntersectPos);if(worldNormal){// Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
|
|
6460
6460
|
math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}// ---------
|
|
@@ -6882,7 +6882,7 @@ return retVal;}}]);return ViewFrustumCullingState;}();var ViewFrustumCullingMana
|
|
|
6882
6882
|
* @private
|
|
6883
6883
|
*/this.vfcState=new ViewFrustumCullingState();console.time("initializeVfcState");this.vfcState.initializeVfcState(this.entities,this.meshes);console.timeEnd("initializeVfcState");console.time("finalizeVfcState");this.vfcState.finalize(this.model,fnForceFinalizeLayer);console.timeEnd("finalizeVfcState");var self=this;var cb=function cb(){return _this32.applyViewFrustumCulling.call(self);};this.model.scene.on("rendering",cb);}/**
|
|
6884
6884
|
* @private
|
|
6885
|
-
*/},{key:"applyViewFrustumCulling",value:function applyViewFrustumCulling(){if(!this.finalized){throw"Not finalized";}this.vfcState.applyViewFrustumCulling(this.model);}}]);return ViewFrustumCullingManager;}();WEBGL_INFO.SUPPORTED_EXTENSIONS["ANGLE_instanced_arrays"];var tempVec3a$
|
|
6885
|
+
*/},{key:"applyViewFrustumCulling",value:function applyViewFrustumCulling(){if(!this.finalized){throw"Not finalized";}this.vfcState.applyViewFrustumCulling(this.model);}}]);return ViewFrustumCullingManager;}();WEBGL_INFO.SUPPORTED_EXTENSIONS["ANGLE_instanced_arrays"];var tempVec3a$13=math.vec3();var tempMat4$3=math.mat4();var defaultScale$1=math.vec3([1,1,1]);var defaultPosition$1=math.vec3([0,0,0]);var defaultRotation$1=math.vec3([0,0,0]);var defaultQuaternion$1=math.identityQuaternion();/**
|
|
6886
6886
|
* @desc A high-performance data-texture-based model representation for efficient rendering and low memory usage.
|
|
6887
6887
|
*
|
|
6888
6888
|
*
|
|
@@ -7305,7 +7305,7 @@ _this33._origin=math.vec3(cfg.origin||[0,0,0]);_this33._position=math.vec3(cfg.p
|
|
|
7305
7305
|
* @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positions````.
|
|
7306
7306
|
* @param {Number[]} [cfg.origin] Optional geometry origin, relative to {@link DataTextureSceneModel#origin}. When this is given, then every mesh created with {@link DataTextureSceneModel#createMesh} that uses this geometry will
|
|
7307
7307
|
* be transformed relative to this origin.
|
|
7308
|
-
*/},{key:"createGeometry",value:function createGeometry(cfg){if(cfg.positionsCompressed&&!cfg.positions){cfg.positions=cfg.positionsCompressed;}var geometryId=cfg.id;if(geometryId===undefined||geometryId===null){this.error("Config missing: id");return;}if(geometryId in this._instancingGeometries){this.error("Geometry already created: "+geometryId);return;}var primitive=cfg.primitive;if(primitive===undefined||primitive===null){this.error("Config missing: primitive");return;}var cfgOrigin=cfg.origin||cfg.rtcCenter;var origin=cfgOrigin?math.addVec3(this._origin,cfgOrigin,tempVec3a$
|
|
7308
|
+
*/},{key:"createGeometry",value:function createGeometry(cfg){if(cfg.positionsCompressed&&!cfg.positions){cfg.positions=cfg.positionsCompressed;}var geometryId=cfg.id;if(geometryId===undefined||geometryId===null){this.error("Config missing: id");return;}if(geometryId in this._instancingGeometries){this.error("Geometry already created: "+geometryId);return;}var primitive=cfg.primitive;if(primitive===undefined||primitive===null){this.error("Config missing: primitive");return;}var cfgOrigin=cfg.origin||cfg.rtcCenter;var origin=cfgOrigin?math.addVec3(this._origin,cfgOrigin,tempVec3a$13):this._origin;switch(primitive){case"triangles":case"solid":case"surface":this._instancingGeometries[cfg.id]=utils.apply({origin:origin,layerIndex:0},cfg);this._numTriangles+=cfg.indices?Math.round(cfg.indices.length/3):0;break;case"lines":throw"Not supported at the moment";case"points":throw"Not supported at the moment";}this.numGeometries++;}/**
|
|
7309
7309
|
* Creates a mesh within this DataTextureSceneModel.
|
|
7310
7310
|
*
|
|
7311
7311
|
* A mesh can either share geometry with other meshes, or have its own unique geometry.
|
|
@@ -7362,7 +7362,7 @@ _this33._origin=math.vec3(cfg.origin||[0,0,0]);_this33._position=math.vec3(cfg.p
|
|
|
7362
7362
|
origin:cfg.origin});this._layerList.push(layer);this._currentDataTextureLayer=layer;}var portionId;var color=cfg.color?new Uint8Array([Math.floor(cfg.color[0]*255),Math.floor(cfg.color[1]*255),Math.floor(cfg.color[2]*255)]):[255,255,255];var opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;var metallic=cfg.metallic!==undefined&&cfg.metallic!==null?Math.floor(cfg.metallic*255):0;var roughness=cfg.roughness!==undefined&&cfg.roughness!==null?Math.floor(cfg.roughness*255):255;var mesh=new DataTextureSceneModelMesh(this,id,color,opacity);var pickId=mesh.pickId;var a=pickId>>24&0xFF;var b=pickId>>16&0xFF;var g=pickId>>8&0xFF;var r=pickId&0xFF;var pickColor=new Uint8Array([r,g,b,a]);// Quantized pick color
|
|
7363
7363
|
var aabb=math.collapseAABB3();preparedGeometryCfg.solid=preparedGeometryCfg.primitive=="solid";if(instancing){var meshMatrix;var worldMatrix=this._worldMatrixNonIdentity?this._worldMatrix:null;if(cfg.matrix){meshMatrix=cfg.matrix;}else{var _scale=cfg.scale||defaultScale$1;var position=cfg.position||defaultPosition$1;var rotation=cfg.rotation||defaultRotation$1;math.eulerToQuaternion(rotation,"XYZ",defaultQuaternion$1);meshMatrix=math.composeMat4(position,defaultQuaternion$1,_scale,tempMat4$3);}portionId=layer.createPortion(preparedGeometryCfg,{origin:cfg.origin,geometryId:geometryId,color:color,metallic:metallic,roughness:roughness,opacity:opacity,meshMatrix:meshMatrix,worldMatrix:worldMatrix,aabb:aabb,pickColor:pickColor});math.expandAABB3(this._aabb,aabb);this._numTriangles+=preparedGeometryCfg.indices.length/3;mesh.numTriangles=preparedGeometryCfg.indices.length/3;mesh.origin=preparedGeometryCfg.origin;}else{// Batching
|
|
7364
7364
|
var origin=null;if(!cfg.positionsDecodeMatrix){// TODO: Assumes we never quantize double-precision coordinates
|
|
7365
|
-
var rtcCenter=math.vec3();var rtcPositions=[];var rtcNeeded=worldToRTCPositions(positions,rtcPositions,rtcCenter);if(rtcNeeded){positions=rtcPositions;origin=math.addVec3(this._origin,rtcCenter,rtcCenter);}}var cfgOrigin=cfg.origin||cfg.rtcCenter;if(cfgOrigin){if(!origin){origin=cfgOrigin;}else{origin=math.addVec3(this._origin,cfgOrigin,tempVec3a$
|
|
7365
|
+
var rtcCenter=math.vec3();var rtcPositions=[];var rtcNeeded=worldToRTCPositions(positions,rtcPositions,rtcCenter);if(rtcNeeded){positions=rtcPositions;origin=math.addVec3(this._origin,rtcCenter,rtcCenter);}}var cfgOrigin=cfg.origin||cfg.rtcCenter;if(cfgOrigin){if(!origin){origin=cfgOrigin;}else{origin=math.addVec3(this._origin,cfgOrigin,tempVec3a$13);}}else{origin=this._origin;}// TODO: treat the possibility of different origins
|
|
7366
7366
|
var _worldMatrix=this._worldMatrixNonIdentity?this._worldMatrix:null;var _meshMatrix;if(!cfg.positionsDecodeMatrix){if(cfg.matrix){_meshMatrix=cfg.matrix;}else{var _scale2=cfg.scale||defaultScale$1;var _position=cfg.position||defaultPosition$1;var _rotation=cfg.rotation||defaultRotation$1;math.eulerToQuaternion(_rotation,"XYZ",defaultQuaternion$1);_meshMatrix=math.composeMat4(_position,defaultQuaternion$1,_scale2,tempMat4$3);}}var _primitive=cfg.primitive||"triangles";switch(_primitive){case"triangles":case"solid":case"surface":portionId=layer.createPortion(utils.apply({origin:origin,color:color,metallic:metallic,roughness:roughness,colors:cfg.colors,colorsCompressed:cfg.colorsCompressed,opacity:opacity,meshMatrix:_meshMatrix,worldMatrix:_worldMatrix,aabb:aabb,pickColor:pickColor},preparedGeometryCfg));var numTriangles=Math.round(preparedGeometryCfg.indices.length/3);this._numTriangles+=numTriangles;mesh.numTriangles=numTriangles;break;case"lines":throw"Not supported at the moment";case"points":throw"Not supported at the moment";}math.expandAABB3(this._aabb,aabb);this.numGeometries++;mesh.origin=origin;}mesh.parent=null;// Will be set within PerformanceModelNode constructor
|
|
7367
7367
|
mesh._layer=layer;mesh._portionId=portionId;mesh.aabb=aabb;this._meshes[id]=mesh;}/**
|
|
7368
7368
|
* Creates an {@link Entity} within this DataTextureSceneModel, giving it one or more meshes previously created with {@link DataTextureSceneModel#createMesh}.
|
|
@@ -11791,9 +11791,9 @@ if(phongMaterial){src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbien
|
|
|
11791
11791
|
//--------------------------------------------------------------------------------
|
|
11792
11792
|
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;}/**
|
|
11793
11793
|
* @author xeolabs / https://github.com/xeolabs
|
|
11794
|
-
*/var tempVec3a$
|
|
11794
|
+
*/var tempVec3a$12=math.vec3();var ids$2=new Map$1({});/**
|
|
11795
11795
|
* @private
|
|
11796
|
-
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$11):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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
|
|
11796
|
+
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$12):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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
|
|
11797
11797
|
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)
|
|
11798
11798
|
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;};/**
|
|
11799
11799
|
* @private
|
|
@@ -11802,47 +11802,47 @@ if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometrySta
|
|
|
11802
11802
|
src.push("vColor = vec4(reflectedColor * fillColor.rgb, fillColor.a);");//src.push("vColor = vec4(reflectedColor + fillColor.rgb, fillColor.a);");
|
|
11803
11803
|
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.sectionPlanes.length>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 _i222=0,len=sectionPlanesState.sectionPlanes.length;_i222<len;_i222++){src.push("uniform bool sectionPlaneActive"+_i222+";");src.push("uniform vec3 sectionPlanePos"+_i222+";");src.push("uniform vec3 sectionPlaneDir"+_i222+";");}}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 _i223=0,_len46=sectionPlanesState.sectionPlanes.length;_i223<_len46;_i223++){src.push("if (sectionPlaneActive"+_i223+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i223+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i223+".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;}/**
|
|
11804
11804
|
* @author xeolabs / https://github.com/xeolabs
|
|
11805
|
-
*/var ids$1=new Map$1({});var tempVec3a$
|
|
11805
|
+
*/var ids$1=new Map$1({});var tempVec3a$11=math.vec3();/**
|
|
11806
11806
|
* @private
|
|
11807
11807
|
*/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
|
|
11808
|
-
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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
11808
|
+
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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$11):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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
|
|
11809
11809
|
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);
|
|
11810
11810
|
// frameCtx.drawElements++;
|
|
11811
11811
|
}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 _i224=0,len=lightsState.lights.length;_i224<len;_i224++){var light=lightsState.lights[_i224];switch(light.type){case"ambient":this._uLightAmbient[_i224]=program.getLocation("lightAmbient");break;case"dir":this._uLightColor[_i224]=program.getLocation("lightColor"+_i224);this._uLightPos[_i224]=null;this._uLightDir[_i224]=program.getLocation("lightDir"+_i224);break;case"point":this._uLightColor[_i224]=program.getLocation("lightColor"+_i224);this._uLightPos[_i224]=program.getLocation("lightPos"+_i224);this._uLightDir[_i224]=null;this._uLightAttenuation[_i224]=program.getLocation("lightAttenuation"+_i224);break;}}this._uSectionPlanes=[];for(var _i225=0,_len47=sectionPlanesState.sectionPlanes.length;_i225<_len47;_i225++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i225),pos:program.getLocation("sectionPlanePos"+_i225),dir:program.getLocation("sectionPlaneDir"+_i225)});}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 _i226=0,len=lightsState.lights.length;_i226<len;_i226++){var light=lightsState.lights[_i226];if(this._uLightAmbient[_i226]){gl.uniform4f(this._uLightAmbient[_i226],light.color[0],light.color[1],light.color[2],light.intensity);}else{if(this._uLightColor[_i226]){gl.uniform4f(this._uLightColor[_i226],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i226]){gl.uniform3fv(this._uLightPos[_i226],light.pos);if(this._uLightAttenuation[_i226]){gl.uniform1f(this._uLightAttenuation[_i226],light.attenuation);}}if(this._uLightDir[_i226]){gl.uniform3fv(this._uLightDir[_i226],light.dir);}}}if(this._uGammaFactor){gl.uniform1f(this._uGammaFactor,scene.gammaFactor);}};/**
|
|
11812
11812
|
* @private
|
|
11813
11813
|
*/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 clipping=scene._sectionPlanesState.sectionPlanes.length>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.sectionPlanes.length>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 _i227=0,len=sectionPlanesState.sectionPlanes.length;_i227<len;_i227++){src.push("uniform bool sectionPlaneActive"+_i227+";");src.push("uniform vec3 sectionPlanePos"+_i227+";");src.push("uniform vec3 sectionPlaneDir"+_i227+";");}}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 _i228=0,_len48=sectionPlanesState.sectionPlanes.length;_i228<_len48;_i228++){src.push("if (sectionPlaneActive"+_i228+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i228+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i228+".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;}/**
|
|
11814
11814
|
* @author xeolabs / https://github.com/xeolabs
|
|
11815
|
-
*/var ids=new Map$1({});var tempVec3a
|
|
11815
|
+
*/var ids=new Map$1({});var tempVec3a$10=math.vec3();/**
|
|
11816
11816
|
* @private
|
|
11817
11817
|
*/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
|
|
11818
|
-
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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a
|
|
11818
|
+
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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$10):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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
|
|
11819
11819
|
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 _i229=0,len=sectionPlanesState.sectionPlanes.length;_i229<len;_i229++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i229),pos:program.getLocation("sectionPlanePos"+_i229),dir:program.getLocation("sectionPlaneDir"+_i229)});}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);}};/**
|
|
11820
11820
|
* @author xeolabs / https://github.com/xeolabs
|
|
11821
11821
|
*/ /**
|
|
11822
11822
|
* @private
|
|
11823
11823
|
*/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 clipping=scene._sectionPlanesState.sectionPlanes.length>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("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 = clipPos;");src.push("}");return src;}function buildFragment$3(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>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.sectionPlanes.length;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.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; }");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;}/**
|
|
11824
11824
|
* @author xeolabs / https://github.com/xeolabs
|
|
11825
|
-
*/var tempVec3a
|
|
11825
|
+
*/var tempVec3a$$=math.vec3();// No ID, because there is exactly one PickMeshRenderer per scene
|
|
11826
11826
|
/**
|
|
11827
11827
|
* @private
|
|
11828
|
-
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a
|
|
11828
|
+
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$$):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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
|
|
11829
11829
|
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);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 _i230=0,len=clips.length;_i230<len;_i230++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i230),pos:program.getLocation("sectionPlanePos"+_i230),dir:program.getLocation("sectionPlaneDir"+_i230)});}this._aPosition=program.getAttribute("position");this._uClippable=program.getLocation("clippable");this._uPickColor=program.getLocation("pickColor");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;};/**
|
|
11830
11830
|
* @private
|
|
11831
11831
|
*/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 clipping=scene._sectionPlanesState.sectionPlanes.length>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;mesh._state.billboard;mesh._state.stationary;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("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 = clipPos;");src.push("}");return src;}function buildFragment$2(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>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 _i231=0;_i231<sectionPlanesState.sectionPlanes.length;_i231++){src.push("uniform bool sectionPlaneActive"+_i231+";");src.push("uniform vec3 sectionPlanePos"+_i231+";");src.push("uniform vec3 sectionPlaneDir"+_i231+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push("if (clippable) {");src.push(" float dist = 0.0;");for(var _i232=0;_i232<sectionPlanesState.sectionPlanes.length;_i232++){src.push("if (sectionPlaneActive"+_i232+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i232+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i232+".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;}/**
|
|
11832
11832
|
* @author xeolabs / https://github.com/xeolabs
|
|
11833
|
-
*/var tempVec3a$
|
|
11833
|
+
*/var tempVec3a$_=math.vec3();/**
|
|
11834
11834
|
* @private
|
|
11835
|
-
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
11835
|
+
*/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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$_):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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);}pickColorsBuf.bind();gl.enableVertexAttribArray(this._aColor.location);gl.vertexAttribPointer(this._aColor.location,pickColorsBuf.itemSize,pickColorsBuf.itemType,true,0,0);// Normalize
|
|
11836
11836
|
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 _i233=0,len=sectionPlanes.length;_i233<len;_i233++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i233),pos:program.getLocation("sectionPlanePos"+_i233),dir:program.getLocation("sectionPlaneDir"+_i233)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._uClippable=program.getLocation("clippable");this._uOffset=program.getLocation("offset");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}};/**
|
|
11837
11837
|
* @author xeolabs / https://github.com/xeolabs
|
|
11838
11838
|
*/ /**
|
|
11839
11839
|
* @private
|
|
11840
11840
|
*/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 clipping=scene._sectionPlanesState.sectionPlanes.length>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.sectionPlanes.length>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.sectionPlanes.length;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.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; }");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;}/**
|
|
11841
11841
|
* @author xeolabs / https://github.com/xeolabs
|
|
11842
|
-
*/var tempVec3a$
|
|
11842
|
+
*/var tempVec3a$Z=math.vec3();// No ID, because there is exactly one PickMeshRenderer per scene
|
|
11843
11843
|
/**
|
|
11844
11844
|
* @private
|
|
11845
|
-
*/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(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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$
|
|
11845
|
+
*/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(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 numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];gl.uniform3fv(sectionPlaneUniforms.pos,origin?getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$Z):sectionPlane.pos);gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}}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 _i234=0,len=clips.length;_i234<len;_i234++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i234),pos:program.getLocation("sectionPlanePos"+_i234),dir:program.getLocation("sectionPlaneDir"+_i234)});}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;};/**
|
|
11846
11846
|
* @private
|
|
11847
11847
|
*/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.sectionPlanes.length>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.sectionPlanes.length;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.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; }");src.push("}");}src.push("outColor = encodeFloat(gl_FragCoord.z);");src.push("}");return src;}/**
|
|
11848
11848
|
* @private
|
|
@@ -15618,7 +15618,7 @@ var positions=K3D.edit.unwrap(m.i_verts,m.c_verts,3);var normals=K3D.edit.unwrap
|
|
|
15618
15618
|
* Destroys this ````LineSet````.
|
|
15619
15619
|
*
|
|
15620
15620
|
* Removes the ```LineSet```` from {@link Scene#lineSets}; causes Scene to fire a "lineSetDestroyed" event.
|
|
15621
|
-
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(LineSet.prototype),"destroy",this).call(this);this.scene._lineSetDestroyed(this);}}]);return LineSet;}(Component);var tempVec3$4=math.vec3();var tempVec3a$
|
|
15621
|
+
*/},{key:"destroy",value:function destroy(){_get(_getPrototypeOf(LineSet.prototype),"destroy",this).call(this);this.scene._lineSetDestroyed(this);}}]);return LineSet;}(Component);var tempVec3$4=math.vec3();var tempVec3a$Y=math.vec3();var tempVec3b$a=math.vec3();var tempVec3c$6=math.vec3();/**
|
|
15622
15622
|
* {@link Viewer} plugin that saves and loads BCF viewpoints as JSON objects.
|
|
15623
15623
|
*
|
|
15624
15624
|
* [<img src="http://xeokit.github.io/xeokit-sdk/assets/images/BCFViewpointsPlugin.png">](http://xeokit.github.io/xeokit-sdk/examples/#BCF_SaveViewpoint)
|
|
@@ -15978,7 +15978,7 @@ alpha=0.1;}else{alpha=scene.xrayMaterial.fillAlpha;}alpha=Math.round(alpha*255).
|
|
|
15978
15978
|
* then this method will apply the updates to objects within those composites.
|
|
15979
15979
|
*/},{key:"setViewpoint",value:function setViewpoint(bcfViewpoint){var _this66=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.forEach(function(e){var pos=xyzObjectToArray(e.location,tempVec3$4);var dir=xyzObjectToArray(e.direction,tempVec3$4);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){var _positions6=[];var indices=[];var _i272=0;bcfViewpoint.lines.forEach(function(e){if(!e.start_point){return;}if(!e.end_point){return;}_positions6.push(e.start_point.x);_positions6.push(e.start_point.y);_positions6.push(e.start_point.z);_positions6.push(e.end_point.x);_positions6.push(e.end_point.y);_positions6.push(e.end_point.z);indices.push(_i272++);indices.push(_i272++);});new LineSet(scene,{positions:_positions6,indices:indices,clippable:false,collidable:true});}scene.clearBitmaps();if(bcfViewpoint.bitmaps){bcfViewpoint.bitmaps.forEach(function(e){var bitmap_type=e.bitmap_type||"jpg";// "jpg" | "png"
|
|
15980
15980
|
var bitmap_data=e.bitmap_data;// base64
|
|
15981
|
-
var location=xyzObjectToArray(e.location,tempVec3a$
|
|
15981
|
+
var location=xyzObjectToArray(e.location,tempVec3a$Y);var normal=xyzObjectToArray(e.normal,tempVec3b$a);var up=xyzObjectToArray(e.up,tempVec3c$6);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 _this66._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 _this66._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.openings_visible===false){scene.setObjectsVisible(viewer.metaScene.getObjectIDsByType("IfcOpening"),false);}if(view_setup_hints.space_boundaries_visible!==undefined);}}if(bcfViewpoint.components.selection){scene.setObjectsSelected(scene.selectedObjectIds,false);bcfViewpoint.components.selection.forEach(function(component){return _this66._withBCFComponent(options,component,function(entity){return entity.selected=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 _this66._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 up;var projection;if(bcfViewpoint.perspective_camera){eye=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_view_point,tempVec3$4);look=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_direction,tempVec3$4);up=xyzObjectToArray(bcfViewpoint.perspective_camera.camera_up_vector,tempVec3$4);camera.perspective.fov=bcfViewpoint.perspective_camera.field_of_view;projection="perspective";}else{eye=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_view_point,tempVec3$4);look=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_direction,tempVec3$4);up=xyzObjectToArray(bcfViewpoint.orthogonal_camera.camera_up_vector,tempVec3$4);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);up=ZToY(up);}if(rayCast){var hit=scene.pick({pickSurface:true,// <<------ This causes picking to find the intersection point on the entity
|
|
15982
15982
|
origin:eye,direction:look});look=hit?hit.worldPos:math.addVec3(eye,look,tempVec3$4);}else{look=math.addVec3(eye,look,tempVec3$4);}if(immediate){camera.eye=eye;camera.look=look;camera.up=up;camera.projection=projection;}else{viewer.cameraFlight.flyTo({eye:eye,look:look,up:up,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);}}});}}/**
|
|
15983
15983
|
* Destroys this BCFViewpointsPlugin.
|
|
15984
15984
|
*/},{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 distVec3=math.vec3();var lengthWire=function lengthWire(x1,y1,x2,y2){var a=x1-x2;var b=y1-y2;return Math.sqrt(a*a+b*b);};/**
|
|
@@ -15990,7 +15990,7 @@ origin:eye,direction:look});look=hit?hit.worldPos:math.addVec3(eye,look,tempVec3
|
|
|
15990
15990
|
*/function DistanceMeasurement(plugin){var _this67;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,DistanceMeasurement);_this67=_super44.call(this,plugin.viewer.scene,cfg);/**
|
|
15991
15991
|
* The {@link DistanceMeasurementsPlugin} that owns this DistanceMeasurement.
|
|
15992
15992
|
* @type {DistanceMeasurementsPlugin}
|
|
15993
|
-
*/_this67.plugin=plugin;_this67._container=cfg.container;if(!_this67._container){throw"config missing: container";}_this67._eventSubs={};var scene=_this67.plugin.viewer.scene;_this67._originMarker=new Marker(scene,cfg.origin);_this67._targetMarker=new Marker(scene,cfg.target);_this67._originWorld=math.vec3();_this67._targetWorld=math.vec3();_this67._wp=new Float64Array(24);_this67._vp=new Float64Array(24);_this67._pp=new Float64Array(24);_this67._cp=new Float64Array(8);_this67._xAxisLabelCulled=false;_this67._yAxisLabelCulled=false;_this67._zAxisLabelCulled=false;_this67._color=cfg.color||_this67.plugin.defaultColor;var onMouseOver=cfg.onMouseOver?function(event){cfg.onMouseOver(event,_assertThisInitialized(_this67));}:null;var onMouseLeave=cfg.onMouseLeave?function(event){cfg.onMouseLeave(event,_assertThisInitialized(_this67));}:null;var onContextMenu=cfg.onContextMenu?function(event){cfg.onContextMenu(event,_assertThisInitialized(_this67));}:null;_this67._originDot=new Dot(_this67._container,{fillColor:_this67._color,zIndex:plugin.zIndex!==undefined?plugin.zIndex+2:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._targetDot=new Dot(_this67._container,{fillColor:_this67._color,zIndex:plugin.zIndex!==undefined?plugin.zIndex+2:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._lengthWire=new Wire(_this67._container,{color:_this67._color,thickness:2,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._xAxisWire=new Wire(_this67._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._yAxisWire=new Wire(_this67._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._zAxisWire=new Wire(_this67._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._lengthLabel=new Label(_this67._container,{fillColor:_this67._color,prefix:"",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+4:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._xAxisLabel=new Label(_this67._container,{fillColor:"red",prefix:"X",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._yAxisLabel=new Label(_this67._container,{fillColor:"green",prefix:"Y",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._zAxisLabel=new Label(_this67._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onContextMenu:onContextMenu});_this67._wpDirty=false;_this67._vpDirty=false;_this67._cpDirty=false;_this67._visible=false;_this67._originVisible=false;_this67._targetVisible=false;_this67._wireVisible=false;_this67._axisVisible=false;_this67._xAxisVisible=false;_this67._yAxisVisible=false;_this67._zAxisVisible=false;_this67._axisEnabled=true;_this67._labelsVisible=false;_this67._clickable=false;_this67._originMarker.on("worldPos",function(value){_this67._originWorld.set(value||[0,0,0]);_this67._wpDirty=true;_this67._needUpdate(0);// No lag
|
|
15993
|
+
*/_this67.plugin=plugin;_this67._container=cfg.container;if(!_this67._container){throw"config missing: container";}_this67._eventSubs={};var scene=_this67.plugin.viewer.scene;_this67._originMarker=new Marker(scene,cfg.origin);_this67._targetMarker=new Marker(scene,cfg.target);_this67._originWorld=math.vec3();_this67._targetWorld=math.vec3();_this67._wp=new Float64Array(24);_this67._vp=new Float64Array(24);_this67._pp=new Float64Array(24);_this67._cp=new Float64Array(8);_this67._xAxisLabelCulled=false;_this67._yAxisLabelCulled=false;_this67._zAxisLabelCulled=false;_this67._color=cfg.color||_this67.plugin.defaultColor;var onMouseOver=cfg.onMouseOver?function(event){cfg.onMouseOver(event,_assertThisInitialized(_this67));}:null;var onMouseLeave=cfg.onMouseLeave?function(event){cfg.onMouseLeave(event,_assertThisInitialized(_this67));}:null;var onContextMenu=cfg.onContextMenu?function(event){cfg.onContextMenu(event,_assertThisInitialized(_this67));}:null;var onMouseWheel=function onMouseWheel(event){_this67.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent('wheel',event));};_this67._originDot=new Dot(_this67._container,{fillColor:_this67._color,zIndex:plugin.zIndex!==undefined?plugin.zIndex+2:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._targetDot=new Dot(_this67._container,{fillColor:_this67._color,zIndex:plugin.zIndex!==undefined?plugin.zIndex+2:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._lengthWire=new Wire(_this67._container,{color:_this67._color,thickness:2,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._xAxisWire=new Wire(_this67._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._yAxisWire=new Wire(_this67._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._zAxisWire=new Wire(_this67._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:plugin.zIndex!==undefined?plugin.zIndex+1:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._lengthLabel=new Label(_this67._container,{fillColor:_this67._color,prefix:"",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+4:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._xAxisLabel=new Label(_this67._container,{fillColor:"red",prefix:"X",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._yAxisLabel=new Label(_this67._container,{fillColor:"green",prefix:"Y",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._zAxisLabel=new Label(_this67._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:plugin.zIndex!==undefined?plugin.zIndex+3:undefined,onMouseOver:onMouseOver,onMouseLeave:onMouseLeave,onMouseWheel:onMouseWheel,onContextMenu:onContextMenu});_this67._wpDirty=false;_this67._vpDirty=false;_this67._cpDirty=false;_this67._visible=false;_this67._originVisible=false;_this67._targetVisible=false;_this67._wireVisible=false;_this67._axisVisible=false;_this67._xAxisVisible=false;_this67._yAxisVisible=false;_this67._zAxisVisible=false;_this67._axisEnabled=true;_this67._labelsVisible=false;_this67._clickable=false;_this67._originMarker.on("worldPos",function(value){_this67._originWorld.set(value||[0,0,0]);_this67._wpDirty=true;_this67._needUpdate(0);// No lag
|
|
15994
15994
|
});_this67._targetMarker.on("worldPos",function(value){_this67._targetWorld.set(value||[0,0,0]);_this67._wpDirty=true;_this67._needUpdate(0);// No lag
|
|
15995
15995
|
});_this67._onViewMatrix=scene.camera.on("viewMatrix",function(){_this67._vpDirty=true;_this67._needUpdate(0);// No lag
|
|
15996
15996
|
});_this67._onProjMatrix=scene.camera.on("projMatrix",function(){_this67._cpDirty=true;_this67._needUpdate();});_this67._onCanvasBoundary=scene.canvas.on("boundary",function(){_this67._cpDirty=true;_this67._needUpdate(0);// No lag
|
|
@@ -16515,7 +16515,7 @@ comparison=arcLengths[i]-targetArcLength;if(comparison<0){low=i+1;}else if(compa
|
|
|
16515
16515
|
*
|
|
16516
16516
|
* @param {Number} t Position to get point at.
|
|
16517
16517
|
* @returns {Number[]} Point at the given position.
|
|
16518
|
-
*/},{key:"getPoint",value:function getPoint(t){var points=this.points;if(points.length<3){this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].");return;}var point=(points.length-1)*t;var intPoint=Math.floor(point);var weight=point-intPoint;var point0=points[intPoint===0?intPoint:intPoint-1];var point1=points[intPoint];var point2=points[intPoint>points.length-2?points.length-1:intPoint+1];var point3=points[intPoint>points.length-3?points.length-1:intPoint+2];var vector=math.vec3();vector[0]=math.catmullRomInterpolate(point0[0],point1[0],point2[0],point3[0],weight);vector[1]=math.catmullRomInterpolate(point0[1],point1[1],point2[1],point3[1],weight);vector[2]=math.catmullRomInterpolate(point0[2],point1[2],point2[2],point3[2],weight);return vector;}},{key:"getJSON",value:function getJSON(){return{points:points,t:this._t};}}]);return SplineCurve;}(Curve);var tempVec3a$
|
|
16518
|
+
*/},{key:"getPoint",value:function getPoint(t){var points=this.points;if(points.length<3){this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].");return;}var point=(points.length-1)*t;var intPoint=Math.floor(point);var weight=point-intPoint;var point0=points[intPoint===0?intPoint:intPoint-1];var point1=points[intPoint];var point2=points[intPoint>points.length-2?points.length-1:intPoint+1];var point3=points[intPoint>points.length-3?points.length-1:intPoint+2];var vector=math.vec3();vector[0]=math.catmullRomInterpolate(point0[0],point1[0],point2[0],point3[0],weight);vector[1]=math.catmullRomInterpolate(point0[1],point1[1],point2[1],point3[1],weight);vector[2]=math.catmullRomInterpolate(point0[2],point1[2],point2[2],point3[2],weight);return vector;}},{key:"getJSON",value:function getJSON(){return{points:points,t:this._t};}}]);return SplineCurve;}(Curve);var tempVec3a$X=math.vec3();/**
|
|
16519
16519
|
* @desc Defines a sequence of frames along which a {@link CameraPathAnimation} can animate a {@link Camera}.
|
|
16520
16520
|
*
|
|
16521
16521
|
* See {@link CameraPathAnimation} for usage.
|
|
@@ -16563,7 +16563,7 @@ comparison=arcLengths[i]-targetArcLength;if(comparison<0){low=i+1;}else if(compa
|
|
|
16563
16563
|
* Sets the position of the {@link Camera} to a position interpolated within this CameraPath at the given time instant.
|
|
16564
16564
|
*
|
|
16565
16565
|
* @param {Number} t Time instant.
|
|
16566
|
-
*/},{key:"loadFrame",value:function loadFrame(t){var camera=this.scene.camera;t=t/(this._frames[this._frames.length-1].t-this._frames[0].t);t=t<0.0?0.0:t>1.0?1.0:t;camera.eye=this._eyeCurve.getPoint(t,tempVec3a$
|
|
16566
|
+
*/},{key:"loadFrame",value:function loadFrame(t){var camera=this.scene.camera;t=t/(this._frames[this._frames.length-1].t-this._frames[0].t);t=t<0.0?0.0:t>1.0?1.0:t;camera.eye=this._eyeCurve.getPoint(t,tempVec3a$X);camera.look=this._lookCurve.getPoint(t,tempVec3a$X);camera.up=this._upCurve.getPoint(t,tempVec3a$X);}/**
|
|
16567
16567
|
* Gets eye, look and up vectors on this CameraPath at a given instant.
|
|
16568
16568
|
*
|
|
16569
16569
|
* @param {Number} t Time instant.
|
|
@@ -16913,7 +16913,7 @@ t/=d;return-c*t*(t-2)+b;}},{key:"_easeInCubic",value:function _easeInCubic(t,b,c
|
|
|
16913
16913
|
* @param {Number} frameIdx Index of the frame to scrub to.
|
|
16914
16914
|
*/},{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;}/**
|
|
16915
16915
|
* Stops playing this CameraPathAnimation.
|
|
16916
|
-
*/},{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$2=math.vec3();var tempVec3b$
|
|
16916
|
+
*/},{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$2=math.vec3();var tempVec3b$9=math.vec3();math.vec3();var zeroVec$1=math.vec3([0,-1,0]);var tempQuat=math.vec4([0,0,0,1]);/**
|
|
16917
16917
|
* @desc A plane-shaped 3D object containing a bitmap image.
|
|
16918
16918
|
*
|
|
16919
16919
|
* Use ````ImagePlane```` to embed bitmap images in your scenes.
|
|
@@ -17149,7 +17149,7 @@ t/=d;return-c*t*(t-2)+b;}},{key:"_easeInCubic",value:function _easeInCubic(t,b,c
|
|
|
17149
17149
|
* Default is ````true````.
|
|
17150
17150
|
*
|
|
17151
17151
|
* @type {Boolean}
|
|
17152
|
-
*/,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$2);var dist=-math.dotVec3(negDir,tempVec3$2);math.normalizeVec3(negDir);math.mulVec3Scalar(negDir,dist,tempVec3b$
|
|
17152
|
+
*/,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$2);var dist=-math.dotVec3(negDir,tempVec3$2);math.normalizeVec3(negDir);math.mulVec3Scalar(negDir,dist,tempVec3b$9);math.vec3PairToQuaternion(zeroVec$1,dir,tempQuat);this._node.quaternion=tempQuat;}}},{key:"collidable",get:/**
|
|
17153
17153
|
* Gets if this ````ImagePlane```` is included in boundary calculations.
|
|
17154
17154
|
*
|
|
17155
17155
|
* Default is ````true````.
|
|
@@ -17680,11 +17680,11 @@ this._occluded=!visible;this._mesh.visible=this._visible&&!this._occluded;_get(_
|
|
|
17680
17680
|
* This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas.
|
|
17681
17681
|
*
|
|
17682
17682
|
* @type {Number}
|
|
17683
|
-
*/function get(){return this._mesh.opacity;},set:function set(opacity){this._mesh.opacity=opacity;}},{key:"_updatePlaneSizeFromImage",value:function _updatePlaneSizeFromImage(){var halfSize=this._size*0.5;var width=this._imageSize[0];var height=this._imageSize[1];var aspect=height/width;if(width>height){this._geometry.positions=[halfSize,halfSize*aspect,0,-halfSize,halfSize*aspect,0,-halfSize,-halfSize*aspect,0,halfSize,-halfSize*aspect,0];}else{this._geometry.positions=[halfSize/aspect,halfSize,0,-halfSize/aspect,halfSize,0,-halfSize/aspect,-halfSize,0,halfSize/aspect,-halfSize,0];}}}]);return SpriteMarker;}(Marker);var tempVec3a$
|
|
17683
|
+
*/function get(){return this._mesh.opacity;},set:function set(opacity){this._mesh.opacity=opacity;}},{key:"_updatePlaneSizeFromImage",value:function _updatePlaneSizeFromImage(){var halfSize=this._size*0.5;var width=this._imageSize[0];var height=this._imageSize[1];var aspect=height/width;if(width>height){this._geometry.positions=[halfSize,halfSize*aspect,0,-halfSize,halfSize*aspect,0,-halfSize,-halfSize*aspect,0,halfSize,-halfSize*aspect,0];}else{this._geometry.positions=[halfSize/aspect,halfSize,0,-halfSize/aspect,halfSize,0,-halfSize/aspect,-halfSize,0,halfSize/aspect,-halfSize,0];}}}]);return SpriteMarker;}(Marker);var tempVec3a$W=math.vec3();var tempVec3b$8=math.vec3();var tempMat4a=math.mat4();/**
|
|
17684
17684
|
* @private
|
|
17685
17685
|
*/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;}();/**
|
|
17686
17686
|
* @private
|
|
17687
|
-
*/var Frustum=/*#__PURE__*/_createClass(function Frustum(){_classCallCheck(this,Frustum);this.planes=[new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane()];});Frustum.INSIDE=0;Frustum.INTERSECT=1;Frustum.OUTSIDE=2;/** @private */function setFrustum(frustum,viewMat,projMat){var m=math.mulMat4(projMat,viewMat,tempMat4a);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.INSIDE;var min=tempVec3a$
|
|
17687
|
+
*/var Frustum=/*#__PURE__*/_createClass(function Frustum(){_classCallCheck(this,Frustum);this.planes=[new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane(),new FrustumPlane()];});Frustum.INSIDE=0;Frustum.INTERSECT=1;Frustum.OUTSIDE=2;/** @private */function setFrustum(frustum,viewMat,projMat){var m=math.mulMat4(projMat,viewMat,tempMat4a);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.INSIDE;var min=tempVec3a$W;var max=tempVec3b$8;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 _i279=0;_i279<6;++_i279){var plane=frustum.planes[_i279];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.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.INTERSECT;}}return ret;}/**
|
|
17688
17688
|
* @desc Saves and restores the state of a {@link Scene}'s {@link Camera}.
|
|
17689
17689
|
*
|
|
17690
17690
|
* ## See Also
|
|
@@ -18822,92 +18822,92 @@ NOT_RENDERED:0,// Normal rendering - mutually exclusive modes
|
|
|
18822
18822
|
COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,// Emphasis silhouette rendering - mutually exclusive modes
|
|
18823
18823
|
SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,// Edges rendering - mutually exclusive modes
|
|
18824
18824
|
EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,// Picking
|
|
18825
|
-
PICK:11};var tempVec4$7=math.vec4();var tempVec3a$
|
|
18825
|
+
PICK:11};var tempVec4$7=math.vec4();var tempVec3a$V=math.vec3();/**
|
|
18826
18826
|
* @private
|
|
18827
|
-
*/var TrianglesBatchingColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18827
|
+
*/var TrianglesBatchingColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$V);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i281=0,len=lights.length;_i281<len;_i281++){light=lights[_i281];switch(light.type){case"dir":this._uLightColor[_i281]=program.getLocation("lightColor"+_i281);this._uLightPos[_i281]=null;this._uLightDir[_i281]=program.getLocation("lightDir"+_i281);break;case"point":this._uLightColor[_i281]=program.getLocation("lightColor"+_i281);this._uLightPos[_i281]=program.getLocation("lightPos"+_i281);this._uLightDir[_i281]=null;this._uLightAttenuation[_i281]=program.getLocation("lightAttenuation"+_i281);break;case"spot":this._uLightColor[_i281]=program.getLocation("lightColor"+_i281);this._uLightPos[_i281]=program.getLocation("lightPos"+_i281);this._uLightDir[_i281]=program.getLocation("lightDir"+_i281);this._uLightAttenuation[_i281]=program.getLocation("lightAttenuation"+_i281);break;}}this._uSectionPlanes=[];for(var _i282=0,_len50=scene._sectionPlanesState.sectionPlanes.length;_i282<_len50;_i282++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i282),pos:program.getLocation("sectionPlanePos"+_i282),dir:program.getLocation("sectionPlaneDir"+_i282)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lights=scene._lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i283=0,len=lights.length;_i283<len;_i283++){var light=lights[_i283];if(this._uLightColor[_i283]){gl.uniform4f(this._uLightColor[_i283],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i283]){gl.uniform3fv(this._uLightPos[_i283],light.pos);if(this._uLightAttenuation[_i283]){gl.uniform1f(this._uLightAttenuation[_i283],light.attenuation);}}if(this._uLightDir[_i283]){gl.uniform3fv(this._uLightDir[_i283],light.dir);}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$7[0]=viewportWidth;tempVec4$7[1]=viewportHeight;tempVec4$7[2]=sao.blendCutoff;tempVec4$7[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$7);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,0);}}if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>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 vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");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;");}src.push("uniform vec4 lightAmbient;");for(var _i284=0,len=lightsState.lights.length;_i284<len;_i284++){light=lightsState.lights[_i284];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+_i284+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+_i284+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+_i284+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+_i284+";");src.push("uniform vec3 lightDir"+_i284+";");}}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 vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18828
18828
|
// renderPass = COLOR_OPAQUE
|
|
18829
18829
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18830
18830
|
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 _i285=0,_len51=lightsState.lights.length;_i285<_len51;_i285++){light=lightsState.lights[_i285];if(light.type==="ambient"){continue;}if(light.type==="dir"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i285+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i285+", 0.0)).xyz);");}}else if(light.type==="point"){if(light.space==="view"){src.push("viewLightDir = -normalize(lightPos"+_i285+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+_i285+", 0.0)).xyz);");}}else if(light.type==="spot"){if(light.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i285+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i285+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i285+".rgb * lightColor"+_i285+".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("vFlags2 = flags2;");}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.sectionPlanes.length>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 vec4 vFlags2;");for(var _i286=0,len=sectionPlanesState.sectionPlanes.length;_i286<len;_i286++){src.push("uniform bool sectionPlaneActive"+_i286+";");src.push("uniform vec3 sectionPlanePos"+_i286+";");src.push("uniform vec3 sectionPlaneDir"+_i286+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i287=0,_len52=sectionPlanesState.sectionPlanes.length;_i287<_len52;_i287++){src.push("if (sectionPlaneActive"+_i287+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i287+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i287+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");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
|
|
18831
18831
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
18832
|
-
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingColorRenderer;}();var tempVec4$6=math.vec4();var tempVec3a$
|
|
18832
|
+
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingColorRenderer;}();var tempVec4$6=math.vec4();var tempVec3a$U=math.vec3();/**
|
|
18833
18833
|
* @private
|
|
18834
|
-
*/var TrianglesBatchingFlatColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingFlatColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingFlatColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingFlatColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18834
|
+
*/var TrianglesBatchingFlatColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingFlatColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingFlatColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingFlatColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$U);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i288=0,len=lights.length;_i288<len;_i288++){light=lights[_i288];switch(light.type){case"dir":this._uLightColor[_i288]=program.getLocation("lightColor"+_i288);this._uLightPos[_i288]=null;this._uLightDir[_i288]=program.getLocation("lightDir"+_i288);break;case"point":this._uLightColor[_i288]=program.getLocation("lightColor"+_i288);this._uLightPos[_i288]=program.getLocation("lightPos"+_i288);this._uLightDir[_i288]=null;this._uLightAttenuation[_i288]=program.getLocation("lightAttenuation"+_i288);break;case"spot":this._uLightColor[_i288]=program.getLocation("lightColor"+_i288);this._uLightPos[_i288]=program.getLocation("lightPos"+_i288);this._uLightDir[_i288]=program.getLocation("lightDir"+_i288);this._uLightAttenuation[_i288]=program.getLocation("lightAttenuation"+_i288);break;}}this._uSectionPlanes=[];for(var _i289=0,_len53=scene._sectionPlanesState.sectionPlanes.length;_i289<_len53;_i289++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i289),pos:program.getLocation("sectionPlanePos"+_i289),dir:program.getLocation("sectionPlaneDir"+_i289)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lights=scene._lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i290=0,len=lights.length;_i290<len;_i290++){var light=lights[_i290];if(this._uLightColor[_i290]){gl.uniform4f(this._uLightColor[_i290],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i290]){gl.uniform3fv(this._uLightPos[_i290],light.pos);if(this._uLightAttenuation[_i290]){gl.uniform1f(this._uLightAttenuation[_i290],light.attenuation);}}if(this._uLightDir[_i290]){gl.uniform3fv(this._uLightDir[_i290],light.dir);}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$6[0]=viewportWidth;tempVec4$6[1]=viewportHeight;tempVec4$6[2]=sao.blendCutoff;tempVec4$6[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$6);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,0);}}if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching flat-shading draw vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18835
18835
|
// renderPass = COLOR_OPAQUE
|
|
18836
18836
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18837
18837
|
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("vViewPosition = viewPosition;");src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 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("vFlags2 = flags2;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var lightsState=scene._lightsState;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching flat-shading 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 vec4 vFlags2;");for(var _i291=0,len=sectionPlanesState.sectionPlanes.length;_i291<len;_i291++){src.push("uniform bool sectionPlaneActive"+_i291+";");src.push("uniform vec3 sectionPlanePos"+_i291+";");src.push("uniform vec3 sectionPlaneDir"+_i291+";");}}src.push("uniform mat4 viewMatrix;");src.push("uniform vec4 lightAmbient;");for(var _i292=0,_len54=lightsState.lights.length;_i292<_len54;_i292++){var light=lightsState.lights[_i292];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+_i292+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+_i292+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+_i292+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+_i292+";");src.push("uniform vec3 lightDir"+_i292+";");}}src.push("in vec4 vViewPosition;");src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i293=0,_len55=sectionPlanesState.sectionPlanes.length;_i293<_len55;_i293++){src.push("if (sectionPlaneActive"+_i293+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i293+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i293+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");src.push("}");}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;");src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var _i294=0,_len56=lightsState.lights.length;_i294<_len56;_i294++){var _light5=lightsState.lights[_i294];if(_light5.type==="ambient"){continue;}if(_light5.type==="dir"){if(_light5.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i294+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i294+", 0.0)).xyz);");}}else if(_light5.type==="point"){if(_light5.space==="view"){src.push("viewLightDir = -normalize(lightPos"+_i294+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+_i294+", 0.0)).xyz);");}}else if(_light5.type==="spot"){if(_light5.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i294+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+_i294+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i294+".rgb * lightColor"+_i294+".a);");}src.push("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
18838
18838
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
18839
|
-
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(fragColor.rgb * ambient, 1.0);");}else{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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingFlatColorRenderer;}();var defaultColor$4=new Float32Array([1,1,1]);var tempVec3a$
|
|
18839
|
+
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(fragColor.rgb * ambient, 1.0);");}else{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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingFlatColorRenderer;}();var defaultColor$4=new Float32Array([1,1,1]);var tempVec3a$T=math.vec3();/**
|
|
18840
18840
|
* @private
|
|
18841
|
-
*/var TrianglesBatchingSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesBatchingSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,TrianglesBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uSilhouetteColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material5=scene.highlightMaterial._state;var _fillColor3=_material5.fillColor;var _fillAlpha3=_material5.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor3[0],_fillColor3[1],_fillColor3[2],_fillAlpha3);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material6=scene.selectedMaterial._state;var _fillColor4=_material6.fillColor;var _fillAlpha4=_material6.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor4[0],_fillColor4[1],_fillColor4[2],_fillAlpha4);}else{gl.uniform4fv(this._uSilhouetteColor,defaultColor$4);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18841
|
+
*/var TrianglesBatchingSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesBatchingSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,TrianglesBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uSilhouetteColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material5=scene.highlightMaterial._state;var _fillColor3=_material5.fillColor;var _fillAlpha3=_material5.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor3[0],_fillColor3[1],_fillColor3[2],_fillAlpha3);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material6=scene.selectedMaterial._state;var _fillColor4=_material6.fillColor;var _fillAlpha4=_material6.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor4[0],_fillColor4[1],_fillColor4[2],_fillAlpha4);}else{gl.uniform4fv(this._uSilhouetteColor,defaultColor$4);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$T);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSilhouetteColor=program.getLocation("silhouetteColor");this._uSectionPlanes=[];for(var _i295=0,len=scene._sectionPlanesState.sectionPlanes.length;_i295<len;_i295++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i295),pos:program.getLocation("sectionPlanePos"+_i295),dir:program.getLocation("sectionPlaneDir"+_i295)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aColor=program.getAttribute("color");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 color;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform vec4 silhouetteColor;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | SILHOUETTE_XRAYED
|
|
18842
18842
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
18843
18843
|
src.push("if (int(flags.y) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18844
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, 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));");}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 i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching silhouette 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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 = vColor;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingSilhouetteRenderer;}();var tempVec3a$
|
|
18844
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, 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));");}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 i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching silhouette 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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 = vColor;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingSilhouetteRenderer;}();var tempVec3a$S=math.vec3();var defaultColor$3=new Float32Array([0,0,0,1]);/**
|
|
18845
18845
|
* @private
|
|
18846
|
-
*/var TrianglesBatchingEdgesRenderer=/*#__PURE__*/function(){function TrianglesBatchingEdgesRenderer(scene){_classCallCheck(this,TrianglesBatchingEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES.EDGES_HIGHLIGHTED){var _material7=scene.highlightMaterial._state;var _edgeColor3=_material7.edgeColor;var _edgeAlpha3=_material7.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor3[0],_edgeColor3[1],_edgeColor3[2],_edgeAlpha3);}else if(renderPass===RENDER_PASSES.EDGES_SELECTED){var _material8=scene.selectedMaterial._state;var _edgeColor4=_material8.edgeColor;var _edgeAlpha4=_material8.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor4[0],_edgeColor4[1],_edgeColor4[2],_edgeAlpha4);}else{gl.uniform4fv(this._uColor,defaultColor$3);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18846
|
+
*/var TrianglesBatchingEdgesRenderer=/*#__PURE__*/function(){function TrianglesBatchingEdgesRenderer(scene){_classCallCheck(this,TrianglesBatchingEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES.EDGES_HIGHLIGHTED){var _material7=scene.highlightMaterial._state;var _edgeColor3=_material7.edgeColor;var _edgeAlpha3=_material7.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor3[0],_edgeColor3[1],_edgeColor3[2],_edgeAlpha3);}else if(renderPass===RENDER_PASSES.EDGES_SELECTED){var _material8=scene.selectedMaterial._state;var _edgeColor4=_material8.edgeColor;var _edgeAlpha4=_material8.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor4[0],_edgeColor4[1],_edgeColor4[2],_edgeAlpha4);}else{gl.uniform4fv(this._uColor,defaultColor$3);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$S);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.edgeIndicesBuf.bind();gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uColor=program.getLocation("color");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i296=0,len=scene._sectionPlanesState.sectionPlanes.length;_i296<len;_i296++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i296),pos:program.getLocation("sectionPlanePos"+_i296),dir:program.getLocation("sectionPlaneDir"+_i296)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var project=scene.camera.project;program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry edges drawing vertex shader");src.push("uniform int renderPass;");src.push("uniform vec4 color;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.z = NOT_RENDERED | EDGES_COLOR_OPAQUE | EDGES_COLOR_TRANSPARENT | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
18847
18847
|
// renderPass = EDGES_COLOR_OPAQUE | EDGES_COLOR_TRANSPARENT | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
18848
18848
|
src.push("if (int(flags.z) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18849
|
-
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i297=0,len=sectionPlanesState.sectionPlanes.length;_i297<len;_i297++){src.push("uniform bool sectionPlaneActive"+_i297+";");src.push("uniform vec3 sectionPlanePos"+_i297+";");src.push("uniform vec3 sectionPlaneDir"+_i297+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i298=0,_len57=sectionPlanesState.sectionPlanes.length;_i298<_len57;_i298++){src.push("if (sectionPlaneActive"+_i298+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i298+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i298+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingEdgesRenderer;}();var tempVec3a$
|
|
18849
|
+
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i297=0,len=sectionPlanesState.sectionPlanes.length;_i297<len;_i297++){src.push("uniform bool sectionPlaneActive"+_i297+";");src.push("uniform vec3 sectionPlanePos"+_i297+";");src.push("uniform vec3 sectionPlaneDir"+_i297+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i298=0,_len57=sectionPlanesState.sectionPlanes.length;_i298<_len57;_i298++){src.push("if (sectionPlaneActive"+_i298+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i298+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i298+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingEdgesRenderer;}();var tempVec3a$R=math.vec3();/**
|
|
18850
18850
|
* @private
|
|
18851
|
-
*/var TrianglesBatchingEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingEdgesColorRenderer(scene){_classCallCheck(this,TrianglesBatchingEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18851
|
+
*/var TrianglesBatchingEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesBatchingEdgesColorRenderer(scene){_classCallCheck(this,TrianglesBatchingEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$R);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.edgeIndicesBuf.bind();gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i299=0,len=scene._sectionPlanesState.sectionPlanes.length;_i299<len;_i299++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i299),pos:program.getLocation("sectionPlanePos"+_i299),dir:program.getLocation("sectionPlaneDir"+_i299)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var project=scene.camera.project;program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry edges drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.z = NOT_RENDERED | EDGES_COLOR_OPAQUE | EDGES_COLOR_TRANSPARENT | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
18852
18852
|
// renderPass = EDGES_COLOR_OPAQUE | EDGES_COLOR_TRANSPARENT
|
|
18853
18853
|
src.push("if (int(flags.z) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18854
18854
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("vColor = vec4(float(color.r-100.0) / 255.0, float(color.g-100.0) / 255.0, float(color.b-100.0) / 255.0, float(color.a) / 255.0);");
|
|
18855
|
-
src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i300=0,len=sectionPlanesState.sectionPlanes.length;_i300<len;_i300++){src.push("uniform bool sectionPlaneActive"+_i300+";");src.push("uniform vec3 sectionPlanePos"+_i300+";");src.push("uniform vec3 sectionPlaneDir"+_i300+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i301=0,_len58=sectionPlanesState.sectionPlanes.length;_i301<_len58;_i301++){src.push("if (sectionPlaneActive"+_i301+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i301+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i301+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingEdgesColorRenderer;}();var tempVec3a$
|
|
18855
|
+
src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i300=0,len=sectionPlanesState.sectionPlanes.length;_i300<len;_i300++){src.push("uniform bool sectionPlaneActive"+_i300+";");src.push("uniform vec3 sectionPlanePos"+_i300+";");src.push("uniform vec3 sectionPlaneDir"+_i300+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i301=0,_len58=sectionPlanesState.sectionPlanes.length;_i301<_len58;_i301++){src.push("if (sectionPlaneActive"+_i301+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i301+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i301+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingEdgesColorRenderer;}();var tempVec3a$Q=math.vec3();/**
|
|
18856
18856
|
* @private
|
|
18857
18857
|
*/var TrianglesBatchingPickMeshRenderer=/*#__PURE__*/function(){function TrianglesBatchingPickMeshRenderer(scene){_classCallCheck(this,TrianglesBatchingPickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
18858
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18858
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$Q);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aPickColor){this._aPickColor.bindArrayBuffer(state.pickColorsBuf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i302=0,len=scene._sectionPlanesState.sectionPlanes.length;_i302<len;_i302++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i302),pos:program.getLocation("sectionPlanePos"+_i302),dir:program.getLocation("sectionPlaneDir"+_i302)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aPickColor=program.getAttribute("pickColor");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;this._program.bind();gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
18859
18859
|
// renderPass = PICK
|
|
18860
18860
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18861
|
-
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickMeshRenderer;}();var tempVec3a$
|
|
18861
|
+
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickMeshRenderer;}();var tempVec3a$P=math.vec3();/**
|
|
18862
18862
|
* @private
|
|
18863
18863
|
*/var TrianglesBatchingPickDepthRenderer=/*#__PURE__*/function(){function TrianglesBatchingPickDepthRenderer(scene){_classCallCheck(this,TrianglesBatchingPickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
18864
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18864
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$P);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}//=============================================================
|
|
18865
18865
|
// TODO: Use drawElements count and offset to draw only one entity
|
|
18866
18866
|
//=============================================================
|
|
18867
18867
|
gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i303=0,len=scene._sectionPlanesState.sectionPlanes.length;_i303<len;_i303++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i303),pos:program.getLocation("sectionPlanePos"+_i303),dir:program.getLocation("sectionPlaneDir"+_i303)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
18868
18868
|
// renderPass = PICK
|
|
18869
18869
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18870
18870
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vViewPosition = viewPosition;");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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth 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 float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 packDepth(const in float depth) {");src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);");src.push(" vec4 res = fract(depth * bitShift);");src.push(" res -= res.xxyz * bitMask;");src.push(" return res;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth
|
|
18871
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickDepthRenderer;}();var tempVec3a$
|
|
18871
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickDepthRenderer;}();var tempVec3a$O=math.vec3();/**
|
|
18872
18872
|
* @private
|
|
18873
18873
|
*/var TrianglesBatchingPickNormalsRenderer=/*#__PURE__*/function(){function TrianglesBatchingPickNormalsRenderer(scene){_classCallCheck(this,TrianglesBatchingPickNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPickNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix?
|
|
18874
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18874
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$O);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}//=============================================================
|
|
18875
18875
|
// TODO: Use drawElements count and offset to draw only one entity
|
|
18876
18876
|
//=============================================================
|
|
18877
18877
|
gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i304=0,len=scene._sectionPlanesState.sectionPlanes.length;_i304<len;_i304++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i304),pos:program.getLocation("sectionPlanePos"+_i304),dir:program.getLocation("sectionPlaneDir"+_i304)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec3 normal;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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;");}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 vec4 vFlags2;");}src.push("out vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
18878
18878
|
// renderPass = PICK
|
|
18879
18879
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18880
|
-
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(" vec3 worldNormal = octDecode(normal.xy); ");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickNormalsRenderer;}();var tempVec3a$
|
|
18880
|
+
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(" vec3 worldNormal = octDecode(normal.xy); ");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickNormalsRenderer;}();var tempVec3a$N=math.vec3();/**
|
|
18881
18881
|
* @private
|
|
18882
|
-
*/var TrianglesBatchingOcclusionRenderer=/*#__PURE__*/function(){function TrianglesBatchingOcclusionRenderer(scene){_classCallCheck(this,TrianglesBatchingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=batchingLayer._state;var camera=scene.camera;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18882
|
+
*/var TrianglesBatchingOcclusionRenderer=/*#__PURE__*/function(){function TrianglesBatchingOcclusionRenderer(scene){_classCallCheck(this,TrianglesBatchingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=batchingLayer._state;var camera=scene.camera;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$N);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}this._aFlags.bindArrayBuffer(state.flagsBuf);if(this._aFlags2){// Won't be in shader when not clipping
|
|
18883
18883
|
this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i305=0,len=scene._sectionPlanesState.sectionPlanes.length;_i305<len;_i305++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i305),pos:program.getLocation("sectionPlanePos"+_i305),dir:program.getLocation("sectionPlaneDir"+_i305)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18884
18884
|
// renderPass = COLOR_OPAQUE
|
|
18885
18885
|
// Only opaque objects can be occluders
|
|
18886
18886
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18887
18887
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i306=0;_i306<sectionPlanesState.sectionPlanes.length;_i306++){src.push("uniform bool sectionPlaneActive"+_i306+";");src.push("uniform vec3 sectionPlanePos"+_i306+";");src.push("uniform vec3 sectionPlaneDir"+_i306+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i307=0;_i307<sectionPlanesState.sectionPlanes.length;_i307++){src.push(" if (sectionPlaneActive"+_i307+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i307+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i307+".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 = vec4(0.0, 0.0, 1.0, 1.0); ");// Occluders are blue
|
|
18888
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingOcclusionRenderer;}();var tempVec3a$
|
|
18888
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingOcclusionRenderer;}();var tempVec3a$M=math.vec3();/**
|
|
18889
18889
|
* @private
|
|
18890
|
-
*/var TrianglesBatchingDepthRenderer=/*#__PURE__*/function(){function TrianglesBatchingDepthRenderer(scene){_classCallCheck(this,TrianglesBatchingDepthRenderer);this._scene=scene;this._allocate();this._hash=this._getHash();}_createClass(TrianglesBatchingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18890
|
+
*/var TrianglesBatchingDepthRenderer=/*#__PURE__*/function(){function TrianglesBatchingDepthRenderer(scene){_classCallCheck(this,TrianglesBatchingDepthRenderer);this._scene=scene;this._allocate();this._hash=this._getHash();}_createClass(TrianglesBatchingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$M);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}this._aFlags.bindArrayBuffer(state.flagsBuf);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i308=0,len=scene._sectionPlanesState.sectionPlanes.length;_i308<len;_i308++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i308),pos:program.getLocation("sectionPlanePos"+_i308),dir:program.getLocation("sectionPlaneDir"+_i308)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec2 vHighPrecisionZW;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18891
18891
|
// renderPass = COLOR_OPAQUE
|
|
18892
18892
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18893
|
-
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("vHighPrecisionZW = gl_Position.zw;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching depth fragment shader");src.push("precision highp float;");src.push("precision highp int;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i309=0;_i309<sectionPlanesState.sectionPlanes.length;_i309++){src.push("uniform bool sectionPlaneActive"+_i309+";");src.push("uniform vec3 sectionPlanePos"+_i309+";");src.push("uniform vec3 sectionPlaneDir"+_i309+";");}}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("const float shiftRight8 = 1.0 / 256.;");src.push("vec4 packDepthToRGBA( const in float v ) {");src.push(" vec4 r = vec4( fract( v * packFactors ), v );");src.push(" r.yzw -= r.xyz * shiftRight8;");src.push(" return r * packUpScale;");src.push("}");src.push("in vec2 vHighPrecisionZW;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return TrianglesBatchingDepthRenderer;}();var tempVec3a$
|
|
18893
|
+
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("vHighPrecisionZW = gl_Position.zw;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching depth fragment shader");src.push("precision highp float;");src.push("precision highp int;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i309=0;_i309<sectionPlanesState.sectionPlanes.length;_i309++){src.push("uniform bool sectionPlaneActive"+_i309+";");src.push("uniform vec3 sectionPlanePos"+_i309+";");src.push("uniform vec3 sectionPlaneDir"+_i309+";");}}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("const float shiftRight8 = 1.0 / 256.;");src.push("vec4 packDepthToRGBA( const in float v ) {");src.push(" vec4 r = vec4( fract( v * packFactors ), v );");src.push(" r.yzw -= r.xyz * shiftRight8;");src.push(" return r * packUpScale;");src.push("}");src.push("in vec2 vHighPrecisionZW;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return TrianglesBatchingDepthRenderer;}();var tempVec3a$L=math.vec3();/**
|
|
18894
18894
|
* @private
|
|
18895
|
-
*/var TrianglesBatchingNormalsRenderer=/*#__PURE__*/function(){function TrianglesBatchingNormalsRenderer(scene){_classCallCheck(this,TrianglesBatchingNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(batchingLayer);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18895
|
+
*/var TrianglesBatchingNormalsRenderer=/*#__PURE__*/function(){function TrianglesBatchingNormalsRenderer(scene){_classCallCheck(this,TrianglesBatchingNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(batchingLayer);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$L);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);this._aOffset.bindArrayBuffer(state.offsetsBuf);this._aNormal.bindArrayBuffer(state.normalsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);// Needed for masking out transparent entities using alpha channel
|
|
18896
18896
|
this._aFlags.bindArrayBuffer(state.flagsBuf);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i310=0,len=scene._sectionPlanesState.sectionPlanes.length;_i310<len;_i310++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i310),pos:program.getLocation("sectionPlanePos"+_i310),dir:program.getLocation("sectionPlaneDir"+_i310)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");if(this._aFlags2){// Won't be in shader when not clipping
|
|
18897
18897
|
this._aFlags2=program.getAttribute("flags2");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");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;");}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 vec4 vFlags2;");}src.push("out vec3 vViewNormal;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18898
18898
|
// renderPass = COLOR_OPAQUE
|
|
18899
|
-
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewNormal = viewNormal;");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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i311=0;_i311<sectionPlanesState.sectionPlanes.length;_i311++){src.push("uniform bool sectionPlaneActive"+_i311+";");src.push("uniform vec3 sectionPlanePos"+_i311+";");src.push("uniform vec3 sectionPlaneDir"+_i311+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingNormalsRenderer;}();var tempVec3a$
|
|
18899
|
+
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewNormal = viewNormal;");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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i311=0;_i311<sectionPlanesState.sectionPlanes.length;_i311++){src.push("uniform bool sectionPlaneActive"+_i311+";");src.push("uniform vec3 sectionPlanePos"+_i311+";");src.push("uniform vec3 sectionPlaneDir"+_i311+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingNormalsRenderer;}();var tempVec3a$K=math.vec3();/**
|
|
18900
18900
|
* Renders BatchingLayer fragment depths to a shadow map.
|
|
18901
18901
|
*
|
|
18902
18902
|
* @private
|
|
18903
18903
|
*/var TrianglesBatchingShadowRenderer=/*#__PURE__*/function(){function TrianglesBatchingShadowRenderer(scene){_classCallCheck(this,TrianglesBatchingShadowRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingShadowRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer){var scene=this._scene;var gl=scene.canvas.gl;var state=batchingLayer._state;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);if(scene.logarithmicDepthBufferEnabled){gl.uniform1f(this._uZFar,scene.camera.project.far);}this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aColor){// Needed for masking out transparent entities using alpha channel
|
|
18904
18904
|
this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();// TODO: Section planes need to be set if RTC center has changed since last RTC center recorded on frameCtx
|
|
18905
|
-
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=batchingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18905
|
+
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=batchingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$K);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uShadowViewMatrix=program.getLocation("shadowViewMatrix");this._uShadowProjMatrix=program.getLocation("shadowProjMatrix");if(scene.logarithmicDepthBufferEnabled){this._uZFar=program.getLocation("zFar");}this._uSectionPlanes=[];var sectionPlanes=sectionPlanesState.sectionPlanes;for(var _i312=0,len=sectionPlanes.length;_i312<len;_i312++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i312),pos:program.getLocation("sectionPlanePos"+_i312),dir:program.getLocation("sectionPlaneDir"+_i312)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniformMatrix4fv(this._uShadowViewMatrix,false,frameCtx.shadowViewMatrix);gl.uniformMatrix4fv(this._uShadowProjMatrix,false,frameCtx.shadowProjMatrix);this._lastLightId=null;}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry shadow vertex shader");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("out vec4 outColor;");src.push("void main(void) {");src.push(" bool visible = (float(flags.x) > 0.0);");src.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);");src.push(" if (!visible || transparent) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");src.push(" } else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewPosition = viewPosition;");src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i313=0;_i313<sectionPlanesState.sectionPlanes.length;_i313++){src.push("uniform bool sectionPlaneActive"+_i313+";");src.push("uniform vec3 sectionPlanePos"+_i313+";");src.push("uniform vec3 sectionPlaneDir"+_i313+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 encodeFloat( const in float v ) {");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(v * 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(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}src.push(" outColor = encodeFloat( gl_FragCoord.z); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingShadowRenderer;}();var tempVec4$5=math.vec4();var tempVec3a$J=math.vec3();// const TEXTURE_DECODE_FUNCS = {};
|
|
18906
18906
|
// TEXTURE_DECODE_FUNCS[LinearEncoding] = "linearToLinear";
|
|
18907
18907
|
// TEXTURE_DECODE_FUNCS[sRGBEncoding] = "sRGBToLinear";
|
|
18908
18908
|
/**
|
|
18909
18909
|
* @private
|
|
18910
|
-
*/var TrianglesBatchingPBRRenderer=/*#__PURE__*/function(){function TrianglesBatchingPBRRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingPBRRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPBRRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;var textureSet=state.textureSet;var lightsState=scene._lightsState;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aUV){this._aUV.bindArrayBuffer(state.uvBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aMetallicRoughness){this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$5[0]=viewportWidth;tempVec4$5[1]=viewportHeight;tempVec4$5[2]=sao.blendCutoff;tempVec4$5[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$5);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}this._program.bindTexture(this._uBaseColorMap,textureSet.colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uMetallicRoughMap,textureSet.metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uEmissiveMap,textureSet.emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uNormalMap,textureSet.normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uAOMap,textureSet.occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i314=0,len=lights.length;_i314<len;_i314++){light=lights[_i314];switch(light.type){case"dir":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=null;this._uLightDir[_i314]=program.getLocation("lightDir"+_i314);break;case"point":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=program.getLocation("lightPos"+_i314);this._uLightDir[_i314]=null;this._uLightAttenuation[_i314]=program.getLocation("lightAttenuation"+_i314);break;case"spot":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=program.getLocation("lightPos"+_i314);this._uLightDir[_i314]=program.getLocation("lightDir"+_i314);this._uLightAttenuation[_i314]=program.getLocation("lightAttenuation"+_i314);break;}}if(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i315=0,_len59=scene._sectionPlanesState.sectionPlanes.length;_i315<_len59;_i315++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i315),pos:program.getLocation("sectionPlanePos"+_i315),dir:program.getLocation("sectionPlaneDir"+_i315)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uBaseColorMap="uBaseColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i316=0,len=lights.length;_i316<len;_i316++){var light=lights[_i316];if(this._uLightColor[_i316]){gl.uniform4f(this._uLightColor[_i316],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i316]){gl.uniform3fv(this._uLightPos[_i316],light.pos);if(this._uLightAttenuation[_i316]){gl.uniform1f(this._uLightAttenuation[_i316],light.attenuation);}}if(this._uLightDir[_i316]){gl.uniform3fv(this._uLightDir[_i316],light.dir);}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var clippingCaps=sectionPlanesState.clippingCaps;var src=[];src.push("#version 300 es");src.push("// Triangles batching quality draw vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in vec2 metallicRoughness;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform mat3 uvDecodeMatrix;");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("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("}");src.push("out vec4 vViewPosition;");src.push("out vec3 vViewNormal;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("out vec2 vMetallicRoughness;");if(lightsState.lightMaps.length>0){src.push("out vec3 vWorldNormal;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");if(clippingCaps){src.push("out vec4 vClipPosition;");}}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18910
|
+
*/var TrianglesBatchingPBRRenderer=/*#__PURE__*/function(){function TrianglesBatchingPBRRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingPBRRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPBRRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;var textureSet=state.textureSet;var lightsState=scene._lightsState;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aNormal){this._aNormal.bindArrayBuffer(state.normalsBuf);}if(this._aUV){this._aUV.bindArrayBuffer(state.uvBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aMetallicRoughness){this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$5[0]=viewportWidth;tempVec4$5[1]=viewportHeight;tempVec4$5[2]=sao.blendCutoff;tempVec4$5[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$5);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}this._program.bindTexture(this._uBaseColorMap,textureSet.colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uMetallicRoughMap,textureSet.metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uEmissiveMap,textureSet.emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uNormalMap,textureSet.normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uAOMap,textureSet.occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i314=0,len=lights.length;_i314<len;_i314++){light=lights[_i314];switch(light.type){case"dir":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=null;this._uLightDir[_i314]=program.getLocation("lightDir"+_i314);break;case"point":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=program.getLocation("lightPos"+_i314);this._uLightDir[_i314]=null;this._uLightAttenuation[_i314]=program.getLocation("lightAttenuation"+_i314);break;case"spot":this._uLightColor[_i314]=program.getLocation("lightColor"+_i314);this._uLightPos[_i314]=program.getLocation("lightPos"+_i314);this._uLightDir[_i314]=program.getLocation("lightDir"+_i314);this._uLightAttenuation[_i314]=program.getLocation("lightAttenuation"+_i314);break;}}if(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i315=0,_len59=scene._sectionPlanesState.sectionPlanes.length;_i315<_len59;_i315++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i315),pos:program.getLocation("sectionPlanePos"+_i315),dir:program.getLocation("sectionPlaneDir"+_i315)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uBaseColorMap="uBaseColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i316=0,len=lights.length;_i316<len;_i316++){var light=lights[_i316];if(this._uLightColor[_i316]){gl.uniform4f(this._uLightColor[_i316],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i316]){gl.uniform3fv(this._uLightPos[_i316],light.pos);if(this._uLightAttenuation[_i316]){gl.uniform1f(this._uLightAttenuation[_i316],light.attenuation);}}if(this._uLightDir[_i316]){gl.uniform3fv(this._uLightDir[_i316],light.dir);}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var clippingCaps=sectionPlanesState.clippingCaps;var src=[];src.push("#version 300 es");src.push("// Triangles batching quality draw vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in vec2 metallicRoughness;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform mat3 uvDecodeMatrix;");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("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("}");src.push("out vec4 vViewPosition;");src.push("out vec3 vViewNormal;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("out vec2 vMetallicRoughness;");if(lightsState.lightMaps.length>0){src.push("out vec3 vWorldNormal;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");if(clippingCaps){src.push("out vec4 vClipPosition;");}}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18911
18911
|
// renderPass = COLOR_OPAQUE
|
|
18912
18912
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18913
18913
|
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("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");src.push("vFragDepth = 1.0 + clipPos.w;");}if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");if(clippingCaps){src.push("vClipPosition = clipPos;");}}src.push("vViewPosition = viewPosition;");src.push("vViewNormal = viewNormal;");src.push("vColor = color;");src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");src.push("vMetallicRoughness = metallicRoughness;");if(lightsState.lightMaps.length>0){src.push("vWorldNormal = worldNormal.xyz;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var gammaOutput=scene.gammaOutput;// If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
|
|
@@ -18925,18 +18925,18 @@ src.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;");src.push
|
|
|
18925
18925
|
src.push("computePBRLighting(light, geometry, material, reflectedLight);");}src.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;");// TODO: correct gamma function
|
|
18926
18926
|
src.push("float aoFactor = texture(uAOMap, vUV).r;");src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;");src.push("vec4 fragColor;");if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
18927
18927
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
18928
|
-
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(" fragColor = vec4(outgoingLight.rgb * ambient * aoFactor, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb * aoFactor, opacity);");}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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPBRRenderer;}();var tempVec3a$
|
|
18928
|
+
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(" fragColor = vec4(outgoingLight.rgb * ambient * aoFactor, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb * aoFactor, opacity);");}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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPBRRenderer;}();var tempVec3a$I=math.vec3();/**
|
|
18929
18929
|
* @private
|
|
18930
18930
|
*/var TrianglesBatchingPickNormalsFlatRenderer=/*#__PURE__*/function(){function TrianglesBatchingPickNormalsFlatRenderer(scene){_classCallCheck(this,TrianglesBatchingPickNormalsFlatRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingPickNormalsFlatRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;if(!this._program){this._allocate(batchingLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix?
|
|
18931
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18931
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}//=============================================================
|
|
18932
18932
|
// TODO: Use drawElements count and offset to draw only one entity
|
|
18933
18933
|
//=============================================================
|
|
18934
18934
|
gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i321=0,len=scene._sectionPlanesState.sectionPlanes.length;_i321<len;_i321++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i321),pos:program.getLocation("sectionPlanePos"+_i321),dir:program.getLocation("sectionPlaneDir"+_i321)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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;");}src.push("out vec4 vWorldPosition;");if(clipping){src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
18935
18935
|
// renderPass = PICK
|
|
18936
18936
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18937
|
-
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(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals 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("in vec4 vWorldPosition;");if(clipping){src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;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(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickNormalsFlatRenderer;}();var tempVec4$4=math.vec4();var tempVec3a$
|
|
18937
|
+
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(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags2 = flags2;");}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(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals 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("in vec4 vWorldPosition;");if(clipping){src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;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(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesBatchingPickNormalsFlatRenderer;}();var tempVec4$4=math.vec4();var tempVec3a$H=math.vec3();/**
|
|
18938
18938
|
* @private
|
|
18939
|
-
*/var TrianglesBatchingColorTextureRenderer=/*#__PURE__*/function(){function TrianglesBatchingColorTextureRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingColorTextureRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingColorTextureRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;var textureSet=state.textureSet;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
18939
|
+
*/var TrianglesBatchingColorTextureRenderer=/*#__PURE__*/function(){function TrianglesBatchingColorTextureRenderer(scene,withSAO){_classCallCheck(this,TrianglesBatchingColorTextureRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesBatchingColorTextureRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;var textureSet=state.textureSet;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aUV){this._aUV.bindArrayBuffer(state.uvBuf);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(textureSet){if(textureSet.colorTexture){this._program.bindTexture(this._uColorMap,textureSet.colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$4[0]=viewportWidth;tempVec4$4[1]=viewportHeight;tempVec4$4[2]=sao.blendCutoff;tempVec4$4[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$4);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}state.indicesBuf.bind();gl.drawElements(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i322=0,len=lights.length;_i322<len;_i322++){light=lights[_i322];switch(light.type){case"dir":this._uLightColor[_i322]=program.getLocation("lightColor"+_i322);this._uLightPos[_i322]=null;this._uLightDir[_i322]=program.getLocation("lightDir"+_i322);break;case"point":this._uLightColor[_i322]=program.getLocation("lightColor"+_i322);this._uLightPos[_i322]=program.getLocation("lightPos"+_i322);this._uLightDir[_i322]=null;this._uLightAttenuation[_i322]=program.getLocation("lightAttenuation"+_i322);break;case"spot":this._uLightColor[_i322]=program.getLocation("lightColor"+_i322);this._uLightPos[_i322]=program.getLocation("lightPos"+_i322);this._uLightDir[_i322]=program.getLocation("lightDir"+_i322);this._uLightAttenuation[_i322]=program.getLocation("lightAttenuation"+_i322);break;}}this._uSectionPlanes=[];for(var _i323=0,_len63=scene._sectionPlanesState.sectionPlanes.length;_i323<_len63;_i323++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i323),pos:program.getLocation("sectionPlanePos"+_i323),dir:program.getLocation("sectionPlaneDir"+_i323)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uColorMap="uColorMap";if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i324=0,len=lights.length;_i324<len;_i324++){var light=lights[_i324];if(this._uLightColor[_i324]){gl.uniform4f(this._uLightColor[_i324],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i324]){gl.uniform3fv(this._uLightPos[_i324],light.pos);if(this._uLightAttenuation[_i324]){gl.uniform1f(this._uLightAttenuation[_i324],light.attenuation);}}if(this._uLightDir[_i324]){gl.uniform3fv(this._uLightDir[_i324],light.dir);}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching color texture vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform mat3 uvDecodeMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
18940
18940
|
// renderPass = COLOR_OPAQUE
|
|
18941
18941
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
18942
18942
|
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("vViewPosition = viewPosition;");src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");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("vFlags2 = flags2;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var gammaOutput=scene.gammaOutput;// If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
|
|
@@ -18973,7 +18973,7 @@ var x=array[i]/(Math.abs(array[i])+Math.abs(array[i+1])+Math.abs(array[i+2]));va
|
|
|
18973
18973
|
*/function octDecodeVec2(oct){// Decode an oct-encoded normal
|
|
18974
18974
|
var x=oct[0];var y=oct[1];x/=x<0?127:128;y/=y<0?127:128;var z=1-Math.abs(x)-Math.abs(y);if(z<0){x=(1-Math.abs(y))*(x>=0?1:-1);y=(1-Math.abs(x))*(y>=0?1:-1);}var length=Math.sqrt(x*x+y*y+z*z);return[x/length,y/length,z/length];}/**
|
|
18975
18975
|
* @private
|
|
18976
|
-
*/function dot(array,i,vec3){return array[i]*vec3[0]+array[i+1]*vec3[1]+array[i+2]*vec3[2];}var tempMat4$2=math.mat4();var tempMat4b=math.mat4();var tempVec4a$a=math.vec4([0,0,0,1]);var tempVec4b$a=math.vec4([0,0,0,1]);var tempVec4c$7=math.vec4([0,0,0,1]);var tempOBB3$2=math.OBB3();var tempVec3a$
|
|
18976
|
+
*/function dot(array,i,vec3){return array[i]*vec3[0]+array[i+1]*vec3[1]+array[i+2]*vec3[2];}var tempMat4$2=math.mat4();var tempMat4b=math.mat4();var tempVec4a$a=math.vec4([0,0,0,1]);var tempVec4b$a=math.vec4([0,0,0,1]);var tempVec4c$7=math.vec4([0,0,0,1]);var tempOBB3$2=math.OBB3();var tempVec3a$G=math.vec3();var tempVec3b$7=math.vec3();var tempVec3c$5=math.vec3();var tempVec3d$2=math.vec3();var tempVec3e$1=math.vec3();var tempVec3f$1=math.vec3();var tempVec3g$1=math.vec3();/**
|
|
18977
18977
|
* @private
|
|
18978
18978
|
*/var TrianglesBatchingLayer=/*#__PURE__*/function(){/**
|
|
18979
18979
|
* @param model
|
|
@@ -19073,108 +19073,108 @@ return;}var portionsIdx=portionId;var portion=this._portions[portionsIdx];var ve
|
|
|
19073
19073
|
// } else {
|
|
19074
19074
|
if(this._batchingRenderers.pickNormalsFlatRenderer){this._batchingRenderers.pickNormalsFlatRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}// }
|
|
19075
19075
|
}//------------------------------------------------------------------------------------------------
|
|
19076
|
-
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}var positions=portion.quantizedPositions;var indices=portion.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$
|
|
19076
|
+
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}var positions=portion.quantizedPositions;var indices=portion.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$G;var rtcRayDir=tempVec3b$7;rtcRayOrigin.set(origin?math.subVec3(worldRayOrigin,origin,tempVec3c$5):worldRayOrigin);// World -> RTC
|
|
19077
19077
|
rtcRayDir.set(worldRayDir);if(offset){math.subVec3(rtcRayOrigin,offset);}math.transformRay(this.model.worldNormalMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);// RTC -> local
|
|
19078
19078
|
var a=tempVec3d$2;var b=tempVec3e$1;var c=tempVec3f$1;var gotIntersect=false;var closestDist=0;var closestIntersectPos=tempVec3g$1;for(var _i353=0,len=indices.length;_i353<len;_i353+=3){var ia=indices[_i353]*3;var ib=indices[_i353+1]*3;var ic=indices[_i353+2]*3;a[0]=positions[ia];a[1]=positions[ia+1];a[2]=positions[ia+2];b[0]=positions[ib];b[1]=positions[ib+1];b[2]=positions[ib+2];c[0]=positions[ic];c[1]=positions[ic+1];c[2]=positions[ic+2];math.decompressPosition(a,state.positionsDecodeMatrix);math.decompressPosition(b,state.positionsDecodeMatrix);math.decompressPosition(c,state.positionsDecodeMatrix);if(math.rayTriangleIntersect(rtcRayOrigin,rtcRayDir,a,b,c,closestIntersectPos)){math.transformPoint3(this.model.worldMatrix,closestIntersectPos,closestIntersectPos);if(offset){math.addVec3(closestIntersectPos,offset);}if(origin){math.addVec3(closestIntersectPos,origin);}var dist=Math.abs(math.lenVec3(math.subVec3(closestIntersectPos,worldRayOrigin,[])));if(!gotIntersect||dist>closestDist){closestDist=dist;worldSurfacePos.set(closestIntersectPos);if(worldNormal){// Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
|
|
19079
19079
|
math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}// ---------
|
|
19080
|
-
},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.normalsBuf){state.normalsBuf.destroy();state.normalsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.metallicRoughnessBuf){state.metallicRoughnessBuf.destroy();state.metallicRoughnessBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}if(state.indicesBuf){state.indicesBuf.destroy();state.indicessBuf=null;}if(state.edgeIndicesBuf){state.edgeIndicesBuf.destroy();state.edgeIndicessBuf=null;}state.destroy();}}]);return TrianglesBatchingLayer;}();var tempVec4$3=math.vec4();var tempVec3a$
|
|
19080
|
+
},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.normalsBuf){state.normalsBuf.destroy();state.normalsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.metallicRoughnessBuf){state.metallicRoughnessBuf.destroy();state.metallicRoughnessBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}if(state.indicesBuf){state.indicesBuf.destroy();state.indicessBuf=null;}if(state.edgeIndicesBuf){state.edgeIndicesBuf.destroy();state.edgeIndicessBuf=null;}state.destroy();}}]);return TrianglesBatchingLayer;}();var tempVec4$3=math.vec4();var tempVec3a$F=math.vec3();/**
|
|
19081
19081
|
* @private
|
|
19082
|
-
*/var TrianglesInstancingColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19082
|
+
*/var TrianglesInstancingColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aModelNormalMatrixCol0.bindArrayBuffer(state.modelNormalMatrixCol0Buf);this._aModelNormalMatrixCol1.bindArrayBuffer(state.modelNormalMatrixCol1Buf);this._aModelNormalMatrixCol2.bindArrayBuffer(state.modelNormalMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aNormal.bindArrayBuffer(geometry.normalsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);frameCtx.drawElements++;gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19083
19083
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i354=0,len=lights.length;_i354<len;_i354++){light=lights[_i354];switch(light.type){case"dir":this._uLightColor[_i354]=program.getLocation("lightColor"+_i354);this._uLightPos[_i354]=null;this._uLightDir[_i354]=program.getLocation("lightDir"+_i354);break;case"point":this._uLightColor[_i354]=program.getLocation("lightColor"+_i354);this._uLightPos[_i354]=program.getLocation("lightPos"+_i354);this._uLightDir[_i354]=null;this._uLightAttenuation[_i354]=program.getLocation("lightAttenuation"+_i354);break;case"spot":this._uLightColor[_i354]=program.getLocation("lightColor"+_i354);this._uLightPos[_i354]=program.getLocation("lightPos"+_i354);this._uLightDir[_i354]=program.getLocation("lightDir"+_i354);this._uLightAttenuation[_i354]=program.getLocation("lightAttenuation"+_i354);break;}}this._uSectionPlanes=[];for(var _i355=0,_len78=scene._sectionPlanesState.sectionPlanes.length;_i355<_len78;_i355++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i355),pos:program.getLocation("sectionPlanePos"+_i355),dir:program.getLocation("sectionPlaneDir"+_i355)});}this._aPosition=program.getAttribute("position");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;this._program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i356=0,len=lights.length;_i356<len;_i356++){var light=lights[_i356];if(this._uLightColor[_i356]){gl.uniform4f(this._uLightColor[_i356],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i356]){gl.uniform3fv(this._uLightPos[_i356],light.pos);if(this._uLightAttenuation[_i356]){gl.uniform1f(this._uLightAttenuation[_i356],light.attenuation);}}if(this._uLightDir[_i356]){gl.uniform3fv(this._uLightDir[_i356],light.dir);}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$3[0]=viewportWidth;tempVec4$3[1]=viewportHeight;tempVec4$3[2]=sao.blendCutoff;tempVec4$3[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$3);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,0);}}if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var i;var len;var light;var src=[];src.push("#version 300 es");src.push("// Instancing geometry drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec2 normal;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19084
19084
|
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;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 projMatrix;");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;");}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 vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19085
19085
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19086
19086
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19087
19087
|
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("vFlags2 = flags2;");}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.sectionPlanes.length>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 vec4 vFlags2;");for(var _i357=0,len=sectionPlanesState.sectionPlanes.length;_i357<len;_i357++){src.push("uniform bool sectionPlaneActive"+_i357+";");src.push("uniform vec3 sectionPlanePos"+_i357+";");src.push("uniform vec3 sectionPlaneDir"+_i357+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i358=0,_len79=sectionPlanesState.sectionPlanes.length;_i358<_len79;_i358++){src.push("if (sectionPlaneActive"+_i358+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i358+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i358+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");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
|
|
19088
19088
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
19089
|
-
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingColorRenderer;}();var tempVec4$2=math.vec4();var tempVec3a$
|
|
19089
|
+
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(vColor.rgb * ambient, 1.0);");}else{src.push(" outColor = vColor;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingColorRenderer;}();var tempVec4$2=math.vec4();var tempVec3a$E=math.vec3();/**
|
|
19090
19090
|
* @private
|
|
19091
|
-
*/var TrianglesInstancingFlatColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingFlatColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingFlatColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingFlatColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19091
|
+
*/var TrianglesInstancingFlatColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingFlatColorRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingFlatColorRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingFlatColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{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,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19092
19092
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i359=0,len=lights.length;_i359<len;_i359++){light=lights[_i359];switch(light.type){case"dir":this._uLightColor[_i359]=program.getLocation("lightColor"+_i359);this._uLightPos[_i359]=null;this._uLightDir[_i359]=program.getLocation("lightDir"+_i359);break;case"point":this._uLightColor[_i359]=program.getLocation("lightColor"+_i359);this._uLightPos[_i359]=program.getLocation("lightPos"+_i359);this._uLightDir[_i359]=null;this._uLightAttenuation[_i359]=program.getLocation("lightAttenuation"+_i359);break;case"spot":this._uLightColor[_i359]=program.getLocation("lightColor"+_i359);this._uLightPos[_i359]=program.getLocation("lightPos"+_i359);this._uLightDir[_i359]=program.getLocation("lightDir"+_i359);this._uLightAttenuation[_i359]=program.getLocation("lightAttenuation"+_i359);break;}}this._uSectionPlanes=[];for(var _i360=0,_len80=scene._sectionPlanesState.sectionPlanes.length;_i360<_len80;_i360++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i360),pos:program.getLocation("sectionPlanePos"+_i360),dir:program.getLocation("sectionPlaneDir"+_i360)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;this._program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i361=0,len=lights.length;_i361<len;_i361++){var light=lights[_i361];if(this._uLightColor[_i361]){gl.uniform4f(this._uLightColor[_i361],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i361]){gl.uniform3fv(this._uLightPos[_i361],light.pos);if(this._uLightAttenuation[_i361]){gl.uniform1f(this._uLightAttenuation[_i361],light.attenuation);}}if(this._uLightDir[_i361]){gl.uniform3fv(this._uLightDir[_i361],light.dir);}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$2[0]=viewportWidth;tempVec4$2[1]=viewportHeight;tempVec4$2[2]=sao.blendCutoff;tempVec4$2[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$2);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,0);}}if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry flat-shading drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19093
19093
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19094
19094
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19095
19095
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19096
19096
|
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("vViewPosition = viewPosition;");src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 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("vFlags2 = flags2;");}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 lightsState=scene._lightsState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry flat-shading 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 vec4 vFlags2;");for(var _i362=0,_len81=sectionPlanesState.sectionPlanes.length;_i362<_len81;_i362++){src.push("uniform bool sectionPlaneActive"+_i362+";");src.push("uniform vec3 sectionPlanePos"+_i362+";");src.push("uniform vec3 sectionPlaneDir"+_i362+";");}}src.push("uniform mat4 viewMatrix;");src.push("uniform vec4 lightAmbient;");for(i=0,len=lightsState.lights.length;i<len;i++){var 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("in vec4 vViewPosition;");src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i363=0,_len82=sectionPlanesState.sectionPlanes.length;_i363<_len82;_i363++){src.push("if (sectionPlaneActive"+_i363+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i363+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i363+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { ");src.push(" discard;");src.push(" }");src.push("}");}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;");src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(i=0,len=lightsState.lights.length;i<len;i++){var _light8=lightsState.lights[i];if(_light8.type==="ambient"){continue;}if(_light8.type==="dir"){if(_light8.space==="view"){src.push("viewLightDir = normalize(lightDir"+i+");");}else{src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+i+", 0.0)).xyz);");}}else if(_light8.type==="point"){if(_light8.space==="view"){src.push("viewLightDir = -normalize(lightPos"+i+" - viewPosition.xyz);");}else{src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+i+", 0.0)).xyz);");}}else if(_light8.type==="spot"){if(_light8.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("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
19097
19097
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
19098
|
-
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(fragColor.rgb * ambient, 1.0);");}else{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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingFlatColorRenderer;}();var tempVec3a$
|
|
19098
|
+
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(fragColor.rgb * ambient, 1.0);");}else{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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingFlatColorRenderer;}();var tempVec3a$D=math.vec3();/**
|
|
19099
19099
|
* @private
|
|
19100
|
-
*/var TrianglesInstancingSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesInstancingSilhouetteRenderer(scene){_classCallCheck(this,TrianglesInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uSilhouetteColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material9=scene.highlightMaterial._state;var _fillColor5=_material9.fillColor;var _fillAlpha5=_material9.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor5[0],_fillColor5[1],_fillColor5[2],_fillAlpha5);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material10=scene.selectedMaterial._state;var _fillColor6=_material10.fillColor;var _fillAlpha6=_material10.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor6[0],_fillColor6[1],_fillColor6[2],_fillAlpha6);}else{gl.uniform4fv(this._uSilhouetteColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19100
|
+
*/var TrianglesInstancingSilhouetteRenderer=/*#__PURE__*/function(){function TrianglesInstancingSilhouetteRenderer(scene){_classCallCheck(this,TrianglesInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uSilhouetteColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material9=scene.highlightMaterial._state;var _fillColor5=_material9.fillColor;var _fillAlpha5=_material9.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor5[0],_fillColor5[1],_fillColor5[2],_fillAlpha5);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material10=scene.selectedMaterial._state;var _fillColor6=_material10.fillColor;var _fillAlpha6=_material10.fillAlpha;gl.uniform4f(this._uSilhouetteColor,_fillColor6[0],_fillColor6[1],_fillColor6[2],_fillAlpha6);}else{gl.uniform4fv(this._uSilhouetteColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$D);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);// TODO: Is this needed
|
|
19101
19101
|
gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}if(this._aColor){gl.vertexAttribDivisor(this._aColor.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSilhouetteColor=program.getLocation("silhouetteColor");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i364=0,len=clips.length;_i364<len;_i364++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i364),pos:program.getLocation("sectionPlanePos"+_i364),dir:program.getLocation("sectionPlaneDir"+_i364)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aColor=program.getAttribute("color");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 color;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19102
19102
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform vec4 silhouetteColor;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19103
19103
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19104
19104
|
src.push("if (int(flags.y) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19105
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, 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));");}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.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing fill 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i365=0,len=sectionPlanesState.sectionPlanes.length;_i365<len;_i365++){src.push("uniform bool sectionPlaneActive"+_i365+";");src.push("uniform vec3 sectionPlanePos"+_i365+";");src.push("uniform vec3 sectionPlaneDir"+_i365+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i366=0,_len83=sectionPlanesState.sectionPlanes.length;_i366<_len83;_i366++){src.push("if (sectionPlaneActive"+_i366+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i366+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i366+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingSilhouetteRenderer;}();var tempVec3a$
|
|
19105
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, 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));");}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.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing fill 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i365=0,len=sectionPlanesState.sectionPlanes.length;_i365<len;_i365++){src.push("uniform bool sectionPlaneActive"+_i365+";");src.push("uniform vec3 sectionPlanePos"+_i365+";");src.push("uniform vec3 sectionPlaneDir"+_i365+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i366=0,_len83=sectionPlanesState.sectionPlanes.length;_i366<_len83;_i366++){src.push("if (sectionPlaneActive"+_i366+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i366+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i366+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingSilhouetteRenderer;}();var tempVec3a$C=math.vec3();var defaultColor$2=new Float32Array([0,0,0,1]);/**
|
|
19106
19106
|
* @private
|
|
19107
|
-
*/var TrianglesInstancingEdgesRenderer=/*#__PURE__*/function(){function TrianglesInstancingEdgesRenderer(scene){_classCallCheck(this,TrianglesInstancingEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES.EDGES_HIGHLIGHTED){var _material11=scene.highlightMaterial._state;var _edgeColor5=_material11.edgeColor;var _edgeAlpha5=_material11.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor5[0],_edgeColor5[1],_edgeColor5[2],_edgeAlpha5);}else if(renderPass===RENDER_PASSES.EDGES_SELECTED){var _material12=scene.selectedMaterial._state;var _edgeColor6=_material12.edgeColor;var _edgeAlpha6=_material12.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor6[0],_edgeColor6[1],_edgeColor6[2],_edgeAlpha6);}else{gl.uniform4fv(this._uColor,defaultColor$2);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19107
|
+
*/var TrianglesInstancingEdgesRenderer=/*#__PURE__*/function(){function TrianglesInstancingEdgesRenderer(scene){_classCallCheck(this,TrianglesInstancingEdgesRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingEdgesRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.EDGES_XRAYED){var material=scene.xrayMaterial._state;var edgeColor=material.edgeColor;var edgeAlpha=material.edgeAlpha;gl.uniform4f(this._uColor,edgeColor[0],edgeColor[1],edgeColor[2],edgeAlpha);}else if(renderPass===RENDER_PASSES.EDGES_HIGHLIGHTED){var _material11=scene.highlightMaterial._state;var _edgeColor5=_material11.edgeColor;var _edgeAlpha5=_material11.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor5[0],_edgeColor5[1],_edgeColor5[2],_edgeAlpha5);}else if(renderPass===RENDER_PASSES.EDGES_SELECTED){var _material12=scene.selectedMaterial._state;var _edgeColor6=_material12.edgeColor;var _edgeAlpha6=_material12.edgeAlpha;gl.uniform4f(this._uColor,_edgeColor6[0],_edgeColor6[1],_edgeColor6[2],_edgeAlpha6);}else{gl.uniform4fv(this._uColor,defaultColor$2);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$C);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags.location,1);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.edgeIndicesBuf.bind();gl.drawElementsInstanced(gl.LINES,geometry.edgeIndicesBuf.numItems,geometry.edgeIndicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);// TODO: Is this needed
|
|
19108
19108
|
gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}if(this._aFlags){gl.vertexAttribDivisor(this._aFlags.location,0);}if(this._aFlags2){gl.vertexAttribDivisor(this._aFlags2.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uColor=program.getLocation("color");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i367=0,len=clips.length;_i367<len;_i367++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i367),pos:program.getLocation("sectionPlanePos"+_i367),dir:program.getLocation("sectionPlaneDir"+_i367)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles instancing edges vertex shader");src.push("uniform int renderPass;");src.push("uniform vec4 color;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19109
19109
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.z = NOT_RENDERED | EDGES_COLOR_OPAQUE | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
19110
19110
|
// renderPass = EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
19111
19111
|
src.push("if (int(flags.z) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19112
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i368=0,len=sectionPlanesState.sectionPlanes.length;_i368<len;_i368++){src.push("uniform bool sectionPlaneActive"+_i368+";");src.push("uniform vec3 sectionPlanePos"+_i368+";");src.push("uniform vec3 sectionPlaneDir"+_i368+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i369=0,_len84=sectionPlanesState.sectionPlanes.length;_i369<_len84;_i369++){src.push("if (sectionPlaneActive"+_i369+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i369+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i369+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingEdgesRenderer;}();var tempVec3a$
|
|
19112
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}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("vColor = vec4(color.r, color.g, color.b, color.a);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i368=0,len=sectionPlanesState.sectionPlanes.length;_i368<len;_i368++){src.push("uniform bool sectionPlaneActive"+_i368+";");src.push("uniform vec3 sectionPlanePos"+_i368+";");src.push("uniform vec3 sectionPlaneDir"+_i368+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i369=0,_len84=sectionPlanesState.sectionPlanes.length;_i369<_len84;_i369++){src.push("if (sectionPlaneActive"+_i369+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i369+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i369+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingEdgesRenderer;}();var tempVec3a$B=math.vec3();/**
|
|
19113
19113
|
* @private
|
|
19114
|
-
*/var TrianglesInstancingEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingEdgesColorRenderer(scene){_classCallCheck(this,TrianglesInstancingEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19114
|
+
*/var TrianglesInstancingEdgesColorRenderer=/*#__PURE__*/function(){function TrianglesInstancingEdgesColorRenderer(scene){_classCallCheck(this,TrianglesInstancingEdgesColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingEdgesColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$B);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags.location,1);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.edgeIndicesBuf.bind();gl.drawElementsInstanced(gl.LINES,geometry.edgeIndicesBuf.numItems,geometry.edgeIndicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);// TODO: Is this needed
|
|
19115
19115
|
gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}if(this._aFlags){gl.vertexAttribDivisor(this._aFlags.location,0);}if(this._aFlags2){gl.vertexAttribDivisor(this._aFlags2.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i370=0,len=clips.length;_i370<len;_i370++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i370),pos:program.getLocation("sectionPlanePos"+_i370),dir:program.getLocation("sectionPlaneDir"+_i370)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles instancing edges vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19116
19116
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.z = NOT_RENDERED | EDGES_COLOR_OPAQUE | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
19117
19117
|
// renderPass = EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED
|
|
19118
19118
|
src.push("if (int(flags.z) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19119
19119
|
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}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("vColor = vec4(float(color.r-100.0) / 255.0, float(color.g-100.0) / 255.0, float(color.b-100.0) / 255.0, float(color.a) / 255.0);");
|
|
19120
|
-
src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i371=0,len=sectionPlanesState.sectionPlanes.length;_i371<len;_i371++){src.push("uniform bool sectionPlaneActive"+_i371+";");src.push("uniform vec3 sectionPlanePos"+_i371+";");src.push("uniform vec3 sectionPlaneDir"+_i371+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i372=0,_len85=sectionPlanesState.sectionPlanes.length;_i372<_len85;_i372++){src.push("if (sectionPlaneActive"+_i372+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i372+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i372+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingEdgesColorRenderer;}();var tempVec3a$
|
|
19120
|
+
src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i371=0,len=sectionPlanesState.sectionPlanes.length;_i371<len;_i371++){src.push("uniform bool sectionPlaneActive"+_i371+";");src.push("uniform vec3 sectionPlanePos"+_i371+";");src.push("uniform vec3 sectionPlaneDir"+_i371+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i372=0,_len85=sectionPlanesState.sectionPlanes.length;_i372<_len85;_i372++){src.push("if (sectionPlaneActive"+_i372+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i372+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i372+".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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingEdgesColorRenderer;}();var tempVec3a$A=math.vec3();/**
|
|
19121
19121
|
* @private
|
|
19122
19122
|
*/var TrianglesInstancingPickMeshRenderer=/*#__PURE__*/function(){function TrianglesInstancingPickMeshRenderer(scene){_classCallCheck(this,TrianglesInstancingPickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19123
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPickColor.bindArrayBuffer(state.pickColorsBuf);gl.vertexAttribDivisor(this._aPickColor.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19123
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPickColor.bindArrayBuffer(state.pickColorsBuf);gl.vertexAttribDivisor(this._aPickColor.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$A);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);// Cleanup
|
|
19124
19124
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aPickColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19125
19125
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i373=0,len=clips.length;_i373<len;_i373++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i373),pos:program.getLocation("sectionPlanePos"+_i373),dir:program.getLocation("sectionPlaneDir"+_i373)});}this._uRenderPass=program.getLocation("renderPass");this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aPickColor=program.getAttribute("pickColor");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry picking vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 pickColor;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19126
19126
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19127
19127
|
// renderPass = PICK
|
|
19128
19128
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19129
|
-
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i374=0;_i374<sectionPlanesState.sectionPlanes.length;_i374++){src.push("uniform bool sectionPlaneActive"+_i374+";");src.push("uniform vec3 sectionPlanePos"+_i374+";");src.push("uniform vec3 sectionPlaneDir"+_i374+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i375=0;_i375<sectionPlanesState.sectionPlanes.length;_i375++){src.push("if (sectionPlaneActive"+_i375+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i375+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i375+".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 = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickMeshRenderer;}();var tempVec3a$
|
|
19129
|
+
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry 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;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i374=0;_i374<sectionPlanesState.sectionPlanes.length;_i374++){src.push("uniform bool sectionPlaneActive"+_i374+";");src.push("uniform vec3 sectionPlanePos"+_i374+";");src.push("uniform vec3 sectionPlaneDir"+_i374+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i375=0;_i375<sectionPlanesState.sectionPlanes.length;_i375++){src.push("if (sectionPlaneActive"+_i375+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i375+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i375+".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 = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickMeshRenderer;}();var tempVec3a$z=math.vec3();/**
|
|
19130
19130
|
* @private
|
|
19131
19131
|
*/var TrianglesInstancingPickDepthRenderer=/*#__PURE__*/function(){function TrianglesInstancingPickDepthRenderer(scene){_classCallCheck(this,TrianglesInstancingPickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}var camera=scene.camera;gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix
|
|
19132
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19132
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$z);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);// Cleanup
|
|
19133
19133
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19134
19134
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i376=0,len=scene._sectionPlanesState.sectionPlanes.length;_i376<len;_i376++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i376),pos:program.getLocation("sectionPlanePos"+_i376),dir:program.getLocation("sectionPlaneDir"+_i376)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19135
19135
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19136
19136
|
// renderPass = PICK
|
|
19137
19137
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19138
19138
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewPosition = viewPosition;");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry depth 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 float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i377=0;_i377<sectionPlanesState.sectionPlanes.length;_i377++){src.push("uniform bool sectionPlaneActive"+_i377+";");src.push("uniform vec3 sectionPlanePos"+_i377+";");src.push("uniform vec3 sectionPlaneDir"+_i377+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 packDepth(const in float depth) {");src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);");src.push(" vec4 res = fract(depth * bitShift);");src.push(" res -= res.xxyz * bitMask;");src.push(" return res;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i378=0;_i378<sectionPlanesState.sectionPlanes.length;_i378++){src.push("if (sectionPlaneActive"+_i378+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i378+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i378+".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(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth
|
|
19139
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickDepthRenderer;}();var tempVec3a$
|
|
19139
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickDepthRenderer;}();var tempVec3a$y=math.vec3();/**
|
|
19140
19140
|
* @private
|
|
19141
19141
|
*/var TrianglesInstancingPickNormalsRenderer=/*#__PURE__*/function(){function TrianglesInstancingPickNormalsRenderer(scene){_classCallCheck(this,TrianglesInstancingPickNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPickNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}// In practice, these binds will only happen once per frame
|
|
19142
19142
|
// because we pick normals on a single previously-picked mesh
|
|
19143
19143
|
gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19144
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19144
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$y);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aModelNormalMatrixCol0.bindArrayBuffer(state.modelNormalMatrixCol0Buf);this._aModelNormalMatrixCol1.bindArrayBuffer(state.modelNormalMatrixCol1Buf);this._aModelNormalMatrixCol2.bindArrayBuffer(state.modelNormalMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aNormal.bindArrayBuffer(geometry.normalsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19145
19145
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i379=0,len=clips.length;_i379<len;_i379++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i379),pos:program.getLocation("sectionPlanePos"+_i379),dir:program.getLocation("sectionPlaneDir"+_i379)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec2 normal;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19146
19146
|
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;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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;");}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 vec4 vFlags2;");}src.push("out vec3 vWorldNormal;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19147
19147
|
// renderPass = PICK
|
|
19148
19148
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19149
|
-
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(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));");src.push(" vWorldNormal = worldNormal;");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i380=0;_i380<sectionPlanesState.sectionPlanes.length;_i380++){src.push("uniform bool sectionPlaneActive"+_i380+";");src.push("uniform vec3 sectionPlanePos"+_i380+";");src.push("uniform vec3 sectionPlaneDir"+_i380+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickNormalsRenderer;}();var tempVec3a$
|
|
19149
|
+
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(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));");src.push(" vWorldNormal = worldNormal;");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i380=0;_i380<sectionPlanesState.sectionPlanes.length;_i380++){src.push("uniform bool sectionPlaneActive"+_i380+";");src.push("uniform vec3 sectionPlanePos"+_i380+";");src.push("uniform vec3 sectionPlaneDir"+_i380+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickNormalsRenderer;}();var tempVec3a$x=math.vec3();/**
|
|
19150
19150
|
* @private
|
|
19151
|
-
*/var TrianglesInstancingOcclusionRenderer=/*#__PURE__*/function(){function TrianglesInstancingOcclusionRenderer(scene){_classCallCheck(this,TrianglesInstancingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19151
|
+
*/var TrianglesInstancingOcclusionRenderer=/*#__PURE__*/function(){function TrianglesInstancingOcclusionRenderer(scene){_classCallCheck(this,TrianglesInstancingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$x);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);}this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);// Cleanup
|
|
19152
19152
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);if(this._aColor){gl.vertexAttribDivisor(this._aColor.location,0);}gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19153
19153
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i381=0,len=clips.length;_i381<len;_i381++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i381),pos:program.getLocation("sectionPlanePos"+_i381),dir:program.getLocation("sectionPlaneDir"+_i381)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19154
19154
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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("in float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19155
19155
|
// renderPass = COLOR_OPAQUE
|
|
19156
19156
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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; ");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing 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("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i382=0;_i382<sectionPlanesState.sectionPlanes.length;_i382++){src.push("uniform bool sectionPlaneActive"+_i382+";");src.push("uniform vec3 sectionPlanePos"+_i382+";");src.push("uniform vec3 sectionPlaneDir"+_i382+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i383=0;_i383<sectionPlanesState.sectionPlanes.length;_i383++){src.push("if (sectionPlaneActive"+_i383+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i383+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i383+".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); ");// Occluders are blue
|
|
19157
|
-
if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingOcclusionRenderer;}();var tempVec3a$
|
|
19157
|
+
if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingOcclusionRenderer;}();var tempVec3a$w=math.vec3();/**
|
|
19158
19158
|
* @private
|
|
19159
|
-
*/var TrianglesInstancingDepthRenderer=/*#__PURE__*/function(){function TrianglesInstancingDepthRenderer(scene){_classCallCheck(this,TrianglesInstancingDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19159
|
+
*/var TrianglesInstancingDepthRenderer=/*#__PURE__*/function(){function TrianglesInstancingDepthRenderer(scene){_classCallCheck(this,TrianglesInstancingDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$w);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19160
19160
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i384=0,len=scene._sectionPlanesState.sectionPlanes.length;_i384<len;_i384++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i384),pos:program.getLocation("sectionPlanePos"+_i384),dir:program.getLocation("sectionPlaneDir"+_i384)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec2 vHighPrecisionZW;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19161
19161
|
// renderPass = COLOR_OPAQUE
|
|
19162
19162
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19163
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}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("vHighPrecisionZW = gl_Position.zw;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth drawing fragment shader");src.push("precision highp float;");src.push("precision highp int;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec2 vHighPrecisionZW;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingDepthRenderer;}();var tempVec3a$
|
|
19163
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}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("vHighPrecisionZW = gl_Position.zw;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth drawing fragment shader");src.push("precision highp float;");src.push("precision highp int;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec2 vHighPrecisionZW;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingDepthRenderer;}();var tempVec3a$v=math.vec3();/**
|
|
19164
19164
|
* @private
|
|
19165
|
-
*/var TrianglesInstancingNormalsRenderer=/*#__PURE__*/function(){function TrianglesInstancingNormalsRenderer(scene){_classCallCheck(this,TrianglesInstancingNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19165
|
+
*/var TrianglesInstancingNormalsRenderer=/*#__PURE__*/function(){function TrianglesInstancingNormalsRenderer(scene){_classCallCheck(this,TrianglesInstancingNormalsRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingNormalsRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$v);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aNormal.bindArrayBuffer(geometry.normalsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19166
19166
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i385=0,len=clips.length;_i385<len;_i385++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i385),pos:program.getLocation("sectionPlanePos"+_i385),dir:program.getLocation("sectionPlaneDir"+_i385)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");if(this._aFlags2){this._aFlags2=program.getAttribute("flags2");}this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry normals drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 viewNormalMatrix;");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;");}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 vec4 vFlags2;");}src.push("out vec3 vViewNormal;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19167
19167
|
// renderPass = COLOR_OPAQUE
|
|
19168
|
-
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push(" vViewNormal = viewNormal;");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i386=0,len=sectionPlanesState.sectionPlanes.length;_i386<len;_i386++){src.push("uniform bool sectionPlaneActive"+_i386+";");src.push("uniform vec3 sectionPlanePos"+_i386+";");src.push("uniform vec3 sectionPlaneDir"+_i386+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i387=0,_len86=sectionPlanesState.sectionPlanes.length;_i387<_len86;_i387++){src.push("if (sectionPlaneActive"+_i387+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i387+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i387+".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 = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingNormalsRenderer;}();var tempVec3a$
|
|
19168
|
+
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push(" vViewNormal = viewNormal;");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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth 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(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i386=0,len=sectionPlanesState.sectionPlanes.length;_i386<len;_i386++){src.push("uniform bool sectionPlaneActive"+_i386+";");src.push("uniform vec3 sectionPlanePos"+_i386+";");src.push("uniform vec3 sectionPlaneDir"+_i386+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i387=0,_len86=sectionPlanesState.sectionPlanes.length;_i387<_len86;_i387++){src.push("if (sectionPlaneActive"+_i387+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i387+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i387+".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 = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingNormalsRenderer;}();var tempVec3a$u=math.vec3();/**
|
|
19169
19169
|
* Renders InstancingLayer fragment depths to a shadow map.
|
|
19170
19170
|
*
|
|
19171
19171
|
* @private
|
|
19172
19172
|
*/var TrianglesInstancingShadowRenderer=/*#__PURE__*/function(){function TrianglesInstancingShadowRenderer(scene){_classCallCheck(this,TrianglesInstancingShadowRenderer);this._scene=scene;this._hash=this._getHash();this._lastLightId=null;this._allocate();}_createClass(TrianglesInstancingShadowRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer){var model=instancingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,instancingLayer);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}// TODO: Section planes need to be set if RTC center has changed since last RTC center recorded on frameCtx
|
|
19173
|
-
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=instancingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19173
|
+
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=instancingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$u);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19174
19174
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uShadowViewMatrix=program.getLocation("shadowViewMatrix");this._uShadowProjMatrix=program.getLocation("shadowProjMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i388=0,len=clips.length;_i388<len;_i388++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i388),pos:program.getLocation("sectionPlanePos"+_i388),dir:program.getLocation("sectionPlaneDir"+_i388)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");}},{key:"_bindProgram",value:function _bindProgram(frameCtx,instancingLayer){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniformMatrix4fv(this._uShadowViewMatrix,false,frameCtx.shadowViewMatrix);gl.uniformMatrix4fv(this._uShadowProjMatrix,false,frameCtx.shadowProjMatrix);this._lastLightId=null;}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry shadow drawing vertex shader");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");src.push("bool visible = (float(flags.x) > 0.0);");src.push("bool transparent = ((float(color.a) / 255.0) < 1.0);");src.push("if (!visible || transparent) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19175
|
-
src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = 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 = shadowViewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth 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("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i389=0,len=sectionPlanesState.sectionPlanes.length;_i389<len;_i389++){src.push("uniform bool sectionPlaneActive"+_i389+";");src.push("uniform vec3 sectionPlanePos"+_i389+";");src.push("uniform vec3 sectionPlaneDir"+_i389+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i390=0,_len87=sectionPlanesState.sectionPlanes.length;_i390<_len87;_i390++){src.push("if (sectionPlaneActive"+_i390+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i390+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i390+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingShadowRenderer;}();var tempVec4$1=math.vec4();var tempVec3a$
|
|
19175
|
+
src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = 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 = shadowViewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth 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("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i389=0,len=sectionPlanesState.sectionPlanes.length;_i389<len;_i389++){src.push("uniform bool sectionPlaneActive"+_i389+";");src.push("uniform vec3 sectionPlanePos"+_i389+";");src.push("uniform vec3 sectionPlaneDir"+_i389+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i390=0,_len87=sectionPlanesState.sectionPlanes.length;_i390<_len87;_i390++){src.push("if (sectionPlaneActive"+_i390+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i390+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i390+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingShadowRenderer;}();var tempVec4$1=math.vec4();var tempVec3a$t=math.vec3();var TEXTURE_DECODE_FUNCS={};TEXTURE_DECODE_FUNCS[LinearEncoding]="linearToLinear";TEXTURE_DECODE_FUNCS[sRGBEncoding]="sRGBToLinear";/**
|
|
19176
19176
|
* @private
|
|
19177
|
-
*/var TrianglesInstancingPBRRenderer=/*#__PURE__*/function(){function TrianglesInstancingPBRRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingPBRRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPBRRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var model=instancingLayer.model;var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=state.origin;var textureSet=state.textureSet;var geometry=state.geometry;var lightsState=scene._lightsState;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19177
|
+
*/var TrianglesInstancingPBRRenderer=/*#__PURE__*/function(){function TrianglesInstancingPBRRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingPBRRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPBRRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var model=instancingLayer.model;var scene=this._scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=state.origin;var textureSet=state.textureSet;var geometry=state.geometry;var lightsState=scene._lightsState;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uWorldNormalMatrix,false,model.worldNormalMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$t);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,geometry.uvDecodeMatrix);}this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aModelNormalMatrixCol0.bindArrayBuffer(state.modelNormalMatrixCol0Buf);this._aModelNormalMatrixCol1.bindArrayBuffer(state.modelNormalMatrixCol1Buf);this._aModelNormalMatrixCol2.bindArrayBuffer(state.modelNormalMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aNormal.bindArrayBuffer(geometry.normalsBuf);if(this._aUV){this._aUV.bindArrayBuffer(geometry.uvBuf);}this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);gl.vertexAttribDivisor(this._aMetallicRoughness.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$1[0]=viewportWidth;tempVec4$1[1]=viewportHeight;tempVec4$1[2]=sao.blendCutoff;tempVec4$1[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$1);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(textureSet){this._program.bindTexture(this._uBaseColorMap,textureSet.colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uMetallicRoughMap,textureSet.metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uEmissiveMap,textureSet.emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;this._program.bindTexture(this._uNormalMap,textureSet.normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);frameCtx.drawElements++;gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aMetallicRoughness.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19178
19178
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uWorldNormalMatrix=program.getLocation("worldNormalMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uViewNormalMatrix=program.getLocation("viewNormalMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var i=0,len=lights.length;i<len;i++){light=lights[i];switch(light.type){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(lightsState.reflectionMaps.length>0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i391=0,_len88=scene._sectionPlanesState.sectionPlanes.length;_i391<_len88;_i391++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i391),pos:program.getLocation("sectionPlanePos"+_i391),dir:program.getLocation("sectionPlaneDir"+_i391)});}this._aPosition=program.getAttribute("position");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._uBaseColorMap="uBaseColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;this._program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i392=0,len=lights.length;_i392<len;_i392++){var light=lights[_i392];if(this._uLightColor[_i392]){gl.uniform4f(this._uLightColor[_i392],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i392]){gl.uniform3fv(this._uLightPos[_i392],light.pos);if(this._uLightAttenuation[_i392]){gl.uniform1f(this._uLightAttenuation[_i392],light.attenuation);}}if(this._uLightDir[_i392]){gl.uniform3fv(this._uLightDir[_i392],light.dir);}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var clippingCaps=sectionPlanesState.clippingCaps;var src=[];src.push("#version 300 es");src.push("// Instancing geometry quality drawing 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 vec2 uv;");src.push("in vec2 metallicRoughness;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19179
19179
|
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;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 worldNormalMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 viewNormalMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform mat3 uvDecodeMatrix;");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("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("}");src.push("out vec4 vViewPosition;");src.push("out vec3 vViewNormal;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("out vec2 vMetallicRoughness;");if(lightsState.lightMaps.length>0){src.push("out vec3 vWorldNormal;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");if(clippingCaps){src.push("out vec4 vClipPosition;");}}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19180
19180
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
@@ -19194,19 +19194,19 @@ src.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;");src.push
|
|
|
19194
19194
|
src.push("computePBRLighting(light, geometry, material, reflectedLight);");}src.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;");// TODO: correct gamma function
|
|
19195
19195
|
src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;");src.push("vec4 fragColor;");if(this._withSAO){// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
19196
19196
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
19197
|
-
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(" fragColor = vec4(outgoingLight.rgb * ambient, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb, opacity);");}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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPBRRenderer;}();var tempVec3a$
|
|
19197
|
+
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(" fragColor = vec4(outgoingLight.rgb * ambient, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb, opacity);");}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;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPBRRenderer;}();var tempVec3a$s=math.vec3();/**
|
|
19198
19198
|
* @private
|
|
19199
19199
|
*/var TrianglesInstancingPickNormalsFlatRenderer=/*#__PURE__*/function(){function TrianglesInstancingPickNormalsFlatRenderer(scene){_classCallCheck(this,TrianglesInstancingPickNormalsFlatRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingPickNormalsFlatRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}// In practice, these binds will only happen once per frame
|
|
19200
19200
|
// because we pick normals on a single previously-picked mesh
|
|
19201
19201
|
gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19202
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19202
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$s);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19203
19203
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i397=0,len=clips.length;_i397<len;_i397++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i397),pos:program.getLocation("sectionPlanePos"+_i397),dir:program.getLocation("sectionPlaneDir"+_i397)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19204
19204
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");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 vFlags2;");}src.push("out vec4 vWorldPosition;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19205
19205
|
// renderPass = PICK
|
|
19206
19206
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19207
|
-
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(" 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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");if(clipping){src.push("in vec4 vFlags2;");for(var _i398=0;_i398<sectionPlanesState.sectionPlanes.length;_i398++){src.push("uniform bool sectionPlaneActive"+_i398+";");src.push("uniform vec3 sectionPlanePos"+_i398+";");src.push("uniform vec3 sectionPlaneDir"+_i398+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickNormalsFlatRenderer;}();var tempVec4=math.vec4();var tempVec3a$
|
|
19207
|
+
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(" 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("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals 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("in vec4 vWorldPosition;");if(clipping){src.push("in vec4 vFlags2;");for(var _i398=0;_i398<sectionPlanesState.sectionPlanes.length;_i398++){src.push("uniform bool sectionPlaneActive"+_i398+";");src.push("uniform vec3 sectionPlanePos"+_i398+";");src.push("uniform vec3 sectionPlaneDir"+_i398+";");}}src.push("in vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesInstancingPickNormalsFlatRenderer;}();var tempVec4=math.vec4();var tempVec3a$r=math.vec3();/**
|
|
19208
19208
|
* @private
|
|
19209
|
-
*/var TrianglesInstancingColorTextureRenderer=/*#__PURE__*/function(){function TrianglesInstancingColorTextureRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingColorTextureRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingColorTextureRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;var textureSet=state.textureSet;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19209
|
+
*/var TrianglesInstancingColorTextureRenderer=/*#__PURE__*/function(){function TrianglesInstancingColorTextureRenderer(scene,withSAO){_classCallCheck(this,TrianglesInstancingColorTextureRenderer);this._scene=scene;this._withSAO=withSAO;this._hash=this._getHash();this._allocate();}_createClass(TrianglesInstancingColorTextureRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var geometry=state.geometry;var origin=instancingLayer._state.origin;var textureSet=state.textureSet;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$r);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,geometry.uvDecodeMatrix);}this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aUV.bindArrayBuffer(geometry.uvBuf);this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.TRIANGLES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);frameCtx.drawElements++;gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19210
19210
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}if(textureSet){if(textureSet.colorTexture){this._program.bindTexture(this._uColorMap,textureSet.colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4[0]=viewportWidth;tempVec4[1]=viewportHeight;tempVec4[2]=sao.blendCutoff;tempVec4[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,0);}}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uUVDecodeMatrix=program.getLocation("uvDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uGammaFactor=program.getLocation("gammaFactor");this._uLightAmbient=program.getLocation("lightAmbient");this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];var lights=lightsState.lights;var light;for(var _i399=0,len=lights.length;_i399<len;_i399++){light=lights[_i399];switch(light.type){case"dir":this._uLightColor[_i399]=program.getLocation("lightColor"+_i399);this._uLightPos[_i399]=null;this._uLightDir[_i399]=program.getLocation("lightDir"+_i399);break;case"point":this._uLightColor[_i399]=program.getLocation("lightColor"+_i399);this._uLightPos[_i399]=program.getLocation("lightPos"+_i399);this._uLightDir[_i399]=null;this._uLightAttenuation[_i399]=program.getLocation("lightAttenuation"+_i399);break;case"spot":this._uLightColor[_i399]=program.getLocation("lightColor"+_i399);this._uLightPos[_i399]=program.getLocation("lightPos"+_i399);this._uLightDir[_i399]=program.getLocation("lightDir"+_i399);this._uLightAttenuation[_i399]=program.getLocation("lightAttenuation"+_i399);break;}}this._uSectionPlanes=[];for(var _i400=0,_len92=scene._sectionPlanesState.sectionPlanes.length;_i400<_len92;_i400++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i400),pos:program.getLocation("sectionPlanePos"+_i400),dir:program.getLocation("sectionPlaneDir"+_i400)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aUV=program.getAttribute("uv");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uColorMap="uColorMap";this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;this._program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,scene._lightsState.getAmbientColorAndIntensity());}for(var _i401=0,len=lights.length;_i401<len;_i401++){var light=lights[_i401];if(this._uLightColor[_i401]){gl.uniform4f(this._uLightColor[_i401],light.color[0],light.color[1],light.color[2],light.intensity);}if(this._uLightPos[_i401]){gl.uniform3fv(this._uLightPos[_i401],light.pos);if(this._uLightAttenuation[_i401]){gl.uniform1f(this._uLightAttenuation[_i401],light.attenuation);}}if(this._uLightDir[_i401]){gl.uniform3fv(this._uLightDir[_i401],light.dir);}}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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19211
19211
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform mat3 uvDecodeMatrix;");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 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19212
19212
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
@@ -19218,7 +19218,7 @@ src.push(" float viewportWidth = uSAOParams[0];");src.push(" float viewp
|
|
|
19218
19218
|
* @private
|
|
19219
19219
|
*/var TrianglesInstancingRenderers=/*#__PURE__*/function(){function TrianglesInstancingRenderers(scene){_classCallCheck(this,TrianglesInstancingRenderers);this._scene=scene;}_createClass(TrianglesInstancingRenderers,[{key:"_compile",value:function _compile(){if(this._colorRenderer&&!this._colorRenderer.getValid()){this._colorRenderer.destroy();this._colorRenderer=null;}if(this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()){this._colorRendererWithSAO.destroy();this._colorRendererWithSAO=null;}if(this._flatColorRenderer&&!this._flatColorRenderer.getValid()){this._flatColorRenderer.destroy();this._flatColorRenderer=null;}if(this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()){this._flatColorRendererWithSAO.destroy();this._flatColorRendererWithSAO=null;}if(this._pbrRenderer&&!this._pbrRenderer.getValid()){this._pbrRenderer.destroy();this._pbrRenderer=null;}if(this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()){this._pbrRendererWithSAO.destroy();this._pbrRendererWithSAO=null;}if(this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()){this._colorTextureRenderer.destroy();this._colorTextureRenderer=null;}if(this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()){this._colorTextureRendererWithSAO.destroy();this._colorTextureRendererWithSAO=null;}if(this._depthRenderer&&!this._depthRenderer.getValid()){this._depthRenderer.destroy();this._depthRenderer=null;}if(this._normalsRenderer&&!this._normalsRenderer.getValid()){this._normalsRenderer.destroy();this._normalsRenderer=null;}if(this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()){this._silhouetteRenderer.destroy();this._silhouetteRenderer=null;}if(this._edgesRenderer&&!this._edgesRenderer.getValid()){this._edgesRenderer.destroy();this._edgesRenderer=null;}if(this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()){this._edgesColorRenderer.destroy();this._edgesColorRenderer=null;}if(this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()){this._pickMeshRenderer.destroy();this._pickMeshRenderer=null;}if(this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()){this._pickDepthRenderer.destroy();this._pickDepthRenderer=null;}if(this._pickNormalsRenderer&&this._pickNormalsRenderer.getValid()===false){this._pickNormalsRenderer.destroy();this._pickNormalsRenderer=null;}if(this._pickNormalsFlatRenderer&&!this._pickNormalsFlatRenderer.getValid()){this._pickNormalsFlatRenderer.destroy();this._pickNormalsFlatRenderer=null;}if(this._occlusionRenderer&&this._occlusionRenderer.getValid()===false){this._occlusionRenderer.destroy();this._occlusionRenderer=null;}if(this._shadowRenderer&&!this._shadowRenderer.getValid()){this._shadowRenderer.destroy();this._shadowRenderer=null;}}},{key:"colorRenderer",get:function get(){if(!this._colorRenderer){this._colorRenderer=new TrianglesInstancingColorRenderer(this._scene,false);}return this._colorRenderer;}},{key:"colorRendererWithSAO",get:function get(){if(!this._colorRendererWithSAO){this._colorRendererWithSAO=new TrianglesInstancingColorRenderer(this._scene,true);}return this._colorRendererWithSAO;}},{key:"flatColorRenderer",get:function get(){if(!this._flatColorRenderer){this._flatColorRenderer=new TrianglesInstancingFlatColorRenderer(this._scene,false);}return this._flatColorRenderer;}},{key:"flatColorRendererWithSAO",get:function get(){if(!this._flatColorRendererWithSAO){this._flatColorRendererWithSAO=new TrianglesInstancingFlatColorRenderer(this._scene,true);}return this._flatColorRendererWithSAO;}},{key:"pbrRenderer",get:function get(){if(!this._pbrRenderer){this._pbrRenderer=new TrianglesInstancingPBRRenderer(this._scene,false);}return this._pbrRenderer;}},{key:"pbrRendererWithSAO",get:function get(){if(!this._pbrRendererWithSAO){this._pbrRendererWithSAO=new TrianglesInstancingPBRRenderer(this._scene,true);}return this._pbrRendererWithSAO;}},{key:"colorTextureRenderer",get:function get(){if(!this._colorTextureRenderer){this._colorTextureRenderer=new TrianglesInstancingColorTextureRenderer(this._scene,false);}return this._colorTextureRenderer;}},{key:"colorTextureRendererWithSAO",get:function get(){if(!this._colorTextureRendererWithSAO){this._colorTextureRendererWithSAO=new TrianglesInstancingColorTextureRenderer(this._scene,true);}return this._colorTextureRendererWithSAO;}},{key:"silhouetteRenderer",get:function get(){if(!this._silhouetteRenderer){this._silhouetteRenderer=new TrianglesInstancingSilhouetteRenderer(this._scene);}return this._silhouetteRenderer;}},{key:"depthRenderer",get:function get(){if(!this._depthRenderer){this._depthRenderer=new TrianglesInstancingDepthRenderer(this._scene);}return this._depthRenderer;}},{key:"normalsRenderer",get:function get(){if(!this._normalsRenderer){this._normalsRenderer=new TrianglesInstancingNormalsRenderer(this._scene);}return this._normalsRenderer;}},{key:"edgesRenderer",get:function get(){if(!this._edgesRenderer){this._edgesRenderer=new TrianglesInstancingEdgesRenderer(this._scene);}return this._edgesRenderer;}},{key:"edgesColorRenderer",get:function get(){if(!this._edgesColorRenderer){this._edgesColorRenderer=new TrianglesInstancingEdgesColorRenderer(this._scene);}return this._edgesColorRenderer;}},{key:"pickMeshRenderer",get:function get(){if(!this._pickMeshRenderer){this._pickMeshRenderer=new TrianglesInstancingPickMeshRenderer(this._scene);}return this._pickMeshRenderer;}},{key:"pickNormalsRenderer",get:function get(){if(!this._pickNormalsRenderer){this._pickNormalsRenderer=new TrianglesInstancingPickNormalsRenderer(this._scene);}return this._pickNormalsRenderer;}},{key:"pickNormalsFlatRenderer",get:function get(){if(!this._pickNormalsFlatRenderer){this._pickNormalsFlatRenderer=new TrianglesInstancingPickNormalsFlatRenderer(this._scene);}return this._pickNormalsFlatRenderer;}},{key:"pickDepthRenderer",get:function get(){if(!this._pickDepthRenderer){this._pickDepthRenderer=new TrianglesInstancingPickDepthRenderer(this._scene);}return this._pickDepthRenderer;}},{key:"occlusionRenderer",get:function get(){if(!this._occlusionRenderer){this._occlusionRenderer=new TrianglesInstancingOcclusionRenderer(this._scene);}return this._occlusionRenderer;}},{key:"shadowRenderer",get:function get(){if(!this._shadowRenderer){this._shadowRenderer=new TrianglesInstancingShadowRenderer(this._scene);}return this._shadowRenderer;}},{key:"_destroy",value:function _destroy(){if(this._colorRenderer){this._colorRenderer.destroy();}if(this._colorRendererWithSAO){this._colorRendererWithSAO.destroy();}if(this._flatColorRenderer){this._flatColorRenderer.destroy();}if(this._flatColorRendererWithSAO){this._flatColorRendererWithSAO.destroy();}if(this._pbrRenderer){this._pbrRenderer.destroy();}if(this._pbrRendererWithSAO){this._pbrRendererWithSAO.destroy();}if(this._colorTextureRenderer){this._colorTextureRenderer.destroy();}if(this._colorTextureRendererWithSAO){this._colorTextureRendererWithSAO.destroy();}if(this._depthRenderer){this._depthRenderer.destroy();}if(this._normalsRenderer){this._normalsRenderer.destroy();}if(this._silhouetteRenderer){this._silhouetteRenderer.destroy();}if(this._edgesRenderer){this._edgesRenderer.destroy();}if(this._edgesColorRenderer){this._edgesColorRenderer.destroy();}if(this._pickMeshRenderer){this._pickMeshRenderer.destroy();}if(this._pickDepthRenderer){this._pickDepthRenderer.destroy();}if(this._pickNormalsRenderer){this._pickNormalsRenderer.destroy();}if(this._pickNormalsFlatRenderer){this._pickNormalsFlatRenderer.destroy();}if(this._occlusionRenderer){this._occlusionRenderer.destroy();}if(this._shadowRenderer){this._shadowRenderer.destroy();}}}]);return TrianglesInstancingRenderers;}();var cachedRenderers$4={};/**
|
|
19220
19220
|
* @private
|
|
19221
|
-
*/function getInstancingRenderers$1(scene){var sceneId=scene.id;var instancingRenderers=cachedRenderers$4[sceneId];if(!instancingRenderers){instancingRenderers=new TrianglesInstancingRenderers(scene);cachedRenderers$4[sceneId]=instancingRenderers;instancingRenderers._compile();scene.on("compile",function(){instancingRenderers._compile();});scene.on("destroyed",function(){delete cachedRenderers$4[sceneId];instancingRenderers._destroy();});}return instancingRenderers;}var tempUint8Vec4$2=new Uint8Array(4);var tempVec4a$9=math.vec4([0,0,0,1]);var tempVec4b$9=math.vec4([0,0,0,1]);var tempVec4c$6=math.vec4([0,0,0,1]);var tempVec3fa$2=new Float32Array(3);var tempVec3a$
|
|
19221
|
+
*/function getInstancingRenderers$1(scene){var sceneId=scene.id;var instancingRenderers=cachedRenderers$4[sceneId];if(!instancingRenderers){instancingRenderers=new TrianglesInstancingRenderers(scene);cachedRenderers$4[sceneId]=instancingRenderers;instancingRenderers._compile();scene.on("compile",function(){instancingRenderers._compile();});scene.on("destroyed",function(){delete cachedRenderers$4[sceneId];instancingRenderers._destroy();});}return instancingRenderers;}var tempUint8Vec4$2=new Uint8Array(4);var tempVec4a$9=math.vec4([0,0,0,1]);var tempVec4b$9=math.vec4([0,0,0,1]);var tempVec4c$6=math.vec4([0,0,0,1]);var tempVec3fa$2=new Float32Array(3);var tempVec3a$q=math.vec3();var tempVec3b$6=math.vec3();var tempVec3c$4=math.vec3();var tempVec3d$1=math.vec3();var tempVec3e=math.vec3();var tempVec3f=math.vec3();var tempVec3g=math.vec3();/**
|
|
19222
19222
|
* @private
|
|
19223
19223
|
*/var TrianglesInstancingLayer=/*#__PURE__*/function(){/**
|
|
19224
19224
|
* @param cfg
|
|
@@ -19329,16 +19329,16 @@ return;}tempVec3fa$2[0]=offset[0];tempVec3fa$2[1]=offset[1];tempVec3fa$2[2]=offs
|
|
|
19329
19329
|
this._instancingRenderers.occlusionRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}// ---------------------- SHADOW BUFFER RENDERING -----------------------------------
|
|
19330
19330
|
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.shadowRenderer){this._instancingRenderers.shadowRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}//---- PICKING ----------------------------------------------------------------------------------------------------
|
|
19331
19331
|
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickMeshRenderer){this._instancingRenderers.pickMeshRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickDepthRenderer){this._instancingRenderers.pickDepthRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickNormalsRenderer){this._instancingRenderers.pickNormalsRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}//-----------------------------------------------------------------------------------------
|
|
19332
|
-
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var geometry=this._state.geometry;var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}if(!portion.inverseMatrix){portion.inverseMatrix=math.inverseMat4(portion.matrix,math.mat4());}if(worldNormal&&!portion.normalMatrix){portion.normalMatrix=math.transposeMat4(portion.inverseMatrix,math.mat4());}var quantizedPositions=geometry.quantizedPositions;var indices=geometry.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$
|
|
19332
|
+
},{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var geometry=this._state.geometry;var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}if(!portion.inverseMatrix){portion.inverseMatrix=math.inverseMat4(portion.matrix,math.mat4());}if(worldNormal&&!portion.normalMatrix){portion.normalMatrix=math.transposeMat4(portion.inverseMatrix,math.mat4());}var quantizedPositions=geometry.quantizedPositions;var indices=geometry.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$q;var rtcRayDir=tempVec3b$6;rtcRayOrigin.set(origin?math.subVec3(worldRayOrigin,origin,tempVec3c$4):worldRayOrigin);// World -> RTC
|
|
19333
19333
|
rtcRayDir.set(worldRayDir);if(offset){math.subVec3(rtcRayOrigin,offset);}math.transformRay(this.model.worldNormalMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);math.transformRay(portion.inverseMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);var a=tempVec3d$1;var b=tempVec3e;var c=tempVec3f;var gotIntersect=false;var closestDist=0;var closestIntersectPos=tempVec3g;for(var _i405=0,len=indices.length;_i405<len;_i405+=3){var ia=indices[_i405+0]*3;var ib=indices[_i405+1]*3;var ic=indices[_i405+2]*3;a[0]=quantizedPositions[ia];a[1]=quantizedPositions[ia+1];a[2]=quantizedPositions[ia+2];b[0]=quantizedPositions[ib];b[1]=quantizedPositions[ib+1];b[2]=quantizedPositions[ib+2];c[0]=quantizedPositions[ic];c[1]=quantizedPositions[ic+1];c[2]=quantizedPositions[ic+2];math.decompressPosition(a,state.positionsDecodeMatrix);math.decompressPosition(b,state.positionsDecodeMatrix);math.decompressPosition(c,state.positionsDecodeMatrix);if(math.rayTriangleIntersect(rtcRayOrigin,rtcRayDir,a,b,c,closestIntersectPos)){math.transformPoint3(portion.matrix,closestIntersectPos,closestIntersectPos);math.transformPoint3(this.model.worldMatrix,closestIntersectPos,closestIntersectPos);if(offset){math.addVec3(closestIntersectPos,offset);}if(origin){math.addVec3(closestIntersectPos,origin);}var dist=Math.abs(math.lenVec3(math.subVec3(closestIntersectPos,worldRayOrigin,[])));if(!gotIntersect||dist>closestDist){closestDist=dist;worldSurfacePos.set(closestIntersectPos);if(worldNormal){// Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
|
|
19334
|
-
math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(portion.normalMatrix,worldNormal,worldNormal);math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}},{key:"destroy",value:function destroy(){var state=this._state;if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.metallicRoughnessBuf){state.metallicRoughnessBuf.destroy();state.metallicRoughnessBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.modelMatrixCol0Buf){state.modelMatrixCol0Buf.destroy();state.modelMatrixCol0Buf=null;}if(state.modelMatrixCol1Buf){state.modelMatrixCol1Buf.destroy();state.modelMatrixCol1Buf=null;}if(state.modelMatrixCol2Buf){state.modelMatrixCol2Buf.destroy();state.modelMatrixCol2Buf=null;}if(state.modelNormalMatrixCol0Buf){state.modelNormalMatrixCol0Buf.destroy();state.modelNormalMatrixCol0Buf=null;}if(state.modelNormalMatrixCol1Buf){state.modelNormalMatrixCol1Buf.destroy();state.modelNormalMatrixCol1Buf=null;}if(state.modelNormalMatrixCol2Buf){state.modelNormalMatrixCol2Buf.destroy();state.modelNormalMatrixCol2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}state.destroy();}}]);return TrianglesInstancingLayer;}();var tempVec3a$
|
|
19334
|
+
math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(portion.normalMatrix,worldNormal,worldNormal);math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}},{key:"destroy",value:function destroy(){var state=this._state;if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.metallicRoughnessBuf){state.metallicRoughnessBuf.destroy();state.metallicRoughnessBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.modelMatrixCol0Buf){state.modelMatrixCol0Buf.destroy();state.modelMatrixCol0Buf=null;}if(state.modelMatrixCol1Buf){state.modelMatrixCol1Buf.destroy();state.modelMatrixCol1Buf=null;}if(state.modelMatrixCol2Buf){state.modelMatrixCol2Buf.destroy();state.modelMatrixCol2Buf=null;}if(state.modelNormalMatrixCol0Buf){state.modelNormalMatrixCol0Buf.destroy();state.modelNormalMatrixCol0Buf=null;}if(state.modelNormalMatrixCol1Buf){state.modelNormalMatrixCol1Buf.destroy();state.modelNormalMatrixCol1Buf=null;}if(state.modelNormalMatrixCol2Buf){state.modelNormalMatrixCol2Buf.destroy();state.modelNormalMatrixCol2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}state.destroy();}}]);return TrianglesInstancingLayer;}();var tempVec3a$p=math.vec3();/**
|
|
19335
19335
|
* @private
|
|
19336
|
-
*/var LinesBatchingColorRenderer=/*#__PURE__*/function(){function LinesBatchingColorRenderer(scene){_classCallCheck(this,LinesBatchingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;batchingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19336
|
+
*/var LinesBatchingColorRenderer=/*#__PURE__*/function(){function LinesBatchingColorRenderer(scene){_classCallCheck(this,LinesBatchingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;batchingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$p);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i406=0,len=scene._sectionPlanesState.sectionPlanes.length;_i406<len;_i406++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i406),pos:program.getLocation("sectionPlanePos"+_i406),dir:program.getLocation("sectionPlaneDir"+_i406)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var project=scene.camera.project;program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching color vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19337
19337
|
// renderPass = COLOR_OPAQUE
|
|
19338
19338
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19339
|
-
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}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.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching color 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;");src.push("in vec4 vFlags2;");for(var _i407=0,len=sectionPlanesState.sectionPlanes.length;_i407<len;_i407++){src.push("uniform bool sectionPlaneActive"+_i407+";");src.push("uniform vec3 sectionPlanePos"+_i407+";");src.push("uniform vec3 sectionPlaneDir"+_i407+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i408=0,_len95=sectionPlanesState.sectionPlanes.length;_i408<_len95;_i408++){src.push("if (sectionPlaneActive"+_i408+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i408+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i408+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return LinesBatchingColorRenderer;}();var defaultColor$1=new Float32Array([1,1,1]);var tempVec3a$
|
|
19339
|
+
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}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.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching color 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;");src.push("in vec4 vFlags2;");for(var _i407=0,len=sectionPlanesState.sectionPlanes.length;_i407<len;_i407++){src.push("uniform bool sectionPlaneActive"+_i407+";");src.push("uniform vec3 sectionPlanePos"+_i407+";");src.push("uniform vec3 sectionPlaneDir"+_i407+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i408=0,_len95=sectionPlanesState.sectionPlanes.length;_i408<_len95;_i408++){src.push("if (sectionPlaneActive"+_i408+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i408+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i408+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return LinesBatchingColorRenderer;}();var defaultColor$1=new Float32Array([1,1,1]);var tempVec3a$o=math.vec3();/**
|
|
19340
19340
|
* @private
|
|
19341
|
-
*/var LinesBatchingSilhouetteRenderer=/*#__PURE__*/function(){function LinesBatchingSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,LinesBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;batchingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material13=scene.highlightMaterial._state;var _fillColor7=_material13.fillColor;var _fillAlpha7=_material13.fillAlpha;gl.uniform4f(this._uColor,_fillColor7[0],_fillColor7[1],_fillColor7[2],_fillAlpha7);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material14=scene.selectedMaterial._state;var _fillColor8=_material14.fillColor;var _fillAlpha8=_material14.fillAlpha;gl.uniform4f(this._uColor,_fillColor8[0],_fillColor8[1],_fillColor8[2],_fillAlpha8);}else{gl.uniform4fv(this._uColor,defaultColor$1);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19341
|
+
*/var LinesBatchingSilhouetteRenderer=/*#__PURE__*/function(){function LinesBatchingSilhouetteRenderer(scene,primitiveType){_classCallCheck(this,LinesBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var model=batchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;batchingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material13=scene.highlightMaterial._state;var _fillColor7=_material13.fillColor;var _fillAlpha7=_material13.fillAlpha;gl.uniform4f(this._uColor,_fillColor7[0],_fillColor7[1],_fillColor7[2],_fillAlpha7);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material14=scene.selectedMaterial._state;var _fillColor8=_material14.fillColor;var _fillAlpha8=_material14.fillAlpha;gl.uniform4f(this._uColor,_fillColor8[0],_fillColor8[1],_fillColor8[2],_fillAlpha8);}else{gl.uniform4fv(this._uColor,defaultColor$1);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$o);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}state.indicesBuf.bind();gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uColor=program.getLocation("color");this._uSectionPlanes=[];for(var _i409=0,len=scene._sectionPlanesState.sectionPlanes.length;_i409<len;_i409++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i409),pos:program.getLocation("sectionPlanePos"+_i409),dir:program.getLocation("sectionPlaneDir"+_i409)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform vec4 color;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | SILHOUETTE_XRAYED
|
|
19342
19342
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19343
19343
|
src.push("if (int(flags.y) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19344
19344
|
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}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.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching silhouette 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;");src.push("in vec4 vFlags2;");for(var _i410=0,len=sectionPlanesState.sectionPlanes.length;_i410<len;_i410++){src.push("uniform bool sectionPlaneActive"+_i410+";");src.push("uniform vec3 sectionPlanePos"+_i410+";");src.push("uniform vec3 sectionPlaneDir"+_i410+";");}}src.push("uniform vec4 color;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i411=0,_len96=sectionPlanesState.sectionPlanes.length;_i411<_len96;_i411++){src.push("if (sectionPlaneActive"+_i411+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i411+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i411+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = color;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return LinesBatchingSilhouetteRenderer;}();/**
|
|
@@ -19401,18 +19401,18 @@ tempArray[_i421+2]=0;// z - edges
|
|
|
19401
19401
|
tempArray[_i421+3]=f3;// w - pickable
|
|
19402
19402
|
}this._state.flagsBuf.setData(tempArray,firstFlag,lenFlags);}}},{key:"_setDeferredFlags",value:function _setDeferredFlags(){if(this._deferredFlagValues){this._state.flagsBuf.setData(this._deferredFlagValues);this._deferredFlagValues=null;}}},{key:"_setFlags2",value:function _setFlags2(portionId,flags){var deferred=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(!this._finalized){throw"Not finalized";}var portionsIdx=portionId*2;var vertexBase=this._portions[portionsIdx];var numVerts=this._portions[portionsIdx+1];var firstFlag=vertexBase*4;var lenFlags=numVerts*4;var clippable=!!(flags&ENTITY_FLAGS$1.CLIPPABLE)?255:0;if(deferred){if(!this._setDeferredFlag2Values){this._setDeferredFlag2Values=new Uint8Array(this._numVerts*4);}for(var _i422=firstFlag,len=firstFlag+lenFlags;_i422<len;_i422+=4){this._setDeferredFlag2Values[_i422]=clippable;}}else{var tempArray=this._scratchMemory.getUInt8Array(lenFlags);for(var _i423=0;_i423<lenFlags;_i423+=4){tempArray[_i423+0]=clippable;}this._state.flags2Buf.setData(tempArray,firstFlag,lenFlags);}}},{key:"_setDeferredFlags2",value:function _setDeferredFlags2(){if(this._setDeferredFlag2Values){this._state.flags2Buf.setData(this._setDeferredFlag2Values);this._setDeferredFlag2Values=null;}}},{key:"setOffset",value:function setOffset(portionId,offset){if(!this._finalized){throw"Not finalized";}if(!this.model.scene.entityOffsetsEnabled){this.model.error("Entity#offset not enabled for this Viewer");// See Viewer entityOffsetsEnabled
|
|
19403
19403
|
return;}var portionsIdx=portionId*2;var vertexBase=this._portions[portionsIdx];var numVerts=this._portions[portionsIdx+1];var firstOffset=vertexBase*3;var lenOffsets=numVerts*3;var tempArray=this._scratchMemory.getFloat32Array(lenOffsets);var x=offset[0];var y=offset[1];var z=offset[2];for(var _i424=0;_i424<lenOffsets;_i424+=3){tempArray[_i424+0]=x;tempArray[_i424+1]=y;tempArray[_i424+2]=z;}this._state.offsetsBuf.setData(tempArray,firstOffset,lenOffsets);}//-- RENDERING ----------------------------------------------------------------------------------------------
|
|
19404
|
-
},{key:"drawColorOpaque",value:function drawColorOpaque(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numTransparentLayerPortions===this._numPortions||this._numXRayedLayerPortions===this._numPortions){return;}if(this._batchingRenderers.colorRenderer){this._batchingRenderers.colorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}},{key:"drawColorTransparent",value:function drawColorTransparent(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numTransparentLayerPortions===0||this._numXRayedLayerPortions===this._numPortions){return;}if(this._batchingRenderers.colorRenderer){this._batchingRenderers.colorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_TRANSPARENT);}}},{key:"drawDepth",value:function drawDepth(renderFlags,frameCtx){}},{key:"drawNormals",value:function drawNormals(renderFlags,frameCtx){}},{key:"drawSilhouetteXRayed",value:function drawSilhouetteXRayed(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numXRayedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_XRAYED);}}},{key:"drawSilhouetteHighlighted",value:function drawSilhouetteHighlighted(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numHighlightedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_HIGHLIGHTED);}}},{key:"drawSilhouetteSelected",value:function drawSilhouetteSelected(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numSelectedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_SELECTED);}}},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){}},{key:"drawEdgesColorTransparent",value:function drawEdgesColorTransparent(renderFlags,frameCtx){}},{key:"drawEdgesHighlighted",value:function drawEdgesHighlighted(renderFlags,frameCtx){}},{key:"drawEdgesSelected",value:function drawEdgesSelected(renderFlags,frameCtx){}},{key:"drawEdgesXRayed",value:function drawEdgesXRayed(renderFlags,frameCtx){}},{key:"drawPickMesh",value:function drawPickMesh(frameCtx){}},{key:"drawPickDepths",value:function drawPickDepths(frameCtx){}},{key:"drawPickNormals",value:function drawPickNormals(frameCtx){}},{key:"drawOcclusion",value:function drawOcclusion(frameCtx){}},{key:"drawShadow",value:function drawShadow(frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.indicesBuf){state.indicesBuf.destroy();state.indicesBuf=null;}state.destroy();}}]);return LinesBatchingLayer;}();var tempVec3a$
|
|
19404
|
+
},{key:"drawColorOpaque",value:function drawColorOpaque(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numTransparentLayerPortions===this._numPortions||this._numXRayedLayerPortions===this._numPortions){return;}if(this._batchingRenderers.colorRenderer){this._batchingRenderers.colorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}},{key:"drawColorTransparent",value:function drawColorTransparent(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numTransparentLayerPortions===0||this._numXRayedLayerPortions===this._numPortions){return;}if(this._batchingRenderers.colorRenderer){this._batchingRenderers.colorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_TRANSPARENT);}}},{key:"drawDepth",value:function drawDepth(renderFlags,frameCtx){}},{key:"drawNormals",value:function drawNormals(renderFlags,frameCtx){}},{key:"drawSilhouetteXRayed",value:function drawSilhouetteXRayed(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numXRayedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_XRAYED);}}},{key:"drawSilhouetteHighlighted",value:function drawSilhouetteHighlighted(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numHighlightedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_HIGHLIGHTED);}}},{key:"drawSilhouetteSelected",value:function drawSilhouetteSelected(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numSelectedLayerPortions===0){return;}if(this._batchingRenderers.silhouetteRenderer){this._batchingRenderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_SELECTED);}}},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){}},{key:"drawEdgesColorTransparent",value:function drawEdgesColorTransparent(renderFlags,frameCtx){}},{key:"drawEdgesHighlighted",value:function drawEdgesHighlighted(renderFlags,frameCtx){}},{key:"drawEdgesSelected",value:function drawEdgesSelected(renderFlags,frameCtx){}},{key:"drawEdgesXRayed",value:function drawEdgesXRayed(renderFlags,frameCtx){}},{key:"drawPickMesh",value:function drawPickMesh(frameCtx){}},{key:"drawPickDepths",value:function drawPickDepths(frameCtx){}},{key:"drawPickNormals",value:function drawPickNormals(frameCtx){}},{key:"drawOcclusion",value:function drawOcclusion(frameCtx){}},{key:"drawShadow",value:function drawShadow(frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.indicesBuf){state.indicesBuf.destroy();state.indicesBuf=null;}state.destroy();}}]);return LinesBatchingLayer;}();var tempVec3a$n=math.vec3();/**
|
|
19405
19405
|
* @private
|
|
19406
|
-
*/var LinesInstancingColorRenderer=/*#__PURE__*/function(){function LinesInstancingColorRenderer(scene){_classCallCheck(this,LinesInstancingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19406
|
+
*/var LinesInstancingColorRenderer=/*#__PURE__*/function(){function LinesInstancingColorRenderer(scene){_classCallCheck(this,LinesInstancingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$n);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.LINES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);frameCtx.drawElements++;gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19407
19407
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i425=0,len=scene._sectionPlanesState.sectionPlanes.length;_i425<len;_i425++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i425),pos:program.getLocation("sectionPlanePos"+_i425),dir:program.getLocation("sectionPlaneDir"+_i425)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uOcclusionTexture="uOcclusionTexture";if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines instancing color vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19408
19408
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}src.push("uniform vec4 lightAmbient;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19409
19409
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19410
19410
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19411
19411
|
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}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 i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines instancing color 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;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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("}");}// Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
|
|
19412
19412
|
// Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
|
|
19413
|
-
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, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);");}else{src.push(" outColor = vColor;");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return LinesInstancingColorRenderer;}();var tempVec3a$
|
|
19413
|
+
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, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);");}else{src.push(" outColor = vColor;");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return LinesInstancingColorRenderer;}();var tempVec3a$m=math.vec3();/**
|
|
19414
19414
|
* @private
|
|
19415
|
-
*/var LinesInstancingSilhouetteRenderer=/*#__PURE__*/function(){function LinesInstancingSilhouetteRenderer(scene){_classCallCheck(this,LinesInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var geometry=instancingLayer.geometry;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material15=scene.highlightMaterial._state;var _fillColor9=_material15.fillColor;var _fillAlpha9=_material15.fillAlpha;gl.uniform4f(this._uColor,_fillColor9[0],_fillColor9[1],_fillColor9[2],_fillAlpha9);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material16=scene.selectedMaterial._state;var _fillColor10=_material16.fillColor;var _fillAlpha10=_material16.fillAlpha;gl.uniform4f(this._uColor,_fillColor10[0],_fillColor10[1],_fillColor10[2],_fillAlpha10);}else{gl.uniform4fv(this._uColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19415
|
+
*/var LinesInstancingSilhouetteRenderer=/*#__PURE__*/function(){function LinesInstancingSilhouetteRenderer(scene){_classCallCheck(this,LinesInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var geometry=instancingLayer.geometry;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material15=scene.highlightMaterial._state;var _fillColor9=_material15.fillColor;var _fillAlpha9=_material15.fillAlpha;gl.uniform4f(this._uColor,_fillColor9[0],_fillColor9[1],_fillColor9[2],_fillAlpha9);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material16=scene.selectedMaterial._state;var _fillColor10=_material16.fillColor;var _fillAlpha10=_material16.fillAlpha;gl.uniform4f(this._uColor,_fillColor10[0],_fillColor10[1],_fillColor10[2],_fillAlpha10);}else{gl.uniform4fv(this._uColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$m);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(state.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}geometry.indicesBuf.bind();gl.drawElementsInstanced(gl.LINES,geometry.indicesBuf.numItems,geometry.indicesBuf.itemType,0,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);// TODO: Is this needed
|
|
19416
19416
|
gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uColor=program.getLocation("color");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i426=0,len=clips.length;_i426<len;_i426++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i426),pos:program.getLocation("sectionPlanePos"+_i426),dir:program.getLocation("sectionPlaneDir"+_i426)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines instancing silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19417
19417
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}src.push("uniform vec4 color;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19418
19418
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
@@ -19491,36 +19491,36 @@ return;}tempVec3fa$1[0]=offset[0];tempVec3fa$1[1]=offset[1];tempVec3fa$1[2]=offs
|
|
|
19491
19491
|
},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){}},{key:"drawEdgesColorTransparent",value:function drawEdgesColorTransparent(renderFlags,frameCtx){}},{key:"drawEdgesXRayed",value:function drawEdgesXRayed(renderFlags,frameCtx){}},{key:"drawEdgesHighlighted",value:function drawEdgesHighlighted(renderFlags,frameCtx){}},{key:"drawEdgesSelected",value:function drawEdgesSelected(renderFlags,frameCtx){}// ---------------------- OCCLUSION CULL RENDERING -----------------------------------
|
|
19492
19492
|
},{key:"drawOcclusion",value:function drawOcclusion(renderFlags,frameCtx){}// ---------------------- SHADOW BUFFER RENDERING -----------------------------------
|
|
19493
19493
|
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){}//---- PICKING ----------------------------------------------------------------------------------------------------
|
|
19494
|
-
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.modelMatrixCol0Buf){state.modelMatrixCol0Buf.destroy();state.modelMatrixCol0Buf=null;}if(state.modelMatrixCol1Buf){state.modelMatrixCol1Buf.destroy();state.modelMatrixCol1Buf=null;}if(state.modelMatrixCol2Buf){state.modelMatrixCol2Buf.destroy();state.modelMatrixCol2Buf=null;}state.destroy();}}]);return LinesInstancingLayer;}();var tempVec3a$
|
|
19494
|
+
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.modelMatrixCol0Buf){state.modelMatrixCol0Buf.destroy();state.modelMatrixCol0Buf=null;}if(state.modelMatrixCol1Buf){state.modelMatrixCol1Buf.destroy();state.modelMatrixCol1Buf=null;}if(state.modelMatrixCol2Buf){state.modelMatrixCol2Buf.destroy();state.modelMatrixCol2Buf=null;}state.destroy();}}]);return LinesInstancingLayer;}();var tempVec3a$l=math.vec3();/**
|
|
19495
19495
|
* @private
|
|
19496
|
-
*/var PointsBatchingColorRenderer=/*#__PURE__*/function(){function PointsBatchingColorRenderer(scene){_classCallCheck(this,PointsBatchingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=pointsBatchingLayer.model;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19496
|
+
*/var PointsBatchingColorRenderer=/*#__PURE__*/function(){function PointsBatchingColorRenderer(scene){_classCallCheck(this,PointsBatchingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=pointsBatchingLayer.model;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$l);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,pointsBatchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);frameCtx.drawArrays++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var pointsMaterial=scene.pointsMaterial._state;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader(scene));if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i430=0,len=scene._sectionPlanesState.sectionPlanes.length;_i430<len;_i430++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i430),pos:program.getLocation("sectionPlanePos"+_i430),dir:program.getLocation("sectionPlaneDir"+_i430)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(pointsMaterial.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var project=scene.camera.project;program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial;var src=[];src.push('#version 300 es');src.push("// Points batching color vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(pointsMaterial.filterIntensity){src.push("uniform vec2 intensityRange;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19497
19497
|
// renderPass = COLOR_OPAQUE
|
|
19498
19498
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19499
19499
|
src.push("} else {");if(pointsMaterial.filterIntensity){src.push("float intensity = float(color.a) / 255.0;");src.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19500
|
-
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");if(pointsMaterial.filterIntensity){src.push("}");}src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching color 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;");src.push("in vec4 vFlags2;");for(var _i431=0,len=sectionPlanesState.sectionPlanes.length;_i431<len;_i431++){src.push("uniform bool sectionPlaneActive"+_i431+";");src.push("uniform vec3 sectionPlanePos"+_i431+";");src.push("uniform vec3 sectionPlaneDir"+_i431+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i432=0,_len102=sectionPlanesState.sectionPlanes.length;_i432<_len102;_i432++){src.push("if (sectionPlaneActive"+_i432+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i432+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i432+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingColorRenderer;}();var defaultColor=new Float32Array([1,1,1]);var tempVec3a$
|
|
19500
|
+
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");if(pointsMaterial.filterIntensity){src.push("}");}src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching color 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;");src.push("in vec4 vFlags2;");for(var _i431=0,len=sectionPlanesState.sectionPlanes.length;_i431<len;_i431++){src.push("uniform bool sectionPlaneActive"+_i431+";");src.push("uniform vec3 sectionPlanePos"+_i431+";");src.push("uniform vec3 sectionPlaneDir"+_i431+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i432=0,_len102=sectionPlanesState.sectionPlanes.length;_i432<_len102;_i432++){src.push("if (sectionPlaneActive"+_i432+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i432+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i432+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingColorRenderer;}();var defaultColor=new Float32Array([1,1,1]);var tempVec3a$k=math.vec3();/**
|
|
19501
19501
|
* @private
|
|
19502
|
-
*/var PointsBatchingSilhouetteRenderer=/*#__PURE__*/function(){function PointsBatchingSilhouetteRenderer(scene){_classCallCheck(this,PointsBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material17=scene.highlightMaterial._state;var _fillColor11=_material17.fillColor;var _fillAlpha11=_material17.fillAlpha;gl.uniform4f(this._uColor,_fillColor11[0],_fillColor11[1],_fillColor11[2],_fillAlpha11);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material18=scene.selectedMaterial._state;var _fillColor12=_material18.fillColor;var _fillAlpha12=_material18.fillAlpha;gl.uniform4f(this._uColor,_fillColor12[0],_fillColor12[1],_fillColor12[2],_fillAlpha12);}else{gl.uniform4fv(this._uColor,defaultColor);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19502
|
+
*/var PointsBatchingSilhouetteRenderer=/*#__PURE__*/function(){function PointsBatchingSilhouetteRenderer(scene){_classCallCheck(this,PointsBatchingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material17=scene.highlightMaterial._state;var _fillColor11=_material17.fillColor;var _fillAlpha11=_material17.fillAlpha;gl.uniform4f(this._uColor,_fillColor11[0],_fillColor11[1],_fillColor11[2],_fillAlpha11);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material18=scene.selectedMaterial._state;var _fillColor12=_material18.fillColor;var _fillAlpha12=_material18.fillAlpha;gl.uniform4f(this._uColor,_fillColor12[0],_fillColor12[1],_fillColor12[2],_fillAlpha12);}else{gl.uniform4fv(this._uColor,defaultColor);}var viewMat=origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMat);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$k);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,pointsBatchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uColor=program.getLocation("color");this._uSectionPlanes=[];for(var _i433=0,len=scene._sectionPlanesState.sectionPlanes.length;_i433<len;_i433++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i433),pos:program.getLocation("sectionPlanePos"+_i433),dir:program.getLocation("sectionPlaneDir"+_i433)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform vec4 color;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | SILHOUETTE_XRAYED
|
|
19503
19503
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19504
19504
|
src.push("if (int(flags.y) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19505
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching silhouette vertex 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;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("uniform vec4 color;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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 = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = color;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingSilhouetteRenderer;}();var tempVec3a$
|
|
19505
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching silhouette vertex 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;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("uniform vec4 color;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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 = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = color;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingSilhouetteRenderer;}();var tempVec3a$j=math.vec3();/**
|
|
19506
19506
|
* @private
|
|
19507
19507
|
*/var PointsBatchingPickMeshRenderer=/*#__PURE__*/function(){function PointsBatchingPickMeshRenderer(scene){_classCallCheck(this,PointsBatchingPickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingPickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate(pointsBatchingLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19508
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19508
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,pointsBatchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}if(this._aPickColor){this._aPickColor.bindArrayBuffer(state.pickColorsBuf);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i434=0,len=scene._sectionPlanesState.sectionPlanes.length;_i434<len;_i434++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i434),pos:program.getLocation("sectionPlanePos"+_i434),dir:program.getLocation("sectionPlaneDir"+_i434)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aPickColor=program.getAttribute("pickColor");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;this._program.bind();gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19509
19509
|
// renderPass = PICK
|
|
19510
19510
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19511
|
-
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex 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;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingPickMeshRenderer;}();var tempVec3a$
|
|
19511
|
+
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex 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;");src.push("in vec4 vFlags2;");for(var i=0;i<sectionPlanesState.sectionPlanes.length;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingPickMeshRenderer;}();var tempVec3a$i=math.vec3();/**
|
|
19512
19512
|
* @private
|
|
19513
19513
|
*/var PointsBatchingPickDepthRenderer=/*#__PURE__*/function(){function PointsBatchingPickDepthRenderer(scene){_classCallCheck(this,PointsBatchingPickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingPickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19514
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19514
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}//=============================================================
|
|
19515
19515
|
// TODO: Use drawElements count and offset to draw only one entity
|
|
19516
19516
|
//=============================================================
|
|
19517
19517
|
gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,pointsBatchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i435=0,len=scene._sectionPlanesState.sectionPlanes.length;_i435<len;_i435++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i435),pos:program.getLocation("sectionPlanePos"+_i435),dir:program.getLocation("sectionPlaneDir"+_i435)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19518
19518
|
// renderPass = PICK
|
|
19519
19519
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19520
19520
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth 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;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i436=0;_i436<sectionPlanesState.sectionPlanes.length;_i436++){src.push("uniform bool sectionPlaneActive"+_i436+";");src.push("uniform vec3 sectionPlanePos"+_i436+";");src.push("uniform vec3 sectionPlaneDir"+_i436+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 packDepth(const in float depth) {");src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);");src.push(" vec4 res = fract(depth * bitShift);");src.push(" res -= res.xxyz * bitMask;");src.push(" return res;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");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; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth
|
|
19521
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingPickDepthRenderer;}();var tempVec3a$
|
|
19521
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsBatchingPickDepthRenderer;}();var tempVec3a$h=math.vec3();/**
|
|
19522
19522
|
* @private
|
|
19523
|
-
*/var PointsBatchingOcclusionRenderer=/*#__PURE__*/function(){function PointsBatchingOcclusionRenderer(scene){_classCallCheck(this,PointsBatchingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var camera=scene.camera;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate(pointsBatchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19523
|
+
*/var PointsBatchingOcclusionRenderer=/*#__PURE__*/function(){function PointsBatchingOcclusionRenderer(scene){_classCallCheck(this,PointsBatchingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsBatchingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,pointsBatchingLayer,renderPass){var model=pointsBatchingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=pointsBatchingLayer._state;var camera=scene.camera;var origin=pointsBatchingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;if(!this._program){this._allocate(pointsBatchingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=pointsBatchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,pointsBatchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}this._aFlags.bindArrayBuffer(state.flagsBuf);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19524
19524
|
this._aFlags2.bindArrayBuffer(state.flags2Buf);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i437=0,len=scene._sectionPlanesState.sectionPlanes.length;_i437<len;_i437++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i437),pos:program.getLocation("sectionPlanePos"+_i437),dir:program.getLocation("sectionPlaneDir"+_i437)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19525
19525
|
// renderPass = COLOR_OPAQUE
|
|
19526
19526
|
// Only opaque objects can be occluders
|
|
@@ -19533,7 +19533,7 @@ src.push("}");return src;}},{key:"webglContextRestored",value:function webglCont
|
|
|
19533
19533
|
*/function getPointsBatchingRenderers(scene){var sceneId=scene.id;var renderers=cachedRenderers$1[sceneId];if(!renderers){renderers=new PointsBatchingRenderers(scene);cachedRenderers$1[sceneId]=renderers;renderers._compile();scene.on("compile",function(){renderers._compile();});scene.on("destroyed",function(){delete cachedRenderers$1[sceneId];renderers._destroy();});}return renderers;}/**
|
|
19534
19534
|
* @private
|
|
19535
19535
|
*/var PointsBatchingBuffer=/*#__PURE__*/_createClass(function PointsBatchingBuffer(){var maxGeometryBatchSize=arguments.length>0&&arguments[0]!==undefined?arguments[0]:5000000;_classCallCheck(this,PointsBatchingBuffer);if(maxGeometryBatchSize>5000000){maxGeometryBatchSize=5000000;}this.maxVerts=maxGeometryBatchSize;this.maxIndices=maxGeometryBatchSize*3;// Rough rule-of-thumb
|
|
19536
|
-
this.positions=[];this.colors=[];this.intensities=[];this.pickColors=[];this.flags=[];this.flags2=[];this.offsets=[];});var tempVec3a$
|
|
19536
|
+
this.positions=[];this.colors=[];this.intensities=[];this.pickColors=[];this.flags=[];this.flags2=[];this.offsets=[];});var tempVec3a$g=math.vec4();var tempVec3b$5=math.vec4();var tempVec4a$6=math.vec4([0,0,0,1]);var tempVec4b$6=math.vec4([0,0,0,1]);var tempVec4c$3=math.vec4([0,0,0,1]);var tempOBB3=math.OBB3();/**
|
|
19537
19537
|
* @private
|
|
19538
19538
|
*/var PointsBatchingLayer=/*#__PURE__*/function(){/**
|
|
19539
19539
|
* @param model
|
|
@@ -19577,7 +19577,7 @@ this._portions=[];this._finalized=false;if(cfg.positionsDecodeMatrix){this._stat
|
|
|
19577
19577
|
* @param cfg.worldAABB Flat float AABB World-space AABB
|
|
19578
19578
|
* @param cfg.pickColor Quantized pick color
|
|
19579
19579
|
* @returns {number} Portion ID
|
|
19580
|
-
*/},{key:"createPortion",value:function createPortion(cfg){if(this._finalized){throw"Already finalized";}var positions=cfg.positions;var positionsCompressed=cfg.positionsCompressed;var color=cfg.color;var colorsCompressed=cfg.colorsCompressed;var colors=cfg.colors;var meshMatrix=cfg.meshMatrix;var worldMatrix=cfg.worldMatrix;var worldAABB=cfg.worldAABB;var pickColor=cfg.pickColor;var buffer=this._buffer;var positionsIndex=buffer.positions.length;var vertsIndex=positionsIndex/3;var numVerts;if(this._preCompressedPositionsExpected){if(!positionsCompressed){throw"positionsCompressed expected";}for(var _i440=0,len=positionsCompressed.length;_i440<len;_i440++){buffer.positions.push(positionsCompressed[_i440]);}var bounds=geometryCompressionUtils.getPositionsBounds(positionsCompressed);var min=geometryCompressionUtils.decompressPosition(bounds.min,this._state.positionsDecodeMatrix,tempVec3a$
|
|
19580
|
+
*/},{key:"createPortion",value:function createPortion(cfg){if(this._finalized){throw"Already finalized";}var positions=cfg.positions;var positionsCompressed=cfg.positionsCompressed;var color=cfg.color;var colorsCompressed=cfg.colorsCompressed;var colors=cfg.colors;var meshMatrix=cfg.meshMatrix;var worldMatrix=cfg.worldMatrix;var worldAABB=cfg.worldAABB;var pickColor=cfg.pickColor;var buffer=this._buffer;var positionsIndex=buffer.positions.length;var vertsIndex=positionsIndex/3;var numVerts;if(this._preCompressedPositionsExpected){if(!positionsCompressed){throw"positionsCompressed expected";}for(var _i440=0,len=positionsCompressed.length;_i440<len;_i440++){buffer.positions.push(positionsCompressed[_i440]);}var bounds=geometryCompressionUtils.getPositionsBounds(positionsCompressed);var min=geometryCompressionUtils.decompressPosition(bounds.min,this._state.positionsDecodeMatrix,tempVec3a$g);var _max3=geometryCompressionUtils.decompressPosition(bounds.max,this._state.positionsDecodeMatrix,tempVec3b$5);worldAABB[0]=min[0];worldAABB[1]=min[1];worldAABB[2]=min[2];worldAABB[3]=_max3[0];worldAABB[4]=_max3[1];worldAABB[5]=_max3[2];if(worldMatrix){math.AABB3ToOBB3(worldAABB,tempOBB3);math.transformOBB3(worldMatrix,tempOBB3);math.OBB3ToAABB3(tempOBB3,worldAABB);}numVerts=positionsCompressed.length/3;}else{if(!positions){throw"positions expected";}numVerts=positions.length/3;var lenPositions=positions.length;var positionsBase=buffer.positions.length;for(var _i441=0,_len103=positions.length;_i441<_len103;_i441++){buffer.positions.push(positions[_i441]);}if(meshMatrix){for(var _i442=positionsBase,_len104=positionsBase+lenPositions;_i442<_len104;_i442+=3){tempVec4a$6[0]=buffer.positions[_i442+0];tempVec4a$6[1]=buffer.positions[_i442+1];tempVec4a$6[2]=buffer.positions[_i442+2];math.transformPoint4(meshMatrix,tempVec4a$6,tempVec4b$6);buffer.positions[_i442+0]=tempVec4b$6[0];buffer.positions[_i442+1]=tempVec4b$6[1];buffer.positions[_i442+2]=tempVec4b$6[2];math.expandAABB3Point3(this._modelAABB,tempVec4b$6);if(worldMatrix){math.transformPoint4(worldMatrix,tempVec4b$6,tempVec4c$3);math.expandAABB3Point3(worldAABB,tempVec4c$3);}else{math.expandAABB3Point3(worldAABB,tempVec4b$6);}}}else{for(var _i443=positionsBase,_len105=positionsBase+lenPositions;_i443<_len105;_i443+=3){tempVec4a$6[0]=buffer.positions[_i443+0];tempVec4a$6[1]=buffer.positions[_i443+1];tempVec4a$6[2]=buffer.positions[_i443+2];math.expandAABB3Point3(this._modelAABB,tempVec4a$6);if(worldMatrix){math.transformPoint4(worldMatrix,tempVec4a$6,tempVec4b$6);math.expandAABB3Point3(worldAABB,tempVec4b$6);}else{math.expandAABB3Point3(worldAABB,tempVec4a$6);}}}}if(this._state.origin){var origin=this._state.origin;worldAABB[0]+=origin[0];worldAABB[1]+=origin[1];worldAABB[2]+=origin[2];worldAABB[3]+=origin[0];worldAABB[4]+=origin[1];worldAABB[5]+=origin[2];}math.expandAABB3(this.aabb,worldAABB);if(colorsCompressed){for(var _i444=0,_len106=colorsCompressed.length;_i444<_len106;_i444++){buffer.colors.push(colorsCompressed[_i444]);}}else if(colors){for(var _i445=0,_len107=colors.length;_i445<_len107;_i445++){buffer.colors.push(colors[_i445]*255);}}else if(color){var _r4=color[0];// Color is pre-quantized by VBOSceneModel
|
|
19581
19581
|
var g=color[1];var b=color[2];var _a4=1.0;for(var _i446=0;_i446<numVerts;_i446++){buffer.colors.push(_r4);buffer.colors.push(g);buffer.colors.push(b);buffer.colors.push(_a4);}}{var pickColorsBase=buffer.pickColors.length;var lenPickColors=numVerts*4;for(var _i447=pickColorsBase,_len108=pickColorsBase+lenPickColors;_i447<_len108;_i447+=4){buffer.pickColors.push(pickColor[0]);buffer.pickColors.push(pickColor[1]);buffer.pickColors.push(pickColor[2]);buffer.pickColors.push(pickColor[3]);}}if(this.model.scene.entityOffsetsEnabled){for(var _i448=0;_i448<numVerts;_i448++){buffer.offsets.push(0);buffer.offsets.push(0);buffer.offsets.push(0);}}var portionId=this._portions.length/2;this._portions.push(vertsIndex);this._portions.push(numVerts);this._numPortions++;this.model.numPortions++;return portionId;}/**
|
|
19582
19582
|
* Builds batch VBOs from appended geometries.
|
|
19583
19583
|
* No more portions can then be created.
|
|
@@ -19598,61 +19598,61 @@ return;}var portionsIdx=portionId*2;var vertexBase=this._portions[portionsIdx];v
|
|
|
19598
19598
|
},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){}},{key:"drawEdgesColorTransparent",value:function drawEdgesColorTransparent(renderFlags,frameCtx){}},{key:"drawEdgesHighlighted",value:function drawEdgesHighlighted(renderFlags,frameCtx){}},{key:"drawEdgesSelected",value:function drawEdgesSelected(renderFlags,frameCtx){}},{key:"drawEdgesXRayed",value:function drawEdgesXRayed(renderFlags,frameCtx){}//---- PICKING ----------------------------------------------------------------------------------------------------
|
|
19599
19599
|
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}if(this._pointsBatchingRenderers.pickMeshRenderer){this._pointsBatchingRenderers.pickMeshRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}if(this._pointsBatchingRenderers.pickDepthRenderer){this._pointsBatchingRenderers.pickDepthRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){}//---- OCCLUSION TESTING -------------------------------------------------------------------------------------------
|
|
19600
19600
|
},{key:"drawOcclusion",value:function drawOcclusion(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}if(this._pointsBatchingRenderers.occlusionRenderer){this._pointsBatchingRenderers.occlusionRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}//---- SHADOWS -----------------------------------------------------------------------------------------------------
|
|
19601
|
-
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}state.destroy();}}]);return PointsBatchingLayer;}();var tempVec3a$
|
|
19601
|
+
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){}},{key:"destroy",value:function destroy(){var state=this._state;if(state.positionsBuf){state.positionsBuf.destroy();state.positionsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.flags2Buf){state.flags2Buf.destroy();state.flags2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}state.destroy();}}]);return PointsBatchingLayer;}();var tempVec3a$f=math.vec3();/**
|
|
19602
19602
|
* @private
|
|
19603
|
-
*/var PointsInstancingColorRenderer=/*#__PURE__*/function(){function PointsInstancingColorRenderer(scene){_classCallCheck(this,PointsInstancingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aColor.bindArrayBuffer(geometry.colorsBuf);if(pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19603
|
+
*/var PointsInstancingColorRenderer=/*#__PURE__*/function(){function PointsInstancingColorRenderer(scene){_classCallCheck(this,PointsInstancingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aColor.bindArrayBuffer(geometry.colorsBuf);if(pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);frameCtx.drawArrays++;gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19604
19604
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var pointsMaterial=scene.pointsMaterial._state;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i453=0,len=scene._sectionPlanesState.sectionPlanes.length;_i453<len;_i453++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i453),pos:program.getLocation("sectionPlanePos"+_i453),dir:program.getLocation("sectionPlaneDir"+_i453)});}this._aPosition=program.getAttribute("position");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aOffset=program.getAttribute("offset");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uOcclusionTexture="uOcclusionTexture";this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(pointsMaterial.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing color vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19605
19605
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(pointsMaterial.filterIntensity){src.push("uniform vec2 intensityRange;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19606
19606
|
// renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19607
19607
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19608
19608
|
src.push("} else {");if(pointsMaterial.filterIntensity){src.push("float intensity = float(color.a) / 255.0;");src.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19609
|
-
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");if(pointsMaterial.filterIntensity){src.push("}");}src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing color 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;");src.push("in vec4 vFlags2;");for(var _i454=0,len=sectionPlanesState.sectionPlanes.length;_i454<len;_i454++){src.push("uniform bool sectionPlaneActive"+_i454+";");src.push("uniform vec3 sectionPlanePos"+_i454+";");src.push("uniform vec3 sectionPlaneDir"+_i454+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i455=0,_len109=sectionPlanesState.sectionPlanes.length;_i455<_len109;_i455++){src.push("if (sectionPlaneActive"+_i455+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i455+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i455+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingColorRenderer;}();var tempVec3a$
|
|
19609
|
+
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("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");if(pointsMaterial.filterIntensity){src.push("}");}src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing color 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;");src.push("in vec4 vFlags2;");for(var _i454=0,len=sectionPlanesState.sectionPlanes.length;_i454<len;_i454++){src.push("uniform bool sectionPlaneActive"+_i454+";");src.push("uniform vec3 sectionPlanePos"+_i454+";");src.push("uniform vec3 sectionPlaneDir"+_i454+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i455=0,_len109=sectionPlanesState.sectionPlanes.length;_i455<_len109;_i455++){src.push("if (sectionPlaneActive"+_i455+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i455+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i455+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}src.push(" outColor = vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingColorRenderer;}();var tempVec3a$e=math.vec3();/**
|
|
19610
19610
|
* @private
|
|
19611
|
-
*/var PointsInstancingSilhouetteRenderer=/*#__PURE__*/function(){function PointsInstancingSilhouetteRenderer(scene){_classCallCheck(this,PointsInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material19=scene.highlightMaterial._state;var _fillColor13=_material19.fillColor;var _fillAlpha13=_material19.fillAlpha;gl.uniform4f(this._uColor,_fillColor13[0],_fillColor13[1],_fillColor13[2],_fillAlpha13);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material20=scene.selectedMaterial._state;var _fillColor14=_material20.fillColor;var _fillAlpha14=_material20.fillAlpha;gl.uniform4f(this._uColor,_fillColor14[0],_fillColor14[1],_fillColor14[2],_fillAlpha14);}else{gl.uniform4fv(this._uColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19611
|
+
*/var PointsInstancingSilhouetteRenderer=/*#__PURE__*/function(){function PointsInstancingSilhouetteRenderer(scene){_classCallCheck(this,PointsInstancingSilhouetteRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingSilhouetteRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate(instancingLayer.model.scene);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);if(renderPass===RENDER_PASSES.SILHOUETTE_XRAYED){var material=scene.xrayMaterial._state;var fillColor=material.fillColor;var fillAlpha=material.fillAlpha;gl.uniform4f(this._uColor,fillColor[0],fillColor[1],fillColor[2],fillAlpha);}else if(renderPass===RENDER_PASSES.SILHOUETTE_HIGHLIGHTED){var _material19=scene.highlightMaterial._state;var _fillColor13=_material19.fillColor;var _fillAlpha13=_material19.fillAlpha;gl.uniform4f(this._uColor,_fillColor13[0],_fillColor13[1],_fillColor13[2],_fillAlpha13);}else if(renderPass===RENDER_PASSES.SILHOUETTE_SELECTED){var _material20=scene.selectedMaterial._state;var _fillColor14=_material20.fillColor;var _fillAlpha14=_material20.fillAlpha;gl.uniform4f(this._uColor,_fillColor14[0],_fillColor14[1],_fillColor14[2],_fillAlpha14);}else{gl.uniform4fv(this._uColor,math.vec3([1,1,1]));}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf,gl.UNSIGNED_BYTE,true);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);// TODO: Is this needed
|
|
19612
19612
|
gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uColor=program.getLocation("silhouetteColor");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i456=0,len=clips.length;_i456<len;_i456++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i456),pos:program.getLocation("sectionPlanePos"+_i456),dir:program.getLocation("sectionPlaneDir"+_i456)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing silhouette vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 color;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19613
19613
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}src.push("uniform vec4 silhouetteColor;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vColor;");src.push("void main(void) {");// flags.y = NOT_RENDERED | SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19614
19614
|
// renderPass = SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | | SILHOUETTE_XRAYED
|
|
19615
19615
|
src.push("if (int(flags.y) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19616
|
-
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);");src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing silhouette 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;");src.push("in vec4 vFlags2;");for(var _i457=0,len=sectionPlanesState.sectionPlanes.length;_i457<len;_i457++){src.push("uniform bool sectionPlaneActive"+_i457+";");src.push("uniform vec3 sectionPlanePos"+_i457+";");src.push("uniform vec3 sectionPlaneDir"+_i457+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i458=0,_len110=sectionPlanesState.sectionPlanes.length;_i458<_len110;_i458++){src.push("if (sectionPlaneActive"+_i458+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i458+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i458+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vColor;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingSilhouetteRenderer;}();var tempVec3a$
|
|
19616
|
+
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);");src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing silhouette 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;");src.push("in vec4 vFlags2;");for(var _i457=0,len=sectionPlanesState.sectionPlanes.length;_i457<len;_i457++){src.push("uniform bool sectionPlaneActive"+_i457+";");src.push("uniform vec3 sectionPlanePos"+_i457+";");src.push("uniform vec3 sectionPlaneDir"+_i457+";");}}src.push("in vec4 vColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i458=0,_len110=sectionPlanesState.sectionPlanes.length;_i458<_len110;_i458++){src.push("if (sectionPlaneActive"+_i458+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i458+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i458+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vColor;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingSilhouetteRenderer;}();var tempVec3a$d=math.vec3();/**
|
|
19617
19617
|
* @private
|
|
19618
19618
|
*/var PointsInstancingPickMeshRenderer=/*#__PURE__*/function(){function PointsInstancingPickMeshRenderer(scene){_classCallCheck(this,PointsInstancingPickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingPickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
19619
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPickColor.bindArrayBuffer(state.pickColorsBuf);gl.vertexAttribDivisor(this._aPickColor.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19619
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPickColor.bindArrayBuffer(state.pickColorsBuf);gl.vertexAttribDivisor(this._aPickColor.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$d);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);// Cleanup
|
|
19620
19620
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aPickColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19621
19621
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i459=0,len=clips.length;_i459<len;_i459++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i459),pos:program.getLocation("sectionPlanePos"+_i459),dir:program.getLocation("sectionPlaneDir"+_i459)});}this._uRenderPass=program.getLocation("renderPass");this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aPickColor=program.getAttribute("pickColor");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 pickColor;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19622
19622
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19623
19623
|
// renderPass = PICK
|
|
19624
19624
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19625
|
-
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh 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;");src.push("in vec4 vFlags2;");for(var _i460=0;_i460<sectionPlanesState.sectionPlanes.length;_i460++){src.push("uniform bool sectionPlaneActive"+_i460+";");src.push("uniform vec3 sectionPlanePos"+_i460+";");src.push("uniform vec3 sectionPlaneDir"+_i460+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i461=0;_i461<sectionPlanesState.sectionPlanes.length;_i461++){src.push("if (sectionPlaneActive"+_i461+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i461+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i461+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingPickMeshRenderer;}();var tempVec3a$
|
|
19625
|
+
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(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh 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;");src.push("in vec4 vFlags2;");for(var _i460=0;_i460<sectionPlanesState.sectionPlanes.length;_i460++){src.push("uniform bool sectionPlaneActive"+_i460+";");src.push("uniform vec3 sectionPlanePos"+_i460+";");src.push("uniform vec3 sectionPlaneDir"+_i460+";");}}src.push("in vec4 vPickColor;");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i461=0;_i461<sectionPlanesState.sectionPlanes.length;_i461++){src.push("if (sectionPlaneActive"+_i461+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i461+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i461+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingPickMeshRenderer;}();var tempVec3a$c=math.vec3();/**
|
|
19626
19626
|
* @private
|
|
19627
19627
|
*/var PointsInstancingPickDepthRenderer=/*#__PURE__*/function(){function PointsInstancingPickDepthRenderer(scene){_classCallCheck(this,PointsInstancingPickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingPickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate(instancingLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}var camera=scene.camera;gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var rtcPickViewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,rtcPickViewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix
|
|
19628
|
-
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19628
|
+
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$c);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(geometry.positionsBuf);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);// Cleanup
|
|
19629
19629
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19630
19630
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i462=0,len=scene._sectionPlanesState.sectionPlanes.length;_i462<len;_i462++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i462),pos:program.getLocation("sectionPlanePos"+_i462),dir:program.getLocation("sectionPlaneDir"+_i462)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){this._program.bind();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19631
19631
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// flags.w = NOT_RENDERED | PICK
|
|
19632
19632
|
// renderPass = PICK
|
|
19633
19633
|
src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19634
19634
|
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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick depth 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;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i463=0;_i463<sectionPlanesState.sectionPlanes.length;_i463++){src.push("uniform bool sectionPlaneActive"+_i463+";");src.push("uniform vec3 sectionPlanePos"+_i463+";");src.push("uniform vec3 sectionPlaneDir"+_i463+";");}}src.push("in vec4 vViewPosition;");src.push("vec4 packDepth(const in float depth) {");src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);");src.push(" vec4 res = fract(depth * bitShift);");src.push(" res -= res.xxyz * bitMask;");src.push(" return res;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i464=0;_i464<sectionPlanesState.sectionPlanes.length;_i464++){src.push("if (sectionPlaneActive"+_i464+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i464+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i464+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth
|
|
19635
|
-
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingPickDepthRenderer;}();var tempVec3a$
|
|
19635
|
+
src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingPickDepthRenderer;}();var tempVec3a$b=math.vec3();/**
|
|
19636
19636
|
* @private
|
|
19637
|
-
*/var PointsInstancingOcclusionRenderer=/*#__PURE__*/function(){function PointsInstancingOcclusionRenderer(scene){_classCallCheck(this,PointsInstancingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19637
|
+
*/var PointsInstancingOcclusionRenderer=/*#__PURE__*/function(){function PointsInstancingOcclusionRenderer(scene){_classCallCheck(this,PointsInstancingOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$b);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);if(this._aColor){this._aColor.bindArrayBuffer(geometry.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);}this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);// Cleanup
|
|
19638
19638
|
gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);if(this._aColor){gl.vertexAttribDivisor(this._aColor.location,0);}gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19639
19639
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i465=0,len=clips.length;_i465<len;_i465++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i465),pos:program.getLocation("sectionPlanePos"+_i465),dir:program.getLocation("sectionPlaneDir"+_i465)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
19640
19640
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19641
19641
|
// renderPass = COLOR_OPAQUE
|
|
19642
19642
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");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; ");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing occlusion vertex 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;");src.push("in vec4 vFlags2;");for(var _i466=0;_i466<sectionPlanesState.sectionPlanes.length;_i466++){src.push("uniform bool sectionPlaneActive"+_i466+";");src.push("uniform vec3 sectionPlanePos"+_i466+";");src.push("uniform vec3 sectionPlaneDir"+_i466+";");}}src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i467=0;_i467<sectionPlanesState.sectionPlanes.length;_i467++){src.push("if (sectionPlaneActive"+_i467+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i467+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i467+".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); ");// Occluders are blue
|
|
19643
|
-
if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingOcclusionRenderer;}();var tempVec3a$
|
|
19643
|
+
if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingOcclusionRenderer;}();var tempVec3a$a=math.vec3();/**
|
|
19644
19644
|
* @private
|
|
19645
|
-
*/var PointsInstancingDepthRenderer=/*#__PURE__*/function(){function PointsInstancingDepthRenderer(scene){_classCallCheck(this,PointsInstancingDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19645
|
+
*/var PointsInstancingDepthRenderer=/*#__PURE__*/function(){function PointsInstancingDepthRenderer(scene){_classCallCheck(this,PointsInstancingDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(PointsInstancingDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer,renderPass){var model=instancingLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=instancingLayer._state;var origin=instancingLayer._state.origin;var pointsMaterial=scene.pointsMaterial._state;var geometry=instancingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$a);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(geometry.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);gl.drawArraysInstanced(gl.POINTS,0,geometry.positionsBuf.numItems,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19646
19646
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i468=0,len=scene._sectionPlanesState.sectionPlanes.length;_i468<len;_i468++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i468),pos:program.getLocation("sectionPlanePos"+_i468),dir:program.getLocation("sectionPlaneDir"+_i468)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(){var scene=this._scene;var gl=scene.canvas.gl;var project=scene.camera.project;this._program.bind();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);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");// flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
19647
19647
|
// renderPass = COLOR_OPAQUE
|
|
19648
19648
|
src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19649
19649
|
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; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing depth vertex 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;");src.push("in vec4 vFlags2;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;i++){src.push("uniform bool sectionPlaneActive"+i+";");src.push("uniform vec3 sectionPlanePos"+i+";");src.push("uniform vec3 sectionPlaneDir"+i+";");}}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("const float shiftRight8 = 1.0 / 256.;");src.push("vec4 packDepthToRGBA( const in float v ) {");src.push(" vec4 r = vec4( fract( v * packFactors ), v );");src.push(" r.yzw -= r.xyz * shiftRight8;");src.push(" return r * packUpScale;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");if(scene.pointsMaterial.roundPoints){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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i<len;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 = packDepthToRGBA( gl_FragCoord.z); ");// Must be linear depth
|
|
19650
|
-
if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingDepthRenderer;}();var tempVec3a$
|
|
19650
|
+
if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingDepthRenderer;}();var tempVec3a$9=math.vec3();/**
|
|
19651
19651
|
* Renders InstancingLayer fragment depths to a shadow map.
|
|
19652
19652
|
*
|
|
19653
19653
|
* @private
|
|
19654
19654
|
*/var PointsInstancingShadowRenderer=/*#__PURE__*/function(){function PointsInstancingShadowRenderer(scene){_classCallCheck(this,PointsInstancingShadowRenderer);this._scene=scene;this._hash=this._getHash();this._lastLightId=null;this._allocate();}_createClass(PointsInstancingShadowRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,instancingLayer){var model=instancingLayer.model;var scene=model.scene;var gl=scene.canvas.gl;var state=instancingLayer._state;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx,instancingLayer);}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,geometry.positionsDecodeMatrix);this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,1);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,1);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);gl.vertexAttribDivisor(this._aOffset.location,1);}this._aColor.bindArrayBuffer(state.colorsBuf);gl.vertexAttribDivisor(this._aColor.location,1);this._aFlags.bindArrayBuffer(state.flagsBuf);gl.vertexAttribDivisor(this._aFlags.location,1);if(this._aFlags2){this._aFlags2.bindArrayBuffer(state.flags2Buf);gl.vertexAttribDivisor(this._aFlags2.location,1);}// TODO: Section planes need to be set if RTC center has changed since last RTC center recorded on frameCtx
|
|
19655
|
-
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=instancingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$
|
|
19655
|
+
var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=instancingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;var origin=instancingLayer._state.origin;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+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$9);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniform1f(this._uPointSize,10);gl.drawArraysInstanced(gl.POINTS,0,state.positionsBuf.numItems,state.numInstances);gl.vertexAttribDivisor(this._aModelMatrixCol0.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol1.location,0);gl.vertexAttribDivisor(this._aModelMatrixCol2.location,0);gl.vertexAttribDivisor(this._aColor.location,0);gl.vertexAttribDivisor(this._aFlags.location,0);if(this._aFlags2){// Won't be in shader when not clipping
|
|
19656
19656
|
gl.vertexAttribDivisor(this._aFlags2.location,0);}if(this._aOffset){gl.vertexAttribDivisor(this._aOffset.location,0);}}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;var sectionPlanesState=scene._sectionPlanesState;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uShadowViewMatrix=program.getLocation("shadowViewMatrix");this._uShadowProjMatrix=program.getLocation("shadowProjMatrix");this._uSectionPlanes=[];var clips=sectionPlanesState.sectionPlanes;for(var _i469=0,len=clips.length;_i469<len;_i469++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i469),pos:program.getLocation("sectionPlanePos"+_i469),dir:program.getLocation("sectionPlaneDir"+_i469)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");this._aFlags2=program.getAttribute("flags2");this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._uPointSize=program.getLocation("pointSize");}},{key:"_bindProgram",value:function _bindProgram(frameCtx,instancingLayer){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;program.bind();gl.uniformMatrix4fv(this._uShadowViewMatrix,false,frameCtx.shadowViewMatrix);gl.uniformMatrix4fv(this._uShadowProjMatrix,false,frameCtx.shadowProjMatrix);this._lastLightId=null;}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Instancing geometry shadow drawing vertex shader");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in vec4 flags;");src.push("in vec4 flags2;");src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform mat4 shadowViewMatrix;");src.push("uniform mat4 shadowProjMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");src.push("uniform float pointSize;");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out vec4 vFlags2;");}src.push("void main(void) {");src.push("bool visible = (float(flags.x) > 0.0);");src.push("bool transparent = ((float(color.a) / 255.0) < 1.0);");src.push("if (!visible || transparent) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex
|
|
19657
19657
|
src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = 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 = shadowViewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags2 = flags2;");}src.push(" gl_Position = shadowProjMatrix * viewPosition;");src.push("}");src.push("gl_PointSize = pointSize;");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Instancing geometry depth 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("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i470=0,len=sectionPlanesState.sectionPlanes.length;_i470<len;_i470++){src.push("uniform bool sectionPlaneActive"+_i470+";");src.push("uniform vec3 sectionPlanePos"+_i470+";");src.push("uniform vec3 sectionPlaneDir"+_i470+";");}}src.push("in vec3 vViewNormal;");src.push("vec3 packNormalToRGB( const in vec3 normal ) {");src.push(" return normalize( normal ) * 0.5 + 0.5;");src.push("}");src.push("out vec4 outColor;");src.push("void main(void) {");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(clipping){src.push(" bool clippable = (float(vFlags2.x) > 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i471=0,_len111=sectionPlanesState.sectionPlanes.length;_i471<_len111;_i471++){src.push("if (sectionPlaneActive"+_i471+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i471+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i471+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return PointsInstancingShadowRenderer;}();/**
|
|
19658
19658
|
* @private
|
|
@@ -20132,7 +20132,7 @@ var FORMAT_OPTIONS=[{"if":'astcSupported',basisFormat:[BasisFormat.UASTC_4x4],tr
|
|
|
20132
20132
|
* The ````transcoderPath```` config will be set to: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/"
|
|
20133
20133
|
*
|
|
20134
20134
|
* @private
|
|
20135
|
-
*/function getKTX2TextureTranscoder(viewer){var sceneId=viewer.scene.id;var transcoder=cachedTranscoders[sceneId];if(!transcoder){transcoder=new KTX2TextureTranscoder({viewer:viewer});cachedTranscoders[sceneId]=transcoder;viewer.scene.on("destroyed",function(){delete cachedTranscoders[sceneId];transcoder.destroy();});}return transcoder;}var tempVec3a$
|
|
20135
|
+
*/function getKTX2TextureTranscoder(viewer){var sceneId=viewer.scene.id;var transcoder=cachedTranscoders[sceneId];if(!transcoder){transcoder=new KTX2TextureTranscoder({viewer:viewer});cachedTranscoders[sceneId]=transcoder;viewer.scene.on("destroyed",function(){delete cachedTranscoders[sceneId];transcoder.destroy();});}return transcoder;}var tempVec3a$8=math.vec3();var tempMat4$1=math.mat4();var defaultScale=math.vec3([1,1,1]);var defaultPosition=math.vec3([0,0,0]);var defaultRotation=math.vec3([0,0,0]);var defaultQuaternion=math.identityQuaternion();var defaultColorTextureId="defaultColorTexture";var defaultMetalRoughTextureId="defaultMetalRoughTexture";var defaultNormalsTextureId="defaultNormalsTexture";var defaultEmissiveTextureId="defaultEmissiveTexture";var defaultOcclusionTextureId="defaultOcclusionTexture";var defaultTextureSetId="defaultTextureSet";/**
|
|
20136
20136
|
* @desc A high-performance model representation for efficient rendering and low memory usage.
|
|
20137
20137
|
*
|
|
20138
20138
|
* # Examples
|
|
@@ -21639,8 +21639,8 @@ if(!this._textureTranscoder){this.error("Can't create texture from 'buffers' - V
|
|
|
21639
21639
|
* @param {Number} [cfg.metallic=0] Metallic factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
|
|
21640
21640
|
* @param {Number} [cfg.roughness=1] Roughness factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````.
|
|
21641
21641
|
*/},{key:"createMesh",value:function createMesh(cfg){var id=cfg.id;if(id===undefined||id===null){this.error("Config missing: id");return;}if(this._meshes[id]){this.error("VBOSceneModel already has a mesh with this ID: ".concat(id));return;}var geometryId=cfg.geometryId;var sharingGeometry=cfg.geometryId!==undefined;if(sharingGeometry&&!this._geometries[cfg.geometryId]){this.error("Geometry not found: ".concat(cfg.geometryId," - ensure that you create it first with createGeometry()"));return;}var textureSetId=cfg.textureSetId||defaultTextureSetId;if(textureSetId){if(!this._textureSets[textureSetId]){this.error("Texture set not found: ".concat(textureSetId," - ensure that you create it first with createTextureSet()"));return;}}var portionId;var color=cfg.color?new Uint8Array([Math.floor(cfg.color[0]*255),Math.floor(cfg.color[1]*255),Math.floor(cfg.color[2]*255)]):[255,255,255];var opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;var metallic=cfg.metallic!==undefined&&cfg.metallic!==null?Math.floor(cfg.metallic*255):0;var roughness=cfg.roughness!==undefined&&cfg.roughness!==null?Math.floor(cfg.roughness*255):255;var mesh=new VBOSceneModelMesh(this,id,color,opacity);var pickId=mesh.pickId;var a=pickId>>24&0xFF;var b=pickId>>16&0xFF;var g=pickId>>8&0xFF;var r=pickId&0xFF;var pickColor=new Uint8Array([r,g,b,a]);// Quantized pick color
|
|
21642
|
-
var aabb=math.collapseAABB3();var layer;if(sharingGeometry){var meshMatrix;var worldMatrix=this._worldMatrixNonIdentity?this._worldMatrix:null;if(cfg.matrix){meshMatrix=cfg.matrix;}else{var _scale4=cfg.scale||defaultScale;var position=cfg.position||defaultPosition;var rotation=cfg.rotation||defaultRotation;math.eulerToQuaternion(rotation,"XYZ",defaultQuaternion);meshMatrix=math.composeMat4(position,defaultQuaternion,_scale4,tempMat4$1);}var cfgOrigin=cfg.origin||cfg.rtcCenter;var origin=cfgOrigin?math.addVec3(this._origin,cfgOrigin,tempVec3a$
|
|
21643
|
-
var primitive=cfg.primitive;if(primitive===undefined||primitive===null){primitive="triangles";}if(primitive!=="points"&&primitive!=="lines"&&primitive!=="triangles"&&primitive!=="solid"&&primitive!=="surface"){this.error("Unsupported value for 'primitive': '".concat(primitive,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'."));return;}if(!cfg.positions&&!cfg.positionsCompressed){this.error("Param expected: 'positions' or 'positionsCompressed' ('geometryId' is absent)");return null;}if(cfg.positions&&cfg.positionsCompressed){this.error("Only one param expected, not both: 'positions' or 'positionsCompressed' ('geometryId' is absent)");return null;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix){this.error("Param expected: 'positionsDecodeMatrix' (required for 'positionsCompressed'; 'geometryId' is absent)");return null;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("Param expected: `uvDecodeMatrix` (required for `uvCompressed'; 'geometryId' is absent)");return null;}if(!cfg.indices&&primitive!=="points"){this.error("Param expected: indices (required for '".concat(primitive,"' primitive type)"));return null;}if(!cfg.indices&&primitive!=="points"){this.error("Config expected: indices (no meshIds provided, so expecting geometry arrays instead)");return null;}var indices=cfg.indices;var edgeIndices=cfg.edgeIndices;var _origin=cfg.origin||cfg.rtcCenter?math.addVec3(this._origin,cfg.origin||cfg.rtcCenter,tempVec3a$
|
|
21642
|
+
var aabb=math.collapseAABB3();var layer;if(sharingGeometry){var meshMatrix;var worldMatrix=this._worldMatrixNonIdentity?this._worldMatrix:null;if(cfg.matrix){meshMatrix=cfg.matrix;}else{var _scale4=cfg.scale||defaultScale;var position=cfg.position||defaultPosition;var rotation=cfg.rotation||defaultRotation;math.eulerToQuaternion(rotation,"XYZ",defaultQuaternion);meshMatrix=math.composeMat4(position,defaultQuaternion,_scale4,tempMat4$1);}var cfgOrigin=cfg.origin||cfg.rtcCenter;var origin=cfgOrigin?math.addVec3(this._origin,cfgOrigin,tempVec3a$8):this._origin;var instancingLayer=this._getInstancingLayer(origin,textureSetId,geometryId);layer=instancingLayer;portionId=instancingLayer.createPortion({color:color,metallic:metallic,roughness:roughness,opacity:opacity,meshMatrix:meshMatrix,worldMatrix:worldMatrix,aabb:aabb,pickColor:pickColor});math.expandAABB3(this._aabb,aabb);var numTriangles=Math.round(instancingLayer.numIndices/3);this._numTriangles+=numTriangles;mesh.numTriangles=numTriangles;mesh.origin=origin;}else{// Batching
|
|
21643
|
+
var primitive=cfg.primitive;if(primitive===undefined||primitive===null){primitive="triangles";}if(primitive!=="points"&&primitive!=="lines"&&primitive!=="triangles"&&primitive!=="solid"&&primitive!=="surface"){this.error("Unsupported value for 'primitive': '".concat(primitive,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'."));return;}if(!cfg.positions&&!cfg.positionsCompressed){this.error("Param expected: 'positions' or 'positionsCompressed' ('geometryId' is absent)");return null;}if(cfg.positions&&cfg.positionsCompressed){this.error("Only one param expected, not both: 'positions' or 'positionsCompressed' ('geometryId' is absent)");return null;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix){this.error("Param expected: 'positionsDecodeMatrix' (required for 'positionsCompressed'; 'geometryId' is absent)");return null;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("Param expected: `uvDecodeMatrix` (required for `uvCompressed'; 'geometryId' is absent)");return null;}if(!cfg.indices&&primitive!=="points"){this.error("Param expected: indices (required for '".concat(primitive,"' primitive type)"));return null;}if(!cfg.indices&&primitive!=="points"){this.error("Config expected: indices (no meshIds provided, so expecting geometry arrays instead)");return null;}var indices=cfg.indices;var edgeIndices=cfg.edgeIndices;var _origin=cfg.origin||cfg.rtcCenter?math.addVec3(this._origin,cfg.origin||cfg.rtcCenter,tempVec3a$8):this._origin;var _positions11=cfg.positions;if(_positions11){var rtcCenter=math.vec3();var rtcPositions=[];var rtcNeeded=worldToRTCPositions(_positions11,rtcPositions,rtcCenter);if(rtcNeeded){_positions11=rtcPositions;_origin=math.addVec3(_origin,rtcCenter,rtcCenter);}}var needNewBatchingLayers=false;if(!this._lastOrigin){needNewBatchingLayers=true;this._lastOrigin=math.vec3(_origin);}else{if(!math.compareVec3(this._lastOrigin,_origin)){needNewBatchingLayers=true;this._lastOrigin.set(_origin);}}if(cfg.positionsDecodeMatrix){if(!this._lastPositionsDecodeMatrix){needNewBatchingLayers=true;this._lastPositionsDecodeMatrix=math.mat4(cfg.positionsDecodeMatrix);}else{if(!math.compareMat4(this._lastPositionsDecodeMatrix,cfg.positionsDecodeMatrix)){needNewBatchingLayers=true;this._lastPositionsDecodeMatrix.set(cfg.positionsDecodeMatrix);}}}if(cfg.uvDecodeMatrix){if(!this._lastUVDecodeMatrix){needNewBatchingLayers=true;this._lastUVDecodeMatrix=math.mat4(cfg.uvDecodeMatrix);}else{if(!math.compareMat4(this._lastUVDecodeMatrix,cfg.uvDecodeMatrix)){needNewBatchingLayers=true;this._lastUVDecodeMatrix.set(cfg.uvDecodeMatrix);}}}if(cfg.textureSetId){if(this._lastTextureSetId!==cfg.textureSetId){needNewBatchingLayers=true;this._lastTextureSetId=cfg.textureSetId;}}if(needNewBatchingLayers){for(var _primitiveId in this._currentBatchingLayers){if(this._currentBatchingLayers.hasOwnProperty(_primitiveId)){this._currentBatchingLayers[_primitiveId].finalize();}}this._currentBatchingLayers={};}var normalsProvided=!!cfg.normals&&cfg.normals.length>0;if(primitive==="triangles"||primitive==="solid"||primitive==="surface"){if(this._lastNormals!==null&&normalsProvided!==this._lastNormals){for(var _primitiveId2 in this._currentBatchingLayers){if(this._currentBatchingLayers[_primitiveId2]){this._currentBatchingLayers[_primitiveId2].finalize();delete this._currentBatchingLayers[_primitiveId2];}}}this._lastNormals=normalsProvided;}var _worldMatrix2=this._worldMatrixNonIdentity?this._worldMatrix:null;var _meshMatrix2;if(!cfg.positionsDecodeMatrix){if(cfg.matrix){_meshMatrix2=cfg.matrix;}else{var _scale5=cfg.scale||defaultScale;var _position2=cfg.position||defaultPosition;var _rotation2=cfg.rotation||defaultRotation;math.eulerToQuaternion(_rotation2,"XYZ",defaultQuaternion);_meshMatrix2=math.composeMat4(_position2,defaultQuaternion,_scale5,tempMat4$1);}}var textureSet=textureSetId?this._textureSets[textureSetId]:null;var primitiveId="".concat(primitive,"-").concat(cfg.normals&&cfg.normals.length>0?1:0,"-").concat(cfg.normalsCompressed&&cfg.normalsCompressed.length>0?1:0,"-").concat(cfg.colors&&cfg.colors.length>0?1:0,"-").concat(cfg.colorsCompressed&&cfg.colorsCompressed.length>0?1:0,"-").concat(cfg.uv&&cfg.uv.length>0?1:0,"-").concat(cfg.uvCompressed&&cfg.uvCompressed.length>0?1:0);layer=this._currentBatchingLayers[primitiveId];var lenPositions=(_positions11||cfg.positionsCompressed).length;switch(primitive){case"triangles":case"solid":case"surface":if(layer){if(!layer.canCreatePortion(lenPositions,indices.length)){layer.finalize();delete this._currentBatchingLayers[primitiveId];layer=null;}}if(!layer){layer=new TrianglesBatchingLayer({model:this,textureSet:textureSet,layerIndex:0,// This is set in #finalize()
|
|
21644
21644
|
scratchMemory:this._scratchMemory,positionsDecodeMatrix:cfg.positionsDecodeMatrix,// Can be undefined
|
|
21645
21645
|
uvDecodeMatrix:cfg.uvDecodeMatrix,// Can be undefined
|
|
21646
21646
|
origin:_origin,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:primitive==="solid",autoNormals:!normalsProvided});this._layerList.push(layer);this._currentBatchingLayers[primitiveId]=layer;}if(!edgeIndices){edgeIndices=buildEdgeIndices(_positions11||cfg.positionsCompressed,indices,null,this._edgeThreshold);}portionId=layer.createPortion({positions:_positions11,positionsCompressed:cfg.positionsCompressed,normals:cfg.normals,normalsCompressed:cfg.normalsCompressed,colors:cfg.colors,colorsCompressed:cfg.colorsCompressed,uv:cfg.uv,uvCompressed:cfg.uvCompressed,indices:indices,edgeIndices:edgeIndices,color:color,opacity:opacity,metallic:metallic,roughness:roughness,meshMatrix:_meshMatrix2,worldMatrix:_worldMatrix2,worldAABB:aabb,pickColor:pickColor});var _numTriangles=Math.round(indices.length/3);this._numTriangles+=_numTriangles;mesh.numTriangles=_numTriangles;break;case"lines":if(layer){if(!layer.canCreatePortion(lenPositions,indices.length)){layer.finalize();delete this._currentBatchingLayers[primitiveId];layer=null;}}if(!layer){layer=new LinesBatchingLayer({model:this,layerIndex:0,// This is set in #finalize()
|
|
@@ -21782,7 +21782,7 @@ _this90.active=cfg.active;return _this90;}/**
|
|
|
21782
21782
|
* @returns {Promise} Resolves when the texture has loaded.
|
|
21783
21783
|
*/function transcode(buffers,texture){var config=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};}/**
|
|
21784
21784
|
* Destroys this transcoder.
|
|
21785
|
-
*/},{key:"destroy",value:function destroy(){}}]);return TextureTranscoder;}();var screenPos=math.vec4();var viewPos=math.vec4();var tempVec3a$
|
|
21785
|
+
*/},{key:"destroy",value:function destroy(){}}]);return TextureTranscoder;}();var screenPos=math.vec4();var viewPos=math.vec4();var tempVec3a$7=math.vec3();var tempVec3b$4=math.vec3();var tempVec3c$3=math.vec3();var tempVec4a$4=math.vec4();var tempVec4b$4=math.vec4();var tempVec4c$1=math.vec4();/**
|
|
21786
21786
|
* @private
|
|
21787
21787
|
*/var PanController=/*#__PURE__*/function(){function PanController(scene){_classCallCheck(this,PanController);this._scene=scene;}/**
|
|
21788
21788
|
* Dollys the Camera towards the given target 2D canvas position.
|
|
@@ -21794,16 +21794,16 @@ _this90.active=cfg.active;return _this90;}/**
|
|
|
21794
21794
|
* @param targetCanvasPos Canvas position of the target
|
|
21795
21795
|
* @param dollyDelta Amount to dolly
|
|
21796
21796
|
* @return True if optionalTargetWorldPos was given, and we've dollied past that position.
|
|
21797
|
-
*/_createClass(PanController,[{key:"dollyToCanvasPos",value:function dollyToCanvasPos(optionalTargetWorldPos,targetCanvasPos,dollyDelta){var dolliedThroughSurface=false;var camera=this._scene.camera;if(optionalTargetWorldPos){var eyeToWorldPosVec=math.subVec3(optionalTargetWorldPos,camera.eye,tempVec3a$
|
|
21797
|
+
*/_createClass(PanController,[{key:"dollyToCanvasPos",value:function dollyToCanvasPos(optionalTargetWorldPos,targetCanvasPos,dollyDelta){var dolliedThroughSurface=false;var camera=this._scene.camera;if(optionalTargetWorldPos){var eyeToWorldPosVec=math.subVec3(optionalTargetWorldPos,camera.eye,tempVec3a$7);var eyeWorldPosDist=math.lenVec3(eyeToWorldPosVec);dolliedThroughSurface=eyeWorldPosDist<dollyDelta;}if(camera.projection==="perspective"){camera.ortho.scale=camera.ortho.scale-dollyDelta;var unprojectedWorldPos=this._unproject(targetCanvasPos,tempVec4a$4);var offset=math.subVec3(unprojectedWorldPos,camera.eye,tempVec4c$1);var moveVec=math.mulVec3Scalar(math.normalizeVec3(offset),-dollyDelta,[]);camera.eye=[camera.eye[0]-moveVec[0],camera.eye[1]-moveVec[1],camera.eye[2]-moveVec[2]];camera.look=[camera.look[0]-moveVec[0],camera.look[1]-moveVec[1],camera.look[2]-moveVec[2]];if(optionalTargetWorldPos){// Subtle UX tweak - if we have a target World position, then set camera eye->look distance to
|
|
21798
21798
|
// the same distance as from eye->target. This just gives us a better position for look,
|
|
21799
21799
|
// if we subsequently orbit eye about look, so that we don't orbit a position that's
|
|
21800
21800
|
// suddenly a lot closer than the point we pivoted about on the surface of the last object
|
|
21801
21801
|
// that we click-drag-pivoted on.
|
|
21802
|
-
var eyeTargetVec=math.subVec3(optionalTargetWorldPos,camera.eye,tempVec3a$
|
|
21802
|
+
var eyeTargetVec=math.subVec3(optionalTargetWorldPos,camera.eye,tempVec3a$7);var lenEyeTargetVec=math.lenVec3(eyeTargetVec);var _eyeLookVec2=math.mulVec3Scalar(math.normalizeVec3(math.subVec3(camera.look,camera.eye,tempVec3b$4)),lenEyeTargetVec);camera.look=[camera.eye[0]+_eyeLookVec2[0],camera.eye[1]+_eyeLookVec2[1],camera.eye[2]+_eyeLookVec2[2]];}}else if(camera.projection==="ortho"){// - set ortho scale, getting the unprojected targetCanvasPos before and after, get that difference in a vector;
|
|
21803
21803
|
// - get the vector in which we're dollying;
|
|
21804
21804
|
// - add both vectors to camera eye and look.
|
|
21805
21805
|
var worldPos1=this._unproject(targetCanvasPos,tempVec4a$4);camera.ortho.scale=camera.ortho.scale-dollyDelta;camera.ortho._update();// HACK
|
|
21806
|
-
var worldPos2=this._unproject(targetCanvasPos,tempVec4b$4);var _offset=math.subVec3(worldPos2,worldPos1,tempVec4c$1);var eyeLookMoveVec=math.mulVec3Scalar(math.normalizeVec3(math.subVec3(camera.look,camera.eye,tempVec3a$
|
|
21806
|
+
var worldPos2=this._unproject(targetCanvasPos,tempVec4b$4);var _offset=math.subVec3(worldPos2,worldPos1,tempVec4c$1);var eyeLookMoveVec=math.mulVec3Scalar(math.normalizeVec3(math.subVec3(camera.look,camera.eye,tempVec3a$7)),-dollyDelta,tempVec3b$4);var _moveVec=math.addVec3(_offset,eyeLookMoveVec,tempVec3c$3);camera.eye=[camera.eye[0]-_moveVec[0],camera.eye[1]-_moveVec[1],camera.eye[2]-_moveVec[2]];camera.look=[camera.look[0]-_moveVec[0],camera.look[1]-_moveVec[1],camera.look[2]-_moveVec[2]];}return dolliedThroughSurface;}},{key:"_unproject",value:function _unproject(canvasPos,worldPos){var camera=this._scene.camera;var transposedProjectMat=camera.project.transposedMatrix;var Pt3=transposedProjectMat.subarray(8,12);var Pt4=transposedProjectMat.subarray(12);var D=[0,0,-1.0,1];var screenZ=math.dotVec4(D,Pt3)/math.dotVec4(D,Pt4);camera.project.unproject(canvasPos,screenZ,screenPos,viewPos,worldPos);return worldPos;}},{key:"destroy",value:function destroy(){}}]);return PanController;}();var tempVec3a$6=math.vec3();var tempVec3b$3=math.vec3();var tempVec3c$2=math.vec3();var tempVec4a$3=math.vec4();var tempVec4b$3=math.vec4();var tempVec4c=math.vec4();/** @private */var PivotController=/*#__PURE__*/function(){/**
|
|
21807
21807
|
* @private
|
|
21808
21808
|
*/function PivotController(scene,configs){var _this91=this;_classCallCheck(this,PivotController);// Pivot math by: http://www.derschmale.com/
|
|
21809
21809
|
this._scene=scene;this._configs=configs;this._pivotWorldPos=math.vec3();this._cameraOffset=math.vec3();this._azimuth=0;this._polar=0;this._radius=0;this._pivotPosSet=false;// Initially false, true as soon as _pivotWorldPos has been set to some value
|
|
@@ -21816,7 +21816,7 @@ var canvasBoundingRect=canvas._lastBoundingClientRect;if(!canvasBoundingRect||ca
|
|
|
21816
21816
|
*/},{key:"setPivotElement",value:function setPivotElement(pivotElement){this._pivotElement=pivotElement;}/**
|
|
21817
21817
|
* Begins pivoting.
|
|
21818
21818
|
*/},{key:"startPivot",value:function startPivot(){if(this._cameraLookingDownwards()){this._pivoting=false;return false;}var camera=this._scene.camera;var lookat=math.lookAtMat4v(camera.eye,camera.look,camera.worldUp);math.transformPoint3(lookat,this.getPivotPos(),this._cameraOffset);var pivotPos=this.getPivotPos();this._cameraOffset[2]+=math.distVec3(camera.eye,pivotPos);lookat=math.inverseMat4(lookat);var offset=math.transformVec3(lookat,this._cameraOffset);var diff=math.vec3();math.subVec3(camera.eye,pivotPos,diff);math.addVec3(diff,offset);if(camera.zUp){var t=diff[1];diff[1]=diff[2];diff[2]=t;}this._radius=math.lenVec3(diff);this._polar=Math.acos(diff[1]/this._radius);this._azimuth=Math.atan2(diff[0],diff[2]);this._pivoting=true;}},{key:"_cameraLookingDownwards",value:function _cameraLookingDownwards(){// Returns true if angle between camera viewing direction and World-space "up" axis is too small
|
|
21819
|
-
var camera=this._scene.camera;var forwardAxis=math.normalizeVec3(math.subVec3(camera.look,camera.eye,tempVec3a$
|
|
21819
|
+
var camera=this._scene.camera;var forwardAxis=math.normalizeVec3(math.subVec3(camera.look,camera.eye,tempVec3a$6));var rightAxis=math.cross3Vec3(forwardAxis,camera.worldUp,tempVec3b$3);var rightAxisLen=math.sqLenVec3(rightAxis);return rightAxisLen<=0.0001;}/**
|
|
21820
21820
|
* Returns true if we are currently pivoting.
|
|
21821
21821
|
*
|
|
21822
21822
|
* @returns {Boolean}
|
|
@@ -21829,7 +21829,7 @@ var camera=this._scene.camera;var forwardAxis=math.normalizeVec3(math.subVec3(ca
|
|
|
21829
21829
|
* at the viewpoint. The radius of the sphere is configured via {@link CameraControl#smartPivot}.
|
|
21830
21830
|
*
|
|
21831
21831
|
* @param canvasPos
|
|
21832
|
-
*/},{key:"setCanvasPivotPos",value:function setCanvasPivotPos(canvasPos){var camera=this._scene.camera;var pivotShereRadius=Math.abs(math.distVec3(this._scene.center,camera.eye));var transposedProjectMat=camera.project.transposedMatrix;var Pt3=transposedProjectMat.subarray(8,12);var Pt4=transposedProjectMat.subarray(12);var D=[0,0,-1.0,1];var screenZ=math.dotVec4(D,Pt3)/math.dotVec4(D,Pt4);var worldPos=tempVec4a$3;camera.project.unproject(canvasPos,screenZ,tempVec4b$3,tempVec4c,worldPos);var eyeWorldPosVec=math.normalizeVec3(math.subVec3(worldPos,camera.eye,tempVec3a$
|
|
21832
|
+
*/},{key:"setCanvasPivotPos",value:function setCanvasPivotPos(canvasPos){var camera=this._scene.camera;var pivotShereRadius=Math.abs(math.distVec3(this._scene.center,camera.eye));var transposedProjectMat=camera.project.transposedMatrix;var Pt3=transposedProjectMat.subarray(8,12);var Pt4=transposedProjectMat.subarray(12);var D=[0,0,-1.0,1];var screenZ=math.dotVec4(D,Pt3)/math.dotVec4(D,Pt4);var worldPos=tempVec4a$3;camera.project.unproject(canvasPos,screenZ,tempVec4b$3,tempVec4c,worldPos);var eyeWorldPosVec=math.normalizeVec3(math.subVec3(worldPos,camera.eye,tempVec3a$6));var posOnSphere=math.addVec3(camera.eye,math.mulVec3Scalar(eyeWorldPosVec,pivotShereRadius,tempVec3b$3),tempVec3c$2);this.setPivotPos(posOnSphere);}/**
|
|
21833
21833
|
* Gets the current position we're pivoting about.
|
|
21834
21834
|
* @returns {Number[]} The current World-space pivot position.
|
|
21835
21835
|
*/},{key:"getPivotPos",value:function getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look;// Avoid pivoting about [0,0,0] by default
|
|
@@ -21888,9 +21888,9 @@ mouseDownLeft=false;mouseDownMiddle=false;mouseDownRight=false;break;case 2:// M
|
|
|
21888
21888
|
mouseDownLeft=false;mouseDownMiddle=false;mouseDownRight=false;break;case 3:// Right button
|
|
21889
21889
|
mouseDownLeft=false;mouseDownMiddle=false;mouseDownRight=false;break;}});canvas.addEventListener("mouseup",this._mouseUpHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}switch(e.which){case 3:// Right button
|
|
21890
21890
|
getCanvasPosFromEvent$4(e,canvasPos);var x=canvasPos[0];var y=canvasPos[1];if(Math.abs(x-lastXDown)<3&&Math.abs(y-lastYDown)<3){controllers.cameraControl.fire("rightClick",{// For context menus
|
|
21891
|
-
pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:canvasPos,event:e},true);}break;}canvas.style.removeProperty("cursor");});canvas.addEventListener("mouseenter",this._mouseEnterHandler=function(){if(!(configs.active&&configs.pointerEnabled)){return;}});var maxElapsed=1/20;var minElapsed=1/60;var secsNowLast=null;canvas.addEventListener("wheel",this._mouseWheelHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}var secsNow=performance.now()/1000.0;var secsElapsed=secsNowLast!==null?secsNow-secsNowLast:0;secsNowLast=secsNow;if(secsElapsed>maxElapsed){secsElapsed=maxElapsed;}if(secsElapsed<minElapsed){secsElapsed=minElapsed;}var delta=Math.max(-1,Math.min(1,-e.deltaY*40));if(delta===0){return;}var normalizedDelta=delta/Math.abs(delta);updates.dollyDelta+=-normalizedDelta*secsElapsed*configs.mouseWheelDollyRate;if(mouseMovedOnCanvasSinceLastWheel){states.followPointerDirty=true;mouseMovedOnCanvasSinceLastWheel=false;}},{passive:true});}_createClass(MousePanRotateDollyHandler,[{key:"reset",value:function reset(){}},{key:"destroy",value:function destroy(){var canvas=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler);document.removeEventListener("keyup",this._documentKeyUpHandler);canvas.removeEventListener("mousedown",this._mouseDownHandler);document.removeEventListener("mousemove",this._documentMouseMoveHandler);canvas.removeEventListener("mousemove",this._canvasMouseMoveHandler);document.removeEventListener("mouseup",this._documentMouseUpHandler);canvas.removeEventListener("mouseup",this._mouseUpHandler);canvas.removeEventListener("mouseenter",this._mouseEnterHandler);canvas.removeEventListener("wheel",this._mouseWheelHandler);}}]);return MousePanRotateDollyHandler;}();var center=math.vec3();var tempVec3a$
|
|
21891
|
+
pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:canvasPos,event:e},true);}break;}canvas.style.removeProperty("cursor");});canvas.addEventListener("mouseenter",this._mouseEnterHandler=function(){if(!(configs.active&&configs.pointerEnabled)){return;}});var maxElapsed=1/20;var minElapsed=1/60;var secsNowLast=null;canvas.addEventListener("wheel",this._mouseWheelHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}var secsNow=performance.now()/1000.0;var secsElapsed=secsNowLast!==null?secsNow-secsNowLast:0;secsNowLast=secsNow;if(secsElapsed>maxElapsed){secsElapsed=maxElapsed;}if(secsElapsed<minElapsed){secsElapsed=minElapsed;}var delta=Math.max(-1,Math.min(1,-e.deltaY*40));if(delta===0){return;}var normalizedDelta=delta/Math.abs(delta);updates.dollyDelta+=-normalizedDelta*secsElapsed*configs.mouseWheelDollyRate;if(mouseMovedOnCanvasSinceLastWheel){states.followPointerDirty=true;mouseMovedOnCanvasSinceLastWheel=false;}},{passive:true});}_createClass(MousePanRotateDollyHandler,[{key:"reset",value:function reset(){}},{key:"destroy",value:function destroy(){var canvas=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler);document.removeEventListener("keyup",this._documentKeyUpHandler);canvas.removeEventListener("mousedown",this._mouseDownHandler);document.removeEventListener("mousemove",this._documentMouseMoveHandler);canvas.removeEventListener("mousemove",this._canvasMouseMoveHandler);document.removeEventListener("mouseup",this._documentMouseUpHandler);canvas.removeEventListener("mouseup",this._mouseUpHandler);canvas.removeEventListener("mouseenter",this._mouseEnterHandler);canvas.removeEventListener("wheel",this._mouseWheelHandler);}}]);return MousePanRotateDollyHandler;}();var center=math.vec3();var tempVec3a$5=math.vec3();var tempVec3b$2=math.vec3();var tempVec3c$1=math.vec3();var tempVec3d=math.vec3();var tempCameraTarget={eye:math.vec3(),look:math.vec3(),up:math.vec3()};/**
|
|
21892
21892
|
* @private
|
|
21893
|
-
*/var KeyboardAxisViewHandler=/*#__PURE__*/function(){function KeyboardAxisViewHandler(scene,controllers,configs,states){_classCallCheck(this,KeyboardAxisViewHandler);this._scene=scene;var cameraControl=controllers.cameraControl;var camera=scene.camera;this._onSceneKeyDown=scene.input.on("keydown",function(){if(!(configs.active&&configs.pointerEnabled)||!scene.input.keyboardEnabled){return;}if(!states.mouseover){return;}var axisViewRight=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_RIGHT);var axisViewBack=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BACK);var axisViewLeft=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_LEFT);var axisViewFront=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_FRONT);var axisViewTop=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_TOP);var axisViewBottom=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BOTTOM);if(!axisViewRight&&!axisViewBack&&!axisViewLeft&&!axisViewFront&&!axisViewTop&&!axisViewBottom){return;}var aabb=scene.aabb;var diag=math.getAABB3Diag(aabb);math.getAABB3Center(aabb,center);var perspectiveDist=Math.abs(diag/Math.tan(controllers.cameraFlight.fitFOV*math.DEGTORAD));var orthoScale=diag*1.1;tempCameraTarget.orthoScale=orthoScale;if(axisViewRight){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldRight,perspectiveDist,tempVec3a$
|
|
21893
|
+
*/var KeyboardAxisViewHandler=/*#__PURE__*/function(){function KeyboardAxisViewHandler(scene,controllers,configs,states){_classCallCheck(this,KeyboardAxisViewHandler);this._scene=scene;var cameraControl=controllers.cameraControl;var camera=scene.camera;this._onSceneKeyDown=scene.input.on("keydown",function(){if(!(configs.active&&configs.pointerEnabled)||!scene.input.keyboardEnabled){return;}if(!states.mouseover){return;}var axisViewRight=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_RIGHT);var axisViewBack=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BACK);var axisViewLeft=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_LEFT);var axisViewFront=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_FRONT);var axisViewTop=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_TOP);var axisViewBottom=cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BOTTOM);if(!axisViewRight&&!axisViewBack&&!axisViewLeft&&!axisViewFront&&!axisViewTop&&!axisViewBottom){return;}var aabb=scene.aabb;var diag=math.getAABB3Diag(aabb);math.getAABB3Center(aabb,center);var perspectiveDist=Math.abs(diag/Math.tan(controllers.cameraFlight.fitFOV*math.DEGTORAD));var orthoScale=diag*1.1;tempCameraTarget.orthoScale=orthoScale;if(axisViewRight){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldRight,perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(camera.worldUp);}else if(axisViewBack){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldForward,perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(camera.worldUp);}else if(axisViewLeft){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldRight,-perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(camera.worldUp);}else if(axisViewFront){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldForward,-perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(camera.worldUp);}else if(axisViewTop){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldUp,perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(math.normalizeVec3(math.mulVec3Scalar(camera.worldForward,1,tempVec3b$2),tempVec3c$1));}else if(axisViewBottom){tempCameraTarget.eye.set(math.addVec3(center,math.mulVec3Scalar(camera.worldUp,-perspectiveDist,tempVec3a$5),tempVec3d));tempCameraTarget.look.set(center);tempCameraTarget.up.set(math.normalizeVec3(math.mulVec3Scalar(camera.worldForward,-1,tempVec3b$2)));}if(!configs.firstPerson&&configs.followPointer){controllers.pivotController.setPivotPos(center);}if(controllers.cameraFlight.duration>0){controllers.cameraFlight.flyTo(tempCameraTarget,function(){if(controllers.pivotController.getPivoting()&&configs.followPointer){controllers.pivotController.showPivot();}});}else{controllers.cameraFlight.jumpTo(tempCameraTarget);if(controllers.pivotController.getPivoting()&&configs.followPointer){controllers.pivotController.showPivot();}}});}_createClass(KeyboardAxisViewHandler,[{key:"reset",value:function reset(){}},{key:"destroy",value:function destroy(){this._scene.input.off(this._onSceneKeyDown);}}]);return KeyboardAxisViewHandler;}();/**
|
|
21894
21894
|
* @private
|
|
21895
21895
|
*/var MousePickHandler=/*#__PURE__*/function(){function MousePickHandler(scene,controllers,configs,states,updates){var _this93=this;_classCallCheck(this,MousePickHandler);this._scene=scene;var pickController=controllers.pickController;var pivotController=controllers.pivotController;var cameraControl=controllers.cameraControl;this._clicks=0;this._timeout=null;this._lastPickedEntityId=null;var leftDown=false;var rightDown=false;var canvas=this._scene.canvas.canvas;var flyCameraTo=function flyCameraTo(pickResult){var pos;if(pickResult&&pickResult.worldPos){pos=pickResult.worldPos;}var aabb=pickResult&&pickResult.entity?pickResult.entity.aabb:scene.aabb;if(pos){// Fly to look at point, don't change eye->look dist
|
|
21896
21896
|
var camera=scene.camera;math.subVec3(camera.eye,camera.look,[]);controllers.cameraFlight.flyTo({// look: pos,
|
|
@@ -24491,7 +24491,7 @@ id:id,isObject:true// Registers the Entity in Scene#objects
|
|
|
24491
24491
|
{boundaries:[[0,6,1,1],[6,0,1,1],[23,6,1,1]],"dir":[0.5,-0.7071,0.5],"up":[0.5,0.7071,0.5]},// Top-back-left corner
|
|
24492
24492
|
{boundaries:[[11,5,2,2]],"dir":[-0.5,-0.7071,-0.5],"up":[-0.5,0.7071,-0.5]}// Top-front-right corner
|
|
24493
24493
|
];for(var _i566=0,len=areasZUp.length;_i566<len;_i566++){math.normalizeVec3(areasZUp[_i566].dir,areasZUp[_i566].dir);math.normalizeVec3(areasZUp[_i566].up,areasZUp[_i566].up);}for(var _i567=0,_len130=areasYUp.length;_i567<_len130;_i567++){math.normalizeVec3(areasYUp[_i567].dir,areasYUp[_i567].dir);math.normalizeVec3(areasYUp[_i567].up,areasYUp[_i567].up);}var areas=areasYUp;this._textureCanvas=document.createElement('canvas');this._textureCanvas.width=width;this._textureCanvas.height=height;this._textureCanvas.style.width=width+"px";this._textureCanvas.style.height=height+"px";this._textureCanvas.style.padding="0";this._textureCanvas.style.margin="0";this._textureCanvas.style.top="0";this._textureCanvas.style.background=cubeColor;this._textureCanvas.style.position="absolute";this._textureCanvas.style.opacity="1.0";this._textureCanvas.style.visibility="hidden";this._textureCanvas.style["z-index"]=2000000;var body=document.getElementsByTagName("body")[0];body.appendChild(this._textureCanvas);var context=this._textureCanvas.getContext("2d");var zUp=false;function paint(){for(var _i568=0,_len131=facesZUp.length;_i568<_len131;_i568++){var face=facesZUp[_i568];var boundary=face.boundary;var xmin=Math.round(boundary[0]*scale);var ymin=Math.round(boundary[1]*scale);var _width=Math.round(boundary[2]*scale);var _height=Math.round(boundary[3]*scale);context.fillStyle=face.color;context.fillRect(xmin,ymin,_width,_height);}for(var _i569=0,_len132=areas.length;_i569<_len132;_i569++){var _xmin=void 0;var _ymin=void 0;var _width2=void 0;var _height2=void 0;var _area=areas[_i569];var boundaries=_area.boundaries;for(var j=0,lenj=boundaries.length;j<lenj;j++){var _boundary=boundaries[j];_xmin=Math.round(_boundary[0]*scale);_ymin=Math.round(_boundary[1]*scale);_width2=Math.round(_boundary[2]*scale);_height2=Math.round(_boundary[3]*scale);if(_area.highlighted){context.fillStyle=_area.highlighted?cubeHighlightColor:_area.color||cubeColor;context.fillRect(_xmin,_ymin,_width2,_height2);}}if(_area.label){context.fillStyle="black";context.font='60px sans-serif';context.textAlign="center";var xcenter=_xmin+_width2*0.5;var ycenter=_ymin+_height2*0.7;context.fillText(translateLabel(_area.label),xcenter,ycenter,80);}}viewer.scene.glRedraw();}var translateLabel=function(){var swizzleYUp={"NavCube.front":"NavCube.front","NavCube.back":"NavCube.back","NavCube.right":"NavCube.right","NavCube.left":"NavCube.left","NavCube.top":"NavCube.top","NavCube.bottom":"NavCube.bottom"};var swizzleZUp={"NavCube.front":"NavCube.front","NavCube.back":"NavCube.back","NavCube.right":"NavCube.right","NavCube.left":"NavCube.left","NavCube.top":"NavCube.top","NavCube.bottom":"NavCube.bottom"};var defaultLabels={"NavCube.front":"FRONT","NavCube.back":"BACK","NavCube.right":"RIGHT","NavCube.left":"LEFT","NavCube.top":"TOP","NavCube.bottom":"BOTTOM"};return function(key){var swizzle=zUp?swizzleZUp:swizzleYUp;var swizzledKey=swizzle?swizzle[key]:null;if(swizzledKey){return viewer.localeService.translate(swizzledKey)||defaultLabels[swizzledKey]||swizzledKey;}return key;};}();this.setZUp=function(){zUp=true;areas=areasZUp;this.clear();};this.setYUp=function(){zUp=false;areas=areasYUp;this.clear();};this.clear=function(){context.fillStyle=cubeColor;context.fillRect(0,0,width,height);for(var i=0,len=areas.length;i<len;i++){var _area2=areas[i];_area2.highlighted=false;}paint();};this.getArea=function(uv){var s=uv[0]*width;var t=height-uv[1]*height;// Correct for our texture Y-flipping
|
|
24494
|
-
for(var i=0,len=areas.length;i<len;i++){var _area3=areas[i];var boundaries=_area3.boundaries;for(var j=0,lenj=boundaries.length;j<lenj;j++){var boundary=boundaries[j];if(s>=boundary[0]*scale&&s<=(boundary[0]+boundary[2])*scale&&t>=boundary[1]*scale&&t<=(boundary[1]+boundary[3])*scale){return i;}}}return-1;};this.setAreaHighlighted=function(areaId,highlighted){var area=areas[areaId];if(!area){throw"Area not found: "+areaId;}area.highlighted=!!highlighted;paint();};this.getAreaDir=function(areaId){var area=areas[areaId];if(!area){throw"Unknown area: "+areaId;}return area.dir;};this.getAreaUp=function(areaId){var area=areas[areaId];if(!area){throw"Unknown area: "+areaId;}return area.up;};this.getImage=function(){return this._textureCanvas;};this.destroy=function(){if(this._textureCanvas){this._textureCanvas.parentNode.removeChild(this._textureCanvas);this._textureCanvas=null;}};}
|
|
24494
|
+
for(var i=0,len=areas.length;i<len;i++){var _area3=areas[i];var boundaries=_area3.boundaries;for(var j=0,lenj=boundaries.length;j<lenj;j++){var boundary=boundaries[j];if(s>=boundary[0]*scale&&s<=(boundary[0]+boundary[2])*scale&&t>=boundary[1]*scale&&t<=(boundary[1]+boundary[3])*scale){return i;}}}return-1;};this.setAreaHighlighted=function(areaId,highlighted){var area=areas[areaId];if(!area){throw"Area not found: "+areaId;}area.highlighted=!!highlighted;paint();};this.getAreaDir=function(areaId){var area=areas[areaId];if(!area){throw"Unknown area: "+areaId;}return area.dir;};this.getAreaUp=function(areaId){var area=areas[areaId];if(!area){throw"Unknown area: "+areaId;}return area.up;};this.getImage=function(){return this._textureCanvas;};this.destroy=function(){if(this._textureCanvas){this._textureCanvas.parentNode.removeChild(this._textureCanvas);this._textureCanvas=null;}};}var tempVec3a$4=math.vec3();var tempVec3b$1=math.vec3();math.mat4();/**
|
|
24495
24495
|
* {@link Viewer} plugin that lets us look at the entire {@link Scene} from along a chosen axis or diagonal.
|
|
24496
24496
|
*
|
|
24497
24497
|
* [<img src="https://user-images.githubusercontent.com/83100/55674490-c93c2e00-58b5-11e9-8a28-eb08876947c0.gif">](https://xeokit.github.io/xeokit-sdk/examples/#gizmos_NavCubePlugin)
|
|
@@ -24576,10 +24576,10 @@ for(var i=0,len=areas.length;i<len;i++){var _area3=areas[i];var boundaries=_area
|
|
|
24576
24576
|
* @param {Boolean} [cfg.isProjectNorth] sets whether the NavCube switches between true north and project north - using the project north offset angle.
|
|
24577
24577
|
* @param {number} [cfg.projectNorthOffsetAngle] sets the NavCube project north offset angle - when the {@link isProjectNorth} is true.
|
|
24578
24578
|
*/function NavCubePlugin(viewer){var _this119;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,NavCubePlugin);_this119=_super79.call(this,"NavCube",viewer,cfg);viewer.navCube=_assertThisInitialized(_this119);var visible=true;try{_this119._navCubeScene=new Scene(viewer,{canvasId:cfg.canvasId,canvasElement:cfg.canvasElement,transparent:true});_this119._navCubeCanvas=_this119._navCubeScene.canvas.canvas;_this119._navCubeScene.input.keyboardEnabled=false;// Don't want keyboard input in the NavCube
|
|
24579
|
-
}catch(error){_this119.error(error);return _possibleConstructorReturn(_this119);}var navCubeScene=_this119._navCubeScene;navCubeScene.clearLights();new DirLight(navCubeScene,{dir:[0.4,-0.4,0.8],color:[0.8,1.0,1.0],intensity:1.0,space:"view"});new DirLight(navCubeScene,{dir:[-0.8,-0.3,-0.4],color:[0.8,0.8,0.8],intensity:1.0,space:"view"});new DirLight(navCubeScene,{dir:[0.8,-0.6,-0.8],color:[1.0,1.0,1.0],intensity:1.0,space:"view"});_this119._navCubeCamera=navCubeScene.camera;_this119._navCubeCamera.ortho.scale=7.0;_this119._navCubeCamera.ortho.near=0.1;_this119._navCubeCamera.ortho.far=2000;navCubeScene.edgeMaterial.edgeColor=[0.2,0.2,0.2];navCubeScene.edgeMaterial.edgeAlpha=0.6;_this119._zUp=Boolean(viewer.camera.zUp);var self=_assertThisInitialized(_this119);_this119.setIsProjectNorth(cfg.isProjectNorth);_this119.setProjectNorthOffsetAngle(cfg.projectNorthOffsetAngle);var rotateTrueNorth=function(){var trueNorthMatrix=math.mat4();
|
|
24579
|
+
}catch(error){_this119.error(error);return _possibleConstructorReturn(_this119);}var navCubeScene=_this119._navCubeScene;navCubeScene.clearLights();new DirLight(navCubeScene,{dir:[0.4,-0.4,0.8],color:[0.8,1.0,1.0],intensity:1.0,space:"view"});new DirLight(navCubeScene,{dir:[-0.8,-0.3,-0.4],color:[0.8,0.8,0.8],intensity:1.0,space:"view"});new DirLight(navCubeScene,{dir:[0.8,-0.6,-0.8],color:[1.0,1.0,1.0],intensity:1.0,space:"view"});_this119._navCubeCamera=navCubeScene.camera;_this119._navCubeCamera.ortho.scale=7.0;_this119._navCubeCamera.ortho.near=0.1;_this119._navCubeCamera.ortho.far=2000;navCubeScene.edgeMaterial.edgeColor=[0.2,0.2,0.2];navCubeScene.edgeMaterial.edgeAlpha=0.6;_this119._zUp=Boolean(viewer.camera.zUp);var self=_assertThisInitialized(_this119);_this119.setIsProjectNorth(cfg.isProjectNorth);_this119.setProjectNorthOffsetAngle(cfg.projectNorthOffsetAngle);var rotateTrueNorth=function(){var trueNorthMatrix=math.mat4();return function(dir,vec,dest){math.identityMat4(trueNorthMatrix);math.rotationMat4v(dir*self._projectNorthOffsetAngle*math.DEGTORAD,[0,1,0],trueNorthMatrix);return math.transformVec3(trueNorthMatrix,vec,dest);};}();_this119._synchCamera=function(){var matrix=math.rotationMat4c(-90*math.DEGTORAD,1,0,0);var eyeLookVec=math.vec3();var eyeLookVecCube=math.vec3();var upCube=math.vec3();return function(){var eye=viewer.camera.eye;var look=viewer.camera.look;var up=viewer.camera.up;eyeLookVec=math.mulVec3Scalar(math.normalizeVec3(math.subVec3(eye,look,eyeLookVec)),5);if(self._isProjectNorth&&self._projectNorthOffsetAngle){eyeLookVec=rotateTrueNorth(-1,eyeLookVec,tempVec3a$4);up=rotateTrueNorth(-1,up,tempVec3b$1);}if(self._zUp){// +Z up
|
|
24580
24580
|
math.transformVec3(matrix,eyeLookVec,eyeLookVecCube);math.transformVec3(matrix,up,upCube);self._navCubeCamera.look=[0,0,0];self._navCubeCamera.eye=math.transformVec3(matrix,eyeLookVec,eyeLookVecCube);self._navCubeCamera.up=math.transformPoint3(matrix,up,upCube);}else{// +Y up
|
|
24581
24581
|
self._navCubeCamera.look=[0,0,0];self._navCubeCamera.eye=eyeLookVec;self._navCubeCamera.up=up;}};}();_this119._cubeTextureCanvas=new CubeTextureCanvas(viewer,cfg);_this119._cubeSampler=new Texture(navCubeScene,{image:_this119._cubeTextureCanvas.getImage(),flipY:true,wrapS:ClampToEdgeWrapping,wrapT:ClampToEdgeWrapping});_this119._cubeMesh=new Mesh(navCubeScene,{geometry:new ReadableGeometry(navCubeScene,{primitive:"triangles",normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[0.5,0.6666,0.25,0.6666,0.25,0.3333,0.5,0.3333,0.5,0.6666,0.5,0.3333,0.75,0.3333,0.75,0.6666,0.5,0.6666,0.5,1,0.25,1,0.25,0.6666,0.25,0.6666,0.0,0.6666,0.0,0.3333,0.25,0.3333,0.25,0,0.50,0,0.50,0.3333,0.25,0.3333,0.75,0.3333,1.0,0.3333,1.0,0.6666,0.75,0.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),material:new PhongMaterial(navCubeScene,{diffuse:[0.4,0.4,0.4],specular:[0.4,0.4,0.4],emissive:[.6,.6,.6],diffuseMap:_this119._cubeSampler,emissiveMap:_this119._cubeSampler}),visible:!!visible,edges:true});_this119._shadow=cfg.shadowVisible===false?null:new Mesh(navCubeScene,{geometry:new ReadableGeometry(navCubeScene,buildCylinderGeometry({center:[0,0,0],radiusTop:0.001,radiusBottom:1.4,height:0.01,radialSegments:20,heightSegments:1,openEnded:true})),material:new PhongMaterial(navCubeScene,{diffuse:[0.0,0.0,0.0],specular:[0,0,0],emissive:[0.0,0.0,0.0],alpha:0.5}),position:[0,-1.5,0],visible:!!visible,pickable:false,backfaces:false});_this119._onCameraMatrix=viewer.camera.on("matrix",_this119._synchCamera);_this119._onCameraWorldAxis=viewer.camera.on("worldAxis",function(){if(viewer.camera.zUp){_this119._zUp=true;_this119._cubeTextureCanvas.setZUp();_this119._repaint();_this119._synchCamera();}else if(viewer.camera.yUp){_this119._zUp=false;_this119._cubeTextureCanvas.setYUp();_this119._repaint();_this119._synchCamera();}});_this119._onCameraFOV=viewer.camera.perspective.on("fov",function(fov){if(_this119._synchProjection){_this119._navCubeCamera.perspective.fov=fov;}});_this119._onCameraProjection=viewer.camera.on("projection",function(projection){if(_this119._synchProjection){_this119._navCubeCamera.projection=projection==="ortho"||projection==="perspective"?projection:"perspective";}});var lastAreaId=-1;function actionMove(posX,posY){var yawInc=(posX-lastX)*-sensitivity;var pitchInc=(posY-lastY)*-sensitivity;viewer.camera.orbitYaw(yawInc);viewer.camera.orbitPitch(-pitchInc);lastX=posX;lastY=posY;}function getCoordsWithinElement(event){var coords=[0,0];if(!event){event=window.event;coords[0]=event.x;coords[1]=event.y;}else{var element=event.target;var totalOffsetLeft=0;var totalOffsetTop=0;while(element.offsetParent){totalOffsetLeft+=element.offsetLeft;totalOffsetTop+=element.offsetTop;element=element.offsetParent;}coords[0]=event.pageX-totalOffsetLeft;coords[1]=event.pageY-totalOffsetTop;}return coords;}{var downX=null;var downY=null;var down=false;var over=false;var sensitivity=0.5;var lastX;var lastY;self._navCubeCanvas.addEventListener("mouseenter",self._onMouseEnter=function(e){over=true;});self._navCubeCanvas.addEventListener("mouseleave",self._onMouseLeave=function(e){over=false;});self._navCubeCanvas.addEventListener("mousedown",self._onMouseDown=function(e){if(e.which!==1){return;}downX=e.x;downY=e.y;lastX=e.clientX;lastY=e.clientY;var canvasPos=getCoordsWithinElement(e);var hit=navCubeScene.pick({canvasPos:canvasPos});if(hit){down=true;}else{down=false;}});document.addEventListener("mouseup",self._onMouseUp=function(e){if(e.which!==1){// Left button
|
|
24582
|
-
return;}down=false;if(downX===null){return;}var canvasPos=getCoordsWithinElement(e);var hit=navCubeScene.pick({canvasPos:canvasPos,pickSurface:true});if(hit){if(hit.uv){var areaId=self._cubeTextureCanvas.getArea(hit.uv);if(areaId>=0){document.body.style.cursor="pointer";if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}if(areaId>=0){self._cubeTextureCanvas.setAreaHighlighted(areaId,true);lastAreaId=areaId;self._repaint();if(e.x<downX-3||e.x>downX+3||e.y<downY-3||e.y>downY+3){return;}var dir=self._cubeTextureCanvas.getAreaDir(areaId);if(dir){if(self._isProjectNorth&&self._projectNorthOffsetAngle){dir=rotateTrueNorth(+1,dir);
|
|
24582
|
+
return;}down=false;if(downX===null){return;}var canvasPos=getCoordsWithinElement(e);var hit=navCubeScene.pick({canvasPos:canvasPos,pickSurface:true});if(hit){if(hit.uv){var areaId=self._cubeTextureCanvas.getArea(hit.uv);if(areaId>=0){document.body.style.cursor="pointer";if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}if(areaId>=0){self._cubeTextureCanvas.setAreaHighlighted(areaId,true);lastAreaId=areaId;self._repaint();if(e.x<downX-3||e.x>downX+3||e.y<downY-3||e.y>downY+3){return;}var dir=self._cubeTextureCanvas.getAreaDir(areaId);if(dir){var up=self._cubeTextureCanvas.getAreaUp(areaId);if(self._isProjectNorth&&self._projectNorthOffsetAngle){dir=rotateTrueNorth(+1,dir,tempVec3a$4);up=rotateTrueNorth(+1,up,tempVec3b$1);}flyTo(dir,up,function(){if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}document.body.style.cursor="pointer";if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}if(areaId>=0){self._cubeTextureCanvas.setAreaHighlighted(areaId,false);lastAreaId=-1;self._repaint();}});}}}}}});document.addEventListener("mousemove",self._onMouseMove=function(e){if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}if(e.buttons===1&&!down){return;}if(down){var posX=e.clientX;var posY=e.clientY;document.body.style.cursor="move";actionMove(posX,posY);return;}if(!over){return;}var canvasPos=getCoordsWithinElement(e);var hit=navCubeScene.pick({canvasPos:canvasPos,pickSurface:true});if(hit){if(hit.uv){document.body.style.cursor="pointer";var areaId=self._cubeTextureCanvas.getArea(hit.uv);if(areaId===lastAreaId){return;}if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);}if(areaId>=0){self._cubeTextureCanvas.setAreaHighlighted(areaId,true);self._repaint();lastAreaId=areaId;}}}else{document.body.style.cursor="default";if(lastAreaId>=0){self._cubeTextureCanvas.setAreaHighlighted(lastAreaId,false);self._repaint();lastAreaId=-1;}}});var flyTo=function(){var center=math.vec3();return function(dir,up,ok){var aabb=self._fitVisible?viewer.scene.getAABB(viewer.scene.visibleObjectIds):viewer.scene.aabb;var diag=math.getAABB3Diag(aabb);math.getAABB3Center(aabb,center);var dist=Math.abs(diag/Math.tan(self._cameraFitFOV*math.DEGTORAD));viewer.cameraControl.pivotPos=center;if(self._cameraFly){viewer.cameraFlight.flyTo({look:center,eye:[center[0]-dist*dir[0],center[1]-dist*dir[1],center[2]-dist*dir[2]],up:up||[0,1,0],orthoScale:diag*1.1,fitFOV:self._cameraFitFOV,duration:self._cameraFlyDuration},ok);}else{viewer.cameraFlight.jumpTo({look:center,eye:[center[0]-dist*dir[0],center[1]-dist*dir[1],center[2]-dist*dir[2]],up:up||[0,1,0],orthoScale:diag*1.1,fitFOV:self._cameraFitFOV},ok);}};}();}_this119._onUpdated=viewer.localeService.on("updated",function(){_this119._cubeTextureCanvas.clear();_this119._repaint();});_this119.setVisible(cfg.visible);_this119.setCameraFitFOV(cfg.cameraFitFOV);_this119.setCameraFly(cfg.cameraFly);_this119.setCameraFlyDuration(cfg.cameraFlyDuration);_this119.setFitVisible(cfg.fitVisible);_this119.setSynchProjection(cfg.synchProjection);return _this119;}_createClass(NavCubePlugin,[{key:"send",value:function send(name,value){switch(name){case"language":this._cubeTextureCanvas.clear();this._repaint();// CubeTextureCanvas gets language from Viewer
|
|
24583
24583
|
break;}}},{key:"_repaint",value:function _repaint(){var image=this._cubeTextureCanvas.getImage();this._cubeMesh.material.diffuseMap.image=image;this._cubeMesh.material.emissiveMap.image=image;}/**
|
|
24584
24584
|
* Sets if the NavCube is visible.
|
|
24585
24585
|
*
|