パッケージの詳細

aframe-physics-extras

wmurphyrd750MIT0.1.3

Cannon API interface components the A-Frame Physics System.

aframe, aframe-component, aframe-vr, vr

readme

A-Frame Physics Extras

npm Dowloads npm Version

Add-on components for the aframe-physics-system to add additional collision detection and behavior control options.

aframe-physics-extras in action

physics-collider

A collision detection component powered by the physics simulation with low overhead and precise collision zones. This is intended to be placed on tracked controller entities to monitor collisions and report them to a gesture interpretation component such as super-hands.

API

Property Description Default Value
ignoreSleep Wake sleeping bodies on collision? true

physics-collider can also report collisions with static bodies when ignoreSleep is true. This can be useful to create collision detection zones for interactivity with things other than dynamic bodies.

Events

Type Description Detail object
collisions Emitted each tick if there are changes to the collision list els: array of new collisions. cleardEls: array of collisions which have ended.

collision-filter

Control which physics bodies interact with each other or ignore each other. This can improve physics system performance by skipping unnecessary collision checks. It also controls which entities can be interacted with via physics-collider

API

Property Description Default Value
group Collision group this entity belongs to 'default'
collidesWith Array of collision groups this entity will interact with 'default'
collisionForces Should other bodies react to collisions with this body? true

collisionForces controls whether collisions with this body generate any forces. Setting this to false allows for collisions to be registered and tracked without causing any corresponding movement. This is useful for your controller entities with physics-collider because it is difficult to pick things up if they are constantly bumped away when your hand gets close. This can be toggles through events with a controller button press if you want to be able to bump other objects sometimes and reach inside to pick them up other times. There is an example of this on the examples page.

Turning off collisionForces can also be useful for setting static bodies as collision zones to detect the presence of other entities without disturbing them.

sleepy

Make entities settle down and be still after physics collisions. Very useful for zero-gravity user interfaces to keep entities from floating away. Also can help performance as sleeping bodies are handled efficiently by the physics simulation.

API

Property Description Default Value
allowSleep Enable sleep for this body true
speedLimit Maximum velocity for sleep to initiate 0.25
delay Time interval to check for sleep initiation (seconds) 0.25
linearDamping Deceleration of liner forces on the entity (0 to 1) 0.99
angularDamping Deceleration of angular forces on the entity (0 to 1) 0.99
holdState Entity state in which sleep is suspended 'grabbed'

Adding sleepy to any body will activate sleep for the entire physics system and will affect other bodies because the cannon defaults for all bodies are to allow sleep with a speed limit of 0.1 and delay of 1 second. You can add sleepy="allowSleep: false; linearDamping: 0.01; angularDamping: 0.01" to restore default behavior to an entity if needed. Sleeping bodies will ignore static bodies (hence why physics-collider has an ignoreSleep setting) until they are woken by a dynamic or kinematic body. Sleep will break constraints, so the holdState property allows you to suspend sleep during interactions such as grabbing/carrying the entity.

Examples

View the examples page to see aframe-physics-extras in action.

Installation

Browser

Install and use by directly including the browser files:

Remix on Glitch

<!DOCTYPE html>
<html>
 <head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
  <script src="//cdn.rawgit.com/donmccurdy/aframe-physics-system/v2.1.0/dist/aframe-physics-system.min.js"></script>
  <script src="https://unpkg.com/super-hands@2.0.2/dist/super-hands.min.js"></script>
  <script src="https://unpkg.com/aframe-physics-extras@0.1.2/dist/aframe-physics-extras.min.js"></script>
</head>

<body>
  <a-scene physics="gravity: 0">
    <a-assets>
      <a-mixin id="controller"
               physics-collider
               static-body="shape: sphere; sphereRadius: 0.02"
               super-hands="colliderEvent: collisions;
                            colliderEventProperty: els;
                            colliderEndEvent: collisions;
                            colliderEndEventProperty: clearedEls"
               collision-filter = "group: hands;
                                   collidesWith: red, blue;
                                   collisionForces: false">
      </a-mixin>
      <a-mixin id="cube" dynamic-body grabbable
          geometry="primitive: box; width: 0.5; height: 0.5; depth: 0.5">
      </a-mixin>
    </a-assets>
    <!-- settings pulled in from controller mixin above -->
    <a-entity hand-controls="left" mixin="controller"></a-entity>
    <a-entity hand-controls="right" mixin="controller"></a-entity>
    <!-- can be picked up because it collides with the hands group and vice versa -->
    <a-entity mixin="cube" position="0 1.6 -1" material="color: red" sleepy
        collision-filter="group: red; collidesWith: default, hands, blue">
    </a-entity>
    <!-- even though the controller has blue in its collidesWith list,
         since the blue cube doesn't also have hands in its list, you cannot
         pick it up, but you can knock it around with the red cube -->
    <a-entity mixin="cube" position="0 1 -1" material="color: blue" sleepy
        collision-filter="group: blue; collidesWith: default, red">
    </a-entity>
    <!-- floor entity. 'default' collision group so cubes will bounce off -->
    <a-box width="20" depth="20" height="0.1" static-body
           collision-filter="collidesWith: red, blue"
        material="color: #7BC8A4"></a-box>
  </a-scene>
</body>
</html>

npm

Install via npm:

npm install

Then require and use.

require('aframe');
require('aframe-physics-system')
require('aframe-physics-extras');

更新履歴

7.0.0

Fixes previous patch and also updates to garnish redesign, leading to new log styles.

Since various ndjson flags have changed, this is a potentially breaking change.

Also added a --verbose / -v option like watchify, which adds some additional debug messages.

6.1.1

Fixes live reload for directory routes like localhost:9966/mydir.

6.1.0

Search for index.html across all static --dir folders, finding the first one.

6.0.0

Major Changes
  • garnish is now included by default in CLI and API
    • you can use --ndjson and ndjson: true to have raw output (for custom pretty-printers)
Minor Changes
  • added --title option for the default HTML title
  • added --css option for a default style sheet

5.0.0

Major Changes
  • you can just type budo . | garnish for the entry point (or index.js)
  • added --onupdate for things like linting, see the docs
  • if no --host is specified, resolves to internal IP
    • you can still hit localhost:9966 and it will work
  • the <script> src defaults to the filename of the first entry
    • eg: budo src/index.js leads to <script src="index.js">
  • browserify options must come after a full stop --
    • except --no-debug which is passed as a budo option
    • eg: budo index.js --no-debug -- -t babelify
  • --dir can be passed multiple times to use multiple static folders
    • budo index.js --dir public --dir tmp
  • removed --live-plugin option to reduce code complexity
    • might be added back into CLI later
    • API still supports budo.live({ plugin: true })
  • portfinding is enabled by default in API and CLI
    • user can disbale with --no-portfind or portfind: false
  • removed --verbose, -v, timing is logged by default now
  • entry files are now optional (i.e. if you just need a static HTML with LiveReload)
  • added --open, -o to launch browser on connect
  • syntax errors in code are shown in the DOM body now
    • can disable with --no-error-handler
    • in API can use errorHandler: Boolean|Function
  • added --version to CLI
  • --live can optionally be a string to only LiveReload on those globs, eg:
    • budo index.js --live=*.{css,html}
  • removed --ignore-watch and --interval
    • use budo.watch(glob, chokidarOpts) instead
  • shorthand for most CLI options now exists
  • arg parsing has improved and uses camel-case in API
  • most args are now supported before entries, eg:
    • budo --live src/index.js
  • cleaner error messaging in terminal
API Changes
  • dir can be a string or array of static paths
  • the 'connect' event now passes livePort
  • the 'connect' event ev.host now uses internal IP by default
  • exposed a CLI feature
    • require('budo').cli(process.argv.slice(2), { overrides... })
  • errorHandler can be used for custom bundle error handling
  • middleware can be a fn(req, res, next) function for custom routes
  • 'update' event now passes (contents, updates)
Browserify Args

Users creating CLI tools on top of budo can use opt.browserifyArgs to handle subarg correctly. Example with minimist:

var args = process.argv.slice(2)
var opts = require('minimist')(args, { '--': true })
budo.cli(args, {
  browserifyArgs: opts['--']
})

If no browserifyArgs is specified, then opt.browserify can be used to send the actual JS object to the browserify constructor.

budo.cli(args, {
  browserify: {
    transform: require('babelify')
  }
})

4.2.0

  • Added --pushstate option #53

4.1.0

  • Fixed a bug with budo ./foo.js