|
@@ -3,8 +3,8 @@
|
|
|
// }
|
|
|
import * as THREE from "../../libs/three.js/build/three.module.js";
|
|
|
import math from "./utils/math.js";
|
|
|
-import browser from "./utils/browser.js";
|
|
|
-
|
|
|
+import browser from "./utils/browser.js";
|
|
|
+import cameraLight from "./utils/cameraLight.js";
|
|
|
import {Utils} from "../utils.js";
|
|
|
import {BinaryLoader} from "../loader/BinaryLoader.js";
|
|
|
import {Features} from "../Features.js";
|
|
@@ -28,6 +28,11 @@ import {LineSegmentsGeometry} from '../../libs/three.js/lines/LineSegmentsGeomet
|
|
|
import {LineGeometry} from '../../libs/three.js/lines/LineGeometry.js'
|
|
|
KeyCodes.BACKSPACE = 8
|
|
|
|
|
|
+
|
|
|
+//注意,这时候Potree.js中export的内容还不在Potree变量中
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
{//defines:
|
|
|
Potree.defines = {}
|
|
|
Potree.defines.Buttons = {// MouseEvent.buttons
|
|
@@ -210,7 +215,7 @@ Utils.loadSkybox = function(path) {
|
|
|
|
|
|
Utils.getMousePointCloudIntersection = function(viewport, mouse, pointer, camera, viewer, pointclouds, pickParams = {} ) {
|
|
|
if(!pointclouds || pointclouds.length == 0)return
|
|
|
-
|
|
|
+ //console.log('getMousePointCloudIntersection')
|
|
|
let renderer = viewer.renderer;
|
|
|
|
|
|
|
|
@@ -253,6 +258,7 @@ Utils.getMousePointCloudIntersection = function(viewport, mouse, pointer, camera
|
|
|
let density
|
|
|
let sizeType
|
|
|
let size = new Map()
|
|
|
+ let visiMap = new Map()
|
|
|
let needsUpdate = false;
|
|
|
|
|
|
if(pickParams.isMeasuring || Potree.settings.displayMode == 'showPanos'){ //测量或全景模式提高精准度
|
|
@@ -260,6 +266,9 @@ Utils.getMousePointCloudIntersection = function(viewport, mouse, pointer, camera
|
|
|
Potree.settings.pointDensity = 'magnifier'
|
|
|
|
|
|
pointclouds.forEach(e=>{//因为全景模式的pointSizeType是fixed所以要还原下
|
|
|
+ visiMap.set(e,e.visible)
|
|
|
+ e.visible = viewer.getObjVisiByReason(e, 'datasetSelection'); //先将隐藏的点云显示
|
|
|
+ if(!e.visible)return
|
|
|
size.set(e, e.temp.pointSize)
|
|
|
sizeType = e.material.pointSizeType
|
|
|
e.material.pointSizeType = Potree.config.material.pointSizeType
|
|
@@ -314,14 +323,16 @@ Utils.getMousePointCloudIntersection = function(viewport, mouse, pointer, camera
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //恢复
|
|
|
if(pickParams.isMeasuring || Potree.settings.displayMode == 'showPanos'){
|
|
|
Potree.settings.pointDensity = density
|
|
|
|
|
|
pointclouds.forEach(e=>{
|
|
|
- e.material.pointSizeType = sizeType
|
|
|
- e.changePointSize(size.get(e))
|
|
|
-
|
|
|
+ if(e.visible){
|
|
|
+ e.material.pointSizeType = sizeType
|
|
|
+ e.changePointSize(size.get(e))
|
|
|
+ }
|
|
|
+ e.visible = visiMap.get(e)
|
|
|
})
|
|
|
}else{
|
|
|
/* if(viewer.viewports.filter(e=>!e.noPointcloud).length>1){
|
|
@@ -794,7 +805,7 @@ Potree.updatePointClouds = function(pointclouds,camera, areaSize ){
|
|
|
Potree.updateVisibilityStructures = function(pointclouds, camera, areaSize) {
|
|
|
let frustums = [];
|
|
|
let camObjPositions = [];
|
|
|
- let priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });
|
|
|
+ let priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });//二叉堆。
|
|
|
|
|
|
for (let i = 0; i < pointclouds.length; i++) {
|
|
|
let pointcloud = pointclouds[i];
|
|
@@ -833,11 +844,12 @@ Potree.updateVisibilityStructures = function(pointclouds, camera, areaSize) {
|
|
|
camObjPositions.push(camObjPos);
|
|
|
|
|
|
// 因漫游模式而隐藏的话 依旧需要加入visibleNodes,因为pick需要
|
|
|
-
|
|
|
- /* viewer.getObjVisiByReason(pointcloud, 'datasetSelection') */
|
|
|
- if (pointcloud.visible || pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode' && pointcloud.root !== null) {//改 visible ->
|
|
|
+ /* if (pointcloud.visible && pointcloud.root !== null) {
|
|
|
priorityQueue.push({pointcloud: i, node: pointcloud.root, weight: Number.MAX_VALUE});
|
|
|
- }
|
|
|
+ } */
|
|
|
+ if (pointcloud.visible || !pointcloud.hasDepthTex && pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode' && pointcloud.root !== null) {//改 visible ->
|
|
|
+ priorityQueue.push({pointcloud: i, node: pointcloud.root, weight: Number.MAX_VALUE});
|
|
|
+ }
|
|
|
|
|
|
// hide all previously visible nodes
|
|
|
// if(pointcloud.root instanceof PointCloudOctreeNode){
|
|
@@ -857,7 +869,7 @@ Potree.updateVisibilityStructures = function(pointclouds, camera, areaSize) {
|
|
|
'camObjPositions': camObjPositions,
|
|
|
'priorityQueue': priorityQueue
|
|
|
};
|
|
|
-};
|
|
|
+};
|
|
|
|
|
|
|
|
|
Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
@@ -892,9 +904,11 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
let pointcloudTransformVersion = Potree._pointcloudTransformVersion;
|
|
|
for(let pointcloud of pointclouds){
|
|
|
|
|
|
- if(!viewer.getObjVisiByReason(pointcloud, 'datasetSelection')){//改 visible ->
|
|
|
+ if(pointcloud.hasDepthTex ? !pointcloud.visible : !viewer.getObjVisiByReason(pointcloud, 'datasetSelection')){//改 visible ->
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ //if(!pointcloud.visible) continue
|
|
|
|
|
|
pointcloud.updateMatrixWorld();
|
|
|
|
|
@@ -916,7 +930,7 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
}
|
|
|
|
|
|
while (priorityQueue.size() > 0) {
|
|
|
- let element = priorityQueue.pop();//其实是拿第一个, 再把最后一个放到前面
|
|
|
+ let element = priorityQueue.pop(); //取出权重最大的一个
|
|
|
|
|
|
let node = element.node;
|
|
|
let parent = element.parent;
|
|
@@ -938,7 +952,7 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
let level = node.getLevel();
|
|
|
let visible = insideFrustum;
|
|
|
visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget);
|
|
|
- visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget);
|
|
|
+ visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget); // pointcloud.pointBudget一直是Infinity
|
|
|
visible = visible && level <= maxLevel; //< 改为 <=
|
|
|
//visible = visible || node.getLevel() <= 2;
|
|
|
|
|
@@ -986,13 +1000,9 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
//}
|
|
|
|
|
|
let frustum = new THREE.Frustum(pxPlane, nxPlane, pyPlane, nyPlane, pzPlane, nzPlane);
|
|
|
- let intersects = frustum.intersectsBox(box);
|
|
|
+ let intersects = frustum.intersectsBox(box); //node的bounding
|
|
|
|
|
|
- /* if(intersects){
|
|
|
- numIntersecting++;
|
|
|
- }
|
|
|
- numIntersectionVolumes++;
|
|
|
- */
|
|
|
+
|
|
|
return !!intersects
|
|
|
}
|
|
|
|
|
@@ -1038,52 +1048,7 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
visible = false
|
|
|
}
|
|
|
}
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /*let clipBoxes = pointcloud.material.clipBoxes;
|
|
|
- if(true && clipBoxes.length > 0){
|
|
|
-
|
|
|
- //node.debug = false;
|
|
|
-
|
|
|
- let numIntersecting = 0;
|
|
|
- let numIntersectionVolumes = 0;
|
|
|
-
|
|
|
- //if(node.name === "r60"){
|
|
|
- // var a = 10;
|
|
|
- //}
|
|
|
-
|
|
|
- for(let clipBox of clipBoxes){
|
|
|
- }
|
|
|
-
|
|
|
- let insideAny = numIntersecting > 0;
|
|
|
- let insideAll = numIntersecting === numIntersectionVolumes;
|
|
|
-
|
|
|
- if(pointcloud.material.clipTask === ClipTask.SHOW_INSIDE){
|
|
|
- if(pointcloud.material.clipMethod === ClipMethod.INSIDE_ANY && insideAny){
|
|
|
- //node.debug = true
|
|
|
- }else if(pointcloud.material.clipMethod === ClipMethod.INSIDE_ALL && insideAll){
|
|
|
- //node.debug = true;
|
|
|
- }else{
|
|
|
- visible = false;
|
|
|
- }
|
|
|
- } else if(pointcloud.material.clipTask === ClipTask.SHOW_OUTSIDE){
|
|
|
- //if(pointcloud.material.clipMethod === ClipMethod.INSIDE_ANY && !insideAny){
|
|
|
- // //visible = true;
|
|
|
- // let a = 10;
|
|
|
- //}else if(pointcloud.material.clipMethod === ClipMethod.INSIDE_ALL && !insideAll){
|
|
|
- // //visible = true;
|
|
|
- // let a = 20;
|
|
|
- //}else{
|
|
|
- // visible = false;
|
|
|
- //}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }*/
|
|
|
+ */
|
|
|
|
|
|
// visible = ["r", "r0", "r06", "r060"].includes(node.name);
|
|
|
// visible = ["r"].includes(node.name);
|
|
@@ -1116,13 +1081,13 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
node = pointcloud.toTreeNode(node, parent);
|
|
|
loadedToGPUThisFrame++;
|
|
|
} else {
|
|
|
- unloadedGeometry.push({pointcloud,node});
|
|
|
+ unloadedGeometry.push({pointcloud,node}); //加载点云
|
|
|
visibleGeometry.push(node);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (node.isTreeNode()) {
|
|
|
- Potree.lru.touch(node.geometryNode);
|
|
|
+ Potree.lru.touch(node.geometryNode);//在缓存中计入点云
|
|
|
node.sceneNode.visible = true;
|
|
|
node.sceneNode.material = pointcloud.material;
|
|
|
|
|
@@ -1182,13 +1147,14 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
|
|
|
|
|
|
let radius = sphere.radius;
|
|
|
-
|
|
|
+
|
|
|
let fov = (camera.fov * Math.PI) / 180;
|
|
|
let slope = Math.tan(fov / 2);
|
|
|
let projFactor = (0.5 * domHeight) / (slope * distance);
|
|
|
let screenPixelRadius = radius * projFactor;
|
|
|
-
|
|
|
- if(screenPixelRadius < pointcloud.minimumNodePixelSize){
|
|
|
+ //screenPixelRadius 和 domHeight 成正比,所以手机横屏后screenPixelRadius会变小。这是正常的,因为vhov不变,相同物体高度在横屏后高度变小,所需要的密度不需要那么高了。但hfov横屏后扩大,所以可见的node范围变大,又增加了一些可见node;只是总体的可见node还是减少了。
|
|
|
+ //使用hfov和domWidth计算结果相同。
|
|
|
+ if(screenPixelRadius < pointcloud.minimumNodePixelSize){
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -1200,14 +1166,14 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
} else {
|
|
|
// TODO ortho visibility
|
|
|
let bb = child.getBoundingBox();
|
|
|
- let distance = child.getBoundingSphere().center.distanceTo(camObjPos);
|
|
|
+ let distance = child.getBoundingSphere().center.distanceTo(camObjPos); //先加载中间然后四周
|
|
|
let diagonal = bb.max.clone().sub(bb.min).length();
|
|
|
//weight = diagonal / distance;
|
|
|
-
|
|
|
+
|
|
|
weight = diagonal;
|
|
|
}
|
|
|
|
|
|
- priorityQueue.push({pointcloud: element.pointcloud, node: child, parent: node, weight: weight});
|
|
|
+ priorityQueue.push({pointcloud: element.pointcloud, node: child, parent: node, weight: weight}); //貌似好像二叉堆中子节点和父节点没什么关系,就只是为了方便排序层层遍历
|
|
|
}
|
|
|
}// end priority queue loop
|
|
|
|
|
@@ -1230,9 +1196,12 @@ Potree.updateVisibility = function(pointclouds, camera, areaSize){
|
|
|
lowestSpacing: lowestSpacing
|
|
|
};
|
|
|
};
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+/*
|
|
|
+ note:
|
|
|
+ 缓存中的点数 Potree.lru.numPoints 会 大于 每个点云显示的numVisiblePoints之和。
|
|
|
+ 当超出缓冲区最大点云数时,加载的点云节点会被dispose彻底消除;否则,隐藏的节点就会等待再次被使用显示
|
|
|
+ 要降低卡顿,就只需要降低Potree.pointBudget即可。为了level显示均匀,还能另外设置整体maxLevel
|
|
|
+ */
|
|
|
{//HQSplatRenderer
|
|
|
let oldInit = HQSplatRenderer.prototype.init;
|
|
|
HQSplatRenderer.prototype.init = function(){
|
|
@@ -1632,28 +1601,22 @@ PointCloudOctreeGeometryNode.prototype.traverse = function(t, e){//add from navv
|
|
|
Object.assign( PointCloudOctreeGeometry.prototype, THREE.EventDispatcher.prototype );
|
|
|
|
|
|
LRU.prototype.freeMemory = function(){
|
|
|
+
|
|
|
if (this.elements <= 1) {
|
|
|
return;
|
|
|
- }
|
|
|
-
|
|
|
- /* while (this.numPoints > Potree.pointLoadLimit) {
|
|
|
- let element = this.first;
|
|
|
- let node = element.node;
|
|
|
- this.disposeDescendants(node);
|
|
|
- } */
|
|
|
+ }
|
|
|
|
|
|
- //改成navvis的,使用pointBudget,否则四屏点云闪烁。
|
|
|
- let max = /* this.pageVisible ? */viewer.viewports.length * 2 * Potree.pointBudget// : 1000
|
|
|
+ //改成navvis的,使用pointBudget,否则四屏点云闪烁。 (似乎要比updateVisiblede的node时限制要宽些,作为缓存继续存着。否则会闪烁)
|
|
|
+ let max = viewer.viewports.length * 2 * Potree.pointBudget// : 1000 // this.pageVisible ?
|
|
|
|
|
|
- for (; this.numPoints > max; ) {//要根据屏幕数量来增加pointBudget
|
|
|
+ for (; this.numPoints > max; ) {//应该是从子node删除
|
|
|
var node = this.getLRUItem();
|
|
|
- node && this.disposeSubtree(node)
|
|
|
+ node && this.disposeDescendants(node); //this.disposeSubtree(node)
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-LRU.prototype.disposeSubtree = function(t) {//add from navvis 25.js
|
|
|
+}
|
|
|
+/*
|
|
|
+LRU.prototype.disposeSubtree = function(t) {//add from navvis 25.js 和原来的disposeDescendants功能一样
|
|
|
var e = [t];
|
|
|
t.traverse((function(t) {
|
|
|
t.loaded && e.push(t)
|
|
@@ -1663,7 +1626,7 @@ LRU.prototype.disposeSubtree = function(t) {//add from navvis 25.js
|
|
|
o.dispose(),
|
|
|
this.remove(o)
|
|
|
}
|
|
|
-}
|
|
|
+}*/
|
|
|
|
|
|
VolumeTool.prototype.update = function(){}
|
|
|
|