work in progress [might break]
This commit is contained in:
parent
1d9ba42d44
commit
b5c10fe853
2
.vimrc
2
.vimrc
|
@ -1,4 +1,4 @@
|
|||
noremap <silent> <F8> :!haxe --no-output %<CR>
|
||||
noremap <silent> <F9> :!./make doc<CR>
|
||||
noremap <silent> <F10> :!./make && echo OK && ./make tests<CR>
|
||||
noremap <silent> <F10> :!./make && echo OK<CR>
|
||||
noremap <silent> <F11> :!./make tests \| less<CR>
|
||||
|
|
|
@ -0,0 +1,579 @@
|
|||
var $hx_exports = typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this;
|
||||
(function ($global) { "use strict";
|
||||
$hx_exports["xrfragment"] = $hx_exports["xrfragment"] || {};
|
||||
var EReg = function(r,opt) {
|
||||
this.r = new RegExp(r,opt.split("u").join(""));
|
||||
};
|
||||
EReg.__name__ = true;
|
||||
EReg.prototype = {
|
||||
match: function(s) {
|
||||
if(this.r.global) {
|
||||
this.r.lastIndex = 0;
|
||||
}
|
||||
this.r.m = this.r.exec(s);
|
||||
this.r.s = s;
|
||||
return this.r.m != null;
|
||||
}
|
||||
,split: function(s) {
|
||||
var d = "#__delim__#";
|
||||
return s.replace(this.r,d).split(d);
|
||||
}
|
||||
};
|
||||
var HxOverrides = function() { };
|
||||
HxOverrides.__name__ = true;
|
||||
HxOverrides.cca = function(s,index) {
|
||||
var x = s.charCodeAt(index);
|
||||
if(x != x) {
|
||||
return undefined;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
HxOverrides.substr = function(s,pos,len) {
|
||||
if(len == null) {
|
||||
len = s.length;
|
||||
} else if(len < 0) {
|
||||
if(pos == 0) {
|
||||
len = s.length + len;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return s.substr(pos,len);
|
||||
};
|
||||
HxOverrides.now = function() {
|
||||
return Date.now();
|
||||
};
|
||||
Math.__name__ = true;
|
||||
var Reflect = function() { };
|
||||
Reflect.__name__ = true;
|
||||
Reflect.field = function(o,field) {
|
||||
try {
|
||||
return o[field];
|
||||
} catch( _g ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reflect.fields = function(o) {
|
||||
var a = [];
|
||||
if(o != null) {
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
for( var f in o ) {
|
||||
if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) {
|
||||
a.push(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
Reflect.deleteField = function(o,field) {
|
||||
if(!Object.prototype.hasOwnProperty.call(o,field)) {
|
||||
return false;
|
||||
}
|
||||
delete(o[field]);
|
||||
return true;
|
||||
};
|
||||
var Std = function() { };
|
||||
Std.__name__ = true;
|
||||
Std.string = function(s) {
|
||||
return js_Boot.__string_rec(s,"");
|
||||
};
|
||||
Std.parseInt = function(x) {
|
||||
if(x != null) {
|
||||
var _g = 0;
|
||||
var _g1 = x.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var c = x.charCodeAt(i);
|
||||
if(c <= 8 || c >= 14 && c != 32 && c != 45) {
|
||||
var nc = x.charCodeAt(i + 1);
|
||||
var v = parseInt(x,nc == 120 || nc == 88 ? 16 : 10);
|
||||
if(isNaN(v)) {
|
||||
return null;
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var StringTools = function() { };
|
||||
StringTools.__name__ = true;
|
||||
StringTools.isSpace = function(s,pos) {
|
||||
var c = HxOverrides.cca(s,pos);
|
||||
if(!(c > 8 && c < 14)) {
|
||||
return c == 32;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
StringTools.ltrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,r)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,r,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.rtrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,0,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.trim = function(s) {
|
||||
return StringTools.ltrim(StringTools.rtrim(s));
|
||||
};
|
||||
StringTools.replace = function(s,sub,by) {
|
||||
return s.split(sub).join(by);
|
||||
};
|
||||
var haxe_iterators_ArrayIterator = function(array) {
|
||||
this.current = 0;
|
||||
this.array = array;
|
||||
};
|
||||
haxe_iterators_ArrayIterator.__name__ = true;
|
||||
haxe_iterators_ArrayIterator.prototype = {
|
||||
hasNext: function() {
|
||||
return this.current < this.array.length;
|
||||
}
|
||||
,next: function() {
|
||||
return this.array[this.current++];
|
||||
}
|
||||
};
|
||||
var js_Boot = function() { };
|
||||
js_Boot.__name__ = true;
|
||||
js_Boot.__string_rec = function(o,s) {
|
||||
if(o == null) {
|
||||
return "null";
|
||||
}
|
||||
if(s.length >= 5) {
|
||||
return "<...>";
|
||||
}
|
||||
var t = typeof(o);
|
||||
if(t == "function" && (o.__name__ || o.__ename__)) {
|
||||
t = "object";
|
||||
}
|
||||
switch(t) {
|
||||
case "function":
|
||||
return "<function>";
|
||||
case "object":
|
||||
if(((o) instanceof Array)) {
|
||||
var str = "[";
|
||||
s += "\t";
|
||||
var _g = 0;
|
||||
var _g1 = o.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s);
|
||||
}
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
var tostr;
|
||||
try {
|
||||
tostr = o.toString;
|
||||
} catch( _g ) {
|
||||
return "???";
|
||||
}
|
||||
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
|
||||
var s2 = o.toString();
|
||||
if(s2 != "[object Object]") {
|
||||
return s2;
|
||||
}
|
||||
}
|
||||
var str = "{\n";
|
||||
s += "\t";
|
||||
var hasp = o.hasOwnProperty != null;
|
||||
var k = null;
|
||||
for( k in o ) {
|
||||
if(hasp && !o.hasOwnProperty(k)) {
|
||||
continue;
|
||||
}
|
||||
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
|
||||
continue;
|
||||
}
|
||||
if(str.length != 2) {
|
||||
str += ", \n";
|
||||
}
|
||||
str += s + k + " : " + js_Boot.__string_rec(o[k],s);
|
||||
}
|
||||
s = s.substring(1);
|
||||
str += "\n" + s + "}";
|
||||
return str;
|
||||
case "string":
|
||||
return o;
|
||||
default:
|
||||
return String(o);
|
||||
}
|
||||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["class"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["src"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL;
|
||||
Frag_h["pos"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.T_STRING_OBJ;
|
||||
Frag_h["href"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["q"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING;
|
||||
Frag_h["scale"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT;
|
||||
Frag_h["rot"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3;
|
||||
Frag_h["translate"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3;
|
||||
Frag_h["visible"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT;
|
||||
Frag_h["env"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING;
|
||||
Frag_h["t"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE;
|
||||
Frag_h["gravity"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3;
|
||||
Frag_h["physics"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3;
|
||||
Frag_h["scroll"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING;
|
||||
Frag_h["fov"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_INT | xrfragment_XRF.BROWSER_OVERRIDE;
|
||||
Frag_h["clip"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE;
|
||||
Frag_h["fog"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.BROWSER_OVERRIDE;
|
||||
Frag_h["namespace"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["SPFX"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["unit"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["src_session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.BROWSER_OVERRIDE | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.BROWSER_OVERRIDE);
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:75:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
console.log("src/xrfragment/Parser.hx:79:","[ i ] fragment '" + key + "' does not exist or has no type typed (yet)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
this.str = "";
|
||||
if(str != null) {
|
||||
this.parse(str);
|
||||
}
|
||||
};
|
||||
xrfragment_Query.__name__ = true;
|
||||
xrfragment_Query.prototype = {
|
||||
toObject: function() {
|
||||
return this.q;
|
||||
}
|
||||
,expandAliases: function(token) {
|
||||
var classAlias = new EReg("^(-)?\\.","");
|
||||
if(classAlias.match(token)) {
|
||||
return StringTools.replace(token,".","class:");
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
var process = function(str,prefix) {
|
||||
if(prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
str = StringTools.trim(str);
|
||||
var k = str.split(":")[0];
|
||||
var v = str.split(":")[1];
|
||||
var filter = { };
|
||||
if(q[prefix + k]) {
|
||||
filter = q[prefix + k];
|
||||
}
|
||||
filter["rules"] = filter["rules"] != null ? filter["rules"] : [];
|
||||
if(_gthis.isProp.match(str)) {
|
||||
var oper = "";
|
||||
if(str.indexOf("*") != -1) {
|
||||
oper = "*";
|
||||
}
|
||||
if(str.indexOf(">") != -1) {
|
||||
oper = ">";
|
||||
}
|
||||
if(str.indexOf("<") != -1) {
|
||||
oper = "<";
|
||||
}
|
||||
if(str.indexOf(">=") != -1) {
|
||||
oper = ">=";
|
||||
}
|
||||
if(str.indexOf("<=") != -1) {
|
||||
oper = "<=";
|
||||
}
|
||||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
if(oper.length == 0) {
|
||||
oper = "=";
|
||||
}
|
||||
if(_gthis.isClass.match(k)) {
|
||||
filter[prefix + k] = oper != "!=";
|
||||
q[v] = filter;
|
||||
} else {
|
||||
var rule = { };
|
||||
if(_gthis.isNumber.match(v)) {
|
||||
rule[oper] = parseFloat(v);
|
||||
} else {
|
||||
rule[oper] = v;
|
||||
}
|
||||
filter["rules"].push(rule);
|
||||
q[k] = filter;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
filter["id"] = _gthis.isExclude.match(str) ? false : true;
|
||||
var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str;
|
||||
q[key] = filter;
|
||||
}
|
||||
};
|
||||
var _g = 0;
|
||||
var _g1 = token.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
process(this.expandAliases(token[i]));
|
||||
}
|
||||
return this.q = q;
|
||||
}
|
||||
,test: function(obj) {
|
||||
var qualify = false;
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v)) {
|
||||
qualify = true;
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v,true)) {
|
||||
qualify = false;
|
||||
}
|
||||
}
|
||||
return qualify;
|
||||
}
|
||||
,testProperty: function(property,value,exclude) {
|
||||
var conds = 0;
|
||||
var fails = 0;
|
||||
var qualify = 0;
|
||||
var testprop = function(expr) {
|
||||
conds += 1;
|
||||
fails += expr ? 0 : 1;
|
||||
return expr;
|
||||
};
|
||||
if(this.q[value] != null) {
|
||||
var v = this.q[value];
|
||||
if(v[property] != null) {
|
||||
return v[property];
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(this.q);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var filter = Reflect.field(this.q,k);
|
||||
if(filter.rules == null) {
|
||||
continue;
|
||||
}
|
||||
var rules = filter.rules;
|
||||
var _g2 = 0;
|
||||
while(_g2 < rules.length) {
|
||||
var rule = rules[_g2];
|
||||
++_g2;
|
||||
if(exclude) {
|
||||
if(Reflect.field(rule,"!=") != null && testprop((value == null ? "null" : "" + value) == Std.string(Reflect.field(rule,"!="))) && exclude) {
|
||||
++qualify;
|
||||
}
|
||||
} else {
|
||||
if(Reflect.field(rule,"*") != null && testprop(parseFloat(value) != null)) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">") != null && testprop(parseFloat(value) > parseFloat(Reflect.field(rule,">")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<") != null && testprop(parseFloat(value) < parseFloat(Reflect.field(rule,"<")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">=") != null && testprop(parseFloat(value) >= parseFloat(Reflect.field(rule,">=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<=") != null && testprop(parseFloat(value) <= parseFloat(Reflect.field(rule,"<=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"=") != null && (testprop(value == Reflect.field(rule,"=")) || testprop(parseFloat(value) == parseFloat(Reflect.field(rule,"="))))) {
|
||||
++qualify;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
};
|
||||
var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { };
|
||||
xrfragment_URI.__name__ = true;
|
||||
xrfragment_URI.parse = function(qs,browser_override) {
|
||||
var fragment = qs.split("#");
|
||||
var splitArray = fragment[1].split("&");
|
||||
var resultMap = { };
|
||||
var _g = 0;
|
||||
var _g1 = splitArray.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var splitByEqual = splitArray[i].split("=");
|
||||
var regexPlus = new EReg("\\+","g");
|
||||
var key = splitByEqual[0];
|
||||
var value = "";
|
||||
if(splitByEqual.length > 1) {
|
||||
var s = regexPlus.split(splitByEqual[1]).join(" ");
|
||||
value = decodeURIComponent(s.split("+").join(" "));
|
||||
}
|
||||
var ok = xrfragment_Parser.parse(key,value,resultMap);
|
||||
}
|
||||
if(browser_override) {
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(resultMap);
|
||||
while(_g < _g1.length) {
|
||||
var key = _g1[_g];
|
||||
++_g;
|
||||
var xrf = resultMap[key];
|
||||
if(!xrf.is(xrfragment_XRF.BROWSER_OVERRIDE)) {
|
||||
Reflect.deleteField(resultMap,key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
};
|
||||
var xrfragment_XRF = function(_fragment,_flags) {
|
||||
this.fragment = _fragment;
|
||||
this.flags = _flags;
|
||||
};
|
||||
xrfragment_XRF.__name__ = true;
|
||||
xrfragment_XRF.prototype = {
|
||||
is: function(flag) {
|
||||
return (this.flags & flag) != 0;
|
||||
}
|
||||
,validate: function(value) {
|
||||
this.guessType(this,value);
|
||||
if(value.split("|").length > 1) {
|
||||
this.args = [];
|
||||
var args = value.split("|");
|
||||
var _g = 0;
|
||||
var _g1 = args.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var x = new xrfragment_XRF(this.fragment,this.flags);
|
||||
this.guessType(x,args[i]);
|
||||
this.args.push(x);
|
||||
}
|
||||
}
|
||||
if(this.fragment == "q") {
|
||||
this.query = new xrfragment_Query(value).get();
|
||||
}
|
||||
var ok = true;
|
||||
if(!((this.args) instanceof Array)) {
|
||||
if(this.is(xrfragment_XRF.T_VECTOR3) && !(typeof(this.x) == "number" && typeof(this.y) == "number" && typeof(this.z) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
if(this.is(xrfragment_XRF.T_VECTOR2) && !(typeof(this.x) == "number" && typeof(this.y) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
var tmp;
|
||||
if(this.is(xrfragment_XRF.T_INT)) {
|
||||
var v = this.int;
|
||||
tmp = !(typeof(v) == "number" && ((v | 0) === v));
|
||||
} else {
|
||||
tmp = false;
|
||||
}
|
||||
if(tmp) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
,guessType: function(v,str) {
|
||||
v.string = str;
|
||||
if(str.split(",").length > 1) {
|
||||
var xyz = str.split(",");
|
||||
if(xyz.length > 0) {
|
||||
v.x = parseFloat(xyz[0]);
|
||||
}
|
||||
if(xyz.length > 1) {
|
||||
v.y = parseFloat(xyz[1]);
|
||||
}
|
||||
if(xyz.length > 2) {
|
||||
v.z = parseFloat(xyz[2]);
|
||||
}
|
||||
}
|
||||
if(xrfragment_XRF.isColor.match(str)) {
|
||||
v.color = str;
|
||||
}
|
||||
if(xrfragment_XRF.isFloat.match(str)) {
|
||||
v.float = parseFloat(str);
|
||||
}
|
||||
if(xrfragment_XRF.isInt.match(str)) {
|
||||
v.int = Std.parseInt(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) {
|
||||
HxOverrides.now = performance.now.bind(performance);
|
||||
}
|
||||
String.__name__ = true;
|
||||
Array.__name__ = true;
|
||||
js_Boot.__toStr = ({ }).toString;
|
||||
xrfragment_Parser.error = "";
|
||||
xrfragment_XRF.ASSET = 1;
|
||||
xrfragment_XRF.PROP_BIND = 2;
|
||||
xrfragment_XRF.QUERY_OPERATOR = 4;
|
||||
xrfragment_XRF.PROMPT = 8;
|
||||
xrfragment_XRF.ROUNDROBIN = 16;
|
||||
xrfragment_XRF.BROWSER_OVERRIDE = 32;
|
||||
xrfragment_XRF.PV_OVERRIDE = 64;
|
||||
xrfragment_XRF.PV_EXECUTE = 128;
|
||||
xrfragment_XRF.T_INT = 512;
|
||||
xrfragment_XRF.T_VECTOR2 = 2048;
|
||||
xrfragment_XRF.T_VECTOR3 = 4096;
|
||||
xrfragment_XRF.T_URL = 8192;
|
||||
xrfragment_XRF.T_PREDEFINED_VIEW = 16384;
|
||||
xrfragment_XRF.T_STRING = 32768;
|
||||
xrfragment_XRF.T_STRING_OBJ = 65536;
|
||||
xrfragment_XRF.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","");
|
||||
xrfragment_XRF.isInt = new EReg("^[0-9]+$","");
|
||||
xrfragment_XRF.isFloat = new EReg("^[0-9]+\\.[0-9]+$","");
|
||||
})({});
|
||||
var xrfragment = $hx_exports["xrfragment"];
|
||||
export default xrfragment;
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,116 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://unpkg.com/axist@latest/dist/axist.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script src="./../dist/xrfragment.js"></script>
|
||||
<script>
|
||||
var DOMReady = function(a,b,c){b=document,c='addEventListener';b[c]?b[c]('DOMContentLoaded',a):window.attachEvent('onload',a)}
|
||||
|
||||
DOMReady(function () {
|
||||
|
||||
let XRF = xrfragment;
|
||||
let $ = (e) => document.querySelector(e)
|
||||
|
||||
log = (str) => {
|
||||
$("#console").innerHTML = JSON.stringify(str, null, 2)
|
||||
$("#console").style.border = "10px solid #"+ ((1 << 24) * Math.random() | 0).toString(16).padStart(6, "0")+"66";
|
||||
}
|
||||
|
||||
let update = () => {
|
||||
let result = {}
|
||||
XRF.Parser.parse( $('#fragment').value, $('#value').value, result );
|
||||
log(result)
|
||||
}
|
||||
|
||||
$("#fragment").addEventListener("change", (e) => {
|
||||
let opt = e.target.options[ e.target.selectedIndex ]
|
||||
$('#value').value = opt.getAttribute("x")
|
||||
update()
|
||||
})
|
||||
|
||||
$('#value').addEventListener("change", update )
|
||||
$('#value').addEventListener("keyup", update )
|
||||
|
||||
addEventListener("hashchange", (e) => log( XRF.URI.parse( document.location.href, true ) ) );
|
||||
|
||||
if( document.location.hash.length < 2 ) document.location.hash = "#t=1,100"
|
||||
|
||||
})
|
||||
|
||||
</script>
|
||||
<section id="forms">
|
||||
<a class="title-link" href="#forms"><h3 class="title">XR Fragments</h3></a>
|
||||
<form>
|
||||
<fieldset>
|
||||
<p>
|
||||
<table>
|
||||
<tr>
|
||||
<td width="200">
|
||||
<label for="fragment">Property in 3D file</label>
|
||||
<br><br>
|
||||
<select id="fragment" class="w-100">
|
||||
<optgroup label="asset loading / linking">
|
||||
<option x="1">prio</option>
|
||||
<option x="pos=0,0,1&fov=2">#</option>
|
||||
<option x="foo">class</option>
|
||||
<option x="./2.gtlf">src</option>
|
||||
</optgroup>
|
||||
<optgroup label="href navigation / portals / teleporting">
|
||||
<option x="1,2,0">pos</option>
|
||||
<option x="3.gltf#q=.kitchen">href</option>
|
||||
</optgroup>
|
||||
<optgroup label="query selector / object manipulation">
|
||||
<option x=".summer -.winter cube" selected="selected" default>q</option>
|
||||
<option x="2" >scale</option>
|
||||
<option x="1,2,3">rot</option>
|
||||
<option x="1,1,1">translate</option>
|
||||
<option x="1">visible</option>
|
||||
</optgroup>
|
||||
<optgroup label="animation">
|
||||
<option x="1,200">t</option>
|
||||
<option x="0,-9.8,0">gravity</option>
|
||||
<option x="0.2,1">physics</option>
|
||||
<option x=#scroll=1,0|2s">scroll</option>
|
||||
</optgroup>
|
||||
<optgroup label="device / viewport settings">
|
||||
<option x="90">fov</option>
|
||||
<option x="1,100">clip</option>
|
||||
<option x="5m|FFAACC">fog</option>
|
||||
</optgroup>
|
||||
<optgroup label="author / metadata">
|
||||
<option x="XXX">namespace</option>
|
||||
<option x="GPL-3.0-or-later">SPFX</option>
|
||||
<option x="1m">unit</option>
|
||||
<option x="this is an example scene">description</option>
|
||||
</optgroup>
|
||||
<optgroup label="multiparty">
|
||||
<option x="matrix://matrix.org/#myroom&room.key=123">src_session</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</td>
|
||||
<td style="text-align:left">
|
||||
<label for="value">Value</label>
|
||||
<br><br>
|
||||
<input id="value" class="w-100" type="text" value=".summer -.winter cube" placeholder="" >
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="border=bottom:none;color:#666">
|
||||
<br><br>
|
||||
ps1. you can test BROWSER_OVERRIDE-enabled fragments (<i>#t=1,200</i> or <i>#fog=2m|FFAABB</i> e.g.) by updating the url<br><br>
|
||||
ps2. see <a href="https://hackmd.io/r-w6JaRgR8OJkbaHiQ8pmQ?view#Asset-linking-fragments" target="_blank">the documentation here</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
<label for="console">parser output:</label>
|
||||
<br><br>
|
||||
<textarea id="console" style="width:100%;height:50vh;" placeholder="" class="w-100"></textarea>
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -5,7 +5,6 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<link type="text/css" rel="stylesheet" href="main.css">
|
||||
<script src="./../../dist/xrfragment.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Import maps polyfill -->
|
||||
|
@ -23,6 +22,7 @@
|
|||
<script type="module">
|
||||
import * as THREE from 'three';
|
||||
|
||||
import xrfragment from './../../../dist/xrfragment.module.js';
|
||||
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
||||
import { Lensflare, LensflareElement } from 'three/addons/objects/Lensflare.js';
|
||||
import { BoxLineGeometry } from 'three/addons/geometries/BoxLineGeometry.js';
|
||||
|
@ -41,7 +41,7 @@
|
|||
let stats, statsMesh;
|
||||
|
||||
const parameters = {
|
||||
scale: 0.3,
|
||||
light: 1.0,
|
||||
};
|
||||
|
||||
init();
|
||||
|
@ -50,27 +50,17 @@
|
|||
function init() {
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color( 0xcccccc );
|
||||
|
||||
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
|
||||
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 2000 );
|
||||
|
||||
let room = new THREE.LineSegments(
|
||||
new BoxLineGeometry( 6, 6, 6, 10, 10, 10 ).translate( 0, 3, 0 ),
|
||||
new THREE.LineBasicMaterial( { color: 0x202020 } )
|
||||
);
|
||||
scene.add( room );
|
||||
|
||||
let floor = new THREE.Mesh(
|
||||
new THREE.PlaneGeometry( 4.8, 4.8, 2, 2 ).rotateX( - Math.PI / 2 ),
|
||||
new THREE.MeshBasicMaterial( { color: 0x404040, transparent: true, opacity: 0.25 } )
|
||||
);
|
||||
scene.add( floor );
|
||||
|
||||
let model;
|
||||
const loader = new GLTFLoader().setPath( './../assets/')
|
||||
const loader = new GLTFLoader().setPath( './../../assets/')
|
||||
loader.load( 'example1.gltf', function ( gltf ) {
|
||||
gltf.scene.position.y = 1.5
|
||||
gltf.scene.position.z = -1
|
||||
gltf.scene.scale.x = gltf.scene.scale.y = gltf.scene.scale.z = parameters.scale
|
||||
gltf.scene.scale.x = gltf.scene.scale.y = gltf.scene.scale.z = 1;
|
||||
|
||||
const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
|
||||
function recursivelySetChildrenUnlit(mesh,cb) {
|
||||
|
@ -83,18 +73,30 @@
|
|||
}
|
||||
|
||||
let XRF = xrfragment;
|
||||
// turn unlit
|
||||
gltf.scene.traverse( (mesh) => {
|
||||
if( mesh.userData ){
|
||||
let frag = {}
|
||||
for( let k in mesh.userData ) XRF.Parser.parse( k, mesh.userData[k], frag )
|
||||
if( Object.keys(frag).length > 0 ) console.dir(frag)
|
||||
if( Object.keys(frag).length > 0 ){
|
||||
for( let k in frag ){
|
||||
if( k == "env" ){
|
||||
console.dir(frag[k])
|
||||
let env = mesh.getObjectByName(frag[k].string)
|
||||
env.material.map.mapping = THREE.EquirectangularReflectionMapping;
|
||||
scene.environment = env.material.map
|
||||
scene.texture = env.material.map
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mesh instanceof THREE.Mesh) {
|
||||
if (mesh.material && mesh.material.map) {
|
||||
mesh.material = new THREE.MeshBasicMaterial({ map: mesh.material.map });
|
||||
mesh.material.dithering = true
|
||||
mesh.material.map.anisotropy = maxAnisotropy;
|
||||
// turn unlit
|
||||
//mesh.material = new THREE.MeshBasicMaterial({ map: mesh.material.map });
|
||||
//mesh.material.dithering = true
|
||||
//mesh.material.map.anisotropy = maxAnisotropy;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -111,6 +113,7 @@
|
|||
renderer.autoClear = false;
|
||||
renderer.setPixelRatio( window.devicePixelRatio );
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
renderer.outputEncoding = THREE.sRGBEncoding;
|
||||
renderer.xr.enabled = true;
|
||||
document.body.appendChild( renderer.domElement );
|
||||
|
||||
|
@ -126,7 +129,7 @@
|
|||
|
||||
controls.screenSpacePanning = false;
|
||||
|
||||
controls.minDistance = 1;
|
||||
controls.minDistance = 0.1;
|
||||
controls.maxDistance = 5000;
|
||||
controls.maxPolarAngle = Math.PI / 2;
|
||||
controls.target = new THREE.Vector3(0,1.6,0)
|
||||
|
@ -159,14 +162,11 @@
|
|||
// GUI
|
||||
|
||||
function onChange() {
|
||||
model.scale.x = model.scale.y = model.scale.z = parameters.scale;
|
||||
}
|
||||
|
||||
function onThicknessChange() {
|
||||
renderer.toneMappingExposure = parameters.light;
|
||||
}
|
||||
|
||||
const gui = new GUI( { width: 300 } );
|
||||
gui.add( parameters, 'scale', 0.0, 1.0, parameters.scale ).onChange( onChange );
|
||||
gui.add( parameters, 'light', 0.2, 3.0, 0.1 ).onChange( onChange );
|
||||
gui.domElement.style.visibility = 'hidden';
|
||||
|
||||
const group = new InteractiveGroup( renderer, camera );
|
13
make
13
make
|
@ -35,5 +35,16 @@ doc(){
|
|||
src/xrfragment/Parser.hx > doc/RFC.md
|
||||
}
|
||||
|
||||
test -z $1 && { try rm dist/* ; haxe build.hxml; sed -i 's|.*nonlocal .*||g' dist/xrfragment.py; exit $?; }
|
||||
build(){
|
||||
try rm dist/*
|
||||
haxe build.hxml
|
||||
ok=$?
|
||||
sed -i 's|.*nonlocal .*||g' dist/xrfragment.py
|
||||
# add js module
|
||||
cp dist/xrfragment.js dist/xrfragment.module.js
|
||||
echo "export default xrfragment;" >> dist/xrfragment.module.js
|
||||
exit $ok
|
||||
}
|
||||
|
||||
test -z $1 && build
|
||||
test -z $1 || "$@"
|
||||
|
|
Loading…
Reference in New Issue