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

how to function "position.set" method in Three.js? - Stack Overflow

programmeradmin3浏览0评论

The center of boxMesh has default value(0,0,0).

I think when I use boxMesh.position.set(1,0,0), the center of boxMesh would be (1,0,0).
but it doesn't looks like (1,0,0), it looks like (2,0,0)

Doesn't one grid cell represent a size of 1? I don't have idea...Please explain how this feature works

enter image description here

// Mesh 
const box_geo = new THREE.BoxGeometry(1, 1, 1); // set box size 
const box_mat = new THREE.MeshStandardMaterial({ color: 'red' }); 
const boxMesh = new THREE.Mesh(box_geo, box_mat); 
boxMesh.position.set(1, 0, 0);
scene.add(boxMesh); 

// axesHelper
const axesHelper = new THREE.AxesHelper(50); 
scene.add(axesHelper);

// GridHelper 
const gridHelper = new THREE.GridHelper(5); 
scene.add(gridHelper);

The center of boxMesh has default value(0,0,0).

I think when I use boxMesh.position.set(1,0,0), the center of boxMesh would be (1,0,0).
but it doesn't looks like (1,0,0), it looks like (2,0,0)

Doesn't one grid cell represent a size of 1? I don't have idea...Please explain how this feature works

enter image description here

// Mesh 
const box_geo = new THREE.BoxGeometry(1, 1, 1); // set box size 
const box_mat = new THREE.MeshStandardMaterial({ color: 'red' }); 
const boxMesh = new THREE.Mesh(box_geo, box_mat); 
boxMesh.position.set(1, 0, 0);
scene.add(boxMesh); 

// axesHelper
const axesHelper = new THREE.AxesHelper(50); 
scene.add(axesHelper);

// GridHelper 
const gridHelper = new THREE.GridHelper(5); 
scene.add(gridHelper);
Share Improve this question asked Feb 7 at 13:56 김혜빈김혜빈 11 bronze badge New contributor 김혜빈 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

according to THREE.GridHelper docs:

const gridHelper = new THREE.GridHelper( size, divisions );
// size -- The size of the grid. Default is 10.
// divisions -- The number of divisions across the grid. Default is 10.

so you created grid with size = 5 and divisions = 10 (as default value) then step is size/divisions = 0.5 so everything works correctly, you moved box from (0,0,0) to (1,0,0)

发布评论

评论列表(0)

  1. 暂无评论