From ee574bd282d082828e6ff9f19eb6aa621c07b0b6 Mon Sep 17 00:00:00 2001 From: goynov Date: Fri, 28 Nov 2025 17:59:11 +0200 Subject: [PATCH] #21 --- .../InteractiveObjects/MazeQuizGame/MazeObject.js | 4 ++-- src/lib/GameEngine.js | 5 +++-- src/lib/Hero.js | 10 +++++----- src/lib/MeshUtils.js | 3 ++- src/lib/Physics.js | 2 +- src/mixins/GameEnvironmentMixin.js | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/InteractiveObjects/MazeQuizGame/MazeObject.js b/src/components/InteractiveObjects/MazeQuizGame/MazeObject.js index c5c1bf3..5d5270a 100644 --- a/src/components/InteractiveObjects/MazeQuizGame/MazeObject.js +++ b/src/components/InteractiveObjects/MazeQuizGame/MazeObject.js @@ -81,7 +81,7 @@ class MazeObject { }); //the floor: - addPhysics(def.matrix, [0, -0.2, offsetZ + wallSize/2], {width:wallSize/2, height:0.1, depth: wallSize/2}) + addPhysics(def.matrix, [0, -0.1, offsetZ + wallSize/2], {width:wallSize/2, height:0.1, depth: wallSize/2}) } this.mazeObject = function(def, room, step = 0) { @@ -106,7 +106,7 @@ class MazeObject { addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ) addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], offsetZ) //the floor: - addPhysics(def.matrix, [0, -0.2, offsetZ/2], {width:tubeSize/2, height:0.1, depth: offsetZ/2}) + addPhysics(def.matrix, [0, -0.1, offsetZ/2], {width:tubeSize/2, height:0.1, depth: offsetZ/2}) addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ) diff --git a/src/lib/GameEngine.js b/src/lib/GameEngine.js index 432cfed..3aebae2 100644 --- a/src/lib/GameEngine.js +++ b/src/lib/GameEngine.js @@ -412,8 +412,9 @@ class GameEngine extends THREE.EventDispatcher{ } if ( object instanceof THREE.Mesh ) { //object.material.envMap = this.scene.environment; - if (object.material.map) object.material.map.colorSpace = THREE.SRGBColorSpace; - //object.material.metalness = 0; + if (object.material.map) { + object.material.map.colorSpace = THREE.SRGBColorSpace; + } } //object.frustumCulled = false; object.castShadow = true; diff --git a/src/lib/Hero.js b/src/lib/Hero.js index 000157b..fa2c0c5 100644 --- a/src/lib/Hero.js +++ b/src/lib/Hero.js @@ -21,10 +21,10 @@ class Hero{ lerp = (x, y, a) => x * (1 - a) + y * a; - constructor(engine, io, data){ + constructor(engine, io){ this.source = io.source; this.model = io.object - this.data = data; + //this.data = data; this.engine = engine; @@ -51,14 +51,14 @@ class Hero{ this.runVelocity = this.size.y * 5 this.walkVelocity = this.size.y * 3 - this.po = engine.physics.add(this.model, 'kinematicPositionBased', false, undefined, 'capsule', { radius: this.size.x/2, halfHeight: (this.size.y-this.size.x)/2}) + this.po = engine.physics.add(this.model, 'kinematicPositionBased', false, undefined, 'capsule', { radius: this.size.y/4, halfHeight: this.size.y/4}) this.po.collider.setTranslationWrtParent({x: 0, y: this.size.y/2, z: 0}); this.currentAction = 'idle'; this.animationsMap[this.currentAction].play() this.characterController = this.engine.physics.world.createCharacterController(this.characterGapOffset); - this.characterController.setUp({x:0, y:1, z:0}); + //this.characterController.setUp({x:0, y:1, z:0}); this.po.rigidBody.setTranslation(this.model.position) this.po.characterController = this.characterController; //this.characterController.enableSnapToGround(0.5); @@ -67,7 +67,7 @@ class Hero{ // Automatically slide down on slopes smaller than 30 degrees. // this.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180); // this.characterController.enableAutostep(0.5, 0.2, true); - this.characterController.setApplyImpulsesToDynamicBodies(true); + //this.characterController.setApplyImpulsesToDynamicBodies(true); // this.characterController.setCharacterMass(50); this.orbitControl = this.engine.orbitControls diff --git a/src/lib/MeshUtils.js b/src/lib/MeshUtils.js index dbdc85a..6c57b2e 100644 --- a/src/lib/MeshUtils.js +++ b/src/lib/MeshUtils.js @@ -50,6 +50,7 @@ function getBoundingBoxCenterPoint(bb, relativeTo){ } function autoScale(object, mk = 1) { + if (mk === null) return; let bb = getBoundingBox(object); let k = getBoundingBoxMaxLength(bb); object.scale.multiplyScalar(mk / k); @@ -74,7 +75,7 @@ function centerOrigin(object){ function bottomOrigin(object){ let group = centerOrigin(object); - group.userData.object.position.y += (group.userData.bbox.max.y - group.userData.bbox.min.y)/2 + group.userData.object.position.y = -group.userData.bbox.min.y return group; } diff --git a/src/lib/Physics.js b/src/lib/Physics.js index 92807d0..0691e90 100644 --- a/src/lib/Physics.js +++ b/src/lib/Physics.js @@ -86,7 +86,6 @@ class Physics{ colliderDesc = RAPIER.ColliderDesc.trimesh( vertices, indices ); } - break } if (!colliderDesc) { @@ -104,6 +103,7 @@ class Physics{ if (colliderSettings.root){ collider.setTranslationWrtParent(colliderSettings.root.position) collider.setRotationWrtParent(colliderSettings.root.quaternion) + console.log(colliderSettings.root.position, mesh.position) } const physicsObject = { mesh, collider, rigidBody, fn: postPhysicsFn, autoAnimate } this.physicsObjects.push(physicsObject) diff --git a/src/mixins/GameEnvironmentMixin.js b/src/mixins/GameEnvironmentMixin.js index 41306a8..7eaf4fd 100644 --- a/src/mixins/GameEnvironmentMixin.js +++ b/src/mixins/GameEnvironmentMixin.js @@ -139,10 +139,10 @@ export default { } if (this.scene.data.$scene){ let env = await gameEngine.load(this.scene.data.$scene.asset.name); - this.setObjectAttributes(l, this.scene.data, env.scene, env, 100); + this.setObjectAttributes(l, this.scene.data, env.scene, env, null); if (this.env != 'GameDesigner'){ env.scene.traverse(o=>{ - if (o.name == 'Sphere'){ + if (o.name.startsWith('land') || o.name == 'Sphere'){ console.log('Fixing ground. TODO!!!') gameEngine.physics.add(o, 'fixed', true, undefined, 'mesh', { root: env.scene}) } @@ -168,7 +168,7 @@ export default { gameEngine.activeObjects.add(io.object); if (this.env != 'GameDesigner'){ if (i.data.$go?.type == 'player3d'){ - let hero = new Hero(gameEngine, io, i.data.$go); + let hero = new Hero(gameEngine, io); }else{ if (io.source?.animations?.length){ gameEngine.playAnimation(gameEngine.scene, io.source.animations[0]);