/
a-entity.js
876 lines (767 loc) · 25.5 KB
/
a-entity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
var ANode = require('./a-node');
var COMPONENTS = require('./component').components;
var registerElement = require('./a-register-element').registerElement;
var THREE = require('../lib/three');
var utils = require('../utils/');
var AEntity;
var debug = utils.debug('core:a-entity:debug');
var warn = utils.debug('core:a-entity:warn');
var MULTIPLE_COMPONENT_DELIMITER = '__';
/**
* Entity is a container object that components are plugged into to comprise everything in
* the scene. In A-Frame, they inherently have position, rotation, and scale.
*
* To be able to take components, the scene element inherits from the entity definition.
*
* @member {object} components - entity's currently initialized components.
* @member {object} object3D - three.js object.
* @member {array} states
* @member {boolean} isPlaying - false if dynamic behavior of the entity is paused.
*/
var proto = Object.create(ANode.prototype, {
defaultComponents: {
value: {
position: '',
rotation: '',
scale: '',
visible: ''
}
},
createdCallback: {
value: function () {
this.components = {};
// To avoid double initializations and infinite loops.
this.initializingComponents = {};
this.componentsToUpdate = {};
this.isEntity = true;
this.isPlaying = false;
this.object3D = new THREE.Group();
this.object3D.el = this;
this.object3DMap = {};
this.parentEl = null;
this.rotationObj = {};
this.states = [];
}
},
/**
* Handle changes coming from the browser DOM inspector.
*/
attributeChangedCallback: {
value: function (attr, oldVal, newVal) {
var component = this.components[attr];
// If the empty string is passed by the component initialization
// logic we ignore the component update.
if (component && component.justInitialized && newVal === '') {
delete component.justInitialized;
return;
}
// When a component is removed after calling el.removeAttribute('material')
if (!component && newVal === null) { return; }
this.setEntityAttribute(attr, oldVal, newVal);
}
},
/**
* Add to parent, load, play.
*/
attachedCallback: {
value: function () {
var assetsEl; // Asset management system element.
var sceneEl = this.sceneEl;
var self = this; // Component.
this.addToParent();
// Don't .load() scene on attachedCallback.
if (this.isScene) { return; }
// Gracefully not error when outside of <a-scene> (e.g., tests).
if (!sceneEl) {
this.load();
return;
}
// Wait for asset management system to finish before loading.
assetsEl = sceneEl.querySelector('a-assets');
if (assetsEl && !assetsEl.hasLoaded) {
assetsEl.addEventListener('loaded', function () { self.load(); });
return;
}
this.load();
}
},
/**
* Tell parent to remove this element's object3D from its object3D.
* Do not call on scene element because that will cause a call to document.body.remove().
*/
detachedCallback: {
value: function () {
var componentName;
if (!this.parentEl) { return; }
// Remove components.
for (componentName in this.components) { this.removeComponent(componentName); }
if (this.isScene) { return; }
this.removeFromParent();
ANode.prototype.detachedCallback.call(this);
// Remove cyclic reference.
this.object3D.el = null;
}
},
/**
* Apply mixin to component.
*/
handleMixinUpdate: {
value: function (attrName) {
if (!attrName) {
this.updateComponents();
return;
}
this.updateComponent(attrName, this.getDOMAttribute(attrName));
}
},
getObject3D: {
value: function (type) {
return this.object3DMap[type];
}
},
/**
* Set a THREE.Object3D into the map.
*
* @param {string} type - Developer-set name of the type of object, will be unique per type.
* @param {object} obj - A THREE.Object3D.
*/
setObject3D: {
value: function (type, obj) {
var oldObj;
var self = this;
if (!(obj instanceof THREE.Object3D)) {
throw new Error(
'`Entity.setObject3D` was called with an object that was not an instance of ' +
'THREE.Object3D.'
);
}
// Remove existing object of the type.
oldObj = this.getObject3D(type);
if (oldObj) { this.object3D.remove(oldObj); }
// Set references to A-Frame entity.
obj.el = this;
if (obj.children.length) {
obj.traverse(function bindEl (child) {
child.el = self;
});
}
// Add.
this.object3D.add(obj);
this.object3DMap[type] = obj;
this.emit('object3dset', {object: obj, type: type});
}
},
/**
* Remove object from scene and entity object3D map.
*/
removeObject3D: {
value: function (type) {
var obj = this.getObject3D(type);
if (!obj) {
warn('Tried to remove `Object3D` of type:', type, 'which was not defined.');
return;
}
this.object3D.remove(obj);
delete this.object3DMap[type];
this.emit('object3dremove', {type: type});
}
},
/**
* Gets or creates an object3D of a given type.
*
* @param {string} type - Type of the object3D.
* @param {string} Constructor - Constructor to use to create the object3D if needed.
* @returns {object}
*/
getOrCreateObject3D: {
value: function (type, Constructor) {
var object3D = this.getObject3D(type);
if (!object3D && Constructor) {
object3D = new Constructor();
this.setObject3D(type, object3D);
}
warn('`getOrCreateObject3D` has been deprecated. Use `setObject3D()` ' +
'and `object3dset` event instead.');
return object3D;
}
},
/**
* Add child entity.
*
* @param {Element} el - Child entity.
*/
add: {
value: function (el) {
if (!el.object3D) {
throw new Error("Trying to add an element that doesn't have an `object3D`");
}
this.object3D.add(el.object3D);
this.emit('child-attached', {el: el});
}
},
/**
* Tell parentNode to add this entity to itself.
*/
addToParent: {
value: function () {
var parentNode = this.parentEl = this.parentNode;
// `!parentNode` check primarily for unit tests.
if (!parentNode || !parentNode.add || this.attachedToParent) { return; }
parentNode.add(this);
this.attachedToParent = true; // To prevent multiple attachments to same parent.
}
},
/**
* Tell parentNode to remove this entity from itself.
*/
removeFromParent: {
value: function () {
var parentEl = this.parentEl;
this.parentEl.remove(this);
this.attachedToParent = false;
this.parentEl = this.parentNode = null;
parentEl.emit('child-detached', {el: this});
}
},
load: {
value: function () {
var self = this;
if (this.hasLoaded || !this.parentEl) { return; }
ANode.prototype.load.call(this, function entityLoadCallback () {
// Check if entity was detached while it was waiting to load.
if (!self.parentEl) { return; }
self.updateComponents();
if (self.isScene || self.parentEl.isPlaying) { self.play(); }
});
},
writable: window.debug
},
/**
* Remove child entity.
*
* @param {Element} el - Child entity.
*/
remove: {
value: function (el) {
this.object3D.remove(el.object3D);
}
},
/**
* @returns {array} Direct children that are entities.
*/
getChildEntities: {
value: function () {
var children = this.children;
var childEntities = [];
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child instanceof AEntity) {
childEntities.push(child);
}
}
return childEntities;
}
},
/**
* Initialize component.
*
* @param {string} attrName - Attribute name asociated to the component.
* @param {object} data - Component data
* @param {boolean} isDependency - True if the component is a dependency.
*/
initComponent: {
value: function (attrName, data, isDependency) {
var component;
var componentId;
var componentInfo;
var componentName;
var isComponentDefined;
componentInfo = utils.split(attrName, MULTIPLE_COMPONENT_DELIMITER);
componentId = componentInfo[1];
componentName = componentInfo[0];
// Not a registered component.
if (!COMPONENTS[componentName]) { return; }
// Component is not a dependency and is undefined.
// If a component is a dependency, then it is okay to have no data.
isComponentDefined = checkComponentDefined(this, attrName) ||
data !== undefined;
if (!isComponentDefined && !isDependency) { return; }
// Component already initialized.
if (attrName in this.components) { return; }
// Initialize dependencies first
this.initComponentDependencies(componentName);
// If component name has an id we check component type multiplic
if (componentId && !COMPONENTS[componentName].multiple) {
throw new Error('Trying to initialize multiple ' +
'components of type `' + componentName +
'`. There can only be one component of this type per entity.');
}
component = new COMPONENTS[componentName].Component(this, data, componentId);
if (this.isPlaying) { component.play(); }
// Components are reflected in the DOM as attributes but the state is not shown
// hence we set the attribute to empty string.
// The flag justInitialized is for attributeChangedCallback to not overwrite
// the component with the empty string.
if (!this.hasAttribute(attrName)) {
component.justInitialized = true;
window.HTMLElement.prototype.setAttribute.call(this, attrName, '');
}
debug('Component initialized: %s', attrName);
},
writable: window.debug
},
/**
* Initialize dependencies of a component.
*
* @param {string} name - Root component name.
*/
initComponentDependencies: {
value: function (name) {
var self = this;
var component = COMPONENTS[name];
var dependencies;
var i;
// Not a component.
if (!component) { return; }
// No dependencies.
dependencies = COMPONENTS[name].dependencies;
if (!dependencies) { return; }
// Initialize dependencies.
for (i = 0; i < dependencies.length; i++) {
// Call getAttribute to initialize the data from the DOM.
self.initComponent(
dependencies[i],
window.HTMLElement.prototype.getAttribute.call(self, dependencies[i]) || undefined,
true
);
}
}
},
removeComponent: {
value: function (name) {
var component;
var isDefault;
// Don't remove default or mixed-in components.
isDefault = name in this.defaultComponents;
if (isDefault) { return; }
component = this.components[name];
if (!component) { return; }
// Wait for component to initialize.
if (!component.initialized) {
this.addEventListener('componentinitialized', function tryRemoveLater (evt) {
if (evt.detail.name !== name) { return; }
this.removeComponent(name);
this.removeEventListener('componentinitialized', tryRemoveLater);
});
return;
}
component.pause();
component.remove();
delete this.components[name];
this.emit('componentremoved', component.evtDetail);
},
writable: window.debug
},
/**
* Initialize or update all components.
* Build data using initial components, defined attributes, mixins, and defaults.
* Update default components before the rest.
*
* @member {function} getExtraComponents - Can be implemented to include component data
* from other sources (e.g., implemented by primitives).
*/
updateComponents: {
value: function () {
var data;
var extraComponents;
var i;
var name;
var componentsToUpdate = this.componentsToUpdate;
if (!this.hasLoaded) { return; }
// Gather mixin-defined components.
for (i = 0; i < this.mixinEls.length; i++) {
for (name in this.mixinEls[i].componentCache) {
if (isComponent(name)) { componentsToUpdate[name] = true; }
}
}
// Gather from extra initial component data if defined (e.g., primitives).
if (this.getExtraComponents) {
extraComponents = this.getExtraComponents();
for (name in extraComponents) {
if (isComponent(name)) { componentsToUpdate[name] = true; }
}
}
// Gather entity-defined components.
for (i = 0; i < this.attributes.length; ++i) {
name = this.attributes[i].name;
if (isComponent(name)) { componentsToUpdate[name] = true; }
}
// Initialze or update default components first.
for (name in this.defaultComponents) {
data = mergeComponentData(this.getDOMAttribute(name),
extraComponents && extraComponents[name]);
this.updateComponent(name, data);
delete componentsToUpdate[name];
}
// Initialize or update rest of components.
for (name in componentsToUpdate) {
data = mergeComponentData(this.getDOMAttribute(name),
extraComponents && extraComponents[name]);
this.updateComponent(name, data);
delete componentsToUpdate[name];
}
},
writable: window.debug
},
/**
* Initialize, update, or remove a single component.
*
* When initializing, we set the component on `this.components`.
*
* @param {string} attr - Component name.
* @param {object} attrValue - Value of the DOM attribute.
* @param {boolean} clobber - If new attrValue completely replaces previous properties.
*/
updateComponent: {
value: function (attr, attrValue, clobber) {
var component = this.components[attr];
var isDefault = attr in this.defaultComponents;
if (component) {
// Remove component.
if (attrValue === null && !isDefault) {
this.removeComponent(attr);
return;
}
// Component already initialized. Update component.
component.updateProperties(attrValue, clobber);
return;
}
// Component not yet initialized. Initialize component.
this.initComponent(attr, attrValue, false);
}
},
/**
* If `attr` is a component name, detach the component from the entity.
*
* If `propertyName` is given, reset the component property value to its default.
*
* @param {string} attr - Attribute name, which could also be a component name.
* @param {string} propertyName - Component prop name, if resetting an individual prop.
*/
removeAttribute: {
value: function (attr, propertyName) {
var component = this.components[attr];
// Remove component.
if (component && propertyName === undefined) {
this.removeComponent(attr);
// Do not remove the component from the DOM if default component.
if (this.components[attr]) { return; }
}
// Reset component property value.
if (component && propertyName !== undefined) {
component.resetProperty(propertyName);
return;
}
// Remove mixins.
if (attr === 'mixin') {
this.mixinUpdate('');
}
window.HTMLElement.prototype.removeAttribute.call(this, attr);
}
},
/**
* Start dynamic behavior associated with entity such as dynamic components and animations.
* Tell all children entities to also play.
*/
play: {
value: function () {
var entities;
var i;
var key;
// Already playing.
if (this.isPlaying || !this.hasLoaded) { return; }
this.isPlaying = true;
// Wake up all components.
for (key in this.components) { this.components[key].play(); }
// Tell all child entities to play.
entities = this.getChildEntities();
for (i = 0; i < entities.length; i++) { entities[i].play(); }
this.emit('play');
},
writable: true
},
/**
* Pause dynamic behavior associated with entity such as dynamic components and animations.
* Tell all children entities to also pause.
*/
pause: {
value: function () {
var entities;
var i;
var key;
if (!this.isPlaying) { return; }
this.isPlaying = false;
// Sleep all components.
for (key in this.components) { this.components[key].pause(); }
// Tell all child entities to pause.
entities = this.getChildEntities();
for (i = 0; i < entities.length; i++) { entities[i].pause(); }
this.emit('pause');
},
writable: true
},
/**
* Deals with updates on entity-specific attributes (i.e., components and mixins).
*
* @param {string} attr
* @param {string} oldVal
* @param {string|object} newVal
*/
setEntityAttribute: {
value: function (attr, oldVal, newVal) {
if (COMPONENTS[attr] || this.components[attr]) {
this.updateComponent(attr, newVal);
return;
}
if (attr === 'mixin') {
// Ignore if `<a-node>` code is just updating computed mixin in the DOM.
if (newVal === this.computedMixinStr) { return; }
this.mixinUpdate(newVal, oldVal);
}
}
},
mixinUpdate: {
value: function (newMixins, oldMixins) {
oldMixins = oldMixins || this.getAttribute('mixin');
this.updateMixins(newMixins, oldMixins);
this.updateComponents();
}
},
/**
* setAttribute can:
*
* 1. Set a single property of a multi-property component.
* 2. Set multiple properties of a multi-property component.
* 3. Replace properties of a multi-property component.
* 4. Set a value for a single-property component, mixin, or normal HTML attribute.
*
* @param {string} attrName - Component or attribute name.
* @param {*} arg1 - Can be a value, property name, CSS-style property string, or
* object of properties.
* @param {*|bool} arg2 - If arg1 is a property name, this should be a value. Otherwise,
* it is a boolean indicating whether to clobber previous values (defaults to false).
*/
setAttribute: {
value: function (attrName, arg1, arg2) {
var newAttrValue;
var clobber;
var componentName;
var delimiterIndex;
var isDebugMode;
delimiterIndex = attrName.indexOf(MULTIPLE_COMPONENT_DELIMITER);
componentName = delimiterIndex > 0 ? attrName.substring(0, delimiterIndex) : attrName;
// Not a component. Normal set attribute.
if (!COMPONENTS[componentName]) {
if (attrName === 'mixin') { this.mixinUpdate(arg1); }
ANode.prototype.setAttribute.call(this, attrName, arg1);
return;
}
// Initialize component first if not yet initialized.
if (!this.components[attrName] && this.hasAttribute(attrName)) {
this.updateComponent(attrName,
window.HTMLElement.prototype.getAttribute.call(this, attrName));
}
// Determine new attributes from the arguments
if (typeof arg2 !== 'undefined' &&
typeof arg1 === 'string' &&
arg1.length > 0 &&
typeof utils.styleParser.parse(arg1) === 'string') {
// Update a single property of a multi-property component
newAttrValue = {};
newAttrValue[arg1] = arg2;
clobber = false;
} else {
// Update with a value, object, or CSS-style property string, with the possiblity
// of clobbering previous values.
newAttrValue = arg1;
clobber = (arg2 === true);
}
// Update component
this.updateComponent(attrName, newAttrValue, clobber);
// In debug mode, write component data up to the DOM.
isDebugMode = this.sceneEl && this.sceneEl.getAttribute('debug');
if (isDebugMode) { this.components[attrName].flushToDOM(); }
},
writable: window.debug
},
/**
* Reflect component data in the DOM (as seen from the browser DOM Inspector).
*
* @param {bool} recursive - Also flushToDOM on the children.
**/
flushToDOM: {
value: function (recursive) {
var components = this.components;
var defaultComponents = this.defaultComponents;
var child;
var children = this.children;
var i;
var key;
// Flush entity's components to DOM.
for (key in components) {
components[key].flushToDOM(key in defaultComponents);
}
// Recurse.
if (!recursive) { return; }
for (i = 0; i < children.length; ++i) {
child = children[i];
if (!child.flushToDOM) { continue; }
child.flushToDOM(recursive);
}
}
},
/**
* If `attr` is a component, returns ALL component data including applied mixins and
* defaults.
*
* If `attr` is not a component, fall back to HTML getAttribute.
*
* @param {string} attr
* @returns {object|string} Object if component, else string.
*/
getAttribute: {
value: function (attr) {
// If component, return component data.
var component;
if (attr === 'position') { return this.object3D.position; }
if (attr === 'rotation') { return getRotation(this); }
if (attr === 'scale') { return this.object3D.scale; }
if (attr === 'visible') { return this.object3D.visible; }
component = this.components[attr];
if (component) { return component.data; }
return window.HTMLElement.prototype.getAttribute.call(this, attr);
},
writable: window.debug
},
/**
* `getAttribute` used to be `getDOMAttribute` and `getComputedAttribute` used to be
* what `getAttribute` is now. Now legacy code.
*
* @param {string} attr
* @returns {object|string} Object if component, else string.
*/
getComputedAttribute: {
value: function (attr) {
warn('`getComputedAttribute` is deprecated. Use `getAttribute` instead.');
return this.getAttribute(attr);
}
},
/**
* If `attr` is a component, returns JUST the component data defined on the entity.
* Like a partial version of `getComputedAttribute` as returned component data
* does not include applied mixins or defaults.
*
* If `attr` is not a component, fall back to HTML getAttribute.
*
* @param {string} attr
* @returns {object|string} Object if component, else string.
*/
getDOMAttribute: {
value: function (attr) {
// If cached value exists, return partial component data.
var component = this.components[attr];
if (component) { return component.attrValue; }
return window.HTMLElement.prototype.getAttribute.call(this, attr);
},
writable: window.debug
},
addState: {
value: function (state) {
if (this.is(state)) { return; }
this.states.push(state);
this.emit('stateadded', state);
}
},
removeState: {
value: function (state) {
var stateIndex = this.states.indexOf(state);
if (stateIndex === -1) { return; }
this.states.splice(stateIndex, 1);
this.emit('stateremoved', state);
}
},
/**
* Checks if the element is in a given state. e.g. el.is('alive');
* @type {string} state - Name of the state we want to check
*/
is: {
value: function (state) {
return this.states.indexOf(state) !== -1;
}
}
});
/**
* Check if a component is *defined* for an entity, including defaults and mixins.
* Does not check whether the component has been *initialized* for an entity.
*
* @param {string} el - Entity.
* @param {string} name - Component name.
* @returns {boolean}
*/
function checkComponentDefined (el, name) {
// Check if default components contain the component.
if (el.defaultComponents[name] !== undefined) { return true; }
// Check if element contains the component.
if (el.components[name] && el.components[name].attrValue) { return true; }
return isComponentMixedIn(name, el.mixinEls);
}
/**
* Check if any mixins contains a component.
*
* @param {string} name - Component name.
* @param {array} mixinEls - Array of <a-mixin>s.
*/
function isComponentMixedIn (name, mixinEls) {
var i;
var inMixin = false;
for (i = 0; i < mixinEls.length; ++i) {
inMixin = mixinEls[i].hasAttribute(name);
if (inMixin) { break; }
}
return inMixin;
}
/**
* Given entity defined value, merge in extra data if necessary.
* Handle both single and multi-property components.
*
* @param {string} attrValue - Entity data.
* @param extraData - Entity data from another source to merge in.
*/
function mergeComponentData (attrValue, extraData) {
// Extra data not defined, just return attrValue.
if (!extraData) { return attrValue; }
// Merge multi-property data.
if (extraData.constructor === Object) {
return utils.extend(extraData, utils.styleParser.parse(attrValue || {}));
}
// Return data, precendence to the defined value.
return attrValue || extraData;
}
function isComponent (componentName) {
if (componentName.indexOf(MULTIPLE_COMPONENT_DELIMITER) !== -1) {
componentName = utils.split(componentName, MULTIPLE_COMPONENT_DELIMITER)[0];
}
if (!COMPONENTS[componentName]) { return false; }
return true;
}
function getRotation (entityEl) {
var radToDeg = THREE.Math.radToDeg;
var rotation = entityEl.object3D.rotation;
var rotationObj = entityEl.rotationObj;
rotationObj.x = radToDeg(rotation.x);
rotationObj.y = radToDeg(rotation.y);
rotationObj.z = radToDeg(rotation.z);
return rotationObj;
}
AEntity = registerElement('a-entity', {prototype: proto});
module.exports = AEntity;