Added thickness to dice tray collision wall and roof

This commit is contained in:
Mitchell McCaffrey 2020-05-27 12:04:28 +10:00
parent 027fc480e1
commit cf12ff22ed
2 changed files with 40 additions and 47 deletions

View File

@ -86,26 +86,6 @@ function DiceTrayOverlay({ isOpen }) {
shadowGenerator.darkness = 0.7; shadowGenerator.darkness = 0.7;
shadowGeneratorRef.current = shadowGenerator; shadowGeneratorRef.current = shadowGenerator;
let ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 2, scene);
ground.physicsImpostor = new BABYLON.PhysicsImpostor(
ground,
BABYLON.PhysicsImpostor.BoxImpostor,
{ mass: 0, friction: 20.0 },
scene
);
ground.isVisible = false;
ground.position.y = 0.2;
let roof = BABYLON.Mesh.CreateGround("roof", 100, 100, 2, scene);
roof.physicsImpostor = new BABYLON.PhysicsImpostor(
roof,
BABYLON.PhysicsImpostor.BoxImpostor,
{ mass: 0, friction: 100.0 },
scene
);
roof.position.y = 10;
roof.isVisible = false;
scene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData( scene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(
environment, environment,
scene scene

View File

@ -18,8 +18,8 @@ class DiceTray {
} }
set size(newSize) { set size(newSize) {
this._size = newSize; this._size = newSize;
const wallOffsetWidth = this.wallSize / 2 + this.width / 2 - 0.5; const wallOffsetWidth = this.collisionSize / 2 + this.width / 2 - 0.5;
const wallOffsetHeight = this.wallSize / 2 + this.height / 2 - 0.5; const wallOffsetHeight = this.collisionSize / 2 + this.height / 2 - 0.5;
this.wallTop.position.z = -wallOffsetHeight; this.wallTop.position.z = -wallOffsetHeight;
this.wallRight.position.x = -wallOffsetWidth; this.wallRight.position.x = -wallOffsetWidth;
this.wallBottom.position.z = wallOffsetHeight; this.wallBottom.position.z = wallOffsetHeight;
@ -33,7 +33,7 @@ class DiceTray {
return this.size === "single" ? 10 : 20; return this.size === "single" ? 10 : 20;
} }
height = 20; height = 20;
wallSize = 50; collisionSize = 50;
wallTop; wallTop;
wallRight; wallRight;
wallBottom; wallBottom;
@ -52,49 +52,62 @@ class DiceTray {
await this.loadMeshes(); await this.loadMeshes();
} }
createWall(name, x, z, yaw) { createCollision(name, x, y, z, friction) {
let wall = BABYLON.Mesh.CreateBox( let collision = BABYLON.Mesh.CreateBox(
name, name,
this.wallSize, this.collisionSize,
this.scene, this.scene,
true, true,
BABYLON.Mesh.DOUBLESIDE BABYLON.Mesh.DOUBLESIDE
); );
wall.rotation = new BABYLON.Vector3(0, yaw, 0); collision.position.x = x;
wall.position.z = z; collision.position.y = y;
wall.position.x = x; collision.position.z = z;
wall.physicsImpostor = new BABYLON.PhysicsImpostor( collision.physicsImpostor = new BABYLON.PhysicsImpostor(
wall, collision,
BABYLON.PhysicsImpostor.BoxImpostor, BABYLON.PhysicsImpostor.BoxImpostor,
{ mass: 0, friction: 10.0 }, { mass: 0, friction: friction },
this.scene this.scene
); );
wall.isVisible = false; collision.isVisible = false;
return wall; return collision;
} }
loadWalls() { loadWalls() {
const wallOffsetWidth = this.wallSize / 2 + this.width / 2 - 0.5; const wallOffsetWidth = this.collisionSize / 2 + this.width / 2 - 0.5;
const wallOffsetHeight = this.wallSize / 2 + this.height / 2 - 0.5; const wallOffsetHeight = this.collisionSize / 2 + this.height / 2 - 0.5;
this.wallTop = this.createWall("wallTop", 0, -wallOffsetHeight, 0); this.wallTop = this.createCollision("wallTop", 0, 0, -wallOffsetHeight, 10);
this.wallRight = this.createWall( this.wallRight = this.createCollision(
"wallRight", "wallRight",
-wallOffsetWidth, -wallOffsetWidth,
0, 0,
Math.PI / 2 0,
10
); );
this.wallBottom = this.createWall( this.wallBottom = this.createCollision(
"wallBottom", "wallBottom",
0, 0,
wallOffsetHeight,
Math.PI
);
this.wallLeft = this.createWall(
"wallLeft",
wallOffsetWidth,
0, 0,
-Math.PI / 2 wallOffsetHeight,
10
);
this.wallLeft = this.createCollision("wallLeft", wallOffsetWidth, 0, 0, 10);
const diceTrayGroundOffset = 0.32;
this.createCollision(
"ground",
0,
-this.collisionSize / 2 + diceTrayGroundOffset,
0,
20
);
const diceTrayRoofOffset = 10;
this.createCollision(
"roof",
0,
this.collisionSize / 2 + diceTrayRoofOffset,
0,
100
); );
} }