A DEv
A DEv

Reputation: 340

forge Viewer - How can we add CAMERA_CHANGE_EVENT for svg markups?

How can we add listener CMERA_CHANGE_EVENT for markups drawn on a viewer? If we create a label against a dbid, we can store its coordinates and can apply worldToClient on coordinates to get new coordinates. But how this work for svg markups?

In my application, two ways user can associate rfi information. 1. by simply clicking a model obkject/dbid, I will let user add some textual information through a textbox and attach it as a label with that selected object/dbid. this is working as label moves along with the selected object while camer rotation event.

Technically to get this done, am using function getObjPosition to get coordinates of dbid and store it in a label control and I pull those values during camera change event and updates current client coordinates using below function getClientCoordinates

function getObjPosition(dbId) {
    const model = viewer.model;
    const instanceTree = model.getData().instanceTree;
    const fragList = model.getFragmentList();

    let bounds = new THREE.Box3();

    instanceTree.enumNodeFragments( dbId, ( fragId ) => {
        let box = new THREE.Box3();
        fragList.getWorldBounds( fragId, box );
        bounds.union( box );
    }, true );

    const position = bounds.center();
    return position;
}

function getClientCoordinates(positionCoordinates){
    var screenpoint = viewer.worldToClient(
                    new THREE.Vector3(positionCoordinates.x,
                                      positionCoordinates.y,
                                      positionCoordinates.z,));
    return screenpoint
}

  1. In this scenarion, I am giving user to draw cloud markup and associate a label for the tetual information user enter on selection of markup. So to get coordinates am using below code
    var pos = markup.markups[0].getClientPosition(); and tag the label with this created markup. It works. For camera change event, the markups itself lose its position, so not sure how I will attach to the model and apply coordinates for label. Here another worrying part is, how I should get all the drawn markups on the model during camera change event

Hope my question is clear now.

Upvotes: 0

Views: 517

Answers (1)

Bryan Huang
Bryan Huang

Reputation: 5342

The CAMERA_CHANGE_EVENT works for the entire scene and whenever navigation occurs so there's no way to bind this to any specific object and it makes little sense to do so either.

If you are trying to move SVG markups to their new corresponding coordinates post navigation simply store their original world positions (using clientToWorld) before navigation and then use worldToClient to get their new coords post navigation.

Upvotes: 1

Related Questions