伪造查看器 - 我们如何为 svg 标记添加 CAMERA_CHANGE_EVENT? [英] forge Viewer - How can we add CAMERA_CHANGE_EVENT for svg markups?

本文介绍了伪造查看器 - 我们如何为 svg 标记添加 CAMERA_CHANGE_EVENT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何为在查看器上绘制的标记添加侦听器 CMERA_CHANGE_EVENT?如果我们针对 dbid 创建一个标签,我们可以存储它的坐标,并且可以在坐标上应用 worldToClient 以获得新坐标.但这对 svg 标记有何作用?

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?

在我的应用程序中,用户可以通过两种方式关联 rfi 信息.1. 只需单击模型对象/dbid,我将让用户通过文本框添加一些文本信息,并将其附加为带有所选对象/dbid 的标签.这是在相机旋转事件时标签与所选对象一起移动的工作.

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.

从技术上讲,要完成此操作,我使用函数 getObjPosition 获取 dbid 的坐标并将其存储在标签控件中,然后在相机更改事件期间提取这些值并使用以下函数 getClientCoordinates 更新当前客户端坐标

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. 在这个场景中,我让用户绘制云标记并为用户在选择标记时输入的基本信息关联一个标签.所以要获取坐标我使用下面的代码
    var pos = markup.markups[0].getClientPosition();并使用此创建的标记标记标签.有用.对于相机更改事件,标记本身会丢失其位置,因此不确定我将如何附加到模型并为标签应用坐标.这里另一个令人担忧的部分是,我应该如何在相机更换事件期间获得模型上的所有绘制标记

希望我的问题现在清楚了.

Hope my question is clear now.

推荐答案

CAMERA_CHANGE_EVENT 适用于整个场景,无论何时发生导航,因此无法将其绑定到任何特定对象,并且几乎没有这样做也有意义.

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.

如果您尝试将 SVG 标记移动到导航后的新对应坐标,只需在导航前存储它们的原始世界位置(使用 clientToWorld),然后使用 worldToClient 来获取他们的新坐标发布导航.

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.

这篇关于伪造查看器 - 我们如何为 svg 标记添加 CAMERA_CHANGE_EVENT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆