From 797dfac7415a233bdae835c4e6e4865a6aae48bc Mon Sep 17 00:00:00 2001 From: HexaField Date: Sun, 4 Aug 2024 14:35:41 +1000 Subject: [PATCH] fix lighting --- src/examples/GLTFs.tsx | 51 ++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/examples/GLTFs.tsx b/src/examples/GLTFs.tsx index be9ac87..9dd4cef 100644 --- a/src/examples/GLTFs.tsx +++ b/src/examples/GLTFs.tsx @@ -6,7 +6,7 @@ import { getMutableState, getState } from '@etherealengine/hyperflux' import { Engine, EntityUUID, UUIDComponent, createEntity, removeEntity } from '@etherealengine/ecs' import { GLTFAssetState } from '@etherealengine/engine/src/gltf/GLTFState' -import { DirectionalLightComponent, TransformComponent } from '@etherealengine/spatial' +import { AmbientLightComponent, DirectionalLightComponent, TransformComponent } from '@etherealengine/spatial' import { EngineState } from '@etherealengine/spatial/src/EngineState' import { CameraComponent } from '@etherealengine/spatial/src/camera/components/CameraComponent' import { CameraOrbitComponent } from '@etherealengine/spatial/src/camera/components/CameraOrbitComponent' @@ -29,27 +29,27 @@ export const gltfRoutes = [ { name: 'Basic', description: 'Basic Duck', - entry: () => + entry: () => }, { name: 'Binary', description: 'Binary Duck', - entry: () => + entry: () => }, { name: 'Draco', description: 'Draco Duck', - entry: () => + entry: () => }, { name: 'Embedded', description: 'Embedded Duck', - entry: () => + entry: () => }, { name: 'Quantized', description: 'Quantized Duck', - entry: () => + entry: () => }, { name: 'KHR_materials_unlit', @@ -59,52 +59,52 @@ export const gltfRoutes = [ { name: 'KHR_materials_emissive_strength', description: 'Khronos Emissive Strength Material Extension', - entry: () => + entry: () => }, { name: 'KHR_materials_clearcoat', description: 'Khronos Clearcoat Material Extension', - entry: () => + entry: () => }, { name: 'KHR_materials_iridescence', description: 'Khronos Iridescence Material Extension', - entry: () => + entry: () => }, { name: 'KHR_materials_sheen', description: 'Khronos Sheen Material Extension', - entry: () => + entry: () => }, { name: 'KHR_materials_transmission', description: 'Khronos Transmission Material Extension', - entry: () => + entry: () => }, { name: 'KHR_materials_volume', description: 'Khronos Volume Material Extension', - entry: () => + entry: () => }, // { // name: 'KHR_materials_ior', // description: 'Khronos Index of Refraction Material Extension', - // entry: () => + // entry: () => // }, { name: 'KHR_materials_specular', description: 'Khronos Specular Material Extension', - entry: () => + entry: () => }, // { // name: 'EXT_materials_bump', // description: 'Khronos Bump Material Extension', - // entry: () => + // entry: () => // }, { name: 'KHR_materials_anisotropy', description: 'Khronos Anisotropy Material Extension', - entry: () => + entry: () => }, { name: 'KHR_lights_punctual', @@ -113,7 +113,7 @@ export const gltfRoutes = [ } ] as RouteData[] -export default function GLTFViewer(props: { src: string }) { +export default function GLTFViewer(props: { src: string; light?: boolean }) { useEffect(() => { const bgColor = document.body.style.backgroundColor document.body.style.backgroundColor = 'gray' @@ -133,5 +133,22 @@ export default function GLTFViewer(props: { src: string }) { return GLTFAssetState.loadScene(props.src, props.src) }, [props.src]) + useEffect(() => { + if (!props.light) return + + const entity = createEntity() + setComponent(entity, UUIDComponent, 'directional light' as EntityUUID) + setComponent(entity, NameComponent, 'Directional Light') + setComponent(entity, TransformComponent, { rotation: new Quaternion().setFromEuler(new Euler(2, 5, 3)) }) + setComponent(entity, EntityTreeComponent, { parentEntity: getState(EngineState).originEntity }) + setComponent(entity, VisibleComponent, true) + setComponent(entity, DirectionalLightComponent, { color: new Color('white'), intensity: 0.5 }) + setComponent(entity, AmbientLightComponent, { color: new Color('white'), intensity: 0.5 }) + + return () => { + removeEntity(entity) + } + }, [props.light]) + return null }