Skip to content

Commit

Permalink
[v3.8.6] Optimize code size by adding helper functions to get data fr…
Browse files Browse the repository at this point in the history
…om pipelineSceneData. (#18172)
  • Loading branch information
dumganhar authored Jan 14, 2025
1 parent cc2ff78 commit 979670f
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 124 deletions.
13 changes: 7 additions & 6 deletions cocos/3d/framework/mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { SubModel } from '../../render-scene/scene';
import { isEnableEffect } from '../../rendering/define';
import type { Model } from '../../render-scene/scene';
import type { ReflectionProbeManager } from '../reflection-probe';
import { getPipelineSceneData } from '../../rendering/pipeline-scene-data-utils';

const { ccclass, help, executeInEditMode, executionOrder, menu, visible, type,
formerlySerializedAs, serializable, editable, disallowAnimation } = _decorator;
Expand Down Expand Up @@ -541,7 +542,7 @@ export class MeshRenderer extends ModelRenderer {
}

set isGlobalStandardSkinObject (val) {
(cclegacy.director.root as Root).pipeline.pipelineSceneData.standardSkinMeshRenderer = val ? this : null;
getPipelineSceneData().standardSkinMeshRenderer = val ? this : null;
this._enabledGlobalStandardSkinObject = val;
}

Expand Down Expand Up @@ -950,13 +951,13 @@ export class MeshRenderer extends ModelRenderer {
if (!mainLight.node) { return; }

if (mainLight.node.mobility === MobilityMode.Static) {
const sceneGlobals = this.node.scene.globals;
const lightProbeInfoData = sceneGlobals.lightProbeInfo.data;
let forceClose = false;
if (this.bakeSettings.texture && !this.node.scene.globals.disableLightmap) {
if (this.bakeSettings.texture && !sceneGlobals.disableLightmap) {
forceClose = true;
}
if (this.node.scene.globals.lightProbeInfo.data
&& this.node.scene.globals.lightProbeInfo.data.hasCoefficients()
&& this._model.useLightProbe) {
if (lightProbeInfoData && lightProbeInfoData.hasCoefficients() && this._model.useLightProbe) {
forceClose = true;
}

Expand Down Expand Up @@ -1308,7 +1309,7 @@ export class MeshRenderer extends ModelRenderer {
}

private _updateStandardSkin (): void {
const pipelineSceneData = (cclegacy.director.root as Root).pipeline.pipelineSceneData;
const pipelineSceneData = getPipelineSceneData();
if (this._enabledGlobalStandardSkinObject) {
pipelineSceneData.standardSkinMeshRenderer = this;
pipelineSceneData.standardSkinModel = this.model;
Expand Down
67 changes: 34 additions & 33 deletions cocos/3d/lights/directional-light-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

import { Light } from './light-component';
import { scene } from '../../render-scene';
import { cclegacy, clamp, warnID, CCBoolean, CCFloat, _decorator, settings, CCInteger, SettingsCategory } from '../../core';
import { clamp, warnID, CCBoolean, CCFloat, _decorator, settings, CCInteger, SettingsCategory } from '../../core';
import { Camera, PCFType, Shadows, ShadowType, CSMOptimizationMode, CSMLevel } from '../../render-scene/scene';
import { Root } from '../../root';
import { MeshRenderer } from '../framework/mesh-renderer';
import { getPipelineSceneData } from '../../rendering/pipeline-scene-data-utils';

const { ccclass, menu, executeInEditMode, property, serializable, formerlySerializedAs, tooltip, help,
visible, type, editable, slide, range } = _decorator;
Expand Down Expand Up @@ -99,15 +100,15 @@ export class DirectionalLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 10])
@type(CCInteger)
get illuminance (): number {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._illuminanceHDR;
} else {
return this._illuminanceLDR;
}
}
set illuminance (val) {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
this._illuminanceHDR = val;
this._light && ((this._light as scene.DirectionalLight).illuminanceHDR = this._illuminanceHDR);

Check warning on line 114 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected an assignment or function call and instead saw an expression
Expand All @@ -122,8 +123,8 @@ export class DirectionalLight extends Light {
* @zh 是否启用实时阴影?
*/
@tooltip('i18n:lights.shadowEnabled')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 1 } })
@editable
@type(CCBoolean)
Expand All @@ -142,8 +143,8 @@ export class DirectionalLight extends Light {
* @zh 实时阴影计算中的阴影 pcf 等级。
*/
@tooltip('i18n:lights.shadowPcf')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 5 } })
@editable
@type(PCFType)
Expand All @@ -162,8 +163,8 @@ export class DirectionalLight extends Light {
* @zh 实时阴影计算中的阴影纹理偏移值。
*/
@tooltip('i18n:lights.shadowBias')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 6 } })
@editable
@type(CCFloat)
Expand All @@ -182,8 +183,8 @@ export class DirectionalLight extends Light {
* @zh 实时阴影计算中的法线偏移。
*/
@tooltip('i18n:lights.shadowNormalBias')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 7 } })
@editable
@type(CCFloat)
Expand All @@ -202,8 +203,8 @@ export class DirectionalLight extends Light {
* @zh 实时阴影计算中的阴影颜色饱和度。
*/
@tooltip('i18n:lights.shadowSaturation')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 8 } })
@editable
@range([0.0, 1.0, 0.01])
Expand All @@ -226,8 +227,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowDistance')
@visible(function (this: DirectionalLight) {

Check warning on line 229 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === false;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 9 } })
Expand All @@ -254,8 +255,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowInvisibleOcclusionRange')
@visible(function (this: DirectionalLight) {

Check warning on line 257 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === false
&& this._csmAdvancedOptions;
})
Expand Down Expand Up @@ -301,8 +302,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.enableCSM')
@visible(function (this: DirectionalLight) {

Check warning on line 304 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === false;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 11 } })
Expand Down Expand Up @@ -367,8 +368,8 @@ export class DirectionalLight extends Light {
* @zh 实时阴影计算中是否使用固定区域阴影。
*/
@tooltip('i18n:lights.shadowFixedArea')
@visible(() => (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
@visible(() => getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap)
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 14 } })
@editable
@type(CCBoolean)
Expand All @@ -388,8 +389,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowNear')
@visible(function (this: DirectionalLight) {

Check warning on line 391 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === true;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 15 } })
Expand All @@ -411,8 +412,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowFar')
@visible(function (this: DirectionalLight) {

Check warning on line 414 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === true;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 16 } })
Expand All @@ -434,8 +435,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowOrthoSize')
@visible(function (this: DirectionalLight) {

Check warning on line 437 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type
=== ShadowType.ShadowMap && this._shadowFixedArea === true;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 17 } })
Expand All @@ -456,8 +457,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.shadowAdvancedOptions')
@visible(function (this: DirectionalLight) {

Check warning on line 459 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap
&& this._csmLevel > CSMLevel.LEVEL_1;
})
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 19 } })
Expand All @@ -476,8 +477,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.csmLayersTransition')
@visible(function (this: DirectionalLight) {

Check warning on line 479 in cocos/3d/lights/directional-light-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap
&& this._csmLevel > CSMLevel.LEVEL_1
&& this._csmAdvancedOptions;
})
Expand All @@ -498,8 +499,8 @@ export class DirectionalLight extends Light {
*/
@tooltip('i18n:lights.csmTransitionRange')
@visible(function (this: DirectionalLight) {
return (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
&& (cclegacy.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap
return getPipelineSceneData().shadows.enabled
&& getPipelineSceneData().shadows.type === ShadowType.ShadowMap
&& this._csmLevel > CSMLevel.LEVEL_1
&& this._csmAdvancedOptions;
})
Expand Down
11 changes: 6 additions & 5 deletions cocos/3d/lights/point-light-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { ccclass, help, executeInEditMode, menu, tooltip, type, displayOrder,
import { scene } from '../../render-scene';
import { Camera, LightType } from '../../render-scene/scene';
import { Light, PhotometricTerm } from './light-component';
import { CCFloat, CCInteger, cclegacy } from '../../core';
import { CCFloat, CCInteger } from '../../core';
import { getPipelineSceneData } from '../../rendering/pipeline-scene-data-utils';

/**
* @en The point light component, multiple point lights can be added to one scene.
Expand Down Expand Up @@ -58,15 +59,15 @@ export class PointLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 100])
@type(CCInteger)
get luminousFlux (): number {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._luminanceHDR * scene.nt2lm(1.0);
} else {
return this._luminanceLDR;
}
}
set luminousFlux (val) {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
let result = 0;
if (isHDR) {
this._luminanceHDR = val / scene.nt2lm(1.0);
Expand All @@ -89,15 +90,15 @@ export class PointLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 10])
@type(CCInteger)
get luminance (): number {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (val) {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
this._luminanceHDR = val;
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
Expand Down
5 changes: 3 additions & 2 deletions cocos/3d/lights/ranged-directional-light-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Camera, LightType } from '../../render-scene/scene';
import { scene } from '../../render-scene';
import { CCInteger, cclegacy } from '../../core';
import { range } from '../../core/data/decorators';
import { getPipelineSceneData } from '../../rendering/pipeline-scene-data-utils';

/**
* @en The ranged directional light component, Multiple ranged directional light sources are allowed in a scene.
Expand All @@ -51,15 +52,15 @@ export class RangedDirectionalLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 10])
@type(CCInteger)
get illuminance (): number {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._illuminanceHDR;
} else {
return this._illuminanceLDR;
}
}
set illuminance (val) {
const isHDR = cclegacy.director.root.pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
this._illuminanceHDR = val;
this._light && ((this._light as scene.RangedDirectionalLight).illuminanceHDR = this._illuminanceHDR);
Expand Down
10 changes: 5 additions & 5 deletions cocos/3d/lights/sphere-light-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { scene } from '../../render-scene';
import { Light, PhotometricTerm } from './light-component';
import { CCFloat, CCInteger, cclegacy } from '../../core';
import { Camera } from '../../render-scene/scene';
import { Root } from '../../root';
import { getPipelineSceneData } from '../../rendering/pipeline-scene-data-utils';

/**
* @en The sphere light component, multiple sphere lights can be added to one scene.
Expand Down Expand Up @@ -62,15 +62,15 @@ export class SphereLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 100])
@type(CCInteger)
get luminousFlux (): number {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._luminanceHDR * scene.nt2lm(this._size);
} else {
return this._luminanceLDR;
}
}
set luminousFlux (val) {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
let result = 0;
if (isHDR) {
this._luminanceHDR = val / scene.nt2lm(this._size);
Expand All @@ -92,15 +92,15 @@ export class SphereLight extends Light {
@range([0, Number.POSITIVE_INFINITY, 10])
@type(CCInteger)
get luminance (): number {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (val) {
const isHDR = (cclegacy.director.root as Root).pipeline.pipelineSceneData.isHDR;
const isHDR = getPipelineSceneData().isHDR;
if (isHDR) {
this._luminanceHDR = val;
this._light && ((this._light as scene.SphereLight).luminanceHDR = this._luminanceHDR);
Expand Down
Loading

0 comments on commit 979670f

Please sign in to comment.