zhouenguang пре 3 година
родитељ
комит
d68693505c
100 измењених фајлова са 60 додато и 160 уклоњено
  1. 18 3
      modules/CharactorManager.js
  2. 34 16
      modules/index.js
  3. 7 0
      modules/utils/common.js
  4. 0 5
      modules/utils/data.js
  5. 1 1
      modules/utils/settings.js
  6. BIN
      scenes/house/close_to_bottom_L.glb
  7. BIN
      scenes/house/room02.glb
  8. 0 0
      scenes/house/test.glb
  9. BIN
      textures/123.mp4
  10. BIN
      textures/op/0/0.mp4
  11. BIN
      textures/op/0/0_1_0.mp4
  12. BIN
      textures/op/0/0_1_1.mp4
  13. BIN
      textures/op/0/0_1_2.mp4
  14. BIN
      textures/op/0/0_1_3.mp4
  15. BIN
      textures/op/0/0_1_4.mp4
  16. BIN
      textures/op/0/0_1_5.mp4
  17. BIN
      textures/op/0/0_1_6.mp4
  18. BIN
      textures/op/0/0_1_7.mp4
  19. BIN
      textures/op/1/1.mp4
  20. BIN
      textures/op/1/1_0_0.mp4
  21. BIN
      textures/op/1/1_0_1.mp4
  22. BIN
      textures/op/1/1_0_2.mp4
  23. BIN
      textures/op/1/1_0_3.mp4
  24. BIN
      textures/op/1/1_0_4.mp4
  25. BIN
      textures/op/1/1_0_5.mp4
  26. BIN
      textures/op/1/1_0_6.mp4
  27. BIN
      textures/op/1/1_0_7.mp4
  28. 0 135
      textures/op/points.json
  29. BIN
      textures/outputmp4/0/0.mp4
  30. BIN
      textures/outputmp4/0/0_1_0.mp4
  31. BIN
      textures/outputmp4/0/0_1_1.mp4
  32. BIN
      textures/outputmp4/0/0_1_2.mp4
  33. BIN
      textures/outputmp4/0/0_1_3.mp4
  34. BIN
      textures/outputmp4/0/0_1_4.mp4
  35. BIN
      textures/outputmp4/0/0_1_5.mp4
  36. BIN
      textures/outputmp4/0/0_1_6.mp4
  37. BIN
      textures/outputmp4/0/0_1_7.mp4
  38. BIN
      textures/outputmp4/0/0_3_0.mp4
  39. BIN
      textures/outputmp4/0/0_3_1.mp4
  40. BIN
      textures/outputmp4/0/0_3_2.mp4
  41. BIN
      textures/outputmp4/0/0_3_3.mp4
  42. BIN
      textures/outputmp4/0/0_3_4.mp4
  43. BIN
      textures/outputmp4/0/0_3_5.mp4
  44. BIN
      textures/outputmp4/0/0_3_6.mp4
  45. BIN
      textures/outputmp4/0/0_3_7.mp4
  46. BIN
      textures/outputmp4/0/0_4_0.mp4
  47. BIN
      textures/outputmp4/0/0_4_1.mp4
  48. BIN
      textures/outputmp4/0/0_4_2.mp4
  49. BIN
      textures/outputmp4/0/0_4_3.mp4
  50. BIN
      textures/outputmp4/0/0_4_4.mp4
  51. BIN
      textures/outputmp4/0/0_4_5.mp4
  52. BIN
      textures/outputmp4/0/0_4_6.mp4
  53. BIN
      textures/outputmp4/0/0_4_7.mp4
  54. BIN
      textures/outputmp4/1/1.mp4
  55. BIN
      textures/outputmp4/1/1_0_0.mp4
  56. BIN
      textures/outputmp4/1/1_0_1.mp4
  57. BIN
      textures/outputmp4/1/1_0_2.mp4
  58. BIN
      textures/outputmp4/1/1_0_3.mp4
  59. BIN
      textures/outputmp4/1/1_0_4.mp4
  60. BIN
      textures/outputmp4/1/1_0_5.mp4
  61. BIN
      textures/outputmp4/1/1_0_6.mp4
  62. BIN
      textures/outputmp4/1/1_0_7.mp4
  63. BIN
      textures/outputmp4/1/1_2_0.mp4
  64. BIN
      textures/outputmp4/1/1_2_1.mp4
  65. BIN
      textures/outputmp4/1/1_2_2.mp4
  66. BIN
      textures/outputmp4/1/1_2_3.mp4
  67. BIN
      textures/outputmp4/1/1_2_4.mp4
  68. BIN
      textures/outputmp4/1/1_2_5.mp4
  69. BIN
      textures/outputmp4/1/1_2_6.mp4
  70. BIN
      textures/outputmp4/1/1_2_7.mp4
  71. BIN
      textures/outputmp4/1/1_3_0.mp4
  72. BIN
      textures/outputmp4/1/1_3_1.mp4
  73. BIN
      textures/outputmp4/1/1_3_2.mp4
  74. BIN
      textures/outputmp4/1/1_3_3.mp4
  75. BIN
      textures/outputmp4/1/1_3_4.mp4
  76. BIN
      textures/outputmp4/1/1_3_5.mp4
  77. BIN
      textures/outputmp4/1/1_3_6.mp4
  78. BIN
      textures/outputmp4/1/1_3_7.mp4
  79. BIN
      textures/outputmp4/1/1_4_0.mp4
  80. BIN
      textures/outputmp4/1/1_4_1.mp4
  81. BIN
      textures/outputmp4/1/1_4_2.mp4
  82. BIN
      textures/outputmp4/1/1_4_3.mp4
  83. BIN
      textures/outputmp4/1/1_4_4.mp4
  84. BIN
      textures/outputmp4/1/1_4_5.mp4
  85. BIN
      textures/outputmp4/1/1_4_6.mp4
  86. BIN
      textures/outputmp4/1/1_4_7.mp4
  87. BIN
      textures/outputmp4/1/1_5_0.mp4
  88. BIN
      textures/outputmp4/1/1_5_1.mp4
  89. BIN
      textures/outputmp4/1/1_5_2.mp4
  90. BIN
      textures/outputmp4/1/1_5_3.mp4
  91. BIN
      textures/outputmp4/1/1_5_4.mp4
  92. BIN
      textures/outputmp4/1/1_5_5.mp4
  93. BIN
      textures/outputmp4/1/1_5_6.mp4
  94. BIN
      textures/outputmp4/1/1_5_7.mp4
  95. BIN
      textures/outputmp4/2/2.mp4
  96. BIN
      textures/outputmp4/2/2_1_0.mp4
  97. BIN
      textures/outputmp4/2/2_1_1.mp4
  98. BIN
      textures/outputmp4/2/2_1_2.mp4
  99. BIN
      textures/outputmp4/2/2_1_3.mp4
  100. 0 0
      textures/outputmp4/2/2_1_4.mp4

+ 18 - 3
modules/CharactorManager.js

@@ -11,7 +11,11 @@ export default class CharactorManager {
 
         this.frameRate = settings.video.frameRate;
 
-        fetch("../textures/outputmp4/points.json", {
+    }
+
+    readPointData() {
+        
+        return fetch("../textures/outputmp4/points.json", {
             headers: {
                 'content-type': 'application/json'
             },
@@ -20,6 +24,17 @@ export default class CharactorManager {
         .then(response => response.json())
         .then(response => {
             this.pointsData = response
+            this.pointsData.forEach(data => {
+                data.position = BABYLON.Vector3.TransformCoordinates(
+                    new BABYLON.Vector3(data.position.x, data.position.y, data.position.z),
+                    BABYLON.Matrix.FromArray([
+                        -0.01,   0,      0,      0,
+                        0,      0,      0.01,  0,
+                        0,      0.01,   0,      0,
+                        0,      0,      0,      1
+                    ])
+                )
+            })
         })
     }
 
@@ -37,7 +52,7 @@ export default class CharactorManager {
             self.charactor.mesh.position = new BABYLON.Vector3(
                 self.pointsData[0].position.x, 
                 0,
-                self.pointsData[0].position.y
+                self.pointsData[0].position.z
             )
         });
 
@@ -99,7 +114,7 @@ export default class CharactorManager {
 
         path = path.map((data) => { 
             return { 
-                point: new BABYLON.Vector3(data.point.x, 0, data.point.y), 
+                point: new BABYLON.Vector3(data.point.x, 0, data.point.z), 
                 video: data.video && common.createVideoElement0(data.video)
             } 
         })

+ 34 - 16
modules/index.js

@@ -25,6 +25,8 @@ export default class App {
         camera1.angularSensibilityX /= 2;
         this.camera = camera1
         this.lastCameraAlpha = 0
+        this.lastDirc = 0
+        this.initAlpha = 0
         this.cameraControlEnable = true
 
         // 人物相机射线
@@ -57,10 +59,10 @@ export default class App {
     init() {
 
         let self = this
-        BABYLON.SceneLoader.ImportMesh("", "../scenes/house/", "000.glb", this.scene, function (newMeshes, particleSystems, skeletons, animationGroups) {
+        BABYLON.SceneLoader.ImportMesh("", "../scenes/house/", "close_to_bottom_L.glb", this.scene, async function (newMeshes, particleSystems, skeletons, animationGroups) {
             
             self.house = newMeshes
-            self.house[0].position = new BABYLON.Vector3(0.6, 2.1, 1.5)
+            // self.house[0].position = new BABYLON.Vector3(0.6, 2.1, 1.5)
             // self.house[0].position = new BABYLON.Vector3(-22, 0, 12)
 
             let houseVideo = document.getElementById("houseTexture0")
@@ -86,7 +88,7 @@ export default class App {
 
                     shaderMaterial.setTexture("texture_video", videoTexture)
                     shaderMaterial.setVector3("focal_width_height", new BABYLON.Vector3(
-                        864 * window.innerWidth / settings.video.width, 
+                        864 * window.innerWidth / settings.video.width, // 1500
                         settings.video.width * window.innerHeight / settings.video.height, 
                         window.innerHeight
                     ))
@@ -97,6 +99,7 @@ export default class App {
             });
 
             self.charactorManager = new CharactorManager(self)
+            await self.charactorManager.readPointData()
             self.charactorManager.importCharactorModel("../scenes/charactors/", "man_YXL.glb")
         });
     }
@@ -191,28 +194,34 @@ export default class App {
         let currentFramePoint = new BABYLON.Vector2(pointerInfo.event.clientX, pointerInfo.event.clientY)
         let pointerOffset = currentFramePoint.clone().subtract(this.lastFramePoint).length()
         let dirc = Math.sign(this.lastFramePoint.x - currentFramePoint.x)
-        if(!this.lastDirc) this.lastDirc = 0
 
         // 一般来说瞬时距离不会超过100,定100时转180度
         // let alphaOffset = Math.max(Math.floor((pointerOffset / 100 * Math.PI / (Math.PI / 30)) * (Math.PI / 30) + Math.PI / 60), Math.PI / 30)
-        let alphaOffset = Math.max(pointerOffset / 100 * Math.PI, Math.PI / 30)
+        let alphaOffset = pointerOffset / 100 * Math.PI
         alphaOffset *= dirc
 
+        this.initAlpha += alphaOffset
+
         if(charactor.actionType.split("-")[1] == "Walking") {
             // 行走时旋转相机,行走停止
             charactor.startWalk([], this.charactorManager)
         } 
-        else if(dirc != 0 && dirc * this.lastDirc <= 0) {
+        // && dirc * this.lastDirc <= 0
+        else if(Math.abs(this.initAlpha) > Math.PI / 30 && dirc != 0) {
+
+            this.initAlpha = 0
 
             let currentPath = charactor.walkData.pathArr[charactor.walkData.currentPoint]
             let startPoint = (currentPath && currentPath.point) || charactor.mesh.position
 
             let pointData = this.charactorManager.getClosestPointData(startPoint)
             let sendData = {
-                video: [pointData.id],
-                reverse: dirc < 0
+                videoList: [pointData.id + "/" + pointData.id],
+                // reverse: dirc < 0
+                videoId: common.uuid()
             }
-            // window.connection.socket.emit("getPush", sendData)
+            // window.connection.socket.emit("pushVideo", sendData)
+            // console.log("[3D] send: ", sendData)
 
             this.rotateCamera(alphaOffset)
         }
@@ -221,10 +230,9 @@ export default class App {
         this.lastDirc = dirc
     }
 
-    // async 
-    rotateCamera(alphaOffset, func) {
+    async rotateCamera(alphaOffset, func) {
         // todo
-        let video0 = document.getElementById("houseTexture0")
+        let video0 = this.house[1].material._textures.texture_video.video
 
         let startTime = Math.abs(this.camera.alpha) % (Math.PI * 2) / (Math.PI * 2) * video0.duration
         let durtime = Math.abs(alphaOffset / (Math.PI * 2) * video0.duration)
@@ -250,8 +258,7 @@ export default class App {
             rotateAni.setKeys(rotateFrames);
 
             video0.currentTime = startTime
-            // await 
-            video0.play()
+            await video0.play()
 
             this.scene.beginDirectAnimation(this.camera, [rotateAni], 0, rotateCameraFrameNum, false, 1, 
                 () => {
@@ -264,6 +271,7 @@ export default class App {
             // console.error("-------------")
             // video0.pause()
         }
+
     }
 
     lockCamera(isTrue) {
@@ -272,12 +280,22 @@ export default class App {
         this.camera.upperAlphaLimit = isTrue ? this.camera.alpha : null
     }
 
-    updateHouseVideo(video) {
+    updateHouseVideo(video, notPlay) {
+        let videoTexture = new BABYLON.VideoTexture("", video, this.scene)
+        this.house.forEach(mesh => {
+            mesh.material && mesh.material.setTexture("texture_video", videoTexture)
+        })
+        !notPlay && video.play()
+    }
+
+    async updateHouseVideoBlob(blobUrl, notPlay) {
+        let video = await common.createVideoElement(blobUrl)
+        video.loop = "loop"
         let videoTexture = new BABYLON.VideoTexture("", video, this.scene)
         this.house.forEach(mesh => {
             mesh.material && mesh.material.setTexture("texture_video", videoTexture)
         })
-        video.play()
+        !notPlay && video.play()
     }
 
 }

+ 7 - 0
modules/utils/common.js

@@ -1,4 +1,11 @@
 export default {
+
+    uuid: () => {
+        let S4 = () => {
+            return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
+        }
+        return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
+    },
     
     postData: (url, data) => {
         return fetch(url, {

+ 0 - 5
modules/utils/data.js

@@ -2,27 +2,22 @@ export default {
 
     walkPath: [
         {
-            // point: { x: -0.5, y: 0 },
             id: 0,
             video: null
         },
         {
-            // point: { x: -0.5, y: 0.1 },
             id: 1,
             video: "../textures/outputmp4/0/0_1_0.mp4"
         },
         {
-            // point: { x: -0.5, y: 2 },
             id: 2,
             video: "../textures/outputmp4/1/1_2_0.mp4"
         },
         {
-            // point: { x: 1.5, y: 2 },
             id: 5,
             video: "../textures/outputmp4/2/2_5_0.mp4"
         },
         {
-            // point: { x: 3.5, y: 2 },
             id: 8,
             video: "../textures/outputmp4/5/5_8_0.mp4"
         }

+ 1 - 1
modules/utils/settings.js

@@ -8,7 +8,7 @@ export default {
     walkVidoeSpeed: 1,   // m/s
     camera: {
         fov: Math.PI / 2,
-        height: 1.5,
+        height: 1.4738033728196456,
         distanceFromCharactor: 3.5
     }
 }

BIN
scenes/house/close_to_bottom_L.glb


BIN
scenes/house/room02.glb


scenes/house/000.glb → scenes/house/test.glb



BIN
textures/op/0/0.mp4


BIN
textures/op/0/0_1_0.mp4


BIN
textures/op/0/0_1_1.mp4


BIN
textures/op/0/0_1_2.mp4


BIN
textures/op/0/0_1_3.mp4


BIN
textures/op/0/0_1_4.mp4


BIN
textures/op/0/0_1_5.mp4


BIN
textures/op/0/0_1_6.mp4


BIN
textures/op/0/0_1_7.mp4


BIN
textures/op/1/1.mp4


BIN
textures/op/1/1_0_0.mp4


BIN
textures/op/1/1_0_1.mp4


BIN
textures/op/1/1_0_2.mp4


BIN
textures/op/1/1_0_3.mp4


BIN
textures/op/1/1_0_4.mp4


BIN
textures/op/1/1_0_5.mp4


BIN
textures/op/1/1_0_6.mp4


BIN
textures/op/1/1_0_7.mp4


+ 0 - 135
textures/op/points.json

@@ -1,135 +0,0 @@
-[
-    {
-        "id": 0,
-        "position": {
-            "x": -0.5,
-            "y": 0,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [1,3,4]
-    },
-    {
-        "id": 1,
-        "position": {
-            "x": -0.5,
-            "y": 0.1,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [0,2,3,4,5]
-    },
-    {
-        "id": 2,
-        "position": {
-            "x": -0.5,
-            "y": 2,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [1,4,5]
-    },
-    {
-        "id": 3,
-        "position": {
-            "x": 1.5,
-            "y": 0,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [0,1,4,6,7]
-    },
-    {
-        "id": 4,
-        "position": {
-            "x": 1.5,
-            "y": 0.1,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 1.5,
-            "y": 0,
-            "z": 1.5
-        },
-        "contact": [0,1,2,3,4,5,6,7,8]
-    },
-    {
-        "id": 5,
-        "position": {
-            "x": 1.5,
-            "y": 2,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 1.5,
-            "y": 0,
-            "z": 1.5
-        },
-        "contact": [1,2,4,7,8]
-    },
-    {
-        "id": 6,
-        "position": {
-            "x": 3.5,
-            "y": 0,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [3,4,7]
-    },
-    {
-        "id": 7,
-        "position": {
-            "x": 3.5,
-            "y": 0.1,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [3,4,5,6,8]
-    },
-    {
-        "id": 8,
-        "position": {
-            "x": 3.5,
-            "y": 2.0,
-            "z": 1.5
-        },
-        "rotation": {
-            "x": 0,
-            "y": 0,
-            "z": 0,
-            "w": 1
-        },
-        "contact": [4,5,7]
-    }
-]

BIN
textures/outputmp4/0/0.mp4


BIN
textures/outputmp4/0/0_1_0.mp4


BIN
textures/outputmp4/0/0_1_1.mp4


BIN
textures/outputmp4/0/0_1_2.mp4


BIN
textures/outputmp4/0/0_1_3.mp4


BIN
textures/outputmp4/0/0_1_4.mp4


BIN
textures/outputmp4/0/0_1_5.mp4


BIN
textures/outputmp4/0/0_1_6.mp4


BIN
textures/outputmp4/0/0_1_7.mp4


BIN
textures/outputmp4/0/0_3_0.mp4


BIN
textures/outputmp4/0/0_3_1.mp4


BIN
textures/outputmp4/0/0_3_2.mp4


BIN
textures/outputmp4/0/0_3_3.mp4


BIN
textures/outputmp4/0/0_3_4.mp4


BIN
textures/outputmp4/0/0_3_5.mp4


BIN
textures/outputmp4/0/0_3_6.mp4


BIN
textures/outputmp4/0/0_3_7.mp4


BIN
textures/outputmp4/0/0_4_0.mp4


BIN
textures/outputmp4/0/0_4_1.mp4


BIN
textures/outputmp4/0/0_4_2.mp4


BIN
textures/outputmp4/0/0_4_3.mp4


BIN
textures/outputmp4/0/0_4_4.mp4


BIN
textures/outputmp4/0/0_4_5.mp4


BIN
textures/outputmp4/0/0_4_6.mp4


BIN
textures/outputmp4/0/0_4_7.mp4


BIN
textures/outputmp4/1/1.mp4


BIN
textures/outputmp4/1/1_0_0.mp4


BIN
textures/outputmp4/1/1_0_1.mp4


BIN
textures/outputmp4/1/1_0_2.mp4


BIN
textures/outputmp4/1/1_0_3.mp4


BIN
textures/outputmp4/1/1_0_4.mp4


BIN
textures/outputmp4/1/1_0_5.mp4


BIN
textures/outputmp4/1/1_0_6.mp4


BIN
textures/outputmp4/1/1_0_7.mp4


BIN
textures/outputmp4/1/1_2_0.mp4


BIN
textures/outputmp4/1/1_2_1.mp4


BIN
textures/outputmp4/1/1_2_2.mp4


BIN
textures/outputmp4/1/1_2_3.mp4


BIN
textures/outputmp4/1/1_2_4.mp4


BIN
textures/outputmp4/1/1_2_5.mp4


BIN
textures/outputmp4/1/1_2_6.mp4


BIN
textures/outputmp4/1/1_2_7.mp4


BIN
textures/outputmp4/1/1_3_0.mp4


BIN
textures/outputmp4/1/1_3_1.mp4


BIN
textures/outputmp4/1/1_3_2.mp4


BIN
textures/outputmp4/1/1_3_3.mp4


BIN
textures/outputmp4/1/1_3_4.mp4


BIN
textures/outputmp4/1/1_3_5.mp4


BIN
textures/outputmp4/1/1_3_6.mp4


BIN
textures/outputmp4/1/1_3_7.mp4


BIN
textures/outputmp4/1/1_4_0.mp4


BIN
textures/outputmp4/1/1_4_1.mp4


BIN
textures/outputmp4/1/1_4_2.mp4


BIN
textures/outputmp4/1/1_4_3.mp4


BIN
textures/outputmp4/1/1_4_4.mp4


BIN
textures/outputmp4/1/1_4_5.mp4


BIN
textures/outputmp4/1/1_4_6.mp4


BIN
textures/outputmp4/1/1_4_7.mp4


BIN
textures/outputmp4/1/1_5_0.mp4


BIN
textures/outputmp4/1/1_5_1.mp4


BIN
textures/outputmp4/1/1_5_2.mp4


BIN
textures/outputmp4/1/1_5_3.mp4


BIN
textures/outputmp4/1/1_5_4.mp4


BIN
textures/outputmp4/1/1_5_5.mp4


BIN
textures/outputmp4/1/1_5_6.mp4


BIN
textures/outputmp4/1/1_5_7.mp4


BIN
textures/outputmp4/2/2.mp4


BIN
textures/outputmp4/2/2_1_0.mp4


BIN
textures/outputmp4/2/2_1_1.mp4


BIN
textures/outputmp4/2/2_1_2.mp4


BIN
textures/outputmp4/2/2_1_3.mp4


+ 0 - 0
textures/outputmp4/2/2_1_4.mp4


Неке датотеке нису приказане због велике количине промена