refactoring meshUtils, added sceneScale, #74

This commit is contained in:
2026-03-24 20:25:50 +02:00
parent 0928ef8999
commit 008cc428d4
19 changed files with 199 additions and 189 deletions
+19 -8
View File
@@ -20,12 +20,13 @@ import { MotionEngine } from './MotionEngine.js';
import { Draggable } from './Draggable.js';
import { EventManager } from "./EventManager";
import { Telemetry } from './Telemetry.js';
import { clearObject } from './MeshUtils.js';
import { MeshUtils } from './MeshUtils.js';
THREE.Cache.enabled = true
const assetPath = '/asset/default/';
const defaultLightIntensity = 11;
const sceneScale = 1//.33;
class GameEngine extends EventManager{
@@ -45,6 +46,11 @@ class GameEngine extends EventManager{
);
const scene = new THREE.Scene();
this.sceneWrapper = new THREE.Group();
this.sceneWrapper.scale.setScalar(this.scale);
scene.add(this.sceneWrapper);
this.scene = scene;
this.initCameraPivot()
@@ -84,7 +90,7 @@ class GameEngine extends EventManager{
this.ambientSound = new THREE.Audio(this.listener);
this.activeObjects = new THREE.Group();
scene.add(this.activeObjects);
this.sceneWrapper.add(this.activeObjects);
if (this.opts.gizmo) {
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
@@ -99,6 +105,7 @@ class GameEngine extends EventManager{
this.orthographicCamera.position.set(0, 0, 100);
this.cameraRig.rotation.y = 0;
}
//this.scene.scale.setScalar(1.25);
//const controls = new MapControls( camera, renderer.domElement );
@@ -145,11 +152,12 @@ class GameEngine extends EventManager{
}
async init(domNode, opts = {}) {
this.scale = sceneScale;
this.w = domNode.clientWidth || 1200, this.h = domNode.clientHeight || 800;
this.aspect = this.w / this.h
this.opts = opts;
const gameEngine = this;
this.raycaster = new THREE.Raycaster();
this.meshUtils = new MeshUtils(this);
const renderer = new THREE.WebGLRenderer({
antialias: true,
@@ -378,7 +386,7 @@ class GameEngine extends EventManager{
this.cameraRig.add(this.orthographicCamera);
this.cameraRig.rotation.y = Math.PI;
this.cameraWorld.add(this.cameraRig);
this.scene.add(this.cameraWorld);
this.sceneWrapper.add(this.cameraWorld);
}
async initPhysics() {
@@ -626,10 +634,11 @@ class GameEngine extends EventManager{
}
processHideIfFar(){
let v = new THREE.Vector3();
let v = new THREE.Vector3(), cv = new THREE.Vector3();
this.cameraWorld.getWorldPosition(cv);
this.farArray.forEach(e=>{
e.object.getWorldPosition(v);
let dst = this.cameraWorld.position.distanceTo(v);
let dst = v.distanceTo(cv) / this.scale;
if (dst <= e.distance && !e.object.visible) {
e.object.visible = true;
}else if (dst > e.distance && e.object.visible){
@@ -672,14 +681,14 @@ class GameEngine extends EventManager{
this.gizmo?.dispose();
this.motionQueue.clearAll();
this.ambientSound.stop();
this.loadedObjects.forEach(o=>clearObject(o.scene))
this.loadedObjects.forEach(o=>this.meshUtils.clearObject(o.scene))
GameEngine.loadedTextures.forEach(t=>{
t.dispose();
});
GameEngine.loadedTextures.splice(0, GameEngine.loadedTextures.length);
this.scene.background?.dispose?.();
this.scene.environment?.dispose?.();
clearObject(this.scene);
this.meshUtils.clearObject(this.scene);
this.scene = null;
this.tm?.setScene(null);
this.removeAllListenersOfType('beforeRender');
@@ -739,6 +748,8 @@ class GameEngine extends EventManager{
})
}
static scale = 1.33;
loadTexture = GameEngine.loadTexture
}