[x3d-public] JavaScript JSON interface to X3DOM

John Carlson yottzumm at gmail.com
Sun Apr 1 23:29:39 PDT 2018

I’m here to discuss adding potential JavaScript JSON APIs to X3DOM, including the use of a X3D JSON validator (for draft07 JSON schema),  an X3D JSON -> XML DOM converter (see pull request),  an  X3D JSON prototype expander (see pull request), an XML DOM -> JSON serializer (to precondition the XML for expanding and preprocessing) and VRMLScript (“X3DOM JSONScript”) preprocessor (still in alpha to pre-alpha—consider yourself lucky if your script works) to HTML JavaScript to handle X3D XML Script tag.  I need help with namespaces and scripting the X3D event model mostly (help with leaving the existing VRMLScript as intact as possible—or replacing it with other, similar JavaScript).

I would like to see an SFRotation field type in X3DOM.


The code I have submitted before is a better display of what I intend for X3DOM.   2 of these files aren’t classes yet.  I have already created classes for a third (see pull request).

I also have yet to get JSON Inlines working all the way outside of X3DOM (not sure about inside), so that’s on a wish list.

If someone could help with debugging/testing, that would most helpful.


An example API from JavaScript might look like this:
https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/html/prototypes.html (currently assumes ExternProtoDeclare is turned into ProtoDeclare on the JSON server).

	function load_X3DOM(htmlselector, url, callback) {


		$.getJSON(url, function(json) {

			var xml = [];

			json = protoExpander.prototypeExpander(url, json, "");

			json = flattener(json);

			if ($('#scripting').is(':checked')) {

				loadScripts(json, htmlselector, url);


			loadX3DJS(document.implementation, json, url, xml, "", loadSchema, doValidate, function(element, xmlDoc) {

				callback(element, xmlDoc, json);




function loadSubscene_X3DOM(htmlselector, xmlselector, url, element, xmlDoc, json, callback) {

		$.getJSON(url, function(subjson) {

			subjson = protoExpander.prototypeExpander(url, subjson, "");

			subjson = flattener(subjson);

			if ($('#scripting').is(':checked')) {

				loadScripts(subjson, htmlselector, url);


			var sceneElement = ConvertToX3DOM(xmlDoc, subjson["X3D"][xmlselector], xmlselector, element.querySelector(xmlselector), url);  // returns Scene element


			// join json for scripts

			for (var c in subjson["X3D"]["Scene"]["-children"]) {



			if (typeof callback === 'function') {

				callback(subjson, htmlselector);



	$(document).ready(function() {

		var htmlselector = "#x3domjson";

		var xmlselector = "Scene";

		var flowers2 = '../data/flowers2.json';

		var bubbles = '../data/force.json';

		var force = '../data/bubs.json';

		if ($('#scripting').is(':checked')) {



		load_X3DOM(htmlselector, flowers2, function(element, xmlDoc, json) {

			loadSubscene_X3DOM(htmlselector, xmlselector, bubbles, element, xmlDoc, json, function(sub1json, htmlselector) {

				loadSubscene_X3DOM(htmlselector, xmlselector, force, element, xmlDoc, json, function(sub2json, htmlselector) {

					$(htmlselector+" Script").empty();

					try {

						x3dom.reload();  // This may be necessary

					} catch (e) {


						alert("Problem with x3dom.reload()", e);





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180402/5326e306/attachment-0001.html>

More information about the x3d-public mailing list