xushiting 3 年 前
コミット
3f539aeef4

+ 0 - 23
dist/index.html

@@ -190,29 +190,6 @@
         isPc: s
     }
 }
-  , ue4Rotation2Xverse = i=>isRotationCorrect() ? (i.pitch >= 89.5 ? i.pitch = 89.5 : i.pitch <= -89.5 && (i.pitch = -89.5),
-new BABYLON.Vector3(-1 * Math.PI * i.pitch / 180,Math.PI * i.yaw / 180 - Math.PI * 27 / 18,Math.PI * i.roll / 180 < .001 ? 0 : Math.PI * i.roll / 180)) : null
-  , ue4Rotation2Xverse_mesh = i=>isRotationCorrect() ? new BABYLON.Vector3(Math.PI * i.pitch / 180,Math.PI * i.yaw / 180,Math.abs(Math.PI * i.roll) / 180 < .001 ? 0 : -1 * (Math.PI * i.roll) / 180) : null
-  , scaleFromUE4toXverse = 100
-  , ue4Scaling2Xverse = i=>isScalingCorrect() ? new BABYLON.Vector3(i.x,i.z,-1 * i.y) : null
-  , ue4Position2Xverse = i=>isPositionCorrect() ? new BABYLON.Vector3(i.x * .01,i.z * .01,-1 * i.y * .01) : null
-  , xversePosition2Ue4 = i=>isPositionCorrect() ? {
-    x: i.x * 100,
-    y: -1 * i.z * 100,
-    z: i.y * 100
-} : null
-  , xverseRotation2Ue4 = i=>{
-    if (isPositionCorrect()) {
-        let e = 0;
-        return i.z == 0 ? e = 0 : e = 180 * i.z / Math.PI,
-        {
-            pitch: 180 * i.x * -1 / Math.PI,
-            yaw: (i.y + Math.PI * 27 / 18) * 180 / Math.PI,
-            roll: e
-        }
-    } else
-        return null
-}
   , calcDistance3D = (i,e)=>Math.sqrt((i.x - e.x) * (i.x - e.x) + (i.y - e.y) * (i.y - e.y) + (i.z - e.z) * (i.z - e.z))
   , calcDistance3DVector = (i,e)=>Math.sqrt((i.x - e.x) * (i.x - e.x) + (i.y - e.y) * (i.y - e.y) + (i.z - e.z) * (i.z - e.z))
   , isPositionCorrect = i=>!0

+ 1 - 1
dist/libs/decoder.js

@@ -1052,7 +1052,7 @@ if ('function' === typeof importScripts) {
   }
 
   Decoder.prototype.decodeFrame = function (data) {
-   // printConsole.log('decodeFrame'+JSON.stringify(data))
+   //printConsole.log('decodeFrame'+JSON.stringify(data))
     var content = data.media
     if (typeof content == 'undefined') {
       printConsole.error('null content in decoder', '5999')

+ 15 - 3
src/ActionsHandler.js

@@ -28,9 +28,6 @@ export default class ActionsHandler {
     }
 
     async sendData(e) {
-
-        console.log('发送数据:'+JSON.stringify(e))
-
         await this.beforeSend(e);
         const t = util.uuid();
         this.room.networkController.sendRtcData(le(oe({}, e.data), {
@@ -58,6 +55,21 @@ export default class ActionsHandler {
         }
         )
     }
+
+    //async sendData(e) {
+        //console.log('发送数据:'+JSON.stringify(e))
+        
+        //旋转
+        //window.room.sceneManager.scene.activeCamera.rotation.y
+
+        //心跳:要去掉
+
+        //邻居点:要去掉
+
+        //漫游
+        //人物所在位置和角度,相机的位置和角度,相机的目标点,点击的坐标
+    //}
+
     async beforeSend(e) {
         var o;
         const t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving

+ 6 - 5
src/BreathPoint.js

@@ -1,3 +1,4 @@
+import util from "./util.js"
 export default class BreathPoint {
     constructor(panoInfo) {
         E(this, "_staticmesh");
@@ -10,8 +11,8 @@ export default class BreathPoint {
         E(this, "_isInScene");
         const {mesh: xStaticMesh, id: id, position: position, rotation: rotation, mat: material, type: type="default", maxVisibleRegion: maxVisibleRegion=-1, scene: scene, skinInfo: skinInfo="default"} = panoInfo;
         this._id = id;
-        xStaticMesh.mesh.position = ue4Position2Xverse(position);
-        xStaticMesh.mesh.rotation = ue4Rotation2Xverse(rotation);
+        xStaticMesh.mesh.position = util.ue4Position2Xverse(position);
+        xStaticMesh.mesh.rotation = util.ue4Rotation2Xverse(rotation);
         this._staticmesh = xStaticMesh;
         this._mat = material;
         this._type = type;
@@ -60,15 +61,15 @@ export default class BreathPoint {
         }
     }
     set position(e) {
-        this._staticmesh.mesh.position = ue4Position2Xverse(e)
+        this._staticmesh.mesh.position = util.ue4Position2Xverse(e)
     }
     get position() {
-        return xversePosition2Ue4(this._staticmesh.mesh.position)
+        return util.xversePosition2Ue4(this._staticmesh.mesh.position)
     }
     set rotation(e) {
         this._staticmesh.mesh.rotation = ue4Rotation2Xverse(e)
     }
     get rotation() {
-        return xverseRotation2Ue4(this._staticmesh.mesh.rotation)
+        return util.xverseRotation2Ue4(this._staticmesh.mesh.rotation)
     }
 }

+ 26 - 20
src/EngineProxy.js

@@ -101,27 +101,33 @@ export default class EngineProxy{
                     if (this._checkSceneDurationFrameNum > 0)
                     {
                         this._checkSceneFrameCount++,
-                        this.room.sceneManager.isReadyToRender({}) && this._checkSceneDurationFrameNum--,
-                        this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && (this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION,
-                        this._checkSceneFrameCount = 0,
-                        this._checkSceneNotReadyCount++,
-                        (this._checkSceneNotReadyCount == 1 || this._checkSceneNotReadyCount % 100 == 0) && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`),
-                        this._checkSceneNotReadyCount > 10 && (logger.error("[SDK] Scene not ready, reload later"),
-                        this.room.proxyEvents("renderError", {
-                            error: new Error("[SDK] Scene not ready, skip render and reload.")
-                        })),
-                        this.room.stats.assign({
-                            renderErrorCount: this._checkSceneNotReadyCount
-                        }),
-                        logger.infoAndReportMeasurement({
-                            value: 0,
-                            startTime: Date.now(),
-                            metric: "renderError",
-                            error: new Error("[SDK] Scene not ready, skip render and reload."),
-                            reportOptions: {
-                                sampleRate: .1
+                        this.room.sceneManager.isReadyToRender({}) && this._checkSceneDurationFrameNum--;
+                        if(this._checkSceneFrameCount > EngineProxy._CHECK_DURATION){
+                            this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION;
+                            this._checkSceneFrameCount = 0;
+                            this._checkSceneNotReadyCount++;
+                            (this._checkSceneNotReadyCount == 1 || this._checkSceneNotReadyCount % 100 == 0) && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`);
+                            if(this._checkSceneNotReadyCount > 10){
+                                logger.error("[SDK] Scene not ready, reload later");
+                                this.room.proxyEvents("renderError", {
+                                    error: new Error("[SDK] Scene not ready, skip render and reload.")
+                                })
                             }
-                        }));
+                            
+                            this.room.stats.assign({
+                                renderErrorCount: this._checkSceneNotReadyCount
+                            });
+
+                            logger.infoAndReportMeasurement({
+                                value: 0,
+                                startTime: Date.now(),
+                                metric: "renderError",
+                                error: new Error("[SDK] Scene not ready, skip render and reload."),
+                                reportOptions: {
+                                    sampleRate: .1
+                                }
+                            })
+                        }
                     }
                     else
                     {

+ 2 - 1
src/StaticMeshEvent.js

@@ -1,5 +1,6 @@
 
 import EMeshType from "./enum/EMeshType.js"
+import util from "./util.js"
 
 const LongPressMesh = [EMeshType.XAvatar];
 export default class StaticMeshEvent extends EventEmitter {
@@ -72,7 +73,7 @@ export default class StaticMeshEvent extends EventEmitter {
             const a = (n = r == null ? void 0 : r.pickedPoint) == null ? void 0 : n.asArray();
             if (a) {
                 const [s,l,u] = a
-                  , c = xversePosition2Ue4({
+                  , c = util.xversePosition2Ue4({
                     x: s,
                     y: l,
                     z: u

+ 5 - 5
src/XAvatar.js

@@ -6,7 +6,7 @@ import XAnimationController from "./XAnimationController.js"
 import XAvatarComopnent from "./XAvatarComopnent.js"
 import XStateMachine from "./XStateMachine.js"
 import XAvatarBillboardComponent from "./XAvatarBillboardComponent.js"
-
+import util from "./util.js"
 const castRayOffsetY = .01;
 const castRayTeleportationOffset = 10;
 
@@ -218,7 +218,7 @@ export default class XAvatar {
     setPosition(e, t=!1) {
         if (this._avatarPosition = e,
         this.rootNode) {
-            const r = ue4Position2Xverse(this._avatarPosition);
+            const r = util.ue4Position2Xverse(this._avatarPosition);
             let n = !1;
             this.avatarManager.getMainAvatar() && (this.id != this.avatarManager.getMainAvatar().id || (Math.abs(r.y - this._previousReceivedPosition.y) > castRayOffsetY && (n = !0),
             r.subtract(this._previousReceivedPosition).length() > castRayTeleportationOffset && (n = !0))),
@@ -243,7 +243,7 @@ export default class XAvatar {
                 yaw: e.yaw + 180,
                 roll: e.roll
             }
-              , r = ue4Rotation2Xverse(t);
+              , r = util.ue4Rotation2Xverse(t);
             this.rootNode.rotation = r
         }
     }
@@ -279,7 +279,7 @@ export default class XAvatar {
     _castRay(e) {
         return new Promise((t,r)=>{
             var d;
-            const n = ue4Position2Xverse(e)
+            const n = util.ue4Position2Xverse(e)
               , o = new BABYLON.Vector3(0,-1,0)
               , a = 1.5 * this.scale
               , s = 100 * a
@@ -399,7 +399,7 @@ export default class XAvatar {
             const r = this.skeleton.bones.find(n=>n.name.replace("Clone of ", "") == e);
             if (r && r.getTransformNode() && ((t = r.getTransformNode()) == null ? void 0 : t.position)) {
                 const n = r.getTransformNode().position;
-                return xversePosition2Ue4({
+                return util.xversePosition2Ue4({
                     x: n.x,
                     y: n.y,
                     z: n.z

+ 42 - 20
src/XAvatarBillboardComponent.js

@@ -1,6 +1,7 @@
 import EMeshType from "./enum/EMeshType.js"
 import BillboardStatus from "./enum/BillboardStatus.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('XAvatarBillboardComponent')
 
@@ -29,34 +30,55 @@ export default class XAvatarBillboardComponent {
             z: 0
         },o=!1,a,s)=>{
             const l = e.rootNode;
-            if (this.bbox || e.getBbox(),
-            t && l) {
+            this.bbox || e.getBbox();
+            if (t && l) {
                 const u = a || t.uniqueId;
                 let c = this._attachmentObservers.get(u);
                 if (c)
+                {
                     if (o)
-                        this._scene.onBeforeRenderObservable.remove(c),
+                    {
+                        this._scene.onBeforeRenderObservable.remove(c);
                         this._attachmentObservers.delete(u);
+                    }
                     else
+                    {
                         return;
-                const h = ue4Position2Xverse(n);
-                r ? (t.setParent(l),
-                t.position = h) : (c = this._scene.onBeforeRenderObservable.add(()=>{
-                    let f = 0;
-                    s ? (f = e.rootNode.rotation.y / Math.PI * 180 + 90,
-                    e.rootNode.rotation.y && (t.rotation.y = e.rootNode.rotation.y)) : f = e.avatarManager.sceneManager.cameraComponent.getCameraPose().rotation.yaw,
-                    f || (f = 0);
-                    const d = new BABYLON.Vector3(0,this._height,0);
-                    e.controller && e.controller.activeAnimation() && e.controller.activeAnimation().animatables[0] && (this._height = d.y = (e.controller.activeAnimation().animatables[0].target.position.y * .01 - .66) * e.scale),
-                    d.y < .07 * e.scale && (d.y = 0),
-                    t.position.x = l.position.x + h.x * Math.sin(f * Math.PI / 180) + h.z * Math.cos(f * Math.PI / 180),
-                    t.position.z = l.position.z + h.x * Math.cos(f * Math.PI / 180) - h.z * Math.sin(f * Math.PI / 180),
-                    t.position.y = l.position.y + this.bbox.maximum.y + h.y + d.y
+                    }
                 }
-                ),
-                this._attachmentObservers.set(u, c))
-            } else
+                const h = util.ue4Position2Xverse(n);
+                if(r){
+                    t.setParent(l);
+                    t.position = h
+                }
+                else{
+                    c = this._scene.onBeforeRenderObservable.add(()=>{
+                        let f = 0;
+                        if(s){
+                            f = e.rootNode.rotation.y / Math.PI * 180 + 90,
+                            e.rootNode.rotation.y && (t.rotation.y = e.rootNode.rotation.y)
+                        }
+                        else{
+                            f = e.avatarManager.sceneManager.cameraComponent.getCameraPose().rotation.yaw;
+                            f || (f = 0);
+                        }
+                        const d = new BABYLON.Vector3(0,this._height,0);
+                        if(e.controller && e.controller.activeAnimation() && e.controller.activeAnimation().animatables[0]){
+                            this._height = d.y = (e.controller.activeAnimation().animatables[0].target.position.y * .01 - .66) * e.scale
+                        }
+                        d.y < .07 * e.scale && (d.y = 0);
+                        t.position.x = l.position.x + h.x * Math.sin(f * Math.PI / 180) + h.z * Math.cos(f * Math.PI / 180);
+                        t.position.z = l.position.z + h.x * Math.cos(f * Math.PI / 180) - h.z * Math.sin(f * Math.PI / 180);
+                        t.position.y = l.position.y + this.bbox.maximum.y + h.y + d.y;
+                    });
+
+                    this._attachmentObservers.set(u, c)
+                }
+            } 
+            else
+            {
                 logger.error("avatar or attachment not found!")
+            }
         }
         );
         E(this, "detachFromAvatar", (e,t,r=!1)=>{
@@ -89,7 +111,7 @@ export default class XAvatarBillboardComponent {
                 let u = new BABYLON.Vector3(0,0,0)
                   , c = new BABYLON.Vector3(0,0,0);
                 if (r) {
-                    const f = ue4Position2Xverse(o);
+                    const f = util.ue4Position2Xverse(o);
                     u = u.add(f.add(new BABYLON.Vector3(-a / 2,-s / 2,-l / 2))),
                     c = c.add(f.add(new BABYLON.Vector3(a / 2,s / 2,l / 2)))
                 } else if (u = u.add(new BABYLON.Vector3(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)),

+ 2 - 1
src/XBillboard.js

@@ -1,6 +1,7 @@
 import EMeshType from "./enum/EMeshType.js"
 import XBillboardManager from "./XBillboardManager.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('Billboard')
 export default class XBillboard {
@@ -121,7 +122,7 @@ export default class XBillboard {
     }
     setPosition(e) {
         if (e && this._mesh) {
-            const t = ue4Position2Xverse(e);
+            const t = util.ue4Position2Xverse(e);
             this._mesh.position = t
         }
     }

+ 3 - 1
src/XBreathPointManager.js

@@ -2,8 +2,10 @@ import XStaticMesh from "./XStaticMesh.js"
 import EMeshType from "./enum/EMeshType.js"
 import BreathPoint from "./BreathPoint.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('XBreathPointManager')
+const scaleFromUE4toXverse = 100
 export default class XBreathPointManager {
     constructor(e) {
         E(this, "_scene");
@@ -190,7 +192,7 @@ export default class XBreathPointManager {
     }
     castRay(e) {
         var s;
-        e = ue4Position2Xverse({
+        e = util.ue4Position2Xverse({
             x: e.x,
             y: e.y,
             z: e.z

+ 15 - 13
src/XCameraComponent.js

@@ -1,3 +1,5 @@
+import util from "./util.js"
+
 export default class XCameraComponent {
     constructor(e, t, r) {
         E(this, "maincameraRotLimitObserver", null);
@@ -60,9 +62,9 @@ export default class XCameraComponent {
         );
         E(this, "setCameraPose", e=>{
             var n;
-            const t = ue4Position2Xverse(e.position);
+            const t = util.ue4Position2Xverse(e.position);
             let r = null;
-            e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)),
+            e.rotation != null && (r = util.ue4Rotation2Xverse(e.rotation)),
             this._cameraPose = {
                 position: t
             },
@@ -183,11 +185,11 @@ export default class XCameraComponent {
           , h = [n - s, n + s]
           , f = [a - u, a + u];
         this.maincameraRotLimitObserver = r.onAfterCheckInputsObservable.add(()=>{
-            let {pitch: d, yaw: _, roll: g} = xverseRotation2Ue4(r.rotation);
+            let {pitch: d, yaw: _, roll: g} = util.xverseRotation2Ue4(r.rotation);
             d = this._limitAngle(d, c),
             _ = this._limitAngle(_, h),
             g = this._limitAngle(g, f),
-            r.rotation = ue4Rotation2Xverse({
+            r.rotation = util.ue4Rotation2Xverse({
                 pitch: d,
                 yaw: _,
                 roll: g
@@ -198,8 +200,8 @@ export default class XCameraComponent {
     setMainCameraRotationLimitByAnchor(e, t, r) {
         this.maincameraRotLimitObserver != null && this.removeMainCameraRotationLimit();
         const n = this.mainCamera
-          , o = ue4Rotation2Xverse_mesh(t)
-          , a = ue4Rotation2Xverse_mesh(r);
+          , o = util.ue4Rotation2Xverse_mesh(t)
+          , a = util.ue4Rotation2Xverse_mesh(r);
         a != null && o != null && e.mesh != null && (this.maincameraRotLimitObserver = n.onAfterCheckInputsObservable.add(()=>{
             const s = e.mesh.rotation;
             r.yaw > 0 && (n.rotation.y <= s.y - a.y + o.y ? n.rotation.y = s.y - a.y + o.y : n.rotation.y >= s.y + a.y + o.y && (n.rotation.y = s.y + a.y + o.y)),
@@ -209,12 +211,12 @@ export default class XCameraComponent {
         ))
     }
     getCameraPose() {
-        const e = xversePosition2Ue4({
+        const e = util.xversePosition2Ue4({
             x: this.mainCamera.position.x,
             y: this.mainCamera.position.y,
             z: this.mainCamera.position.z
         })
-          , t = xverseRotation2Ue4({
+          , t = util.xverseRotation2Ue4({
             x: this.mainCamera.rotation.x,
             y: this.mainCamera.rotation.y,
             z: this.mainCamera.rotation.z
@@ -238,7 +240,7 @@ export default class XCameraComponent {
     }
     addRot(e) {
         const t = this.mainCamera
-          , r = ue4Rotation2Xverse_mesh(e);
+          , r = util.ue4Rotation2Xverse_mesh(e);
         r != null && t.rotation.addInPlace(r)
     }
     getCameraFov() {
@@ -251,8 +253,8 @@ export default class XCameraComponent {
         this.mainCamera.detachControl(this.canvas)
     }
     forceChangeSavedCameraPose(e) {
-        this.saveCameraPose != null && (e.position != null && (this.saveCameraPose.position = ue4Position2Xverse(e.position)),
-        e.rotation != null && (this.saveCameraPose.rotation = ue4Rotation2Xverse(e.rotation)))
+        this.saveCameraPose != null && (e.position != null && (this.saveCameraPose.position = util.ue4Position2Xverse(e.position)),
+        e.rotation != null && (this.saveCameraPose.rotation = util.ue4Rotation2Xverse(e.rotation)))
     }
     changeToFirstPersonView(e) {
         this.saveCameraPose = {
@@ -260,8 +262,8 @@ export default class XCameraComponent {
             rotation: this.mainCamera.rotation.clone()
         },
         this.mainCamera.attachControl(this.canvas, !0),
-        e.position != null && (this.mainCamera.position = ue4Position2Xverse(e.position)),
-        e.rotation != null && (this.mainCamera.rotation = ue4Rotation2Xverse(e.rotation))
+        e.position != null && (this.mainCamera.position = util.ue4Position2Xverse(e.position)),
+        e.rotation != null && (this.mainCamera.rotation = util.ue4Rotation2Xverse(e.rotation))
     }
     changeToThirdPersonView() {
         this.saveCameraPose != null && this.mainCamera != null && (this.mainCamera.position = this.saveCameraPose.position.clone(),

+ 2 - 1
src/XMaterialComponent.js

@@ -1,5 +1,6 @@
 import XVideoRawYUV from "./XVideoRawYUV"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const planeWidth  = 1728
 const planeHeight = 1080
@@ -354,7 +355,7 @@ export default class XMaterialComponent {
         !this._isInDynamicRange(e))
             return logger.error(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`),
             Promise.reject(new XMaterialError(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`));
-        const r = ue4Position2Xverse(t.pose.position);
+        const r = util.ue4Position2Xverse(t.pose.position);
         return r && (this._dynamic_babylonpose[e] = {
             position: r
         }),

+ 14 - 13
src/XStateMachine.js

@@ -1,4 +1,5 @@
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('XStateMachine')
 export default class XStateMachine {
@@ -30,8 +31,8 @@ export default class XStateMachine {
                     if (!e.rootNode)
                         return e.setRotation(t),
                         o();
-                    const d = BABYLON.Vector3.Lerp(e.rootNode.rotation, ue4Rotation2Xverse(t), l);
-                    e.setRotation(xverseRotation2Ue4(d)),
+                    const d = BABYLON.Vector3.Lerp(e.rootNode.rotation, util.ue4Rotation2Xverse(t), l);
+                    e.setRotation(util.xverseRotation2Ue4(d)),
                     l += u / (c * 1e3)
                 } else
                     return s.onBeforeRenderObservable.remove(this._movingObserver),
@@ -65,8 +66,8 @@ export default class XStateMachine {
                 return l("[Engine input path error]");
             let d = calcDistance3D(h, f) / n;
             const _ = 1e3 / 25;
-            e.rootNode.lookAt(ue4Position2Xverse(f));
-            const g = xverseRotation2Ue4({
+            e.rootNode.lookAt(util.ue4Position2Xverse(f));
+            const g = util.xverseRotation2Ue4({
                 x: e.rootNode.rotation.x,
                 y: e.rootNode.rotation.y,
                 z: e.rootNode.rotation.z
@@ -79,8 +80,8 @@ export default class XStateMachine {
             this._movingObserver = u == null ? void 0 : u.onBeforeRenderObservable.add(()=>{
                 var v;
                 if (c < 1) {
-                    const y = BABYLON.Vector3.Lerp(ue4Position2Xverse(h), ue4Position2Xverse(f), c);
-                    if (e.setPosition(xversePosition2Ue4(y)),
+                    const y = BABYLON.Vector3.Lerp(util.ue4Position2Xverse(h), util.ue4Position2Xverse(f), c);
+                    if (e.setPosition(util.xversePosition2Ue4(y)),
                     !e.rootNode)
                         return e.setPosition(r),
                         s();
@@ -89,8 +90,8 @@ export default class XStateMachine {
                 f = a.shift(),
                 f) {
                     d = calcDistance3D(h, f) / n,
-                    e.rootNode.lookAt(ue4Position2Xverse(f));
-                    const y = xverseRotation2Ue4({
+                    e.rootNode.lookAt(util.ue4Position2Xverse(f));
+                    const y = util.xverseRotation2Ue4({
                         x: e.rootNode.rotation.x,
                         y: e.rootNode.rotation.y,
                         z: e.rootNode.rotation.z
@@ -111,7 +112,7 @@ export default class XStateMachine {
     lookAt(e, t, r) {
         return new Promise(n=>{
             var _, g;
-            const o = ue4Position2Xverse(t)
+            const o = util.ue4Position2Xverse(t)
               , s = e.rootNode.position.subtract(o).length()
               , l = new BABYLON.Vector3(s * Math.sin(e.rootNode.rotation.y),0,s * Math.cos(e.rootNode.rotation.y))
               , u = (_ = e.rootNode) == null ? void 0 : _.position.add(l);
@@ -148,15 +149,15 @@ export default class XStateMachine {
                   , _ = o / 100
                   , g = 8 * _ * f * f;
                 let m = .5 * g / f
-                  , v = ue4Position2Xverse(e.position);
-                const y = ue4Position2Xverse(a)
-                  , b = ue4Position2Xverse(e.position)
+                  , v = util.ue4Position2Xverse(e.position);
+                const y = util.ue4Position2Xverse(a)
+                  , b = util.ue4Position2Xverse(e.position)
                   , T = c == null ? void 0 : c.onBeforeRenderObservable.add(()=>{
                     (!t || !e.position || !t.position) && (T && c.onBeforeRenderObservable.remove(T),
                     l("Invalid receiver when shoot gift!")),
                     r.loaded || (T && c.onBeforeRenderObservable.remove(T),
                     s());
-                    const C = ue4Position2Xverse(t.position)
+                    const C = util.ue4Position2Xverse(t.position)
                       , A = new BABYLON.Vector3((C.x - b.x) * f,m,(C.z - b.z) * f);
                     m = m - g,
                     h < 1 ? (v = v.add(A),

+ 6 - 5
src/XStaticMesh.js

@@ -1,5 +1,6 @@
 import EMeshType from "./enum/EMeshType.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('XStaticMesh')
 export default class XStaticMesh {
@@ -64,9 +65,9 @@ export default class XStaticMesh {
             y: .35,
             z: .35
         })=>{
-            const o = ue4Scaling2Xverse(n)
-              , a = ue4Rotation2Xverse(r)
-              , s = ue4Position2Xverse(t)
+            const o = util.ue4Scaling2Xverse(n)
+              , a = util.ue4Rotation2Xverse(r)
+              , s = util.ue4Position2Xverse(t)
               , l = this._mesh;
             e && l ? (e.setParent(l),
             e.position = s,
@@ -142,13 +143,13 @@ export default class XStaticMesh {
     }
     setPosition(e) {
         if (this._mesh) {
-            const t = ue4Position2Xverse(e);
+            const t = util.ue4Position2Xverse(e);
             this._mesh.position = t
         } else
             logger.error("[Engine] no root for positioning")
     }
     setRotation(e) {
-        const t = ue4Rotation2Xverse_mesh(e);
+        const t = util.ue4Rotation2Xverse_mesh(e);
         this._mesh ? this._mesh.rotation = t : logger.error("[Engine] no root for rotating")
     }
     setScale(e) {

+ 2 - 1
src/XStaticMeshComponent.js

@@ -3,6 +3,7 @@ import EMeshType from "./enum/EMeshType.js"
 import XStaticMeshFromOneGltf from "./XStaticMeshFromOneGltf.js"
 import XLowpolyModelError from "./error/XLowpolyModelError.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('XStaticMeshComponent')
 export default class XStaticMeshComponent{
@@ -154,7 +155,7 @@ export default class XStaticMeshComponent{
         }
         );
         E(this, "checkPointInView", ({x: e, y: t, z: r})=>{
-            const n = ue4Position2Xverse({
+            const n = util.ue4Position2Xverse({
                 x: e,
                 y: t,
                 z: r

+ 7 - 6
src/XSubSequence.js

@@ -1,5 +1,6 @@
 import {http2} from "./Http2.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('subSequence')
 
@@ -349,10 +350,10 @@ export default class XSubSequence {
         return this._abosoluteUrl
     }
     get position() {
-        return xversePosition2Ue4(this.pos)
+        return util.xversePosition2Ue4(this.pos)
     }
     get rotation() {
-        return xverseRotation2Ue4(this.rot)
+        return util.xverseRotation2Ue4(this.rot)
     }
     get scaling() {
         return this.scal
@@ -421,10 +422,10 @@ export default class XSubSequence {
         )
     }
     lookAt(e) {
-        ue4Position2Xverse(e) && this.root.lookAt(ue4Position2Xverse(e))
+        util.ue4Position2Xverse(e) && this.root.lookAt(util.ue4Position2Xverse(e))
     }
     setPosition(e) {
-        this.setPositionVector(ue4Position2Xverse(e))
+        this.setPositionVector(util.ue4Position2Xverse(e))
     }
     setPositionVector(e) {
         this._centerNode.position = e,
@@ -441,7 +442,7 @@ export default class XSubSequence {
         )
     }
     setScaling(e) {
-        this.setScalingVector(ue4Scaling2Xverse(e))
+        this.setScalingVector(util.ue4Scaling2Xverse(e))
     }
     setScalingVector(e) {
         var t;
@@ -462,7 +463,7 @@ export default class XSubSequence {
         )
     }
     setRotation(e) {
-        this.setRotationVector(ue4Rotation2Xverse(e))
+        this.setRotationVector(util.ue4Rotation2Xverse(e))
     }
     setRotationVector(e) {
         this._centerNode.rotation = e

+ 1 - 1
src/XverseAvatar.js

@@ -335,7 +335,7 @@ export default class XverseAvatar extends EventEmitter {
     async beforeChangeComponentsHook(e) {}
     turnTo(e) {
         if (this._room.viewMode === "observer") {
-            this._room.sceneManager.cameraComponent.MainCamera.setTarget(ue4Position2Xverse(e.point));
+            this._room.sceneManager.cameraComponent.MainCamera.setTarget(util.ue4Position2Xverse(e.point));
             return
         }
         return this._room.actionsHandler.turnTo(e).then(()=>{

+ 1 - 1
src/main.js

@@ -1,6 +1,6 @@
 import Xverse from "./Xverse.js";
 import Codes from "./enum/Codes.js";
-import './video/index.js'
+// import './video/index.js'
 
 const xverse = new Xverse({
   env: "DEV",

+ 104 - 0
src/util.js

@@ -102,5 +102,109 @@ var util = {
           , {x: o, y: a, z: s} = e;
         return Math.sqrt(Math.abs(t - o) ** 2 + Math.abs(r - a) ** 2 + Math.abs(n - s) ** 2)
     }
+    , 
+    ue4Rotation2Xverse(i){
+        if(this.isRotationCorrect(i)){
+            if(i.pitch >= 89.5){
+                i.pitch = 89.5
+            }
+            else if(i.pitch <= -89.5){
+                i.pitch = -89.5
+            }
+
+            if(Math.PI * i.roll / 180 < .001){
+                return new BABYLON.Vector3(-1 * Math.PI * i.pitch / 180,Math.PI * i.yaw / 180 - Math.PI * 27 / 18, 0 )
+            }
+            else{
+                return new BABYLON.Vector3(-1 * Math.PI * i.pitch / 180,Math.PI * i.yaw / 180 - Math.PI * 27 / 18, Math.PI * i.roll / 180 )
+            }
+        }
+        else{
+            return null
+        }
+    },
+    ue4Rotation2Xverse_mesh(i){
+        if(this.isRotationCorrect(i)){
+            if(Math.abs(Math.PI * i.roll) / 180 < .001){
+                return new BABYLON.Vector3(Math.PI * i.pitch / 180,Math.PI * i.yaw / 180,0)
+      
+            }
+            else{
+                return new BABYLON.Vector3(Math.PI * i.pitch / 180,Math.PI * i.yaw / 180, -1 * (Math.PI * i.roll) / 180)
+            }
+            
+        }
+        else{
+            return null;
+        }
+    },
+    ue4Scaling2Xverse(i){
+        if(this.isScalingCorrect(i)){
+            return new BABYLON.Vector3(i.x,i.z,-1 * i.y)
+        }
+        else{
+            return null;
+        }
+    },
+    ue4Position2Xverse(i){
+        if(this.isPositionCorrect(i)){
+            return new BABYLON.Vector3(i.x * .01,i.z * .01,-1 * i.y * .01)
+        }
+        else{
+            return null;
+        }
+    },
+    xversePosition2Ue4(i){
+        if(this.isPositionCorrect(i)){
+            return {
+                x: i.x * 100,
+                y: -1 * i.z * 100,
+                z: i.y * 100
+            }
+        }
+        else{
+            return null;
+        }
+    },
+    xverseRotation2Ue4(i){
+        if (this.isPositionCorrect(i)) {
+            let e = 0;
+            i.z == 0 ? e = 0 : e = 180 * i.z / Math.PI;
+            return {
+                pitch: 180 * i.x * -1 / Math.PI,
+                yaw: (i.y + Math.PI * 27 / 18) * 180 / Math.PI,
+                roll: e
+            }
+        } 
+        else
+        {
+            return null
+        }
+    },
+    //isRotationCorrect = i=>!0
+    isRotationCorrect(i){
+        if(i){
+            return true
+        }
+        else{
+            return false
+        }
+    },
+    isPositionCorrect(i){
+        if(i){
+            return true
+        }
+        else{
+            return false
+        }
+    },
+    isScalingCorrect(i){
+        if(i){
+            return true
+        }
+        else{
+            return false
+        }
+    }
 }
 export default util

+ 2 - 1
src/video/index.js

@@ -121,6 +121,7 @@ tinyH264Worker.addEventListener("message", (e) => {
         fetches.push(
           fetch(`https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/earth/${i}`).then((response) => {
             return response.arrayBuffer().then(function (buffer) {
+              //h264
               cacheBuffer[i] = new Uint8Array(buffer);
             });
           })
@@ -199,7 +200,7 @@ function onPicture(buffer, width, height) {
   // debugger
     // data = window.changeTexture(data);
     // window.updateTexture( data );
-  // yuvSurfaceShader.draw();
+   //yuvSurfaceShader.draw();
 }
 
 // steam1.readAll(null, function (buffer) {