-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-4.html
70 lines (57 loc) · 2.47 KB
/
ex-4.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="lib/aframe.min.js"></script>
<script src="lib/aframe-physics-system.min.js"></script>
<!--https://aframe.io/examples/showcase/shopping/ -->
</head>
<body>
<a-scene physics="debug: true; gravity: -9.8;" vr-mode-ui="enabled: false">
<a-assets>
<a-asset-item id="duck" src="glTF-Sample-Models-master/1.0/Duck/glTF-Binary/Duck.glb"></a-asset-item>
</a-assets>
<a-entity id="physDuck"
position="0 4 -4"
dynamic-body="shape: box; mass: 2"
gltf-model="#duck"></a-entity>
<!--
<a-box id="box"
color="#9932cc"
position="0 4 -4"
dynamic-body="shape: box; mass: 2"></a-box> -->
<a-plane position="0 -1.1 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4" static-body></a-plane>
<!-- <a-box id="plane"
position="0 -0.5 -4"
color="#7BC8A4"
dynamic-body="shape: box; mass: 2"></a-box> -->
<a-sphere radius="1.25"
position="0 2 -4"
color="#EF2D5E"
dynamic-body="mass: 10"></a-sphere>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
<script>
var sceneEl = document.querySelector('a-scene');
document.addEventListener('click', function() {
console.log("click");
var el = sceneEl.querySelector('#physDuck');
el.body.applyImpulse(
/* impulse */ new CANNON.Vec3(2, 0, 0),
/* world position */ new CANNON.Vec3().copy(el.getAttribute('position'))
);
});
// var el = sceneEl.querySelector('#box');
// var plane = sceneEl.querySelector('#plane');
// var hinge = new CANNON.HingeConstraint(el.body, plane.body, {pivotA: new CANNON.Vec3(0,-0.5,0.5),
// axisA: new CANNON.Vec3(1,0,0),
// pivotB: new CANNON.Vec3(0, 0.5, 0.5),
// axisB: new CANNON.Vec3(1,0,0) });
// console.log(el.body);
// console.log(sceneEl.systems.physics.addConstraint(hinge));
</script>
</body>
</html>