Skip to content

Commit 676dfc6

Browse files
Include desktop keys example
1 parent a6b5f15 commit 676dfc6

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ npm-debug.log
55
README.html
66
.bashcommands
77
firefox/
8-
CNAME
9-
examples/physics/index-ammo-keys.html
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<html>
2+
<head>
3+
<title>A-Frame Super Hands Component - 6DOF With Physics (Ammo.js Engine)</title>
4+
<!-- Replace "../build.js" with the super-hands and
5+
A-Frame distributions to run : -->
6+
<!--<script src="../build.js"></script>-->
7+
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
8+
<script src="../../dist/super-hands.js"></script>
9+
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
10+
<script src="https://cdn.jsdelivr.net/gh/n5ro/[email protected]/dist/aframe-physics-system.js"></script>
11+
<script src="https://unpkg.com/aframe-event-set-component@^4.1.1/dist/aframe-event-set-component.min.js"></script>
12+
<!--version of a-frame-environment-component previously specified is incompatible with A-Frame 1.2.0
13+
due to three.js changes-->
14+
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script>
15+
<script src="https://cdn.jsdelivr.net/gh/diarmidmackenzie/[email protected]/key-bindings.min.js"></script>
16+
<script src="https://cdn.jsdelivr.net/gh/diarmidmackenzie/[email protected]/src/keyboard-hand-controls.min.js"></script>
17+
<script>
18+
//color randomizer
19+
// updated to act based on collisions rather than an object being dropped
20+
// due to current limitation with aframe-physics-system when using the
21+
// Ammo.js physics engine.
22+
AFRAME.registerComponent('color-randomizer', {
23+
play: function () {
24+
this.el.addEventListener('collidestart', function (evt) {
25+
evt.detail.targetEl.setAttribute('material', 'color',
26+
'#'+(Math.random()*0xFFFFFF<<0).toString(16))
27+
// color randomizer credit: http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript#comment6801353_5365036
28+
})
29+
}
30+
})
31+
// turn controller's physics presence on only while button held down
32+
AFRAME.registerComponent('phase-shift', {
33+
init: function () {
34+
var el = this.el
35+
el.addEventListener('gripdown', function () {
36+
el.setAttribute('ammo-body', {disableCollision: false})
37+
})
38+
el.addEventListener('gripup', function () {
39+
el.setAttribute('ammo-body', {disableCollision: true})
40+
})
41+
}
42+
})
43+
</script>
44+
<link rel="stylesheet" type="text/css" href="../assets/examples.css">
45+
</head>
46+
<body>
47+
<!-- <button id="replayer-button" type="button" onclick="playDemoRecording()">
48+
Don't have roomscale VR handy? Click here for a preview.
49+
</button> -->
50+
<a-scene environment="preset: tron; shadow: true" physics="driver: ammo; debug: true; debugDrawMode: 1">
51+
<a-assets>
52+
<img id="portals-preview" src="../assets/hand-controls.jpg"></img>
53+
<img id="colortransform" src="./colortransform-ammo.png" />
54+
<a-mixin id="cube" geometry="primitive: box; width: 0.33; height: 0.33; depth: 0.33"
55+
hoverable
56+
grabbable="constraintComponentName: ammo-constraint;"
57+
stretchable draggable
58+
event-set__hoveron="_event: hover-start; material.opacity: 0.7; transparent: true"
59+
event-set__hoveroff="_event: hover-end; material.opacity: 1; transparent: false"
60+
ammo-body="type: dynamic" ammo-shape="type: box"
61+
shadow></a-mixin>
62+
<!--In the original example, shapes could be dropped through this.
63+
This required a shape which could trigger collisions, but would not
64+
prevent shapes passing through.
65+
With CANNON physics, that was achieved by setting collisionForces: false
66+
As of today, there is no equivalent function in the Ammo physics engine.
67+
It looks as though the underlying physics engine could support this
68+
if a shape was instantiated, without a body. But the current implementation
69+
of aframe-physics-system with Ammo.js assumes there is always a body.-->
70+
71+
<a-mixin id="transformer" color-randomizer droppable
72+
event-set__dragon="_event: dragover-start; material.wireframe: true"
73+
event-set__dragoff="_event: dragover-end; material.wireframe: false"
74+
geometry="primitive: box; width: 0.5; height: 0.5; depth: 0.5"
75+
ammo-body="type: static; emitCollisionEvents: true" ammo-shape="type: box"></a-mixin>
76+
<a-mixin id="touch"
77+
physics-collider phase-shift
78+
ammo-body="type: kinematic; emitCollisionEvents: true; disableCollision: true"
79+
ammo-shape="fit: manual; type:sphere; sphereRadius: 0.02"
80+
super-hands="colliderEvent: collidestart;
81+
colliderEventProperty: targetEl;
82+
colliderEndEvent: collideend;
83+
colliderEndEventProperty: targetEl">
84+
</a-mixin>
85+
</a-assets>
86+
<a-entity>
87+
<a-text value="Press Left Shift or Right Shift to choose a controller.\n
88+
Press C or V to select Thumbstick x or y,\n
89+
then -/= to move in that direction.\n
90+
Also, use 4/5/6 to re-orient controller\n
91+
to test effect of thumbstick moves\n
92+
at different orientations."
93+
position="-7 1 -5" color="grey"></a-text>
94+
95+
<a-camera position="0 1.6 0">
96+
<a-text id="log-panel1" wrapCount=80 width="1" value="L Hand Keyboard Sim Data" position="-1.5 .75 -1.5" color="grey"></a-text>
97+
<a-text id="log-panel2" wrapCount=80 width="1" value="R Hand Keyboard Data" position="0.75 0.75 -1.5" color="grey"></a-text>
98+
</a-camera>
99+
<a-entity id="lhand" mixin="touch"
100+
hand-controls="hand: left"
101+
keyboard-hand-controls="logger:#log-panel1"
102+
key-bindings="bindings:ShiftLeft=enable,ShiftRight=disable"
103+
position="-0.3 0.3 -0.5">
104+
</a-entity>
105+
<a-entity id="rhand" mixin="touch"
106+
hand-controls="hand: right"
107+
keyboard-hand-controls="logger:#log-panel2"
108+
key-bindings="bindings:ShiftRight=enable,ShiftLeft=disable"
109+
position="0.3 0.3 -0.5">
110+
</a-entity>
111+
</a-entity>
112+
<a-entity id= "red-cube-back" class="cube" mixin="cube" position="0 0.265 -1" material="color: red"></a-entity>
113+
<a-entity id= "red-cube-front" class="cube" mixin="cube" position="0 0.265 -0.5" material="color: red"></a-entity>
114+
<a-entity id= "blue-cube-back" class="cube" mixin="cube" position="-1 0.265 -1" material="color: blue"></a-entity>
115+
<a-entity id= "blue-cube-front" class="cube" mixin="cube" position="-1 0.265 -0.5" material="color: blue"></a-entity>
116+
<a-entity id= "green-cube-back" class="cube" mixin="cube" position="1 0.265 -1" material="color: green"></a-entity>
117+
<a-entity id= "green-cube-front" class="cube" mixin="cube" position="1 0.265 -0.5" material="color: green"></a-entity>
118+
<a-entity class="transformer" mixin="transformer" position = "0 1.6 -1"
119+
material="src:#colortransform" shadow></a-entity>
120+
<!-- ground collider keeps objets from falling -->
121+
<a-box id= "ground" ammo-body="type: static" ammo-shape="type: box" width="100" height="0.01" depth="100" visible="false"></a-box>
122+
<a-link href="../mouse" title="Basic Example"
123+
ammo-body="type: static" ammo-shape="fit: manual; type: sphere; sphereRadius: 0.25"
124+
image="#portals-preview"
125+
onmouseover="this.setAttribute('link', {highlighted: true})"
126+
onmouseout="this.setAttribute('link', {highlighted: false})"
127+
position = "0 1.6 0.7" rotation="0 0 0" scale="0.25 0.25 0.25">
128+
</a-link>
129+
</a-scene>
130+
131+
<!-- GitHub Corner. -->
132+
<a href="https://github.com/wmurphyrd/aframe-super-hands-component" class="github-corner">
133+
<svg width="80" height="80" viewBox="0 0 250 250" style="fill:#222; color:#fff; position: absolute; top: 0; border: 0; right: 0;">
134+
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
135+
</svg>
136+
</a>
137+
<style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
138+
</body>
139+
</html>

0 commit comments

Comments
 (0)