diff --git a/samples/animation/Sample_CurveAnimation.ts b/samples/animation/Sample_CurveAnimation.ts index 4605c5cf..73780d9c 100644 --- a/samples/animation/Sample_CurveAnimation.ts +++ b/samples/animation/Sample_CurveAnimation.ts @@ -22,7 +22,7 @@ class Sample_AnimCurve { Engine3D.setting.shadow.type = `HARD`; this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -36,6 +36,7 @@ class Sample_AnimCurve { Engine3D.startRenderView(view); await this.initScene(); + sky.relativeTransform = this.lightObj3D.transform; } async initScene() { diff --git a/samples/animation/Sample_MorphTarget.ts b/samples/animation/Sample_MorphTarget.ts index b2b9c5d6..22af1b70 100644 --- a/samples/animation/Sample_MorphTarget.ts +++ b/samples/animation/Sample_MorphTarget.ts @@ -14,13 +14,14 @@ class Sample_MorphTarget { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, webGPUContext.aspect, 1, 5000.0); camera.object3D.addComponent(HoverCameraController).setCamera(0, 0, 150); this.initDirectLight(); + sky.relativeTransform = this.lightObj3D.transform; await this.initMorphModel(); let view = new View3D(); diff --git a/samples/animation/Sample_PropertyAnimation.ts b/samples/animation/Sample_PropertyAnimation.ts index 696cc374..560a79e6 100644 --- a/samples/animation/Sample_PropertyAnimation.ts +++ b/samples/animation/Sample_PropertyAnimation.ts @@ -16,8 +16,6 @@ class Sample_PropertyAnimation { await Engine3D.init(); let param = createSceneParam(); param.camera.distance = 16; - param.camera.pitch = -25; - param.light.intensity = 40; let exampleScene = createExampleScene(param); GUIHelp.init(); diff --git a/samples/animation/Sample_Skeleton.ts b/samples/animation/Sample_Skeleton.ts index 67aec50f..ff26b72c 100644 --- a/samples/animation/Sample_Skeleton.ts +++ b/samples/animation/Sample_Skeleton.ts @@ -15,7 +15,7 @@ class Sample_Skeleton { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -30,7 +30,8 @@ class Sample_Skeleton { Engine3D.startRenderView(view); - this.initScene(this.scene); + await this.initScene(this.scene); + sky.relativeTransform = this.lightObj3D.transform; } diff --git a/samples/animation/Sample_Skeleton2.ts b/samples/animation/Sample_Skeleton2.ts index 4a4bafce..7656a560 100644 --- a/samples/animation/Sample_Skeleton2.ts +++ b/samples/animation/Sample_Skeleton2.ts @@ -16,7 +16,7 @@ class Sample_Skeleton2 { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); this.scene.exposure = 1; let mainCamera = CameraUtil.createCamera3DObject(this.scene); @@ -33,6 +33,7 @@ class Sample_Skeleton2 { Engine3D.startRenderView(view); await this.initScene(this.scene); + sky.relativeTransform = this.lightObj3D.transform; } async initScene(scene: Scene3D) { @@ -56,7 +57,7 @@ class Sample_Skeleton2 { GUIUtil.renderDirLight(directLight); scene.addChild(this.lightObj3D); } - + { // load model with skeletion animation let rootNode = await Engine3D.res.loadGltf('gltfs/glb/Soldier.glb'); @@ -96,8 +97,8 @@ class Sample_Skeleton2 { return true; } - sleep(time:number){ - return new Promise(res=>{ + sleep(time: number) { + return new Promise(res => { setTimeout(res, time || 200) }) } diff --git a/samples/animation/Sample_Skeleton3.ts b/samples/animation/Sample_Skeleton3.ts index e3efc849..3faf9199 100644 --- a/samples/animation/Sample_Skeleton3.ts +++ b/samples/animation/Sample_Skeleton3.ts @@ -21,7 +21,7 @@ class Sample_Skeleton3 { GUIHelp.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let mainCamera = CameraUtil.createCamera3DObject(this.scene); mainCamera.perspective(60, webGPUContext.aspect, 1, 3000.0); @@ -37,6 +37,7 @@ class Sample_Skeleton3 { this.view.camera = mainCamera; Engine3D.startRenderView(this.view); + sky.relativeTransform = this.lightObj3D.transform; } async initScene(scene: Scene3D) { diff --git a/samples/base/Sample_Destroy.ts b/samples/base/Sample_Destroy.ts index 0e6734f6..14915062 100644 --- a/samples/base/Sample_Destroy.ts +++ b/samples/base/Sample_Destroy.ts @@ -31,6 +31,7 @@ class Sample_Destroy { let light: Object3D = new Object3D() // add direct light component let component: DirectLight = light.addComponent(DirectLight) + sky.relativeTransform = component.transform; // adjust lighting light.rotationX = 45 light.rotationY = 30 diff --git a/samples/base/Sample_Transform.ts b/samples/base/Sample_Transform.ts index 3de4144e..6cb6498d 100644 --- a/samples/base/Sample_Transform.ts +++ b/samples/base/Sample_Transform.ts @@ -44,6 +44,8 @@ class Sample_Transform { dirLight.intensity = 10; scene.addChild(lightObj); + sky.relativeTransform = dirLight.transform; + // create a view with target scene and camera let view = new View3D(); view.scene = scene; diff --git a/samples/geometry/Sample_CustomGeometry.ts b/samples/geometry/Sample_CustomGeometry.ts index 88a76276..ce14ce92 100644 --- a/samples/geometry/Sample_CustomGeometry.ts +++ b/samples/geometry/Sample_CustomGeometry.ts @@ -4,6 +4,7 @@ import { GUIUtil } from "@samples/utils/GUIUtil"; // An sample of custom vertex attribute of geometry class Sample_CustomGeometry { + dirLight: DirectLight; async run() { Engine3D.setting.shadow.autoUpdate = true; Engine3D.setting.shadow.shadowBias = 0.002; @@ -13,7 +14,7 @@ class Sample_CustomGeometry { await Engine3D.init(); let view = new View3D(); view.scene = new Scene3D(); - view.scene.addComponent(AtmosphericComponent); + let sky = view.scene.addComponent(AtmosphericComponent); view.camera = CameraUtil.createCamera3DObject(view.scene); view.camera.perspective(60, webGPUContext.aspect, 1, 5000.0); @@ -22,12 +23,13 @@ class Sample_CustomGeometry { Engine3D.startRenderView(view); - this.createScene(view.scene); + await this.createScene(view.scene); + sky.relativeTransform = this.dirLight.transform; } private async createScene(scene: Scene3D) { let sunObj = new Object3D(); - let sunLight = sunObj.addComponent(DirectLight); + let sunLight = this.dirLight = sunObj.addComponent(DirectLight); sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(65533); sunLight.castShadow = true; sunObj.transform.rotationX = 50; diff --git a/samples/geometry/Sample_InternalGeometry.ts b/samples/geometry/Sample_InternalGeometry.ts index f86d244b..58a5b418 100644 --- a/samples/geometry/Sample_InternalGeometry.ts +++ b/samples/geometry/Sample_InternalGeometry.ts @@ -4,6 +4,7 @@ import { GUIUtil } from "@samples/utils/GUIUtil"; // An sample of display internal geometry class Sample_InternalGeometry { + lightObj: Object3D; async run() { Engine3D.setting.shadow.autoUpdate = true; Engine3D.setting.shadow.shadowBias = 0.002; @@ -13,7 +14,7 @@ class Sample_InternalGeometry { await Engine3D.init(); let view = new View3D(); view.scene = new Scene3D(); - view.scene.addComponent(AtmosphericComponent); + let sky = view.scene.addComponent(AtmosphericComponent); view.camera = CameraUtil.createCamera3DObject(view.scene); view.camera.perspective(60, webGPUContext.aspect, 1, 5000.0); @@ -22,12 +23,13 @@ class Sample_InternalGeometry { Engine3D.startRenderView(view); - this.createScene(view.scene); + await this.createScene(view.scene); + sky.relativeTransform = this.lightObj.transform; } private async createScene(scene: Scene3D) { // add a direction light - let lightObj3D = new Object3D(); + let lightObj3D = this.lightObj = new Object3D(); let sunLight = lightObj3D.addComponent(DirectLight); sunLight.intensity = 15; sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(6553); diff --git a/samples/geometry/Sample_VertexAnimation.ts b/samples/geometry/Sample_VertexAnimation.ts index 6b975c87..7063adc5 100644 --- a/samples/geometry/Sample_VertexAnimation.ts +++ b/samples/geometry/Sample_VertexAnimation.ts @@ -8,6 +8,7 @@ class Smaple_VertexAnimation { // This geometry will dynamically update its vertex data over time floorGeometry: PlaneGeometry; scene: Scene3D; + lightObj: Object3D; async run() { await Engine3D.init({ beforeRender: () => this.update() }); @@ -15,7 +16,7 @@ class Smaple_VertexAnimation { let view = new View3D(); view.scene = new Scene3D(); - view.scene.addComponent(AtmosphericComponent); + let sky = view.scene.addComponent(AtmosphericComponent); view.scene.addComponent(Stats); this.scene = view.scene; @@ -27,12 +28,13 @@ class Smaple_VertexAnimation { Engine3D.startRenderView(view); this.createScene(); + sky.relativeTransform = this.lightObj.transform; } private createScene() { GUIHelp.init(); // add light - let lightObj3D = new Object3D(); + let lightObj3D = this.lightObj = new Object3D(); let directLight = lightObj3D.addComponent(DirectLight); directLight.intensity = 25; directLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355); diff --git a/samples/lights/Sample_AddRemovePointLight.ts b/samples/lights/Sample_AddRemovePointLight.ts index c2f45519..6ab9e1d8 100644 --- a/samples/lights/Sample_AddRemovePointLight.ts +++ b/samples/lights/Sample_AddRemovePointLight.ts @@ -15,7 +15,7 @@ class Sample_AddRemovePointLight { GUIHelp.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); // init camera3D let mainCamera = CameraUtil.createCamera3D(null, this.scene); mainCamera.perspective(60, Engine3D.aspect, 1, 2000.0); @@ -29,6 +29,7 @@ class Sample_AddRemovePointLight { view.camera = mainCamera; Engine3D.startRenderViews([view]); + sky.relativeTransform = this.lightObj.transform; } diff --git a/samples/lights/Sample_DirectLight.ts b/samples/lights/Sample_DirectLight.ts index c37079b4..109f14e8 100644 --- a/samples/lights/Sample_DirectLight.ts +++ b/samples/lights/Sample_DirectLight.ts @@ -19,7 +19,7 @@ class Sample_DirectLight { mainCamera.perspective(60, Engine3D.aspect, 1, 2000.0); //set camera data mainCamera.object3D.addComponent(HoverCameraController).setCamera(0, -25, 1000); - + sky.relativeTransform = this.initLight(); this.initScene(); @@ -39,7 +39,7 @@ class Sample_DirectLight { this.lightObj3D.z = -40; this.lightObj3D.rotationX = 46; this.lightObj3D.rotationY = 62; - this.lightObj3D.rotationZ = 360; + this.lightObj3D.rotationZ = 0; let directLight = this.lightObj3D.addComponent(DirectLight); //Convert color temperature to color object directLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355); diff --git a/samples/lights/Sample_DirectLightShadow.ts b/samples/lights/Sample_DirectLightShadow.ts index 4073ba36..6a8de19e 100644 --- a/samples/lights/Sample_DirectLightShadow.ts +++ b/samples/lights/Sample_DirectLightShadow.ts @@ -32,7 +32,7 @@ class Sample_DirectLightShadow { let view = new View3D(); view.scene = this.scene; view.camera = mainCamera; - + Engine3D.startRenderView(view); } @@ -40,6 +40,9 @@ class Sample_DirectLightShadow { private initLight() { // add a direction light let lightObj3D = new Object3D(); + lightObj3D.rotationX = 46; + lightObj3D.rotationY = 62; + lightObj3D.rotationZ = 0; let sunLight = lightObj3D.addComponent(DirectLight); sunLight.intensity = 15; sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(6553); @@ -47,7 +50,7 @@ class Sample_DirectLightShadow { GUIUtil.renderDirLight(sunLight); this.scene.addChild(lightObj3D); - return sunLight.transform + return sunLight.transform; } initScene() { diff --git a/samples/lights/Sample_PointLight.ts b/samples/lights/Sample_PointLight.ts index 90315d42..343f7d48 100644 --- a/samples/lights/Sample_PointLight.ts +++ b/samples/lights/Sample_PointLight.ts @@ -15,7 +15,7 @@ class Sample_PointLight { GUIHelp.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); // init camera3D let mainCamera = CameraUtil.createCamera3D(null, this.scene); mainCamera.perspective(60, Engine3D.aspect, 1, 2000.0); @@ -23,6 +23,7 @@ class Sample_PointLight { mainCamera.object3D.addComponent(HoverCameraController).setCamera(0, -25, 500); await this.initScene(this.scene); + sky.relativeTransform = this.lightObj.transform; let view = new View3D(); view.scene = this.scene; @@ -32,7 +33,7 @@ class Sample_PointLight { } initScene(scene: Scene3D) { - let lightObj3D = new Object3D(); + let lightObj3D = this.lightObj = new Object3D(); let render = lightObj3D.addComponent(MeshRenderer); render.geometry = new SphereGeometry(5, 30, 30); render.material = new LitMaterial(); diff --git a/samples/lights/Sample_PointLightShadow.ts b/samples/lights/Sample_PointLightShadow.ts index 0201ac68..3baabe03 100644 --- a/samples/lights/Sample_PointLightShadow.ts +++ b/samples/lights/Sample_PointLightShadow.ts @@ -5,7 +5,7 @@ import { GUIUtil } from "@samples/utils/GUIUtil"; // sample of point light shadow class Sample_PointLightShadow { scene: Scene3D; - + lightObj: Object3D; async run() { Engine3D.setting.shadow.enable = true; @@ -16,7 +16,7 @@ class Sample_PointLightShadow { await Engine3D.init({}); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); // init camera3D let mainCamera = CameraUtil.createCamera3D(null, this.scene); @@ -25,6 +25,7 @@ class Sample_PointLightShadow { mainCamera.object3D.addComponent(HoverCameraController).setCamera(0, -45, 500); await this.initScene(this.scene); + sky.relativeTransform = this.lightObj.transform; let view = new View3D(); view.scene = this.scene; @@ -34,7 +35,7 @@ class Sample_PointLightShadow { } async initScene(scene: Scene3D) { - let lightObj3D = new Object3D(); + let lightObj3D = this.lightObj = new Object3D(); lightObj3D.y = 25; //make point light diff --git a/samples/loader/Sample_LoadGLTF.ts b/samples/loader/Sample_LoadGLTF.ts index 569b6512..35f79ed1 100644 --- a/samples/loader/Sample_LoadGLTF.ts +++ b/samples/loader/Sample_LoadGLTF.ts @@ -40,9 +40,10 @@ class Sample_LoadGLTF { } async initScene() { + let atmospheric: AtmosphericComponent; /******** sky *******/ { - let atmospheric = this.scene.addComponent(AtmosphericComponent); + atmospheric = this.scene.addComponent(AtmosphericComponent); atmospheric.sunY = 0.62; atmospheric.sunRadiance = 47; atmospheric.exposure = 1; @@ -62,6 +63,8 @@ class Sample_LoadGLTF { GUIHelp.init(); GUIUtil.renderDirLight(directLight); this.scene.addChild(this.lightObj3D); + + atmospheric.relativeTransform = this.lightObj3D.transform; } { diff --git a/samples/material/Sample_PBR.ts b/samples/material/Sample_PBR.ts index e81b3c04..9391d502 100644 --- a/samples/material/Sample_PBR.ts +++ b/samples/material/Sample_PBR.ts @@ -17,7 +17,7 @@ class Sample_PBR { GUIHelp.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 1, 5000.0); @@ -30,6 +30,7 @@ class Sample_PBR { Engine3D.startRenderView(view); await this.initScene(); + sky.relativeTransform = this.lightObj3D.transform; } async initScene() { diff --git a/samples/material/Sample_PBRMaterial.ts b/samples/material/Sample_PBRMaterial.ts index 084bfd53..dc46703b 100644 --- a/samples/material/Sample_PBRMaterial.ts +++ b/samples/material/Sample_PBRMaterial.ts @@ -40,8 +40,9 @@ class Sample_PBRMaterial { async initScene() { /******** sky *******/ + let sky: AtmosphericComponent; { - let sky = this.scene.addComponent(AtmosphericComponent); + sky = this.scene.addComponent(AtmosphericComponent); sky.enable = false; } /******** light *******/ @@ -56,6 +57,8 @@ class Sample_PBRMaterial { directLight.intensity = 43; GUIUtil.renderDirLight(directLight); this.scene.addChild(this.lightObj3D); + + sky.relativeTransform = this.lightObj3D.transform; } { diff --git a/samples/material/Sample_RenderPassClean.ts b/samples/material/Sample_RenderPassClean.ts index def7ee21..ae9001f0 100644 --- a/samples/material/Sample_RenderPassClean.ts +++ b/samples/material/Sample_RenderPassClean.ts @@ -13,7 +13,7 @@ class Sample_RenderPassClean { Engine3D.setting.shadow.shadowBias = 0.0001; this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -27,6 +27,7 @@ class Sample_RenderPassClean { Engine3D.startRenderView(view); await this.initScene(); + sky.relativeTransform = this.lightObj3D.transform; } async initScene() { diff --git a/samples/material/Sample_UVMove.ts b/samples/material/Sample_UVMove.ts index 6b3ad11e..f607f5b3 100644 --- a/samples/material/Sample_UVMove.ts +++ b/samples/material/Sample_UVMove.ts @@ -6,7 +6,7 @@ import { GUIUtil } from "@samples/utils/GUIUtil"; class Sample_UVMove { scene: Scene3D; - + lightObj: Object3D; async run() { await Engine3D.init(); @@ -24,7 +24,7 @@ class Sample_UVMove { }; this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -38,6 +38,7 @@ class Sample_UVMove { Engine3D.startRenderView(view); await this.initScene(); + sky.relativeTransform = this.lightObj.transform; } async initScene() { @@ -48,10 +49,10 @@ class Sample_UVMove { } /******** light *******/ { - let lightObj = new Object3D(); + let lightObj = this.lightObj = new Object3D(); lightObj.rotationX = 57; lightObj.rotationY = 347; - lightObj.rotationZ = 10; + lightObj.rotationZ = 0; let directLight = lightObj.addComponent(DirectLight); directLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355); diff --git a/samples/material/Sample_UnlitMaterial.ts b/samples/material/Sample_UnlitMaterial.ts index 8b2c98f1..8265b608 100644 --- a/samples/material/Sample_UnlitMaterial.ts +++ b/samples/material/Sample_UnlitMaterial.ts @@ -9,7 +9,7 @@ class Sample_UnlitMaterial { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let mainCamera = CameraUtil.createCamera3DObject(this.scene); @@ -17,6 +17,7 @@ class Sample_UnlitMaterial { mainCamera.object3D.addComponent(HoverCameraController).setCamera(45, -45, 50); await this.initScene(this.scene); + sky.relativeTransform = this.lightObj3D.transform; let view = new View3D(); view.scene = this.scene; @@ -60,7 +61,7 @@ class Sample_UnlitMaterial { { let sphere = new Object3D(); let renderer = sphere.addComponent(MeshRenderer); - renderer.geometry = new SphereGeometry(1,32,32); + renderer.geometry = new SphereGeometry(1, 32, 32); renderer.material = new UnLitMaterial() sphere.scaleX = 5; sphere.scaleY = 5; @@ -73,7 +74,7 @@ class Sample_UnlitMaterial { { let sphere = new Object3D(); let renderer = sphere.addComponent(MeshRenderer); - renderer.geometry = new SphereGeometry(1,32,32); + renderer.geometry = new SphereGeometry(1, 32, 32); renderer.material = new LitMaterial() sphere.scaleX = 5; sphere.scaleY = 5; diff --git a/samples/particle/Sample_CandleFlame.ts b/samples/particle/Sample_CandleFlame.ts index f9984ed3..f1bdc716 100644 --- a/samples/particle/Sample_CandleFlame.ts +++ b/samples/particle/Sample_CandleFlame.ts @@ -7,6 +7,7 @@ import { } from '@orillusion/particle'; export class Sample_CandleFlame { + lightObj: Object3D; async run() { Engine3D.setting.shadow.enable = true; Engine3D.setting.shadow.pointShadowBias = 0.001; @@ -15,7 +16,7 @@ export class Sample_CandleFlame { await Engine3D.init(); let scene = new Scene3D(); - scene.addComponent(AtmosphericComponent); + let sky = scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(scene); camera.perspective(60, webGPUContext.aspect, 0.1, 5000.0); @@ -24,7 +25,7 @@ export class Sample_CandleFlame { // ctrl.maxDistance = 1000; await this.initScene(scene); - + sky.relativeTransform = this.lightObj.transform; let view = new View3D(); view.scene = scene; view.camera = camera; @@ -42,7 +43,7 @@ export class Sample_CandleFlame { let particleSystem = obj.addComponent(ParticleSystem); { - let lightObj = new Object3D(); + let lightObj = this.lightObj = new Object3D(); let pl = lightObj.addComponent(PointLight); pl.range = 56; pl.radius = 1; diff --git a/samples/post/Sample_Bloom.ts b/samples/post/Sample_Bloom.ts index 9e61e4c0..d8f184d1 100644 --- a/samples/post/Sample_Bloom.ts +++ b/samples/post/Sample_Bloom.ts @@ -18,13 +18,16 @@ class Sample_Bloom { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent).sunY = 0.6; + let sky = this.scene.addComponent(AtmosphericComponent); + sky.sunY = 0.6; let mainCamera = CameraUtil.createCamera3DObject(this.scene, 'camera'); mainCamera.perspective(60, webGPUContext.aspect, 1, 5000.0); let ctrl = mainCamera.object3D.addComponent(HoverCameraController); ctrl.setCamera(0, -15, 500); await this.initScene(); + sky.relativeTransform = this.lightObj.transform; + let view = new View3D(); view.scene = this.scene; diff --git a/samples/post/Sample_Fog.ts b/samples/post/Sample_Fog.ts index bcd9ae35..9a666d1e 100644 --- a/samples/post/Sample_Fog.ts +++ b/samples/post/Sample_Fog.ts @@ -22,6 +22,7 @@ class Sample_Fog { let ctrl = mainCamera.object3D.addComponent(HoverCameraController); ctrl.setCamera(0, -10, 400); await this.initScene(); + sky.relativeTransform = this.lightObj.transform; let view = new View3D(); view.scene = this.scene; view.camera = mainCamera; @@ -34,7 +35,7 @@ class Sample_Fog { GUIUtil.renderGlobalFog(fog, true); } - async initScene() { + initScene() { { this.lightObj = new Object3D(); this.lightObj.rotationX = 45; diff --git a/samples/post/Sample_GTAO.ts b/samples/post/Sample_GTAO.ts index 6499c0c6..d206c01a 100644 --- a/samples/post/Sample_GTAO.ts +++ b/samples/post/Sample_GTAO.ts @@ -18,7 +18,8 @@ class Sample_GTAO { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent).sunY = 0.6; + let sky = this.scene.addComponent(AtmosphericComponent); + sky.sunY = 0.6; let mainCamera = CameraUtil.createCamera3DObject(this.scene, 'camera'); mainCamera.perspective(60, webGPUContext.aspect, 1, 5000.0); @@ -26,6 +27,8 @@ class Sample_GTAO { ctrl.setCamera(0, -15, 500); await this.initScene(); + sky.relativeTransform = this.lightObj.transform; + let view = new View3D(); view.scene = this.scene; view.camera = mainCamera; @@ -40,7 +43,7 @@ class Sample_GTAO { async initScene() { { this.lightObj = new Object3D(); - this.lightObj.rotationX = 45; + this.lightObj.rotationX = 20; this.lightObj.rotationY = 110; this.lightObj.rotationZ = 0; let lc = this.lightObj.addComponent(DirectLight); diff --git a/samples/post/Sample_TAA.ts b/samples/post/Sample_TAA.ts index 77aa6930..0293f95f 100644 --- a/samples/post/Sample_TAA.ts +++ b/samples/post/Sample_TAA.ts @@ -19,7 +19,8 @@ class Sample_TAA { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent).sunY = 0.6; + let sky = this.scene.addComponent(AtmosphericComponent); + sky.sunY = 0.6; let mainCamera = CameraUtil.createCamera3DObject(this.scene, 'camera'); mainCamera.perspective(60, webGPUContext.aspect, 1, 5000.0); @@ -27,6 +28,8 @@ class Sample_TAA { ctrl.setCamera(0, -15, 20); await this.initScene(); + sky.relativeTransform = this.lightObj.transform; + let view = new View3D(); view.scene = this.scene; view.camera = mainCamera; diff --git a/samples/render/Sample_BlendMode.ts b/samples/render/Sample_BlendMode.ts index a88a4842..bd436d18 100644 --- a/samples/render/Sample_BlendMode.ts +++ b/samples/render/Sample_BlendMode.ts @@ -12,7 +12,7 @@ class Sample_BlendMode { await Engine3D.init({}); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let mainCamera = CameraUtil.createCamera3DObject(this.scene, 'camera'); mainCamera.perspective(60, Engine3D.aspect, 1, 5000.0); @@ -21,11 +21,13 @@ class Sample_BlendMode { await this.initScene(this.scene); + let view = new View3D(); view.scene = this.scene; view.camera = mainCamera; this.initLight(); + sky.relativeTransform = this.lightObj.transform; // Engine3D.startRenderView(view); } diff --git a/samples/render/Sample_BlendMode2.ts b/samples/render/Sample_BlendMode2.ts index fe640921..5f5998ec 100644 --- a/samples/render/Sample_BlendMode2.ts +++ b/samples/render/Sample_BlendMode2.ts @@ -3,7 +3,7 @@ import { Scene3D, Engine3D, AtmosphericComponent, CameraUtil, HoverCameraControl class Sample_BlendMode2 { scene: Scene3D; - + lightObj: Object3D; async run() { await Engine3D.init(); @@ -21,7 +21,7 @@ class Sample_BlendMode2 { }; this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -35,6 +35,8 @@ class Sample_BlendMode2 { Engine3D.startRenderView(view); await this.initScene(); + + sky.relativeTransform = this.lightObj.transform; } async initScene() { @@ -45,7 +47,7 @@ class Sample_BlendMode2 { } /******** light *******/ { - let lightObj = new Object3D(); + let lightObj = this.lightObj = new Object3D(); lightObj.rotationX = 57; lightObj.rotationY = 347; lightObj.rotationZ = 10; diff --git a/samples/render/Sample_ChangeTexture.ts b/samples/render/Sample_ChangeTexture.ts index bcbde729..d99336cb 100644 --- a/samples/render/Sample_ChangeTexture.ts +++ b/samples/render/Sample_ChangeTexture.ts @@ -1,62 +1,38 @@ -import { Object3D, Scene3D, Engine3D, AtmosphericComponent, HoverCameraController, View3D, DirectLight, KelvinUtil, MeshRenderer, BoxGeometry, LitMaterial, Vector3, Color, BlendMode, CameraUtil } from "@orillusion/core"; +import { Object3D, Scene3D, Engine3D, BoxGeometry, LitMaterial, MeshRenderer, } from "@orillusion/core"; +import { createExampleScene } from "@samples/utils/ExampleScene"; class Sample_ChangeTexture { - lightObj: Object3D; - scene: Scene3D; + scene: Scene3D; async run() { await Engine3D.init(); - this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); - - //camera - let mainCamera = CameraUtil.createCamera3DObject(this.scene, 'camera'); - mainCamera.perspective(60, Engine3D.aspect, 1, 5000.0); - mainCamera.object3D.addComponent(HoverCameraController).setCamera(-125, -10, 10); - + let exampleScene = createExampleScene(); + this.scene = exampleScene.scene; await this.initScene(); + Engine3D.startRenderView(exampleScene.view); - let view = new View3D(); - view.scene = this.scene; - view.camera = mainCamera; - - this.initLight(); - Engine3D.startRenderView(view); } - private initLight(): void { - this.lightObj = new Object3D(); - this.lightObj.x = 0; - this.lightObj.y = 30; - this.lightObj.z = -40; - this.lightObj.rotationX = 46; - this.lightObj.rotationY = 62; - this.lightObj.rotationZ = 360; - let lc = this.lightObj.addComponent(DirectLight); - lc.lightColor = KelvinUtil.color_temperature_to_rgb(5355); - lc.intensity = 20; - this.scene.addChild(this.lightObj); - } async initScene() { //create first box let box1 = new Object3D(); - box1.transform.z = -2 + box1.transform.z = -20; this.scene.addChild(box1); let render1 = box1.addComponent(MeshRenderer); - render1.geometry = new BoxGeometry(2, 2, 2); + render1.geometry = new BoxGeometry(20, 20, 20); let material1 = render1.material = new LitMaterial(); material1.maskMap = Engine3D.res.maskTexture; //create second box let box2 = new Object3D(); - box2.transform.z = 2; + box2.transform.z = 20; this.scene.addChild(box2); let render2 = box2.addComponent(MeshRenderer); - render2.geometry = new BoxGeometry(2, 2, 2); + render2.geometry = new BoxGeometry(20, 20, 20); let material2 = render2.material = new LitMaterial(); material2.maskMap = Engine3D.res.maskTexture; diff --git a/samples/render/Sample_CullMode.ts b/samples/render/Sample_CullMode.ts index f95c11ae..80b389db 100644 --- a/samples/render/Sample_CullMode.ts +++ b/samples/render/Sample_CullMode.ts @@ -7,7 +7,7 @@ class Sample_CullMode { GUIHelp.init(); let scene = new Scene3D(); - scene.addComponent(AtmosphericComponent); + let sky = scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(scene); camera.perspective(60, Engine3D.aspect, 0.01, 10000.0); @@ -31,6 +31,8 @@ class Sample_CullMode { light.intensity = 10; scene.addChild(lightObj); + sky.relativeTransform = light.transform; + let planeObj: Object3D; let texture = new BitmapTexture2D(); await texture.load('https://cdn.orillusion.com/gltfs/cube/material_02.png'); diff --git a/samples/render/Sample_TextureSample.ts b/samples/render/Sample_TextureSample.ts index c09d23e0..4db6a3db 100644 --- a/samples/render/Sample_TextureSample.ts +++ b/samples/render/Sample_TextureSample.ts @@ -11,7 +11,7 @@ class Sample_TextureSample { await Engine3D.init(); this.scene = new Scene3D(); - this.scene.addComponent(AtmosphericComponent); + let sky = this.scene.addComponent(AtmosphericComponent); let camera = CameraUtil.createCamera3DObject(this.scene); camera.perspective(60, Engine3D.aspect, 0.01, 5000.0); @@ -23,6 +23,7 @@ class Sample_TextureSample { Engine3D.startRenderView(view); await this.initScene(); + sky.relativeTransform = this.lightObj3D.transform; } async initScene() { diff --git a/samples/sky/Sample_AtmosphericSky.ts b/samples/sky/Sample_AtmosphericSky.ts index b06f2d42..927abefb 100644 --- a/samples/sky/Sample_AtmosphericSky.ts +++ b/samples/sky/Sample_AtmosphericSky.ts @@ -1,7 +1,7 @@ import { GUIHelp } from "@orillusion/debug/GUIHelp"; import { GUIUtil } from "@samples/utils/GUIUtil"; import { createExampleScene } from "@samples/utils/ExampleScene"; -import { AtmosphericComponent, Engine3D, GPUCullMode, LitMaterial, MeshRenderer, Object3D, Object3DUtil, PlaneGeometry, Scene3D, UnLitMaterial, Vector3 } from "@orillusion/core"; +import { AtmosphericComponent, Engine3D, GPUCullMode, MeshRenderer, Object3D, PlaneGeometry, Scene3D, UnLitMaterial, Vector3 } from "@orillusion/core"; // sample of AtmosphericSky class Sample_AtmosphericSky { @@ -13,9 +13,9 @@ class Sample_AtmosphericSky { // start renderer Engine3D.startRenderView(scene.view); // add atmospheric sky - let component = scene.getComponent(AtmosphericComponent); + let sky = scene.getComponent(AtmosphericComponent); - let texture = component['_atmosphericScatteringSky']; + let texture = sky['_atmosphericScatteringSky']; let ulitMaterial = new UnLitMaterial(); ulitMaterial.baseMap = texture.texture2D; ulitMaterial.cullMode = GPUCullMode.none; @@ -28,7 +28,7 @@ class Sample_AtmosphericSky { // gui GUIHelp.init(); - GUIUtil.renderAtomosphericSky(component); + GUIUtil.renderAtomosphericSky(sky); } } diff --git a/src/components/AtmosphericComponent.ts b/src/components/AtmosphericComponent.ts index 9ea3b2c3..9f274a65 100644 --- a/src/components/AtmosphericComponent.ts +++ b/src/components/AtmosphericComponent.ts @@ -150,12 +150,12 @@ export class AtmosphericComponent extends SkyRenderer { public onUpdate(view?: any) { if (this._relatedTransform) { this._relatedTransform.rotationZ = 0; - if (this._historyData.isSkyChange(this.sunX, this.sunY)) { - this._relatedTransform.rotationY = this.sunX * 360 - 90; - this._relatedTransform.rotationX = (this.sunY - 0.5) * 180; - } else if (this._historyData.isRotateChange(this._relatedTransform.rotationX, this._relatedTransform.rotationY)) { + if (this._historyData.isRotateChange(this._relatedTransform.rotationX, this._relatedTransform.rotationY)) { this.sunX = (this._relatedTransform.rotationY + 90) / 360// this.sunY = this._relatedTransform.rotationX / 180 + 0.5; + } else if (this._historyData.isSkyChange(this.sunX, this.sunY)) { + this._relatedTransform.rotationY = this.sunX * 360 - 90; + this._relatedTransform.rotationX = (this.sunY - 0.5) * 180; } this._historyData.save(this.sunX, this.sunY, this._relatedTransform.rotationX, this._relatedTransform.rotationY); }