Threejs how to get center of model after rotation

javascript three.js

100 просмотра

1 ответ

Recently I started to learn threejs and on the basis of threejs.org/editor tried to write a function that puts the selected model to the center of the scene, and there was a problem:

center of model will be calculated wrong if the model was rotated, so i cant place model in right way

code of my alignCenter function

editor.selected.geometry.center();
var box = new THREE.Box3().setFromObject(editor.selected);    
var newPosition = new THREE.Vector3(0, box.size().y/2, 0);    
editor.execute(new SetPositionCommand(editor.selected, newPosition));

here is how it works - http://lexsandbox.netne.net/editor/ - (tab Alignment - AlignCenter)

how it is if model was rotated - http://joxi.ru/EA41k31HqVQ0rb (random angles, box.size().y = 105.89974660644481, position.y = 52.95) and because of wrong center position it works in wrong way

how i can fix this issue?

PS: sory for my english, i am foreign student ;(

Автор: leviafun777 Источник Размещён: 08.11.2019 11:28

Ответы (1)


0 плюса

you can specify rotation parameter for axis separately as, cube.rotate.x+=0.1; cube.rotate.y+=0.1; for rotation.Here cube mean geometry or mesh or else try to compute bounding box and rotate about it's centre.

Автор: Aasha joney Размещён: 08.09.2016 07:28
Вопросы из категории :
32x32