Difference between revisions of "Qmaze Rules"
Nick Bannink (talk | contribs) |
Nick Bannink (talk | contribs) |
||
| Line 11: | Line 11: | ||
| + | Place this piece of code in your outputscript: | ||
$(document).ready(function(){ | $(document).ready(function(){ | ||
$(qmaze.events).on(qmaze.events.CONSTRAINT, function(e, constraints) { | $(qmaze.events).on(qmaze.events.CONSTRAINT, function(e, constraints) { | ||
Revision as of 10:16, 3 April 2019
Using Qmaze rules to call functions
Use the following script to catch the x3d commands given in the qmaze builder rules section.
The rules must be written as:
x3d(object).action = value
action: what action needs to be executed? e.g. changeColor.
object: what object is the subject of change?
value: what value needs to be given to the function?
Place this piece of code in your outputscript:
$(document).ready(function(){
$(qmaze.events).on(qmaze.events.CONSTRAINT, function(e, constraints) {
if (typeof constraints !== "undefined") {
var res = constraints.split(";");
for (var i = 0; i < res.length; i++) {
var regex = new RegExp(/(x3d\((.*?)\)\.(\w+)(\s+)?\=['"]?(.*)['"]?)/gi);
while (result = regex.exec(res[i])) {
var object = result[2],
method = result[3],
value = unescape(result[5]).replace('\, );
console.log('qmaze:'+method+'='+value);
eval(method + '="' + value + '";');
window["my"+method](object, value);
}
}
}
});
var lazyLoadingConstraints = $('input[id$="hfLazyLoading"]').val();
$(qmaze.events).trigger(qmaze.events.CONSTRAINT, [lazyLoadingConstraints]);
});
In your output script you need to declare all the functions called by the qmaze rules.
The functions always need to begin with ' my ' as seen below.
function mysetColor(obj, val) {
obj: is the object in the qmaze rules
val: is the value given in the qmaze rules
the following example is for looking up an object in the scene (v3d)
var obj = app.scene.getObjectByName(obj);
}