gn8
This commit is contained in:
449
visual_logic.js
449
visual_logic.js
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Generated by Verge3D Puzzles v.2.12.5
|
||||
* Sat Jun 08 2019 00:30:36 GMT+0200 (Mitteleuropäische Sommerzeit)
|
||||
* Sat Jun 08 2019 04:01:26 GMT+0200 (Mitteleuropäische Sommerzeit)
|
||||
* Do not edit this file - your changes may get overridden when Puzzles are saved.
|
||||
* Refer to https://www.soft8soft.com/docs/manual/en/introduction/Using-JavaScript.html
|
||||
* for information on how to add your own JavaScript to Verge3D apps.
|
||||
@@ -91,17 +91,7 @@ PL.execInitPuzzles = function() {
|
||||
preloaderEndCb: function() {},
|
||||
}
|
||||
}
|
||||
var ctrlInit, cinitx, cinity, cinitz;
|
||||
|
||||
|
||||
// addHTMLElement puzzle
|
||||
function addHTMLElement(elemType, id) {
|
||||
var elem = document.createElement(elemType);
|
||||
document.body.appendChild(elem);
|
||||
elem.id = id;
|
||||
elem.style.position = "absolute";
|
||||
}
|
||||
|
||||
var cinitx, cinity, cinitz;
|
||||
|
||||
|
||||
// utility functions envoked by the HTML puzzles
|
||||
@@ -144,19 +134,6 @@ function getElement(id, isParent) {
|
||||
|
||||
|
||||
|
||||
// setHTMLElemAttribute puzzle
|
||||
function setHTMLElemAttribute(attr, value, ids, isParent) {
|
||||
var elems = getElements(ids, isParent);
|
||||
for (var i = 0; i < elems.length; i++) {
|
||||
var elem = elems[i];
|
||||
if (!elem)
|
||||
continue;
|
||||
elem[attr] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// setHTMLElemStyle puzzle
|
||||
function setHTMLElemStyle(prop, value, ids, isParent) {
|
||||
var elems = getElements(ids, isParent);
|
||||
@@ -170,9 +147,6 @@ function setHTMLElemStyle(prop, value, ids, isParent) {
|
||||
|
||||
|
||||
|
||||
addHTMLElement('input', 'lightness');
|
||||
setHTMLElemAttribute('type', 'range', 'lightness', false);
|
||||
|
||||
|
||||
// initSettings puzzle
|
||||
_initGlob.output.initOptions.fadeAnnotations = true;
|
||||
@@ -181,14 +155,6 @@ _initGlob.output.initOptions.preserveDrawBuf = false;
|
||||
_initGlob.output.initOptions.useCompAssets = false;
|
||||
_initGlob.output.initOptions.useFullscreen = false;
|
||||
|
||||
ctrlInit;
|
||||
|
||||
addHTMLElement('input', 'hue');
|
||||
setHTMLElemAttribute('type', 'range', 'hue', false);
|
||||
|
||||
addHTMLElement('input', 'saturation');
|
||||
setHTMLElemAttribute('type', 'range', 'saturation', false);
|
||||
|
||||
setHTMLElemStyle('backgroundColor', 'rgb(127,127,127)', ["BODY"], false);
|
||||
cinitx = 0;
|
||||
cinity = 0;
|
||||
@@ -204,7 +170,7 @@ initOptions = initOptions || {};
|
||||
if ('fadeAnnotations' in initOptions) {
|
||||
_pGlob.fadeAnnotations = initOptions.fadeAnnotations;
|
||||
}
|
||||
var distZ, r, g, b, stepY, distY, dragging, distX, inboundStepper, maxDist, sat, hue, value;
|
||||
var distZ, r, g, b, distY, dragging, distX, inboundStepper, r_, maxDist, bitState, stepY, hue, g_, sat, b_, value;
|
||||
|
||||
|
||||
// utility function envoked by almost all V3D-specific puzzles
|
||||
@@ -332,152 +298,14 @@ function getObjTransform(objName, mode, coord) {
|
||||
|
||||
|
||||
|
||||
// getObjectMaterial puzzle
|
||||
function getObjectMaterial(objNames) {
|
||||
objNames = retrieveObjectNames(objNames);
|
||||
if (!objNames)
|
||||
return '';
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
var objName = objNames[i]
|
||||
if (!objName)
|
||||
continue;
|
||||
var obj = getObjectByName(objName);
|
||||
if (!obj)
|
||||
continue;
|
||||
if (obj.material && typeof obj.material.name == "string")
|
||||
return obj.material.name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// assignMaterial puzzle
|
||||
function assignMat(objNames, matName) {
|
||||
objNames = retrieveObjectNames(objNames);
|
||||
if (!objNames || !matName)
|
||||
return;
|
||||
var mat = v3d.SceneUtils.getMaterialByName(appInstance, matName);
|
||||
if (!mat)
|
||||
return;
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
var objName = objNames[i];
|
||||
if (!objName)
|
||||
continue;
|
||||
var obj = getObjectByName(objName);
|
||||
if (obj)
|
||||
obj.material = mat;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// utility function used by the whenClicked, whenHovered and whenDraggedOver puzzles
|
||||
function initObjectPicking(callback, eventType, mouseDownUseTouchStart) {
|
||||
|
||||
var elem = appInstance.container;
|
||||
elem.addEventListener(eventType, pickListener);
|
||||
if (eventType == "mousedown") {
|
||||
var touchEventName = mouseDownUseTouchStart ? "touchstart" : "touchend";
|
||||
elem.addEventListener(touchEventName, pickListener);
|
||||
}
|
||||
|
||||
var raycaster = new v3d.Raycaster();
|
||||
function pickListener(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var xNorm = 0, yNorm = 0;
|
||||
if (event instanceof MouseEvent) {
|
||||
xNorm = event.offsetX / elem.clientWidth;
|
||||
yNorm = event.offsetY / elem.clientHeight;
|
||||
} else if (event instanceof TouchEvent) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
xNorm = (event.changedTouches[0].clientX - rect.left) / rect.width;
|
||||
yNorm = (event.changedTouches[0].clientY - rect.top) / rect.height;
|
||||
}
|
||||
|
||||
_pGlob.screenCoords.x = xNorm * 2 - 1;
|
||||
_pGlob.screenCoords.y = -yNorm * 2 + 1;
|
||||
raycaster.setFromCamera(_pGlob.screenCoords, appInstance.camera);
|
||||
var objList = [];
|
||||
appInstance.scene.traverse(function(obj){objList.push(obj);});
|
||||
var intersects = raycaster.intersectObjects(objList);
|
||||
if (intersects.length > 0) {
|
||||
var obj = intersects[0].object;
|
||||
callback(obj, event);
|
||||
} else {
|
||||
callback(null, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// utility function used by the whenDraggedOver puzzles
|
||||
function fireObjectPickingCallbacks(objName, source, index, cbParam) {
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
var cb = source[i];
|
||||
if (objectsIncludeObj([cb[0]], objName)) {
|
||||
cb[index](cbParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function objectsIncludeObj(objNames, testedObjName) {
|
||||
if (!testedObjName) return false;
|
||||
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
if (testedObjName == objNames[i]) {
|
||||
return true;
|
||||
} else {
|
||||
// also check children which are auto-generated for multi-material objects
|
||||
var obj = getObjectByName(objNames[i]);
|
||||
if (obj && obj.type == "Group") {
|
||||
for (var j = 0; j < obj.children.length; j++) {
|
||||
if (testedObjName == obj.children[j].name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// utility function used by the whenClicked, whenHovered and whenDraggedOver puzzles
|
||||
function getPickedObjectName(obj) {
|
||||
// auto-generated from a multi-material object, use parent name instead
|
||||
if (obj.isMesh && obj.isMaterialGeneratedMesh && obj.parent) {
|
||||
return obj.parent.name;
|
||||
} else {
|
||||
return obj.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// whenClicked puzzle
|
||||
initObjectPicking(function(obj) {
|
||||
|
||||
// save the object for the pickedObject block
|
||||
_pGlob.pickedObject = obj ? getPickedObjectName(obj) : '';
|
||||
|
||||
_pGlob.objClickCallbacks.forEach(function(el) {
|
||||
var isPicked = obj && objectsIncludeObj(el.objNames, getPickedObjectName(obj));
|
||||
el.callbacks[isPicked ? 0 : 1]();
|
||||
});
|
||||
}, 'mousedown');
|
||||
|
||||
|
||||
|
||||
// whenClicked puzzle
|
||||
function registerOnClick(objNames, cbDo, cbIfMissedDo) {
|
||||
objNames = retrieveObjectNames(objNames) || [];
|
||||
var objNamesFiltered = objNames.filter(function(name) {
|
||||
return name;
|
||||
});
|
||||
_pGlob.objClickCallbacks.push({
|
||||
objNames: objNamesFiltered,
|
||||
callbacks: [cbDo, cbIfMissedDo]
|
||||
});
|
||||
// ssao puzzle
|
||||
function ssao(radius, aoClamp, lumInfluence) {
|
||||
appInstance.enablePostprocessing([{
|
||||
type: 'ssao',
|
||||
radius: radius,
|
||||
aoClamp: aoClamp,
|
||||
lumInfluence: lumInfluence
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
@@ -654,6 +482,88 @@ function getJSFunction(funcName) {
|
||||
|
||||
|
||||
|
||||
// utility function used by the whenClicked, whenHovered and whenDraggedOver puzzles
|
||||
function initObjectPicking(callback, eventType, mouseDownUseTouchStart) {
|
||||
|
||||
var elem = appInstance.container;
|
||||
elem.addEventListener(eventType, pickListener);
|
||||
if (eventType == "mousedown") {
|
||||
var touchEventName = mouseDownUseTouchStart ? "touchstart" : "touchend";
|
||||
elem.addEventListener(touchEventName, pickListener);
|
||||
}
|
||||
|
||||
var raycaster = new v3d.Raycaster();
|
||||
function pickListener(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var xNorm = 0, yNorm = 0;
|
||||
if (event instanceof MouseEvent) {
|
||||
xNorm = event.offsetX / elem.clientWidth;
|
||||
yNorm = event.offsetY / elem.clientHeight;
|
||||
} else if (event instanceof TouchEvent) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
xNorm = (event.changedTouches[0].clientX - rect.left) / rect.width;
|
||||
yNorm = (event.changedTouches[0].clientY - rect.top) / rect.height;
|
||||
}
|
||||
|
||||
_pGlob.screenCoords.x = xNorm * 2 - 1;
|
||||
_pGlob.screenCoords.y = -yNorm * 2 + 1;
|
||||
raycaster.setFromCamera(_pGlob.screenCoords, appInstance.camera);
|
||||
var objList = [];
|
||||
appInstance.scene.traverse(function(obj){objList.push(obj);});
|
||||
var intersects = raycaster.intersectObjects(objList);
|
||||
if (intersects.length > 0) {
|
||||
var obj = intersects[0].object;
|
||||
callback(obj, event);
|
||||
} else {
|
||||
callback(null, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// utility function used by the whenDraggedOver puzzles
|
||||
function fireObjectPickingCallbacks(objName, source, index, cbParam) {
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
var cb = source[i];
|
||||
if (objectsIncludeObj([cb[0]], objName)) {
|
||||
cb[index](cbParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function objectsIncludeObj(objNames, testedObjName) {
|
||||
if (!testedObjName) return false;
|
||||
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
if (testedObjName == objNames[i]) {
|
||||
return true;
|
||||
} else {
|
||||
// also check children which are auto-generated for multi-material objects
|
||||
var obj = getObjectByName(objNames[i]);
|
||||
if (obj && obj.type == "Group") {
|
||||
for (var j = 0; j < obj.children.length; j++) {
|
||||
if (testedObjName == obj.children[j].name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// utility function used by the whenClicked, whenHovered and whenDraggedOver puzzles
|
||||
function getPickedObjectName(obj) {
|
||||
// auto-generated from a multi-material object, use parent name instead
|
||||
if (obj.isMesh && obj.isMaterialGeneratedMesh && obj.parent) {
|
||||
return obj.parent.name;
|
||||
} else {
|
||||
return obj.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function eventGetOffsetCoords(e, touchId, dest) {
|
||||
if (e instanceof MouseEvent) {
|
||||
dest.set(e.offsetX, e.offsetY);
|
||||
@@ -824,6 +734,74 @@ function registerOnDrag(objNames, callback_start, callback_move, callback_drop,
|
||||
|
||||
|
||||
|
||||
// getObjectMaterial puzzle
|
||||
function getObjectMaterial(objNames) {
|
||||
objNames = retrieveObjectNames(objNames);
|
||||
if (!objNames)
|
||||
return '';
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
var objName = objNames[i]
|
||||
if (!objName)
|
||||
continue;
|
||||
var obj = getObjectByName(objName);
|
||||
if (!obj)
|
||||
continue;
|
||||
if (obj.material && typeof obj.material.name == "string")
|
||||
return obj.material.name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// assignMaterial puzzle
|
||||
function assignMat(objNames, matName) {
|
||||
objNames = retrieveObjectNames(objNames);
|
||||
if (!objNames || !matName)
|
||||
return;
|
||||
var mat = v3d.SceneUtils.getMaterialByName(appInstance, matName);
|
||||
if (!mat)
|
||||
return;
|
||||
for (var i = 0; i < objNames.length; i++) {
|
||||
var objName = objNames[i];
|
||||
if (!objName)
|
||||
continue;
|
||||
var obj = getObjectByName(objName);
|
||||
if (obj)
|
||||
obj.material = mat;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// whenClicked puzzle
|
||||
initObjectPicking(function(obj) {
|
||||
|
||||
// save the object for the pickedObject block
|
||||
_pGlob.pickedObject = obj ? getPickedObjectName(obj) : '';
|
||||
|
||||
_pGlob.objClickCallbacks.forEach(function(el) {
|
||||
var isPicked = obj && objectsIncludeObj(el.objNames, getPickedObjectName(obj));
|
||||
el.callbacks[isPicked ? 0 : 1]();
|
||||
});
|
||||
}, 'mousedown');
|
||||
|
||||
|
||||
|
||||
// whenClicked puzzle
|
||||
function registerOnClick(objNames, cbDo, cbIfMissedDo) {
|
||||
objNames = retrieveObjectNames(objNames) || [];
|
||||
var objNamesFiltered = objNames.filter(function(name) {
|
||||
return name;
|
||||
});
|
||||
_pGlob.objClickCallbacks.push({
|
||||
objNames: objNamesFiltered,
|
||||
callbacks: [cbDo, cbIfMissedDo]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function matGetColors(matName) {
|
||||
|
||||
var mat = v3d.SceneUtils.getMaterialByName(appInstance, matName);
|
||||
@@ -869,35 +847,15 @@ function setMaterialColor(matName, colName, r, g, b) {
|
||||
|
||||
function setRGB(r, g, b) {
|
||||
setMaterialColor("transparent", "Principled BSDF Color", r, g, b);
|
||||
r_ = r;
|
||||
g_ = g;
|
||||
b_ = b;
|
||||
printStates();
|
||||
}
|
||||
appInstance.ExternalInterface["setRGB"] = setRGB;
|
||||
|
||||
|
||||
|
||||
// bloom puzzle
|
||||
function bloom(threshold, strength, radius) {
|
||||
appInstance.enablePostprocessing([{
|
||||
type: 'bloom',
|
||||
threshold: threshold,
|
||||
strength: strength,
|
||||
radius: radius
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ssao puzzle
|
||||
function ssao(radius, aoClamp, lumInfluence) {
|
||||
appInstance.enablePostprocessing([{
|
||||
type: 'ssao',
|
||||
radius: radius,
|
||||
aoClamp: aoClamp,
|
||||
lumInfluence: lumInfluence
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// getEventProperty puzzle
|
||||
function getEventProperty(prop, event) {
|
||||
if (typeof event != "undefined") {
|
||||
@@ -963,19 +921,31 @@ function eventHTMLElem(eventType, ids, isParent, callback) {
|
||||
|
||||
|
||||
|
||||
// toFixedPoint puzzle
|
||||
function toNumber(num, prec) {
|
||||
prec = Math.pow(10, prec);
|
||||
return Math.round(num * prec)/prec;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Describe this function...
|
||||
*/
|
||||
function printStates() {
|
||||
console.log(['Bit [',bitState,'] Qubit: [',toNumber(r_, 3),'] [',toNumber(g_, 3),'] [',toNumber(b_, 3),']'].join(''));
|
||||
}
|
||||
|
||||
|
||||
distZ = getObjTransform("qubit", "position", "y") - getObjTransform("qubit_controller", "position", "y");
|
||||
distY = getObjTransform("qubit", "position", "z") - getObjTransform("qubit_controller", "position", "z");
|
||||
distX = getObjTransform("qubit", "position", "x") - getObjTransform("qubit_controller", "position", "x");
|
||||
maxDist = 2;
|
||||
maxDist = 2.3;
|
||||
stepY = 0.1;
|
||||
|
||||
registerOnClick("bit", function() {
|
||||
if (getObjectMaterial("bit") == "white") {
|
||||
assignMat("bit", "black");
|
||||
} else {
|
||||
assignMat("bit", "white");
|
||||
}
|
||||
}, function() {});
|
||||
bitState = 0;
|
||||
r_ = 0;
|
||||
g_ = 0;
|
||||
b_ = 0;
|
||||
ssao(1, 0.01, 0.3);
|
||||
|
||||
registerOnDrag(["GROUP", "qubit_grp"], function() {
|
||||
dragging = true;
|
||||
@@ -987,40 +957,49 @@ registerOnDrag(["GROUP", "qubit_grp"], function() {
|
||||
distX = getObjTransform("qubit", "position", "x") - getObjTransform("qubit_controller", "position", "x");
|
||||
while (getDistanceBetweenObjects("qubit_controller", "qubit") > maxDist) {
|
||||
inboundStepper = (typeof inboundStepper == 'number' ? inboundStepper : 0) + 1;
|
||||
applyObjLocalTransform("qubit_controller", "position", (distX / 50) * inboundStepper, 0, (distZ / 50) * inboundStepper);
|
||||
applyObjLocalTransform("qubit_controller", "position", distX / 200, 0, distZ / 100);
|
||||
}
|
||||
hue = 0;
|
||||
distZ = getObjTransform("qubit", "position", "y") - getObjTransform("qubit_controller", "position", "y");
|
||||
distX = getObjTransform("qubit", "position", "x") - getObjTransform("qubit_controller", "position", "x");
|
||||
hue = Math.atan(Math.abs(distY / distX)) / Math.PI * 180;
|
||||
sat = Math.sqrt(distX * distX + distY * distY) / maxDist;
|
||||
value = ((distZ - maxDist) / (2 * maxDist)) * -1;
|
||||
getJSFunction('HSVtoRGB')(hue, sat, value);
|
||||
getJSFunction('HSVtoRGB')(hue / 180, sat, value);
|
||||
},
|
||||
function() {
|
||||
dragging = false;
|
||||
}, "x7;j`9Tr6$fIW]tXfLwm");
|
||||
|
||||
bloom(0.5, 0.2, 0.15);
|
||||
ssao(2, 0.25, 0.7);
|
||||
registerOnClick("bit", function() {
|
||||
if (getObjectMaterial("bit") == "white") {
|
||||
assignMat("bit", "black");
|
||||
bitState = 0;
|
||||
} else {
|
||||
assignMat("bit", "white");
|
||||
bitState = 1;
|
||||
}
|
||||
printStates();
|
||||
}, function() {});
|
||||
|
||||
eventHTMLElem('wheel', ["DOCUMENT"], false, function(event) {
|
||||
if (dragging == true) {
|
||||
if (getEventProperty('deltaY', event) < 0) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY, 0);
|
||||
if (getDistanceBetweenObjects("qubit_controller", "qubit") >= maxDist) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY * -1, 0);
|
||||
}
|
||||
} else if (getEventProperty('deltaY', event) > 0) {
|
||||
if (getEventProperty('deltaY', event) < 0) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY, 0);
|
||||
if (getDistanceBetweenObjects("qubit_controller", "qubit") >= maxDist) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY * -1, 0);
|
||||
if (getDistanceBetweenObjects("qubit_controller", "qubit") >= maxDist) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY, 0);
|
||||
}
|
||||
}
|
||||
distY = getObjTransform("qubit", "position", "z") - getObjTransform("qubit_controller", "position", "z");
|
||||
sat = Math.sqrt(distX * distX + distY * distY) / maxDist;
|
||||
} else if (getEventProperty('deltaY', event) > 0) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY * -1, 0);
|
||||
if (getDistanceBetweenObjects("qubit_controller", "qubit") >= maxDist) {
|
||||
applyObjLocalTransform("qubit_controller", "position", 0, stepY, 0);
|
||||
}
|
||||
}
|
||||
distY = getObjTransform("qubit", "position", "z") - getObjTransform("qubit_controller", "position", "z");
|
||||
hue = Math.atan(Math.abs(distY / distX)) / Math.PI * 180;
|
||||
sat = Math.sqrt(distX * distX + distY * distY) / maxDist;
|
||||
value = ((distZ - maxDist) / (2 * maxDist)) * -1;
|
||||
getJSFunction('HSVtoRGB')(hue / 180, sat, value);
|
||||
});
|
||||
|
||||
stepY;
|
||||
|
||||
} // end of PL.init function
|
||||
|
||||
if (window.v3dApp) {
|
||||
|
||||
Reference in New Issue
Block a user