This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize non 3d webpages from rendering canvas (#10421)
* initial work to separate engine canvas as requirement * studio works * fixes * studio fixes * fix cache busting for admin panel * license * fix preview panels, various bug fixes * fix checks and tests * visual script, particles * fix * add dispose to mock renderer * skip visual script tests * console log * add note * fix error with renderer system test, don't start time for tests * format * fix regressions * fix destroying spatial entities * fix zindex for viewport toolbar * client input system was still running if no viewer was available * revert --------- Co-authored-by: Daniel Belmes <[email protected]>
- Loading branch information
1 parent
06a06b9
commit db09aee
Showing
68 changed files
with
680 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
CPAL-1.0 License | ||
The contents of this file are subject to the Common Public Attribution License | ||
Version 1.0. (the "License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE. | ||
The License is based on the Mozilla Public License Version 1.1, but Sections 14 | ||
and 15 have been added to cover use of software over a computer network and | ||
provide for limited attribution for the Original Developer. In addition, | ||
Exhibit A has been modified to be consistent with Exhibit B. | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the | ||
specific language governing rights and limitations under the License. | ||
The Original Code is Ethereal Engine. | ||
The Original Developer is the Initial Developer. The Initial Developer of the | ||
Original Code is the Ethereal Engine team. | ||
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023 | ||
Ethereal Engine. All Rights Reserved. | ||
*/ | ||
|
||
import { getComponent } from '@etherealengine/ecs' | ||
import { getState, useHookstate } from '@etherealengine/hyperflux' | ||
import { EngineState } from '@etherealengine/spatial/src/EngineState' | ||
import { destroySpatialEngine, initializeSpatialEngine } from '@etherealengine/spatial/src/initializeEngine' | ||
import { RendererComponent } from '@etherealengine/spatial/src/renderer/WebGLRendererSystem' | ||
import { useEffect } from 'react' | ||
|
||
export const useEngineCanvas = (ref: React.RefObject<HTMLElement>) => { | ||
const lastRef = useHookstate(ref.current) | ||
|
||
useEffect(() => { | ||
if (ref.current !== lastRef.value) { | ||
lastRef.set(ref.current) | ||
} | ||
}, [ref.current]) | ||
|
||
useEffect(() => { | ||
if (!lastRef.value) return | ||
|
||
const parent = lastRef.value as HTMLElement | ||
|
||
const canvas = document.getElementById('engine-renderer-canvas') as HTMLCanvasElement | ||
const originalParent = canvas.parentElement | ||
initializeSpatialEngine(canvas) | ||
parent.appendChild(canvas) | ||
|
||
const observer = new ResizeObserver(() => { | ||
getComponent(getState(EngineState).viewerEntity, RendererComponent).needsResize = true | ||
}) | ||
|
||
observer.observe(parent) | ||
|
||
return () => { | ||
destroySpatialEngine() | ||
observer.disconnect() | ||
parent.removeChild(canvas) | ||
originalParent?.appendChild(canvas) | ||
} | ||
}, [lastRef.value]) | ||
} | ||
|
||
export const useRemoveEngineCanvas = () => { | ||
useEffect(() => { | ||
const canvas = document.getElementById('engine-renderer-canvas')! | ||
const parent = canvas.parentElement | ||
parent?.removeChild(canvas) | ||
|
||
return () => { | ||
parent?.appendChild(canvas) | ||
} | ||
}, []) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.