xzw пре 1 година
родитељ
комит
2652d46ab6
2 измењених фајлова са 30 додато и 25 уклоњено
  1. 24 21
      service/PanoBoxFrame.js
  2. 6 4
      service/planeCoverService.js

+ 24 - 21
service/PanoBoxFrame.js

@@ -7,10 +7,11 @@ import Vectors from './util/Vectors.js'
 const version = 'output'
  
 const convertTool = {
-    getQuaByAim: function (aim, center) {
-        return new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, -1), aim.clone().sub(center).normalize())
+    getQuaByAim: function (aim, center=new THREE.Vector3, forward=new THREE.Vector3(0, 0, -1)){ //z朝上的坐标系是  forward = new THREE.Vector3(0, 1, 0)
+        let qua1 = new THREE.Quaternion().setFromUnitVectors(forward, aim.clone().sub(center).normalize())
         //或var _ = (new THREE.Matrix4).lookAt(pano.position, aim, new THREE.Vector3(0,1,0));  aimQua = (new THREE.Quaternion).setFromRotationMatrix(_);
-    } 
+        return qua1
+    },
 }
 
 //----------------------复制以下内容--------------------------------- 
@@ -26,6 +27,7 @@ let hue = 0,
     startTime
 const MinBoxInitialScore = 0.68 //找不到匹配时,若box分数低于该值,不createSinglePano
 let boxesSolid = []
+  
 
 let standards = {
     cabinet: {
@@ -293,10 +295,8 @@ class Box {
     }
 
 
-    getDirection(){//需要全部box都创建完再调用
-        
-        
-        //let quaternion =
+    getDirection(){//获得正面朝向。  需要全部box都创建完再调用
+           
         let xProp = this.xProp
         let dir 
         //哪边pano多朝哪边
@@ -340,41 +340,45 @@ class Box {
             
             if(xProp == 'width'){
                  
-                if (Math.abs(this.panosDir['z+']) < Math.abs(this.panosDir['z-'])) {//朝-z
-                    /* this.dirQua='下' */dir = new THREE.Vector3(0,0,-1)
+                if (Math.abs(this.panosDir['z+']) < Math.abs(this.panosDir['z-'])) {//朝-z//也就是新坐标系的y
+                    //this.dirQua='下' 
+                    dir = new THREE.Vector3(0,1,0)
                 }else{//朝+z
-                    /* this.dirQua='上' */dir = new THREE.Vector3(0,0, 1)
+                    //this.dirQua='上' 
+                    dir = new THREE.Vector3(0,-1,0)
                 }
             }else{
                 if (Math.abs(this.panosDir['x+']) < Math.abs(this.panosDir['x-'])) {//朝-x
-                    /* this.dirQua='右' */dir = new THREE.Vector3(-1,0,0)
+                    //this.dirQua='右' 
+                    dir = new THREE.Vector3(-1,0,0)
                 }else{//朝+x
-                    /* this.dirQua='左' */dir = new THREE.Vector3(1,0,0)
+                     //this.dirQua='左' 
+                     dir = new THREE.Vector3(1,0,0)
                 }
             }
         } 
         //addLabel(this.position, this.dirQua)
+          
             
-            
-        this.dirQua = convertTool.getQuaByAim(new THREE.Vector3, dir) 
+        this.dirQua = convertTool.getQuaByAim(dir, new THREE.Vector3, new THREE.Vector3(0,1,0)) 
         return   this.dirQua 
         
         
       /*飞到俯视图查看(不旋转视图,x朝右,z朝下)。以下四个qua是四个墙壁每个墙壁上的dirQua。 
       
-                            _x: 0, _y: 0, _z: 0, _w: 1
+                                     _x: 0, _y: -0, _z: 1, _w: 0 
     
 
-  _x: 0, _y: 0.707, _z: 0, _w: 0.707               _x: 0, _y: -0.707, _z: 0, _w: 0.707}
+        _x: 0, _y: 0, _z: -0.707, _w: 0.707                    _x: 0, _y: -0, _z: 0.707, _w: 0.707
 
 
-                             _x: 0, _y: 1, _z: 0, _w: 0 
+                                    x: 0, _y: 0, _z: 0, _w: 1
                              
      */
         
     }
 
-    toJson() {
+    toJson() {//转出的坐标系是z朝上的
         let category = typeNames[this.boxType]
         if (category instanceof Array) {
             let scoreMap = new Map()
@@ -395,12 +399,11 @@ class Box {
             })
             category = category[0] //最高分
         }
-        
+         
         this.getDirection()
-        
 
         let json = {
-            points: axises.map(axis => new THREE.Vector3().addVectors(this.position, this.size.clone().multiply(axis).multiplyScalar(0.5)).toArray()),
+            points: axises.map(axis => math.invertVisionVector(new THREE.Vector3().addVectors(this.position, this.size.clone().multiply(axis).multiplyScalar(0.5))).toArray()),
             category,
             type: this.boxType,
             sid: this.name,

+ 6 - 4
service/planeCoverService.js

@@ -4,10 +4,9 @@ import * as THREE from 'three'
 import axios from 'axios'
 import Decompress from './util/Decompress.js'
 import Process from './util/Process.js'
-import Model from './util/Model.js'
-
+import Model from './util/Model.js' 
 import Chunks from './util/Chunks.js' 
-
+import math from './util/math.js'
 import PanoBoxFrame from './PanoBoxFrame.js'
 
 
@@ -73,7 +72,10 @@ function outputJson(boxCenvert, sceneNum, player){
   let json = {
     sceneNum, 
     boxes:boxCenvert.boxesSolid.map(e=> e.toJson()),
-    boundingBox: {min:boxCenvert.safeBound.min.toArray(),max:boxCenvert.safeBound.max.toArray()}
+    boundingBox: {
+      min:math.invertVisionVector(boxCenvert.safeBound.min).toArray(),
+      max:math.invertVisionVector(boxCenvert.safeBound.max).toArray()
+    }
   }
   
   return json