| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173 |
- import * as THREE from "../libs/three.js/build/three.module.js";
- import {PointCloudTree, PointCloudTreeNode} from "./PointCloudTree.js";
- import {PointCloudOctreeGeometryNode} from "./PointCloudOctreeGeometry.js";
- import {Utils} from "./utils.js";
- import {PointCloudMaterial} from "./materials/PointCloudMaterial.js";
- import math from "./utils/math.js";
- import Common from './utils/Common.js'
- import {MeshDraw} from "./utils/DrawUtil.js";
- import searchRings from "./utils/searchRings.js";
- import {TextSprite} from './objects/TextSprite.js'
- import {PointSizeType } from "./defines.js";
-
- const planeGeo = new THREE.PlaneBufferGeometry(1,1);
-
- const planeMats = new Map()
- let getPlaneMat = (group, removed)=>{
- let mat = planeMats.get(group)
- if(mat)return mat
-
-
- var planeMat = new THREE.MeshBasicMaterial({
- //color: level == 'removed' ? "#f00" : new THREE.Color(1 - level*0.2, 1,1),
- color: (new THREE.Color()).setHSL(Math.random(), 0.5, 0.9) ,
- //color: (new THREE.Color()).setHSL(removed ? 0 : 0.6, Math.random(), 0.9/* Math.random() */) ,
-
- transparent:true,
- side:2,
- opacity: removed ? 0.3 : 0.9,
- })
- planeMats.set(group, planeMat)
- return planeMat
- }
- export class PointCloudOctreeNode extends PointCloudTreeNode {
- constructor () {
- super();
- //this.children = {};
- this.children = [];
- this.sceneNode = null;
- this.octree = null;
-
-
-
-
- }
-
- getNumPoints () {
- return this.geometryNode.numPoints;
- }
- isLoaded () {
- return true;
- }
- isTreeNode () {
- return true;
- }
- isGeometryNode () {
- return false;
- }
- getLevel () {
- return this.geometryNode.level;
- }
- getBoundingSphere () {
- return this.geometryNode.boundingSphere;
- }
- getBoundingBox () {
- return this.geometryNode.boundingBox;
- }
- getChildren () {
- let children = [];
- for (let i = 0; i < 8; i++) {
- if (this.children[i]) {
- children.push(this.children[i]);
- }
- }
- return children;
- }
- getPointsInBox(boxNode){
- if(!this.sceneNode){
- return null;
- }
- let buffer = this.geometryNode.buffer;
- let posOffset = buffer.offset("position");
- let stride = buffer.stride;
- let view = new DataView(buffer.data);
- let worldToBox = boxNode.matrixWorld.clone().invert();
- let objectToBox = new THREE.Matrix4().multiplyMatrices(worldToBox, this.sceneNode.matrixWorld);
- let inBox = [];
- let pos = new THREE.Vector4();
- for(let i = 0; i < buffer.numElements; i++){
- let x = view.getFloat32(i * stride + posOffset + 0, true);
- let y = view.getFloat32(i * stride + posOffset + 4, true);
- let z = view.getFloat32(i * stride + posOffset + 8, true);
- pos.set(x, y, z, 1);
- pos.applyMatrix4(objectToBox);
- if(-0.5 < pos.x && pos.x < 0.5){
- if(-0.5 < pos.y && pos.y < 0.5){
- if(-0.5 < pos.z && pos.z < 0.5){
- pos.set(x, y, z, 1).applyMatrix4(this.sceneNode.matrixWorld);
- inBox.push(new THREE.Vector3(pos.x, pos.y, pos.z));
- }
- }
- }
- }
- return inBox;
- }
- get name () {
- return this.geometryNode.name;
- }
- };
- export class PointCloudOctree extends PointCloudTree {
- constructor (geometry, material) {
- super();
-
- //this.pointBudget = Infinity;
- this.pcoGeometry = geometry;
- this.boundingBox = this.pcoGeometry.tightBoundingBox//this.pcoGeometry.boundingBox; //boundingBox是正方体,所以换掉
- this.boundingSphere = this.boundingBox.getBoundingSphere(new THREE.Sphere());
- this.material = material || new PointCloudMaterial();
- this.visiblePointsTarget = 2 * 1000 * 1000;
- this.minimumNodePixelSize = 150;
- this.level = 0;
- this.position.copy(geometry.offset);
- this.updateMatrix();
- this.nodeMaxLevel = 0;//add
- this.maxLevel = Infinity;
- this.temp = { sizeFitToLevel:{}, opacity:{}}//add
- //add
-
- this.panos = []
- this.matrixAutoUpdate = false //最好禁止updateMatrix 直接使用matrixWorld
- this.orientationUser = 0
- this.translateUser = new THREE.Vector3;
-
- this.rotateMatrix = new THREE.Matrix4;
- this.transformMatrix = new THREE.Matrix4;// 数据集的变化矩阵
- this.transformInvMatrix = new THREE.Matrix4;
- this.rotateInvMatrix = new THREE.Matrix4;
-
-
- this.nodeMaxLevelPredict = this.predictNodeMaxLevel()//预测maxNodeLevel
- this.testMaxNodeCount = this.testMaxNodeCount2 = 0
-
- this.material.spacing = this.pcoGeometry.spacing;//初始化一下 以便于设置pointsize
-
-
-
- {
- let priorityQueue = ["rgba", "rgb", "intensity", "classification"];
- let selected = "rgba";
- for(let attributeName of priorityQueue){
- let attribute = this.pcoGeometry.pointAttributes.attributes.find(a => a.name === attributeName);
- if(!attribute){
- continue;
- }
- let min = attribute.range[0].constructor.name === "Array" ? attribute.range[0] : [attribute.range[0]];
- let max = attribute.range[1].constructor.name === "Array" ? attribute.range[1] : [attribute.range[1]];
- let range_min = new THREE.Vector3(...min);
- let range_max = new THREE.Vector3(...max);
- let range = range_min.distanceTo(range_max);
- if(range === 0){
- continue;
- }
- selected = attributeName;
- break;
- }
- this.material.activeAttributeName = selected;
- }
- this.showBoundingBox = false;
- this.boundingBoxNodes = [];
- this.loadQueue = [];
- this.visibleBounds = new THREE.Box3();
- this.visibleNodes = [];
- this.visibleGeometry = [];
- this.generateDEM = false;
- this.profileRequests = [];
- this.name = '';
- this._visible = true;
- //this._isVisible = true//add
- //this.unvisibleReasons = []
-
- {
- let box = [this.pcoGeometry.tightBoundingBox, this.getBoundingBoxWorld()]
- .find(v => v !== undefined);
- this.updateMatrixWorld(true);
- box = Utils.computeTransformedBoundingBox(box, this.matrixWorld);
- let bMin = box.min.z;
- let bMax = box.max.z;
- this.material.heightMin = bMin;
- this.material.heightMax = bMax;
- }
- // TODO read projection from file instead
- this.projection = geometry.projection;
- this.fallbackProjection = geometry.fallbackProjection;
- this.root = this.pcoGeometry.root;
-
-
-
- this.pcoGeometry.addEventListener('updateNodeMaxLevel', this.updateNodeMaxLevel.bind(this))
- this.isPointcloud = true //add
- }
-
- /*
-
- 注释:node的level从最大的box 0开始。
- 且加载任意一个node必定也会加载它的所有祖先。(如visibleNodes中有一个level为4,则一定有3,2,1,0)
- visibleNodes就是所有可见的node,比如:
- 如果相机在0这个位置朝下,这时候的visibleNodes中只有一个level为0的node;
- 而如果朝上看,上方的几个node如果在视野中占据足够大的位置的话,就会加载。
- 如果相机在2这个位置朝上,这时候的visibleNodes中所包含的level为: 0,1,2
-
- ________________
- | | | |
- |__2| | |
- | 1 | 1 |
- |_______|_______|
- | |
- | |
- | 0 |
- |_______________|
-
- 查看box可在potree中开启
- */
-
-
-
-
-
- updateNodeMaxLevel(e){//目前点云包含node的最高level
- var level = Math.max(e.level, this.nodeMaxLevel)
- if(level != this.nodeMaxLevel){
- this.nodeMaxLevel = level
- //viewer.dispatchEvent({type:'updateNodeMaxLevel', pointcloud: this, nodeMaxLevel:level})
-
- //console.log('updateNodeMaxLevel ' + this.dataset_id + " : "+ this.nodeMaxLevel)
-
- this.setPointLevel()//重新计算
-
- if(!Potree.settings.sizeFitToLevel){
- this.changePointSize()
- }
- }
- }//注:在没有加载到真实的 nodeMaxLevel之前,点云会显示得偏大
-
-
-
- //panoEdit时比预测值小很多?
-
- testMaxNodeLevel(){//手动使maxLevel达到最高,从而迫使updateNodeMaxLevel。 因为Potree.settings.pointDensity 不为 'high'时,maxLevel不是所加载的最高,就很容易加载不出下一个层级,导致无法知道nodeMaxLevel
- if(this.testMaxNodeLevelDone ) return
- //if(this.nodeMaxLevel > this.nodeMaxLevelPredict.min )return
-
-
- if( this.nodeMaxLevel==0 )return true
- if( !viewer.atDatasets.includes(this))return true //否则老远就count++
-
- let levels = this.visibleNodes.map(e=>e.getLevel())
- let actMaxLevel = Math.max.apply(null, levels) //实际加载到的最高的node level
- if(actMaxLevel < this.maxLevel)return true// 还没加载到能加载到的最高。 但在细节设置较低时,排除作用微弱。
-
-
- //尝试加载出更高级的level
- let old = this.maxLevel
- this.maxLevel = 12;
- //var visibleNodes1 = this.visibleNodes.map(e=>e.getLevel())
- //console.log('visibleNodes1',visibleNodes1)
- Potree.updatePointClouds([this], viewer.scene.getActiveCamera(), viewer.mainViewport.resolution );
- //不在camera可视范围内还是加载不出来。即使临时修改位置
-
-
- var visibleNodes2 = this.visibleNodes.map(e=>e.getLevel())
- //console.log('visibleNodes2',visibleNodes2)
- this.maxLevel = old;
-
-
-
- this.testMaxNodeCount ++
- if(this.testMaxNodeCount > 500){
- console.log('testMaxNodeLevel次数超出,强制结束:',this.dataset_id, this.nodeMaxLevel, this.nodeMaxLevelPredict.min)
- this.testMaxNodeLevelDone = 'moreThanMaxCount'
- return; //在可以看见点云的情况下,超时,有可能是预测的max是错的
- }
- if(this.nodeMaxLevel < this.nodeMaxLevelPredict.min) return true //仍需要继续testMaxNodeLevel
-
- this.testMaxNodeCount2 ++; // 已经> this.nodeMaxLevelPredict.min 后,开始计数。因为min可能低于真实nodeMaxLevel所以要再试几次
-
- /* if(this.name == 'SS-t-CWmVgzP4XU'){
- console.log('SS-t-CWmVgzP4XU count++')
- } */
-
- if(this.testMaxNodeCount2 < 50) return true //再试几次 ( 主要是细节调得低时需要多测几次才加载到
- this.testMaxNodeLevelDone = true
-
-
-
-
-
- }
-
-
-
-
-
-
- setPointLevel(){
-
- var pointDensity = Potree.settings.pointDensity
- var config = Potree.config.pointDensity[pointDensity];
- if(!config)return
-
-
- /* if(this.testingMaxLevel){
- this.maxLevel = 12;//先加载到最大的直到测试完毕。由于5个level为一组来加载,所以如果写4最高能加载到5,如果写5最高能加载到下一个级别的最高也就是10
- //console.log('maxLevel: '+e.maxLevel + ' testingMaxLevel中 ' )
- }else{ */
- let percent = config.percentByUser && Potree.settings.UserDensityPercent != void 0 ? Potree.settings.UserDensityPercent : config.maxLevelPercent
- this.maxLevel = Math.round( percent * this.nodeMaxLevel);
- //console.log('maxLevel: '+e.maxLevel + ', density : '+Potree.settings.pointDensity, ", percent :"+percent);
-
- if(Potree.settings.sizeFitToLevel){
- this.changePointSize()
- }
- this.changePointOpacity()
- //}
- }
-
- //预测可能的nodeMaxLevel:
-
- predictNodeMaxLevel(){//预测maxNodeLevel。 可能只适用于我们相机拍的点云
- let spacing = {min:0.005, max:0.014};//最小节的两点间的距离 ,获得方法:spacing / Math.pow(2, nodeMaxLevel)。 目前观测的我们自己拍的这个数值的范围大概是这样
- let min = Math.log2(this.material.spacing / spacing.max); //有见过最大是0.01368
- let max = Math.log2(this.material.spacing / spacing.min); //大部分是 0.006
- //console.log('predictNodeMaxLevel:', this.name , min, max )
-
-
- return {min, max}
- }
-
- getHighestNodeSpacing(){
- return this.material.spacing / Math.pow(2, this.nodeMaxLevel) //前提是这个nodeMaxLevel是准确的
- }
-
- setName (name) {
- if (this.name !== name) {
- this.name = name;
- this.dispatchEvent({type: 'name_changed', name: name, pointcloud: this});
- }
- }
- getName () {
- return this.name;
- }
- getAttribute(name){
- const attribute = this.pcoGeometry.pointAttributes.attributes.find(a => a.name === name);
- if(attribute){
- return attribute;
- }else{
- return null;
- }
- }
- getAttributes(){
- return this.pcoGeometry.pointAttributes;
- }
- toTreeNode (geometryNode, parent) {
- let node = new PointCloudOctreeNode();
- // if(geometryNode.name === "r40206"){
- // console.log("creating node for r40206");
- // }
- let sceneNode = new THREE.Points(geometryNode.geometry, this.material); //好像没什么用
- sceneNode.name = geometryNode.name;
- sceneNode.position.copy(geometryNode.boundingBox.min);
- sceneNode.frustumCulled = false;
- sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
- if (material.program) {
- _this.getContext().useProgram(material.program.program);
- if (material.program.getUniforms().map.level) {
- let level = geometryNode.getLevel();
- material.uniforms.level.value = level;
- material.program.getUniforms().map.level.setValue(_this.getContext(), level);
- }
- if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
- let vnStart = this.visibleNodeTextureOffsets.get(node);
- material.uniforms.vnStart.value = vnStart;
- material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
- }
- if (material.program.getUniforms().map.pcIndex) {
- let i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
- material.uniforms.pcIndex.value = i;
- material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
- }
- }
- };
- // { // DEBUG
- // let sg = new THREE.SphereGeometry(1, 16, 16);
- // let sm = new THREE.MeshNormalMaterial();
- // let s = new THREE.Mesh(sg, sm);
- // s.scale.set(5, 5, 5);
- // s.position.copy(geometryNode.mean)
- // .add(this.position)
- // .add(geometryNode.boundingBox.min);
- //
- // viewer.scene.scene.add(s);
- // }
- node.geometryNode = geometryNode;
- node.sceneNode = sceneNode;
- node.pointcloud = this;
- node.children = [];
- //for (let key in geometryNode.children) {
- // node.children[key] = geometryNode.children[key];
- //}
- for(let i = 0; i < 8; i++){
- node.children[i] = geometryNode.children[i];
- }
- if (!parent) {
- this.root = node;
- this.add(sceneNode);
- } else {
- let childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
- parent.sceneNode.add(sceneNode);
- parent.children[childIndex] = node;
- }
- let disposeListener = function () {
- let childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
- parent.sceneNode.remove(node.sceneNode);
- parent.children[childIndex] = geometryNode;
- };
- geometryNode.oneTimeDisposeHandlers.push(disposeListener);
-
-
- //this.buildTexMesh(geometryNode,sceneNode)
- return node;
- }
-
-
-
-
-
- buildTexMesh11(geometryNode,sceneNode){
- // viewer.scene.pointclouds.forEach(a=>a.areaPlanes.forEach(e=>e.material = viewer.images360.cube.material))
- //还是无法避免不在同一个平面的点被识别到同一个面上,然后法向都算错了。 另外还有就是破面太多。虽然能算出地板也不错。或者只去算水平面和垂直面。
- let startTime = Date.now()
-
-
- if(!this.splitSprites){
- let splitSprites = new THREE.Object3D
- splitSprites.name = 'splitSprites_'+this.name
- splitSprites.matrixAutoUpdate = false //同pointcloud一样不自动更新,直接使用
- splitSprites.matrix.copy(this.matrix)
- splitSprites.matrixWorld.copy(this.matrixWorld)
- this.splitSprites = splitSprites
- viewer.scene.scene.add(splitSprites)
-
-
- this.areaPlanes = []
- }
-
-
- if(this.texMeshUseLevel == void 0 || geometryNode.level == this.texMeshUseLevel){//只需要某一层level的点
-
-
- let showPointLabel = true, showCenterLabel = false
-
-
-
- //let spritesGeo = new THREE.BufferGeometry();
-
- let scaleRatio = 1.4 //稍微放大些,填满缝隙
- let spriteWidth1 = this.material.spacing / Math.pow(2, geometryNode.level)
- if(spriteWidth1 > 3)return
- let spriteWidth = spriteWidth1 * scaleRatio
-
- if(this.texMeshUseLevel == void 0 ){
- this.texMeshUseLevel = geometryNode.level
- console.log('texMeshUseLevel ',geometryNode.level)
- }
-
- let geometry = geometryNode.geometry
- let count = geometry.attributes.position.count
-
- let end = Math.min(count, 6000)
- let start = Math.min(5000, end)
- console.warn('check points count:', end-start)
-
-
- let position = geometry.attributes.position.array
- let normal = geometry.attributes.normal.array
- let i
- let up = new THREE.Vector3(0,1,0) , zeroVec = new THREE.Vector3 //up写成z向上居然结果一样
-
- let positions = [];
- let normals = [];
- let newPositions = [];
- let newIndices = []
- let groupMaxPointCount = 1000 ;//太多找环会崩
-
- let minDisSquare = Math.pow(spriteWidth1 * 1.8 , 2 ) //这个数太小就连不上啦 1.65太小
- let minDot = Math.cos(THREE.Math.degToRad(5))//括号内是最小偏差角度, 20太大。太大的话会将立方体的相邻两面视为一个面。
-
- //根据相邻点位置和角度是否相近来分组。有风险:两大区域可能因为一个模棱两可中间点连接在一起。
-
- let closeGroups = []
- let groupTolerateMaxPoint = 6//组内点<=这个数的最后会被删除
- let removedCount = 0
- let useGroupCount = 0
-
- let splitSprites = new THREE.Object3D
- splitSprites.name = 'sub_splitSprites_'+geometryNode.name
- splitSprites.position.copy(sceneNode.position)
- splitSprites.rotation.copy(sceneNode.rotation)
- this.splitSprites.add(splitSprites)
-
- for(i=start;i<end;i++){
- let pos = new THREE.Vector3(position[3*i], position[3*i+1], position[3*i+2] );
- let nor = new THREE.Vector3(normal[3*i],normal[3*i+1],normal[3*i+2]);
- pos.nor = nor
- pos.index = i
- positions.push(pos)
- normals.push(nor)
-
-
- let groups = closeGroups.filter(group=>{
- if(group.length>groupMaxPointCount)return //满员了
- var hasClosed = group.some(p=>{
- var dis = p.distanceToSquared(pos)
- var dot = p.nor.dot(nor)
- if(dis<minDisSquare && dot>minDot){
- //return dis / minDisSquare + (Math.abs(p.nor.x - nor.x) + Math.abs(p.nor.y - nor.y) + Math.abs(p.nor.z - nor.z)) < 1.7
- return dis / minDisSquare - p.nor.dot(nor) < 0
- }
- })
- return hasClosed
- })
-
- if(groups.length == 0){//创建一个新的
- var newGroup = []
- closeGroups.push(newGroup)
- groups = [newGroup]
- }
-
- if(groups.length == 1){//直接加入原有的
- pos.belongTo = groups[0];
- }else if(groups.length>1){ // comebine多个组成一个
- let newBigGroup = [];
- groups.forEach(e=>{
- newBigGroup.push(...e)
- let index = closeGroups.indexOf(e);
- closeGroups.splice(index, 1)
- })
- closeGroups.push(newBigGroup)
- pos.belongTo = newBigGroup
- newBigGroup.forEach(e=>{e.belongTo = newBigGroup})
- }
- pos.belongTo.push(pos)
-
- }
-
-
-
- closeGroups.forEach((points,index)=>{//建造面
- if(points.length <= groupTolerateMaxPoint ){
-
-
- /* let sprite = new THREE.Mesh(planeGeo, getPlaneMat(pos.belongTo, true))
- sprite.lookAt(nor);
- sprite.position.copy(pos)
- sprite.scale.set(spriteWidth,spriteWidth,spriteWidth)
- sprite.name = geometryNode.name+'_index'+i
- splitSprites.add(sprite)
- removedCount ++; */
-
-
- removedCount += points.length;
- return
- }
- useGroupCount ++
-
- points.sort(function(a,b){
- return a.index - b.index
- })
-
- console.log(`开始解析 ${geometryNode.name} - 第${index}组,总第${points[0].index}个点,组内有${points.length}个点`)
-
- let planeMat = getPlaneMat(points, true)
-
-
- if(showPointLabel){
- points.forEach((p,i)=>{
- var label = new TextSprite({
- text : index+"-"+i+" ("+p.index+")"+geometryNode.name, dontFixOrient:true,
- backgroundColor: {r: planeMat.color.r*255, g: planeMat.color.g*255, b: planeMat.color.b*255, a:0.6},
- });
- label.lookAt(p.nor);
- label.position.copy(p)
- label.scale.set(spriteWidth/3, spriteWidth/3, spriteWidth/3)
- splitSprites.add(label)
-
- /* let sprite = new THREE.Mesh(planeGeo,planeMat)
- sprite.lookAt(p.nor);
- sprite.position.copy(p)
- sprite.scale.set(spriteWidth/3,spriteWidth/3,spriteWidth/3)
- sprite.name = geometryNode.name+'_group'+index+"_"+ i
- splitSprites.add(sprite) */
- })
-
- }
-
-
-
- var avePos = points.reduce(function(total, currentValue){
- return total.add(currentValue)
- }, new THREE.Vector3).multiplyScalar(1/points.length)
-
-
-
- let planeNormals = []
-
-
-
- {//获得planeNormals
- //随机找两个距离远的点算normal。 按距离排序后, //抽取若干个点,然后算两两之间的法线,其中距离远的多抽取几个。
- var sortPoints = points.slice(0).sort(function(a,b){
- return a.distanceToSquared(avePos) - b.distanceToSquared(avePos)
- })//从小到大
- var pickPoints
-
- var length = sortPoints.length
- if(length>=7){
- var ratio = [0.02,0.15,0.4,0.55,0.7,0.86,0.99];
- var index = ratio.map(e=>Math.round(e * (length-1)))
- //console.log('index ',index)
- pickPoints = index.map(e=>sortPoints[e])
- }else{
- pickPoints = sortPoints
- }
- //console.log('pickPoints', pickPoints)
- let num = pickPoints.length
-
- for(let i=0;i<num;i++){//任意一个三角形能算出一个normal
- for(let j=i+1;j<num;j++){
- for(let u=j+1;u<num;u++){
- var p1 = pickPoints[i]
- var p2 = pickPoints[j]
- var p3 = pickPoints[u]
-
- let vec1 = new THREE.Vector3().subVectors(p1,p3)
- let vec2 = new THREE.Vector3().subVectors(p2,p3)
- let nor = vec1.cross(vec2).normalize()
-
- if(planeNormals[0]){
- if(nor.dot(planeNormals[0])<0)nor.negate() //反向下
- }
- console.log('nor',nor)
- planeNormals.push(nor)
-
- }
- }
- }
-
- }
-
-
-
-
- var aveNor = planeNormals.reduce(function(total, currentValue){
- return total.add(currentValue)
- }, new THREE.Vector3).normalize()
-
- console.log('aveNor',aveNor, 'avePos' ,avePos, index)
-
-
- if(showCenterLabel){
- var label = new TextSprite({
- //index+"-"+i+" ("+p.index+")"+geometryNode.name
-
- text : `我是${index}组 ${geometryNode.name} 中心点`, dontFixOrient:true,
- backgroundColor: {r: planeMat.color.r*255, g: planeMat.color.g*255, b: planeMat.color.b*255, a:0.6},
- });
- label.lookAt(aveNor);
- label.position.copy(avePos)
- label.scale.set(spriteWidth, spriteWidth, spriteWidth)
- splitSprites.add(label)
- }
-
- var facePlane = new THREE.Plane().setFromNormalAndCoplanarPoint(aveNor, avePos )
-
- var coplanarPoints = points.map(p=> facePlane.projectPoint(p, new THREE.Vector3() ))
-
-
-
- var originPoint0 = coplanarPoints[0].clone()
- var qua = math.getQuaBetween2Vector(facePlane.normal, new THREE.Vector3(0,0,1), new THREE.Vector3(0,0,1));
- let points2d = coplanarPoints.map(e=>e.clone().applyQuaternion(qua))
- let quaInverse = qua.clone().invert()
-
- //--------------------
-
- let lines = []
-
- points2d.forEach((p,j)=>{
- p.id = j
- for(let i=0;i<j;i++){
- if(p.distanceToSquared(points2d[i])<minDisSquare*1.5){
- lines.push({p1:i,p2:j})
- }
- }
- })
-
- console.log('points count:',points2d.length, 'lines:',lines)
- var rings = searchRings({
- points:points2d,
- lines,
- onlyGetOutRing:true,
- precision: Math.max(spriteWidth1/10, 0.01)
- })
- console.log( 'rings:', rings )//mesh间可能重叠 但换上贴图材质应该看不出(但只要searchRings时getSliceLines就不会重叠)
- if(!rings)return
- let planeMat2 = planeMat.clone(); planeMat2.opacity = 0.5;
- var firstPos = points2d[0].clone()
- firstPos.z = 0 //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
- firstPos.applyQuaternion(quaInverse)
- var vec = originPoint0.clone().sub(firstPos)
-
- rings.forEach(ring=>{
- var shapeGeo = MeshDraw.getShapeGeo(ring.points)
- var areaPlane = new THREE.Mesh(shapeGeo, planeMat2)
-
-
- areaPlane.quaternion.copy(quaInverse)
- areaPlane.position.copy(vec)
- areaPlane.name = 'areaPlane_'+index
- splitSprites.add(areaPlane)
- this.areaPlanes.push(areaPlane)
- })
-
-
-
- })
- console.log(geometryNode.name, '中:')
- console.log('removed point count: ', removedCount/* splitSprites.children.length */)
- console.log(closeGroups)
- console.log('comebine mesh Len:', useGroupCount)
-
-
- /*
- spritesGeo.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(newPositions), 3));
- spritesGeo.setIndex( newIndices );
-
-
-
- let sprites = new THREE.Mesh(spritesGeo, getPlaneMat('use'))
- sprites.name = geometryNode.name
- sprites.position.copy(sceneNode.position)
- sprites.rotation.copy(sceneNode.rotation)
-
- sceneNode.sprites = sprites
- sprites.pointsNode = sceneNode
-
- if(geometryNode.level == 0){
- let root = new THREE.Object3D;
- root.name = 'spriteNodeRoot'
-
-
- root.matrixAutoUpdate = false //同pointcloud一样不自动更新,直接使用
- root.matrix.copy(this.matrix)
- root.matrixWorld.copy(this.matrixWorld)
- viewer.scene.scene.add(root)
- this.spriteNodeRoot = root
- }
- this.spriteNodeRoot.add(sprites) */
-
- console.log('computeTime: ' + (Date.now() - startTime))
- }
-
-
-
-
-
-
-
-
- //------------------
- /*
- viewer.scene.pointclouds[0].spriteNodeRoot.traverse(e=>e.material && (e.material = viewer.images360.cube.material))
- viewer.scene.scene.children[12].visible = false
-
- */
- }
-
- buildTexMesh(geometryNode,sceneNode){
-
- if(geometryNode.level <= 0){
- let startTime = Date.now()
- let splitSprites = new THREE.Object3D
- splitSprites.name = 'splitSprites_'+geometryNode.name
- splitSprites.matrixAutoUpdate = false //同pointcloud一样不自动更新,直接使用
- splitSprites.matrix.copy(this.matrix)
- splitSprites.matrixWorld.copy(this.matrixWorld)
- viewer.scene.scene.add(splitSprites)
-
-
- let spritesGeo = new THREE.BufferGeometry();
-
- let scaleRatio = 1.4 //稍微放大些,填满缝隙
- let spriteWidth1 = this.material.spacing / Math.pow(2, geometryNode.level)
- let spriteWidth = spriteWidth1 * scaleRatio
- console.log('spriteWidth:',spriteWidth)
-
-
-
- const removeChip = false
-
-
- let geometry = geometryNode.geometry
- let count = geometry.attributes.position.count
-
- //count = 4000
-
-
- let position = geometry.attributes.position.array
- let normal = geometry.attributes.normal.array
- let i
- let up = new THREE.Vector3(0,1,0) , zeroVec = new THREE.Vector3 //up写成z向上居然结果一样
-
- let positions = [];
- let normals = [];
- let newPositions = [];
- //let newNormals = [];
- let newIndices = []
- let cornerPoints = [new THREE.Vector3(-1,1,0),new THREE.Vector3(1,1,0),new THREE.Vector3(-1,-1,0),new THREE.Vector3(1,-1,0) ]
- let indices = [0, 2, 1, 2, 3, 1]
- cornerPoints.forEach(e=>e.multiplyScalar(spriteWidth/2))
-
-
-
- let minDisSquare = spriteWidth1 * spriteWidth1 * 1.5
-
-
- let closeGroups = []
- let groupTolerateMaxPoint = 4//组内点<=这个数的最后会被删除
- let removedCount = 0
-
-
- for(i=0;i<count;i++){
- let pos = new THREE.Vector3(position[3*i], position[3*i+1], position[3*i+2] );
- let nor = new THREE.Vector3(normal[3*i],normal[3*i+1],normal[3*i+2]);
- pos.nor = nor
- positions.push(pos)
- normals.push(nor)
-
- if(removeChip){
- let groups = closeGroups.filter(group=>{
- var hasClosed = group.some(p=>{
- var dis = p.distanceToSquared(pos)
- if(dis<minDisSquare){
- //return dis / minDisSquare + (Math.abs(p.nor.x - nor.x) + Math.abs(p.nor.y - nor.y) + Math.abs(p.nor.z - nor.z)) < 1.7
- return dis / minDisSquare - p.nor.dot(nor) < 0
-
-
- }
- })
- return hasClosed
- })
-
- if(groups.length == 0){//创建一个新的
- var newGroup = []
- closeGroups.push(newGroup)
- groups = [newGroup]
- }
-
- if(groups.length == 1){//直接加入原有的
- pos.belongTo = groups[0];
- }else if(groups.length>1){ // comebine多个组成一个
- let newBigGroup = [];
- groups.forEach(e=>{
- newBigGroup.push(...e)
- let index = closeGroups.indexOf(e);
- closeGroups.splice(index, 1)
- })
- closeGroups.push(newBigGroup)
- pos.belongTo = newBigGroup
- newBigGroup.forEach(e=>{e.belongTo = newBigGroup})
- }
- pos.belongTo.push(pos)
- }
-
-
-
- }
-
- for(i=0;i<count;i++){
- let pos = positions[i]
- let nor = normals[i]
- if(Math.abs(nor.z)>0.2)continue
-
- if(removeChip){
- if(pos.belongTo.length <= groupTolerateMaxPoint){
-
- let sprite = new THREE.Mesh(planeGeo, getPlaneMat(pos.belongTo, true))
- sprite.lookAt(nor);
- sprite.position.copy(pos)
- sprite.scale.set(spriteWidth,spriteWidth,spriteWidth)
- sprite.name = geometryNode.name+'_index'+i
- splitSprites.add(sprite)
- removedCount ++;
-
- continue
- }else{
- /*
- let sprite = new THREE.Mesh(planeGeo, getPlaneMat(pos.belongTo))
- sprite.lookAt(nor);
- sprite.position.copy(pos)
- sprite.scale.set(spriteWidth/3,spriteWidth/3,spriteWidth/3)
- sprite.name = geometryNode.name+'_index'+i
- splitSprites.add(sprite)
- */
-
- }
- }
-
-
-
- let matrix = (new THREE.Matrix4).lookAt( nor, zeroVec, up);
- matrix.elements[12] = pos.x
- matrix.elements[13] = pos.y
- matrix.elements[14] = pos.z
-
-
- cornerPoints.forEach(p=>{
- let point = p.clone();
- point.applyMatrix4(matrix)
-
- newPositions.push(...point.toArray())
- //newNormals
- })
-
- indices.forEach(index=>{
- newIndices.push(index + i*4)
- })
-
-
-
- }
-
- /* closeGroups.forEach(e=>{
- if(e.length <= groupTolerateMaxPoint )return
-
-
-
- }) */
-
- console.log('removed count: ', removedCount/* splitSprites.children.length */)
- console.log(closeGroups)
- console.log('computeTime: ' + (Date.now() - startTime))
-
-
-
- spritesGeo.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(newPositions), 3));
- spritesGeo.setIndex( newIndices );
-
-
-
- let sprites = new THREE.Mesh(spritesGeo, getPlaneMat('use'))
- sprites.name = geometryNode.name
- sprites.position.copy(sceneNode.position)
- sprites.rotation.copy(sceneNode.rotation)
-
- sceneNode.sprites = sprites
- sprites.pointsNode = sceneNode
-
- if(geometryNode.level == 0){
- let root = new THREE.Object3D;
- root.name = 'spriteNodeRoot'
-
-
- root.matrixAutoUpdate = false //同pointcloud一样不自动更新,直接使用
- root.matrix.copy(this.matrix)
- root.matrixWorld.copy(this.matrixWorld)
- viewer.scene.scene.add(root)
- this.spriteNodeRoot = root
- }
- this.spriteNodeRoot.add(sprites)
- viewer.setObjectLayers(sprites,'sceneObjects')
-
-
- }
-
-
- }
-
-
-
-
- updateVisibleBounds () {
- let leafNodes = [];
- for (let i = 0; i < this.visibleNodes.length; i++) {
- let node = this.visibleNodes[i];
- let isLeaf = true;
- for (let j = 0; j < node.children.length; j++) {
- let child = node.children[j];
- if (child instanceof PointCloudOctreeNode) {
- isLeaf = isLeaf && !child.sceneNode.visible;
- } else if (child instanceof PointCloudOctreeGeometryNode) {
- isLeaf = true;
- }
- }
- if (isLeaf) {
- leafNodes.push(node);
- }
- }
- this.visibleBounds.min = new THREE.Vector3(Infinity, Infinity, Infinity);
- this.visibleBounds.max = new THREE.Vector3(-Infinity, -Infinity, -Infinity);
- for (let i = 0; i < leafNodes.length; i++) {
- let node = leafNodes[i];
- this.visibleBounds.expandByPoint(node.getBoundingBox().min);
- this.visibleBounds.expandByPoint(node.getBoundingBox().max);
- }
- }
- updateMaterial (material, visibleNodes, camera, renderer, resolution) {
- material.fov = camera.fov * (Math.PI / 180);
- /* material.screenWidth = renderer.domElement.clientWidth;
- material.screenHeight = renderer.domElement.clientHeight; */
- material.resolution = resolution
-
-
- //material.spacing = this.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z); //应该不需要
- material.near = camera.near;
- material.far = camera.far;
- material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize(new THREE.Vector3()).x;
- }
- computeVisibilityTextureData(nodes, camera){
- if(Potree.measureTimings) performance.mark("computeVisibilityTextureData-start");
- let data = new Uint8Array(nodes.length * 4);
- let visibleNodeTextureOffsets = new Map();
- // copy array
- nodes = nodes.slice();
- // sort by level and index, e.g. r, r0, r3, r4, r01, r07, r30, ...
- let sort = function (a, b) {
- let na = a.geometryNode.name;
- let nb = b.geometryNode.name;
- if (na.length !== nb.length) return na.length - nb.length;
- if (na < nb) return -1;
- if (na > nb) return 1;
- return 0;
- };
- nodes.sort(sort);
- let worldDir = new THREE.Vector3();
- let nodeMap = new Map();
- let offsetsToChild = new Array(nodes.length).fill(Infinity);
- for(let i = 0; i < nodes.length; i++){
- let node = nodes[i];
- nodeMap.set(node.name, node);
- visibleNodeTextureOffsets.set(node, i);
- if(i > 0){
- let index = parseInt(node.name.slice(-1));
- let parentName = node.name.slice(0, -1);
- let parent = nodeMap.get(parentName);
- let parentOffset = visibleNodeTextureOffsets.get(parent);
- let parentOffsetToChild = (i - parentOffset);
- offsetsToChild[parentOffset] = Math.min(offsetsToChild[parentOffset], parentOffsetToChild);
- data[parentOffset * 4 + 0] = data[parentOffset * 4 + 0] | (1 << index);
- data[parentOffset * 4 + 1] = (offsetsToChild[parentOffset] >> 8);
- data[parentOffset * 4 + 2] = (offsetsToChild[parentOffset] % 256);
- }
- let density = node.geometryNode.density;
-
- if(typeof density === "number"){
- let lodOffset = Math.log2(density) / 2 - 1.5;
- let offsetUint8 = (lodOffset + 10) * 10;
- data[i * 4 + 3] = offsetUint8;
- }else{
- data[i * 4 + 3] = 100;
- }
- }
- if(Potree.measureTimings){
- performance.mark("computeVisibilityTextureData-end");
- performance.measure("render.computeVisibilityTextureData", "computeVisibilityTextureData-start", "computeVisibilityTextureData-end");
- }
- return {
- data: data,
- offsets: visibleNodeTextureOffsets
- };
- }
- nodeIntersectsProfile (node, profile) {
- let bbWorld = node.boundingBox.clone().applyMatrix4(this.matrixWorld);
- let bsWorld = bbWorld.getBoundingSphere(new THREE.Sphere());
- let intersects = false;
- for (let i = 0; i < profile.points.length - 1; i++) {
- let start = new THREE.Vector3(profile.points[i + 0].x, profile.points[i + 0].y, bsWorld.center.z);
- let end = new THREE.Vector3(profile.points[i + 1].x, profile.points[i + 1].y, bsWorld.center.z);
- let closest = new THREE.Line3(start, end).closestPointToPoint(bsWorld.center, true, new THREE.Vector3());
- let distance = closest.distanceTo(bsWorld.center);
- intersects = intersects || (distance < (bsWorld.radius + profile.width));
- }
- //console.log(`${node.name}: ${intersects}`);
- return intersects;
- }
- deepestNodeAt(position){
-
- const toObjectSpace = this.matrixWorld.clone().invert();
- const objPos = position.clone().applyMatrix4(toObjectSpace);
- let current = this.root;
- while(true){
- let containingChild = null;
- for(const child of current.children){
- if(child !== undefined){
- if(child.getBoundingBox().containsPoint(objPos)){
- containingChild = child;
- }
- }
- }
- if(containingChild !== null && containingChild instanceof PointCloudOctreeNode){
- current = containingChild;
- }else{
- break;
- }
- }
- const deepest = current;
- return deepest;
- }
- nodesOnRay (nodes, ray) {
- let nodesOnRay = [];
- let _ray = ray.clone();
- for (let i = 0; i < nodes.length; i++) {
- let node = nodes[i];
- let sphere = node.getBoundingSphere().clone().applyMatrix4(this.matrixWorld);
- if (_ray.intersectsSphere(sphere)) {
- nodesOnRay.push(node);
- }
- }
- return nodesOnRay;
- }
- updateMatrixWorld (force) {
- if (this.matrixAutoUpdate === true) this.updateMatrix();
- if (this.matrixWorldNeedsUpdate === true || force === true) {
- if (!this.parent) {
- this.matrixWorld.copy(this.matrix);
- } else {
- this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
- }
- this.matrixWorldNeedsUpdate = false;
- force = true;
- }
- }
- hideDescendants (object) {
- let stack = [];
- for (let i = 0; i < object.children.length; i++) {
- let child = object.children[i];
- if (child.visible) {
- stack.push(child);
- }
- }
- while (stack.length > 0) {
- let object = stack.shift();
- object.visible = false;
- for (let i = 0; i < object.children.length; i++) {
- let child = object.children[i];
- if (child.visible) {
- stack.push(child);
- }
- }
- }
- }
- moveToOrigin () {
- this.position.set(0, 0, 0);
- this.updateMatrixWorld(true);
- let box = this.boundingBox;
- let transform = this.matrixWorld;
- let tBox = Utils.computeTransformedBoundingBox(box, transform);
- this.position.set(0, 0, 0).sub(tBox.getCenter(new THREE.Vector3()));
- };
- moveToGroundPlane () {
- this.updateMatrixWorld(true);
- let box = this.boundingBox;
- let transform = this.matrixWorld;
- let tBox = Utils.computeTransformedBoundingBox(box, transform);
- this.position.y += -tBox.min.y;
- };
- getBoundingBoxWorld () {
- this.updateMatrixWorld(true);
- let box = this.boundingBox;
- let transform = this.matrixWorld;
- let tBox = Utils.computeTransformedBoundingBox(box, transform);
- return tBox;
- };
- /**
- * returns points inside the profile points
- *
- * maxDepth: search points up to the given octree depth
- *
- *
- * The return value is an array with all segments of the profile path
- * let segment = {
- * start: THREE.Vector3,
- * end: THREE.Vector3,
- * points: {}
- * project: function()
- * };
- *
- * The project() function inside each segment can be used to transform
- * that segments point coordinates to line up along the x-axis.
- *
- *
- */
- getPointsInProfile (profile, maxDepth, callback) {
- if (callback) {
- let request = new Potree.ProfileRequest(this, profile, maxDepth, callback);
- this.profileRequests.push(request);
- return request;
- }
- let points = {
- segments: [],
- boundingBox: new THREE.Box3(),
- projectedBoundingBox: new THREE.Box2()
- };
- // evaluate segments
- for (let i = 0; i < profile.points.length - 1; i++) {
- let start = profile.points[i];
- let end = profile.points[i + 1];
- let ps = this.getProfile(start, end, profile.width, maxDepth);
- let segment = {
- start: start,
- end: end,
- points: ps,
- project: null
- };
- points.segments.push(segment);
- points.boundingBox.expandByPoint(ps.boundingBox.min);
- points.boundingBox.expandByPoint(ps.boundingBox.max);
- }
- // add projection functions to the segments
- let mileage = new THREE.Vector3();
- for (let i = 0; i < points.segments.length; i++) {
- let segment = points.segments[i];
- let start = segment.start;
- let end = segment.end;
- let project = (function (_start, _end, _mileage, _boundingBox) {
- let start = _start;
- let end = _end;
- let mileage = _mileage;
- let boundingBox = _boundingBox;
- let xAxis = new THREE.Vector3(1, 0, 0);
- let dir = new THREE.Vector3().subVectors(end, start);
- dir.y = 0;
- dir.normalize();
- let alpha = Math.acos(xAxis.dot(dir));
- if (dir.z > 0) {
- alpha = -alpha;
- }
- return function (position) {
- let toOrigin = new THREE.Matrix4().makeTranslation(-start.x, -boundingBox.min.y, -start.z);
- let alignWithX = new THREE.Matrix4().makeRotationY(-alpha);
- let applyMileage = new THREE.Matrix4().makeTranslation(mileage.x, 0, 0);
- let pos = position.clone();
- pos.applyMatrix4(toOrigin);
- pos.applyMatrix4(alignWithX);
- pos.applyMatrix4(applyMileage);
- return pos;
- };
- }(start, end, mileage.clone(), points.boundingBox.clone()));
- segment.project = project;
- mileage.x += new THREE.Vector3(start.x, 0, start.z).distanceTo(new THREE.Vector3(end.x, 0, end.z));
- mileage.y += end.y - start.y;
- }
- points.projectedBoundingBox.min.x = 0;
- points.projectedBoundingBox.min.y = points.boundingBox.min.y;
- points.projectedBoundingBox.max.x = mileage.x;
- points.projectedBoundingBox.max.y = points.boundingBox.max.y;
- return points;
- }
- /**
- * returns points inside the given profile bounds.
- *
- * start:
- * end:
- * width:
- * depth: search points up to the given octree depth
- * callback: if specified, points are loaded before searching
- *
- *
- */
- getProfile (start, end, width, depth, callback) {
- let request = new Potree.ProfileRequest(start, end, width, depth, callback);
- this.profileRequests.push(request);
- };
- getVisibleExtent () {
- return this.visibleBounds.applyMatrix4(this.matrixWorld);
- };
- intersectsPoint(position){
- let rootAvailable = this.pcoGeometry.root && this.pcoGeometry.root.geometry;
- if(!rootAvailable){
- return false;
- }
- if(typeof this.signedDistanceField === "undefined"){
- const resolution = 32;
- const field = new Float32Array(resolution ** 3).fill(Infinity);
- const positions = this.pcoGeometry.root.geometry.attributes.position;
- const boundingBox = this.boundingBox;
- const n = positions.count;
- for(let i = 0; i < n; i = i + 3){
- const x = positions.array[3 * i + 0];
- const y = positions.array[3 * i + 1];
- const z = positions.array[3 * i + 2];
- const ix = parseInt(Math.min(resolution * (x / boundingBox.max.x), resolution - 1));
- const iy = parseInt(Math.min(resolution * (y / boundingBox.max.y), resolution - 1));
- const iz = parseInt(Math.min(resolution * (z / boundingBox.max.z), resolution - 1));
- const index = ix + iy * resolution + iz * resolution * resolution;
- field[index] = 0;
- }
- const sdf = {
- resolution: resolution,
- field: field,
- };
- this.signedDistanceField = sdf;
- }
- {
- const sdf = this.signedDistanceField;
- const boundingBox = this.boundingBox;
- const toObjectSpace = this.matrixWorld.clone().invert();
- const objPos = position.clone().applyMatrix4(toObjectSpace);
- const resolution = sdf.resolution;
- const ix = parseInt(resolution * (objPos.x / boundingBox.max.x));
- const iy = parseInt(resolution * (objPos.y / boundingBox.max.y));
- const iz = parseInt(resolution * (objPos.z / boundingBox.max.z));
- if(ix < 0 || iy < 0 || iz < 0){
- return false;
- }
- if(ix >= resolution || iy >= resolution || iz >= resolution){
- return false;
- }
- const index = ix + iy * resolution + iz * resolution * resolution;
- const value = sdf.field[index];
- if(value === 0){
- return true;
- }
- }
- return false;
- }
- /**
- *
- *
- *
- * params.pickWindowSize: Look for points inside a pixel window of this size.
- * Use odd values: 1, 3, 5, ...
- *
- *
- * TODO: only draw pixels that are actually read with readPixels().
- *
- */
- pick(viewer, viewport, camera, ray, params = {}){
-
- let renderer = viewer.renderer;
- let pRenderer = viewer.pRenderer;
- performance.mark("pick-start");
- let getVal = (a, b) => a != void 0 ? a : b;
-
-
- let pickWindowSize_ = THREE.Math.clamp( Math.round((1.1-this.maxLevel/this.nodeMaxLevel)*80), 5, 100)
-
- let pickWindowSize = getVal(params.pickWindowSize, pickWindowSize_ ); /* 65 */ //拾取像素边长,越小越精准,但点云稀疏的话可能容易出现识别不到的情况。 另外左下侧会有缝隙无法识别到,缝隙大小和这个值有关
-
- let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
- let size = viewport ? viewport.resolution : renderer.getSize(new THREE.Vector2());
- let width = Math.ceil(getVal(params.width, size.width)); //renderTarget大小。影响识别精度
- let height = Math.ceil(getVal(params.height, size.height));
-
- let screenshot = ()=>{
- if(window.testScreen){
- let dataUrl = Potree.Utils.renderTargetToDataUrl(pickState.renderTarget, width, height, renderer)
-
- Common.downloadFile(dataUrl, 'screenshot.jpg') //为什么图片上不是只有pickWindowSize区域有颜色??
- window.testScreen = 0
- }
- }
-
-
- let pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
- let pointSize = getVal(params.pointSize, this.material.size);
- let nodes = this.nodesOnRay(this.visibleNodes, ray);
- if (nodes.length === 0) {
-
- return null;
- }
- //console.log('nodes.length != 0', this.name)
- if (!this.pickState) {
- let scene = new THREE.Scene();
- let material = new Potree.PointCloudMaterial();
- material.activeAttributeName = "indices";
- let renderTarget = new THREE.WebGLRenderTarget(
- 1, 1,
- { minFilter: THREE.LinearFilter,
- magFilter: THREE.NearestFilter,
- format: THREE.RGBAFormat }
- );
- this.pickState = {
- renderTarget: renderTarget,
- material: material,
- scene: scene
- };
- };
- let pickState = this.pickState;
- let pickMaterial = pickState.material;
- { // update pick material
- pickMaterial.pointSizeType = pointSizeType;
- //pickMaterial.shape = this.material.shape;
- pickMaterial.shape = Potree.PointShape.PARABOLOID;
- pickMaterial.uniforms.uFilterReturnNumberRange.value = this.material.uniforms.uFilterReturnNumberRange.value;
- pickMaterial.uniforms.uFilterNumberOfReturnsRange.value = this.material.uniforms.uFilterNumberOfReturnsRange.value;
- pickMaterial.uniforms.uFilterGPSTimeClipRange.value = this.material.uniforms.uFilterGPSTimeClipRange.value;
- pickMaterial.uniforms.uFilterPointSourceIDClipRange.value = this.material.uniforms.uFilterPointSourceIDClipRange.value;
- pickMaterial.activeAttributeName = "indices";
- pickMaterial.size = pointSize;
- pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
- pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
- pickMaterial.classification = this.material.classification;
- pickMaterial.recomputeClassification();
- if(params.pickClipped){
- pickMaterial.clipBoxes = this.material.clipBoxes;
- pickMaterial.uniforms.clipBoxes = this.material.uniforms.clipBoxes;
- if(this.material.clipTask === Potree.ClipTask.HIGHLIGHT){
- pickMaterial.clipTask = Potree.ClipTask.NONE;
- }else{
- pickMaterial.clipTask = this.material.clipTask;
- }
- pickMaterial.clipMethod = this.material.clipMethod;
- }else{
- pickMaterial.clipBoxes = [];
- }
- this.updateMaterial(pickMaterial, nodes, camera, renderer, new THREE.Vector2(width, height));
- }
- pickState.renderTarget.setSize(width, height); //仅绘制屏幕大小的,而不乘以devicePixelRatio
- let pixelPos = new THREE.Vector2(params.x, params.y);
- let gl = renderer.getContext();
- gl.enable(gl.SCISSOR_TEST);
- gl.scissor( //规定渲染范围,只渲染一小块
- parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
- parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
- parseInt(pickWindowSize), parseInt(pickWindowSize));
- renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
- renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
- renderer.state.setBlending(THREE.NoBlending);
- { // RENDER
- renderer.setRenderTarget(pickState.renderTarget);
- gl.clearColor(0, 0, 0, 0);
- renderer.clear(true, true, true);
- let tmp = this.material;
- this.material = pickMaterial;
-
- pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget);
- screenshot();
- this.material = tmp;
- }
- let clamp = (number, min, max) => Math.min(Math.max(min, number), max);
- let x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
- let y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
- /* let w = parseInt(Math.min(x + pickWindowSize, width) - x);
- let h = parseInt(Math.min(y + pickWindowSize, height) - y); */
-
- let pixelCount = pickWindowSize * pickWindowSize//w * h;
- let buffer = new Uint8Array(4 * pixelCount);
- //w<pickWindowSize会报错
-
- gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
- renderer.setRenderTarget(null);
- renderer.state.reset();
- renderer.setScissorTest(false);
- gl.disable(gl.SCISSOR_TEST);
- let pixels = buffer;
- let ibuffer = new Uint32Array(buffer.buffer); //四个数整合成一个
- // find closest hit inside pixelWindow boundaries
- let min = Number.MAX_VALUE;
- let hits = [];
- for (let u = 0; u < pickWindowSize; u++) {
- for (let v = 0; v < pickWindowSize; v++) {
- let offset = (u + v * pickWindowSize);
- let distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
- let pcIndex = pixels[4 * offset + 3];//nodes index(第四位)
- pixels[4 * offset + 3] = 0; //去除nodes index后剩下的是index(前三位)
- let pIndex = ibuffer[offset]; //index
- if(!(pcIndex === 0 && pIndex === 0) && (pcIndex !== undefined) && (pIndex !== undefined)){
- let hit = {
- pIndex: pIndex,
- pcIndex: pcIndex,
- distanceToCenter: distance
- };
- if(params.all){
- hits.push(hit);
- }else{
- if(hits.length > 0){
- if(distance < hits[0].distanceToCenter){
- hits[0] = hit;
- }
- }else{
- hits.push(hit);
- }
- }
- }
- }
- }
-
- // { // DEBUG: show panel with pick image
- // let img = Utils.pixelsArrayToImage(buffer, w, h);
- // let screenshot = img.src;
-
- // if(!this.debugDIV){
- // this.debugDIV = $(`
- // <div id="pickDebug"
- // style="position: absolute;
- // right: 400px; width: 300px;
- // bottom: 44px; width: 300px;
- // z-index: 1000;
- // "></div>`);
- // $(document.body).append(this.debugDIV);
- // }
-
- // this.debugDIV.empty();
- // this.debugDIV.append($(`<img src="${screenshot}"
- // style="transform: scaleY(-1); width: 300px"/>`));
- // //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
- // //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
- // }
- for(let hit of hits){
- let point = {};
- if (!nodes[hit.pcIndex]) {
- return null;
- }
- let node = nodes[hit.pcIndex];
- let pc = node.sceneNode;
- let geometry = node.geometryNode.geometry;
- for(let attributeName in geometry.attributes){
- let attribute = geometry.attributes[attributeName];
- if (attributeName === 'position') {
- let x = attribute.array[3 * hit.pIndex + 0];
- let y = attribute.array[3 * hit.pIndex + 1];
- let z = attribute.array[3 * hit.pIndex + 2];
- let position = new THREE.Vector3(x, y, z);
-
- position.applyMatrix4( pc.matrixWorld );
-
- point[attributeName] = position;
- } else if (attributeName === 'indices') {
- } else {
- let values = attribute.array.slice(attribute.itemSize * hit.pIndex, attribute.itemSize * (hit.pIndex + 1)) ;
- if(attribute.potree){
- const {scale, offset} = attribute.potree;
- values = values.map(v => v / scale + offset);
- }
- point[attributeName] = values;
- //debugger;
- //if (values.itemSize === 1) {
- // point[attribute.name] = values.array[hit.pIndex];
- //} else {
- // let value = [];
- // for (let j = 0; j < values.itemSize; j++) {
- // value.push(values.array[values.itemSize * hit.pIndex + j]);
- // }
- // point[attribute.name] = value;
- //}
- }
- }
- hit.point = point;
- }
- performance.mark("pick-end");
- performance.measure("pick", "pick-start", "pick-end");
- if(params.all){
- return hits.map(hit => hit.point);
- }else{
- if(hits.length === 0){
- return null;
- }else{
- return hits[0].point;
- //let sorted = hits.sort( (a, b) => a.distanceToCenter - b.distanceToCenter);
- //return sorted[0].point;
- }
- }
- };
- * getFittedBoxGen(boxNode){//???
- let start = performance.now();
- let shrinkedLocalBounds = new THREE.Box3();
- let worldToBox = boxNode.matrixWorld.clone().invert();
- for(let node of this.visibleNodes){
- if(!node.sceneNode){
- continue;
- }
- let buffer = node.geometryNode.buffer;
- let posOffset = buffer.offset("position");
- let stride = buffer.stride;
- let view = new DataView(buffer.data);
- let objectToBox = new THREE.Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
- let pos = new THREE.Vector4();
- for(let i = 0; i < buffer.numElements; i++){
- let x = view.getFloat32(i * stride + posOffset + 0, true);
- let y = view.getFloat32(i * stride + posOffset + 4, true);
- let z = view.getFloat32(i * stride + posOffset + 8, true);
- pos.set(x, y, z, 1);
- pos.applyMatrix4(objectToBox);
- if(-0.5 < pos.x && pos.x < 0.5){
- if(-0.5 < pos.y && pos.y < 0.5){
- if(-0.5 < pos.z && pos.z < 0.5){
- shrinkedLocalBounds.expandByPoint(pos);
- }
- }
- }
- }
- yield;
- }
- let fittedPosition = shrinkedLocalBounds.getCenter(new THREE.Vector3()).applyMatrix4(boxNode.matrixWorld);
- let fitted = new THREE.Object3D();
- fitted.position.copy(fittedPosition);
- fitted.scale.copy(boxNode.scale);
- fitted.rotation.copy(boxNode.rotation);
- let ds = new THREE.Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
- fitted.scale.multiply(ds);
- let duration = performance.now() - start;
- console.log("duration: ", duration);
- yield fitted;
- }
- getFittedBox(boxNode, maxLevel = Infinity){
- maxLevel = Infinity;
- let start = performance.now();
- let shrinkedLocalBounds = new THREE.Box3();
- let worldToBox = boxNode.matrixWorld.clone().invert();
- for(let node of this.visibleNodes){
- if(!node.sceneNode || node.getLevel() > maxLevel){
- continue;
- }
- let buffer = node.geometryNode.buffer;
- let posOffset = buffer.offset("position");
- let stride = buffer.stride;
- let view = new DataView(buffer.data);
- let objectToBox = new THREE.Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
- let pos = new THREE.Vector4();
- for(let i = 0; i < buffer.numElements; i++){
- let x = view.getFloat32(i * stride + posOffset + 0, true);
- let y = view.getFloat32(i * stride + posOffset + 4, true);
- let z = view.getFloat32(i * stride + posOffset + 8, true);
- pos.set(x, y, z, 1);
- pos.applyMatrix4(objectToBox);
- if(-0.5 < pos.x && pos.x < 0.5){
- if(-0.5 < pos.y && pos.y < 0.5){
- if(-0.5 < pos.z && pos.z < 0.5){
- shrinkedLocalBounds.expandByPoint(pos);
- }
- }
- }
- }
- }
- let fittedPosition = shrinkedLocalBounds.getCenter(new THREE.Vector3()).applyMatrix4(boxNode.matrixWorld);
- let fitted = new THREE.Object3D();
- fitted.position.copy(fittedPosition);
- fitted.scale.copy(boxNode.scale);
- fitted.rotation.copy(boxNode.rotation);
- let ds = new THREE.Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
- fitted.scale.multiply(ds);
- let duration = performance.now() - start;
- console.log("duration: ", duration);
- return fitted;
- }
- get progress () {
- return this.visibleNodes.length / this.visibleGeometry.length;
- }
- find(name){
- let node = null;
- for(let char of name){
- if(char === "r"){
- node = this.root;
- }else{
- node = node.children[char];
- }
- }
- return node;
- }
- get visible(){
- return this._visible;
- }
- set visible(value){
- if(value !== this._visible){
- this._visible = value;
- this.dispatchEvent({type: 'visibility_changed', pointcloud: this});
- }
- }
-
- // 设置点大小
- changePointSize(num, sizeFitToLevel) {
-
- if(this.material.pointSizeType != PointSizeType.ATTENUATED){
- return num && (this.material.size = num)
- }
- if (num == void 0) {
- num = this.temp.pointSize
- } else {
- this.temp.pointSize = num
-
- }
- num /= (Potree.config.material.realPointSize / Potree.config.material.pointSize) //兼容
-
-
-
-
- num = Math.pow(num, 1.05) * 6
-
-
-
-
- if(sizeFitToLevel || Potree.settings.sizeFitToLevel){//按照点云质量来调整的版本: 近似将pointSizeType换成ADAPTIVE
- let str = this.temp.pointSize+':'+this.maxLevel+':'+this.nodeMaxLevel
- let value = this.temp.sizeFitToLevel[str] //储存。防止每次渲染(反复切换density)都要算。
- if(value){
- this.material.size = value
- }else{
-
- let base = this.material.spacing / Math.pow(2, this.maxLevel) //点云大小在level为0时设置为spacing,每长一级,大小就除以2
- base *= this.nodeMaxLevel > 0 ? Math.max(0.1, Math.pow(this.maxLevel / this.nodeMaxLevel, 1.3)) : 0.1 //低质量的缩小点,因为视觉上看太大了。navvis是不铺满的,我们也留一点缝隙
- this.material.size = base * 3 * num/* * window.devicePixelRatio */
- //在t-8BCqxQAr93 会议室 和 t-e2Kb2iU 隧道 两个场景里调节,因为它们的spacing相差较大,观察会议室墙壁的龟裂程度
- this.temp.sizeFitToLevel[str] = this.material.size
- }
- }else{
-
- let base = 0.007; //let base = this.material.spacing / Math.pow(2, this.nodeMaxLevel) //点云大小在level为0时设置为spacing,每长一级,大小就除以2
- //base的数值理论上应该是右侧算出来的,但发现有的场景nodeMaxLevel和nodeMaxLevelPredict差别较大的点云显示也过大,而直接换成固定值反而可以适应所有场景。该固定值来源于 getHighestNodeSpacing 最小值,修改了下。(会不会是我们的相机其实该值是固定的,根据该值算出的spacing才是有误差的? 如果换了相机是否要改值?)
- this.material.size = base * 5 * num /* * window.devicePixelRatio */
- }
-
-
- //console.log('changePointSize ' + this.dataset_id + ' , num : ' + num + ' , size : ' + this.material.size, this.material.spacing)
-
- }
-
-
-
- // 设置点透明度
- changePointOpacity(num, canMoreThanOne) {
- //num:0-1 navvis用的是亮度
- if (num == void 0) {
- num = this.temp.pointOpacity
- } else {
- this.temp.pointOpacity = num
- }
-
- if(Potree.settings.editType == 'merge'){ //not AdditiveBlending
- return this.material.opacity = num
- }
-
- if (num == 1) {
- this.material.opacity = 1
- } else {
- let str = (Potree.settings.sizeFitToLevel?'sizeFit:':'')+ (canMoreThanOne ? 'canMoreThanOne:':'') +this.temp.pointOpacity+':'+this.maxLevel+':'+this.nodeMaxLevel
- let value = this.temp.opacity[str] //储存。防止每次渲染(反复切换density)都要算。
- if(value){
- this.material.opacity = value
- }else{
- if(Potree.settings.sizeFitToLevel){//按照点云质量来调整的版本:
- let base = this.material.spacing / Math.pow(1.4, this.maxLevel) //随着level提高,点云重叠几率增多
- let minBase = this.material.spacing / Math.pow(1.4, this.nodeMaxLevel)
- let ratio = Math.min(1 / base, 1 / minBase / 3) //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
- this.material.opacity = base * ratio * num
- if(!canMoreThanOne){
- this.material.opacity = THREE.Math.clamp(this.material.opacity, 0, 0.999) //到1就不透明了(可能出现一段一样)
- }
- }else{
- let base = this.material.spacing / Math.pow(1.8, this.maxLevel)
- let minBase = this.material.spacing / Math.pow(1.8, this.nodeMaxLevel)
- //console.log(1 / base, 1 / minBase / 6)
- let ratio = Math.min(1 / base, 1 / minBase / 6) //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
- this.material.opacity = base * ratio * num
- if(!canMoreThanOne){
- this.material.opacity = THREE.Math.clamp(this.material.opacity, 0, 0.999) //到1就不透明了(可能出现一段一样)
- }
- }
- this.temp.opacity[str] = this.material.opacity
- }
-
- //缺点:防止颜色过亮主要是相机离远时,当在漫游点处由于离点云太近,可能会导致高质量点云看起来很暗。
- }
- //console.log('changePointOpacity ' + this.dataset_id + ', num : ' + num + ' , opacity : ' + this.material.opacity) //检查是否做到了低质量时num==opacity,中质量opacity稍小于num,高质量更小
-
- }
-
- updateBound(){
- var boundingBox_ = this.pcoGeometry.tightBoundingBox.clone().applyMatrix4(this.matrixWorld)
- this.bound = boundingBox_
- }
- getPanosBound(){
- if(this.panos.length > 0){
- let minSize = new THREE.Vector3(1,1,1)
- this.panosBound = math.getBoundByPoints(this.panos.map(e=>e.position), minSize)
- }else{
- this.panosBound = null
- }
- }
-
- getUnrotBoundPoint(type){//获取没有旋转的tightBounding的水平四个点
- //如果alighment支持任意轴旋转,水平面上看到的可能就是六边形了,失去意义,到时候不能用这个。也可以若只绕z旋转, 使用tightBoundingBox,否则bound
- let bound = this.pcoGeometry.tightBoundingBox
- if(type == 'all'){
- return [new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
- new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
- new THREE.Vector3(bound.max.x, bound.max.y,bound.min.z),
- new THREE.Vector3(bound.min.x, bound.max.y,bound.min.z),
- new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
- new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
- new THREE.Vector3(bound.max.x, bound.max.y,bound.max.z),
- new THREE.Vector3(bound.min.x, bound.max.y,bound.max.z),
- ].map(e=>e.applyMatrix4(this.matrixWorld))
- }else
- return [new THREE.Vector3(bound.min.x, bound.min.y,0),
- new THREE.Vector3(bound.max.x, bound.min.y,0),
- new THREE.Vector3(bound.max.x, bound.max.y,0),
- new THREE.Vector3(bound.min.x, bound.max.y,0),
- ].map(e=>e.applyMatrix4(this.matrixWorld))
- }
-
-
-
- ifContainsPoint(pos){
- if(!this.bound || !this.bound.containsPoint(pos))return
- var points = this.getUnrotBoundPoint()
- return math.isPointInArea(points, null, pos)
- }
-
- getVolume(){
- var points = this.getUnrotBoundPoint()
- var area = Math.abs(math.getArea(points))
- return area * (this.bound.max.z - this.bound.min.z)
- }
-
-
- //数据集的显示影响到其下的:点云、marker .不会影响地图上的显示
-
- /*
- updateVisible(reason, ifShow){//当所有加入的条件都不为false时才显示
- if(ifShow){
- var index = this.unvisibleReasons.indexOf(reason);
- index > -1 && this.unvisibleReasons.splice(index, 1);
- if(this.unvisibleReasons.length == 0){
- this.visible = true;
- this.dispatchEvent({
- type: 'isVisible'
- visible:true
- })
- }
- }else {
- if(!this.unvisibleReasons.includes(reason)) this.unvisibleReasons.push(reason);
- this.visible = false;
- this.dispatchEvent({
- type: 'isVisible'
- visible:false
- })
- }
-
- }
-
- getVisible(reason){//获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
- if(this.visible)return true
- else{
- return !this.unvisibleReasons.includes(reason)
- }
- } */
-
-
- /* get isVisible(){//add 手动在数据集选择是否显示(和是否全景图、隐藏点云无关)
- return this._isVisible
- }
- set isVisible(visi){
-
- if(!visi)this.visible = false
-
-
-
- this._isVisible = visi
- } */
- }
- /*
- window.searchOutRing = function(points){
- var points = [{x:0,y:0},{x:1,y:1},{x:0,y:1},{x:1,y:0},{x:2,y:1},{x:1,y:2},{x:1,y:3},{x:2,y:3},
- {x:3,y:1},{x:3,y:2},{x:0,y:2},{x:0,y:3},{x:2,y:0},{x:-1,y:0},{x:-1,y:1},{x:-2,y:1},{x:3,y:3},
- {x:3,y:0},{x:2,y:-1},{x:0,y:-1},{x:1,y:0.5},{x:2,y:0.5}, ].map((e,index)=>{
- var a = new THREE.Vector2().copy(e)
- a.id = index;
- return a
- })
- var lines = []
- var minDis = 2*2
- points.forEach((p,j)=>{
- for(let i=0;i<j;i++){
- if(p.distanceToSquared(points[i])<minDis){
- lines.push({p1:i,p2:j})
- }
- }
- })
-
-
- searchRings({
- points,
- lines,
- onlyGetOutRing:true
- })
- }
- */
|