first('.panelclick').addEventListener("click", function () {
first('panel').classList.toggle('hdn-i');
first('.panelclick').classList.toggle('cwgray');
});
first('.helperclick').addEventListener("click", function () {
first('helper').classList.toggle('hdn-i');
first('.helperclick').classList.toggle('cwgray');
});
first('.propclick').addEventListener("click", function () {
first('prop').classList.toggle('hdn-i');
first('.propclick').classList.toggle('cwgray');
});
function refreshStorage() {
first('storage > div').innerHTML = "";
first('storage > div').innerHTML += "
TempDb : Geometries Instance
";
db_temp.all(function (c, v) {
var html = first('storageMeshTemp').innerHTML
.replaceAll('#[Name]', c.name)
.replaceAll('#[detail]', c.op.id)
.replaceAll('#[ActionDb]', 'deleteDbMesh')
.replaceAll('#[Action]', 'editDbMesh')
.replaceAll('#[Option]', JSON.stringify(c.op).replaceAll('"', '^'))
.replaceAll('#[Theme]', 'm-00125 w-auto cdark cnavy c-hblack c-i-hblue c-twhite pl-005 pr-005 rad-05 ba-i-02 c-b-iblack')
.replaceAll('#[Index]', c.ind)
.replaceAll('#[dbInd]', c.id)
.replaceAll('#[Select]', geos[c.ind] ? "corg" : "")
;
first('storage > div').innerHTML += html;
}, function () {
first('storage > div').innerHTML += " Main : Geometries Instance
";
db_main.all(function (c, v) {
var html = first('storageMeshTemp').innerHTML
.replaceAll('#[Name]', c.name)
.replaceAll('#[detail]', c.op.id)
.replaceAll('#[ActionDb]', 'deleteDbMesh')
.replaceAll('#[Action]', 'editDbMesh')
.replaceAll('#[Theme]', 'm-00125 w-auto cdark cnavy c-hblack c-i-hblue c-twhite pl-005 pr-005 rad-05 ba-i-02 c-b-iblack')
.replaceAll('#[Index]', c.ind)
.replaceAll('#[dbInd]', c.id)
.replaceAll('#[Select]', geos[c.ind] ? "corg" : "");
first('storage > div').innerHTML += html;
}, function () {
}, 0);
}, 0);
}
first('.storageclick').addEventListener("click", function () {
dy.body.iclick(event, this, function () { console.log('storage logo'); }, 1)
first('storage').classList.toggle('hdn-i');
first('.storageclick').classList.toggle('c-iwhite');
if (first('storage').className.indexOf('hdn-i') == -1) {
refreshStorage();
}
});
document.body.addEventListener("keyup", function (event) {
if (event.keyCode == 192 && event.altKey) {
if (first('panel').className.indexOf('hdn-i') == -1) {
first('panel').classList.add('hdn-i');
first('.panelclick').classList.remove('cwgray');
first('panel').classList.add('sphide');
} else if (first('panel').className.indexOf('hdn-i') != -1 && first('panel').className.indexOf('sphide') != -1) {
first('panel').classList.remove('hdn-i');
first('.panelclick').classList.add('cwgray');
first('panel').classList.remove('sphide');
}
if (first('helper').className.indexOf('hdn-i') == -1) {
first('helper').classList.add('hdn-i');
first('.helperclick').classList.remove('cwgray');
first('helper').classList.add('sphide');
} else if (first('helper').className.indexOf('hdn-i') != -1 && first('helper').className.indexOf('sphide') != -1) {
first('helper').classList.remove('hdn-i');
first('.helperclick').classList.add('cwgray');
first('helper').classList.remove('sphide');
}
if (first('prop').className.indexOf('hdn-i') == -1) {
first('prop').classList.add('hdn-i');
first('.propclick').classList.remove('cwgray');
first('prop').classList.add('sphide');
} else if (first('prop').className.indexOf('hdn-i') != -1 && first('prop').className.indexOf('sphide') != -1) {
first('prop').classList.remove('hdn-i');
first('.propclick').classList.add('cwgray');
first('prop').classList.remove('sphide');
}
event.preventDefault();
return false;
}
if (event.keyCode == 49 && event.altKey) {
first('panel').classList.toggle('hdn-i');
first('.panelclick').classList.toggle('cwgray');
event.preventDefault();
return false;
}
if (event.keyCode == 50 && event.altKey) {
first('helper').classList.toggle('hdn-i');
first('.helperclick').classList.toggle('cwgray');
event.preventDefault();
return false;
}
if (event.keyCode == 51 && event.altKey) {
first('prop').classList.toggle('hdn-i');
first('.propclick').classList.toggle('cwgray');
event.preventDefault();
return false;
}
});
var geometryIndex = 0;
var geos = [], params = [];
var attachToModelsList = function (name) {
geometryIndex++;
all('.geoInstance', function (at) {
at.classList.remove('cnavy');
at.classList.remove('c-i-hblue');
}, function () {
});
var html = first('modelTemp').innerHTML
.replaceAll('#[Name]', name)
.replaceAll('#[Action]', 'editParameters')
.replaceAll('#[Theme]', 'geoInstance m-00125 w-auto cdark cnavy c-hblack c-i-hblue c-twhite pl-005 pr-005 rad-05 ba-i-02 c-b-iblack')
.replaceAll('#[Index]', geometryIndex);
first('panel').innerHTML += html;
var obj;
eval('obj = geo_' + name + ';');
first('prop').innerHTML = "";
var ii = 0;
for (var prp in obj.prps) {
ii++;
var pr2 = obj.prps[prp].toString().substr(obj.prps[prp].toString().indexOf(':')+1, obj.prps[prp].toString().length - obj.prps[prp].toString().indexOf(":")-1);
prp = obj.prps[prp].split(':');
var prpItem = first('parameterTemp').innerHTML
.replaceAll('#[Value]', pr2)
.replaceAll('#[Name]', prp[0])
.replaceAll('#[Parent]', name)
.replaceAll('#[Theme]', ii % 2 == 0 ? 'ctrblack' : ' ')
.replaceAll('#[Index]', geometryIndex);
first('prop').innerHTML += prpItem;
}
geos[geometryIndex] = obj.toMesh(getParameters(geometryIndex, name));
}
var editParameters = function (name, ind, th) {
var obj;
eval('obj = geo_' + name + ';');
var pp = params[ind];
first('prop').innerHTML = "";
var ii = 0;
all('.geoInstance', function (at) {
at.classList.remove('cnavy');
at.classList.remove('c-i-hblue');
}, function () {
th.classList.add('cnavy');
th.classList.add('c-i-hblue');
});
for (var prp in obj.prps) {
ii++;
prp = obj.prps[prp].split(':');
var prpItem = first('parameterTemp').innerHTML
.replaceAll('#[Value]', eval('params[' + ind + '].' + prp[0]))
.replaceAll('#[Name]', prp[0])
.replaceAll('#[Parent]', name)
.replaceAll('#[Theme]', ii % 2 == 0 ? 'ctrblack' : ' ')
.replaceAll('#[Index]', ind);
first('prop').innerHTML += prpItem;
}
//geos[ind] = obj.toMesh(getParameters(ind));
}
var getParameters = function (i, n) {
var op = {};
return all('prop input', function (at) {
if (at && at.id) {
eval('op.' + at.id + ' = "' + at.value + '";');
}
}, function () {
if (i) try {
params[i] = op;
// saved
db_temp.add({ ind: i, op: op, name: n }, function () {
var ids = [];
db_temp.all(function (c, v) {
if (c.ind == i && c.name == n)
ids.push(c.id);
}, function (m, e) {
var n1 = 0;
for(var id in ids) {
n1++
if(n1 < ids.length )
var id2 = ids[id];
try {
db_temp.remove(id2, function () { }, 0);
} catch (e) { }
}
});
}, 0);
} catch (e) { }
return op;
})
}
var setParameter = function (v, n, p, i) {
var obj, mat;
if (geos[i]) {
mat = geos[i].material;
geos[i].dispose();
}
eval('obj = geo_' + p + ';');
geos[i] = obj.toMesh(getParameters(i, p));
}
var showDbMesh = function (n, o, i, th) {
if (th.className.indexOf('corg') == -1) {
geos[i].dispose();
}
else {
var obj;
eval('obj = geo_' + n + ';');
var pp = JSON.parse(o.replaceAll('^', '"'));
geos[i] = obj.toMesh(pp);
}
}
var editDbMesh = function (n, o, i, th) {
if (geos[i] && confirm('this index is exist in Temp Storag if you wanna keep both instance')) {
i = ++geometryIndex;
}
if (i >= geometryIndex) geometryIndex = i + 1;
var obj;
eval('obj = geo_' + n + ';');
var pp = JSON.parse(o.replaceAll('^', '"'));
geos[i] = obj.toMesh(pp);
params[i] = pp;
all('.geoInstance', function (at) {
at.classList.remove('cnavy');
at.classList.remove('c-i-hblue');
}, function () {
});
var html = first('modelTemp').innerHTML
.replaceAll('#[Name]', n)
.replaceAll('#[Action]', 'editParameters')
.replaceAll('#[Theme]', 'geoInstance m-00125 w-auto cdark cnavy c-hblack c-i-hblue c-twhite pl-005 pr-005 rad-05 ba-i-02 c-b-iblack')
.replaceAll('#[Index]', i);
first('panel').innerHTML += html;
var pp = params[i];
first('prop').innerHTML = "";
var ii = 0;
for (var prp in obj.prps) {
ii++;
prp = obj.prps[prp].split(':');
var prpItem = first('parameterTemp').innerHTML
.replaceAll('#[Value]', eval('params[' + i + '].' + prp[0]))
.replaceAll('#[Name]', prp[0])
.replaceAll('#[Parent]', n)
.replaceAll('#[Theme]', ii % 2 == 0 ? 'ctrblack' : ' ')
.replaceAll('#[Index]', i);
first('prop').innerHTML += prpItem;
}
first('storage').classList.add('hdn-i');
first('.storageclick').classList.add('c-iwhite');
}
var deleteDbMesh = function (n, o, i, th,dbInd) {
if (confirm('remove mesh from temp db')) {
db_temp.remove(dbInd,function(){
if (geos[i]) {
geos[i].dispose();
geos[i] = null;
params[i] = null;
}
refreshStorage();
},0);
}
}
var dom_body = function () {
first('storage').classList.add('hdn-i');
first('.storageclick').classList.add('c-iwhite');
}