Hello. Recently I began to study threejs and, based on the already ready editor, I tried to write a function that puts the selected model in the center above the stage and a problem arose:
- if the model is rotated in a certain way so that its height would change, then it cannot be correctly positioned;
here is the function code that puts the model in the center
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)); console.log('box.size.y = ' + box.size().y); Link to the code in http://lexsandbox.netne.net/editor/ (Alignment-AlignCenter tab)
screen as it should be http://joxi.ru/5mdo7aoinGy5r1 - turn corners = 0, everything is fine
and the problem screen - http://joxi.ru/EA41k31HqVQ0rb - in the current state box.size.y = 105.89974660644481, position.y = 52.95, and it would be correct if the center were not shifted
How in this case to correctly calculate the center and correctly position the model above the stage?
Threejs editor r79 is used for work, not a single line of code other than the one responsible for the menu item and the alignment has changed