答案 0 :(得分:6)
您可以像这样访问3d.io实体的three.js对象:
var threeElem = document.getElementById("custom-id").components['io3d-data3d'].data3dView.threeParent
然后你可以使用three.js的原生边界框:
var bbox = new THREE.Box3().setFromObject(threeElem)
就像你得到最小/最大界限一样,你可以用它来确定原点。
我希望能回答你的问题。让我知道!
编辑: 对于家具,它可能是
var threeElem = document.getElementById("custom-id").components['io3d-furniture'].data3dView.threeParent
答案 1 :(得分:4)
根据Madlaina的回答。我需要确保在
之前加载模型addModelToScene(type) {
let scene = document.querySelector('a-scene');
let model = document.createElement('a-entity');
model.setAttribute('io3d-data3d', getModelKey(type) )
model.addEventListener('model-loaded', () => {
// Access the three.js object of the 3d.io
let threeElem = model.components['io3d-data3d'].data3dView.threeParent
// create the bounding box
let bbox = new THREE.Box3().setFromObject(threeElem)
// Calculate the center-point offsets from the max and min points
const offsetX = (bbox.max.x + bbox.min.x)/2
const offsetY = (bbox.max.y + bbox.min.y)/2
const offsetZ = (bbox.max.z + bbox.min.z)/2
// apply the offset
model.setAttribute('position', {x:-offsetX,y:-offsetY, z:-offsetZ})
} );
scene.appendChild(model);
}