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

1.1K
Vistas
How to scale,position an object to the right size in three.js

I just started learning three.js and I wanted to test out importing models using the gltf loader. when I load a certain 3d model my scene looks like this , enter image description here

but without the model ,the background looks like this (after enabling alpha true and changing the bg of the canvas to a gradient)

enter image description here

the object im trying to load is this, enter image description here

Im assuming it has something to do with the camera angle or object scale ,Below is my complete js code.

const loader = new GLTFLoader();
const gui = new dat.GUI()
loader.load('orange.glb', (gltf) => {
   browserscene.add(gltf.scene)
   gltf.scene.position.x = 10
   gltf.scene.position.y = 20
   gltf.scene.rotation.x = 0.2
   gltf.scene.rotation.z = 0.8
   gltf.scene.scale.x = 3
   gltf.scene.scale.y = 3

 });


  // Debug


  // Canvas
  const canvas = document.querySelector('canvas.webgl')

  // Scene
  const browserscene = new THREE.Scene()

  // Materials

   const material = new THREE.MeshBasicMaterial()
   material.color = new THREE.Color(0xFFFE00)

   // Lights

   var light = new THREE.HemisphereLight(0x404040, 0xFFFFFF, 10);
   browserscene.add(light);

   const sizes = {
     width: window.innerWidth,
     height: window.innerHeight
    }

     window.addEventListener('resize', () => {
      // Update sizes
      sizes.width = window.innerWidth
      sizes.height = window.innerHeight

       // Update camera
       camera.aspect = sizes.width / sizes.height
       camera.updateProjectionMatrix()

       // Update renderer
       renderer.setSize(sizes.width, sizes.height)
       renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
      })


      const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
      camera.position.x = 0
      camera.position.y = 0
      camera.position.z = 2
      browserscene.add(camera)


      const renderer = new THREE.WebGLRenderer({
         canvas: canvas, antialias: true, alpha: true
      })
      renderer.setSize(sizes.width, sizes.height)
      renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))

      const animate = () => {

      // Render
      requestAnimationFrame(animate)
      renderer.render(browserscene, camera)

    

     }

     animate()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Without access to the model we probably can't tell you what size or position you should be giving it, but glTF models are intended to be in units of meters. Depending on the source, the model might or might not obey that, e.g. it might have been converted from another format without units, like OBJ.

You can use THREE.Box3.setFromObject(gltf.scene) to find the dimensions of the model and adjust, given that your camera is 2m from the origin.

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