Use useLayoutEffect in ViewportCanvas and add cameraSyncRequestId prop
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import type { LoadedModelAsset } from "../assets/gltf-model-import";
|
import type { LoadedModelAsset } from "../assets/gltf-model-import";
|
||||||
import type { LoadedImageAsset } from "../assets/image-assets";
|
import type { LoadedImageAsset } from "../assets/image-assets";
|
||||||
@@ -54,6 +54,7 @@ interface ViewportCanvasProps {
|
|||||||
toolPreview: ViewportToolPreview;
|
toolPreview: ViewportToolPreview;
|
||||||
transformSession: TransformSessionState;
|
transformSession: TransformSessionState;
|
||||||
cameraState: ViewportPanelCameraState;
|
cameraState: ViewportPanelCameraState;
|
||||||
|
cameraSyncRequestId: number;
|
||||||
viewMode: ViewportViewMode;
|
viewMode: ViewportViewMode;
|
||||||
displayMode: ViewportDisplayMode;
|
displayMode: ViewportDisplayMode;
|
||||||
layoutMode: ViewportLayoutMode;
|
layoutMode: ViewportLayoutMode;
|
||||||
@@ -85,6 +86,7 @@ export function ViewportCanvas({
|
|||||||
toolPreview,
|
toolPreview,
|
||||||
transformSession,
|
transformSession,
|
||||||
cameraState,
|
cameraState,
|
||||||
|
cameraSyncRequestId,
|
||||||
viewMode,
|
viewMode,
|
||||||
displayMode,
|
displayMode,
|
||||||
layoutMode,
|
layoutMode,
|
||||||
@@ -136,19 +138,19 @@ export function ViewportCanvas({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setRenderEnabled(shouldRenderPanel);
|
hostRef.current?.setRenderEnabled(shouldRenderPanel);
|
||||||
}, [shouldRenderPanel]);
|
}, [shouldRenderPanel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setPanelId(panelId);
|
hostRef.current?.setPanelId(panelId);
|
||||||
}, [panelId]);
|
}, [panelId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.updateWorld(world);
|
hostRef.current?.updateWorld(world);
|
||||||
}, [world]);
|
}, [world]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.updateAssets(
|
hostRef.current?.updateAssets(
|
||||||
projectAssets,
|
projectAssets,
|
||||||
loadedModelAssets,
|
loadedModelAssets,
|
||||||
@@ -156,36 +158,36 @@ export function ViewportCanvas({
|
|||||||
);
|
);
|
||||||
}, [projectAssets, loadedModelAssets, loadedImageAssets]);
|
}, [projectAssets, loadedModelAssets, loadedImageAssets]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setWhiteboxSnapSettings(
|
hostRef.current?.setWhiteboxSnapSettings(
|
||||||
whiteboxSnapEnabled,
|
whiteboxSnapEnabled,
|
||||||
whiteboxSnapStep
|
whiteboxSnapStep
|
||||||
);
|
);
|
||||||
}, [whiteboxSnapEnabled, whiteboxSnapStep]);
|
}, [whiteboxSnapEnabled, whiteboxSnapStep]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setGridVisible(viewportGridVisible);
|
hostRef.current?.setGridVisible(viewportGridVisible);
|
||||||
}, [viewportGridVisible]);
|
}, [viewportGridVisible]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setWhiteboxSelectionMode(whiteboxSelectionMode);
|
hostRef.current?.setWhiteboxSelectionMode(whiteboxSelectionMode);
|
||||||
}, [whiteboxSelectionMode]);
|
}, [whiteboxSelectionMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.updateDocument(sceneDocument, selection);
|
hostRef.current?.updateDocument(sceneDocument, selection);
|
||||||
}, [sceneDocument, selection]);
|
}, [sceneDocument, selection]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setViewMode(viewMode);
|
hostRef.current?.setViewMode(viewMode);
|
||||||
}, [viewMode]);
|
}, [viewMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setDisplayMode(displayMode);
|
hostRef.current?.setDisplayMode(displayMode);
|
||||||
}, [displayMode]);
|
}, [displayMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setCameraState(cameraState);
|
hostRef.current?.setCameraState(cameraState);
|
||||||
}, [cameraState, sceneDocument, transformSession.kind]);
|
}, [cameraState, cameraSyncRequestId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
hostRef.current?.setBrushSelectionChangeHandler(onSelectionChange);
|
hostRef.current?.setBrushSelectionChangeHandler(onSelectionChange);
|
||||||
@@ -230,11 +232,11 @@ export function ViewportCanvas({
|
|||||||
hostRef.current?.setTransformCancelHandler(onTransformCancel);
|
hostRef.current?.setTransformCancelHandler(onTransformCancel);
|
||||||
}, [onTransformCancel]);
|
}, [onTransformCancel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setToolMode(toolMode);
|
hostRef.current?.setToolMode(toolMode);
|
||||||
}, [toolMode]);
|
}, [toolMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setCreationPreview(
|
hostRef.current?.setCreationPreview(
|
||||||
toolMode === "create" && toolPreview.kind === "create"
|
toolMode === "create" && toolPreview.kind === "create"
|
||||||
? toolPreview
|
? toolPreview
|
||||||
@@ -242,7 +244,7 @@ export function ViewportCanvas({
|
|||||||
);
|
);
|
||||||
}, [toolMode, toolPreview]);
|
}, [toolMode, toolPreview]);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
hostRef.current?.setTransformSession(transformSession);
|
hostRef.current?.setTransformSession(transformSession);
|
||||||
}, [transformSession]);
|
}, [transformSession]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user