Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
threejs, animejs, can't "animate on scroll" imported gltf files. only primitives working

I was experimenting with threejs, animations (animejs) and scroll event. here's a working codepen: https://codepen.io/cristigoia/pen/JjPMQMP

On line 30 i add the cube to the scene:

function addCube () {
    cube = new THREE.Mesh( new THREE.BoxGeometry( 50, 50, 50 ), new THREE.MeshNormalMaterial() );
    cube.position.y = 5
    cube.position.z = -100
    scene.add(cube);
}

on line 37 I init and set the timeline

function initTimeline() {
  timeline = anime.timeline({
    autoplay: false,
    duration: 4500,
    easing: 'easeOutSine'
  });
  timeline.add({
    targets: cube.position,
    x: 100,
    y: 25,
    z: -50,
    duration: 2250,
    update: camera.updateProjectionMatrix()
  })
  timeline.add({
    targets: cube.position,
    x: 0,
    y: 0,
    z: 50,
    duration: 2250,
    update: camera.updateProjectionMatrix()
  })
  var value = new THREE.Color(0xFFFCFC)
  var initial = new THREE.Color(0x161216)
  timeline.add({
    targets: initial,
    r: [initial.r, value.r],
    g: [initial.g, value.g],
    b: [initial.b, value.b],
    duration: 4500,
    update: () => {
      renderer.setClearColor(initial);
    }
  }, 0);
}

Ok so this is perfect, the only problem is that this is working with primitives only (box, cylinder, spherere, whatever) Whenever I try to load a custom GLTF through GLTFLoader the thing get broken and I really can't solve it even if I think I'm near to debug the problem.

I'm trying to load another model like this:

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

var loader = new GLTFLoader();

var something;
function addSomething() {

  loader.load("./assets/something.gltf", function(gltf) {
    something = gltf.scene;
    scene.add(something);

  });
}

and everything looks good (if I stay inside this function) but as long as I go outside the function, no matter what I do, errors happen.. (I tried different things and got different errors: from errors like "something is null", "something is not declared", to errors like "no error shown but at the same time nothing happens")

If I try to initialize the timeline and animate the model like I did above with the cube, nothing is working, and I'm stuck here. I tried different thing to solve this, but now I have to "give up" and ask for help, but I'm pretty confident it's an easy task to fix and I'm just braindead right now..

If you can show me how this can be solved I would be very grateful. Thank you

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

i solved by using this:

const gltf = await loader.loadAsync("./assets/mymodel.gltf")

and then

var mymodel = gltf.scene
scene.add(mymodel)

doing so I'm able to call "mymodel" on the timeline

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda