diff --git a/cocos/core/3d/framework/directional-light-component.ts b/cocos/core/3d/framework/directional-light-component.ts index 3a3c492566..e208b45ef9 100644 --- a/cocos/core/3d/framework/directional-light-component.ts +++ b/cocos/core/3d/framework/directional-light-component.ts @@ -80,7 +80,6 @@ export class DirectionalLightComponent extends LightComponent { protected _destroyLight (scene?: RenderScene) { if (!this.node.scene || !this._light) { return; } - this._light.enabled = false; scene = scene || this._getRenderScene(); this._light.node = scene.defaultMainLightNode; } diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index fa77751fc9..db60637706 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -166,8 +166,11 @@ export class LightComponent extends Component { protected _attachToScene() { this._detachFromScene(); - if (this._light && !this._light.scene && !this.node.scene) { + if (this._light && !this._light.scene && this.node.scene) { switch (this._type) { + case LightType.DIRECTIONAL: + this._light.attachToScene(this._getRenderScene()); + break; case LightType.SPHERE: this._getRenderScene().addSphereLight(this._light as any); break; @@ -181,6 +184,9 @@ export class LightComponent extends Component { protected _detachFromScene() { if (this._light && this._light.scene) { switch (this._type) { + case LightType.DIRECTIONAL: + this._light.detachFromScene(); + break; case LightType.SPHERE: this._light.scene.removeSphereLight(this._light as any); break; diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index 20b86e2e1b..5f8742abc1 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -205,7 +205,7 @@ export class ForwardPipeline extends RenderPipeline { let spotNum = 0; for (let l = this._lightIndexOffset[i]; l < nextLightIndex; l++) { const light = this._validLights[this._lightIndices[l]]; - if (light && light.enabled) { + if (light) { switch (light.type) { case LightType.SPHERE: if (sphereNum >= UBOForwardLight.MAX_SPHERE_LIGHTS) { @@ -289,23 +289,19 @@ export class ForwardPipeline extends RenderPipeline { const sphereLights = view.camera.scene!.sphereLights; for (let i = 0; i < sphereLights.length; i++) { const light = sphereLights[i]; - if (light.enabled) { - light.update(); - sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); - if (intersect.sphere_frustum(_sphere, view.camera.frustum)) { - this._validLights.push(light); - } + light.update(); + sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); + if (intersect.sphere_frustum(_sphere, view.camera.frustum)) { + this._validLights.push(light); } } const spotLights = view.camera.scene!.spotLights; for (let i = 0; i < spotLights.length; i++) { const light = spotLights[i]; - if (light.enabled) { - light.update(); - sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); - if (intersect.sphere_frustum(_sphere, view.camera.frustum)) { - this._validLights.push(light); - } + light.update(); + sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); + if (intersect.sphere_frustum(_sphere, view.camera.frustum)) { + this._validLights.push(light); } } diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 469de3ab56..5d8aa39ce3 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -1163,7 +1163,7 @@ export abstract class RenderPipeline { Vec3.toArray(fv, mainLight.direction, UBOGlobal.MAIN_LIT_DIR_OFFSET); - if (mainLight.enabled) { + if (mainLight.scene) { Vec3.toArray(fv, mainLight.color, UBOGlobal.MAIN_LIT_COLOR_OFFSET); if (mainLight.useColorTemperature) { const colorTempRGB = mainLight.colorTemperatureRGB; @@ -1208,7 +1208,7 @@ export abstract class RenderPipeline { this._renderObjects.length = 0; const mainLight = scene.mainLight; - if (mainLight && mainLight.enabled) { + if (mainLight && mainLight.scene) { mainLight.update(); } diff --git a/cocos/core/renderer/models/skinning-model.ts b/cocos/core/renderer/models/skinning-model.ts index 3c52382294..e9321d6646 100644 --- a/cocos/core/renderer/models/skinning-model.ts +++ b/cocos/core/renderer/models/skinning-model.ts @@ -85,7 +85,7 @@ export class SkinningModel extends Model { this._mesh = mesh; if (!skeleton || !skinningRoot || !mesh) { return; } this._transform = skinningRoot; - this._jointsMedium.animInfo = this._scene!.root.dataPoolManager.jointsAnimationInfo.get(skinningRoot.uuid); + this._jointsMedium.animInfo = cc.director.root.dataPoolManager.jointsAnimationInfo.get(skinningRoot.uuid); if (!this._jointsMedium.buffer) { this._jointsMedium.buffer = this._device.createBuffer({ usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, @@ -124,7 +124,7 @@ export class SkinningModel extends Model { public uploadAnimation (anim: AnimationClip | null) { if (!this._skeleton || !this._mesh) { return; } this.uploadedAnim = anim; - const resMgr = this._scene!.root.dataPoolManager; + const resMgr = cc.director.root.dataPoolManager; const texture = anim ? resMgr.jointsTexturePool.getJointsTextureWithAnimation(this._skeleton, anim) : resMgr.jointsTexturePool.getDefaultJointsTexture(this._skeleton); resMgr.jointsAnimationInfo.switchClip(this._jointsMedium.animInfo!, anim); @@ -136,7 +136,7 @@ export class SkinningModel extends Model { protected _applyJointsTexture (texture: IJointsTextureHandle | null) { if (!texture) { return; } const oldTex = this._jointsMedium.texture; - if (oldTex && oldTex !== texture) { this._scene!.root.dataPoolManager.jointsTexturePool.releaseHandle(oldTex); } + if (oldTex && oldTex !== texture) { cc.director.root.dataPoolManager.jointsTexturePool.releaseHandle(oldTex); } this._jointsMedium.texture = texture; const { buffer, jointsTextureInfo } = this._jointsMedium; jointsTextureInfo[0] = texture.handle.texture.width; diff --git a/cocos/core/renderer/scene/directional-light.ts b/cocos/core/renderer/scene/directional-light.ts index b522274a2f..c3bd1986df 100644 --- a/cocos/core/renderer/scene/directional-light.ts +++ b/cocos/core/renderer/scene/directional-light.ts @@ -1,5 +1,4 @@ import { Quat, Vec3 } from '../../math'; -import { TransformBit } from '../../scene-graph/node-enum'; import { INode } from '../../utils/interfaces'; import { Light, LightType } from './light'; import { RenderScene } from './render-scene'; @@ -34,7 +33,6 @@ export class DirectionalLight extends Light { constructor () { super(); this._type = LightType.DIRECTIONAL; - this._node.hasChangedFlags = TransformBit.ROTATION; } public update () { diff --git a/cocos/core/renderer/scene/light.ts b/cocos/core/renderer/scene/light.ts index 99b6f2d3f0..1e7e7c6e03 100644 --- a/cocos/core/renderer/scene/light.ts +++ b/cocos/core/renderer/scene/light.ts @@ -1,6 +1,7 @@ import { Vec3 } from '../../math'; import { INode } from '../../utils/interfaces'; import { RenderScene } from './render-scene'; +import { TransformBit } from '../../scene-graph/node-enum'; // Color temperature (in Kelvin) to RGB export function ColorTemperatureToRGB (rgb: Vec3, kelvin: number) { @@ -40,13 +41,6 @@ export const nt2lm = (size: number) => 4 * Math.PI * Math.PI * size * size; export class Light { - set enabled (val) { - this._enabled = val; - } - get enabled () { - return this._enabled; - } - set color (color: Vec3) { this._color.set(color); } @@ -78,6 +72,9 @@ export class Light { set node (n) { this._node = n; + if (this._node) { + this._node.hasChangedFlags = TransformBit.ROTATION; + } } get node () { @@ -96,7 +93,6 @@ export class Light { return this._scene; } - protected _enabled = true; protected _color: Vec3 = new Vec3(1, 1, 1); protected _useColorTemp: boolean = false; protected _colorTemp: number = 6550.0; diff --git a/cocos/core/renderer/scene/model.ts b/cocos/core/renderer/scene/model.ts index 44d169e4d9..d8b2e432a4 100644 --- a/cocos/core/renderer/scene/model.ts +++ b/cocos/core/renderer/scene/model.ts @@ -146,7 +146,7 @@ export class Model { protected _node: INode | null = null; protected _transform: INode | null = null; protected _id: number = -1; - protected _enabled: boolean = false; + protected _enabled: boolean = true; protected _visFlags = Layers.Enum.NONE; protected _cameraID = -1; protected _userKey = -1; diff --git a/cocos/core/renderer/scene/render-scene.ts b/cocos/core/renderer/scene/render-scene.ts index 61189e719a..611bbc8cd9 100644 --- a/cocos/core/renderer/scene/render-scene.ts +++ b/cocos/core/renderer/scene/render-scene.ts @@ -132,7 +132,6 @@ export class RenderScene { this._mainLight = new DirectionalLight(); this._mainLight.initialize('Main Light', this._defaultMainLightNode); this._mainLight.illuminance = Ambient.SUN_ILLUM; - this._mainLight.enabled = false; // disabled by default this._ambient = new Ambient(this); this._skybox = new Skybox(this); this._planarShadows = new PlanarShadows(this); diff --git a/cocos/core/renderer/ui/ui.ts b/cocos/core/renderer/ui/ui.ts index 8bb3748f84..a45cfc3c09 100644 --- a/cocos/core/renderer/ui/ui.ts +++ b/cocos/core/renderer/ui/ui.ts @@ -376,7 +376,7 @@ export class UI { } } - const uiCanvas = this.getScreen(comp.node.uiTransfromComp.visibility); + const uiCanvas = this._currCanvas; const curDrawBatch = this._drawBatchPool.alloc(); curDrawBatch.camera = uiCanvas && uiCanvas.camera; curDrawBatch.model = model; diff --git a/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts b/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts index f20bb9793e..0301fc58c4 100644 --- a/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts @@ -176,11 +176,10 @@ export const graphicsAssembler: IAssembler = { }, end (graphics: GraphicsComponent){ - const scene = director.root!.ui.renderScene as RenderScene; - if (graphics.model){ + if (graphics.model) { graphics.model.destroy(); - scene.destroyModel(graphics.model); - graphics.model = null; + } else { + graphics.model = new Model(); } const impl = graphics.impl; @@ -226,9 +225,8 @@ export const graphicsAssembler: IAssembler = { indices, }, undefined, { calculateBounds: false }); - graphics.model = scene.createModel(Model, graphics.node); - graphics.model.initSubModel(0, mesh.getSubMesh(0), graphics.material!); - graphics.model.enabled = true; + graphics.model!.initialize(graphics.node); + graphics.model!.initSubModel(0, mesh.getSubMesh(0), graphics.material!); graphics.markForUpdateRenderData(); }, diff --git a/cocos/ui/components/graphics-component.ts b/cocos/ui/components/graphics-component.ts index 154e5fb20e..0a599dba65 100644 --- a/cocos/ui/components/graphics-component.ts +++ b/cocos/ui/components/graphics-component.ts @@ -214,22 +214,21 @@ export class GraphicsComponent extends UIRenderComponent { public onLoad (){ this._sceneGetter = director.root!.ui.getRenderSceneGetter(); + if (!this.model) { + this.model = new Model(); + } } public onEnable () { super.onEnable(); - if (this.model){ - this.model.enabled = true; - } + this._attachToScene(); this._activateMaterial(); } public onDisable (){ - if (this.model){ - this.model.enabled = false; - } + this._detachFromScene(); } public onDestroy () { @@ -237,7 +236,7 @@ export class GraphicsComponent extends UIRenderComponent { this._sceneGetter = null; if (this.model) { - this._getRenderScene().destroyModel(this.model); + this.model.destroy(); this.model = null; } @@ -249,6 +248,23 @@ export class GraphicsComponent extends UIRenderComponent { this.impl = null; } + protected _attachToScene(){ + const scene = director.root!.ui.renderScene; + if (!this.model) { + return; + } + if (this.model!.scene != null) { + this._detachFromScene(); + } + scene.addModel(this.model!); + } + + protected _detachFromScene() { + if (this.model && this.model.scene) { + this.model.scene.removeModel(this.model); + } + } + public _activateMaterial () { if (!this._material) { return; @@ -435,8 +451,8 @@ export class GraphicsComponent extends UIRenderComponent { this.impl.clear(clean); if (this.model) { - this.model.scene.destroyModel(this.model); - this.model = null; + this._detachFromScene(); + this.model.destroy(); } this.markForUpdateRenderData();