How to do Plain Select - autodesk-forge

I'm using the Autodesk Forge Viewer with the Edit2D tools to allow the user to draw and modify polygons. I have this working with the polygonTool and polyEditTool. However, I also have a use case where the user needs to be able to select polygons but NOT make any modifications. As far as I can tell, the polyEditTool and moveTool allow the user to select polygons but they also allow them to modify. If I deactivate all tools they can't select, and the standard viewer selection doesn't seem to allow you to select the Edit2D shapes.
How can I get a selection only mode?

The Edit2D extension does not have any built-in option to only enable selection but not editing of shapes, and the workaround you suggested earlier looks reasonable.
Another option to consider would be implementing a custom subclass of EditToolBase (you could use the implementation of the official Edit2D tools as a reference) that would only allow selection, and nothing else.

Ok well it seems a little convoluted but I found a way that seems to work. The move tool allows you to select and move, but each shape has a movable property. If you set movable to false on the shape it can still be selected but can't be moved. So if you are switching between the editing and selection only modes you would have to change that property by iterating over the shapes on the layer and set it each time. Here is my implementation:
for (const shape of state.editor.defaultContext.layer.shapes) {
// #ts-ignore
shape.movable = tool !== DrawTools.Select;
}
Note that TypeScript definitions don't seem to include the movable property so I have to ignore the error.
This seems to work but if there is a better solution out there I would be happy to accept a better answer.

Related

Is it possible to set snap settings?

I'm using the Autodesk Forge viewer v7 using the Edit2D tool. This question is specifically about the snapping functionality. It is currently working but a bit overzealous... It seems to have all of the possible snaps on (endpoint, along line, intersections, centers, etc.). It also seems to snap to layers that I have hidden.
Is there a way to set the snaps that are on and off? Also is there a way to limit the layers that it snaps to? I was looking for possibly a method that will tell me the object(s) it's trying to snap to and the type of snap and let me determine if that's a viable snap point and return true/false or something like that but I couldn't find one. Is there a way to do this?
EDIT
I did find setSnapFilter but it doesn't seem to do anything. I have this implementation in my code:
// #ts-ignore
e.defaultContext.snapper.sheetSnapper.setSnapFilter((e) => {
console.log(e);
return false;
});
However, I never get a console log happening. I have tried this on both the sheet snapper and the layer snapper and I've tried returning both true and false and none of them are ever called or make any difference to the snapping.
Good catch! The context.snapper.sheetSnapper object does have a setSnapFilter method you can override. Unfortunately, this filter is only invoked in the Snapper#onMouseMove method, and the Edit2D extension bypasses this method. That's why overriding the method has no effect. Let me pass this info to the engineering team for consideration.

Customize Forge BimWalkExtension keyboard inputs

I want to change the keys used in bimwalkExtensions to move in 3D model.
I did not find a method to override keycontrols in the doc
Current configuration
There's no option for overriding for now.

Autodesk Forge Viewer: how to set object occlusion

I'm playing around with the Autodesk forge viewer and adding custom elements, like it is done in the Autodesk's scene builder example.
I am looking for a possibility to set the "visibility" of one of the new objects - e.g. when moving around the camera, the green cube should remain on it's 3D-position but should not be occluded by any other object (like it is somehow in blue with outline when it is selected). Or maybe even better: if it is covered by another object, it should shine through (with configurable opacity).
Unfortunately after discussing with Engineering it's not yet possible - will continue the conversation to see if we could come up with a workaround for the upcoming releases ...
Like I suggested in the comments try append your geometry to Viewer3DImpl.sceneAfter for the time being (which will be publicly documented and exposed as Viewer3D.sceneAfter in a couple of weeks) or an overlay. Then setting depthTest to false should do what you want...
The choice of sceneAfter or an overlay depends on how you want the objects to be drawn during progressive rendering. sceneAfter is only drawn once at the end of everything else. Overlays are redrawn for each progressive frame...

how to change a CesiumJS viewer's baselayer url

i am using a CesiumJS instance to display a base map of the earth using a imageryProvider from source A.
var viewer = new Cesium.Viewer('cesiumContainer', imageryProvider:providerA);
Now while using the Viewer I would like to be able to change this map to get images from providerB at a certain event.
I tried:
viewer.scene.imageryLayers.get(0).imageryProvider.url = providerB.url
However that does not seem to work and also feels quite like hack anyway.
I could not find anything in Cesium's documentation .
Is this at all possible without restarting / recreating the viewer instance?
I know that there is a Cesium.BaseLayerPicker (https://cesium.com/docs/cesiumjs-ref-doc/BaseLayerPicker.html)
However I do not see what method this picker calls on "select" )
Thanks a lot.
The BaseLayerPicker widget calls this code when the user selects a new layer.
There's a lot of boilerplate widget management in that block of code, but for your sake, only a couple of the lines are critical. First, the old existing active imagery layer is searched for, and removed:
imageryLayers.remove(layer);
Then, a new imagery provider is constructed and added at index 0, the first position, which is the base imagery layer:
imageryLayers.addImageryProvider(newProviders, 0);
You can directly change the URL of the provider but you should also change appropriate parameters("layers" in case of WMS, "layer", "style", "format", "tileMatrixSetID " ... in case of WMTS) depending on the type of provider(WMS or WMTS).

How to use the Selection Reticle in CesiumJS

In any of the Cesium sandcastle examples with entities, clicking an entity shows a green square reticle type thing.
My question is, what is it? I want to implement something that behaves similarly but can't find anything about it in the code base or the documentation.
Note: I have disabled the selection widget in my application.
You can see the reticle thing I am talking about in the attached photo.
You mention:
Note: I have disabled the selection widget in my application.
I'm guessing you have a typo or something, because that green reticle is indeed the SelectionIndicator. It can be disabled by setting a constructor option on the Cesium.Viewer, namely:
var viewer = new Cesium.Viewer('cesiumContainer', {
selectionIndicator: false
});
Check your code to see if you really set this option correctly in the constructor.
After the viewer is constructed, it's a bit late to try to turn it off, since it binds into events generated by viewer.selectedEntity changing values. By default, the selectedEntity gets the SelectionIndicator unless the viewer was constructed without one.