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

@ -168,6 +168,7 @@ R3.Event.Emit = function(
}
}
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,7 +57,13 @@ R3.D3.API.Composer = function(
if (R3.Utils.UndefinedOrNull(apiComponent.passes)) {
apiComponent.passes = this.renderer.scenes.reduce(
var passes = [];
if (this.renderer && this.renderer.scenes) {
/**
* Construct default render passes
*/
passes = this.renderer.scenes.reduce(
function(result, scene) {
result.push(
@ -75,27 +81,33 @@ R3.D3.API.Composer = function(
}.bind(this),
[]
);
}
apiComponent.passes.push(
if (this.renderer) {
passes.push(
new R3.D3.API.Pass.Bloom(
{
parent : this,
name : this.name + ' - Bloom Pass',
renderer : this.renderer
}
)
)
apiComponent.passes.push(
new R3.D3.API.Pass.FXAA(
{
parent : this,
name : this.name + ' - FXAA Pass',
renderer : this.renderer
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,13 +367,16 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
event,
null,
function(urlData) {
apiUrl = urlData.apiUrl
apiUrl = urlData.apiUrl;
apiAuthorization = urlData.apiAuthorization;
}
);
try {
var apiObjects = Object.keys(data.component.idToObject).reduce(
function(result, componentId) {
function (result, componentId) {
var component = R3.EntityManager.Instance.findComponentById(componentId);
@ -381,12 +390,22 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
[]
);
if (typeof XMLHttpRequest === 'undefined') {
console.log('Implement server side save here');
return;
} catch (error) {
this.savedSubscription.remove();
this.savedErrorSubscription.remove();
this.savedSubscription = null;
this.savedErrorSubscription = null;
throw new Error('An error occurred during save:' + error.message);
}
try {
apiObjects.map(
function(apiObject) {
var xhr = new XMLHttpRequest();
@ -403,22 +422,8 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
xhr.onload = function() {
try {
var response = JSON.parse(xhr.responseText);
} catch (error) {
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: this.responseText,
component : apiObject
}
);
}
if (response.result === 'success') {
R3.Event.Emit(
@ -453,6 +458,17 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
}
);
} catch (error) {
R3.Event.Emit(
R3.Event.SAVE_COMPONENT_ERROR,
{
message: this.responseText,
component : apiObject
}
);
}
};