📰Getting Started | ⭐**Updates |** 📝 Guides | 🔢 API | ❓FAQ
Web Editor Basics
HoloLens
Mobile
Meta Quest
Chapter Series Documentation
Assets
Scripting
Enklu Embedded
API Reference
Release Notes
FAQ
Contact
Enklu comes with a simple scene editing API. This allows scripts running in the scene to make changes to the scene. This should not be used for multiplayer, but is a handy way to automate scene editing.
const editp = require('edit');
First, make sure the edit api is connected to the Enklu platform. This is generally done after checking the isConnected
flag. The edit
object also fires events when the isConnected
value changes, i.e. as the device connects and disconnects from the authoring server.
if (edit.isConnected) {
start();
}else {
edit.connect(function(err) {
if (err) {
log.error("Oh no! I couldn't connect : " + err);
}else {
start();
}
});
}
Then, add a listener for connection changes.
edit.on('connectionchange',function (isConnected) {
if (!isConnected) {
log.warn('We were just disconnected!');
}
});
The scene can be edited through the use of transactions (txns). A transaction is a list of actions on a scene that are applied atomically. This means that if any of the actions fail, all of the actions are rolled back.
First, create a transaction.
var txn = edit.txns.create();
Next, add actions to the transaction.
txn
.update(element.id, "bool", "visible", true)
.update(element.id, "vec3", "position", vec3(0, 1, 0));
Finally, make a request to apply the transaction.
// fire and forget (useful for frequent updates)
edit.txns.request(txn);
// callback
edit.txns.requestCallback(txn,function(err) {
if (err) {
log.error('There was an error : ' + err);
}
});
You may also duplicate an element. This requires creating a unique id for the element ahead of time. This is so that the created element may be referenced with other actions within the same transaction.
var id = edit.txns.generateId(); // generates a unique id for the new element
var txn = edit.txns
.create()
// include the element this new element should be a child of, the element to duplicate, and the id of the new element
.duplicate(parentElement.id, templateElement.id, id)
// now we can reference the created element before it's even created
.update(id, "bool", "visible", false);
Finally, delete elements with delete
.
var txn = edit.txns
.create()
.delete(id);
isConnected <bool>
connect(callback)
callback <function>
Called on success or failure. If the connection fails, an object
describing the error is passed as a parameter.Connect to the authoring server.
txns.create()
ElementTxn
objectCreates a transaction.
txns.generateId()
string
Generates a new guid.
txns.request(txn)
txn <ElementTxn>
The transaction to send.Sends a transation to the authoring server.
txns.requestCallback(txn, callback)
txn <ElementTcn>
The transaction to send.callback <function>
Called when the request completes. If there was an error, it is passed as a parameterElementTxn.Sends a transaction to the authoring server, with a callback.
ElementTxn
Classupdate(elementId, schemaType, key, value)
elementId <string>
Id of the element to apply transaction to.schemaType <string>
Describes the value's type. Acceptable values are string
, int
, float
, bool
, col4
, and vec3
.key <string>
The key in the element's schema to update.value <object>
The new value.Applies a new value to a key in an element's schema.
duplicate(parentId, templateId, newId)
parentId <string>
Id of the new element's parent.templateId <string>
Id of the element to be duplicated.newId <string>
ID of the new element.Copies an element.
create(parentId, elementType, elementId)
parentId <string>
Id of the new element's parent.elementType <int>
An integer
representing the new element's type (see below).elementId <string>
The ID if the new element.Creates a new element that is the child of the provided parent element.
delete(elementId)
elementId <string>
The ID of the element to be deleted.Deletes an element
0
10
20
21
100
101
120
130
131
140
150
200
201
210
211
270
1000
1100
1200
1300
1400
1500
10000
10001
1000000
10000001
Next: Score (Preview)
Sidebar Table of Contents