我有一个可爱的太阳能系统在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>
*............*
这是太阳动画的实现。
点击事件如下:
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);
这有效地停止了动画,因为它禁用了节点,但是当我恢复动画时,内部循环似乎没有停止。 结果是,当我再次单击并恢复动画时,对象会闪烁到新位置,而不是按原样顺利恢复旋转。
任何想法怎么做?
答案 0 :(得分:1)
'enable'字段只是停止TimeSensor发送时间事件,它不会“停止”或“暂停”传感器。您想要的是将当前时间(可从“时间”字段或其他位置获得)发送到pauseTime字段。这将冻结TimeSensor的当前状态。要恢复发送当前时间以恢复时间。
在http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/time.html#TimeSensor
查看TimeSensor的完整定义答案 1 :(得分:0)
如果您尝试在X3DOM中暂停和恢复TimeSensor,请注意,此功能在1.8.1及更低版本中未正确实现。有关详细信息,请参见this GitHub Issue。