* Set a THREE.Object3D into the map. * * @param {string} type - Developer-set name of the type of object, will be unique per type. * @param {THREE.Object3D} obj - A THREE.Object3D.
(type, obj)
| 122 | * @param {THREE.Object3D} obj - A THREE.Object3D. |
| 123 | */ |
| 124 | setObject3D (type, obj) { |
| 125 | var oldObj; |
| 126 | var self = this; |
| 127 | |
| 128 | if (!(obj instanceof THREE.Object3D)) { |
| 129 | throw new Error( |
| 130 | '`Entity.setObject3D` was called with an object that was not an instance of ' + |
| 131 | 'THREE.Object3D.' |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | // Remove existing object of the type. |
| 136 | oldObj = this.getObject3D(type); |
| 137 | if (oldObj) { this.object3D.remove(oldObj); } |
| 138 | |
| 139 | // Set references to A-Frame entity. |
| 140 | obj.el = this; |
| 141 | if (obj.children.length) { |
| 142 | obj.traverse(function bindEl (child) { |
| 143 | child.el = self; |
| 144 | }); |
| 145 | } |
| 146 | |
| 147 | // Add. |
| 148 | this.object3D.add(obj); |
| 149 | this.object3DMap[type] = obj; |
| 150 | this.emit('object3dset', {object: obj, type: type}); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Remove object from scene and entity object3D map. |
no test coverage detected