Skip to content

Commit eccbe03

Browse files
Merge pull request #11 from diarmidmackenzie/extend-examples
Extend examples
2 parents 1f53db5 + 52b44ea commit eccbe03

36 files changed

+1557
-407
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
os: [ubuntu-18.04, macos-10.15, windows-2019]
7+
os: [ubuntu-18.04, macos-12, windows-2019]
88
browser: [ChromeHeadless, FirefoxHeadless]
99
runs-on: ${{ matrix.os }}
1010
steps:

AmmoDriver.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ An `ammo-body` component may be added to any entity in a scene. While having onl
127127
| collisionFilterGroup | `1` | 32-bit bitmask to determine what collision "group" this object belongs to. See: [Collision Filtering](#collision-filtering). |
128128
| collisionFilterMask | `1` | 32-bit bitmask to determine what collision "groups" this object should collide with. See: [Collision Filtering](#collision-filtering). |
129129
| scaleAutoUpdate | `true` | Should the shapes of the objecct be automatically scaled to match the scale of the entity. |
130+
| restitution | 0 | Coefficient of restitution (bounciness). Note that this must be set to a non-zero value on *both* objects to get bounce from a collision.<br/>This value cannot be changed after initialization of the `ammo-body`. |
130131

131132
#### `ammo-body` type
132133

CannonDriver.md

Lines changed: 297 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 86 additions & 268 deletions
Large diffs are not rendered by default.

dist/aframe-physics-system.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15780,7 +15780,11 @@ module.exports = AFRAME.registerComponent("ammo-constraint", {
1578015780

1578115781
// An axis that each body can rotate around, defined locally to that body. Used for hinge constraints.
1578215782
axis: { type: "vec3", default: { x: 0, y: 0, z: 1 } },
15783-
targetAxis: { type: "vec3", default: { x: 0, y: 0, z: 1 } }
15783+
targetAxis: { type: "vec3", default: { x: 0, y: 0, z: 1 } },
15784+
15785+
// damping & stuffness - used for spring contraints only
15786+
damping: { type: "number", default: 1 },
15787+
stiffness: { type: "number", default: 100 },
1578415788
},
1578515789

1578615790
init: function() {
@@ -15848,7 +15852,20 @@ module.exports = AFRAME.registerComponent("ammo-constraint", {
1584815852
}
1584915853
case CONSTRAINT.SPRING: {
1585015854
constraint = new Ammo.btGeneric6DofSpringConstraint(body, targetBody, bodyTransform, targetTransform, true);
15851-
//TODO: enableSpring, setStiffness and setDamping
15855+
15856+
// Very limited initial implementation of spring constraint.
15857+
// See: https://github.com/n5ro/aframe-physics-system/issues/171
15858+
for (var i in [0,1,2,3,4,5]) {
15859+
constraint.enableSpring(1, true)
15860+
constraint.setStiffness(1, this.data.stiffness)
15861+
constraint.setDamping(1, this.data.damping)
15862+
}
15863+
const upper = new Ammo.btVector3(-1, -1, -1);
15864+
const lower = new Ammo.btVector3(1, 1, 1);
15865+
constraint.setLinearUpperLimit(upper);
15866+
constraint.setLinearLowerLimit(lower)
15867+
Ammo.destroy(upper);
15868+
Ammo.destroy(lower);
1585215869
break;
1585315870
}
1585415871
case CONSTRAINT.SLIDER: {
@@ -15972,7 +15989,8 @@ let AmmoBody = {
1597215989
disableCollision: { default: false },
1597315990
collisionFilterGroup: { default: 1 }, //32-bit mask,
1597415991
collisionFilterMask: { default: 1 }, //32-bit mask
15975-
scaleAutoUpdate: { default: true }
15992+
scaleAutoUpdate: { default: true },
15993+
restitution: {default: 0} // does not support updates
1597615994
},
1597715995

1597815996
/**
@@ -16012,6 +16030,7 @@ let AmmoBody = {
1601216030
return function() {
1601316031
const el = this.el,
1601416032
data = this.data;
16033+
const clamp = (num, min, max) => Math.min(Math.max(num, min), max)
1601516034

1601616035
this.localScaling = new Ammo.btVector3();
1601716036

@@ -16041,6 +16060,7 @@ let AmmoBody = {
1604116060
this.compoundShape,
1604216061
this.localInertia
1604316062
);
16063+
this.rbInfo.m_restitution = clamp(this.data.restitution, 0, 1);
1604416064
this.body = new Ammo.btRigidBody(this.rbInfo);
1604516065
this.body.setActivationState(ACTIVATION_STATES.indexOf(data.activationState) + 1);
1604616066
this.body.setSleepingThresholds(data.linearSleepingThreshold, data.angularSleepingThreshold);
@@ -16236,6 +16256,10 @@ let AmmoBody = {
1623616256
Ammo.destroy(angularFactor);
1623716257
}
1623816258

16259+
if (prevData.restitution != data.restitution ) {
16260+
console.warn("ammo-body restitution cannot be updated from its initial value.")
16261+
}
16262+
1623916263
//TODO: support dynamic update for other properties
1624016264
}
1624116265
},

dist/aframe-physics-system.min.js

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

examples/README.md

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,17 @@
33
To help demonstrate the features and capabilities of `aframe-physics-system`
44
the following collection of examples have been prepared.
55

6-
- [**Ammo sandbox**](ammo.html)
7-
Demonstration of many [Ammo driver](../AmmoDriver.md) features in a single
8-
example.
6+
Examples marked "Broken" do not currently function as expected, due to open bugs.
7+
Examples marked "Limited" have limitations in terms of what function can be exercised (e.g. due to constraints on mouse interaction, or limitations with particular driver implementations)
8+
9+
| Example | Cannon | Cannon Worker | Ammo |
10+
| ------------------------------------------------------------ | -------------------------------------- | ------------------------------------------------------ | ---------------------------------------- |
11+
| Demonstration of many features in a single example. | [**OK**](cannon/sandbox.html) | [**Broken**](cannon-worker/sandbox.html) | [**OK**](ammo/sandbox.html) |
12+
| Construct a [compound shape](../README.md#shape) and simulate collision with a ground plane. | [**OK**](cannon/compound.html) | [**Broken**](cannon-worker/compound.html) | [**OK**](ammo/compound.html) |
13+
| Demonstration of many constraints including cone twist, hinge, lock, point to point, slider (Ammo only) and distance (Cannon only) constraints. | [**OK**](cannon/constraints.html) | [**Broken**](cannon-worker/constraints.html) | [**OK**](ammo/constraints.html) |
14+
| Bounce simulation with [restitution (bounciness)](../README.md#system-configuration) of 1. | [**OK**](cannon/materials.html) | [**Limited**](cannon-worker/materials.html) | [**OK**](ammo/materials.html) |
15+
| Four vertical [springs](../README.md#spring) each between two boxes with an assortment of damping and stiffness values | [**OK**](cannon/spring.html) | [**OK**](cannon-worker/spring.html) | [**Limited**](ammo/spring.html) |
16+
| Apply [strong impulse](../README.md#using-the-cannonjs-api) to a cube when the user clicks with a mouse. Cubes are arranged in four 4x3 walls. | [**OK**](cannon/stress.html) | [**Limited**](cannon-worker/stress.html) | [**OK**](ammo/stress.html) |
17+
| Animate a long wall moving along the z-axis along the initial view direction. | [**OK**](cannon/sweeper.html) | [**Broken**](cannon-worker/sweeper.html) | [**OK**](ammo/sweeper.html) |
18+
| Remove a [dynamic body](../README.md#dynamic-body-and-static-body) from the scene after 100 frames | [**OK**](cannon/ttl.html) | [**Broken**](cannon-worker/ttl.html) | [**OK**](ammo/ttl.html) |
919

10-
- [**Cannon.js sandbox**](cannon.html)
11-
Demonstration of many Cannon driver features in a single example.
12-
13-
- [**Compound**](compound.html)
14-
Construct a [compound shape](../README.md#shape) and simulate collision with
15-
a ground plane using the Cannon driver.
16-
17-
- [**Constraints with Ammo**](constraints-ammo.html)
18-
Demonstration of many
19-
[Ammo driver constraints](../AmmoDriver.md#ammo-constraint) including cone
20-
twist, hinge, lock, point to point, and slider constraints.
21-
22-
- [**Constraints with Cannon**](constraints.html)
23-
Demonstration of many
24-
[Cannon driver constraints](../README.md#constraint) including cone twist,
25-
hinge, lock, point to point, and distance constraints.
26-
27-
- [**Materials**](materials.html)
28-
Bounce simulation with
29-
[restitution (bounciness)](../README.md#system-configuration) of 1 using the
30-
Cannon driver.
31-
32-
- [**Spring**](spring.html)
33-
Four vertical [springs](../README.md#spring) each between two boxes with an
34-
assortment of damping and stiffness values using the Cannon driver.
35-
36-
- [**Stress**](stress.html)
37-
Apply [strong impulse](../README.md#using-the-cannonjs-api) to a cube when the
38-
user clicks with a mouse using the Cannon driver. Cubes are arranged in four
39-
4x3 walls.
40-
41-
- [**Sweeper**](sweeper.html)
42-
Animate a long wall moving along the z-axis along the initial view direction
43-
using the velocity component and the Cannon driver.
44-
45-
- [**Time to live**](ttl.html)
46-
Remove a [dynamic body](../README.md#dynamic-body-and-static-body) from the
47-
scene after 100 frames using the Cannon driver.

examples/ammo/compound.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
6+
<title>Examples • Compound AMMO</title>
7+
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
8+
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script>
9+
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
10+
<script src="../../dist/aframe-physics-system.js"></script>
11+
<script src="../components/force-pushable.js"></script>
12+
<script src="../components/grab.js"></script>
13+
<link rel="stylesheet" href="../styles.css">
14+
</head>
15+
<body>
16+
<div class="text-overlay">
17+
<p>Compound shape, using the Ammo driver.</p>
18+
<p>Click when the red reticle is over the sphere to apply a force to it.</p>
19+
</div>
20+
<a class="code-link"
21+
target="_blank"
22+
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/ammo/compound.html">
23+
view code
24+
</a>
25+
<a-scene environment physics="driver: ammo; debug: true;">
26+
<!-- Player -->
27+
<a-entity camera look-controls wasd-controls position="0 1.6 0">
28+
<a-entity cursor
29+
raycaster="objects:[force-pushable]"
30+
position="0 0 -0.5"
31+
geometry="primitive: circle; radius: 0.01; segments: 4;"
32+
material="color: #FF4444; shader: flat"></a-entity>
33+
</a-entity>
34+
<a-entity id="left-hand" ammo-body="type: kinematic; emitCollisionEvents: true" ammo-shape="type: sphere; fit: manual; sphereRadius: 0.02;"
35+
hand-controls="hand: left" grab></a-entity>
36+
<a-entity id="right-hand" ammo-body="type: kinematic; emitCollisionEvents: true" ammo-shape="type: sphere; fit: manual; sphereRadius: 0.02;"
37+
hand-controls="hand: right" grab></a-entity>
38+
39+
<!-- Terrain -->
40+
<a-box width="75" height="0.1" depth="75" ammo-body="type: static" ammo-shape visible="false"></a-box>
41+
42+
<!-- Blocks -->
43+
<a-sphere radius="0.25" position="0 4 -2" color="red"
44+
ammo-body="type: dynamic; shape: none; mass: 5;"
45+
ammo-shape__main="type: cylinder;
46+
fit: manual;
47+
halfExtents: 0.24 0.18 0.24;
48+
cylinderAxis: y"
49+
ammo-shape__handle="type: box;
50+
fit: manual;
51+
halfExtents: 0.15 0.18 0.04;
52+
offset: 0.4 0 0;"
53+
force-pushable
54+
></a-sphere>
55+
</a-scene>
56+
</body>
57+
</html>

examples/constraints-ammo.html renamed to examples/ammo/constraints.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@
44
<meta http-equiv="X-UA-Compatible" content="IE=edge">
55
<meta http-equiv="content-type" content="text/html; charset=utf-8">
66
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
7-
<title>Examples • Constraints • AmmoDriver</title>
7+
<title>Examples • Constraints • AMMO</title>
88
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
99
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
1010
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script>
1111
<script src="https://cdn.jsdelivr.net/gh/fernandojsg/aframe-teleport-controls@master/dist/aframe-teleport-controls.min.js"></script>
12-
<script src="../dist/aframe-physics-system.js"></script>
13-
<link rel="stylesheet" href="styles.css">
12+
<script src="../../dist/aframe-physics-system.js"></script>
13+
<script src="../components/force-pushable.js"></script>
14+
<link rel="stylesheet" href="../styles.css">
1415
</head>
1516
<body>
1617
<div class="text-overlay">
1718
<p>Demonstration of many Ammo driver constraints including cone
1819
twist, hinge, lock, point to point, and slider constraints.</p>
20+
<p>Click when the red reticle is over a red object to apply a force to it.</p>
21+
<p>There seem to be problems with the slider constraint - to be investigated.</p>
1922
</div>
2023
<a class="code-link"
2124
target="_blank"
22-
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/consraints-ammo.html">
25+
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/ammo/constraints.html">
2326
view code
2427
</a>
2528
<a-scene environment physics="driver: ammo; debug: true">
2629
<a-entity id="cameraRig">
27-
<a-camera></a-camera>
30+
<a-entity camera look-controls wasd-controls position="0 1.6 0">
31+
<a-entity cursor
32+
raycaster="objects:[force-pushable]"
33+
position="0 0 -0.5"
34+
geometry="primitive: circle; radius: 0.01; segments: 4;"
35+
material="color: #FF4444; shader: flat"></a-entity>
36+
</a-entity>
2837
<a-entity teleport-controls="cameraRig: #cameraRig; button: trigger; type: line"
2938
ammo-body="type: kinematic"
3039
ammo-shape="type: box; halfExtents: 0.05 0.1 0.1; fit: manual;"
@@ -45,6 +54,7 @@
4554
</a-sphere>
4655
<a-box width="0.25" height="0.25" depth="0.25" color="#F00"
4756
ammo-body ammo-shape
57+
force-pushable
4858
ammo-constraint="type: coneTwist;
4959
target: #conetwist-target;
5060
pivot: 0.13 0 0.0;
@@ -62,6 +72,7 @@
6272
color="#F00"
6373
scale="0.25 0.25 0.25"
6474
ammo-body ammo-shape
75+
force-pushable
6576
ammo-constraint="type: hinge;
6677
target: #hinge-target;
6778
axis: 0 1 0;
@@ -85,6 +96,7 @@
8596
position="0 1.25 0"
8697
scale="0.25 0.25 0.25"
8798
ammo-body ammo-shape
99+
force-pushable
88100
ammo-constraint="type: lock; target: #lock-target">
89101
</a-box>
90102
</a-entity>
@@ -101,6 +113,7 @@
101113
<a-box color="#F00"
102114
scale="0.25 0.25 0.25"
103115
ammo-body ammo-shape
116+
force-pushable
104117
ammo-constraint="type: pointToPoint;
105118
target: #pointtopoint-target;
106119
pivot: -0.125 -0.125 0.125;
@@ -121,6 +134,7 @@
121134
radius="0.125"
122135
position="0 1 0"
123136
ammo-body ammo-shape
137+
force-pushable
124138
ammo-constraint="type: slider; target: #slider-target">
125139
</a-sphere>
126140
<a-cylinder radius="0.05" height="2" position="0 1 0" rotation="0 0 90"></a-cylinder>

examples/ammo/materials.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
6+
<title>Examples • Materials AMMO</title>
7+
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
8+
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script>
9+
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
10+
<script src="../../dist/aframe-physics-system.js"></script>
11+
<script src="../components/force-pushable.js"></script>
12+
<script src="../components/grab.js"></script>
13+
<link rel="stylesheet" href="../styles.css">
14+
</head>
15+
<body>
16+
<div class="text-overlay">
17+
<p>Bounce simulation with restitution (bounciness) of 1 using the Ammo driver.</p>
18+
<p>Ball seems to bounce off to the left after a couple of bounces. Not understood why - inaccuracy in physics simulation, perhaps?</p>
19+
</div>
20+
<a class="code-link"
21+
target="_blank"
22+
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/ammo/materials.html">
23+
view code
24+
</a>
25+
<a-scene stats="true"
26+
environment
27+
physics="driver: ammo; restitution: 1">
28+
<a-entity camera look-controls wasd-controls position="0 1.6 0">
29+
<a-entity cursor
30+
raycaster="objects:[force-pushable]"
31+
position="0 0 -0.5"
32+
geometry="primitive: circle; radius: 0.01; segments: 4;"
33+
material="color: #FF4444; shader: flat"></a-entity>
34+
</a-entity>
35+
<a-entity id="left-hand" ammo-body="type: kinematic; emitCollisionEvents: true" ammo-shape="type: sphere; fit: manual; sphereRadius: 0.02;"
36+
hand-controls="hand: left" grab></a-entity>
37+
<a-entity id="right-hand" ammo-body="type: kinematic; emitCollisionEvents: true" ammo-shape="type: sphere; fit: manual; sphereRadius: 0.02;"
38+
hand-controls="hand: right" grab></a-entity>
39+
40+
<!-- Terrain -->
41+
<a-box width="75" height="0.1" depth="75" ammo-body="type: static; restitution:1" ammo-shape visible="false"></a-box>
42+
43+
<!-- Blocks -->
44+
<a-sphere radius="0.25" position="0 4 -2" color="red" ammo-body="restitution:1" ammo-shape force-pushable></a-sphere>
45+
</a-scene>
46+
</body>
47+
</html>

examples/ammo.html renamed to examples/ammo/sandbox.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Examples • AmmoDriver</title>
4+
<title>Examples • AMMO</title>
55
<meta name="description" content="Hello, WebVR! - A-Frame" />
66
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
77
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
8-
<script src="../dist/aframe-physics-system.js"></script>
9-
<link rel="stylesheet" href="styles.css">
8+
<script src="../../dist/aframe-physics-system.js"></script>
9+
<link rel="stylesheet" href="../styles.css">
1010
<script>
1111
AFRAME.registerComponent("bounce", {
1212
init: function() {
@@ -61,7 +61,7 @@
6161
</div>
6262
<a class="code-link"
6363
target="_blank"
64-
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/ammo.html">
64+
href="https://github.com/c-frame/aframe-physics-system/blob/master/examples/ammo/sandbox.html">
6565
view code
6666
</a>
6767
<a-scene physics="driver: ammo; debug: true; gravity: -9.8; debugDrawMode: 1">
@@ -92,7 +92,7 @@
9292
ammo-shape="type: sphere;"
9393
></a-sphere>
9494
<a-cone
95-
position="0 3.75 -4"
95+
position="-1 3.75 -4"
9696
radius-bottom="1.25"
9797
color="green"
9898
shadow

0 commit comments

Comments
 (0)