import Charactor from "./Charactor.js"; import common from "./common.js"; import data from "./data.js"; import settings from "./settings.js"; export default class CharactorManager { constructor(app) { this.app = app this.frameRate = settings.video.frameRate; fetch("../textures/outputmp4/points.json", { headers: { 'content-type': 'application/json' }, method: 'GET', }) .then(response => response.json()) .then(response => { this.pointsData = response }) } importCharactorModel(modelPath, modelName) { let self = this BABYLON.SceneLoader.ImportMesh("", modelPath, modelName, this.app.scene, function (newMeshes, particleSystems, skeletons, animationGroups) { self.charactor = new Charactor(newMeshes, particleSystems, skeletons, animationGroups) self.charactor.mesh.scaling.scaleInPlace(1.4); // 初始人物位置 self.charactor.mesh.position = new BABYLON.Vector3( self.pointsData[0].position.x, 0, self.pointsData[0].position.y ) }); } clickHouse() { var scene = this.app.scene var pickinfo = scene.pick(scene.pointerX, scene.pointerY); if(pickinfo.pickedPoint) { this.charactorWalkTo(pickinfo.pickedPoint) // // 在行走之前,首先要把人物矫正到45度的倍数(有视频的8个方向) // if(this.charactor.actionType.split("-")[1] == "Walking") // { // // 如果是行走时改方向的话,相机保持之前已校正的度数,所以不用再改 // this.charactorWalkTo(pickinfo.pickedPoint) // } // else { // let cameraAlphaAmend = parseInt(this.app.camera.alpha / (Math.PI / 2)) * (Math.PI / 2) // let sendData = { // type: "CameraRotate", // point: this.charactor.mesh.position, // dirc: { // from: this.app.camera.alpha % (Math.PI * 2), // to: cameraAlphaAmend % (Math.PI * 2) // } // } // // todo 发送数据 // // common.postData("", sendData).then(response => { // let video = response[0].video // this.app.updateHouseVideo(video) // let rotateAni = new BABYLON.Animation("rotate", "alpha", this.frameRate, // BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE); // const rotateFrameNum = this.frameRate * video.duration // const rotateKeyFrames = [{ // frame: 0, // value: this.app.camera.alpha // },{ // frame: rotateFrameNum, // value: cameraAlphaAmend // }]; // rotateAni.setKeys(rotateKeyFrames); // scene.beginDirectAnimation(this.app.camera, [rotateAni], 0, rotateFrameNum, false, 1, () => { // // 旋转完后开始行走 // this.charactorWalkTo(pickinfo.pickedPoint) // }) // // }) // } } } onBeforeAnimation() { this.charactor.updateAniTrans() } charactorWalkTo(endPoint) { let currentPath = this.charactor.walkData.pathArr[this.charactor.walkData.currentPoint] let startPoint = (currentPath && currentPath.point) || this.charactor.mesh.position let sendData = { type: "Walk", point: { from: { x: startPoint.x, y: startPoint.z }, to: { x: endPoint.x, y: endPoint.z } }, dirc: this.app.camera.alpha % (Math.PI * 2) } // todo 发送数据 // common.postData("", sendData).then(response => { let path = data.walkPath // response path.forEach(data => data.point = this.pointsData[data.id].position) path = path.map(data => { return { point: new BABYLON.Vector3(data.point.x, 0, data.point.y), video: data.video && common.createVideoElement(data.video) } }) // 行走时锁定camera this.app.lockCamera(true) this.charactor.startWalk(path, this) // }) } }