imwithye commited on
Commit
050237b
·
1 Parent(s): f68ade5

implement rotation

Browse files
Files changed (1) hide show
  1. src/components/rotator.tsx +6 -7
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.forEach((child) => {
80
- scene.attach(child);
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
- cubes.forEach((cube) => {
90
- rotatingGroup.current.attach(cube);
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
  };