1
0

Compare commits

..

5 Commits

Author SHA1 Message Date
5234d77434 fix 2025-03-18 06:33:11 +09:00
e79dc42a23 fix 2024-10-05 14:17:04 +09:00
72456a96f3 fix 2024-10-04 13:37:23 +09:00
7bc0ba9e93 fix 2024-10-02 14:58:36 +09:00
70366cc5ae add holo 2024-10-02 13:25:44 +09:00
5 changed files with 53 additions and 31 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@
**_site** **_site**
**.jekyll** **.jekyll**
galaxy-react/public/models galaxy-react/public/models
holo/public/models

View File

@@ -12,7 +12,13 @@ $ npm run start
# npm install three three-stdlib @types/three @react-three/fiber @react-three/fiber @react-three/drei @react-three/postprocessing # npm install three three-stdlib @types/three @react-three/fiber @react-three/fiber @react-three/drei @react-three/postprocessing
``` ```
## tips
- `?ms=0`
- `?g=moon`
## ref ## ref
- galaxy.glb : https://sketchfab.com/3d-models/need-some-space-d6521362b37b48e3a82bce4911409303 - galaxy.glb : https://sketchfab.com/3d-models/need-some-space-d6521362b37b48e3a82bce4911409303
- tsx : https://gist.github.com/artokun/fb7f0c68a01ba5d9813abb3ccce254c4 - tsx : https://gist.github.com/artokun/fb7f0c68a01ba5d9813abb3ccce254c4

View File

@@ -17,6 +17,7 @@ html {
} }
.time { .time {
transform:scale(-1,1);
position: absolute; position: absolute;
top: 10px; top: 10px;
padding: 10px; padding: 10px;
@@ -27,6 +28,7 @@ html {
} }
.api { .api {
transform:scale(-1,1);
position: absolute; position: absolute;
top: 50px; top: 50px;
padding: 10px; padding: 10px;

View File

@@ -1,7 +1,12 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
//function reverseString(str: string): string {
// return str.split('').reverse().join('');
//}
const ScreenTimeCanvas: React.FC = () => { const ScreenTimeCanvas: React.FC = () => {
const [currentDateTime, setCurrentDateTime] = useState<string>(''); const [currentDateTime, setCurrentDateTime] = useState<string>('');
//const [reversedDateTime, setReversedDateTime] = useState<string>('');
useEffect(() => { useEffect(() => {
const updateDateTime = () => { const updateDateTime = () => {
@@ -15,11 +20,10 @@ const ScreenTimeCanvas: React.FC = () => {
second: '2-digit' second: '2-digit'
}); });
setCurrentDateTime(formatted); setCurrentDateTime(formatted);
//setReversedDateTime(reverseString(formatted));
}; };
updateDateTime(); updateDateTime();
const timer = setInterval(updateDateTime, 1000); const timer = setInterval(updateDateTime, 1000);
return () => clearInterval(timer); return () => clearInterval(timer);
}, []); }, []);

View File

@@ -5,19 +5,20 @@ import { useFrame, Canvas } from '@react-three/fiber';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { VRM, VRMUtils, VRMLoaderPlugin } from '@pixiv/three-vrm'; import { VRM, VRMUtils, VRMLoaderPlugin } from '@pixiv/three-vrm';
import { VRMAnimationLoaderPlugin, VRMAnimation, createVRMAnimationClip } from "@pixiv/three-vrm-animation"; import { VRMAnimationLoaderPlugin, VRMAnimation, createVRMAnimationClip } from "@pixiv/three-vrm-animation";
import { VRMSpringBoneManager } from '@pixiv/three-vrm-springbone';
interface ModelProps { interface ModelProps {
url: string url: string
url_anim: string url_anim: string
scale: [number, number, number] scale: number
position: [number, number, number] position: [number, number, number]
rotation: [number, number, number] rotation: [number, number, number]
} }
const VRMModel: React.FC<ModelProps> = ({ url, url_anim, position, rotation, scale }) => { const VRMModel: React.FC<ModelProps> = ({ url, url_anim, position, rotation, scale }) => {
const [vrm, setVrm] = useState<VRM | null>(null); const [vrm, setVrm] = useState<VRM | null>(null);
const mixerRef = useRef<THREE.AnimationMixer | null>(null); const mixerRef = useRef<THREE.AnimationMixer | null>(null);
const springBoneManagerRef = useRef<VRMSpringBoneManager | null>(null);
useEffect(() => { useEffect(() => {
const loader = new GLTFLoader(); const loader = new GLTFLoader();
@@ -26,7 +27,14 @@ const VRMModel: React.FC<ModelProps> = ({ url, url_anim, position, rotation, sca
loader.load(url, (gltf) => { loader.load(url, (gltf) => {
const vrmModel = gltf.userData.vrm as VRM; const vrmModel = gltf.userData.vrm as VRM;
VRMUtils.removeUnnecessaryJoints(vrmModel.scene); VRMUtils.removeUnnecessaryJoints(vrmModel.scene);
springBoneManagerRef.current = vrmModel.springBoneManager as VRMSpringBoneManager;
springBoneManagerRef.current?.reset();
setVrm(vrmModel); setVrm(vrmModel);
if (vrmModel) {
vrmModel.scene.rotation.set(...rotation);
vrmModel.scene.position.set(...position);
vrmModel.scene.scale.setScalar(scale);
}
const mixer = new THREE.AnimationMixer(vrmModel.scene); const mixer = new THREE.AnimationMixer(vrmModel.scene);
mixerRef.current = mixer; mixerRef.current = mixer;
loader.load(url_anim, (animGltf) => { loader.load(url_anim, (animGltf) => {
@@ -37,14 +45,15 @@ const VRMModel: React.FC<ModelProps> = ({ url, url_anim, position, rotation, sca
} }
}); });
}); });
}, [url, url_anim]); }, [url, url_anim, position, scale, rotation]);
useFrame((state, delta) => { useFrame((state, delta) => {
if (mixerRef.current) mixerRef.current.update(delta); if (mixerRef.current) mixerRef.current.update(delta);
if (springBoneManagerRef.current) springBoneManagerRef.current.update(delta);
if (vrm) vrm.update(delta); if (vrm) vrm.update(delta);
}); });
return vrm ? <primitive object={vrm.scene} position={position} rotation={rotation} scale={scale}/> : null; return vrm ? <primitive object={vrm.scene} /> : null;
}; };
export const VRMModelCanvas = () => { export const VRMModelCanvas = () => {
@@ -65,10 +74,10 @@ export const VRMModelCanvas = () => {
}} }}
camera={{ position: [1.2, 0, 0] }}> camera={{ position: [1.2, 0, 0] }}>
<color attach="background" args={["#000"]} /> {/* Light gray background */} <color attach="background" args={["#000"]} /> {/* Light gray background */}
<OrbitControls /> <OrbitControls dampingFactor={0.05} rotateSpeed={0.1} zoomSpeed={0.5}/>
<ambientLight intensity={10} /> <ambientLight intensity={10} />
<pointLight position={[10, 10, 10]} /> <pointLight position={[10, 10, 10]} />
<VRMModel url="./models/t.vrm" url_anim="./models/default.vrma" position={[0, -0.7, 0]} rotation={[0, -4.7, 0]} scale={[1, 1, 1]} /> <VRMModel url="./models/t.vrm" url_anim="./models/default.vrma" position={[0, -0.6, 0]} rotation={[0, 89.5, 0]} scale={1} />
</Canvas> </Canvas>
</div> </div>
) )