最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to move object from position {x,y} to {newx,newy} in Three.js - Stack Overflow

programmeradmin2浏览0评论

X and y are coordinates of object. Z is always 0. How can I move (with visible move animation, not popping up in different location) this object to new location using Three.js?

EDIT: Code example of object (mesh)

var mesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), new THREE.MeshBasicMaterial({img: THREE.ImageUtils.loadTexture('img.png')}))
scene.add(mesh)

EDIT 2: I can make my mesh jump to new position with mesh.position.x=newx and mesh.position.y=newy but I want it to look smooth like in JQuery animate().

X and y are coordinates of object. Z is always 0. How can I move (with visible move animation, not popping up in different location) this object to new location using Three.js?

EDIT: Code example of object (mesh)

var mesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), new THREE.MeshBasicMaterial({img: THREE.ImageUtils.loadTexture('img.png')}))
scene.add(mesh)

EDIT 2: I can make my mesh jump to new position with mesh.position.x=newx and mesh.position.y=newy but I want it to look smooth like in JQuery animate().

Share Improve this question edited Jan 20, 2015 at 8:56 Bartek Kosa asked Jan 20, 2015 at 1:35 Bartek KosaBartek Kosa 8421 gold badge14 silver badges25 bronze badges 1
  • Show us some code for helping us understand what you want. – user3998237 Commented Jan 20, 2015 at 1:44
Add a ment  | 

1 Answer 1

Reset to default 5

The key to animating any kind of object is to move it small amounts, at a high refresh rate.

This means rendering the scene many times but moving the object in the direction you wish a little bit per frame.

e.g.

var direction = new THREE.Vector3(0.3, 0.5, 0); // amount to move per frame

function animate() {
  object.position.add(direction); // add to position

  renderer.render(camera, scene); // render new frame

  requestAnimationFrame(animate); // keep looping
}

requestAnimationFrame(animate);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论