Skip to content

Commit c308171

Browse files
committed
updated physics
1 parent 5f1b0b3 commit c308171

File tree

9 files changed

+6729
-64
lines changed

9 files changed

+6729
-64
lines changed

build/whs.js

Lines changed: 1120 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/whs.module.js

Lines changed: 1120 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/assets/ammo.js

Lines changed: 17 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/assets/physics-module.js

Lines changed: 4430 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/design/easter/script.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ document.body.addEventListener('mousemove', (e) => {
239239
});
240240

241241
document.body.addEventListener('click', () => {
242-
rabbit.setLinearVelocity(new THREE.Vector3(0, 5, 0));
243-
egg.setAngularVelocity(new THREE.Vector3(0, 10, 0));
244-
egg2.setAngularVelocity(new THREE.Vector3(0, -10, 0));
245-
egg3.setAngularVelocity(new THREE.Vector3(0, -10, 0));
246-
egg4.setAngularVelocity(new THREE.Vector3(0, 10, 0));
247-
egg5.setAngularVelocity(new THREE.Vector3(0, -10, 0));
248-
egg6.setAngularVelocity(new THREE.Vector3(0, -10, 0));
249-
egg7.setAngularVelocity(new THREE.Vector3(0, 10, 0));
250-
egg8.setAngularVelocity(new THREE.Vector3(0, -10, 0));
251-
egg9.setAngularVelocity(new THREE.Vector3(0, -10, 0));
242+
rabbit.use('physics').setLinearVelocity(new THREE.Vector3(0, 5, 0));
243+
egg.use('physics').setAngularVelocity(new THREE.Vector3(0, 10, 0));
244+
egg2.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
245+
egg3.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
246+
egg4.use('physics').setAngularVelocity(new THREE.Vector3(0, 10, 0));
247+
egg5.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
248+
egg6.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
249+
egg7.use('physics').setAngularVelocity(new THREE.Vector3(0, 10, 0));
250+
egg8.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
251+
egg9.use('physics').setAngularVelocity(new THREE.Vector3(0, -10, 0));
252252
});

examples/softbody/cloth2/script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ const arm = new WHS.Box({ // Rigidbody (green).
8181
});
8282

8383
arm.addTo(app);
84-
cloth.addTo(app).then(() => {
85-
cloth.appendAnchor(arm, 0, 1, false);
86-
cloth.appendAnchor(arm, 20, 1, false);
84+
cloth.addTo(app).then(object => object.use('physics')).then(physics => {
85+
physics.appendAnchor(arm, 0, 1, false);
86+
physics.appendAnchor(arm, 20, 1, false);
8787
});
8888

8989
new WHS.Box({ // Rigidbody (green).

examples/softbody/cloth3/script.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ const arm = new WHS.Box({ // Rigidbody (green).
7979
});
8080

8181
arm.addTo(app);
82-
cloth.addTo(app).then(() => {
83-
cloth.appendAnchor(arm, 0, 1, false);
84-
cloth.appendAnchor(arm, 40, 1, false);
82+
cloth.addTo(app).then(object => object.use('physics')).then(physics => {
83+
physics.appendAnchor(arm, 0, 1, false);
84+
physics.appendAnchor(arm, 40, 1, false);
8585
});
8686

8787
new WHS.Box({ // Rigidbody (green).
@@ -106,7 +106,7 @@ new WHS.Box({ // Rigidbody (green).
106106
}
107107
}).addTo(app).then(box => {
108108
mouse.on('move', () => {
109-
box.setLinearVelocity(mouse.project().sub(box.position));
109+
box.use('physics').setLinearVelocity(mouse.project().sub(box.position));
110110
});
111111
});
112112

examples/softbody/ropes/script.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ new WHS.Tube({
8383
material: tubeMaterial
8484
}).addTo(app);
8585

86+
const envCamera = new THREE.CubeCamera(1, 100000, 128);
87+
8688
const sphere = new WHS.Sphere({
8789
geometry: {
8890
radius: 3,
@@ -96,8 +98,11 @@ const sphere = new WHS.Sphere({
9698
})
9799
],
98100

99-
material: new THREE.MeshBasicMaterial({
100-
color: 0xffffff
101+
material: new THREE.MeshStandardMaterial({
102+
color: 0xffffff,
103+
metalness: 0.8,
104+
roughness: 0,
105+
envMap: envCamera.renderTarget.texture
101106
}),
102107

103108
position: {
@@ -107,13 +112,15 @@ const sphere = new WHS.Sphere({
107112
}
108113
});
109114

115+
sphere.native.add(envCamera);
116+
110117
const sphereHandler = [];
111-
const blackBasic = new THREE.MeshBasicMaterial({color: 0x000000});
118+
const blackBasic = new THREE.MeshBasicMaterial({color: 0xffffff});
112119

113120
for (let i = 0; i < 5; i++) {
114-
const sc = sphere.clone();
121+
const sc = sphere.clone(false, true);
115122
sc.position.x = -20 + i * 6;
116-
sc.material = sc.material.clone();
123+
// sc.material = sc.material.clone();
117124
sc.addTo(app);
118125
sphereHandler.push(sc);
119126

@@ -122,10 +129,7 @@ for (let i = 0; i < 5; i++) {
122129
v2.y = 30;
123130

124131
const rope = new WHS.Line({
125-
geometry: {
126-
curve: new THREE.LineCurve3(v1, v2)
127-
},
128-
132+
curve: new THREE.LineCurve3(v1, v2),
129133
material: blackBasic,
130134

131135
modules: [
@@ -137,9 +141,9 @@ for (let i = 0; i < 5; i++) {
137141
]
138142
});
139143

140-
rope.addTo(app).then(() => {
141-
rope.appendAnchor(toptube, 50, 1);
142-
rope.appendAnchor(sc, 0, 1);
144+
rope.addTo(app).then(object => object.use('physics')).then(physics => {
145+
physics.appendAnchor(toptube, 50, 1);
146+
physics.appendAnchor(sc, 0, 1);
143147
});
144148
}
145149

@@ -156,9 +160,7 @@ const sphereStart = new WHS.Sphere({
156160
})
157161
],
158162

159-
material: new THREE.MeshBasicMaterial({
160-
color: 0xffffff
161-
}),
163+
material: sphere.material.clone(),
162164

163165
position: {
164166
x: 25,
@@ -171,10 +173,7 @@ sphereStart.addTo(app);
171173
sphereHandler.push(sphereStart);
172174

173175
const rope1 = new WHS.Line({
174-
geometry: {
175-
curve: new THREE.LineCurve3(sphereStart.position.clone(), new THREE.Vector3(10, 30, 0))
176-
},
177-
176+
curve: new THREE.LineCurve3(sphereStart.position.clone(), new THREE.Vector3(10, 30, 0)),
178177
material: blackBasic,
179178

180179
modules: [
@@ -186,9 +185,9 @@ const rope1 = new WHS.Line({
186185
]
187186
});
188187

189-
rope1.addTo(app).then(() => {
190-
rope1.appendAnchor(toptube, 50, 1);
191-
rope1.appendAnchor(sphereStart, 0, 1);
188+
rope1.addTo(app).then(object => object.use('physics')).then(physics => {
189+
physics.appendAnchor(toptube, 50, 1);
190+
physics.appendAnchor(sphereStart, 0, 1);
192191
});
193192

194193
new WHS.Plane({
@@ -236,6 +235,7 @@ new WHS.AmbientLight({
236235
}).addTo(app);
237236

238237
app.start();
238+
new WHS.AmbientLight({intensity: 0.8}).addTo(app);
239239

240240
// Check mouse.
241241

@@ -264,6 +264,6 @@ for (let i = 0, max = sphereHandler.length; i < max; i++) {
264264
});
265265

266266
mouse.on('move', () => {
267-
if (dragged) nows.setLinearVelocity(mouse.project().sub(nows.position).multiplyScalar(3));
267+
if (dragged) nows.use('physics').setLinearVelocity(mouse.project().sub(nows.position).multiplyScalar(3));
268268
});
269269
}

gulp/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ export const getTemplateData = ({devPhysics = false, devMode = false} = {devPhys
33
assets: '\'../../assets\'',
44
devMode,
55

6-
physicsModule: devPhysics
6+
physicsModule: !isNaN(Number(devPhysics))
77
? `http://localhost:${devPhysics}/physics-module.js`
88
: '../../assets/physics-module.js',
99

10-
ammojs: devPhysics
10+
ammojs: !isNaN(Number(devPhysics))
1111
? `'http://localhost:${devPhysics}/vendor/ammo.js'`
1212
: 'window.location.href + \'../../assets/ammo.js\''
1313
});

0 commit comments

Comments
 (0)