Skip to content

Commit 4cfaed1

Browse files
committed
Minor changes
1 parent 1f18386 commit 4cfaed1

File tree

6 files changed

+178
-189
lines changed

6 files changed

+178
-189
lines changed

fiveserver.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
root: 'src',
33
port: 8081,
44
highlight: false,
5-
injectBody: false
5+
injectBody: false,
6+
navigate: false
67
}

src/examples.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -52,15 +52,6 @@
5252
<div class="container">
5353
<h2>Examples</h2>
5454

55-
<h3>Prototypes</h3>
56-
<ul class="examples-list">
57-
<li>
58-
<a href="https://github.com/yandeu/kronos2-prototype#readme" target="_blank" rel="noopener"
59-
>Krono's Path 2 (prototype)</a
60-
>
61-
</li>
62-
</ul>
63-
6455
<h3>Headless Mode (Ammo Physics on Node.js Server)</h3>
6556
<ul class="examples-list">
6657
<li><a href="./examples/headless-mode.html">Headless Mode</a></li>
@@ -71,6 +62,7 @@ <h3>Headless Mode (Ammo Physics on Node.js Server)</h3>
7162
<h3>As Physics Extension for three.js</h3>
7263
<ul class="examples-list">
7364
<li><a href="./examples/native-three-with-physics.html">Native three.js with Physics</a></li>
65+
<li><a href="./examples/compare-physics-body-shapes.html">Compare Physics Body Shapes</a></li>
7466
<li><a href="./examples/gltf-loader-with-physics.html">GLTFLoader with Physics</a></li>
7567
<li><a href="./examples/point-to-point-constraint.html">Point to Point Constraint</a></li>
7668
<li><a href="./examples/hollow-cylinder.html">Hollow Cylinder</a></li>
@@ -88,6 +80,7 @@ <h3>Standalone Mode</h3>
8880
<li><a href="./examples/standalone-mode.html">Standalone Mode</a></li>
8981
<li><a href="./examples/resize-window.html">Resize Window</a></li>
9082
<li><a href="./examples/texture-on-a-plane.html">Texture on a Plane</a></li>
83+
<li><a href="./examples/standalone/texture-cube.html">Texture Cube</a></li>
9184
<li><a href="./examples/objects-recycling.html">Objects Recycling</a></li>
9285
<li><a href="./examples/use-tweenjs.html">Use tween.js</a></li>
9386
<li><a href="./examples/project-options-and-multiple-scenes.html">Project Options and Multiple Scenes</a></li>
@@ -195,9 +188,7 @@ <h3>As 3D Extension for Phaser</h3>
195188
<li>
196189
<a href="./examples/adjust-gamma-factor-and-shadows.html">Adjust GammaFactor and Shadows at Runtime</a>
197190
</li>
198-
<li><a href="./examples/texture-cube.html">Texture Cube</a></li>
199191
<li><a href="./examples/change-material-of-3d-model.html">Change Material of 3d Model</a></li>
200-
<li><a href="./examples/compare-physics-body-shapes.html">Compare Physics Body Shapes</a></li>
201192
<li><a href="./examples/tween-manager.html">Tween Manager</a></li>
202193
<li><a href="./examples/switch-camera-between-2d-and-3d.html">Switch Camera between 2d and 3d</a></li>
203194
</ul>
Lines changed: 109 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -10,106 +10,130 @@
1010
<title>Compare Physics Body Shapes</title>
1111
<link rel="stylesheet" href="/css/examples.css?ver=1.0.0" />
1212
<script src="/js/examples.js?ver=1.1.1"></script>
13-
<script src="/lib/phaser.min.js?ver=3.52.0"></script>
14-
<script src="/lib/enable3d/enable3d.phaserExtension.0.25.4.min.js"></script>
1513
</head>
1614

1715
<body>
1816
<div id="info-text">From left to right:<br />box, compound, hull, hacd, convexMesh, concaveMesh</div>
19-
<script>
20-
const { enable3d, Scene3D, Canvas, ExtendedObject3D } = ENABLE3D
21-
22-
class MainScene extends Scene3D {
23-
constructor() {
24-
super({ key: 'MainScene' })
17+
<script type="importmap">
18+
{
19+
"imports": {
20+
"three": "/lib/threejs/r171/three.module.min.js",
21+
"orbit-controls": "/lib/threejs/r171/OrbitControls.module.min.js",
22+
"enable3d": "/lib/enable3d/enable3d.ammoPhysics.0.26.0_dev0.module.min.js",
23+
"gltf-loader": "/lib/threejs/r171/GLTFLoader.module.min.js"
2524
}
25+
}
26+
</script>
27+
<script type="module">
28+
import * as THREE from 'three'
29+
import { AmmoPhysics, PhysicsLoader } from 'enable3d'
30+
import { OrbitControls } from 'orbit-controls'
31+
import { GLTFLoader } from 'gltf-loader'
32+
33+
const MainScene = () => {
34+
const scene = new THREE.Scene()
35+
scene.background = new THREE.Color(0xf0f0f0)
36+
37+
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000)
38+
camera.position.set(4, 4, 8)
39+
camera.lookAt(0, 1, 0)
40+
41+
const renderer = new THREE.WebGLRenderer()
42+
renderer.setSize(window.innerWidth, window.innerHeight)
43+
document.body.appendChild(renderer.domElement)
44+
45+
const controls = new OrbitControls(camera, renderer.domElement)
46+
controls.target.set(0, 1, 0)
47+
controls.update()
48+
49+
scene.add(new THREE.HemisphereLight(0xffffff, 0x000000, 1))
50+
scene.add(new THREE.AmbientLight(0xffffff))
51+
const light = new THREE.DirectionalLight(0xffffff, 1)
52+
light.position.set(50, 200, 100)
53+
light.position.multiplyScalar(1.3)
54+
55+
// initialize physics
56+
const physics = new AmmoPhysics(scene)
57+
physics.debug.enable(true)
58+
59+
// add a ground
60+
physics.add.ground({ width: 20, height: 20 })
61+
62+
// add suzanne (the monkey's name is suzanne)
63+
new GLTFLoader().load('/assets/glb/suzanne.glb', function (gltf) {
64+
// If you can, always use simple shapes like BOX, SPHERE, CONE etc.
65+
// The second most efficient shape is a COMPOUND, which merges multiple simple shapes.
66+
// Prefer HULL over CONVEX MESH.
67+
// HACD is the most expensive but also the most accurate.
68+
// If you need a concave shape, for a static or kinematic body, use CONCAVE MESH.
69+
70+
// (mesh and convex are aliases for convexMesh)
71+
// (concave is an alias for concaveMesh)
72+
// (heightMap uses concaveMesh by default)
73+
// (extrude uses hacd by default)
74+
75+
const suzanne = gltf.scene.children[0]
76+
77+
const shapes = ['box', 'compound', 'hull', 'hacd', 'convexMesh', 'concaveMesh']
78+
79+
const material = new THREE.MeshStandardMaterial({ color: 0xc4c4c4, transparent: true, opacity: 0.7 })
80+
const boxShape = { shape: 'box', width: 2, height: 1.5, depth: 1.25 }
81+
82+
// compound multiple simple shape together
83+
const compoundShape = {
84+
compound: [
85+
// nose
86+
{ shape: 'box', width: 0.5, height: 1, depth: 0.4, y: -0.5, z: 0.5 },
87+
// ears
88+
{ shape: 'box', width: 2.4, height: 0.6, depth: 0.4, z: -0.4, y: 0.2 },
89+
// head back
90+
{ shape: 'sphere', radius: 0.65, z: -0.25, y: 0.35 },
91+
// head front
92+
{ shape: 'box', width: 1.5, height: 0.8, depth: 1, y: 0.2, z: 0.2 }
93+
]
94+
}
95+
96+
suzanne.traverse(child => {
97+
if (child.isMesh && child.material.isMaterial) {
98+
child.material = material
99+
}
100+
})
26101

27-
init() {
28-
this.accessThirdDimension()
29-
}
102+
shapes.forEach((shape, i) => {
103+
const object = new THREE.Object3D()
30104

31-
async create() {
32-
this.third.warpSpeed()
33-
34-
this.third.physics.debug.enable()
35-
36-
// add suzanne (the monkey's name is suzanne)
37-
this.third.load.gltf('/assets/glb/suzanne.glb').then(gltf => {
38-
// If you can, always use simple shapes like BOX, SPHERE, CONE etc.
39-
// The second most efficient shape is a COMPOUND, which merges multiple simple shapes.
40-
// Prefer HULL over CONVEX MESH.
41-
// HACD is the most expensive but also the most accurate.
42-
// If you need a concave shape, for a static or kinematic body, use CONCAVE MESH.
43-
44-
// (mesh and convex are aliases for convexMesh)
45-
// (concave is an alias for concaveMesh)
46-
// (heightMap uses concaveMesh by default)
47-
// (extrude uses hacd by default)
48-
49-
const suzanne = gltf.scene.children[0]
50-
51-
const shapes = ['box', 'compound', 'hull', 'hacd', 'convexMesh', 'concaveMesh']
52-
53-
const material = this.third.add.material({ standard: { color: 0xc4c4c4, transparent: true, opacity: 0.5 } })
54-
const boxShape = { shape: 'box', width: 2, height: 1.5, depth: 1.25 }
55-
56-
// compound multiple simple shape together
57-
const compoundShape = {
58-
compound: [
59-
// nose
60-
{ shape: 'box', width: 0.5, height: 1, depth: 0.4, y: -0.5, z: 0.5 },
61-
// ears
62-
{ shape: 'box', width: 2.4, height: 0.6, depth: 0.4, z: -0.4, y: 0.2 },
63-
// head back
64-
{ shape: 'sphere', radius: 0.65, z: -0.25, y: 0.35 },
65-
// head front
66-
{ shape: 'box', width: 1.5, height: 0.8, depth: 1, y: 0.2, z: 0.2 }
67-
]
68-
}
105+
object.add(suzanne.clone())
106+
object.position.set(i * 3 - 7.5, 1.2, 0)
69107

70-
suzanne.traverse(child => {
71-
if (child.isMesh && child.material.isMaterial) {
72-
child.material = material
73-
}
74-
})
108+
// we se addChildren to false since we do not want
109+
// to create a body from suzanne's child meshes
110+
// (it would create a box 1x1x1 since no matching shape would be found)
111+
let options = { addChildren: false, shape }
75112

76-
shapes.forEach((shape, i) => {
77-
const object = new ExtendedObject3D()
113+
if (shape === 'box') options = { ...options, ...boxShape }
114+
else if (shape === 'compound') options = { ...options, ...compoundShape }
78115

79-
object.add(suzanne.clone())
80-
object.position.set(i * 3 - 7.5, 1.2, 0)
116+
scene.add(object)
117+
physics.add.existing(object, options)
118+
})
119+
})
81120

82-
// we se addChildren to false since we do not want
83-
// to create a body from suzanne's child meshes
84-
// (it would create a box 1x1x1 since no matching shape would be found)
85-
let options = { addChildren: false, shape }
121+
const clock = new THREE.Clock()
86122

87-
if (shape === 'box') options = { ...options, ...boxShape }
88-
else if (shape === 'compound') options = { ...options, ...compoundShape }
123+
const animate = () => {
124+
// update physics
125+
physics.update(clock.getDelta() * 1000)
126+
// update the physics debugger
127+
physics.updateDebugger()
89128

90-
this.third.add.existing(object)
91-
this.third.physics.add.existing(object, options)
92-
})
93-
})
129+
renderer.render(scene, camera)
130+
requestAnimationFrame(animate)
94131
}
132+
requestAnimationFrame(animate)
95133
}
134+
PhysicsLoader('/lib/ammo/moz', () => MainScene())
96135

97-
const config = {
98-
type: Phaser.WEBGL,
99-
transparent: true,
100-
scale: {
101-
mode: Phaser.Scale.FIT,
102-
autoCenter: Phaser.Scale.CENTER_BOTH,
103-
width: window.innerWidth * Math.max(1, window.devicePixelRatio / 2),
104-
height: window.innerHeight * Math.max(1, window.devicePixelRatio / 2)
105-
},
106-
scene: [MainScene],
107-
...Canvas()
108-
}
109-
110-
window.addEventListener('load', () => {
111-
enable3d(() => new Phaser.Game(config)).withPhysics('/lib/ammo/moz')
112-
})
136+
console.log(`three.js version "${THREE.REVISION}"`)
113137
</script>
114138
</body>
115139
</html>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
8+
/>
9+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
10+
<title>Texture Cube</title>
11+
<link rel="stylesheet" href="/css/examples.css?ver=1.0.0" />
12+
<script src="/js/examples.js?ver=1.1.1"></script>
13+
<script src="/lib/enable3d/enable3d.framework.0.25.4.min.js"></script>
14+
</head>
15+
16+
<body>
17+
<div id="info-text">(scene restarts every 5 seconds)</div>
18+
<script>
19+
const { Project, Scene3D, PhysicsLoader, THREE } = ENABLE3D
20+
21+
class MainScene extends Scene3D {
22+
init() {
23+
this.load.preload('side', '/assets/img/box-side.png')
24+
this.load.preload('top', '/assets/img/box-top.png')
25+
this.load.preload('bottom', '/assets/img/box-bottom.png')
26+
}
27+
28+
async create() {
29+
this.warpSpeed('-ground')
30+
31+
// create the texture cube
32+
const leftRight = await this.load.texture('side')
33+
leftRight.encoding = THREE.sRGBEncoding
34+
leftRight.needUpdate = true
35+
// if we clone a texture, we have to manually set needsUpdate to true
36+
const backFront = leftRight.clone()
37+
backFront.needsUpdate = true
38+
const top = await this.load.texture('top')
39+
top.encoding = THREE.sRGBEncoding
40+
top.needUpdate = true
41+
const bottom = await this.load.texture('bottom')
42+
bottom.encoding = THREE.sRGBEncoding
43+
bottom.needUpdate = true
44+
45+
const textureCube = this.misc.textureCube([leftRight, leftRight, top, bottom, backFront, backFront])
46+
47+
textureCube.texture.front.repeat.set(4, 1)
48+
textureCube.texture.back.repeat.set(4, 1)
49+
50+
textureCube.texture.left.repeat.set(1, 1)
51+
textureCube.texture.right.repeat.set(1, 1)
52+
53+
// add the texture cube's materials as a custom material
54+
this.add.box({ width: 4 }, { custom: textureCube.materials })
55+
56+
setTimeout(() => {
57+
this.restart()
58+
}, 5000)
59+
}
60+
}
61+
new Project({ scenes: [MainScene] })
62+
</script>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)