Skip to content

Commit

Permalink
fix first load
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Jan 18, 2025
1 parent 6bac47e commit 36a33e4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
"url": "http://localhost:3000",
"runtimeArgs": ["--incognito"]
},
{
"name": "Next.js: debug full stack",
Expand Down
2 changes: 1 addition & 1 deletion app/components/three-world/ModelController/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const keyMap = {

function ModelController({ type }: { type: keyof typeof keyMap }) {

const modelPromise = useGlobalStore.getState()[keyMap[type]]
const modelPromise = useGlobalStore(state => state[keyMap[type]])
const props = { type, modelPromise }

return (
Expand Down
17 changes: 12 additions & 5 deletions app/components/three-world/character/Helper.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import WithSuspense from "../../suspense";
import useAnimation from "./useAnimation";
import Model from "./Model";
import usePose from "./usePose";
import usePhysics from "./usePhysics";
import useGlobalStore from "@/app/stores/useGlobalStore";
import { SkinnedMesh } from "three";

const BaseHelper = WithSuspense(({ characterPromise, stagePromise }: { characterPromise: Promise<SkinnedMesh>, stagePromise: Promise<SkinnedMesh> }) => {
useAnimation(characterPromise)
usePhysics(characterPromise)
usePose(characterPromise, stagePromise)
return <></>
})

function Helper() {
usePhysics()
useAnimation()
usePose()
return <></>;
const characterPromise = useGlobalStore(state => state.characterPromise)
const stagePromise = useGlobalStore(state => state.stagePromise)
return <BaseHelper characterPromise={characterPromise} stagePromise={stagePromise}></BaseHelper>;
}

export default WithSuspense(Helper);
7 changes: 4 additions & 3 deletions app/components/three-world/character/useAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import useGlobalStore from "@/app/stores/useGlobalStore";
import useVMD from "../animation/useVMD";
import usePresetStore from "@/app/stores/usePresetStore";
import { AnimationMixer, Quaternion } from "three";
import { AnimationMixer, Quaternion, SkinnedMesh } from "three";
import { use, useEffect, useMemo } from "react";
import { GrantSolver } from "@/app/modules/MMDAnimationHelper";
import { CCDIKSolver } from "three/examples/jsm/animation/CCDIKSolver.js";

function useAnimation() {
const mesh = use(useGlobalStore(state => state.characterPromise))
function useAnimation(characterPromise: Promise<SkinnedMesh>) {
const mesh = use(characterPromise)
console.log(mesh)
const player = useGlobalStore(state => state.player)
const motionFile = usePresetStore(state => state.motionFile)

Expand Down
5 changes: 3 additions & 2 deletions app/components/three-world/character/usePhysics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import useGlobalStore from "@/app/stores/useGlobalStore";
import { RootState, useFrame } from "@react-three/fiber";
import { use, useMemo } from "react";
import { SkinnedMesh } from "three";
import { MMDPhysics } from "three/examples/jsm/animation/MMDPhysics.js";

function usePhysics() {
const mesh = use(useGlobalStore(state => state.characterPromise))
function usePhysics(promise: Promise<SkinnedMesh>) {
const mesh = use(promise)
const playDeltaRef = useGlobalStore(state => state.playDeltaRef)
const isMotionUpdating = useGlobalStore(state => state.isMotionUpdating)
const onUpdate = useMemo(() => {
Expand Down
7 changes: 2 additions & 5 deletions app/components/three-world/character/usePose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import useGlobalStore from "@/app/stores/useGlobalStore";
import { buildLoadFileFn } from "@/app/utils/gui";
import { button, useControls } from "leva";
import { use } from "react";
import WithSuspense from "../../suspense";
import { SkinnedMesh } from "three";

function usePose() {

const characterPromise = useGlobalStore(state => state.characterPromise)
const stagePromise = useGlobalStore(state => state.stagePromise)
function usePose(characterPromise: Promise<SkinnedMesh>, stagePromise: Promise<SkinnedMesh>) {
const bindParentCb = useGlobalStore(state => state.bindParentCb)
const character = use(characterPromise)
const stage = use(stagePromise)
Expand Down

0 comments on commit 36a33e4

Please sign in to comment.