|
@@ -30,7 +30,20 @@ const maxTexVisi = 500
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+function getGpuMemoryUsage(win = window){//总的
|
|
|
+ let c = 0
|
|
|
+ viewer.objs.children.filter(e=>{
|
|
|
+ if(e.fileType == '3dTiles'){
|
|
|
+ let tileset3D = e.runtime.getTileset()
|
|
|
+ c += tileset3D.gpuMemoryUsageInBytes
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if(win.parent != win){//还有父级页面。 暂时只有子级需要考虑父级,假设父级在前台时子级已经销毁
|
|
|
+ c += getGpuMemoryUsage(win.parent)
|
|
|
+ }
|
|
|
+ return c
|
|
|
+}
|
|
|
|
|
|
|
|
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -7511,11 +7524,18 @@ class TilesetCache {
|
|
|
const sentinel = this._sentinel;
|
|
|
let node = list.head;
|
|
|
|
|
|
- while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) {
|
|
|
+ /* while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) {
|
|
|
+ const tile = node.item;
|
|
|
+ node = node.next;
|
|
|
+ this.unloadTile(tileset, tile, unloadCallback);
|
|
|
+ } */
|
|
|
+ //改
|
|
|
+ while (node !== sentinel && ( getGpuMemoryUsage() > maximumMemoryUsageInBytes || trimTiles)) {
|
|
|
const tile = node.item;
|
|
|
node = node.next;
|
|
|
this.unloadTile(tileset, tile, unloadCallback);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
trim() {
|
|
@@ -7779,7 +7799,7 @@ class OrientedBoundingBox {
|
|
|
return INTERSECTION.INSIDE;
|
|
|
}
|
|
|
|
|
|
- return INTERSECTION.INTERSECTING;
|
|
|
+ return INTERSECTION.INTERSECTING; //在相机frustum内
|
|
|
}
|
|
|
|
|
|
distanceTo(point) {
|
|
@@ -8277,11 +8297,15 @@ function update(frustum) {
|
|
|
|
|
|
if (frustum.fov !== frustum._fov || frustum.aspectRatio !== frustum._aspectRatio || frustum.near !== frustum._near || frustum.far !== frustum._far || frustum.xOffset !== frustum._xOffset || frustum.yOffset !== frustum._yOffset) {
|
|
|
assert$4(frustum.fov >= 0 && frustum.fov < Math.PI);
|
|
|
- assert$4(frustum.aspectRatio > 0);
|
|
|
+ //assert$4(frustum.aspectRatio > 0);
|
|
|
+ if(frustum.aspectRatio == 0){
|
|
|
+ console.log(1)
|
|
|
+ }
|
|
|
+
|
|
|
assert$4(frustum.near >= 0 && frustum.near < frustum.far);
|
|
|
- frustum._aspectRatio = frustum.aspectRatio;
|
|
|
+ frustum._aspectRatio = Math.max(0.001, frustum.aspectRatio);
|
|
|
frustum._fov = frustum.fov;
|
|
|
- frustum._fovy = frustum.aspectRatio <= 1 ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;
|
|
|
+ frustum._fovy = frustum._aspectRatio <= 1 ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum._aspectRatio) * 2.0;
|
|
|
frustum._near = frustum.near;
|
|
|
frustum._far = frustum.far;
|
|
|
frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);
|
|
@@ -8289,7 +8313,7 @@ function update(frustum) {
|
|
|
frustum._yOffset = frustum.yOffset;
|
|
|
f.top = frustum.near * Math.tan(0.5 * frustum._fovy);
|
|
|
f.bottom = -f.top;
|
|
|
- f.right = frustum.aspectRatio * f.top;
|
|
|
+ f.right = frustum._aspectRatio * f.top;
|
|
|
f.left = -f.right;
|
|
|
f.near = frustum.near;
|
|
|
f.far = frustum.far;
|
|
@@ -9159,6 +9183,11 @@ class TileHeader {
|
|
|
|
|
|
_defineProperty(this, "_initialTransform", void 0);
|
|
|
|
|
|
+ _defineProperty(this, "tilesetMatrix", void 0);//add
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
this.header = header;
|
|
|
this.tileset = tileset;
|
|
|
this.id = extendedId || header.id;
|
|
@@ -9233,7 +9262,9 @@ class TileHeader {
|
|
|
}
|
|
|
|
|
|
get isVisibleAndInRequestVolume() {
|
|
|
- return this._visible && this._inRequestVolume;
|
|
|
+ let v = /* this._visible && */this.tileset.visible && this._inRequestVolume; //用_updateBoundingVolume这个算的在相机靠近时不准确,容易缺块
|
|
|
+ if(window.tileVisi2)v = this._visible && v
|
|
|
+ return v
|
|
|
}
|
|
|
|
|
|
get hasRenderContent() {
|
|
@@ -9304,7 +9335,11 @@ class TileHeader {
|
|
|
const useParentScreenSpaceError = parent && (!maySkipTile || this._screenSpaceError === 0.0 || parent.hasTilesetContent);
|
|
|
const screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : this._screenSpaceError;
|
|
|
const rootScreenSpaceError = traverser.root ? traverser.root._screenSpaceError : 0.0;
|
|
|
- return Math.max(rootScreenSpaceError - screenSpaceError, 0);
|
|
|
+ let v = Math.max(rootScreenSpaceError - screenSpaceError, 0);
|
|
|
+ if(!this._visible){
|
|
|
+ v = THREE.Math.clamp(v * 0.1, -0.9, 100);//xzw add 因为this._visible我也令其显示所以这里降低这些的优先级
|
|
|
+ }
|
|
|
+ return v
|
|
|
}
|
|
|
|
|
|
async loadContent() {
|
|
@@ -9393,7 +9428,7 @@ class TileHeader {
|
|
|
const parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE;
|
|
|
|
|
|
if (this.tileset._traverser.options.updateTransforms) {
|
|
|
- const parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix;
|
|
|
+ const parentTransform = parent ? parent.computedTransform : new Matrix4().elements //this.tileset.modelMatrix; 改:去掉左乘modelMatrix
|
|
|
|
|
|
this._updateTransform(parentTransform);
|
|
|
}
|
|
@@ -9471,10 +9506,10 @@ class TileHeader {
|
|
|
}
|
|
|
|
|
|
_initializeTransforms(tileHeader) {
|
|
|
- this.transform = tileHeader.transform ? new Matrix4(tileHeader.transform) : new Matrix4();
|
|
|
+ this.transform = tileHeader.transform ? new Matrix4(tileHeader.transform) : new Matrix4();
|
|
|
const parent = this.parent;
|
|
|
const tileset = this.tileset;
|
|
|
- const parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : tileset.modelMatrix.clone();
|
|
|
+ const parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : new Matrix4().elements // tileset.modelMatrix.clone(); 改:去掉左乘modelMatrix
|
|
|
this.computedTransform = new Matrix4(parentTransform).multiplyRight(this.transform);
|
|
|
const parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new Matrix4();
|
|
|
this._initialTransform = new Matrix4(parentInitialTransform).multiplyRight(this.transform);
|
|
@@ -9543,32 +9578,38 @@ class TileHeader {
|
|
|
}
|
|
|
|
|
|
_updateBoundingVolume(header) {
|
|
|
- this.boundingVolume = createBoundingVolume(header.boundingVolume, this.computedTransform, this.boundingVolume);
|
|
|
+
|
|
|
+ let computedTransform = new Matrix4(this.tileset.modelMatrix).multiplyRight(this.computedTransform); //add
|
|
|
+ //console.log('_updateBoundingVolume computedTransform', this.tileset.modelMatrix, computedTransform)
|
|
|
+
|
|
|
+ this.boundingVolume = createBoundingVolume(header.boundingVolume, computedTransform/* this.computedTransform */, this.boundingVolume);
|
|
|
const content = header.content;
|
|
|
|
|
|
if (!content) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (content.boundingVolume) {
|
|
|
- this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, this.computedTransform, this._contentBoundingVolume);
|
|
|
+ this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume);
|
|
|
}
|
|
|
|
|
|
if (header.viewerRequestVolume) {
|
|
|
- this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume);
|
|
|
+ this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_updateTransform(parentTransform = new Matrix4()) {
|
|
|
const computedTransform = parentTransform.clone().multiplyRight(this.transform);
|
|
|
- const didTransformChange = !computedTransform.equals(this.computedTransform);
|
|
|
+ const didTransformChange = !computedTransform.equals(this.computedTransform) || !this.tilesetMatrix || !this.tilesetMatrix.equals(this.tileset.modelMatrix) //改 后面加了两个判断,为了在模型移动后更新_updateBoundingVolume
|
|
|
|
|
|
if (!didTransformChange) {
|
|
|
return;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ this.tileset.modelMatrix
|
|
|
this.computedTransform = computedTransform;
|
|
|
-
|
|
|
+
|
|
|
+ this.tilesetMatrix = this.tileset.modelMatrix; //add 标记
|
|
|
+
|
|
|
this._updateBoundingVolume(this.header);
|
|
|
}
|
|
|
|
|
@@ -9887,6 +9928,10 @@ class Tileset3D extends EventDispatcher{//xzw add EventDispatcher
|
|
|
_defineProperty(this, "frameStateData", void 0);
|
|
|
|
|
|
_defineProperty(this, "maximumMemoryUsage", void 0);
|
|
|
+
|
|
|
+
|
|
|
+ _defineProperty(this, "visible", true);//add
|
|
|
+
|
|
|
|
|
|
assert$7(json);
|
|
|
this.options = { ...DEFAULT_PROPS,
|
|
@@ -17499,6 +17544,7 @@ class Loader3DTiles {
|
|
|
threeMat.premultiply(lastRootTransform);
|
|
|
threeMat.copy(lastRootTransform).multiply(new Matrix4$1().copy(tileTrasnform).invert());
|
|
|
tileset.modelMatrix = new Matrix4(threeMat.toArray());
|
|
|
+ //console.log('update tileset ModelMatrix', tileset.modelMatrix.elements)
|
|
|
}
|
|
|
}
|
|
|
// 更新瓦片显隐和瓦片迭代更新
|
|
@@ -17516,6 +17562,7 @@ class Loader3DTiles {
|
|
|
});
|
|
|
sseDenominator = loadersFrustum.sseDenominator;
|
|
|
lastCameraAspect = camera.aspect;
|
|
|
+ if(camera.aspect == 0)return//add
|
|
|
if (options.debug) {
|
|
|
console.log('Updated sse denonimator:', sseDenominator);
|
|
|
}
|
|
@@ -17557,7 +17604,7 @@ class Loader3DTiles {
|
|
|
visiVertexCount += renderMap[tile.id].vertexCount //xzw add
|
|
|
options.debug && (boxMap[tile.id].material.opacity = 1)
|
|
|
}else{
|
|
|
- console.log('超出', visiVertexCount)
|
|
|
+ //console.log('超出', visiVertexCount)
|
|
|
}
|
|
|
}
|
|
|
/* if(!renderMap[tile.id].realVisible()){
|
|
@@ -17682,11 +17729,11 @@ class Loader3DTiles {
|
|
|
model.add(mesh);
|
|
|
return model;
|
|
|
},
|
|
|
- update: function (dt, renderer, camera) {
|
|
|
+ update: function (dt, renderer, camera, ifForce) {
|
|
|
cameraReference = camera;
|
|
|
- rendererReference = renderer;
|
|
|
+ rendererReference = renderer;
|
|
|
timer += dt;
|
|
|
- if (tileset && timer >= UPDATE_INTERVAL) {
|
|
|
+ if (tileset && (timer >= UPDATE_INTERVAL || ifForce)) {
|
|
|
if (!lastRootTransform.equals(root.matrixWorld)) {
|
|
|
timer = 0;
|
|
|
lastRootTransform.copy(root.matrixWorld);
|
|
@@ -17715,7 +17762,7 @@ class Loader3DTiles {
|
|
|
else {
|
|
|
const cameraChanged = !camera.matrixWorld.equals(this.lastCameraTransform) ||
|
|
|
!(camera.aspect == lastCameraAspect);
|
|
|
- if (cameraChanged) {
|
|
|
+ if (cameraChanged || ifForce) {
|
|
|
timer = 0;
|
|
|
tileset._frameNumber++;
|
|
|
camera.getWorldPosition(lastCameraPosition);
|
|
@@ -17762,9 +17809,13 @@ function createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTransform
|
|
|
const rotateX = new Matrix4$1().makeRotationAxis(new Vector3$1(1, 0, 0), Math.PI / 2);
|
|
|
const shouldRotate = ((_a = tile.tileset.asset) === null || _a === void 0 ? void 0 : _a.gltfUpAxis) !== "Z";
|
|
|
// The computed trasnform already contains the root's transform, so we have to invert it
|
|
|
- const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(rootTransformInverse); //xzw 删。原先的会造成移动后tiles错乱
|
|
|
+ //const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tileMatrix)//.premultiply(rootTransformInverse); //xzw 删。原先的会造成移动后tiles错乱
|
|
|
+ const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tile.tileset.modelMatrix).premultiply(rootTransformInverse)
|
|
|
+ // 这句同tile.computedTransform左乘tileTrasnform。 因为tileTrasnform拿不到所以使用modelMatrix。modelMatrix为tileTrasnform左乘rootTransform, 所以再左乘rootTransformInverse
|
|
|
|
|
|
- //不知为何在刚开始加载时迅速移动模型,tiles位置会参差不齐。应该和contentTransform有关,也就是tile.computedTransform 和rootTransformInverse的问题。但即使每次_updateTransform后重新计算也不对
|
|
|
+
|
|
|
+ //改动:contentTransform中的computedTransform 去掉左乘 root.modelMatrixWorld , 因为移动过后这个computedTransform没更新
|
|
|
+
|
|
|
|
|
|
|
|
|
if (shouldRotate) {
|
|
@@ -17929,11 +17980,48 @@ export { GeoTransform, Loader3DTiles, PointCloudColoring, Shading };
|
|
|
Loader3DTiles : const tileset = new Tileset3D
|
|
|
tileset.dispatchEvent({type:'tileLoaded',tileContent})
|
|
|
|
|
|
-createGLTFNodes : gltfLoader.parse
|
|
|
+createGLTFNodes(gltfLoader 创建tile
|
|
|
+executeTraversal(root, frameState) 遍历root
|
|
|
+
|
|
|
+
|
|
|
+lastRootTransform rootTransformInverse
|
|
|
+
|
|
|
+tileset._loadTiles 依次加载tiles
|
|
|
+_getPriority 加载优先级 加了一句
|
|
|
+
|
|
|
+
|
|
|
+笔记:
|
|
|
+
|
|
|
+
|
|
|
+主要类:
|
|
|
+class tileset3D 最外层整体。 获取方法: viewer.objs.children[index].runtime.getTileset()。 .tiles包含所有tiles
|
|
|
+class tileHeader 也就是tileset里面的一个个tile 。 其上有.tileset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+tileset里算的tileTrasnform之后是不会改变的, tile.transform也是,是json里的。
|
|
|
+
|
|
|
+tileset.modelMatrix (通常这个值很大) 会随着位移改变
|
|
|
+tile.computedTransform 被我修改了,之前左乘了tileset.modelMatrix,现只包含了transform信息 _updateTransform(parentTransfor 其中有_updateBoundingVolume,这个影响可见性, 在computeVisibilityWithPlaneMask中计算
|
|
|
+
|
|
|
+
|
|
|
+tileset._cache.trim(), 然后再update //可以将所有不可见的tiles dispose
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+相机靠近容易缺块的bug暂时修改如下: _visible是由computeVisibilityWithPlaneMask计算得
|
|
|
+get isVisibleAndInRequestVolume() {
|
|
|
+ return this._inRequestVolume; //去掉了_visible ||
|
|
|
+}
|
|
|
+
|
|
|
+显示所有tile似乎也不会卡顿. 但好像影响了加载顺序从而变慢了。visiVertexCount过量。 怀疑应该还是文件的bound有问题。
|
|
|
+原本会消失的地方虽然不会消失了但一直是模糊的
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|