| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
-
- import {Images360} from '../Images360.js'
- import TileUtils from './TileUtils.js'
- import cameraLight from '../../../utils/cameraLight.js'
- import math from '../../../utils/math.js'
- import Common from '../../../utils/Common.js'
- import * as THREE from "../../../../../libs/three.js/build/three.module.js";
- import browser from '../../../utils/browser.js'
- let {DownloadStatus} = Potree.defines
- var h = Object.freeze({
- None: 0,
- DirectionalFOV: 1
- });
- var u = function () {
- var e = function e(t, i) {
- var n = e._panoSpaceDir,
- r = e._fovThreshold,
- o = e._fovThresholdNarrow,
- a = Math.max(Math.min(n.dot(t.direction), 1), -1),
- s = Math.max(Math.min(n.dot(i.direction), 1), -1);
- return t._dot = a,
- i._dot = s,
- a >= r && s < r ? -1 : a < r && s >= r ? 1 : a >= o && s < o ? -1 : a < o && s >= o ? 1 : t.panoSize > i.panoSize ? 1 : i.panoSize > t.panoSize ? -1 : -(a - s)
- };
- return e._panoSpaceDir = new THREE.Vector3,
- e._fovThreshold = -1,
- e._fovThresholdNarrow = -1,
- e
- }();
- export default class TilePrioritizer {//优先级处理序列
- constructor(e,t, i, o, a) {
- this.qualityManager = e;
- this.maxNavQuality = this.qualityManager.getMaxNavPanoSize();
- this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize();
- this.baseSize = t;
- this.standardSize = i;
- this.highSize = o;
- this.ultraHighSize = a;
- this.priorityCriteria = new TilePrioritizer.PriorityCriteria(null, new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, -1), new THREE.Vector3(0, 0, -1));
-
-
-
-
- }
- updateCriteria(e, t, i, n) {//由player更新
- this.priorityCriteria.pano = e,
- this.priorityCriteria.cameraPosition.copy(t),
- //this.priorityCriteria.cameraDir.copy(i),
- this.priorityCriteria.cameraDirs = i
-
- this.priorityCriteria.upcomingPanos = n,
- this.maxNavQuality = this.qualityManager.getMaxNavPanoSize(),
- this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize()
-
-
- }
-
-
-
- canDownloadSize(e) {
- return this.maxNavQuality >= e || this.maxZoomQuality >= e && this.zoomingActive
- }
-
- /* populateNeighborPanos(e, t, i) {
- i = i || [],
- i.length = 0;
- var n = t.getNeighbours(e);
- for (var r in n)
- if (n.hasOwnProperty(r)) {
- var o = t.get(r);
- if(!o){
- console.log(1)
- }
- i.push(o)
- }
- return i
- } */
-
- getNearPanos(panos){
- if(!this.priorityCriteria.pano || viewer.mainViewport.view.isFlying())return
- let cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward
-
- this.populateScoredPanos(panos, [], cameraDirLocals , Infinity, true);
-
- }
- filterDepthTex(panos) {// 下载depthTex
- if(!Potree.settings.useDepthTex )return
- viewer.addTimeMark('filterDepthTex','start')
-
- let dlCount = 1 //window.slowDown ? 0 : (browser.isMobile() ? 1 : Common.getBestCountFPS('loadDepTexCount', false, 1, 2, 57, 62 ) )
-
- let loadingCount = panos.filter(p=>p.depthTexLoading).length
- if(viewer.mapViewer){
- let mapLayer = viewer.mapViewer.mapLayer
- loadingCount += mapLayer.loadingInProgress * 1.5 + mapLayer.waitQueue.length
- }
-
- if(loadingCount<dlCount){
- //console.log('dlCount-loadingCount', dlCount-loadingCount)
- (this.nearPanos || panos).filter(p=>!p.depthTex).slice(0, dlCount-loadingCount).forEach(p=>p.loadDepthImg())
- }
-
- viewer.addTimeMark('filterDepthTex','end')
- }
-
- populateScoredPanos(/* e, */ t, i, dirs, count, dontFilterDir) {
- i = i || [],
- i.length = 0;
- viewer.addTimeMark('populateScoredPanos','start')
-
- var s = [Images360.filters.not(this.priorityCriteria.pano)],
- l = [Images360.scoreFunctions.distanceSquaredNew(this.priorityCriteria.pano), Images360.scoreFunctions.direction(this.priorityCriteria.pano.position, dirs)]
-
- /* if(!dontFilterDir){//太耗时了,尤其是点多时,直接去掉,反正有count限制。如果必须的话,使用direction中得到的值
- s.push(Images360.filters.inPanoDirection(this.priorityCriteria.pano.position, dirs, TilePrioritizer.DIRECTION_SCORE_STRICTNESS) )
- } */
- let c = Common.sortByScore(t, s, l);
- //900个点的时候populateScoredPanos已经耗时1.8
-
-
- viewer.addTimeMark('populateScoredPanos','end')
-
- this.nearPanos = c.map(e=>e.item); //xzw add 用于获得邻近点位序列
-
- if (c)
- for (var h = 0; h < c.length && h < count; h++) {
- var u = c[h].item;
- i.push(u)
- }
-
-
- return i
- }
-
- queueTilesForPanos(e, t, i, n, r) {
- for (var o = 0, a = 0; a < t.length; a++) {
- var s = t[a],
- l = this.queueTilesForPano(e, i, s, n);
- if (o += l > 0 ? 1 : 0,
- r && o >= r)
- break
- }
- return o
- }
- /* queueTilesInDirectionForPanos(e, t, i, n, r, o, a, s) {//没用到
- for (var l = 0, c = 0; c < i.length; c++) {
- var h = i[c],
- u = this.queueTilesInDirectionForPano(e, t, h, n, o, a);
- if (l += u > 0 ? 1 : 0,
- s && l >= s)
- break
- }
- return l
- }
- */
- canIncludeDescriptor(e) {
- return e.status !== DownloadStatus.Downloading && e.status !== DownloadStatus.Downloaded
- }
- canIncludePano(e, t) {
- return !e.isLoaded(t)
- }
- getFOVDotThreshold(e) {
- return Math.cos(THREE.Math.degToRad(e / 2))
- }
- setZoomingActive(e) {
- e !== this.zoomingActive && (this.zoomingActive = e)
- }
- }
- TilePrioritizer.PriorityCriteria = function (e, t, i, n, o) {
- this.pano = e,
- this.cameraPosition = (new THREE.Vector3).copy(t),
-
- //this.cameraDir = (new THREE.Vector3).copy(i),
- this.cameraDirs = [], //
-
- this.panoSpaceDir = (new THREE.Vector3).copy(n),
- this.upcomingPanos = o,
- this.copy = function (e) {
- this.pano = e.pano,
- this.cameraPosition.copy(e.cameraPosition),
- //this.cameraDir.copy(e.cameraDir),
- this.cameraDirs = e.cameraDirs
-
- this.panoSpaceDir.copy(e.panoSpaceDir),
- this.upcomingPanos = o
- },
- this.zoomingActive = !1
- }
- TilePrioritizer.DIRECTIONAL_FOV = 180;
- TilePrioritizer.DIRECTIONAL_FOV_NARROW = 120;
- TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER = 6;
- TilePrioritizer.MAX_SCORED_PANOS_TOADD = 2;
- TilePrioritizer.MAX_UPCOMING_PANOS_TOADD = 3;
- TilePrioritizer.DIRECTION_SCORE_STRICTNESS = .75;
- TilePrioritizer.appendQueue = function (e, t) {
- if (e && t)
- for (var i = 0; i < t.length; i++){
- e.push(t[i])
- //console.log(t[i])
- }
- };
- TilePrioritizer.sortPanoTiles = function (descriptors, pano, dir) {
- if(dir.datasetsLocal) dir = dir.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
- u._panoSpaceDir.copy(dir)
- TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir) //应该是将dir根据quaternion转化下
- u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW)
- u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV)
- descriptors.sort(u)
- };
- TilePrioritizer.insertSortedPanoTile = function (e, t, pano, dir) {
- if(dir.datasetsLocal) dir = dir.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
- u._panoSpaceDir.copy(dir),
- TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir),
- u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW),
- u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV);
- for (var o = -1, a = 0; a < e.length; a++) {
- var s = u(t, e[a]);
- if (s <= 0) {
- o = a;
- break
- }
- }
- if (o === -1)
- e[e.length] = t;
- else {
- for (var h = e.length; h > o; h--)
- e[h] = e[h - 1];
- e[o] = t
- }
- };
- TilePrioritizer.prototype.filterAndPrioritize = function () {//挑选出优先加载的 pano和tile (有点复杂,没看很懂)
- var e = [],
- t = [],
- i = [];
- return function (queue, panos, tileDownloader) {
- //this.populateNeighborPanos(this.priorityCriteria.pano, panos, e);
-
- /* let cameraDirLocals = this.priorityCriteria.cameraDirs.map(e=>{ //add
- var dataset = viewer.scene.pointclouds.find(u=>u.dataset_id == e.datasetId)
- var matrix = new THREE.Matrix4().copy(dataset.rotateMatrix)
- var direction = math.convertVector.YupToZup(e.direction)
-
-
- return {
- datasetId:e.datasetId,
- direction: direction.clone().applyMatrix4(matrix)
- }
- }) */
- let cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward
-
- //获得视野范围内的邻近点位序列t
- this.populateScoredPanos(/* this.priorityCriteria.pano, */panos, t, cameraDirLocals , TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER);
-
-
- //t.filter(p=>!p.depthTex).slice(0, Potree.config.depTexDlCount).forEach(p=>p.loadDepthImg()) //add
-
- var s = this.baseSize //512
- ,
- l = this.standardSize //1024
- ,
- c = this.highSize //2048
- ,
- h = this.priorityCriteria.pano.pointcloud.tileClass //xzw //this.ultraHighSize; //4096
-
-
- this.queueTilesForPano(queue, tileDownloader, this.priorityCriteria.pano, s); //把当前pano的512下载了
-
-
- if (this.priorityCriteria.upcomingPanos) {// 添加即将走到的点(之前用于导览路线)512 tiles
- this.queueTilesForPanos(queue, this.priorityCriteria.upcomingPanos, tileDownloader, s, TilePrioritizer.MAX_UPCOMING_PANOS_TOADD);
- }
- i.length = 0;
-
- //把当前pano角度范围内的tile按照分辨率从低到高加入队列
-
- if (this.canDownloadSize(l)) {//1024如果在限制范围内的话
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
- }
- TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs); //排序
- TilePrioritizer.appendQueue(queue, i);
-
- //添加邻近点t 512的tiles
- this.queueTilesForPanos(queue, t, tileDownloader, s, TilePrioritizer.MAX_SCORED_PANOS_TOADD);
- i.length = 0;
-
-
- //NARROW :
- if (this.canDownloadSize(c)) {//2048
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
- }
- if (this.canDownloadSize(h) && this.priorityCriteria.pano.pointcloud.tileRes != '2k') {//4096
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
- }
- TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs);//排序
- TilePrioritizer.appendQueue(queue, i);
- i.length = 0;
- if (this.canDownloadSize(l)) {//1024
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
- }
- if (this.canDownloadSize(c)) {//2048
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
- }
- if (this.canDownloadSize(h) && this.priorityCriteria.pano.pointcloud.tileRes != '2k') {//4096
- this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
- }
- TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs);//排序
- TilePrioritizer.appendQueue(queue, i);
-
-
-
- this.queueTilesForPanos(queue, e, tileDownloader, s); // 如果前面有populateNeighborPanos的话,这步就是加neibour
- }
- }()
- TilePrioritizer.prototype.queueTilesInDirectionForPano = function () {
- var e = {
- filter: h.DirectionalFOV,
- direction: new THREE.Vector3,
- fov: 60
- },
- t = new THREE.Vector3;
- return function (i, n, pano, o, a, dirs, c) {
-
- var dir = dirs.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
- //var dir = dirs
-
- t.copy(dir);
-
- TileUtils.getRelativeDirection(pano.quaternion4dkk, t);
- e.direction.copy(t);
- e.fov = c;
- return this.filterAndQueueTileDownloadDescriptors(i, n, pano, o, e)
- }
- }()
- TilePrioritizer.prototype.filterAndQueueTileDownloadDescriptors = function () {
- var e = [];
- return function (t, i, n, r, o) {
- var a = i.getTileDownloadDescriptors(n, r);
- e.length = 0,
- this.filterTileDownloadDescriptors(n, a, e, o);
- for (var s = 0, l = 0; l < e.length; l++) {
- var c = e[l];
- if (c) {
- t.push(c);
- s++;
- }
- }
- return s
- }
- }()
- TilePrioritizer.prototype.filterTileDownloadDescriptors = function () {
- new THREE.Vector3;
- return function (e, t, i, n) {
- var r, o;
- switch (n.filter) {
- case h.DirectionalFOV:
- for (r = 0; r < t.length; r++)
- o = t[r],
- TileUtils.isTileWithinFOV(o.panoSize, o.tileSize, o.face, o.tileX, o.tileY, n.direction, n.fov) && i.push(o);
- break;
- default:
- for (r = 0; r < t.length; r++)
- o = t[r],
- i.push(o)
- }
- for (r = 0; r < i.length; r++)
- o = i[r],
- this.canIncludeDescriptor(o) || (i[r] = null)
- }
- }()
- TilePrioritizer.prototype.queueTilesForPano = function () {
- var e = {
- filter: h.None
- };
- return function (t, i, n, r) {
- return this.filterAndQueueTileDownloadDescriptors(t, i, n, r, e)
- }
- }()
- /* TilePrioritizer.prototype.queueTilesForPanosInDirection = function () { //没用到
- var e = new THREE.Vector3;
- return function (t, i, n, r, o, a, s, l) {
- for (var h = 0, u = 0; u < n.length; u++) {
- var d = n[u];
- e.copy(d.position),
- e.sub(o),
- e.normalize();
- var p = Math.max(Math.min(a.dot(e), 1), -1),
- f = c.getFOVDotThreshold(s);
- if (p >= f) {
- var g = this.queueTilesInDirectionForPano(t, i, d, r, o, a, s);
- if (h += g > 0 ? 1 : 0,
- l && h >= l)
- break
- }
- }
- return h
- }
- }() */
|