Merge pull request #8 from storytold/feature/editor-context

Feature/editor context
This commit is contained in:
wil authored and GitHub committed 2024-03-25 14:25:56 -04:00
commit 7f22bf4d31
6 files changed
+153 -92

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
import { createContext } from "react";
import Editor from "~/pages/PageEnigma/js/editor";
export const EngineContext = createContext<Editor|null>(null);
+36
View File
@@ -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<Editor | null>(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(
<EngineContext.Provider value={editorRef.current}>
{children}
</EngineContext.Provider>
);
}
+44 -84
View File
@@ -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<HTMLCanvasElement | null>(null);
const editorRef = useRef<Editor | null>(null);
const [timelineHeight, setTimelineHeight] = useState(0);
const timelineRef = useRef<HTMLDivElement | null>(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 (
<div>
<TopBarHelmet>
<Button icon={faWandSparkles}>Generate Movie</Button>
<Button icon={faSparkles}>Generate Movie</Button>
</TopBarHelmet>
<EngineProvider>
<div style={{ height: "calc(100vh - 68px)" }}>
{/* Engine section/side panel */}
<div
className="flex"
style={{ height: `calc(100% - ${timelineHeight}px)` }}
>
<div className="relative w-full overflow-hidden bg-gray-400">
<canvas
ref={canvasRef}
id="video-scene"
width="1280px"
height="720px"
/>
<div style={{ height: "calc(100vh - 68px)" }}>
{/* Engine section/side panel */}
<div
className="flex"
style={{ height: `calc(100% - ${timelineHeight}px)` }}
>
<div className="relative w-full overflow-hidden bg-gray-400">
<canvas
ref={canvasRef}
id="video-scene"
width="1280px"
height="720px"
/>
{/* Top controls */}
<div className="absolute left-0 top-0 w-full">
<div className="grid grid-cols-3 gap-4">
<div className="flex gap-2 pl-3 pt-3">
<Button variant="secondary" onClick={handleButtonPlayBack}>
Toggle Camera View
</Button>
<Button variant="secondary" onClick={handleButtonSave}>
Save Scene
</Button>
<ButtonDialogue
buttonProps={{
variant: "secondary",
label: "Help",
}}
title="Help"
>
<p>Do you need help?</p>
<p>Ask Michael about this project</p>
<p>Ask Miles about ThreeJS</p>
<p>Ask Wil about React</p>
</ButtonDialogue>
{/* Top controls */}
<div className="absolute left-0 top-0 w-full">
<div className="grid grid-cols-3 gap-4">
<ControlsTopButtons />
<Controls3D />
</div>
</div>
<Controls3D />
{/* Bottom controls */}
<div className="absolute bottom-0 left-0 w-full">
<ControlsVideo />
</div>
</div>
{/* Bottom controls */}
<div className="absolute bottom-0 left-0 w-full">
<ControlsVideo />
</div>
{/* Side panel */}
<SidePanel>
<SidePanelTabs />
</SidePanel>
</div>
{/* Side panel */}
<SidePanel>
<SidePanelTabs />
</SidePanel>
{/* Timeline */}
<div className="min-h-[220px]" ref={timelineRef}>
<TrackProvider>
<Timeline
// editorCurrent={editorRef.current}
// time={20}
// length={12}
/>
</TrackProvider>
</div>
</div>
{/* Timeline */}
<div className="min-h-[260px]" ref={timelineRef}>
<TrackProvider>
<Timeline editorCurrent={editorRef.current} />
</TrackProvider>
</div>
</div>
</EngineProvider>
</div>
);
};
@@ -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(
<div className="flex gap-2 pl-3 pt-3">
<Button variant="secondary" onClick={handleButtonPlayBack}>
Toggle Camera View
</Button>
<Button variant="secondary" onClick={handleButtonSave}>
Save Scene
</Button>
<ButtonDialogue
buttonProps={{
variant: "secondary",
label: "Help",
}}
title="Help"
>
<p>Do you need help?</p>
<p>Ask Michael about this project</p>
<p>Ask Miles about ThreeJS</p>
<p>Ask Wil about React</p>
</ButtonDialogue>
</div>
);
};
@@ -0,0 +1,2 @@
export { ControlsTopButtons } from './ControlsTopButtons';
@@ -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 = () => {};