beta.r3js.org
Theunis Johannes Botha 2018-04-09 09:35:04 +02:00
parent bb0efcf756
commit ed9c19b2d5
352 changed files with 55309 additions and 0 deletions

59
src/r3-a-0.js Normal file
View File

@ -0,0 +1,59 @@
/**
* R3 Namespace
*/
if (typeof R3 === 'undefined') {
function R3() {}
}
/**
* R3.D3 Namespace
*/
if (typeof R3.D3 === 'undefined') {
R3.D3 = function(){};
}
/**
* R3.D3.API Namespace
* @constructor
*/
if (typeof R3.D3.API === 'undefined') {
R3.D3.API = function(){};
}
/**
* R3.API Namespace
*/
if (typeof R3.API === 'undefined') {
R3.API = function(){};
}
/**
* R3.D3.Runtime Namespace
* @constructor
*/
if (typeof R3.D3.Runtime === 'undefined') {
R3.D3.Runtime = function(){};
}
// if (typeof Q === 'undefined') {
//
// if (typeof require === 'undefined') {
// console.warn('You need the Q promise library for the R3.D3');
// throw new Error('You need the Q promise library for the R3.D3');
// }
//
// var Q = require('q');
// }
//
// if (typeof _ === 'undefined') {
//
// if (typeof require === 'undefined') {
// console.warn('You need the lodash library for the R3.D3');
// throw new Error('You need the lodash library for the R3.D3');
// }
//
// var _ = require('lodash');
// }
// This gets injected by gulp
console.log("Loading R3 compiled at: " + __DATE__);

486
src/r3-a-1-event.js Normal file
View File

@ -0,0 +1,486 @@
/**
* Event Core
* @constructor
*/
R3.Event = function() {
};
/**
* Some nice Events handling
* @type {{}}
*/
R3.Event.Subscriptions = {};
R3.Event.OnceSubscriptions = {};
/**
* Events we can subscribe to and publish
*/
R3.Event.WINDOW_RESIZE = 0x1;
R3.Event.PARENT_SCENE_CHANGE = 0x2;
R3.Event.EXCLUDE_FROM_ENVIRONMENT = 0x3;
R3.Event.INSTANCE_CLONED = 0x4;
R3.Event.LOAD_IMAGE = 0x5;
R3.Event.NEW_ENTITY = 0x6;
R3.Event.MATERIAL_TYPE_CHANGED = 0x7;
R3.Event.SAVE_COMPONENT = 0x8;
R3.Event.SAVE_COMPONENT_ERROR = 0x9;
R3.Event.COMPONENT_SAVED = 0xa;
R3.Event.LOAD_COMPONENT = 0xb;
R3.Event.LOAD_COMPONENT_ERROR = 0xc;
R3.Event.LOGGED_IN = 0xd;
R3.Event.COMPONENT_CREATED = 0xe;
R3.Event.COMPONENT_CLONED = 0xf;
R3.Event.TEXTURE_ANIMATED_CHANGE = 0x10;
R3.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
R3.Event.REMOVE_PARTICLE_ENGINE = 0x12;
R3.Event.GAME_PAUSE = 0x13;
R3.Event.SHADER_UPDATE = 0x14;
R3.Event.PLAY_AUDIO = 0x15;
R3.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
R3.Event.PAUSE_AUDIO = 0x17;
R3.Event.MESH_INSTANCE_UPDATED = 0x18;
R3.Event.STOP_AUDIO = 0x19;
R3.Event.LIGHT_INSTANCE_UPDATED = 0x1a;
R3.Event.DELETE_COMPONENT = 0x1b;
R3.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c;
R3.Event.COMPONENTS_LINKED = 0x1d;
R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e;
R3.Event.REGISTER_UPDATE = 0x1f;
R3.Event.BUILD_GUI = 0x20;
R3.Event.REMOVE_MESH = 0x21;
R3.Event.MESH_SELECTED = 0x22;
R3.Event.MESH_DESELECTED = 0x23;
R3.Event.COMPONENT_REGISTER = 0x24;
R3.Event.IMAGE_NOT_FOUND = 0x25;
R3.Event.BLENDER_DATA_RECEIVED = 0x26;
R3.Event.IMAGE_UPLOAD_COMPLETE = 0x27;
R3.Event.REMOVE_COMPONENT = 0x28;
R3.Event.KEY_DOWN = 0x29;
R3.Event.KEY_UP = 0x2a;
R3.Event.RENDER = 0x2b;
R3.Event.EVENT_LIST = 0x2c;
R3.Event.COMPILE_SUCCESS = 0x2d;
R3.Event.COMPILE_FAILED = 0x2e;
R3.Event.TEXTURE_INSTANCE_UPDATED = 0x2f;
R3.Event.EVENT_ID_UPDATE = 0x30;
R3.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
R3.Event.DELETE_COMPONENT_ERROR = 0x32;
R3.Event.COMPONENT_DELETED = 0x33;
R3.Event.COMPONENT_TYPES_FETCHED = 0x34;
R3.Event.AUDIO_ENDED = 0x35;
R3.Event.COMPONENT_LINKED = 0x36;
R3.Event.DONE_SAVING = 0x37;
R3.Event.BEFORE_RENDER = 0x38;
R3.Event.AFTER_RENDER = 0x39;
R3.Event.ARRAY_ITEM_ADDED = 0x3a;
R3.Event.INSTANCE_CREATED = 0x3b;
R3.Event.VISUALIZE = 0x3c;
R3.Event.STOP_VISUALIZE = 0x3d;
R3.Event.FETCH_COMPONENT_TYPES = 0x3e;
R3.Event.FETCH_COMPONENTS = 0x3f;
R3.Event.GET_API_URL = 0x40;
R3.Event.GET_RUNTIME = 0x41;
R3.Event.PARENT_WORLD_CHANGE = 0x42;
R3.Event.ANIMATE = 0x43;
R3.Event.ANIMATION_COMPILE_SUCCESS = 0x44;
R3.Event.ANIMATION_COMPILE_FAILED = 0x45;
R3.Event.SAVING = 0x46;
R3.Event.GAME_OVER = 0x47;
R3.Event.GAME_START = 0x48;
R3.Event.TOUCH_START = 0x49;
R3.Event.TOUCH_END = 0x4a;
R3.Event.TOUCH_MOVE = 0x4b;
R3.Event.TOUCH_CANCEL = 0x4c;
R3.Event.GET_REMOTE_API_URL = 0x4d;
R3.Event.COMPONENT_TYPES_UPDATE = 0x4e;
R3.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
R3.Event.CAST_SOURCE_CHANGED = 0x50;
R3.Event.RESOLVE_DEPENDENCIES = 0x51;
R3.Event.NAME_UPDATE = 0x52;
R3.Event.CANVAS_CHANGE = 0x53;
R3.Event.AFTER_WINDOW_RESIZE = 0x54;
R3.Event.LOAD_FONT = 0x55;
R3.Event.FONT_NOT_FOUND = 0x56;
R3.Event.STOP_ALL_AUDIO = 0x57;
R3.Event.REGISTER_DEPENDENCIES = 0x58;
R3.Event.GAME_LOADED = 0x59;
R3.Event.COMPONENT_UPDATE = 0x5a;
R3.Event.LOAD_PROGRESS = 0x5b;
R3.Event.ENTITY_LOADED = 0x5c;
R3.Event.MOUSE_DOWN = 0x5d;
R3.Event.MOUSE_MOVE = 0x5e;
R3.Event.MOUSE_WHEEL = 0x5f;
R3.Event.MOUSE_UP = 0x60;
R3.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
R3.Event.GAME_DATA = 0x62;
R3.Event.PAUSE_ALL_AUDIO = 0x63;
R3.Event.CONTINUE_ALL_AUDIO = 0x64;
R3.Event.MUTE_AUDIO = 0x65;
R3.Event.GAME_STARTED = 0x66;
R3.Event.GAME_PAUSED = 0x67;
R3.Event.GAME_RESUMED = 0x68;
R3.Event.CUSTOM_GAME_START = 0x69;
R3.Event.AUDIO_MUTED = 0x6a;
R3.Event.AUDIO_UNMUTED = 0x6b;
R3.Event.RECEIVE_DESTINATION_CHANGED = 0x6c;
R3.Event.SELECTION_MODE_CHANGE = 0x6d;
R3.Event.MESH_FACE_SELECTED = 0x6e;
R3.Event.MESH_FACE_DESELECTED = 0x6f;
R3.Event.BEFORE_WINDOW_RESIZE = 0x70;
R3.Event.GET_WINDOW_SIZE = 0x71;
R3.Event.GET_RENDER_CONFIGURATION = 0x72;
R3.Event.SET_ACTIVE_RENDER_CONFIGURATION = 0x73;
R3.Event.REPLACE_COMPONENT = 0x74;
R3.Event.COMPONENT_REPLACED = 0x75;
R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76;
/**
* Returns string name of event ID
* @param number
* @returns {*}
* @constructor
*/
R3.Event.GetEventName = function(number) {
switch(number) {
case 0x1 : return 'window_resize';
case 0x2 : return 'parent_scene_change';
case 0x3 : return 'unused';
case 0x4 : return 'instance_cloned';
case 0x5 : return 'load_image';
case 0x6 : return 'new_entity';
case 0x7 : return 'material_type_changed';
case 0x8 : return 'save_component';
case 0x9 : return 'save_component_error';
case 0xa : return 'component_saved';
case 0xb : return 'load_component';
case 0xc : return 'load_component_error';
case 0xd : return 'logged_in';
case 0xe : return 'component_created';
case 0xf : return 'component_cloned';
case 0x10 : return 'texture_animated_change';
case 0x11 : return 'animate_texture_instance';
case 0x12 : return 'remove_particle_engine';
case 0x13 : return 'pause';
case 0x14 : return 'shader_update';
case 0x15 : return 'play_audio';
case 0x16 : return 'material_instance_updated';
case 0x17 : return 'pause_audio';
case 0x18 : return 'mesh_instance_updated';
case 0x19 : return 'stop_audio';
case 0x1a : return 'light_instance_updated';
case 0x1b : return 'delete_component';
case 0x1c : return 'component_download_complete';
case 0x1d : return 'components_linked';
case 0x1e : return 'unresolved_dependencies_update';
case 0x1f : return 'register_update';
case 0x20 : return 'build_gui';
case 0x21 : return 'remove_mesh';
case 0x22 : return 'mesh_selected';
case 0x23 : return 'mesh_deselected';
case 0x24 : return 'component_register';
case 0x25 : return 'image_not_found';
case 0x26 : return 'blender_data_received';
case 0x27 : return 'image_upload_complete';
case 0x28 : return 'remove_component';
case 0x29 : return 'key_down';
case 0x2a : return 'key_up';
case 0x2b : return 'render';
case 0x2c : return 'event_list';
case 0x2d : return 'compile_success';
case 0x2e : return 'compile_failed';
case 0x2f : return 'texture_image_updated';
case 0x30 : return 'event_id_update';
case 0x31 : return 'material_textures_updated';
case 0x32 : return 'delete_component_error';
case 0x33 : return 'component_deleted';
case 0x34 : return 'component_types_updated';
case 0x35 : return 'audio_ended';
case 0x36 : return 'component_linked';
case 0x37 : return 'done_saving';
case 0x38 : return 'before_render';
case 0x39 : return 'after_render';
case 0x3a : return 'array_item_added';
case 0x3b : return 'instance_created';
case 0x3c : return 'visualize';
case 0x3d : return 'stop_visualize';
case 0x3e : return 'fetch_component_types';
case 0x3f : return 'fetch_components';
case 0x40 : return 'get_api_url';
case 0x41 : return 'get_runtime';
case 0x42 : return 'parent_world_change';
case 0x43 : return 'animate';
case 0x44 : return 'animation_compile_success';
case 0x45 : return 'animation_compile_failed';
case 0x46 : return 'saving';
case 0x47 : return 'game_over';
case 0x48 : return 'game_start';
case 0x49 : return 'touch_start';
case 0x4a : return 'touch_end';
case 0x4b : return 'touch_move';
case 0x4c : return 'touch_cancel';
case 0x4d : return 'get_remote_api_url';
case 0x4e : return 'component_types_update';
case 0x4f : return 'delayed_instance_encountered';
case 0x50 : return 'cast_source_changed';
case 0x51 : return 'resolve_dependencies';;
case 0x52 : return 'name_update';
case 0x53 : return 'dom_element_change';
case 0x54 : return 'after_window_resize';
case 0x55 : return 'load_font';
case 0x56 : return 'font_not_found';
case 0x57 : return 'stop_all_audio';
case 0x58 : return 'register_dependencies';
case 0x59 : return 'game_loaded';
case 0x5a : return 'component_update';
case 0x5b : return 'load_progress';
case 0x5c : return 'entity_loaded';
case 0x5d : return 'mouse_down';
case 0x5e : return 'mouse_move';
case 0x5f : return 'mouse_wheel';
case 0x60 : return 'mouse_up';
case 0x61 : return 'particle_instance_updated';
case 0x62 : return 'game_data';
case 0x63 : return 'pause_all_audio';
case 0x64 : return 'continue_all_audio';
case 0x65 : return 'mute_audio';
case 0x66 : return 'game_started';
case 0x67 : return 'game_paused';
case 0x68 : return 'game_resumed';
case 0x69 : return 'custom_game_start';
case 0x6a : return 'audio_muted';
case 0x6b : return 'audio_unmuted';
case 0x6c : return 'receive_destination_changed';
case 0x6d : return 'selection_mode_change';
case 0x6e : return 'mesh_face_selected';
case 0x6f : return 'mesh_face_deselected';
case 0x70 : return 'before_window_resize';
case 0x71 : return 'get_window_size';
case 0x72 : return 'get_render_configuration';
case 0x73 : return 'set_active_render_configuration';
case 0x74 : return 'replace_component';
case 0x75 : return 'component_replaced';
case 0x76 : return 'engine_fired_particles_zero';
break;
}
throw new error('unknown event id: ' + number );
};
/**
* Subscribe to some events
* @param eventName
* @param callback
*/
R3.Event.prototype.subscribe = function(
eventName,
callback
) {
return R3.Event.Subscribe(eventName, callback.bind(this));
};
// /**
// * Stop listening for this event after the callback returns true
// * @param eventName
// * @param callback
// * @returns {{fn, remove: remove}}
// */
// R3.Event.prototype.subscribeOnce = function(
// eventName,
// callback
// ) {
// throw new Error('implement first properly');
// // var fn = callback.bind(this);
// //
// // if (R3.Event.OnceSubscriptions.hasOwnProperty(eventName)) {
// // R3.Event.OnceSubscriptions[eventName].push(fn);
// // } else {
// // R3.Event.OnceSubscriptions[eventName] = [];
// // R3.Event.OnceSubscriptions[eventName].push(fn);
// // }
// //
// // /**
// // * Return a handle to the caller to allow us to unsubscribe to this event
// // */
// // return {
// // fn : fn,
// // remove : function() {
// // R3.Event.Subscriptions[eventName].splice(
// // R3.Event.Subscriptions[eventName].indexOf(fn),
// // 1
// // );
// // }
// // }
// };
/**
*
* @param eventName
* @param data
*/
/**
* Publish some event happened with some data
* @param eventName
* @param data
* @param clientCallback
* @param clientErrorCallback
* @returns {number} of callbacks executed
*/
R3.Event.prototype.publish = function(
eventName,
data,
clientCallback,
clientErrorCallback
) {
return R3.Event.Emit(
eventName,
data,
clientCallback,
clientErrorCallback
);
};
/**
* Static method call
* @param eventName
* @param data
* @param clientCallback is executed ideally when the event completed
* @param clientErrorCallback
* @returns {number} of callbacks executed
* @constructor
*/
R3.Event.Emit = function(
eventName,
data,
clientCallback,
clientErrorCallback
) {
var count = 0;
if (R3.Event.Subscriptions.hasOwnProperty(eventName)) {
if (R3.Event.Subscriptions[eventName].length === 0) {
if (clientCallback) {
/**
* We execute the client callback immediately since there are no subscriptions to this event
*/
clientCallback();
}
if (clientErrorCallback) {
clientErrorCallback({
message : 'No subscriptions for event ' + eventName
})
}
}
/**
* We need to execute all the callbacks, but not execute them twice, but also keep in mind they can remove
* themselves during execution
*/
// var length = R3.Event.Subscriptions[eventName].length;
//
// for (var i = 0; i < length; i++) {
//
// var object = R3.Event.Subscriptions[eventName][i];
//
// if (object.fn && object.executed === false) {
// object.fn(data, clientCallback, clientErrorCallback);
// object.executed = true;
// }
//
// if (length !== R3.Event.Subscriptions[eventName].length) {
// /**
// * this callback removed a subscription - reset i and reset the length
// */
// i = 0;
// length = R3.Event.Subscriptions[eventName].length;
// }
// }
//
// R3.Event.Subscriptions[eventName].map(
// function(object){
// object.executed = false;
// }
// )
R3.Event.Subscriptions[eventName].map(
function(callback) {
if (callback) {
callback(data, clientCallback, clientErrorCallback);
count++;
}
}
)
} else {
if (clientCallback) {
/**
* We execute the client callback immediately since there are no subscriptions to this event
*/
clientCallback();
}
if (clientErrorCallback) {
clientErrorCallback({
message : 'No subscriptions for event ' + eventName
})
}
}
return count;
};
R3.Event.Subscribe = function(
eventName,
fn
) {
if (R3.Event.Subscriptions.hasOwnProperty(eventName)) {
R3.Event.Subscriptions[eventName].push(fn);
// {
// fn : fn,
// executed : false
// }
// );
} else {
R3.Event.Subscriptions[eventName] = [];
R3.Event.Subscriptions[eventName].push(fn);
// {
// fn : fn,
// executed : false
// }
// );
}
/**
* Return a handle to the caller to allow us to unsubscribe to this event
*/
return {
fn : fn,
remove : function() {
var index = R3.Event.Subscriptions[eventName].indexOf(fn);
// reduce(
// function(result, object, index) {
// if (object.fn === fn) {
// result = index;
// }
// return result;
// },
// -1
// );
if (index === -1) {
throw new Error('could not remove subscription');
}
R3.Event.Subscriptions[eventName].splice(
index,
1
);
}
}
};

990
src/r3-a-2-utils.js Normal file
View File

@ -0,0 +1,990 @@
R3.Utils = function() {};
/**
* Strips image extension from given path
* @param imagePath
* @constructor
*/
R3.Utils.StripImageExtension = function(imagePath) {
return imagePath.replace(/(\.png$|\.gif$|\.jpeg$|\.jpg$)/,'')
};
R3.Utils.BuildVectorSource = function(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
*/
R3.Utils.GetArrayInstances = function(array) {
return array.reduce(
function(result, object) {
if (result === null) {
return result;
}
if (R3.Utils.UndefinedOrNull(object.instance)) {
result = null;
} else {
result.push(object.instance);
}
return result;
},
[]
);
};
R3.Utils.SortFacesByMaterialIndex = function(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;
};
R3.Utils.BuildQuaternionSource = function(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;
};
R3.Utils.ObjectPropertiesAsBoolean = function(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) {
// R3.Utils.BuildVectorSource(result, propertyId, 2);
// }
//
// if (object[propertyId] instanceof R3.Vector3) {
// R3.Utils.BuildVectorSource(result, propertyId, 3);
// }
//
// if (object[propertyId] instanceof R3.Vector4) {
// R3.Utils.BuildVectorSource(result, propertyId, 4);
// }
//
// if (object[propertyId] instanceof R3.Quaternion) {
// R3.Utils.BuildQuaternionSource(result, propertyId);
// }
return result;
}.bind(this),
{}
);
};
R3.Utils.GetRuntime = function() {
var result = null;
R3.Event.Emit(
R3.Event.GET_RUNTIME,
null,
function(runtime) {
result = runtime;
}
);
return result;
};
/**
* Returns the window size or null
* @returns {*}
* @constructor
*/
R3.Utils.GetWindowSize = function() {
var 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
*/
R3.Utils.UpdateWindowSize = function(object) {
var size = R3.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
*/
R3.Utils.ObjectIdWithNameInArray = function(name, array) {
return array.reduce(
function(result, object) {
if (result) {
return result;
}
if (name === object.name) {
return object.id;
}
return null;
},
null
);
};
// R3.Utils.ObjectFactory = function() {
//
// var promiseList = {};
//
// return function(objectId) {
//
// if (!objectId) {
// console.log('No Object ID specified ' + objectId);
// throw new Error('No Object ID specified ' + objectId);
// }
//
// if (promiseList[objectId]) {
// return promiseList[objectId];
// }
//
// var defer = Q.defer();
//
// promiseList[objectId] = defer.promise;
//
// R3.Utils.ObjectFactory.Link(idToObject, objectId, defer);
//
// return promiseList[objectId];
// }
// };
R3.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
};
R3.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
};
/**
* Gets random int exclusive of maximum but inclusive of minimum
* @param min
* @param max
* @returns {*}
* @constructor
*/
R3.Utils.GetRandomInt = function(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
*/
R3.Utils.GetRandomIntInclusive = function(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
};
R3.Utils.InterpolateArray = function(data, fitCount) {
var linearInterpolate = function (before, after, atPoint) {
return before + (after - before) * atPoint;
};
var newData = [];
var springFactor = Number((data.length - 1) / (fitCount - 1));
newData[0] = data[0]; // for new allocation
for ( var i = 1; i < fitCount - 1; i++) {
var tmp = i * springFactor;
var before = Number(Math.floor(tmp)).toFixed();
var after = Number(Math.ceil(tmp)).toFixed();
var 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
*/
R3.Utils.UndefinedOrNull = function (
variable
) {
return typeof variable === 'undefined' || variable === null;
};
/**
* The variable is not undefined and not null
* @param variable
* @returns {boolean}
* @constructor
*/
R3.Utils.Defined = function (
variable
) {
return typeof variable !== 'undefined' && variable !== null;
};
/**
* Gets function parameters
* @param fn
* @constructor
*/
R3.Utils.GetParameters = function(fn) {
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(.+?)\1\s*$/;
var STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg;
var 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
*/
R3.Utils.IdOrNull = function (object) {
if (R3.Utils.UndefinedOrNull(object)) {
return null;
} else {
if (R3.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
*/
R3.Utils.LimitToPI = function(property, objectProperty) {
var 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
*/
R3.Utils.IdArrayOrEmptyArray = function (array) {
if (R3.Utils.UndefinedOrNull(array)) {
return [];
} else {
return array.map(function(item) {
if (R3.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
*/
R3.Utils.Link = function(propertyString, idToObject, parentObject, id) {
if (!R3.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
*/
R3.Utils.RandomId = function(length) {
if (R3.Utils.UndefinedOrNull(length)) {
length = 10;
}
return Math.random().toString(36).substr(2, length);
};
R3.Utils.InvertWindingOrder = function(triangles) {
for (var i = 0; i < triangles.length; i++) {
var v1 = triangles[i].v1;
triangles[i].v1 = triangles[i].v2;
triangles[i].v2 = v1;
var 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
*/
R3.Utils.InvertMeshWindingOrder = function(mesh) {
mesh.faces.forEach(
function (face) {
var tmpV1 = face.v1;
face.v1 = face.v2;
face.v2 = tmpV1;
var 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)
*/
R3.Utils.ResetWindingOrder = function(faces, vertices) {
var vertexList = new R3.API.Vector3.Points();
for (var v = 0; v < vertices.length; v++) {
vertexList.add(new R3.API.Vector3(
vertices[v].position.x,
vertices[v].position.y,
vertices[v].position.z
));
}
var V = vertexList.average();
var triangles = [];
for (var s = 0; s < faces.length; s += 3) {
var v0 = faces[s];
var v1 = faces[s+1];
var 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 (var 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');
var 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}
*/
R3.Utils.FixWindingOrder = function(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 (var 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 (var 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)
) {
var 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;
}
var 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
)
];
var processed = [];
while (toProcess.length > 0) {
var 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)
) {
var backupV = triangleEdge.triangle.v1index;
triangleEdge.triangle.v1index = triangleEdge.triangle.v2index;
triangleEdge.triangle.v2index = backupV;
// var backupUV = triangleEdge.triangle.v1uv;
// triangleEdge.triangle.v1uv = triangleEdge.triangle.v2uv;
// triangleEdge.triangle.v2uv = backupUV;
//
var 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);
var 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 (var j = 0; j < edges.length; j++) {
var 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}
*/
var triangles = [];
for (var i = 0; i < processed.length; i++) {
var found = false;
for (var 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 []
*/
R3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
if ((verticesFlat.length % 3) !== 0 && !(verticesFlat.length > 9)) {
console.log("The vertices are not in the right length : " + verticesFlat.length);
}
var vertices = [];
var points = new R3.API.Quaternion.Points();
for (var 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;
};
R3.Utils.MovingAverage = function(period) {
var nums = [];
return function(num) {
nums.push(num);
if (nums.length > period)
nums.splice(0,1); // remove the first element of the array
var sum = 0;
for (var i in nums)
sum += nums[i];
var n = period;
if (nums.length < period)
n = nums.length;
return(sum/n);
}
};
R3.Utils.Intersect = function (a, b) {
var 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;
}
);
};
R3.Utils.Difference = function (a, b) {
var 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
*/
R3.Utils.PushUnique = function(array, object) {
if (array.indexOf(object) === -1) {
array.push(object);
}
};
/**
* Checks whether or not the object is empty
* @param obj
* @returns {boolean}
* @constructor
*/
R3.Utils.IsEmpty = function(obj) {
return (Object.keys(obj).length === 0 && obj.constructor === Object);
};
R3.Utils.isString = function(member) {
return (typeof member === 'string');
};
R3.Utils.isBoolean = function(member) {
return (member === true || member === false);
};
R3.Utils.isColor = function(member) {
return (member instanceof R3.Color);
};
R3.Utils.isNumber = function(member) {
return (typeof member === 'number');
};
R3.Utils.isVector2 = function(member) {
return (
member instanceof R3.API.Vector2 ||
member instanceof R3.Vector2
);
};
R3.Utils.isVector3 = function(member) {
return (
member instanceof R3.API.Vector3 ||
member instanceof R3.Vector3
);
};
R3.Utils.isVector4 = function(member) {
return (
member instanceof R3.API.Vector4 ||
member instanceof R3.Vector4 ||
member instanceof R3.API.Quaternion ||
member instanceof R3.Quaternion
);
};
/**
* @return {string}
*/
R3.Utils.LowerUnderscore = function(name) {
return name.toLowerCase().replace(/\s+/, '_');
};
R3.Utils.UpperCaseWordsSpaces = function(input) {
var word = input.replace(/[-_]/g, ' ');
word = word.replace(/\s+/, ' ');
var words = word.split(' ');
return words.reduce(
function(result, word) {
result += word[0].toUpperCase() + word.substr(1);
return result + ' ';
},
''
).trim();
};
/**
* @return {string}
*/
R3.Utils.UpperCaseUnderscore = function(word) {
var 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
*/
R3.Utils.PaddedText = function(length, padChar, string) {
var pad = "";
for (var x = 0; x < length; x++) {
pad += padChar;
}
return pad.substring(0, pad.length - string.length) + string;
};

19
src/r3-a-api-component.js Normal file
View File

@ -0,0 +1,19 @@
/**
* API Component Interface - Do not construct objects of this type directly
* @param componentType
* @param parentEntity
* @constructor
*/
R3.API.Component = function(
componentType,
parentEntity
) {
this.componentType = componentType;
if (R3.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
R3.API.Component.prototype.constructor = R3.API.Component;

2003
src/r3-a-component-a.js Normal file

File diff suppressed because it is too large Load Diff

45
src/r3-api-box3.js Normal file
View File

@ -0,0 +1,45 @@
/**
* R3.API.Box3
* @param id
* @param name
* @param parentEntity
* @param min
* @param max
* @constructor
*/
R3.API.Box3 = function (
id,
name,
parentEntity,
min,
max
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Box (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(min)) {
min = new R3.API.Vector3(0,0,0);
}
this.min = min;
if (R3.Utils.UndefinedOrNull(max)) {
max = new R3.API.Vector3(1,1,1);
}
this.max = max;
R3.API.Component.call(
this,
R3.Component.BOX3,
parentEntity
)
};
R3.API.Box3.prototype = Object.create(R3.API.Component.prototype);
R3.API.Box3.prototype.constructor = R3.API.Box3;

87
src/r3-api-canvas.js Normal file
View File

@ -0,0 +1,87 @@
/**
* R3.API.Canvas
* @param id
* @param name
* @param parentEntity
* @param parentTexture
* @param autoUpdateSize
* @param width
* @param height
* @param offset
* @param tabIndex
* @param texts
* @param textBaseline
* @constructor
*/
R3.API.Canvas = function(
id,
name,
parentEntity,
parentTexture,
autoUpdateSize,
width,
height,
offset,
tabIndex,
texts,
textBaseline
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Canvas (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(parentTexture)) {
parentTexture = null;
}
this.parentTexture = parentTexture;
if (R3.Utils.UndefinedOrNull(autoUpdateSize)) {
autoUpdateSize = true;
}
this.autoUpdateSize = autoUpdateSize;
if (R3.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(offset)) {
offset = new R3.API.Vector2(0,0);
}
this.offset = offset;
if (R3.Utils.UndefinedOrNull(tabIndex)) {
tabIndex = 1;
}
this.tabIndex = tabIndex;
if (R3.Utils.UndefinedOrNull(texts)) {
texts = [];
}
this.texts = texts;
if (R3.Utils.UndefinedOrNull(textBaseline)) {
textBaseline = 'middle';
}
this.textBaseline = textBaseline;
R3.API.Component.call(
this,
R3.Component.CANVAS,
parentEntity
);
};
R3.API.Canvas.prototype = Object.create(R3.API.Component.prototype);
R3.API.Canvas.prototype.constructor = R3.API.Canvas;

47
src/r3-api-clock.js Normal file
View File

@ -0,0 +1,47 @@
/**
* Raw Clock API object - should always correspond with the Clock Schema
* @constructor
* @param id
* @param name
* @param parentEntity
*/
R3.API.Clock = function(
id,
name,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Clock (' + this.id + ')';
}
this.name = name;
R3.API.Component.call(
this,
R3.Component.CLOCK,
parentEntity
);
};
R3.API.Clock.prototype = Object.create(R3.API.Component.prototype);
R3.API.Clock.prototype.constructor = R3.API.Clock;
/**
* Creates an API camera from an Object camera
* @param objectClock
* @constructor
*/
R3.API.Clock.FromObject = function(objectClock) {
return new R3.API.Clock(
objectClock.id,
objectClock.name,
objectClock.parentEntity
);
};

51
src/r3-api-color.js Normal file
View File

@ -0,0 +1,51 @@
/**
* API Color
* @param r
* @param g
* @param b
* @param a
* @constructor
*/
R3.API.Color = function (r, g, b, a) {
if (R3.Utils.UndefinedOrNull(r)) {
r = 1;
}
this.r = r;
if (R3.Utils.UndefinedOrNull(g)) {
g = 1;
}
this.g = g;
if (R3.Utils.UndefinedOrNull(b)) {
b = 1;
}
this.b = b;
if (R3.Utils.UndefinedOrNull(a)) {
a = 0;
}
this.a = a;
};
/**
* Returns an API color from an Object color
* @param objectColor
* @constructor
*/
R3.API.Color.FromObject = function(objectColor) {
if (R3.Utils.UndefinedOrNull(objectColor)){
objectColor = {};
}
return new R3.API.Color(
objectColor.r,
objectColor.g,
objectColor.b,
objectColor.a
);
};

115
src/r3-api-controls-0.js Normal file
View File

@ -0,0 +1,115 @@
/**
* Raw Controls API object
* @param id
* @param controlsType
* @param name
* @param canvas
* @param parentEntity
* @property controlsType
* @constructor
*/
R3.API.Controls = function(
id,
name,
controlsType,
canvas,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(controlsType)) {
controlsType = R3.API.Controls.CONTROLS_TYPE_NONE;
}
this.controlsType = controlsType;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Controls';
switch (this.controlsType) {
case R3.API.Controls.CONTROLS_TYPE_TOUCH :
name = 'Controls Editor';
break;
case R3.API.Controls.CONTROLS_TYPE_KEYBOARD :
name = 'Controls Keyboard';
break;
case R3.API.Controls.CONTROLS_TYPE_MOUSE :
name = 'Controls Mouse';
break;
case R3.API.Controls.CONTROLS_TYPE_EDITOR :
name = 'Controls Editor';
break;
case R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON :
name = 'Controls First Person';
break;
case R3.API.Controls.CONTROLS_TYPE_ORBIT :
name = 'Controls Orbit';
break;
}
name += ' (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(canvas)) {
canvas = null;
}
this.canvas = canvas;
R3.API.Component.call(
this,
R3.API.Controls.GetComponentType(this.controlsType),
parentEntity
);
};
R3.API.Controls.prototype = Object.create(R3.API.Component.prototype);
R3.API.Controls.prototype.constructor = R3.API.Controls;
R3.API.Controls.GetComponentType = function(controlsType) {
var componentType = null;
switch (controlsType) {
case R3.API.Controls.CONTROLS_TYPE_NONE :
componentType = R3.Component.CONTROLS;
break;
case R3.API.Controls.CONTROLS_TYPE_TOUCH :
componentType = R3.Component.CONTROLS_TOUCH;
break;
case R3.API.Controls.CONTROLS_TYPE_KEYBOARD :
componentType = R3.Component.CONTROLS_KEYBOARD;
break;
case R3.API.Controls.CONTROLS_TYPE_MOUSE :
componentType = R3.Component.CONTROLS_MOUSE;
break;
case R3.API.Controls.CONTROLS_TYPE_EDITOR :
componentType = R3.Component.CONTROLS_EDITOR;
break;
case R3.API.Controls.CONTROLS_TYPE_ORBIT :
componentType = R3.Component.CONTROLS_ORBIT;
break;
default :
throw new Error('unhandled controls type: ' + controlsType);
break;
}
return componentType;
};
R3.API.Controls.D3 = function() {};
/**
* Controls Type
* @type {number}
*/
R3.API.Controls.CONTROLS_TYPE_NONE = 0x0;
R3.API.Controls.CONTROLS_TYPE_TOUCH = 0x1;
R3.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
R3.API.Controls.CONTROLS_TYPE_MOUSE = 0x3;
R3.API.Controls.CONTROLS_TYPE_EDITOR = 0x4;
R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON = 0x5;
R3.API.Controls.CONTROLS_TYPE_ORBIT = 0x6;

View File

@ -0,0 +1,44 @@
/**
* @param apiControls
* @param raycaster
* @param camera
* @constructor
*/
R3.API.Controls.D3.Editor = function(
apiControls,
raycaster,
camera
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR;
}
if (R3.Utils.UndefinedOrNull(raycaster)) {
raycaster = new R3.D3.API.Raycaster();
}
this.raycaster = raycaster;
if (R3.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.D3.Editor.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.D3.Editor.prototype.constructor = R3.API.Controls.D3.Editor;

View File

@ -0,0 +1,136 @@
/**
* R3.API.Controls.D3.FirstPerson
* @param apiControls
* @param camera
* @param enabled
* @param movementSpeed
* @param lookSpeed
* @param lookVertical
* @param autoForward
* @param activeLook
* @param heightSpeed
* @param heightCoef
* @param heightMin
* @param heightMax
* @param constrainVertical
* @param verticalMin
* @param verticalMax
* @param autoSpeedFactor
* @constructor
*/
R3.API.Controls.D3.FirstPerson = function(
apiControls,
camera,
enabled,
movementSpeed,
lookSpeed,
lookVertical,
autoForward,
activeLook,
heightSpeed,
heightCoef,
heightMin,
heightMax,
constrainVertical,
verticalMin,
verticalMax,
autoSpeedFactor
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON;
}
if (R3.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (R3.Utils.UndefinedOrNull(enabled)) {
enabled = true;
}
this.enabled = enabled;
if (R3.Utils.UndefinedOrNull(movementSpeed)) {
movementSpeed = 1.0;
}
this.movementSpeed = movementSpeed;
if (R3.Utils.UndefinedOrNull(lookSpeed)) {
lookSpeed = 0.005;
}
this.lookSpeed = lookSpeed;
if (R3.Utils.UndefinedOrNull(lookVertical)) {
lookVertical = true;
}
this.lookVertical = lookVertical;
if (R3.Utils.UndefinedOrNull(autoForward)) {
autoForward = false;
}
this.autoForward = autoForward;
if (R3.Utils.UndefinedOrNull(activeLook)) {
activeLook = false;
}
this.activeLook = activeLook;
if (R3.Utils.UndefinedOrNull(heightSpeed)) {
heightSpeed = false;
}
this.heightSpeed = heightSpeed;
if (R3.Utils.UndefinedOrNull(heightCoef)) {
heightCoef = 1.0;
}
this.heightCoef = heightCoef;
if (R3.Utils.UndefinedOrNull(heightMin)) {
heightMin = 0.0;
}
this.heightMin = heightMin;
if (R3.Utils.UndefinedOrNull(heightMax)) {
heightMax = 1.0;
}
this.heightMax = heightMax;
if (R3.Utils.UndefinedOrNull(constrainVertical)) {
constrainVertical = false;
}
this.constrainVertical = constrainVertical;
if (R3.Utils.UndefinedOrNull(verticalMin)) {
verticalMin = 0;
}
this.verticalMin = verticalMin;
if (R3.Utils.UndefinedOrNull(verticalMax)) {
verticalMax = Math.PI;
}
this.verticalMax = verticalMax;
if (R3.Utils.UndefinedOrNull(autoSpeedFactor)) {
autoSpeedFactor = 0;
}
this.autoSpeedFactor = autoSpeedFactor;
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.D3.FirstPerson.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.D3.FirstPerson.prototype.constructor = R3.API.Controls.D3.FirstPerson;

View File

@ -0,0 +1,147 @@
/**
* R3.API.Controls.D3.Orbit
* @param apiControls
* @param camera
* @param target
* @param enabled
* @param minDistance
* @param maxDistance
* @param minZoom
* @param maxZoom
* @param minPolarAngle
* @param maxPolarAngle
* @param enableDamping
* @param dampingFactor
* @param enableZoom
* @param zoomSpeed
* @param enableRotate
* @param rotateSpeed
* @param enablePan
* @param keyPanSpeed
* @param autoRotate
* @param autoRotateSpeed
* @param enableKeys
* @constructor
*/
R3.API.Controls.D3.Orbit = function(
apiControls,
camera,
target,
enabled,
minPolarAngle,
maxPolarAngle,
enableDamping,
dampingFactor,
enableZoom,
zoomSpeed,
enableRotate,
rotateSpeed,
enablePan,
keyPanSpeed,
autoRotate,
autoRotateSpeed,
enableKeys
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_ORBIT
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_ORBIT;
}
if (R3.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (R3.Utils.UndefinedOrNull(target)) {
target = null;
}
this.target = target;
if (R3.Utils.UndefinedOrNull(enabled)) {
enabled = true;
}
this.enabled = enabled;
if (R3.Utils.UndefinedOrNull(minPolarAngle)) {
minPolarAngle = 0;
}
this.minPolarAngle = minPolarAngle;
if (R3.Utils.UndefinedOrNull(maxPolarAngle)) {
maxPolarAngle = Math.PI;
}
this.maxPolarAngle = maxPolarAngle;
if (R3.Utils.UndefinedOrNull(enableDamping)) {
enableDamping = false;
}
this.enableDamping = enableDamping;
if (R3.Utils.UndefinedOrNull(dampingFactor)) {
dampingFactor = 0.25;
}
this.dampingFactor = dampingFactor;
if (R3.Utils.UndefinedOrNull(enableZoom)) {
enableZoom = true;
}
this.enableZoom = enableZoom;
if (R3.Utils.UndefinedOrNull(zoomSpeed)) {
zoomSpeed = 1.0;
}
this.zoomSpeed = zoomSpeed;
if (R3.Utils.UndefinedOrNull(enableRotate)) {
enableRotate = true;
}
this.enableRotate = enableRotate;
if (R3.Utils.UndefinedOrNull(rotateSpeed)) {
rotateSpeed = 1.0;
}
this.rotateSpeed = rotateSpeed;
if (R3.Utils.UndefinedOrNull(enablePan)) {
enablePan = true;
}
this.enablePan = enablePan;
if (R3.Utils.UndefinedOrNull(keyPanSpeed)) {
keyPanSpeed = 7.0;
}
this.keyPanSpeed = keyPanSpeed;
if (R3.Utils.UndefinedOrNull(autoRotate)) {
autoRotate = false;
}
this.autoRotate = autoRotate;
if (R3.Utils.UndefinedOrNull(autoRotateSpeed)) {
autoRotateSpeed = 2.0;
}
this.autoRotateSpeed = autoRotateSpeed;
if (R3.Utils.UndefinedOrNull(enableKeys)) {
enableKeys = false;
}
this.enableKeys = enableKeys;
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.D3.Orbit.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.D3.Orbit.prototype.constructor = R3.API.Controls.D3.Orbit;

View File

@ -0,0 +1,30 @@
/**
* @param apiControls
* @constructor
*/
R3.API.Controls.Keyboard = function(
apiControls
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_KEYBOARD
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_KEYBOARD;
}
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.Keyboard.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.Keyboard.prototype.constructor = R3.API.Controls.Keyboard;

View File

@ -0,0 +1,31 @@
/**
* @param apiControls
* @constructor
*/
R3.API.Controls.Mouse = function(
apiControls
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_MOUSE
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_MOUSE;
}
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.Mouse.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.Mouse.prototype.constructor = R3.API.Controls.Mouse;

View File

@ -0,0 +1,37 @@
/**
* @param apiControls
* @param sensitivity
* @constructor
*/
R3.API.Controls.Touch = function(
apiControls,
sensitivity
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_TOUCH
};
}
if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) {
apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_TOUCH;
}
if (R3.Utils.UndefinedOrNull(sensitivity)) {
sensitivity = 5;
}
this.sensitivity = sensitivity;
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
};
R3.API.Controls.Touch.prototype = Object.create(R3.API.Controls.prototype);
R3.API.Controls.Touch.prototype.constructor = R3.API.Controls.Touch;

89
src/r3-api-curve-a.js Normal file
View File

@ -0,0 +1,89 @@
/**
* R3.API.Curve
* @param id
* @param name
* @param curveType
* @param parentEntity
* @param arcLenghDivisions
* @constructor
*/
R3.API.Curve = function (
id,
name,
curveType,
parentEntity,
arcLenghDivisions
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(curveType)) {
curveType = R3.API.Curve.CURVE_TYPE_NONE;
}
this.curveType = curveType;
if (R3.Utils.UndefinedOrNull(name)) {
switch (this.curveType) {
case R3.API.Curve.CURVE_TYPE_NONE :
name = 'Curve';
break;
case R3.API.Curve.CURVE_TYPE_PATH :
name = 'Curve Path';
break;
default:
console.log('no nice name for curve');
}
name += ' (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(arcLenghDivisions)) {
arcLenghDivisions = 200;
}
this.arcLenghDivisions = arcLenghDivisions;
R3.API.Component.call(
this,
R3.API.Curve.GetComponentType(this.curveType),
parentEntity
);
};
R3.API.Curve.prototype = Object.create(R3.API.Curve.prototype);
R3.API.Curve.prototype.constructor = R3.API.Curve;
R3.API.Curve.GetComponentType = function(curveType) {
var componentType = null;
switch (curveType) {
case R3.API.Curve.CURVE_TYPE_NONE :
componentType = R3.Component.CURVE;
break;
case R3.API.Curve.CURVE_TYPE_PATH :
componentType = R3.Component.CURVE_PATH;
break;
case R3.API.Curve.CURVE_TYPE_PATH_2D :
componentType = R3.Component.CURVE_PATH_D2;
break;
case R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE :
componentType = R3.Component.CURVE_PATH_D2_SHAPE;
break;
default :
throw new Error('unhandled curve type');
}
return componentType;
};
R3.API.Curve.CURVE_TYPE_NONE = 0x0;
R3.API.Curve.CURVE_TYPE_PATH = 0x1;
R3.API.Curve.CURVE_TYPE_PATH_2D = 0x2;
R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3;

View File

@ -0,0 +1,44 @@
/**
* R3.API.Curve.Path
* @constructor
* @param apiCurve
* @param curves
* @param autoClose
*/
R3.API.Curve.Path = function (
apiCurve,
curves,
autoClose
) {
if (R3.Utils.UndefinedOrNull(apiCurve)) {
apiCurve = {
curveType: R3.API.Curve.CURVE_TYPE_PATH
};
}
if (R3.Utils.UndefinedOrNull(apiCurve.curveType)) {
apiCurve.curveType = R3.API.Curve.CURVE_TYPE_PATH;
}
if (R3.Utils.UndefinedOrNull(curves)) {
curves = [];
}
this.curves = curves;
if (R3.Utils.UndefinedOrNull(autoClose)) {
autoClose = false;
}
this.autoClose = autoClose;
R3.API.Curve.call(
this,
apiCurve.id,
apiCurve.name,
apiCurve.curveType,
apiCurve.parentEntity,
apiCurve.arcLenghDivisions
);
};
R3.API.Curve.Path.prototype = Object.create(R3.API.Curve.prototype);
R3.API.Curve.Path.prototype.constructor = R3.API.Curve.Path;

View File

@ -0,0 +1,35 @@
/**
* R3.API.Curve.Path.D2
* @constructor
* @param apiCurvePath
* @param points
*/
R3.API.Curve.Path.D2 = function (
apiCurvePath,
points
) {
if (R3.Utils.UndefinedOrNull(apiCurvePath)) {
apiCurvePath = {
curveType: R3.API.Curve.CURVE_TYPE_PATH_2D
};
}
if (R3.Utils.UndefinedOrNull(apiCurvePath.curveType)) {
apiCurvePath.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D;
}
if (R3.Utils.UndefinedOrNull(points)) {
points = [];
}
this.points = points;
R3.API.Curve.Path.call(
this,
apiCurvePath,
apiCurvePath.curves,
apiCurvePath.autoClose
);
};
R3.API.Curve.Path.D2.prototype = Object.create(R3.API.Curve.Path.prototype);
R3.API.Curve.Path.D2.prototype.constructor = R3.API.Curve.Path.D2;

View File

@ -0,0 +1,27 @@
/**
* R3.API.Curve.Path.D2.Shape
* @constructor
* @param apiCurvePathD2
*/
R3.API.Curve.Path.D2.Shape = function (
apiCurvePathD2
) {
if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) {
apiCurvePathD2 = {
curveType : R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE
};
}
if (R3.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) {
apiCurvePathD2.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ;
}
R3.API.Curve.Path.call(
this,
apiCurvePathD2,
apiCurvePathD2.points
);
};
R3.API.Curve.Path.D2.Shape.prototype = Object.create(R3.API.Curve.Path.D2.prototype);
R3.API.Curve.Path.D2.Shape.prototype.constructor = R3.API.Curve.Path.D2.Shape;

45
src/r3-api-custom-code.js Normal file
View File

@ -0,0 +1,45 @@
/**
* Custom Code Component
* @param id
* @param name
* @param eventId
* @param code
* @param parentEntity
* @constructor
*/
R3.API.CustomCode = function (
id,
name,
eventId,
code,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'CustomCode (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(eventId)) {
eventId = 42;
}
this.eventId = eventId;
if (R3.Utils.UndefinedOrNull(code)) {
code = "return null;\n//@ sourceURL=" + this.name + ".js";
}
this.code = code;
R3.API.Component.call(
this,
R3.Component.CUSTOM_CODE,
parentEntity
);
};
R3.API.CustomCode.prototype = Object.create(R3.API.Component.prototype);
R3.API.CustomCode.prototype.constructor = R3.API.CustomCode;

53
src/r3-api-dom-element.js Normal file
View File

@ -0,0 +1,53 @@
/**
* API DomElement
* @param id
* @param name
* @param domElementId
* @param parentEntity
* @constructor
*/
R3.API.DomElement = function(
id,
name,
domElementId,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'DOM Element (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(domElementId)) {
domElementId = '';
}
this.domElementId = domElementId;
R3.API.Component.call(
this,
R3.Component.DOM_ELEMENT,
parentEntity
);
};
R3.API.DomElement.prototype = Object.create(R3.API.Component.prototype);
R3.API.DomElement.prototype.constructor = R3.API.DomElement;
/**
* Returns an API domElement from an Object domElement
* @param objectDomElement
* @constructor
*/
R3.API.DomElement.FromObject = function (objectDomElement) {
return new R3.API.DomElement(
objectDomElement.id,
objectDomElement.name,
objectDomElement.domElementId,
objectDomElement.parentEntity
)
};

45
src/r3-api-draw-range.js Normal file
View File

@ -0,0 +1,45 @@
/**
* R3.API.Box3
* @constructor
* @param id
* @param name
* @param parentEntity
* @param start
* @param count
*/
R3.API.DrawRange = function (
id,
name,
parentEntity,
start,
count
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'DrawRange (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(start)) {
start = 0;
}
this.start = start;
if (R3.Utils.UndefinedOrNull(count)) {
count = Infinity;
}
this.count = count;
R3.API.Component.call(
this,
R3.Component.DRAW_RANGE,
parentEntity
)
};
R3.API.DrawRange.prototype = Object.create(R3.API.Component.prototype);
R3.API.DrawRange.prototype.constructor = R3.API.DrawRange;

View File

@ -0,0 +1,67 @@
/**
* Entity API Object (for storing / loading entities to and from API)
* @constructor
* @param id
* @param name
* @param entities R3.API.Entity[]
* @param defaultEntity
* @param parentEntity
*/
R3.API.EntityManager = function(
id,
name,
entities,
defaultEntity,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Entity Manager (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(entities)) {
entities = [];
}
this.entities = entities;
if (R3.Utils.UndefinedOrNull(defaultEntity)) {
defaultEntity = null;
}
this.defaultEntity = defaultEntity;
R3.API.Component.call(
this,
R3.Component.ENTITY_MANAGER,
parentEntity
);
};
R3.API.EntityManager.prototype = Object.create(R3.API.Component.prototype);
R3.API.EntityManager.prototype.constructor = R3.API.EntityManager;
/**
* Creates an API entity manager from an Object entity manager
* @param objectEntityManager
* @constructor
*/
R3.API.EntityManager.FromObject = function(objectEntityManager) {
var apiEntities = objectEntityManager.entities.map(
function (objectEntity) {
return R3.API.Entity.FromObject(objectEntity);
}
);
return new R3.API.EntityManager(
objectEntityManager.id,
objectEntityManager.name,
apiEntities,
objectEntityManager.defaultEntity,
objectEntityManager.parentEntity
);
};

52
src/r3-api-entity.js Normal file
View File

@ -0,0 +1,52 @@
/**
* Entity API Object (for storing / loading entities to and from API)
* @param id
* @param name
* @param components R3.Component[]
* @param parentEntity R3.Entity
* @constructor
*/
R3.API.Entity = function(
id,
name,
components,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Entity (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(components)) {
components = [];
}
this.components = components;
R3.API.Component.call(
this,
R3.Component.ENTITY,
parentEntity
);
};
R3.API.Entity.prototype = Object.create(R3.API.Component.prototype);
R3.API.Entity.prototype.constructor = R3.API.Entity;
/**
* Returns an API entity from an Object entity
* @param objectEntity
* @constructor
*/
R3.API.Entity.FromObject = function(objectEntity) {
return new R3.API.Entity(
objectEntity.id,
objectEntity.name,
objectEntity.components,
objectEntity.parentEntity
)
};

View File

@ -0,0 +1,64 @@
/**
* R3.API.GraphicsRuntime
* @param id
* @param name
* @param graphicsType
* @param parentEntity
* @constructor
*/
R3.API.GraphicsRuntime = function(
id,
name,
graphicsType,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Graphics Runtime (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(graphicsType)) {
graphicsType = null;
}
this.graphicsType = graphicsType;
R3.API.Component.call(
this,
R3.API.GraphicsRuntime.GetComponentType(this.graphicsType),
parentEntity
);
};
R3.API.GraphicsRuntime.prototype = Object.create(R3.API.Component.prototype);
R3.API.GraphicsRuntime.prototype.constructor = R3.API.GraphicsRuntime;
R3.API.GraphicsRuntime.GetComponentType = function(graphicsType) {
var componentType = null;
switch (graphicsType) {
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE :
componentType = R3.Component.GRAPHICS;
break;
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS :
componentType = R3.Component.GRAPHICS_THREE;
break;
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS :
componentType = R3.Component.GRAPHICS_IMPACT;
break;
default:
throw new Error('Invalid graphics type');
}
return componentType;
};
R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE = 0x0;
R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS = 0x1;
R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS = 0x2;

View File

@ -0,0 +1,30 @@
/**
* R3.API.GraphicsRuntime.Impact
* @constructor
* @param apiGraphicsRuntime
*/
R3.API.GraphicsRuntime.Impact = function(
apiGraphicsRuntime
) {
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
apiGraphicsRuntime = {
graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS
};
}
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS;
}
R3.API.GraphicsRuntime.call(
this,
apiGraphicsRuntime.id,
apiGraphicsRuntime.name,
apiGraphicsRuntime.graphicsType,
apiGraphicsRuntime.parentEntity
);
};
R3.API.GraphicsRuntime.Impact.prototype = Object.create(R3.API.GraphicsRuntime.prototype);
R3.API.GraphicsRuntime.Impact.prototype.constructor = R3.API.GraphicsRuntime.Impact;

View File

@ -0,0 +1,30 @@
/**
* R3.API.GraphicsRuntime.Three
* @constructor
* @param apiGraphicsRuntime
*/
R3.API.GraphicsRuntime.Three = function(
apiGraphicsRuntime
) {
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
apiGraphicsRuntime = {
graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS
};
}
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS;
}
R3.API.GraphicsRuntime.call(
this,
apiGraphicsRuntime.id,
apiGraphicsRuntime.name,
apiGraphicsRuntime.graphicsType,
apiGraphicsRuntime.parentEntity
);
};
R3.API.GraphicsRuntime.Three.prototype = Object.create(R3.API.GraphicsRuntime.prototype);
R3.API.GraphicsRuntime.Three.prototype.constructor = R3.API.GraphicsRuntime.Three;

52
src/r3-api-group.js Normal file
View File

@ -0,0 +1,52 @@
/**
* R3.API.Group
* @constructor
* @param id
* @param name
* @param parentEntity
* @param start
* @param count
* @param materialIndex
*/
R3.API.Group = function (
id,
name,
parentEntity,
start,
count,
materialIndex
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Group (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(start)) {
start = 0;
}
this.start = start;
if (R3.Utils.UndefinedOrNull(count)) {
count = 0;
}
this.count = count;
if (R3.Utils.UndefinedOrNull(materialIndex)) {
materialIndex = 0;
}
this.materialIndex = materialIndex;
R3.API.Component.call(
this,
R3.Component.GROUP,
parentEntity
)
};
R3.API.Group.prototype = Object.create(R3.API.Component.prototype);
R3.API.Group.prototype.constructor = R3.API.Group;

64
src/r3-api-gui.js Normal file
View File

@ -0,0 +1,64 @@
/**
* Raw GUI API object - should always correspond with the GUI Schema
* @param id
* @param name
* @param domElement
* @param parentEntity
* @constructor
*/
R3.API.GUI = function(
id,
name,
domElement,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'GUI (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(domElement)) {
domElement = null;
}
this.domElement = domElement;
R3.API.Component.call(
this,
R3.Component.GUI,
parentEntity
);
};
R3.API.GUI.prototype = Object.create(R3.API.Component.prototype);
R3.API.GUI.prototype.constructor = R3.API.GUI;
/**
* Creates an API GUI from an Object GUI
* @param objectGUI
* @constructor
*/
R3.API.GUI.FromObject = function(objectGUI) {
var apiDomElement = null;
if (objectGUI.domElement) {
if (objectGUI.domElement instanceof Object) {
apiDomElement = R3.API.DomElement.FromObject(objectGUI.domElement);
} else {
apiDomElement = objectGUI.domElement;
}
}
return new R3.API.GUI(
objectGUI.id,
objectGUI.name,
apiDomElement,
objectGUI.parentEntity
);
};

100
src/r3-api-image.js Normal file
View File

@ -0,0 +1,100 @@
/**
* R3.API.Image
* @param id
* @param name
* @param parentEntity
* @param parentTexture
* @param fileName
* @param extension
* @param path
* @param contentType
* @param size
* @param width
* @param height
* @constructor
*/
R3.API.Image = function(
id,
name,
parentEntity,
parentTexture,
fileName,
extension,
path,
contentType,
size,
width,
height
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Image ' + id;
}
this.name = name;
if (R3.Utils.UndefinedOrNull(parentTexture)) {
parentTexture = null;
}
this.parentTexture = parentTexture;
if (R3.Utils.UndefinedOrNull(fileName)) {
fileName = R3.Utils.LowerUnderscore(name);
}
this.fileName = fileName;
if (R3.Utils.UndefinedOrNull(extension)) {
extension = '.unknown';
}
this.extension = extension;
if (R3.Utils.UndefinedOrNull(path)) {
path = '/';
}
this.path = path;
if (R3.Utils.UndefinedOrNull(contentType)) {
contentType = 'application/octet-stream';
if (this.extension.match(/(png)$/i)) {
contentType = 'image/png';
}
if (this.extension.match(/(jpg|jpeg)$/i)) {
contentType = 'image/jpeg';
}
if (this.extension.match(/(gif)$/i)) {
contentType = 'image/gif';
}
}
this.contentType = contentType;
if (R3.Utils.UndefinedOrNull(size)) {
size = 0;
}
this.size = size;
if (R3.Utils.UndefinedOrNull(width)) {
width = 0;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 0;
}
this.height = height;
R3.API.Component.call(
this,
R3.Component.IMAGE,
parentEntity
);
};
R3.API.Image.prototype = Object.create(R3.API.Component.prototype);
R3.API.Image.prototype.constructor = R3.API.Image;

159
src/r3-api-matrix4.js Normal file
View File

@ -0,0 +1,159 @@
/**
* Api Matrix 4
* @param row0 R3.API.Vector4
* @param row1 R3.API.Vector4
* @param row2 R3.API.Vector4
* @param row3 R3.API.Vector4
* @constructor
*/
R3.API.Matrix4 = function ApiMatrix4(
row0,
row1,
row2,
row3
) {
this.rows = [];
if (R3.Utils.UndefinedOrNull(row0)) {
row0 = new R3.API.Vector4(1, 0, 0, 0);
}
this.rows[0] = row0;
if (R3.Utils.UndefinedOrNull(row1)) {
row1 = new R3.API.Vector4(0, 1, 0, 0);
}
this.rows[1] = row1;
if (R3.Utils.UndefinedOrNull(row2)) {
row2 = new R3.API.Vector4(0, 0, 1, 0);
}
this.rows[2] = row2;
if (R3.Utils.UndefinedOrNull(row3)) {
row3 = new R3.API.Vector4(0, 0, 0, 1);
}
this.rows[3] = row3;
this.temp = [];
this.temp.push(
new R3.API.Vector4()
);
this.temp.push(
new R3.API.Vector4()
);
this.temp.push(
new R3.API.Vector4()
);
this.temp.push(
new R3.API.Vector4()
);
this.forward = new R3.API.Vector4();
this.left = new R3.API.Vector4();
this.up = new R3.API.Vector4();
};
/**
* Returns an API matrix from an Object matrix
* @param objectMatrix
* @constructor
*/
R3.API.Matrix4.FromObject = function(objectMatrix) {
if (objectMatrix.rows) {
return new R3.API.Matrix4(
R3.API.Vector4.FromObject(objectMatrix.rows[0]),
R3.API.Vector4.FromObject(objectMatrix.rows[1]),
R3.API.Vector4.FromObject(objectMatrix.rows[2]),
R3.API.Vector4.FromObject(objectMatrix.rows[3])
);
} else if (objectMatrix instanceof Array) {
return new R3.API.Matrix4(
R3.API.Vector4.FromObject(objectMatrix[0]),
R3.API.Vector4.FromObject(objectMatrix[1]),
R3.API.Vector4.FromObject(objectMatrix[2]),
R3.API.Vector4.FromObject(objectMatrix[3])
);
} else {
console.warn('Unsupported object matrix type - whats your DB version?');
throw new Error('Unsupported object matrix type - whats your DB version?');
}
};
R3.API.Matrix4.prototype.rotationMatrixX = function (radians) {
this.identity();
this.rows[1] = new R3.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
this.rows[2] = new R3.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0);
return this;
};
R3.API.Matrix4.prototype.rotationMatrixY = function (radians) {
this.identity();
this.rows[0] = new R3.API.Vector4(
Math.cos(radians),
0,
Math.sin(radians),
0
);
this.rows[2] = new R3.API.Vector4(
-1 * Math.sin(radians),
0,
Math.cos(radians),
0
);
return this;
};
R3.API.Matrix4.prototype.rotationMatrixZ = function (radians) {
this.identity();
this.rows[0] = new R3.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
this.rows[1] = new R3.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0);
return this;
};
R3.API.Matrix4.prototype.rotateX = function (radians, point) {
this.identity();
this.rotationMatrixX(radians);
return this.multiply(point);
};
R3.API.Matrix4.prototype.rotateY = function (radians, point) {
this.identity();
this.rotationMatrixY(radians);
return this.multiply(point);
};
R3.API.Matrix4.prototype.rotateZ = function (radians, point) {
this.identity();
this.rotationMatrixZ(radians);
return this.multiply(point);
};
R3.API.Matrix4.prototype.multiply = function (mvp) {
if (mvp instanceof R3.API.Quaternion || mvp instanceof R3.API.Vector4) {
return new R3.API.Quaternion(
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w,
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z + this.rows[1].w * mvp.w,
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + this.rows[2].w * mvp.w,
this.rows[3].x * mvp.x + this.rows[3].y * mvp.y + this.rows[3].z * mvp.z + this.rows[3].w * mvp.w
);
} else if (mvp instanceof R3.API.Vector3) {
return new R3.API.Vector3(
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z,
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z,
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z
);
}
};
R3.API.Matrix4.prototype.identity = function () {
this.rows = [
new R3.API.Vector4(1, 0, 0, 0),
new R3.API.Vector4(0, 1, 0, 0),
new R3.API.Vector4(0, 0, 1, 0),
new R3.API.Vector4(0, 0, 0, 1)
];
};

45
src/r3-api-mouse.js Normal file
View File

@ -0,0 +1,45 @@
/**
* API Mouse
* @param id
* @param name
* @param parentEntity
* @param x
* @param y
* @constructor
*/
R3.API.Mouse = function(
id,
name,
parentEntity,
x,
y
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Mouse (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(x)) {
x = 0;
}
this.x = x;
if (R3.Utils.UndefinedOrNull(y)) {
y = 0;
}
this.y = y;
R3.API.Component.call(
this,
R3.Component.MOUSE,
parentEntity
);
};
R3.API.Mouse.prototype = Object.create(R3.API.Component.prototype);
R3.API.Mouse.prototype.constructor = R3.API.Mouse;

34
src/r3-api-number.js Normal file
View File

@ -0,0 +1,34 @@
/**
* R3.API.Number
* @constructor
* @param value
* @param grain
* @param min
* @param max
*/
R3.API.Number = function (
value,
grain,
min,
max
) {
if (R3.Utils.UndefinedOrNull(value)) {
value = 0;
}
this.value = value;
if (R3.Utils.UndefinedOrNull(grain)) {
grain = 0.1;
}
this.grain = grain;
if (R3.Utils.UndefinedOrNull(min)) {
min = 0;
}
this.min = min;
if (R3.Utils.UndefinedOrNull(max)) {
max = 100;
}
this.max = max;
};

53
src/r3-api-plane.js Normal file
View File

@ -0,0 +1,53 @@
R3.API.Plane = function (
id,
name,
normal,
constant,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Plane (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(normal)) {
normal = new R3.API.Vector3(1,0,0);
}
this.normal = normal;
if (R3.Utils.UndefinedOrNull(constant)) {
constant = 0;
}
this.constant = constant;
R3.API.Component.call(
this,
R3.Component.PLANE,
parentEntity
);
};
R3.API.Plane.prototype = Object.create(R3.API.Component.prototype);
R3.API.Plane.prototype.constructor = R3.API.Plane;
/**
* Returns an API vector from an Object vector
* @param objectPlane
* @constructor
*/
R3.API.Plane.FromObject = function (objectPlane) {
return new R3.API.Plane(
objectPlane.id,
objectPlane.name,
R3.API.Vector3.FromObject(objectPlane.normal),
objectPlane.constant,
objectPlane.parentEntity
);
};

237
src/r3-api-quaternion-a.js Normal file
View File

@ -0,0 +1,237 @@
/**
* Quaternion
* @param x
* @param y
* @param z
* @param w
* @param axis
* @param angle
* @constructor
*/
R3.API.Quaternion = function (
x,
y,
z,
w,
axis,
angle
) {
if (R3.Utils.UndefinedOrNull(x)) {
x = 0;
}
this.x = x;
if (R3.Utils.UndefinedOrNull(y)) {
y = 0;
}
this.y = y;
if (R3.Utils.UndefinedOrNull(z)) {
z = 0;
}
this.z = z;
if (R3.Utils.UndefinedOrNull(w)) {
w = 1;
}
this.w = w;
if (R3.Utils.UndefinedOrNull(axis)) {
axis = new R3.API.Vector3();
}
this.axis = axis;
if (R3.Utils.UndefinedOrNull(angle)) {
angle = 0;
}
this.angle = angle;
};
R3.API.Quaternion.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
R3.API.Quaternion.prototype.copy = function () {
return new R3.API.Quaternion(
this.x,
this.y,
this.z,
this.w
);
};
/**
* Note, this normalize function leaves 'w' component untouched
*/
R3.API.Quaternion.prototype.normalize = function () {
var EPSILON = 0.000001;
var v2 = this.x * this.x + this.y * this.y + this.z * this.z;
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1 / Math.sqrt(v2);
this.x *= invLength;
this.y *= invLength;
this.z *= invLength;
};
R3.API.Quaternion.prototype.multiply = function (q) {
var x, y, z, w;
var a = q;
var b = this;
if (q instanceof R3.API.Matrix4) {
x = a.rows[0].x * b.x + a.rows[0].y * b.y + a.rows[0].z * b.z + a.rows[0].w * b.w;
y = a.rows[1].x * b.x + a.rows[1].y * b.y + a.rows[1].z * b.z + a.rows[1].w * b.w;
z = a.rows[2].x * b.x + a.rows[2].y * b.y + a.rows[2].z * b.z + a.rows[2].w * b.w;
w = a.rows[3].x * b.x + a.rows[3].y * b.y + a.rows[3].z * b.z + a.rows[3].w * b.w;
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
} else if (q instanceof R3.API.Quaternion) {
x = ((a.x * b.x) - (a.y * b.y) - (a.z * b.z) - (a.w * a.w));
y = ((a.x * b.y) + (a.y * b.x) - (a.z * b.w) + (a.w * a.z));
z = ((a.x * b.z) + (a.y * b.w) + (a.z * b.x) - (a.w * a.y));
w = ((a.x * b.w) - (a.y * b.z) + (a.z * b.y) + (a.w * a.x));
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
} else {
console.log("This functionality not implemented - please do this");
throw new Error("This functionality not implemented - please do this");
}
};
R3.API.Quaternion.prototype.setFromAngle = function (angle) {
this.instance.setFromAxisAngle(this.axis.instance, angle);
this.x = this.instance.x;
this.y = this.instance.y;
this.z = this.instance.z;
this.w = this.instance.w;
return this;
};
R3.API.Quaternion.prototype.subtract = function (v) {
if (v instanceof R3.API.Vector3) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
}
if (v instanceof R3.API.Quaternion) {
this.x -= v.x;
this.y -= v.y;
this.z -= v.z;
this.w -= v.w;
}
return this;
};
R3.API.Quaternion.prototype.magnitude = function () {
return Math.sqrt(
(this.x * this.x) +
(this.y * this.y) +
(this.z * this.z) +
(this.w * this.w)
);
};
R3.API.Quaternion.prototype.normalize = function () {
var magnitude = this.magnitude();
if (magnitude < 0.000001) {
return this; //do nothing for zero vector
}
this.x *= magnitude;
this.y *= magnitude;
this.z *= magnitude;
this.w *= magnitude;
return this;
};
/**
*
* @param matrix4 R3.Matrix4
*/
R3.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) {
this.instance.setFromRotationMatrix(matrix4.instance);
this.x = this.instance.x;
this.y = this.instance.y;
this.z = this.instance.z;
this.w = this.instance.w;
};
/**
*
* @param quaternion R3.Quaternion
* @param t
* @returns {R3.Quaternion}
*/
R3.API.Quaternion.prototype.slerp = function (quaternion, t) {
this.updateInstance();
this.instance.slerp(quaternion.instance, t);
this.x = this.instance.x;
this.y = this.instance.y;
this.z = this.instance.z;
this.w = this.instance.w;
return this;
};
/**
* Returns an API quaternion from an Object quaternion
* @param objectQuaternion
* @constructor
*/
R3.API.Quaternion.FromObject = function (objectQuaternion) {
var apiAxis = null;
if (objectQuaternion.axis) {
apiAxis = R3.API.Vector3.FromObject(objectQuaternion.axis);
}
return new R3.API.Quaternion(
objectQuaternion.x,
objectQuaternion.y,
objectQuaternion.z,
objectQuaternion.w,
apiAxis,
objectQuaternion.angle
)
};

View File

@ -0,0 +1,224 @@
R3.API.Quaternion.Points = function () {
this.vectors = [];
};
R3.API.Quaternion.Points.prototype.add = function (vector) {
if (vector instanceof R3.API.Vector3) {
vector = new R3.API.Quaternion(
vector.x,
vector.y,
vector.z,
1
)
}
if (!vector instanceof R3.API.Quaternion) {
console.warn("Vector needs to be of type Quaternion");
throw new Error("Vector needs to be of type Quaternion");
}
this.vectors.push(vector);
return this;
};
R3.API.Quaternion.Points.prototype.copy = function () {
var vectors = [];
for (var i = 0; i < this.vectors.length; i++) {
vectors.push(this.vectors[i].copy());
}
return vectors;
};
R3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixY = new R3.API.Matrix4().rotationMatrixY(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxXDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixY.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.x > maxXDistance) {
maxXDistance = distances.x;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
var maxRotationMatrix = new R3.API.Matrix4().rotationMatrixY(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
R3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) {
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
var multiplier = 0;
var rotationMatrixX = new R3.API.Matrix4().rotationMatrixX(grain);
var totalRadians = 0;
var backupVectors = this.copy();
var maxYDistance = 0;
for (var i = 0; i < Math.PI * 2; i += grain) {
multiplier++;
for (var j = 0; j < this.vectors.length; j++) {
this.vectors[j] = rotationMatrixX.multiply(this.vectors[j]);
}
var distances = this.distances();
if (distances.y > maxYDistance) {
maxYDistance = distances.y;
totalRadians = multiplier * grain;
}
}
this.vectors = backupVectors;
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
var maxRotationMatrix = new R3.API.Matrix4().rotationMatrixX(totalRadians);
for (var k = 0; k < this.vectors.length; k++) {
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
}
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
};
R3.API.Quaternion.Points.prototype.lookAt = function (at, up) {
var polyCenter = this.average();
console.log("poly center : " + JSON.stringify(polyCenter));
var lookAtMatrix = new R3.API.Matrix4().lookAt(polyCenter, at, up);
lookAtMatrix.rows[0] = new R3.API.Quaternion(1, 0, 0, 0);
lookAtMatrix.rows[1] = new R3.API.Quaternion(0, 0, 1, 0);
lookAtMatrix.rows[2] = new R3.API.Quaternion(0, 1, 0, 0);
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
for (var i = 0; i < this.vectors.length; i++) {
console.log("vector " + i + " (before): " + JSON.stringify(this.vectors[i]));
this.vectors[i] = lookAtMatrix.multiply(this.vectors[i]);
console.log("vector " + i + " (after) : " + JSON.stringify(this.vectors[i]));
}
};
R3.API.Quaternion.Points.prototype.distances = function () {
var minX = this.vectors[0].x;
var minY = this.vectors[0].y;
var minZ = this.vectors[0].z;
var maxX = this.vectors[0].x;
var maxY = this.vectors[0].y;
var maxZ = this.vectors[0].z;
for (var i = 0; i < this.vectors.length; i++) {
if (this.vectors[i].x < minX) {
minX = this.vectors[i].x;
}
if (this.vectors[i].y < minY) {
minY = this.vectors[i].y;
}
if (this.vectors[i].z < minZ) {
minZ = this.vectors[i].z;
}
if (this.vectors[i].x > maxX) {
maxX = this.vectors[i].x;
}
if (this.vectors[i].y > maxY) {
maxY = this.vectors[i].y;
}
if (this.vectors[i].z > maxZ) {
maxZ = this.vectors[i].z;
}
}
return new R3.API.Vector3(
Math.abs(maxX - minX),
Math.abs(maxY - minY),
Math.abs(maxY - minZ)
)
};
R3.API.Quaternion.Points.prototype.average = function () {
var averageX = 0;
var averageY = 0;
var averageZ = 0;
for (var i = 0; i < this.vectors.length; i++) {
averageX += this.vectors[i].x;
averageY += this.vectors[i].y;
averageZ += this.vectors[i].z;
}
return new R3.API.Vector3(
averageX / this.vectors.length,
averageY / this.vectors.length,
averageZ / this.vectors.length
);
};
R3.API.Quaternion.Points.prototype.negate = function () {
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].x *= -1;
this.vectors[i].y *= -1;
this.vectors[i].z *= -1;
}
return this;
};
R3.API.Quaternion.Points.prototype.toOrigin = function () {
var distanceFromOrigin = this.average().negate();
for (var i = 0; i < this.vectors.length; i++) {
this.vectors[i].translate(distanceFromOrigin);
}
};

View File

@ -0,0 +1,117 @@
/**
* R3.API.RenderConfiguration
* @param id
* @param name
* @param parentEntity
* @param logicalSize
* @param aspectRatio
* @param scaleMode
* @param activeCamera
* @param activeScenes
* @param activeComposer
* @param activeEffect
* @param activeRenderer
* @param enableComposer
* @param enableEffect
* @constructor
*/
R3.API.RenderConfiguration = function (
id,
name,
parentEntity,
logicalSize,
aspectRatio,
scaleMode,
activeCamera,
activeScenes,
activeRenderer,
activeComposer,
activeEffect,
enableComposer,
enableEffect
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = "RenderConfiguration (" + this.id + ")";
}
this.name = name;
if (R3.Utils.UndefinedOrNull(logicalSize)) {
logicalSize = new R3.API.Vector2(
480,
320
);
}
this.logicalSize = logicalSize;
if (R3.Utils.UndefinedOrNull(aspectRatio)) {
aspectRatio = R3.API.Renderer.ASPECT_RATIO_3_2;
}
this.aspectRatio = aspectRatio;
if (R3.Utils.UndefinedOrNull(scaleMode)) {
scaleMode = R3.API.Renderer.SCALE_MODE_LETTERBOX;
}
this.scaleMode = scaleMode;
if (R3.Utils.UndefinedOrNull(activeCamera)) {
activeCamera = null;
}
this.activeCamera = activeCamera;
if (R3.Utils.UndefinedOrNull(activeScenes)) {
activeScenes = [];
}
this.activeScenes = activeScenes;
if (R3.Utils.UndefinedOrNull(activeRenderer)) {
activeRenderer = null;
}
this.activeRenderer = activeRenderer;
if (R3.Utils.UndefinedOrNull(activeComposer)) {
activeComposer = null;
}
this.activeComposer = activeComposer;
if (R3.Utils.UndefinedOrNull(activeEffect)) {
activeEffect = null;
}
this.activeEffect = activeEffect;
if (R3.Utils.UndefinedOrNull(enableComposer)) {
enableComposer = false;
}
this.enableComposer = enableComposer;
if (R3.Utils.UndefinedOrNull(enableEffect)) {
enableEffect = false;
}
this.enableEffect = enableEffect;
R3.API.Component.call(
this,
R3.Component.RENDER_CONFIGURATION,
parentEntity
);
};
R3.API.RenderConfiguration.prototype = Object.create(R3.API.Component.prototype);
R3.API.RenderConfiguration.prototype.constructor = R3.API.RenderConfiguration;
R3.API.RenderConfiguration.ASPECT_RATIO_NONE = 0x1;
R3.API.RenderConfiguration.ASPECT_RATIO_4_3 = 0x2;
R3.API.RenderConfiguration.ASPECT_RATIO_3_2 = 0x3;
R3.API.RenderConfiguration.ASPECT_RATIO_16_10 = 0x4;
R3.API.RenderConfiguration.ASPECT_RATIO_17_10 = 0x5;
R3.API.RenderConfiguration.ASPECT_RATIO_16_9 = 0x6;
R3.API.RenderConfiguration.SCALE_MODE_NONE = 0x1;
R3.API.RenderConfiguration.SCALE_MODE_LETTERBOX = 0x2;
R3.API.RenderConfiguration.SCALE_MODE_ZOOM_TO_BIGGER = 0x3;
R3.API.RenderConfiguration.SCALE_MODE_NON_UNIFORM = 0x4;

122
src/r3-api-renderer-a.js Normal file
View File

@ -0,0 +1,122 @@
/**
* R3.API.Renderer
* @param id
* @param name
* @param rendererType
* @param parentEntity
* @param width
* @param height
* @param offset
* @param canvas
* @constructor
*/
R3.API.Renderer = function (
id,
name,
rendererType,
parentEntity,
width,
height,
offset,
canvas
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(rendererType)) {
rendererType = R3.API.Renderer.RENDERER_TYPE_NONE;
}
this.rendererType = rendererType;
if (R3.Utils.UndefinedOrNull(name)) {
switch (this.rendererType) {
case R3.API.Renderer.RENDERER_TYPE_NONE :
name = "Renderer";
break;
case R3.API.Renderer.RENDERER_TYPE_2D :
name = "Renderer 2D";
break;
case R3.API.Renderer.RENDERER_TYPE_3D :
name = "Renderer 3D";
break;
default :
console.warn('no nice name for renderer');
break;
}
name += " (" + this.id + ")";
}
this.name = name;
if (R3.Utils.UndefinedOrNull(width)) {
width = 1;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 1;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(offset)) {
offset = new R3.API.Vector2(0,0);
}
this.offset = offset;
if (R3.Utils.UndefinedOrNull(canvas)) {
canvas = new R3.API.Canvas();
}
this.canvas = canvas;
R3.API.Component.call(
this,
R3.API.Renderer.GetComponentType(this.rendererType),
parentEntity
);
};
R3.API.Renderer.prototype = Object.create(R3.API.Component.prototype);
R3.API.Renderer.prototype.constructor = R3.API.Renderer;
R3.API.Renderer.GetComponentType = function(rendererType) {
var componentType = null;
switch (rendererType) {
case R3.API.Renderer.RENDERER_TYPE_NONE :
componentType = R3.Component.RENDERER;
break;
case R3.API.Renderer.RENDERER_TYPE_2D :
componentType = R3.Component.RENDERER_D2;
break;
case R3.API.Renderer.RENDERER_TYPE_3D :
componentType = R3.Component.RENDERER_D3;
break;
default :
console.warn('could not determine component type');
break;
}
return componentType;
};
R3.API.Renderer.RENDERER_TYPE_NONE = 0x0;
R3.API.Renderer.RENDERER_TYPE_2D = 0x1;
R3.API.Renderer.RENDERER_TYPE_3D = 0x2;
R3.API.Renderer.MODE_CANVAS = 0x1;
R3.API.Renderer.MODE_TARGET = 0x2;
R3.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3;
R3.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0;
R3.API.Renderer.SHADOW_MAP_TYPE_PCF = 1;
R3.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT = 2;
R3.API.Renderer.TONE_MAPPING_LINEAR = 1;
R3.API.Renderer.TONE_MAPPING_REINHARD = 2;
R3.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3;
R3.API.Renderer.TONE_MAPPING_CINEON = 4;

35
src/r3-api-renderer-d2.js Normal file
View File

@ -0,0 +1,35 @@
/**
* R3.API.Renderer.D2
* @constructor
* @param apiRenderer
*/
R3.API.Renderer.D2 = function (
apiRenderer
) {
if (R3.Utils.UndefinedOrNull(apiRenderer)) {
apiRenderer = {
rendererType : R3.API.Renderer.RENDERER_TYPE_2D
};
}
if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) {
apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_2D;
}
R3.API.Renderer.call(
this,
apiRenderer.id,
apiRenderer.name,
apiRenderer.rendererType,
apiRenderer.parentEntity,
apiRenderer.width,
apiRenderer.height,
apiRenderer.offset,
apiRenderer.canvas
);
};
R3.API.Renderer.D2.prototype = Object.create(R3.API.Renderer.prototype);
R3.API.Renderer.D2.prototype.constructor = R3.API.Renderer.D2;

266
src/r3-api-renderer-d3.js Normal file
View File

@ -0,0 +1,266 @@
/**
* R3.API.Renderer.D3
* @param apiRenderer
* @param renderMode
* @param autoClear
* @param autoClearColor
* @param autoClearDepth
* @param autoClearStencil
* @param gammaFactor
* @param gammaInput
* @param gammaOutput
* @param maxMorphTargets
* @param maxMorphNormals
* @param physicallyCorrectLights
* @param shadowMapEnabled
* @param shadowMapAutoUpdate
* @param shadowMapNeedsUpdate
* @param shadowMapType
* @param shadowMapRenderReverseSided
* @param shadowMapRenderSingleSided
* @param sortObjects
* @param toneMapping
* @param toneMappingExposure
* @param toneMappingWhitePoint
* @param premultipliedAlpha
* @param antialias
* @param stencil
* @param preserveDrawingBuffer
* @param depth
* @param logarithmicDepthBuffer
* @param localClippingEnabled
* @param renderTarget
* @param clippingPlanes
* @param clearColor
* @param viewports
* @constructor
*/
R3.API.Renderer.D3 = function (
apiRenderer,
renderMode,
autoClear,
autoClearColor,
autoClearDepth,
autoClearStencil,
gammaFactor,
gammaInput,
gammaOutput,
maxMorphTargets,
maxMorphNormals,
physicallyCorrectLights,
shadowMapEnabled,
shadowMapAutoUpdate,
shadowMapNeedsUpdate,
shadowMapType,
shadowMapRenderReverseSided,
shadowMapRenderSingleSided,
sortObjects,
toneMapping,
toneMappingExposure,
toneMappingWhitePoint,
premultipliedAlpha,
antialias,
stencil,
preserveDrawingBuffer,
depth,
logarithmicDepthBuffer,
localClippingEnabled,
renderTarget,
clippingPlanes,
clearColor,
viewports
) {
if (R3.Utils.UndefinedOrNull(apiRenderer)) {
apiRenderer = {
rendererType : R3.API.Renderer.RENDERER_TYPE_3D
};
}
if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) {
apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D;
}
if (R3.Utils.UndefinedOrNull(renderMode)) {
renderMode = R3.API.Renderer.MODE_CANVAS;
}
this.renderMode = renderMode;
if (R3.Utils.UndefinedOrNull(autoClear)) {
autoClear = true;
}
this.autoClear = autoClear;
if (R3.Utils.UndefinedOrNull(autoClearColor)) {
autoClearColor = true;
}
this.autoClearColor = autoClearColor;
if (R3.Utils.UndefinedOrNull(autoClearDepth)) {
autoClearDepth = true;
}
this.autoClearDepth = autoClearDepth;
if (R3.Utils.UndefinedOrNull(autoClearStencil)) {
autoClearStencil = true;
}
this.autoClearStencil = autoClearStencil;
if (R3.Utils.UndefinedOrNull(gammaFactor)) {
gammaFactor = 2;
}
this.gammaFactor = gammaFactor;
if (R3.Utils.UndefinedOrNull(gammaInput)) {
gammaInput = false;
}
this.gammaInput = gammaInput;
if (R3.Utils.UndefinedOrNull(gammaOutput)) {
gammaOutput = false;
}
this.gammaOutput = gammaOutput;
if (R3.Utils.UndefinedOrNull(maxMorphTargets)) {
maxMorphTargets = 8;
}
this.maxMorphTargets = maxMorphTargets;
if (R3.Utils.UndefinedOrNull(maxMorphNormals)) {
maxMorphNormals = 4;
}
this.maxMorphNormals = maxMorphNormals;
if (R3.Utils.UndefinedOrNull(physicallyCorrectLights)) {
physicallyCorrectLights = false;
}
this.physicallyCorrectLights = physicallyCorrectLights;
if (R3.Utils.UndefinedOrNull(shadowMapEnabled)) {
shadowMapEnabled = false;
}
this.shadowMapEnabled = shadowMapEnabled;
if (R3.Utils.UndefinedOrNull(shadowMapAutoUpdate)) {
shadowMapAutoUpdate = true;
}
this.shadowMapAutoUpdate = shadowMapAutoUpdate;
if (R3.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) {
shadowMapNeedsUpdate = false;
}
this.shadowMapNeedsUpdate = shadowMapNeedsUpdate;
if (R3.Utils.UndefinedOrNull(shadowMapType)) {
shadowMapType = R3.API.Renderer.SHADOW_MAP_TYPE_BASIC;
}
this.shadowMapType = shadowMapType;
if (R3.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) {
shadowMapRenderReverseSided = true;
}
this.shadowMapRenderReverseSided = shadowMapRenderReverseSided;
if (R3.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) {
shadowMapRenderSingleSided = true;
}
this.shadowMapRenderSingleSided = shadowMapRenderSingleSided;
if (R3.Utils.UndefinedOrNull(sortObjects)) {
sortObjects = true;
}
this.sortObjects = sortObjects;
if (R3.Utils.UndefinedOrNull(toneMapping)) {
toneMapping = R3.API.Renderer.TONE_MAPPING_LINEAR;
}
this.toneMapping = toneMapping;
if (R3.Utils.UndefinedOrNull(toneMappingExposure)) {
toneMappingExposure = 1;
}
this.toneMappingExposure = toneMappingExposure;
if (R3.Utils.UndefinedOrNull(toneMappingWhitePoint)) {
toneMappingWhitePoint = 1;
}
this.toneMappingWhitePoint = toneMappingWhitePoint;
if (R3.Utils.UndefinedOrNull(premultipliedAlpha)) {
premultipliedAlpha = true;
}
this.premultipliedAlpha = premultipliedAlpha;
if (R3.Utils.UndefinedOrNull(antialias)) {
antialias = false;
}
this.antialias = antialias;
if (R3.Utils.UndefinedOrNull(stencil)) {
stencil = true;
}
this.stencil = stencil;
if (R3.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
preserveDrawingBuffer = false;
}
this.preserveDrawingBuffer = preserveDrawingBuffer;
if (R3.Utils.UndefinedOrNull(depth)) {
depth = true;
}
this.depth = depth;
if (R3.Utils.UndefinedOrNull(logarithmicDepthBuffer)) {
logarithmicDepthBuffer = false;
}
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
if (R3.Utils.UndefinedOrNull(localClippingEnabled)) {
localClippingEnabled = false;
}
this.localClippingEnabled = localClippingEnabled;
if (R3.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
}
this.renderTarget = renderTarget;
if (R3.Utils.UndefinedOrNull(clippingPlanes)) {
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
if (R3.Utils.UndefinedOrNull(clearColor)) {
clearColor = new R3.API.Color(0.11, 0.11, 0.11);
}
this.clearColor = clearColor;
if (R3.Utils.UndefinedOrNull(viewports)) {
viewports = [new R3.D3.API.Viewport(
null,
null,
1,
1,
0,
0
)];
}
this.viewports = viewports;
R3.API.Renderer.call(
this,
apiRenderer.id,
apiRenderer.name,
apiRenderer.rendererType,
apiRenderer.parentEntity,
apiRenderer.width,
apiRenderer.height,
apiRenderer.offset,
apiRenderer.canvas
);
};
R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype);
R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3;

79
src/r3-api-server.js Normal file
View File

@ -0,0 +1,79 @@
/**
* Raw Server API object - should always correspond with the Server Schema
* @param id
* @param name
* @param protocol
* @param ip
* @param port
* @param protocols
* @param parentEntity
* @constructor
*/
R3.API.Server = function(
id,
name,
protocol,
ip,
port,
protocols,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Server (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(protocol)) {
protocol = 'http';
}
this.protocol = protocol;
if (R3.Utils.UndefinedOrNull(ip)) {
ip = '127.0.0.1';
}
this.ip = ip;
if (R3.Utils.UndefinedOrNull(port)) {
port = 80;
}
this.port = port;
if (R3.Utils.UndefinedOrNull(protocols)) {
protocols = [];
}
this.protocols = protocols;
R3.API.Component.call(
this,
R3.Component.SERVER,
parentEntity
);
};
R3.API.Server.prototype = Object.create(R3.API.Component.prototype);
R3.API.Server.prototype.constructor = R3.API.Server;
/**
* Creates an API Server from an Object Server
* @param objectServer
* @constructor
*/
R3.API.Server.FromObject = function(objectServer) {
return new R3.API.Server(
objectServer.id,
objectServer.name,
objectServer.protocol,
objectServer.ip,
objectServer.port,
objectServer.protocols,
objectServer.parentEntity
);
};

93
src/r3-api-socket-0.js Normal file
View File

@ -0,0 +1,93 @@
/**
* Raw Socket API object - should always correspond with the Socket Schema
* @param id
* @param name
* @param socketType
* @param roomId
* @param peerId
* @param server R3.Server
* @param parentEntity
* @constructor
*/
R3.API.Socket = function(
id,
name,
socketType,
roomId,
peerId,
server,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Socket (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(socketType)) {
socketType = R3.API.Socket.TYPE_NONE;
}
this.socketType = socketType;
if (R3.Utils.UndefinedOrNull(roomId)) {
roomId = 'room_' + R3.Utils.RandomId();
}
this.roomId = roomId;
if (R3.Utils.UndefinedOrNull(peerId)) {
peerId = null;
}
this.peerId = peerId;
if (R3.Utils.UndefinedOrNull(server)) {
server = null;
}
this.server = server;
var componentType = R3.Component.SOCKET;
if (this.socketType === R3.API.Socket.TYPE_CAST) {
componentType = R3.Component.SOCKET_CAST;
}
if (this.socketType === R3.API.Socket.TYPE_RECEIVE) {
componentType = R3.Component.SOCKET_RECEIVE;
}
R3.API.Component.call(
this,
componentType,
parentEntity
);
};
R3.API.Socket.prototype = Object.create(R3.API.Component.prototype);
R3.API.Socket.prototype.constructor = R3.API.Socket;
R3.API.Socket.TYPE_NONE = 0x1;
R3.API.Socket.TYPE_CAST = 0x2;
R3.API.Socket.TYPE_RECEIVE = 0x3;
/**
* Creates an API Socket from an Object Socket
* @param objectSocket
* @constructor
*/
R3.API.Socket.FromObject = function(objectSocket) {
return new R3.API.Socket(
objectSocket.id,
objectSocket.name,
objectSocket.socketType,
objectSocket.roomId,
objectSocket.peerId,
objectSocket.server,
objectSocket.parentEntity
);
};

78
src/r3-api-socket-cast.js Normal file
View File

@ -0,0 +1,78 @@
/**
* Raw Cast API object - should always correspond with the Cast Schema
* @param apiSocket
* @param castType
* @param source
* @param sourceProperties
* @constructor
*/
R3.API.Socket.Cast = function(
apiSocket,
castType,
source,
sourceProperties
) {
if (R3.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {
socketType : R3.API.Socket.SOCKET_CAST
};
}
R3.API.Socket.call(
this,
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (R3.Utils.UndefinedOrNull(castType)) {
castType = R3.API.Socket.Cast.CAST_TYPE_ROOM;
}
this.castType = castType;
if (R3.Utils.UndefinedOrNull(source)) {
source = null;
}
this.source = source;
if (R3.Utils.UndefinedOrNull(sourceProperties)) {
sourceProperties = null;
}
this.sourceProperties = sourceProperties;
R3.API.Component.call(
this,
R3.Component.SOCKET_CAST
);
};
R3.API.Socket.Cast.prototype = Object.create(R3.API.Socket.prototype);
R3.API.Socket.Cast.prototype.constructor = R3.API.Socket.Cast.Receive;
R3.API.Socket.Cast.CAST_TYPE_ROOM = 0x1;
R3.API.Socket.Cast.CAST_TYPE_PEER = 0x2;
R3.API.Socket.Cast.CAST_TYPE_ALL = 0x3;
R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;
/**
* Creates an API.Socket.Cast from an Object Cast
* @param objectSocketCast
* @constructor
*/
R3.API.Socket.Cast.FromObject = function(objectSocketCast) {
var apiSocket = R3.API.Socket.FromObject(objectSocketCast);
return new R3.API.Socket.Cast(
apiSocket,
objectSocketCast.castType,
objectSocketCast.source,
objectSocketCast.sourceProperties
);
};

View File

@ -0,0 +1,77 @@
/**
* Raw Socket.Receive API object - should always correspond with the Socket.Receive Schema
* @param apiSocket
* @param receiveType
* @param destination
* @param destinationProperties
* @constructor
*/
R3.API.Socket.Receive = function(
apiSocket,
receiveType,
destination,
destinationProperties
) {
if (R3.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {
socketType : R3.API.Socket.SOCKET_RECEIVE
};
}
R3.API.Socket.call(
this,
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (R3.Utils.UndefinedOrNull(receiveType)) {
receiveType = R3.API.Socket.Receive.RECEIVE_TYPE_ROOM;
}
this.receiveType = receiveType;
if (R3.Utils.UndefinedOrNull(destination)) {
destination = null;
}
this.destination = destination;
if (R3.Utils.UndefinedOrNull(destinationProperties)) {
destinationProperties = null;
}
this.destinationProperties = destinationProperties;
R3.API.Component.call(
this,
R3.Component.SOCKET_RECEIVE
);
};
R3.API.Socket.Receive.prototype = Object.create(R3.API.Socket.prototype);
R3.API.Socket.Receive.prototype.constructor = R3.API.Socket.Receive;
R3.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1;
R3.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2;
/**
* Creates an API Socket.Receive from an Object Socket.Receive
* @param socket R3.SocketsRuntime
* @param objectSocketReceive
* @constructor
*/
R3.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) {
var apiSocket = R3.API.Socket.FromObject(objectSocketReceive);
return new R3.API.Socket.Receive(
apiSocket,
objectSocketReceive.receiveType,
objectSocketReceive.destination,
objectSocketReceive.destinationProperties
);
};

20
src/r3-api-sphere.js Normal file
View File

@ -0,0 +1,20 @@
/**
* R3.API.Sphere
* @constructor
* @param center
* @param radius
*/
R3.API.Sphere = function (
center,
radius
) {
if (R3.Utils.UndefinedOrNull(center)) {
center = new R3.API.Vector3(0,0,0);
}
this.center = center;
if (R3.Utils.UndefinedOrNull(radius)) {
radius = 1;
}
this.radius = radius;
};

64
src/r3-api-stats.js Normal file
View File

@ -0,0 +1,64 @@
/**
* Raw Stats API object - should always correspond with the Stats Schema
* @param id
* @param name
* @param domElement
* @param parentEntity
* @constructor
*/
R3.API.Stats = function(
id,
name,
domElement,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Stats (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(domElement)) {
domElement = null;
}
this.domElement = domElement;
R3.API.Component.call(
this,
R3.Component.STATS,
parentEntity
);
};
R3.API.Stats.prototype = Object.create(R3.API.Component.prototype);
R3.API.Stats.prototype.constructor = R3.API.Stats;
/**
* Creates an API Stats from an Object Stats
* @param objectStats
* @constructor
*/
R3.API.Stats.FromObject = function(objectStats) {
var apiDomElement = null;
if (objectStats.domElement) {
if (objectStats.domElement instanceof Object) {
apiDomElement = R3.API.DomElement.FromObject(objectStats.domElement);
} else {
apiDomElement = objectStats.domElement;
}
}
return new R3.API.Stats(
objectStats.id,
objectStats.name,
apiDomElement,
objectStats.parentEntity
);
};

104
src/r3-api-system.js Normal file
View File

@ -0,0 +1,104 @@
/**
* This component renders a scene
* @param id String
* @param name String
* @param systemType
* @param parentEntity
* @constructor
*/
R3.API.System = function (
id,
name,
systemType,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = "System (" + this.id + ")";
}
this.name = name;
if (R3.Utils.UndefinedOrNull(systemType)) {
systemType = R3.System.SYSTEM_TYPE_NONE;
}
this.systemType = systemType;
var componentType = R3.Component.SYSTEM;
if (this.systemType === R3.System.SYSTEM_TYPE_NONE) {
componentType = R3.Component.SYSTEM;
}
if (this.systemType === R3.System.SYSTEM_TYPE_ANIMATION) {
componentType = R3.Component.SYSTEM_ANIMATION;
}
if (this.systemType === R3.System.SYSTEM_TYPE_CUSTOM) {
componentType = R3.Component.SYSTEM_CUSTOM_CODE;
}
if (this.systemType === R3.System.SYSTEM_TYPE_GUI) {
componentType = R3.Component.SYSTEM_GUI;
}
if (this.systemType === R3.System.SYSTEM_TYPE_INPUT) {
componentType = R3.Component.SYSTEM_INPUT;
}
if (this.systemType === R3.System.SYSTEM_TYPE_LINKING) {
componentType = R3.Component.SYSTEM_LINKING;
}
if (this.systemType === R3.System.SYSTEM_TYPE_PHYSICS) {
componentType = R3.Component.SYSTEM_PHYSICS;
}
if (this.systemType === R3.System.SYSTEM_TYPE_RENDER) {
componentType = R3.Component.SYSTEM_RENDER;
}
if (this.systemType === R3.System.SYSTEM_TYPE_STORAGE) {
componentType = R3.Component.SYSTEM_STORAGE;
}
if (this.systemType === R3.System.SYSTEM_TYPE_VISUALIZATION) {
componentType = R3.Component.SYSTEM_VISUALIZATION;
}
if (this.systemType === R3.System.SYSTEM_TYPE_PARTICLE) {
componentType = R3.Component.SYSTEM_PARTICLE;
}
if (this.systemType === R3.System.SYSTEM_TYPE_AUDIO) {
componentType = R3.Component.SYSTEM_AUDIO;
}
R3.API.Component.call(
this,
componentType,
parentEntity
);
};
R3.API.System.prototype = Object.create(R3.API.Component.prototype);
R3.API.System.prototype.constructor = R3.API.System;
/**
* Object to R3.D3.API.System
* @param objectComponent
* @constructor
*/
R3.API.System.FromObject = function(objectComponent) {
return new R3.API.System(
objectComponent.id,
objectComponent.name,
objectComponent.systemType,
objectComponent.parentEntity
);
};

42
src/r3-api-vector2.js Normal file
View File

@ -0,0 +1,42 @@
R3.API.Vector2 = function (x, y) {
if (R3.Utils.UndefinedOrNull(x)) {
x = 0;
}
this.x = x;
if (R3.Utils.UndefinedOrNull(y)) {
y = 0;
}
this.y = y;
};
R3.API.Vector2.prototype.copy = function () {
return new R3.API.Vector2(
this.x,
this.y
);
};
R3.API.Vector2.prototype.equals = function (v) {
return this.x === v.x && this.y === v.y;
};
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
R3.API.Vector2.FromObject = function (objectVector) {
if (R3.Utils.UndefinedOrNull(objectVector)) {
console.warn('vector from db undefined - stale version in db');
objectVector = {};
}
return new R3.API.Vector2(
objectVector.x,
objectVector.y
)
};

277
src/r3-api-vector3.js Normal file
View File

@ -0,0 +1,277 @@
R3.API.Vector3 = function (x, y, z) {
if (R3.Utils.UndefinedOrNull(x)) {
x = 0;
}
this.x = x;
if (R3.Utils.UndefinedOrNull(y)) {
y = 0;
}
this.y = y;
if (R3.Utils.UndefinedOrNull(z)) {
z = 0;
}
this.z = z;
};
R3.API.Vector3.prototype.negate = function() {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
};
R3.API.Vector3.prototype.subtract = function (v) {
return new R3.API.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
R3.API.Vector3.prototype.sub = function (v) {
return new R3.API.Vector3(
this.x - v.x,
this.y - v.y,
this.z - v.z
);
};
R3.API.Vector3.prototype.equals = function (v) {
return this.x === v.x && this.y === v.y && this.z === v.z;
};
R3.API.Vector3.prototype.cross = function (v) {
return new R3.API.Vector3(
this.y * v.z - this.z * v.y,
this.z * v.x - this.x * v.z,
this.x * v.y - this.y * v.x
);
};
R3.API.Vector3.clockwise = function (u, v, w, viewPoint) {
var normal = R3.API.Vector3.normal(u, v, w);
var uv = u.copy();
var winding = normal.dot(uv.subtract(viewPoint));
return (winding > 0);
};
R3.API.Vector3.normal = function (u, v, w) {
var vv = v.copy();
var wv = w.copy();
return vv.subtract(u).cross(wv.subtract(u));
};
R3.API.Vector3.prototype.lookAt = function (at, up) {
var lookAtMatrix = R3.API.Matrix4.lookAt(this, at, up);
return this.multiply(lookAtMatrix);
};
R3.API.Vector3.prototype.translate = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
R3.API.Vector3.prototype.add = function (v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
return this;
};
R3.API.Vector3.prototype.squared = function () {
return this.x * this.x + this.y * this.y + this.z * this.z;
};
R3.API.Vector3.prototype.copy = function () {
return new R3.API.Vector3(
this.x,
this.y,
this.z
);
};
R3.API.Vector3.prototype.set = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
R3.API.Vector3.prototype.lerp = function ( v, alpha ) {
return new R3.API.Vector3(
this.x + ( v.x - this.x ) * alpha,
this.y + ( v.y - this.y ) * alpha,
this.z + ( v.z - this.z ) * alpha
);
};
R3.API.Vector3.prototype.distanceTo = function(v) {
var dx = this.x - v.x,
dy = this.y - v.y,
dz = this.z - v.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
};
/**
* @return {number}
*/
R3.API.Vector3.AngleDirection = function(forward, directionToCheck, up) {
var perp = forward.cross(directionToCheck);
var dir = perp.dot(up);
if (dir > 0.0) {
return 1.0;
} else if (dir < 0.0) {
return -1.0;
} else {
return 0.0;
}
};
/**
* Multiplies this vector with a scalar, vector or matrix. If you want a copy, copy() it first
* @param object {Number | R3.API.Vector3 | R3.API.Vector4 | R3.API.Matrix3 | R3.API.Matrix4}
* @param cross boolean true if you want the cross product, otherwise returns the scalar (dot or inner) product
* @returns {R3.API.Vector3 | Number}
*/
R3.API.Vector3.prototype.multiply = function (object, cross) {
var x, y, z;
var a = object;
var b = this;
if (R3.Utils.UndefinedOrNull(cross)) {
cross = false;
}
if (typeof object === 'number') {
if (cross) {
this.x *= object;
this.y *= object;
this.z *= object;
return this;
} else {
return ((this.x * object) + (this.y * object) + (this.z * object));
}
}
if (object instanceof R3.API.Vector3) {
if (cross) {
x = (a.y * b.z) - (a.z * b.y);
y = (a.z * b.x) - (a.x * b.z);
z = (a.x * b.y) - (a.y * b.x);
this.x = x;
this.y = y;
this.z = z;
return this;
} else {
return ((this.x * object.x) + (this.y * object.y) + (this.z * object.z));
}
} else {
console.log("functionality not implemented - please do this");
throw new Error("not implemented");
}
};
R3.API.Vector3.prototype.dot = function (v) {
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
};
R3.API.Vector3.prototype.normalize = function () {
var EPSILON = 0.000001;
var v2 = this.squared();
if (v2 < EPSILON) {
return this; //do nothing for zero vector
}
var invLength = 1.0 / Math.sqrt(v2);
return new R3.API.Vector3(
this.x * invLength,
this.y * invLength,
this.z * invLength
);
};
R3.API.Vector3.prototype.clone = function () {
return new R3.API.Vector3(
this.x,
this.y,
this.z
);
};
R3.API.Vector3.prototype.applyQuaternion = function(q) {
var x = this.x, y = this.y, z = this.z;
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
// calculate quat * vector
var ix = qw * x + qy * z - qz * y;
var iy = qw * y + qz * x - qx * z;
var iz = qw * z + qx * y - qy * x;
var iw = - qx * x - qy * y - qz * z;
// calculate result * inverse quat
this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
return this;
};
R3.API.Vector3.prototype.clamp = function(min, max) {
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
this.z = Math.max( min.z, Math.min( max.z, this.z ) );
return this;
};
R3.API.Vector3.prototype.length = function() {
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
};
R3.API.Vector3.prototype.reflect = function(normal) {
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
};
R3.API.Vector3.prototype.angleTo = function (v) {
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
};
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
R3.API.Vector3.FromObject = function (objectVector) {
if (R3.Utils.UndefinedOrNull(objectVector)) {
console.warn('vector from db undefined - stale version in db');
objectVector = {};
}
return new R3.API.Vector3(
objectVector.x,
objectVector.y,
objectVector.z
)
};

46
src/r3-api-vector4.js Normal file
View File

@ -0,0 +1,46 @@
R3.API.Vector4 = function (x, y, z, w) {
if (R3.Utils.UndefinedOrNull(x)) {
x = 0;
}
this.x = x;
if (R3.Utils.UndefinedOrNull(y)) {
y = 0;
}
this.y = y;
if (R3.Utils.UndefinedOrNull(z)) {
z = 0;
}
this.z = z;
if (R3.Utils.UndefinedOrNull(w)) {
w = 1;
}
this.w = w;
};
R3.API.Vector4.prototype.equals = function (v) {
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
};
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
R3.API.Vector4.FromObject = function (objectVector) {
if (R3.Utils.UndefinedOrNull(objectVector)) {
console.warn('vector from db undefined - stale version in db');
objectVector = {};
}
return new R3.API.Vector4(
objectVector.x,
objectVector.y,
objectVector.z,
objectVector.w
)
};

97
src/r3-box3.js Normal file
View File

@ -0,0 +1,97 @@
/**
* R3.Box3
* @param implementation
* @param apiBox3
* @param parentObject
* @constructor
*/
R3.Box3 = function (
implementation,
apiBox3,
parentObject
) {
this.implementation = implementation;
this.implementation.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
this.parentObject = parentObject;
if (R3.Utils.UndefinedOrNull(apiBox3)) {
apiBox3 = {};
}
R3.API.Box3.call(
this,
apiBox3.id,
apiBox3.name,
apiBox3.parentEntity,
apiBox3.min,
apiBox3.max
);
this.min = new R3.Vector3(
this.implementation,
this.min,
this
);
this.max = new R3.Vector3(
this.implementation,
this.max,
this
);
this.createInstance();
};
R3.Box3.prototype = Object.create(R3.Component.prototype);
R3.Box3.prototype.constructor = R3.Box3;
/**
* Creates an instance R3.Box3
* @returns {*}
*/
R3.Box3.prototype.createInstance = function() {
this.instance = new THREE.Box3(
this.min.instance,
this.max.instance
);
};
/**
* Updates R3.Box3 instance
* @param property
*/
R3.Box3.prototype.updateInstance = function(property) {
if (property === 'min') {
this.instance.min.x = this.min.x;
this.instance.min.y = this.min.y;
this.instance.min.z = this.min.z;
}
if (property === 'max') {
this.instance.max.x = this.max.x;
this.instance.max.y = this.max.y;
this.instance.max.z = this.max.z;
}
};
/**
* R3.Box3 to R3.API.Box3
* @returns {R3.API.Box3}
*/
R3.Box3.prototype.toApiObject = function() {
return new R3.API.Box3(
this.id,
this.name,
R3.Utils.IdOrNull(this.parentEntity),
this.min.toApiObject(),
this.max.toApiObject()
);
};

335
src/r3-canvas.js Normal file
View File

@ -0,0 +1,335 @@
/**
* Canvas object
* @param graphics
* @param apiCanvas
* @returns {R3.Canvas}
* @constructor
*/
R3.Canvas = function(
graphics,
apiCanvas
) {
this.graphics = graphics;
if (R3.Utils.UndefinedOrNull(apiCanvas)) {
apiCanvas = {};
}
R3.API.Canvas.call(
this,
apiCanvas.id,
apiCanvas.name,
apiCanvas.parentEntity,
apiCanvas.parentTexture,
apiCanvas.autoUpdateSize,
apiCanvas.width,
apiCanvas.height,
apiCanvas.offset,
apiCanvas.tabIndex,
apiCanvas.texts,
apiCanvas.textBaseline
);
this.offset = new R3.Vector2(
this.graphics,
this.offset,
this
);
R3.Component.call(
this,
{
'parentTexture' : R3.D3.Texture,
'texts' : [R3.D3.Text]
}
);
this.context = null;
};
R3.Canvas.prototype = Object.create(R3.Component.prototype);
R3.Canvas.prototype.constructor = R3.Canvas;
/**
* Creates a light instance
* @returns {*}
*/
R3.Canvas.prototype.createInstance = function() {
this.instance = document.createElement('canvas');
this.instance.setAttribute('id', this.id);
this.instance.setAttribute('tabindex', this.tabIndex);
this.instance.setAttribute('style', 'left: ' + this.offset.x + 'px;top: ' + this.offset.y + 'px');
if (this.autoUpdateSize) {
/**
* Update our size from the instance size
*/
this.width = this.instance.width;
this.height = this.instance.height;
} else {
/**
* Update our instance with our size
*/
this.instance.width = this.width;
this.instance.height = this.height;
}
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Canvas.prototype.updateInstance = function(property) {
if (R3.Utils.UndefinedOrNull(property)) {
console.warn('unknown property update for Canvas: ' + property);
}
if (property === 'id') {
this.instance.setAttribute('id', this.id);
return;
}
if (property === 'offset') {
this.instance.style.left = this.offset.x + 'px';
this.instance.style.top = this.offset.y + 'px';
return;
}
if (property === 'tabIndex') {
this.instance.setAttribute('tabIndex', this.tabIndex);
return;
}
if (
property === 'autoUpdateSize' ||
property === 'width' ||
property === 'height'
) {
/**
* We cannot control everything about the canvas - this is dependent on where the canvas lives and its
* dimensions can also be controlled via CSS -
*
* This means - autoUpdateSize works a little different for this component - instead of getting our size and
* applying it, it gets our canvas size and applies it, or applies our size to the canvas - of course
* the user settings override this.
*/
if (this.autoUpdateSize) {
/**
* Update from our canvas size
*/
this.width = this.instance.width;
this.height = this.instance.height;
} else {
/**
* Command our canvas to take a size - this is not guaranteed however - CSS wins
*/
this.instance.width = this.width;
this.instance.height = this.height;
}
return;
}
if (property === 'texts') {
this.writeText();
return;
}
if (property === 'textBaseLine') {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
this.context.textBaseline = this.textBaseline;
return;
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Canvas to a R3.API.Canvas
* @returns {R3.API.Canvas}
*/
R3.Canvas.prototype.toApiObject = function() {
return new R3.API.Canvas(
this.id,
this.name,
R3.Utils.IdOrNull(this.parentEntity),
R3.Utils.IdOrNull(this.parentTexture),
this.autoUpdateSize,
this.width,
this.height,
this.offset.toApiObject(),
this.tabIndex,
this.texts.map(function(text){
return R3.Utils.IdOrNull(text)
}),
this.textBaseline
);
};
R3.Canvas.prototype.writeText = function() {
this.clear();
this.texts.map(
function(text){
if (!this.context) {
this.context = this.instance.getContext('2d');
}
text.parentCanvas = this;
this.context.fillStyle = text.fillStyle;
this.context.font = text.font;
this.context.fillText(text.value, text.offset.x, text.offset.y);
if (this.parentTexture && this.parentTexture.instance) {
this.parentTexture.instance.needsUpdate = true;
}
}.bind(this)
);
};
R3.Canvas.prototype.clear = function() {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
this.context.clearRect(0, 0, this.width, this.height);
};
R3.Canvas.prototype.filledRectangle = function(
x,
y,
width,
height,
fillStyle
) {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
if (fillStyle) {
this.context.fillStyle = fillStyle;
}
this.context.fillRect(x, y, width, height);
};
R3.Canvas.prototype.outlineRectangle = function(
x,
y,
width,
height,
lineWidth,
strokeStyle
) {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
if (lineWidth) {
this.context.lineWidth = lineWidth;
}
if (strokeStyle) {
this.context.strokeStyle = strokeStyle;
}
this.context.fillRect(x, y, width, height);
};
R3.Canvas.prototype.line = function(
x,
y,
endX,
endY,
lineWidth,
strokeStyle
) {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
if (lineWidth) {
this.context.lineWidth = lineWidth;
}
if (strokeStyle) {
this.context.strokeStyle = strokeStyle;
}
this.context.beginPath();
this.context.moveTo(x, y);
this.context.lineTo(endX, endY);
this.context.stroke();
};
R3.Canvas.prototype.text = function(
text,
x,
y,
font,
fillStyle
) {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
if (font) {
this.context.font = font;
}
if (fillStyle) {
this.context.fillStyle = fillStyle;
}
this.context.fillText(text, x, y);
};
R3.Canvas.prototype.image = function(
image,
x,
y,
width,
height,
sx,
sy,
swidth,
sheight
) {
if (!this.context) {
this.context = this.instance.getContext('2d');
}
if (sx && sy && swidth && sheight) {
this.context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
return;
}
if (width && height) {
this.context.drawImage(image, x, y, width, height);
return;
}
this.context.drawImage(image, x, y);
};

96
src/r3-clock.js Normal file
View File

@ -0,0 +1,96 @@
/**
* Creates a Clock object
* @param graphics
* @param apiClock R3.API.Clock
* @constructor
*/
R3.Clock = function(
graphics,
apiClock
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiClock)) {
apiClock = {};
}
R3.API.Clock.call(
this,
apiClock.id,
apiClock.name,
apiClock.parentEntity
);
R3.Component.call(this);
} ;
R3.Clock.prototype = Object.create(R3.Component.prototype);
R3.Clock.prototype.constructor = R3.Clock;
/**
* Creates a camera instance of 'graphics' type (only THREE for now)
* @returns {THREE.Clock}
*/
R3.Clock.prototype.createInstance = function() {
this.instance = new THREE.Clock();
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Clock.prototype.updateInstance = function() {
};
R3.Clock.prototype.getDelta = function() {
var delta = this.instance.getDelta();
/**
* clamp the delta to 1/60
*/
if (delta > (1 / 30.0)) {
// console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time');
delta = (1 / 30.0);
}
return delta;
};
/**
* Converts a R3.Clock to a new R3.API.Clock
* @returns {R3.API.Clock}
*/
R3.Clock.prototype.toApiObject = function() {
return new R3.API.Clock(
this.id,
this.name,
R3.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts from an Object camera to a R3.Clock
* @param graphics R3.Graphics
* @param objectClock Object
* @returns {R3.Clock}
* @constructor
*/
R3.Clock.FromObject = function(graphics, objectClock) {
var apiClock = R3.API.Clock.FromObject(objectClock);
return new R3.Clock(
graphics,
apiClock
);
};

60
src/r3-coder-runtime.js Normal file
View File

@ -0,0 +1,60 @@
/**
* Coder
* @param id
* @param name
* @param coderType
* @constructor
*/
R3.CoderRuntime = function(
id,
name,
coderType
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Coder (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(coderType)) {
coderType = R3.CoderRuntime.TYPE_CODE_MIRROR;
}
this.coderType = coderType;
this.createInstance();
};
/**
* R3.CoderRuntime Types
* @type {number}
*/
R3.CoderRuntime.TYPE_CODE_MIRROR = 0x1;
R3.CoderRuntime.prototype.createInstance = function() {
if (this.coderType === R3.CoderRuntime.TYPE_CODE_MIRROR) {
this.instance = CodeMirror;
} else {
this.instance = null;
}
};
R3.CoderRuntime.prototype.updateInstance = function(property) {
if (property === 'coderType') {
this.createInstance();
}
};
/**
* Logs a warning and throws an error if not cannon
*/
R3.CoderRuntime.prototype.isNotCodeMirrorThrow = function() {
if (this.instance !== CodeMirror) {
console.error('Only CodeMirror supported');
throw new Error('Only CodeMirror supported');
}
};

152
src/r3-color.js Normal file
View File

@ -0,0 +1,152 @@
/**
* Runtime color for updating instance objects
* @param graphics R3.GraphicsRuntime
* @param parentObject R3.D3.*
* @param apiColor R3.API.Color
* @param grain Number
* @constructor
*/
R3.Color = function (
graphics,
apiColor,
parentObject,
grain
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiColor)) {
apiColor = {};
}
R3.API.Color.call(
this,
apiColor.r,
apiColor.g,
apiColor.b,
apiColor.a
);
if (R3.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
this.parentObject = parentObject;
if (R3.Utils.UndefinedOrNull(grain)) {
grain = 0.001;
}
this.grain = grain;
this.createInstance();
};
R3.Color.prototype = Object.create(R3.API.Color.prototype);
R3.Color.prototype.constructor = R3.Color;
/**
* Creates an instance color
* @returns {*}
*/
R3.Color.prototype.createInstance = function() {
this.instance = new THREE.Color(
this.r,
this.g,
this.b
);
};
/**
* Updates the instance color, calls updateInstance on the parent object
*/
R3.Color.prototype.updateInstance = function(property) {
this.instance.r = this.r;
this.instance.g = this.g;
this.instance.b = this.b;
if (this.parentObject &&
this.parentObject.updateInstance) {
this.parentObject.updateInstance(property);
}
};
/**
* Converts runtime color to API Color
* @returns {R3.API.Color}
*/
R3.Color.prototype.toApiObject = function() {
return new R3.API.Color(
this.r,
this.g,
this.b,
this.a
);
};
/**
* Converts the current color to HTML hex format (ex. #ffffff)
* @returns {string}
*/
R3.Color.prototype.toHex = function() {
if (this.r < 0) {
this.r = 0;
}
if (this.g < 0) {
this.g = 0;
}
if (this.b < 0) {
this.b = 0;
}
if (this.r > 1) {
this.r = 1;
}
if (this.g > 1) {
this.g = 1;
}
if (this.b > 1) {
this.b = 1;
}
var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16);
var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16);
var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16);
if (rf.length < 2) {
rf = '0' + rf;
}
if (gf.length < 2) {
gf = '0' + gf;
}
if (bf.length < 2) {
bf = '0' + bf;
}
return '#' + rf + gf + bf;
};
/**
* Sets this object color to what the hex value is
* @param hex
* @returns {string}
*/
R3.Color.prototype.fromHex = function(hex) {
var matches = hex.match(new RegExp('#+(..)(..)(..)'));
this.r = parseInt(matches[1], 16) / 255.0;
this.g = parseInt(matches[2], 16) / 255.0;
this.b = parseInt(matches[3], 16) / 255.0;
this.instance.r = this.r;
this.instance.g = this.g;
this.instance.b = this.b;
};

100
src/r3-controls-0.js Normal file
View File

@ -0,0 +1,100 @@
/**
* R3.Controls
* @param apiControls
* @property controlsType
* @constructor
*/
R3.Controls = function (
apiControls
) {
if (R3.Utils.UndefinedOrNull(apiControls)) {
apiControls = {};
}
R3.API.Controls.call(
this,
apiControls.id,
apiControls.name,
apiControls.controlsType,
apiControls.canvas,
apiControls.parentEntity
);
var linkedObjects = {
canvas : R3.Canvas
};
var delayed = false;
switch (this.controlsType) {
case (R3.API.Controls.CONTROLS_TYPE_EDITOR) :
linkedObjects.raycaster = R3.D3.Raycaster;
linkedObjects.camera = R3.D3.Camera;
delayed = true;
break;
case (R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON) :
linkedObjects.camera = R3.D3.Camera;
delayed = true;
break;
case (R3.API.Controls.CONTROLS_TYPE_ORBIT) :
linkedObjects.camera = R3.D3.Camera;
linkedObjects.target = R3.Component;
delayed = true;
break;
}
R3.Component.call(
this,
linkedObjects,
delayed
);
};
R3.Controls.prototype = Object.create(R3.Component.prototype);
R3.Controls.prototype.constructor = R3.Controls;
R3.Controls.D3 = function() {};
R3.Controls.D3.prototype = Object.create(R3.Controls.prototype);
R3.Controls.D3.prototype.constructor = R3.Controls.D3;
/**
* Creates a mesh instance or updates it
*/
R3.Controls.prototype.createInstance = function() {
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the mesh instance
*/
R3.Controls.prototype.updateInstance = function(property) {
if (property === 'canvas') {
R3.Event.Emit(
R3.Event.CANVAS_CHANGE,
{
component: this
}
);
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls to a R3.API.Controls
* @returns {R3.API.Controls}
*/
R3.Controls.prototype.toApiObject = function() {
var apiControls = new R3.API.Controls(
this.id,
this.name,
this.controlsType,
R3.Utils.IdOrNull(this.canvas),
R3.Utils.IdOrNull(this.parentEntity)
);
return apiControls;
};

View File

@ -0,0 +1,116 @@
/**
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
* @param graphics R3.GraphicsRuntime
* @param apiEditorControls
* @constructor
*/
R3.Controls.D3.Editor = function (
graphics,
apiEditorControls
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiEditorControls)) {
apiEditorControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR
};
}
if (R3.Utils.UndefinedOrNull()) {
apiEditorControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR;
}
R3.API.Controls.D3.Editor.call(
this,
apiEditorControls,
apiEditorControls.raycaster,
apiEditorControls.camera
);
if (this.raycaster instanceof R3.D3.API.Raycaster) {
this.raycaster = new R3.D3.Raycaster(
this.graphics,
this.raycaster
);
}
R3.Controls.call(
this,
apiEditorControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.D3.Editor.prototype = Object.create(R3.Controls.D3.prototype);
R3.Controls.D3.Editor.prototype.constructor = R3.Controls.D3.Editor;
/**
* Create Instance
*/
R3.Controls.D3.Editor.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.camera) ||
R3.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('no camera at time of editor-controls create instance');
return;
}
if (
R3.Utils.UndefinedOrNull(this.canvas) ||
R3.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('no canvas at time of editor-controls create instance');
return;
}
this.instance = new THREE.EditorControls(
this.camera.instance,
this.canvas.instance
);
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.D3.Editor.prototype.updateInstance = function(property) {
if (
property === 'canvas' ||
property === 'camera'
) {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
}
}
console.warn('an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability');
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.D3.Editor to a R3.D3.API.Mesh
* @returns {R3.API.Controls}
*/
R3.Controls.D3.Editor.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
apiControls.raycaster = R3.Utils.IdOrNull(this.raycaster);
apiControls.camera = R3.Utils.IdOrNull(this.camera);
return apiControls;
};

View File

@ -0,0 +1,220 @@
/**
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
* @param graphics R3.GraphicsRuntime
* @param apiFirstPersonControls
* @constructor
*/
R3.Controls.D3.FirstPerson = function (
graphics,
apiFirstPersonControls
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiFirstPersonControls)) {
apiFirstPersonControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON
};
}
if (R3.Utils.UndefinedOrNull()) {
apiFirstPersonControls.controlsType = R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON;
}
R3.API.Controls.D3.FirstPerson.call(
this,
apiFirstPersonControls,
apiFirstPersonControls.camera,
apiFirstPersonControls.enabled,
apiFirstPersonControls.movementSpeed,
apiFirstPersonControls.lookSpeed,
apiFirstPersonControls.lookVertical,
apiFirstPersonControls.autoForward,
apiFirstPersonControls.activeLook,
apiFirstPersonControls.heightSpeed,
apiFirstPersonControls.heightCoef,
apiFirstPersonControls.heightMin,
apiFirstPersonControls.heightMax,
apiFirstPersonControls.constrainVertical,
apiFirstPersonControls.verticalMin,
apiFirstPersonControls.verticalMax,
apiFirstPersonControls.autoSpeedFactor
);
R3.Controls.call(
this,
apiFirstPersonControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.D3.FirstPerson.prototype = Object.create(R3.Controls.D3.prototype);
R3.Controls.D3.FirstPerson.prototype.constructor = R3.Controls.D3.FirstPerson;
/**
* Create Instance
*/
R3.Controls.D3.FirstPerson.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.camera) ||
R3.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('no camera at time of editor-controls create instance');
return;
}
if (
R3.Utils.UndefinedOrNull(this.canvas) ||
R3.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('no canvas at time of editor-controls create instance');
return;
}
this.instance = new THREE.FirstPersonControls(
this.camera.instance,
this.canvas.instance
);
this.instance.enabled = this.enabled;
this.instance.movementSpeed = this.movementSpeed;
this.instance.lookSpeed = this.lookSpeed;
this.instance.lookVertical = this.lookVertical;
this.instance.autoForward = this.autoForward;
this.instance.activeLook = this.activeLook;
this.instance.heightSpeed = this.heightSpeed;
this.instance.heightCoef = this.heightCoef;
this.instance.heightMin = this.heightMin;
this.instance.heightMax = this.heightMax;
this.instance.constrainVertical = this.constrainVertical;
this.instance.verticalMin = this.verticalMin;
this.instance.verticalMax = this.verticalMax;
this.instance.autoSpeedFactor = this.autoSpeedFactor;
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.D3.FirstPerson.prototype.updateInstance = function(property) {
if (
property === 'canvas' ||
property === 'camera'
) {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
}
}
if (property === 'enabled') {
this.instance.enabled = this.enabled;
return;
}
if (property === 'movementSpeed') {
this.instance.movementSpeed = this.movementSpeed;
return;
}
if (property === 'lookSpeed') {
this.instance.lookSpeed = this.lookSpeed;
return;
}
if (property === 'lookVertical') {
this.instance.lookVertical = this.lookVertical;
return;
}
if (property === 'autoForward') {
this.instance.autoForward = this.autoForward;
return;
}
if (property === 'activeLook') {
this.instance.activeLook = this.activeLook;
return;
}
if (property === 'heightSpeed') {
this.instance.heightSpeed = this.heightSpeed;
return;
}
if (property === 'heightCoef') {
this.instance.heightCoef = this.heightCoef;
return;
}
if (property === 'heightMin') {
this.instance.heightMin = this.heightMin;
return;
}
if (property === 'heightMax') {
this.instance.heightMax = this.heightMax;
return;
}
if (property === 'constrainVertical') {
this.instance.constrainVertical = this.constrainVertical;
return;
}
if (property === 'verticalMin') {
this.instance.verticalMin = this.verticalMin;
return;
}
if (property === 'verticalMax') {
this.instance.verticalMax = this.verticalMax;
return;
}
if (property === 'autoSpeedFactor') {
this.instance.autoSpeedFactor = this.autoSpeedFactor;
return;
}
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.D3.FirstPerson to a R3.D3.API.Mesh
* @returns {R3.API.Controls}
*/
R3.Controls.D3.FirstPerson.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
return new R3.API.Controls.D3.FirstPerson(
apiControls,
R3.Utils.IdOrNull(this.camera),
this.enabled,
this.movementSpeed,
this.lookSpeed,
this.lookVertical,
this.autoForward,
this.activeLook,
this.heightSpeed,
this.heightCoef,
this.heightMin,
this.heightMax,
this.constrainVertical,
this.verticalMin,
this.verticalMax,
this.autoSpeedFactor
);
};

235
src/r3-controls-d3-orbit.js Normal file
View File

@ -0,0 +1,235 @@
/**
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
* @param graphics R3.GraphicsRuntime
* @param apiOrbitControls
* @constructor
*/
R3.Controls.D3.Orbit = function (
graphics,
apiOrbitControls
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiOrbitControls)) {
apiOrbitControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_ORBIT
};
}
if (R3.Utils.UndefinedOrNull()) {
apiOrbitControls.controlsType = R3.API.Controls.CONTROLS_TYPE_ORBIT;
}
R3.API.Controls.D3.Orbit.call(
this,
apiOrbitControls,
apiOrbitControls.camera,
apiOrbitControls.target,
apiOrbitControls.enabled,
apiOrbitControls.minPolarAngle,
apiOrbitControls.maxPolarAngle,
apiOrbitControls.enableDamping,
apiOrbitControls.dampingFactor,
apiOrbitControls.enableZoom,
apiOrbitControls.zoomSpeed,
apiOrbitControls.enableRotate,
apiOrbitControls.rotateSpeed,
apiOrbitControls.enablePan,
apiOrbitControls.keyPanSpeed,
apiOrbitControls.autoRotate,
apiOrbitControls.autoRotateSpeed,
apiOrbitControls.enableKeys
);
R3.Controls.call(
this,
apiOrbitControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.D3.Orbit.prototype = Object.create(R3.Controls.D3.prototype);
R3.Controls.D3.Orbit.prototype.constructor = R3.Controls.D3.Orbit;
/**
* Create Instance
*/
R3.Controls.D3.Orbit.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.camera) ||
R3.Utils.UndefinedOrNull(this.camera.instance)
) {
console.warn('no camera at time of editor-controls create instance');
return;
}
if (
R3.Utils.UndefinedOrNull(this.canvas) ||
R3.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('no canvas at time of editor-controls create instance');
return;
}
this.instance = new THREE.OrbitControls(
this.camera.instance,
this.canvas.instance
);
if (this.target && this.target.instance) {
this.instance.target = this.target.instance.position;
}
this.instance.enabled = this.enabled;
this.instance.minPolarAngle = this.minPolarAngle;
this.instance.maxPolarAngle = this.maxPolarAngle;
this.instance.enableDamping = this.enableDamping;
this.instance.dampingFactor = this.dampingFactor;
this.instance.enableZoom = this.enableZoom;
this.instance.zoomSpeed = this.zoomSpeed;
this.instance.enableRotate = this.enableRotate;
this.instance.rotateSpeed = this.rotateSpeed;
this.instance.enablePan = this.enablePan;
this.instance.keyPanSpeed = this.keyPanSpeed;
this.instance.autoRotate = this.autoRotate;
this.instance.autoRotateSpeed = this.autoRotateSpeed;
this.instance.enableKeys = this.enableKeys;
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.D3.Orbit.prototype.updateInstance = function(property) {
if (
property === 'canvas' ||
property === 'camera'
) {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
}
}
if (property === 'target') {
if (this.target && this.target.instance) {
this.instance.target = this.target.instance.position;
} else {
this.instance.target = new THREE.Vector3();
}
return;
}
if (property === 'enabled') {
this.instance.enabled = this.enabled;
return;
}
if (property === 'minPolarAngle') {
this.instance.minPolarAngle = this.minPolarAngle;
return;
}
if (property === 'maxPolarAngle') {
this.instance.maxPolarAngle = this.maxPolarAngle;
return;
}
if (property === 'enableDamping') {
this.instance.enableDamping = this.enableDamping;
return;
}
if (property === 'dampingFactor') {
this.instance.dampingFactor = this.dampingFactor;
return;
}
if (property === 'enableZoom') {
this.instance.enableZoom = this.enableZoom;
return;
}
if (property === 'zoomSpeed') {
this.instance.zoomSpeed = this.zoomSpeed;
return;
}
if (property === 'enableRotate') {
this.instance.enableRotate = this.enableRotate;
return;
}
if (property === 'rotateSpeed') {
this.instance.rotateSpeed = this.rotateSpeed;
return;
}
if (property === 'enablePan') {
this.instance.enablePan = this.enablePan;
return;
}
if (property === 'keyPanSpeed') {
this.instance.keyPanSpeed = this.keyPanSpeed;
return;
}
if (property === 'autoRotate') {
this.instance.autoRotate = this.autoRotate;
return;
}
if (property === 'autoRotateSpeed') {
this.instance.autoRotateSpeed = this.autoRotateSpeed;
return;
}
if (property === 'enableKeys') {
this.instance.enableKeys = this.enableKeys;
return;
}
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.D3.Orbit to a R3.D3.API.Mesh
* @returns {R3.API.Controls}
*/
R3.Controls.D3.Orbit.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
return new R3.API.Controls.D3.Orbit(
apiControls,
R3.Utils.IdOrNull(this.camera),
R3.Utils.IdOrNull(this.target),
this.enabled,
this.minPolarAngle,
this.maxPolarAngle,
this.enableDamping,
this.dampingFactor,
this.enableZoom,
this.zoomSpeed,
this.enableRotate,
this.rotateSpeed,
this.enablePan,
this.keyPanSpeed,
this.autoRotate,
this.autoRotateSpeed,
this.enableKeys
);
};

View File

@ -0,0 +1,79 @@
/**
* Keyboard Controls
* @param apiKeyboardControls R3.API.Controls
* @constructor
*/
R3.Controls.Keyboard = function (
apiKeyboardControls
) {
if (R3.Utils.UndefinedOrNull(apiKeyboardControls)) {
apiKeyboardControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_KEYBOARD
};
}
R3.API.Controls.Keyboard.call(
this,
apiKeyboardControls
);
R3.Controls.call(
this,
apiKeyboardControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.Keyboard.prototype = Object.create(R3.Controls.prototype);
R3.Controls.Keyboard.prototype.constructor = R3.Controls.Keyboard;
/**
* Create Instance
* @returns
*/
R3.Controls.Keyboard.prototype.createInstance = function() {
/**
* Set instance to true to indicate no dependencies to other components
*/
this.instance = true;
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.Keyboard.prototype.updateInstance = function(property) {
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.Keyboard to a R3.API.Controls
* @returns {R3.API.Controls}
*/
R3.Controls.Keyboard.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
/**
* add other properties here as this component develops...
*/
return apiControls;
};
/**
* Construct an Keyboard Controls object from data
* @param objectControls
* @returns {R3.Controls.Keyboard}
* @constructor
*/
R3.Controls.Keyboard.FromObject = function(objectControls) {
var apiKeyboardControls = R3.API.Controls.Keyboard.FromObject(objectControls);
return new R3.Controls.Keyboard(
apiKeyboardControls
);
};

79
src/r3-controls-mouse.js Normal file
View File

@ -0,0 +1,79 @@
/**
* Mouse Controls
* @param apiMouseControls R3.API.Controls
* @constructor
*/
R3.Controls.Mouse = function (
apiMouseControls
) {
if (R3.Utils.UndefinedOrNull(apiMouseControls)) {
apiMouseControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_MOUSE
};
}
R3.API.Controls.Mouse.call(
this,
apiMouseControls
);
R3.Controls.call(
this,
apiMouseControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.Mouse.prototype = Object.create(R3.Controls.prototype);
R3.Controls.Mouse.prototype.constructor = R3.Controls.Mouse;
/**
* Create Instance
* @returns
*/
R3.Controls.Mouse.prototype.createInstance = function() {
/**
* Set instance to true to indicate no dependencies to other components
*/
this.instance = true;
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.Mouse.prototype.updateInstance = function(property) {
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.Mouse to a R3.API.Controls
* @returns {R3.API.Controls}
*/
R3.Controls.Mouse.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
/**
* add other properties here as this component develops...
*/
return apiControls;
};
/**
* Construct an Mouse Controls object from data
* @param objectControls
* @returns {R3.Controls.Mouse}
* @constructor
*/
R3.Controls.Mouse.FromObject = function(objectControls) {
var apiMouseControls = R3.API.Controls.Mouse.FromObject(objectControls);
return new R3.Controls.Mouse(
apiMouseControls
);
};

82
src/r3-controls-touch.js Normal file
View File

@ -0,0 +1,82 @@
/**
* Touch Controls
* @constructor
* @param apiTouchControls
*/
R3.Controls.Touch = function (
apiTouchControls
) {
if (R3.Utils.UndefinedOrNull(apiTouchControls)) {
apiTouchControls = {
controlsType : R3.API.Controls.CONTROLS_TYPE_TOUCH
};
}
R3.API.Controls.Touch.call(
this,
apiTouchControls,
apiTouchControls.sensitivity
);
R3.Controls.call(
this,
apiTouchControls
);
};
/**
* Inheritance
* @type {R3.Controls}
*/
R3.Controls.Touch.prototype = Object.create(R3.Controls.prototype);
R3.Controls.Touch.prototype.constructor = R3.Controls.Touch;
/**
* Create Instance
* @returns
*/
R3.Controls.Touch.prototype.createInstance = function() {
/**
* Set instance to true to indicate no dependencies to other components
*/
this.instance = true;
R3.Controls.prototype.createInstance.call(this);
};
/**
* Update Instance
*/
R3.Controls.Touch.prototype.updateInstance = function(property) {
R3.Controls.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Controls.Touch to a R3.API.Controls
* @returns {R3.API.Controls}
*/
R3.Controls.Touch.prototype.toApiObject = function() {
var apiControls = R3.Controls.prototype.toApiObject.call(this);
apiControls.sensitivity = this.sensitivity;
/**
* add other properties here as this component develops...
*/
return apiControls;
};
/**
* Construct an Touch Controls object from data
* @param objectControls
* @returns {R3.Controls.Touch}
* @constructor
*/
R3.Controls.Touch.FromObject = function(objectControls) {
var apiTouchControls = R3.API.Controls.Touch.FromObject(objectControls);
return new R3.Controls.Touch(apiTouchControls);
};

87
src/r3-curve-a.js Normal file
View File

@ -0,0 +1,87 @@
/**
* R3.Curve
* @param graphics R3.GraphicsRuntime
* @param apiCurve R3.API.Curve
* @property curveType
* @constructor
*/
R3.Curve = function(
graphics,
apiCurve
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiCurve)) {
apiCurve = {};
}
R3.API.Curve.call(
this,
apiCurve.id,
apiCurve.name,
apiCurve.curveType,
apiCurve.parentEntity,
apiCurve.arcLenghDivisions
);
var linkedObjects = {};
switch (this.curveType) {
case R3.API.Curve.CURVE_TYPE_PATH :
linkedObjects.curves = [R3.Curve];
break;
}
R3.Component.call(
this,
linkedObjects
);
};
R3.Curve.prototype = Object.create(R3.Component.prototype);
R3.Curve.prototype.constructor = R3.Curve;
/**
* Create Instance
*/
R3.Curve.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
console.warn('you should not instantiate this curve object directly');
this.instance = new THREE.Curve();
}
this.instance.arcLenghDivisions = this.arcLenghDivisions;
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Curve.prototype.updateInstance = function(property) {
if (property === 'arcLenghDivisions') {
this.instance.arcLenghDivisions = this.arcLenghDivisions;
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Curve to a new R3.API.Curve
* @returns {R3.API.Curve}
*/
R3.Curve.prototype.toApiObject = function() {
return new R3.API.Curve(
this.id,
this.name,
this.curveType,
R3.Utils.IdOrNull(this.parentEntity),
this.arcLenghDivisions
);
};

109
src/r3-curve-path-a.js Normal file
View File

@ -0,0 +1,109 @@
/**
* R3.Curve.Path
* @param graphics R3.GraphicsRuntime
* @param apiCurvePath
* @constructor
*/
R3.Curve.Path = function(
graphics,
apiCurvePath
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiCurvePath)) {
apiCurvePath = {
curveType : R3.API.Curve.CURVE_TYPE_PATH
};
}
R3.API.Curve.Path.call(
this,
apiCurvePath,
apiCurvePath.curves,
apiCurvePath.autoClose
);
this.curves = this.curves.map(
function(curve) {
if (curve instanceof R3.API.Curve) {
return new R3.Curve(
this.graphics,
curve
);
}
}.bind(this)
);
R3.Curve.call(
this,
this.graphics,
this
);
};
R3.Curve.Path.prototype = Object.create(R3.Curve.prototype);
R3.Curve.Path.prototype.constructor = R3.Curve.Path;
/**
* Creates a camera instance
* @returns {*}
*/
R3.Curve.Path.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
console.warn('you should not instantiate this curve object directly');
this.instance = new THREE.CurvePath();
}
this.instance.curves = this.curves.map(
function(curve) {
return curve.instance;
}
);
this.instance.autoClose = this.autoClose;
R3.Curve.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Curve.Path.prototype.updateInstance = function(property) {
if (property === 'curves') {
console.warn('todo: update curves');
return;
}
if (property === 'autoClose') {
this.instance.autoClose = this.autoClose;
return;
}
R3.Curve.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Curve to a R3.API.Curve
* @returns {R3.API.Curve}
*/
R3.Curve.Path.prototype.toApiObject = function() {
var apiCurve = R3.Curve.prototype.toApiObject.call(this);
var apiCurvePath = new R3.API.Curve.Path(
apiCurve,
this.curves.map(
function(curve) {
return R3.Utils.IdOrNull(curve);
}
),
this.autoClose
);
return apiCurvePath;
};

101
src/r3-curve-path-d2-a.js Normal file
View File

@ -0,0 +1,101 @@
/**
* R3.Curve.Path.D2
* @param graphics R3.GraphicsRuntime
* @param apiCurvePath
* @constructor
*/
R3.Curve.Path.D2 = function(
graphics,
apiCurvePath
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiCurvePath)) {
apiCurvePath = {
curveType : R3.API.Curve.CURVE_TYPE_PATH_2D
};
}
R3.API.Curve.Path.D2.call(
this,
apiCurvePath,
apiCurvePath.points
);
this.points = this.points.map(
function(point) {
return new R3.Vector2(
this.graphics,
point
);
}.bind(this)
);
R3.Curve.Path.call(
this,
this.graphics,
this
);
};
R3.Curve.Path.D2.prototype = Object.create(R3.Curve.Path.prototype);
R3.Curve.Path.D2.prototype.constructor = R3.Curve.Path.D2;
/**
* Creates a camera instance
* @returns {*}
*/
R3.Curve.Path.D2.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.instance = new THREE.Path(
this.points.map(
function(point) {
return point.instance;
}
)
);
}
R3.Curve.Path.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Curve.Path.D2.prototype.updateInstance = function(property) {
if (property === 'points') {
console.warn('todo: update points (and test it)');
this.instance.points = this.points.map(
function(point) {
return point.instance;
}
);
return;
}
R3.Curve.Path.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Curve to a R3.API.Curve
* @returns {R3.API.Curve}
*/
R3.Curve.Path.D2.prototype.toApiObject = function() {
var apiCurvePath = R3.Curve.Path.prototype.toApiObject.call(this);
return new R3.API.Curve.Path.D2(
apiCurvePath,
this.points.map(
function(point) {
return point.toApiObject();
}
)
);
};

View File

@ -0,0 +1,74 @@
/**
* R3.Curve.Path.D2
* @param graphics R3.GraphicsRuntime
* @param apiCurvePathD2
* @constructor
*/
R3.Curve.Path.D2.Shape = function(
graphics,
apiCurvePathD2
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) {
apiCurvePathD2 = {
curveType : R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE
};
}
R3.API.Curve.Path.D2.call(
this,
apiCurvePathD2,
apiCurvePathD2.points
);
R3.Curve.Path.D2.call(
this,
this.graphics,
this
);
};
R3.Curve.Path.D2.Shape.prototype = Object.create(R3.Curve.Path.D2.prototype);
R3.Curve.Path.D2.Shape.prototype.constructor = R3.Curve.Path.D2.Shape;
/**
* Creates a camera instance
* @returns {*}
*/
R3.Curve.Path.D2.Shape.prototype.createInstance = function() {
this.instance = new THREE.Shape(
this.points.map(
function(point) {
return point.instance;
}
)
);
R3.Curve.Path.D2.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Curve.Path.D2.Shape.prototype.updateInstance = function(property) {
R3.Curve.Path.D2.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Curve to a R3.API.Curve
* @returns {R3.API.Curve}
*/
R3.Curve.Path.D2.Shape.prototype.toApiObject = function() {
var apiCurvePathD2 = R3.Curve.Path.D2.prototype.toApiObject.call(this);
return new R3.API.Curve.Path.D2.Shape(
apiCurvePathD2
);
};

173
src/r3-custom-code.js Normal file
View File

@ -0,0 +1,173 @@
/**
* Creates a CustomCode object
* @param apiCustomCode R3.API.CustomCode
* @constructor
*/
R3.CustomCode = function(
apiCustomCode
) {
if (R3.Utils.UndefinedOrNull(apiCustomCode)) {
apiCustomCode = {};
}
R3.API.CustomCode.call(
this,
apiCustomCode.id,
apiCustomCode.name,
apiCustomCode.eventId,
apiCustomCode.code,
apiCustomCode.parentEntity
);
this.editor = null;
R3.Component.call(this);
};
R3.CustomCode.prototype = Object.create(R3.Component.prototype);
R3.CustomCode.prototype.constructor = R3.CustomCode;
R3.CustomCode.prototype.createInstance = function() {
try {
this.instance = new Function('data', this.code).bind(this);
} catch (error) {
/**
* Set the instance to true here to indicate that even though the compilation failed, the instance will be fine and
* this component loaded fine.
*/
this.instance = new Function('data', "console.log('compilation failed for : " + this.name + "');").bind(this);
}
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.CustomCode.prototype.updateInstance = function(property) {
if (property === 'name') {
R3.Event.Emit(
R3.Event.NAME_UPDATE,
{
component : this
}
);
return;
}
if (property === 'code') {
try {
this.instance = new Function('data', this.code).bind(this);
this.publish(
R3.Event.COMPILE_SUCCESS,
{
component: this
}
)
} catch (error) {
this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this);
this.publish(
R3.Event.COMPILE_FAILED,
{
component: this
}
)
}
return;
}
if (property === 'eventId') {
this.publish(
R3.Event.EVENT_ID_UPDATE,
{
component : this
}
)
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.CustomCode to a new R3.API.CustomCode
* @returns {R3.API.CustomCode}
*/
R3.CustomCode.prototype.toApiObject = function() {
return new R3.API.CustomCode(
this.id,
this.name,
this.eventId,
this.code,
R3.Utils.IdOrNull(this.parentEntity)
);
};
R3.CustomCode.prototype.launchEditor = function(){
R3.Event.Emit(
R3.Event.GET_RUNTIME,
null,
function(runtime) {
this.coder = runtime.coder;
this.coder.isNotCodeMirrorThrow();
}.bind(this)
);
if (this instanceof R3.D3.Shader.Vertex) {
this.editor = this.coder.instance(
document.body,
{
value: this.code,
mode: 'x-shader/x-vertex',
lineNumbers: true,
scrollbarStyle: 'overlay',
indentWithTabs: true,
indentUnit: 4
}
);
} else if (this instanceof R3.D3.Shader.Fragment) {
this.editor = this.coder.instance(
document.body,
{
value: this.code,
mode: 'x-shader/x-fragment',
lineNumbers: true,
scrollbarStyle: 'overlay',
indentWithTabs: true,
indentUnit: 4
}
);
} else {
this.editor = this.coder.instance(
document.body,
{
value: this.code,
mode: 'javascript',
lineNumbers: true,
scrollbarStyle: 'overlay',
indentWithTabs: true,
indentUnit: 4
}
);
}
this.editor.on('change', function(){
this.code = this.editor.getValue();
this.updateInstance('code');
}.bind(this))
};
R3.CustomCode.prototype.closeEditor = function(){
var dom = this.editor.getWrapperElement();
dom.parentElement.removeChild(dom);
};

173
src/r3-d3-api-a-object.js Normal file
View File

@ -0,0 +1,173 @@
/**
* R3.D3.API.Object
* @param id
* @param name
* @param objectType
* @param parentEntity
* @param useQuaternion
* @param position
* @param quaternion
* @param rotation
* @param scale
* @param up
* @param lookAt
* @constructor
*/
R3.D3.API.Object = function(
id,
name,
objectType,
parentEntity,
useQuaternion,
position,
quaternion,
rotation,
scale,
up,
lookAt
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(objectType)) {
objectType = 0;
}
this.objectType = objectType;
if (R3.Utils.UndefinedOrNull(name)) {
switch (this.objectType) {
case R3.D3.API.Object.OBJECT_TYPE_NONE :
name = 'Object';
break;
/**
* Cameras
*/
case R3.D3.API.Object.OBJECT_TYPE_CAMERA :
name = 'Camera';
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
name = 'Camera Orthographic';
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
name = 'Camera Perspective';
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
name = 'Camera Cube';
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
name = 'Camera Stereo';
break;
/**
* Meshes
*/
case R3.D3.API.Object.OBJECT_TYPE_MESH :
name = 'Mesh';
break;
}
name += ' (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(useQuaternion)) {
useQuaternion = true;
}
this.useQuaternion = useQuaternion;
if (R3.Utils.UndefinedOrNull(position)) {
position = new R3.API.Vector3();
}
this.position = position;
if (R3.Utils.UndefinedOrNull(quaternion)) {
quaternion = new R3.API.Quaternion();
}
this.quaternion = quaternion;
if (R3.Utils.UndefinedOrNull(rotation)) {
rotation = new R3.API.Vector3();
}
this.rotation = rotation;
if (R3.Utils.UndefinedOrNull(scale)) {
scale = new R3.API.Vector3(1,1,1);
}
this.scale = scale;
if (R3.Utils.UndefinedOrNull(up)) {
up = new R3.API.Vector3(0,1,0);
}
this.up = up;
if (R3.Utils.UndefinedOrNull(lookAt)) {
lookAt = new R3.API.Vector3();
}
this.lookAt = lookAt;
R3.API.Component.call(
this,
R3.D3.API.Object.GetComponentType(this.objectType),
parentEntity
);
};
R3.D3.API.Object.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Object.prototype.constructor = R3.D3.API.Object;
R3.D3.API.Object.GetComponentType = function(objectType) {
var componentType = null;
switch (objectType) {
case R3.D3.API.Object.OBJECT_TYPE_NONE :
componentType = R3.Component.OBJECT;
break;
/**
* Cameras
*/
case R3.D3.API.Object.OBJECT_TYPE_CAMERA :
componentType = R3.Component.CAMERA;
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
componentType = R3.Component.CAMERA_PERSPECTIVE;
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
componentType = R3.Component.CAMERA_ORTHOGRAPHIC;
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
componentType = R3.Component.CAMERA_STEREO;
break;
case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
componentType = R3.Component.CAMERA_CUBE;
break;
/**
* Meshes
*/
case R3.D3.API.Object.OBJECT_TYPE_MESH :
componentType = R3.Component.MESH;
break;
default:
throw new Error('unsupported camera type: ' + objectType);
}
return componentType;
};
R3.D3.API.Object.OBJECT_TYPE_NONE = 0x0;
/**
* Cameras
* @type {number}
*/
R3.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11;
R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1;
R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2;
R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO = 0x14;//0x3;
R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4;
/**
* Meshes
* @type {number}
*/
R3.D3.API.Object.OBJECT_TYPE_MESH = 0x21;

121
src/r3-d3-api-animation.js Normal file
View File

@ -0,0 +1,121 @@
/**
* Animation Component
* @param id
* @param name
* @param rotationSpeed
* @param translationSpeed
* @param scaleSpeed
* @param rotationFn
* @param translationFn
* @param scaleFn
* @param blocking
* @param applyToMeshWhenDone
* @param meshes
* @param parentEntity
* @constructor
*/
R3.D3.API.Animation = function (
id,
name,
rotationSpeed,
translationSpeed,
scaleSpeed,
rotationFn,
translationFn,
scaleFn,
blocking,
applyToMeshWhenDone,
meshes,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Animation (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(rotationSpeed)) {
rotationSpeed = 0;
}
this.rotationSpeed = rotationSpeed;
if (R3.Utils.UndefinedOrNull(translationSpeed)) {
translationSpeed = 0;
}
this.translationSpeed = translationSpeed;
if (R3.Utils.UndefinedOrNull(scaleSpeed)) {
scaleSpeed = 0;
}
this.scaleSpeed = scaleSpeed;
if (R3.Utils.UndefinedOrNull(rotationFn)) {
rotationFn = null;
}
this.rotationFn = rotationFn;
if (R3.Utils.UndefinedOrNull(translationFn)) {
translationFn = null;
}
this.translationFn = translationFn;
if (R3.Utils.UndefinedOrNull(scaleFn)) {
scaleFn = null;
}
this.scaleFn = scaleFn;
if (R3.Utils.UndefinedOrNull(blocking)) {
blocking = {
position : false, //positions can be blocked from accumulating and executing at once
rotation : true, //rotations need to execute in order
scale : false //scale can accumulate
};
}
this.blocking = blocking;
if (R3.Utils.UndefinedOrNull(applyToMeshWhenDone)) {
applyToMeshWhenDone = true;
}
this.applyToMeshWhenDone = applyToMeshWhenDone;
if (R3.Utils.UndefinedOrNull(meshes)) {
meshes = [];
}
this.meshes = meshes;
R3.API.Component.call(
this,
R3.Component.ANIMATION,
parentEntity
);
};
R3.D3.API.Animation.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Animation.prototype.constructor = R3.D3.API.Animation;
/**
* Object to R3.D3.API.Animation
* @param objectComponent
* @returns {R3.D3.API.Animation}
* @constructor
*/
R3.D3.API.Animation.FromObject = function(objectComponent) {
return new R3.D3.API.Animation(
objectComponent.id,
objectComponent.name,
objectComponent.rotationSpeed,
objectComponent.translationSpeed,
objectComponent.scaleSpeed,
objectComponent.rotationFn,
objectComponent.translationFn,
objectComponent.scaleFn,
objectComponent.blocking,
objectComponent.applyToMeshWhenDone,
objectComponent.meshes,
objectComponent.parentEntity
);
};

104
src/r3-d3-api-audio.js Normal file
View File

@ -0,0 +1,104 @@
/**
* Raw Audio API object - should always correspond with the Audio Schema
* @param id
* @param name
* @param path
* @param loop
* @param volume
* @param camera
* @param overplay
* @param paused
* @param parentEntity
* @constructor
*/
R3.D3.API.Audio = function(
id,
name,
path,
loop,
volume,
camera,
overplay,
paused,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Audio (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(path)) {
path = '';
}
this.path = path;
if (R3.Utils.UndefinedOrNull(loop)) {
loop = false;
}
this.loop = loop;
if (R3.Utils.UndefinedOrNull(volume)) {
volume = 0.5;
}
this.volume = volume;
if (R3.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (R3.Utils.UndefinedOrNull(overplay)) {
overplay = false;
}
this.overplay = overplay;
if (R3.Utils.UndefinedOrNull(paused)) {
paused = false;
}
this.paused = paused;
R3.API.Component.call(
this,
R3.Component.AUDIO,
parentEntity
);
};
R3.D3.API.Audio.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Audio.prototype.constructor = R3.D3.API.Audio;
/**
* Creates an API Audio from an Object Audio
* @param objectAudio
* @constructor
*/
R3.D3.API.Audio.FromObject = function(objectAudio) {
var apiCamera = null;
if (objectAudio.camera) {
if (objectAudio.camera instanceof Object) {
apiCamera = R3.D3.API.Camera.FromObject(objectAudio.camera);
} else {
apiCamera = objectAudio.camera;
}
}
return new R3.D3.API.Audio(
objectAudio.id,
objectAudio.name,
objectAudio.path,
objectAudio.loop,
objectAudio.volume,
apiCamera,
objectAudio.overplay,
objectAudio.paused,
objectAudio.parentEntity
);
};

View File

@ -0,0 +1,26 @@
/**
* BoneWeight object - associates a vertex to a bone with some weight
* @param boneIndex int
* @param weight float
* @constructor
*/
R3.D3.API.BoneWeight = function (
boneIndex,
weight
) {
this.boneIndex = boneIndex;
this.weight = weight;
};
/**
* Object to R3.D3.API.BoneWeight
* @param objectBoneWeight
* @returns {R3.D3.API.BoneWeight}
* @constructor
*/
R3.D3.API.BoneWeight.FromObject = function(objectBoneWeight) {
return new R3.D3.API.BoneWeight(
objectBoneWeight.boneIndex,
objectBoneWeight.weight
)
};

93
src/r3-d3-api-bone.js Normal file
View File

@ -0,0 +1,93 @@
/**
* Bone Superset
* @param id
* @param name string
* @param childBoneIds
* @param parentBoneIds
* @param quaternion R3.API.Quaternion
* @param position R3.API.Vector3
* @param scale R3.API.Vector3
* @param up R3.API.Vector3
* @param parentEntity
* @constructor
*/
R3.D3.API.Bone = function (
id,
name,
childBoneIds,
parentBoneIds,
position,
quaternion,
scale,
up,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Bone (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(childBoneIds)) {
childBoneIds = [];
}
this.childBoneIds = childBoneIds;
if (R3.Utils.UndefinedOrNull(parentBoneIds)) {
parentBoneIds = [];
}
this.parentBoneIds = parentBoneIds;
if (R3.Utils.UndefinedOrNull(position)) {
position = new R3.API.Vector3();
}
this.position = position;
if (R3.Utils.UndefinedOrNull(quaternion)) {
quaternion = new R3.API.Quaternion();
}
this.quaternion = quaternion;
if (R3.Utils.UndefinedOrNull(scale)) {
scale = new R3.API.Vector3(1,1,1);
}
this.scale = scale;
if (R3.Utils.UndefinedOrNull(up)) {
up = new R3.API.Vector3(0,1,0);
}
this.up = up;
R3.API.Component.call(
this,
R3.Component.BONE,
parentEntity
);
};
R3.D3.API.Bone.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Bone.prototype.constructor = R3.D3.API.Bone;
/**
* Returns an API bone from an Object bone
* @param objectBone
* @constructor
*/
R3.D3.API.Bone.FromObject = function(objectBone) {
return new R3.D3.API.Bone(
objectBone.id,
objectBone.name,
objectBone.childBoneIds,
objectBone.parentBoneIds,
R3.API.Vector3.FromObject(objectBone.position),
R3.API.Quaternion.FromObject(objectBone.quaternion),
R3.API.Vector3.FromObject(objectBone.scale),
R3.API.Vector3.FromObject(objectBone.up),
objectBone.parentEntity
);
};

View File

@ -0,0 +1,54 @@
/**
* Raw Broadphase API object - should always correspond with the Broadphase Schema
* @param id
* @param name
* @param broadphaseType
* @param parentEntity
* @constructor
*/
R3.D3.API.Broadphase = function(
id,
name,
broadphaseType,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Broadphase (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(broadphaseType)) {
broadphaseType = R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE;
}
this.broadphaseType = broadphaseType;
R3.API.Component.call(
this,
R3.Component.BROADPHASE,
parentEntity
);
};
R3.D3.API.Broadphase.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Broadphase.prototype.constructor = R3.D3.API.Broadphase;
/**
* Creates an API Broadphase from an Object Broadphase
* @param objectBroadphase
* @constructor
*/
R3.D3.API.Broadphase.FromObject = function(objectBroadphase) {
return new R3.D3.API.Broadphase(
objectBroadphase.id,
objectBroadphase.name,
objectBroadphase.broadphaseType,
objectBroadphase.parentEntity
);
};

52
src/r3-d3-api-camera-a.js Normal file
View File

@ -0,0 +1,52 @@
/**
* R3.D3.API.Camera
* @param apiD3Object
* @param aspect
* @constructor
*/
R3.D3.API.Camera = function(
apiD3Object,
aspect
) {
if (R3.Utils.UndefinedOrNull(apiD3Object)) {
apiD3Object = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA
};
}
if (R3.Utils.UndefinedOrNull(apiD3Object.objectType)) {
apiD3Object.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA;
}
if (R3.Utils.UndefinedOrNull(aspect)) {
aspect = 1;
}
this.aspect = aspect;
if (R3.Utils.UndefinedOrNull(apiD3Object.position)) {
apiD3Object.position = new R3.API.Vector3(
15,
15,
15
);
}
R3.D3.API.Object.call(
this,
apiD3Object.id,
apiD3Object.name,
apiD3Object.objectType,
apiD3Object.parentEntity,
apiD3Object.useQuaternion,
apiD3Object.position,
apiD3Object.quaternion,
apiD3Object.rotation,
apiD3Object.scale,
apiD3Object.up,
apiD3Object.lookAt
);
};
R3.D3.API.Camera.prototype = Object.create(R3.D3.API.Object.prototype);
R3.D3.API.Camera.prototype.constructor = R3.D3.API.Camera;

View File

@ -0,0 +1,59 @@
/**
* R3.D3.API.Camera.Cube
* @constructor
* @param apiD3ObjectCamera
* @param near
* @param far
* @param cubeResolution
* @param renderTarget
*/
R3.D3.API.Camera.Cube = function(
apiD3ObjectCamera,
near,
far,
cubeResolution,
renderTarget
) {
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
apiD3ObjectCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE
};
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE;
}
if (R3.Utils.UndefinedOrNull(near)) {
near = 0.1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
far = 2000;
}
this.far = far;
if (R3.Utils.UndefinedOrNull(cubeResolution)) {
cubeResolution = 128;
}
this.cubeResolution = cubeResolution;
if (R3.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
}
this.renderTarget = renderTarget;
/**
* CubeCamera's have hardcoded fov=90 and aspect=1
*/
R3.D3.API.Camera.call(
this,
apiD3ObjectCamera,
apiD3ObjectCamera.aspect
);
};
R3.D3.API.Camera.Cube.prototype = Object.create(R3.D3.API.Camera.prototype);
R3.D3.API.Camera.Cube.prototype.constructor = R3.D3.API.Camera.Cube;

View File

@ -0,0 +1,144 @@
/**
* R3.D3.API.Camera.Orthographic
*
* OK - since the introduction of fixed aspect ratio's for our canvases, we only need to know
* the aspect ratio and width - then we calculate the left, right, up and down coords -
*
* for the Z space - we simply use the values in near and far - you should know what you are doing when you
* create an orthographic camera
*
* There are two ways to update the camera - one is by affecting the aspect ratio - the other is modifying the left,
* right, top and bottom values - this also affects the aspect ratio.
*
* In both modes - the camera is assumed to be at position 0,0,10 and facing direction 0,0,-1 (in the positive Z facing
* the negative Z direction seeing what happens around the origin)
*
* Also - the offset is always respected
*
* @constructor
* @param apiD3ObjectCamera
* @param aspectRatioMode
* @param minWidth
* @param minHeight
* @param width
* @param height
* @param near
* @param far
* @param left
* @param right
* @param top
* @param bottom
* @param zoom
*/
R3.D3.API.Camera.Orthographic = function(
apiD3ObjectCamera,
aspectRatioMode,
minWidth,
minHeight,
width,
height,
near,
far,
left,
right,
top,
bottom,
zoom
) {
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
apiD3ObjectCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC
};
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC;
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) {
apiD3ObjectCamera.position = new R3.API.Vector3(0,0,10);
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) {
apiD3ObjectCamera.lookAt = new R3.API.Vector3(0,0,-10);
}
if (R3.Utils.UndefinedOrNull(aspectRatioMode)) {
aspectRatioMode = R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT;
}
this.aspectRatioMode = aspectRatioMode;
if (R3.Utils.UndefinedOrNull(minWidth)) {
minWidth = 10;
}
this.minWidth = minWidth;
if (R3.Utils.UndefinedOrNull(minHeight)) {
minHeight = 10;
}
this.minHeight = minHeight;
if (R3.Utils.UndefinedOrNull(height)) {
height = 10;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(width)) {
width = 10;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 10;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(near)) {
near = 0.1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
far = 2000;
}
this.far = far;
if (R3.Utils.UndefinedOrNull(left)) {
left = -5;
}
this.left = left;
if (R3.Utils.UndefinedOrNull(right)) {
right = 5;
}
this.right = right;
if (R3.Utils.UndefinedOrNull(top)) {
top = 5;
}
this.top = top;
if (R3.Utils.UndefinedOrNull(bottom)) {
bottom = -5;
}
this.bottom = bottom;
if (R3.Utils.UndefinedOrNull(zoom)) {
zoom = 1;
}
this.zoom = zoom;
R3.D3.API.Camera.call(
this,
apiD3ObjectCamera,
apiD3ObjectCamera.aspect
);
};
R3.D3.API.Camera.Orthographic.prototype = Object.create(R3.D3.API.Camera.prototype);
R3.D3.API.Camera.Orthographic.prototype.constructor = R3.D3.API.Camera.Orthographic;
R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0;
R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1;
R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2;

View File

@ -0,0 +1,84 @@
/**
* R3.D3.API.Camera.Perspective
* @constructor
* @param apiD3ObjectCamera
* @param fov
* @param near
* @param far
* @param filmGauge
* @param filmOffset
* @param focus
* @param zoom
*/
R3.D3.API.Camera.Perspective = function(
apiD3ObjectCamera,
near,
far,
fov,
filmGauge,
filmOffset,
focus,
zoom
) {
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
apiD3ObjectCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
};
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE;
}
if (R3.Utils.UndefinedOrNull(near)) {
// near = new R3.API.Number(0.1, 0.001, 0.001, 2000);
near = 0.1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
// far = new R3.API.Number(2000, 1, 1, 4000);
far = 2000;
}
this.far = far;
if (R3.Utils.UndefinedOrNull(fov)) {
// fov = new R3.API.Number(50, 1, 0, 180);
fov = 50;
}
this.fov = fov;
if (R3.Utils.UndefinedOrNull(filmGauge)) {
// filmGauge = new R3.API.Number(35, 1, 0, 200);
filmGauge = 35;
}
this.filmGauge = filmGauge;
if (R3.Utils.UndefinedOrNull(filmOffset)) {
// filmOffset = new R3.API.Number(0, 1, 0, 200);
filmOffset = 0;
}
this.filmOffset = filmOffset;
if (R3.Utils.UndefinedOrNull(focus)) {
// focus = new R3.API.Number(10, 0.1, 0, 200);
focus = 10;
}
this.focus = focus;
if (R3.Utils.UndefinedOrNull(zoom)) {
// zoom = new R3.API.Number(1, 0.01, 0, 10);
zoom = 1;
}
this.zoom = zoom;
R3.D3.API.Camera.call(
this,
apiD3ObjectCamera,
apiD3ObjectCamera.aspect
);
};
R3.D3.API.Camera.Perspective.prototype = Object.create(R3.D3.API.Camera.prototype);
R3.D3.API.Camera.Perspective.prototype.constructor = R3.D3.API.Camera.Perspective;

View File

@ -0,0 +1,40 @@
/**
* R3.D3.API.Camera.Stereo
* @constructor
* @param apiD3ObjectCamera
* @param stereoMode
*/
R3.D3.API.Camera.Stereo = function(
apiD3ObjectCamera,
stereoMode
) {
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
apiD3ObjectCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO
};
}
if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO;
}
if (R3.Utils.UndefinedOrNull(stereoMode)) {
stereoMode = R3.D3.API.Camera.Stereo.STEREO_MODE_STEREO;
}
this.stereoMode = stereoMode;
R3.D3.API.Camera.call(
this,
apiD3ObjectCamera,
apiD3ObjectCamera.aspect
);
};
R3.D3.API.Camera.Stereo.prototype = Object.create(R3.D3.API.Camera.prototype);
R3.D3.API.Camera.Stereo.prototype.constructor = R3.D3.API.Camera.Stereo;
R3.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1;
R3.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2;
R3.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3;

73
src/r3-d3-api-composer.js Normal file
View File

@ -0,0 +1,73 @@
/**
* R3.D3.API.Composer
* @param id
* @param name
* @param parentEntity
* @param autoUpdateSize
* @param width
* @param height
* @param renderer
* @param renderTarget
* @param passes
* @constructor
*/
R3.D3.API.Composer = function (
id,
name,
parentEntity,
autoUpdateSize,
width,
height,
renderer,
renderTarget,
passes
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Composer (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(autoUpdateSize)) {
autoUpdateSize = true;
}
this.autoUpdateSize = autoUpdateSize;
if (R3.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
this.renderer = renderer;
if (R3.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = null;
}
this.renderTarget = renderTarget;
if (R3.Utils.UndefinedOrNull(passes)) {
passes = [];
}
this.passes = passes;
R3.API.Component.call(
this,
R3.Component.COMPOSER,
parentEntity
);
};
R3.D3.API.Composer.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Composer.prototype.constructor = R3.D3.API.Composer;

100
src/r3-d3-api-effect-a.js Normal file
View File

@ -0,0 +1,100 @@
/**
* R3.D3.API.Effect
* @param id
* @param name
* @param effectType
* @param parentEntity
* @param renderer
* @param width
* @param height
*
* @property effectType
*
* @constructor
*/
R3.D3.API.Effect = function(
id,
name,
effectType,
parentEntity,
renderer,
width,
height
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(effectType)) {
effectType = R3.D3.API.Effect.EFFECT_TYPE_NONE;
}
this.effectType = effectType;
if (R3.Utils.UndefinedOrNull(name)) {
switch (this.effectType) {
case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH :
name = 'Effect Anaglyph';
break;
case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX :
name = 'Effect Parallax';
break;
case R3.D3.API.Effect.EFFECT_TYPE_STEREO :
name = 'Effect Stereo';
break;
default :
console.warn('no nice name for effect');
name = 'Effect';
}
name += ' (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
this.renderer = renderer;
if (R3.Utils.UndefinedOrNull(width)) {
width = 512;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 512;
}
this.height = height;
var componentType = null;
switch (this.effectType) {
case R3.D3.API.Effect.EFFECT_TYPE_STEREO :
componentType = R3.Component.EFFECT_STEREO;
break;
case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH :
componentType = R3.Component.EFFECT_ANAGLYPH;
break;
case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX :
componentType = R3.Component.EFFECT_PARALLAX;
break;
default:
throw new Error('unsupported effect type: ' + this.effectType);
}
R3.API.Component.call(
this,
componentType,
parentEntity
);
};
R3.D3.API.Effect.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Effect.prototype.constructor = R3.D3.API.Effect;
R3.D3.API.Effect.EFFECT_TYPE_NONE = 0x0;
R3.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1;
R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2;
R3.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3;

View File

@ -0,0 +1,34 @@
/**
* R3.D3.API.Effect.Anaglyph
* @constructor
* @param apiEffect
*/
R3.D3.API.Effect.Anaglyph = function(
apiEffect
) {
if (R3.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH
};
}
if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH;
}
R3.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
R3.D3.API.Effect.Anaglyph.prototype = Object.create(R3.D3.API.Effect.prototype);
R3.D3.API.Effect.Anaglyph.prototype.constructor = R3.D3.API.Effect.Anaglyph;

View File

@ -0,0 +1,34 @@
/**
* R3.D3.API.Effect.Parallax
* @constructor
* @param apiEffect
*/
R3.D3.API.Effect.Parallax = function(
apiEffect
) {
if (R3.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_PARALLAX
};
}
if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_PARALLAX;
}
R3.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
R3.D3.API.Effect.Parallax.prototype = Object.create(R3.D3.API.Effect.prototype);
R3.D3.API.Effect.Parallax.prototype.constructor = R3.D3.API.Effect.Parallax;

View File

@ -0,0 +1,41 @@
/**
* R3.D3.API.Effect.Stereo
* @constructor
* @param apiEffect
* @param eyeSeperation
*/
R3.D3.API.Effect.Stereo = function(
apiEffect,
eyeSeperation
) {
if (R3.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_STEREO
};
}
if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) {
apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_STEREO;
}
if (R3.Utils.UndefinedOrNull(eyeSeperation)) {
eyeSeperation = 0.064;
}
this.eyeSeperation = eyeSeperation;
R3.D3.API.Effect.call(
this,
apiEffect.id,
apiEffect.name,
apiEffect.effectType,
apiEffect.parentEntity,
apiEffect.renderer,
apiEffect.width,
apiEffect.height
);
};
R3.D3.API.Effect.Stereo.prototype = Object.create(R3.D3.API.Effect.prototype);
R3.D3.API.Effect.Stereo.prototype.constructor = R3.D3.API.Effect.Stereo;

243
src/r3-d3-api-face.js Normal file
View File

@ -0,0 +1,243 @@
/**
* Face
* @param id
* @param name
* @param v0index
* @param v1index
* @param v2index
* @param materialIndex
* @param uvs [[v0uv (R3.Vector2), v1uv(R3.Vector2), v2uv(R3.Vector2)]]
* @param color
* @param vertexColors
* @param vertexNormals
* @param normal
* @param selected
* @param parentGeometry
* @param parentEntity
* @constructor
*/
R3.D3.API.Face = function(
id,
name,
v0index,
v1index,
v2index,
materialIndex,
uvs,
color,
vertexColors,
vertexNormals,
normal,
selected,
parentGeometry,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Face ' + id;
}
this.name = name;
if (R3.Utils.UndefinedOrNull(v0index)) {
v0index = -1;
}
this.v0index = v0index;
if (R3.Utils.UndefinedOrNull(v1index)) {
v1index = -1;
}
this.v1index = v1index;
if (R3.Utils.UndefinedOrNull(v2index)) {
v2index = -1;
}
this.v2index = v2index;
if (R3.Utils.UndefinedOrNull(materialIndex)) {
materialIndex = -1;
}
this.materialIndex = materialIndex;
if (R3.Utils.UndefinedOrNull(uvs)) {
uvs = [[]];
}
this.uvs = uvs;
if (R3.Utils.UndefinedOrNull(color)) {
color = new R3.API.Color();
}
this.color = color;
if (R3.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = [
new R3.API.Color(),
new R3.API.Color(),
new R3.API.Color()
];
}
this.vertexColors = vertexColors;
if (R3.Utils.UndefinedOrNull(vertexNormals)) {
vertexNormals = [];
}
this.vertexNormals = vertexNormals;
if (R3.Utils.UndefinedOrNull(normal)) {
normal = null;
}
this.normal = normal;
if (R3.Utils.UndefinedOrNull(selected)) {
selected = false;
}
this.selected = selected;
if (R3.Utils.UndefinedOrNull(parentGeometry)) {
parentGeometry = null;
}
this.parentGeometry = parentGeometry;
R3.API.Component.call(
this,
R3.Component.FACE,
parentEntity
);
};
/**
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
*/
R3.D3.API.Face.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Face.prototype.constructor = R3.D3.API.Face;
/**
* Returns an API Face from a data object
* @constructor
* @param objectFace
*/
// R3.D3.API.Face.FromObject = function(objectFace) {
//
// var apiUvs = objectFace.uvs.reduce(
//
// function(result, uvArray, index) {
//
// result[index] = uvArray.reduce(
// function(uvResult, uv) {
// uvResult.push(R3.API.Vector2.FromObject(uv));
// return uvResult;
// },
// []
// );
//
// return result;
// },
// []
// );
//
// var apiVertexColors = objectFace.vertexColors.map(
// function(vertexColor) {
// return R3.API.Color.FromObject(vertexColor);
// }
// );
//
// var apiColor = null;
// if (objectFace.color) {
// apiColor = R3.API.Color.FromObject(objectFace.color);
// }
//
// var apiVertexNormals = objectFace.vertexNormals.map(
// function(vertexNormal) {
// return R3.API.Vector3.FromObject(vertexNormal);
// }
// );
//
// var apiNormal = null;
// if (objectFace.normal) {
// apiNormal = R3.API.Vector3.FromObject(objectFace.normal);
// }
//
// return new R3.D3.API.Face(
// objectFace.id,
// objectFace.name,
// objectFace.v0index,
// objectFace.v1index,
// objectFace.v2index,
// objectFace.materialIndex,
// apiUvs,
// apiColor,
// apiVertexColors,
// apiVertexNormals,
// apiNormal
// );
// };
//
/**
* Clone a Face
* @returns {R3.D3.API.Face}
*/
R3.D3.API.Face.prototype.clone = function(){
return new R3.D3.API.Face(
this.id,
this.name,
this.v0index,
this.v1index,
this.v2index,
this.materialIndex,
this.uvs,
this.color,
this.vertexColors,
this.vertexNormals,
this.normal
);
};
/**
* Returns true if two triangles are equal (their vertex indices match in some order)
* @param triangle
* @returns {boolean}
*/
R3.D3.API.Face.prototype.equals = function(triangle) {
return (
(
(this.v0index === triangle.v0index) &&
(this.v1index === triangle.v1index) &&
(this.v2index === triangle.v2index)
)
||
(
(this.v0index === triangle.v0index) &&
(this.v1index === triangle.v2index) &&
(this.v2index === triangle.v1index)
)
||
(
(this.v0index === triangle.v1index) &&
(this.v1index === triangle.v0index) &&
(this.v2index === triangle.v2index)
)
||
(
(this.v0index === triangle.v1index) &&
(this.v1index === triangle.v2index) &&
(this.v2index === triangle.v0index)
)
||
(
(this.v0index === triangle.v2index) &&
(this.v1index === triangle.v0index) &&
(this.v2index === triangle.v1index)
)
||
(
(this.v0index === triangle.v2index) &&
(this.v1index === triangle.v1index) &&
(this.v2index === triangle.v0index)
)
);
};

67
src/r3-d3-api-fog.js Normal file
View File

@ -0,0 +1,67 @@
/**
* Raw Fog API object - should always correspond with the Fog Schema
* @param id String
* @param name String
* @param exponential
* @param color
* @param near
* @param far
* @param density
* @param parentEntity
* @constructor
*/
R3.D3.API.Fog = function(
id,
name,
exponential,
color,
near,
far,
density,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Fog (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(exponential)) {
exponential = false;
}
this.exponential = exponential;
if (R3.Utils.UndefinedOrNull(color)) {
color = new R3.API.Color(1, 1, 1, 1)
}
this.color = color;
if (R3.Utils.UndefinedOrNull(near)) {
near = 1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
far = 1000;
}
this.far = far;
if (R3.Utils.UndefinedOrNull(density)) {
density = 0.00025;
}
this.density = density;
R3.API.Component.call(
this,
R3.Component.FOG,
parentEntity
);
};
R3.D3.API.Fog.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Fog.prototype.constructor = R3.D3.API.Fog;

52
src/r3-d3-api-font.js Normal file
View File

@ -0,0 +1,52 @@
/**
* Raw Font API object - should always correspond with the Font Schema
* @param id
* @param name
* @param url
* @param parentEntity
* @constructor
*/
R3.D3.API.Font = function(
id,
name,
url,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Font (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(url)) {
url = '/apiRelative/path/to/font';
}
this.url = url;
R3.API.Component.call(
this,
R3.Component.FONT,
parentEntity
);
};
R3.D3.API.Font.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Font.prototype.constructor = R3.D3.API.Font;
/**
* Returns an API light from an Object light
* @param objectFont
* @constructor
*/
R3.D3.API.Font.FromObject = function(objectFont) {
return new R3.D3.API.Font(
objectFont.id,
objectFont.name,
objectFont.url,
objectFont.parentEntity
);
};

View File

@ -0,0 +1,102 @@
/**
* Raw FrictionContactMaterial API object - should always correspond with the FrictionContactMaterial Schema
* @param id
* @param name
* @param materials
* @param friction
* @param restitution
* @param contactEquationStiffness
* @param contactEquationRelaxation
* @param frictionEquationStiffness
* @param frictionEquationRelaxation
* @param parentEntity
* @constructor
*/
R3.D3.API.FrictionContactMaterial = function(
id,
name,
materials,
friction,
restitution,
contactEquationStiffness,
contactEquationRelaxation,
frictionEquationStiffness,
frictionEquationRelaxation,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Friction Material (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(materials)) {
materials = [];
}
this.materials = materials;
if (R3.Utils.UndefinedOrNull(friction)) {
friction = 0.3;
}
this.friction = friction;
if (R3.Utils.UndefinedOrNull(restitution)) {
restitution = 0.3;
}
this.restitution = restitution;
if (R3.Utils.UndefinedOrNull(contactEquationStiffness)) {
contactEquationStiffness = 1e7;
}
this.contactEquationStiffness = contactEquationStiffness;
if (R3.Utils.UndefinedOrNull(contactEquationRelaxation)) {
contactEquationRelaxation = 3;
}
this.contactEquationRelaxation = contactEquationRelaxation;
if (R3.Utils.UndefinedOrNull(frictionEquationStiffness)) {
frictionEquationStiffness = 1e7;
}
this.frictionEquationStiffness = frictionEquationStiffness;
if (R3.Utils.UndefinedOrNull(frictionEquationRelaxation)) {
frictionEquationRelaxation = 3;
}
this.frictionEquationRelaxation = frictionEquationRelaxation;
R3.API.Component.call(
this,
R3.Component.FRICTION_CONTACT_MATERIAL,
parentEntity
);
};
R3.D3.API.FrictionContactMaterial.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.FrictionContactMaterial.prototype.constructor = R3.D3.API.FrictionContactMaterial;
/**
* Creates an API FrictionContactMaterial from an Object FrictionContactMaterial
* @param objectFrictionContactMaterial
* @constructor
*/
R3.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMaterial) {
return new R3.D3.API.FrictionContactMaterial(
objectFrictionContactMaterial.id,
objectFrictionContactMaterial.name,
objectFrictionContactMaterial.materials,
objectFrictionContactMaterial.friction,
objectFrictionContactMaterial.restitution,
objectFrictionContactMaterial.contactEquationStiffness,
objectFrictionContactMaterial.contactEquationRelaxation,
objectFrictionContactMaterial.frictionEquationStiffness,
objectFrictionContactMaterial.frictionEquationRelaxation,
objectFrictionContactMaterial.parentEntity
);
};

View File

@ -0,0 +1,62 @@
/**
* Raw FrictionMaterial API object - should always correspond with the FrictionMaterial Schema
* @param id
* @param name
* @param friction
* @param restitution
* @param parentEntity
* @constructor
*/
R3.D3.API.FrictionMaterial = function(
id,
name,
friction,
restitution,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Friction Material (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(friction)) {
friction = -1;
}
this.friction = friction;
if (R3.Utils.UndefinedOrNull(restitution)) {
restitution = -1;
}
this.restitution = restitution;
R3.API.Component.call(
this,
R3.Component.FRICTION_MATERIAL,
parentEntity
);
};
R3.D3.API.FrictionMaterial.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.FrictionMaterial.prototype.constructor = R3.D3.API.FrictionMaterial;
/**
* Creates an API FrictionMaterial from an Object FrictionMaterial
* @param objectFrictionMaterial
* @constructor
*/
R3.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) {
return new R3.D3.API.FrictionMaterial(
objectFrictionMaterial.id,
objectFrictionMaterial.name,
objectFrictionMaterial.friction,
objectFrictionMaterial.restitution,
objectFrictionMaterial.parentEntity
);
};

413
src/r3-d3-api-geometry-a.js Normal file
View File

@ -0,0 +1,413 @@
/**
* R3.D3.API.Geometry
* @param id
* @param name
* @param geometryType
* @param parentEntity
* @param parentMesh
* @param boundingBox
* @param boundingSphere
* @param faces
* @param vertices
* @constructor
*/
R3.D3.API.Geometry = function(
id,
name,
geometryType,
parentEntity,
parentMesh,
boundingBox,
boundingSphere,
faces,
vertices
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(geometryType)) {
geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NONE;
}
this.geometryType = geometryType;
if (R3.Utils.UndefinedOrNull(name)) {
switch (this.geometryType) {
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL :
name = 'Geometry';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX :
name = 'Geometry Normal Box';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE :
name = 'Geometry Normal Circle';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE :
name = 'Geometry Normal Cone';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER :
name = 'Geometry Normal Cylinder';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON :
name = 'Geometry Normal Dodecahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES :
name = 'Geometry Normal Edges';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE :
name = 'Geometry Normal Extrude';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON :
name = 'Geometry Normal Icosahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE :
name = 'Geometry Normal Lathe';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON :
name = 'Geometry Normal Octahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC :
name = 'Geometry Normal Parametric';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE :
name = 'Geometry Normal Plane';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON :
name = 'Geometry Normal Polyhedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING :
name = 'Geometry Normal Ring';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE :
name = 'Geometry Normal Shape';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE :
name = 'Geometry Normal Sphere';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON :
name = 'Geometry Normal Tetrahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT :
name = 'Geometry Normal Text';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS :
name = 'Geometry Normal Torus';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT :
name = 'Geometry Normal Torus Knot';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE :
name = 'Geometry Normal Tube';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME :
name = 'Geometry Normal Wireframe';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER :
name = 'Geometry Buffer';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX :
name = 'Geometry Buffer Box';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE :
name = 'Geometry Buffer Circle';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE :
name = 'Geometry Buffer Cone';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER :
name = 'Geometry Buffer Cylinder';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON :
name = 'Geometry Buffer Dodecahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE :
name = 'Geometry Buffer Extrude';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON :
name = 'Geometry Buffer Icosahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE :
name = 'Geometry Buffer Lathe';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON :
name = 'Geometry Buffer Octahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC :
name = 'Geometry Buffer Parametric';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE :
name = 'Geometry Buffer Plane';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON :
name = 'Geometry Buffer Polyhedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING :
name = 'Geometry Buffer Ring';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE :
name = 'Geometry Buffer Shape';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE :
name = 'Geometry Buffer Sphere';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON :
name = 'Geometry Buffer Tetrahedron';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT :
name = 'Geometry Buffer Text';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS :
name = 'Geometry Buffer Torus';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT :
name = 'Geometry Buffer Torus Knot';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE :
name = 'Geometry Buffer Tube';
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED :
name = 'Geometry Buffer Instanced';
break;
default :
console.warn('no nice name for geometry');
name = 'Geometry';
}
name += ' (' + id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(parentMesh)) {
parentMesh = null;
}
this.parentMesh = parentMesh;
if (R3.Utils.UndefinedOrNull(boundingBox)) {
boundingBox = new R3.API.Box3();
}
this.boundingBox = boundingBox;
if (R3.Utils.UndefinedOrNull(boundingSphere)) {
boundingSphere = new R3.API.Sphere();
}
this.boundingSphere = boundingSphere;
if (R3.Utils.UndefinedOrNull(faces)) {
faces = [];
}
this.faces = faces;
if (R3.Utils.UndefinedOrNull(vertices)) {
vertices = [];
}
this.vertices = vertices;
R3.API.Component.call(
this,
R3.D3.API.Geometry.GetComponentType(this.geometryType),
parentEntity
);
};
R3.D3.API.Geometry.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Geometry.prototype.constructor = R3.D3.API.Geometry;
R3.D3.API.Geometry.GetComponentType = function(geometryType) {
var componentType = null;
switch (geometryType) {
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL :
componentType = R3.Component.GEOMETRY_NORMAL;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX :
componentType = R3.Component.GEOMETRY_NORMAL_BOX;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE :
componentType = R3.Component.GEOMETRY_NORMAL_CIRCLE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE :
componentType = R3.Component.GEOMETRY_NORMAL_CONE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER :
componentType = R3.Component.GEOMETRY_NORMAL_CYLINDER;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON :
componentType = R3.Component.GEOMETRY_NORMAL_DODECAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES :
componentType = R3.Component.GEOMETRY_NORMAL_EDGES;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE :
componentType = R3.Component.GEOMETRY_NORMAL_EXTRUDE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON :
componentType = R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE :
componentType = R3.Component.GEOMETRY_NORMAL_LATHE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON :
componentType = R3.Component.GEOMETRY_NORMAL_OCTAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC :
componentType = R3.Component.GEOMETRY_NORMAL_PARAMETRIC;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE :
componentType = R3.Component.GEOMETRY_NORMAL_PLANE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON :
componentType = R3.Component.GEOMETRY_NORMAL_POLYHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING :
componentType = R3.Component.GEOMETRY_NORMAL_RING;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE :
componentType = R3.Component.GEOMETRY_NORMAL_SHAPE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE :
componentType = R3.Component.GEOMETRY_NORMAL_SPHERE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON :
componentType = R3.Component.GEOMETRY_NORMAL_TETRAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT :
componentType = R3.Component.GEOMETRY_NORMAL_TEXT;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS :
componentType = R3.Component.GEOMETRY_NORMAL_TORUS;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT :
componentType = R3.Component.GEOMETRY_NORMAL_TORUS_KNOT;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE :
componentType = R3.Component.GEOMETRY_NORMAL_TUBE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME :
componentType = R3.Component.GEOMETRY_NORMAL_WIREFRAME;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER :
componentType = R3.Component.GEOMETRY_BUFFER;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX :
componentType = R3.Component.GEOMETRY_BUFFER_BOX;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE :
componentType = R3.Component.GEOMETRY_BUFFER_CIRCLE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE :
componentType = R3.Component.GEOMETRY_BUFFER_CONE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER :
componentType = R3.Component.GEOMETRY_BUFFER_CYLINDER;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON :
componentType = R3.Component.GEOMETRY_BUFFER_DODECAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE :
componentType = R3.Component.GEOMETRY_BUFFER_EXTRUDE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON :
componentType = R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE :
componentType = R3.Component.GEOMETRY_BUFFER_LATHE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON :
componentType = R3.Component.GEOMETRY_BUFFER_OCTAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC:
componentType = R3.Component.GEOMETRY_BUFFER_PARAMETRIC;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE :
componentType = R3.Component.GEOMETRY_BUFFER_PLANE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON :
componentType = R3.Component.GEOMETRY_BUFFER_POLYHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING:
componentType = R3.Component.GEOMETRY_BUFFER_RING;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE :
componentType = R3.Component.GEOMETRY_BUFFER_SHAPE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE :
componentType = R3.Component.GEOMETRY_BUFFER_SPHERE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON :
componentType = R3.Component.GEOMETRY_BUFFER_TETRAHEDRON;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT :
componentType = R3.Component.GEOMETRY_BUFFER_TEXT;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS :
componentType = R3.Component.GEOMETRY_BUFFER_TORUS;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT :
componentType = R3.Component.GEOMETRY_BUFFER_TORUS_KNOT;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE :
componentType = R3.Component.GEOMETRY_BUFFER_TUBE;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED :
componentType = R3.Component.GEOMETRY_BUFFER_INSTANCED;
break;
default:
throw new Error('unhandled geometry type: ' + geometryType);
}
return componentType;
};
/**
* Geometry Type
* @type {number}
*/
R3.D3.API.Geometry.GEOMETRY_TYPE_NONE = 0x0;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x1;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX = 0x2;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE = 0x3;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE = 0x4;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER = 0x5;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON = 0x6;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES = 0x7;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE = 0x8;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON = 0x9;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE = 0xa;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON = 0xb;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC = 0xc;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE = 0xd;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON = 0xe;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING = 0xf;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE = 0x10;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE = 0x11;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON = 0x12;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT = 0x13;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS = 0x14;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT = 0x15;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE = 0x16;
R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME = 0x17;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER = 0x18;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX = 0x19;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE = 0x1a;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE = 0x1b;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER = 0x1c;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON = 0x1d;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE = 0x1e;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON = 0x1f;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE = 0x20;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON = 0x21;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC = 0x22;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE = 0x23;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON = 0x24;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING = 0x25;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE = 0x26;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE = 0x27;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON = 0x28;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT = 0x29;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS = 0x2a;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT = 0x2b;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE = 0x2c;
R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED = 0x2d;

View File

@ -0,0 +1,69 @@
/**
* R3.D3.API.Geometry.Buffer
* @param apiGeometry
* @param attributes
* @param drawRange
* @param groups
* @param index
* @param morphAttributes
* @constructor
*/
R3.D3.API.Geometry.Buffer = function(
apiGeometry,
attributes,
drawRange,
groups,
index,
morphAttributes
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER;
}
if (R3.Utils.UndefinedOrNull(attributes)) {
attributes = [];
}
this.attributes = attributes;
if (R3.Utils.UndefinedOrNull(groups)) {
groups = [];
}
this.groups = groups;
if (R3.Utils.UndefinedOrNull(drawRange)) {
drawRange = new R3.API.DrawRange()
}
this.drawRange = drawRange;
if (R3.Utils.UndefinedOrNull(index)) {
index = null;
}
this.index = index;
if (R3.Utils.UndefinedOrNull(morphAttributes)) {
morphAttributes = null;
}
this.morphAttributes = morphAttributes;
R3.D3.API.Geometry.call(
this,
apiGeometry.id,
apiGeometry.name,
apiGeometry.geometryType,
apiGeometry.parentEntity,
apiGeometry.parentMesh,
apiGeometry.boundingBox,
apiGeometry.boundingSphere,
apiGeometry.faces,
apiGeometry.vertices
);
};
R3.D3.API.Geometry.Buffer.prototype = Object.create(R3.D3.API.Geometry.prototype);
R3.D3.API.Geometry.Buffer.prototype.constructor = R3.D3.API.Geometry.Buffer;

View File

@ -0,0 +1,74 @@
/**
* R3.D3.API.Geometry.Buffer.Box
* @param apiGeometry
* @param width
* @param height
* @param depth
* @param widthSegments
* @param heightSegments
* @param depthSegments
* @constructor
*/
R3.D3.API.Geometry.Buffer.Box = function(
apiGeometry,
width,
height,
depth,
widthSegments,
heightSegments,
depthSegments
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX;
}
if (R3.Utils.UndefinedOrNull(width)) {
width = 1;
}
this.width = width;
if (R3.Utils.UndefinedOrNull(height)) {
height = 1;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(depth)) {
depth = 1;
}
this.depth = depth;
if (R3.Utils.UndefinedOrNull(widthSegments)) {
widthSegments = 1;
}
this.widthSegments = widthSegments;
if (R3.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 1;
}
this.heightSegments = heightSegments;
if (R3.Utils.UndefinedOrNull(depthSegments)) {
depthSegments = 1;
}
this.depthSegments = depthSegments;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Box.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Box.prototype.constructor = R3.D3.API.Geometry.Buffer.Box;

View File

@ -0,0 +1,60 @@
/**
* R3.D3.API.Geometry.Buffer.Circle
* @param apiGeometry
* @param radius
* @param segments
* @param thetaStart
* @param thetaLength
* @constructor
*/
R3.D3.API.Geometry.Buffer.Circle = function(
apiGeometry,
radius,
segments,
thetaStart,
thetaLength
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE;
}
if (R3.Utils.UndefinedOrNull(radius)) {
radius = 1;
}
this.radius = radius;
if (R3.Utils.UndefinedOrNull(segments)) {
segments = 8;
}
this.segments = segments;
if (R3.Utils.UndefinedOrNull(thetaStart)) {
thetaStart = 0;
}
this.thetaStart = thetaStart;
if (R3.Utils.UndefinedOrNull(thetaLength)) {
thetaLength = Math.PI * 2;
}
this.thetaLength = thetaLength;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Circle.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Circle.prototype.constructor = R3.D3.API.Geometry.Buffer.Circle;

View File

@ -0,0 +1,81 @@
/**
* R3.D3.API.Geometry.Buffer.Cone
* @param apiGeometry
* @param radius
* @param height
* @param radialSegments
* @param heightSegments
* @param openEnded
* @param thetaStart
* @param thetaLength
* @constructor
*/
R3.D3.API.Geometry.Buffer.Cone = function(
apiGeometry,
radius,
height,
radialSegments,
heightSegments,
openEnded,
thetaStart,
thetaLength
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE;
}
if (R3.Utils.UndefinedOrNull(radius)) {
radius = 1;
}
this.radius = radius;
if (R3.Utils.UndefinedOrNull(height)) {
height = 100;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(radialSegments)) {
radialSegments = 8;
}
this.radialSegments = radialSegments;
if (R3.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 1;
}
this.heightSegments = heightSegments;
if (R3.Utils.UndefinedOrNull(openEnded)) {
openEnded = false;
}
this.openEnded = openEnded;
if (R3.Utils.UndefinedOrNull(thetaStart)) {
thetaStart = 0;
}
this.thetaStart = thetaStart;
if (R3.Utils.UndefinedOrNull(thetaLength)) {
thetaLength = Math.PI * 2;
}
this.thetaLength = thetaLength;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Cone.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Cone.prototype.constructor = R3.D3.API.Geometry.Buffer.Cone;

View File

@ -0,0 +1,88 @@
/**
* R3.D3.API.Geometry.Buffer.Cylinder
* @param apiGeometry
* @param radiusTop
* @param radiusBottom
* @param height
* @param radialSegments
* @param heightSegments
* @param openEnded
* @param thetaStart
* @param thetaLength
* @constructor
*/
R3.D3.API.Geometry.Buffer.Cylinder = function(
apiGeometry,
radiusTop,
radiusBottom,
height,
radialSegments,
heightSegments,
openEnded,
thetaStart,
thetaLength
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER;
}
if (R3.Utils.UndefinedOrNull(radiusTop)) {
radiusTop = 1;
}
this.radiusTop = radiusTop;
if (R3.Utils.UndefinedOrNull(radiusBottom)) {
radiusBottom = 1;
}
this.radiusBottom = radiusBottom;
if (R3.Utils.UndefinedOrNull(height)) {
height = 100;
}
this.height = height;
if (R3.Utils.UndefinedOrNull(radialSegments)) {
radialSegments = 8;
}
this.radialSegments = radialSegments;
if (R3.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 1;
}
this.heightSegments = heightSegments;
if (R3.Utils.UndefinedOrNull(openEnded)) {
openEnded = false;
}
this.openEnded = openEnded;
if (R3.Utils.UndefinedOrNull(thetaStart)) {
thetaStart = 0;
}
this.thetaStart = thetaStart;
if (R3.Utils.UndefinedOrNull(thetaLength)) {
thetaLength = Math.PI * 2;
}
this.thetaLength = thetaLength;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Cylinder.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Cylinder.prototype.constructor = R3.D3.API.Geometry.Buffer.Cylinder;

View File

@ -0,0 +1,46 @@
/**
* R3.D3.API.Geometry.Buffer.Dodecahedron
* @param apiGeometry
* @param radius
* @param detail
* @constructor
*/
R3.D3.API.Geometry.Buffer.Dodecahedron = function(
apiGeometry,
radius,
detail
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON;
}
if (R3.Utils.UndefinedOrNull(radius)) {
radius = 1;
}
this.radius = radius;
if (R3.Utils.UndefinedOrNull(detail)) {
detail = 0;
}
this.detail = detail;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Dodecahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Dodecahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Dodecahedron;

View File

@ -0,0 +1,104 @@
/**
* R3.D3.API.Geometry.Buffer.Extrude
* @param apiGeometry
* @param shapes
* @param curveSegments
* @param steps
* @param amount
* @param bevelEnabled
* @param bevelThickness
* @param bevelSize
* @param bevelSegments
* @param extrudePath
* @param frames
* @param UVGenerator
* @constructor
*/
R3.D3.API.Geometry.Buffer.Extrude = function(
apiGeometry,
shapes,
curveSegments,
steps,
amount,
bevelEnabled,
bevelThickness,
bevelSize,
bevelSegments,
extrudePath,
frames,
UVGenerator
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE;
}
if (R3.Utils.UndefinedOrNull(shapes)) {
shapes = [];
}
this.shapes = shapes;
if (R3.Utils.UndefinedOrNull(curveSegments)) {
curveSegments = 12;
}
this.curveSegments = curveSegments;
if (R3.Utils.UndefinedOrNull(steps)) {
steps = 1;
}
this.steps = steps;
if (R3.Utils.UndefinedOrNull(amount)) {
amount = 100;
}
this.amount = amount;
if (R3.Utils.UndefinedOrNull(bevelEnabled)) {
bevelEnabled = true;
}
this.bevelEnabled = bevelEnabled;
if (R3.Utils.UndefinedOrNull(bevelThickness)) {
bevelThickness = 6;
}
this.bevelThickness = bevelThickness;
if (R3.Utils.UndefinedOrNull(bevelSegments)) {
bevelSegments = 3;
}
this.bevelSegments = bevelSegments;
if (R3.Utils.UndefinedOrNull(extrudePath)) {
extrudePath = null;
}
this.extrudePath = extrudePath;
if (R3.Utils.UndefinedOrNull(frames)) {
frames = null;
}
this.frames = frames;
if (R3.Utils.UndefinedOrNull(UVGenerator)) {
UVGenerator = null;
}
this.UVGenerator = UVGenerator;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Extrude.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Extrude.prototype.constructor = R3.D3.API.Geometry.Buffer.Extrude;

View File

@ -0,0 +1,46 @@
/**
* R3.D3.API.Geometry.Buffer.Icosahedron
* @param apiGeometry
* @param radius
* @param detail
* @constructor
*/
R3.D3.API.Geometry.Buffer.Icosahedron = function(
apiGeometry,
radius,
detail
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON;
}
if (R3.Utils.UndefinedOrNull(radius)) {
radius = 1;
}
this.radius = radius;
if (R3.Utils.UndefinedOrNull(detail)) {
detail = 0;
}
this.detail = detail;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Icosahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Icosahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Icosahedron;

View File

@ -0,0 +1,39 @@
/**
* R3.D3.API.Geometry.Buffer.Instanced
* @param apiGeometry
* @param maxInstancedCount
* @constructor
*/
R3.D3.API.Geometry.Buffer.Instanced = function(
apiGeometry,
maxInstancedCount
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED;
}
if (R3.Utils.UndefinedOrNull(maxInstancedCount)) {
maxInstancedCount = null;
}
this.maxInstancedCount = maxInstancedCount;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Instanced.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Instanced.prototype.constructor = R3.D3.API.Geometry.Buffer.Instanced;

View File

@ -0,0 +1,60 @@
/**
* R3.D3.API.Geometry.Buffer.Lathe
* @param apiGeometry
* @param points [R3.Vector2] (x must be larger than 0)
* @param segments
* @param phiStart
* @param phiLength
* @constructor
*/
R3.D3.API.Geometry.Buffer.Lathe = function(
apiGeometry,
points,
segments,
phiStart,
phiLength
) {
if (R3.Utils.UndefinedOrNull(apiGeometry)) {
apiGeometry = {
geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE
};
}
if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE;
}
if (R3.Utils.UndefinedOrNull(points)) {
points = [];
}
this.points = points;
if (R3.Utils.UndefinedOrNull(segments)) {
segments = 12;
}
this.segments = segments;
if (R3.Utils.UndefinedOrNull(phiStart)) {
phiStart = 0;
}
this.phiStart = phiStart;
if (R3.Utils.UndefinedOrNull(phiLength)) {
phiLength = Math.PI * 2;
}
this.phiLength = phiLength;
R3.D3.API.Geometry.Buffer.call(
this,
apiGeometry,
apiGeometry.attributes,
apiGeometry.drawRange,
apiGeometry.groups,
apiGeometry.index,
apiGeometry.morphAttributes
);
};
R3.D3.API.Geometry.Buffer.Lathe.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype);
R3.D3.API.Geometry.Buffer.Lathe.prototype.constructor = R3.D3.API.Geometry.Buffer.Lathe;

Some files were not shown because too many files have changed in this diff Show More