123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- import * as THREE from "../libs/three.js/build/three.module.js";
- import {settings, config} from './settings'
- import math from './utils/math'
- import browser from './utils/browser'
- import './extensions/three.shim.js'
-
- import {Utils} from "../src/utils.js"
-
- var start = function(dom, mapDom, number, fileServer, webSite){ //t-Zvd3w0m
- /* {
- let obj = JSON.parse(localStorage.getItem('setting'))
- for(let i in obj){
- console.log(i + ': ' + obj[i])
- }
- }
- */
- Potree.settings.number = number || 't-o5YMR13'// 't-iksBApb'// 写在viewer前
- Potree.fileServer = fileServer
- webSite && (Potree.settings.webSite = webSite)
-
-
- let viewer = new Potree.Viewer(dom , mapDom);
-
- let Alignment = viewer.modules.Alignment
-
-
- //let pointDensity = config.pointDensity.middle
- viewer.setEDLEnabled(false);
- viewer.setFOV(config.view.fov);
- //viewer.setPointBudget(pointDensity.pointBudget);
- viewer.loadSettingsFromURL();
-
-
-
- if(!Potree.settings.isOfficial){
- viewer.loadGUI(() => {
- viewer.setLanguage('en');
- //$("#menu_appearance").next().show();
- $("#menu_tools").next().show();
- $("#menu_scene").next().show();
- //$("#siteModel").show();
- $("#alignment").show();
- viewer.toggleSidebar();
- });
- Potree.settings.sizeFitToLevel = true//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
- }
- Potree.loadDatasetsCallback = function(data, ifReload){
- Potree.datasetData = data
- viewer.transform = null
- var datasetLength = data.length
- var loaded = 0
- var loadDone = function(){//点云cloud.js加载完毕后
- viewer.updateModelBound()
- let {boundSize, center} = viewer.bound
-
- Potree.Log(`中心点: ${math.toPrecision(center.toArray(),2)}, boundSize: ${math.toPrecision(boundSize.toArray(),2)} ` , null, 12)
-
- if(!ifReload){
- Potree.Images360Loader.load(viewer, {
- boundSize: boundSize.clone(),
- center: center.clone()
- }, images360 => {
- viewer.scene.add360Images(images360);
-
- viewer.mapViewer.addListener(images360)
-
- {//初始位置
-
- var urlFirstView = false
- var panoId = browser.urlHasValue('pano',true);
- if(panoId != void 0){
- var pos
- var pano = viewer.images360.panos.find(e=>e.id==panoId);
- if(pano){
- viewer.images360.focusPano({
- pano,
- duration:0,
- callback:()=>{/* Potree.settings.displayMode = 'showPanos' */}
- })
-
- }
- }
-
- }
-
-
-
- viewer.addObjectTest()
-
- viewer.emit('allLoaded')
- });
-
- }
- Potree.loadMapEntity() //加载floorplan,不一定成功
-
- if(!ifReload){
- viewer.scene.view.setView(//position, target
- center.clone().add(new THREE.Vector3(10,5,10)),
- center
- )
-
- if(!Potree.settings.isOfficial){
- setTimeout(//暂时延迟,等focus第一个点之后
- ()=>{
- // viewer.loadProject(Potree.scriptPath + "/data/t-iksBApb/potree.json5")
- },
- 500)
- }
-
- viewer.dispatchEvent({type:'loadPointCloudDone'})
-
- if(!Potree.settings.UserPointDensity){
- Potree.settings.UserPointDensity = 'middle'
- }
-
-
- Potree.Log('loadPointCloudDone 点云加载完毕', null, 10)
- }
-
-
-
-
- }
-
-
-
- var transformPointcloud = (pointcloud, dataset)=>{
- var locationLonLat = dataset.location.slice(0,2)
- //当只有一个dataset时,无论如何transform 点云和漫游点都能对应上。
- var location = viewer.transform.lonlatToLocal.forward(locationLonLat) //transform.inverse()
- //初始化位置
- pointcloud.matrixAutoUpdate = false //最好禁止updateMatrix 直接使用matrixWorld
- pointcloud.orientationUser = 0
- pointcloud.translateUser = new THREE.Vector3;
-
- viewer.sidebar && viewer.sidebar.addAlignmentButton(pointcloud)
-
- //dataset.orientation = 0
-
- Alignment.rotate(pointcloud, null, dataset.orientation)
- Alignment.translate(pointcloud, new THREE.Vector3(location[0], location[1], dataset.location[2]))
-
- pointcloud.updateMatrixWorld()
-
-
- Potree.Log(`点云${pointcloud.dataset_id}旋转值:${pointcloud.orientationUser}, 位置${math.toPrecision(pointcloud.translateUser.toArray(),3)}, 经纬度 ${locationLonLat}, spacing ${pointcloud.material.spacing}`, null, 17 )
-
-
- //-------------------
-
- //viewer.mapView.showSources(false);
- }
-
- data.forEach((dataset,index)=>{
-
- //dataset.location = [ 113.60182446595765,22.364155116865753,0]
- //dataset.orientation = -0.9
-
- if(!viewer.transform){//拿任意一个数据集作为基准。它的位置就会是000 (第一个数据集应该一直就是初始数据集吧?)
- var locationLonLat = dataset.location.slice(0,2)
- proj4.defs("NAVVIS:TMERC", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
- proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
- //proj4.defs("pointcloud", viewer.getProjection()); //不用从cloud里拿了
-
- let transform1 = proj4("WGS84", "NAVVIS:TMERC"); //这个ok TMERC是展开的平面投影
- let transform2 = proj4("+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs;");
-
-
- viewer.transform = {
- lonlatToLocal : transform1,
- lonlatTo4550 : transform2 // 转大地坐标EPSG:4550
- }
- // proj4(fromProjection, toProjection, coordinates)
- //let transform = proj4("WGS84", "pointcloud");
- viewer.mapViewer && viewer.mapViewer.mapLayer.maps[0].updateProjection()
-
- }
-
- if(!ifReload){
- var cloudPath = `https://${Potree.config.urls.prefix}/${Potree.settings.webSite}/${number}/data/${dataset.name}/webcloud/cloud.js`
- var timeStamp = dataset.createTime.replace(/[^0-9]/ig,''); //每重算一次后缀随createTime更新一次
-
- Potree.loadPointCloud(cloudPath, dataset.name , timeStamp, e => {
- let scene = viewer.scene;
- let pointcloud = e.pointcloud;
- let config = Potree.config.material
- let material = pointcloud.material;
-
- material.minSize = config.minSize
- material.maxSize = config.maxSize
- material.pointSizeType = config.pointSizeType //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
- pointcloud.changePointSize(config.pointSize) //material.size = config.pointSize;
- pointcloud.changePointOpacity(1)
- material.shape = Potree.PointShape.SQUARE;
- pointcloud.color = pointcloud.material.color = dataset.color
- pointcloud.dataset_id = dataset.id;//供漫游点找到属于的dataset点云
- pointcloud.timeStamp = timeStamp
- pointcloud.panos = []
- transformPointcloud(pointcloud,dataset)
- scene.addPointCloud(pointcloud);
- loaded ++;
- if(loaded == datasetLength)loadDone()
- })
-
- }else{
- let pointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == dataset.id)
- if(!pointcloud){
- Potree.Log('数据集id变了,自动使用第一个','#500')
- pointcloud = viewer.scene.pointclouds[0]
- }
- //先归零
- Alignment.translate(pointcloud, pointcloud.translateUser.clone().negate())
- Alignment.rotate(pointcloud, null, - pointcloud.orientationUser)
-
- transformPointcloud(pointcloud, dataset)
-
- }
-
- })
-
- if(ifReload){
-
- loadDone()
- }
-
-
- }
-
-
-
- Potree.loadDatasets(Potree.loadDatasetsCallback)
-
-
- window.testTransform = function(locationLonLat, location1, location2){
- proj4.defs("NAVVIS:test", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
-
- let transform = proj4("WGS84", "NAVVIS:test"); //这个ok navvis里也是这两种转换 见proj4Factory
- if(location1){//经纬度
- return transform.forward(location1)
- }else{
- return transform.inverse(location2)
- }
-
- }
- window.THREE = THREE
- window.buttonFunction = function(){
- /*
- viewer.startScreenshot({type:'measure', measurement:viewer.scene.measurements[0]})
- */
-
- viewer.modules.RouteGuider.routeStart = new THREE.Vector3(0,0,-1.3)
- viewer.modules.RouteGuider.routeEnd = new THREE.Vector3(-10,0,-1.3)
-
-
- }
- }
-
-
-
-
- /* var changeLog = ()=>{ //如果移动端加了test反而出不来bug的话,用这个
-
-
- var textarea = document.createElement('textarea');
- textarea.id = "consoleLog";
-
- textarea.style.width = '160px';
- textarea.style.height = '200px'
- textarea.style.position = 'fixed'
- textarea.style.right = 0
- textarea.style.bottom = '0'
- textarea.style['z-index'] = 9999;
- textarea.style.color = 'black';
- textarea.style.opacity = 0.9;
- textarea.style['font-size'] = '12px';
- textarea.style['backgroundColor'] = '#ffffff'
-
-
- document.getElementsByTagName("body")[0].appendChild(textarea);
- var list = ["log", "error", "warn", "debug", "info", "time", "timeEnd"]
- var exchange = function (o) {
- console["old" + o] = console[o];
- console[o] = function () {
- var args = Array.from(arguments)
- console["old" + o].apply(this, arguments)
- var t = document.getElementById("consoleLog").innerHTML;
-
- var str = ''
- args.forEach(a=>{
- str += a + ' '
- })
- document.getElementById("consoleLog").innerHTML = str + "\n\n" + t;
- }
- }
- for (var i = 0; i < list.length; i++) {
- exchange(list[i])
- }
-
-
-
- }
-
- changeLog() */
-
-
-
-
-
- export {start}
- /*
- 坐标转换问题:
- 由于控制点可以随便输入,所以本地和地理位置的转换也是可拉伸的。而navvis的转换是等比由中心展开,
- 所以对比两种转化方式时误差较大。
- 另外地理注册控制点是有参考数据集的,若参考数据集和我放置在0,0,0的数据集一致,就可直接使用,否则要转换。
- */
|