Skip to content

Commit e22194d

Browse files
committed
Adds random-primitive to randomizer component
1 parent 59f997f commit e22194d

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ See documentation for individual components:
2929
- [mountain](https://github.com/supermedium/superframe/tree/master/components/mountain/) - Mountain terrain in A-Frame using randomly-generated height maps
3030
- [orbit-controls](https://github.com/supermedium/superframe/tree/master/components/orbit-controls/) - Orbit controls component for A-Frame.
3131
- [proxy-event](https://github.com/supermedium/superframe/tree/master/components/proxy-event/) - A component to declaratively proxy events for A-Frame.
32-
- [randomizer](https://github.com/supermedium/superframe/tree/master/components/randomizer/) - Randomize color, position, rotation, and scale in A-Frame
32+
- [randomizer](https://github.com/supermedium/superframe/tree/master/components/randomizer/) - Randomize color, position, rotation, scale, and primitive in A-Frame
3333
- [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.
3434
- [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.
3535
- [sun-sky](https://github.com/supermedium/superframe/tree/master/components/sun-sky/) - Gradient sky with adjustable sun in A-Frame

components/randomizer/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ Random position that maps to a surface of a bounding sphere.
4444
| min | Minimum scale components. | 1 1 1 |
4545
| max | Maximum scale components. | 2 2 2 |
4646

47+
#### random-primitive
48+
49+
| Property | Description | Default Value |
50+
|----------|---------------------------|---------------|
51+
| exclude | Primitives to exclude. | [] |
52+
4753
### Usage
4854

4955
#### Browser Installation
@@ -59,8 +65,7 @@ Install and use by directly including the [browser files](dist):
5965

6066
<body>
6167
<a-scene>
62-
<a-entity geometry="primitive: box"
63-
random-position random-rotation random-scale></a-entity>
68+
<a-entity random-position random-rotation random-scale random-primitive></a-entity>
6469
</a-scene>
6570
</body>
6671
```

components/randomizer/examples/basic/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<html>
22
<head>
33
<title>Basic</title>
4-
<meta name="description" content="20 boxes of random color, position, rotation, and scale">
4+
<meta name="description" content="20 boxes of random color, position, rotation, scale, and primitive">
55
<meta property="og:image" content="https://raw.githubusercontent.com/supermedium/superframe/master/components/randomizer/examples/basic/preview.png"></meta>
66
<script src="../build.js"></script>
77
</head>
88
<body>
99
<a-scene>
1010
<a-assets>
1111
<a-mixin id="random" geometry="primitive: box"
12-
random-color random-position random-rotation random-scale>
12+
random-color random-position random-rotation random-scale random-primitive>
1313
</a-mixin>
1414
</a-assets>
1515

components/randomizer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h2>Examples</h2>
7070
<li>
7171
<a href="examples/basic/" style="background-color: #222; background-image: url(examples/basic/preview.png)"></a>
7272
<h3>Basic</h3>
73-
<p>20 boxes of random color, position, rotation, and scale</p>
73+
<p>20 entities of random color, position, rotation, scale, and primitive</p>
7474
</li>
7575

7676
<li>

components/randomizer/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ AFRAME.registerComponent('random-color', {
2323
}
2424
});
2525

26+
/**
27+
* Set random primitive.
28+
*/
29+
AFRAME.registerComponent('random-primitive', {
30+
schema: {
31+
exclude: { default: [] },
32+
},
33+
update: function () {
34+
var exclude = this.data.exclude;
35+
var primitives = Object.keys(AFRAME.geometries).filter(primitive => !exclude.includes(primitive));
36+
const randomPrimitive = primitives[Math.floor(Math.random() * primitives.length)];
37+
this.el.setAttribute('geometry', {
38+
primitive: randomPrimitive
39+
});
40+
}
41+
});
42+
2643
/**
2744
* Set random position within bounds.
2845
*/

0 commit comments

Comments
 (0)