Search code examples
autodesk-forgeautodesk-viewer

Is It possible to move the avatar programmatically or specify position in Autodesk.AEC.Minimap3DExtension


Autodesk.AEC.Minimap3DExtension provides a 3d and 2d sync forge viewer where a user can use 2d viewer and move the avatar to navigate. In order to navigate user has to move the avatar or a dot icon in 2d viewer to navigate in 3d model.

My question is where is there any possibility where I can send the set of coordinates which are with me and can I move the avatar programmatically so that user don't have to do so.

here is any example why I am asking so, I have a geometry on my forge viewer which is on 2D and I am looking to make a first person view over that geometry. So If I have all the points of geometry I want to make it use with Autodesk.AEC.Minimap3DExtension so that I can move first person to different views

here is the sample I am rereferring to link

I had been following this wonderful blog link with the help of this I am aware little bit aware how to work with 2dto3d here in above link

const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model, 
viewer3D.model);

the above line of code gives me worldPos with which a geometric point is created in the 3d viewer in spite of creating a geometry how can I use to show view of that particular place

basically in this below line of code which transits camera from one position to another

viewer.navigation.setRequestTransition(true, newPos, newTarget, 
viewer.navigation.getHorizontalFov());

Solution

  • I'm glad you like the blog post :)

    After reading the question I have the impression that you have already answered it yourself. If you have some kind of a geometry, let's say a polyline, overlaid on top of the 2D drawing, you can use the same logic explained in the blog post, but when calling viewer.hitTest, instead of passing in some mouse coordinates, you would just supply one of the points of your polyline.

    Instead of:

    viewer2D.container.addEventListener('click', function (ev) {
        const intersection = viewer2D.hitTest(ev.clientX, ev.clientY);
        viewer3D.isolate([]);
        if (intersection) {
            viewer3D.isolate(intersection.dbId);
            const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model, viewer3D.model);
            if (worldPos) {
                let mesh = new THREE.Mesh(geometry, material);
                mesh.position.set(worldPos.x, worldPos.y, worldPos.z);
                viewer3D.overlays.addMesh(mesh, 'indicator-scene');
            }
        }
    });
    

    It could look something like this:

    function moveCameraToPointOnSheet(x, y) {
        const intersection = viewer2D.hitTest(x, y);
        if (intersection) {
            const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model, viewer3D.model);
            if (worldPos) {
                const eyeVec = viewer3D.navigation.getEyeVector();
                const newPos = worldPos;
                const newTarget = newPos.clone().add(eyeVec);
                const fov = viewer3D.navigation.getHorizontalFov();
                viewer3D.navigation.setRequestTransition(true, newPos, newTarget, fov);
            }
        }
    });