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

94
Views
How to case switch between models in THREE.js

Im writing a program in THREE.js where I would like a key press to change the current model loaded. I have gotten this to work fairly simply using the built in mesh's in THREE, but when I try to use the same framework in imported .glb files, it wont work.

Here is my loader function:

let charSelect = "models/charMod.glb";

loader = new GLTFLoader();

function loadModels() {
  const onLoadStatic = function (gltf, position) {
    charModel = gltf.scene.children[2];
    scene.remove(charModel);
    charModel.scale.multiplyScalar(4);
    charModel.position.copy(position);
    modelLoaded = true;
    scene.add(charModel);
  };

  const onProgress = function () {
    console.log("progress");
  };

  const onError = function (errorMessage) {
    console.log(errorMessage);
  };

  const modPos = new THREE.Vector3(0, -3.5, 0);
  loader.load(
    charSelect,
    function (gltf) {
      onLoadStatic(gltf, modPos);
    },
    onProgress,
    onError
  );

My case switch:

function caseSwitch() {
  switch (caseNum) {
    case 1:
      charSelect = "models/idle.glb";
      loadModels();
      break;

    case 2:
      charSelect = "models/kick.glb";
      loadModels();
      break;

    default:
      charSelect = "models/charMod.glb";
      loadModels();
  }
}

As I said, this worked with the default THREE.js mesh, but not with this. Anyone know a fix for this? Thanks :)

about 4 years ago · Juan Pablo Isaza
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!