beta.r3js.org
parent
a03fe8f983
commit
bb0efcf756
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* GameLib Namespace
|
||||
*/
|
||||
if (typeof GameLib === 'undefined') {
|
||||
function GameLib() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.D3 Namespace
|
||||
*/
|
||||
if (typeof GameLib.D3 === 'undefined') {
|
||||
GameLib.D3 = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.D3.API Namespace
|
||||
* @constructor
|
||||
*/
|
||||
if (typeof GameLib.D3.API === 'undefined') {
|
||||
GameLib.D3.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.API Namespace
|
||||
*/
|
||||
if (typeof GameLib.API === 'undefined') {
|
||||
GameLib.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.D3.Runtime Namespace
|
||||
* @constructor
|
||||
*/
|
||||
if (typeof GameLib.D3.Runtime === 'undefined') {
|
||||
GameLib.D3.Runtime = function(){};
|
||||
}
|
||||
|
||||
// if (typeof Q === 'undefined') {
|
||||
//
|
||||
// if (typeof require === 'undefined') {
|
||||
// console.warn('You need the Q promise library for the GameLib.D3');
|
||||
// throw new Error('You need the Q promise library for the GameLib.D3');
|
||||
// }
|
||||
//
|
||||
// var Q = require('q');
|
||||
// }
|
||||
//
|
||||
// if (typeof _ === 'undefined') {
|
||||
//
|
||||
// if (typeof require === 'undefined') {
|
||||
// console.warn('You need the lodash library for the GameLib.D3');
|
||||
// throw new Error('You need the lodash library for the GameLib.D3');
|
||||
// }
|
||||
//
|
||||
// var _ = require('lodash');
|
||||
// }
|
||||
|
||||
// This gets injected by gulp
|
||||
console.log("Loading GameLib compiled at: " + __DATE__);
|
|
@ -1,486 +0,0 @@
|
|||
/**
|
||||
* Event Core
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Event = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Some nice Events handling
|
||||
* @type {{}}
|
||||
*/
|
||||
GameLib.Event.Subscriptions = {};
|
||||
GameLib.Event.OnceSubscriptions = {};
|
||||
|
||||
/**
|
||||
* Events we can subscribe to and publish
|
||||
*/
|
||||
GameLib.Event.WINDOW_RESIZE = 0x1;
|
||||
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
|
||||
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT = 0x3;
|
||||
GameLib.Event.INSTANCE_CLONED = 0x4;
|
||||
GameLib.Event.LOAD_IMAGE = 0x5;
|
||||
GameLib.Event.NEW_ENTITY = 0x6;
|
||||
GameLib.Event.MATERIAL_TYPE_CHANGED = 0x7;
|
||||
GameLib.Event.SAVE_COMPONENT = 0x8;
|
||||
GameLib.Event.SAVE_COMPONENT_ERROR = 0x9;
|
||||
GameLib.Event.COMPONENT_SAVED = 0xa;
|
||||
GameLib.Event.LOAD_COMPONENT = 0xb;
|
||||
GameLib.Event.LOAD_COMPONENT_ERROR = 0xc;
|
||||
GameLib.Event.LOGGED_IN = 0xd;
|
||||
GameLib.Event.COMPONENT_CREATED = 0xe;
|
||||
GameLib.Event.COMPONENT_CLONED = 0xf;
|
||||
GameLib.Event.TEXTURE_ANIMATED_CHANGE = 0x10;
|
||||
GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
|
||||
GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12;
|
||||
GameLib.Event.GAME_PAUSE = 0x13;
|
||||
GameLib.Event.SHADER_UPDATE = 0x14;
|
||||
GameLib.Event.PLAY_AUDIO = 0x15;
|
||||
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
|
||||
GameLib.Event.PAUSE_AUDIO = 0x17;
|
||||
GameLib.Event.MESH_INSTANCE_UPDATED = 0x18;
|
||||
GameLib.Event.STOP_AUDIO = 0x19;
|
||||
GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1a;
|
||||
GameLib.Event.DELETE_COMPONENT = 0x1b;
|
||||
GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c;
|
||||
GameLib.Event.COMPONENTS_LINKED = 0x1d;
|
||||
GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e;
|
||||
GameLib.Event.REGISTER_UPDATE = 0x1f;
|
||||
GameLib.Event.BUILD_GUI = 0x20;
|
||||
GameLib.Event.REMOVE_MESH = 0x21;
|
||||
GameLib.Event.MESH_SELECTED = 0x22;
|
||||
GameLib.Event.MESH_DESELECTED = 0x23;
|
||||
GameLib.Event.COMPONENT_REGISTER = 0x24;
|
||||
GameLib.Event.IMAGE_NOT_FOUND = 0x25;
|
||||
GameLib.Event.BLENDER_DATA_RECEIVED = 0x26;
|
||||
GameLib.Event.IMAGE_UPLOAD_COMPLETE = 0x27;
|
||||
GameLib.Event.REMOVE_COMPONENT = 0x28;
|
||||
GameLib.Event.KEY_DOWN = 0x29;
|
||||
GameLib.Event.KEY_UP = 0x2a;
|
||||
GameLib.Event.RENDER = 0x2b;
|
||||
GameLib.Event.EVENT_LIST = 0x2c;
|
||||
GameLib.Event.COMPILE_SUCCESS = 0x2d;
|
||||
GameLib.Event.COMPILE_FAILED = 0x2e;
|
||||
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x2f;
|
||||
GameLib.Event.EVENT_ID_UPDATE = 0x30;
|
||||
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
|
||||
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
|
||||
GameLib.Event.COMPONENT_DELETED = 0x33;
|
||||
GameLib.Event.COMPONENT_TYPES_FETCHED = 0x34;
|
||||
GameLib.Event.AUDIO_ENDED = 0x35;
|
||||
GameLib.Event.COMPONENT_LINKED = 0x36;
|
||||
GameLib.Event.DONE_SAVING = 0x37;
|
||||
GameLib.Event.BEFORE_RENDER = 0x38;
|
||||
GameLib.Event.AFTER_RENDER = 0x39;
|
||||
GameLib.Event.ARRAY_ITEM_ADDED = 0x3a;
|
||||
GameLib.Event.INSTANCE_CREATED = 0x3b;
|
||||
GameLib.Event.VISUALIZE = 0x3c;
|
||||
GameLib.Event.STOP_VISUALIZE = 0x3d;
|
||||
GameLib.Event.FETCH_COMPONENT_TYPES = 0x3e;
|
||||
GameLib.Event.FETCH_COMPONENTS = 0x3f;
|
||||
GameLib.Event.GET_API_URL = 0x40;
|
||||
GameLib.Event.GET_RUNTIME = 0x41;
|
||||
GameLib.Event.PARENT_WORLD_CHANGE = 0x42;
|
||||
GameLib.Event.ANIMATE = 0x43;
|
||||
GameLib.Event.ANIMATION_COMPILE_SUCCESS = 0x44;
|
||||
GameLib.Event.ANIMATION_COMPILE_FAILED = 0x45;
|
||||
GameLib.Event.SAVING = 0x46;
|
||||
GameLib.Event.GAME_OVER = 0x47;
|
||||
GameLib.Event.GAME_START = 0x48;
|
||||
GameLib.Event.TOUCH_START = 0x49;
|
||||
GameLib.Event.TOUCH_END = 0x4a;
|
||||
GameLib.Event.TOUCH_MOVE = 0x4b;
|
||||
GameLib.Event.TOUCH_CANCEL = 0x4c;
|
||||
GameLib.Event.GET_REMOTE_API_URL = 0x4d;
|
||||
GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e;
|
||||
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
|
||||
GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
|
||||
GameLib.Event.RESOLVE_DEPENDENCIES = 0x51;
|
||||
GameLib.Event.NAME_UPDATE = 0x52;
|
||||
GameLib.Event.CANVAS_CHANGE = 0x53;
|
||||
GameLib.Event.AFTER_WINDOW_RESIZE = 0x54;
|
||||
GameLib.Event.LOAD_FONT = 0x55;
|
||||
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
||||
GameLib.Event.STOP_ALL_AUDIO = 0x57;
|
||||
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
|
||||
GameLib.Event.GAME_LOADED = 0x59;
|
||||
GameLib.Event.COMPONENT_UPDATE = 0x5a;
|
||||
GameLib.Event.LOAD_PROGRESS = 0x5b;
|
||||
GameLib.Event.ENTITY_LOADED = 0x5c;
|
||||
GameLib.Event.MOUSE_DOWN = 0x5d;
|
||||
GameLib.Event.MOUSE_MOVE = 0x5e;
|
||||
GameLib.Event.MOUSE_WHEEL = 0x5f;
|
||||
GameLib.Event.MOUSE_UP = 0x60;
|
||||
GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
|
||||
GameLib.Event.GAME_DATA = 0x62;
|
||||
GameLib.Event.PAUSE_ALL_AUDIO = 0x63;
|
||||
GameLib.Event.CONTINUE_ALL_AUDIO = 0x64;
|
||||
GameLib.Event.MUTE_AUDIO = 0x65;
|
||||
GameLib.Event.GAME_STARTED = 0x66;
|
||||
GameLib.Event.GAME_PAUSED = 0x67;
|
||||
GameLib.Event.GAME_RESUMED = 0x68;
|
||||
GameLib.Event.CUSTOM_GAME_START = 0x69;
|
||||
GameLib.Event.AUDIO_MUTED = 0x6a;
|
||||
GameLib.Event.AUDIO_UNMUTED = 0x6b;
|
||||
GameLib.Event.RECEIVE_DESTINATION_CHANGED = 0x6c;
|
||||
GameLib.Event.SELECTION_MODE_CHANGE = 0x6d;
|
||||
GameLib.Event.MESH_FACE_SELECTED = 0x6e;
|
||||
GameLib.Event.MESH_FACE_DESELECTED = 0x6f;
|
||||
GameLib.Event.BEFORE_WINDOW_RESIZE = 0x70;
|
||||
GameLib.Event.GET_WINDOW_SIZE = 0x71;
|
||||
GameLib.Event.GET_RENDER_CONFIGURATION = 0x72;
|
||||
GameLib.Event.SET_ACTIVE_RENDER_CONFIGURATION = 0x73;
|
||||
GameLib.Event.REPLACE_COMPONENT = 0x74;
|
||||
GameLib.Event.COMPONENT_REPLACED = 0x75;
|
||||
GameLib.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76;
|
||||
|
||||
/**
|
||||
* Returns string name of event ID
|
||||
* @param number
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Event.prototype.subscribe = function(
|
||||
eventName,
|
||||
callback
|
||||
) {
|
||||
return GameLib.Event.Subscribe(eventName, callback.bind(this));
|
||||
};
|
||||
|
||||
|
||||
// /**
|
||||
// * Stop listening for this event after the callback returns true
|
||||
// * @param eventName
|
||||
// * @param callback
|
||||
// * @returns {{fn, remove: remove}}
|
||||
// */
|
||||
// GameLib.Event.prototype.subscribeOnce = function(
|
||||
// eventName,
|
||||
// callback
|
||||
// ) {
|
||||
// throw new Error('implement first properly');
|
||||
// // var fn = callback.bind(this);
|
||||
// //
|
||||
// // if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) {
|
||||
// // GameLib.Event.OnceSubscriptions[eventName].push(fn);
|
||||
// // } else {
|
||||
// // GameLib.Event.OnceSubscriptions[eventName] = [];
|
||||
// // GameLib.Event.OnceSubscriptions[eventName].push(fn);
|
||||
// // }
|
||||
// //
|
||||
// // /**
|
||||
// // * Return a handle to the caller to allow us to unsubscribe to this event
|
||||
// // */
|
||||
// // return {
|
||||
// // fn : fn,
|
||||
// // remove : function() {
|
||||
// // GameLib.Event.Subscriptions[eventName].splice(
|
||||
// // GameLib.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
|
||||
*/
|
||||
GameLib.Event.prototype.publish = function(
|
||||
eventName,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
) {
|
||||
return GameLib.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
|
||||
*/
|
||||
GameLib.Event.Emit = function(
|
||||
eventName,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
) {
|
||||
|
||||
var count = 0;
|
||||
|
||||
if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) {
|
||||
|
||||
if (GameLib.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 = GameLib.Event.Subscriptions[eventName].length;
|
||||
//
|
||||
// for (var i = 0; i < length; i++) {
|
||||
//
|
||||
// var object = GameLib.Event.Subscriptions[eventName][i];
|
||||
//
|
||||
// if (object.fn && object.executed === false) {
|
||||
// object.fn(data, clientCallback, clientErrorCallback);
|
||||
// object.executed = true;
|
||||
// }
|
||||
//
|
||||
// if (length !== GameLib.Event.Subscriptions[eventName].length) {
|
||||
// /**
|
||||
// * this callback removed a subscription - reset i and reset the length
|
||||
// */
|
||||
// i = 0;
|
||||
// length = GameLib.Event.Subscriptions[eventName].length;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// GameLib.Event.Subscriptions[eventName].map(
|
||||
// function(object){
|
||||
// object.executed = false;
|
||||
// }
|
||||
// )
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.Event.Subscribe = function(
|
||||
eventName,
|
||||
fn
|
||||
) {
|
||||
|
||||
if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) {
|
||||
GameLib.Event.Subscriptions[eventName].push(fn);
|
||||
// {
|
||||
// fn : fn,
|
||||
// executed : false
|
||||
// }
|
||||
// );
|
||||
} else {
|
||||
GameLib.Event.Subscriptions[eventName] = [];
|
||||
GameLib.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 = GameLib.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');
|
||||
}
|
||||
|
||||
GameLib.Event.Subscriptions[eventName].splice(
|
||||
index,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,990 +0,0 @@
|
|||
GameLib.Utils = function() {};
|
||||
|
||||
/**
|
||||
* Strips image extension from given path
|
||||
* @param imagePath
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Utils.StripImageExtension = function(imagePath) {
|
||||
return imagePath.replace(/(\.png$|\.gif$|\.jpeg$|\.jpg$)/,'')
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.GetArrayInstances = function(array) {
|
||||
return array.reduce(
|
||||
function(result, object) {
|
||||
|
||||
if (result === null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(object.instance)) {
|
||||
result = null;
|
||||
} else {
|
||||
result.push(object.instance);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
[]
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.Vector2) {
|
||||
// GameLib.Utils.BuildVectorSource(result, propertyId, 2);
|
||||
// }
|
||||
//
|
||||
// if (object[propertyId] instanceof GameLib.Vector3) {
|
||||
// GameLib.Utils.BuildVectorSource(result, propertyId, 3);
|
||||
// }
|
||||
//
|
||||
// if (object[propertyId] instanceof GameLib.Vector4) {
|
||||
// GameLib.Utils.BuildVectorSource(result, propertyId, 4);
|
||||
// }
|
||||
//
|
||||
// if (object[propertyId] instanceof GameLib.Quaternion) {
|
||||
// GameLib.Utils.BuildQuaternionSource(result, propertyId);
|
||||
// }
|
||||
|
||||
return result;
|
||||
|
||||
}.bind(this),
|
||||
{}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Utils.GetRuntime = function() {
|
||||
|
||||
var result = null;
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.GET_RUNTIME,
|
||||
null,
|
||||
function(runtime) {
|
||||
result = runtime;
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the window size or null
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Utils.GetWindowSize = function() {
|
||||
|
||||
var size = null;
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.UpdateWindowSize = function(object) {
|
||||
var size = GameLib.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
|
||||
*/
|
||||
GameLib.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
|
||||
);
|
||||
};
|
||||
|
||||
// GameLib.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;
|
||||
//
|
||||
// GameLib.Utils.ObjectFactory.Link(idToObject, objectId, defer);
|
||||
//
|
||||
// return promiseList[objectId];
|
||||
// }
|
||||
// };
|
||||
|
||||
GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
|
||||
|
||||
};
|
||||
|
||||
GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets random int exclusive of maximum but inclusive of minimum
|
||||
* @param min
|
||||
* @param max
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.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
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.UndefinedOrNull = function (
|
||||
variable
|
||||
) {
|
||||
return typeof variable === 'undefined' || variable === null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The variable is not undefined and not null
|
||||
* @param variable
|
||||
* @returns {boolean}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Utils.Defined = function (
|
||||
variable
|
||||
) {
|
||||
return typeof variable !== 'undefined' && variable !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets function parameters
|
||||
* @param fn
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.IdOrNull = function (object) {
|
||||
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||
return null;
|
||||
} else {
|
||||
if (GameLib.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
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.IdArrayOrEmptyArray = function (array) {
|
||||
if (GameLib.Utils.UndefinedOrNull(array)) {
|
||||
return [];
|
||||
} else {
|
||||
|
||||
return array.map(function(item) {
|
||||
|
||||
if (GameLib.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
|
||||
*/
|
||||
GameLib.Utils.Link = function(propertyString, idToObject, parentObject, id) {
|
||||
|
||||
if (!GameLib.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
|
||||
*/
|
||||
GameLib.Utils.RandomId = function(length) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(length)) {
|
||||
length = 10;
|
||||
}
|
||||
|
||||
return Math.random().toString(36).substr(2, length);
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.D3.Mesh
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.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)
|
||||
*/
|
||||
GameLib.Utils.ResetWindingOrder = function(faces, vertices) {
|
||||
|
||||
var vertexList = new GameLib.API.Vector3.Points();
|
||||
|
||||
for (var v = 0; v < vertices.length; v++) {
|
||||
vertexList.add(new GameLib.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 (
|
||||
GameLib.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 GameLib.D3.Face[]
|
||||
* @param orientationEdge GameLib.API.Vector2
|
||||
* @returns {Array}
|
||||
*/
|
||||
GameLib.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 GameLib.API.Vector2
|
||||
* @param faces GameLib.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 GameLib.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 GameLib.D3.TriangleEdge(
|
||||
triangle,
|
||||
edge
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var toProcess = [
|
||||
new GameLib.D3.TriangleEdge(
|
||||
new GameLib.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 GameLib.API.Vector2(
|
||||
triangleEdge.triangle.v0index,
|
||||
triangleEdge.triangle.v1index
|
||||
),
|
||||
new GameLib.API.Vector2(
|
||||
triangleEdge.triangle.v1index,
|
||||
triangleEdge.triangle.v2index
|
||||
),
|
||||
new GameLib.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 []
|
||||
*/
|
||||
GameLib.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 GameLib.API.Quaternion.Points();
|
||||
|
||||
for (var i = 0; i < verticesFlat.length; i += 3) {
|
||||
points.add(new GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.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);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.Utils.IsEmpty = function(obj) {
|
||||
return (Object.keys(obj).length === 0 && obj.constructor === Object);
|
||||
};
|
||||
|
||||
GameLib.Utils.isString = function(member) {
|
||||
return (typeof member === 'string');
|
||||
};
|
||||
|
||||
GameLib.Utils.isBoolean = function(member) {
|
||||
return (member === true || member === false);
|
||||
};
|
||||
|
||||
GameLib.Utils.isColor = function(member) {
|
||||
return (member instanceof GameLib.Color);
|
||||
};
|
||||
|
||||
GameLib.Utils.isNumber = function(member) {
|
||||
return (typeof member === 'number');
|
||||
};
|
||||
|
||||
GameLib.Utils.isVector2 = function(member) {
|
||||
return (
|
||||
member instanceof GameLib.API.Vector2 ||
|
||||
member instanceof GameLib.Vector2
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Utils.isVector3 = function(member) {
|
||||
return (
|
||||
member instanceof GameLib.API.Vector3 ||
|
||||
member instanceof GameLib.Vector3
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Utils.isVector4 = function(member) {
|
||||
return (
|
||||
member instanceof GameLib.API.Vector4 ||
|
||||
member instanceof GameLib.Vector4 ||
|
||||
member instanceof GameLib.API.Quaternion ||
|
||||
member instanceof GameLib.Quaternion
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
GameLib.Utils.LowerUnderscore = function(name) {
|
||||
return name.toLowerCase().replace(/\s+/, '_');
|
||||
};
|
||||
|
||||
GameLib.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}
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.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;
|
||||
};
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* API Component Interface - Do not construct objects of this type directly
|
||||
* @param componentType
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Component = function(
|
||||
componentType,
|
||||
parentEntity
|
||||
) {
|
||||
this.componentType = componentType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
};
|
||||
|
||||
GameLib.API.Component.prototype.constructor = GameLib.API.Component;
|
File diff suppressed because it is too large
Load Diff
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Box3
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param min
|
||||
* @param max
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Box3 = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
min,
|
||||
max
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Box (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(min)) {
|
||||
min = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.min = min;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(max)) {
|
||||
max = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.max = max;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.BOX3,
|
||||
parentEntity
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.API.Box3.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Box3.prototype.constructor = GameLib.API.Box3;
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.API.Canvas = function(
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
parentTexture,
|
||||
autoUpdateSize,
|
||||
width,
|
||||
height,
|
||||
offset,
|
||||
tabIndex,
|
||||
texts,
|
||||
textBaseline
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Canvas (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentTexture)) {
|
||||
parentTexture = null;
|
||||
}
|
||||
this.parentTexture = parentTexture;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) {
|
||||
autoUpdateSize = true;
|
||||
}
|
||||
this.autoUpdateSize = autoUpdateSize;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 512;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 512;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(offset)) {
|
||||
offset = new GameLib.API.Vector2(0,0);
|
||||
}
|
||||
this.offset = offset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(tabIndex)) {
|
||||
tabIndex = 1;
|
||||
}
|
||||
this.tabIndex = tabIndex;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(texts)) {
|
||||
texts = [];
|
||||
}
|
||||
this.texts = texts;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(textBaseline)) {
|
||||
textBaseline = 'middle';
|
||||
}
|
||||
this.textBaseline = textBaseline;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.CANVAS,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Canvas.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Canvas.prototype.constructor = GameLib.API.Canvas;
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
* Raw Clock API object - should always correspond with the Clock Schema
|
||||
* @constructor
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
*/
|
||||
GameLib.API.Clock = function(
|
||||
id,
|
||||
name,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Clock (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.CLOCK,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Clock.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Clock.prototype.constructor = GameLib.API.Clock;
|
||||
|
||||
/**
|
||||
* Creates an API camera from an Object camera
|
||||
* @param objectClock
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Clock.FromObject = function(objectClock) {
|
||||
|
||||
return new GameLib.API.Clock(
|
||||
objectClock.id,
|
||||
objectClock.name,
|
||||
objectClock.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* API Color
|
||||
* @param r
|
||||
* @param g
|
||||
* @param b
|
||||
* @param a
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Color = function (r, g, b, a) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(r)) {
|
||||
r = 1;
|
||||
}
|
||||
this.r = r;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(g)) {
|
||||
g = 1;
|
||||
}
|
||||
this.g = g;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(b)) {
|
||||
b = 1;
|
||||
}
|
||||
this.b = b;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(a)) {
|
||||
a = 0;
|
||||
}
|
||||
this.a = a;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an API color from an Object color
|
||||
* @param objectColor
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Color.FromObject = function(objectColor) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectColor)){
|
||||
objectColor = {};
|
||||
}
|
||||
|
||||
return new GameLib.API.Color(
|
||||
objectColor.r,
|
||||
objectColor.g,
|
||||
objectColor.b,
|
||||
objectColor.a
|
||||
);
|
||||
|
||||
};
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* Raw Controls API object
|
||||
* @param id
|
||||
* @param controlsType
|
||||
* @param name
|
||||
* @param canvas
|
||||
* @param parentEntity
|
||||
* @property controlsType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Controls = function(
|
||||
id,
|
||||
name,
|
||||
controlsType,
|
||||
canvas,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
||||
controlsType = GameLib.API.Controls.CONTROLS_TYPE_NONE;
|
||||
}
|
||||
this.controlsType = controlsType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
name = 'Controls';
|
||||
|
||||
switch (this.controlsType) {
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_TOUCH :
|
||||
name = 'Controls Editor';
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD :
|
||||
name = 'Controls Keyboard';
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_MOUSE :
|
||||
name = 'Controls Mouse';
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_EDITOR :
|
||||
name = 'Controls Editor';
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON :
|
||||
name = 'Controls First Person';
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_ORBIT :
|
||||
name = 'Controls Orbit';
|
||||
break;
|
||||
}
|
||||
|
||||
name += ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
||||
canvas = null;
|
||||
}
|
||||
this.canvas = canvas;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.API.Controls.GetComponentType(this.controlsType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Controls.prototype.constructor = GameLib.API.Controls;
|
||||
|
||||
GameLib.API.Controls.GetComponentType = function(controlsType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (controlsType) {
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_NONE :
|
||||
componentType = GameLib.Component.CONTROLS;
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_TOUCH :
|
||||
componentType = GameLib.Component.CONTROLS_TOUCH;
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD :
|
||||
componentType = GameLib.Component.CONTROLS_KEYBOARD;
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_MOUSE :
|
||||
componentType = GameLib.Component.CONTROLS_MOUSE;
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_EDITOR :
|
||||
componentType = GameLib.Component.CONTROLS_EDITOR;
|
||||
break;
|
||||
case GameLib.API.Controls.CONTROLS_TYPE_ORBIT :
|
||||
componentType = GameLib.Component.CONTROLS_ORBIT;
|
||||
break;
|
||||
default :
|
||||
throw new Error('unhandled controls type: ' + controlsType);
|
||||
break;
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.API.Controls.D3 = function() {};
|
||||
|
||||
/**
|
||||
* Controls Type
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.API.Controls.CONTROLS_TYPE_NONE = 0x0;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_TOUCH = 0x1;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_EDITOR = 0x4;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON = 0x5;
|
||||
GameLib.API.Controls.CONTROLS_TYPE_ORBIT = 0x6;
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* @param apiControls
|
||||
* @param raycaster
|
||||
* @param camera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Controls.D3.Editor = function(
|
||||
apiControls,
|
||||
raycaster,
|
||||
camera
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
||||
raycaster = new GameLib.D3.API.Raycaster();
|
||||
}
|
||||
this.raycaster = raycaster;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.D3.Editor.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.D3.Editor.prototype.constructor = GameLib.API.Controls.D3.Editor;
|
|
@ -1,136 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.API.Controls.D3.FirstPerson = function(
|
||||
apiControls,
|
||||
camera,
|
||||
enabled,
|
||||
movementSpeed,
|
||||
lookSpeed,
|
||||
lookVertical,
|
||||
autoForward,
|
||||
activeLook,
|
||||
heightSpeed,
|
||||
heightCoef,
|
||||
heightMin,
|
||||
heightMax,
|
||||
constrainVertical,
|
||||
verticalMin,
|
||||
verticalMax,
|
||||
autoSpeedFactor
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enabled)) {
|
||||
enabled = true;
|
||||
}
|
||||
this.enabled = enabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(movementSpeed)) {
|
||||
movementSpeed = 1.0;
|
||||
}
|
||||
this.movementSpeed = movementSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookSpeed)) {
|
||||
lookSpeed = 0.005;
|
||||
}
|
||||
this.lookSpeed = lookSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookVertical)) {
|
||||
lookVertical = true;
|
||||
}
|
||||
this.lookVertical = lookVertical;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoForward)) {
|
||||
autoForward = false;
|
||||
}
|
||||
this.autoForward = autoForward;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeLook)) {
|
||||
activeLook = false;
|
||||
}
|
||||
this.activeLook = activeLook;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightSpeed)) {
|
||||
heightSpeed = false;
|
||||
}
|
||||
this.heightSpeed = heightSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightCoef)) {
|
||||
heightCoef = 1.0;
|
||||
}
|
||||
this.heightCoef = heightCoef;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightMin)) {
|
||||
heightMin = 0.0;
|
||||
}
|
||||
this.heightMin = heightMin;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightMax)) {
|
||||
heightMax = 1.0;
|
||||
}
|
||||
this.heightMax = heightMax;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(constrainVertical)) {
|
||||
constrainVertical = false;
|
||||
}
|
||||
this.constrainVertical = constrainVertical;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(verticalMin)) {
|
||||
verticalMin = 0;
|
||||
}
|
||||
this.verticalMin = verticalMin;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(verticalMax)) {
|
||||
verticalMax = Math.PI;
|
||||
}
|
||||
this.verticalMax = verticalMax;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoSpeedFactor)) {
|
||||
autoSpeedFactor = 0;
|
||||
}
|
||||
this.autoSpeedFactor = autoSpeedFactor;
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.D3.FirstPerson.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.D3.FirstPerson.prototype.constructor = GameLib.API.Controls.D3.FirstPerson;
|
|
@ -1,147 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.API.Controls.D3.Orbit = function(
|
||||
apiControls,
|
||||
camera,
|
||||
target,
|
||||
enabled,
|
||||
minPolarAngle,
|
||||
maxPolarAngle,
|
||||
enableDamping,
|
||||
dampingFactor,
|
||||
enableZoom,
|
||||
zoomSpeed,
|
||||
enableRotate,
|
||||
rotateSpeed,
|
||||
enablePan,
|
||||
keyPanSpeed,
|
||||
autoRotate,
|
||||
autoRotateSpeed,
|
||||
enableKeys
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_ORBIT
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_ORBIT;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(target)) {
|
||||
target = null;
|
||||
}
|
||||
this.target = target;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enabled)) {
|
||||
enabled = true;
|
||||
}
|
||||
this.enabled = enabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(minPolarAngle)) {
|
||||
minPolarAngle = 0;
|
||||
}
|
||||
this.minPolarAngle = minPolarAngle;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxPolarAngle)) {
|
||||
maxPolarAngle = Math.PI;
|
||||
}
|
||||
this.maxPolarAngle = maxPolarAngle;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableDamping)) {
|
||||
enableDamping = false;
|
||||
}
|
||||
this.enableDamping = enableDamping;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(dampingFactor)) {
|
||||
dampingFactor = 0.25;
|
||||
}
|
||||
this.dampingFactor = dampingFactor;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableZoom)) {
|
||||
enableZoom = true;
|
||||
}
|
||||
this.enableZoom = enableZoom;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(zoomSpeed)) {
|
||||
zoomSpeed = 1.0;
|
||||
}
|
||||
this.zoomSpeed = zoomSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableRotate)) {
|
||||
enableRotate = true;
|
||||
}
|
||||
this.enableRotate = enableRotate;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotateSpeed)) {
|
||||
rotateSpeed = 1.0;
|
||||
}
|
||||
this.rotateSpeed = rotateSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enablePan)) {
|
||||
enablePan = true;
|
||||
}
|
||||
this.enablePan = enablePan;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(keyPanSpeed)) {
|
||||
keyPanSpeed = 7.0;
|
||||
}
|
||||
this.keyPanSpeed = keyPanSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoRotate)) {
|
||||
autoRotate = false;
|
||||
}
|
||||
this.autoRotate = autoRotate;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoRotateSpeed)) {
|
||||
autoRotateSpeed = 2.0;
|
||||
}
|
||||
this.autoRotateSpeed = autoRotateSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableKeys)) {
|
||||
enableKeys = false;
|
||||
}
|
||||
this.enableKeys = enableKeys;
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.D3.Orbit.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.D3.Orbit.prototype.constructor = GameLib.API.Controls.D3.Orbit;
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* @param apiControls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Controls.Keyboard = function(
|
||||
apiControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD;
|
||||
}
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.Keyboard.prototype.constructor = GameLib.API.Controls.Keyboard;
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* @param apiControls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Controls.Mouse = function(
|
||||
apiControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_MOUSE;
|
||||
}
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.Mouse.prototype.constructor = GameLib.API.Controls.Mouse;
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* @param apiControls
|
||||
* @param sensitivity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Controls.Touch = function(
|
||||
apiControls,
|
||||
sensitivity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) {
|
||||
apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_TOUCH;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(sensitivity)) {
|
||||
sensitivity = 5;
|
||||
}
|
||||
this.sensitivity = sensitivity;
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype);
|
||||
GameLib.API.Controls.Touch.prototype.constructor = GameLib.API.Controls.Touch;
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Curve
|
||||
* @param id
|
||||
* @param name
|
||||
* @param curveType
|
||||
* @param parentEntity
|
||||
* @param arcLenghDivisions
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Curve = function (
|
||||
id,
|
||||
name,
|
||||
curveType,
|
||||
parentEntity,
|
||||
arcLenghDivisions
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(curveType)) {
|
||||
curveType = GameLib.API.Curve.CURVE_TYPE_NONE;
|
||||
}
|
||||
this.curveType = curveType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.curveType) {
|
||||
case GameLib.API.Curve.CURVE_TYPE_NONE :
|
||||
name = 'Curve';
|
||||
break;
|
||||
case GameLib.API.Curve.CURVE_TYPE_PATH :
|
||||
name = 'Curve Path';
|
||||
break;
|
||||
default:
|
||||
console.log('no nice name for curve');
|
||||
}
|
||||
|
||||
name += ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(arcLenghDivisions)) {
|
||||
arcLenghDivisions = 200;
|
||||
}
|
||||
this.arcLenghDivisions = arcLenghDivisions;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.API.Curve.GetComponentType(this.curveType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Curve.prototype = Object.create(GameLib.API.Curve.prototype);
|
||||
GameLib.API.Curve.prototype.constructor = GameLib.API.Curve;
|
||||
|
||||
GameLib.API.Curve.GetComponentType = function(curveType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (curveType) {
|
||||
case GameLib.API.Curve.CURVE_TYPE_NONE :
|
||||
componentType = GameLib.Component.CURVE;
|
||||
break;
|
||||
case GameLib.API.Curve.CURVE_TYPE_PATH :
|
||||
componentType = GameLib.Component.CURVE_PATH;
|
||||
break;
|
||||
case GameLib.API.Curve.CURVE_TYPE_PATH_2D :
|
||||
componentType = GameLib.Component.CURVE_PATH_D2;
|
||||
break;
|
||||
case GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE :
|
||||
componentType = GameLib.Component.CURVE_PATH_D2_SHAPE;
|
||||
break;
|
||||
default :
|
||||
throw new Error('unhandled curve type');
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.API.Curve.CURVE_TYPE_NONE = 0x0;
|
||||
GameLib.API.Curve.CURVE_TYPE_PATH = 0x1;
|
||||
GameLib.API.Curve.CURVE_TYPE_PATH_2D = 0x2;
|
||||
GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3;
|
||||
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Curve.Path
|
||||
* @constructor
|
||||
* @param apiCurve
|
||||
* @param curves
|
||||
* @param autoClose
|
||||
*/
|
||||
GameLib.API.Curve.Path = function (
|
||||
apiCurve,
|
||||
curves,
|
||||
autoClose
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurve)) {
|
||||
apiCurve = {
|
||||
curveType: GameLib.API.Curve.CURVE_TYPE_PATH
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurve.curveType)) {
|
||||
apiCurve.curveType = GameLib.API.Curve.CURVE_TYPE_PATH;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(curves)) {
|
||||
curves = [];
|
||||
}
|
||||
this.curves = curves;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClose)) {
|
||||
autoClose = false;
|
||||
}
|
||||
this.autoClose = autoClose;
|
||||
|
||||
GameLib.API.Curve.call(
|
||||
this,
|
||||
apiCurve.id,
|
||||
apiCurve.name,
|
||||
apiCurve.curveType,
|
||||
apiCurve.parentEntity,
|
||||
apiCurve.arcLenghDivisions
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Curve.Path.prototype = Object.create(GameLib.API.Curve.prototype);
|
||||
GameLib.API.Curve.Path.prototype.constructor = GameLib.API.Curve.Path;
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Curve.Path.D2
|
||||
* @constructor
|
||||
* @param apiCurvePath
|
||||
* @param points
|
||||
*/
|
||||
GameLib.API.Curve.Path.D2 = function (
|
||||
apiCurvePath,
|
||||
points
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) {
|
||||
apiCurvePath = {
|
||||
curveType: GameLib.API.Curve.CURVE_TYPE_PATH_2D
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePath.curveType)) {
|
||||
apiCurvePath.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(points)) {
|
||||
points = [];
|
||||
}
|
||||
this.points = points;
|
||||
|
||||
GameLib.API.Curve.Path.call(
|
||||
this,
|
||||
apiCurvePath,
|
||||
apiCurvePath.curves,
|
||||
apiCurvePath.autoClose
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Curve.Path.D2.prototype = Object.create(GameLib.API.Curve.Path.prototype);
|
||||
GameLib.API.Curve.Path.D2.prototype.constructor = GameLib.API.Curve.Path.D2;
|
|
@ -1,27 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Curve.Path.D2.Shape
|
||||
* @constructor
|
||||
* @param apiCurvePathD2
|
||||
*/
|
||||
GameLib.API.Curve.Path.D2.Shape = function (
|
||||
apiCurvePathD2
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) {
|
||||
apiCurvePathD2 = {
|
||||
curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) {
|
||||
apiCurvePathD2.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ;
|
||||
}
|
||||
|
||||
GameLib.API.Curve.Path.call(
|
||||
this,
|
||||
apiCurvePathD2,
|
||||
apiCurvePathD2.points
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Curve.Path.D2.Shape.prototype = Object.create(GameLib.API.Curve.Path.D2.prototype);
|
||||
GameLib.API.Curve.Path.D2.Shape.prototype.constructor = GameLib.API.Curve.Path.D2.Shape;
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Custom Code Component
|
||||
* @param id
|
||||
* @param name
|
||||
* @param eventId
|
||||
* @param code
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.CustomCode = function (
|
||||
id,
|
||||
name,
|
||||
eventId,
|
||||
code,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'CustomCode (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(eventId)) {
|
||||
eventId = 42;
|
||||
}
|
||||
this.eventId = eventId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(code)) {
|
||||
code = "return null;\n//@ sourceURL=" + this.name + ".js";
|
||||
}
|
||||
this.code = code;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.CUSTOM_CODE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.CustomCode.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.CustomCode.prototype.constructor = GameLib.API.CustomCode;
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* API DomElement
|
||||
* @param id
|
||||
* @param name
|
||||
* @param domElementId
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.DomElement = function(
|
||||
id,
|
||||
name,
|
||||
domElementId,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'DOM Element (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
|
||||
domElementId = '';
|
||||
}
|
||||
this.domElementId = domElementId;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.DOM_ELEMENT,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.DomElement.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.DomElement.prototype.constructor = GameLib.API.DomElement;
|
||||
|
||||
/**
|
||||
* Returns an API domElement from an Object domElement
|
||||
* @param objectDomElement
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.DomElement.FromObject = function (objectDomElement) {
|
||||
return new GameLib.API.DomElement(
|
||||
objectDomElement.id,
|
||||
objectDomElement.name,
|
||||
objectDomElement.domElementId,
|
||||
objectDomElement.parentEntity
|
||||
)
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Box3
|
||||
* @constructor
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param start
|
||||
* @param count
|
||||
*/
|
||||
GameLib.API.DrawRange = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
start,
|
||||
count
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'DrawRange (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(start)) {
|
||||
start = 0;
|
||||
}
|
||||
this.start = start;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(count)) {
|
||||
count = Infinity;
|
||||
}
|
||||
this.count = count;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.DRAW_RANGE,
|
||||
parentEntity
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.API.DrawRange.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.DrawRange.prototype.constructor = GameLib.API.DrawRange;
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* Entity API Object (for storing / loading entities to and from API)
|
||||
* @constructor
|
||||
* @param id
|
||||
* @param name
|
||||
* @param entities GameLib.API.Entity[]
|
||||
* @param defaultEntity
|
||||
* @param parentEntity
|
||||
*/
|
||||
GameLib.API.EntityManager = function(
|
||||
id,
|
||||
name,
|
||||
entities,
|
||||
defaultEntity,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Entity Manager (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(entities)) {
|
||||
entities = [];
|
||||
}
|
||||
this.entities = entities;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(defaultEntity)) {
|
||||
defaultEntity = null;
|
||||
}
|
||||
this.defaultEntity = defaultEntity;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.ENTITY_MANAGER,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.EntityManager.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.EntityManager.prototype.constructor = GameLib.API.EntityManager;
|
||||
|
||||
/**
|
||||
* Creates an API entity manager from an Object entity manager
|
||||
* @param objectEntityManager
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.EntityManager.FromObject = function(objectEntityManager) {
|
||||
|
||||
var apiEntities = objectEntityManager.entities.map(
|
||||
function (objectEntity) {
|
||||
return GameLib.API.Entity.FromObject(objectEntity);
|
||||
}
|
||||
);
|
||||
|
||||
return new GameLib.API.EntityManager(
|
||||
objectEntityManager.id,
|
||||
objectEntityManager.name,
|
||||
apiEntities,
|
||||
objectEntityManager.defaultEntity,
|
||||
objectEntityManager.parentEntity
|
||||
);
|
||||
};
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Entity API Object (for storing / loading entities to and from API)
|
||||
* @param id
|
||||
* @param name
|
||||
* @param components GameLib.Component[]
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Entity = function(
|
||||
id,
|
||||
name,
|
||||
components,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Entity (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(components)) {
|
||||
components = [];
|
||||
}
|
||||
this.components = components;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.ENTITY,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Entity.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Entity.prototype.constructor = GameLib.API.Entity;
|
||||
|
||||
/**
|
||||
* Returns an API entity from an Object entity
|
||||
* @param objectEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Entity.FromObject = function(objectEntity) {
|
||||
return new GameLib.API.Entity(
|
||||
objectEntity.id,
|
||||
objectEntity.name,
|
||||
objectEntity.components,
|
||||
objectEntity.parentEntity
|
||||
)
|
||||
};
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.GraphicsRuntime
|
||||
* @param id
|
||||
* @param name
|
||||
* @param graphicsType
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.GraphicsRuntime = function(
|
||||
id,
|
||||
name,
|
||||
graphicsType,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Graphics Runtime (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
|
||||
graphicsType = null;
|
||||
}
|
||||
this.graphicsType = graphicsType;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.API.GraphicsRuntime.GetComponentType(this.graphicsType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.GraphicsRuntime.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.GraphicsRuntime.prototype.constructor = GameLib.API.GraphicsRuntime;
|
||||
|
||||
GameLib.API.GraphicsRuntime.GetComponentType = function(graphicsType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (graphicsType) {
|
||||
case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE :
|
||||
componentType = GameLib.Component.GRAPHICS;
|
||||
break;
|
||||
case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS :
|
||||
componentType = GameLib.Component.GRAPHICS_THREE;
|
||||
break;
|
||||
case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS :
|
||||
componentType = GameLib.Component.GRAPHICS_IMPACT;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Invalid graphics type');
|
||||
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE = 0x0;
|
||||
GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS = 0x1;
|
||||
GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS = 0x2;
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.GraphicsRuntime.Impact
|
||||
* @constructor
|
||||
* @param apiGraphicsRuntime
|
||||
*/
|
||||
GameLib.API.GraphicsRuntime.Impact = function(
|
||||
apiGraphicsRuntime
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
|
||||
apiGraphicsRuntime = {
|
||||
graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
|
||||
apiGraphicsRuntime.graphicsType = GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS;
|
||||
}
|
||||
|
||||
GameLib.API.GraphicsRuntime.call(
|
||||
this,
|
||||
apiGraphicsRuntime.id,
|
||||
apiGraphicsRuntime.name,
|
||||
apiGraphicsRuntime.graphicsType,
|
||||
apiGraphicsRuntime.parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.GraphicsRuntime.Impact.prototype = Object.create(GameLib.API.GraphicsRuntime.prototype);
|
||||
GameLib.API.GraphicsRuntime.Impact.prototype.constructor = GameLib.API.GraphicsRuntime.Impact;
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.GraphicsRuntime.Three
|
||||
* @constructor
|
||||
* @param apiGraphicsRuntime
|
||||
*/
|
||||
GameLib.API.GraphicsRuntime.Three = function(
|
||||
apiGraphicsRuntime
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
|
||||
apiGraphicsRuntime = {
|
||||
graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
|
||||
apiGraphicsRuntime.graphicsType = GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS;
|
||||
}
|
||||
|
||||
GameLib.API.GraphicsRuntime.call(
|
||||
this,
|
||||
apiGraphicsRuntime.id,
|
||||
apiGraphicsRuntime.name,
|
||||
apiGraphicsRuntime.graphicsType,
|
||||
apiGraphicsRuntime.parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.GraphicsRuntime.Three.prototype = Object.create(GameLib.API.GraphicsRuntime.prototype);
|
||||
GameLib.API.GraphicsRuntime.Three.prototype.constructor = GameLib.API.GraphicsRuntime.Three;
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Group
|
||||
* @constructor
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param start
|
||||
* @param count
|
||||
* @param materialIndex
|
||||
*/
|
||||
GameLib.API.Group = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
start,
|
||||
count,
|
||||
materialIndex
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Group (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(start)) {
|
||||
start = 0;
|
||||
}
|
||||
this.start = start;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(count)) {
|
||||
count = 0;
|
||||
}
|
||||
this.count = count;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(materialIndex)) {
|
||||
materialIndex = 0;
|
||||
}
|
||||
this.materialIndex = materialIndex;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.GROUP,
|
||||
parentEntity
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.API.Group.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Group.prototype.constructor = GameLib.API.Group;
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* Raw GUI API object - should always correspond with the GUI Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param domElement
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.GUI = function(
|
||||
id,
|
||||
name,
|
||||
domElement,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'GUI (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
||||
domElement = null;
|
||||
}
|
||||
this.domElement = domElement;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.GUI,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.GUI.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.GUI.prototype.constructor = GameLib.API.GUI;
|
||||
|
||||
/**
|
||||
* Creates an API GUI from an Object GUI
|
||||
* @param objectGUI
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.GUI.FromObject = function(objectGUI) {
|
||||
|
||||
var apiDomElement = null;
|
||||
if (objectGUI.domElement) {
|
||||
if (objectGUI.domElement instanceof Object) {
|
||||
apiDomElement = GameLib.API.DomElement.FromObject(objectGUI.domElement);
|
||||
} else {
|
||||
apiDomElement = objectGUI.domElement;
|
||||
}
|
||||
}
|
||||
|
||||
return new GameLib.API.GUI(
|
||||
objectGUI.id,
|
||||
objectGUI.name,
|
||||
apiDomElement,
|
||||
objectGUI.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.API.Image = function(
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
parentTexture,
|
||||
fileName,
|
||||
extension,
|
||||
path,
|
||||
contentType,
|
||||
size,
|
||||
width,
|
||||
height
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Image ' + id;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentTexture)) {
|
||||
parentTexture = null;
|
||||
}
|
||||
this.parentTexture = parentTexture;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(fileName)) {
|
||||
fileName = GameLib.Utils.LowerUnderscore(name);
|
||||
}
|
||||
this.fileName = fileName;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(extension)) {
|
||||
extension = '.unknown';
|
||||
}
|
||||
this.extension = extension;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(path)) {
|
||||
path = '/';
|
||||
}
|
||||
this.path = path;
|
||||
|
||||
if (GameLib.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 (GameLib.Utils.UndefinedOrNull(size)) {
|
||||
size = 0;
|
||||
}
|
||||
this.size = size;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 0;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 0;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.IMAGE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Image.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Image.prototype.constructor = GameLib.API.Image;
|
|
@ -1,159 +0,0 @@
|
|||
/**
|
||||
* Api Matrix 4
|
||||
* @param row0 GameLib.API.Vector4
|
||||
* @param row1 GameLib.API.Vector4
|
||||
* @param row2 GameLib.API.Vector4
|
||||
* @param row3 GameLib.API.Vector4
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Matrix4 = function ApiMatrix4(
|
||||
row0,
|
||||
row1,
|
||||
row2,
|
||||
row3
|
||||
) {
|
||||
this.rows = [];
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(row0)) {
|
||||
row0 = new GameLib.API.Vector4(1, 0, 0, 0);
|
||||
}
|
||||
this.rows[0] = row0;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(row1)) {
|
||||
row1 = new GameLib.API.Vector4(0, 1, 0, 0);
|
||||
}
|
||||
this.rows[1] = row1;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(row2)) {
|
||||
row2 = new GameLib.API.Vector4(0, 0, 1, 0);
|
||||
}
|
||||
this.rows[2] = row2;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(row3)) {
|
||||
row3 = new GameLib.API.Vector4(0, 0, 0, 1);
|
||||
}
|
||||
this.rows[3] = row3;
|
||||
|
||||
this.temp = [];
|
||||
this.temp.push(
|
||||
new GameLib.API.Vector4()
|
||||
);
|
||||
|
||||
this.temp.push(
|
||||
new GameLib.API.Vector4()
|
||||
);
|
||||
|
||||
this.temp.push(
|
||||
new GameLib.API.Vector4()
|
||||
);
|
||||
|
||||
this.temp.push(
|
||||
new GameLib.API.Vector4()
|
||||
);
|
||||
|
||||
this.forward = new GameLib.API.Vector4();
|
||||
this.left = new GameLib.API.Vector4();
|
||||
this.up = new GameLib.API.Vector4();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an API matrix from an Object matrix
|
||||
* @param objectMatrix
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Matrix4.FromObject = function(objectMatrix) {
|
||||
|
||||
if (objectMatrix.rows) {
|
||||
return new GameLib.API.Matrix4(
|
||||
GameLib.API.Vector4.FromObject(objectMatrix.rows[0]),
|
||||
GameLib.API.Vector4.FromObject(objectMatrix.rows[1]),
|
||||
GameLib.API.Vector4.FromObject(objectMatrix.rows[2]),
|
||||
GameLib.API.Vector4.FromObject(objectMatrix.rows[3])
|
||||
);
|
||||
} else if (objectMatrix instanceof Array) {
|
||||
return new GameLib.API.Matrix4(
|
||||
GameLib.API.Vector4.FromObject(objectMatrix[0]),
|
||||
GameLib.API.Vector4.FromObject(objectMatrix[1]),
|
||||
GameLib.API.Vector4.FromObject(objectMatrix[2]),
|
||||
GameLib.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?');
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
||||
this.identity();
|
||||
this.rows[1] = new GameLib.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
||||
this.rows[2] = new GameLib.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0);
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixY = function (radians) {
|
||||
this.identity();
|
||||
this.rows[0] = new GameLib.API.Vector4(
|
||||
Math.cos(radians),
|
||||
0,
|
||||
Math.sin(radians),
|
||||
0
|
||||
);
|
||||
this.rows[2] = new GameLib.API.Vector4(
|
||||
-1 * Math.sin(radians),
|
||||
0,
|
||||
Math.cos(radians),
|
||||
0
|
||||
);
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixZ = function (radians) {
|
||||
this.identity();
|
||||
this.rows[0] = new GameLib.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
|
||||
this.rows[1] = new GameLib.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0);
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotateX = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixX(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotateY = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixY(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.rotateZ = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixZ(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.multiply = function (mvp) {
|
||||
if (mvp instanceof GameLib.API.Quaternion || mvp instanceof GameLib.API.Vector4) {
|
||||
return new GameLib.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 GameLib.API.Vector3) {
|
||||
return new GameLib.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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.API.Matrix4.prototype.identity = function () {
|
||||
this.rows = [
|
||||
new GameLib.API.Vector4(1, 0, 0, 0),
|
||||
new GameLib.API.Vector4(0, 1, 0, 0),
|
||||
new GameLib.API.Vector4(0, 0, 1, 0),
|
||||
new GameLib.API.Vector4(0, 0, 0, 1)
|
||||
];
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* API Mouse
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param x
|
||||
* @param y
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Mouse = function(
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
x,
|
||||
y
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Mouse (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.MOUSE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Mouse.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Mouse.prototype.constructor = GameLib.API.Mouse;
|
|
@ -1,34 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Number
|
||||
* @constructor
|
||||
* @param value
|
||||
* @param grain
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
GameLib.API.Number = function (
|
||||
value,
|
||||
grain,
|
||||
min,
|
||||
max
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(value)) {
|
||||
value = 0;
|
||||
}
|
||||
this.value = value;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.1;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(min)) {
|
||||
min = 0;
|
||||
}
|
||||
this.min = min;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(max)) {
|
||||
max = 100;
|
||||
}
|
||||
this.max = max;
|
||||
};
|
|
@ -1,53 +0,0 @@
|
|||
GameLib.API.Plane = function (
|
||||
id,
|
||||
name,
|
||||
normal,
|
||||
constant,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Plane (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(normal)) {
|
||||
normal = new GameLib.API.Vector3(1,0,0);
|
||||
}
|
||||
this.normal = normal;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(constant)) {
|
||||
constant = 0;
|
||||
}
|
||||
this.constant = constant;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.PLANE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
GameLib.API.Plane.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Plane.prototype.constructor = GameLib.API.Plane;
|
||||
|
||||
/**
|
||||
* Returns an API vector from an Object vector
|
||||
* @param objectPlane
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Plane.FromObject = function (objectPlane) {
|
||||
return new GameLib.API.Plane(
|
||||
objectPlane.id,
|
||||
objectPlane.name,
|
||||
GameLib.API.Vector3.FromObject(objectPlane.normal),
|
||||
objectPlane.constant,
|
||||
objectPlane.parentEntity
|
||||
);
|
||||
};
|
|
@ -1,237 +0,0 @@
|
|||
/**
|
||||
* Quaternion
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
* @param axis
|
||||
* @param angle
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Quaternion = function (
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
w,
|
||||
axis,
|
||||
angle
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(w)) {
|
||||
w = 1;
|
||||
}
|
||||
this.w = w;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(axis)) {
|
||||
axis = new GameLib.API.Vector3();
|
||||
}
|
||||
this.axis = axis;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||
angle = 0;
|
||||
}
|
||||
this.angle = angle;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.prototype.copy = function () {
|
||||
return new GameLib.API.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Note, this normalize function leaves 'w' component untouched
|
||||
*/
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.prototype.multiply = function (q) {
|
||||
|
||||
var x, y, z, w;
|
||||
var a = q;
|
||||
var b = this;
|
||||
|
||||
if (q instanceof GameLib.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 GameLib.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");
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.prototype.subtract = function (v) {
|
||||
|
||||
if (v instanceof GameLib.API.Vector3) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
}
|
||||
|
||||
if (v instanceof GameLib.API.Quaternion) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
this.w -= v.w;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.prototype.magnitude = function () {
|
||||
return Math.sqrt(
|
||||
(this.x * this.x) +
|
||||
(this.y * this.y) +
|
||||
(this.z * this.z) +
|
||||
(this.w * this.w)
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.Matrix4
|
||||
*/
|
||||
GameLib.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 GameLib.Quaternion
|
||||
* @param t
|
||||
* @returns {GameLib.Quaternion}
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.API.Quaternion.FromObject = function (objectQuaternion) {
|
||||
|
||||
var apiAxis = null;
|
||||
|
||||
if (objectQuaternion.axis) {
|
||||
apiAxis = GameLib.API.Vector3.FromObject(objectQuaternion.axis);
|
||||
}
|
||||
|
||||
return new GameLib.API.Quaternion(
|
||||
objectQuaternion.x,
|
||||
objectQuaternion.y,
|
||||
objectQuaternion.z,
|
||||
objectQuaternion.w,
|
||||
apiAxis,
|
||||
objectQuaternion.angle
|
||||
)
|
||||
};
|
|
@ -1,224 +0,0 @@
|
|||
GameLib.API.Quaternion.Points = function () {
|
||||
this.vectors = [];
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.Points.prototype.add = function (vector) {
|
||||
|
||||
if (vector instanceof GameLib.API.Vector3) {
|
||||
vector = new GameLib.API.Quaternion(
|
||||
vector.x,
|
||||
vector.y,
|
||||
vector.z,
|
||||
1
|
||||
)
|
||||
}
|
||||
|
||||
if (!vector instanceof GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixY = new GameLib.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 GameLib.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));
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixX = new GameLib.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 GameLib.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));
|
||||
|
||||
};
|
||||
|
||||
|
||||
GameLib.API.Quaternion.Points.prototype.lookAt = function (at, up) {
|
||||
|
||||
var polyCenter = this.average();
|
||||
|
||||
console.log("poly center : " + JSON.stringify(polyCenter));
|
||||
|
||||
var lookAtMatrix = new GameLib.API.Matrix4().lookAt(polyCenter, at, up);
|
||||
|
||||
lookAtMatrix.rows[0] = new GameLib.API.Quaternion(1, 0, 0, 0);
|
||||
lookAtMatrix.rows[1] = new GameLib.API.Quaternion(0, 0, 1, 0);
|
||||
lookAtMatrix.rows[2] = new GameLib.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]));
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.API.Vector3(
|
||||
Math.abs(maxX - minX),
|
||||
Math.abs(maxY - minY),
|
||||
Math.abs(maxY - minZ)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.API.Vector3(
|
||||
averageX / this.vectors.length,
|
||||
averageY / this.vectors.length,
|
||||
averageZ / this.vectors.length
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
|
||||
GameLib.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);
|
||||
}
|
||||
};
|
|
@ -1,117 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.API.RenderConfiguration = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
logicalSize,
|
||||
aspectRatio,
|
||||
scaleMode,
|
||||
activeCamera,
|
||||
activeScenes,
|
||||
activeRenderer,
|
||||
activeComposer,
|
||||
activeEffect,
|
||||
enableComposer,
|
||||
enableEffect
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = "RenderConfiguration (" + this.id + ")";
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(logicalSize)) {
|
||||
logicalSize = new GameLib.API.Vector2(
|
||||
480,
|
||||
320
|
||||
);
|
||||
}
|
||||
this.logicalSize = logicalSize;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(aspectRatio)) {
|
||||
aspectRatio = GameLib.API.Renderer.ASPECT_RATIO_3_2;
|
||||
}
|
||||
this.aspectRatio = aspectRatio;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scaleMode)) {
|
||||
scaleMode = GameLib.API.Renderer.SCALE_MODE_LETTERBOX;
|
||||
}
|
||||
this.scaleMode = scaleMode;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
|
||||
activeCamera = null;
|
||||
}
|
||||
this.activeCamera = activeCamera;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeScenes)) {
|
||||
activeScenes = [];
|
||||
}
|
||||
this.activeScenes = activeScenes;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeRenderer)) {
|
||||
activeRenderer = null;
|
||||
}
|
||||
this.activeRenderer = activeRenderer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeComposer)) {
|
||||
activeComposer = null;
|
||||
}
|
||||
this.activeComposer = activeComposer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeEffect)) {
|
||||
activeEffect = null;
|
||||
}
|
||||
this.activeEffect = activeEffect;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableComposer)) {
|
||||
enableComposer = false;
|
||||
}
|
||||
this.enableComposer = enableComposer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(enableEffect)) {
|
||||
enableEffect = false;
|
||||
}
|
||||
this.enableEffect = enableEffect;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.RENDER_CONFIGURATION,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.RenderConfiguration.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.RenderConfiguration.prototype.constructor = GameLib.API.RenderConfiguration;
|
||||
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_NONE = 0x1;
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_4_3 = 0x2;
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_3_2 = 0x3;
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_16_10 = 0x4;
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_17_10 = 0x5;
|
||||
GameLib.API.RenderConfiguration.ASPECT_RATIO_16_9 = 0x6;
|
||||
|
||||
GameLib.API.RenderConfiguration.SCALE_MODE_NONE = 0x1;
|
||||
GameLib.API.RenderConfiguration.SCALE_MODE_LETTERBOX = 0x2;
|
||||
GameLib.API.RenderConfiguration.SCALE_MODE_ZOOM_TO_BIGGER = 0x3;
|
||||
GameLib.API.RenderConfiguration.SCALE_MODE_NON_UNIFORM = 0x4;
|
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Renderer
|
||||
* @param id
|
||||
* @param name
|
||||
* @param rendererType
|
||||
* @param parentEntity
|
||||
* @param width
|
||||
* @param height
|
||||
* @param offset
|
||||
* @param canvas
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Renderer = function (
|
||||
id,
|
||||
name,
|
||||
rendererType,
|
||||
parentEntity,
|
||||
width,
|
||||
height,
|
||||
offset,
|
||||
canvas
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rendererType)) {
|
||||
rendererType = GameLib.API.Renderer.RENDERER_TYPE_NONE;
|
||||
}
|
||||
this.rendererType = rendererType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.rendererType) {
|
||||
case GameLib.API.Renderer.RENDERER_TYPE_NONE :
|
||||
name = "Renderer";
|
||||
break;
|
||||
case GameLib.API.Renderer.RENDERER_TYPE_2D :
|
||||
name = "Renderer 2D";
|
||||
break;
|
||||
case GameLib.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 (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 1;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 1;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(offset)) {
|
||||
offset = new GameLib.API.Vector2(0,0);
|
||||
}
|
||||
this.offset = offset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
||||
canvas = new GameLib.API.Canvas();
|
||||
}
|
||||
this.canvas = canvas;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.API.Renderer.GetComponentType(this.rendererType),
|
||||
parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Renderer.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Renderer.prototype.constructor = GameLib.API.Renderer;
|
||||
|
||||
GameLib.API.Renderer.GetComponentType = function(rendererType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (rendererType) {
|
||||
case GameLib.API.Renderer.RENDERER_TYPE_NONE :
|
||||
componentType = GameLib.Component.RENDERER;
|
||||
break;
|
||||
case GameLib.API.Renderer.RENDERER_TYPE_2D :
|
||||
componentType = GameLib.Component.RENDERER_D2;
|
||||
break;
|
||||
case GameLib.API.Renderer.RENDERER_TYPE_3D :
|
||||
componentType = GameLib.Component.RENDERER_D3;
|
||||
break;
|
||||
default :
|
||||
console.warn('could not determine component type');
|
||||
break;
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.API.Renderer.RENDERER_TYPE_NONE = 0x0;
|
||||
GameLib.API.Renderer.RENDERER_TYPE_2D = 0x1;
|
||||
GameLib.API.Renderer.RENDERER_TYPE_3D = 0x2;
|
||||
|
||||
GameLib.API.Renderer.MODE_CANVAS = 0x1;
|
||||
GameLib.API.Renderer.MODE_TARGET = 0x2;
|
||||
GameLib.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3;
|
||||
|
||||
GameLib.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0;
|
||||
GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF = 1;
|
||||
GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT = 2;
|
||||
|
||||
GameLib.API.Renderer.TONE_MAPPING_LINEAR = 1;
|
||||
GameLib.API.Renderer.TONE_MAPPING_REINHARD = 2;
|
||||
GameLib.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3;
|
||||
GameLib.API.Renderer.TONE_MAPPING_CINEON = 4;
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Renderer.D2
|
||||
* @constructor
|
||||
* @param apiRenderer
|
||||
*/
|
||||
GameLib.API.Renderer.D2 = function (
|
||||
apiRenderer
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRenderer)) {
|
||||
apiRenderer = {
|
||||
rendererType : GameLib.API.Renderer.RENDERER_TYPE_2D
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRenderer.rendererType)) {
|
||||
apiRenderer.rendererType = GameLib.API.Renderer.RENDERER_TYPE_2D;
|
||||
}
|
||||
|
||||
GameLib.API.Renderer.call(
|
||||
this,
|
||||
apiRenderer.id,
|
||||
apiRenderer.name,
|
||||
apiRenderer.rendererType,
|
||||
apiRenderer.parentEntity,
|
||||
apiRenderer.width,
|
||||
apiRenderer.height,
|
||||
apiRenderer.offset,
|
||||
apiRenderer.canvas
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Renderer.D2.prototype = Object.create(GameLib.API.Renderer.prototype);
|
||||
GameLib.API.Renderer.D2.prototype.constructor = GameLib.API.Renderer.D2;
|
|
@ -1,266 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.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 (GameLib.Utils.UndefinedOrNull(apiRenderer)) {
|
||||
apiRenderer = {
|
||||
rendererType : GameLib.API.Renderer.RENDERER_TYPE_3D
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRenderer.rendererType)) {
|
||||
apiRenderer.rendererType = GameLib.API.Renderer.RENDERER_TYPE_3D;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderMode)) {
|
||||
renderMode = GameLib.API.Renderer.MODE_CANVAS;
|
||||
}
|
||||
this.renderMode = renderMode;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
||||
autoClear = true;
|
||||
}
|
||||
this.autoClear = autoClear;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClearColor)) {
|
||||
autoClearColor = true;
|
||||
}
|
||||
this.autoClearColor = autoClearColor;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClearDepth)) {
|
||||
autoClearDepth = true;
|
||||
}
|
||||
this.autoClearDepth = autoClearDepth;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClearStencil)) {
|
||||
autoClearStencil = true;
|
||||
}
|
||||
this.autoClearStencil = autoClearStencil;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(gammaFactor)) {
|
||||
gammaFactor = 2;
|
||||
}
|
||||
this.gammaFactor = gammaFactor;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(gammaInput)) {
|
||||
gammaInput = false;
|
||||
}
|
||||
this.gammaInput = gammaInput;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(gammaOutput)) {
|
||||
gammaOutput = false;
|
||||
}
|
||||
this.gammaOutput = gammaOutput;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxMorphTargets)) {
|
||||
maxMorphTargets = 8;
|
||||
}
|
||||
this.maxMorphTargets = maxMorphTargets;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxMorphNormals)) {
|
||||
maxMorphNormals = 4;
|
||||
}
|
||||
this.maxMorphNormals = maxMorphNormals;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(physicallyCorrectLights)) {
|
||||
physicallyCorrectLights = false;
|
||||
}
|
||||
this.physicallyCorrectLights = physicallyCorrectLights;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapEnabled)) {
|
||||
shadowMapEnabled = false;
|
||||
}
|
||||
this.shadowMapEnabled = shadowMapEnabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapAutoUpdate)) {
|
||||
shadowMapAutoUpdate = true;
|
||||
}
|
||||
this.shadowMapAutoUpdate = shadowMapAutoUpdate;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) {
|
||||
shadowMapNeedsUpdate = false;
|
||||
}
|
||||
this.shadowMapNeedsUpdate = shadowMapNeedsUpdate;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapType)) {
|
||||
shadowMapType = GameLib.API.Renderer.SHADOW_MAP_TYPE_BASIC;
|
||||
}
|
||||
this.shadowMapType = shadowMapType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) {
|
||||
shadowMapRenderReverseSided = true;
|
||||
}
|
||||
this.shadowMapRenderReverseSided = shadowMapRenderReverseSided;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) {
|
||||
shadowMapRenderSingleSided = true;
|
||||
}
|
||||
this.shadowMapRenderSingleSided = shadowMapRenderSingleSided;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(sortObjects)) {
|
||||
sortObjects = true;
|
||||
}
|
||||
this.sortObjects = sortObjects;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(toneMapping)) {
|
||||
toneMapping = GameLib.API.Renderer.TONE_MAPPING_LINEAR;
|
||||
}
|
||||
this.toneMapping = toneMapping;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(toneMappingExposure)) {
|
||||
toneMappingExposure = 1;
|
||||
}
|
||||
this.toneMappingExposure = toneMappingExposure;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(toneMappingWhitePoint)) {
|
||||
toneMappingWhitePoint = 1;
|
||||
}
|
||||
this.toneMappingWhitePoint = toneMappingWhitePoint;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) {
|
||||
premultipliedAlpha = true;
|
||||
}
|
||||
this.premultipliedAlpha = premultipliedAlpha;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(antialias)) {
|
||||
antialias = false;
|
||||
}
|
||||
this.antialias = antialias;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(stencil)) {
|
||||
stencil = true;
|
||||
}
|
||||
this.stencil = stencil;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
||||
preserveDrawingBuffer = false;
|
||||
}
|
||||
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(depth)) {
|
||||
depth = true;
|
||||
}
|
||||
this.depth = depth;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(logarithmicDepthBuffer)) {
|
||||
logarithmicDepthBuffer = false;
|
||||
}
|
||||
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(localClippingEnabled)) {
|
||||
localClippingEnabled = false;
|
||||
}
|
||||
this.localClippingEnabled = localClippingEnabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||
renderTarget = null;
|
||||
}
|
||||
this.renderTarget = renderTarget;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||
clippingPlanes = [];
|
||||
}
|
||||
this.clippingPlanes = clippingPlanes;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(clearColor)) {
|
||||
clearColor = new GameLib.API.Color(0.11, 0.11, 0.11);
|
||||
}
|
||||
this.clearColor = clearColor;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(viewports)) {
|
||||
viewports = [new GameLib.D3.API.Viewport(
|
||||
null,
|
||||
null,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0
|
||||
)];
|
||||
}
|
||||
this.viewports = viewports;
|
||||
|
||||
GameLib.API.Renderer.call(
|
||||
this,
|
||||
apiRenderer.id,
|
||||
apiRenderer.name,
|
||||
apiRenderer.rendererType,
|
||||
apiRenderer.parentEntity,
|
||||
apiRenderer.width,
|
||||
apiRenderer.height,
|
||||
apiRenderer.offset,
|
||||
apiRenderer.canvas
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Renderer.D3.prototype = Object.create(GameLib.API.Renderer.prototype);
|
||||
GameLib.API.Renderer.D3.prototype.constructor = GameLib.API.Renderer.D3;
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
GameLib.API.Server = function(
|
||||
id,
|
||||
name,
|
||||
protocol,
|
||||
ip,
|
||||
port,
|
||||
protocols,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Server (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(protocol)) {
|
||||
protocol = 'http';
|
||||
}
|
||||
this.protocol = protocol;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(ip)) {
|
||||
ip = '127.0.0.1';
|
||||
}
|
||||
this.ip = ip;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(port)) {
|
||||
port = 80;
|
||||
}
|
||||
this.port = port;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(protocols)) {
|
||||
protocols = [];
|
||||
}
|
||||
this.protocols = protocols;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.SERVER,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Server.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Server.prototype.constructor = GameLib.API.Server;
|
||||
|
||||
/**
|
||||
* Creates an API Server from an Object Server
|
||||
* @param objectServer
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Server.FromObject = function(objectServer) {
|
||||
|
||||
return new GameLib.API.Server(
|
||||
objectServer.id,
|
||||
objectServer.name,
|
||||
objectServer.protocol,
|
||||
objectServer.ip,
|
||||
objectServer.port,
|
||||
objectServer.protocols,
|
||||
objectServer.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Raw Socket API object - should always correspond with the Socket Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param socketType
|
||||
* @param roomId
|
||||
* @param peerId
|
||||
* @param server GameLib.Server
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket = function(
|
||||
id,
|
||||
name,
|
||||
socketType,
|
||||
roomId,
|
||||
peerId,
|
||||
server,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Socket (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(socketType)) {
|
||||
socketType = GameLib.API.Socket.TYPE_NONE;
|
||||
}
|
||||
this.socketType = socketType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(roomId)) {
|
||||
roomId = 'room_' + GameLib.Utils.RandomId();
|
||||
}
|
||||
this.roomId = roomId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(peerId)) {
|
||||
peerId = null;
|
||||
}
|
||||
this.peerId = peerId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(server)) {
|
||||
server = null;
|
||||
}
|
||||
this.server = server;
|
||||
|
||||
var componentType = GameLib.Component.SOCKET;
|
||||
|
||||
if (this.socketType === GameLib.API.Socket.TYPE_CAST) {
|
||||
componentType = GameLib.Component.SOCKET_CAST;
|
||||
}
|
||||
|
||||
if (this.socketType === GameLib.API.Socket.TYPE_RECEIVE) {
|
||||
componentType = GameLib.Component.SOCKET_RECEIVE;
|
||||
}
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
componentType,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Socket.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Socket.prototype.constructor = GameLib.API.Socket;
|
||||
|
||||
GameLib.API.Socket.TYPE_NONE = 0x1;
|
||||
GameLib.API.Socket.TYPE_CAST = 0x2;
|
||||
GameLib.API.Socket.TYPE_RECEIVE = 0x3;
|
||||
|
||||
/**
|
||||
* Creates an API Socket from an Object Socket
|
||||
* @param objectSocket
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket.FromObject = function(objectSocket) {
|
||||
|
||||
return new GameLib.API.Socket(
|
||||
objectSocket.id,
|
||||
objectSocket.name,
|
||||
objectSocket.socketType,
|
||||
objectSocket.roomId,
|
||||
objectSocket.peerId,
|
||||
objectSocket.server,
|
||||
objectSocket.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* Raw Cast API object - should always correspond with the Cast Schema
|
||||
* @param apiSocket
|
||||
* @param castType
|
||||
* @param source
|
||||
* @param sourceProperties
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket.Cast = function(
|
||||
apiSocket,
|
||||
castType,
|
||||
source,
|
||||
sourceProperties
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||
apiSocket = {
|
||||
socketType : GameLib.API.Socket.SOCKET_CAST
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Socket.call(
|
||||
this,
|
||||
apiSocket.id,
|
||||
apiSocket.name,
|
||||
apiSocket.socketType,
|
||||
apiSocket.roomId,
|
||||
apiSocket.peerId,
|
||||
apiSocket.server,
|
||||
apiSocket.parentEntity
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(castType)) {
|
||||
castType = GameLib.API.Socket.Cast.CAST_TYPE_ROOM;
|
||||
}
|
||||
this.castType = castType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(source)) {
|
||||
source = null;
|
||||
}
|
||||
this.source = source;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(sourceProperties)) {
|
||||
sourceProperties = null;
|
||||
}
|
||||
this.sourceProperties = sourceProperties;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.SOCKET_CAST
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Socket.Cast.prototype = Object.create(GameLib.API.Socket.prototype);
|
||||
GameLib.API.Socket.Cast.prototype.constructor = GameLib.API.Socket.Cast.Receive;
|
||||
|
||||
GameLib.API.Socket.Cast.CAST_TYPE_ROOM = 0x1;
|
||||
GameLib.API.Socket.Cast.CAST_TYPE_PEER = 0x2;
|
||||
GameLib.API.Socket.Cast.CAST_TYPE_ALL = 0x3;
|
||||
GameLib.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an API.Socket.Cast from an Object Cast
|
||||
* @param objectSocketCast
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket.Cast.FromObject = function(objectSocketCast) {
|
||||
|
||||
var apiSocket = GameLib.API.Socket.FromObject(objectSocketCast);
|
||||
|
||||
return new GameLib.API.Socket.Cast(
|
||||
apiSocket,
|
||||
objectSocketCast.castType,
|
||||
objectSocketCast.source,
|
||||
objectSocketCast.sourceProperties
|
||||
);
|
||||
};
|
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* Raw Socket.Receive API object - should always correspond with the Socket.Receive Schema
|
||||
* @param apiSocket
|
||||
* @param receiveType
|
||||
* @param destination
|
||||
* @param destinationProperties
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket.Receive = function(
|
||||
apiSocket,
|
||||
receiveType,
|
||||
destination,
|
||||
destinationProperties
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||
apiSocket = {
|
||||
socketType : GameLib.API.Socket.SOCKET_RECEIVE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Socket.call(
|
||||
this,
|
||||
apiSocket.id,
|
||||
apiSocket.name,
|
||||
apiSocket.socketType,
|
||||
apiSocket.roomId,
|
||||
apiSocket.peerId,
|
||||
apiSocket.server,
|
||||
apiSocket.parentEntity
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(receiveType)) {
|
||||
receiveType = GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM;
|
||||
}
|
||||
this.receiveType = receiveType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(destination)) {
|
||||
destination = null;
|
||||
}
|
||||
this.destination = destination;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(destinationProperties)) {
|
||||
destinationProperties = null;
|
||||
}
|
||||
this.destinationProperties = destinationProperties;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.SOCKET_RECEIVE
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Socket.Receive.prototype = Object.create(GameLib.API.Socket.prototype);
|
||||
GameLib.API.Socket.Receive.prototype.constructor = GameLib.API.Socket.Receive;
|
||||
|
||||
GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1;
|
||||
GameLib.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2;
|
||||
|
||||
/**
|
||||
* Creates an API Socket.Receive from an Object Socket.Receive
|
||||
* @param socket GameLib.SocketsRuntime
|
||||
* @param objectSocketReceive
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) {
|
||||
|
||||
var apiSocket = GameLib.API.Socket.FromObject(objectSocketReceive);
|
||||
|
||||
return new GameLib.API.Socket.Receive(
|
||||
apiSocket,
|
||||
objectSocketReceive.receiveType,
|
||||
objectSocketReceive.destination,
|
||||
objectSocketReceive.destinationProperties
|
||||
);
|
||||
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* GameLib.API.Sphere
|
||||
* @constructor
|
||||
* @param center
|
||||
* @param radius
|
||||
*/
|
||||
GameLib.API.Sphere = function (
|
||||
center,
|
||||
radius
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(center)) {
|
||||
center = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.center = center;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
};
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* Raw Stats API object - should always correspond with the Stats Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param domElement
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Stats = function(
|
||||
id,
|
||||
name,
|
||||
domElement,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Stats (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
||||
domElement = null;
|
||||
}
|
||||
this.domElement = domElement;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.STATS,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Stats.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.Stats.prototype.constructor = GameLib.API.Stats;
|
||||
|
||||
/**
|
||||
* Creates an API Stats from an Object Stats
|
||||
* @param objectStats
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.Stats.FromObject = function(objectStats) {
|
||||
|
||||
var apiDomElement = null;
|
||||
if (objectStats.domElement) {
|
||||
if (objectStats.domElement instanceof Object) {
|
||||
apiDomElement = GameLib.API.DomElement.FromObject(objectStats.domElement);
|
||||
} else {
|
||||
apiDomElement = objectStats.domElement;
|
||||
}
|
||||
}
|
||||
|
||||
return new GameLib.API.Stats(
|
||||
objectStats.id,
|
||||
objectStats.name,
|
||||
apiDomElement,
|
||||
objectStats.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* This component renders a scene
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param systemType
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.System = function (
|
||||
id,
|
||||
name,
|
||||
systemType,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = "System (" + this.id + ")";
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(systemType)) {
|
||||
systemType = GameLib.System.SYSTEM_TYPE_NONE;
|
||||
}
|
||||
this.systemType = systemType;
|
||||
|
||||
var componentType = GameLib.Component.SYSTEM;
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_NONE) {
|
||||
componentType = GameLib.Component.SYSTEM;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||
componentType = GameLib.Component.SYSTEM_ANIMATION;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_CUSTOM) {
|
||||
componentType = GameLib.Component.SYSTEM_CUSTOM_CODE;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
|
||||
componentType = GameLib.Component.SYSTEM_GUI;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
|
||||
componentType = GameLib.Component.SYSTEM_INPUT;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_LINKING) {
|
||||
componentType = GameLib.Component.SYSTEM_LINKING;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_PHYSICS) {
|
||||
componentType = GameLib.Component.SYSTEM_PHYSICS;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
|
||||
componentType = GameLib.Component.SYSTEM_RENDER;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) {
|
||||
componentType = GameLib.Component.SYSTEM_STORAGE;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_VISUALIZATION) {
|
||||
componentType = GameLib.Component.SYSTEM_VISUALIZATION;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_PARTICLE) {
|
||||
componentType = GameLib.Component.SYSTEM_PARTICLE;
|
||||
}
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_AUDIO) {
|
||||
componentType = GameLib.Component.SYSTEM_AUDIO;
|
||||
}
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
componentType,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.System.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.API.System.prototype.constructor = GameLib.API.System;
|
||||
|
||||
/**
|
||||
* Object to GameLib.D3.API.System
|
||||
* @param objectComponent
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.API.System.FromObject = function(objectComponent) {
|
||||
return new GameLib.API.System(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.systemType,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -1,42 +0,0 @@
|
|||
GameLib.API.Vector2 = function (x, y) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Vector2.prototype.copy = function () {
|
||||
return new GameLib.API.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.API.Vector2.FromObject = function (objectVector) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||
console.warn('vector from db undefined - stale version in db');
|
||||
objectVector = {};
|
||||
}
|
||||
|
||||
return new GameLib.API.Vector2(
|
||||
objectVector.x,
|
||||
objectVector.y
|
||||
)
|
||||
};
|
|
@ -1,277 +0,0 @@
|
|||
GameLib.API.Vector3 = function (x, y, z) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.negate = function() {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
this.z = -this.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.subtract = function (v) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x - v.x,
|
||||
this.y - v.y,
|
||||
this.z - v.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.sub = function (v) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x - v.x,
|
||||
this.y - v.y,
|
||||
this.z - v.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.equals = function (v) {
|
||||
return this.x === v.x && this.y === v.y && this.z === v.z;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.cross = function (v) {
|
||||
return new GameLib.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
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.clockwise = function (u, v, w, viewPoint) {
|
||||
var normal = GameLib.API.Vector3.normal(u, v, w);
|
||||
var uv = u.copy();
|
||||
var winding = normal.dot(uv.subtract(viewPoint));
|
||||
return (winding > 0);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.normal = function (u, v, w) {
|
||||
var vv = v.copy();
|
||||
var wv = w.copy();
|
||||
return vv.subtract(u).cross(wv.subtract(u));
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.lookAt = function (at, up) {
|
||||
var lookAtMatrix = GameLib.API.Matrix4.lookAt(this, at, up);
|
||||
return this.multiply(lookAtMatrix);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.squared = function () {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.copy = function () {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.set = function (x, y, z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x + ( v.x - this.x ) * alpha,
|
||||
this.y + ( v.y - this.y ) * alpha,
|
||||
this.z + ( v.z - this.z ) * alpha
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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}
|
||||
*/
|
||||
GameLib.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 | GameLib.API.Vector3 | GameLib.API.Vector4 | GameLib.API.Matrix3 | GameLib.API.Matrix4}
|
||||
* @param cross boolean true if you want the cross product, otherwise returns the scalar (dot or inner) product
|
||||
* @returns {GameLib.API.Vector3 | Number}
|
||||
*/
|
||||
GameLib.API.Vector3.prototype.multiply = function (object, cross) {
|
||||
|
||||
var x, y, z;
|
||||
|
||||
var a = object;
|
||||
var b = this;
|
||||
|
||||
if (GameLib.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 GameLib.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");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GameLib.API.Vector3.prototype.dot = function (v) {
|
||||
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.API.Vector3(
|
||||
this.x * invLength,
|
||||
this.y * invLength,
|
||||
this.z * invLength
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.clone = function () {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.length = function() {
|
||||
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
|
||||
};
|
||||
|
||||
GameLib.API.Vector3.prototype.reflect = function(normal) {
|
||||
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.API.Vector3.FromObject = function (objectVector) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||
console.warn('vector from db undefined - stale version in db');
|
||||
objectVector = {};
|
||||
}
|
||||
|
||||
return new GameLib.API.Vector3(
|
||||
objectVector.x,
|
||||
objectVector.y,
|
||||
objectVector.z
|
||||
)
|
||||
};
|
|
@ -1,46 +0,0 @@
|
|||
GameLib.API.Vector4 = function (x, y, z, w) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(w)) {
|
||||
w = 1;
|
||||
}
|
||||
this.w = w;
|
||||
};
|
||||
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.API.Vector4.FromObject = function (objectVector) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectVector)) {
|
||||
console.warn('vector from db undefined - stale version in db');
|
||||
objectVector = {};
|
||||
}
|
||||
|
||||
return new GameLib.API.Vector4(
|
||||
objectVector.x,
|
||||
objectVector.y,
|
||||
objectVector.z,
|
||||
objectVector.w
|
||||
)
|
||||
};
|
|
@ -1,97 +0,0 @@
|
|||
/**
|
||||
* GameLib.Box3
|
||||
* @param implementation
|
||||
* @param apiBox3
|
||||
* @param parentObject
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Box3 = function (
|
||||
implementation,
|
||||
apiBox3,
|
||||
parentObject
|
||||
) {
|
||||
|
||||
this.implementation = implementation;
|
||||
this.implementation.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiBox3)) {
|
||||
apiBox3 = {};
|
||||
}
|
||||
|
||||
GameLib.API.Box3.call(
|
||||
this,
|
||||
apiBox3.id,
|
||||
apiBox3.name,
|
||||
apiBox3.parentEntity,
|
||||
apiBox3.min,
|
||||
apiBox3.max
|
||||
);
|
||||
|
||||
this.min = new GameLib.Vector3(
|
||||
this.implementation,
|
||||
this.min,
|
||||
this
|
||||
);
|
||||
|
||||
this.max = new GameLib.Vector3(
|
||||
this.implementation,
|
||||
this.max,
|
||||
this
|
||||
);
|
||||
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Box3.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.Box3.prototype.constructor = GameLib.Box3;
|
||||
|
||||
/**
|
||||
* Creates an instance GameLib.Box3
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Box3.prototype.createInstance = function() {
|
||||
|
||||
this.instance = new THREE.Box3(
|
||||
this.min.instance,
|
||||
this.max.instance
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates GameLib.Box3 instance
|
||||
* @param property
|
||||
*/
|
||||
GameLib.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;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.Box3 to GameLib.API.Box3
|
||||
* @returns {GameLib.API.Box3}
|
||||
*/
|
||||
GameLib.Box3.prototype.toApiObject = function() {
|
||||
return new GameLib.API.Box3(
|
||||
this.id,
|
||||
this.name,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
this.min.toApiObject(),
|
||||
this.max.toApiObject()
|
||||
);
|
||||
};
|
|
@ -1,335 +0,0 @@
|
|||
/**
|
||||
* Canvas object
|
||||
* @param graphics
|
||||
* @param apiCanvas
|
||||
* @returns {GameLib.Canvas}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Canvas = function(
|
||||
graphics,
|
||||
apiCanvas
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCanvas)) {
|
||||
apiCanvas = {};
|
||||
}
|
||||
|
||||
GameLib.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 GameLib.Vector2(
|
||||
this.graphics,
|
||||
this.offset,
|
||||
this
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
{
|
||||
'parentTexture' : GameLib.D3.Texture,
|
||||
'texts' : [GameLib.D3.Text]
|
||||
}
|
||||
);
|
||||
|
||||
this.context = null;
|
||||
};
|
||||
|
||||
GameLib.Canvas.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.Canvas.prototype.constructor = GameLib.Canvas;
|
||||
|
||||
/**
|
||||
* Creates a light instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.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;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.Canvas.prototype.updateInstance = function(property) {
|
||||
|
||||
if (GameLib.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;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Canvas to a GameLib.API.Canvas
|
||||
* @returns {GameLib.API.Canvas}
|
||||
*/
|
||||
GameLib.Canvas.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.API.Canvas(
|
||||
this.id,
|
||||
this.name,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
GameLib.Utils.IdOrNull(this.parentTexture),
|
||||
this.autoUpdateSize,
|
||||
this.width,
|
||||
this.height,
|
||||
this.offset.toApiObject(),
|
||||
this.tabIndex,
|
||||
this.texts.map(function(text){
|
||||
return GameLib.Utils.IdOrNull(text)
|
||||
}),
|
||||
this.textBaseline
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.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)
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Canvas.prototype.clear = function() {
|
||||
|
||||
if (!this.context) {
|
||||
this.context = this.instance.getContext('2d');
|
||||
}
|
||||
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
GameLib.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);
|
||||
};
|
||||
|
||||
GameLib.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);
|
||||
};
|
||||
|
||||
GameLib.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();
|
||||
};
|
||||
|
||||
GameLib.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);
|
||||
};
|
||||
|
||||
GameLib.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);
|
||||
};
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Creates a Clock object
|
||||
* @param graphics
|
||||
* @param apiClock GameLib.API.Clock
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Clock = function(
|
||||
graphics,
|
||||
apiClock
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiClock)) {
|
||||
apiClock = {};
|
||||
}
|
||||
|
||||
GameLib.API.Clock.call(
|
||||
this,
|
||||
apiClock.id,
|
||||
apiClock.name,
|
||||
apiClock.parentEntity
|
||||
);
|
||||
|
||||
GameLib.Component.call(this);
|
||||
} ;
|
||||
|
||||
GameLib.Clock.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.Clock.prototype.constructor = GameLib.Clock;
|
||||
|
||||
/**
|
||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||
* @returns {THREE.Clock}
|
||||
*/
|
||||
GameLib.Clock.prototype.createInstance = function() {
|
||||
|
||||
this.instance = new THREE.Clock();
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.Clock.prototype.updateInstance = function() {
|
||||
|
||||
};
|
||||
|
||||
GameLib.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 GameLib.Clock to a new GameLib.API.Clock
|
||||
* @returns {GameLib.API.Clock}
|
||||
*/
|
||||
GameLib.Clock.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.API.Clock(
|
||||
this.id,
|
||||
this.name,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object camera to a GameLib.Clock
|
||||
* @param graphics GameLib.Graphics
|
||||
* @param objectClock Object
|
||||
* @returns {GameLib.Clock}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Clock.FromObject = function(graphics, objectClock) {
|
||||
|
||||
var apiClock = GameLib.API.Clock.FromObject(objectClock);
|
||||
|
||||
return new GameLib.Clock(
|
||||
graphics,
|
||||
apiClock
|
||||
);
|
||||
|
||||
};
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Coder
|
||||
* @param id
|
||||
* @param name
|
||||
* @param coderType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.CoderRuntime = function(
|
||||
id,
|
||||
name,
|
||||
coderType
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Coder (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(coderType)) {
|
||||
coderType = GameLib.CoderRuntime.TYPE_CODE_MIRROR;
|
||||
}
|
||||
this.coderType = coderType;
|
||||
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.CoderRuntime Types
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.CoderRuntime.TYPE_CODE_MIRROR = 0x1;
|
||||
|
||||
GameLib.CoderRuntime.prototype.createInstance = function() {
|
||||
if (this.coderType === GameLib.CoderRuntime.TYPE_CODE_MIRROR) {
|
||||
this.instance = CodeMirror;
|
||||
} else {
|
||||
this.instance = null;
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.CoderRuntime.prototype.updateInstance = function(property) {
|
||||
if (property === 'coderType') {
|
||||
this.createInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a warning and throws an error if not cannon
|
||||
*/
|
||||
GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() {
|
||||
if (this.instance !== CodeMirror) {
|
||||
console.error('Only CodeMirror supported');
|
||||
throw new Error('Only CodeMirror supported');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
/**
|
||||
* Runtime color for updating instance objects
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiColor GameLib.API.Color
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Color = function (
|
||||
graphics,
|
||||
apiColor,
|
||||
parentObject,
|
||||
grain
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiColor)) {
|
||||
apiColor = {};
|
||||
}
|
||||
|
||||
GameLib.API.Color.call(
|
||||
this,
|
||||
apiColor.r,
|
||||
apiColor.g,
|
||||
apiColor.b,
|
||||
apiColor.a
|
||||
);
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Color.prototype = Object.create(GameLib.API.Color.prototype);
|
||||
GameLib.Color.prototype.constructor = GameLib.Color;
|
||||
|
||||
/**
|
||||
* Creates an instance color
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.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
|
||||
*/
|
||||
GameLib.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 {GameLib.API.Color}
|
||||
*/
|
||||
GameLib.Color.prototype.toApiObject = function() {
|
||||
return new GameLib.API.Color(
|
||||
this.r,
|
||||
this.g,
|
||||
this.b,
|
||||
this.a
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the current color to HTML hex format (ex. #ffffff)
|
||||
* @returns {string}
|
||||
*/
|
||||
GameLib.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}
|
||||
*/
|
||||
GameLib.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;
|
||||
};
|
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* GameLib.Controls
|
||||
* @param apiControls
|
||||
* @property controlsType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls = function (
|
||||
apiControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
||||
apiControls = {};
|
||||
}
|
||||
|
||||
GameLib.API.Controls.call(
|
||||
this,
|
||||
apiControls.id,
|
||||
apiControls.name,
|
||||
apiControls.controlsType,
|
||||
apiControls.canvas,
|
||||
apiControls.parentEntity
|
||||
);
|
||||
|
||||
var linkedObjects = {
|
||||
canvas : GameLib.Canvas
|
||||
};
|
||||
|
||||
var delayed = false;
|
||||
|
||||
switch (this.controlsType) {
|
||||
case (GameLib.API.Controls.CONTROLS_TYPE_EDITOR) :
|
||||
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
||||
linkedObjects.camera = GameLib.D3.Camera;
|
||||
delayed = true;
|
||||
break;
|
||||
case (GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON) :
|
||||
linkedObjects.camera = GameLib.D3.Camera;
|
||||
delayed = true;
|
||||
break;
|
||||
case (GameLib.API.Controls.CONTROLS_TYPE_ORBIT) :
|
||||
linkedObjects.camera = GameLib.D3.Camera;
|
||||
linkedObjects.target = GameLib.Component;
|
||||
delayed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
linkedObjects,
|
||||
delayed
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Controls.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.Controls.prototype.constructor = GameLib.Controls;
|
||||
|
||||
GameLib.Controls.D3 = function() {};
|
||||
GameLib.Controls.D3.prototype = Object.create(GameLib.Controls.prototype);
|
||||
GameLib.Controls.D3.prototype.constructor = GameLib.Controls.D3;
|
||||
|
||||
/**
|
||||
* Creates a mesh instance or updates it
|
||||
*/
|
||||
GameLib.Controls.prototype.createInstance = function() {
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the mesh instance
|
||||
*/
|
||||
GameLib.Controls.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'canvas') {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.CANVAS_CHANGE,
|
||||
{
|
||||
component: this
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls to a GameLib.API.Controls
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.prototype.toApiObject = function() {
|
||||
|
||||
var apiControls = new GameLib.API.Controls(
|
||||
this.id,
|
||||
this.name,
|
||||
this.controlsType,
|
||||
GameLib.Utils.IdOrNull(this.canvas),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiControls;
|
||||
};
|
|
@ -1,116 +0,0 @@
|
|||
/**
|
||||
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiEditorControls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.D3.Editor = function (
|
||||
graphics,
|
||||
apiEditorControls
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEditorControls)) {
|
||||
apiEditorControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull()) {
|
||||
apiEditorControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR;
|
||||
}
|
||||
|
||||
GameLib.API.Controls.D3.Editor.call(
|
||||
this,
|
||||
apiEditorControls,
|
||||
apiEditorControls.raycaster,
|
||||
apiEditorControls.camera
|
||||
);
|
||||
|
||||
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
this.graphics,
|
||||
this.raycaster
|
||||
);
|
||||
}
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiEditorControls
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.Editor.prototype = Object.create(GameLib.Controls.D3.prototype);
|
||||
GameLib.Controls.D3.Editor.prototype.constructor = GameLib.Controls.D3.Editor;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
*/
|
||||
GameLib.Controls.D3.Editor.prototype.createInstance = function() {
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.camera) ||
|
||||
GameLib.Utils.UndefinedOrNull(this.camera.instance)
|
||||
) {
|
||||
console.warn('no camera at time of editor-controls create instance');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.canvas) ||
|
||||
GameLib.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
|
||||
);
|
||||
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.D3.Editor.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'canvas' ||
|
||||
property === 'camera'
|
||||
) {
|
||||
if (GameLib.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');
|
||||
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.D3.Editor to a GameLib.D3.API.Mesh
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.Editor.prototype.toApiObject = function() {
|
||||
|
||||
var apiControls = GameLib.Controls.prototype.toApiObject.call(this);
|
||||
|
||||
apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster);
|
||||
apiControls.camera = GameLib.Utils.IdOrNull(this.camera);
|
||||
|
||||
return apiControls;
|
||||
};
|
|
@ -1,220 +0,0 @@
|
|||
/**
|
||||
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiFirstPersonControls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.D3.FirstPerson = function (
|
||||
graphics,
|
||||
apiFirstPersonControls
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiFirstPersonControls)) {
|
||||
apiFirstPersonControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull()) {
|
||||
apiFirstPersonControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON;
|
||||
}
|
||||
|
||||
GameLib.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
|
||||
);
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiFirstPersonControls
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.FirstPerson.prototype = Object.create(GameLib.Controls.D3.prototype);
|
||||
GameLib.Controls.D3.FirstPerson.prototype.constructor = GameLib.Controls.D3.FirstPerson;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
*/
|
||||
GameLib.Controls.D3.FirstPerson.prototype.createInstance = function() {
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.camera) ||
|
||||
GameLib.Utils.UndefinedOrNull(this.camera.instance)
|
||||
) {
|
||||
console.warn('no camera at time of editor-controls create instance');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.canvas) ||
|
||||
GameLib.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;
|
||||
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.D3.FirstPerson.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'canvas' ||
|
||||
property === 'camera'
|
||||
) {
|
||||
if (GameLib.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;
|
||||
}
|
||||
|
||||
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.D3.FirstPerson to a GameLib.D3.API.Mesh
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.FirstPerson.prototype.toApiObject = function() {
|
||||
|
||||
var apiControls = GameLib.Controls.prototype.toApiObject.call(this);
|
||||
|
||||
return new GameLib.API.Controls.D3.FirstPerson(
|
||||
apiControls,
|
||||
GameLib.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
|
||||
);
|
||||
};
|
|
@ -1,235 +0,0 @@
|
|||
/**
|
||||
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiOrbitControls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.D3.Orbit = function (
|
||||
graphics,
|
||||
apiOrbitControls
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiOrbitControls)) {
|
||||
apiOrbitControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_ORBIT
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull()) {
|
||||
apiOrbitControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_ORBIT;
|
||||
}
|
||||
|
||||
GameLib.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
|
||||
);
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiOrbitControls
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.Orbit.prototype = Object.create(GameLib.Controls.D3.prototype);
|
||||
GameLib.Controls.D3.Orbit.prototype.constructor = GameLib.Controls.D3.Orbit;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
*/
|
||||
GameLib.Controls.D3.Orbit.prototype.createInstance = function() {
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.camera) ||
|
||||
GameLib.Utils.UndefinedOrNull(this.camera.instance)
|
||||
) {
|
||||
console.warn('no camera at time of editor-controls create instance');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.canvas) ||
|
||||
GameLib.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;
|
||||
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.D3.Orbit.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'canvas' ||
|
||||
property === 'camera'
|
||||
) {
|
||||
if (GameLib.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;
|
||||
}
|
||||
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.D3.Orbit to a GameLib.D3.API.Mesh
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.D3.Orbit.prototype.toApiObject = function() {
|
||||
|
||||
var apiControls = GameLib.Controls.prototype.toApiObject.call(this);
|
||||
|
||||
return new GameLib.API.Controls.D3.Orbit(
|
||||
apiControls,
|
||||
GameLib.Utils.IdOrNull(this.camera),
|
||||
GameLib.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
|
||||
);
|
||||
};
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Keyboard Controls
|
||||
* @param apiKeyboardControls GameLib.API.Controls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.Keyboard = function (
|
||||
apiKeyboardControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiKeyboardControls)) {
|
||||
apiKeyboardControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Controls.Keyboard.call(
|
||||
this,
|
||||
apiKeyboardControls
|
||||
);
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiKeyboardControls
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.Keyboard.prototype = Object.create(GameLib.Controls.prototype);
|
||||
GameLib.Controls.Keyboard.prototype.constructor = GameLib.Controls.Keyboard;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
* @returns
|
||||
*/
|
||||
GameLib.Controls.Keyboard.prototype.createInstance = function() {
|
||||
/**
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
this.instance = true;
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.Keyboard.prototype.updateInstance = function(property) {
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.Keyboard to a GameLib.API.Controls
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.Keyboard.prototype.toApiObject = function() {
|
||||
var apiControls = GameLib.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 {GameLib.Controls.Keyboard}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.Keyboard.FromObject = function(objectControls) {
|
||||
|
||||
var apiKeyboardControls = GameLib.API.Controls.Keyboard.FromObject(objectControls);
|
||||
|
||||
return new GameLib.Controls.Keyboard(
|
||||
apiKeyboardControls
|
||||
);
|
||||
|
||||
};
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Mouse Controls
|
||||
* @param apiMouseControls GameLib.API.Controls
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.Mouse = function (
|
||||
apiMouseControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMouseControls)) {
|
||||
apiMouseControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Controls.Mouse.call(
|
||||
this,
|
||||
apiMouseControls
|
||||
);
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiMouseControls
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.Mouse.prototype = Object.create(GameLib.Controls.prototype);
|
||||
GameLib.Controls.Mouse.prototype.constructor = GameLib.Controls.Mouse;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
* @returns
|
||||
*/
|
||||
GameLib.Controls.Mouse.prototype.createInstance = function() {
|
||||
/**
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
this.instance = true;
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.Mouse.prototype.updateInstance = function(property) {
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.Mouse to a GameLib.API.Controls
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.Mouse.prototype.toApiObject = function() {
|
||||
var apiControls = GameLib.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 {GameLib.Controls.Mouse}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.Mouse.FromObject = function(objectControls) {
|
||||
|
||||
var apiMouseControls = GameLib.API.Controls.Mouse.FromObject(objectControls);
|
||||
|
||||
return new GameLib.Controls.Mouse(
|
||||
apiMouseControls
|
||||
);
|
||||
|
||||
};
|
|
@ -1,82 +0,0 @@
|
|||
/**
|
||||
* Touch Controls
|
||||
* @constructor
|
||||
* @param apiTouchControls
|
||||
*/
|
||||
GameLib.Controls.Touch = function (
|
||||
apiTouchControls
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiTouchControls)) {
|
||||
apiTouchControls = {
|
||||
controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Controls.Touch.call(
|
||||
this,
|
||||
apiTouchControls,
|
||||
apiTouchControls.sensitivity
|
||||
);
|
||||
|
||||
GameLib.Controls.call(
|
||||
this,
|
||||
apiTouchControls
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {GameLib.Controls}
|
||||
*/
|
||||
GameLib.Controls.Touch.prototype = Object.create(GameLib.Controls.prototype);
|
||||
GameLib.Controls.Touch.prototype.constructor = GameLib.Controls.Touch;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
* @returns
|
||||
*/
|
||||
GameLib.Controls.Touch.prototype.createInstance = function() {
|
||||
/**
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
this.instance = true;
|
||||
GameLib.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
GameLib.Controls.Touch.prototype.updateInstance = function(property) {
|
||||
GameLib.Controls.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Controls.Touch to a GameLib.API.Controls
|
||||
* @returns {GameLib.API.Controls}
|
||||
*/
|
||||
GameLib.Controls.Touch.prototype.toApiObject = function() {
|
||||
|
||||
var apiControls = GameLib.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 {GameLib.Controls.Touch}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Controls.Touch.FromObject = function(objectControls) {
|
||||
|
||||
var apiTouchControls = GameLib.API.Controls.Touch.FromObject(objectControls);
|
||||
|
||||
return new GameLib.Controls.Touch(apiTouchControls);
|
||||
|
||||
};
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* GameLib.Curve
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCurve GameLib.API.Curve
|
||||
* @property curveType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Curve = function(
|
||||
graphics,
|
||||
apiCurve
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurve)) {
|
||||
apiCurve = {};
|
||||
}
|
||||
|
||||
GameLib.API.Curve.call(
|
||||
this,
|
||||
apiCurve.id,
|
||||
apiCurve.name,
|
||||
apiCurve.curveType,
|
||||
apiCurve.parentEntity,
|
||||
apiCurve.arcLenghDivisions
|
||||
);
|
||||
|
||||
var linkedObjects = {};
|
||||
|
||||
switch (this.curveType) {
|
||||
case GameLib.API.Curve.CURVE_TYPE_PATH :
|
||||
linkedObjects.curves = [GameLib.Curve];
|
||||
break;
|
||||
}
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
linkedObjects
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.Curve.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.Curve.prototype.constructor = GameLib.Curve;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
*/
|
||||
GameLib.Curve.prototype.createInstance = function() {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
console.warn('you should not instantiate this curve object directly');
|
||||
this.instance = new THREE.Curve();
|
||||
}
|
||||
|
||||
this.instance.arcLenghDivisions = this.arcLenghDivisions;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.Curve.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'arcLenghDivisions') {
|
||||
this.instance.arcLenghDivisions = this.arcLenghDivisions;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Curve to a new GameLib.API.Curve
|
||||
* @returns {GameLib.API.Curve}
|
||||
*/
|
||||
GameLib.Curve.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.API.Curve(
|
||||
this.id,
|
||||
this.name,
|
||||
this.curveType,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
this.arcLenghDivisions
|
||||
);
|
||||
|
||||
};
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
* GameLib.Curve.Path
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCurvePath
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Curve.Path = function(
|
||||
graphics,
|
||||
apiCurvePath
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) {
|
||||
apiCurvePath = {
|
||||
curveType : GameLib.API.Curve.CURVE_TYPE_PATH
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Curve.Path.call(
|
||||
this,
|
||||
apiCurvePath,
|
||||
apiCurvePath.curves,
|
||||
apiCurvePath.autoClose
|
||||
);
|
||||
|
||||
this.curves = this.curves.map(
|
||||
function(curve) {
|
||||
if (curve instanceof GameLib.API.Curve) {
|
||||
return new GameLib.Curve(
|
||||
this.graphics,
|
||||
curve
|
||||
);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
GameLib.Curve.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.Curve.Path.prototype = Object.create(GameLib.Curve.prototype);
|
||||
GameLib.Curve.Path.prototype.constructor = GameLib.Curve.Path;
|
||||
|
||||
/**
|
||||
* Creates a camera instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Curve.Path.prototype.createInstance = function() {
|
||||
|
||||
if (GameLib.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;
|
||||
|
||||
GameLib.Curve.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.Curve.Path.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'curves') {
|
||||
console.warn('todo: update curves');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoClose') {
|
||||
this.instance.autoClose = this.autoClose;
|
||||
return;
|
||||
}
|
||||
|
||||
GameLib.Curve.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Curve to a GameLib.API.Curve
|
||||
* @returns {GameLib.API.Curve}
|
||||
*/
|
||||
GameLib.Curve.Path.prototype.toApiObject = function() {
|
||||
|
||||
var apiCurve = GameLib.Curve.prototype.toApiObject.call(this);
|
||||
|
||||
var apiCurvePath = new GameLib.API.Curve.Path(
|
||||
apiCurve,
|
||||
this.curves.map(
|
||||
function(curve) {
|
||||
return GameLib.Utils.IdOrNull(curve);
|
||||
}
|
||||
),
|
||||
this.autoClose
|
||||
);
|
||||
|
||||
return apiCurvePath;
|
||||
};
|
|
@ -1,101 +0,0 @@
|
|||
/**
|
||||
* GameLib.Curve.Path.D2
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCurvePath
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Curve.Path.D2 = function(
|
||||
graphics,
|
||||
apiCurvePath
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) {
|
||||
apiCurvePath = {
|
||||
curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Curve.Path.D2.call(
|
||||
this,
|
||||
apiCurvePath,
|
||||
apiCurvePath.points
|
||||
);
|
||||
|
||||
this.points = this.points.map(
|
||||
function(point) {
|
||||
return new GameLib.Vector2(
|
||||
this.graphics,
|
||||
point
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
GameLib.Curve.Path.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.Curve.Path.D2.prototype = Object.create(GameLib.Curve.Path.prototype);
|
||||
GameLib.Curve.Path.D2.prototype.constructor = GameLib.Curve.Path.D2;
|
||||
|
||||
/**
|
||||
* Creates a camera instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Curve.Path.D2.prototype.createInstance = function() {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
this.instance = new THREE.Path(
|
||||
this.points.map(
|
||||
function(point) {
|
||||
return point.instance;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
GameLib.Curve.Path.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.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;
|
||||
}
|
||||
|
||||
GameLib.Curve.Path.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Curve to a GameLib.API.Curve
|
||||
* @returns {GameLib.API.Curve}
|
||||
*/
|
||||
GameLib.Curve.Path.D2.prototype.toApiObject = function() {
|
||||
|
||||
var apiCurvePath = GameLib.Curve.Path.prototype.toApiObject.call(this);
|
||||
|
||||
return new GameLib.API.Curve.Path.D2(
|
||||
apiCurvePath,
|
||||
this.points.map(
|
||||
function(point) {
|
||||
return point.toApiObject();
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
};
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
* GameLib.Curve.Path.D2
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCurvePathD2
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Curve.Path.D2.Shape = function(
|
||||
graphics,
|
||||
apiCurvePathD2
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) {
|
||||
apiCurvePathD2 = {
|
||||
curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.API.Curve.Path.D2.call(
|
||||
this,
|
||||
apiCurvePathD2,
|
||||
apiCurvePathD2.points
|
||||
);
|
||||
|
||||
GameLib.Curve.Path.D2.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.Curve.Path.D2.Shape.prototype = Object.create(GameLib.Curve.Path.D2.prototype);
|
||||
GameLib.Curve.Path.D2.Shape.prototype.constructor = GameLib.Curve.Path.D2.Shape;
|
||||
|
||||
/**
|
||||
* Creates a camera instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Curve.Path.D2.Shape.prototype.createInstance = function() {
|
||||
|
||||
this.instance = new THREE.Shape(
|
||||
this.points.map(
|
||||
function(point) {
|
||||
return point.instance;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
GameLib.Curve.Path.D2.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.Curve.Path.D2.Shape.prototype.updateInstance = function(property) {
|
||||
GameLib.Curve.Path.D2.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Curve to a GameLib.API.Curve
|
||||
* @returns {GameLib.API.Curve}
|
||||
*/
|
||||
GameLib.Curve.Path.D2.Shape.prototype.toApiObject = function() {
|
||||
|
||||
var apiCurvePathD2 = GameLib.Curve.Path.D2.prototype.toApiObject.call(this);
|
||||
|
||||
return new GameLib.API.Curve.Path.D2.Shape(
|
||||
apiCurvePathD2
|
||||
);
|
||||
|
||||
};
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* Creates a CustomCode object
|
||||
* @param apiCustomCode GameLib.API.CustomCode
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.CustomCode = function(
|
||||
apiCustomCode
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCustomCode)) {
|
||||
apiCustomCode = {};
|
||||
}
|
||||
|
||||
GameLib.API.CustomCode.call(
|
||||
this,
|
||||
apiCustomCode.id,
|
||||
apiCustomCode.name,
|
||||
apiCustomCode.eventId,
|
||||
apiCustomCode.code,
|
||||
apiCustomCode.parentEntity
|
||||
);
|
||||
|
||||
this.editor = null;
|
||||
|
||||
GameLib.Component.call(this);
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.CustomCode.prototype.constructor = GameLib.CustomCode;
|
||||
|
||||
GameLib.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);
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.CustomCode.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'name') {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.NAME_UPDATE,
|
||||
{
|
||||
component : this
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'code') {
|
||||
|
||||
try {
|
||||
this.instance = new Function('data', this.code).bind(this);
|
||||
this.publish(
|
||||
GameLib.Event.COMPILE_SUCCESS,
|
||||
{
|
||||
component: this
|
||||
}
|
||||
)
|
||||
} catch (error) {
|
||||
this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this);
|
||||
this.publish(
|
||||
GameLib.Event.COMPILE_FAILED,
|
||||
{
|
||||
component: this
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'eventId') {
|
||||
this.publish(
|
||||
GameLib.Event.EVENT_ID_UPDATE,
|
||||
{
|
||||
component : this
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.CustomCode to a new GameLib.API.CustomCode
|
||||
* @returns {GameLib.API.CustomCode}
|
||||
*/
|
||||
GameLib.CustomCode.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.API.CustomCode(
|
||||
this.id,
|
||||
this.name,
|
||||
this.eventId,
|
||||
this.code,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.launchEditor = function(){
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.GET_RUNTIME,
|
||||
null,
|
||||
function(runtime) {
|
||||
this.coder = runtime.coder;
|
||||
this.coder.isNotCodeMirrorThrow();
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this instanceof GameLib.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 GameLib.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))
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.closeEditor = function(){
|
||||
var dom = this.editor.getWrapperElement();
|
||||
dom.parentElement.removeChild(dom);
|
||||
};
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.D3.API.Object = function(
|
||||
id,
|
||||
name,
|
||||
objectType,
|
||||
parentEntity,
|
||||
useQuaternion,
|
||||
position,
|
||||
quaternion,
|
||||
rotation,
|
||||
scale,
|
||||
up,
|
||||
lookAt
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectType)) {
|
||||
objectType = 0;
|
||||
}
|
||||
this.objectType = objectType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
switch (this.objectType) {
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_NONE :
|
||||
name = 'Object';
|
||||
break;
|
||||
/**
|
||||
* Cameras
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA :
|
||||
name = 'Camera';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
|
||||
name = 'Camera Orthographic';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
|
||||
name = 'Camera Perspective';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
|
||||
name = 'Camera Cube';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
|
||||
name = 'Camera Stereo';
|
||||
break;
|
||||
/**
|
||||
* Meshes
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_MESH :
|
||||
name = 'Mesh';
|
||||
break;
|
||||
}
|
||||
name += ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(useQuaternion)) {
|
||||
useQuaternion = true;
|
||||
}
|
||||
this.useQuaternion = useQuaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotation)) {
|
||||
rotation = new GameLib.API.Vector3();
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
|
||||
lookAt = new GameLib.API.Vector3();
|
||||
}
|
||||
this.lookAt = lookAt;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.D3.API.Object.GetComponentType(this.objectType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Object.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Object.prototype.constructor = GameLib.D3.API.Object;
|
||||
|
||||
GameLib.D3.API.Object.GetComponentType = function(objectType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (objectType) {
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_NONE :
|
||||
componentType = GameLib.Component.OBJECT;
|
||||
break;
|
||||
/**
|
||||
* Cameras
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA :
|
||||
componentType = GameLib.Component.CAMERA;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
|
||||
componentType = GameLib.Component.CAMERA_PERSPECTIVE;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
|
||||
componentType = GameLib.Component.CAMERA_ORTHOGRAPHIC;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
|
||||
componentType = GameLib.Component.CAMERA_STEREO;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
|
||||
componentType = GameLib.Component.CAMERA_CUBE;
|
||||
break;
|
||||
/**
|
||||
* Meshes
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_MESH :
|
||||
componentType = GameLib.Component.MESH;
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported camera type: ' + objectType);
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_NONE = 0x0;
|
||||
|
||||
/**
|
||||
* Cameras
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO = 0x14;//0x3;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4;
|
||||
|
||||
/**
|
||||
* Meshes
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_MESH = 0x21;
|
|
@ -1,121 +0,0 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
GameLib.D3.API.Animation = function (
|
||||
id,
|
||||
name,
|
||||
rotationSpeed,
|
||||
translationSpeed,
|
||||
scaleSpeed,
|
||||
rotationFn,
|
||||
translationFn,
|
||||
scaleFn,
|
||||
blocking,
|
||||
applyToMeshWhenDone,
|
||||
meshes,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Animation (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
rotationSpeed = 0;
|
||||
}
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(translationSpeed)) {
|
||||
translationSpeed = 0;
|
||||
}
|
||||
this.translationSpeed = translationSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scaleSpeed)) {
|
||||
scaleSpeed = 0;
|
||||
}
|
||||
this.scaleSpeed = scaleSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationFn)) {
|
||||
rotationFn = null;
|
||||
}
|
||||
this.rotationFn = rotationFn;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(translationFn)) {
|
||||
translationFn = null;
|
||||
}
|
||||
this.translationFn = translationFn;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scaleFn)) {
|
||||
scaleFn = null;
|
||||
}
|
||||
this.scaleFn = scaleFn;
|
||||
|
||||
if (GameLib.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 (GameLib.Utils.UndefinedOrNull(applyToMeshWhenDone)) {
|
||||
applyToMeshWhenDone = true;
|
||||
}
|
||||
this.applyToMeshWhenDone = applyToMeshWhenDone;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(meshes)) {
|
||||
meshes = [];
|
||||
}
|
||||
this.meshes = meshes;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.ANIMATION,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Animation.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Animation.prototype.constructor = GameLib.D3.API.Animation;
|
||||
|
||||
/**
|
||||
* Object to GameLib.D3.API.Animation
|
||||
* @param objectComponent
|
||||
* @returns {GameLib.D3.API.Animation}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Animation.FromObject = function(objectComponent) {
|
||||
return new GameLib.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
|
||||
);
|
||||
};
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
GameLib.D3.API.Audio = function(
|
||||
id,
|
||||
name,
|
||||
path,
|
||||
loop,
|
||||
volume,
|
||||
camera,
|
||||
overplay,
|
||||
paused,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Audio (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(path)) {
|
||||
path = '';
|
||||
}
|
||||
this.path = path;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(loop)) {
|
||||
loop = false;
|
||||
}
|
||||
this.loop = loop;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(volume)) {
|
||||
volume = 0.5;
|
||||
}
|
||||
this.volume = volume;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(overplay)) {
|
||||
overplay = false;
|
||||
}
|
||||
this.overplay = overplay;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(paused)) {
|
||||
paused = false;
|
||||
}
|
||||
this.paused = paused;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.AUDIO,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Audio.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Audio.prototype.constructor = GameLib.D3.API.Audio;
|
||||
|
||||
/**
|
||||
* Creates an API Audio from an Object Audio
|
||||
* @param objectAudio
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Audio.FromObject = function(objectAudio) {
|
||||
|
||||
var apiCamera = null;
|
||||
if (objectAudio.camera) {
|
||||
if (objectAudio.camera instanceof Object) {
|
||||
apiCamera = GameLib.D3.API.Camera.FromObject(objectAudio.camera);
|
||||
} else {
|
||||
apiCamera = objectAudio.camera;
|
||||
}
|
||||
}
|
||||
|
||||
return new GameLib.D3.API.Audio(
|
||||
objectAudio.id,
|
||||
objectAudio.name,
|
||||
objectAudio.path,
|
||||
objectAudio.loop,
|
||||
objectAudio.volume,
|
||||
apiCamera,
|
||||
objectAudio.overplay,
|
||||
objectAudio.paused,
|
||||
objectAudio.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
* BoneWeight object - associates a vertex to a bone with some weight
|
||||
* @param boneIndex int
|
||||
* @param weight float
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.BoneWeight = function (
|
||||
boneIndex,
|
||||
weight
|
||||
) {
|
||||
this.boneIndex = boneIndex;
|
||||
this.weight = weight;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object to GameLib.D3.API.BoneWeight
|
||||
* @param objectBoneWeight
|
||||
* @returns {GameLib.D3.API.BoneWeight}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.BoneWeight.FromObject = function(objectBoneWeight) {
|
||||
return new GameLib.D3.API.BoneWeight(
|
||||
objectBoneWeight.boneIndex,
|
||||
objectBoneWeight.weight
|
||||
)
|
||||
};
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Bone Superset
|
||||
* @param id
|
||||
* @param name string
|
||||
* @param childBoneIds
|
||||
* @param parentBoneIds
|
||||
* @param quaternion GameLib.API.Quaternion
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param up GameLib.API.Vector3
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Bone = function (
|
||||
id,
|
||||
name,
|
||||
childBoneIds,
|
||||
parentBoneIds,
|
||||
position,
|
||||
quaternion,
|
||||
scale,
|
||||
up,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Bone (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(childBoneIds)) {
|
||||
childBoneIds = [];
|
||||
}
|
||||
this.childBoneIds = childBoneIds;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentBoneIds)) {
|
||||
parentBoneIds = [];
|
||||
}
|
||||
this.parentBoneIds = parentBoneIds;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.BONE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Bone.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Bone.prototype.constructor = GameLib.D3.API.Bone;
|
||||
|
||||
/**
|
||||
* Returns an API bone from an Object bone
|
||||
* @param objectBone
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Bone.FromObject = function(objectBone) {
|
||||
return new GameLib.D3.API.Bone(
|
||||
objectBone.id,
|
||||
objectBone.name,
|
||||
objectBone.childBoneIds,
|
||||
objectBone.parentBoneIds,
|
||||
GameLib.API.Vector3.FromObject(objectBone.position),
|
||||
GameLib.API.Quaternion.FromObject(objectBone.quaternion),
|
||||
GameLib.API.Vector3.FromObject(objectBone.scale),
|
||||
GameLib.API.Vector3.FromObject(objectBone.up),
|
||||
objectBone.parentEntity
|
||||
);
|
||||
};
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* Raw Broadphase API object - should always correspond with the Broadphase Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param broadphaseType
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Broadphase = function(
|
||||
id,
|
||||
name,
|
||||
broadphaseType,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Broadphase (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(broadphaseType)) {
|
||||
broadphaseType = GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE;
|
||||
}
|
||||
this.broadphaseType = broadphaseType;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.BROADPHASE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Broadphase.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Broadphase.prototype.constructor = GameLib.D3.API.Broadphase;
|
||||
|
||||
/**
|
||||
* Creates an API Broadphase from an Object Broadphase
|
||||
* @param objectBroadphase
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Broadphase.FromObject = function(objectBroadphase) {
|
||||
return new GameLib.D3.API.Broadphase(
|
||||
objectBroadphase.id,
|
||||
objectBroadphase.name,
|
||||
objectBroadphase.broadphaseType,
|
||||
objectBroadphase.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera
|
||||
* @param apiD3Object
|
||||
* @param aspect
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Camera = function(
|
||||
apiD3Object,
|
||||
aspect
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object)) {
|
||||
apiD3Object = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object.objectType)) {
|
||||
apiD3Object.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(aspect)) {
|
||||
aspect = 1;
|
||||
}
|
||||
this.aspect = aspect;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object.position)) {
|
||||
apiD3Object.position = new GameLib.API.Vector3(
|
||||
15,
|
||||
15,
|
||||
15
|
||||
);
|
||||
}
|
||||
|
||||
GameLib.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
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.prototype = Object.create(GameLib.D3.API.Object.prototype);
|
||||
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Cube
|
||||
* @constructor
|
||||
* @param apiD3ObjectCamera
|
||||
* @param near
|
||||
* @param far
|
||||
* @param cubeResolution
|
||||
* @param renderTarget
|
||||
*/
|
||||
GameLib.D3.API.Camera.Cube = function(
|
||||
apiD3ObjectCamera,
|
||||
near,
|
||||
far,
|
||||
cubeResolution,
|
||||
renderTarget
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 0.1;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
far = 2000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
|
||||
cubeResolution = 128;
|
||||
}
|
||||
this.cubeResolution = cubeResolution;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||
renderTarget = null;
|
||||
}
|
||||
this.renderTarget = renderTarget;
|
||||
|
||||
/**
|
||||
* CubeCamera's have hardcoded fov=90 and aspect=1
|
||||
*/
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.Cube.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
GameLib.D3.API.Camera.Cube.prototype.constructor = GameLib.D3.API.Camera.Cube;
|
|
@ -1,144 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.D3.API.Camera.Orthographic = function(
|
||||
apiD3ObjectCamera,
|
||||
aspectRatioMode,
|
||||
minWidth,
|
||||
minHeight,
|
||||
width,
|
||||
height,
|
||||
near,
|
||||
far,
|
||||
left,
|
||||
right,
|
||||
top,
|
||||
bottom,
|
||||
zoom
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) {
|
||||
apiD3ObjectCamera.position = new GameLib.API.Vector3(0,0,10);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) {
|
||||
apiD3ObjectCamera.lookAt = new GameLib.API.Vector3(0,0,-10);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(aspectRatioMode)) {
|
||||
aspectRatioMode = GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT;
|
||||
}
|
||||
this.aspectRatioMode = aspectRatioMode;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(minWidth)) {
|
||||
minWidth = 10;
|
||||
}
|
||||
this.minWidth = minWidth;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(minHeight)) {
|
||||
minHeight = 10;
|
||||
}
|
||||
this.minHeight = minHeight;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 10;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 10;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 10;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 0.1;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
far = 2000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(left)) {
|
||||
left = -5;
|
||||
}
|
||||
this.left = left;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(right)) {
|
||||
right = 5;
|
||||
}
|
||||
this.right = right;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(top)) {
|
||||
top = 5;
|
||||
}
|
||||
this.top = top;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bottom)) {
|
||||
bottom = -5;
|
||||
}
|
||||
this.bottom = bottom;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(zoom)) {
|
||||
zoom = 1;
|
||||
}
|
||||
this.zoom = zoom;
|
||||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.Orthographic.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
GameLib.D3.API.Camera.Orthographic.prototype.constructor = GameLib.D3.API.Camera.Orthographic;
|
||||
|
||||
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0;
|
||||
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1;
|
||||
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2;
|
|
@ -1,84 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Perspective
|
||||
* @constructor
|
||||
* @param apiD3ObjectCamera
|
||||
* @param fov
|
||||
* @param near
|
||||
* @param far
|
||||
* @param filmGauge
|
||||
* @param filmOffset
|
||||
* @param focus
|
||||
* @param zoom
|
||||
*/
|
||||
GameLib.D3.API.Camera.Perspective = function(
|
||||
apiD3ObjectCamera,
|
||||
near,
|
||||
far,
|
||||
fov,
|
||||
filmGauge,
|
||||
filmOffset,
|
||||
focus,
|
||||
zoom
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
// near = new GameLib.API.Number(0.1, 0.001, 0.001, 2000);
|
||||
near = 0.1;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
// far = new GameLib.API.Number(2000, 1, 1, 4000);
|
||||
far = 2000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(fov)) {
|
||||
// fov = new GameLib.API.Number(50, 1, 0, 180);
|
||||
fov = 50;
|
||||
}
|
||||
this.fov = fov;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(filmGauge)) {
|
||||
// filmGauge = new GameLib.API.Number(35, 1, 0, 200);
|
||||
filmGauge = 35;
|
||||
}
|
||||
this.filmGauge = filmGauge;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(filmOffset)) {
|
||||
// filmOffset = new GameLib.API.Number(0, 1, 0, 200);
|
||||
filmOffset = 0;
|
||||
}
|
||||
this.filmOffset = filmOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(focus)) {
|
||||
// focus = new GameLib.API.Number(10, 0.1, 0, 200);
|
||||
focus = 10;
|
||||
}
|
||||
this.focus = focus;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(zoom)) {
|
||||
// zoom = new GameLib.API.Number(1, 0.01, 0, 10);
|
||||
zoom = 1;
|
||||
}
|
||||
this.zoom = zoom;
|
||||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.Perspective.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
GameLib.D3.API.Camera.Perspective.prototype.constructor = GameLib.D3.API.Camera.Perspective;
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Stereo
|
||||
* @constructor
|
||||
* @param apiD3ObjectCamera
|
||||
* @param stereoMode
|
||||
*/
|
||||
GameLib.D3.API.Camera.Stereo = function(
|
||||
apiD3ObjectCamera,
|
||||
stereoMode
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO;
|
||||
}
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(stereoMode)) {
|
||||
stereoMode = GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO;
|
||||
}
|
||||
this.stereoMode = stereoMode;
|
||||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.Stereo.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stereo;
|
||||
|
||||
GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1;
|
||||
GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2;
|
||||
GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3;
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Composer
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param autoUpdateSize
|
||||
* @param width
|
||||
* @param height
|
||||
* @param renderer
|
||||
* @param renderTarget
|
||||
* @param passes
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Composer = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
autoUpdateSize,
|
||||
width,
|
||||
height,
|
||||
renderer,
|
||||
renderTarget,
|
||||
passes
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Composer (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) {
|
||||
autoUpdateSize = true;
|
||||
}
|
||||
this.autoUpdateSize = autoUpdateSize;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 512;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 512;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
||||
renderer = null;
|
||||
}
|
||||
this.renderer = renderer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||
renderTarget = null;
|
||||
}
|
||||
this.renderTarget = renderTarget;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(passes)) {
|
||||
passes = [];
|
||||
}
|
||||
this.passes = passes;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPOSER,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Composer.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Composer.prototype.constructor = GameLib.D3.API.Composer;
|
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Effect
|
||||
* @param id
|
||||
* @param name
|
||||
* @param effectType
|
||||
* @param parentEntity
|
||||
* @param renderer
|
||||
* @param width
|
||||
* @param height
|
||||
*
|
||||
* @property effectType
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Effect = function(
|
||||
id,
|
||||
name,
|
||||
effectType,
|
||||
parentEntity,
|
||||
renderer,
|
||||
width,
|
||||
height
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(effectType)) {
|
||||
effectType = GameLib.D3.API.Effect.EFFECT_TYPE_NONE;
|
||||
}
|
||||
this.effectType = effectType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.effectType) {
|
||||
case GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH :
|
||||
name = 'Effect Anaglyph';
|
||||
break;
|
||||
case GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX :
|
||||
name = 'Effect Parallax';
|
||||
break;
|
||||
case GameLib.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 (GameLib.Utils.UndefinedOrNull(renderer)) {
|
||||
renderer = null;
|
||||
}
|
||||
this.renderer = renderer;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 512;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 512;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (this.effectType) {
|
||||
case GameLib.D3.API.Effect.EFFECT_TYPE_STEREO :
|
||||
componentType = GameLib.Component.EFFECT_STEREO;
|
||||
break;
|
||||
case GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH :
|
||||
componentType = GameLib.Component.EFFECT_ANAGLYPH;
|
||||
break;
|
||||
case GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX :
|
||||
componentType = GameLib.Component.EFFECT_PARALLAX;
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported effect type: ' + this.effectType);
|
||||
}
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
componentType,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Effect.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Effect.prototype.constructor = GameLib.D3.API.Effect;
|
||||
|
||||
GameLib.D3.API.Effect.EFFECT_TYPE_NONE = 0x0;
|
||||
GameLib.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1;
|
||||
GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2;
|
||||
GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3;
|
|
@ -1,34 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Effect.Anaglyph
|
||||
* @constructor
|
||||
* @param apiEffect
|
||||
*/
|
||||
GameLib.D3.API.Effect.Anaglyph = function(
|
||||
apiEffect
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
|
||||
apiEffect = {
|
||||
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
|
||||
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH;
|
||||
}
|
||||
|
||||
GameLib.D3.API.Effect.call(
|
||||
this,
|
||||
apiEffect.id,
|
||||
apiEffect.name,
|
||||
apiEffect.effectType,
|
||||
apiEffect.parentEntity,
|
||||
apiEffect.renderer,
|
||||
apiEffect.width,
|
||||
apiEffect.height
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Effect.Anaglyph.prototype = Object.create(GameLib.D3.API.Effect.prototype);
|
||||
GameLib.D3.API.Effect.Anaglyph.prototype.constructor = GameLib.D3.API.Effect.Anaglyph;
|
|
@ -1,34 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Effect.Parallax
|
||||
* @constructor
|
||||
* @param apiEffect
|
||||
*/
|
||||
GameLib.D3.API.Effect.Parallax = function(
|
||||
apiEffect
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
|
||||
apiEffect = {
|
||||
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
|
||||
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX;
|
||||
}
|
||||
|
||||
GameLib.D3.API.Effect.call(
|
||||
this,
|
||||
apiEffect.id,
|
||||
apiEffect.name,
|
||||
apiEffect.effectType,
|
||||
apiEffect.parentEntity,
|
||||
apiEffect.renderer,
|
||||
apiEffect.width,
|
||||
apiEffect.height
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Effect.Parallax.prototype = Object.create(GameLib.D3.API.Effect.prototype);
|
||||
GameLib.D3.API.Effect.Parallax.prototype.constructor = GameLib.D3.API.Effect.Parallax;
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Effect.Stereo
|
||||
* @constructor
|
||||
* @param apiEffect
|
||||
* @param eyeSeperation
|
||||
*/
|
||||
GameLib.D3.API.Effect.Stereo = function(
|
||||
apiEffect,
|
||||
eyeSeperation
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect)) {
|
||||
apiEffect = {
|
||||
effectType : GameLib.D3.API.Effect.EFFECT_TYPE_STEREO
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) {
|
||||
apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_STEREO;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(eyeSeperation)) {
|
||||
eyeSeperation = 0.064;
|
||||
}
|
||||
this.eyeSeperation = eyeSeperation;
|
||||
|
||||
GameLib.D3.API.Effect.call(
|
||||
this,
|
||||
apiEffect.id,
|
||||
apiEffect.name,
|
||||
apiEffect.effectType,
|
||||
apiEffect.parentEntity,
|
||||
apiEffect.renderer,
|
||||
apiEffect.width,
|
||||
apiEffect.height
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Effect.Stereo.prototype = Object.create(GameLib.D3.API.Effect.prototype);
|
||||
GameLib.D3.API.Effect.Stereo.prototype.constructor = GameLib.D3.API.Effect.Stereo;
|
|
@ -1,243 +0,0 @@
|
|||
/**
|
||||
* Face
|
||||
* @param id
|
||||
* @param name
|
||||
* @param v0index
|
||||
* @param v1index
|
||||
* @param v2index
|
||||
* @param materialIndex
|
||||
* @param uvs [[v0uv (GameLib.Vector2), v1uv(GameLib.Vector2), v2uv(GameLib.Vector2)]]
|
||||
* @param color
|
||||
* @param vertexColors
|
||||
* @param vertexNormals
|
||||
* @param normal
|
||||
* @param selected
|
||||
* @param parentGeometry
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Face = function(
|
||||
id,
|
||||
name,
|
||||
v0index,
|
||||
v1index,
|
||||
v2index,
|
||||
materialIndex,
|
||||
uvs,
|
||||
color,
|
||||
vertexColors,
|
||||
vertexNormals,
|
||||
normal,
|
||||
selected,
|
||||
parentGeometry,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Face ' + id;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(v0index)) {
|
||||
v0index = -1;
|
||||
}
|
||||
this.v0index = v0index;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(v1index)) {
|
||||
v1index = -1;
|
||||
}
|
||||
this.v1index = v1index;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(v2index)) {
|
||||
v2index = -1;
|
||||
}
|
||||
this.v2index = v2index;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(materialIndex)) {
|
||||
materialIndex = -1;
|
||||
}
|
||||
this.materialIndex = materialIndex;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(uvs)) {
|
||||
uvs = [[]];
|
||||
}
|
||||
this.uvs = uvs;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.API.Color();
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
|
||||
vertexColors = [
|
||||
new GameLib.API.Color(),
|
||||
new GameLib.API.Color(),
|
||||
new GameLib.API.Color()
|
||||
];
|
||||
}
|
||||
this.vertexColors = vertexColors;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertexNormals)) {
|
||||
vertexNormals = [];
|
||||
}
|
||||
this.vertexNormals = vertexNormals;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(normal)) {
|
||||
normal = null;
|
||||
}
|
||||
this.normal = normal;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(selected)) {
|
||||
selected = false;
|
||||
}
|
||||
this.selected = selected;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentGeometry)) {
|
||||
parentGeometry = null;
|
||||
}
|
||||
this.parentGeometry = parentGeometry;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.FACE,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
|
||||
*/
|
||||
|
||||
GameLib.D3.API.Face.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
|
||||
|
||||
/**
|
||||
* Returns an API Face from a data object
|
||||
* @constructor
|
||||
* @param objectFace
|
||||
*/
|
||||
// GameLib.D3.API.Face.FromObject = function(objectFace) {
|
||||
//
|
||||
// var apiUvs = objectFace.uvs.reduce(
|
||||
//
|
||||
// function(result, uvArray, index) {
|
||||
//
|
||||
// result[index] = uvArray.reduce(
|
||||
// function(uvResult, uv) {
|
||||
// uvResult.push(GameLib.API.Vector2.FromObject(uv));
|
||||
// return uvResult;
|
||||
// },
|
||||
// []
|
||||
// );
|
||||
//
|
||||
// return result;
|
||||
// },
|
||||
// []
|
||||
// );
|
||||
//
|
||||
// var apiVertexColors = objectFace.vertexColors.map(
|
||||
// function(vertexColor) {
|
||||
// return GameLib.API.Color.FromObject(vertexColor);
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// var apiColor = null;
|
||||
// if (objectFace.color) {
|
||||
// apiColor = GameLib.API.Color.FromObject(objectFace.color);
|
||||
// }
|
||||
//
|
||||
// var apiVertexNormals = objectFace.vertexNormals.map(
|
||||
// function(vertexNormal) {
|
||||
// return GameLib.API.Vector3.FromObject(vertexNormal);
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// var apiNormal = null;
|
||||
// if (objectFace.normal) {
|
||||
// apiNormal = GameLib.API.Vector3.FromObject(objectFace.normal);
|
||||
// }
|
||||
//
|
||||
// return new GameLib.D3.API.Face(
|
||||
// objectFace.id,
|
||||
// objectFace.name,
|
||||
// objectFace.v0index,
|
||||
// objectFace.v1index,
|
||||
// objectFace.v2index,
|
||||
// objectFace.materialIndex,
|
||||
// apiUvs,
|
||||
// apiColor,
|
||||
// apiVertexColors,
|
||||
// apiVertexNormals,
|
||||
// apiNormal
|
||||
// );
|
||||
// };
|
||||
//
|
||||
/**
|
||||
* Clone a Face
|
||||
* @returns {GameLib.D3.API.Face}
|
||||
*/
|
||||
GameLib.D3.API.Face.prototype.clone = function(){
|
||||
return new GameLib.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}
|
||||
*/
|
||||
GameLib.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)
|
||||
)
|
||||
);
|
||||
};
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
GameLib.D3.API.Fog = function(
|
||||
id,
|
||||
name,
|
||||
exponential,
|
||||
color,
|
||||
near,
|
||||
far,
|
||||
density,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Fog (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(exponential)) {
|
||||
exponential = false;
|
||||
}
|
||||
this.exponential = exponential;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.API.Color(1, 1, 1, 1)
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 1;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
far = 1000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(density)) {
|
||||
density = 0.00025;
|
||||
}
|
||||
this.density = density;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.FOG,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Fog.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Fog.prototype.constructor = GameLib.D3.API.Fog;
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Raw Font API object - should always correspond with the Font Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param url
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Font = function(
|
||||
id,
|
||||
name,
|
||||
url,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Font (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(url)) {
|
||||
url = '/apiRelative/path/to/font';
|
||||
}
|
||||
this.url = url;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.FONT,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Font.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Font.prototype.constructor = GameLib.D3.API.Font;
|
||||
|
||||
/**
|
||||
* Returns an API light from an Object light
|
||||
* @param objectFont
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Font.FromObject = function(objectFont) {
|
||||
return new GameLib.D3.API.Font(
|
||||
objectFont.id,
|
||||
objectFont.name,
|
||||
objectFont.url,
|
||||
objectFont.parentEntity
|
||||
);
|
||||
};
|
|
@ -1,102 +0,0 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
GameLib.D3.API.FrictionContactMaterial = function(
|
||||
id,
|
||||
name,
|
||||
materials,
|
||||
friction,
|
||||
restitution,
|
||||
contactEquationStiffness,
|
||||
contactEquationRelaxation,
|
||||
frictionEquationStiffness,
|
||||
frictionEquationRelaxation,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Friction Material (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||
materials = [];
|
||||
}
|
||||
this.materials = materials;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(friction)) {
|
||||
friction = 0.3;
|
||||
}
|
||||
this.friction = friction;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(restitution)) {
|
||||
restitution = 0.3;
|
||||
}
|
||||
this.restitution = restitution;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(contactEquationStiffness)) {
|
||||
contactEquationStiffness = 1e7;
|
||||
}
|
||||
this.contactEquationStiffness = contactEquationStiffness;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(contactEquationRelaxation)) {
|
||||
contactEquationRelaxation = 3;
|
||||
}
|
||||
this.contactEquationRelaxation = contactEquationRelaxation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(frictionEquationStiffness)) {
|
||||
frictionEquationStiffness = 1e7;
|
||||
}
|
||||
this.frictionEquationStiffness = frictionEquationStiffness;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(frictionEquationRelaxation)) {
|
||||
frictionEquationRelaxation = 3;
|
||||
}
|
||||
this.frictionEquationRelaxation = frictionEquationRelaxation;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.FRICTION_CONTACT_MATERIAL,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.FrictionContactMaterial.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.FrictionContactMaterial.prototype.constructor = GameLib.D3.API.FrictionContactMaterial;
|
||||
|
||||
/**
|
||||
* Creates an API FrictionContactMaterial from an Object FrictionContactMaterial
|
||||
* @param objectFrictionContactMaterial
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMaterial) {
|
||||
return new GameLib.D3.API.FrictionContactMaterial(
|
||||
objectFrictionContactMaterial.id,
|
||||
objectFrictionContactMaterial.name,
|
||||
objectFrictionContactMaterial.materials,
|
||||
objectFrictionContactMaterial.friction,
|
||||
objectFrictionContactMaterial.restitution,
|
||||
objectFrictionContactMaterial.contactEquationStiffness,
|
||||
objectFrictionContactMaterial.contactEquationRelaxation,
|
||||
objectFrictionContactMaterial.frictionEquationStiffness,
|
||||
objectFrictionContactMaterial.frictionEquationRelaxation,
|
||||
objectFrictionContactMaterial.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Raw FrictionMaterial API object - should always correspond with the FrictionMaterial Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param friction
|
||||
* @param restitution
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.FrictionMaterial = function(
|
||||
id,
|
||||
name,
|
||||
friction,
|
||||
restitution,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Friction Material (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(friction)) {
|
||||
friction = -1;
|
||||
}
|
||||
this.friction = friction;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(restitution)) {
|
||||
restitution = -1;
|
||||
}
|
||||
this.restitution = restitution;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.Component.FRICTION_MATERIAL,
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.FrictionMaterial.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.FrictionMaterial.prototype.constructor = GameLib.D3.API.FrictionMaterial;
|
||||
|
||||
/**
|
||||
* Creates an API FrictionMaterial from an Object FrictionMaterial
|
||||
* @param objectFrictionMaterial
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) {
|
||||
return new GameLib.D3.API.FrictionMaterial(
|
||||
objectFrictionMaterial.id,
|
||||
objectFrictionMaterial.name,
|
||||
objectFrictionMaterial.friction,
|
||||
objectFrictionMaterial.restitution,
|
||||
objectFrictionMaterial.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -1,413 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry
|
||||
* @param id
|
||||
* @param name
|
||||
* @param geometryType
|
||||
* @param parentEntity
|
||||
* @param parentMesh
|
||||
* @param boundingBox
|
||||
* @param boundingSphere
|
||||
* @param faces
|
||||
* @param vertices
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry = function(
|
||||
id,
|
||||
name,
|
||||
geometryType,
|
||||
parentEntity,
|
||||
parentMesh,
|
||||
boundingBox,
|
||||
boundingSphere,
|
||||
faces,
|
||||
vertices
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(geometryType)) {
|
||||
geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NONE;
|
||||
}
|
||||
this.geometryType = geometryType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.geometryType) {
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL :
|
||||
name = 'Geometry';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX :
|
||||
name = 'Geometry Normal Box';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE :
|
||||
name = 'Geometry Normal Circle';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE :
|
||||
name = 'Geometry Normal Cone';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER :
|
||||
name = 'Geometry Normal Cylinder';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON :
|
||||
name = 'Geometry Normal Dodecahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES :
|
||||
name = 'Geometry Normal Edges';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE :
|
||||
name = 'Geometry Normal Extrude';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON :
|
||||
name = 'Geometry Normal Icosahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE :
|
||||
name = 'Geometry Normal Lathe';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON :
|
||||
name = 'Geometry Normal Octahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC :
|
||||
name = 'Geometry Normal Parametric';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE :
|
||||
name = 'Geometry Normal Plane';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON :
|
||||
name = 'Geometry Normal Polyhedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING :
|
||||
name = 'Geometry Normal Ring';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE :
|
||||
name = 'Geometry Normal Shape';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE :
|
||||
name = 'Geometry Normal Sphere';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON :
|
||||
name = 'Geometry Normal Tetrahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT :
|
||||
name = 'Geometry Normal Text';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS :
|
||||
name = 'Geometry Normal Torus';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT :
|
||||
name = 'Geometry Normal Torus Knot';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE :
|
||||
name = 'Geometry Normal Tube';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME :
|
||||
name = 'Geometry Normal Wireframe';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER :
|
||||
name = 'Geometry Buffer';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX :
|
||||
name = 'Geometry Buffer Box';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE :
|
||||
name = 'Geometry Buffer Circle';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE :
|
||||
name = 'Geometry Buffer Cone';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER :
|
||||
name = 'Geometry Buffer Cylinder';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON :
|
||||
name = 'Geometry Buffer Dodecahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE :
|
||||
name = 'Geometry Buffer Extrude';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON :
|
||||
name = 'Geometry Buffer Icosahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE :
|
||||
name = 'Geometry Buffer Lathe';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON :
|
||||
name = 'Geometry Buffer Octahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC :
|
||||
name = 'Geometry Buffer Parametric';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE :
|
||||
name = 'Geometry Buffer Plane';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON :
|
||||
name = 'Geometry Buffer Polyhedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING :
|
||||
name = 'Geometry Buffer Ring';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE :
|
||||
name = 'Geometry Buffer Shape';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE :
|
||||
name = 'Geometry Buffer Sphere';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON :
|
||||
name = 'Geometry Buffer Tetrahedron';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT :
|
||||
name = 'Geometry Buffer Text';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS :
|
||||
name = 'Geometry Buffer Torus';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT :
|
||||
name = 'Geometry Buffer Torus Knot';
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE :
|
||||
name = 'Geometry Buffer Tube';
|
||||
break;
|
||||
case GameLib.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 (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
||||
parentMesh = null;
|
||||
}
|
||||
this.parentMesh = parentMesh;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(boundingBox)) {
|
||||
boundingBox = new GameLib.API.Box3();
|
||||
}
|
||||
this.boundingBox = boundingBox;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(boundingSphere)) {
|
||||
boundingSphere = new GameLib.API.Sphere();
|
||||
}
|
||||
this.boundingSphere = boundingSphere;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
||||
faces = [];
|
||||
}
|
||||
this.faces = faces;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
||||
vertices = [];
|
||||
}
|
||||
this.vertices = vertices;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.D3.API.Geometry.GetComponentType(this.geometryType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Geometry.prototype.constructor = GameLib.D3.API.Geometry;
|
||||
|
||||
GameLib.D3.API.Geometry.GetComponentType = function(geometryType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (geometryType) {
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_BOX;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_CIRCLE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_CONE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_CYLINDER;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_DODECAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_EDGES;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_EXTRUDE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_ICOSAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_LATHE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_OCTAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_PARAMETRIC;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_PLANE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_POLYHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_RING;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_SHAPE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_SPHERE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_TETRAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_TEXT;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_TORUS;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_TORUS_KNOT;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_TUBE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME :
|
||||
componentType = GameLib.Component.GEOMETRY_NORMAL_WIREFRAME;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_BOX;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_CIRCLE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_CONE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_CYLINDER;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_DODECAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_EXTRUDE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_ICOSAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_LATHE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_OCTAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC:
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_PARAMETRIC;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_PLANE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_POLYHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING:
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_RING;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_SHAPE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_SPHERE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_TETRAHEDRON;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_TEXT;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_TORUS;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_TORUS_KNOT;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_TUBE;
|
||||
break;
|
||||
case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED :
|
||||
componentType = GameLib.Component.GEOMETRY_BUFFER_INSTANCED;
|
||||
break;
|
||||
default:
|
||||
throw new Error('unhandled geometry type: ' + geometryType);
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Geometry Type
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NONE = 0x0;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x1;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX = 0x2;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE = 0x3;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE = 0x4;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER = 0x5;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON = 0x6;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES = 0x7;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE = 0x8;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON = 0x9;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE = 0xa;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON = 0xb;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC = 0xc;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE = 0xd;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON = 0xe;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING = 0xf;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE = 0x10;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE = 0x11;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON = 0x12;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT = 0x13;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS = 0x14;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT = 0x15;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE = 0x16;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME = 0x17;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER = 0x18;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX = 0x19;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE = 0x1a;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE = 0x1b;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER = 0x1c;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON = 0x1d;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE = 0x1e;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON = 0x1f;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE = 0x20;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON = 0x21;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC = 0x22;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE = 0x23;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON = 0x24;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING = 0x25;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE = 0x26;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE = 0x27;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON = 0x28;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT = 0x29;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS = 0x2a;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT = 0x2b;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE = 0x2c;
|
||||
GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED = 0x2d;
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer
|
||||
* @param apiGeometry
|
||||
* @param attributes
|
||||
* @param drawRange
|
||||
* @param groups
|
||||
* @param index
|
||||
* @param morphAttributes
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer = function(
|
||||
apiGeometry,
|
||||
attributes,
|
||||
drawRange,
|
||||
groups,
|
||||
index,
|
||||
morphAttributes
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(attributes)) {
|
||||
attributes = [];
|
||||
}
|
||||
this.attributes = attributes;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(groups)) {
|
||||
groups = [];
|
||||
}
|
||||
this.groups = groups;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(drawRange)) {
|
||||
drawRange = new GameLib.API.DrawRange()
|
||||
}
|
||||
this.drawRange = drawRange;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(index)) {
|
||||
index = null;
|
||||
}
|
||||
this.index = index;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(morphAttributes)) {
|
||||
morphAttributes = null;
|
||||
}
|
||||
this.morphAttributes = morphAttributes;
|
||||
|
||||
GameLib.D3.API.Geometry.call(
|
||||
this,
|
||||
apiGeometry.id,
|
||||
apiGeometry.name,
|
||||
apiGeometry.geometryType,
|
||||
apiGeometry.parentEntity,
|
||||
apiGeometry.parentMesh,
|
||||
apiGeometry.boundingBox,
|
||||
apiGeometry.boundingSphere,
|
||||
apiGeometry.faces,
|
||||
apiGeometry.vertices
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.prototype = Object.create(GameLib.D3.API.Geometry.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.prototype.constructor = GameLib.D3.API.Geometry.Buffer;
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Box
|
||||
* @param apiGeometry
|
||||
* @param width
|
||||
* @param height
|
||||
* @param depth
|
||||
* @param widthSegments
|
||||
* @param heightSegments
|
||||
* @param depthSegments
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Box = function(
|
||||
apiGeometry,
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
widthSegments,
|
||||
heightSegments,
|
||||
depthSegments
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||
width = 1;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 1;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(depth)) {
|
||||
depth = 1;
|
||||
}
|
||||
this.depth = depth;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(widthSegments)) {
|
||||
widthSegments = 1;
|
||||
}
|
||||
this.widthSegments = widthSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 1;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(depthSegments)) {
|
||||
depthSegments = 1;
|
||||
}
|
||||
this.depthSegments = depthSegments;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Box.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Box.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Box;
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Circle
|
||||
* @param apiGeometry
|
||||
* @param radius
|
||||
* @param segments
|
||||
* @param thetaStart
|
||||
* @param thetaLength
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Circle = function(
|
||||
apiGeometry,
|
||||
radius,
|
||||
segments,
|
||||
thetaStart,
|
||||
thetaLength
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(segments)) {
|
||||
segments = 8;
|
||||
}
|
||||
this.segments = segments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaStart)) {
|
||||
thetaStart = 0;
|
||||
}
|
||||
this.thetaStart = thetaStart;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaLength)) {
|
||||
thetaLength = Math.PI * 2;
|
||||
}
|
||||
this.thetaLength = thetaLength;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Circle.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Circle.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Circle;
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Cone
|
||||
* @param apiGeometry
|
||||
* @param radius
|
||||
* @param height
|
||||
* @param radialSegments
|
||||
* @param heightSegments
|
||||
* @param openEnded
|
||||
* @param thetaStart
|
||||
* @param thetaLength
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Cone = function(
|
||||
apiGeometry,
|
||||
radius,
|
||||
height,
|
||||
radialSegments,
|
||||
heightSegments,
|
||||
openEnded,
|
||||
thetaStart,
|
||||
thetaLength
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 100;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radialSegments)) {
|
||||
radialSegments = 8;
|
||||
}
|
||||
this.radialSegments = radialSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 1;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(openEnded)) {
|
||||
openEnded = false;
|
||||
}
|
||||
this.openEnded = openEnded;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaStart)) {
|
||||
thetaStart = 0;
|
||||
}
|
||||
this.thetaStart = thetaStart;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaLength)) {
|
||||
thetaLength = Math.PI * 2;
|
||||
}
|
||||
this.thetaLength = thetaLength;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Cone.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Cone.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Cone;
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Cylinder
|
||||
* @param apiGeometry
|
||||
* @param radiusTop
|
||||
* @param radiusBottom
|
||||
* @param height
|
||||
* @param radialSegments
|
||||
* @param heightSegments
|
||||
* @param openEnded
|
||||
* @param thetaStart
|
||||
* @param thetaLength
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Cylinder = function(
|
||||
apiGeometry,
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
radialSegments,
|
||||
heightSegments,
|
||||
openEnded,
|
||||
thetaStart,
|
||||
thetaLength
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radiusTop)) {
|
||||
radiusTop = 1;
|
||||
}
|
||||
this.radiusTop = radiusTop;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radiusBottom)) {
|
||||
radiusBottom = 1;
|
||||
}
|
||||
this.radiusBottom = radiusBottom;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 100;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radialSegments)) {
|
||||
radialSegments = 8;
|
||||
}
|
||||
this.radialSegments = radialSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 1;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(openEnded)) {
|
||||
openEnded = false;
|
||||
}
|
||||
this.openEnded = openEnded;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaStart)) {
|
||||
thetaStart = 0;
|
||||
}
|
||||
this.thetaStart = thetaStart;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(thetaLength)) {
|
||||
thetaLength = Math.PI * 2;
|
||||
}
|
||||
this.thetaLength = thetaLength;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Cylinder.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Cylinder.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Cylinder;
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Dodecahedron
|
||||
* @param apiGeometry
|
||||
* @param radius
|
||||
* @param detail
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Dodecahedron = function(
|
||||
apiGeometry,
|
||||
radius,
|
||||
detail
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(detail)) {
|
||||
detail = 0;
|
||||
}
|
||||
this.detail = detail;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Dodecahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Dodecahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Dodecahedron;
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* GameLib.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
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Extrude = function(
|
||||
apiGeometry,
|
||||
shapes,
|
||||
curveSegments,
|
||||
steps,
|
||||
amount,
|
||||
bevelEnabled,
|
||||
bevelThickness,
|
||||
bevelSize,
|
||||
bevelSegments,
|
||||
extrudePath,
|
||||
frames,
|
||||
UVGenerator
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shapes)) {
|
||||
shapes = [];
|
||||
}
|
||||
this.shapes = shapes;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(curveSegments)) {
|
||||
curveSegments = 12;
|
||||
}
|
||||
this.curveSegments = curveSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(steps)) {
|
||||
steps = 1;
|
||||
}
|
||||
this.steps = steps;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(amount)) {
|
||||
amount = 100;
|
||||
}
|
||||
this.amount = amount;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) {
|
||||
bevelEnabled = true;
|
||||
}
|
||||
this.bevelEnabled = bevelEnabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelThickness)) {
|
||||
bevelThickness = 6;
|
||||
}
|
||||
this.bevelThickness = bevelThickness;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelSegments)) {
|
||||
bevelSegments = 3;
|
||||
}
|
||||
this.bevelSegments = bevelSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(extrudePath)) {
|
||||
extrudePath = null;
|
||||
}
|
||||
this.extrudePath = extrudePath;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(frames)) {
|
||||
frames = null;
|
||||
}
|
||||
this.frames = frames;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(UVGenerator)) {
|
||||
UVGenerator = null;
|
||||
}
|
||||
this.UVGenerator = UVGenerator;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Extrude.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Extrude.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Extrude;
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Icosahedron
|
||||
* @param apiGeometry
|
||||
* @param radius
|
||||
* @param detail
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Icosahedron = function(
|
||||
apiGeometry,
|
||||
radius,
|
||||
detail
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(detail)) {
|
||||
detail = 0;
|
||||
}
|
||||
this.detail = detail;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Icosahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Icosahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Icosahedron;
|
|
@ -1,39 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Instanced
|
||||
* @param apiGeometry
|
||||
* @param maxInstancedCount
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Instanced = function(
|
||||
apiGeometry,
|
||||
maxInstancedCount
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxInstancedCount)) {
|
||||
maxInstancedCount = null;
|
||||
}
|
||||
this.maxInstancedCount = maxInstancedCount;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Instanced.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Instanced.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Instanced;
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* GameLib.D3.API.Geometry.Buffer.Lathe
|
||||
* @param apiGeometry
|
||||
* @param points [GameLib.Vector2] (x must be larger than 0)
|
||||
* @param segments
|
||||
* @param phiStart
|
||||
* @param phiLength
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Geometry.Buffer.Lathe = function(
|
||||
apiGeometry,
|
||||
points,
|
||||
segments,
|
||||
phiStart,
|
||||
phiLength
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
||||
apiGeometry = {
|
||||
geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) {
|
||||
apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(points)) {
|
||||
points = [];
|
||||
}
|
||||
this.points = points;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(segments)) {
|
||||
segments = 12;
|
||||
}
|
||||
this.segments = segments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(phiStart)) {
|
||||
phiStart = 0;
|
||||
}
|
||||
this.phiStart = phiStart;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(phiLength)) {
|
||||
phiLength = Math.PI * 2;
|
||||
}
|
||||
this.phiLength = phiLength;
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.call(
|
||||
this,
|
||||
apiGeometry,
|
||||
apiGeometry.attributes,
|
||||
apiGeometry.drawRange,
|
||||
apiGeometry.groups,
|
||||
apiGeometry.index,
|
||||
apiGeometry.morphAttributes
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Geometry.Buffer.Lathe.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype);
|
||||
GameLib.D3.API.Geometry.Buffer.Lathe.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Lathe;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue