Repository: playcanvas/engine (js)

Issue:
Ensure all components clone the 'enabled' property
For some context:
https://github.com/playcanvas/engine/pull/3408#discussion_r690714489

We need to make sure all components are consistent and clone the enabled property

Pull request description:
[FIX] Ensure enabled property is cloned for all components
* Add unit tests to check the `enabled` property for all components is correctly cloned.
* Fixed the 4 components which were not cloning the `enabled` correctly.

Fixes #3413

I confirm I have read the [contributing guidelines](https://github.com/playcanvas/engine/blob/master/.github/CONTRIBUTING.md) and signed the [Contributor License Agreement](https://docs.google.com/a/playcanvas.com/forms/d/1Ih69zQfJG-QDLIEpHr6CsaAs6fPORNOVnMv5nuo0cjk/viewform).


Patch:
diff --git a/src/framework/components/anim/system.js b/src/framework/components/anim/system.js
index a1e259ad0..67c05f7ec 100644
--- a/src/framework/components/anim/system.js
+++ b/src/framework/components/anim/system.js
@@ -104,7 +104,8 @@ class AnimComponentSystem extends ComponentSystem {
 
     cloneComponent(entity, clone) {
         let masks;
-        // If the component animaites from the components entity, any layer mask hierarchy should be updated from the old entity to the cloned entity.
+        // If the component animates from the components entity, any layer mask hierarchy should be
+        // updated from the old entity to the cloned entity.
         if (!entity.anim.rootBone || entity.anim.rootBone === entity) {
             masks = {};
             entity.anim.layers.forEach((layer, i) => {
@@ -122,6 +123,7 @@ class AnimComponentSystem extends ComponentSystem {
             });
         }
         const data = {
+            enabled: entity.anim.enabled,
             stateGraphAsset: entity.anim.stateGraphAsset,
             animationAssets: entity.anim.animationAssets,
             speed: entity.anim.speed,
diff --git a/src/framework/components/joint/system.js b/src/framework/components/joint/system.js
index 5e8f0e785..310c1cea0 100644
--- a/src/framework/components/joint/system.js
+++ b/src/framework/components/joint/system.js
@@ -34,6 +34,8 @@ class JointComponentSystem extends ComponentSystem {
 
     initializeComponentData(component, data, properties) {
         component.initFromData(data);
+
+        super.initializeComponentData(component, data, _schema);
     }
 }
 
diff --git a/src/framework/components/screen/system.js b/src/framework/components/screen/system.js
index b7b23ee12..a73e01b68 100644
--- a/src/framework/components/screen/system.js
+++ b/src/framework/components/screen/system.js
@@ -70,7 +70,7 @@ class ScreenComponentSystem extends ComponentSystem {
 
         // queue up a draw order sync
         component.syncDrawOrder();
-        super.initializeComponentData(component, data, properties);
+        super.initializeComponentData(component, data, _schema);
     }
 
     destroy() {
diff --git a/src/framework/components/zone/system.js b/src/framework/components/zone/system.js
index b4d42bebc..c25b80c64 100644
--- a/src/framework/components/zone/system.js
+++ b/src/framework/components/zone/system.js
@@ -49,6 +49,7 @@ class ZoneComponentSystem extends ComponentSystem {
 
     cloneComponent(entity, clone) {
         const data = {
+            enabled: entity.zone.enabled,
             size: entity.zone.size
         };
 
diff --git a/src/platform/graphics/texture.js b/src/platform/graphics/texture.js
index 87a6c4f1d..987b1f32e 100644
--- a/src/platform/graphics/texture.js
+++ b/src/platform/graphics/texture.js
@@ -955,8 +955,13 @@ class Texture {
                     this._levelsUpdated[mipLevel] = true;
                 }
 
-                width = source.width;
-                height = source.height;
+                if (source instanceof HTMLVideoElement) {
+                    width = source.videoWidth;
+                    height = source.videoHeight;
+                } else {
+                    width = source.width;
+                    height = source.height;
+                }
             }
         }
 
diff --git a/src/scene/materials/standard-material-options-builder.js b/src/scene/materials/standard-material-options-builder.js
index 1d0c45c4c..9f35dfc03 100644
--- a/src/scene/materials/standard-material-options-builder.js
+++ b/src/scene/materials/standard-material-options-builder.js
@@ -328,7 +328,7 @@ class StandardMaterialOptionsBuilder {
             options.litOptions.ambientEncoding = null;
         } else {
             const envAtlas = stdMat.envAtlas || (stdMat.useSkybox && scene.envAtlas ? scene.envAtlas : null);
-            if (envAtlas) {
+            if (envAtlas && !stdMat.sphereMap) {
                 options.litOptions.ambientSource = 'envAtlas';
                 options.litOptions.ambientEncoding = envAtlas.encoding;
             } else {


Test patch:
diff --git a/test/framework/entity.test.mjs b/test/framework/entity.test.mjs
index ee6902669..8400f8a57 100644
--- a/test/framework/entity.test.mjs
+++ b/test/framework/entity.test.mjs
@@ -250,6 +250,15 @@ describe('Entity', function () {
             }
         });
 
+        for (const name in components) {
+            it(`clones the enabled state of ${name} components correctly`, function () {
+                const entity = new Entity('Test');
+                entity.addComponent(name, { enabled: false });
+                const clone = entity.clone();
+                expect(clone[name].enabled).to.equal(false);
+            });
+        }
+
         it('clones an entity hierarchy', function () {
             const root = new Entity('Test');
             const child = new Entity('Child');