Reputation: 406
I am using the Autodesk Forge viewer v7.* in a project. In this project I have to show multiple 2d models derriving from .dwg
files uploaded to BIM360. I can load in each model and they are stacked on top of each other, but their alignment seems to be totally wrong. I have tried all sorts of loadOptions
and also tried to post adapt the total transformation of the model, but their alignment remains to look random. Here is a part of the code:
onDocumentLoaded = (doc, id, resolve, reject) => {
// A document contains references to 3D and 2D geometries.
let geometries = doc.getRoot().search({ 'type': 'geometry' })
if (geometries.length === 0) {
console.error('Document contains no geometries.')
return
}
// Choose any of the avialable geometries
let initGeom = geometries[0]
let ops = {
placementTransform: new window.THREE.Matrix4(),
modelSpace: true,
globalOffset: { x: 0, y: 0, z: 0 },
applyRefPoint: true,
isAEC: true, // to align the models,
}
// Load the chosen geometry
let svfUrl = doc.getViewablePath(initGeom)
this.viewerApp.loadModel(svfUrl, ops, (model) => this.onModelLoaded(model, id, resolve, reject), (error) => reject(error))
}
As you see, I tried a few loadoptions, but they all do not seem to matter when loading 2d models. they do have an impact on 3d (.ifc, .rvt, .nwd) models.
I also tried to update the transformation after the model has been loaded:
transformModel = (viewer, model, transform) => {
let translation = new window.THREE.Vector3();
let rotation = new window.THREE.Quaternion();
let scale = new window.THREE.Vector3();
transform.decompose(translation, rotation, scale);
function transformFragProxy(fragId) {
var fragProxy = viewer.impl.getFragmentProxy(
model,
fragId);
fragProxy.getAnimTransform();
fragProxy.position = translation;
fragProxy.scale = scale;
fragProxy.quaternion._x = rotation.x;
fragProxy.quaternion._y = rotation.y;
fragProxy.quaternion._z = rotation.z;
fragProxy.quaternion._w = rotation.w;
fragProxy.updateAnimTransform();
}
var fragCount = model.getFragmentList().fragments.fragId2dbId.length;
//fragIds range from 0 to fragCount-1
for (var fragId = 0; fragId < fragCount; ++fragId) {
transformFragProxy(fragId);
}
}
onModelLoaded = (model, id, resolve) => {
if (!model.isLoadDone()) {
// wait for loading complete, 2d models are not completely loaded even though onModelLoaded is called
setTimeout(this.onModelLoaded, 0.1, model, id, resolve)
} else {
// done loading
// force transformation
this.transformModel(this.viewerApp, model, new window.THREE.Matrix4());
this.viewerApp.impl.sceneUpdated(true);
// .. rest op code here
}
}
Upvotes: 0
Views: 841
Reputation: 5342
If all else fails try apply translation manually using the placementTransform
option:
const mat4 = new THREE.Matrix4()
mat4.makeTranslation(10,10,10)
//...
NOP_VIEWER.loadDocumentNode(document, geometry, {
placementTransform: mat4,
keepCurrentModels: true
})
Upvotes: 1