Created
January 19, 2016 13:36
-
-
Save vrjump/392a2c175f0083f3fb91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Beispiel für eine simple A-Frame Komponente | |
*/ | |
AFRAME.aframeCore.registerComponent('randomator', { | |
schema: { | |
threshold: { default: 1.0 }, | |
nervous: { default: false } | |
}, | |
/** | |
* Wird einmalig aufgerufen, sobald die Komponente an ein Objekt gebunden wird. | |
* Verwende diese Methode für das initiale Setup. | |
*/ | |
init: function () { | |
if (this.data.nervous) { | |
this.el.sceneEl.addBehavior(this); | |
} | |
}, | |
/** | |
* Wird erstmalig aufgerufen, wenn die Komponente an ein Objekt gebunden wird | |
* (nach der init-Methode) und dann jedes Mal, wenn die Eigenschaften verändert | |
* werden ODER (falls eingestellt) bei jedem Frame. | |
* | |
* In der Regel wird in dieser Methode basierend auf den gegebenen Daten das | |
* Objekt verändert oder neue Objekte hinzugefügt. | |
*/ | |
update: function () { | |
var obj = this.el.object3D; | |
var th = this.data.threshold; | |
var x = Math.random()*th; | |
var y = Math.random()*th; | |
var z = Math.random()*th; | |
obj.position.set(x, y, z); | |
}, | |
/** | |
* Wird einmalig aufgerufen, sobald die Komponente aus der Szene entfernt wurde | |
* (z.B. durch removeAttribute). Hier solltest du alle Änderungen am Objekt | |
* wieder rückgängig machen. | |
*/ | |
remove: function () {} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Eine Beispiel-Komponente für A-Frame</title> | |
<script src="https://aframe.io/releases/latest/aframe.js"></script> | |
<script src="aframe-randomator-component.js"></script> | |
</head> | |
<body> | |
<a-scene> | |
<a-cube randomator></a-cube> | |
<a-sphere randomator="nervous: true"></a-sphere> | |
</a-scene> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment