admin管理员组文章数量:1352819
I have a script that positions cubes of various width, height and depth and am struggling to line them up accurately based on the xAxis, yAxis and zAxis (which also vary).
var geometry = new THREE.BoxGeometry(width, height, depth);
var cube = new THREE.Mesh(geometry, material);
cube.position.set(xAxis, yAxis, -zAxis);
scene.add(cube);
I believe this is because the cube is positioned based on it's centre, however is there a method to position it based on the front, left and corner - which would solve this issue for varying sized cubes?
I have a script that positions cubes of various width, height and depth and am struggling to line them up accurately based on the xAxis, yAxis and zAxis (which also vary).
var geometry = new THREE.BoxGeometry(width, height, depth);
var cube = new THREE.Mesh(geometry, material);
cube.position.set(xAxis, yAxis, -zAxis);
scene.add(cube);
I believe this is because the cube is positioned based on it's centre, however is there a method to position it based on the front, left and corner - which would solve this issue for varying sized cubes?
Share Improve this question edited Oct 11, 2017 at 15:54 WestLangley 105k11 gold badges287 silver badges283 bronze badges asked Oct 10, 2017 at 10:51 wrdevelopwrdevelop 531 gold badge1 silver badge4 bronze badges 3- Hi Any example on jsfiddle? – user8556290 Commented Oct 10, 2017 at 10:56
- Or a picture with the desired result, as it's hard to understand, at least for me, what "front, left and corner" is. – prisoner849 Commented Oct 10, 2017 at 10:58
- 1 "am struggling to line them up accurately based on the xAxis, yAxis and zAxis" - what is the exact issue? Maybe an image would be helpful. – Paul Kertscher Commented Oct 10, 2017 at 11:07
1 Answer
Reset to default 6You can translate your geometry so one corner of the box is located at the origin:
var geometry = new THREE.BoxGeometry( width, height, depth );
geometry.translate( width / 2, height / 2, depth / 2 );
If you have many cube instances of different sizes, it is better to use this pattern:
var geometry = new THREE.BoxGeometry( 1, 1, 1 ); // create once and reuse
geometry.translate( 0.5, 0.5, 0.5 );
var cube_1 = new THREE.Mesh( geometry, material );
cube_1.scale.set( width, height, depth );
three.js r.87
本文标签: javascriptthreejshow to translate geometryStack Overflow
版权声明:本文标题:javascript - three.js - how to translate geometry - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743920002a2561911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论