Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit e9140a7

Browse files
committed
めたねのおくすり専用アバターを読み込めるようにする
1 parent 3d11764 commit e9140a7

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

src/components/Exhibition/3d/Player.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ControllerKeys } from "./Controller";
1515
import { useMultiplay } from "~/hooks/exhibition/useMultuplay";
1616
import { Area, AreaName, AreaObject } from "~/types/exhibition";
1717
import { getGltf, rewriteMaterials } from "~/utils/exhibition";
18+
import { getMetanenoToken } from "~/utils/exhibition/metaneno";
1819

1920
CameraControls.install({ THREE });
2021

@@ -129,7 +130,7 @@ export const Exhibition3dPlayer = React.memo<
129130

130131
accessory.position.set(
131132
scene?.position.x || 0,
132-
(scene?.position.y || 0) + 0.95,
133+
(scene?.position.y || 0) + (getMetanenoToken() ? 1.21 : 0.95),
133134
scene?.position.z || 0
134135
);
135136

@@ -152,7 +153,9 @@ export const Exhibition3dPlayer = React.memo<
152153

153154
useEffect(() => {
154155
(async () => {
155-
const { animations, scene } = await getGltf(url);
156+
const { animations, scene } = await getGltf(
157+
getMetanenoToken() ? "/objects/metaneno.glb" : url
158+
);
156159

157160
scene.scale.set(0.5, 0.5, 0.5);
158161

@@ -284,7 +287,7 @@ export const Exhibition3dPlayer = React.memo<
284287
if (accessory) {
285288
accessory.position.set(
286289
nextPosition.x,
287-
nextPosition.y + 0.95,
290+
nextPosition.y + (getMetanenoToken() ? 1.21 : 0.95),
288291
nextPosition.z
289292
);
290293
accessory.rotation.y = Math.atan2(rotation.x, rotation.z);

src/components/Exhibition/3d/Players.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { getGltf, rewriteMaterials } from "~/utils/exhibition";
77

88
type S = Scene & {
99
accessory: "fried_egg" | "pancake" | null;
10-
hasAccessory: boolean;
10+
accessoryScene: Scene | null;
11+
metaneno: boolean;
1112
mixer: AnimationMixer;
1213
nextPosition: Vector3 | null;
1314
lerpAlpha: number;
@@ -49,7 +50,6 @@ const applyPlayerTransform = async (scene: S, payload: UpdateResponse) => {
4950

5051
if (!scene.ready) {
5152
scene.accessory = null;
52-
scene.hasAccessory = false;
5353
scene.mixer = new AnimationMixer(scene);
5454
scene.nextPosition = null;
5555
scene.position.set(
@@ -72,23 +72,18 @@ const applyPlayerTransform = async (scene: S, payload: UpdateResponse) => {
7272
// Accessory
7373

7474
if (scene.accessory !== payload.accessory) {
75-
if (scene.hasAccessory) {
76-
scene.children = scene.children.slice(0, scene.children.length - 1);
77-
}
78-
7975
if (payload.accessory === "pancake" || payload.accessory === "fried_egg") {
8076
const { scene: accessory } = await getGltf(
8177
`/objects/accessories/${payload.accessory}.glb`
8278
);
8379
rewriteMaterials(accessory);
8480
accessory.position.set(
8581
scene.position.x || 0,
86-
(scene.position.y || 0) + 0.95,
82+
(scene.position.y || 0) + (scene.metaneno ? 1.21 : 0.95),
8783
scene.position.z || 0
8884
);
89-
scene.children.push(accessory);
85+
scene.accessoryScene = accessory;
9086
scene.accessory = payload.accessory;
91-
scene.hasAccessory = true;
9287
}
9388
}
9489

@@ -128,10 +123,10 @@ const applyPlayerTransform = async (scene: S, payload: UpdateResponse) => {
128123
const position = scene.position.lerp(nextPosition, scene.lerpAlpha);
129124
scene.lerpAlpha += ALPFA;
130125

131-
if (scene.hasAccessory) {
132-
scene.children[scene.children.length - 1].position.set(
126+
if (scene.accessoryScene) {
127+
scene.accessoryScene.position.set(
133128
position.x,
134-
position.y + 0.95,
129+
position.y + (scene.metaneno ? 1.21 : 0.95),
135130
position.z
136131
);
137132
}
@@ -188,9 +183,13 @@ export const Exhibition3dPlayers = React.memo<{
188183
});
189184
} else {
190185
const { scene } = await getGltf(
191-
`/objects/${payload.metaneno ? "" : "other_"}player.glb`
186+
`/objects/${
187+
payload.metaneno ? "metaneno" : "other_player"
188+
}.glb`
192189
);
193190

191+
(scene as S).metaneno = !!payload.metaneno;
192+
194193
return Promise.resolve({
195194
[playerId]: await applyPlayerTransform(scene as S, payload),
196195
});
@@ -211,7 +210,10 @@ export const Exhibition3dPlayers = React.memo<{
211210
return (
212211
<>
213212
{Object.values(scenes).map((scene) => (
214-
<primitive key={scene.id} object={scene} />
213+
<React.Fragment key={scene.id}>
214+
<primitive object={scene} />
215+
{scene.accessoryScene && <primitive object={scene.accessoryScene} />}
216+
</React.Fragment>
215217
))}
216218
</>
217219
);

src/hooks/exhibition/useMultuplay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react";
22
import { io } from "socket.io-client";
33
import { AreaName } from "~/types/exhibition";
44
import * as GA from "~/utils/exhibition/google-analytics";
5+
import { getMetanenoToken } from "~/utils/exhibition/metaneno";
56

67
export type UpdateResponse = UpdatePayload & {
78
metaneno: boolean;
@@ -47,7 +48,7 @@ export const useMultiplay = () => {
4748
//
4849

4950
useEffect(() => {
50-
const token = localStorage.getItem("_metaneno");
51+
const token = getMetanenoToken();
5152

5253
if (token) {
5354
if (socket.connected) {

src/utils/exhibition/metaneno.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const getMetanenoToken = () => localStorage.getItem("_metaneno");

0 commit comments

Comments
 (0)