From 7744b32ab02039f5536300b0fe809d47c776f7b3 Mon Sep 17 00:00:00 2001 From: HexaField Date: Thu, 8 Feb 2024 14:57:23 +1100 Subject: [PATCH] update to latest engine --- src/CustomLocationPage.tsx | 38 ++++++++++++++++++-------------------- src/engine.tsx | 13 +++++++++---- src/main.tsx | 4 ++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/CustomLocationPage.tsx b/src/CustomLocationPage.tsx index e038823..fa86dac 100644 --- a/src/CustomLocationPage.tsx +++ b/src/CustomLocationPage.tsx @@ -1,14 +1,8 @@ import React, { useEffect } from 'react' import Debug from '@etherealengine/client-core/src/components/Debug' -import '@etherealengine/spatial/src/renderer/WebGLRendererSystem' import { defineState, getMutableState, getState } from '@etherealengine/hyperflux' - -import '@etherealengine/client/src/themes/base.css' -import '@etherealengine/client/src/themes/components.css' -import '@etherealengine/client/src/themes/utilities.css' -import 'daisyui/dist/full.css' -import 'tailwindcss/tailwind.css' +import '@etherealengine/spatial/src/renderer/WebGLRendererSystem' import { BoxGeometry, Mesh, MeshBasicMaterial } from 'three' @@ -16,17 +10,22 @@ import { Entity, createEntity, defineSystem, getComponent, setComponent } from ' import { ECSState } from '@etherealengine/ecs/src/ECSState' import { Engine } from '@etherealengine/ecs/src/Engine' import { CameraComponent } from '@etherealengine/spatial/src/camera/components/CameraComponent' +import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent' import { V_010 } from '@etherealengine/spatial/src/common/constants/MathConstants' -import { TransformComponent } from '@etherealengine/spatial/src/transform/components/TransformComponent' -import { TransformSystem } from '@etherealengine/spatial/src/transform/systems/TransformSystem' import { addObjectToGroup } from '@etherealengine/spatial/src/renderer/components/GroupComponent' -import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent' +import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent' +import { TransformComponent } from '@etherealengine/spatial/src/transform/components/TransformComponent' +import { TransformSystem, computeTransformMatrix } from '@etherealengine/spatial/src/transform/systems/TransformSystem' const SceneState = defineState({ name: 'ee.minimalist.SceneState', - initial: () => ({ - entity: createEntity() - }) + initial: () => { + const entity = createEntity() + setComponent(entity, TransformComponent) + return { + entity + } + } }) const UpdateSystem = defineSystem({ @@ -35,12 +34,8 @@ const UpdateSystem = defineSystem({ execute: () => { const entity = getState(SceneState).entity const elapsedSeconds = getState(ECSState).elapsedSeconds - const transformComponent = getComponent(entity, TransformComponent) - - if (transformComponent) { - transformComponent.rotation.setFromAxisAngle(V_010, elapsedSeconds) - } + transformComponent.rotation.setFromAxisAngle(V_010, elapsedSeconds) }, reactor: function () { const state = getMutableState(SceneState) @@ -51,12 +46,15 @@ const UpdateSystem = defineSystem({ const mesh = new Mesh(new BoxGeometry(1, 1, 1), new MeshBasicMaterial({ color: 0x00ff00 })) addObjectToGroup(entity, mesh) setComponent(entity, NameComponent, 'Box') + setComponent(entity, VisibleComponent) // Make the camera look at the box - const camera = getComponent(Engine.instance.cameraEntity, CameraComponent) - camera.lookAt(0, 0, 0) const cameraTransform = getComponent(Engine.instance.cameraEntity, TransformComponent) + const camera = getComponent(Engine.instance.cameraEntity, CameraComponent) + cameraTransform.position.set(5, 2, 0) cameraTransform.rotation.copy(camera.quaternion) + computeTransformMatrix(Engine.instance.cameraEntity) + camera.lookAt(0, 0, 0) }, []) return null diff --git a/src/engine.tsx b/src/engine.tsx index 211f37c..4f5dd08 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -26,12 +26,13 @@ Ethereal Engine. All Rights Reserved. import React, { Suspense } from 'react' /** @todo due to circular dependences, engine must be imported prior to other imports */ -import '@etherealengine/engine/src/ecs/classes/Engine' import { LoadingCircle } from '@etherealengine/client-core/src/components/LoadingCircle' -import { EngineState } from '@etherealengine/spatial/src/EngineState' import { initializeBrowser } from '@etherealengine/engine/src/initializeBrowser' -import { createEngine } from '@etherealengine/spatial/src/initializeEngine' import { getMutableState } from '@etherealengine/hyperflux' +import { EngineState } from '@etherealengine/spatial/src/EngineState' +import { createEngine } from '@etherealengine/spatial/src/initializeEngine' + +import { ThemeProvider } from '@etherealengine/client-core/src/common/services/ThemeService' createEngine() getMutableState(EngineState).publicPath.set( @@ -41,5 +42,9 @@ getMutableState(EngineState).publicPath.set( initializeBrowser() export default function ({ children }) { - return }>{children} + return ( + + }>{children} + + ) } diff --git a/src/main.tsx b/src/main.tsx index 330cc8e..d1b4016 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -31,6 +31,10 @@ import { createRoot } from 'react-dom/client' import ErrorBoundary from '@etherealengine/client-core/src/common/components/ErrorBoundary' +import '@etherealengine/client/src/themes/base.css' +import '@etherealengine/client/src/themes/components.css' +import '@etherealengine/client/src/themes/utilities.css' + const Engine = lazy(() => import('./engine')) const CustomLocationPage = lazy(() => import('./CustomLocationPage'))