简体   繁体   English

如何在同一鼠标事件上同时旋转两个不同的 X3D 场景?

[英]How to rotate two diffrent X3D scenes at the same time and on the same mouse event?

do i need some java script or jQuery for this ?为此我需要一些 java 脚本或 jQuery 吗? I'm just asking because i need something like thishttp://examples.x3dom.org/cadViewer/slimViewerConrod/index.html .我只是问,因为我需要这样的东西http://examples.x3dom.org/cadViewer/slimViewerConrod/index.html As you can see you can rotate the main object (main scene) with the axes(helper scene) together with the same mouse event.如您所见,您可以使用轴(辅助场景)以及相同的鼠标事件旋转主对象(主场景)。 I'm relative new to X3DOM and i just wanted to ask because i have no clue how it works.我对 X3DOM 比较陌生,我只是想问,因为我不知道它是如何工作的。 If it helps, my X3D scenes are :如果有帮助,我的 X3D 场景是:

<X3D id="x3dElement"> <Scene id='scene'>
<Viewpoint id="part7" position=" 0.028793486820279934 0.06097637432245687 -0.009845212995355457" description="camera"></Viewpoint> <Group id='alles' children='gr1 gr2 gr3' render='true'> <Group id='gr1' children='gr2 gr3' render='true'> <transform translation='0 0 0' rotation='0 0 0 0'> <Inline nameSpaceName="case" mapDEFToID="true" url="case1.x3d"/> </transform>
<transform translation='0 0.02 0.031' Rotation='0.86603 0 0 0'> <transform Rotation='0 0 0 0'> <Inline nameSpaceName="switch" mapDEFToID="true" url="switch1.x3d"/> <Inline id="b_sauele" nameSpaceName="inline" mapDEFToID="true" url="inlineSrc/bSauele/bolt1.x3d" onload="init()" ></Inline>
</transform> </transform> <transform translation='-0.03 -0.0155 0.024' rotation='0 1 0 1.5708'> <transform rotation='1 0 0 3.1416'> <Inline nameSpaceName="socket" mapDEFToID="true" url="socket2.x3d"/> </transform> </transform> <transform translation='-0.03 -0.0155 -0.024' rotation='1 0 0 3.1416'> <transform rotation='0 1 0 1.5708'> <Inline nameSpaceName="socket" mapDEFToID="true" url="socket2.x3d"/> </transform> </transform> <transform translation='0.03 -0.0155 -0.024' rotation='1 0 0 3.1416'> <transform rotation='0 1 0 1.5708'> <Inline nameSpaceName="socket" mapDEFToID="true" url="socket2.x3d"/> </transform> </transform> <transform translation='0.03 -0.0155 0.024' rotation='1 0 0 3.1416'> <transform rotation='0 1 0 1.5708'> <Inline nameSpaceName="socket" mapDEFToID="true" url="socket2.x3d"/> </transform> </transform> </Group> <Group id='gr2' children='gr3' render='true'> <transform translation='0 -0.018 -0.01988' Rotation='0 0 0 0'> <Inline nameSpaceName="head" mapDEFToID="true" url="head1.x3d"/> </transform> </Group> <Group id='gr3' render='true'> <transform translation='0 -0.05 -0.0275' Rotation='0 0 0 0'> <Inline nameSpaceName="shaft" mapDEFToID="true" url="shaft2.x3d"/> </transform> <transform translation='0.0129 0.0129 -0.009' Rotation='0 1 0 3.1416'> <Inline nameSpaceName="bolt" mapDEFToID="true" url="bolt1.x3d"/>
</transform> <transform translation='-0.0129 0.0129 0.009' Rotation='0 1 0 3.1416'> <Inline nameSpaceName="bolt" mapDEFToID="true" url="bolt1.x3d"/> </transform>
</Group>
</Group>
</Scene> </x3d>
<X3D id='CoordinateAxes' showStat='false' showLog='false'> <scene id="helper_scene"> <viewpoint id="coordinateAxesViewpoint" centerOfRotation='0 0 0' position='0 0 3'></viewpoint> <Inline mapDEFToID="true" nameSpaceName="CoordinateAxes" url="data/CoordinateAxes.x3d"></Inline> </scene> </X3D>'>

I personally solved it the following way:我个人是通过以下方式解决的:

X3DomAdapter.syncViews = function(firstView, secondView) {


    function sync(firstView, SecondView) {


        var firstViewarea = $('#' + firstView)[0].runtime.canvas.doc._viewarea;
        var secondViewarea = $('#' + SecondView)[0].runtime.canvas.doc._viewarea;

        if (sync.firstViewmatrix === undefined || sync.secondViewmatrix ===
            undefined) {
            sync.firstViewmatrix = firstViewarea.getViewMatrix();
            sync.secondViewmatrix = secondViewarea.getViewMatrix();
            sync.firstChanged = false;
            sync.secondChanged = false;
            return;
        }

        sync.firstChanged = !(firstViewarea.getViewMatrix().equals(sync.firstViewmatrix));
        sync.secondChanged = !(secondViewarea.getViewMatrix().equals(sync.secondViewmatrix));

        if (sync.firstChanged && InputProcessor.active_view === firstView) {
            secondViewarea.animateTo(firstViewarea.getViewMatrix(),
                secondViewarea._scene.getViewpoint(), 0);
            sync.firstViewmatrix = firstViewarea.getViewMatrix();
            sync.secondViewmatrix = secondViewarea.getViewMatrix();
        } else if (sync.secondChanged && InputProcessor.active_view ===
            secondView) {
            firstViewarea.animateTo(secondViewarea.getViewMatrix(),
                firstViewarea._scene.getViewpoint(), 0);
            sync.firstViewmatrix = firstViewarea.getViewMatrix();
            sync.secondViewmatrix = secondViewarea.getViewMatrix();
        }
    }

    return setInterval(function() {
        sync(firstView, secondView);
    }, 50);
};

Applied to your example you should be able to call应用于您的示例,您应该可以调用

X3DomAdapter.syncViews("scene", "helper_scene");

You may want to replace the jQuery calls and pass in DOM nodes directly through the function plus make this a clean class that stores the states.您可能希望替换 jQuery 调用并直接通过函数传入 DOM 节点,并使其成为存储状态的干净类。 In my use case I just wanted to sync two x3dom-views (splitscreen mode) and forget about it.在我的用例中,我只想同步两个 x3dom 视图(分屏模式),然后忘记它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM