动态添加新模型到查看器 [英] Dynamic adding new models into viewer

查看:25
本文介绍了动态添加新模型到查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个网页,其中左侧将显示模型缩略图,而在右侧,我需要显示所述模型.我找到了最初加载多个模型的解决方案,如下所示:

I want to create a web page where in the left side, the model thumbnail will be displayed and in the right side, I need to show said model. I found the solution to initially load multiple models, as seen below:

    window.addEventListener('DOMContentLoaded', () =>
        loadModels([
            { urn: "urn1", xform: { x: -60, y: 0, z: 0 } },
            { urn: "urn2", xform: { x: 60, y: 0, z: 0 } },
            { urn: "urn3", xform: { x: 50, y: 0, z: 50 } },
        ])
    );

并使用以下函数

       Autodesk.Viewing.Initializer(viewerOptions, () => {

            const div = document.getElementById('forgeViewer');
            viewer = new Autodesk.Viewing.Private.GuiViewer3D(div, { extensions: ["DragControlExtension"] });
            viewer.start();
            urns.map((m) => {
                Autodesk.Viewing.Document.load(`urn:${m.urn}`, (doc) => {
                    var viewables = doc.getRoot().getDefaultGeometry();
                    viewer.loadDocumentNode(doc, viewables, {
                        placementTransform: (new THREE.Matrix4()).setPosition(m.xform),
                        keepCurrentModels: true,
                        globalOffset: { x: 0, y: 0, z: 0 }
                    })
                        .then(onLoadFinished);
                });

            })
        });

现在,我的问题是:我可以在运行时拖动新模型吗".另外,是否可以通过拖动来移动现有模型.

Now, my question is: 'Can I drag a new model at runtime'. Also, is it possible to move the existing model by dragging.

Autodesk.Viewing.Initializer 之后,是否有任何可以帮助的事件或方法?(一些参考也会有所帮助.)

After Autodesk.Viewing.Initializer, is there any event or method which may help? (Some reference will also help.)

推荐答案

加载模型后,您可以通过修改其 placementTransform 来移动它 - 例如如果 secondModel 是您刚刚添加的并且正在尝试移动,例如键盘上的键,你可以这样做:

Once you loaded the model you can move it around by modifying its placementTransform - e.g. if secondModel is the one you just added and are trying to move around with e.g. keys on the keyboard, you could do this:

document.onkeydown = event => {
  if (!event.shiftKey)
    return;

  if (event.code === "ArrowRight") {
    let tr = secondModel.getPlacementTransform();
    // move along X axis
    tr.elements[12] += 1;
    secondModel.setPlacementTransform(tr);
  }

  if (event.code === "ArrowLeft") {
    let tr = secondModel.getPlacementTransform();
    // move along X axis
    tr.elements[12] -= 1;
    secondModel.setPlacementTransform(tr);
  }
};  

您可以在此处找到有关它的更多详细信息:https://forge.autodesk.com/blog/dynamic-model-placement

You can find more details about it here: https://forge.autodesk.com/blog/dynamic-model-placement

这篇关于动态添加新模型到查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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