1
0

add planet

This commit is contained in:
syui 2024-08-05 18:40:46 +09:00
parent f5fa7a9a0c
commit 5c79c64679
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
6 changed files with 175 additions and 125 deletions

View File

@ -16,8 +16,21 @@ $ yarn dev
$ yarn build $ yarn build
``` ```
## planet
- deploy : [https://card.syui.ai/planet?g=sun](https://card.syui.ai/planet?g=sun)
- ref : [https://git.syui.ai/ai/star](https://git.syui.ai/ai/star/src/branch/main/galaxy-react)
```
$ cd planet
$ npm i
$ npm run start
```
## min-react ## min-react
three-vrm v3 + vrm(unity + vrm v1.0) + anim(vrma)
``` ```
$ cd min-react $ cd min-react
$ npm i $ npm i
@ -33,3 +46,5 @@ $ cd min-ts
$ yarn install $ yarn install
$ yarn dev $ yarn dev
``` ```

2
dist/vrma vendored

@ -1 +1 @@
Subproject commit 12ce521873fb3a4ec2fd3f5e75a0792351c8a207 Subproject commit 1eccc36a5113246728ae8b63389c948ce1bd286f

View File

@ -1,19 +1,19 @@
body { html {
background-color: #000;
height: 100%; height: 100%;
}
body {
background-color: #fff;
background-color: #000;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', height: 100%;
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', }
sans-serif;
-webkit-font-smoothing: antialiased; div#root{
-moz-osx-font-smoothing: grayscale; height: 100%;
} }
code { code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace; monospace;
} }
html {
height: 100%;
}

View File

@ -12,9 +12,12 @@ import { GLTF } from 'three-stdlib'
interface ModelProps { interface ModelProps {
url: string url: string
url_anim: string url_anim: string
position?: [number, number, number]
rotation?: [number, number, number]
scale?: number
} }
const VRMModel: React.FC<ModelProps> = ({ url = "./models/ai.vrm", url_anim="./models/default.vrma" }) => { const VRMModel: React.FC<ModelProps> = ({ url = "./models/ai.vrm", url_anim="./models/default.vrma", position = [0, 0, 0], scale = 1, rotation = [0, 1.5, 0] }) => {
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);
@ -27,6 +30,11 @@ const VRMModel: React.FC<ModelProps> = ({ url = "./models/ai.vrm", url_anim="./m
const vrmModel = gltf.userData.vrm as VRM; const vrmModel = gltf.userData.vrm as VRM;
VRMUtils.removeUnnecessaryJoints(vrmModel.scene); VRMUtils.removeUnnecessaryJoints(vrmModel.scene);
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,7 +45,7 @@ const VRMModel: React.FC<ModelProps> = ({ url = "./models/ai.vrm", url_anim="./m
} }
}); });
}); });
}, [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);
@ -47,6 +55,20 @@ const VRMModel: React.FC<ModelProps> = ({ url = "./models/ai.vrm", url_anim="./m
return vrm ? <primitive object={vrm.scene} /> : null; return vrm ? <primitive object={vrm.scene} /> : null;
}; };
interface ModelGlbProps {
url: string
position?: [number, number, number]
rotation?: [number, number, number]
scale?: number
}
const GlbModel: React.FC<ModelGlbProps> = ({ url = "./models/solar_system.glb", position = [0, 0, 0], scale = 1, rotation = [0, 0, 0] }) => {
const { scene } = useGLTF(url)
scene.scale.setScalar(scale);
scene.position.set(...position);
return <primitive object={scene} />
}
type GLTFResult = GLTF & { type GLTFResult = GLTF & {
nodes: { nodes: {
Object_2: THREE.Mesh Object_2: THREE.Mesh
@ -61,50 +83,53 @@ export function Galaxy(props: JSX.IntrinsicElements['group']) {
const galaxyCenterLightRef = useRef<THREE.PointLight>(null!) const galaxyCenterLightRef = useRef<THREE.PointLight>(null!)
const searchParams = new URLSearchParams(window.location.search); const searchParams = new URLSearchParams(window.location.search);
var g = searchParams.get('g') ?? 'galaxy'; var g = searchParams.get('g') ?? 'galaxy';
var model_path = "./models/" + g + ".glb" var model_galaxy = "./models/galaxy.glb"
var model_scale = 0.05; var model_custom = "./models/ai.vrm"
var model_scale = 0.01;
const { nodes } = useGLTF(model_path) as GLTFResult var position_custom = [-0.2, -0.8, -0.3] as [number, number, number];
const [positions, colors] = useMemo(() => { var rotation_custom = [0, 1.5, 0] as [number, number, number];
var sphereGeometry = new SphereGeometry(1, 332, 332);
var anim_custom = "./models/emote.vrma";
const { nodes } = useGLTF(model_galaxy) as GLTFResult
var model_color = 100;
nodes.Object_2.geometry.center() nodes.Object_2.geometry.center()
if (g === 'sun'){
sphereGeometry = new SphereGeometry(1, 332, 332);
nodes.Object_2.geometry = sphereGeometry;
model_scale = 1;
} else if (g === 'moon'){
sphereGeometry = new SphereGeometry(1, 132, 132);
nodes.Object_2.geometry = sphereGeometry;
model_color = 1;
model_scale = 0.01;
position_custom = [-0.5,-1,0];
anim_custom = "./models/fly.vrma";
model_custom = "./models/ai_default.vrm";
} else if (g === 'earth'){
sphereGeometry = new SphereGeometry(1, 232, 232);
nodes.Object_2.geometry = sphereGeometry;
model_color = 0.5;
model_scale = 0.3;
position_custom = [-1,-1,0];
anim_custom = "./models/fly.vrma";
model_custom = "./models/ai_default.vrm";
} else if (g === 'neutron') {
model_color = 1;
}
const [positions, colors] = useMemo(() => {
const positions = new Float32Array( const positions = new Float32Array(
nodes.Object_2.geometry.attributes.position.array.buffer nodes.Object_2.geometry.attributes.position.array.buffer
) )
const colors = new Float32Array(positions.length) const colors = new Float32Array(positions.length)
const getDistanceToCenter = (x: number, y: number, z: number) => const getDistanceToCenter = (x: number, y: number, z: number) =>
Math.sqrt(x * x + y * y + z * z) Math.sqrt(x * x + y * y + z * z)
var model_color = 100;
if (g === 'sun'){
const sphereGeometry = new SphereGeometry(1, 332, 332);
nodes.Object_2.geometry = sphereGeometry;
model_scale = 1;
} else if (g === 'moon'){
const sphereGeometry = new SphereGeometry(1, 132, 132);
nodes.Object_2.geometry = sphereGeometry;
model_color = 1;
model_scale = 0.1;
} else if (g === 'earth'){
const sphereGeometry = new SphereGeometry(1, 232, 232);
nodes.Object_2.geometry = sphereGeometry;
model_color = 0.5;
model_scale = 0.3;
} else if (g === 'asteroid') {
const sphereGeometry = new SphereGeometry(1, 32, 32);
nodes.Object_2.geometry = sphereGeometry;
model_color = 1;
model_scale = 0.1;
} else if (g === 'neutron') {
model_color = 1;
}
// make colors closer to 0,0,0 be more reddish and colors further away be more blueish
const color = new THREE.Color() const color = new THREE.Color()
for (let i = 0; i < positions.length; i += 3) { for (let i = 0; i < positions.length; i += 3) {
const x = positions[i] const x = positions[i]
const y = positions[i + 1] const y = positions[i + 1]
const z = positions[i + 2] const z = positions[i + 1]
const distanceToCenter = getDistanceToCenter(x, y, z) const distanceToCenter = getDistanceToCenter(x, y, z)
const normalizedDistanceToCenter = distanceToCenter / model_color const normalizedDistanceToCenter = distanceToCenter / model_color
// make colors closer to 0,0,0 be more reddish and colors further away be more blueish (do not use hsl)
color.setHSL( color.setHSL(
(0.15 * (0.21 + Math.cos(distanceToCenter * 0.02))) / 2, (0.15 * (0.21 + Math.cos(distanceToCenter * 0.02))) / 2,
0.75, 0.75,
@ -119,22 +144,25 @@ export function Galaxy(props: JSX.IntrinsicElements['group']) {
} }
return [positions, colors] return [positions, colors]
}, [nodes]) }, [nodes, model_color])
useFrame(({ clock }) => { useFrame(({ clock }) => {
// zoom in and out ref.current.rotation.y = clock.getElapsedTime() / 2
ref.current.rotation.z = clock.getElapsedTime() / 2 ref.current.scale.setScalar(Math.sin(clock.getElapsedTime() / 2) + 1.2)
ref.current.scale.setScalar(Math.sin(clock.getElapsedTime() / 10) + 1.2)
}) })
return ( return (
<group {...props} dispose={null} ref={ref}> <group {...props} dispose={null} ref={ref}>
<VRMModel url={model_custom} url_anim={anim_custom} position={position_custom} scale={1} rotation={rotation_custom} />
{g === 'sun' && <GlbModel url="./models/solar-system.glb" scale={10} />}
{g === 'galaxy' && <GlbModel url="./models/solar-system.glb" scale={0.5} position={[0,0.5,2]}/>}
<pointLight <pointLight
position={[0, 0, 0]} position={[0, 0, 0]}
ref={galaxyCenterLightRef} ref={galaxyCenterLightRef}
intensity={0.5} intensity={0.2}
/> />
<Points scale={model_scale} positions={positions} colors={colors}> <Points scale={model_scale} positions={positions} colors={colors} rotation={[1.5,0,0]}>
<pointsMaterial <pointsMaterial
//map={starTexture} //map={starTexture}
transparent transparent
@ -160,13 +188,11 @@ export function Galaxy(props: JSX.IntrinsicElements['group']) {
export const VRMModelCanvas = () => { export const VRMModelCanvas = () => {
return ( return (
<div style={{ height: '100vh', width: '100vw' }}>
<Canvas <Canvas
shadows shadows
gl={{ gl={{
toneMapping: THREE.NeutralToneMapping, toneMapping: THREE.NeutralToneMapping,
toneMappingExposure: 1.5, toneMappingExposure: 1.1,
alpha: true, alpha: true,
powerPreference: "high-performance", powerPreference: "high-performance",
antialias: true, antialias: true,
@ -177,16 +203,20 @@ export const VRMModelCanvas = () => {
color="white" color="white"
castShadow castShadow
position={[0, 10, 0]} position={[0, 10, 0]}
intensity={1.5} intensity={0.4}
shadow-mapSize={[1024, 1024]}/> shadow-mapSize={[1024, 1024]}/>
<OrbitControls /> <OrbitControls
minDistance={2} maxDistance={3}
enableZoom={true} enablePan={false} enableRotate={true}
zoomSpeed={0.5}
panSpeed={0.5}
rotateSpeed={0.5} />
<ambientLight intensity={1} /> <ambientLight intensity={1} />
<pointLight position={[10, 10, 10]} /> <pointLight position={[10, 10, 10]} />
<VRMModel url="./models/ai.vrm" url_anim="./models/default.vrma" /> <Galaxy position={[0, 0, 0]} />
<Galaxy position={[0, 9, 0]} />
</Canvas> </Canvas>
</div>
) )
} }
export default VRMModelCanvas; export default VRMModelCanvas;

View File

@ -10,6 +10,7 @@ import { BloomEffect, EffectComposer, EffectPass, RenderPass } from "postprocess
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
let default_model = "/vrma/model/test.vrm"
// vrma // vrma
let motion_enable = false; let motion_enable = false;
let head = null; let head = null;
@ -107,7 +108,7 @@ window.addEventListener("DOMContentLoaded", () => {
return new VRMAnimationLoaderPlugin(parser); return new VRMAnimationLoaderPlugin(parser);
}); });
load("/vrma/model/ai.vrm"); load(default_model);
load("/vrma/anime/fly_c.vrma"); load("/vrma/anime/fly_c.vrma");
let item = null; let item = null;

View File

@ -3,5 +3,9 @@
"target": "es2016", "target": "es2016",
"module": "commonjs", "module": "commonjs",
"skipLibCheck": true "skipLibCheck": true
} },
"exclude": [
"min-*",
"planet"
]
} }