Skip to content

Commit

Permalink
Update camera querySelectors to ignore a-mixin elements (fix #5023) (#…
Browse files Browse the repository at this point in the history
…5024)

* Exclude <a-mixin> from initial camera query

* Add camera mixin to examples

* Ignore a-mixin elements in querySelector

Co-authored-by: Diego Marcos <[email protected]>
  • Loading branch information
mattrossman and dmarcos authored Mar 14, 2022
1 parent 018e123 commit d780484
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions examples/test/mixin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
rotation="0 45 0"></a-mixin>
<a-mixin id="sphere" geometry="primitive: sphere"
material="color: blue"></a-mixin>
<a-mixin id="camera" camera="active: false"></a-mixin>
</a-assets>

<a-entity mixin="cube" position="-3.5 1 -4" material="color: yellow"></a-entity>
<a-entity mixin="cube" position="0 1 -4"></a-entity>
<a-entity mixin="cube" position="3.5 1 -4"></a-entity>
<a-entity mixin="camera"></a-entity>
</a-scene>
</body>
</html>
8 changes: 4 additions & 4 deletions src/systems/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports.System = registerSystem('camera', {
}

// Search for initial user-defined camera.
cameraEls = sceneEl.querySelectorAll('a-camera, [camera]');
cameraEls = sceneEl.querySelectorAll('a-camera, :not(a-mixin)[camera]');

// No user cameras, create default one.
if (!cameraEls.length) {
Expand Down Expand Up @@ -132,7 +132,7 @@ module.exports.System = registerSystem('camera', {
disableActiveCamera: function () {
var cameraEls;
var newActiveCameraEl;
cameraEls = this.sceneEl.querySelectorAll('[camera]');
cameraEls = this.sceneEl.querySelectorAll(':not(a-mixin)[camera]');
newActiveCameraEl = cameraEls[cameraEls.length - 1];
newActiveCameraEl.setAttribute('camera', 'active', true);
},
Expand All @@ -159,7 +159,7 @@ module.exports.System = registerSystem('camera', {
// Grab the default camera.
var defaultCameraWrapper = sceneEl.querySelector('[' + DEFAULT_CAMERA_ATTR + ']');
var defaultCameraEl = defaultCameraWrapper &&
defaultCameraWrapper.querySelector('[camera]');
defaultCameraWrapper.querySelector(':not(a-mixin)[camera]');

// Remove default camera if new camera is not the default camera.
if (newCameraEl !== defaultCameraEl) { removeDefaultCamera(sceneEl); }
Expand All @@ -175,7 +175,7 @@ module.exports.System = registerSystem('camera', {
}

// Disable other cameras in the scene
cameraEls = sceneEl.querySelectorAll('[camera]');
cameraEls = sceneEl.querySelectorAll(':not(a-mixin)[camera]');
for (i = 0; i < cameraEls.length; i++) {
cameraEl = cameraEls[i];
if (!cameraEl.isEntity || newCameraEl === cameraEl) { continue; }
Expand Down

0 comments on commit d780484

Please sign in to comment.