|
@@ -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()
|
|
|
}
|
|
|
|
|
|
}
|