0

I'm trying to rotate tetrahedrons so that they lie with one side facing downwards, like how they would be if they where physical objects that you placed on a floor.

I expected this SO answer to solve my problem

After applying the accepted answer by giving the tetrahedron the applyMatrix property, my code looked like this:

const Triangle = ({ position, color }) => {
  const mesh = useRef(null);
  return (
    <mesh castShadow ref={mesh} position={position}>
      <tetrahedronGeometry
        attach="geometry"
        args={[0.6, 0]}
        applyMatrix={new THREE.Matrix4().makeRotationAxis(
          new THREE.Vector3(2, 0, -1).normalize(),
          Math.atan(Math.sqrt(2))
        )}
      />
      <meshStandardMaterial attach="material" color={color} />
    </mesh>
  );
};

However, the rotation of my tetrahedrons did not change. What am I doing wrong?

This is my current code: fiddle

hellogoodnight
  • 1,989
  • 7
  • 29
  • 57

1 Answers1

1

applyMatrix is a function. you are overwriting it with a matrix. essentially you're doing this:

const geom = new THREE.TetrahedronGeometry()
geom.applyMatrix = new THREE.Matrix4() 

put a ref on the mesh or the geometry, then use useLayoutEffect to call the function.

hpalu
  • 1,357
  • 7
  • 12