简体   繁体   English

x3d TimeSensor 在点击时暂停和恢复

[英]x3d TimeSensor pause and resume on click

I have a cute solar system implemented in x3d, and the thing I've been trying to do for a couple hours is to stop the rotation of a planet on a single click with the mouse, which "works" :我有一个在 x3d 中实现的可爱的太阳系,我几个小时以来一直试图做的事情是用鼠标单击一下即可停止行星的旋转,这“有效”:

<TimeSensor DEF='clockSol' id='clockSol' cycleInterval='80' loop='true' enabled='true' />
...
<OrientationInterpolator DEF='interRotacion'  key='0 0.25 0.5 0.75 1' keyValue='0 1 0 0  0 1 0 1.57079  0 1 0 3.14159  0 1 0 4.71239  0 1 0 6.28317'/>
...
<ROUTE fromNode='clockSol' fromField='fraction_changed' toNode='interRotacion' toField='set_fraction'></ROUTE>
<ROUTE fromNode='interRotacion' fromField='value_changed' toNode='RotacionSol' toField='set_rotation'></ROUTE>
*............*

That's the implementation of the sun animation.这就是太阳动画的实现。

The click event is as follows:点击事件如下:

document.getElementById('Sol').addEventListener('click',
        function() { 
            if(document.getElementById('clockSol').getAttribute('enabled') == 'true' )
                document.getElementById('clockSol').setAttribute('enabled', 'false');
            else
                document.getElementById('clockSol').setAttribute('enabled', 'true');
        }, false);

This effectively stops the animation as it disables the node, but when I resumen the animation, the cycle internally doesn't seem to have stopped.这有效地停止了动画,因为它禁用了节点,但是当我恢复动画时,内部循环似乎没有停止。 The effect is that when I click again, and resume the animation, the object blinks to a new position instead of resuming the rotation smoothly as it should be.效果是,当我再次单击并恢复动画时,对象会闪烁到新位置,而不是像应有的那样平滑地恢复旋转。

Any ideas how to do it?任何想法如何做到这一点?

The 'enable' field just stops the TimeSensor from sending time events, it does not 'stop' or 'pause' the sensor. “启用”字段只是阻止 TimeSensor 发送时间事件,它不会“停止”或“暂停”传感器。 What you want is to send the current time (available from the 'time' field or other locations) to the pauseTime field.您想要的是将当前时间(可从“时间”字段或其他位置获得)发送到 pauseTime 字段。 That will freeze the TimeSensor at it's current state.这会将 TimeSensor 冻结在其当前状态。 To resume send the current time to resumeTime.恢复发送当前时间到resumeTime。

See the full definition of TimeSensor at http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/time.html#TimeSensorhttp://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/time.html#TimeSensor 中查看 TimeSensor 的完整定义

X3DOM: http://doc.x3dom.org/author/Time/TimeSensor.html X3DOM: http ://doc.x3dom.org/author/Time/TimeSensor.html

If you are trying to pause and resume a TimeSensor in X3DOM note that this feature is not properly implemented in versions 1.8.1 and earlier.如果您尝试在 X3DOM 中暂停和恢复 TimeSensor,请注意此功能在 1.8.1 及更早版本中未正确实现。 See this GitHub Issue for details.有关详细信息,请参阅此 GitHub 问题

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

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