1:获取模型宽高
var getObjectHalfSize = function(obj) { var objectBox = new THREE.Box3(); objectBox.setFromObject(obj); return objectBox.max.clone().sub(objectBox.min).divideScalar(2); };
2计算模型的对角线并设置位置 添加的场景中
var size = getObjectHalfSize(modelObject); var radius = Math.sqrt(Math.pow(size.x, 2) + Math.pow(size.y, 2) + Math.pow(size.z, 2)); modelObject.scale.multiplyScalar(0.5 / radius);
modelObject.position.y = -size.y * (0.5 / radius); modelObject.name = mtlName; scene.add(modelObject);