Skip to content

Commit

Permalink
fix first load default camera broken
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Jan 19, 2025
1 parent 9f26c80 commit 046fde4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/components/three-world/ModelHelper/ModelContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, use } from 'react';
import { createContext, useContext } from 'react';
import { SkinnedMesh } from 'three';

export const ModelContext = createContext<SkinnedMesh>(null);
export const useModel = () => use(ModelContext);
export const useModel = () => useContext(ModelContext);
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import usePresetStore from "@/app/stores/usePresetStore";
import { useThree } from "@react-three/fiber";
import { useCallback, useMemo } from "react";
import { useCallback, useEffect, useMemo } from "react";
import { AnimationMixer } from "three";
import useVMD from "../../../animation/useVMD";
import WithSuspense from "@/app/components/suspense";
import usePresetReady from "@/app/stores/usePresetReady";
import WithReady from "@/app/stores/WithReady";


function MotionFileMode() {
const camera = useThree(state => state.camera)
const cameraMixer = useMemo(() => new AnimationMixer(camera), [camera])
usePresetReady()
const cameraFile = usePresetStore(state => state.cameraFile)
const setTimeCb = useCallback((setTime: () => void) => {
setTime();
Expand All @@ -23,4 +22,4 @@ function MotionFileMode() {
return <></>;
}

export default WithSuspense(MotionFileMode);
export default WithReady(MotionFileMode);
7 changes: 2 additions & 5 deletions app/components/three-world/character/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import usePresetStore from "@/app/stores/usePresetStore";
import { buildGuiItem, buildLoadFileFn, buildLoadModelFn } from "@/app/utils/gui";
import { button, useControls } from "leva";
import * as THREE from 'three';
import WithSuspense from "../../suspense";
import usePresetReady from "@/app/stores/usePresetReady";
import PmxModel from "../pmx-model";
import { ThreeEvent } from "@react-three/fiber";
import WithReady from "@/app/stores/WithReady";

function Model() {
usePresetReady()

const characterName = usePresetStore(state => state.character)
const motionName = usePresetStore(state => state.motion)
const pmxFiles = usePresetStore(state => state.pmxFiles)
Expand Down Expand Up @@ -83,4 +80,4 @@ function Model() {
);
}

export default WithSuspense(Model);
export default WithReady(Model);
7 changes: 2 additions & 5 deletions app/components/three-world/stage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import useGlobalStore from "@/app/stores/useGlobalStore";
import usePresetStore from "@/app/stores/usePresetStore";
import { buildGuiItem, buildLoadModelFn } from "@/app/utils/gui";
import { button, useControls } from "leva";
import usePresetReady from "@/app/stores/usePresetReady";
import WithSuspense from "../../suspense";
import PmxModel from "../pmx-model";
import * as THREE from 'three';
import WithReady from "@/app/stores/WithReady";

function Stage() {
usePresetReady()
const stageName = usePresetStore(state => state.stage)
const pmxFiles = usePresetStore(state => state.pmxFiles)
const enablePBR = usePresetStore(state => state["enable PBR"])
const groundShadow = usePresetStore(state => state["ground shadow"])

const url = pmxFiles.stage[stageName]
const filename = stageName

const [_, set] = useControls('Stage', () => ({
name: {
Expand Down Expand Up @@ -51,4 +48,4 @@ function Stage() {
);
}

export default WithSuspense(Stage);
export default WithReady(Stage);
15 changes: 15 additions & 0 deletions app/stores/WithReady.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import useGlobalStore, { GlobalState } from "@/app/stores/useGlobalStore";
import { useThree } from "@react-three/fiber";

function WithReady<T>(Component: React.ComponentType<T>) {
return function WrappedComponent(props: T) {
const presetReady = useGlobalStore(state => state.presetReady)
const camera = useThree(state => state.camera)
if (!presetReady || !camera.getObjectByName("target")) return <></>
return (
<Component {...props}></Component>
)
};
}

export default WithReady
9 changes: 0 additions & 9 deletions app/stores/usePresetReady.ts

This file was deleted.

0 comments on commit 046fde4

Please sign in to comment.