Skip to content

Commit

Permalink
Merge pull request #12 from galacean/feat/physics-case
Browse files Browse the repository at this point in the history
feat: opt physics case
  • Loading branch information
gz65555 authored May 16, 2024
2 parents 7484a6f + 42f8d97 commit 5b706aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
13 changes: 9 additions & 4 deletions src/babylon/collider-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
DirectionalLight,
Engine,
Scene,
SceneLoader,
HemisphericLight,
UniversalCamera,
HavokPlugin,
CannonJSPlugin,
MeshBuilder,
Vector3,
PhysicsAggregate,
Expand All @@ -26,6 +25,9 @@ document.body.appendChild(canvas);
// Generate the BABYLON 3D engine
const engine = new Engine(canvas, true);

canvas.width = canvas.clientWidth * window.devicePixelRatio;
canvas.height = canvas.clientHeight * window.devicePixelRatio;

// Create the scene
const createScene = async function () {
const scene = new Scene(engine);
Expand All @@ -42,14 +44,17 @@ const createScene = async function () {

// Targets the camera to a particular position. In this case the scene origin
camera.setTarget(Vector3.Zero());
const hemisphericLight = new HemisphericLight("hemisphericLight", new Vector3(0, 1, 0), scene);
hemisphericLight.intensity = 1;

const light = new DirectionalLight(
"dir01",
new Vector3(0, -0.5, -1.0),
new Vector3(0, 0, 0),
scene
);
light.position = new Vector3(0, 5, 5);
light.position = new Vector3(-0.3, 1, 0.4);
light.shadowEnabled = false;
light.intensity = 1;

// Create a ground plane
const ground = MeshBuilder.CreateGround(
Expand Down
24 changes: 12 additions & 12 deletions src/three/collider-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ scriptPromise.then(() => {
camera.lookAt(0, 0, 0);

scene = new THREE.Scene();
scene.background = new THREE.Color(0x666666);
scene.background = new THREE.Color();
var ambientLight = new THREE.AmbientLight(0xffffff);
ambientLight.color.set(new THREE.Color(1, 1, 1));
scene.add(ambientLight);

const dirLight = new THREE.DirectionalLight();
dirLight.position.set(-0.3, 1, 0.4);
Expand All @@ -57,22 +60,21 @@ scriptPromise.then(() => {
// Boxes
const geometryBox = new THREE.BoxGeometry(0.075, 0.075, 0.075);


var boxCount = 0;
setInterval(() => {
if (boxCount > 850) return;

addBox(
new THREE.Vector3(
Math.random() - 0.5,
Math.random() * 2 + 2.5,
Math.random() - 0.5
))
new THREE.Vector3(
Math.random() - 0.5,
Math.random() * 2 + 2.5,
Math.random() - 0.5
)
);
boxCount++;
}, 16);

function addBox( position) {

function addBox(position) {
let boxes = new THREE.Mesh(
geometryBox,
new THREE.MeshStandardMaterial({ color: 0xffffff * Math.random() })
Expand All @@ -81,9 +83,7 @@ scriptPromise.then(() => {
boxes.receiveShadow = false;
scene.add(boxes);

boxes.position.set(
position.x,position.y,position.z
);
boxes.position.set(position.x, position.y, position.z);
physics.addMesh(boxes, 1);
}
const canvas = <HTMLCanvasElement>document.getElementById("canvas");
Expand Down

0 comments on commit 5b706aa

Please sign in to comment.