Thrimjs,Animejs,可以在卷轴上进行动画。导入GLTF文件。只有原语

发布于 2025-01-21 12:37:29 字数 1888 浏览 3 评论 0原文

我正在尝试三个JJ,动画(动漫J)和滚动事件。 是一个工作codepen:

这 30我将立方体添加到场景中:

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);
}

在第37行上,我启动并设置时间表

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);
}

,所以这是完美的,唯一的问题是它仅适用于原语(盒,圆柱,球形等) 每当我尝试通过gltfloader加载自定义的GLTF时,即使我认为我要调试问题,我也真的无法解决它。

我正在尝试加载这样的另一个模型:

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);

  });
}

一切看起来都不错(如果我留在此功能中) 但是,只要我走出功能,无论我做什么,错误都会发生。 但同时又什么也没有发生”。

没有显示错误, 我尝试了不同的事情来解决这个问题,但是现在我必须“放弃”并寻求帮助,但是我非常有信心修复是一件容易的事,我现在只是脑脱水。.

如果您可以告诉我如何这可以解决,我将非常感谢。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守护在此方 2025-01-28 12:37:29

我通过使用此问题解决了:

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

然后

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

这样做,我可以在时间轴上称为“ mymodel”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文