@xtctwins/tctwins-core 1.1.17 → 1.1.18
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/tctwins-core.es5.js +184 -83
- package/dist/tctwins-core.min.es5.js +4 -4
- package/package.json +1 -1
package/dist/tctwins-core.es5.js
CHANGED
|
@@ -3850,6 +3850,17 @@ _this23._lodManagerList[_i47].resetLodCulling();}}sceneTick++;});}/**
|
|
|
3850
3850
|
@keyframes sk-circleFadeDelay {\
|
|
3851
3851
|
0%, 39%, 100% { opacity: 0; }\
|
|
3852
3852
|
40% { opacity: 1; }\
|
|
3853
|
+
}\
|
|
3854
|
+
.tctwins-spinner-text {\
|
|
3855
|
+
position: absolute;\
|
|
3856
|
+
top: 100%;\
|
|
3857
|
+
left: 50%;\
|
|
3858
|
+
transform: translateX(-50%);\
|
|
3859
|
+
white-space: nowrap;\
|
|
3860
|
+
font-size: 13px;\
|
|
3861
|
+
line-height: 20px;\
|
|
3862
|
+
color: #666666;\
|
|
3863
|
+
pointer-events: none;\
|
|
3853
3864
|
}";/**
|
|
3854
3865
|
* @desc Displays a progress animation at the center of its {@link Canvas} while things are loading or otherwise busy.
|
|
3855
3866
|
*
|
|
@@ -3879,7 +3890,8 @@ _this23._lodManagerList[_i47].resetLodCulling();}}sceneTick++;});}/**
|
|
|
3879
3890
|
*/var Spinner=/*#__PURE__*/function(_Component5){/**
|
|
3880
3891
|
@private
|
|
3881
3892
|
*/function Spinner(owner){var _this24;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,Spinner);_this24=_callSuper(this,Spinner,[owner,cfg]);_this24._canvas=cfg.canvas;_this24._element=null;_this24._isCustom=false;// True when the element is custom HTML
|
|
3882
|
-
|
|
3893
|
+
_this24._textElement=null;// 转圈下面那行说明文字(见 text)
|
|
3894
|
+
_this24._text="";if(cfg.elementId){// Custom spinner element supplied
|
|
3883
3895
|
_this24._element=document.getElementById(cfg.elementId);if(!_this24._element){_this24._createDefaultSpinner(cfg.elementId);}else{_this24._adjustPosition();}}else{_this24._createDefaultSpinner("engine_spinner");}_this24._enabled=true;_this24._manualVisible=false;_this24.processes=0;return _this24;}_inherits(Spinner,_Component5);return _createClass(Spinner,[{key:"type",get:/**
|
|
3884
3896
|
@private
|
|
3885
3897
|
*/function get(){return"Spinner";}},{key:"visible",get:function get(){return this._element.style["visibility"]==="visible";}/**
|
|
@@ -3901,7 +3913,16 @@ _this24._element=document.getElementById(cfg.elementId);if(!_this24._element){_t
|
|
|
3901
3913
|
* Gets whether this Spinner is enabled.
|
|
3902
3914
|
*
|
|
3903
3915
|
* @returns {Boolean} Whether this Spinner is enabled.
|
|
3904
|
-
*/function get(){return this._enabled;}/**
|
|
3916
|
+
*/function get(){return this._enabled;}/**
|
|
3917
|
+
* 转圈下面的一行说明文字(不设就没这行)。
|
|
3918
|
+
*
|
|
3919
|
+
* 用途:有些等待需要给用户一句解释(例如"首次开启测量,正在准备测量数据,请稍候"),
|
|
3920
|
+
* 光转圈用户不知道为什么要等。空字符串 = 移掉这行。
|
|
3921
|
+
*
|
|
3922
|
+
* 只作用于引擎自己生成的转圈元素;应用自己传 `elementId` 的情况不去改人家的 DOM。
|
|
3923
|
+
*
|
|
3924
|
+
* @param {String} value
|
|
3925
|
+
*/,set:function set(enabled){enabled=enabled!==false;if(this._enabled===enabled){return;}this._enabled=enabled;this._syncVisibility();}},{key:"text",get:function get(){return this._text;}/** @private */,set:function set(value){value=value||"";if(this._text===value){return;}this._text=value;if(this._isCustom||!this._element){return;}if(!value){if(this._textElement){this._textElement.parentNode.removeChild(this._textElement);this._textElement=null;}return;}if(!this._textElement){var element=document.createElement("div");element.setAttribute("class","tctwins-spinner-text");this._element.appendChild(element);this._textElement=element;}this._textElement.textContent=value;}},{key:"_createDefaultSpinner",value:function _createDefaultSpinner(elementId){// console.log("_createDefaultSpinner");
|
|
3905
3926
|
this._injectDefaultCSS();var element=document.createElement("div");element.setAttribute("id",elementId);var style=element.style;style["z-index"]="9000";style.position="absolute";element.innerHTML='<div class="sk-fading-circle">\
|
|
3906
3927
|
<div class="sk-circle1 sk-circle"></div>\
|
|
3907
3928
|
<div class="sk-circle2 sk-circle"></div>\
|
|
@@ -4556,9 +4577,10 @@ return imageDataCache;}},{key:"unbind",value:function unbind(){var gl=this.gl;gl
|
|
|
4556
4577
|
* @private
|
|
4557
4578
|
*/var Renderer$1=function Renderer$1(scene,options){options=options||{};var frameCtx=new FrameContext(scene);var canvas=scene.canvas.canvas;/**
|
|
4558
4579
|
* @type {WebGL2RenderingContext}
|
|
4559
|
-
*/var gl=scene.canvas.gl;var canvasTransparent=!!options.transparent;var alphaDepthMask
|
|
4580
|
+
*/var gl=scene.canvas.gl;var canvasTransparent=!!options.transparent;var alphaDepthMask=!!options.alphaDepthMask;var pickIDs=new Map$1({});var drawableTypeInfo={};var drawables={};var postSortDrawableList=[];var postCullDrawableList=[];var drawableListDirty=true;var stateSortDirty=true;var imageDirty=true;var transparentEnabled=true;var edgesEnabled=!!options.edgesEnabled;var saoEnabled=true;var pbrEnabled=true;var colorTextureEnabled=true;var renderBufferManager=new RenderBufferManager(scene);var snapshotBound=false;var saoOcclusionRenderer=new SAOOcclusionRenderer(scene);var saoDepthLimitedBlurRenderer=new SAODepthLimitedBlurRenderer(scene);this.scene=scene;this._occlusionTester=null;// Lazy-created in #addMarker()
|
|
4560
4581
|
this.capabilities={astcSupported:!!getExtension(gl,"WEBGL_compressed_texture_astc"),etc1Supported:true,// WebGL2
|
|
4561
|
-
etc2Supported:!!getExtension(gl,"WEBGL_compressed_texture_etc"),dxtSupported:!!getExtension(gl,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!getExtension(gl,"EXT_texture_compression_bptc"),pvrtcSupported:!!(getExtension(gl,"WEBGL_compressed_texture_pvrtc")||getExtension(gl,"WEBKIT_WEBGL_compressed_texture_pvrtc"))};this.setTransparentEnabled=function(enabled){transparentEnabled=enabled;canvasTransparent=enabled;imageDirty=true;}
|
|
4582
|
+
etc2Supported:!!getExtension(gl,"WEBGL_compressed_texture_etc"),dxtSupported:!!getExtension(gl,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!getExtension(gl,"EXT_texture_compression_bptc"),pvrtcSupported:!!(getExtension(gl,"WEBGL_compressed_texture_pvrtc")||getExtension(gl,"WEBKIT_WEBGL_compressed_texture_pvrtc"))};this.setTransparentEnabled=function(enabled){transparentEnabled=enabled;canvasTransparent=enabled;imageDirty=true;};// 运行期开关:半透明物体是否写入深度缓冲(Scene#alphaDepthMask 代理到此)
|
|
4583
|
+
this.setAlphaDepthMask=function(enabled){alphaDepthMask=!!enabled;imageDirty=true;};this.setEdgesEnabled=function(enabled){edgesEnabled=enabled;imageDirty=true;};this.setSAOEnabled=function(enabled){saoEnabled=enabled;imageDirty=true;};this.setPBREnabled=function(enabled){pbrEnabled=enabled;imageDirty=true;};this.setColorTextureEnabled=function(enabled){colorTextureEnabled=enabled;imageDirty=true;};this.needStateSort=function(){stateSortDirty=true;};this.shadowsDirty=function(){};this.imageDirty=function(){imageDirty=true;};this.webglContextLost=function(){};this.webglContextRestored=function(gl){// renderBufferManager.webglContextRestored(gl);
|
|
4562
4584
|
saoOcclusionRenderer.init();saoDepthLimitedBlurRenderer.init();imageDirty=true;};/**
|
|
4563
4585
|
* Inserts a drawable into this renderer.
|
|
4564
4586
|
* @private
|
|
@@ -8982,7 +9004,8 @@ function getEntityIDMap(scene,entityIds){var map={};var entityId;var entity;for(
|
|
|
8982
9004
|
* @throws {String} Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement.
|
|
8983
9005
|
*/function Scene(viewer){var _this51;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,Scene);_this51=_callSuper(this,Scene,[null,cfg]);var canvas=cfg.canvasElement||document.getElementById(cfg.canvasId);if(!(canvas instanceof HTMLCanvasElement)){throw"Mandatory config expected: valid canvasId or canvasElement";}/**
|
|
8984
9006
|
* @type {{[key: string]: {wrapperFunc: Function, tickSubId: string}}}
|
|
8985
|
-
*/_this51._tickifiedFunctions={};_this51._transparent=!!cfg.transparent;var alphaDepthMask=!!cfg.alphaDepthMask
|
|
9007
|
+
*/_this51._tickifiedFunctions={};_this51._transparent=!!cfg.transparent;var alphaDepthMask=!!cfg.alphaDepthMask;// 运行期可经 scene.alphaDepthMask 修改(见下方 accessor;Renderer 侧即时生效)
|
|
9008
|
+
_this51._alphaDepthMask=alphaDepthMask;_this51._edgesEnabled=!!cfg.edgesEnabled;_this51._spacesVisible=false;_this51._aabbDirty=true;_this51._aabbUpdate=false;_this51._collideWithEntity=false;_this51._readableGeometry=!!cfg.readableGeometryEnabled;/**
|
|
8986
9009
|
* The {@link Viewer} this Scene belongs to.
|
|
8987
9010
|
* @type {Viewer}
|
|
8988
9011
|
*/_this51.viewer=viewer;/** Decremented each frame, triggers occlusion test for occludable {@link Marker}s when zero.
|
|
@@ -9165,8 +9188,9 @@ core._addScene(_this51);_this51._initDefaults();// Global components
|
|
|
9165
9188
|
_this51._viewport=new Viewport(_this51,{id:"default.viewport",autoBoundary:true,dontClear:true// Never destroy this component with Scene#clear();
|
|
9166
9189
|
});_this51._camera=new Camera(_this51,{id:"default.camera",worldAxis:cfg.worldAxis,dontClear:true// Never destroy this component with Scene#clear();
|
|
9167
9190
|
});// Default lights
|
|
9168
|
-
new AmbientLight(_this51,{color:[1,1,1.0],intensity:_this51.lightIntensity});new DirLight(_this51,{dir:[0.8,-0.5,-0.5],color:[0.67,0.67,0.86],intensity:_this51.lightIntensity,space:"world"});new DirLight(_this51,{dir:[-0.8,-1.0,0.5],color:[0.8,0.8,0.7],intensity:_this51.lightIntensity,space:"world"});_this51._camera.on("dirty",function(){_this51._renderer.imageDirty();});_this51._lod=new LOD(_this51,{enabled:_this51._lodEnabled,targetFPS:30});// 相机远裁剪面自适应:保证大尺度模型在相机拉远时不因 far
|
|
9169
|
-
|
|
9191
|
+
new AmbientLight(_this51,{color:[1,1,1.0],intensity:_this51.lightIntensity});new DirLight(_this51,{dir:[0.8,-0.5,-0.5],color:[0.67,0.67,0.86],intensity:_this51.lightIntensity,space:"world"});new DirLight(_this51,{dir:[-0.8,-1.0,0.5],color:[0.8,0.8,0.7],intensity:_this51.lightIntensity,space:"world"});_this51._camera.on("dirty",function(){_this51._renderer.imageDirty();});_this51._lod=new LOD(_this51,{enabled:_this51._lodEnabled,targetFPS:30});// 相机远裁剪面自适应:保证大尺度模型在相机拉远时不因 far 过小而“被剖切式”裁掉。
|
|
9192
|
+
// 常驻注册、方法内按开关早退,便于运行期用 scene.autoFarPlaneFitEnabled 随时开关(测试用)。
|
|
9193
|
+
_this51.on("tick",function(){return _this51._autoFitCameraFarPlane();});return _this51;}/**
|
|
9170
9194
|
* 让透视相机的远裁剪面({@link Perspective#far})始终覆盖整个场景:
|
|
9171
9195
|
*
|
|
9172
9196
|
* - 目标值 = ceil(max(初始 far, (相机到场景 AABB 中心距离 + AABB 半对角线) * 1.1 + 10));
|
|
@@ -9179,8 +9203,17 @@ if(_this51._autoFarPlaneFitEnabled){_this51.on("tick",function(){return _this51.
|
|
|
9179
9203
|
* @private
|
|
9180
9204
|
*/_inherits(Scene,_Component18);return _createClass(Scene,[{key:"type",get:/**
|
|
9181
9205
|
@private
|
|
9182
|
-
*/function get(){return"Scene";}},{key:"_autoFitCameraFarPlane",value:function _autoFitCameraFarPlane(){var camera=this._camera;if(!camera||camera.projection!=="perspective"){return;}var aabb=this.aabb;if(!aabb||aabb[3]<aabb[0]||aabb[4]<aabb[1]||aabb[5]<aabb[2]){return;}var perspective=camera.perspective;if(this._autoFarPlaneFitFloor===undefined){// 收缩下限取首次参与自适应时的 far(即 Perspective 默认的 2000)
|
|
9183
|
-
this._autoFarPlaneFitFloor=perspective.far;}var radius=0.5*Math.hypot(aabb[3]-aabb[0],aabb[4]-aabb[1],aabb[5]-aabb[2]);var eye=camera.eye;var dist=Math.hypot(eye[0]-(aabb[0]+aabb[3])/2,eye[1]-(aabb[1]+aabb[4])/2,eye[2]-(aabb[2]+aabb[5])/2);var targetFar=Math.ceil(Math.max(this._autoFarPlaneFitFloor,(dist+radius)*1.1+10));var currentFar=perspective.far;if(targetFar>currentFar||targetFar<currentFar*0.5){perspective.far=targetFar;}}
|
|
9206
|
+
*/function get(){return"Scene";}},{key:"_autoFitCameraFarPlane",value:function _autoFitCameraFarPlane(){if(!this._autoFarPlaneFitEnabled){return;}var camera=this._camera;if(!camera||camera.projection!=="perspective"){return;}var aabb=this.aabb;if(!aabb||aabb[3]<aabb[0]||aabb[4]<aabb[1]||aabb[5]<aabb[2]){return;}var perspective=camera.perspective;if(this._autoFarPlaneFitFloor===undefined){// 收缩下限取首次参与自适应时的 far(即 Perspective 默认的 2000)
|
|
9207
|
+
this._autoFarPlaneFitFloor=perspective.far;}var radius=0.5*Math.hypot(aabb[3]-aabb[0],aabb[4]-aabb[1],aabb[5]-aabb[2]);var eye=camera.eye;var dist=Math.hypot(eye[0]-(aabb[0]+aabb[3])/2,eye[1]-(aabb[1]+aabb[4])/2,eye[2]-(aabb[2]+aabb[5])/2);var targetFar=Math.ceil(Math.max(this._autoFarPlaneFitFloor,(dist+radius)*1.1+10));var currentFar=perspective.far;if(targetFar>currentFar||targetFar<currentFar*0.5){perspective.far=targetFar;}}/**
|
|
9208
|
+
* Sets whether the perspective camera's far clipping plane is automatically fitted to the whole
|
|
9209
|
+
* Scene on each tick(运行期开关,默认 true;也可在 Viewer/Scene 构造配置中设置)。
|
|
9210
|
+
*
|
|
9211
|
+
* @type {Boolean}
|
|
9212
|
+
*/},{key:"autoFarPlaneFitEnabled",get:/**
|
|
9213
|
+
* Gets whether automatic far-plane fitting is enabled.
|
|
9214
|
+
*
|
|
9215
|
+
* @returns {Boolean}
|
|
9216
|
+
*/function get(){return this._autoFarPlaneFitEnabled;},set:function set(value){value=value!==false;if(value===this._autoFarPlaneFitEnabled){return;}this._autoFarPlaneFitEnabled=value;this.glRedraw();}},{key:"_initDefaults",value:function _initDefaults(){this.geometry;this.material;this.xrayMaterial;this.edgeMaterial;this.selectedMaterial;this.highlightMaterial;}},{key:"_addComponent",value:function _addComponent(component){if(component.id){// Manual ID
|
|
9184
9217
|
if(this.components[component.id]){if(component.id=="sectionControl"){return;}this.error("Component "+utils.inQuotes(component.id)+" already exists in Scene - ignoring ID, will randomly-generate instead");component.id=null;}}if(!component.id){// Auto ID
|
|
9185
9218
|
if(window.nextID===undefined){window.nextID=0;}//component.id = math.createUUID();
|
|
9186
9219
|
component.id="__"+window.nextID++;while(this.components[component.id]){component.id=math.createUUID();}}this.components[component.id]=component;// Register for class type
|
|
@@ -9335,6 +9368,19 @@ this._transparent=trans;this._renderer.setTransparentEnabled(trans);}},{key:"bac
|
|
|
9335
9368
|
*
|
|
9336
9369
|
* @returns {Boolean} True if basic color texture rendering is enabled.
|
|
9337
9370
|
*/function get(){return this._colorTextureEnabled;},set:function set(colorTextureEnabled){this._colorTextureEnabled=!!colorTextureEnabled;this.glRedraw();}},{key:"lightsObject",get:function get(){return this.lights;}/**
|
|
9371
|
+
* LOD 剔除组件(运行期可通过 scene.lod.enabled / scene.lod.targetFPS 调整)。
|
|
9372
|
+
*/},{key:"lod",get:function get(){return this._lod;}/**
|
|
9373
|
+
* Sets whether transparent objects write into the depth buffer
|
|
9374
|
+
* (对应构造期 Viewer/Scene 的 alphaDepthMask,运行期修改即时生效)。
|
|
9375
|
+
*
|
|
9376
|
+
* false 时半透明物体之间互不遮挡(玻璃叠玻璃无剪影),代价是 overdraw 增加。
|
|
9377
|
+
*
|
|
9378
|
+
* @type {Boolean}
|
|
9379
|
+
*/},{key:"alphaDepthMask",get:/**
|
|
9380
|
+
* Gets whether transparent objects write into the depth buffer.
|
|
9381
|
+
*
|
|
9382
|
+
* @returns {Boolean}
|
|
9383
|
+
*/function get(){return this._alphaDepthMask;}/**
|
|
9338
9384
|
* Gets the Z value of offset for Marker's OcclusionTester.
|
|
9339
9385
|
* The closest the value is to 0.000 the more precise OcclusionTester will be, but at the same time the less
|
|
9340
9386
|
* precise it will behave for Markers that are located exactly on the Surface.
|
|
@@ -9342,7 +9388,7 @@ this._transparent=trans;this._renderer.setTransparentEnabled(trans);}},{key:"bac
|
|
|
9342
9388
|
* Default is ````-0.001````.
|
|
9343
9389
|
*
|
|
9344
9390
|
* @returns {Number} Z offset for Marker
|
|
9345
|
-
|
|
9391
|
+
*/,set:function set(value){value=!!value;if(this._alphaDepthMask===value){return;}this._alphaDepthMask=value;this._renderer.setAlphaDepthMask(value);}},{key:"markerZOffset",get:function get(){if(this._markerZOffset==null){return-0.001;}return this._markerZOffset;}/**
|
|
9346
9392
|
* Performs an occlusion test on all {@link Marker}s in this {@link Scene}.
|
|
9347
9393
|
*
|
|
9348
9394
|
* Sets each {@link Marker#visible} ````true```` if the Marker is currently not occluded by any opaque {@link Entity}s
|
|
@@ -10367,7 +10413,9 @@ src.push("ambientColor *= (lightAmbient.rgb * lightAmbient.a);");src.push("vec3
|
|
|
10367
10413
|
* @private
|
|
10368
10414
|
*/var DrawRenderer=function DrawRenderer(hash,mesh){this.id=ids$2.addItem({});this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new DrawShaderSource(mesh);this._allocate(mesh);};var drawRenderers={};DrawRenderer.get=function(mesh){var scene=mesh.scene;var hash=[scene.canvas.canvas.id,(scene.gammaInput?"gi;":";")+(scene.gammaOutput?"go":""),scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._material._state.hash,mesh._state.drawHash].join(";");var renderer=drawRenderers[hash];if(!renderer){renderer=new DrawRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}drawRenderers[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};DrawRenderer.prototype.put=function(){if(--this._useCount===0){ids$2.removeItem(this.id);if(this._program){this._program.destroy();}delete drawRenderers[this._hash];stats.memory.programs--;}};DrawRenderer.prototype.webglContextRestored=function(){this._program=null;};DrawRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_UNITS;var scene=mesh.scene;var material=mesh._material;var gl=scene.canvas.gl;var program=this._program;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var camera=scene.camera;var origin=mesh.origin;var background=meshState.background;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;if(background){gl.depthFunc(gl.LEQUAL);}this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCViewMatrix(meshState.originHash,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uViewNormalMatrix,false,camera.viewNormalMatrix);if(meshState.clippable){var numAllocatedSectionPlanes=scene._sectionPlanesState.getNumAllocatedSectionPlanes();var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numAllocatedSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numAllocatedSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){if(sectionPlaneIndex<numSectionPlanes){var active=renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$G);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}else{gl.uniform1i(sectionPlaneUniforms.active,0);}}}}}if(materialState.id!==this._lastMaterialId){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
|
|
10369
10415
|
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)
|
|
10370
|
-
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;};/**
|
|
10416
|
+
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;// C: 编译失败(如 GPU OOM/上下文丢失)时也要把后续 draw 会解引用的字段
|
|
10417
|
+
// 初始化为空数组,否则每帧在 _uLightColor 等处抛异常、掩盖真实错误。
|
|
10418
|
+
this._uLightAmbient=[];this._uLightColor=[];this._uLightDir=[];this._uLightPos=[];this._uLightAttenuation=[];this._uShadowViewMatrix=[];this._uShadowProjMatrix=[];this._uSectionPlanes=[];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;};/**
|
|
10371
10419
|
* @private
|
|
10372
10420
|
*/var EmphasisFillShaderSource=/*#__PURE__*/_createClass(function EmphasisFillShaderSource(mesh){_classCallCheck(this,EmphasisFillShaderSource);this.vertex=buildVertex$5(mesh);this.fragment=buildFragment$5(mesh);});function buildVertex$5(mesh){var scene=mesh.scene;var lightsState=scene._lightsState;var normals=hasNormals(mesh);var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push("#version 300 es");src.push("// EmphasisFillShaderSource 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 colorize;");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("uniform vec4 lightAmbient;");src.push("uniform vec4 fillColor;");if(normals){src.push("in vec3 normal;");src.push("uniform mat4 modelNormalMatrix;");src.push("uniform mat4 viewNormalMatrix;");for(var _i109=0,len=lightsState.lights.length;_i109<len;_i109++){var light=lightsState.lights[_i109];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+_i109+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+_i109+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+_i109+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+_i109+";");}}if(quantizedGeometry){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 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;");}if(normals){if(quantizedGeometry){src.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); ");}else{src.push("vec4 localNormal = vec4(normal, 0.0); ");}src.push("mat4 modelNormalMatrix2 = modelNormalMatrix;");src.push("mat4 viewNormalMatrix2 = viewNormalMatrix;");}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);");if(normals){src.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;");src.push("billboard(modelNormalMatrix2);");src.push("billboard(viewNormalMatrix2);");src.push("billboard(modelViewNormalMatrix);");}src.push("worldPosition = modelMatrix2 * localPosition;");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(normals){src.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).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;");if(normals){for(var _i110=0,_len15=lightsState.lights.length;_i110<_len15;_i110++){var _light3=lightsState.lights[_i110];if(_light3.type==="ambient"){continue;}if(_light3.type==="dir"){if(_light3.space==="view"){src.push("viewLightDir = normalize(lightDir"+_i110+");");}else{src.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+_i110+", 0.0)).xyz);");}}else if(_light3.type==="point"){if(_light3.space==="view"){src.push("viewLightDir = normalize(lightPos"+_i110+" - viewPosition.xyz);");}else{src.push("viewLightDir = normalize((viewMatrix2 * vec4(lightPos"+_i110+", 0.0)).xyz);");}}else{continue;}src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");src.push("reflectedColor += lambertian * (lightColor"+_i110+".rgb * lightColor"+_i110+".a);");}}// TODO: A blending mode for emphasis materials, to select add/multiply/mix
|
|
10373
10421
|
//src.push("vColor = vec4((mix(reflectedColor, fillColor.rgb, 0.7)), fillColor.a);");
|
|
@@ -14745,7 +14793,10 @@ this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);this._aModelMat
|
|
|
14745
14793
|
if(state.edgeIndicesBuf){state.edgeIndicesBuf.bind();}}else{if(state.indicesBuf){state.indicesBuf.bind();}}}else{if(this._edges){if(state.edgeIndicesBuf){state.edgeIndicesBuf.bind();}}else{if(state.indicesBuf){state.indicesBuf.bind();}}}return vao;}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){var _ref7=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{},_ref7$colorUniform=_ref7.colorUniform,colorUniform=_ref7$colorUniform===void 0?false:_ref7$colorUniform,_ref7$incrementDrawSt=_ref7.incrementDrawState,incrementDrawState=_ref7$incrementDrawSt===void 0?false:_ref7$incrementDrawSt;var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var state=layer._state,model=layer.model;var textureSet=state.textureSet,origin=state.origin,positionsDecodeMatrix=state.positionsDecodeMatrix;var lightsState=scene._lightsState;var pointsMaterial=scene.pointsMaterial;var camera=model.scene.camera;var viewNormalMatrix=camera.viewNormalMatrix,project=camera.project;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate,worldNormalMatrix=model.worldNormalMatrix;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(this._vaoCache.has(layer)){gl.bindVertexArray(this._vaoCache.get(layer));}else{this._vaoCache.set(layer,this._makeVAO(state));}var offset=0;var mat4Size=4*4;this._matricesUniformBlockBufferData.set(rotationMatrixConjugate,0);var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3a$A;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3c$s);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];this._matricesUniformBlockBufferData.set(createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$r),offset+=mat4Size);}else{this._matricesUniformBlockBufferData.set(viewMatrix,offset+=mat4Size);}this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix||project.matrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(positionsDecodeMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(worldNormalMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(viewNormalMatrix,offset+=mat4Size);gl.bindBuffer(gl.UNIFORM_BUFFER,this._matricesUniformBlockBuffer);gl.bufferData(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,gl.DYNAMIC_DRAW);gl.bindBufferBase(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);gl.uniform1i(this._uRenderPass,renderPass);if(this._uBrightness){gl.uniform1f(this._uBrightness,model._brightness!==undefined?model._brightness:1.0);}this.setSectionPlanesStateUniforms(layer);if(scene.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix?
|
|
14746
14794
|
gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(this._uZFar,scene.camera.project.far);}}if(this._uPickInvisible){gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}if(this._uPickZNear){gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);}if(this._uPickZFar){gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);}if(this._uPickClipPos){gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);}if(this._uDrawingBufferSize){gl.uniform2f(this._uDrawingBufferSize,gl.drawingBufferWidth,gl.drawingBufferHeight);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}if(this._uIntensityRange&&pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._uPointSize){gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);}if(this._uNearPlaneHeight){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);}if(textureSet){var colorTexture=textureSet.colorTexture,metallicRoughnessTexture=textureSet.metallicRoughnessTexture,emissiveTexture=textureSet.emissiveTexture,normalsTexture=textureSet.normalsTexture,occlusionTexture=textureSet.occlusionTexture;if(this._uColorMap&&colorTexture){this._program.bindTexture(this._uColorMap,colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uMetallicRoughMap&&metallicRoughnessTexture){this._program.bindTexture(this._uMetallicRoughMap,metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uEmissiveMap&&emissiveTexture){this._program.bindTexture(this._uEmissiveMap,emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uNormalMap&&normalsTexture){this._program.bindTexture(this._uNormalMap,normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uAOMap&&occlusionTexture){this._program.bindTexture(this._uAOMap,occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}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[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,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(colorUniform){var colorKey=this._edges?"edgeColor":"fillColor";var alphaKey=this._edges?"edgeAlpha":"fillAlpha";if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var material=scene.xrayMaterial._state;var _color3=material[colorKey];var alpha=material[alphaKey];gl.uniform4f(this._uColor,_color3[0],_color3[1],_color3[2],alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var _material=scene.highlightMaterial._state;var _color4=_material[colorKey];var _alpha=_material[alphaKey];gl.uniform4f(this._uColor,_color4[0],_color4[1],_color4[2],_alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var _material2=scene.selectedMaterial._state;var _color5=_material2[colorKey];var _alpha2=_material2[alphaKey];gl.uniform4f(this._uColor,_color5[0],_color5[1],_color5[2],_alpha2);}else{gl.uniform4fv(this._uColor,this._edges?edgesDefaultColor:defaultColor$2);}}this._draw({state:state,frameCtx:frameCtx,incrementDrawState:incrementDrawState});gl.bindVertexArray(null);}},{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--;}}]);}();/**
|
|
14747
14795
|
* @private
|
|
14748
|
-
*/var TrianglesBatchingRenderer=/*#__PURE__*/function(_VBORenderer){function TrianglesBatchingRenderer(scene,withSAO){var _ref8=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref8$edges=_ref8.edges,edges=_ref8$edges===void 0?false:_ref8$edges;_classCallCheck(this,TrianglesBatchingRenderer);return _callSuper(this,TrianglesBatchingRenderer,[scene,withSAO,{instancing:false,edges:edges}]);}_inherits(TrianglesBatchingRenderer,_VBORenderer);return _createClass(TrianglesBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){
|
|
14796
|
+
*/var TrianglesBatchingRenderer=/*#__PURE__*/function(_VBORenderer){function TrianglesBatchingRenderer(scene,withSAO){var _ref8=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref8$edges=_ref8.edges,edges=_ref8$edges===void 0?false:_ref8$edges;_classCallCheck(this,TrianglesBatchingRenderer);return _callSuper(this,TrianglesBatchingRenderer,[scene,withSAO,{instancing:false,edges:edges}]);}_inherits(TrianglesBatchingRenderer,_VBORenderer);return _createClass(TrianglesBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){// 该层可能一个边索引都没有(例如模型导出时没有边数据、或该层的几何都没算出边线段)。
|
|
14797
|
+
// 此时层的 portion 仍可能带 EDGES 标志(全局 edgesEnabled / 实体 edges / 房间体强制轮廓),
|
|
14798
|
+
// 于是边线 pass 会走到这里 —— 没有边缓冲就什么也不画,绝不能在 null 上取 numItems。
|
|
14799
|
+
if(state.edgeIndicesBuf){gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}}else{var count=frameCtx.pickElementsCount||state.indicesBuf.numItems;var offset=frameCtx.pickElementsOffset?frameCtx.pickElementsOffset*state.indicesBuf.itemByteSize:0;gl.drawElements(gl.TRIANGLES,count,state.indicesBuf.itemType,offset);if(incrementDrawState){frameCtx.drawElements++;}}}}]);}(VBORenderer);/**
|
|
14749
14800
|
* @private
|
|
14750
14801
|
*/var TrianglesColorRenderer$1=/*#__PURE__*/function(_TrianglesBatchingRen){function TrianglesColorRenderer$1(){_classCallCheck(this,TrianglesColorRenderer$1);return _callSuper(this,TrianglesColorRenderer$1,arguments);}_inherits(TrianglesColorRenderer$1,_TrianglesBatchingRen);return _createClass(TrianglesColorRenderer$1,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_superPropGet(TrianglesColorRenderer$1,"drawLayer",this,3)([frameCtx,layer,renderPass,{incrementDrawState:true}]);}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var light;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("in vec4 modelNormalMatrixCol0;");src.push("in vec4 modelNormalMatrixCol1;");src.push("in vec4 modelNormalMatrixCol2;");this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(var _i159=0,len=lightsState.lights.length;_i159<len;_i159++){light=lightsState.lights[_i159];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+_i159+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+_i159+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+_i159+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+_i159+";");src.push("uniform vec3 lightDir"+_i159+";");}}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
14751
14802
|
// renderPass = COLOR_OPAQUE
|
|
@@ -14882,7 +14933,9 @@ src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:fu
|
|
|
14882
14933
|
if(!this._silhouetteRenderer){// Used for highlighting and selection
|
|
14883
14934
|
this._silhouetteRenderer=new TrianglesSilhouetteRenderer$1(this._scene);}if(!this._pickMeshRenderer){this._pickMeshRenderer=new TrianglesPickMeshRenderer$1(this._scene);}if(!this._pickDepthRenderer){this._pickDepthRenderer=new TrianglesPickDepthRenderer$1(this._scene);}if(!this._snapInitRenderer){this._snapInitRenderer=new TrianglesSnapInitRenderer$1(this._scene,false);}if(!this._snapRenderer){this._snapRenderer=new TrianglesSnapRenderer$1(this._scene);}}},{key:"colorRenderer",get:function get(){if(!this._colorRenderer){this._colorRenderer=new TrianglesColorRenderer$1(this._scene,false);}return this._colorRenderer;}},{key:"colorRendererWithSAO",get:function get(){if(!this._colorRendererWithSAO){this._colorRendererWithSAO=new TrianglesColorRenderer$1(this._scene,true);}return this._colorRendererWithSAO;}},{key:"flatColorRenderer",get:function get(){if(!this._flatColorRenderer){this._flatColorRenderer=new TrianglesFlatColorRenderer$1(this._scene,false);}return this._flatColorRenderer;}},{key:"flatColorRendererWithSAO",get:function get(){if(!this._flatColorRendererWithSAO){this._flatColorRendererWithSAO=new TrianglesFlatColorRenderer$1(this._scene,true);}return this._flatColorRendererWithSAO;}},{key:"colorTextureRenderer",get:function get(){if(!this._colorTextureRenderer){this._colorTextureRenderer=new TrianglesColorTextureRenderer$1(this._scene,false);}return this._colorTextureRenderer;}},{key:"colorTextureRendererWithSAO",get:function get(){if(!this._colorTextureRendererWithSAO){this._colorTextureRendererWithSAO=new TrianglesColorTextureRenderer$1(this._scene,true);}return this._colorTextureRendererWithSAO;}},{key:"pbrRenderer",get:function get(){if(!this._pbrRenderer){this._pbrRenderer=new TrianglesPBRRenderer$1(this._scene,false);}return this._pbrRenderer;}},{key:"pbrRendererWithSAO",get:function get(){if(!this._pbrRendererWithSAO){this._pbrRendererWithSAO=new TrianglesPBRRenderer$1(this._scene,true);}return this._pbrRendererWithSAO;}},{key:"silhouetteRenderer",get:function get(){if(!this._silhouetteRenderer){this._silhouetteRenderer=new TrianglesSilhouetteRenderer$1(this._scene);}return this._silhouetteRenderer;}},{key:"depthRenderer",get:function get(){if(!this._depthRenderer){this._depthRenderer=new TrianglesDepthRenderer$1(this._scene);}return this._depthRenderer;}},{key:"normalsRenderer",get:function get(){if(!this._normalsRenderer){this._normalsRenderer=new TrianglesNormalsRenderer$1(this._scene);}return this._normalsRenderer;}},{key:"edgesRenderer",get:function get(){if(!this._edgesRenderer){this._edgesRenderer=new EdgesEmphasisRenderer$1(this._scene);}return this._edgesRenderer;}},{key:"edgesColorRenderer",get:function get(){if(!this._edgesColorRenderer){this._edgesColorRenderer=new EdgesColorRenderer$1(this._scene);}return this._edgesColorRenderer;}},{key:"pickMeshRenderer",get:function get(){if(!this._pickMeshRenderer){this._pickMeshRenderer=new TrianglesPickMeshRenderer$1(this._scene);}return this._pickMeshRenderer;}},{key:"pickNormalsRenderer",get:function get(){if(!this._pickNormalsRenderer){this._pickNormalsRenderer=new TrianglesPickNormalsRenderer$1(this._scene);}return this._pickNormalsRenderer;}},{key:"pickNormalsFlatRenderer",get:function get(){if(!this._pickNormalsFlatRenderer){this._pickNormalsFlatRenderer=new TrianglesPickNormalsFlatRenderer$1(this._scene);}return this._pickNormalsFlatRenderer;}},{key:"pickDepthRenderer",get:function get(){if(!this._pickDepthRenderer){this._pickDepthRenderer=new TrianglesPickDepthRenderer$1(this._scene);}return this._pickDepthRenderer;}},{key:"occlusionRenderer",get:function get(){if(!this._occlusionRenderer){this._occlusionRenderer=new TrianglesOcclusionRenderer$1(this._scene);}return this._occlusionRenderer;}},{key:"shadowRenderer",get:function get(){if(!this._shadowRenderer){this._shadowRenderer=new TrianglesShadowRenderer$1(this._scene);}return this._shadowRenderer;}},{key:"snapRenderer",get:function get(){if(!this._snapRenderer){this._snapRenderer=new TrianglesSnapRenderer$1(this._scene);}return this._snapRenderer;}},{key:"snapInitRenderer",get:function get(){if(!this._snapInitRenderer){this._snapInitRenderer=new TrianglesSnapInitRenderer$1(this._scene);}return this._snapInitRenderer;}},{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._colorTextureRenderer){this._colorTextureRenderer.destroy();}if(this._colorTextureRendererWithSAO){this._colorTextureRendererWithSAO.destroy();}if(this._pbrRenderer){this._pbrRenderer.destroy();}if(this._pbrRendererWithSAO){this._pbrRendererWithSAO.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();}if(this._snapInitRenderer){this._snapInitRenderer.destroy();}if(this._snapRenderer){this._snapRenderer.destroy();}}}]);}();var cachdRenderers$1={};/**
|
|
14884
14935
|
* @private
|
|
14885
|
-
*/function getRenderers$7(scene){var sceneId=scene.id;var batchingRenderers=cachdRenderers$1[sceneId];if(!batchingRenderers){batchingRenderers=new Renderers$1(scene);cachdRenderers$1[sceneId]=batchingRenderers;batchingRenderers._compile();batchingRenderers.eagerCreateRenders();scene.on("compile",function(){batchingRenderers._compile();batchingRenderers.eagerCreateRenders();});scene.on("destroyed",function(){delete cachdRenderers$1[sceneId];batchingRenderers._destroy();});}return batchingRenderers;}
|
|
14936
|
+
*/function getRenderers$7(scene){var sceneId=scene.id;var batchingRenderers=cachdRenderers$1[sceneId];if(!batchingRenderers){batchingRenderers=new Renderers$1(scene);cachdRenderers$1[sceneId]=batchingRenderers;batchingRenderers._compile();batchingRenderers.eagerCreateRenders();scene.on("compile",function(){batchingRenderers._compile();batchingRenderers.eagerCreateRenders();});scene.on("destroyed",function(){delete cachdRenderers$1[sceneId];batchingRenderers._destroy();});}return batchingRenderers;}// B: 与 setter 的上限(4096)和文档一致;此前误写成 1<<16=65536,
|
|
14937
|
+
// 使单层几何数据纹理高度预算放大 16×(4096×65536),易超 GL 纹理上限/显存。
|
|
14938
|
+
var maxDataTextureHeight=1<<12;var maxGeometryBatchSize=5000000;/**
|
|
14886
14939
|
* Manages global configurations for all {@link Viewer}s.
|
|
14887
14940
|
*
|
|
14888
14941
|
* ## Example
|
|
@@ -15069,7 +15122,9 @@ if(state.modelNormalMatrixCol0Buf){var normalMatrix=math.mat4();math.inverseMat4
|
|
|
15069
15122
|
}}},{key:"drawNormals",value:function drawNormals(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numTransparentLayerPortions===this._numPortions||this._numXRayedLayerPortions===this._numPortions){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.normalsRenderer){this._renderers.normalsRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);// Assume whatever post-effect uses normals (eg SAO) does not apply to transparent objects
|
|
15070
15123
|
}}// ---------------------- SILHOUETTE RENDERING -----------------------------------
|
|
15071
15124
|
},{key:"drawSilhouetteXRayed",value:function drawSilhouetteXRayed(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numXRayedLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.silhouetteRenderer){this._renderers.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;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.silhouetteRenderer){this._renderers.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;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.silhouetteRenderer){this._renderers.silhouetteRenderer.drawLayer(frameCtx,this,RENDER_PASSES.SILHOUETTE_SELECTED);}}// ---------------------- EDGES RENDERING -----------------------------------
|
|
15072
|
-
},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numEdgesLayerPortions===0
|
|
15125
|
+
},{key:"drawEdgesColorOpaque",value:function drawEdgesColorOpaque(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numEdgesLayerPortions===0||// 层内没有任何边索引:例如模型导出时就没有边数据(no_edges),
|
|
15126
|
+
// 此时不能进入边线 pass —— 否则渲染器会在 null 的 edgeIndicesBuf 上取 numItems
|
|
15127
|
+
!this._state.edgeIndicesBuf){return;}if(this._renderers.edgesColorRenderer){this._renderers.edgesColorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.EDGES_COLOR_OPAQUE);}}},{key:"drawEdgesColorTransparent",value:function drawEdgesColorTransparent(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numEdgesLayerPortions===0||this._numTransparentLayerPortions===0||!this._state.edgeIndicesBuf){return;}if(this._renderers.edgesColorRenderer){this._renderers.edgesColorRenderer.drawLayer(frameCtx,this,RENDER_PASSES.EDGES_COLOR_TRANSPARENT);}}},{key:"drawEdgesHighlighted",value:function drawEdgesHighlighted(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numHighlightedLayerPortions===0||!this._state.edgeIndicesBuf){return;}if(this._renderers.edgesRenderer){this._renderers.edgesRenderer.drawLayer(frameCtx,this,RENDER_PASSES.EDGES_HIGHLIGHTED);}}},{key:"drawEdgesSelected",value:function drawEdgesSelected(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numSelectedLayerPortions===0||!this._state.edgeIndicesBuf){return;}if(this._renderers.edgesRenderer){this._renderers.edgesRenderer.drawLayer(frameCtx,this,RENDER_PASSES.EDGES_SELECTED);}}},{key:"drawEdgesXRayed",value:function drawEdgesXRayed(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0||this._numXRayedLayerPortions===0||!this._state.edgeIndicesBuf){return;}if(this._renderers.edgesRenderer){this._renderers.edgesRenderer.drawLayer(frameCtx,this,RENDER_PASSES.EDGES_XRAYED);}}// ---------------------- OCCLUSION CULL RENDERING -----------------------------------
|
|
15073
15128
|
},{key:"drawOcclusion",value:function drawOcclusion(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.occlusionRenderer){this._renderers.occlusionRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}// ---------------------- SHADOW BUFFER RENDERING -----------------------------------
|
|
15074
15129
|
},{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.shadowRenderer){this._renderers.shadowRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}//---- PICKING ----------------------------------------------------------------------------------------------------
|
|
15075
15130
|
},{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._renderers.pickMeshRenderer){this._renderers.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._renderers.pickDepthRenderer){this._renderers.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);////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -15088,7 +15143,8 @@ var a=tempVec3d$a;var b=tempVec3e$1;var c=tempVec3f$1;var gotIntersect=false;var
|
|
|
15088
15143
|
math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}// ---------
|
|
15089
15144
|
},{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.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();}}]);}();/**
|
|
15090
15145
|
* @private
|
|
15091
|
-
*/var TrianglesInstancingRenderer=/*#__PURE__*/function(_VBORenderer4){function TrianglesInstancingRenderer(scene,withSAO){var _ref9=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref9$edges=_ref9.edges,edges=_ref9$edges===void 0?false:_ref9$edges;_classCallCheck(this,TrianglesInstancingRenderer);return _callSuper(this,TrianglesInstancingRenderer,[scene,withSAO,{instancing:true,edges:edges}]);}_inherits(TrianglesInstancingRenderer,_VBORenderer4);return _createClass(TrianglesInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){
|
|
15146
|
+
*/var TrianglesInstancingRenderer=/*#__PURE__*/function(_VBORenderer4){function TrianglesInstancingRenderer(scene,withSAO){var _ref9=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref9$edges=_ref9.edges,edges=_ref9$edges===void 0?false:_ref9$edges;_classCallCheck(this,TrianglesInstancingRenderer);return _callSuper(this,TrianglesInstancingRenderer,[scene,withSAO,{instancing:true,edges:edges}]);}_inherits(TrianglesInstancingRenderer,_VBORenderer4);return _createClass(TrianglesInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){// 与 TrianglesBatchingRenderer 同理:没有边索引就跳过,避免空缓冲导致整个绘制中断
|
|
15147
|
+
if(state.edgeIndicesBuf){gl.drawElementsInstanced(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0,state.numInstances);}}else{gl.drawElementsInstanced(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}}]);}(VBORenderer);/**
|
|
15092
15148
|
* @private
|
|
15093
15149
|
*/var TrianglesColorRenderer=/*#__PURE__*/function(_TrianglesInstancingR){function TrianglesColorRenderer(){_classCallCheck(this,TrianglesColorRenderer);return _callSuper(this,TrianglesColorRenderer,arguments);}_inherits(TrianglesColorRenderer,_TrianglesInstancingR);return _createClass(TrianglesColorRenderer,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_superPropGet(TrianglesColorRenderer,"drawLayer",this,3)([frameCtx,layer,renderPass,{incrementDrawState:true}]);}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.getNumAllocatedSectionPlanes()>0;var 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 float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix
|
|
15094
15150
|
src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("in vec4 modelNormalMatrixCol0;");src.push("in vec4 modelNormalMatrixCol1;");src.push("in vec4 modelNormalMatrixCol2;");this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(i=0,len=lightsState.lights.length;i<len;i++){light=lightsState.lights[i];if(light.type==="ambient"){continue;}src.push("uniform vec4 lightColor"+i+";");if(light.type==="dir"){src.push("uniform vec3 lightDir"+i+";");}if(light.type==="point"){src.push("uniform vec3 lightPos"+i+";");}if(light.type==="spot"){src.push("uniform vec3 lightPos"+i+";");src.push("uniform vec3 lightDir"+i+";");}}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
|
|
@@ -15234,52 +15290,52 @@ this._silhouetteRenderer=new TrianglesSilhouetteRenderer(this._scene);}if(!this.
|
|
|
15234
15290
|
*/function getRenderers$6(scene){var sceneId=scene.id;var instancingRenderers=cachedRenderers$5[sceneId];if(!instancingRenderers){instancingRenderers=new Renderers(scene);cachedRenderers$5[sceneId]=instancingRenderers;instancingRenderers._compile();instancingRenderers.eagerCreateRenders();scene.on("compile",function(){instancingRenderers._compile();instancingRenderers.eagerCreateRenders();});scene.on("destroyed",function(){delete cachedRenderers$5[sceneId];instancingRenderers._destroy();});}return instancingRenderers;}var tempUint8Vec4$2=new Uint8Array(4);var tempFloat32$2=new Float32Array(1);var tempVec4a$4=math.vec4([0,0,0,1]);var tempVec3fa$2=new Float32Array(3);var tempVec3a$u=math.vec3();var tempVec3b$s=math.vec3();var tempVec3c$m=math.vec3();var tempVec3d$7=math.vec3();var tempVec3e=math.vec3();var tempVec3f=math.vec3();var tempVec3g=math.vec3();var tempFloat32Vec4$2=new Float32Array(4);/**
|
|
15235
15291
|
* @private
|
|
15236
15292
|
*/var VBOInstancingTrianglesLayer=/*#__PURE__*/function(){/**
|
|
15237
|
-
|
|
15238
|
-
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
|
|
15243
|
-
|
|
15293
|
+
* @param cfg
|
|
15294
|
+
* @param cfg.layerIndex
|
|
15295
|
+
* @param cfg.model
|
|
15296
|
+
* @param cfg.geometry
|
|
15297
|
+
* @param cfg.textureSet
|
|
15298
|
+
* @param cfg.origin
|
|
15299
|
+
*/function VBOInstancingTrianglesLayer(cfg){_classCallCheck(this,VBOInstancingTrianglesLayer);// console.info("Creating VBOInstancingTrianglesLayer");
|
|
15244
15300
|
/**
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
|
|
15250
|
-
|
|
15251
|
-
|
|
15252
|
-
|
|
15253
|
-
|
|
15301
|
+
* Owner model
|
|
15302
|
+
* @type {VBOSceneModel}
|
|
15303
|
+
*/this.model=cfg.model;/**
|
|
15304
|
+
* State sorting key.
|
|
15305
|
+
* @type {string}
|
|
15306
|
+
*/this.sortId="TrianglesInstancingLayer"+(cfg.solid?"-solid":"-surface")+(cfg.normals?"-normals":"-autoNormals");/**
|
|
15307
|
+
* Index of this InstancingLayer in VBOSceneModel#_layerList
|
|
15308
|
+
* @type {Number}
|
|
15309
|
+
*/this.layerIndex=cfg.layerIndex;this._renderers=getRenderers$6(cfg.model.scene);this._aabb=math.collapseAABB3();this._state=new RenderState({numInstances:0,obb:math.OBB3(),origin:math.vec3(),geometry:cfg.geometry,textureSet:cfg.textureSet,pbrSupported:false,// Set in #finalize if we have enough to support quality rendering
|
|
15254
15310
|
positionsDecodeMatrix:cfg.geometry.positionsDecodeMatrix,// So we can null the geometry for GC
|
|
15255
15311
|
colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null});// These counts are used to avoid unnecessary render passes
|
|
15256
15312
|
this._numPortions=0;this._numVisibleLayerPortions=0;this._numTransparentLayerPortions=0;this._numXRayedLayerPortions=0;this._numHighlightedLayerPortions=0;this._numSelectedLayerPortions=0;this._numClippableLayerPortions=0;this._numEdgesLayerPortions=0;this._numPickableLayerPortions=0;this._numCulledLayerPortions=0;/** @private */this.numIndices=cfg.geometry.numIndices;// Vertex arrays
|
|
15257
15313
|
this._colors=[];this._metallicRoughness=[];this._pickColors=[];this._offsets=[];// Modeling matrix per instance, array for each column
|
|
15258
15314
|
this._modelMatrix=[];this._modelMatrixCol0=[];this._modelMatrixCol1=[];this._modelMatrixCol2=[];// Modeling normal matrix per instance, array for each column
|
|
15259
15315
|
this._modelNormalMatrixCol0=[];this._modelNormalMatrixCol1=[];this._modelNormalMatrixCol2=[];this._portions=[];this._meshes=[];this._aabb=math.collapseAABB3();this.aabbDirty=true;if(cfg.origin){this._state.origin.set(cfg.origin);}this._finalized=false;/**
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
|
|
15263
|
-
|
|
15264
|
-
|
|
15265
|
-
|
|
15266
|
-
|
|
15267
|
-
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
|
|
15279
|
-
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
|
|
15316
|
+
* When true, this layer contains solid triangle meshes, otherwise this layer contains surface triangle meshes
|
|
15317
|
+
* @type {boolean}
|
|
15318
|
+
*/this.solid=!!cfg.solid;/**
|
|
15319
|
+
* The number of indices in this layer.
|
|
15320
|
+
* @type {number|*}
|
|
15321
|
+
*/this.numIndices=cfg.geometry.numIndices;}return _createClass(VBOInstancingTrianglesLayer,[{key:"aabb",get:function get(){if(this.aabbDirty){math.collapseAABB3(this._aabb);for(var _i227=0,len=this._meshes.length;_i227<len;_i227++){math.expandAABB3(this._aabb,this._meshes[_i227].aabb);}this.aabbDirty=false;}return this._aabb;}/**
|
|
15322
|
+
* Creates a new portion within this InstancingLayer, returns the new portion ID.
|
|
15323
|
+
*
|
|
15324
|
+
* The portion will instance this InstancingLayer's geometry.
|
|
15325
|
+
*
|
|
15326
|
+
* Gives the portion the specified color and matrix.
|
|
15327
|
+
*
|
|
15328
|
+
* @param mesh The SceneModelMesh that owns the portion
|
|
15329
|
+
* @param cfg Portion params
|
|
15330
|
+
* @param cfg.color Color [0..255,0..255,0..255]
|
|
15331
|
+
* @param cfg.metallic Metalness factor [0..255]
|
|
15332
|
+
* @param cfg.roughness Roughness factor [0..255]
|
|
15333
|
+
* @param cfg.opacity Opacity [0..255].
|
|
15334
|
+
* @param cfg.meshMatrix Flat float 4x4 matrix.
|
|
15335
|
+
* @param [cfg.worldMatrix] Flat float 4x4 matrix.
|
|
15336
|
+
* @param cfg.pickColor Quantized pick color
|
|
15337
|
+
* @returns {number} Portion ID.
|
|
15338
|
+
*/},{key:"createPortion",value:function createPortion(mesh,cfg){var color=cfg.color;var metallic=cfg.metallic;var roughness=cfg.roughness;var opacity=cfg.opacity!==null&&cfg.opacity!==undefined?cfg.opacity:255;var meshMatrix=cfg.meshMatrix;var pickColor=cfg.pickColor;if(this._finalized){throw"Already finalized";}var r=color[0];// Color is pre-quantized by SceneModel
|
|
15283
15339
|
var g=color[1];var b=color[2];this._colors.push(r);this._colors.push(g);this._colors.push(b);this._colors.push(opacity);this._metallicRoughness.push(metallic!==null&&metallic!==undefined?metallic:0);this._metallicRoughness.push(roughness!==null&&roughness!==undefined?roughness:255);if(this.model.scene.entityOffsetsEnabled){this._offsets.push(0);this._offsets.push(0);this._offsets.push(0);}this._modelMatrixCol0.push(meshMatrix[0]);this._modelMatrixCol0.push(meshMatrix[4]);this._modelMatrixCol0.push(meshMatrix[8]);this._modelMatrixCol0.push(meshMatrix[12]);this._modelMatrixCol1.push(meshMatrix[1]);this._modelMatrixCol1.push(meshMatrix[5]);this._modelMatrixCol1.push(meshMatrix[9]);this._modelMatrixCol1.push(meshMatrix[13]);this._modelMatrixCol2.push(meshMatrix[2]);this._modelMatrixCol2.push(meshMatrix[6]);this._modelMatrixCol2.push(meshMatrix[10]);this._modelMatrixCol2.push(meshMatrix[14]);if(this._state.geometry.normals){// Note: order of inverse and transpose doesn't matter
|
|
15284
15340
|
var transposedMat=math.transposeMat4(meshMatrix,math.mat4());// TODO: Use cached matrix
|
|
15285
15341
|
var normalMatrix=math.inverseMat4(transposedMat);this._modelNormalMatrixCol0.push(normalMatrix[0]);this._modelNormalMatrixCol0.push(normalMatrix[4]);this._modelNormalMatrixCol0.push(normalMatrix[8]);this._modelNormalMatrixCol0.push(normalMatrix[12]);this._modelNormalMatrixCol1.push(normalMatrix[1]);this._modelNormalMatrixCol1.push(normalMatrix[5]);this._modelNormalMatrixCol1.push(normalMatrix[9]);this._modelNormalMatrixCol1.push(normalMatrix[13]);this._modelNormalMatrixCol2.push(normalMatrix[2]);this._modelNormalMatrixCol2.push(normalMatrix[6]);this._modelNormalMatrixCol2.push(normalMatrix[10]);this._modelNormalMatrixCol2.push(normalMatrix[14]);}// Per-vertex pick colors
|
|
@@ -15293,7 +15349,9 @@ var _notNormalized4=false;state.flagsBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Flo
|
|
|
15293
15349
|
// const normalized = true; // For oct-encoded UInt8
|
|
15294
15350
|
// state.normalsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, geometry.normalsCompressed, geometry.normalsCompressed.length, 3, gl.STATIC_DRAW, normalized);
|
|
15295
15351
|
// }
|
|
15296
|
-
if(geometry.colorsCompressed&&geometry.colorsCompressed.length>0){var colorsCompressed=new Uint8Array(geometry.colorsCompressed);var _notNormalized6=false;state.colorsBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,colorsCompressed,colorsCompressed.length,4,gl.STATIC_DRAW,_notNormalized6);}if(geometry.uvCompressed&&geometry.uvCompressed.length>0){var uvCompressed=geometry.uvCompressed;state.uvDecodeMatrix=geometry.uvDecodeMatrix;state.uvBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,uvCompressed,uvCompressed.length,2,gl.STATIC_DRAW,false);}if(geometry.indices&&geometry.indices.length>0){state.indicesBuf=new ArrayBuf(gl,gl.ELEMENT_ARRAY_BUFFER,new Uint32Array(geometry.indices),geometry.indices.length,1,gl.STATIC_DRAW);state.numIndices=geometry.indices.length;}if(geometry.primitive==="triangles"||geometry.primitive==="solid"||geometry.primitive==="surface")
|
|
15352
|
+
if(geometry.colorsCompressed&&geometry.colorsCompressed.length>0){var colorsCompressed=new Uint8Array(geometry.colorsCompressed);var _notNormalized6=false;state.colorsBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,colorsCompressed,colorsCompressed.length,4,gl.STATIC_DRAW,_notNormalized6);}if(geometry.uvCompressed&&geometry.uvCompressed.length>0){var uvCompressed=geometry.uvCompressed;state.uvDecodeMatrix=geometry.uvDecodeMatrix;state.uvBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,uvCompressed,uvCompressed.length,2,gl.STATIC_DRAW,false);}if(geometry.indices&&geometry.indices.length>0){state.indicesBuf=new ArrayBuf(gl,gl.ELEMENT_ARRAY_BUFFER,new Uint32Array(geometry.indices),geometry.indices.length,1,gl.STATIC_DRAW);state.numIndices=geometry.indices.length;}if((geometry.primitive==="triangles"||geometry.primitive==="solid"||geometry.primitive==="surface")&&geometry.edgeIndices&&geometry.edgeIndices.length>0){// 没有边索引就不建边缓冲(与 VBOBatchingTrianglesLayer 一致);
|
|
15353
|
+
// 渲染侧已判空,不会再在 null 上取 numItems
|
|
15354
|
+
state.edgeIndicesBuf=new ArrayBuf(gl,gl.ELEMENT_ARRAY_BUFFER,new Uint32Array(geometry.edgeIndices),geometry.edgeIndices.length,1,gl.STATIC_DRAW);}if(this._modelMatrixCol0.length>0){var _normalized5=false;state.modelMatrixCol0Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,gl.STATIC_DRAW,_normalized5);state.modelMatrixCol1Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,gl.STATIC_DRAW,_normalized5);state.modelMatrixCol2Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,gl.STATIC_DRAW,_normalized5);this._modelMatrixCol0=[];this._modelMatrixCol1=[];this._modelMatrixCol2=[];if(state.normalsBuf){state.modelNormalMatrixCol0Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,gl.STATIC_DRAW,_normalized5);state.modelNormalMatrixCol1Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,gl.STATIC_DRAW,_normalized5);state.modelNormalMatrixCol2Buf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,gl.STATIC_DRAW,_normalized5);this._modelNormalMatrixCol0=[];this._modelNormalMatrixCol1=[];this._modelNormalMatrixCol2=[];}}if(this._pickColors.length>0){var _normalized6=false;state.pickColorsBuf=new ArrayBuf(gl,gl.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,gl.STATIC_DRAW,_normalized6);this._pickColors=[];// Release memory
|
|
15297
15355
|
}state.pbrSupported=!!state.metallicRoughnessBuf&&!!state.uvBuf&&!!state.normalsBuf&&!!textureSet&&!!textureSet.colorTexture&&!!textureSet.metallicRoughnessTexture;state.colorTextureSupported=!!state.uvBuf&&!!textureSet&&!!textureSet.colorTexture;this._state.geometry=null;this._finalized=true;}// The following setters are called by VBOSceneModelMesh, in turn called by VBOSceneModelNode, only after the layer is finalized.
|
|
15298
15356
|
// It's important that these are called after finalize() in order to maintain integrity of counts like _numVisibleLayerPortions etc.
|
|
15299
15357
|
},{key:"initFlags",value:function initFlags(portionId,flags,meshTransparent){if(flags&ENTITY_FLAGS.VISIBLE){this._numVisibleLayerPortions++;this.model.numVisibleLayerPortions++;}if(flags&ENTITY_FLAGS.HIGHLIGHTED){this._numHighlightedLayerPortions++;this.model.numHighlightedLayerPortions++;}if(flags&ENTITY_FLAGS.XRAYED){this._numXRayedLayerPortions++;this.model.numXRayedLayerPortions++;}if(flags&ENTITY_FLAGS.SELECTED){this._numSelectedLayerPortions++;this.model.numSelectedLayerPortions++;}if(flags&ENTITY_FLAGS.CLIPPABLE){this._numClippableLayerPortions++;this.model.numClippableLayerPortions++;}if(flags&ENTITY_FLAGS.EDGES){this._numEdgesLayerPortions++;this.model.numEdgesLayerPortions++;}if(flags&ENTITY_FLAGS.PICKABLE){this._numPickableLayerPortions++;this.model.numPickableLayerPortions++;}if(flags&ENTITY_FLAGS.CULLED){this._numCulledLayerPortions++;this.model.numCulledLayerPortions++;}if(meshTransparent){this._numTransparentLayerPortions++;this.model.numTransparentLayerPortions++;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setVisible",value:function setVisible(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.VISIBLE){this._numVisibleLayerPortions++;this.model.numVisibleLayerPortions++;}else{this._numVisibleLayerPortions--;this.model.numVisibleLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setHighlighted",value:function setHighlighted(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.HIGHLIGHTED){this._numHighlightedLayerPortions++;this.model.numHighlightedLayerPortions++;}else{this._numHighlightedLayerPortions--;this.model.numHighlightedLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setXRayed",value:function setXRayed(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.XRAYED){this._numXRayedLayerPortions++;this.model.numXRayedLayerPortions++;}else{this._numXRayedLayerPortions--;this.model.numXRayedLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setSelected",value:function setSelected(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.SELECTED){this._numSelectedLayerPortions++;this.model.numSelectedLayerPortions++;}else{this._numSelectedLayerPortions--;this.model.numSelectedLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setEdges",value:function setEdges(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.EDGES){this._numEdgesLayerPortions++;this.model.numEdgesLayerPortions++;}else{this._numEdgesLayerPortions--;this.model.numEdgesLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setClippable",value:function setClippable(portionId,flags){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.CLIPPABLE){this._numClippableLayerPortions++;this.model.numClippableLayerPortions++;}else{this._numClippableLayerPortions--;this.model.numClippableLayerPortions--;}this._setFlags(portionId,flags);}},{key:"setCollidable",value:function setCollidable(portionId,flags){if(!this._finalized){throw"Not finalized";}}},{key:"setPickable",value:function setPickable(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.PICKABLE){this._numPickableLayerPortions++;this.model.numPickableLayerPortions++;}else{this._numPickableLayerPortions--;this.model.numPickableLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setCulled",value:function setCulled(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}if(flags&ENTITY_FLAGS.CULLED){this._numCulledLayerPortions++;this.model.numCulledLayerPortions++;}else{this._numCulledLayerPortions--;this.model.numCulledLayerPortions--;}this._setFlags(portionId,flags,meshTransparent);}},{key:"setColor",value:function setColor(portionId,color){// RGBA color is normalized as ints
|
|
@@ -15327,8 +15385,8 @@ if(!this._finalized){throw"Not finalized";}tempUint8Vec4$2[0]=color[0];tempUint8
|
|
|
15327
15385
|
// this._state.modelMatrixCol2Buf.setData(tempFloat32Vec4, offset);
|
|
15328
15386
|
// }
|
|
15329
15387
|
/**
|
|
15330
|
-
|
|
15331
|
-
|
|
15388
|
+
* flags are 4bits values encoded on a 32bit base. color flag on the first 4 bits, silhouette flag on the next 4 bits and so on for edge, pick and clippable.
|
|
15389
|
+
*/},{key:"_setFlags",value:function _setFlags(portionId,flags,meshTransparent){if(!this._finalized){throw"Not finalized";}var visible=!!(flags&ENTITY_FLAGS.VISIBLE);var xrayed=!!(flags&ENTITY_FLAGS.XRAYED);var highlighted=!!(flags&ENTITY_FLAGS.HIGHLIGHTED);var selected=!!(flags&ENTITY_FLAGS.SELECTED);var edges=!!(flags&ENTITY_FLAGS.EDGES);var pickable=!!(flags&ENTITY_FLAGS.PICKABLE);var culled=!!(flags&ENTITY_FLAGS.CULLED);var colorFlag;if(!visible||culled||xrayed||highlighted&&!this.model.scene.highlightMaterial.glowThrough||selected&&!this.model.scene.selectedMaterial.glowThrough){colorFlag=RENDER_PASSES.NOT_RENDERED;}else{if(meshTransparent){colorFlag=RENDER_PASSES.COLOR_TRANSPARENT;}else{colorFlag=RENDER_PASSES.COLOR_OPAQUE;}}var silhouetteFlag;if(!visible||culled){silhouetteFlag=RENDER_PASSES.NOT_RENDERED;}else if(selected){silhouetteFlag=RENDER_PASSES.SILHOUETTE_SELECTED;}else if(highlighted){silhouetteFlag=RENDER_PASSES.SILHOUETTE_HIGHLIGHTED;}else if(xrayed){silhouetteFlag=RENDER_PASSES.SILHOUETTE_XRAYED;}else{silhouetteFlag=RENDER_PASSES.NOT_RENDERED;}var edgeFlag=0;if(!visible||culled){edgeFlag=RENDER_PASSES.NOT_RENDERED;}else if(selected){edgeFlag=RENDER_PASSES.EDGES_SELECTED;}else if(highlighted){edgeFlag=RENDER_PASSES.EDGES_HIGHLIGHTED;}else if(xrayed){edgeFlag=RENDER_PASSES.EDGES_XRAYED;}else if(edges){if(meshTransparent){edgeFlag=RENDER_PASSES.EDGES_COLOR_TRANSPARENT;}else{edgeFlag=RENDER_PASSES.EDGES_COLOR_OPAQUE;}}else{edgeFlag=RENDER_PASSES.NOT_RENDERED;}var pickFlag=visible&&!culled&&pickable?RENDER_PASSES.PICK:RENDER_PASSES.NOT_RENDERED;var clippableFlag=!!(flags&ENTITY_FLAGS.CLIPPABLE)?1:0;var vertFlag=0;vertFlag|=colorFlag;vertFlag|=silhouetteFlag<<4;vertFlag|=edgeFlag<<8;vertFlag|=pickFlag<<12;vertFlag|=clippableFlag<<16;tempFloat32$2[0]=vertFlag;if(this._state.flagsBuf){this._state.flagsBuf.setData(tempFloat32$2,portionId);}}},{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
|
|
15332
15390
|
return;}tempVec3fa$2[0]=offset[0];tempVec3fa$2[1]=offset[1];tempVec3fa$2[2]=offset[2];if(this._state.offsetsBuf){this._state.offsetsBuf.setData(tempVec3fa$2,portionId*3);}}},{key:"getEachVertex",value:function getEachVertex(portionId,callback){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var state=this._state;var geometry=state.geometry;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return;}var positions=geometry.quantizedPositions;var origin=state.origin;var offset=portion.offset;var offsetX=origin[0]+offset[0];var offsetY=origin[1]+offset[1];var offsetZ=origin[2]+offset[2];var worldPos=tempVec4a$4;var portionMatrix=portion.matrix;var sceneModelPatrix=this.model.sceneModelMatrix;var positionsDecodeMatrix=state.positionsDecodeMatrix;for(var _i228=0,len=positions.length;_i228<len;_i228+=3){worldPos[0]=positions[_i228];worldPos[1]=positions[_i228+1];worldPos[2]=positions[_i228+2];math.decompressPosition(worldPos,positionsDecodeMatrix);math.transformPoint3(portionMatrix,worldPos);math.transformPoint3(sceneModelPatrix,worldPos);worldPos[0]+=offsetX;worldPos[1]+=offsetY;worldPos[2]+=offsetZ;callback(worldPos);}}},{key:"setMatrix",value:function setMatrix(portionId,matrix){if(!this._finalized){throw"Not finalized";}////////////////////////////////////////
|
|
15333
15391
|
// TODO: Update portion matrix
|
|
15334
15392
|
////////////////////////////////////////
|
|
@@ -16013,14 +16071,16 @@ texArray.set(positionDecodeMatrices[_i277],_i277*16);}var texture=gl.createTextu
|
|
|
16013
16071
|
* @param {ArrayLike<int>} portionIdsArray
|
|
16014
16072
|
*
|
|
16015
16073
|
* @returns {BindableDataTexture}
|
|
16016
|
-
*/},{key:"generateTextureForPackedPortionIds",value:function generateTextureForPackedPortionIds(gl,portionIdsArray){if(portionIdsArray.length===0){return{texture:null,textureHeight:0};}var lenArray=portionIdsArray.length;var textureWidth=4096;var textureHeight=Math.ceil(lenArray/textureWidth);if(textureHeight===0){throw"texture height===0";}var texArraySize=textureWidth*textureHeight;var texArray=new Uint16Array(texArraySize);texArray.set(portionIdsArray,0);dataTextureRamStats$1.sizeDataTexturePortionIds+=texArray.byteLength;dataTextureRamStats$1.numberOfTextures++;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);gl.texStorage2D(gl.TEXTURE_2D,1,gl.R16UI,textureWidth,textureHeight);gl.texSubImage2D(gl.TEXTURE_2D,0,0,0,textureWidth,textureHeight,gl.RED_INTEGER,gl.UNSIGNED_SHORT,texArray,0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);return new BindableDataTexture(gl,texture,textureWidth,textureHeight);}}]);}();var configs$1=new Configs();var MAX_NUMBER_OF_OBJECTS_IN_LAYER$1=1<<16;var
|
|
16074
|
+
*/},{key:"generateTextureForPackedPortionIds",value:function generateTextureForPackedPortionIds(gl,portionIdsArray){if(portionIdsArray.length===0){return{texture:null,textureHeight:0};}var lenArray=portionIdsArray.length;var textureWidth=4096;var textureHeight=Math.ceil(lenArray/textureWidth);if(textureHeight===0){throw"texture height===0";}var texArraySize=textureWidth*textureHeight;var texArray=new Uint16Array(texArraySize);texArray.set(portionIdsArray,0);dataTextureRamStats$1.sizeDataTexturePortionIds+=texArray.byteLength;dataTextureRamStats$1.numberOfTextures++;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);gl.texStorage2D(gl.TEXTURE_2D,1,gl.R16UI,textureWidth,textureHeight);gl.texSubImage2D(gl.TEXTURE_2D,0,0,0,textureWidth,textureHeight,gl.RED_INTEGER,gl.UNSIGNED_SHORT,texArray,0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);return new BindableDataTexture(gl,texture,textureWidth,textureHeight);}}]);}();var configs$1=new Configs();var MAX_NUMBER_OF_OBJECTS_IN_LAYER$1=1<<16;var INDICES_EDGE_INDICES_ALIGNEMENT_SIZE$1=8;var MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE$1=10;var tempMat4a$d=new Float32Array(16);var tempUint8Array4$1=new Uint8Array(4);var tempFloat32Array3$1=new Float32Array(3);var numLayers$1=0;var DEFAULT_MATRIX$2=math.identityMat4();/**
|
|
16017
16075
|
* @private
|
|
16018
16076
|
*/var DTXLinesLayer=/*#__PURE__*/function(){function DTXLinesLayer(model,cfg){_classCallCheck(this,DTXLinesLayer);// console.info("Creating DTXLinesLayer");
|
|
16019
16077
|
dataTextureRamStats$1.numberOfLayers++;this._layerNumber=numLayers$1++;this.sortId="TriDTX-".concat(this._layerNumber);// State sorting key.
|
|
16020
16078
|
this.layerIndex=cfg.layerIndex;// Index of this DTXLinesLayer in {@link SceneModel#_layerList}.
|
|
16021
|
-
this._renderers=getRenderers$1(model.scene);this.model=model;this._buffer=new DTXLinesBuffer();this._dataTextureState=new DTXLinesState();this._dataTextureGenerator=new DTXLinesTextureFactory()
|
|
16079
|
+
this._renderers=getRenderers$1(model.scene);this.model=model;this._buffer=new DTXLinesBuffer();this._dataTextureState=new DTXLinesState();this._dataTextureGenerator=new DTXLinesTextureFactory();// 构造时读取:需在创建 Viewer/Layer 之前设置 Configs.maxDataTextureHeight 才生效
|
|
16080
|
+
//(旧实现在模块 import 时读一次,运行时再设无效)。
|
|
16081
|
+
this._maxDataTextureHeight=configs$1.maxDataTextureHeight;this._state=new RenderState({origin:math.vec3(cfg.origin),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numVertices:0});this._numPortions=0;// These counts are used to avoid unnecessary render passes
|
|
16022
16082
|
this._numVisibleLayerPortions=0;this._numTransparentLayerPortions=0;this._numXRayedLayerPortions=0;this._numSelectedLayerPortions=0;this._numHighlightedLayerPortions=0;this._numClippableLayerPortions=0;this._numPickableLayerPortions=0;this._numCulledLayerPortions=0;this._subPortions=[];this._portionToSubPortionsMap=[];this._bucketGeometries={};this._meshes=[];this._aabb=math.collapseAABB3();this.aabbDirty=true;this._numUpdatesInFrame=0;this._finalized=false;}return _createClass(DTXLinesLayer,[{key:"aabb",get:function get(){if(this.aabbDirty){math.collapseAABB3(this._aabb);for(var _i282=0,len=this._meshes.length;_i282<len;_i282++){math.expandAABB3(this._aabb,this._meshes[_i282].aabb);}this.aabbDirty=false;}return this._aabb;}},{key:"canCreatePortion",value:function canCreatePortion(portionCfg){if(this._finalized){throw"Already finalized";}var numNewPortions=portionCfg.buckets.length;if(this._numPortions+numNewPortions>MAX_NUMBER_OF_OBJECTS_IN_LAYER$1){dataTextureRamStats$1.cannotCreatePortion.because10BitsObjectId++;}var retVal=this._numPortions+numNewPortions<=MAX_NUMBER_OF_OBJECTS_IN_LAYER$1;var bucketIndex=0;// TODO: Is this a bug?
|
|
16023
|
-
var bucketGeometryId=portionCfg.geometryId!==undefined&&portionCfg.geometryId!==null?"".concat(portionCfg.geometryId,"#").concat(bucketIndex):"".concat(portionCfg.id,"#").concat(bucketIndex);var alreadyHasPortionGeometry=this._bucketGeometries[bucketGeometryId];if(!alreadyHasPortionGeometry){var maxIndicesOfAnyBits=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);var numVertices=0;var numIndices=0;portionCfg.buckets.forEach(function(bucket){numVertices+=bucket.positionsCompressed.length/3;numIndices+=bucket.indices.length/2;});if(this._state.numVertices+numVertices>
|
|
16083
|
+
var bucketGeometryId=portionCfg.geometryId!==undefined&&portionCfg.geometryId!==null?"".concat(portionCfg.geometryId,"#").concat(bucketIndex):"".concat(portionCfg.id,"#").concat(bucketIndex);var alreadyHasPortionGeometry=this._bucketGeometries[bucketGeometryId];if(!alreadyHasPortionGeometry){var maxIndicesOfAnyBits=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);var numVertices=0;var numIndices=0;portionCfg.buckets.forEach(function(bucket){numVertices+=bucket.positionsCompressed.length/3;numIndices+=bucket.indices.length/2;});if(this._state.numVertices+numVertices>this._maxDataTextureHeight*4096||maxIndicesOfAnyBits+numIndices>this._maxDataTextureHeight*4096){dataTextureRamStats$1.cannotCreatePortion.becauseTextureSize++;}retVal&&(retVal=this._state.numVertices+numVertices<=this._maxDataTextureHeight*4096&&maxIndicesOfAnyBits+numIndices<=this._maxDataTextureHeight*4096);}return retVal;}},{key:"createPortion",value:function createPortion(mesh,portionCfg){var _this66=this;if(this._finalized){throw"Already finalized";}var subPortionIds=[];// const portionAABB = portionCfg.worldAABB;
|
|
16024
16084
|
portionCfg.buckets.forEach(function(bucket,bucketIndex){var bucketGeometryId=portionCfg.geometryId!==undefined&&portionCfg.geometryId!==null?"".concat(portionCfg.geometryId,"#").concat(bucketIndex):"".concat(portionCfg.id,"#").concat(bucketIndex);var bucketGeometry=_this66._bucketGeometries[bucketGeometryId];if(!bucketGeometry){bucketGeometry=_this66._createBucketGeometry(portionCfg,bucket);_this66._bucketGeometries[bucketGeometryId]=bucketGeometry;}// const subPortionAABB = math.collapseAABB3(tempAABB3b);
|
|
16025
16085
|
var subPortionId=_this66._createSubPortion(portionCfg,bucketGeometry,bucket);//math.expandAABB3(portionAABB, subPortionAABB);
|
|
16026
16086
|
subPortionIds.push(subPortionId);});var portionId=this._portionToSubPortionsMap.length;this._portionToSubPortionsMap.push(subPortionIds);this.model.numPortions++;this._meshes.push(mesh);return portionId;}},{key:"_createBucketGeometry",value:function _createBucketGeometry(portionCfg,bucket){if(bucket.indices){var alignedIndicesLen=Math.ceil(bucket.indices.length/2/INDICES_EDGE_INDICES_ALIGNEMENT_SIZE$1)*INDICES_EDGE_INDICES_ALIGNEMENT_SIZE$1*2;dataTextureRamStats$1.overheadSizeAlignementIndices+=2*(alignedIndicesLen-bucket.indices.length);var alignedIndices=new Uint32Array(alignedIndicesLen);alignedIndices.fill(0);alignedIndices.set(bucket.indices);bucket.indices=alignedIndices;}var positionsCompressed=bucket.positionsCompressed;var indices=bucket.indices;var buffer=this._buffer;buffer.positionsCompressed.push(positionsCompressed);var vertexBase=buffer.lenPositionsCompressed/3;var numVertices=positionsCompressed.length/3;buffer.lenPositionsCompressed+=positionsCompressed.length;var indicesBase;var numLines=0;if(indices){numLines=indices.length/2;var indicesBuffer;if(numVertices<=1<<8){indicesBuffer=buffer.indices8Bits;indicesBase=buffer.lenIndices8Bits/2;buffer.lenIndices8Bits+=indices.length;}else if(numVertices<=1<<16){indicesBuffer=buffer.indices16Bits;indicesBase=buffer.lenIndices16Bits/2;buffer.lenIndices16Bits+=indices.length;}else{indicesBuffer=buffer.indices32Bits;indicesBase=buffer.lenIndices32Bits/2;buffer.lenIndices32Bits+=indices.length;}indicesBuffer.push(indices);}this._state.numVertices+=numVertices;dataTextureRamStats$1.numberOfGeometries++;var bucketGeometry={vertexBase:vertexBase,numVertices:numVertices,numLines:numLines,indicesBase:indicesBase};return bucketGeometry;}},{key:"_createSubPortion",value:function _createSubPortion(portionCfg,bucketGeometry){var color=portionCfg.color;var colors=portionCfg.colors;var opacity=portionCfg.opacity;var meshMatrix=portionCfg.meshMatrix;var pickColor=portionCfg.pickColor;var buffer=this._buffer;var state=this._state;buffer.perObjectPositionsDecodeMatrices.push(portionCfg.positionsDecodeMatrix);buffer.perObjectInstancePositioningMatrices.push(meshMatrix||DEFAULT_MATRIX$2);buffer.perObjectSolid.push(!!portionCfg.solid);if(colors){buffer.perObjectColors.push([colors[0]*255,colors[1]*255,colors[2]*255,255]);}else if(color){// Color is pre-quantized by SceneModel
|
|
@@ -16626,9 +16686,6 @@ texArray.set(positionDecodeMatrices[_i317],_i317*16);}var texture=gl.createTextu
|
|
|
16626
16686
|
* 12-bits allowed for object ids.
|
|
16627
16687
|
* Limits the per-object texture height in the layer.
|
|
16628
16688
|
*/var MAX_NUMBER_OF_OBJECTS_IN_LAYER=1<<16;/**
|
|
16629
|
-
* 4096 is max data texture height.
|
|
16630
|
-
* Limits the aggregated geometry texture height in the layer.
|
|
16631
|
-
*/var MAX_DATA_TEXTURE_HEIGHT=configs.maxDataTextureHeight;/**
|
|
16632
16689
|
* Align `indices` and `edgeIndices` memory layout to 8 elements.
|
|
16633
16690
|
*
|
|
16634
16691
|
* Used as an optimization for the `...portionIds...` texture, so it
|
|
@@ -16642,7 +16699,9 @@ texArray.set(positionDecodeMatrices[_i317],_i317*16);}var texture=gl.createTextu
|
|
|
16642
16699
|
*/var DTXTrianglesLayer=/*#__PURE__*/function(){function DTXTrianglesLayer(model,cfg){_classCallCheck(this,DTXTrianglesLayer);// console.info("Creating DTXTrianglesLayer");
|
|
16643
16700
|
dataTextureRamStats.numberOfLayers++;this._layerNumber=numLayers++;this.sortId="TriDTX-".concat(this._layerNumber);// State sorting key.
|
|
16644
16701
|
this.layerIndex=cfg.layerIndex;// Index of this TrianglesDataTextureLayer in {@link SceneModel#_layerList}.
|
|
16645
|
-
this._renderers=getRenderers(model.scene);this.model=model;this._buffer=new DTXTrianglesBuffer();this._dtxState=new DTXTrianglesState();this._dtxTextureFactory=new DTXTrianglesTextureFactory()
|
|
16702
|
+
this._renderers=getRenderers(model.scene);this.model=model;this._buffer=new DTXTrianglesBuffer();this._dtxState=new DTXTrianglesState();this._dtxTextureFactory=new DTXTrianglesTextureFactory();// 构造时读取:需在创建 Viewer/Layer 之前设置 Configs.maxDataTextureHeight 才生效
|
|
16703
|
+
//(旧实现在模块 import 时读一次,运行时再设无效)。
|
|
16704
|
+
this._maxDataTextureHeight=configs.maxDataTextureHeight;this._state=new RenderState({origin:math.vec3(cfg.origin),metallicRoughnessBuf:null,textureState:this._dtxState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0});this._numPortions=0;// These counts are used to avoid unnecessary render passes
|
|
16646
16705
|
this._numVisibleLayerPortions=0;this._numTransparentLayerPortions=0;this._numXRayedLayerPortions=0;this._numSelectedLayerPortions=0;this._numHighlightedLayerPortions=0;this._numClippableLayerPortions=0;this._numEdgesLayerPortions=0;this._numPickableLayerPortions=0;this._numCulledLayerPortions=0;this._subPortions=[];/**
|
|
16647
16706
|
* Due to `index rebucketting` process in ```prepareMeshGeometry``` function, it's possible that a single
|
|
16648
16707
|
* portion is expanded to more than 1 real sub-portion.
|
|
@@ -16664,7 +16723,7 @@ this._numVisibleLayerPortions=0;this._numTransparentLayerPortions=0;this._numXRa
|
|
|
16664
16723
|
* @param {object} portionCfg An object containing the geometrical data (`positions`, `indices`, `edgeIndices`) for the portion.
|
|
16665
16724
|
* @returns {Boolean} Wheter the requested portion can be created
|
|
16666
16725
|
*/},{key:"canCreatePortion",value:function canCreatePortion(portionCfg){if(this._finalized){throw"Already finalized";}var numNewPortions=portionCfg.buckets.length;if(this._numPortions+numNewPortions>MAX_NUMBER_OF_OBJECTS_IN_LAYER){dataTextureRamStats.cannotCreatePortion.because10BitsObjectId++;}var retVal=this._numPortions+numNewPortions<=MAX_NUMBER_OF_OBJECTS_IN_LAYER;var bucketIndex=0;// TODO: Is this a bug?
|
|
16667
|
-
var bucketGeometryId=portionCfg.geometryId!==undefined&&portionCfg.geometryId!==null?"".concat(portionCfg.geometryId,"#").concat(bucketIndex):"".concat(portionCfg.id,"#").concat(bucketIndex);var alreadyHasPortionGeometry=this._bucketGeometries[bucketGeometryId];if(!alreadyHasPortionGeometry){var maxIndicesOfAnyBits=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);var numVertices=0;var numIndices=0;portionCfg.buckets.forEach(function(bucket){numVertices+=bucket.positionsCompressed.length/3;numIndices+=bucket.indices.length/3;});if(this._state.numVertices+numVertices>
|
|
16726
|
+
var bucketGeometryId=portionCfg.geometryId!==undefined&&portionCfg.geometryId!==null?"".concat(portionCfg.geometryId,"#").concat(bucketIndex):"".concat(portionCfg.id,"#").concat(bucketIndex);var alreadyHasPortionGeometry=this._bucketGeometries[bucketGeometryId];if(!alreadyHasPortionGeometry){var maxIndicesOfAnyBits=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);var numVertices=0;var numIndices=0;portionCfg.buckets.forEach(function(bucket){numVertices+=bucket.positionsCompressed.length/3;numIndices+=bucket.indices.length/3;});if(this._state.numVertices+numVertices>this._maxDataTextureHeight*4096||maxIndicesOfAnyBits+numIndices>this._maxDataTextureHeight*4096){dataTextureRamStats.cannotCreatePortion.becauseTextureSize++;}retVal&&(retVal=this._state.numVertices+numVertices<=this._maxDataTextureHeight*4096&&maxIndicesOfAnyBits+numIndices<=this._maxDataTextureHeight*4096);}return retVal;}/**
|
|
16668
16727
|
* Creates a new portion within this TrianglesDataTextureLayer, returns the new portion ID.
|
|
16669
16728
|
*
|
|
16670
16729
|
* Gives the portion the specified geometry, color and matrix.
|
|
@@ -18860,7 +18919,10 @@ entity.opacity=this.scene.spacesVisible?128/255:1/255;}/** @private 供 {@link S
|
|
|
18860
18919
|
* @param {Number[]} [cfg.uvDecodeMatrix] A 3x3 matrix for decompressing ````uvCompressed````.
|
|
18861
18920
|
* @param {Number[]} [cfg.indices] Array of primitive connectivity indices. Not required for `points` primitives.
|
|
18862
18921
|
* @param {Number[]} [cfg.edgeIndices] Array of edge line indices. Used only with 'triangles', 'solid' and 'surface' primitives. Automatically generated internally if not supplied, using the optional ````edgeThreshold```` given to the ````SceneModel```` constructor.
|
|
18863
|
-
*/},{key:"createGeometry",value:function createGeometry(cfg){if(cfg.id===undefined||cfg.id===null){this.error("[createGeometry] Config missing: id");return;}if(this._geometries[cfg.id]){this.error("[createGeometry] Geometry already created: "+cfg.id);return;}if(cfg.primitive===undefined||cfg.primitive===null){cfg.primitive="triangles";}if(cfg.primitive!=="points"&&cfg.primitive!=="lines"&&cfg.primitive!=="triangles"&&cfg.primitive!=="solid"&&cfg.primitive!=="surface"){this.error("[createGeometry] Unsupported value for 'primitive': '".concat(cfg.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));return;}if(!cfg.positions&&!cfg.positionsCompressed&&!cfg.buckets){this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets");return null;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix&&!cfg.positionsDecodeBoundary){this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')");return null;}if(cfg.positionsDecodeMatrix&&cfg.positionsDecodeBoundary){this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')");return null;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')");return null;}if(!cfg.buckets&&!cfg.indices&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")){var numPositions=(cfg.positions||cfg.positionsCompressed).length/3;cfg.indices=this._createDefaultIndices(numPositions);}if(!cfg.buckets&&!cfg.indices&&cfg.primitive!=="points"){this.error("[createGeometry] Param expected: indices (required for '".concat(cfg.primitive,"' primitive type)"));return null;}if(cfg.positionsDecodeBoundary){cfg.positionsDecodeMatrix=createPositionsDecodeMatrix(cfg.positionsDecodeBoundary,math.mat4());}if(cfg.positions){var aabb=math.collapseAABB3();cfg.positionsDecodeMatrix=math.mat4();math.expandAABB3Points3(aabb,cfg.positions);cfg.positionsCompressed=quantizePositions(cfg.positions,aabb,cfg.positionsDecodeMatrix);cfg.aabb=aabb;}else if(cfg.positionsCompressed){var _aabb=math.collapseAABB3();cfg.positionsDecodeMatrix=new Float64Array(cfg.positionsDecodeMatrix);cfg.positionsCompressed=new Uint16Array(cfg.positionsCompressed);math.expandAABB3Points3(_aabb,cfg.positionsCompressed);geometryCompressionUtils.decompressAABB(_aabb,cfg.positionsDecodeMatrix);cfg.aabb=_aabb;}else if(cfg.buckets){var _aabb2=math.collapseAABB3();this._dtxBuckets[cfg.id]=cfg.buckets;for(var _i375=0,len=cfg.buckets.length;_i375<len;_i375++){var bucket=cfg.buckets[_i375];if(bucket.positions){math.expandAABB3Points3(_aabb2,bucket.positions);}else if(bucket.positionsCompressed){math.expandAABB3Points3(_aabb2,bucket.positionsCompressed);}}if(cfg.positionsDecodeMatrix){geometryCompressionUtils.decompressAABB(_aabb2,cfg.positionsDecodeMatrix);}cfg.aabb=_aabb2;}if(cfg.colorsCompressed&&cfg.colorsCompressed.length>0){cfg.colorsCompressed=new Uint8Array(cfg.colorsCompressed);}else if(cfg.colors&&cfg.colors.length>0){var colors=cfg.colors;var colorsCompressed=new Uint8Array(colors.length);for(var _i376=0,_len54=colors.length;_i376<_len54;_i376++){colorsCompressed[_i376]=colors[_i376]*255;}cfg.colorsCompressed=colorsCompressed;}
|
|
18922
|
+
*/},{key:"createGeometry",value:function createGeometry(cfg){if(cfg.id===undefined||cfg.id===null){this.error("[createGeometry] Config missing: id");return;}if(this._geometries[cfg.id]){this.error("[createGeometry] Geometry already created: "+cfg.id);return;}if(cfg.primitive===undefined||cfg.primitive===null){cfg.primitive="triangles";}if(cfg.primitive!=="points"&&cfg.primitive!=="lines"&&cfg.primitive!=="triangles"&&cfg.primitive!=="solid"&&cfg.primitive!=="surface"){this.error("[createGeometry] Unsupported value for 'primitive': '".concat(cfg.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));return;}if(!cfg.positions&&!cfg.positionsCompressed&&!cfg.buckets){this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets");return null;}if(cfg.positionsCompressed&&!cfg.positionsDecodeMatrix&&!cfg.positionsDecodeBoundary){this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')");return null;}if(cfg.positionsDecodeMatrix&&cfg.positionsDecodeBoundary){this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')");return null;}if(cfg.uvCompressed&&!cfg.uvDecodeMatrix){this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')");return null;}if(!cfg.buckets&&!cfg.indices&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")){var numPositions=(cfg.positions||cfg.positionsCompressed).length/3;cfg.indices=this._createDefaultIndices(numPositions);}if(!cfg.buckets&&!cfg.indices&&cfg.primitive!=="points"){this.error("[createGeometry] Param expected: indices (required for '".concat(cfg.primitive,"' primitive type)"));return null;}if(cfg.positionsDecodeBoundary){cfg.positionsDecodeMatrix=createPositionsDecodeMatrix(cfg.positionsDecodeBoundary,math.mat4());}if(cfg.positions){var aabb=math.collapseAABB3();cfg.positionsDecodeMatrix=math.mat4();math.expandAABB3Points3(aabb,cfg.positions);cfg.positionsCompressed=quantizePositions(cfg.positions,aabb,cfg.positionsDecodeMatrix);cfg.aabb=aabb;}else if(cfg.positionsCompressed){var _aabb=math.collapseAABB3();cfg.positionsDecodeMatrix=new Float64Array(cfg.positionsDecodeMatrix);cfg.positionsCompressed=new Uint16Array(cfg.positionsCompressed);math.expandAABB3Points3(_aabb,cfg.positionsCompressed);geometryCompressionUtils.decompressAABB(_aabb,cfg.positionsDecodeMatrix);cfg.aabb=_aabb;}else if(cfg.buckets){var _aabb2=math.collapseAABB3();this._dtxBuckets[cfg.id]=cfg.buckets;for(var _i375=0,len=cfg.buckets.length;_i375<len;_i375++){var bucket=cfg.buckets[_i375];if(bucket.positions){math.expandAABB3Points3(_aabb2,bucket.positions);}else if(bucket.positionsCompressed){math.expandAABB3Points3(_aabb2,bucket.positionsCompressed);}}if(cfg.positionsDecodeMatrix){geometryCompressionUtils.decompressAABB(_aabb2,cfg.positionsDecodeMatrix);}cfg.aabb=_aabb2;}if(cfg.colorsCompressed&&cfg.colorsCompressed.length>0){cfg.colorsCompressed=new Uint8Array(cfg.colorsCompressed);}else if(cfg.colors&&cfg.colors.length>0){var colors=cfg.colors;var colorsCompressed=new Uint8Array(colors.length);for(var _i376=0,_len54=colors.length;_i376<_len54;_i376++){colorsCompressed[_i376]=colors[_i376]*255;}cfg.colorsCompressed=colorsCompressed;}// 注意:空数组(长度 0)也算"未提供"。XTC 在 no_edges=True 导出时边线段为空,
|
|
18923
|
+
// 解析器会传进来一个零长 subarray;以前它被当成"调用方已提供",于是从此不再建边,
|
|
18924
|
+
// 模型开启 edgesEnabled 后就一条边都看不到。
|
|
18925
|
+
if(!cfg.buckets&&(!cfg.edgeIndices||cfg.edgeIndices.length===0)&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")){if(cfg.positions){cfg.edgeIndices=buildEdgeIndices(cfg.positions,cfg.indices,null,5.0);}else{cfg.edgeIndices=buildEdgeIndices(cfg.positionsCompressed,cfg.indices,cfg.positionsDecodeMatrix,2.0);}}if(cfg.uv){var bounds=geometryCompressionUtils.getUVBounds(cfg.uv);var result=geometryCompressionUtils.compressUVs(cfg.uv,bounds.min,bounds.max);cfg.uvCompressed=result.quantized;cfg.uvDecodeMatrix=result.decodeMatrix;}else if(cfg.uvCompressed){cfg.uvCompressed=new Uint16Array(cfg.uvCompressed);cfg.uvDecodeMatrix=new Float64Array(cfg.uvDecodeMatrix);}if(cfg.normals){// HACK
|
|
18864
18926
|
cfg.normals=null;}this._geometries[cfg.id]=cfg;this._numTriangles+=cfg.indices?Math.round(cfg.indices.length/3):0;this.numGeometries++;}/**
|
|
18865
18927
|
* Creates a texture within this SceneModel.
|
|
18866
18928
|
*
|
|
@@ -18971,14 +19033,14 @@ cfg.type=DTX;// NPR
|
|
|
18971
19033
|
cfg.color=cfg.color?new Uint8Array([Math.floor(cfg.color[0]*255),Math.floor(cfg.color[1]*255),Math.floor(cfg.color[2]*255)]):defaultCompressedColor;cfg.opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;// RTC
|
|
18972
19034
|
if(cfg.positions){var rtcCenter=math.vec3();var rtcPositions=[];var rtcNeeded=worldToRTCPositions(cfg.positions,rtcPositions,rtcCenter);if(rtcNeeded){cfg.positions=rtcPositions;cfg.origin=math.addVec3(cfg.origin,rtcCenter,rtcCenter);}}// COMPRESSION
|
|
18973
19035
|
if(cfg.positions){var aabb=math.collapseAABB3();cfg.positionsDecodeMatrix=math.mat4();math.expandAABB3Points3(aabb,cfg.positions);cfg.positionsCompressed=quantizePositions(cfg.positions,aabb,cfg.positionsDecodeMatrix);cfg.aabb=aabb;}else if(cfg.positionsCompressed){var _aabb3=math.collapseAABB3();math.expandAABB3Points3(_aabb3,cfg.positionsCompressed);geometryCompressionUtils.decompressAABB(_aabb3,cfg.positionsDecodeMatrix);cfg.aabb=_aabb3;}if(cfg.buckets){var _aabb4=math.collapseAABB3();for(var _i377=0,len=cfg.buckets.length;_i377<len;_i377++){var bucket=cfg.buckets[_i377];if(bucket.positions){math.expandAABB3Points3(_aabb4,bucket.positions);}else if(bucket.positionsCompressed){math.expandAABB3Points3(_aabb4,bucket.positionsCompressed);}}if(cfg.positionsDecodeMatrix){geometryCompressionUtils.decompressAABB(_aabb4,cfg.positionsDecodeMatrix);}cfg.aabb=_aabb4;}if(cfg.meshMatrix){math.AABB3ToOBB3(cfg.aabb,tempOBB3);math.transformOBB3(cfg.meshMatrix,tempOBB3);math.OBB3ToAABB3(tempOBB3,cfg.aabb);}// EDGES
|
|
18974
|
-
if(!cfg.buckets
|
|
19036
|
+
if(!cfg.buckets&&(!cfg.edgeIndices||cfg.edgeIndices.length===0)&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")){if(cfg.positions){// Faster
|
|
18975
19037
|
cfg.edgeIndices=buildEdgeIndices(cfg.positions,cfg.indices,null,2.0);}else{cfg.edgeIndices=buildEdgeIndices(cfg.positionsCompressed,cfg.indices,cfg.positionsDecodeMatrix,2.0);}}// BUCKETING
|
|
18976
19038
|
if(!cfg.buckets){cfg.buckets=createDTXBuckets(cfg,this._enableVertexWelding&&this._enableIndexBucketing);}}else{// VBO
|
|
18977
19039
|
cfg.type=VBO_BATCHED;// PBR
|
|
18978
19040
|
cfg.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];cfg.opacity=cfg.opacity!==undefined&&cfg.opacity!==null?Math.floor(cfg.opacity*255):255;cfg.metallic=cfg.metallic!==undefined&&cfg.metallic!==null?Math.floor(cfg.metallic*255):0;cfg.roughness=cfg.roughness!==undefined&&cfg.roughness!==null?Math.floor(cfg.roughness*255):255;// RTC
|
|
18979
19041
|
if(cfg.positions){var _rtcPositions=[];var _rtcNeeded=worldToRTCPositions(cfg.positions,_rtcPositions,tempVec3a$8);if(_rtcNeeded){cfg.positions=_rtcPositions;cfg.origin=math.addVec3(cfg.origin,tempVec3a$8,math.vec3());}}if(cfg.positions){var _aabb5=math.collapseAABB3();if(cfg.meshMatrix){math.transformPositions3(cfg.meshMatrix,cfg.positions,cfg.positions);cfg.meshMatrix=null;// Positions now baked, don't need any more
|
|
18980
19042
|
}math.expandAABB3Points3(_aabb5,cfg.positions);cfg.aabb=_aabb5;}else{var _aabb6=math.collapseAABB3();math.expandAABB3Points3(_aabb6,cfg.positionsCompressed);geometryCompressionUtils.decompressAABB(_aabb6,cfg.positionsDecodeMatrix);cfg.aabb=_aabb6;}if(cfg.meshMatrix){math.AABB3ToOBB3(cfg.aabb,tempOBB3);math.transformOBB3(cfg.meshMatrix,tempOBB3);math.OBB3ToAABB3(tempOBB3,cfg.aabb);}// EDGES
|
|
18981
|
-
if(!cfg.buckets
|
|
19043
|
+
if(!cfg.buckets&&(!cfg.edgeIndices||cfg.edgeIndices.length===0)&&(cfg.primitive==="triangles"||cfg.primitive==="solid"||cfg.primitive==="surface")){if(cfg.positions){cfg.edgeIndices=buildEdgeIndices(cfg.positions,cfg.indices,null,2.0);}else{cfg.edgeIndices=buildEdgeIndices(cfg.positionsCompressed,cfg.indices,cfg.positionsDecodeMatrix,2.0);}}// TEXTURE
|
|
18982
19044
|
// cfg.textureSetId = cfg.textureSetId || DEFAULT_TEXTURE_SET_ID;
|
|
18983
19045
|
if(cfg.textureSetId){cfg.textureSet=this._textureSets[cfg.textureSetId];// if (!cfg.textureSet) {
|
|
18984
19046
|
// this.error(
|
|
@@ -21057,7 +21119,14 @@ this._scheduleBuild();}return;}this._buildEntry(entry);}catch(e){this._stats.ski
|
|
|
21057
21119
|
* 幂等:重复调用不会重复建。
|
|
21058
21120
|
*
|
|
21059
21121
|
* @param {"edges"|"planes"|"circles"} level
|
|
21060
|
-
*/},{key:"requireLevel",value:function requireLevel(level){var wantCircles=level==="circles"
|
|
21122
|
+
*/},{key:"requireLevel",value:function requireLevel(level){var wantCircles=level==="circles";// **只升不降**:传 "edges" / "planes" 不会把已经建到含圆的索引作废。
|
|
21123
|
+
//
|
|
21124
|
+
// 这一条很关键(踩过):应用层每次开启测量方式都会按该模式的下限调一次 requireLevel,
|
|
21125
|
+
// 例如"先开圆半径、再开两点测距"就会调 requireLevel("planes")。如果这里允许降级,
|
|
21126
|
+
// 两个后果:① 那些已经建好的网格会被按 planes 级别**重建**(白等一次);
|
|
21127
|
+
// ② 更糟 —— 到最高级时原始数组已经释放(`_built` 清空),之后再也升不回含圆级别,
|
|
21128
|
+
// 那些网格的索引里就永远没有圆,圆半径模式在它们身上失效。
|
|
21129
|
+
if(!wantCircles||this._circles){return;}this._circles=true;// 已经建过的网格要按新级别重来(数组还在 `_built` 里)
|
|
21061
21130
|
if(this._built.length){// 先把已消费的头部压掉,避免 pending 里混着"已建过"的前缀
|
|
21062
21131
|
if(this._consumed){this._pending.splice(0,this._consumed);this._consumed=0;}for(var _i453=0;_i453<this._built.length;_i453++){this._pending.push(this._built[_i453]);}this._built.length=0;this._cache=new WeakMap();// 缓存里的旧级别索引作废
|
|
21063
21132
|
}if(this._wantIndex){this._scheduleBuild();}}/** 同步建完(测试 / 需要立刻可用时)。 */},{key:"buildPendingSync",value:function buildPendingSync(){this._wantIndex=true;while(this._consumed<this._pending.length){this._buildEntry(this._pending[this._consumed++]);}this._compactPending();this._indexing=false;this._notifyIndexed();}/** 把游标前面的已建条目一次性切掉(O(n) 一次,代替逐次 `shift()` 的 O(n²))。 */},{key:"_compactPending",value:function _compactPending(){if(this._consumed>0){this._pending.splice(0,this._consumed);this._consumed=0;}}/**
|
|
@@ -21069,7 +21138,13 @@ if(this._consumed){this._pending.splice(0,this._consumed);this._consumed=0;}for(
|
|
|
21069
21138
|
* 一次「切片」= 一小段连续构建时间;切片结束就重新向浏览器要下一个时段:
|
|
21070
21139
|
* 有 `requestIdleCallback` 就用它(空闲时几乎一次干完),没有就退回按帧切片。
|
|
21071
21140
|
* 每片至少建一个网格(否则某些极端场景下会一直空转)。
|
|
21072
|
-
*/},{key:"_scheduleBuild",value:function _scheduleBuild(){var _this93=this
|
|
21141
|
+
*/},{key:"_scheduleBuild",value:function _scheduleBuild(){var _this93=this;// 已经在建了:**直接返回**,不要在这里 `_notifyIndexed()`。
|
|
21142
|
+
//
|
|
21143
|
+
// 踩过:升级级别(`requireLevel`)时它会自己把构建启动起来,紧接着控制层才调 `wantIndex()`
|
|
21144
|
+
// 注册"建完"回调。如果这里把回调当"已完成"提前触发,控制层就会立刻收掉转圈和那句等待提示,
|
|
21145
|
+
// 然后剩下几秒在**没有任何提示**的情况下建索引(用户以为卡死了)。
|
|
21146
|
+
// 正确的语义是:回调由 `_indexedCallbacks` 攒着,等这一轮真的建完时统一通知。
|
|
21147
|
+
if(this._indexing){return;}if(this.pending<=0){this._notifyIndexed();return;}this._indexing=true;this._forcedSlices=0;// 新一轮构建:重新试 idle
|
|
21073
21148
|
var gen=this._gen;var _slice=function slice(deadline){_this93._idleHandle=null;if(gen!==_this93._gen){// destroy 过了(换模型 / 关工具):这轮别再碰任何东西
|
|
21074
21149
|
return;}var start=_this93._now();var budget=_this93._sliceBudget(deadline);var built=0;while(_this93._consumed<_this93._pending.length&&(built===0||_this93._now()-start<budget)){_this93._buildEntry(_this93._pending[_this93._consumed++]);built++;}if(_this93._consumed>=_this93._pending.length){_this93._compactPending();_this93._indexing=false;_this93._notifyIndexed();return;}// 还没建完:把这一片已经建过的从队首切掉,再要下一个时段。
|
|
21075
21150
|
// (一个网格若是超大,单片可能超预算 —— 这也是为什么至少建一个。)
|
|
@@ -21666,6 +21741,10 @@ if(this._relation.type==="point-edge"||this._relation.type==="point-face"){item.
|
|
|
21666
21741
|
* the spot) and are gone. `quarter` etc. stay because they are genuinely useful names.
|
|
21667
21742
|
*/var SPECIAL_POINT_TEXT={endpoint:"端点",vertex:"端点",midpoint:"中点",quarter:"四分点",foot:"垂足",intersection:"交点",// 圆环上的点:形状已经说明了,不需要再多一个词
|
|
21668
21743
|
"on-circle":""};/**
|
|
21744
|
+
* 首次开启测量、正在建特征索引时,给用户的一句解释(显示在转圈控件下面)。
|
|
21745
|
+
*
|
|
21746
|
+
* 索引要算几秒,用户不知道就会以为卡死了 —— 说明"要等"以及"为什么要等"就够了,别写成说明书。
|
|
21747
|
+
*/var MEASURE_INDEX_HINT="正在准备测量数据,首次使用需要几秒,请稍候…";/**
|
|
21669
21748
|
* Mouse control for {@link ProMeasurementsPlugin}.
|
|
21670
21749
|
*
|
|
21671
21750
|
* Interaction (phase 1 - "point mode"):
|
|
@@ -21685,9 +21764,14 @@ if(this._relation.type==="point-edge"||this._relation.type==="point-face"){item.
|
|
|
21685
21764
|
* @param {PointerLens} [cfg.pointerLens]
|
|
21686
21765
|
* @param {Boolean} [cfg.snapping=true]
|
|
21687
21766
|
* @param {String[]} [cfg.featureTypes] Candidate types to consider.
|
|
21688
|
-
*/function ProMeasurementsMouseControl(plugin){var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,ProMeasurementsMouseControl);this.plugin=plugin;this.viewer=plugin.viewer;this.scene=plugin.viewer.scene
|
|
21767
|
+
*/function ProMeasurementsMouseControl(plugin){var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,ProMeasurementsMouseControl);this.plugin=plugin;this.viewer=plugin.viewer;this.scene=plugin.viewer.scene;// 建索引期间显示在转圈下面的一句话(可以传空 = 不显示)
|
|
21768
|
+
this._indexHint=cfg.indexHint!==undefined?cfg.indexHint:MEASURE_INDEX_HINT;this.pointerLens=cfg.pointerLens||null;this._snapping=cfg.snapping!==false;this._offsetX=cfg.offsetX!==undefined?cfg.offsetX:0;this._offsetY=cfg.offsetY!==undefined?cfg.offsetY:0;this._featureTypes=cfg.featureTypes||["endpoint","midpoint","quarter","foot","on-edge","edge-point","surface"];this._active=false;this._activated=false;this._currentMeasurement=null;this._clickCanvasPos=[0,0];this._canvasPos=[0,0];this._hoverResult=null;this._hoverCanvasPos=null;this._cycleIndex=0;this._lastCycleCanvasPos=[0,0];this._bind();}return _createClass(ProMeasurementsMouseControl,[{key:"active",get:function get(){return this._active;},set:function set(active){this._active=!!active;if(!this._active){this.plugin.overlay.hideHover();if(this.pointerLens){this.pointerLens.visible=false;}return;}// 开启测量方式 = 这时才做特征索引的预处理(加载模型时不付这份开销)。
|
|
21689
21769
|
// 索引是分批建的(每帧一小段),所以不会白屏;建完前测量仍可用,只是只能点到面上的自由点。
|
|
21690
21770
|
this._requestFeatureIndex();}/**
|
|
21771
|
+
* 给转圈控件设置/清除一句说明文字。
|
|
21772
|
+
*
|
|
21773
|
+
* 引擎的 Spinner 可能没实现 `text`(旧版本),所以用 `"text" in spinner` 探一下,不存在就静默跳过。
|
|
21774
|
+
*/},{key:"_setSpinnerHint",value:function _setSpinnerHint(spinner,text){if(spinner&&"text"in spinner){spinner.text=text;}}/**
|
|
21691
21775
|
* 开启测量时触发一次特征索引构建(幂等,重复开启不会重复建)。
|
|
21692
21776
|
*
|
|
21693
21777
|
* 加载模型时 `FeatureIndexStore` 只把几何数组抓下来(零成本),真正的重活在这里、
|
|
@@ -21696,19 +21780,24 @@ this._requestFeatureIndex();}/**
|
|
|
21696
21780
|
// 注意:**没有**"只建边"这个级别 —— 模型的边一半来自引擎的 edgeIndices、一半来自面聚类的边界环,
|
|
21697
21781
|
// 跳过聚类会让很多模型(特别是构件被切得很碎的 XTC)索引里一条边都没有,hover 反而比不建索引还差。
|
|
21698
21782
|
// (viewer 也可以显式下发 features,两边结论一致;这里只是兜底,保证 core 单独用也不会缺料。)
|
|
21699
|
-
if(typeof store.requireLevel==="function"){var kinds=this.plugin&&this.plugin.featureKinds||[];var level=kinds.indexOf("circle")!==-1?"circles":"planes";store.requireLevel(level);}var spinner=this.scene.canvas&&this.scene.canvas.spinner;var stats=store.getStats?store.getStats():null;var pending=store.pending;if(!pending){// 没有待处理的网格 →
|
|
21700
|
-
if(stats&&stats.enabled===false){console.log("[ProMeasurements] 未装特征索引(features.enabled = false):只能点到面上的自由点");}else if(stats&&!stats.indexed){console.log(stats.meshes?"[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u4E3A\u7A7A\uFF1A\u6CA1\u6709\u6293\u5230\u53EF\u7D22\u5F15\u7684\u7F51\u683C\uFF08\u5EFA\u4E86 ".concat(stats.meshes," \u4E2A / \u8DF3\u8FC7 ").concat(stats.skipped," \u4E2A\uFF09\u3002")+"注意:索引 store 必须在 loadModel 之前装上,装晚了就什么都抓不到(现象:只有点能用,边/面/圆全无效)":"[ProMeasurements] 特征索引存储已就绪:还没有网格(模型加载时抓数组,点开测量时分批构建)");}else if(stats){console.log("[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u5DF2\u5C31\u7EEA\uFF1A".concat(stats.indexed,"/").concat(stats.meshes," \u4E2A\u7F51\u683C \xB7 ").concat(stats.buildMs," ms"));}return;}if(spinner){spinner.visible=true;}//
|
|
21783
|
+
if(typeof store.requireLevel==="function"){var kinds=this.plugin&&this.plugin.featureKinds||[];var level=kinds.indexOf("circle")!==-1?"circles":"planes";store.requireLevel(level);}var spinner=this.scene.canvas&&this.scene.canvas.spinner;var stats=store.getStats?store.getStats():null;var pending=store.pending;if(!pending){// 没有待处理的网格 → 不转圈;顺便把可能残留的提示清掉。
|
|
21784
|
+
this._setSpinnerHint(spinner,"");if(stats&&stats.enabled===false){console.log("[ProMeasurements] 未装特征索引(features.enabled = false):只能点到面上的自由点");}else if(stats&&!stats.indexed){console.log(stats.meshes?"[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u4E3A\u7A7A\uFF1A\u6CA1\u6709\u6293\u5230\u53EF\u7D22\u5F15\u7684\u7F51\u683C\uFF08\u5EFA\u4E86 ".concat(stats.meshes," \u4E2A / \u8DF3\u8FC7 ").concat(stats.skipped," \u4E2A\uFF09\u3002")+"注意:索引 store 必须在 loadModel 之前装上,装晚了就什么都抓不到(现象:只有点能用,边/面/圆全无效)":"[ProMeasurements] 特征索引存储已就绪:还没有网格(模型加载时抓数组,点开测量时分批构建)");}else if(stats){console.log("[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u5DF2\u5C31\u7EEA\uFF1A".concat(stats.indexed,"/").concat(stats.meshes," \u4E2A\u7F51\u683C \xB7 ").concat(stats.buildMs," ms"));}return;}if(spinner){spinner.visible=true;}// 转圈下面给一句解释:索引不是免费的,但每个模型只算一次(用户不知道为什么要等就会以为卡了)。
|
|
21785
|
+
this._setSpinnerHint(spinner,this._indexHint);// 快速模式:转圈期间用户就是在等这件事,允许每片多干一点(空闲时一次建完);
|
|
21701
21786
|
// 建完立刻关掉,之后的正常操作不受影响。
|
|
21702
|
-
if("fast"in store){store.fast=true;}var t0=Date.now();console.log("[ProMeasurements] \u5F00\u59CB\u5EFA\u7279\u5F81\u7D22\u5F15\uFF1A".concat(pending," \u4E2A\u7F51\u683C \xB7 \u7EA7\u522B ").concat(stats?stats.level:"edges","\uFF08\u7A7A\u95F2\u4F18\u5148\uFF0C\u4E0D\u963B\u585E\uFF09"));store.wantIndex(function(stats){
|
|
21787
|
+
if("fast"in store){store.fast=true;}var t0=Date.now();console.log("[ProMeasurements] \u5F00\u59CB\u5EFA\u7279\u5F81\u7D22\u5F15\uFF1A".concat(pending," \u4E2A\u7F51\u683C \xB7 \u7EA7\u522B ").concat(stats?stats.level:"edges","\uFF08\u7A7A\u95F2\u4F18\u5148\uFF0C\u4E0D\u963B\u585E\uFF09"));store.wantIndex(function(stats){// 保险:万一回调在"还在建"的时候被触发(例如将来又有人动了调度),
|
|
21788
|
+
// 也不能把转圈和等待提示收掉 —— 否则用户面对的是几秒钟毫无反馈的等待。
|
|
21789
|
+
if(store.indexing||store.pending>0){return;}if(spinner){spinner.visible=false;}// 建完了,提示也要拿掉(这个转圈是公用的,模型加载时还会用到)
|
|
21790
|
+
_this99._setSpinnerHint(spinner,"");if("fast"in store){store.fast=false;}// 索引多了新的网格 → hover 缓存作废(之前“吸不到”的位置现在可能吸得到了)
|
|
21703
21791
|
var probe=_this99.plugin.probe;if(probe&&typeof probe.invalidate==="function"){probe.invalidate();}// 索引内容也打出来:万一只吸不到东西,这一行能直接看出是缺边、缺面还是根本没建。
|
|
21704
|
-
console.log("[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u5C31\u7EEA\uFF1A".concat(stats.indexed,"/").concat(stats.meshes," \u4E2A\u7F51\u683C \xB7 ")+"\u9876\u70B9 ".concat(stats.vertices," \xB7 \u8FB9 ").concat(stats.edgeCount," \xB7 \u9762 ").concat(stats.planeCount," \xB7 \u5706 ").concat(stats.circleCount," \xB7 ")+"\u5899\u4E0A ".concat(Date.now()-t0," ms \xB7 CPU ").concat(stats.buildMs," ms"));if(!stats.edgeCount){console.warn("[ProMeasurements] 警告:索引里一条边都没有 —— 这个模型的网格既没有引擎 edgeIndices,"+"聚类也没聚出边界环(例如每个网格只有几个三角形)。此时 hover 只能吸到面上的自由点。");}});}},{key:"snapping",get:function get(){return this._snapping;},set:function set(snapping){this._snapping=!!snapping;}/**
|
|
21792
|
+
console.log("[ProMeasurements] \u7279\u5F81\u7D22\u5F15\u5C31\u7EEA\uFF1A".concat(stats.indexed,"/").concat(stats.meshes," \u4E2A\u7F51\u683C \xB7 ")+"\u9876\u70B9 ".concat(stats.vertices," \xB7 \u8FB9 ").concat(stats.edgeCount," \xB7 \u9762 ").concat(stats.planeCount," \xB7 \u5706 ").concat(stats.circleCount," \xB7 ")+"\u5899\u4E0A ".concat(Date.now()-t0," ms \xB7 CPU ").concat(stats.buildMs," ms"));if(!stats.edgeCount){console.warn("[ProMeasurements] 警告:索引里一条边都没有 —— 这个模型的网格既没有引擎 edgeIndices,"+"聚类也没聚出边界环(例如每个网格只有几个三角形)。此时 hover 只能吸到面上的自由点。"+"\uFF08\u5DF2\u5EFA ".concat(stats.indexed," / \u6293\u4E86 ").concat(stats.meshes," \u4E2A\u7F51\u683C \xB7 \u9762 ").concat(stats.planeCount," \xB7 \u8DF3\u8FC7 ").concat(stats.skipped,"\uFF09"));}});}},{key:"snapping",get:function get(){return this._snapping;},set:function set(snapping){this._snapping=!!snapping;}/**
|
|
21705
21793
|
* Pointer offset (pixels) added to the picked canvas position.
|
|
21706
21794
|
*
|
|
21707
21795
|
* Same meaning as on the legacy mouse / touch controls: on a touch screen the finger covers the point
|
|
21708
21796
|
* being measured, so the app passes a fingertip compensation here. Every calculation that depends on
|
|
21709
21797
|
* where the pointer is - hover, snapping, the click, the WYSIWYG tolerance - follows it, so the marker
|
|
21710
21798
|
* and the picked geometry stay consistent with each other.
|
|
21711
|
-
*/},{key:"offsetX",get:function get(){return this._offsetX;},set:function set(offsetX){this._offsetX=offsetX||0;}},{key:"offsetY",get:function get(){return this._offsetY;},set:function set(offsetY){this._offsetY=offsetY||0;}},{key:"autoFocus",get:function get(){return this.plugin.probe.autoFocus;},set:function set(value){this.plugin.probe.autoFocus=value;}},{key:"currentMeasurement",get:function get(){return this._currentMeasurement;}/** Number of measurements created by this control (informational). */},{key:"numMeasurements",get:function get(){return this.plugin.numMeasurements;}},{key:"activate",value:function activate(){if(this._activated){return;}this._activated=true;this.fire("activated",true);}},{key:"deactivate",value:function deactivate(){if(!this._activated){return;}this._activated=false;this.reset();this.plugin.overlay.hideHover();if(this.pointerLens){this.pointerLens.visible=false;}this.fire("activated",false);}/** Cancels the measurement in progress (if any). */},{key:"reset",value:function reset(){if(this._currentMeasurement){this.plugin.fire("measurementCancel",this._currentMeasurement);this.plugin.destroyMeasurement(this._currentMeasurement.id);this._currentMeasurement=null;}this._cycleIndex=0;}},{key:"destroy",value:function destroy(){this.deactivate();this._unbind()
|
|
21799
|
+
*/},{key:"offsetX",get:function get(){return this._offsetX;},set:function set(offsetX){this._offsetX=offsetX||0;}},{key:"offsetY",get:function get(){return this._offsetY;},set:function set(offsetY){this._offsetY=offsetY||0;}},{key:"autoFocus",get:function get(){return this.plugin.probe.autoFocus;},set:function set(value){this.plugin.probe.autoFocus=value;}},{key:"currentMeasurement",get:function get(){return this._currentMeasurement;}/** Number of measurements created by this control (informational). */},{key:"numMeasurements",get:function get(){return this.plugin.numMeasurements;}},{key:"activate",value:function activate(){if(this._activated){return;}this._activated=true;this.fire("activated",true);}},{key:"deactivate",value:function deactivate(){if(!this._activated){return;}this._activated=false;this.reset();this.plugin.overlay.hideHover();if(this.pointerLens){this.pointerLens.visible=false;}this.fire("activated",false);}/** Cancels the measurement in progress (if any). */},{key:"reset",value:function reset(){if(this._currentMeasurement){this.plugin.fire("measurementCancel",this._currentMeasurement);this.plugin.destroyMeasurement(this._currentMeasurement.id);this._currentMeasurement=null;}this._cycleIndex=0;}},{key:"destroy",value:function destroy(){this.deactivate();this._unbind();// 插件没了 → 把那句提示也收掉(转圈是公用的,模型加载还要用)
|
|
21800
|
+
var spinner=this.scene&&this.scene.canvas&&this.scene.canvas.spinner;this._setSpinnerHint(spinner,"");}// ---------------------------------------------------------------------------------------------
|
|
21712
21801
|
},{key:"_bind",value:function _bind(){var _this100=this;if(this._bound){return;}this._bound=true;var canvas=this.scene.canvas.canvas;this._onPointerMove=function(event){if(!_this100._active){return;}if(_this100._pointerDown){// While the button is down: if the user is actually dragging (orbit / pan) get out of the way,
|
|
21713
21802
|
// otherwise **keep the hover as it is** - the next click has to select exactly what is
|
|
21714
21803
|
// highlighted, and re-probing is what used to lose the edge.
|
|
@@ -21907,7 +21996,8 @@ solvedFeature={kind:"point",worldPos:worldPos,pointType:candidate?candidate.type
|
|
|
21907
21996
|
*/function ProMeasurementsPlugin(viewer){var _this101;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,ProMeasurementsPlugin);_this101=_callSuper(this,ProMeasurementsPlugin,[cfg.id||"ProMeasurementsPlugin".concat(proPluginCount++),viewer]);_this101._mode=cfg.mode||"all";_this101._pickMode=cfg.pickMode||"point";_this101._edgeMode=cfg.edgeMode||"distance";// 点选模式的"单击即完成"(标高用);特征模式对应的是 `edgeMode: "length"`
|
|
21908
21997
|
_this101._singlePick=cfg.singlePick===true;_this101._featureKinds=cfg.featureKinds||null;_this101._rejectSkew=cfg.rejectSkew===true;_this101._rejectParallel=cfg.rejectParallel===true;_this101._rejectDegenerate=cfg.rejectDegenerate===true;_this101._degenerateTolerance=cfg.degenerateTolerance!==undefined?cfg.degenerateTolerance:1e-3;_this101._highlightFaces=cfg.highlightFaces===true;_this101._pickRadius=cfg.pickRadius!==undefined?cfg.pickRadius:30;_this101._highlightSlotConfig=cfg.highlightSlot||{};_this101._defaultColor=cfg.defaultColor||"#0065FC";_this101._precision=cfg.precision!==undefined?cfg.precision:2;_this101._angleTolerance=cfg.angleTolerance!==undefined?cfg.angleTolerance:1;_this101._measurements={};_this101._numMeasurements=0;_this101._measurementsShown=true;// Feature index (SceneModel#_createMesh fills it), overlay, hover highlight and probe are shared
|
|
21909
21998
|
// with every other pro-measurement plugin in this viewer.
|
|
21910
|
-
_this101._shared=acquireShared(viewer,cfg);_this101._featureStore=_this101._shared.store;_this101._overlay=_this101._shared.overlay;_this101._highlight=_this101._shared.highlight;_this101._probe=_this101._shared.probe;_this101._probe.autoFocus=cfg.autoFocus!==false;_this101._probe.focusRadius=cfg.focusRadius!==undefined?cfg.focusRadius:14;_this101._control=new ProMeasurementsMouseControl(_this101,{pointerLens:cfg.pointerLens,snapping:cfg.snapping!==false,featureTypes:cfg.featureTypes,offsetX:cfg.offsetX,offsetY:cfg.offsetY
|
|
21999
|
+
_this101._shared=acquireShared(viewer,cfg);_this101._featureStore=_this101._shared.store;_this101._overlay=_this101._shared.overlay;_this101._highlight=_this101._shared.highlight;_this101._probe=_this101._shared.probe;_this101._probe.autoFocus=cfg.autoFocus!==false;_this101._probe.focusRadius=cfg.focusRadius!==undefined?cfg.focusRadius:14;_this101._control=new ProMeasurementsMouseControl(_this101,{pointerLens:cfg.pointerLens,snapping:cfg.snapping!==false,featureTypes:cfg.featureTypes,offsetX:cfg.offsetX,offsetY:cfg.offsetY,// 建特征索引时显示在转圈下面的一句解释(不传用 core 的默认中文;应用层要 i18n 就传自己的)
|
|
22000
|
+
indexHint:cfg.indexHint});return _this101;}/** `"distance"`, `"angle"` or `"all"`. */_inherits(ProMeasurementsPlugin,_Plugin6);return _createClass(ProMeasurementsPlugin,[{key:"mode",get:function get(){return this._mode;}/**
|
|
21911
22001
|
* Whether this plugin accepts a solved relation.
|
|
21912
22002
|
*
|
|
21913
22003
|
* Kept as a convenience wrapper around `rejectionReason` - the control uses the *reason*, so it can
|
|
@@ -21963,7 +22053,11 @@ _this101._shared=acquireShared(viewer,cfg);_this101._featureStore=_this101._shar
|
|
|
21963
22053
|
* 不应该留下来一条标高标识。传 `null` 卸掉。
|
|
21964
22054
|
*
|
|
21965
22055
|
* @param {((feature: Object, result: Object) => Boolean) | null} fn
|
|
21966
|
-
*/},{key:"setPickInterceptor",value:function setPickInterceptor(fn){this._pickInterceptor=typeof fn==="function"?fn:null;}/** @private 鼠标控件专用:没装拦截器 / 没命中都返回 `false`,走正常测量流程。 */},{key:"handlePick",value:function handlePick(feature,result){if(!this._pickInterceptor){return false;}return this._pickInterceptor(feature,result)===true;}},{key:"probe",get:function get(){return this._probe;}},{key:"defaultColor",get:function get(){return this._defaultColor;}},{key:"angleTolerance",get:function get(){return this._angleTolerance;}},{key:"container",get:function get(){return this._shared.overlay?this._shared.overlay._container:null;}},{key:"control",get:function get(){return this._control;}/** The multiplier from world units to the displayed unit (see `scene.metrics`). */},{key:"valueScale",get:function get(){var scale=this.viewer.scene.metrics.scale;return scale===undefined||scale===null?1:scale;}},{key:"unitAbbrev",get:function get(){var metrics=this.viewer.scene.metrics;var info=metrics.unitsInfo?metrics.unitsInfo[metrics.units]:null;return info&&info.abbrev||metrics.units||"";}},{key:"precision",get:function get(){return this._precision;},set:function set(value){this._precision=value;for(var id in this._measurements){this._measurements[id]._refresh();}}},{key:"snapping",get:function get(){return this._control.snapping;},set:function set(value){this._control.snapping=value;}},{key:"autoFocus",get:function get(){return this._probe.autoFocus;},set:function set(value){this._probe.autoFocus=value;}},{key:"focusRadius",get:function get(){return this._probe.focusRadius;},set:function set(value){this._probe.focusRadius=value;}},{key:"measurementsShown",get:function get(){return this._measurementsShown;}/** Number of created measurements. */,set:function set(value){this._measurementsShown=!!value;for(var id in this._measurements){this._measurements[id].setVisible(this._measurementsShown);}}},{key:"numMeasurements",get:function get(){return this._numMeasurements;}},{key:"measurements",get:function get(){return this._measurements;}/** Feature index statistics - useful while tuning (how many meshes were indexed). */},{key:"getFeatureStats",value:function getFeatureStats(){return this._featureStore.getStats();}
|
|
22056
|
+
*/},{key:"setPickInterceptor",value:function setPickInterceptor(fn){this._pickInterceptor=typeof fn==="function"?fn:null;}/** @private 鼠标控件专用:没装拦截器 / 没命中都返回 `false`,走正常测量流程。 */},{key:"handlePick",value:function handlePick(feature,result){if(!this._pickInterceptor){return false;}return this._pickInterceptor(feature,result)===true;}},{key:"probe",get:function get(){return this._probe;}},{key:"defaultColor",get:function get(){return this._defaultColor;}},{key:"angleTolerance",get:function get(){return this._angleTolerance;}},{key:"container",get:function get(){return this._shared.overlay?this._shared.overlay._container:null;}},{key:"control",get:function get(){return this._control;}/** The multiplier from world units to the displayed unit (see `scene.metrics`). */},{key:"valueScale",get:function get(){var scale=this.viewer.scene.metrics.scale;return scale===undefined||scale===null?1:scale;}},{key:"unitAbbrev",get:function get(){var metrics=this.viewer.scene.metrics;var info=metrics.unitsInfo?metrics.unitsInfo[metrics.units]:null;return info&&info.abbrev||metrics.units||"";}},{key:"precision",get:function get(){return this._precision;},set:function set(value){this._precision=value;for(var id in this._measurements){this._measurements[id]._refresh();}}},{key:"snapping",get:function get(){return this._control.snapping;},set:function set(value){this._control.snapping=value;}},{key:"autoFocus",get:function get(){return this._probe.autoFocus;},set:function set(value){this._probe.autoFocus=value;}},{key:"focusRadius",get:function get(){return this._probe.focusRadius;},set:function set(value){this._probe.focusRadius=value;}},{key:"measurementsShown",get:function get(){return this._measurementsShown;}/** Number of created measurements. */,set:function set(value){this._measurementsShown=!!value;for(var id in this._measurements){this._measurements[id].setVisible(this._measurementsShown);}}},{key:"numMeasurements",get:function get(){return this._numMeasurements;}},{key:"measurements",get:function get(){return this._measurements;}/** Feature index statistics - useful while tuning (how many meshes were indexed). */},{key:"getFeatureStats",value:function getFeatureStats(){return this._featureStore.getStats();}/**
|
|
22057
|
+
* hover 耗时统计(调优用):真正探了几次、命中几次缓存、平均打几枪、平均几毫秒。
|
|
22058
|
+
*
|
|
22059
|
+
* 一枪 = 一次全场景渲染 + GPU 回读,所以 `avgPicks` 基本就决定了 hover 卡不卡。
|
|
22060
|
+
*/},{key:"getHoverStats",value:function getHoverStats(){return this._probe&&this._probe.getStats?this._probe.getStats():null;}/** 清掉 hover 统计(想单独量某一段时间时先调它)。 */},{key:"resetHoverStats",value:function resetHoverStats(){if(this._probe&&this._probe.resetStats){this._probe.resetStats();}}// --- measurements -----------------------------------------------------------------------------
|
|
21967
22061
|
},{key:"createMouseControl",value:function createMouseControl(){var cfg=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new ProMeasurementsMouseControl(this,cfg);}/**
|
|
21968
22062
|
* Creates a measurement between two features.
|
|
21969
22063
|
*
|
|
@@ -24829,7 +24923,9 @@ if(Math.abs(updates.panDeltaX)<EPSILON*dynamicEPSILON){updates.panDeltaX=0;}if(M
|
|
|
24829
24923
|
// Dollying
|
|
24830
24924
|
//----------------------------------------------------------------------------------------------------------
|
|
24831
24925
|
if(dollyDeltaForDist!==0){if(dollyDeltaForDist<0){cursorType="zoom-in";}else{cursorType="zoom-out";}if(configs.firstPerson){var _verticalEye;var _verticalLook;if(configs.constrainVertical){if(camera.xUp){_verticalEye=camera.eye[0];_verticalLook=camera.look[0];}else if(camera.yUp){_verticalEye=camera.eye[1];_verticalLook=camera.look[1];}else if(camera.zUp){_verticalEye=camera.eye[2];_verticalLook=camera.look[2];}}if(configs.followPointer){var dolliedThroughSurface=panController.dollyToCanvasPos(followPointerWorldPos,states.pointerCanvasPos,-dollyDeltaForDist);if(dolliedThroughSurface){states.followPointerDirty=true;}}else{camera.pan([0,0,dollyDeltaForDist]);camera.ortho.scale=camera.ortho.scale-dollyDeltaForDist;}if(configs.constrainVertical){var _eye=camera.eye;var _look=camera.look;if(camera.xUp){_eye[0]=_verticalEye;_look[0]=_verticalLook;}else if(camera.yUp){_eye[1]=_verticalEye;_look[1]=_verticalLook;}else if(camera.zUp){_eye[2]=_verticalEye;_look[2]=_verticalLook;}camera.eye=_eye;camera.look=_look;}}else if(configs.planView){if(configs.followPointer){var _dolliedThroughSurface=panController.dollyToCanvasPos(followPointerWorldPos,states.pointerCanvasPos,-dollyDeltaForDist);if(_dolliedThroughSurface){states.followPointerDirty=true;}}else{camera.ortho.scale=camera.ortho.scale+dollyDeltaForDist;camera.zoom(dollyDeltaForDist);}}else{// Orbiting
|
|
24832
|
-
if(configs.followPointer){var _dolliedThroughSurface2=panController.dollyToCanvasPos(followPointerWorldPos,states.pointerCanvasPos,-dollyDeltaForDist);if(_dolliedThroughSurface2){states.followPointerDirty=true;}}else{camera.ortho.scale=camera.ortho.scale+dollyDeltaForDist;camera.zoom(dollyDeltaForDist);}}updates.dollyDelta*=configs.dollyInertia;}pickController.fireEvents()
|
|
24926
|
+
if(configs.followPointer){var _dolliedThroughSurface2=panController.dollyToCanvasPos(followPointerWorldPos,states.pointerCanvasPos,-dollyDeltaForDist);if(_dolliedThroughSurface2){states.followPointerDirty=true;}}else{camera.ortho.scale=camera.ortho.scale+dollyDeltaForDist;camera.zoom(dollyDeltaForDist);}}updates.dollyDelta*=configs.dollyInertia;}pickController.fireEvents();// 没有创建 NavCubePlugin 时 viewer.navCube 为 undefined(如最小 demo),
|
|
24927
|
+
// 旧代码会每帧抛异常并中断渲染循环;这里做空值保护。
|
|
24928
|
+
if(!viewer.navCube||!viewer.navCube.MOUSEDOWN&&!viewer.navCube.MOUSEOVER){document.body.style.cursor=cursorType;}});}return _createClass(CameraUpdater,[{key:"destroy",value:function destroy(){this._scene.off(this._onTick);}}]);}();/**
|
|
24833
24929
|
* @private
|
|
24834
24930
|
*/var MouseMiscHandler=/*#__PURE__*/function(){function MouseMiscHandler(scene,controllers,configs,states,updates){var _this125=this;_classCallCheck(this,MouseMiscHandler);this._scene=scene;this.canvas=this._scene.canvas.canvas;this.canvas.addEventListener("mouseenter",this._mouseEnterHandler=function(){states.mouseover=true;});this.canvas.addEventListener("mouseleave",this._mouseLeaveHandler=function(){states.mouseover=false;_this125.canvas.style.cursor=null;});document.addEventListener("mousemove",this._mouseMoveHandler=function(e){getCanvasPosFromEvent$2(e,_this125.canvas,states.pointerCanvasPos);});this.canvas.addEventListener("mousedown",this._mouseDownHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}getCanvasPosFromEvent$2(e,_this125.canvas,states.pointerCanvasPos);states.mouseover=true;});this.canvas.addEventListener("mouseup",this._mouseUpHandler=function(e){if(!(configs.active&&configs.pointerEnabled)){return;}});}return _createClass(MouseMiscHandler,[{key:"reset",value:function reset(){}},{key:"destroy",value:function destroy(){//网络问题导致的模型加载失败等情况时,如果切换模型,会找不到canvas
|
|
24835
24931
|
//因此暂时在此加判断
|
|
@@ -26781,6 +26877,7 @@ var documentBackgroundColor=ownerDocument.documentElement?parseColor(context,get
|
|
|
26781
26877
|
* @param {Number[]} [cfg.origin=[0,0,0]] The Real-space 3D origin, in current measurement units, at which the World-space coordinate origin ````[0,0,0]```` sits.
|
|
26782
26878
|
* @param {Boolean} [cfg.saoEnabled=false] Whether to enable Scalable Ambient Obscurance (SAO) effect. See {@link SAO} for more info.
|
|
26783
26879
|
* @param {Boolean} [cfg.antialias=true] Whether to enable anti-aliasing.
|
|
26880
|
+
* @param {Boolean} [cfg.webgl2=true] Whether to request a WebGL2 context when available. WebGL2 is required by data-texture (DTX) rendering.
|
|
26784
26881
|
* @throws {String} Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement.
|
|
26785
26882
|
* @param {Boolean} [cfg.alphaDepthMask=true] Whether writing into the depth buffer is enabled or disabled when rendering transparent objects.
|
|
26786
26883
|
* @param {Boolean} [cfg.entityOffsetsEnabled=false] Whether to enable {@link Entity#offset}. For best performance, only set this ````true```` when you need to use {@link Entity#offset}.
|
|
@@ -26828,7 +26925,7 @@ var documentBackgroundColor=ownerDocument.documentElement?parseColor(context,get
|
|
|
26828
26925
|
* The Viewer's {@link Scene}.
|
|
26829
26926
|
* @property scene
|
|
26830
26927
|
* @type {Scene}
|
|
26831
|
-
*/this.scene=new Scene(this,{canvasId:cfg.canvasId,canvasElement:cfg.canvasElement,keyboardEventsElement:cfg.keyboardEventsElement,contextAttr:{preserveDrawingBuffer:cfg.preserveDrawingBuffer!==false,premultipliedAlpha:!!cfg.premultipliedAlpha,antialias:cfg.antialias!==false},spinnerElementId:cfg.spinnerElementId,transparent:cfg.transparent!==false,gammaInput:true,gammaOutput:false,backgroundColor:cfg.backgroundColor,backgroundColorFromAmbientLight:cfg.backgroundColorFromAmbientLight,ticksPerRender:1,ticksPerOcclusionTest:20,units:cfg.units,scale:cfg.scale,origin:cfg.origin,lightIntensity:cfg.lightIntensity,saoEnabled:cfg.saoEnabled,alphaDepthMask:cfg.alphaDepthMask!==false,entityOffsetsEnabled:!!cfg.entityOffsetsEnabled,pickSurfacePrecisionEnabled:!!cfg.pickSurfacePrecisionEnabled,readableGeometryEnabled:!!cfg.readableGeometryEnabled,logarithmicDepthBufferEnabled:!!cfg.logarithmicDepthBufferEnabled,autoFarPlaneFitEnabled:cfg.autoFarPlaneFitEnabled,pbrEnabled:!!cfg.pbrEnabled,colorTextureEnabled:cfg.colorTextureEnabled!==false,dtxEnabled:!!cfg.dtxEnabled,edgesEnabled:cfg.edgesEnabled,markerZOffset:cfg.markerZOffset,numCachedSectionPlanes:cfg.numCachedSectionPlanes,lodEnabled:!!cfg.lodEnabled,resolutionScale:cfg.resolutionScale,offset:cfg.offset,worldAxis:cfg.worldAxis});/**
|
|
26928
|
+
*/this.scene=new Scene(this,{canvasId:cfg.canvasId,canvasElement:cfg.canvasElement,keyboardEventsElement:cfg.keyboardEventsElement,contextAttr:{preserveDrawingBuffer:cfg.preserveDrawingBuffer!==false,premultipliedAlpha:!!cfg.premultipliedAlpha,antialias:cfg.antialias!==false},spinnerElementId:cfg.spinnerElementId,transparent:cfg.transparent!==false,gammaInput:true,gammaOutput:false,backgroundColor:cfg.backgroundColor,backgroundColorFromAmbientLight:cfg.backgroundColorFromAmbientLight,ticksPerRender:1,ticksPerOcclusionTest:20,units:cfg.units,scale:cfg.scale,origin:cfg.origin,lightIntensity:cfg.lightIntensity,saoEnabled:cfg.saoEnabled,alphaDepthMask:cfg.alphaDepthMask!==false,entityOffsetsEnabled:!!cfg.entityOffsetsEnabled,pickSurfacePrecisionEnabled:!!cfg.pickSurfacePrecisionEnabled,readableGeometryEnabled:!!cfg.readableGeometryEnabled,logarithmicDepthBufferEnabled:!!cfg.logarithmicDepthBufferEnabled,webgl2:cfg.webgl2,autoFarPlaneFitEnabled:cfg.autoFarPlaneFitEnabled,pbrEnabled:!!cfg.pbrEnabled,colorTextureEnabled:cfg.colorTextureEnabled!==false,dtxEnabled:!!cfg.dtxEnabled,edgesEnabled:cfg.edgesEnabled,markerZOffset:cfg.markerZOffset,numCachedSectionPlanes:cfg.numCachedSectionPlanes,lodEnabled:!!cfg.lodEnabled,resolutionScale:cfg.resolutionScale,offset:cfg.offset,worldAxis:cfg.worldAxis});/**
|
|
26832
26929
|
* Metadata about the {@link Scene} and the models and objects within it.
|
|
26833
26930
|
* @property metaScene
|
|
26834
26931
|
* @type {MetaScene}
|
|
@@ -29622,7 +29719,11 @@ var wrapR=eachTextureAttributes[textureAttrBaseIdx+8];// ClampToEdgeWrapping | M
|
|
|
29622
29719
|
if(textureDataPortionExists){var imageDataSubarray=new Uint8Array(textureData.subarray(textureDataPortionStart,textureDataPortionEnd));var arrayBuffer=imageDataSubarray.buffer;var textureId="".concat(modelPartId,"-texture-").concat(textureIndex);if(compressed){sceneModel.createTexture({id:textureId,buffers:[arrayBuffer],minFilter:minFilter,magFilter:magFilter,wrapS:wrapS,wrapT:wrapT,wrapR:wrapR});}else{sceneModel.createTexture({id:textureId,imageBuffer:arrayBuffer,minFilter:minFilter,magFilter:magFilter,wrapS:wrapS,wrapT:wrapT,wrapR:wrapR});}}}// Create texture sets
|
|
29623
29720
|
for(var textureSetIndex=0;textureSetIndex<numTextureSets;textureSetIndex++){var eachTextureSetTexturesIndex=textureSetIndex*5;var textureSetId="".concat(modelPartId,"-textureSet-").concat(textureSetIndex);var colorTextureIndex=eachTextureSetTextures[eachTextureSetTexturesIndex+0];var metallicRoughnessTextureIndex=eachTextureSetTextures[eachTextureSetTexturesIndex+1];var normalsTextureIndex=eachTextureSetTextures[eachTextureSetTexturesIndex+2];var emissiveTextureIndex=eachTextureSetTextures[eachTextureSetTexturesIndex+3];var occlusionTextureIndex=eachTextureSetTextures[eachTextureSetTexturesIndex+4];sceneModel.createTextureSet({id:textureSetId,colorTextureId:colorTextureIndex>=0?"".concat(modelPartId,"-texture-").concat(colorTextureIndex):null,normalsTextureId:normalsTextureIndex>=0?"".concat(modelPartId,"-texture-").concat(normalsTextureIndex):null,metallicRoughnessTextureId:metallicRoughnessTextureIndex>=0?"".concat(modelPartId,"-texture-").concat(metallicRoughnessTextureIndex):null,emissiveTextureId:emissiveTextureIndex>=0?"".concat(modelPartId,"-texture-").concat(emissiveTextureIndex):null,occlusionTextureId:occlusionTextureIndex>=0?"".concat(modelPartId,"-texture-").concat(occlusionTextureIndex):null});}// Count instances of each geometry
|
|
29624
29721
|
var geometryReuseCounts=new Uint32Array(numGeometries);for(var meshIndex=0;meshIndex<numMeshes;meshIndex++){var geometryIndex=eachMeshGeometriesPortion[meshIndex];if(geometryReuseCounts[geometryIndex]!==undefined){geometryReuseCounts[geometryIndex]++;}else{geometryReuseCounts[geometryIndex]=1;}}// Iterate over tiles
|
|
29625
|
-
var tileCenter=math.vec3();var rtcAABB=math.AABB3();var geometryArraysCache={}
|
|
29722
|
+
var tileCenter=math.vec3();var rtcAABB=math.AABB3();var geometryArraysCache={};// A: 复用几何按「几何」全局去重。旧版 geometryId 带 tileIndex 且 created 标记
|
|
29723
|
+
// 在瓦片循环内重建,导致一个全局复用几何被复制成「瓦片数」份(合肥旺芯 15.2万→63万)。
|
|
29724
|
+
// 复用几何的 positionsDecodeMatrix 是全局 reusedGeometriesDecodeMatrix,瓦片偏移
|
|
29725
|
+
// 在 mesh 的 origin 上,因此可以全局共享;只有非复用(batchThisMesh)才每瓦片一份。
|
|
29726
|
+
var geometryCreated={};var reuseGeometries=options.reuseGeometries!==false;for(var tileIndex=0;tileIndex<numTiles;tileIndex++){var lastTileIndex=numTiles-1;var atLastTile=tileIndex===lastTileIndex;var firstTileEntityIndex=eachTileEntitiesPortion[tileIndex];var lastTileEntityIndex=atLastTile?numEntities-1:eachTileEntitiesPortion[tileIndex+1]-1;var tileAABBIndex=tileIndex*6;var tileAABB=eachTileAABB.subarray(tileAABBIndex,tileAABBIndex+6);math.getAABB3Center(tileAABB,tileCenter);rtcAABB[0]=tileAABB[0]-tileCenter[0];rtcAABB[1]=tileAABB[1]-tileCenter[1];rtcAABB[2]=tileAABB[2]-tileCenter[2];rtcAABB[3]=tileAABB[3]-tileCenter[0];rtcAABB[4]=tileAABB[4]-tileCenter[1];rtcAABB[5]=tileAABB[5]-tileCenter[2];var tileDecodeMatrix=geometryCompressionUtils.createPositionsDecodeMatrix(rtcAABB);// Iterate over each tile's entities
|
|
29626
29727
|
for(var tileEntityIndex=firstTileEntityIndex;tileEntityIndex<=lastTileEntityIndex;tileEntityIndex++){var xtcEntityId=eachEntityId[tileEntityIndex];var entityId=options.globalizeObjectIds?math.globalizeObjectId(sceneModel.id,xtcEntityId):xtcEntityId;var finalTileEntityIndex=numEntities-1;var atLastTileEntity=tileEntityIndex===finalTileEntityIndex;var firstMeshIndex=eachEntityMeshesPortion[tileEntityIndex];var lastMeshIndex=atLastTileEntity?eachMeshGeometriesPortion.length-1:eachEntityMeshesPortion[tileEntityIndex+1]-1;var meshIds=[];var metaObject=viewer.metaScene.metaObjects[entityId];var entityDefaults={};var meshDefaults={};if(metaObject){// Mask loading of object types
|
|
29627
29728
|
if(options.excludeTypesMap&&metaObject.type&&options.excludeTypesMap[metaObject.type]){continue;}if(options.includeTypesMap&&metaObject.type&&!options.includeTypesMap[metaObject.type]){continue;}// Get initial property values for object types
|
|
29628
29729
|
var props=options.objectDefaults?options.objectDefaults[metaObject.type]||options.objectDefaults["DEFAULT"]:null;if(props){if(props.visible===false){entityDefaults.visible=false;}if(props.pickable===false){entityDefaults.pickable=false;}if(props.colorize){meshDefaults.color=props.colorize;}if(props.opacity!==undefined&&props.opacity!==null){meshDefaults.opacity=props.opacity;}if(props.metallic!==undefined&&props.metallic!==null){meshDefaults.metallic=props.metallic;}if(props.roughness!==undefined&&props.roughness!==null){meshDefaults.roughness=props.roughness;}}}else{if(options.excludeUnclassifiedObjects){continue;}}// Iterate each entity's meshes
|
|
@@ -29630,8 +29731,8 @@ for(var _meshIndex=firstMeshIndex;_meshIndex<=lastMeshIndex;_meshIndex++){var _g
|
|
|
29630
29731
|
// SceneModel._registerSpaceEntity 统一应用(对齐 Scene#spacesVisible 开关);
|
|
29631
29732
|
// 此处保持导出材质原值,不做特殊处理。
|
|
29632
29733
|
var meshOpacity=meshOpacityByte/255.0;var meshMetallic=eachMeshMaterialAttributes[_meshIndex*6+4]/255.0;var meshRoughness=eachMeshMaterialAttributes[_meshIndex*6+5]/255.0;var meshId=manifestCtx.getNextId();if(isReusedGeometry){// Create mesh for multi-use geometry - create (or reuse) geometry, create mesh using that geometry
|
|
29633
|
-
var meshMatrixIndex=eachMeshMatricesPortion[_meshIndex];var meshMatrix=matrices.slice(meshMatrixIndex,meshMatrixIndex+16);var geometryId="".concat(modelPartId,"-geometry.").concat(tileIndex,".").concat(_geometryIndex);// These IDs are local to the SceneModel
|
|
29634
|
-
var geometryArrays=geometryArraysCache[geometryId];if(!geometryArrays){geometryArrays={batchThisMesh:!options.reuseGeometries};var primitiveType=eachGeometryPrimitiveType[_geometryIndex];var geometryValid=false;switch(primitiveType){case 0:geometryArrays.primitiveName="solid";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryArrays.geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryArrays.geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 1:geometryArrays.primitiveName="surface";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryArrays.geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryArrays.geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 2:geometryArrays.primitiveName="points";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryColors=colors.subarray(eachGeometryColorsPortion[_geometryIndex],atLastGeometry?colors.length:eachGeometryColorsPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0;break;case 3:geometryArrays.primitiveName="lines";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 4:geometryArrays.primitiveName="lines";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=lineStripToLines(geometryArrays.geometryPositions,indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]));geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;default:continue;}if(!geometryValid){geometryArrays=null;}if(geometryArrays){if(geometryArrays.geometryPositions.length>1000);if(geometryArrays.batchThisMesh){geometryArrays.decompressedPositions=new Float32Array(geometryArrays.geometryPositions.length);geometryArrays.transformedAndRecompressedPositions=new Uint16Array(geometryArrays.geometryPositions.length);var geometryPositions=geometryArrays.geometryPositions;var decompressedPositions=geometryArrays.decompressedPositions;for(var _i615=0,len=geometryPositions.length;_i615<len;_i615+=3){decompressedPositions[_i615+0]=geometryPositions[_i615+0]*reusedGeometriesDecodeMatrix[0]+reusedGeometriesDecodeMatrix[12];decompressedPositions[_i615+1]=geometryPositions[_i615+1]*reusedGeometriesDecodeMatrix[5]+reusedGeometriesDecodeMatrix[13];decompressedPositions[_i615+2]=geometryPositions[_i615+2]*reusedGeometriesDecodeMatrix[10]+reusedGeometriesDecodeMatrix[14];}geometryArrays.geometryPositions=null;geometryArraysCache[geometryId]=geometryArrays;}}}if(geometryArrays){if(geometryArrays.batchThisMesh){var _decompressedPositions=geometryArrays.decompressedPositions;var transformedAndRecompressedPositions=geometryArrays.transformedAndRecompressedPositions;for(var _i616=0,_len80=_decompressedPositions.length;_i616<_len80;_i616+=3){tempVec4a[0]=_decompressedPositions[_i616+0];tempVec4a[1]=_decompressedPositions[_i616+1];tempVec4a[2]=_decompressedPositions[_i616+2];tempVec4a[3]=1;math.transformVec4(meshMatrix,tempVec4a,tempVec4b);geometryCompressionUtils.compressPosition(tempVec4b,rtcAABB,tempVec4a);transformedAndRecompressedPositions[_i616+0]=tempVec4a[0];transformedAndRecompressedPositions[_i616+1]=tempVec4a[1];transformedAndRecompressedPositions[_i616+2]=tempVec4a[2];}sceneModel.createMesh(utils.apply(meshDefaults,{id:meshId,textureSetId:_textureSetId,origin:tileCenter,primitive:geometryArrays.primitiveName,positionsCompressed:transformedAndRecompressedPositions,normalsCompressed:geometryArrays.geometryNormals,uv:geometryArrays.geometryUVs,colorsCompressed:geometryArrays.geometryColors,indices:geometryArrays.geometryIndices,edgeIndices:spaceEdgeIndices(spaceEidsSet.has(xtcEntityId),geometryArrays.geometryEdgeIndices),positionsDecodeMatrix:tileDecodeMatrix,color:meshColor,metallic:meshMetallic,roughness:meshRoughness,opacity:meshOpacity}));meshIds.push(meshId);}else{if(!
|
|
29734
|
+
var meshMatrixIndex=eachMeshMatricesPortion[_meshIndex];var meshMatrix=matrices.slice(meshMatrixIndex,meshMatrixIndex+16);var geometryId=reuseGeometries?"".concat(modelPartId,"-geometry.").concat(_geometryIndex):"".concat(modelPartId,"-geometry.").concat(tileIndex,".").concat(_geometryIndex);// These IDs are local to the SceneModel
|
|
29735
|
+
var geometryArrays=geometryArraysCache[geometryId];if(!geometryArrays){geometryArrays={batchThisMesh:!options.reuseGeometries};var primitiveType=eachGeometryPrimitiveType[_geometryIndex];var geometryValid=false;switch(primitiveType){case 0:geometryArrays.primitiveName="solid";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryArrays.geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryArrays.geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 1:geometryArrays.primitiveName="surface";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryArrays.geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryArrays.geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 2:geometryArrays.primitiveName="points";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryColors=colors.subarray(eachGeometryColorsPortion[_geometryIndex],atLastGeometry?colors.length:eachGeometryColorsPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0;break;case 3:geometryArrays.primitiveName="lines";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;case 4:geometryArrays.primitiveName="lines";geometryArrays.geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryArrays.geometryIndices=lineStripToLines(geometryArrays.geometryPositions,indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]));geometryValid=geometryArrays.geometryPositions.length>0&&geometryArrays.geometryIndices.length>0;break;default:continue;}if(!geometryValid){geometryArrays=null;}if(geometryArrays){if(geometryArrays.geometryPositions.length>1000);if(geometryArrays.batchThisMesh){geometryArrays.decompressedPositions=new Float32Array(geometryArrays.geometryPositions.length);geometryArrays.transformedAndRecompressedPositions=new Uint16Array(geometryArrays.geometryPositions.length);var geometryPositions=geometryArrays.geometryPositions;var decompressedPositions=geometryArrays.decompressedPositions;for(var _i615=0,len=geometryPositions.length;_i615<len;_i615+=3){decompressedPositions[_i615+0]=geometryPositions[_i615+0]*reusedGeometriesDecodeMatrix[0]+reusedGeometriesDecodeMatrix[12];decompressedPositions[_i615+1]=geometryPositions[_i615+1]*reusedGeometriesDecodeMatrix[5]+reusedGeometriesDecodeMatrix[13];decompressedPositions[_i615+2]=geometryPositions[_i615+2]*reusedGeometriesDecodeMatrix[10]+reusedGeometriesDecodeMatrix[14];}geometryArrays.geometryPositions=null;geometryArraysCache[geometryId]=geometryArrays;}}}if(geometryArrays){if(geometryArrays.batchThisMesh){var _decompressedPositions=geometryArrays.decompressedPositions;var transformedAndRecompressedPositions=geometryArrays.transformedAndRecompressedPositions;for(var _i616=0,_len80=_decompressedPositions.length;_i616<_len80;_i616+=3){tempVec4a[0]=_decompressedPositions[_i616+0];tempVec4a[1]=_decompressedPositions[_i616+1];tempVec4a[2]=_decompressedPositions[_i616+2];tempVec4a[3]=1;math.transformVec4(meshMatrix,tempVec4a,tempVec4b);geometryCompressionUtils.compressPosition(tempVec4b,rtcAABB,tempVec4a);transformedAndRecompressedPositions[_i616+0]=tempVec4a[0];transformedAndRecompressedPositions[_i616+1]=tempVec4a[1];transformedAndRecompressedPositions[_i616+2]=tempVec4a[2];}sceneModel.createMesh(utils.apply(meshDefaults,{id:meshId,textureSetId:_textureSetId,origin:tileCenter,primitive:geometryArrays.primitiveName,positionsCompressed:transformedAndRecompressedPositions,normalsCompressed:geometryArrays.geometryNormals,uv:geometryArrays.geometryUVs,colorsCompressed:geometryArrays.geometryColors,indices:geometryArrays.geometryIndices,edgeIndices:spaceEdgeIndices(spaceEidsSet.has(xtcEntityId),geometryArrays.geometryEdgeIndices),positionsDecodeMatrix:tileDecodeMatrix,color:meshColor,metallic:meshMetallic,roughness:meshRoughness,opacity:meshOpacity}));meshIds.push(meshId);}else{if(!geometryCreated[geometryId]){sceneModel.createGeometry({id:geometryId,primitive:geometryArrays.primitiveName,positionsCompressed:geometryArrays.geometryPositions,normalsCompressed:geometryArrays.geometryNormals,uv:geometryArrays.geometryUVs,colorsCompressed:geometryArrays.geometryColors,indices:geometryArrays.geometryIndices,edgeIndices:spaceEdgeIndices(spaceEidsSet.has(xtcEntityId),geometryArrays.geometryEdgeIndices),positionsDecodeMatrix:reusedGeometriesDecodeMatrix});geometryCreated[geometryId]=true;}sceneModel.createMesh(utils.apply(meshDefaults,{id:meshId,geometryId:geometryId,textureSetId:_textureSetId,matrix:meshMatrix,color:meshColor,metallic:meshMetallic,roughness:meshRoughness,opacity:meshOpacity,origin:tileCenter}));meshIds.push(meshId);}}}else{// Do not reuse geometry
|
|
29635
29736
|
var _primitiveType=eachGeometryPrimitiveType[_geometryIndex];var primitiveName=void 0;var _geometryPositions=void 0;var geometryNormals=void 0;var geometryUVs=void 0;var geometryColors=void 0;var geometryIndices=void 0;var geometryEdgeIndices=void 0;var _geometryValid=false;switch(_primitiveType){case 0:primitiveName="solid";_geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);_geometryValid=_geometryPositions.length>0&&geometryIndices.length>0;break;case 1:primitiveName="surface";_geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryNormals=normals.subarray(eachGeometryNormalsPortion[_geometryIndex],atLastGeometry?normals.length:eachGeometryNormalsPortion[_geometryIndex+1]);geometryUVs=uvs.subarray(eachGeometryUVsPortion[_geometryIndex],atLastGeometry?uvs.length:eachGeometryUVsPortion[_geometryIndex+1]);geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);geometryEdgeIndices=edgeIndices.subarray(eachGeometryEdgeIndicesPortion[_geometryIndex],atLastGeometry?edgeIndices.length:eachGeometryEdgeIndicesPortion[_geometryIndex+1]);_geometryValid=_geometryPositions.length>0&&geometryIndices.length>0;break;case 2:primitiveName="points";_geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryColors=colors.subarray(eachGeometryColorsPortion[_geometryIndex],atLastGeometry?colors.length:eachGeometryColorsPortion[_geometryIndex+1]);_geometryValid=_geometryPositions.length>0;break;case 3:primitiveName="lines";_geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryIndices=indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]);_geometryValid=_geometryPositions.length>0&&geometryIndices.length>0;break;case 4:primitiveName="lines";_geometryPositions=positions.subarray(eachGeometryPositionsPortion[_geometryIndex],atLastGeometry?positions.length:eachGeometryPositionsPortion[_geometryIndex+1]);geometryIndices=lineStripToLines(_geometryPositions,indices.subarray(eachGeometryIndicesPortion[_geometryIndex],atLastGeometry?indices.length:eachGeometryIndicesPortion[_geometryIndex+1]));_geometryValid=_geometryPositions.length>0&&geometryIndices.length>0;break;default:continue;}if(_geometryValid){sceneModel.createMesh(utils.apply(meshDefaults,{id:meshId,textureSetId:_textureSetId,origin:tileCenter,primitive:primitiveName,positionsCompressed:_geometryPositions,normalsCompressed:geometryNormals,uv:geometryUVs&&geometryUVs.length>0?geometryUVs:null,colorsCompressed:geometryColors,indices:geometryIndices&&geometryIndices.length>0?geometryIndices:null,edgeIndices:spaceEdgeIndices(spaceEidsSet.has(xtcEntityId),geometryEdgeIndices),positionsDecodeMatrix:tileDecodeMatrix,color:meshColor,metallic:meshMetallic,roughness:meshRoughness,opacity:meshOpacity}));meshIds.push(meshId);}}}if(meshIds.length>0){var sceneModelEntity=sceneModel.createEntity(utils.apply(entityDefaults,{id:entityId,isObject:true,meshIds:meshIds}));// 房间体(spaceEids 命中):注册到 SceneModel,默认"仅轮廓"呈现(填充近不可见 + 边线),
|
|
29636
29737
|
// 下游可用 viewer.scene.spacesVisible = true 显示 50% 半透明填充。
|
|
29637
29738
|
if(sceneModelEntity&&spaceEidsSet.has(xtcEntityId)){sceneModel._registerSpaceEntity(sceneModelEntity);}}}}}/**
|