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

Andreas Plesch andreasplesch at gmail.com
Sun Sep 27 16:16:28 PDT 2015


Hi Leonard

thanks !

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

I believe you are referring to the initialize() function in a script node ?
Using this had occurred to me but I was not sure if there is a solution
without using a script. It looks there may be not.

I  could not get a looping timesensor such as

<TimeSensor DEF='delayedclock' startTime='5s_from_loadTime'
cycleInterval='30s'  loop='true' />

with the actual startTime set via Javascript to work and I assumed it was
due to how the spec. prescribes that a timesensor is supposed to ignore
resetting of startTime after becoming active, and loop='true' activates the
sensor as quickly as possible. So ignoring the delay started to make sense
but you seem to suggest that a timesensor like above should work ?

What worked but seemed overly complicated was:

<TimeSensor def='slowclock' enabled='false' cycleInterval='32' loop='true'
/>
<TimeSensor def='slowclocktrigger' startTime='5s_from_loadTime'
cycleInterval='1000' loop='false' />
<ROUTE fromNode='slowclocktrigger' fromField='isActive' toNode='slowclock'
toField='enabled' />
with the actual startTime set via Javascript.

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

I believe there is probably a regular, non-JQuery DOM equivalent as well.
And x3dom provides x3dom.runtime.ready().


> If you are creating a 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.
>

Using x3dom.runtime.ready() should guarantee that the scene's nodes and
attributes are available to the script if requested,

I see, a short cycleInterval should get you the time close to the load time
of the scene without a script node.

A way to get a 5s delay without a script may be:

<TimeSensor def='delay' startTime='1' stopTime='0' cycleInterval='5' />
<TimeSensor def='slowclock' enabled='false' cycleInterval='32' loop='true'
/>
<BooleanFilter def='invert' />
<ROUTE fromNode='delay' fromField='isActive' toNode='invert'
toField='set_boolean' />
<ROUTE fromNode='invert' fromField='inputNegate' toNode='slowclock'
toField='enabled' />

Just trying out more declarative ways of programming to compare to the
imperative approach which does seem more concise.

Andreas

-- 
> *Leonard Daly*
> X3D Co-Chair
> Cloud Consultant
> President, Daly Realism - *Creating the Future*
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> X3dom-users mailing list
> X3dom-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x3dom-users
>
>


-- 
Andreas Plesch
39 Barbara Rd.
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20150927/9d0203ac/attachment.html>


More information about the x3d-public mailing list