From 0aaaf082774b3f30e30dd1cc255be3b34d5681c8 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Thu, 16 May 2024 17:04:16 +0800 Subject: [PATCH 1/2] feat: opt case --- src/babylon/collider-benchmark.ts | 13 +++++++++---- src/three/collider-benchmark.ts | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/babylon/collider-benchmark.ts b/src/babylon/collider-benchmark.ts index b7fbcd1..d042c13 100644 --- a/src/babylon/collider-benchmark.ts +++ b/src/babylon/collider-benchmark.ts @@ -7,10 +7,9 @@ import { DirectionalLight, Engine, Scene, - SceneLoader, + HemisphericLight, UniversalCamera, HavokPlugin, - CannonJSPlugin, MeshBuilder, Vector3, PhysicsAggregate, @@ -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); @@ -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 BABYLON.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( diff --git a/src/three/collider-benchmark.ts b/src/three/collider-benchmark.ts index 94d8c28..f5642e0 100644 --- a/src/three/collider-benchmark.ts +++ b/src/three/collider-benchmark.ts @@ -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); @@ -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() }) @@ -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 = document.getElementById("canvas"); From 42f8d97aef9e01bcf33a2d113047e0f404d69e4a Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Thu, 16 May 2024 17:06:46 +0800 Subject: [PATCH 2/2] feat: opt case --- src/babylon/collider-benchmark.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/babylon/collider-benchmark.ts b/src/babylon/collider-benchmark.ts index d042c13..0ea0179 100644 --- a/src/babylon/collider-benchmark.ts +++ b/src/babylon/collider-benchmark.ts @@ -44,7 +44,7 @@ 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 BABYLON.Vector3(0, 1, 0), scene); + const hemisphericLight = new HemisphericLight("hemisphericLight", new Vector3(0, 1, 0), scene); hemisphericLight.intensity = 1; const light = new DirectionalLight(