diff --git a/cocos/core/renderer/scene/camera.ts b/cocos/core/renderer/scene/camera.ts index 216e567033e..d0c2c2427e4 100644 --- a/cocos/core/renderer/scene/camera.ts +++ b/cocos/core/renderer/scene/camera.ts @@ -351,9 +351,10 @@ export class Camera { CameraPool.setMat4(this._poolHandle, CameraView.MAT_VIEW_PROJ_INV, this._matViewProjInv); this._nativeObj.matViewProj = this._matViewProj; this._nativeObj.matViewProjInv = this._matViewProjInv; + + recordFrustumToSharedMemory(this._frustumHandle, this._frustum); + this._nativeObj.frustum = this._frustum; } - recordFrustumToSharedMemory(this._frustumHandle, this._frustum); - this._nativeObj.frustum = this._frustum; } } @@ -578,8 +579,10 @@ export class Camera { set frustum (val) { this._frustum = val; - recordFrustumToSharedMemory(this._frustumHandle, val); - this._nativeObj.frustum = this._frustum; + if (JSB) { + recordFrustumToSharedMemory(this._frustumHandle, val); + this._nativeObj.frustum = this._frustum; + } } get frustum () { diff --git a/cocos/core/renderer/scene/directional-light.ts b/cocos/core/renderer/scene/directional-light.ts index 21d93c60e87..e9c45aa1520 100644 --- a/cocos/core/renderer/scene/directional-light.ts +++ b/cocos/core/renderer/scene/directional-light.ts @@ -40,7 +40,7 @@ export class DirectionalLight extends Light { Vec3.normalize(this._dir, dir); if (JSB) { LightPool.setVec3(this._handle, LightView.DIRECTION, this._dir); - this._nativeObj.setDir(dir); + this._nativeObj.setDirection(dir); } } diff --git a/cocos/core/renderer/scene/render-scene.ts b/cocos/core/renderer/scene/render-scene.ts index d960a1e341e..28b0f3953cd 100644 --- a/cocos/core/renderer/scene/render-scene.ts +++ b/cocos/core/renderer/scene/render-scene.ts @@ -34,7 +34,6 @@ import { TransformBit } from '../../scene-graph/node-enum'; import { ScenePool, SceneView, ModelArrayPool, ModelArrayHandle, SceneHandle, NULL_HANDLE, UIBatchArrayHandle, UIBatchArrayPool, LightArrayHandle, LightArrayPool } from '../core/memory-pools'; import { DrawBatch2D } from '../../../2d/renderer/draw-batch'; -import { scene } from '..'; export interface IRenderSceneInfo { name: string; @@ -222,13 +221,10 @@ export class RenderScene { if (this._mainLight === dl) { const dlList = this._directionalLights; if (dlList.length) { - this._mainLight = dlList[dlList.length - 1]; - this._nativeObj.setMainLight(this._mainLight); + this.setMainLight(dlList[dlList.length - 1]); if (this._mainLight.node) { // trigger update this._mainLight.node.hasChangedFlags |= TransformBit.ROTATION; } - } else { - this._nativeObj.setMainLight(null); } } } @@ -253,6 +249,7 @@ export class RenderScene { this._sphereLights.push(pl); if (JSB) { LightArrayPool.push(this._sphereLightsHandle, pl.handle); + this._nativeObj.addSphereLight(pl.native); } } @@ -263,6 +260,7 @@ export class RenderScene { this._sphereLights.splice(i, 1); if (JSB) { LightArrayPool.erase(this._sphereLightsHandle, i); + this._nativeObj.removeSphereLight(pl.native); } return; } @@ -274,6 +272,7 @@ export class RenderScene { this._spotLights.push(sl); if (JSB) { LightArrayPool.push(this._spotLightsHandle, sl.handle); + this._nativeObj.addSpotLight(sl.native); } } @@ -284,6 +283,7 @@ export class RenderScene { this._spotLights.splice(i, 1); if (JSB) { LightArrayPool.erase(this._spotLightsHandle, i); + this._nativeObj.removeSpotLight(sl.native); } return; } @@ -297,6 +297,7 @@ export class RenderScene { this._sphereLights.length = 0; if (JSB) { LightArrayPool.clear(this._sphereLightsHandle); + this._nativeObj.removeSphereLights(); } } @@ -307,6 +308,7 @@ export class RenderScene { this._spotLights = []; if (JSB) { LightArrayPool.clear(this._spotLightsHandle); + this._nativeObj.removeSpotLights(); } } diff --git a/cocos/core/renderer/scene/sphere-light.ts b/cocos/core/renderer/scene/sphere-light.ts index e717f325a3a..35a649e7689 100644 --- a/cocos/core/renderer/scene/sphere-light.ts +++ b/cocos/core/renderer/scene/sphere-light.ts @@ -52,6 +52,9 @@ export class SphereLight extends Light { LightPool.setVec3(this._handle, LightView.POSITION, this._pos); AABBPool.setVec3(this._hAABB, AABBView.CENTER, this._aabb.center); AABBPool.setVec3(this._hAABB, AABBView.HALF_EXTENSION, this._aabb.halfExtents); + + this._nativeObj.setPosition(this._pos); + this._nativeObj.setAABB(this._aabb); } } @@ -63,6 +66,7 @@ export class SphereLight extends Light { this._size = size; if (JSB) { LightPool.set(this._handle, LightView.SIZE, size); + this._nativeObj.setSize(size); } } @@ -74,6 +78,7 @@ export class SphereLight extends Light { this._range = range; if (JSB) { LightPool.set(this._handle, LightView.RANGE, range); + this._nativeObj.setRange(range); } this._needUpdate = true; @@ -87,6 +92,7 @@ export class SphereLight extends Light { this._luminance = lum; if (JSB) { LightPool.set(this._handle, LightView.ILLUMINANCE, lum); + this._nativeObj.setIlluminance(lum); } } diff --git a/cocos/core/renderer/scene/spot-light.ts b/cocos/core/renderer/scene/spot-light.ts index 53b8ec9a485..a0960aecec5 100644 --- a/cocos/core/renderer/scene/spot-light.ts +++ b/cocos/core/renderer/scene/spot-light.ts @@ -92,6 +92,7 @@ export class SpotLight extends Light { this._dir.set(dir); if (JSB) { LightPool.setVec3(this._handle, LightView.DIRECTION, this._dir); + this._nativeObj.setDirection(dir); } } @@ -102,6 +103,10 @@ export class SpotLight extends Light { AABBPool.setVec3(this._hAABB, AABBView.CENTER, this._aabb.center); AABBPool.setVec3(this._hAABB, AABBView.HALF_EXTENSION, this._aabb.halfExtents); recordFrustumToSharedMemory(this._hFrustum, this._frustum); + this._nativeObj.setFrustum(this._frustum); + this._nativeObj.setAABB(this._aabb); + this._nativeObj.setDirection(this._dir); + this._nativeObj.setPosition(this._pos); } } @@ -113,6 +118,7 @@ export class SpotLight extends Light { this._size = size; if (JSB) { LightPool.set(this._handle, LightView.SIZE, size); + this._nativeObj.setSize(size); } } @@ -124,6 +130,7 @@ export class SpotLight extends Light { this._range = range; if (JSB) { LightPool.set(this._handle, LightView.RANGE, range); + this._nativeObj.setRange(range); } this._needUpdate = true; @@ -137,6 +144,7 @@ export class SpotLight extends Light { this._luminance = lum; if (JSB) { LightPool.set(this._handle, LightView.ILLUMINANCE, lum); + this._nativeObj.setIlluminance(lum); } } @@ -157,6 +165,7 @@ export class SpotLight extends Light { this._spotAngle = Math.cos(val * 0.5); if (JSB) { LightPool.set(this._handle, LightView.SPOT_ANGLE, this._spotAngle); + this._nativeObj.setAngle(this._spotAngle); } this._needUpdate = true; @@ -166,6 +175,7 @@ export class SpotLight extends Light { this._aspect = val; if (JSB) { LightPool.set(this._handle, LightView.ASPECT, val); + this._nativeObj.setAspect(val); } this._needUpdate = true; diff --git a/cocos/core/renderer/scene/submodel.ts b/cocos/core/renderer/scene/submodel.ts index 0084652a6bf..9563a954430 100644 --- a/cocos/core/renderer/scene/submodel.ts +++ b/cocos/core/renderer/scene/submodel.ts @@ -213,7 +213,6 @@ export class SubModel { } public destroy (): void { - this._destroy(); this._destroyDescriptorSet(); this._destroyInputAssembler(); this.priority = RenderPriority.DEFAULT; @@ -221,6 +220,8 @@ export class SubModel { this._patches = null; this._subMesh = null; this._passes = null; + + this._destroy(); } public update (): void {