Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

399
Vistas
How do i rotate around the center of the text geometry in react-three-fiber?

I'm currently working on a little side project, where i am using react-three-fiber. I have the following code which renders a text geometry with the display "Test". For some reason the Text Geometry gets rotated at the bottom left corner instead of it being rotated around its own center. How can i change the behavior so that it rotates around its own center?

export function TextMesh(props){
    const textMesh = useRef();
    const font = new FontLoader().parse(props.font);

    useHelper(textMesh, BoxHelper, 'cyan');

    useEffect( () => {
    })

    useFrame( ({clock}) => {
        textMesh.current.rotation.y = clock.getElapsedTime(); 
    })
    
    return (
        <mesh ref={textMesh} position={[-1,-0.25,0]}>
            <textGeometry args={["Test", {
                font: font, 
                size: .5,
                height: 0.1
            }]}/>
            <meshStandardMaterial/>
        </mesh>
    );
}

Here the Code where i wrap the TextMesh onto the Canvas

export default function App() {
  //... Other code
  return (
    <div className="App">
      <Canvas>
        <Suspense fallback={null}>
          //... Other code
          <TextMesh font={Roboto}/>
          <OrbitControls />
        </Suspense>
      </Canvas>
    </div>
  );
}

Currently it looks like thisenter image description here

Any help is appreciated!


I solved it adding following code to the useEffect Hook.

useEffect( () => {
        textMesh.current.geometry.computeBoundingBox();
        const boundingBox = textMesh.current.geometry.boundingBox;
        const center = new THREE.Vector3();
        boundingBox.getCenter(center);
        textMesh.current.geometry.translate(-center.x,-center.y,-center.z);            
})`
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like your Text geometry's rotation origin is in the left side. You could change this origin as a one-time operation with geometry.translate(x, y, z).

I don't know how wide your text is, but you'll probably want to translate it half of its width in the x-axis so the origin lands in the middle:

// Translate the geometry
textMesh.current.geometry.translate(1, 0, 0);

// Return to its starting position
textMesh.current.position.set(-1, 0, 0);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda