forked from n5ro/aframe-physics-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathammo.html
166 lines (164 loc) · 4.43 KB
/
ammo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<title>Examples • AmmoDriver</title>
<meta name="description" content="Hello, WebVR! - A-Frame" />
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
<script src="../dist/aframe-physics-system.js"></script>
<script>
AFRAME.registerComponent("bounce", {
init: function() {
this.direction = 1;
this.position = new THREE.Vector3();
this.position.copy(this.el.object3D.position);
setTimeout(() => {
this.ready = true;
}, 3000);
},
tick: function() {
if (!this.ready) return;
var position = this.el.object3D.position.y;
if (position <= 0) {
this.direction = 1;
} else if (position >= 5) {
this.direction = -1;
}
this.el.object3D.position.set(this.position.x, position + 0.05 * this.direction, this.position.z);
}
});
AFRAME.registerComponent("changescale", {
init: function() {
this.direction = 1;
setTimeout(() => {
this.ready = true;
}, 3000);
},
tick: function() {
if (!this.ready) return;
var scale = this.el.object3D.scale;
if (scale.x <= 0.05) {
this.direction = 1;
} else if (scale.x >= 1) {
this.direction = -1;
}
this.el.object3D.scale.set(
scale.x + this.direction * 0.01,
scale.y + this.direction * 0.01,
scale.z + this.direction * 0.01
);
}
});
</script>
</head>
<body>
<a-scene physics="driver: ammo; debug: true; gravity: -9.8; debugDrawMode: 1">
<a-camera near="0.001"></a-camera>
<a-box
position="-1 5 -5"
rotation="0 45 0"
color="#4CC3D9"
shadow
ammo-body
ammo-shape="type: box; halfExtents: 0.6 0.6 0.6; fit: manual;"
></a-box>
<a-box
id="target"
position="1 3.75 -4"
rotation="0 45 0"
color="purple"
shadow
ammo-body
ammo-shape="type: box;"
></a-box>
<a-sphere
position="0 10 -10"
radius="1.25"
color="#EF2D5E"
shadow
ammo-body
ammo-shape="type: sphere;"
></a-sphere>
<a-cone
position="0 3.75 -4"
radius-bottom="1.25"
color="green"
shadow
bounce
ammo-body="type: kinematic; addCollideEventListener: true; disableCollision: true;"
ammo-shape="type: cone;"
ammo-constraint="target: #target;"
></a-cone>
<a-torus
position="-1 3.75 -7"
radius="1.25"
scale="0.5 0.5 0.5"
color="red"
shadow
ammo-body
ammo-shape="type: capsule; cylinderAxis: z;"
changescale
></a-torus>
<a-torus-knot
position="0 3.75 -5"
radius="1.25"
scale="0.5 0.5 0.5"
color="blue"
shadow
ammo-body="addCollideEventListener: false;"
ammo-shape
></a-torus-knot>
<a-cylinder
segments-height="1"
segments-radial="10"
position="1 4.0 -5"
radius="0.5"
height="1.5"
color="#FFC65D"
shadow
ammo-body
ammo-shape="type: cylinder"
></a-cylinder>
<a-plane
position="0 2 -4"
rotation="90 0 0"
width="1"
height="1"
color="#7BC8A4"
shadow
ammo-body="type: static; mass: 0;"
ammo-shape="type: box;"
></a-plane>
<a-torus-knot
position="0 0 -7"
radius="1.25"
scale="5 0.1 5"
rotation="0 90 0"
color="#7BC8A4"
shadow
ammo-body="type: static; mass: 0;"
ammo-shape="type: mesh;"
></a-torus-knot>
<!-- HACD and VHACD are slow -->
<!-- <a-torus-knot
position="-2 1.5 -1"
rotation="0 90 90"
scale="0.5 0.5 0.5"
color="red"
shadow
ammo-body
ammo-shape="type: hacd;"
></a-torus-knot>
<a-torus-knot
position="2 1.5 -1"
rotation="0 90 90"
scale="0.5 0.5 0.5"
color="blue"
shadow
ammo-body
ammo-shape="type: vhacd;"
></a-torus-knot> -->
<a-sky color="#000000"></a-sky>
</a-scene>
</body>
</html>