diff --git a/app/contexts/EngineContext.tsx b/app/contexts/EngineContext.tsx new file mode 100644 index 0000000000..9da0df1808 --- /dev/null +++ b/app/contexts/EngineContext.tsx @@ -0,0 +1,4 @@ +import { createContext } from "react"; +import Editor from "~/pages/PageEnigma/js/editor"; + +export const EngineContext = createContext(null); \ No newline at end of file diff --git a/app/contexts/EngineProvider.tsx b/app/contexts/EngineProvider.tsx new file mode 100644 index 0000000000..7c708816c4 --- /dev/null +++ b/app/contexts/EngineProvider.tsx @@ -0,0 +1,36 @@ +import { + ReactNode, + useEffect, + useRef, +} from "react"; +import { EngineContext } from "./EngineContext"; +import Editor from "~/pages/PageEnigma/js/editor"; + + +interface Props{ + children:ReactNode; +} + +export const EngineProvider = ({ children }: Props)=>{ + const editorRef = useRef(null); + + + useEffect(() => { + //componentDidMount + if (editorRef.current !== null ) { + console.warn('Editor Engine already exist'); + }else if (document.getElementById("video-scene") === null){ + console.error('Editor Engine need a target cavas with the id "video-scene"'); + }else{ + editorRef.current = new Editor(); + editorRef.current.initialize(); + } + }, []); + + return( + + {children} + + ); +} + diff --git a/app/pages/PageEnigma/PageEnigma.tsx b/app/pages/PageEnigma/PageEnigma.tsx index af96c8ef96..acf2a476aa 100644 --- a/app/pages/PageEnigma/PageEnigma.tsx +++ b/app/pages/PageEnigma/PageEnigma.tsx @@ -1,53 +1,28 @@ import { useCallback, useEffect, useRef, useState } from "react"; -import { faWandSparkles } from "@fortawesome/pro-solid-svg-icons"; +import { faSparkles } from "@fortawesome/pro-solid-svg-icons"; import { Button, ButtonLink } from "~/components"; -import { ButtonDialogue } from "~/modules/ButtonDialogue"; +// import { ButtonDialogue } from "~/modules/ButtonDialogue"; import { TopBarHelmet } from "~/modules/TopBarHelmet/TopBarHelmet"; import { SidePanel } from "~/modules/SidePanel"; - import { Controls3D } from "./comps/Controls3D"; +import { ControlsTopButtons } from "./comps/ControlsTopButtons"; import { ControlsVideo } from "./comps/ControlsVideo"; import { Timeline } from "./comps/Timeline"; import { SidePanelTabs } from "./comps/SidePanelTabs"; -import Editor from "./js/editor"; - import { TrackProvider } from "~/contexts/TrackContext/TrackProvider"; +import { EngineProvider } from "~/contexts/EngineProvider"; export const PageEnigma = () => { - // const { setTopBarInner } = useContext(TopBarInnerContext) || {}; - const canvasRef = useRef(null); - const editorRef = useRef(null); + const [timelineHeight, setTimelineHeight] = useState(0); const timelineRef = useRef(null); - const editorCallback = useCallback(() => { - // handle editorCallback here - }, []); - useEffect(() => { - //componentDidMount - if (editorRef.current == null) { - editorRef.current = new Editor(); - editorRef.current.initialize(); - } - }, []); - - const handleButtonSave = () => { - editorRef.current?.save(); - }; - - const handleButtonCameraView = () => { - editorRef.current?.change_camera_view(); - }; - - const handleButtonPlayBack = () => { - editorRef.current?.start_playback(); - }; const updateTimelineHeight = useCallback(() => { if (timelineRef.current) { @@ -73,70 +48,55 @@ export const PageEnigma = () => { return (
- + + +
+ {/* Engine section/side panel */} +
+
+ -
- {/* Engine section/side panel */} -
-
- - - {/* Top controls */} -
-
-
- - - -

Do you need help?

-

Ask Michael about this project

-

Ask Miles about ThreeJS

-

Ask Wil about React

-
+ {/* Top controls */} +
+
+ +
+
- + {/* Bottom controls */} +
+
- {/* Bottom controls */} -
- -
+ {/* Side panel */} + + +
- {/* Side panel */} - - - + {/* Timeline */} +
+ + + +
- - {/* Timeline */} -
- - - -
-
+
); }; diff --git a/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx new file mode 100644 index 0000000000..f42211022b --- /dev/null +++ b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx @@ -0,0 +1,43 @@ +import { useContext } from "react"; +import { Button } from "~/components"; +import { ButtonDialogue } from "~/modules/ButtonDialogue"; +import { EngineContext } from "~/contexts/EngineContext"; + + +export const ControlsTopButtons = () => { + const editorEngine = useContext(EngineContext); + + const handleButtonSave = () => { + editorEngine?.save(); + }; + + const handleButtonCameraView = () => { + editorEngine?.change_camera_view(); + }; + + const handleButtonPlayBack = () => { + editorEngine?.start_playback(); + }; + return( +
+ + + +

Do you need help?

+

Ask Michael about this project

+

Ask Miles about ThreeJS

+

Ask Wil about React

+
+
+ ); +}; \ No newline at end of file diff --git a/app/pages/PageEnigma/comps/ControlsTopButtons/index.tsx b/app/pages/PageEnigma/comps/ControlsTopButtons/index.tsx new file mode 100644 index 0000000000..6e31c86712 --- /dev/null +++ b/app/pages/PageEnigma/comps/ControlsTopButtons/index.tsx @@ -0,0 +1,2 @@ +export { ControlsTopButtons } from './ControlsTopButtons'; + diff --git a/app/pages/PageEnigma/comps/Timeline/Timeline.tsx b/app/pages/PageEnigma/comps/Timeline/Timeline.tsx index c64bf43010..e5aa34f3f9 100644 --- a/app/pages/PageEnigma/comps/Timeline/Timeline.tsx +++ b/app/pages/PageEnigma/comps/Timeline/Timeline.tsx @@ -1,19 +1,35 @@ -import { LowerPanel } from "~/modules/LowerPanel"; -import Editor from "../../js/editor"; -import { Character } from "./Character"; -import { Fragment, useContext } from "react"; -import { TrackContext } from "~/contexts/TrackContext/TrackContext"; +import { + Fragment, + // useCallback, + useContext +} from "react"; + import { Button } from "~/components"; + +// import Editor from "../../js/editor"; +import { EngineContext } from "~/contexts/EngineContext"; +import { TrackContext } from "~/contexts/TrackContext/TrackContext"; + +import { LowerPanel } from "~/modules/LowerPanel"; +import { Character } from "./Character"; + + + import { Camera } from "./Camera"; import { Audio } from "./Audio"; import { Objects } from "./Objects"; import { useMouseEventsAnimation } from "./utils/useMouseEventsAnimation"; export const Timeline = ({ - editorCurrent, + // editorCurrent, + // time, }: { - editorCurrent: Editor | null; + // editorCurrent: Editor | null; + // time: number; }) => { + const editorEngine = useContext(EngineContext); + // editorEngine replaced the engineRef.current passed as a prop + // const { characters, updateCharacters } = useContext(TrackContext); const { characters, objects, scale, length } = useContext(TrackContext); const { onPointerDown, time } = useMouseEventsAnimation(); @@ -21,7 +37,7 @@ export const Timeline = ({ document.getElementById("load-upload")?.click(); }; const handleButtonRender = () => { - editorCurrent?.togglePlayback(); + editorEngine?.togglePlayback(); }; const handleButtonPlay = () => {};