Skip to content

How to import json strings (not files) into the editor scene? #20546

@turtlechang

Description

@turtlechang

I hope that clicking on option will get the JSON string from the MySQL database and load it into the scene of the Three.js editor to display the 3D object.

Menubar.Room.js

// Import JSON Object to Editor, not File

	var option = new UIRow();
	option.setClass('option');
	option.setTextContent(strings.getKey('menubar/room/import/object'));
	option.onClick(function () {

		// AJAX 

		var xhr = new XMLHttpRequest();

		xhr.open('post', 'http://192.168.63.100/vdcim/threejsEditor/postThreejsObject.php', true);
		xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

		xhr.onreadystatechange = function () {
			if (xhr.readyState == 4 && xhr.status == 200) {
				console.log(xhr.responseText);

				// var response = JSON.parse(xhr.responseText);
				// console.log("response: " + response);
				var data;

				try {
					// data = JSON.stringify(response['objectjson']);
					// console.log("objectjson: \n" + data);

					//data = JSON.parse(xhr.responseText);
					data = xhr.responseText;

					// var objectloader = new THREE.ObjectLoader();
					// objectloader.parseObject(data);
					editor.loader.loadFile(data);

				} catch (error) {
					alert(error);
					return;
				}

				alert(xhr.responseText + "\n成功,已新增物件到資料庫");
			}
		}

		let objectid = 3;
		let objId = "objectId=" + objectid;
		xhr.send(objId);


	});
	options.add(option);

Error message.

螢幕擷取畫面 2020-10-22 153758

螢幕擷取畫面 2020-10-22 154006

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions