diff --git a/README.md b/README.md index 3d2e9e39..a6fe5df9 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ See documentation for individual components: - [mountain](https://github.com/supermedium/superframe/tree/master/components/mountain/) - Mountain terrain in A-Frame using randomly-generated height maps - [orbit-controls](https://github.com/supermedium/superframe/tree/master/components/orbit-controls/) - Orbit controls component for A-Frame. - [proxy-event](https://github.com/supermedium/superframe/tree/master/components/proxy-event/) - A component to declaratively proxy events for A-Frame. -- [randomizer](https://github.com/supermedium/superframe/tree/master/components/randomizer/) - Randomize color, position, rotation, and scale in A-Frame +- [randomizer](https://github.com/supermedium/superframe/tree/master/components/randomizer/) - Randomize color, position, rotation, scale, and primitive in A-Frame - [render-order](https://github.com/supermedium/superframe/tree/master/components/render-order/) - A component that enables sorting and manually defining render order for transparent objects. - [state](https://github.com/supermedium/superframe/tree/master/components/state/) - State management for A-Frame using single global state modified through actions. State flows down to application via declarative binding. - [sun-sky](https://github.com/supermedium/superframe/tree/master/components/sun-sky/) - Gradient sky with adjustable sun in A-Frame diff --git a/components/randomizer/README.md b/components/randomizer/README.md index 0bed1b3f..609ef073 100644 --- a/components/randomizer/README.md +++ b/components/randomizer/README.md @@ -44,6 +44,12 @@ Random position that maps to a surface of a bounding sphere. | min | Minimum scale components. | 1 1 1 | | max | Maximum scale components. | 2 2 2 | +#### random-primitive + +| Property | Description | Default Value | +|----------|---------------------------|---------------| +| exclude | Primitives to exclude. | [] | + ### Usage #### Browser Installation @@ -59,8 +65,7 @@ Install and use by directly including the [browser files](dist): - + ``` diff --git a/components/randomizer/examples/basic/index.html b/components/randomizer/examples/basic/index.html index 251790b5..9a18e29b 100644 --- a/components/randomizer/examples/basic/index.html +++ b/components/randomizer/examples/basic/index.html @@ -1,7 +1,7 @@ Basic - + @@ -9,7 +9,7 @@ + random-color random-position random-rotation random-scale random-primitive> diff --git a/components/randomizer/index.html b/components/randomizer/index.html index 66b3eeeb..d560ebf0 100644 --- a/components/randomizer/index.html +++ b/components/randomizer/index.html @@ -70,7 +70,7 @@

Examples

  • Basic

    -

    20 boxes of random color, position, rotation, and scale

    +

    20 entities of random color, position, rotation, scale, and primitive

  • diff --git a/components/randomizer/index.js b/components/randomizer/index.js index 8d52e5b3..7b5d9435 100644 --- a/components/randomizer/index.js +++ b/components/randomizer/index.js @@ -23,6 +23,23 @@ AFRAME.registerComponent('random-color', { } }); +/** + * Set random primitive. + */ +AFRAME.registerComponent('random-primitive', { + schema: { + exclude: { default: [] }, + }, + update: function () { + var exclude = this.data.exclude; + var primitives = Object.keys(AFRAME.geometries).filter(primitive => !exclude.includes(primitive)); + var primitive = primitives[Math.floor(Math.random() * primitives.length)]; + this.el.setAttribute('geometry', { + primitive: primitive + }); + } +}); + /** * Set random position within bounds. */