|
@@ -13,14 +13,15 @@ const planeGeo = new THREE.PlaneBufferGeometry(1,1);
|
|
const sphereSizeInfo = {
|
|
const sphereSizeInfo = {
|
|
nearBound : 2, scale:arrowSize, restricMeshScale : true,
|
|
nearBound : 2, scale:arrowSize, restricMeshScale : true,
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+//const arrowsShowingCount = 25; //场景里最多展示多少个箭头
|
|
|
|
+const arrowShowMinDis = 10
|
|
export class RouteGuider extends EventDispatcher{
|
|
export class RouteGuider extends EventDispatcher{
|
|
constructor () {
|
|
constructor () {
|
|
super();
|
|
super();
|
|
|
|
|
|
this.route = [];
|
|
this.route = [];
|
|
this.curve = []
|
|
this.curve = []
|
|
|
|
+ this.scenePoints = []
|
|
this.sceneMeshGroup = new THREE.Object3D;
|
|
this.sceneMeshGroup = new THREE.Object3D;
|
|
this.mapMeshGroup = new THREE.Object3D;
|
|
this.mapMeshGroup = new THREE.Object3D;
|
|
this.generateDeferred;
|
|
this.generateDeferred;
|
|
@@ -31,15 +32,39 @@ export class RouteGuider extends EventDispatcher{
|
|
}
|
|
}
|
|
init(){
|
|
init(){
|
|
if(this.inited) return;
|
|
if(this.inited) return;
|
|
|
|
+
|
|
let zoom;
|
|
let zoom;
|
|
viewer.mapViewer.addEventListener('camera_changed', e => {
|
|
viewer.mapViewer.addEventListener('camera_changed', e => {
|
|
|
|
+ if(!this.routeStart || !this.routeEnd) return
|
|
var camera = e.viewport.camera
|
|
var camera = e.viewport.camera
|
|
if(camera.zoom != zoom){
|
|
if(camera.zoom != zoom){
|
|
this.updateMapArrows(true)
|
|
this.updateMapArrows(true)
|
|
- zoom = camera.zoom
|
|
|
|
|
|
+ zoom = camera.zoom //这个就不延时了,因为滚轮不怎么连续
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ let lastPos = new THREE.Vector3
|
|
|
|
+ viewer.addEventListener('camera_changed', e => {
|
|
|
|
+ if(!this.routeStart || !this.routeEnd) return
|
|
|
|
+ Common.intervalTool.isWaiting('routeCameraInterval', ()=>{ //延时update,防止卡顿
|
|
|
|
+ let currPos = viewer.scene.getActiveCamera().position
|
|
|
|
+
|
|
|
|
+ if(!currPos.equals(lastPos)){
|
|
|
|
+ lastPos.copy(currPos)
|
|
|
|
+ this.updateArrowDisplay()
|
|
|
|
+
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }, 1000)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
var polesMats = {
|
|
var polesMats = {
|
|
shadowMat: new THREE.MeshBasicMaterial({
|
|
shadowMat: new THREE.MeshBasicMaterial({
|
|
@@ -452,7 +477,34 @@ export class RouteGuider extends EventDispatcher{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ updateArrowDisplay(){//根据当前位置更新显示一定范围内的箭头'
|
|
|
|
|
|
|
|
+ if(this.scenePoints.length == 0)return
|
|
|
|
+
|
|
|
|
+ /* var a = Common.sortByScore(this.scenePoints , null, [(point)=>{ //是否还要再requires里限制最远距离?
|
|
|
|
+ var playerPos = viewer.scene.getActiveCamera().position.clone().setZ(0)
|
|
|
|
+
|
|
|
|
+ var pos = point.clone().setZ(0)
|
|
|
|
+
|
|
|
|
+ return -pos.distanceTo(playerPos);
|
|
|
|
+
|
|
|
|
+ }]);
|
|
|
|
+ //获得展示的起始点
|
|
|
|
+ let start = a[0].item
|
|
|
|
+ let startIndex = this.scenePoints.indexOf(start)
|
|
|
|
+ this.arrows.children.forEach((e,i)=>{
|
|
|
|
+ if(i<startIndex || i>startIndex+arrowsShowingCount)e.visible = false
|
|
|
|
+ else e.visible = true
|
|
|
|
+ }) */
|
|
|
|
+
|
|
|
|
+ let cameraPos = viewer.scene.getActiveCamera().position
|
|
|
|
+ this.arrows.children.forEach((e,i)=>{
|
|
|
|
+ if(e.position.distanceTo(cameraPos) < arrowShowMinDis) e.visible = true
|
|
|
|
+ else e.visible = false
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
displayRoute(o={}){
|
|
displayRoute(o={}){
|
|
@@ -470,6 +522,7 @@ export class RouteGuider extends EventDispatcher{
|
|
this.mapPoints.forEach(e=>this.addMapArrow(e))
|
|
this.mapPoints.forEach(e=>this.addMapArrow(e))
|
|
this.mapArrows.children.forEach((e,i)=>this.setArrowDir(this.mapArrows.children,i));
|
|
this.mapArrows.children.forEach((e,i)=>this.setArrowDir(this.mapArrows.children,i));
|
|
viewer.mapViewer.dispatchEvent({'type':'content_changed'})
|
|
viewer.mapViewer.dispatchEvent({'type':'content_changed'})
|
|
|
|
+ this.updateArrowDisplay()
|
|
}
|
|
}
|
|
|
|
|
|
clearRoute(o={}){
|
|
clearRoute(o={}){
|