Repository: playcanvas/engine
Pull request #4734 (2022-10-11 15:19:24)

Moved lightmapper from /scene to /framework
- majority of Lightmapper has moved to framework, as it uses entities / components and so that’s where it belongs
- LightmapCache stayed behind on the scene level, as mesh instances need to communicate with it
- this fixes an import from higher up


Patch:
diff --git a/src/framework/app-base.js b/src/framework/app-base.js
index 38dde2b15..edd6902df 100644
--- a/src/framework/app-base.js
+++ b/src/framework/app-base.js
@@ -77,7 +77,7 @@ import {
 /** @typedef {import('../scene/graph-node.js').GraphNode} GraphNode */
 /** @typedef {import('../scene/mesh.js').Mesh} Mesh */
 /** @typedef {import('../scene/mesh-instance.js').MeshInstance} MeshInstance */
-/** @typedef {import('../scene/lightmapper/lightmapper.js').Lightmapper} Lightmapper */
+/** @typedef {import('./lightmapper/lightmapper.js').Lightmapper} Lightmapper */
 /** @typedef {import('../scene/batching/batch-manager.js').BatchManager} BatchManager */
 /** @typedef {import('./app-options.js').AppOptions} AppOptions */
 /** @typedef {import('./xr/xr-manager.js').XrManager} XrManager */
diff --git a/src/framework/app-options.js b/src/framework/app-options.js
index a66259054..cac8f1799 100644
--- a/src/framework/app-options.js
+++ b/src/framework/app-options.js
@@ -6,7 +6,7 @@
 /** @typedef {import('../platform/input/mouse.js').Mouse} Mouse */
 /** @typedef {import('../platform/input/touch-device.js').TouchDevice} TouchDevice */
 /** @typedef {import('../platform/sound/manager.js').SoundManager} SoundManager */
-/** @typedef {import('../scene/lightmapper/lightmapper.js').Lightmapper} Lightmapper */
+/** @typedef {import('./lightmapper/lightmapper.js').Lightmapper} Lightmapper */
 /** @typedef {import('../scene/batching/batch-manager.js').BatchManager} BatchManager */
 /** @typedef {import('./components/system.js').ComponentSystem} ComponentSystem */
 /** @typedef {import('./xr/xr-manager.js').XrManager} XrManager */
diff --git a/src/framework/application.js b/src/framework/application.js
index 283534968..1d6ed019d 100644
--- a/src/framework/application.js
+++ b/src/framework/application.js
@@ -4,7 +4,7 @@ import { WebglGraphicsDevice } from '../platform/graphics/webgl/webgl-graphics-d
 
 import { SoundManager } from '../platform/sound/manager.js';
 
-import { Lightmapper } from '../scene/lightmapper/lightmapper.js';
+import { Lightmapper } from './lightmapper/lightmapper.js';
 import { BatchManager } from '../scene/batching/batch-manager.js';
 
 import { AppBase } from './app-base.js';
diff --git a/src/scene/lightmapper/bake-light-ambient.js b/src/framework/lightmapper/bake-light-ambient.js
similarity index 95%
rename from src/scene/lightmapper/bake-light-ambient.js
rename to src/framework/lightmapper/bake-light-ambient.js
index 037165b67..50c8841a5 100644
--- a/src/scene/lightmapper/bake-light-ambient.js
+++ b/src/framework/lightmapper/bake-light-ambient.js
@@ -1,8 +1,8 @@
 import { Vec3 } from '../../core/math/vec3.js';
 import { random } from '../../core/math/random.js';
 import { Color } from '../../core/math/color.js';
-import { Entity } from '../../framework/entity.js';
-import { SHADOW_PCF3 } from '../constants.js';
+import { Entity } from '../entity.js';
+import { SHADOW_PCF3 } from '../../scene/constants.js';
 import { BakeLight } from './bake-light.js';
 
 const _tempPoint = new Vec3();
diff --git a/src/scene/lightmapper/bake-light-simple.js b/src/framework/lightmapper/bake-light-simple.js
similarity index 95%
rename from src/scene/lightmapper/bake-light-simple.js
rename to src/framework/lightmapper/bake-light-simple.js
index e751045e9..d9e72ec29 100644
--- a/src/scene/lightmapper/bake-light-simple.js
+++ b/src/framework/lightmapper/bake-light-simple.js
@@ -1,6 +1,6 @@
 import { Vec2 } from '../../core/math/vec2.js';
 import { random } from '../../core/math/random.js';
-import { LIGHTTYPE_DIRECTIONAL } from '../constants.js';
+import { LIGHTTYPE_DIRECTIONAL } from '../../scene/constants.js';
 import { BakeLight } from './bake-light.js';
 
 const _tempPoint = new Vec2();
diff --git a/src/scene/lightmapper/bake-light.js b/src/framework/lightmapper/bake-light.js
similarity index 97%
rename from src/scene/lightmapper/bake-light.js
rename to src/framework/lightmapper/bake-light.js
index 84b905c57..77e518f23 100644
--- a/src/scene/lightmapper/bake-light.js
+++ b/src/framework/lightmapper/bake-light.js
@@ -1,6 +1,6 @@
 import { BoundingBox } from '../../core/shape/bounding-box.js';
 import { BoundingSphere } from '../../core/shape/bounding-sphere.js';
-import { LIGHTTYPE_DIRECTIONAL } from '../constants.js';
+import { LIGHTTYPE_DIRECTIONAL } from '../../scene/constants.js';
 
 const tempSphere = new BoundingSphere();
 
diff --git a/src/scene/lightmapper/bake-mesh-node.js b/src/framework/lightmapper/bake-mesh-node.js
similarity index 100%
rename from src/scene/lightmapper/bake-mesh-node.js
rename to src/framework/lightmapper/bake-mesh-node.js
diff --git a/src/scene/lightmapper/lightmap-filters.js b/src/framework/lightmapper/lightmap-filters.js
similarity index 100%
rename from src/scene/lightmapper/lightmap-filters.js
rename to src/framework/lightmapper/lightmap-filters.js
diff --git a/src/scene/lightmapper/lightmapper.js b/src/framework/lightmapper/lightmapper.js
similarity index 98%
rename from src/scene/lightmapper/lightmapper.js
rename to src/framework/lightmapper/lightmapper.js
index 0bbe2d63c..80ca35a1f 100644
--- a/src/scene/lightmapper/lightmapper.js
+++ b/src/framework/lightmapper/lightmapper.js
@@ -23,16 +23,16 @@ import { RenderTarget } from '../../platform/graphics/render-target.js';
 import { Texture } from '../../platform/graphics/texture.js';
 import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';
 
-import { MeshInstance } from '../mesh-instance.js';
+import { MeshInstance } from '../../scene/mesh-instance.js';
 
-import { LightingParams } from '../lighting/lighting-params.js';
-import { WorldClusters } from '../lighting/world-clusters.js';
+import { LightingParams } from '../../scene/lighting/lighting-params.js';
+import { WorldClusters } from '../../scene/lighting/world-clusters.js';
 
-/** @typedef {import('../../framework/asset/asset-registry.js').AssetRegistry} AssetRegistry */
-/** @typedef {import('../../framework/entity.js').Entity} Entity */
-/** @typedef {import('../renderer/forward-renderer.js').ForwardRenderer} ForwardRenderer */
+/** @typedef {import('../asset/asset-registry.js').AssetRegistry} AssetRegistry */
+/** @typedef {import('../entity.js').Entity} Entity */
+/** @typedef {import('../../scene/renderer/forward-renderer.js').ForwardRenderer} ForwardRenderer */
 /** @typedef {import('../../platform/graphics/graphics-device.js').GraphicsDevice} GraphicsDevice */
-/** @typedef {import('../scene.js').Scene} Scene */
+/** @typedef {import('../../scene/scene.js').Scene} Scene */
 
 import {
     BAKE_COLORDIR,
@@ -43,15 +43,15 @@ import {
     SHADERDEF_DIRLM, SHADERDEF_LM, SHADERDEF_LMAMBIENT,
     MASK_BAKE, MASK_AFFECT_LIGHTMAPPED,
     SHADOWUPDATE_REALTIME, SHADOWUPDATE_THISFRAME
-} from '../constants.js';
-import { Camera } from '../camera.js';
-import { GraphNode } from '../graph-node.js';
-import { StandardMaterial } from '../materials/standard-material.js';
+} from '../../scene/constants.js';
+import { Camera } from '../../scene/camera.js';
+import { GraphNode } from '../../scene/graph-node.js';
+import { StandardMaterial } from '../../scene/materials/standard-material.js';
 
 import { BakeLightSimple } from './bake-light-simple.js';
 import { BakeLightAmbient } from './bake-light-ambient.js';
 import { BakeMeshNode } from './bake-mesh-node.js';
-import { LightmapCache } from './lightmap-cache.js';
+import { LightmapCache } from '../../scene/graphics/lightmap-cache.js';
 import { LightmapFilters } from './lightmap-filters.js';
 
 const MAX_LIGHTMAP_SIZE = 2048;
diff --git a/src/index.js b/src/index.js
index d14fcc26e..2ed9906fe 100644
--- a/src/index.js
+++ b/src/index.js
@@ -110,7 +110,6 @@ export { Layer } from './scene/layer.js';
 export { LayerComposition } from './scene/composition/layer-composition.js';
 export { Light } from './scene/light.js';
 export { LightingParams } from './scene/lighting/lighting-params.js';
-export { Lightmapper } from './scene/lightmapper/lightmapper.js';
 export { Material } from './scene/materials/material.js';
 export { Mesh } from './scene/mesh.js';
 export { MeshInstance, Command } from './scene/mesh-instance.js';
@@ -187,6 +186,7 @@ export { LayoutGroupComponent } from './framework/components/layout-group/compon
 export { LayoutGroupComponentSystem } from './framework/components/layout-group/system.js';
 export { LightComponent } from './framework/components/light/component.js';
 export { LightComponentSystem } from './framework/components/light/system.js';
+export { Lightmapper } from './framework/lightmapper/lightmapper.js';
 export { ModelComponent } from './framework/components/model/component.js';
 export { ModelComponentSystem } from './framework/components/model/system.js';
 export { ParticleSystemComponent } from './framework/components/particle-system/component.js';
diff --git a/src/scene/lightmapper/lightmap-cache.js b/src/scene/graphics/lightmap-cache.js
similarity index 100%
rename from src/scene/lightmapper/lightmap-cache.js
rename to src/scene/graphics/lightmap-cache.js
diff --git a/src/scene/mesh-instance.js b/src/scene/mesh-instance.js
index 721594bf1..3429465c7 100644
--- a/src/scene/mesh-instance.js
+++ b/src/scene/mesh-instance.js
@@ -20,7 +20,7 @@ import {
 
 import { GraphNode } from './graph-node.js';
 import { getDefaultMaterial } from './materials/default-material.js';
-import { LightmapCache } from './lightmapper/lightmap-cache.js';
+import { LightmapCache } from './graphics/lightmap-cache.js';
 
 /** @typedef {import('../platform/graphics/texture.js').Texture} Texture */
 /** @typedef {import('../platform/graphics/shader.js').Shader} Shader */


Test patch:
diff --git a/test/framework/application.test.mjs b/test/framework/application.test.mjs
index 78dca3d64..084def393 100644
--- a/test/framework/application.test.mjs
+++ b/test/framework/application.test.mjs
@@ -6,7 +6,7 @@ import { ComponentSystemRegistry } from '../../src/framework/components/registry
 import { Entity } from '../../src/framework/entity.js';
 import { GraphicsDevice } from '../../src/platform/graphics/graphics-device.js';
 import { I18n } from '../../src/framework/i18n/i18n.js';
-import { Lightmapper } from '../../src/scene/lightmapper/lightmapper.js';
+import { Lightmapper } from '../../src/framework/lightmapper/lightmapper.js';
 import { ResourceLoader } from '../../src/framework/handlers/loader.js';
 import { Scene } from '../../src/scene/scene.js';
 import { SceneRegistry } from '../../src/framework/scene-registry.js';