UNPKG

@c-frame/physx

Version:

Physics for A-Frame using Nvidia PhysX

149 lines (147 loc) 4.1 kB
<!DOCTYPE html> <html> <head> <title>Examples • Sandbox PhysX</title> <script src="https://aframe.io/releases/1.7.1/aframe.min.js"></script> <script src="../../dist/physx.js"></script> <link rel="stylesheet" href="../../styles.css"> <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> <div class="text-overlay"> <p>Demonstration of many PhysX driver features in a single example.</p> <p>The cone is a kinematic object, and the purple box has a constraint attaching it to the cone.</p> <p>Seems to be a problem with the torus scaling up/down - collision mesh does not seem to adjust.</p> </div> <a class="code-link" target="_blank" href="https://github.com/c-frame/physx/blob/master/examples/sandbox/index.html"> view code </a> <a-scene physx="autoLoad: true; delay: 1000; useDefaultScene: false"> <a-camera near="0.001"></a-camera> <a-box position="-1 3 -6" rotation="0 45 0" color="#4CC3D9" shadow physx-body physx-material= "restitution: 0" ></a-box> <a-box id="target" position="1 3.75 -4" rotation="0 45 0" color="purple" shadow physx-body ></a-box> <a-sphere position="0 10 -10" radius="1.25" color="#EF2D5E" shadow physx-body ></a-sphere> <a-cone position="-1 3.75 -4" radius-bottom="1.25" color="green" shadow bounce physx-body="type: kinematic"> <a-entity physx-joint="type: Fixed; target:#target; collideWithTarget: true"> </a-entity> </a-cone> <a-torus position="-1 3.75 -7" radius="1.25" scale="0.7 0.7 0.7" color="red" shadow physx-body changescale ></a-torus> <a-torus-knot position="0 3.75 -5" radius="1.25" scale="0.5 0.5 0.5" color="blue" shadow physx-body ></a-torus-knot> <a-cylinder segments-height="1" segments-radial="10" position="1 2 -3" radius="0.5" height="1.5" color="#FFC65D" shadow physx-body ></a-cylinder> <a-plane position="0 2 -4" rotation="90 0 0" width="1" height="1" color="#7BC8A4" shadow physx-body="type:static" ></a-plane> <a-torus-knot position="0 0 -7" radius="1.25" scale="5 0.1 5" rotation="0 90 0" color="#7BC8A4" shadow physx-body="type:static" ></a-torus-knot> <a-sky color="#000000"></a-sky> </a-scene> </body> </html>