From cf12ff22ed7f736f1b1fe397f7b4e046b71b5af4 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Wed, 27 May 2020 12:04:28 +1000 Subject: [PATCH] Added thickness to dice tray collision wall and roof --- src/components/map/dice/DiceTrayOverlay.js | 20 ------- src/dice/diceTray/DiceTray.js | 67 +++++++++++++--------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/components/map/dice/DiceTrayOverlay.js b/src/components/map/dice/DiceTrayOverlay.js index 5a56592..6b0dbba 100644 --- a/src/components/map/dice/DiceTrayOverlay.js +++ b/src/components/map/dice/DiceTrayOverlay.js @@ -86,26 +86,6 @@ function DiceTrayOverlay({ isOpen }) { shadowGenerator.darkness = 0.7; 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( environment, scene diff --git a/src/dice/diceTray/DiceTray.js b/src/dice/diceTray/DiceTray.js index 8fd90c2..8e7bcf6 100644 --- a/src/dice/diceTray/DiceTray.js +++ b/src/dice/diceTray/DiceTray.js @@ -18,8 +18,8 @@ class DiceTray { } set size(newSize) { this._size = newSize; - const wallOffsetWidth = this.wallSize / 2 + this.width / 2 - 0.5; - const wallOffsetHeight = this.wallSize / 2 + this.height / 2 - 0.5; + const wallOffsetWidth = this.collisionSize / 2 + this.width / 2 - 0.5; + const wallOffsetHeight = this.collisionSize / 2 + this.height / 2 - 0.5; this.wallTop.position.z = -wallOffsetHeight; this.wallRight.position.x = -wallOffsetWidth; this.wallBottom.position.z = wallOffsetHeight; @@ -33,7 +33,7 @@ class DiceTray { return this.size === "single" ? 10 : 20; } height = 20; - wallSize = 50; + collisionSize = 50; wallTop; wallRight; wallBottom; @@ -52,49 +52,62 @@ class DiceTray { await this.loadMeshes(); } - createWall(name, x, z, yaw) { - let wall = BABYLON.Mesh.CreateBox( + createCollision(name, x, y, z, friction) { + let collision = BABYLON.Mesh.CreateBox( name, - this.wallSize, + this.collisionSize, this.scene, true, BABYLON.Mesh.DOUBLESIDE ); - wall.rotation = new BABYLON.Vector3(0, yaw, 0); - wall.position.z = z; - wall.position.x = x; - wall.physicsImpostor = new BABYLON.PhysicsImpostor( - wall, + collision.position.x = x; + collision.position.y = y; + collision.position.z = z; + collision.physicsImpostor = new BABYLON.PhysicsImpostor( + collision, BABYLON.PhysicsImpostor.BoxImpostor, - { mass: 0, friction: 10.0 }, + { mass: 0, friction: friction }, this.scene ); - wall.isVisible = false; + collision.isVisible = false; - return wall; + return collision; } loadWalls() { - const wallOffsetWidth = this.wallSize / 2 + this.width / 2 - 0.5; - const wallOffsetHeight = this.wallSize / 2 + this.height / 2 - 0.5; - this.wallTop = this.createWall("wallTop", 0, -wallOffsetHeight, 0); - this.wallRight = this.createWall( + const wallOffsetWidth = this.collisionSize / 2 + this.width / 2 - 0.5; + const wallOffsetHeight = this.collisionSize / 2 + this.height / 2 - 0.5; + this.wallTop = this.createCollision("wallTop", 0, 0, -wallOffsetHeight, 10); + this.wallRight = this.createCollision( "wallRight", -wallOffsetWidth, 0, - Math.PI / 2 + 0, + 10 ); - this.wallBottom = this.createWall( + this.wallBottom = this.createCollision( "wallBottom", 0, - wallOffsetHeight, - Math.PI - ); - this.wallLeft = this.createWall( - "wallLeft", - wallOffsetWidth, 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 ); }