Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds random-primitive to randomizer component #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions components/randomizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,8 +65,7 @@ Install and use by directly including the [browser files](dist):

<body>
<a-scene>
<a-entity geometry="primitive: box"
random-position random-rotation random-scale></a-entity>
<a-entity random-position random-rotation random-scale random-primitive></a-entity>
</a-scene>
</body>
```
Expand Down
4 changes: 2 additions & 2 deletions components/randomizer/examples/basic/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<html>
<head>
<title>Basic</title>
<meta name="description" content="20 boxes of random color, position, rotation, and scale">
<meta name="description" content="20 entities of random color, position, rotation, scale, and primitive">
<meta property="og:image" content="https://raw.githubusercontent.com/supermedium/superframe/master/components/randomizer/examples/basic/preview.png"></meta>
<script src="../build.js"></script>
</head>
<body>
<a-scene>
<a-assets>
<a-mixin id="random" geometry="primitive: box"
random-color random-position random-rotation random-scale>
random-color random-position random-rotation random-scale random-primitive>
</a-mixin>
</a-assets>

Expand Down
2 changes: 1 addition & 1 deletion components/randomizer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h2>Examples</h2>
<li>
<a href="examples/basic/" style="background-color: #222; background-image: url(examples/basic/preview.png)"></a>
<h3>Basic</h3>
<p>20 boxes of random color, position, rotation, and scale</p>
<p>20 entities of random color, position, rotation, scale, and primitive</p>
</li>

<li>
Expand Down
17 changes: 17 additions & 0 deletions components/randomizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down