Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
update to latest engine
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Feb 8, 2024
1 parent 7c444c5 commit 7744b32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
38 changes: 18 additions & 20 deletions src/CustomLocationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
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'

import { Entity, createEntity, defineSystem, getComponent, setComponent } from '@etherealengine/ecs'
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({
Expand All @@ -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)
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,5 +42,9 @@ getMutableState(EngineState).publicPath.set(
initializeBrowser()

export default function ({ children }) {
return <Suspense fallback={<LoadingCircle message={'Loading...'} />}>{children}</Suspense>
return (
<ThemeProvider>
<Suspense fallback={<LoadingCircle message={'Loading...'} />}>{children}</Suspense>
</ThemeProvider>
)
}
4 changes: 4 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down

0 comments on commit 7744b32

Please sign in to comment.