|
@@ -1,7 +1,7 @@
|
|
|
import CharactorManager from "./CharactorManager.js";
|
|
|
-import common from "./common.js";
|
|
|
-import houseShader from "./houseShader.js";
|
|
|
-import settings from "./settings.js";
|
|
|
+import common from "./utils/common.js";
|
|
|
+import houseShader from "./shaders/houseShader.js";
|
|
|
+import settings from "./utils/settings.js";
|
|
|
|
|
|
export default class App {
|
|
|
|
|
@@ -16,15 +16,13 @@ export default class App {
|
|
|
scene.activeCamera.attachControl(scene.canvas, true);
|
|
|
camera1.inertia = 0
|
|
|
camera1.minZ = 0
|
|
|
- camera1.fov = Math.PI / 2
|
|
|
+ camera1.fov = settings.camera.fov
|
|
|
camera1.fovMode = BABYLON.ArcRotateCamera.FOVMODE_HORIZONTAL_FIXED
|
|
|
camera1.lowerBetaLimit = Math.PI / 2
|
|
|
camera1.upperBetaLimit = Math.PI / 2
|
|
|
camera1.lowerRadiusLimit = settings.camera.distanceFromCharactor;
|
|
|
camera1.upperRadiusLimit = settings.camera.distanceFromCharactor;
|
|
|
- camera1.wheelDeltaPercentage = 0.01;
|
|
|
camera1.angularSensibilityX /= 2;
|
|
|
- // camera1.targetScreenOffset = new BABYLON.Vector2(0, -1.65)
|
|
|
this.camera = camera1
|
|
|
this.lastCameraAlpha = 0
|
|
|
// camera1.checkCollisions = true;
|
|
@@ -46,10 +44,9 @@ export default class App {
|
|
|
// }
|
|
|
// console.error(camera1)
|
|
|
|
|
|
-
|
|
|
- var ray = new BABYLON.Ray(new BABYLON.Vector3(0,0,0), new BABYLON.Vector3(0,0,1), 50);
|
|
|
- BABYLON.RayHelper.CreateAndShow(ray, scene, new BABYLON.Color3(1, 0.1, 0.1));
|
|
|
- this.ray = ray
|
|
|
+ // 人物相机射线
|
|
|
+ this.ray = new BABYLON.Ray(new BABYLON.Vector3(0,0,0), new BABYLON.Vector3(0,0,1), 50);
|
|
|
+ BABYLON.RayHelper.CreateAndShow(this.ray, scene, new BABYLON.Color3(1, 0.1, 0.1));
|
|
|
|
|
|
// Lights
|
|
|
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, -1, 0), scene);
|
|
@@ -80,9 +77,10 @@ export default class App {
|
|
|
|
|
|
self.house = newMeshes
|
|
|
self.house[0].position = new BABYLON.Vector3(0.6, 2.1, 1.5)
|
|
|
+ // self.house[0].position = new BABYLON.Vector3(-22, 0, 12)
|
|
|
|
|
|
newMeshes.forEach(m => {
|
|
|
- // m.scaling.scaleInPlace(1.4);
|
|
|
+ // m.scaling.scaleInPlace(100);
|
|
|
m._geometry && (m.checkCollisions = true)
|
|
|
|
|
|
if(m.material)
|
|
@@ -101,7 +99,12 @@ export default class App {
|
|
|
// document.getElementById("houseTexture0").loop = "loop"
|
|
|
|
|
|
shaderMaterial.setTexture("texture_video", videoTexture)
|
|
|
- shaderMaterial.setVector3("focal_width_height", new BABYLON.Vector3(735, settings.video.width, settings.video.height)) // 1100 470 860
|
|
|
+ // shaderMaterial.setVector3("focal_width_height", new BABYLON.Vector3(735, settings.video.width, settings.video.height)) // 1100 470 860
|
|
|
+ shaderMaterial.setVector3("focal_width_height", new BABYLON.Vector3(
|
|
|
+ 735 * window.innerHeight / settings.video.height,
|
|
|
+ settings.video.width * window.innerHeight / settings.video.height,
|
|
|
+ window.innerHeight
|
|
|
+ ))
|
|
|
shaderMaterial.setFloat("isYUV", 0)
|
|
|
|
|
|
m.material = shaderMaterial
|
|
@@ -168,18 +171,23 @@ export default class App {
|
|
|
|
|
|
// 实时更新相机target
|
|
|
let cameraTarget = this.charactorManager.charactor.mesh.position.clone()
|
|
|
- cameraTarget.y = 1.5
|
|
|
- this.camera.target = cameraTarget
|
|
|
+ cameraTarget.y = settings.camera.height
|
|
|
+ this.camera.setTarget(cameraTarget)
|
|
|
|
|
|
// 相机碰撞检测
|
|
|
this.ray.origin = cameraTarget
|
|
|
this.ray.direction = BABYLON.Vector3.Normalize( this.camera.position.clone().subtract(cameraTarget) )
|
|
|
let info = this.ray.intersectsMeshes(this.house)[0];
|
|
|
- const offset = 0.5
|
|
|
- if(info.distance > settings.camera.distanceFromCharactor + offset) return
|
|
|
+ const offset = 0.6
|
|
|
+ if(!info || info.distance > settings.camera.distanceFromCharactor + offset) return
|
|
|
+ let charactorVisi = this.charactorManager.charactor.visible
|
|
|
this.camera.lowerRadiusLimit = Math.max( info.distance - offset, 0.1 )
|
|
|
this.camera.upperRadiusLimit = Math.max( info.distance - offset, 0.1 )
|
|
|
// console.error(info.pickedPoint, this.camera.position)
|
|
|
+
|
|
|
+ // 根据相机位置更新人物显隐
|
|
|
+ if(info.distance - offset < 0.25 && charactorVisi) this.charactorManager.charactor.visible = false
|
|
|
+ if(info.distance - offset >= 0.25 && !charactorVisi) this.charactorManager.charactor.visible = true
|
|
|
|
|
|
// let r = this.cameraCollision()
|
|
|
// this.camera.lowerRadiusLimit = Math.max( r, 0.1 )
|
|
@@ -212,10 +220,12 @@ export default class App {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
- // this.lastCameraAlpha = this.camera.alpha
|
|
|
- this.lockCamera(false)
|
|
|
- }, 10)
|
|
|
+ window.connection.socket.emit("RotateCamera", sendData)
|
|
|
+
|
|
|
+ // setTimeout(() => {
|
|
|
+ // // this.lastCameraAlpha = this.camera.alpha
|
|
|
+ // this.lockCamera(false)
|
|
|
+ // }, 10)
|
|
|
|
|
|
// todo 发送数据
|
|
|
// common.postData("", sendData).then(response => {
|