3drepo / 3drepo.io

3D Repo web server
http://www.3drepo.io
GNU Affero General Public License v3.0
95 stars 38 forks source link

[2D MVP] Milestone 3: Step 3 - Planes height calibration #4911

Closed sanmont3drepo closed 2 months ago

sanmont3drepo commented 7 months ago

Description

In step 3 of the calibration wizard the user will be asked to set the vertical limits of the calibration. In this step the 3d viewer occupies all the content.

General flow - The viewer starts in calibration select mode (view unity integration for details) - If this a re-calibration we should set the vertical planes to the previous calibration - The user clicks on an object in the viewer and then the calibration mode changes to plane, activating **spatial boundaries** button, and selecting the appropriate top/bottom plane button. - The user adjusts the height of the planes (switching as will between the top and bottom plane) - When the user is satisfied with it they click *confirm*
Toolbar Toolbar will have **Home**, **Perspective/Ortographic view**, **Turntable/Helicopter view**, **sectioning**, **attribute data** as the previous steps plus the **Spatial boundaries** button. image ### Note: the 3d vector button shouldn't be there, the figma file is wrong. When activating the **Spatial boundaries** button, two buttons should appear in the subtoolbar and a information box showing the height of the spatial boundary. image Clicking on **bottom plane** selects the bottom plane to adjust it, while clicking **top plane** does the same thing with the top plane. The information button with the height data should be reflected in real time (look at unity integration). The value is in meters or feet depending of the units of the container/federation.
Unity integration - For starting the spatial boundaries mode _UnityUtil._**setCalibrationToolMode("Vertical")** should be called. - For re-calibration use _UnityUtil._**setCalibrationToolVerticalPlanes(bottom, top)** - For selecting an object for the planes to adjust we need to subscribe to the object selection and then call _UnityUtil._**setCalibrationToolFloorToObject(**_{teamspace}, {container/federationId}, {objectId}_**)** - Provide a drawing to be shown on the planes. For this a DOM object is needed. To test this API before the actual drawing is available, create a placeholder, such as an node, like so: ``` var i = new Image() i.crossOrigin = "anonymous" i.src = "https://as2.ftcdn.net/v2/jpg/02/77/71/45/1000_F_277714513_fQ0akmI3TQxa0wkPCLeO12Rx3cL2AuIf.jpg" ``` (Make sure the image has fully loaded before handing it to the API. This is because the call will immediately read a couple of properties of the image, such as the width, which cannot be changed later.) Then call `setCalibrationToolDrawing`, like so: `UnityUtil.setCalibrationToolDrawing(i, [0, 0, 1, 0, 0, 1])` The array defines the rectangle of the image in the ZX plane as the positions of three corners in Project coordinates. The above command requests that the node `i` be shown in a rectangle with the bottom left corner at `[0,0]`, the bottom right corner at `[1,0]` and the top left corner at `[0,1]` - that is, a unit square starting at the origin. (As such, that exact command should only be used with very small models, e.g. one unit cube). - For selecting the top plane for adjusting (while in vertical mode) _UnityUtil._**selectCalibrationToolUpperPlane()** - For selecting the bottom plane for adjusting (while in vertical mode) _UnityUtil._**selectCalibrationToolLowerPlane()** - Every frame the user adjusts either of the planes using the gizmo, the viewer will call `UnityUtil.calibrationPlanesChanged`. This method will be passed an object containing the height of each plane in Project coordinates. ``` { "lower": -1.4685417413711548, "upper": 0 } ``` You can use the difference between both planes to show the height in the information button in the toolbar. This is the data that will be saved afterwards.
Calibration format ```js { // this will most likely live in the drawing history calibration: { horizontal: { model: [[0,0,0], [1,1,1]], drawing: [[0,0], [1,1]] }, verticalRange: [ 0, 10], // considering different container can be in different units we'd need to make sure we know how to scale it when viewing on a different model. units: "m" } } When showing the calibration take in consideration that the units might be different from the units in the container. Calculate to compensate if necessary. ```

Goals

Tasks

Related Resources

MockUp

sebjf commented 3 months ago

Hi @The-Daniel,

After having set the planes if the user cancel's calibration and re-enters a calibration the clipping from the previous attempt appears (but with no gizmo)

TLDR: Made a couple of Unity tweaks - should be resolved now.

This was triggered by the SetCalibrationToolVerticalPlanes call that comes from here...

image

In brief, whenever the planes change, Unity will update the clipping planes for the selected level. However, when the tool first starts, nothing is selected, so no clipping planes are shown. After the user selects one of the planes, it remains selected even after they cancel the wizard however, so as soon as the wizard starts up again and calls SetCalibrationToolVerticalPlanes, the clipping planes are updated for that level, even though the tool is off (hence why the gizmo isn't seen).

Additionally, if no planes are selected, calling SetCalibrationToolVerticalPlanes will reset the clip planes. For example - completely outside the 2D viewer or calibration wizar - if I use the clip tool to set a box section, then call SetCalibrationToolVerticalPlanes with [0,0], it will remove my clip planes.

The fix for this is to make Unity deselect all planes when when the tool is deactivated, and also gate the clip plane updates based on whether the tool is active in Vertical Mode. Now, calling SetCalibrationToolVerticalPlanes will update the planes inside the tool, but they wont manifest on the clip planes until the tool is activated (and the users clip planes are saved).

I have made these changes, and pushed an updated version of Unity to #4911.

I can now call the following sequence of commands and see that it behaves correctly,

UnityUtil.setCalibrationToolMode("Vertical")
UnityUtil.selectCalibrationToolLowerPlane() // And move the plane...
UnityUtil.setCalibrationToolMode("None") // Users planes are restored
UnityUtil.setCalibrationToolVerticalPlanes(0,0) // Users planes don't change
UnityUtil.setCalibrationToolMode("Vertical") // No clipping is visible (because no plane is selected)
UnityUtil.selectCalibrationToolLowerPlane() // Plane clips at 0,0, because we reset the last levels position

I did notice however that the wizard currently deletes the users clipping planes, before the vertical mode is activated...

image

...which prevents the users clip planes being restored when the wizard is cancelled or completes. Not sure if this is intentional!

sebjf commented 3 months ago

if after cancelling and re-entering the user were to carry on with the calibration the image does not load onto the plane.

This one is a little harder, so far I have been unable to reproduce.. does/did it occur every time? Does it still occur with the latest viewer?

The-Daniel commented 3 months ago

@sebjf the deletion of the clipping planes is to remove the clipping set in the previous steps, as the third step removes the regular clipping tool from the toolbar. Without that call you can get something like this... image Is there a better unity method for removing both the gizmo and the actually clipping without deleting it so it can be restored later?

carmenfan commented 3 months ago

@sebjf @The-Daniel

Unless there's compelling user stories to keep the clippnig planes and restoring them (in which case let me know I haven't really thought this through!), I suggest we just reset them as Dan's done to simplify the whole thing.

Bottom line is we don't know what the use case is atm so let's do the simplest thing that make sense without troubling ourselves with additional work

sebjf commented 3 months ago

Is there a better unity method for removing both the gizmo and the actually clipping without deleting it so it can be restored later?

I thought the idea was that the users' clipping planes remained during vector calibration (so if they wanted to see a floor, they could). In which case keeping the clipping on, but hiding the box and gizmo, is just whatever happens when you toggle the clip edit mode on the toolbar.

The vertical mode will save and restore the user's clip planes on its own when its activated and deactivated.

Unless there's compelling user stories to keep the clippnig planes and restoring them (in which case let me know I haven't really thought this through!), I suggest we just reset them as Dan's done to simplify the whole thing.

Also fine with this 😄, just remarking in case the behaviour was accidental - the calibration tool code doesn't expect the planes to be in one state either way.

carmenfan commented 3 months ago

I thought the idea was that the users' clipping planes remained during vector calibration (so if they wanted to see a floor, they could). In which case keeping the clipping on, but hiding the box and gizmo, is just whatever happens when you toggle the clip edit mode on the toolbar.

Yes that's what I wanted for the horizontal behaviour, and also kind of makes sense for vertical other than it may conflict with the vertical height gizmo. But considering of how long this is taking and the fact that we still don't know how the user wants to use it - Maybe we can review when the whole thing is put together and got some feedback 🙈

sebjf commented 3 months ago

Hi @The-Daniel, also just to check as well, are you happy with the preview planes colours APIs?

sanmont3drepo commented 2 months ago

Merged into main branch