How to make sure the building is loaded in the right orientation? - autodesk-forge

I use the grid on the scene. The Building A (first image) setup is to be expected. But when I uploaded Building B, the orientation didn't match. Do I have to set it up in Revit ? or can I do it programatically.

Every model you load into the viewer is coming with its own metadata such as:
what is the "up" direction of the model
what is the offset of the model from the origin
what units is the model defined in
By default the viewer honors all these settings which means that, for example, if you load a Revit model that is defined in feet (and uses the Z-axis as the "up" direction), and then an Inventor model that is defined in meters (and uses the Y-axis as the "up" direction), the two models will have different scale and orientation.
To work around this issue, when loading (aggregating) multiple models in Forge Viewer, you can override any unit scaling, offset, or general 4x4 transformation that is applied to each model. For more details, look at https://forge.autodesk.com/blog/multi-model-refresher.

Related

Models created with `SceneBuilder` in `AggregatedView` disappear/reappear on rotate/zoom when loaded in combination with larger models

Custom objects disappear on every orbit zoom or rotation for about one second, then reappear again when added to a aggregated view in combination with a large model. While the objects are hidden, I can see that there is some reloading/rerendering of the other unrelated model going on.
Overlays (meshes rendered directly into threejs) obviously don't show this behavior.
I'm using viewer version 7.85 and the sample code from here: https://aps.autodesk.com/blog/custom-models-forge-viewer
modelBuilder.addFragment(sphereGeometry, sphereMaterial, sphereTransform);
Is there any way I can prioritize rendering of my custom model or disconnect the rendering from other loaded models?

Set Custom Viewpoint for Forge Model for a 360 kind-of centre location viewpoint

Referring to this article, the viewpoints from a model derivative URL manifest can be obtained. But I want to create a custom viewpoint in the model since I don't have those viewpoints. My requirement is below:
I would like to create a viewpoint such that it is centered at a point(aka the pivot) and I should be able to look around that point in all 360 degrees, while staying at that same point (and preventing the user from moving around the model freely if possible). I have the x,y,z viewpoint.
How can I create the aforementioned viewpoint?
How do I create an upward vector?
How do I get aspect, fov and orthoScale?
Also, I need to rotate the camera view based on event from another component. That component provides me data such as pitch, yaw and roll. How can I use that to change the camera view using the viewer.setView() method? Or is there any other method that needs to be used for changing the view with former parameters?
Details:
I have a nwd file loaded in the forge viewer.
I have the offset information available, if that plays a role in the above requirement.
Regarding the up vector, you can get that via viewer.avigation.getCameraUpVector()
For aspect, fov, and orthoScale, it's similar:
const aspect = viewer.navigation.getCamera().aspect;
cosnt fov = viewer.navigation.getVerticalFov();
const orthoScale = viewer.navigation.getCamera().orthoScale; //!<<< for Orthographic camera mode only

Autodesk Forge Viewer - Near and Far clipping issues

We recently updated one of our projects to use the latest version of the Autodesk Forge Viewer (v7.x).
In general, the migration went fine, however we noticed that for some models we have issues with the far cutting planes of the camera. I have figured out that this happens because the model contains some elements that are very far from the rest of the model and thus the bounding box of the entire model is magnitudes larger than it should be. This results in camera near = 1 and far = 10000. It seems that far should be higher in order to not hide parts of the model when zooming out.
For now, we have been able to workaround the issue be specifying a the "nearRadius" when loading the model, but since we have to set it to a value like 50 or 100 in order to not have far plane issues, we still have some near plane clipping issues.
I was wondering if there is any possibility to fix the model once it is loaded, so that the viewer uses a more realistic bounding box for the model. I have found out so far that during the load it already sets the variable verylargebbox to true and therefore is not using the nearRadius = 0 but either the passed value in the load options or 1. I was able to set nearRadius to a negative value to have the same behaviour as with nearRadius = 0, but due to the large bounding box of the model, we still experience clipping issues.
In order to fix the model I have already tried:
Excluding the ids of the elements that are far away with ids = [...] in the load options
Setting the visibility of these elements to off using setNodeOff()
Use NOP_VIEWER.navigation.fitBounds() to set the bounding box (as suggested in near and far calculation in Autodesk Forge Viewer)
However, getVisibleBounds() still returns the huge bounding box.
We would like to find a solution in which we don't need to modify the source model file before translating it to .svf.
The engineering team has confirmed that there are pathological cases where due to the bounding box of the model being extremely large, the computation of the near/far camera planes causes clipping artifacts. While this is being addressed, the suggested workaround is to set the near plane to 1:
viewer.impl.setNearRadius(1);

Forge Viewer - Cannot view multiple different models properly

I'm having trouble loading different models in the viewer. I suspect the problem comes from mixing up different units (meters and millimeters) in the models.
So I have 3 Models:
IFC 1, is using millimeters as unit.
When loading the SVF derrivative into the viewer, doing
console.log(model.getUnitScale(), model.getUnitString());
outputs:
0.001, mm
IFC 2, using millimeters as unit. Getting the same output as IFC 1
Obj. Model of a simple cube with center of cube at origin [0, 0, 0]. This does not seem to have any inherent unit.
When loading the SVF derrivative into the viewer, doing
console.log(model.getUnitScale(), model.getUnitString());
outputs:
1, null
In order to load the models with the right coordinates I use the following options:
IFC 1 and 2:
{
globalOffset: {x: 1000000, y: 100000, z: 7000},
sharedPropertyDbPath: doc.getPropertyDbPath(),
}
Obj:
let mat = new THREE.Matrix4();
mat.makeTranslation(1000000, 100000,7000);
{
placementTransform: mat,
sharedPropertyDbPath: doc.getPropertyDbPath(),
}
The rationale here is that the IFC models are located far away from the origin, while the Obj model is located at origin. Using globalOffset for the IFCs seems necessary to get them to align in the viewer, using placementTransform is necessary to put the Obj close to the IFC models.
I'm struggling with the following problems here:
Navigating the models is hard, when highlighting the Obj model, it seems like it is set to using y-up or something, making it hard to do orientation navigation for the other models.
When trying to change zoom, only the Obj seems to be affected. Could this be due to different scale settings?
EDIT 1:
Looks like making the Obj cube the same size as the other models fixes the zooming problem.
Also, if loading the IFC files first, the orientation navigation is right. It's only when loading the OBJ file first that we get the "y-up orientation" problem
Edit 2:
The orientation navigation problem can be fixed with viewer.navigation.setWorldUpVector(new THREE.Vector3(0,0,1), false);.
Is it possible to also control behavior like this globally instead always letting the different models set the behavior?
I think the last loaded model will always have precedence over any previously set world-up vector. So if you want to control the world-up globally, you'll need to use the viewer.navigation.setWorldUpVector method manually after all the models have been loaded.

Cesium czml change orientation of 3d model (gltf/glb) along with position in time

I have implemented a 3d model (cesium air) aircraft to move along a path. Its position is being changed based on time and the detailed data is available in the czml file under position attribute. However, I am not able to change the orientation of the aircraft along with path. The aircraft flies through the path but its heading , pitch and roll are constant. It does not pitch up with increase in height etc. How to implement the attitude changes using orientation attribute in the czml file or any other solution for the said problem?
You need to assign a VelocityOrientationProperty to each entity (aircraft) that needs to orient itself along the path. Unfortunately there's no CZML indicator for this, but you can assign it in client-side code after loading the CZML.
The Sandcastle Interpolation Demo shows VelocityOrientationProperty applied to a moving aircraft. Be sure to select a non-linear interpolation so it looks cool.