原始 MediaWiki 页面

我知道编辑这个网站吗?

3D 查看器 › 自定义行为

自迁移出 MediaWiki 以来,本页内容尚未经过审查。如果您愿意帮忙,请查看帮助指南

如何捕获和处理 3D 上的事件

您可以下载本操作指南here的示例源代码。

本指南展示了如何捕获和处理鼠标或按键事件:

在您宇宙的地方,调用setInteractiveBehavior(...)

univ = new Image3DUniverse();
univ.show();
Content c = univ.addCustomMesh(...);

// this is necessary for catching the mouse events
univ.setInteractiveBehavior(new CustomBehavior(univ, c));

然后创建一个扩展 ij3d.behaviors.InteractiveBehavior 的新(可能是内部)类。

private class CustomBehavior extends InteractiveBehavior {

    private Content c;
    
    CustomBehavior(Image3DUniverse univ, Content c) {
        super(univ);
        this.c = c;
    }

    public void doProcess(MouseEvent e) {
        if(!e.isControlDown() ||
            e.getID() != MouseEvent.MOUSE_PRESSED) {
            super.doProcess(e);
            return;
        }
        // Get the point on the geometry where the mouse
        // press occurred
        Point3d p = univ.getPicker().
            getPickPointGeometry(c, e.getX(), e.getY());
        if(p == null)
            return;

        IJ.showMessage("Picked " + new Point3f(p));
    }
}

在上面显示的示例中,捕获操作了按住控制键的鼠标。Universe 的 Picker 对象用于获取拾取点(即鼠标桌面与对象相交的点)。在示例中,该坐标点仅显示在屏幕上。

重要:
必要时请小心调用super.process(...),根据需要保持正常(旋转、平移)行为。