123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import Charactor from "./Charactor.js";
- import common from "./utils/common.js";
- import data from "./utils/data.js";
- import settings from "./utils/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) {
- // 在行走之前,首先要把人物矫正到45度的倍数(有视频的8个方向)
- if(this.app.camera.alpha % (Math.PI / 4) == 0 )
- {
- // 如果已经在8个方向上了
- this.charactorWalkTo(pickinfo.pickedPoint)
- }
- else {
- // 相机方向矫正
- let cameraAlphaAmend = parseInt(this.app.camera.alpha / (Math.PI / 4)) * (Math.PI / 4)
- let pointData = this.getClosestPointData(this.charactor.mesh.position)
- let sendData = {
- video: [pointData.id],
- reverse: this.app.camera.alpha - cameraAlphaAmend < 0
- }
- // window.connection.socket.emit("getPush", sendData)
- // todo
- this.app.rotateCamera(this.app.camera.alpha - cameraAlphaAmend, () => {
- // this.charactorWalkTo(pickinfo.pickedPoint)
- })
- }
- }
- }
- onBeforeAnimation() {
- this.charactor.updateAniTrans()
- }
- charactorWalkTo(endPoint) {
- let endPointData = this.getClosestPointData(endPoint)
- let currentPath = this.charactor.walkData.pathArr[this.charactor.walkData.currentPoint]
- let startPoint = (currentPath && currentPath.point) || this.charactor.mesh.position
- let sendData = {
- video: [endPointData.id], // todo
- reverse: true // todo
- }
- // window.connection.socket.emit("getPush", sendData)
- // todo
- 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)
- }
- getClosestPointData(vec) {
- let ueVec = {x: vec.x, y: vec.z, z: vec.y}
- let closestPoint = { data: null, length: 99999 }
- this.pointsData.forEach( data => {
- let length = common.getLengthBetweenVec3(ueVec, data.position)
- if(length < closestPoint.length) {
- closestPoint.data = data
- closestPoint.length = length
- }
- })
- return closestPoint.data
- }
- }
|