Skip to content

fitbox for small box #576

@widefire

Description

@widefire

Describe the bug

fitbox for small box not work.nothing rendered,for example this model https://threejs.org/examples/models/gltf/BoomBox.glb。boundingBoxSize {x: 0.019842308, y: 0.01954326, z: 0.0201524906} 。fitToBox can't visible the model.

To Reproduce

fitBox for BoomBox.glb can't see it.is the modle boundingbox too small?

Code

import * as THREE from "three";
import { DRACOLoader, GLTF, GLTFLoader } from "three-stdlib";
import CameraControls from "camera-controls";

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
  60,
  window.innerWidth / window.innerHeight,
  0.1,
  1000
);
camera.position.set(0, 1, 3);

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

scene.add(new THREE.AmbientLight(0xffffff, 0.8));
CameraControls.install({ THREE: THREE });
const cameraControls = new CameraControls(camera, renderer.domElement);

const loader = new GLTFLoader();
loader.setPath("https://threejs.org/examples/models/gltf/");
loader.load(
   "BoomBox.glb",
//   "Horse.glb",
  (gltf) => {
    scene.add(gltf.scene);

    scene.updateMatrixWorld(true);

    cameraControls.fitToBox(scene, true);
  },
  (xhr) => {
    console.log(`progress: ${(xhr.loaded / xhr.total) * 100}%`);
  },
  (error) => {
    console.error("failed:", error);
  }
);

let lastTime: number = 0;
function animate(ts: number) {
  const delta = ts - lastTime;
  lastTime = ts;
  cameraControls.update(delta);
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}
animate(0);

Live example

No response

Expected behavior

fitBox for small scene like the BoomBox

Screenshots or Video

No response

Device

No response

OS

No response

Browser

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions