r3-v2/dist/r3.js

3014 lines
71 KiB
JavaScript
Raw Normal View History

2021-07-04 20:32:41 +02:00
const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
/**
CUSTOM_OPTIONS_START
started=false
CUSTOM_OPTIONS_END
CUSTOM_METHODS_START
start(options) - Just calls System.Start(options)
stop(options) - Just calls System.Stop(options)
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
Start(options) - Starts the system by registering subscriptions to events
Stop(options) - Stops the system by removing these subscriptions to events
CUSTOM_STATIC_METHODS_END
**/
class System {
//GENERATE_CONSTRUCTOR_START
constructor(options) {
Event.Emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
if (typeof options === 'undefined') {
options = {};
}
if (Utils.UndefinedOrNull(options.started)) {
options.started = false;
}
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
Event.Emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
//GENERATE_METHODS_START
/**
* start()
* - Just calls System.Start(options)
* @param options
*/
start(options) {
//GENERATE_START_METHOD_START
//GENERATE_START_METHOD_END
//CUSTOM_START_METHOD_START
System.Start(options);
/**
* Now do something else
*/
console.log('something else');
//CUSTOM_START_METHOD_END
}
/**
* stop()
* - Just calls System.Stop(options)
* @param options
*/
stop(options) {
//GENERATE_STOP_METHOD_START
//GENERATE_STOP_METHOD_END
//CUSTOM_STOP_METHOD_START
System.Stop(options);
//CUSTOM_STOP_METHOD_END
}
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
/**
* Start()
* - Starts the system by registering subscriptions to events
* @param options
*/
static Start(options) {
//GENERATE_STATIC_START_METHOD_START
//GENERATE_STATIC_START_METHOD_END
//CUSTOM_STATIC_START_METHOD_START
console.log('Starting system X');
//CUSTOM_STATIC_START_METHOD_END
}
/**
* Stop()
* - Stops the system by removing these subscriptions to events
* @param options
*/
static Stop(options) {
//GENERATE_STATIC_STOP_METHOD_START
//GENERATE_STATIC_STOP_METHOD_END
//CUSTOM_STATIC_STOP_METHOD_START
console.log('Stopping system X');
//CUSTOM_STATIC_STOP_METHOD_END
}
//GENERATE_STATIC_METHODS_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = System;const Utils = require('./r3-utils');
/**
GENERATE_INHERITED_START
GENERATE_INHERITED_END
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
CUSTOM_METHODS_START
async(eventId, data, clientCallback, clientErrorCallback) - Simply calls 'Async()' passing it the arguments
emit(eventId, data, clientCallback, clientErrorCallback) - Simply calls 'Emit()' passing it the arguments
subscribe(eventId, callback) - Simply calls 'Subscribe()' passing it the arguments
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
Async(eventId, data, clientCallback, clientErrorCallback) - Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the error as argument.
Emit(eventId, data, clientCallback, clientErrorCallback) - Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after the event result is obtained, passing it the result. If an exception occurs during execution, the clientErrorCallback is called with the error as argument.
Subscribe(eventId, callback) - Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised @return {Object} - A handle to the subscription which can be removed by calling handle.remove()
CUSTOM_STATIC_METHODS_END
**/
class Event {
//GENERATE_CONSTRUCTOR_START
constructor(options) {
Event.Emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
Event.Emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_END
//CUSTOM_IMPLEMENTATION_START
/**
* Some nice Events handling
* @type {{}}
*/
static Subscriptions = {};
//CUSTOM_IMPLEMENTATION_END
//GENERATE_METHODS_START
/**
* async()
* - Simply calls 'Async()' passing it the arguments
* @param eventId
* @param data
* @param clientCallback
* @param clientErrorCallback
*/
async(
eventId,
data,
clientCallback,
clientErrorCallback
) {
//GENERATE_ASYNC_METHOD_START
//GENERATE_ASYNC_METHOD_END
//CUSTOM_ASYNC_METHOD_START
return Event.Async(
eventId,
data,
clientCallback,
clientErrorCallback
);
//CUSTOM_ASYNC_METHOD_END
}
/**
* emit()
* - Simply calls 'Emit()' passing it the arguments
* @param eventId
* @param data
* @param clientCallback
* @param clientErrorCallback
*/
emit(
eventId,
data,
clientCallback,
clientErrorCallback
) {
//GENERATE_EMIT_METHOD_START
//GENERATE_EMIT_METHOD_END
//CUSTOM_EMIT_METHOD_START
return Event.Emit(
eventId,
data,
clientCallback,
clientErrorCallback
);
//CUSTOM_EMIT_METHOD_END
}
/**
* subscribe()
* - Simply calls 'Subscribe()' passing it the arguments
* @param eventId
* @param callback
*/
subscribe(
eventId,
callback
) {
//GENERATE_SUBSCRIBE_METHOD_START
//GENERATE_SUBSCRIBE_METHOD_END
//CUSTOM_SUBSCRIBE_METHOD_START
return Event.Subscribe(eventId, callback.bind(this));
//CUSTOM_SUBSCRIBE_METHOD_END
}
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
/**
* Async()
* - Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as
* arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the
* error as argument.
* @param eventId
* @param data
* @param clientCallback
* @param clientErrorCallback
*/
static Async(
eventId,
data,
clientCallback,
clientErrorCallback
) {
//GENERATE_STATIC_ASYNC_METHOD_START
//GENERATE_STATIC_ASYNC_METHOD_END
//CUSTOM_STATIC_ASYNC_METHOD_START
if (Event.Subscriptions.hasOwnProperty(eventId)) {
let subscriptionIds = Object.keys(Event.Subscriptions[eventId]);
subscriptionIds.map(
function(subscriptionId) {
try {
Event.Subscriptions[eventId][subscriptionId](data, clientCallback, clientErrorCallback);
} catch (error) {
if (clientErrorCallback) {
clientErrorCallback(error);
} else {
console.error(error);
throw error;
}
}
}
)
}
//CUSTOM_STATIC_ASYNC_METHOD_END
}
/**
* Emit()
* - Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after
* the event result is obtained, passing it the result. If an exception occurs during execution, the
* clientErrorCallback is called with the error as argument.
* @param eventId
* @param data
* @param clientCallback
* @param clientErrorCallback
*/
static Emit(
eventId,
data,
clientCallback,
clientErrorCallback
) {
//GENERATE_STATIC_EMIT_METHOD_START
//GENERATE_STATIC_EMIT_METHOD_END
//CUSTOM_STATIC_EMIT_METHOD_START
if (Event.Subscriptions.hasOwnProperty(eventId)) {
let subscriptionIds = Object.keys(Event.Subscriptions[eventId]);
subscriptionIds.map(
function(subscriptionId) {
try {
let result = Event.Subscriptions[eventId][subscriptionId](data);
if (clientCallback) {
clientCallback(result);
}
} catch (error) {
if (clientErrorCallback) {
clientErrorCallback(error);
} else {
console.error(error);
throw error;
}
}
}
)
}
//CUSTOM_STATIC_EMIT_METHOD_END
}
/**
* Subscribe()
* - Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised
* @param eventId
* @param callback \n * @returns {Object} - A handle to the subscription which can be removed by calling handle.remove()
*/
static Subscribe(
eventId,
callback
) {
//GENERATE_STATIC_SUBSCRIBE_METHOD_START
//GENERATE_STATIC_SUBSCRIBE_METHOD_END
//CUSTOM_STATIC_SUBSCRIBE_METHOD_START
let subscriptionId = Utils.RandomId(10);
if (Event.Subscriptions.hasOwnProperty(eventId)) {
if (Event.Subscriptions[eventId][subscriptionId]) {
throw new Error('A component can only subscribe to a particular event ID once');
}
Event.Subscriptions[eventId][subscriptionId] = callback;
} else {
Event.Subscriptions[eventId] = {};
Event.Subscriptions[eventId][subscriptionId] = callback;
}
/**
* Return a handle to the caller to allow us to unsubscribe to this event
*/
return {
fn: callback,
remove: function (eventId, subscriptionId) {
return function () {
/**
* Stop listening for this event from this component
*/
delete Event.Subscriptions[eventId][subscriptionId];
/**
* If the length of listeners is 0, stop referencing this event
* @type {string[]}
*/
let listeners = Object.keys(Event.Subscriptions[eventId]);
if (listeners.length === 0) {
delete Event.Subscriptions[eventId];
}
}
}(eventId, subscriptionId),
subscriptionId : subscriptionId
};
//CUSTOM_STATIC_SUBSCRIBE_METHOD_END
}
//GENERATE_STATIC_METHODS_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//EVENT_GENERATED_START
Event.COMPONENT_INITIALIZED = 0x1;
Event.CREATE_INSTANCE_BEFORE = 0x2;
Event.DISPOSE_INSTANCE = 0x3;
Event.DISPOSE_OBJECT = 0x4;
Event.GET_RUNTIME = 0x5;
Event.GET_WINDOW_SIZE = 0x6;
Event.INSTANCE_CREATED = 0x7;
Event.INSTANCE_DISPOSED = 0x8;
Event.OBJECT_CREATED = 0x9;
Event.OBJECT_INITIALIZED = 0xa;
Event.PAUSE = 0xb;
Event.RESTART = 0xc;
Event.START = 0xd;
Event.UPDATE_FROM_INSTANCE_AFTER = 0xe;
Event.UPDATE_FROM_INSTANCE_BEFORE = 0xf;
Event.UPDATE_INSTANCE_AFTER = 0x10;
Event.UPDATE_INSTANCE_BEFORE = 0x11;
Event.MAX_EVENTS = 0x12;
Event.GetEventName = function(eventId) {
switch(eventId) {
case 0x1 : return 'component_initialized';
case 0x2 : return 'create_instance_before';
case 0x3 : return 'dispose_instance';
case 0x4 : return 'dispose_object';
case 0x5 : return 'get_runtime';
case 0x6 : return 'get_window_size';
case 0x7 : return 'instance_created';
case 0x8 : return 'instance_disposed';
case 0x9 : return 'object_created';
case 0xa : return 'object_initialized';
case 0xb : return 'pause';
case 0xc : return 'restart';
case 0xd : return 'start';
case 0xe : return 'update_from_instance_after';
case 0xf : return 'update_from_instance_before';
case 0x10 : return 'update_instance_after';
case 0x11 : return 'update_instance_before';
default :
throw new Error('Event type not defined : ' + eventId);
}
};
//EVENT_GENERATED_END
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = Event;const Event = require('./r3-event');
/**
GENERATE_INHERITED_START
GENERATE_INHERITED_END
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
CUSTOM_METHODS_START
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
CUSTOM_STATIC_METHODS_END
**/
class Utils {
//GENERATE_CONSTRUCTOR_START
constructor(options) {
Event.Emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
Event.Emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_END
//CUSTOM_IMPLEMENTATION_START
static GetFirstParent(object, constructor) {
if (Utils.UndefinedOrNull(constructor)) {
throw new Error('You need to specify a constructor');
}
if (object.parent === null) {
return null;
}
if (object.parent instanceof constructor) {
return object.parent;
} else {
return Utils.GetFirstParent(object.parent, constructor);
}
};
static SyntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\u[a-zA-Z0-9]{4}|\[^u]|[^\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
let cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
};
static GetParentProject(component) {
if (Utils.UndefinedOrNull(component.parent)) {
throw new Error('Parent not found');
}
if (component.parent instanceof R3.Project) {
return component.parent;
}
return Utils.GetParentProject(component.parent);
};
static GetParents(component, parents) {
if (Utils.UndefinedOrNull(parents)) {
parents = [];
}
if (Utils.UndefinedOrNull(component.parent)) {
return parents;
}
parents.push(component.parent);
return Utils.GetParents(component.parent, parents);
};
/**
* @return {boolean}
*/
static Instance(component) {
return Utils.Defined(component) && Utils.Defined(component.instance);
};
/**
* Utils.RemoveFromSelect
* @param select
* @param id
* @returns {boolean}
* @constructor
*/
static RemoveFromSelect(select, id) {
let i;
for (i = 0; i < select.options.length; i++) {
if (select.options[i].value === id) {
select.remove(i);
return true;
}
}
return false;
};
/**
* Utils.GetSelectIndex
*
* Get the select index of given id
*
* @param select
* @param id
* @returns boolean true if successful
*
* @constructor
*/
static SetSelectIndex(select, id) {
for (let i = 0; i < select.options.length; i++) {
if (select.options[i].value === id) {
select.selectedIndex = i;
return true;
}
}
return false;
};
static SortSelect(select) {
let tmp = [];
let i;
for (i = 1; i < select.options.length; i++) {
tmp[i-1] = [];
tmp[i-1][0] = select.options[i].text;
tmp[i-1][1] = select.options[i].value;
}
tmp.sort();
select.options = [select.options[0]];
for (i = 0; i < tmp.length; i++) {
select.options[i+1] = new Option(tmp[i][0], tmp[i][1]);
}
return;
};
/**
* Gets the parent of object whith property of optional type constructor. If index is specified, get the parent of the
* object with property[index] - which means the property should be an array
* @param object
* @param property
* @param index
* @param constructor
* @returns {*}
* @constructor
*/
static GetParent(object, property, index, constructor) {
if (Utils.UndefinedOrNull(constructor)) {
constructor = null;
}
if (Utils.UndefinedOrNull(index)) {
index = null;
}
if (object.parent) {
/**
* Parent defined
*/
if (object.parent.hasOwnProperty(property)) {
if (constructor) {
if (index) {
if (object.parent[property][index] instanceof constructor) {
return object.parent[property][index];
} else {
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
if (object.parent[property] instanceof constructor) {
return object.parent[property];
} else {
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
}
} else {
if (index) {
return object.parent[property][index];
} else {
return object.parent[property];
}
}
} else {
/**
* This parent does not have the property - go a level higher
*/
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
/**
* No parent defined
*/
console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain');
return null;
}
};
/**
* Strips image extension from given path
* @param imagePath
* @constructor
*/
static StripImageExtension(imagePath) {
return imagePath.replace(/(\.png$|\.gif$|\.jpeg$|\.jpg$)/,'')
};
/**
* Returns true if unloaded
* @param component
* @returns {boolean}
* @constructor
*/
static Unloaded(component) {
if (
Utils.UndefinedOrNull(component) ||
Utils.UndefinedOrNull(component.instance)
) {
return true;
}
return false;
};
/**
*
* @param component
* @returns {boolean}
* @constructor
*/
static Loaded(component) {
if (component && component.instance) {
return true;
}
return false;
};
static BuildVectorSource(result, name, dimension) {
if (dimension === 2) {
result[name] = {};
result[name].x = false;
result[name].y = false;
return;
}
if (dimension === 3) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].y = false;
return;
}
if (dimension === 4) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
return;
}
console.warn('unknown dimension : ' + dimension);
};
/**
* Returns all 'instances' of the array, or null if an 'instance' is undefined
* @constructor
* @param array
*/
static GetArrayInstances(array) {
return array.reduce(
function(result, object) {
if (result === null) {
return result;
}
if (Utils.UndefinedOrNull(object.instance)) {
result = null;
} else {
result.push(object.instance);
}
return result;
},
[]
);
};
static SortFacesByMaterialIndex(faces) {
/**
* Sorts faces according to material index because later we will create
* groups for each vertice group
*/
faces.sort(function(a, b) {
if (a.materialIndex < b.materialIndex) {
return -1;
}
if (a.materialIndex > b.materialIndex) {
return 1;
}
return 0;
});
return faces;
};
static BuildQuaternionSource(result, name) {
result[name] = {};
result[name].axis = {};
result[name].axis.x = false;
result[name].axis.y = false;
result[name].axis.z = false;
result[name].angle = false;
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
};
static ObjectPropertiesAsBoolean(object) {
return Object.keys(object).reduce(
function(result, propertyId) {
if (typeof object[propertyId] === 'function') {
return result;
}
result[propertyId] = false;
// if (object[propertyId] instanceof R3.Vector2) {
// Utils.BuildVectorSource(result, propertyId, 2);
// }
//
// if (object[propertyId] instanceof R3.Vector3) {
// Utils.BuildVectorSource(result, propertyId, 3);
// }
//
// if (object[propertyId] instanceof R3.Vector4) {
// Utils.BuildVectorSource(result, propertyId, 4);
// }
//
// if (object[propertyId] instanceof R3.Quaternion) {
// Utils.BuildQuaternionSource(result, propertyId);
// }
return result;
}.bind(this),
{}
);
};
static GetRuntime() {
let result = null;
R3.Event.Emit(
R3.Event.GET_RUNTIME,
null,
function(runtime) {
result = runtime;
}
);
return result;
};
/**
* Returns the window size or null
* @returns {*}
* @constructor
*/
static GetWindowSize() {
let size = null;
R3.Event.Emit(
R3.Event.GET_WINDOW_SIZE,
null,
function(data) {
size = data;
}.bind(this)
);
return size;
};
/**
* Convenience function to update object width and height members with window size
* @param object
* @constructor
*/
static UpdateWindowSize(object) {
let size = Utils.GetWindowSize();
object.width = size.width;
object.height = size.height;
};
/**
* Returns id of object with the name if it exists in the array, otherwise null
* @param name
* @param array
* @returns {*}
* @constructor
*/
static ObjectIdWithNameInArray(name, array) {
return array.reduce(
function(result, object) {
if (result) {
return result;
}
if (name === object.name) {
return object.id;
}
return null;
},
null
);
};
static LoadIdsFromArrayToIdObject(array, idToObject) {
};
static LoadIdsFromObjectToIdObject(object, idToObject) {
};
/**
* Gets random int exclusive of maximum but inclusive of minimum
* @param min
* @param max
* @returns {*}
* @constructor
*/
static GetRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
};
/**
* Gets random int inclusive of minimum and maximum
* @param min
* @param max
* @returns {*}
* @constructor
*/
static GetRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
};
static InterpolateArray(data, fitCount) {
let linearInterpolate = function(before, after, atPoint) {
return before + (after - before) * atPoint;
};
let newData = [];
let springFactor = Number((data.length - 1) / (fitCount - 1));
newData[0] = data[0]; // for new allocation
for ( let i = 1; i < fitCount - 1; i++) {
let tmp = i * springFactor;
let before = Number(Math.floor(tmp)).toFixed();
let after = Number(Math.ceil(tmp)).toFixed();
let atPoint = tmp - before;
newData[i] = linearInterpolate(data[before], data[after], atPoint);
}
newData[fitCount - 1] = data[data.length - 1]; // for new allocation
return newData;
};
/**
* Undefined or null check
* @param variable
* @returns {boolean}
* @constructor
*/
static UndefinedOrNull(
variable
) {
return typeof variable === 'undefined' || variable === null;
};
/**
* The variable is not undefined and not null
* @param variable
* @returns {boolean}
* @constructor
*/
static Defined(
variable
) {
return typeof variable !== 'undefined' && variable !== null;
};
/**
* Gets function parameters
* @param fn
* @constructor
*/
static GetParameters(fn) {
let FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
let FN_ARG_SPLIT = /,/;
let FN_ARG = /^\s*(_?)(.+?)\s*$/;
let STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\'|[^'\r\n])*')|("(?:\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg;
let parameters,
fnText,
argDecl;
if (typeof fn !== 'function') {
parameters = [];
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
argDecl[1].split(FN_ARG_SPLIT).forEach(function(arg) {
arg.replace(FN_ARG, function(all, underscore, name) {
parameters.push(name);
});
});
} else {
throw Error("not a function")
}
return parameters;
};
/**
* Returns either an ID of the object or Null
* @param object
* @returns {null}
* @constructor
*/
static IdOrNull(object) {
if (Utils.UndefinedOrNull(object)) {
return null;
} else {
if (Utils.UndefinedOrNull(object.id)) {
console.warn('saving an object reference with no ID : ', object);
return null;
}
return object.id;
}
};
/**
* Limit a property to values between -pi and +pi
* @param property
* @param objectProperty
* @returns {{configurable?: boolean, enumerable?: boolean, value?, writable?: boolean, get?: Function, set?: Function}}
* @constructor
*/
static LimitToPI(property, objectProperty) {
let store = objectProperty;
return {
get : function() {
return store;
},
set : function(value) {
while (value > Math.PI) {
value -= (Math.PI * 2);
}
while (value < -(Math.PI)) {
value += (Math.PI * 2);
}
store = value;
}
};
};
/**
* Returns an array of IDs representing the objects
* @param array
* @returns []
* @constructor
*/
static IdArrayOrEmptyArray(array) {
if (Utils.UndefinedOrNull(array)) {
return [];
} else {
return array.map(function(item) {
if (Utils.UndefinedOrNull(item.id)) {
throw new Error('No ID found while trying to store IDs to array');
}
return item.id
});
}
};
/**
* Links an object to its parent through idToObject array
* @param propertyString
* @param idToObject
* @param parentObject
* @param id
* @constructor
*/
static Link(propertyString, idToObject, parentObject, id) {
if (!Utils.UndefinedOrNull(parentObject[propertyString])) {
if (!idToObject.hasOwnProperty(id)) {
console.warn('Linking failed for object:' + parentObject.name);
}
parentObject[propertyString] = idToObject[id];
}
};
/**
* Generates a random ID
* @returns {string}
* @constructor
*/
static RandomId(length) {
if (Utils.UndefinedOrNull(length)) {
length = 10;
}
return Math.random().toString(36).substr(2, length);
};
static InvertWindingOrder(triangles) {
for (let i = 0; i < triangles.length; i++) {
let v1 = triangles[i].v1;
triangles[i].v1 = triangles[i].v2;
triangles[i].v2 = v1;
let backupUV = triangles[i].triangle.v1uv;
triangles[i].triangle.v1uv = triangles[i].triangle.v2uv;
triangles[i].triangle.v2uv = backupUV;
}
return triangles;
};
/**
* Inverts a mesh winding order (and its instance)
* @param mesh R3.D3.Mesh
* @returns {*}
* @constructor
*/
static InvertMeshWindingOrder(mesh) {
mesh.faces.forEach(
function(face) {
let tmpV1 = face.v1;
face.v1 = face.v2;
face.v2 = tmpV1;
let tmpV1uv = face.v1uv;
face.v1uv = face.v2uv;
face.v2uv = tmpV1uv;
}.bind(this)
);
//mesh.computeNormals = true;
//mesh.createInstance();
};
/**
* This function resets a the winding order of a mesh from a reference point V (the average center of the mesh)
*/
static ResetWindingOrder(faces, vertices) {
let vertexList = new R3.API.Vector3.Points();
for (let v = 0; v < vertices.length; v++) {
vertexList.add(new R3.API.Vector3(
vertices[v].position.x,
vertices[v].position.y,
vertices[v].position.z
));
}
let V = vertexList.average();
let triangles = [];
for (let s = 0; s < faces.length; s += 3) {
let v0 = faces[s];
let v1 = faces[s+1];
let v2 = faces[s+2];
triangles.push(
{
v0 : v0,
v1 : v1,
v2 : v2,
edges : [
{v0: v0, v1: v1},
{v0: v1, v1: v2},
{v0: v2, v1: v0}
],
winding : 0,
edgeIndex : -1,
processed : false
}
);
}
for (let i = 0; i < triangles.length; i++) {
if (
R3.API.Vector3.clockwise(
vertices[triangles[i].v0].position,
vertices[triangles[i].v1].position,
vertices[triangles[i].v2].position,
V
)
) {
console.log('clockwise');
let bv1 = triangles[i].v1;
triangles[i].v1 = triangles[i].v2;
triangles[i].v2 = bv1;
} else {
console.log('not clockwise');
}
}
return triangles;
};
/**
* This function resets the winding order for triangles in faces, given an initial triangle and orientation edge
* used pseudocode from
* http://stackoverflow.com/questions/17036970/how-to-correct-winding-of-triangles-to-counter-clockwise-direction-of-a-3d-mesh
* We need to use a graph traversal algorithm,
* lets assume we have method that returns neighbor of triangle on given edge
*
* neighbor_on_egde( next_tria, edge )
*
* to_process = set of pairs triangle and orientation edge, initial state is one good oriented triangle with any edge on it
* processed = set of processed triangles; initial empty
*
* while to_process is not empty:
* next_tria, orientation_edge = to_process.pop()
* add next_tria in processed
* if next_tria is not opposite oriented than orientation_edge:
* change next_tria (ABC) orientation (B<->C)
* for each edge (AB) in next_tria:
* neighbor_tria = neighbor_on_egde( next_tria, edge )
* if neighbor_tria exists and neighbor_tria not in processed:
* to_process add (neighbor_tria, edge opposite oriented (BA))
* @param faces R3.D3.Face[]
* @param orientationEdge R3.API.Vector2
* @returns {Array}
*/
static FixWindingOrder(faces, orientationEdge) {
/**
* Checks if a Face belonging to a TriangleEdge has already been processed
* @param processed TriangleEdge[]
* @param triangle Face
* @returns {boolean}
*/
function inProcessed(processed, triangle) {
for (let i = 0; i < processed.length; i++) {
if (processed[i].triangle.equals(triangle)) {
return true;
}
}
return false;
}
/**
* Returns a neighbouring triangle on a specific edge - preserving the edge orientation
* @param edge R3.API.Vector2
* @param faces R3.D3.Face[]
* @param currentTriangle
* @returns {*}
*/
function neighbourOnEdge(edge, faces, currentTriangle) {
for (let i = 0; i < faces.length; i++) {
if (
(faces[i].v0 === edge.x && faces[i].v1 === edge.y) ||
(faces[i].v1 === edge.x && faces[i].v2 === edge.y) ||
(faces[i].v2 === edge.x && faces[i].v0 === edge.y) ||
(faces[i].v0 === edge.y && faces[i].v1 === edge.x) ||
(faces[i].v1 === edge.y && faces[i].v2 === edge.x) ||
(faces[i].v2 === edge.y && faces[i].v0 === edge.x)
) {
let triangle = new R3.D3.API.Face(
null,
null,
faces[i].v0index,
faces[i].v1index,
faces[i].v2index,
faces[i].materialIndex,
faces[i].uvs
);
if (triangle.equals(currentTriangle)) {
continue;
}
return new R3.D3.TriangleEdge(
triangle,
edge
);
}
}
return null;
}
let toProcess = [
new R3.D3.TriangleEdge(
new R3.D3.API.Face(
null,
null,
faces[0].v0index,
faces[0].v1index,
faces[0].v2index,
faces[0].materialIndex,
faces[0].uvs
),
orientationEdge
)
];
let processed = [];
while (toProcess.length > 0) {
let triangleEdge = toProcess.pop();
/**
* If edge is the same orientation (i.e. the edge order is the same as the given triangle edge) it needs to be reversed
* to have the same winding order)
*/
if (
(triangleEdge.triangle.v0index === triangleEdge.edge.x &&
triangleEdge.triangle.v1index === triangleEdge.edge.y) ||
(triangleEdge.triangle.v1index === triangleEdge.edge.x &&
triangleEdge.triangle.v2index === triangleEdge.edge.y) ||
(triangleEdge.triangle.v2index === triangleEdge.edge.x &&
triangleEdge.triangle.v0index === triangleEdge.edge.y)
) {
let backupV = triangleEdge.triangle.v1index;
triangleEdge.triangle.v1index = triangleEdge.triangle.v2index;
triangleEdge.triangle.v2index = backupV;
// let backupUV = triangleEdge.triangle.v1uv;
// triangleEdge.triangle.v1uv = triangleEdge.triangle.v2uv;
// triangleEdge.triangle.v2uv = backupUV;
//
let backupUV = triangleEdge.triangle.uvs[0][1];
triangleEdge.triangle.uvs[0][1] = triangleEdge.triangle.uvs[0][2];
triangleEdge.triangle.uvs[0][2] = backupUV;
}
processed.push(triangleEdge);
let edges = [
new R3.API.Vector2(
triangleEdge.triangle.v0index,
triangleEdge.triangle.v1index
),
new R3.API.Vector2(
triangleEdge.triangle.v1index,
triangleEdge.triangle.v2index
),
new R3.API.Vector2(
triangleEdge.triangle.v2index,
triangleEdge.triangle.v0index
)
];
for (let j = 0; j < edges.length; j++) {
let neighbour = neighbourOnEdge(edges[j], faces, triangleEdge.triangle);
if (neighbour && !inProcessed(processed, neighbour.triangle)) {
toProcess.push(neighbour);
}
}
}
/**
* In processed - we will have some duplicates - only add the unique ones
* @type {Array}
*/
let triangles = [];
for (let i = 0; i < processed.length; i++) {
let found = false;
for (let k = 0; k < triangles.length; k++) {
if (triangles[k].equals(processed[i].triangle)){
found = true;
break;
}
}
if (!found) {
triangles.push(processed[i].triangle);
}
}
return triangles;
};
/**
* This is a work-around function to fix polys which don't triangulate because
* they could lie on Z-plane (XZ or YZ)) - we translate the poly to the origin, systematically rotate the poly around
* Z then Y axis
* @param verticesFlat []
* @param grain is the amount to systematically rotate the poly by - a finer grain means a more accurate maximum XY
* @return []
*/
static FixPolyZPlane(verticesFlat, grain) {
if ((verticesFlat.length % 3) !== 0 && !(verticesFlat.length > 9)) {
console.log("The vertices are not in the right length : " + verticesFlat.length);
}
let vertices = [];
let points = new R3.API.Quaternion.Points();
for (let i = 0; i < verticesFlat.length; i += 3) {
points.add(new R3.API.Vector3(
verticesFlat[i],
verticesFlat[i + 1],
verticesFlat[i + 2]
));
}
points.toOrigin();
points.maximizeXDistance(grain);
points.maximizeYDistance(grain);
for (i = 0; i < points.vectors.length; i++) {
vertices.push(
[
points.vectors[i].x,
points.vectors[i].y
]
);
}
return vertices;
};
static MovingAverage(period) {
let nums = [];
return function(num) {
nums.push(num);
if (nums.length > period)
nums.splice(0,1); // remove the first element of the array
let sum = 0;
for (let i in nums)
sum += nums[i];
let n = period;
if (nums.length < period)
n = nums.length;
return(sum/n);
}
};
static Intersect(a, b) {
let t;
/**
* Loop over shortest array
*/
if (b.length > a.length) {
t = b;
b = a;
a = t;
}
return a.filter(
/**
* Check if exists
* @param e
* @returns {boolean}
*/
function(e) {
return (b.indexOf(e) > -1);
}
).filter(
/**
* Remove Duplicates
* @param e
* @param i
* @param c
* @returns {boolean}
*/
function(e, i, c) {
return c.indexOf(e) === i;
}
);
};
static Difference(a, b) {
let t;
/**
* Loop over shortest array
*/
if (b.length > a.length) {
t = b;
b = a;
a = t;
}
return a.filter(
/**
* Check if exists
* @param e
* @returns {boolean}
*/
function(e) {
return (b.indexOf(e) === -1);
}
).filter(
/**
* Remove Duplicates
* @param e
* @param i
* @param c
* @returns {boolean}
*/
function(e, i, c) {
return c.indexOf(e) === i;
}
);
};
/**
* Push only if not in there already
* @param array
* @param object
* @constructor
*/
static PushUnique(array, object) {
if (array.indexOf(object) === -1) {
array.push(object);
}
};
/**
* Checks whether or not the object is empty
* @param obj
* @returns {boolean}
* @constructor
*/
static IsEmpty(obj) {
return (Object.keys(obj).length === 0 && obj.constructor === Object);
};
static IsString(member) {
return (typeof member === 'string');
};
static IsBoolean(member) {
return (member === true || member === false);
};
static IsColor(member) {
return (member instanceof R3.Color);
};
static IsNumber(member) {
return (typeof member === 'number');
};
static IsVector2(member) {
return (
member instanceof R3.API.Vector2 ||
member instanceof R3.Vector2
);
};
static IsVector3(member) {
return (
member instanceof R3.API.Vector3 ||
member instanceof R3.Vector3
);
};
static IsVector4(member) {
return (
member instanceof R3.API.Vector4 ||
member instanceof R3.Vector4 ||
member instanceof R3.API.Quaternion ||
member instanceof R3.Quaternion
);
};
static IsObject(member) {
let type = typeof member;
return type === 'function' || type === 'object' && !!member;
};
/**
* @return {string}
*/
static LowerUnderscore(name) {
let string = name.toLowerCase().replace(/\s+/g, '_');
string = string.replace(/-/g, '_');
string = string.replace(/\_+/g, '_');
return string;
};
static UpperCaseWordsSpaces(input) {
let word = input.replace(/[-_]/g, ' ');
word = word.replace(/\s+/, ' ');
let words = word.split(' ');
return words.reduce(
function(result, word) {
result += word[0].toUpperCase() + word.substr(1);
return result + ' ';
},
''
).trim();
};
/**
* @return {string}
*/
static UpperCaseUnderscore(word) {
let str = '';
word.split('').map(
function(letter){
if (letter === letter.toUpperCase()) {
str += '_' + letter;
} else {
str += letter.toUpperCase();
}
});
str = str.replace(new RegExp('^_'),'');
return str;
};
/**
* Returns Left Padded Text - ex. length 5, padchar 0, string abc = '00abc'
* @param length
* @param padChar
* @param string
* @returns {string}
* @constructor
*/
static PaddedText(length, padChar, string) {
let pad = "";
for (let x = 0; x < length; x++) {
pad += padChar;
}
return pad.substring(0, pad.length - string.length) + string;
};
//CUSTOM_IMPLEMENTATION_END
//GENERATE_METHODS_START
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
//GENERATE_STATIC_METHODS_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = Utils;const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
const System = require('./r3-system.js');
/**
GENERATE_INHERITED_START
[Inherited from System]
Properties:
- started (Default value false)
Methods:
- start(options)
Just calls System.Start(options)
- stop(options)
Just calls System.Stop(options)
Static Methods:
- Start(options)
Starts the system by registering subscriptions to events
- Stop(options)
Stops the system by removing these subscriptions to events
[Belonging to SystemLinking]
Properties:
<no static properties>
Methods:
<no methods>
Static Methods:
<no static methods>
GENERATE_INHERITED_END
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
CUSTOM_EVENT_LISTENERS_START
CUSTOM_EVENT_LISTENERS_END
**/
class SystemLinking extends System {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
super(options);
this.emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_EVENT_LISTENERS_START
//GENERATE_EVENT_LISTENERS_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = SystemLinking;const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
const System = require('./r3-system.js');
/**
GENERATE_INHERITED_START
[Inherited from System]
Properties:
- started (Default value false)
Methods:
- start(options)
Just calls System.Start(options)
- stop(options)
Just calls System.Stop(options)
Static Methods:
- Start(options)
Starts the system by registering subscriptions to events
- Stop(options)
Stops the system by removing these subscriptions to events
[Belonging to SystemSocket]
Properties:
<no static properties>
Methods:
<no methods>
Static Methods:
<no static methods>
GENERATE_INHERITED_END
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
CUSTOM_EVENT_LISTENERS_START
CUSTOM_EVENT_LISTENERS_END
**/
class SystemSocket extends System {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
super(options);
this.emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_EVENT_LISTENERS_START
//GENERATE_EVENT_LISTENERS_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = SystemSocket;const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
const System = require('./r3-system.js');
/**
GENERATE_INHERITED_START
[Inherited from System]
Properties:
- started (Default value false)
Methods:
- start(options)
Just calls System.Start(options)
- stop(options)
Just calls System.Stop(options)
Static Methods:
- Start(options)
Starts the system by registering subscriptions to events
- Stop(options)
Stops the system by removing these subscriptions to events
[Belonging to SystemTest]
Properties:
<no static properties>
Methods:
<no methods>
Static Methods:
<no static methods>
GENERATE_INHERITED_END
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
CUSTOM_EVENT_LISTENERS_START
CUSTOM_EVENT_LISTENERS_END
**/
class SystemTest extends System {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
super(options);
this.emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_EVENT_LISTENERS_START
//GENERATE_EVENT_LISTENERS_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
module.exports = SystemTest;const Utils = require('./r3-utils');
const Event = require('./r3-event.js');
2021-06-20 20:46:13 +02:00
/**
2021-07-04 20:32:41 +02:00
GENERATE_INHERITED_START
[Inherited from Event]
Properties:
<no inherited properties>
Methods:
- async(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Async()' passing it the arguments
- emit(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Emit()' passing it the arguments
- subscribe(eventId, callback)
Simply calls 'Subscribe()' passing it the arguments
Static Methods:
- Async(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as
arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the
error as argument.
- Emit(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after
the event result is obtained, passing it the result. If an exception occurs during execution, the
clientErrorCallback is called with the error as argument.
- Subscribe(eventId, callback)
Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised
[Belonging to R3Object]
Properties:
- register (Default value true)
Methods:
<no methods>
Static Methods:
<no static methods>
GENERATE_INHERITED_END
Of the form x=<value>
CUSTOM_OPTIONS_START
register=true
CUSTOM_OPTIONS_END
Of the form x=<instance.property>
CUSTOM_INSTANCE_OPTIONS_MAPPING_START
CUSTOM_INSTANCE_OPTIONS_MAPPING_END
CUSTOM_LINKED_OBJECTS_START
CUSTOM_LINKED_OBJECTS_END
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_START
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
CUSTOM_STATIC_METHODS_END
2021-06-20 20:46:13 +02:00
**/
2021-07-04 20:32:41 +02:00
class R3Object extends Event {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
super(options);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_CREATED, this);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_OPTIONS_INIT_START
2021-06-20 20:46:13 +02:00
if (typeof options === 'undefined') {
options = {};
2021-07-04 20:32:41 +02:00
}
if (Utils.UndefinedOrNull(options.register)) {
options.register = true;
}
//GENERATE_OPTIONS_INIT_END
2021-06-20 20:46:13 +02:00
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
2021-07-04 20:32:41 +02:00
Object.assign(this, options);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_BEFORE_INIT_START
2021-06-20 20:46:13 +02:00
//CUSTOM_BEFORE_INIT_END
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_METHODS_START
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
//GENERATE_STATIC_METHODS_END
2021-06-20 20:46:13 +02:00
//CUSTOM_IMPLEMENTATION_START
2021-07-04 20:32:41 +02:00
//CUSTOM_IMPLEMENTATION_END
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
module.exports = R3Object;const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
const R3Object = require('.././r3-r3-object.js');
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
GENERATE_INHERITED_START
[Inherited from Event]
Properties:
<no inherited properties>
Methods:
- async(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Async()' passing it the arguments
- emit(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Emit()' passing it the arguments
- subscribe(eventId, callback)
Simply calls 'Subscribe()' passing it the arguments
Static Methods:
- Async(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as
arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the
error as argument.
- Emit(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after
the event result is obtained, passing it the result. If an exception occurs during execution, the
clientErrorCallback is called with the error as argument.
- Subscribe(eventId, callback)
Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised
[Inherited from R3Object]
Properties:
- register (Default value true)
Methods:
<no inherited methods>
Static Methods:
<no inherited static methods>
[Belonging to Component]
Properties:
- x (Default value 0)
- y (Default value 0)
- z (Default value 0)
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
Static Methods:
<no static methods>
GENERATE_INHERITED_END
Of the form x=<value>
CUSTOM_OPTIONS_START
x=0
y=0
z=0
CUSTOM_OPTIONS_END
Of the form x=<instance.property>
CUSTOM_INSTANCE_OPTIONS_MAPPING_START
CUSTOM_INSTANCE_OPTIONS_MAPPING_END
CUSTOM_LINKED_OBJECTS_START
CUSTOM_LINKED_OBJECTS_END
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_START
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
createInstance() - Creates an instance of this object based on the runtime.
updateInstance(property) - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object property(ies)
updateFromInstance(property) - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the value of the instance property(ies)
dispose() - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's instance, because an object instance should not exist without an object parent (except maybe for particles)
disposeInstance() - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to dispose the object parent this instance.
toApiObject() - Transforms the current object into JSON ready to be stored to the back-end. @returns JSON
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
CUSTOM_STATIC_METHODS_END
**/
class Component extends R3Object {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
super(options);
this.emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
if (typeof options === 'undefined') {
options = {};
2021-06-20 20:46:13 +02:00
}
2021-07-04 20:32:41 +02:00
if (Utils.UndefinedOrNull(options.x)) {
options.x = 0;
2021-06-20 20:46:13 +02:00
}
2021-07-04 20:32:41 +02:00
if (Utils.UndefinedOrNull(options.y)) {
options.y = 0;
}
if (Utils.UndefinedOrNull(options.z)) {
options.z = 0;
}
//GENERATE_OPTIONS_INIT_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
Object.assign(this, options);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_METHODS_START
/**
* createInstance()
* - Creates an instance of this object based on the runtime.
*/
createInstance() {
//GENERATE_CREATE_INSTANCE_METHOD_START
this.emit(Event.CREATE_INSTANCE_BEFORE, this);
this[this.runtime].createInstance(
this,
{
//GENERATE_CREATE_INSTANCE_OPTIONS_START
'x': this.x,
'y': this.y,
'z': this.z
//GENERATE_CREATE_INSTANCE_OPTIONS_END
2021-06-20 20:46:13 +02:00
}
2021-07-04 20:32:41 +02:00
)
this.emit(Event.INSTANCE_CREATED, this);
//GENERATE_CREATE_INSTANCE_METHOD_END
//CUSTOM_CREATE_INSTANCE_METHOD_START
//CUSTOM_CREATE_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
* updateInstance()
* - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
* property(ies)
* @param property
*/
updateInstance(property) {
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_INSTANCE_METHOD_START
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_INSTANCE_OPTIONS_START
if (property === 'x') {
this.instance.x = this.x;
if (property !== 'all') {
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
return;
2021-06-20 20:46:13 +02:00
}
}
2021-07-04 20:32:41 +02:00
if (property === 'y') {
this.instance.y = this.y;
if (property !== 'all') {
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
return;
}
}
if (property === 'z') {
this.instance.z = this.z;
if (property !== 'all') {
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
return;
2021-06-20 20:46:13 +02:00
}
}
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_INSTANCE_OPTIONS_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//GENERATE_UPDATE_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_UPDATE_INSTANCE_METHOD_START
//CUSTOM_UPDATE_INSTANCE_METHOD_END
2021-06-18 13:54:08 +02:00
2021-07-04 20:32:41 +02:00
}
/**
* updateFromInstance()
* - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
* value of the instance property(ies)
* @param property
*/
updateFromInstance(property) {
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_START
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_START
if (property === 'x' || property === 'all') {
this.x = this.instance.x;
if (property !== 'all') {
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
return;
}
}
if (property === 'y' || property === 'all') {
this.y = this.instance.y;
if (property !== 'all') {
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
return;
}
}
if (property === 'z' || property === 'all') {
this.z = this.instance.z;
if (property !== 'all') {
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
return;
}
}
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_START
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
* dispose()
* - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
* instance, because an object instance should not exist without an object parent (except maybe for particles)
*/
dispose() {
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_DISPOSE_METHOD_START
this.subscribe(
Event.INSTANCE_DISPOSED,
function(object) {
if (object === this) {
this.emit(Event.DISPOSE_OBJECT, this);
}
}
);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
this.disposeInstance();
//GENERATE_DISPOSE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_DISPOSE_METHOD_START
//CUSTOM_DISPOSE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
* disposeInstance()
* - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
* will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
* dispose the object parent this instance.
*/
disposeInstance() {
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_DISPOSE_INSTANCE_METHOD_START
console.log('Disposing instance of ' + this.name);
this.emit(Event.DISPOSE_INSTANCE, this);
//GENERATE_DISPOSE_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_DISPOSE_INSTANCE_METHOD_START
//CUSTOM_DISPOSE_INSTANCE_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
}
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
* toApiObject()
* - Transforms the current object into JSON ready to be stored to the back-end. \n * @returns JSON
*/
toApiObject() {
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_TO_API_OBJECT_METHOD_START
//GENERATE_TO_API_OBJECT_METHOD_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_TO_API_OBJECT_METHOD_START
//CUSTOM_TO_API_OBJECT_METHOD_END
2021-06-20 20:46:13 +02:00
}
2021-07-04 20:32:41 +02:00
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
//GENERATE_STATIC_METHODS_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
2021-06-20 20:46:13 +02:00
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
2021-07-04 20:32:41 +02:00
module.exports = Component;const Event = require('./r3-event');
const Utils = require('./r3-utils');
const R3Object = require('./r3-r3-object.js');
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
/**
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
GENERATE_INHERITED_START
2020-04-21 11:54:13 +02:00
2021-07-04 20:32:41 +02:00
[Inherited from Event]
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Properties:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no inherited properties>
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Methods:
2021-07-04 20:32:41 +02:00
- async(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Async()' passing it the arguments
2021-07-04 20:32:41 +02:00
- emit(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Emit()' passing it the arguments
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- subscribe(eventId, callback)
Simply calls 'Subscribe()' passing it the arguments
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Static Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- Async(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as
arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the
error as argument.
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- Emit(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after
the event result is obtained, passing it the result. If an exception occurs during execution, the
clientErrorCallback is called with the error as argument.
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- Subscribe(eventId, callback)
Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
[Inherited from R3Object]
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Properties:
2021-07-04 20:32:41 +02:00
- register (Default value true)
2021-07-04 20:32:41 +02:00
Methods:
2021-07-04 20:32:41 +02:00
<no inherited methods>
2021-07-04 20:32:41 +02:00
Static Methods:
2021-07-04 20:32:41 +02:00
<no inherited static methods>
2021-07-04 20:32:41 +02:00
[Belonging to Project]
2021-07-04 20:32:41 +02:00
Properties:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no static properties>
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no methods>
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Static Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no static methods>
2021-07-04 20:32:41 +02:00
GENERATE_INHERITED_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Of the form x=<value>
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
Of the form x=<instance.property>
CUSTOM_INSTANCE_OPTIONS_MAPPING_START
CUSTOM_INSTANCE_OPTIONS_MAPPING_END
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
CUSTOM_LINKED_OBJECTS_START
CUSTOM_LINKED_OBJECTS_END
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_START
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
CUSTOM_STATIC_METHODS_END
**/
class Project extends R3Object {
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
2021-06-20 20:46:13 +02:00
options = {};
}
2021-07-04 20:32:41 +02:00
super(options);
2021-06-20 20:46:13 +02:00
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_CREATED, this);
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
2021-06-20 20:46:13 +02:00
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
2021-07-04 20:32:41 +02:00
Object.assign(this, options);
2021-07-04 20:32:41 +02:00
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_INITIALIZED, this);
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
}
//GENERATE_CONSTRUCTOR_EXTENDS_END
2021-07-04 20:32:41 +02:00
//GENERATE_METHODS_START
//GENERATE_METHODS_END
2021-07-04 20:32:41 +02:00
//GENERATE_STATIC_METHODS_START
//GENERATE_STATIC_METHODS_END
2021-07-04 20:32:41 +02:00
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
Project.CAMERA_INDEX_EDIT = 0x0;
Project.CAMERA_INDEX_RUN = 0x1;
Project.APPLICATION_MODE_EDIT = Project.CAMERA_INDEX_EDIT;
Project.APPLICATION_MODE_RUN = Project.CAMERA_INDEX_RUN;
Project.RENDERER_INDEX_MAIN = 0x0;
Project.RENDER_TARGET_INDEX_NONE = -0x1;
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
2021-07-04 20:32:41 +02:00
module.exports = Project;const Event = require('.././r3-event');
const Utils = require('.././r3-utils');
const Component = require('.././r3-component.js');
2020-04-21 11:54:13 +02:00
2021-07-04 20:32:41 +02:00
/**
2020-04-21 11:54:13 +02:00
2021-07-04 20:32:41 +02:00
GENERATE_INHERITED_START
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
[Inherited from Event]
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Properties:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no inherited properties>
2020-04-21 11:54:13 +02:00
2021-07-04 20:32:41 +02:00
Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- async(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Async()' passing it the arguments
2020-04-21 11:54:13 +02:00
2021-07-04 20:32:41 +02:00
- emit(eventId, data, clientCallback, clientErrorCallback)
Simply calls 'Emit()' passing it the arguments
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
- subscribe(eventId, callback)
Simply calls 'Subscribe()' passing it the arguments
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Static Methods:
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
- Async(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as
arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the
error as argument.
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
- Emit(eventId, data, clientCallback, clientErrorCallback)
Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after
the event result is obtained, passing it the result. If an exception occurs during execution, the
clientErrorCallback is called with the error as argument.
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
- Subscribe(eventId, callback)
Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
[Inherited from R3Object]
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Properties:
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
- register (Default value true)
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Methods:
2021-07-04 20:32:41 +02:00
<no inherited methods>
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Static Methods:
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
<no inherited static methods>
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
[Inherited from Component]
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Properties:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- x (Default value 0)
- y (Default value 0)
- z (Default value 0)
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- createInstance()
Creates an instance of this object based on the runtime.
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
Static Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
<no inherited static methods>
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
[Belonging to Image]
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Properties:
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
<no static properties>
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
Methods:
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
- createInstance()
Creates an instance of this object based on the runtime.
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
Static Methods:
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
<no static methods>
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
GENERATE_INHERITED_END
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
Of the form x=<value>
CUSTOM_OPTIONS_START
CUSTOM_OPTIONS_END
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
Of the form x=<instance.property>
CUSTOM_INSTANCE_OPTIONS_MAPPING_START
CUSTOM_INSTANCE_OPTIONS_MAPPING_END
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
CUSTOM_LINKED_OBJECTS_START
CUSTOM_LINKED_OBJECTS_END
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_START
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
CUSTOM_METHODS_START
createInstance() - Creates an instance of this object based on the runtime.
updateInstance(property) - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object property(ies)
updateFromInstance(property) - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the value of the instance property(ies)
dispose() - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's instance, because an object instance should not exist without an object parent (except maybe for particles)
disposeInstance() - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to dispose the object parent this instance.
toApiObject() - Transforms the current object into JSON ready to be stored to the back-end. @returns JSON
CUSTOM_METHODS_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
CUSTOM_STATIC_METHODS_START
CUSTOM_STATIC_METHODS_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
**/
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
class Image extends Component {
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_CONSTRUCTOR_EXTENDS_START
constructor(options) {
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
if (Utils.UndefinedOrNull(options)) {
options = {};
2021-06-18 02:10:32 +02:00
}
2021-07-04 20:32:41 +02:00
super(options);
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_CREATED, this);
2020-04-23 15:26:54 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_OPTIONS_INIT_START
//GENERATE_OPTIONS_INIT_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
Object.assign(this, options);
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
this.emit(Event.OBJECT_INITIALIZED, this);
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//CUSTOM_AFTER_INIT_START
//CUSTOM_AFTER_INIT_END
2021-06-18 02:10:32 +02:00
}
2021-07-04 20:32:41 +02:00
//GENERATE_CONSTRUCTOR_EXTENDS_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_METHODS_START
/**
* createInstance()
* - Creates an instance of this object based on the runtime.
*/
createInstance() {
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
//GENERATE_CREATE_INSTANCE_METHOD_START
this.emit(Event.CREATE_INSTANCE_BEFORE, this);
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
this[this.runtime].createInstance(
this,
{
//GENERATE_CREATE_INSTANCE_OPTIONS_START
//GENERATE_CREATE_INSTANCE_OPTIONS_END
}
)
this.emit(Event.INSTANCE_CREATED, this);
//GENERATE_CREATE_INSTANCE_METHOD_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//CUSTOM_CREATE_INSTANCE_METHOD_START
//CUSTOM_CREATE_INSTANCE_METHOD_END
2021-06-18 02:10:32 +02:00
2021-07-04 20:32:41 +02:00
}
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
/**
* updateInstance()
* - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
* property(ies)
* @param property
*/
updateInstance(property) {
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_INSTANCE_METHOD_START
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//GENERATE_UPDATE_INSTANCE_OPTIONS_START
//GENERATE_UPDATE_INSTANCE_OPTIONS_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//GENERATE_UPDATE_INSTANCE_METHOD_END
2021-07-04 20:32:41 +02:00
//CUSTOM_UPDATE_INSTANCE_METHOD_START
//CUSTOM_UPDATE_INSTANCE_METHOD_END
2020-02-27 17:07:46 +01:00
2021-06-18 02:10:32 +02:00
}
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
/**
* updateFromInstance()
* - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
* value of the instance property(ies)
* @param property
*/
updateFromInstance(property) {
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_START
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_START
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_END
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_START
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
}
/**
* dispose()
* - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
* instance, because an object instance should not exist without an object parent (except maybe for particles)
*/
dispose() {
//GENERATE_DISPOSE_METHOD_START
this.subscribe(
Event.INSTANCE_DISPOSED,
function(object) {
if (object === this) {
this.emit(Event.DISPOSE_OBJECT, this);
}
}
);
this.disposeInstance();
//GENERATE_DISPOSE_METHOD_END
//CUSTOM_DISPOSE_METHOD_START
//CUSTOM_DISPOSE_METHOD_END
}
/**
* disposeInstance()
* - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
* will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
* dispose the object parent this instance.
*/
disposeInstance() {
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
//GENERATE_DISPOSE_INSTANCE_METHOD_START
console.log('Disposing instance of ' + this.name);
this.emit(Event.DISPOSE_INSTANCE, this);
//GENERATE_DISPOSE_INSTANCE_METHOD_END
//CUSTOM_DISPOSE_INSTANCE_METHOD_START
//CUSTOM_DISPOSE_INSTANCE_METHOD_END
}
/**
* toApiObject()
* - Transforms the current object into JSON ready to be stored to the back-end. \n * @returns JSON
*/
toApiObject() {
//GENERATE_TO_API_OBJECT_METHOD_START
//GENERATE_TO_API_OBJECT_METHOD_END
//CUSTOM_TO_API_OBJECT_METHOD_START
//CUSTOM_TO_API_OBJECT_METHOD_END
}
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START
//GENERATE_STATIC_METHODS_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
2020-02-27 17:07:46 +01:00
2021-07-04 20:32:41 +02:00
module.exports = Image;