|
|
@@ -37,7 +37,18 @@ export default class Overlay extends THREE.Object3D {
|
|
|
this.setContent( data.media[0], data.url, data.isNew)
|
|
|
//this.setScale(data.width, data.height)
|
|
|
this.scale.set(data.width||1, data.height||1, 1) //需要把width转化一下吗,还是后端转化?
|
|
|
+ data.reverse && (this.scale.x *= -1)
|
|
|
this.addEventListener('dispose',this.dispose.bind(this))
|
|
|
+
|
|
|
+
|
|
|
+ let updatePlayInSight = ()=>{
|
|
|
+ Common.intervalTool.isWaiting('updatePlayInSight', ()=>{
|
|
|
+ Overlay.updatePlayInSight()
|
|
|
+ },500)
|
|
|
+ }
|
|
|
+ this.addEventListener('isVisible',updatePlayInSight)
|
|
|
+ this.addEventListener('transformChanged',updatePlayInSight)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -103,45 +114,89 @@ export default class Overlay extends THREE.Object3D {
|
|
|
|
|
|
dispose(){
|
|
|
//geo和mat已经在mergeEditor里删了,这要删一下video啥的吗?
|
|
|
+ let index = viewer.scene.overlays.indexOf(this)
|
|
|
+ if(index == -1)return
|
|
|
+ viewer.scene.overlays.splice(index,1)
|
|
|
+
|
|
|
if(this.mediaType == 'video'){
|
|
|
let media = this.plane.material.map.image
|
|
|
- media?.pause()
|
|
|
+ media?.pause()
|
|
|
this.disposed = true
|
|
|
}
|
|
|
}
|
|
|
- /* save(){ //不在这保存,因为当做模型保存的,只需要比模型多一个url、type的数据
|
|
|
- 也是加入到viewer.objs里
|
|
|
- let info = {
|
|
|
- "media": [
|
|
|
- this.mediaType
|
|
|
- ],
|
|
|
- "reverse": false,
|
|
|
- "limitToOnlyPano": false,
|
|
|
- "url": "WqXhX412472.png",
|
|
|
- "sid": "WqXhX412472",
|
|
|
- "depth": 0,
|
|
|
- "pos": [
|
|
|
- 0.8304,
|
|
|
- 0.8788,
|
|
|
- 1.2941
|
|
|
- ],
|
|
|
- "createTime": 1740641260916,
|
|
|
- "width": 0.7926,
|
|
|
- "frameType": "wall_1",
|
|
|
- "qua": [
|
|
|
- 0,
|
|
|
- 1,
|
|
|
- 0,
|
|
|
- 0
|
|
|
- ],
|
|
|
- "poster": "WqXhX412472.png",
|
|
|
- "floorIndex": 0,
|
|
|
- "height": 0.6309
|
|
|
+
|
|
|
+
|
|
|
+ videoControl(state){
|
|
|
+ var video = this.plane.material.map.image
|
|
|
+ if(!video)return
|
|
|
+
|
|
|
+
|
|
|
+ this.shouldPlay = state
|
|
|
+ if (!state || state == 'stop') {
|
|
|
+ if (!video.paused){
|
|
|
+ video.pause()
|
|
|
+ console.log('videoControl paused ')
|
|
|
+ }
|
|
|
+ }else if(state) {
|
|
|
+ if (video.paused){
|
|
|
+ console.log('videoControl play ')
|
|
|
+ //video = this.loadVideo()
|
|
|
+ video.play()
|
|
|
+ }
|
|
|
}
|
|
|
- return info
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ static updatePlayInSight(){
|
|
|
+ const min = 0.15//最小可播放尺寸(屏幕宽高都是2)
|
|
|
+ let camera = viewer.mainViewport.camera
|
|
|
+ let camDir = viewer.mainViewport.view.direction
|
|
|
+ let frustumMatrix = new THREE.Matrix4
|
|
|
+ frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
|
|
|
+ let frustum = new THREE.Frustum();
|
|
|
+ frustum.setFromProjectionMatrix(frustumMatrix)
|
|
|
|
|
|
- } */
|
|
|
+ let insight = (overlay)=>{
|
|
|
+
|
|
|
+ if(overlay.plane.material.side!=2){ //side为0
|
|
|
+ let dir = overlay.plane.getWorldDirection(new THREE.Vector3)
|
|
|
+ if(dir.dot(camDir)>0 ){
|
|
|
+ console.log('dir.dot(camDir)',dir.dot(camDir))
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //可能看到背面。若能看到正面,视线方向和plane朝向必定为钝角
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let bound = overlay.bound.clone()
|
|
|
+ let insight = frustum.intersectsBox(bound )
|
|
|
+ if(!insight)return false
|
|
|
+ bound.applyMatrix4(frustumMatrix); //project on screen
|
|
|
+ let boundSize = bound.getSize(new THREE.Vector3)
|
|
|
+ if(boundSize.x < min && boundSize.y < min){
|
|
|
+ //console.log('too small', boundSize)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ viewer.scene.overlays.forEach(overlay=>{
|
|
|
+ if(overlay.mediaType != 'video')return
|
|
|
+ let shouldPlay = overlay.realVisible() && insight(overlay)
|
|
|
+ overlay.videoControl(shouldPlay)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|