Thrimjs,Animejs,可以在卷轴上进行动画。导入GLTF文件。只有原语
我正在尝试三个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用此问题解决了:
然后
这样做,我可以在时间轴上称为“ mymodel”
i solved by using this:
and then
doing so I'm able to call "mymodel" on the timeline