Spaces:
Sleeping
Sleeping
implement rotation
Browse files
src/components/rotator.tsx
CHANGED
|
@@ -17,7 +17,6 @@ export const Rotator = ({ facingDirection }: RotatorProps) => {
|
|
| 17 |
"clockwise",
|
| 18 |
);
|
| 19 |
const rotatingGroup = useRef<Group>(new Group());
|
| 20 |
-
scene.add(rotatingGroup.current);
|
| 21 |
|
| 22 |
useFrame((state, delta) => {
|
| 23 |
if (!isRotating.current) return;
|
|
@@ -76,9 +75,9 @@ export const Rotator = ({ facingDirection }: RotatorProps) => {
|
|
| 76 |
}
|
| 77 |
|
| 78 |
if (!isRotating.current) {
|
| 79 |
-
rotatingGroup.current.children
|
| 80 |
-
|
| 81 |
-
|
| 82 |
}
|
| 83 |
});
|
| 84 |
|
|
@@ -86,9 +85,9 @@ export const Rotator = ({ facingDirection }: RotatorProps) => {
|
|
| 86 |
if (isRotating.current) return;
|
| 87 |
const cubes = getCubes(facingDirection);
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
rotatingDirection.current = direction;
|
| 93 |
isRotating.current = true;
|
| 94 |
};
|
|
|
|
| 17 |
"clockwise",
|
| 18 |
);
|
| 19 |
const rotatingGroup = useRef<Group>(new Group());
|
|
|
|
| 20 |
|
| 21 |
useFrame((state, delta) => {
|
| 22 |
if (!isRotating.current) return;
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
if (!isRotating.current) {
|
| 78 |
+
const children = [...rotatingGroup.current.children];
|
| 79 |
+
children.forEach((child) => scene.attach(child));
|
| 80 |
+
scene.remove(rotatingGroup.current);
|
| 81 |
}
|
| 82 |
});
|
| 83 |
|
|
|
|
| 85 |
if (isRotating.current) return;
|
| 86 |
const cubes = getCubes(facingDirection);
|
| 87 |
|
| 88 |
+
rotatingGroup.current = new Group();
|
| 89 |
+
scene.add(rotatingGroup.current);
|
| 90 |
+
cubes.forEach((cube) => rotatingGroup.current.attach(cube));
|
| 91 |
rotatingDirection.current = direction;
|
| 92 |
isRotating.current = true;
|
| 93 |
};
|