import { useContext, useEffect } from "react"; import { Transition } from "@headlessui/react"; import { faArrowRightArrowLeft, faCube, faTrash, } from "@fortawesome/pro-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { AppUiContext } from "../../../../contexts/AppUiContext"; import { EngineContext } from "../../../../contexts/EngineContext"; import { Button, H5, InputVector } from "~/components"; import { XYZ } from "../../datastructures/common"; import { ACTION_TYPES } from "~/reducers/appUiReducer/types"; import { QueueNames } from "../../Queue/QueueNames"; import Queue from "~/pages/PageEnigma/Queue/Queue"; import { toTimelineActions } from "../../Queue/toTimelineActions"; import { QueueKeyframe } from "~/pages/PageEnigma/models"; export const ControlPanelSceneObject = () => { const editorEngine = useContext(EngineContext); const [appUiState, dispatchAppUiState] = useContext(AppUiContext); const position = appUiState.controlPanel.currentSceneObject?.objectVectors?.position; const rotation = appUiState.controlPanel.currentSceneObject?.objectVectors?.rotation; const scale = appUiState.controlPanel.currentSceneObject?.objectVectors?.scale; const currentSceneObject = appUiState.controlPanel.currentSceneObject; useEffect(() => { // TODO this causes a subtle bug because it renders way too many times. const vectors = appUiState.controlPanel.currentSceneObject.objectVectors; editorEngine?.setSelectedObject( vectors.position, vectors.rotation, vectors.scale, ); }, [appUiState.controlPanel.currentSceneObject, editorEngine]); if (!appUiState.controlPanel.currentSceneObject) { return null; } const handlePositionChange = (xyz: XYZ) => { if (!currentSceneObject) { console.log("Missing Scene Object Position"); return; } dispatchAppUiState({ type: ACTION_TYPES.UPDATE_CONTROLPANELS_SCENEOBJECT, payload: { group: currentSceneObject.group, object_uuid: currentSceneObject.object_uuid, object_name: currentSceneObject.object_name, version: currentSceneObject.version, objectVectors: { position: { ...xyz }, rotation: appUiState?.controlPanel.currentSceneObject?.objectVectors ?.rotation ?? { x: 0, y: 0, z: 0 }, scale: appUiState?.controlPanel.currentSceneObject?.objectVectors ?.scale ?? { x: 0, y: 0, z: 0 }, }, }, }); }; const handleRotationChange = (xyz: XYZ) => { if (appUiState) { if (currentSceneObject == null) { console.log("Missing Scene Object Rotation"); return; } dispatchAppUiState({ type: ACTION_TYPES.UPDATE_CONTROLPANELS_SCENEOBJECT, payload: { group: currentSceneObject.group, object_uuid: currentSceneObject.object_uuid, object_name: currentSceneObject.object_name, version: currentSceneObject.version, objectVectors: { position: appUiState.controlPanel.currentSceneObject.objectVectors.position, rotation: { ...xyz }, scale: appUiState.controlPanel.currentSceneObject.objectVectors.scale, }, }, }); } }; const handleScaleChange = (xyz: XYZ) => { if (appUiState) { if (currentSceneObject == null) { console.log("Missing Scene Object Scale"); return; } dispatchAppUiState({ type: ACTION_TYPES.UPDATE_CONTROLPANELS_SCENEOBJECT, payload: { group: currentSceneObject.group, object_uuid: currentSceneObject.object_uuid, object_name: currentSceneObject.object_name, version: currentSceneObject.version, objectVectors: { position: appUiState.controlPanel.currentSceneObject.objectVectors.position, rotation: appUiState.controlPanel.currentSceneObject.objectVectors.rotation, scale: { ...xyz }, }, }, }); } }; const handleOnAddKeyFrame = () => { if (appUiState) { if ( position == null || rotation == null || scale == null || currentSceneObject == null ) { return; } for (const key in editorEngine?.timeline.characters) { const element = editorEngine?.timeline.characters[key]; if (key == currentSceneObject.object_uuid) { currentSceneObject.group = element; break; } } Queue.publish({ queueName: QueueNames.TO_TIMELINE, action: toTimelineActions.ADD_KEYFRAME, data: { group: currentSceneObject.group, object_uuid: currentSceneObject.object_uuid, object_name: currentSceneObject.object_name, version: 1, position: currentSceneObject.objectVectors.position, rotation: currentSceneObject.objectVectors.rotation, scale: currentSceneObject.objectVectors.scale, } as QueueKeyframe, }); } }; const handleDeleteObject = () => { editorEngine?.deleteObject(currentSceneObject.object_uuid); }; return (

{appUiState.controlPanel.currentSceneObject.object_name}

Swap Object

Position
Rotation
Scale
); };