[x3d-public] [x3dom-users] delay before animation

Leonard Daly web3d at realism.com
Fri Sep 25 20:54:04 PDT 2015

On 9/25/2015 5:52 PM, Andreas Plesch wrote:
> I would like to automatically start a cyclic animation but after some initial delay (say 5s). My first approach was to use a looping timesensor with a startTime. However, setting a startTime on a looping timesensor turns out to be ignored since looping automatically activates the timesensor right after it is loaded (added to the scenegraph?). And active timesensors ignore attempts to set the startTime.


The StartTime field accepts any SFTime value. If the StartTime is in the 
past, the TimeSensor starts immediately.  (If StopTime is also in the 
past, it may stop immediately too.) StartTime is the number of seconds 
since 1970-01-01 00:00:00 on the local computer.

I don't have an example right here, but I have used a TimeSensor that 
starts a few seconds into the scene. There is a Script node methods that 
runs just prior to the scene being displayed. That is useful for 
grabbing the current time to use for your deltas.

All events when presented to a Script function are really two 
parameters. The first being the event data (SFVec3F or whatever) and the 
second being the timestamp. The event model in X3D has all events in a 
cascade happening at the same time. That is not the case in HTML. If the 
initial delay is not critical, you can use the jQuery document.ready 
function and grab the time from their to feed into the TimeSensor.

If you are creating an X3DOM-only scene, I suggest to not use X3D's 
Script node and grab the time from JavaScript. You can put that code at 
the bottom of the HTML file so it only runs after the stuff above gets 
queued for loading. It may work to create a TimeSensor with startTime > 
stopTime and a short cycleInterval. You can (in HTML's JavaScript) get 
the last value of 'time' to be the base time for your calculation.

Leonard Daly

> My second approach was then to disable the looping timesensor and use a second nonlooping timesensor with a setable startTime to enable it. This works by routing the isActive event issued by the second sensor after startTime has arrived to the enable field of the looping sensor. While this approach works in principle, it seems rather convoluted. Is there a better, third approach ?
> Another issue is how to determine what the startTime is. In x3dom I can override the x3dom.runtime.ready function to get the current time with the JavaScript Date object and then add a delay to arrive at a startTime. (Why does x3dom not provide any of the timestamps such as touchtime or bindtime?)
> How would it be best done in x3d ? Is there a sensor which produces a time event when the scene starts ? Use bindTime for the background node ? Is there a way to avoid a script ?
> Andreas

*Leonard Daly*
X3D Co-Chair
Cloud Consultant
President, Daly Realism - /Creating the Future/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20150925/35bddd7f/attachment.html>

More information about the x3d-public mailing list