This commit is contained in:
+55
-33
@@ -33,7 +33,7 @@ class GameEngine extends EventManager{
|
||||
|
||||
this.perspectiveCamera = new THREE.PerspectiveCamera(45, this.aspect, 0.001, 99);
|
||||
this.raycaster = new THREE.Raycaster();
|
||||
this.perspectiveCamera.position.set(0, 0, 10);
|
||||
//this.perspectiveCamera.position.set(0, 0, 10);
|
||||
|
||||
this.camera = this.perspectiveCamera;
|
||||
|
||||
@@ -45,7 +45,7 @@ class GameEngine extends EventManager{
|
||||
this.frustumSize / - 2,
|
||||
0.01, 1000
|
||||
);
|
||||
this.orthographicCamera.position.set(0, 0, 100);
|
||||
|
||||
const scene = new THREE.Scene();
|
||||
this.scene = scene;
|
||||
|
||||
@@ -100,6 +100,7 @@ class GameEngine extends EventManager{
|
||||
renderer.setViewport(0, 0, this.w, this.h);
|
||||
renderer.autoClear = true;
|
||||
renderer.alpha = true
|
||||
this.renderer = renderer;
|
||||
|
||||
this.anaglyph = new AnaglyphEffect(renderer);
|
||||
this.anaglyph.setSize(this.w, this.h);
|
||||
@@ -120,29 +121,31 @@ class GameEngine extends EventManager{
|
||||
this.activeObjects = new THREE.Group();
|
||||
scene.add(this.activeObjects);
|
||||
|
||||
const controls = new OrbitControls(this.camera, renderer.domElement);
|
||||
if (opts.gizmo) {
|
||||
this.orbitControls = new OrbitControls(this.camera, renderer.domElement);
|
||||
this.orbitControls.enableZoom = false;
|
||||
const gizmo = new ViewportGizmo(this.camera, renderer, {
|
||||
container: '.renderer-gizmo',
|
||||
//type:'cube'
|
||||
});
|
||||
gizmo.attachControls(controls);
|
||||
gizmo.attachControls(this.orbitControls);
|
||||
this.gizmo = gizmo;
|
||||
this.perspectiveCamera.position.set(0, 0, 10);
|
||||
this.orthographicCamera.position.set(0, 0, 100);
|
||||
this.cameraRig.rotation.y = 0;
|
||||
}
|
||||
|
||||
if (opts.telemetry){
|
||||
this.tm = new Telemetry(opts.telemetry, opts.mode);
|
||||
}
|
||||
|
||||
this.orbitControls = controls;
|
||||
controls.enableZoom = false;
|
||||
//const controls = new MapControls( camera, renderer.domElement );
|
||||
this.transformControls = new TransformControls(this.camera, renderer.domElement);
|
||||
this.transformControls.addEventListener('dragging-changed', function (event) {
|
||||
controls.enabled = !event.value;
|
||||
});
|
||||
|
||||
this.pointerControls = new PointerControls(this.camera, renderer.domElement);
|
||||
this.pointerControls = new PointerControls(this);
|
||||
// controls.enableDamping = true;
|
||||
// controls.screenSpacePanning = true;
|
||||
|
||||
@@ -173,7 +176,6 @@ class GameEngine extends EventManager{
|
||||
const clock = new THREE.Clock();
|
||||
|
||||
this.clock = clock;
|
||||
this.renderer = renderer;
|
||||
|
||||
this.draco = new DRACOLoader().setDecoderPath('/3rdparty/draco/');
|
||||
this.loader = new GLTFLoader();
|
||||
@@ -204,7 +206,7 @@ class GameEngine extends EventManager{
|
||||
gameEngine.camera.zoom -= event.deltaY / (1000 / gameEngine.camera.zoom);
|
||||
gameEngine.camera.zoom = Math.max(gameEngine.camera.zoom, .01);
|
||||
//controls.rotateSpeed = 1 / Math.sqrt(gameEngine.camera.zoom);
|
||||
controls.panSpeed = 1 / gameEngine.camera.zoom;
|
||||
gameEngine.orbitControls.panSpeed = 1 / gameEngine.camera.zoom;
|
||||
gameEngine.camera.updateProjectionMatrix();
|
||||
}
|
||||
})
|
||||
@@ -226,23 +228,25 @@ class GameEngine extends EventManager{
|
||||
if (opts.xr) {
|
||||
renderer.xr.enabled = true;
|
||||
this.xrBtn = XRButton.createButton(renderer, opts.depthSense ? {
|
||||
'requiredFeatures': ['depth-sensing'],
|
||||
'depthSensing': {
|
||||
requiredFeatures: ['depth-sensing'],
|
||||
depthSensing: {
|
||||
usagePreference: ["gpu-optimized"],
|
||||
dataFormatPreference: ["unsigned-short"],
|
||||
matchDepthView: false
|
||||
}
|
||||
} : {})
|
||||
} : {
|
||||
|
||||
})
|
||||
this.xrBtn.classList.add('engine-xr-btn');
|
||||
document.body.appendChild(this.xrBtn);
|
||||
this.initXrControllers();
|
||||
this.initXr();
|
||||
}
|
||||
|
||||
this.clickable = new Clickable(20);
|
||||
this.draggable = new Draggable(20);
|
||||
}
|
||||
|
||||
initXrControllers() {
|
||||
initXr() {
|
||||
let c1 = this.renderer.xr.getController(0);
|
||||
c1.addEventListener('select', this.onSelect.bind(this));
|
||||
c1.addEventListener('selectstart', this.onControllerEvent.bind(this));
|
||||
@@ -287,22 +291,32 @@ class GameEngine extends EventManager{
|
||||
|
||||
this.xrController1 = c1
|
||||
this.xrController2 = c2
|
||||
|
||||
this.xrCamera = this.renderer.xr.getCamera();
|
||||
}
|
||||
|
||||
initCameraPivot() {
|
||||
const pivot = new THREE.Object3D()
|
||||
pivot.position.set(0, 0, 0)
|
||||
// const pivot = new THREE.Object3D()
|
||||
// pivot.position.set(0, 0, 0)
|
||||
|
||||
const yaw = new THREE.Object3D()
|
||||
const pitch = new THREE.Object3D()
|
||||
// const yaw = new THREE.Object3D()
|
||||
// const pitch = new THREE.Object3D()
|
||||
|
||||
this.scene.add(pivot)
|
||||
pivot.add(yaw)
|
||||
yaw.add(pitch)
|
||||
this.scene.add(this.perspectiveCamera);
|
||||
this.scene.add(this.orthographicCamera);
|
||||
this.cameraPivot = pivot;
|
||||
this.cameraYaw = yaw;
|
||||
// this.scene.add(pivot)
|
||||
// pivot.add(yaw)
|
||||
// yaw.add(pitch)
|
||||
// this.scene.add(this.perspectiveCamera);
|
||||
// this.scene.add(this.orthographicCamera);
|
||||
// this.cameraPivot = pivot;
|
||||
// this.cameraYaw = yaw;
|
||||
|
||||
this.cameraWorld = new THREE.Group();
|
||||
this.cameraRig = new THREE.Group();
|
||||
this.cameraRig.add(this.perspectiveCamera);
|
||||
this.cameraRig.add(this.orthographicCamera);
|
||||
this.cameraRig.rotation.y = Math.PI;
|
||||
this.cameraWorld.add(this.cameraRig);
|
||||
this.scene.add(this.cameraWorld);
|
||||
}
|
||||
|
||||
async initPhysics() {
|
||||
@@ -540,7 +554,7 @@ class GameEngine extends EventManager{
|
||||
// o.updateProjectionMatrix();
|
||||
this.camera = o;
|
||||
this.transformControls.camera = o;
|
||||
this.orbitControls.object = o;
|
||||
//this.orbitControls.object = o;
|
||||
if (this.gizmo) {
|
||||
this.gizmo.camera = o;
|
||||
}
|
||||
@@ -554,7 +568,7 @@ class GameEngine extends EventManager{
|
||||
// o.updateProjectionMatrix();
|
||||
this.camera = o;
|
||||
this.transformControls.camera = o;
|
||||
this.orbitControls.object = o;
|
||||
//this.orbitControls.object = o;
|
||||
if (this.gizmo) {
|
||||
this.gizmo.camera = o;
|
||||
}
|
||||
@@ -607,12 +621,20 @@ class GameEngine extends EventManager{
|
||||
this.ambientSound.play();
|
||||
}
|
||||
|
||||
showBackground(show, t = 1){
|
||||
this.motionQueue.add({
|
||||
o: this.scene,
|
||||
a: { backgroundIntensity: show ? 1 : 0},
|
||||
t
|
||||
})
|
||||
immersive(show, t = 1){
|
||||
this.motionQueue.add([
|
||||
{
|
||||
o: this.scene,
|
||||
a: {
|
||||
backgroundIntensity: show ? 0.1 : 1, environmentIntensity: show ? 0.1 : 1
|
||||
},
|
||||
t
|
||||
},{
|
||||
o: this.ambientLight,
|
||||
a: { intensity: show ? 0.1 : 11},
|
||||
t
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
destroy(){
|
||||
|
||||
Reference in New Issue
Block a user