/** * Helpers for displaying outlines or making 'invisible' scene objects visible * @param graphics GameLib.D3.Graphics * @param apiHelper GameLib.D3.API.Helper * @constructor */ GameLib.D3.Helper = function Helper( graphics, apiHelper ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiHelper)) { apiHelper = {}; } GameLib.D3.API.Helper.call( this, apiHelper.id, apiHelper.name, apiHelper.helperType, apiHelper.object, apiHelper.parentEntity ); this.instance = this.createInstance(); }; GameLib.D3.Helper.prototype = Object.create(GameLib.D3.API.Helper.prototype); GameLib.D3.Helper.prototype.constructor = GameLib.D3.Helper; /** * Helper types * @type {string} */ GameLib.D3.Helper.HELPER_TYPE_EDGES = 'edges'; GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 'directional-light'; GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 'spot-light'; GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 'point-light'; GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 'wireframe'; GameLib.D3.Helper.HELPER_TYPE_SKELETON = 'skeleton'; /** * Creates a helper instance * @param update */ GameLib.D3.Helper.prototype.createInstance = function(update) { var instance = null; if (update) { instance = this.instance; } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_EDGES) { instance = new THREE.WireframeHelper(this.object.instance, 0x007700); } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) { instance = new THREE.DirectionalLightHelper(this.object.instance); } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) { instance = new THREE.PointLightHelper(this.object.instance, 1); } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) { instance = new THREE.SpotLightHelper(this.object.instance); } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) { instance = new THREE.WireframeHelper(this.object.instance, 0x007700); } if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SKELETON) { instance = new THREE.SkeletonHelper(this.object.instance); } if (!instance) { throw new Error('Unsupported helper type: ' + this.helperType); } return instance; }; /** * Updates the instance with the current state */ GameLib.D3.Helper.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; /** * Converts a GameLib.D3.Helper to a new GameLib.D3.API.Helper * @returns {GameLib.D3.API.Helper} */ GameLib.D3.Helper.prototype.toApiHelper = function() { return new GameLib.D3.API.Helper( this.id, this.name, this.helperType, GameLib.Utils.IdOrNull(this.object), GameLib.Utils.IdOrNull(this.parentEntity) ); }; /** * Converts from an Object Helper to a GameLib.D3.Helper * @param graphics GameLib.D3.Graphics * @param objectHelper Object * @returns {GameLib.D3.Helper} * @constructor */ GameLib.D3.Helper.FromObjectHelper = function(graphics, objectHelper) { var apiHelper = GameLib.D3.API.Helper.FromObjectHelper(objectHelper); return new GameLib.D3.Helper( graphics, apiHelper ); };