Last active
December 12, 2022 15:52
-
-
Save Carnaux/0763e4d041db5161cd1e45df48777f42 to your computer and use it in GitHub Desktop.
Jsartoolkit5 model centering method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let width = source_image_width; | |
let height = source_image_height; | |
let dpi = source_image_dpi; | |
// CONVERT PIXEL TO MM | |
let w = width / dpi * 2.54 * 10; | |
let h = height / dpi * 2.54 * 10; | |
// SCALE OBJECT | |
var box = new THREE.Box3().setFromObject( model ); | |
var size = new THREE.Vector3(); | |
box.getSize( size ); | |
let scaleVecX = (w/size.x); | |
model.scale.setScalar(scaleVecX + (scaleVecX * 0.2)); | |
// SET MODEL ORIGIN AS BOX CENTER | |
var box2 = new THREE.Box3().setFromObject( model ); | |
let boxCenter = new THREE.Vector3(); | |
box2.getCenter(boxCenter); | |
let dist = new THREE.Vector3((w/2) - boxCenter.x, (h/2) - boxCenter.y); | |
// SET POSITION | |
model.position.x += dist.x; | |
model.position.y += dist.y; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment