to API Object

beta.r3js.org
cybafelo 2019-10-27 10:58:42 +01:00
parent 1535237170
commit 7c9c8d19bb
7 changed files with 141 additions and 105 deletions

View File

@ -167,7 +167,8 @@ R3.Event.Emit = function(
console.error('failed to execute client callback error:', error2);
}
}
return;
}
if (clientCallback) {

View File

@ -924,12 +924,12 @@ R3.Component.prototype.toApiObject = function() {
/**
* Check if this property is an array of something
*/
if (this[property].isArray) {
if (this[property] instanceof Array) {
/**
* Quick sanity check that the apiObject also thinks this is an array
*/
if (!arrayObject[property].isArray) {
if (!apiObject[property] instanceof Array) {
throw new Error('The API Object ' + apiObject + ' does not seem to think ' + property + ' is an array');
}
@ -944,7 +944,7 @@ R3.Component.prototype.toApiObject = function() {
throw new Error('Please don\'t store Runtime Objects in Arrays');
}
if (item.isArray) {
if (item instanceof Array) {
result[index] = item.reduce(
function (subResult, subItem) {
subResult.push(this.getPropertyValue(subItem));

View File

@ -16,8 +16,6 @@ R3.API.Controls = function(
apiComponent.canvas = null;
}
this.canvas = apiComponent.canvas;
this.previousCanvas = this.canvas;
};
R3.API.Controls.prototype = Object.create(R3.API.Component.prototype);

View File

@ -36,6 +36,7 @@ R3.API.CustomCode = function(
"\t * Set some initialization code here\n" +
"\t */\n" +
"\tthis.totalTime = 0;\n" +
"\tproject.cameras[1].position.y = 10;\n" +
"\n" +
"\tthis.initialized = true;\n" +
"}\n" +
@ -44,7 +45,8 @@ R3.API.CustomCode = function(
"\n" +
"\tthis.totalTime += project.clock.delta;\n" +
"\t\n" +
"\tproject.cameras[1].position.x = 4 * Math.sin(this.totalTime);\n" +
"\tproject.cameras[1].position.x = 15 * Math.sin(this.totalTime * 0.1);\n" +
"\tproject.cameras[1].position.z = 15 * Math.cos(this.totalTime * 0.1);\n" +
"\tproject.cameras[1].lookAt.x = 0;\n" +
"\tproject.cameras[1].lookAt.y = 0;\n" +
"\tproject.cameras[1].lookAt.z = 0;\n" +

View File

@ -32,10 +32,17 @@ R3.API.Quaternion = function(
this.w = apiComponent.w;
if (R3.Utils.UndefinedOrNull(apiComponent.axis)) {
var name = 'Quaternion Axis';
if (this.parent && this.parent.name) {
name = this.parent.name + ' - Quaternion Axis';
}
apiComponent.axis = new R3.API.Vector3(
{
parent : this.parent,
name : this.parent.name + ' - Quaternion Axis',
name : name,
register : this.register
}
);

View File

@ -57,45 +57,57 @@ R3.D3.API.Composer = function(
if (R3.Utils.UndefinedOrNull(apiComponent.passes)) {
apiComponent.passes = this.renderer.scenes.reduce(
function(result, scene) {
var passes = [];
result.push(
new R3.D3.API.Pass.Render(
{
parent : this,
scene : scene,
name : this.name + ' - Render Pass',
camera : this.camera
}
)
);
if (this.renderer && this.renderer.scenes) {
/**
* Construct default render passes
*/
passes = this.renderer.scenes.reduce(
function(result, scene) {
return result;
}.bind(this),
[]
);
result.push(
new R3.D3.API.Pass.Render(
{
parent : this,
scene : scene,
name : this.name + ' - Render Pass',
camera : this.camera
}
)
);
apiComponent.passes.push(
new R3.D3.API.Pass.Bloom(
{
parent : this,
name : this.name + ' - Bloom Pass',
renderer : this.renderer
}
)
)
return result;
}.bind(this),
[]
);
}
apiComponent.passes.push(
new R3.D3.API.Pass.FXAA(
{
parent : this,
name : this.name + ' - FXAA Pass',
renderer : this.renderer
}
)
);
if (this.renderer) {
passes.push(
new R3.D3.API.Pass.Bloom(
{
parent: this,
name: this.name + ' - Bloom Pass',
renderer: this.renderer
}
)
);
}
if (this.renderer) {
passes.push(
new R3.D3.API.Pass.FXAA(
{
parent: this,
name: this.name + ' - FXAA Pass',
renderer: this.renderer
}
)
);
}
apiComponent.passes = passes;
}
this.passes = apiComponent.passes;

View File

@ -273,8 +273,13 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
var saved = [];
var failed = [];
if (typeof XMLHttpRequest === 'undefined') {
console.log('Implement server side save here');
return;
}
if (this.savedSubscription || this.savedErrorSubscription) {
console.warn('another save is in progress');
console.warn('Another save is in progress');
return;
}
@ -350,6 +355,7 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
);
var apiUrl = null;
var apiAuthorization = null;
var event = R3.Event.GET_API_URL;
@ -361,98 +367,108 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
event,
null,
function(urlData) {
apiUrl = urlData.apiUrl
apiUrl = urlData.apiUrl;
apiAuthorization = urlData.apiAuthorization;
}
);
var apiObjects = Object.keys(data.component.idToObject).reduce(
try {
function(result, componentId) {
var apiObjects = Object.keys(data.component.idToObject).reduce(
var component = R3.EntityManager.Instance.findComponentById(componentId);
function (result, componentId) {
var apiObject = component.toApiObject();
var component = R3.EntityManager.Instance.findComponentById(componentId);
result.push(apiObject);
var apiObject = component.toApiObject();
return result;
result.push(apiObject);
}.bind(this),
[]
);
return result;
}.bind(this),
[]
);
} catch (error) {
this.savedSubscription.remove();
this.savedErrorSubscription.remove();
this.savedSubscription = null;
this.savedErrorSubscription = null;
throw new Error('An error occurred during save:' + error.message);
if (typeof XMLHttpRequest === 'undefined') {
console.log('Implement server side save here');
return;
}
apiObjects.map(
function(apiObject) {
try {
var xhr = new XMLHttpRequest();
apiObjects.map(
xhr.open(
'POST',
apiUrl + '/component/create'
);
function(apiObject) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("x-api-authorization", apiAuthorization);
xhr.setRequestHeader('x-api-user-token', this.apiUserToken);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
xhr.open(
'POST',
apiUrl + '/component/create'
);
try {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("x-api-authorization", apiAuthorization);
xhr.setRequestHeader('x-api-user-token', this.apiUserToken);
xhr.onload = function() {
var response = JSON.parse(xhr.responseText);
} catch (error) {
if (response.result === 'success') {
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: this.responseText,
component : apiObject
}
);
R3.Event.Emit(
R3.Event.COMPONENT_SAVED,
{
message: response.message || 'Successfully saved the component',
component : apiObject
}
);
}
} else {
if (response.result === 'success') {
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: response.message || 'The server responded but failed to save the component',
component : apiObject
}
)
R3.Event.Emit(
R3.Event.COMPONENT_SAVED,
{
message: response.message || 'Successfully saved the component',
component : apiObject
}
);
}
} else {
};
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: response.message || 'The server responded but failed to save the component',
component : apiObject
}
)
var data = JSON.stringify(apiObject);
}
xhr.send(
{
component : data
}
);
}
);
};
} catch (error) {
var data = JSON.stringify(apiObject);
xhr.send(
{
component : data
}
);
}
);
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: this.responseText,
component : apiObject
}
);
}
};