Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!