123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- /**
- * Generated by Verge3D Puzzles v.2.12.5
- * Sat Jun 08 2019 21:51:22 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.
- */
-
- "use strict";
-
- (function() {
-
- // global variables/constants used by puzzles' functions
- var _pGlob = {};
-
- _pGlob.objCache = {};
- _pGlob.fadeAnnotations = true;
- _pGlob.objClickCallbacks = [];
- _pGlob.pickedObject = '';
- _pGlob.objHoverCallbacks = [];
- _pGlob.hoveredObject = '';
- _pGlob.objMovementInfos = {};
- _pGlob.objDragOverCallbacks = [];
- _pGlob.objDragOverInfoByBlock = {}
- _pGlob.dragMoveOrigins = {};
- _pGlob.dragScaleOrigins = {};
- _pGlob.mediaElements = {};
- _pGlob.loadedFiles = {};
- _pGlob.loadedFile = '';
- _pGlob.animMixerCallbacks = [];
- _pGlob.arHitPoint = new v3d.Vector3(0, 0, 0);
- _pGlob.states = [];
- _pGlob.percentage = 0;
- _pGlob.animateParamUpdate = null;
- _pGlob.openedFile = '';
- _pGlob.xrSessionAcquired = false;
- _pGlob.xrSessionCallbacks = [];
- _pGlob.screenCoords = new v3d.Vector2();
-
- _pGlob.AXIS_X = new v3d.Vector3(1, 0, 0);
- _pGlob.AXIS_Y = new v3d.Vector3(0, 1, 0);
- _pGlob.AXIS_Z = new v3d.Vector3(0, 0, 1);
- _pGlob.MIN_DRAG_SCALE = 10e-4;
-
- _pGlob.vec2Tmp = new v3d.Vector2();
- _pGlob.vec2Tmp2 = new v3d.Vector2();
- _pGlob.vec3Tmp = new v3d.Vector3();
- _pGlob.vec3Tmp2 = new v3d.Vector3();
- _pGlob.quatTmp = new v3d.Quaternion();
- _pGlob.quatTmp2 = new v3d.Quaternion();
- _pGlob.mat4Tmp = new v3d.Matrix4();
- _pGlob.planeTmp = new v3d.Plane();
- _pGlob.raycasterTmp = new v3d.Raycaster();
- _pGlob.timers = {};
-
- var _pPhysics = {};
-
- _pPhysics.syncList = [];
-
- // internal info
- _pPhysics.collisionData = [];
-
- // goes to collision callback
- _pPhysics.collisionInfo = {
- objectA: '',
- objectB: '',
- distance: 0,
- positionOnA: [0, 0, 0],
- positionOnB: [0, 0, 0],
- normalOnB: [0, 0, 0]
- };
-
- var PL = v3d.PL = v3d.PL || {};
-
- PL.legacyMode = false;
-
- PL.execInitPuzzles = function() {
-
- var _initGlob = {};
- _initGlob.percentage = 0;
- _initGlob.output = {
- initOptions: {
- fadeAnnotations: true,
- useBkgTransp: false,
- preserveDrawBuf: false,
- useCompAssets: false,
- useFullscreen: true,
- useCustomPreloader: false,
- preloaderStartCb: function() {},
- preloaderProgressCb: function() {},
- preloaderEndCb: function() {},
- }
- }
-
- // utility functions envoked by the HTML puzzles
- function getElements(ids, isParent) {
- var elems = [];
- if (Array.isArray(ids) && ids[0] != "WINDOW" && ids[0] != "DOCUMENT" && ids[0] != "BODY") {
- for (var i = 0; i < ids.length; i++)
- elems.push(getElement(ids[i], isParent));
- } else {
- elems.push(getElement(ids, isParent));
- }
- return elems;
- }
-
- function getElement(id, isParent) {
- var elem;
- if (Array.isArray(id) && id[0] == "WINDOW") {
- if (isParent)
- elem = parent;
- else
- elem = window;
- } else if (Array.isArray(id) && id[0] == "DOCUMENT") {
- if (isParent)
- elem = parent.document;
- else
- elem = document;
- } else if (Array.isArray(id) && id[0] == "BODY") {
- if (isParent)
- elem = parent.document.body;
- else
- elem = document.body;
- } else {
- if (isParent)
- elem = parent.document.getElementById(id);
- else
- elem = document.getElementById(id);
- }
- return elem;
- }
-
-
-
- // setHTMLElemStyle puzzle
- function setHTMLElemStyle(prop, value, ids, isParent) {
- var elems = getElements(ids, isParent);
- for (var i = 0; i < elems.length; i++) {
- var elem = elems[i];
- if (!elem || !elem.style)
- continue;
- elem.style[prop] = value;
- }
- }
-
-
-
-
- // initSettings puzzle
- _initGlob.output.initOptions.fadeAnnotations = true;
- _initGlob.output.initOptions.useBkgTransp = true;
- _initGlob.output.initOptions.preserveDrawBuf = false;
- _initGlob.output.initOptions.useCompAssets = false;
- _initGlob.output.initOptions.useFullscreen = false;
-
- setHTMLElemStyle('backgroundColor', 'rgb(127,127,127)', ["BODY"], false);
-
- return _initGlob.output;
- }
-
- PL.init = function(appInstance, initOptions) {
-
- initOptions = initOptions || {};
-
- if ('fadeAnnotations' in initOptions) {
- _pGlob.fadeAnnotations = initOptions.fadeAnnotations;
- }
- var distZ, R, G, B, hue, dragging, distY, distX, inboundStepper, r_, maxDist, recordqubitstate, recordbitstate, bitstate, stepY, g_, sat, b_, value;
-
-
- // utility function envoked by almost all V3D-specific puzzles
- // process object input, which can be either single obj or array of objects, or a group
- function retrieveObjectNames(objNames) {
- var acc = [];
- retrieveObjectNamesAcc(objNames, acc);
- return acc;
- }
-
- function retrieveObjectNamesAcc(currObjNames, acc) {
- if (typeof currObjNames == "string") {
- acc.push(currObjNames);
- } else if (Array.isArray(currObjNames) && currObjNames[0] == "GROUP") {
- var newObj = getObjectNamesByGroupName(currObjNames[1]);
- for (var i = 0; i < newObj.length; i++)
- acc.push(newObj[i]);
- } else if (Array.isArray(currObjNames) && currObjNames[0] == "ALL_OBJECTS") {
- var newObj = getAllObjectNames();
- for (var i = 0; i < newObj.length; i++)
- acc.push(newObj[i]);
- } else if (Array.isArray(currObjNames)) {
- for (var i = 0; i < currObjNames.length; i++)
- retrieveObjectNamesAcc(currObjNames[i], acc);
- }
- }
-
-
- // utility function envoked by almost all V3D-specific puzzles
- // find first occurence of the object by its name
- function getObjectByName(objName) {
- var objFound;
- var runTime = typeof _pGlob != "undefined";
- objFound = runTime ? _pGlob.objCache[objName] : null;
- if (objFound && objFound.name == objName)
- return objFound;
- appInstance.scene.traverse(function(obj) {
- if (!objFound && notIgnoredObj(obj) && (obj.name == objName)) {
- objFound = obj;
- if (runTime)
- _pGlob.objCache[objName] = objFound;
- }
- });
- return objFound;
- }
-
- // utility function envoked by almost all V3D-specific puzzles
- // retrieve all objects which belong to the group
- function getObjectNamesByGroupName(targetGroupName) {
- var objNameList = [];
- appInstance.scene.traverse(function(obj){
- if (notIgnoredObj(obj)) {
- var groupNames = obj.groupNames;
- if (!groupNames)
- return;
- for (var i = 0; i < groupNames.length; i++) {
- var groupName = groupNames[i];
- if (groupName == targetGroupName) {
- objNameList.push(obj.name);
- }
- }
- }
- });
- return objNameList;
- }
-
- // utility function envoked by almost all V3D-specific puzzles
- // filter off some non-mesh types
- function notIgnoredObj(obj) {
- return (obj.type != "Scene" && obj.type != "AmbientLight" &&
- obj.name != "" && !(obj.isMesh && obj.isMaterialGeneratedMesh));
- }
-
- // utility function envoked by almost all V3D-specific puzzles
- // retrieve all objects on the scene
- function getAllObjectNames() {
- var objNameList = [];
- appInstance.scene.traverse(function(obj) {
- if (notIgnoredObj(obj))
- objNameList.push(obj.name)
- });
- return objNameList;
- }
-
- function swizzleValueSign(newAxis, value) {
- newAxis = newAxis.toLowerCase();
-
- if (newAxis == 'z') {
- if (typeof value == 'number')
- return -value
- else if (typeof value == 'string' && value != '' && value != "''" && value != '""')
- return String(-Number(value));
- else
- return value;
- } else
- return value;
- }
-
- function swizzleVec3(vec, isScale) {
-
- var dest = []
-
- dest[0] = vec[0];
- dest[1] = vec[2];
- dest[2] = isScale ? vec[1] : swizzleValueSign('z', vec[1])
-
- return dest;
- }
-
-
- function intersectPlaneCSS(plane, cssX, cssY, dest) {
- var coords = _pGlob.vec2Tmp;
- var rc = _pGlob.raycasterTmp;
- coords.x = (cssX / appInstance.getWidth()) * 2 - 1;
- coords.y = - (cssY / appInstance.getHeight()) * 2 + 1;
- rc.setFromCamera(coords, appInstance.camera);
- return rc.ray.intersectPlane(plane, dest);
- }
-
-
-
- // dragMove puzzle
- function dragMove(objNames, mode, blockId, parentDragOverBlockId) {
- if (!appInstance.camera) return;
-
- objNames = retrieveObjectNames(objNames);
- if (!objNames) return;
-
- var info = _pGlob.objDragOverInfoByBlock[parentDragOverBlockId];
- if (!info) return;
-
- var draggedObj = getObjectByName(info.draggedObjName);
- if (!draggedObj) return;
-
- if (!(blockId in _pGlob.dragMoveOrigins)) {
- _pGlob.dragMoveOrigins[blockId] = [];
- }
- var posOrigins = _pGlob.dragMoveOrigins[blockId];
- var lenDiff = objNames.length - posOrigins.length;
- for (var i = 0; i < lenDiff; i++) {
- posOrigins.push(new v3d.Vector3());
- }
-
- for (var i = 0; i < objNames.length; i++) {
- var obj = getObjectByName(objNames[i]);
- var posOrigin = posOrigins[i];
-
- if (!info.isMoved) {
- // the object position before the first move is used as an initial value
- posOrigin.copy(obj.position);
- }
-
- if (mode == "X" || mode == "Y" || mode == "Z") {
- var axis = mode == "X" ? _pGlob.AXIS_X : (mode == "Y" ? _pGlob.AXIS_Y : _pGlob.AXIS_Z);
- var coord = mode == "X" ? "x" : (mode == "Y" ? "y" : "z");
-
- var planeNor = appInstance.camera.getWorldDirection(_pGlob.vec3Tmp);
- planeNor.cross(axis).cross(axis);
- var plane = _pGlob.planeTmp.setFromNormalAndCoplanarPoint(planeNor, draggedObj.position);
-
- var p0 = intersectPlaneCSS(plane, info.downX, info.downY, _pGlob.vec3Tmp);
- var p1 = intersectPlaneCSS(plane, info.currX, info.currY, _pGlob.vec3Tmp2);
- if (p0 && p1) {
- obj.position[coord] = posOrigin[coord] + p1[coord] - p0[coord];
- }
- } else if (mode == "XY" || mode == "XZ" || mode == "YZ") {
- var normal = mode == "XY" ? _pGlob.AXIS_Z : (mode == "XZ" ? _pGlob.AXIS_Y : _pGlob.AXIS_X);
- var coord0 = mode == "XY" ? "x" : (mode == "XZ" ? "x" : "y");
- var coord1 = mode == "XY" ? "y" : (mode == "XZ" ? "z" : "z");
-
- var plane = _pGlob.planeTmp.setFromNormalAndCoplanarPoint(normal, draggedObj.position);
-
- var p0 = intersectPlaneCSS(plane, info.downX, info.downY, _pGlob.vec3Tmp);
- var p1 = intersectPlaneCSS(plane, info.currX, info.currY, _pGlob.vec3Tmp2);
- if (p0 && p1) {
- obj.position[coord0] = posOrigin[coord0] + p1[coord0] - p0[coord0];
- obj.position[coord1] = posOrigin[coord1] + p1[coord1] - p0[coord1];
- }
- } else if (mode == "XYZ") {
- var planeNor = appInstance.camera.getWorldDirection(_pGlob.vec3Tmp);
- var plane = _pGlob.planeTmp.setFromNormalAndCoplanarPoint(planeNor, draggedObj.position);
-
- var p0 = intersectPlaneCSS(plane, info.downX, info.downY, _pGlob.vec3Tmp);
- var p1 = intersectPlaneCSS(plane, info.currX, info.currY, _pGlob.vec3Tmp2);
- if (p0 && p1) {
- obj.position.addVectors(posOrigin, p1).sub(p0);
- }
- }
- obj.updateMatrixWorld(true);
- }
- }
-
-
-
- // getObjTransform puzzle
- function getObjTransform(objName, mode, coord) {
- if (!objName)
- return;
- var obj = getObjectByName(objName);
- if (!obj)
- return;
- if (mode == "rotation")
- return swizzleValueSign(coord, obj[mode][coord] * 180/Math.PI);
- else if (mode == 'position')
- return swizzleValueSign(coord, obj[mode][coord]);
- else
- return obj[mode][coord];
- }
-
-
-
- // distanceBetweenObjects puzzle
- function getDistanceBetweenObjects(objName1, objName2) {
- if (!objName1 || !objName2)
- return;
- var obj1 = getObjectByName(objName1);
- var obj2 = getObjectByName(objName2);
- if (!obj1 || !obj2)
- return;
- return obj1.getWorldPosition(_pGlob.vec3Tmp).distanceTo(obj2.getWorldPosition(_pGlob.vec3Tmp2));
- }
-
-
-
- // applyObjLocalTransform puzzle
- function applyObjLocalTransform(objNames, mode, x, y, z) {
-
- objNames = retrieveObjectNames(objNames);
- if (!objNames) return;
-
- var defValue = mode == "scale" ? 1 : 0;
- if (typeof x != "number") x = defValue;
- if (typeof y != "number") y = defValue;
- if (typeof z != "number") z = defValue;
-
- var inVec = swizzleVec3([x,y,z], mode == 'scale');
-
- for (var i = 0; i < objNames.length; i++) {
- var objName = objNames[i];
- if (!objName) continue;
-
- var obj = getObjectByName(objName);
- if (!obj) continue;
-
- // don't swizzle values for cameras, their local space happens
- // to be the same as for Blender/Max cameras, bcz their different
- // rest orientation balances difference in coordinate systems
- var useSwizzled = !obj.isCamera;
- var xVal = useSwizzled ? inVec[0] : x;
- var yVal = useSwizzled ? inVec[1] : y;
- var zVal = useSwizzled ? inVec[2] : z;
-
- switch (mode) {
- case "position":
- if (_pGlob.xrSessionAcquired && obj.isCamera) {
- v3d.WebVRUtils.translateVRCamera(obj, _pGlob.AXIS_X, xVal);
- v3d.WebVRUtils.translateVRCamera(obj, _pGlob.AXIS_Y, yVal);
- v3d.WebVRUtils.translateVRCamera(obj, _pGlob.AXIS_Z, zVal);
- } else {
- obj.translateX(xVal);
- obj.translateY(yVal);
- obj.translateZ(zVal);
- }
- break;
- case "rotation":
- if (_pGlob.xrSessionAcquired && obj.isCamera) {
- v3d.WebVRUtils.rotateVRCamera(obj, _pGlob.AXIS_X, v3d.Math.degToRad(xVal));
- v3d.WebVRUtils.rotateVRCamera(obj, _pGlob.AXIS_Y, v3d.Math.degToRad(yVal));
- v3d.WebVRUtils.rotateVRCamera(obj, _pGlob.AXIS_Z, v3d.Math.degToRad(zVal));
- } else {
- obj.rotateX(v3d.Math.degToRad(xVal));
- obj.rotateY(v3d.Math.degToRad(yVal));
- obj.rotateZ(v3d.Math.degToRad(zVal));
- }
- break;
- case "scale":
- obj.scale.x *= xVal;
- obj.scale.y *= yVal;
- obj.scale.z *= zVal;
- break;
- }
-
- obj.updateMatrixWorld(true);
- }
- }
-
-
-
- // 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);
- } else if (window.TouchEvent && e instanceof TouchEvent) {
- var rect = e.target.getBoundingClientRect();
- var touches = e.touches;
- if (e.type == "touchstart" || e.type == "touchend" || e.type == "touchmove") {
- touches = e.changedTouches;
- }
-
- var touch = touches[0];
- for (var i = 0; i < touches.length; i++) {
- if (touches[i].identifier == touchId) {
- touch = touches[i];
- break;
- }
- }
-
- dest.set(touch.clientX - rect.left, touch.clientY - rect.top);
- }
- return dest;
- }
-
-
- function eventTouchIdGetFirst(e) {
- if (e instanceof MouseEvent) {
- return -1;
- } else if (window.TouchEvent && e instanceof TouchEvent) {
- if (e.type == "touchstart" || e.type == "touchend" || e.type == "touchmove") {
- return e.changedTouches[0].identifier;
- } else {
- return e.touches[0].identifier;
- }
- }
- return -1;
- }
-
-
- function eventTouchIdChangedFilter(e, touchId) {
- if (window.TouchEvent && e instanceof TouchEvent) {
- if (e.type == "touchstart" || e.type == "touchend" || e.type == "touchmove") {
- var isChanged = false;
- for (var i = 0; i < e.changedTouches.length; i++) {
- if (e.changedTouches[i].identifier == touchId) {
- isChanged = true;
- break;
- }
- }
- return isChanged;
- }
- }
-
- return true;
- }
-
-
- function initDragOverInfo() {
- return {
- draggedObjName: '',
- downX: 0, downY: 0,
- prevX: 0, prevY: 0,
- currX: 0, currY: 0,
- isDowned: false,
- isMoved: false,
- touchId: -1
- };
- }
-
-
- // whenDraggedOver puzzle
- initObjectPicking(function(obj, downEvent) {
- if (!obj) {
- return;
- }
-
- var objName = getPickedObjectName(obj);
- fireObjectPickingCallbacks(objName, _pGlob.objDragOverCallbacks, 1,
- { downEvent: downEvent, draggedObjName: objName });
- }, "mousedown", true);
-
-
-
- // whenDraggedOver puzzle
- function registerOnDrag(objNames, callback_start, callback_move, callback_drop, blockId) {
- objNames = retrieveObjectNames(objNames);
- if (!objNames)
- return;
- var cb = function(cbParam) {
-
- if (appInstance.controls) {
- appInstance.controls.enabled = false;
- }
-
- if (!(blockId in _pGlob.objDragOverInfoByBlock)) {
- _pGlob.objDragOverInfoByBlock[blockId] = initDragOverInfo();
- }
- var info = _pGlob.objDragOverInfoByBlock[blockId];
-
- // NOTE: don't use more than one pointing event, e.g. don't process
- // some events related to multitouch actions
- if (info.isDowned) {
- return;
- }
-
- var touchId = eventTouchIdGetFirst(cbParam.downEvent);
- var coords = eventGetOffsetCoords(cbParam.downEvent, touchId,
- _pGlob.vec2Tmp);
-
- info.downX = info.prevX = info.currX = coords.x;
- info.downY = info.prevY = info.currY = coords.y;
- info.touchId = touchId;
- info.isDowned = true;
- info.isMoved = false;
- info.draggedObjName = cbParam.draggedObjName;
-
- callback_start();
-
- var elem = appInstance.container;
-
- var moveCb = function(e) {
- if (!eventTouchIdChangedFilter(e, info.touchId)) {
- // don't handle events not intended for this particular touch
- return;
- }
-
- var coords = eventGetOffsetCoords(e, info.touchId, _pGlob.vec2Tmp);
- info.prevX = info.currX;
- info.prevY = info.currY;
- info.currX = coords.x;
- info.currY = coords.y;
- callback_move();
- info.isMoved = true;
- }
- var upCb = function(e) {
- if (!eventTouchIdChangedFilter(e, info.touchId)) {
- // don't handle events not intended for this particular touch
- return;
- }
-
- var coords = eventGetOffsetCoords(e, info.touchId, _pGlob.vec2Tmp);
- info.currX = coords.x;
- info.currY = coords.y;
- info.prevX = info.currX;
- info.prevY = info.currY;
- callback_drop();
- info.isDowned = false;
-
- elem.removeEventListener("mousemove", moveCb, false);
- elem.removeEventListener("touchmove", moveCb, false);
- elem.removeEventListener("mouseup", upCb, false);
- elem.removeEventListener("touchend", upCb, false);
- if (appInstance.controls) {
- appInstance.controls.enabled = true;
- }
- }
-
- elem.addEventListener("mousemove", moveCb, false);
- elem.addEventListener("touchmove", moveCb, false);
- elem.addEventListener("mouseup", upCb, false);
- elem.addEventListener("touchend", upCb, false);
- }
- for (var i = 0; i < objNames.length; i++) {
- var objName = objNames[i];
- if (!objName) continue;
- _pGlob.objDragOverCallbacks.push([objName, cb]);
- }
- }
-
-
-
- // ssao puzzle
- function ssao(radius, aoClamp, lumInfluence) {
- appInstance.enablePostprocessing([{
- type: 'ssao',
- radius: radius,
- aoClamp: aoClamp,
- lumInfluence: lumInfluence
- }]);
- }
-
-
-
- // 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]
- });
- }
-
-
-
- // callJSFunction puzzle
- function getJSFunction(funcName) {
- var jsFunc = appInstance.ExternalInterface[funcName];
- if (typeof jsFunc == "function")
- return jsFunc;
- else
- return function() {};
- }
-
-
-
- // setInterval puzzle
- function registerInterval(timeout, callback) {
- window.setInterval(callback, 1000 * timeout);
- }
-
-
-
- // getEventProperty puzzle
- function getEventProperty(prop, event) {
- if (typeof event != "undefined") {
- if (prop == "target.id")
- return event.target.id;
- else
- return event[prop];
- }
- }
-
-
-
- // utility functions envoked by the HTML puzzles
- function getElements(ids, isParent) {
- var elems = [];
- if (Array.isArray(ids) && ids[0] != "WINDOW" && ids[0] != "DOCUMENT" && ids[0] != "BODY") {
- for (var i = 0; i < ids.length; i++)
- elems.push(getElement(ids[i], isParent));
- } else {
- elems.push(getElement(ids, isParent));
- }
- return elems;
- }
-
- function getElement(id, isParent) {
- var elem;
- if (Array.isArray(id) && id[0] == "WINDOW") {
- if (isParent)
- elem = parent;
- else
- elem = window;
- } else if (Array.isArray(id) && id[0] == "DOCUMENT") {
- if (isParent)
- elem = parent.document;
- else
- elem = document;
- } else if (Array.isArray(id) && id[0] == "BODY") {
- if (isParent)
- elem = parent.document.body;
- else
- elem = document.body;
- } else {
- if (isParent)
- elem = parent.document.getElementById(id);
- else
- elem = document.getElementById(id);
- }
- return elem;
- }
-
-
-
- // eventHTMLElem puzzle
- function eventHTMLElem(eventType, ids, isParent, callback) {
- var elems = getElements(ids, isParent);
- for (var i = 0; i < elems.length; i++) {
- var elem = elems[i];
- if (!elem)
- continue;
- elem.addEventListener(eventType, callback, false);
- }
- }
-
-
-
- function matGetColors(matName) {
-
- var mat = v3d.SceneUtils.getMaterialByName(appInstance, matName);
- if (!mat) return [];
-
- if (mat.isMeshNodeMaterial)
- return Object.keys(mat.nodeRGBMap);
- else if (mat.isMeshStandardMaterial)
- return ['color', 'emissive'];
- else
- return []
- }
-
-
- // setMaterialColor puzzle
- function setMaterialColor(matName, colName, r, g, b) {
- var colors = matGetColors(matName);
-
- if (colors.indexOf(colName) < 0) return;
-
- var mats = v3d.SceneUtils.getMaterialsByName(appInstance, matName);
-
- for (var i = 0; i < mats.length; i++) {
- var mat = mats[i];
-
- if (mat.isMeshNodeMaterial) {
- var rgbIdx = mat.nodeRGBMap[colName];
- mat.nodeRGB[rgbIdx].x = r;
- mat.nodeRGB[rgbIdx].y = g;
- mat.nodeRGB[rgbIdx].z = b;
- } else {
- mat[colName].r = r;
- mat[colName].g = g;
- mat[colName].b = b;
- }
- mat.needsUpdate = true;
-
- if (mat === appInstance.worldMaterial)
- appInstance.updateEnvironment(mat);
- }
- }
-
-
- function setRGB(R, G, B) {
- setMaterialColor("transparent", "Principled BSDF Color", R, G, B);
- r_ = R;
- g_ = G;
- b_ = B;
- printStates();
- }
- appInstance.ExternalInterface["setRGB"] = setRGB;
-
-
-
- // 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(''));
- }
-
- /**
- * Describe this function...
- */
- function setHSV() {
- hue = Math.atan(Math.min(Math.max(distX / (distY + 1), Math.PI * -2), Math.PI * 2) + Math.PI * 2) / Math.PI * 180;
- hue = hue / (Math.PI * 4);
- sat = Math.sqrt(distX * distX + distY * distY) / maxDist;
- value = ((distZ - maxDist) / (2 * maxDist)) * -1;
- getJSFunction('HSVtoRGB')(hue, sat, value);
- }
-
-
- registerOnDrag(["GROUP", "qubit_grp"], function() {
- dragging = true;
- },
- function() {
- dragMove("qubit_controller", "XY", "5{hamS]l^diNZ_?={UNM", "x7;j`9Tr6$fIW]tXfLwm");
- inboundStepper = 0;
- distZ = getObjTransform("qubit", "position", "y") - getObjTransform("qubit_controller", "position", "y");
- 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 / 200, 0, distZ / 100);
- }
- distZ = getObjTransform("qubit", "position", "y") - getObjTransform("qubit_controller", "position", "y");
- distX = getObjTransform("qubit", "position", "x") - getObjTransform("qubit_controller", "position", "x");
- setHSV();
- },
- function() {
- dragging = false;
- }, "x7;j`9Tr6$fIW]tXfLwm");
-
- 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.3;
- stepY = 0.1;
- bitstate = 0;
- r_ = 0.5;
- g_ = 0.5;
- b_ = 0.5;
- ssao(1, 0.01, 0.3);
-
- distX / distY;
-
- registerOnClick("recordqubit", function() {
- if (getObjectMaterial("recordqubit") == "on") {
- assignMat("recordqubit", "black");
- recordqubitstate = 0;
- } else {
- assignMat("recordqubit", "on");
- recordqubitstate = 1;
- }
- }, function() {});
-
- 2 / 10;
-
- registerInterval(1, function() {
- if (recordbitstate == 1) {
- getJSFunction('addBit')(bitstate);
- }
- if (recordqubitstate == 1) {
- getJSFunction('addQubit')(r_, g_, b_);
- }
- });
-
- Math.atan(45) / Math.PI * 180;
-
- console.log(distX);
- console.log(distY);
-
- 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 (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) {
- 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");
- setHSV();
- });
-
- Math.abs(4);
-
- 8;
-
- registerOnClick("recordbit", function() {
- if (getObjectMaterial("recordbit") == "on") {
- assignMat("recordbit", "black");
- recordbitstate = 0;
- } else {
- assignMat("recordbit", "on");
- recordbitstate = 1;
- }
- }, function() {});
-
- Math.sqrt(4);
-
- hue = Math.acos(distX / Math.sqrt(distX * distX + distY * distY + distZ * distZ)) / Math.PI * 180;
-
- hue = (Math.atan(Math.abs(distX / distY)) / Math.PI * 180) / 45 - 1;
-
- } // end of PL.init function
-
- if (window.v3dApp) {
- // backwards compatibility for old player projects
- PL.legacyMode = true;
- PL.init(window.v3dApp);
- }
-
- })(); // end of closure
-
- /* ================================ end of code ============================= */
|