/** * Helpers for displaying outlines or making 'invisible' scene objects visible * @param id * @param object GameLib.D3.Object * @param name * @param graphics * @param helperType * @constructor */ GameLib.D3.Helper = function Helper( id, object, helperType, name, graphics ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(object)) { throw new Error('Cannot create helpers for unknown objects'); } this.object = object; if (GameLib.Utils.UndefinedOrNull(helperType)) { helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES; } this.helperType = helperType; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Helper (' + this.helperType + ')'; } this.name = name; this.graphics = graphics; this.graphics.isNotThreeThrow(); this.instance = this.createInstance(); }; /** * 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 (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.skeleton.instance); } if (!instance) { throw new Error('Unsupported helper type: ' + this.helperType); } if (update) { this.instance = instance; } return instance; };