This commit is contained in:
2025-11-28 17:59:11 +02:00
parent 8a28846fe8
commit ee574bd282
6 changed files with 16 additions and 14 deletions
@@ -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)
+3 -2
View File
@@ -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;
+5 -5
View File
@@ -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
+2 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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]);