From 4aee52d1bbd6b383ae8cc89a6e8185b5ff621d0f Mon Sep 17 00:00:00 2001 From: sirxu <397939361@qq.com> Date: Wed, 9 Aug 2023 22:33:06 +0800 Subject: [PATCH 1/2] fix: change number children change number children --- src/components/Transform.ts | 2 +- src/core/entities/Entity.ts | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/Transform.ts b/src/components/Transform.ts index cc01a892..a237193e 100644 --- a/src/components/Transform.ts +++ b/src/components/Transform.ts @@ -133,7 +133,7 @@ export class Transform extends ComponentBase { } else { this._scene3d = hasRoot; for (let c of this.object3D.components.values()) { - ComponentCollect.appendWaitStart(this.object3D, c); + ComponentCollect.appendWaitStart(c); } } diff --git a/src/core/entities/Entity.ts b/src/core/entities/Entity.ts index 4712ff71..f01a00b0 100644 --- a/src/core/entities/Entity.ts +++ b/src/core/entities/Entity.ts @@ -3,9 +3,8 @@ import { RenderNode } from '../../components/renderer/RenderNode'; import { Transform } from '../../components/Transform'; import { CEventDispatcher } from '../../event/CEventDispatcher'; import { RenderLayer } from '../../gfx/renderJob/config/RenderLayer'; -import { Vector3 } from '../../math/Vector3'; import { BoundUtil } from '../../util/BoundUtil'; -import { GetCountInstanceID, UUID } from '../../util/Global'; +import { GetCountInstanceID } from '../../util/Global'; import { BoundingBox } from '../bound/BoundingBox'; import { IBound } from '../bound/IBound'; import { Object3D } from './Object3D'; @@ -24,6 +23,7 @@ export class Entity extends CEventDispatcher { public name: string = ''; protected readonly _instanceID: string = ''; + private _numChildren: number; /** * The unique identifier of the object. @@ -62,9 +62,6 @@ export class Entity extends CEventDispatcher { public components: Map; - public numChildren: number = 0; - - protected waitDisposeComponents: IComponent[]; /** @@ -132,7 +129,7 @@ export class Entity extends CEventDispatcher { * Returns the number of child objects of an object */ public get numChildren(): number { - return this.entityChildren.length; + return this._numChildren; } /** @@ -157,7 +154,7 @@ export class Entity extends CEventDispatcher { } child.transform.parent = this.transform; this.entityChildren.push(child); - this.numChildren = this.entityChildren.length; + this._numChildren = this.entityChildren.length; return child; } return null; @@ -175,7 +172,7 @@ export class Entity extends CEventDispatcher { if (index != -1) { this.entityChildren.splice(index, 1); child.transform.parent = null; - this.numChildren = this.entityChildren.length; + this._numChildren = this.entityChildren.length; } } From 1ecb8d2de9873d649f4ec56bea3ac1b143faafc7 Mon Sep 17 00:00:00 2001 From: sirxu <397939361@qq.com> Date: Thu, 10 Aug 2023 21:22:35 +0800 Subject: [PATCH 2/2] fix: fix renderer fix transform localQuat fix renderer enable --- samples/material/Sample_PBRMaterial.ts | 2 +- src/components/AtmosphericComponent.ts | 8 +++- src/components/Transform.ts | 51 +++++--------------------- src/components/renderer/RenderNode.ts | 6 +-- 4 files changed, 20 insertions(+), 47 deletions(-) diff --git a/samples/material/Sample_PBRMaterial.ts b/samples/material/Sample_PBRMaterial.ts index dc46703b..e7f4d91d 100644 --- a/samples/material/Sample_PBRMaterial.ts +++ b/samples/material/Sample_PBRMaterial.ts @@ -54,7 +54,7 @@ class Sample_PBRMaterial { let directLight = this.lightObj3D.addComponent(DirectLight); directLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355); directLight.castShadow = true; - directLight.intensity = 43; + directLight.intensity = 72; GUIUtil.renderDirLight(directLight); this.scene.addChild(this.lightObj3D); diff --git a/src/components/AtmosphericComponent.ts b/src/components/AtmosphericComponent.ts index 9f274a65..c3139a46 100644 --- a/src/components/AtmosphericComponent.ts +++ b/src/components/AtmosphericComponent.ts @@ -129,9 +129,15 @@ export class AtmosphericComponent extends SkyRenderer { super.init(); this._historyData = new HistoryData(); this._atmosphericScatteringSky = new AtmosphericScatteringSky(new AtmosphericScatteringSkySetting()); + + let view3D = this.transform.view3D; + let scene = this.transform.scene3D; + this.map = this._atmosphericScatteringSky; + scene.envMap = this._atmosphericScatteringSky; + this.onUpdate(view3D); } - public start(): void { + public start(view?: any): void { let scene = this.transform.scene3D; this.map = this._atmosphericScatteringSky; scene.envMap = this._atmosphericScatteringSky; diff --git a/src/components/Transform.ts b/src/components/Transform.ts index a237193e..53b0a474 100644 --- a/src/components/Transform.ts +++ b/src/components/Transform.ts @@ -217,12 +217,9 @@ export class Transform extends ComponentBase { public set up(value: Vector3) { this._up.copyFrom(value); - this.notifyLocalChange(); - this.onRotationChange?.(); - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } + MathUtil.fromToRotation(Vector3.UP, this._up, Quaternion.HELP_0); + this.transform.localRotQuat = Quaternion.HELP_0; } public get down(): Vector3 { @@ -232,13 +229,8 @@ export class Transform extends ComponentBase { public set down(value: Vector3) { this._down.copyFrom(value); - this.notifyLocalChange(); - - this.onRotationChange?.(); - - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } + MathUtil.fromToRotation(Vector3.DOWN, this._down, Quaternion.HELP_0); + this.transform.localRotQuat = Quaternion.HELP_0; } public get forward(): Vector3 { @@ -250,12 +242,6 @@ export class Transform extends ComponentBase { this._forward.copyFrom(value); MathUtil.fromToRotation(Vector3.FORWARD, this._forward, Quaternion.HELP_0); this.transform.localRotQuat = Quaternion.HELP_0; - this.notifyLocalChange(); - this.onRotationChange?.(); - - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } } public get back(): Vector3 { @@ -267,12 +253,6 @@ export class Transform extends ComponentBase { this._back.copyFrom(value); MathUtil.fromToRotation(Vector3.BACK, this._back, Quaternion.HELP_0); this.transform.localRotQuat = Quaternion.HELP_0; - this.notifyLocalChange(); - this.onRotationChange?.(); - - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } } public get left(): Vector3 { @@ -282,11 +262,8 @@ export class Transform extends ComponentBase { public set left(value: Vector3) { this._left.copyFrom(value); - this.notifyLocalChange(); - this.onRotationChange?.(); - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } + MathUtil.fromToRotation(Vector3.LEFT, this._left, Quaternion.HELP_0); + this.transform.localRotQuat = Quaternion.HELP_0; } public get right(): Vector3 { @@ -296,12 +273,8 @@ export class Transform extends ComponentBase { public set right(value: Vector3) { this._right.copyFrom(value); - this.notifyLocalChange(); - this.onRotationChange?.(); - - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } + MathUtil.fromToRotation(Vector3.RIGHT, this._right, Quaternion.HELP_0); + this.transform.localRotQuat = Quaternion.HELP_0; } /** @@ -315,13 +288,7 @@ export class Transform extends ComponentBase { public set localRotQuat(value: Quaternion) { this._localRotQuat = value; this._localRotQuat.getEulerAngles(this._localRot); - - this.notifyLocalChange(); - this.onRotationChange?.(); - - if (this.eventRotationChange) { - this.eventDispatcher.dispatchEvent(this.eventRotationChange); - } + this.localRotation = this._localRot; } /** diff --git a/src/components/renderer/RenderNode.ts b/src/components/renderer/RenderNode.ts index b21a5d54..8f8bc88b 100644 --- a/src/components/renderer/RenderNode.ts +++ b/src/components/renderer/RenderNode.ts @@ -467,9 +467,9 @@ export class RenderNode extends ComponentBase { renderShader.setTexture(`envMap`, envMap); } - if (!node._ignorePrefilterMap && renderShader.prefilterMap != envMap) { - renderShader.setTexture(`prefilterMap`, envMap); - } + // if (!node._ignorePrefilterMap && renderShader.prefilterMap != envMap) { + renderShader.setTexture(`prefilterMap`, envMap); + // } if (renderShader.pipeline) { renderShader.apply(node._geometry, pass, renderPassState, () => node.noticeShaderChange());