x3d TimeSensor pause and resume on click

989 views Asked by At

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" :

<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?

2

There are 2 answers

0
Daly Realism On BEST ANSWER

The 'enable' field just stops the TimeSensor from sending time events, it does not 'stop' or 'pause' the sensor. What you want is to send the current time (available from the 'time' field or other locations) to the pauseTime field. That will freeze the TimeSensor at it's current state. To resume send the current time to resumeTime.

See the full definition of TimeSensor at http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/time.html#TimeSensor

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

0
user1281657 On

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. See this GitHub Issue for details.