Commit 5786fdab authored by Roque's avatar Roque

erp5_web_renderjs_ui: add babylonjs assets to renderjs

parent ecb6e36a
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Drone Simulator</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- This gadget provides a babylonjs canvas that runs a Drone simulator -->
<!-- all within a web worker -->
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<script src="babylonjs.gadget.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global self, window, rJS, jIO, RSVP, console, importScripts, bindHandler,
handlers, prepareCanvas, postMessage, runGame, updateGame, handleEvent*/
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
self.window = {
addEventListener: function (event, fn, opt) {
bindHandler('window', event, fn, opt);
},
setTimeout: self.setTimeout.bind(self),
PointerEvent: true
};
self.document = {
addEventListener: function (event, fn, opt) {
bindHandler('document', event, fn, opt);
},
// Uses to detect wheel event like at src/Inputs/scene.inputManager.ts:797
createElement: function () {
return {onwheel: true};
},
defaultView: self.window
};
importScripts('babylon.js', 'babylon.gui.js', 'rsvp.js');
function mainToWorker(evt) {
var i, offscreen_canvas;
switch (evt.data.type) {
case 'start':
console.log("[WEB WORKER] Ready to handle the folliwing events:",
handlers.keys());
for (i = 0; i < evt.data.logic_url_list.length; i += 1) {
importScripts(evt.data.logic_url_list[i]);
}
offscreen_canvas = prepareCanvas(evt.data);
RSVP = window.RSVP;
return new RSVP.Queue()
.push(function () {
postMessage({'type': 'started'});
return runGame(offscreen_canvas, evt.data.game_parameters);
})
.push(function (result) {
return postMessage({'type': 'finished', 'result': result});
}, function (error) {
console.log("ERROR:", error);
return postMessage({'type': 'error', 'error': error});
});
case 'update':
return new RSVP.Queue()
.push(function () {
return updateGame();
})
.push(function () {
return postMessage({'type': 'updated'});
});
case 'event':
handleEvent(evt.data);
break;
default:
throw new Error('Unsupported message ' + JSON.stringify(evt.data));
}
}
// Doesn't work without it
class HTMLElement {}
self.handlers = new Map();
self.canvas = null;
// getBoundingInfo()
var rect = {
top: 0,
left: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
height: 0,
width: 0
};
function bindHandler(targetName, eventName, fn, opt) {
var handlerId = targetName + eventName;
handlers.set(handlerId, fn);
postMessage({
type: 'event',
targetName: targetName,
eventName: eventName,
opt: opt
});
}
function noop() {}
function handleEvent(event) {
var handlerId = event.targetName + event.eventName;
event.eventClone.preventDefault = noop;
event.eventClone.target = self.canvas;
if (!handlers.has(handlerId)) {
throw new Error('Unknown handlerId: ' + handlerId);
}
handlers.get(handlerId)(event.eventClone);
}
function prepareCanvas(data) {
var canvas = data.canvas, style;
self.canvas = canvas;
canvas.clientWidth = data.width;
canvas.clientHeight = data.height;
canvas.width = data.width;
canvas.height = data.height;
rect.right = rect.width = data.width;
rect.bottom = rect.height = data.height;
canvas.setAttribute = function (name, value) {
postMessage({
type: 'canvasMethod',
method: 'setAttribute',
args: [name, value]
});
};
canvas.addEventListener = function (event, fn, opt) {
bindHandler('canvas', event, fn, opt);
};
canvas.getBoundingClientRect = function () {
return rect;
};
canvas.focus = function () {
postMessage({
type: 'canvasMethod',
method: 'focus',
args: []
});
};
// noinspection JSUnusedGlobalSymbols
style = {
set touchAction (value) {
postMessage({
type: 'canvasStyle',
name: 'touchAction',
value: value
});
}
};
Object.defineProperty(canvas, 'style', {get () { return style }});
return canvas;
}
(function (worker) {
worker.onmessage = mainToWorker;
worker.postMessage({
'type': 'loaded'
});
}(this));
\ No newline at end of file
url_list = [
"babylonjs.gadget.html",
"babylonjs.gadget.js",
"gadget_erp5_page_babylonjs_web_worker.js",
"babylon.js",
"babylon.gui.js"
]
return url_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_getBabylonjsPrecacheManifestList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment