Animating textures/exporting from Blender

Tips and discussion about scenery creation for RailWorks.

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Mon Mar 24, 2014 10:01 am

mrennie wrote:
GetSimulationTime gives the amount of time, in seconds, that the scenario had been running, not the absolute time of day - for that, you need to do:

local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay") -- time since midnight, in seconds, of the current scenario

So at 8AM, it would be 28,800 seconds.


Thanks Mike, I've seen that function mentioned before, but I can't remember where. What time do all the night nodes fire up in the sim?

EDIT- Oh, I think chacal said between 8p and 8a.

I foresee two scenarios, the first is where the script only runs between 'sunset' and 'sunrise', or it runs all the time, but only calls the nodes at night. The only thing I'm worried about is that when night transitions to day, it will leave the night node still rendered, just not animated. Papa, sorry to bug you again man, but I believe that this is my final question on the matter...
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Mon Mar 24, 2014 11:04 am

oops, day and night nodes are activated at differing times, depending on the season in the scenario! Summer switches over at 530a. Winter doesn't. *!rolleyes!*

Papa, I pm'd you a new dropbox link with the full igs.
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Mon Mar 24, 2014 12:31 pm

I tried something here Mike, and it sorta worked until the clock struck 2100. At that point, the day texture gets replaced by the first night node and the game crashes. All my changes are prefaced by --ADD comment lines.

Code: Select all
   --Script storage area (above dashed line):--
   
  -- local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")-- from Mrennie
 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------   
    -- set globals

    -- assumes the first frame is named Node_0
    --   however it appears we need to work backwards??
    gNextNode = 9;

    -- the maximum number of nodes, remember we are 0 based
    --   so if there are ten nodes then the last node
    --   would be Node_9
    MAX_NODES = 10;

    -- number of seconds to wait till showing the next frame
    INTERVAL_SEC = 2;

    -- use this to determine if the interval has passed
    gNextTime = 0.0;

    -- initialize, always needed
    function Initialise()
       Call( "BeginUpdate" )
    end

    -- update, always needed
    function Update( time )   
       SetNode( );
    end

    -- this is where all the heavy lifting is done
    function SetNode()
      -- first get the time, then find out if the interval has passed (test for 0)
      local currTime = Call("*:GetSimulationTime", 0);
       
      -- there is a trick here because this function is called several times
      --   per second, not on the second, so we need to build a semaphore to
      --   guard it from cycling though all the frames within the span of
      --   one second
      if (currTime > gNextTime) then
        local index = 0;
        --ADDED below
        local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
        --ADDED below, where 75600 is 2100hrs in the scenario
        while (SecondsAfterMidnight >= 75600) do
       
        while (index < MAX_NODES) do     
          -- if the frame is equal to the index then turn it on
          if (index == gNextNode) then
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  1 );
          else -- turn the frame off
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  0 );
          end
          index = index + 1;   
        end
        --ADDED
        end

        -- if we cycled through all the frames then reset to the first frame
        --  remember that we seem to need to flip through the frames backwards
        if (gNextNode ~= 0) then
           gNextNode = gNextNode - 1;
        else
           gNextNode = MAX_NODES - 1;
        end
        -- set the semaphore
        gNextTime = currTime + INTERVAL_SEC;
      end
    end


Below: Here's what happens: note the clock in the HUD...
https://www.youtube.com/watch?v=9KViBapw7Tc&feature=youtu.be
Alas, even if I get this to work, it won't be consistent with different seasons, because night textures are activated at different times in the Time of Day BPs. Oh well, just tinkering...
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby mrennie » Mon Mar 24, 2014 1:44 pm

dogrokket wrote:I tried something here Mike, and it sorta worked until the clock struck 2100. At that point, the day texture gets replaced by the first night node and the game crashes. All my changes are prefaced by --ADD comment lines.

Code: Select all
   --Script storage area (above dashed line):--
   
  -- local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")-- from Mrennie
 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------   
    -- set globals

    -- assumes the first frame is named Node_0
    --   however it appears we need to work backwards??
    gNextNode = 9;

    -- the maximum number of nodes, remember we are 0 based
    --   so if there are ten nodes then the last node
    --   would be Node_9
    MAX_NODES = 10;

    -- number of seconds to wait till showing the next frame
    INTERVAL_SEC = 2;

    -- use this to determine if the interval has passed
    gNextTime = 0.0;

    -- initialize, always needed
    function Initialise()
       Call( "BeginUpdate" )
    end

    -- update, always needed
    function Update( time )   
       SetNode( );
    end

    -- this is where all the heavy lifting is done
    function SetNode()
      -- first get the time, then find out if the interval has passed (test for 0)
      local currTime = Call("*:GetSimulationTime", 0);
       
      -- there is a trick here because this function is called several times
      --   per second, not on the second, so we need to build a semaphore to
      --   guard it from cycling though all the frames within the span of
      --   one second
      if (currTime > gNextTime) then
        local index = 0;
        --ADDED below
        local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
        --ADDED below, where 75600 is 2100hrs in the scenario
        while (SecondsAfterMidnight >= 75600) do
       
        while (index < MAX_NODES) do     
          -- if the frame is equal to the index then turn it on
          if (index == gNextNode) then
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  1 );
          else -- turn the frame off
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  0 );
          end
          index = index + 1;   
        end
        --ADDED
        end

        -- if we cycled through all the frames then reset to the first frame
        --  remember that we seem to need to flip through the frames backwards
        if (gNextNode ~= 0) then
           gNextNode = gNextNode - 1;
        else
           gNextNode = MAX_NODES - 1;
        end
        -- set the semaphore
        gNextTime = currTime + INTERVAL_SEC;
      end
    end


Below: Here's what happens: note the clock in the HUD...
https://www.youtube.com/watch?v=9KViBapw7Tc&feature=youtu.be
Alas, even if I get this to work, it won't be consistent with different seasons, because night textures are activated at different times in the Time of Day BPs. Oh well, just tinkering...


The problem there is that "while (SecondsAfterMidnight >= 75600) do" is true all the time until it gets to midnight, so you repeat the loop over and over agan, which hogs the CPU and makes it look like the game has hung. If you change it to "if (SecondsAfterMidnight >= 75600) then" it should work, because it'll just do the inner loop once each time Update is called.

In fact, if you want it to stop when it gets to 8am, then it should really be:

Code: Select all
if (SecondsAfterMidnight >= 75600) or (SecondsAfterMidnight <= 28800) then -- after 9pm or before 8am
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby mrennie » Mon Mar 24, 2014 1:49 pm

dogrokket wrote:Alas, even if I get this to work, it won't be consistent with different seasons, because night textures are activated at different times in the Time of Day BPs. Oh well, just tinkering...


It's also possible to get the current season:

Code: Select all
local Season = SysCall ("ScenarioManager:GetSeason") -- Spring = 0, summer = 1, autumn/fall = 2, winter = 3


Then to test for the start and end of nighttime, you could use different numbers depending on the season.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby Chacal » Mon Mar 24, 2014 3:01 pm

Is there a documentation of the TS2014 syscalls?
Over the hill and gathering speed
Chacal
Site Admin
 
Posts: 6477
Joined: Tue Jul 05, 2011 1:11 pm
Location: Quebec, Canada

Re: Animating textures/exporting from Blender

Unread postby mrennie » Mon Mar 24, 2014 3:19 pm

Chacal wrote:Is there a documentation of the TS2014 syscalls?


I think it's on UKTS somewhere.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Tue Mar 25, 2014 4:13 pm

Check this out: AndiS over at UKTS looked at it and came up with this:
Code: Select all
          if (currTime > gNextTime) then
            local index = 0;
           
            while (index < MAX_NODES) do     
              -- if the frame is equal to the index then turn it on
              if (index == gNextNode) then
                Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  1 );
              else -- turn the frame off
                Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  0 );
              end
              index = index + 1;   
            end

            -- set the semaphore
            gNextTime = currTime + INTERVAL_SEC;
            -- if we cycled through all the frames then reset to the first frame
            --  remember that we seem to need to flip through the frames backwards
            if (gNextNode ~= 0) then
               gNextNode = gNextNode - 1;
            else
                          -- here we know we are at gNextNode 0, and we consider stopping
               local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
               if SecondsAfterMidnight >= 3600 * 6 and SecondsAfterMidnight < 3600 * 12 then
                      -- turn it off at 6 a.m.
                  gNextTime = 3600 * 21      -- do something again at 9 p.m.
               end
               gNextNode = MAX_NODES - 1;
            end
          end

In case you're bored, across the pond, I've had this going over there for a little while: http://forums.uktrainsim.com/viewtopic.php?f=374&t=136967
One little irritation is that I don't have enough rank over there, and the little man has to approve my posts before they show up. *!mad!*

>>>EDIT---- I had to and an 'end' at the end to get it to work, and I also changed the 3600 * 6 to 3600 * 5.5 to sync with the summertime day/night nodes. What happens with this above script, is that at 0530, the day node appears in front of the animation, and the animation stops running. I want it to go away completely, so it doesn't look stupid. How to make the scripted nodes disappear.....
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Tue Mar 25, 2014 5:31 pm

Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Morning has broken... it's still partially broken

Unread postby dogrokket » Tue Mar 25, 2014 7:38 pm

Getting closer... figured out how to turn off the script at daybreak, still with a residual cycle. Thanks to AndiS at UKTS. We inserted these lines near the end.
Code: Select all
       --set the semaphore
            gNextTime = currTime + INTERVAL_SEC;
            -- if we cycled through all the frames then reset to the first frame
            --  remember that we seem to need to flip through the frames backwards
            if (gNextNode ~= 0) then
               gNextNode = gNextNode - 1;
            else
              -- ADDED from AndiS
              -- here we know we are at gNextNode 0, and we consider stopping
               local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
               if SecondsAfterMidnight >= 3600 * 5.5 and SecondsAfterMidnight < 3600 * 12 then   
               -- turn it off at 6 a.m.
                  gNextTime = 3600 * 21         -- do something again at 9 p.m.
               --ADD to turn off
              Call( "*:ActivateNode", "Node_1_fx_night", 0 );
              Call( "*:ActivateNode", "Node_0_fx_night", 0 );
               
               end
             
               
               gNextNode = MAX_NODES - 1;
            end
           
           
            -- set the semaphore (moved up AndiS)
            --gNextTime = currTime + INTERVAL_SEC;
           end
       
           
        end

Here's a vid- https://www.youtube.com/watch?v=uRlsSxnANlM&feature=youtu.be
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Success

Unread postby dogrokket » Sat Mar 29, 2014 12:49 pm

With a little help from my friends, main goal achieved!
Here's what it looks like:
https://www.youtube.com/watch?v=P4t52fElC4Q&feature=youtu.be

Here's what the code ended as, PapaXpress' original with adjustments to make the animation only run at the appropriate time of day:

Code: Select all
   --Script storage area (above dashed line):--
   
  -- local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")-- from Mrennie
   --add test andis on wed 3/26
--       -- start of temporary testing code
--if SecondsAfterMidnight == nil then
--Call( "*:ActivateNode", "Node_2_fx_night", 1 );
--else
---- end of temporary testing code
--           if SecondsAfterMidnight >= 3600 * 5.5 and SecondsAfterMidnight < 3600 * 21 then   
--              gNextTime = 3600 * 21         -- do something again at 9 p.m.
--           end
---- start of temporary testing code
--end
---- end of temporary testing code

--- replace this:           local currTime = Call("*:GetSimulationTime", 0);
--- with this:          local currTime = SysCall ("ScenarioManager:GetTimeOfDay")
 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------   
    -- set globals

    -- assumes the first frame is named Node_0
    --   however it appears we need to work backwards??
    gNextNode = 9;

    -- the maximum number of nodes, remember we are 0 based
    --   so if there are ten nodes then the last node
    --   would be Node_9
    MAX_NODES = 10;

    -- number of seconds to wait till showing the next frame
    INTERVAL_SEC = 2;

    -- use this to determine if the interval has passed
    gNextTime = 0.0;

    -- initialize, always needed
    function Initialise()
       Call( "BeginUpdate" )

     
           local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
               if SecondsAfterMidnight >= 3599 * 5.5 and SecondsAfterMidnight < 3600 * 21 then --meaning daytime 
                  gNextTime = 3600 * 21         -- do something again at 9 p.m.
           end
    end

    -- update, always needed
    function Update( time )   
       SetNode( );
    end

    -- this is where all the heavy lifting is done
    function SetNode()
      -- first get the time, then find out if the interval has passed (test for 0)
      -- local currTime = Call("*:GetSimulationTime", 0);swapped out for below code
      local currTime = SysCall ("ScenarioManager:GetTimeOfDay")
       
      -- there is a trick here because this function is called several times
      --   per second, not on the second, so we need to build a semaphore to
      --   guard it from cycling though all the frames within the span of
      --   one second
      if (currTime > gNextTime) then
        local index = 0;       
           
        while (index < MAX_NODES) do     
          -- if the frame is equal to the index then turn it on
          if (index == gNextNode) then
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  1 );
          else -- turn the frame off
            Call( "*:ActivateNode", "Node_" .. index .. "_fx_night",  0 );
          end
          index = index + 1;   
        end
       

        --set the semaphore
        gNextTime = currTime + INTERVAL_SEC;
        -- if we cycled through all the frames then reset to the first frame
        --  remember that we seem to need to flip through the frames backwards
        if (gNextNode ~= 0) then
           gNextNode = gNextNode - 1;
        else
          -- ADDED from AndiS
          -- here we know we are at gNextNode 0, and we consider stopping
           local SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
           if SecondsAfterMidnight >= 3599 * 5.5 and SecondsAfterMidnight < 3600 * 12 then   
           -- turn it off at 0530 a.m.
                 gNextTime = 3600 * 21         -- do something again at 9 p.m. (see what happens)(doesn't work if removed)
           --ADD to turn off
          Call( "*:ActivateNode", "Node_1_fx_night", 0 );
          Call( "*:ActivateNode", "Node_0_fx_night", 0 );
           
           end
         
           
           gNextNode = MAX_NODES - 1;
        end
       
       
        -- set the semaphore (was originally here; moved up AndiS)
        -- gNextTime = currTime + INTERVAL_SEC;
       end
   
       
    end

Now on to make some seasonal adjustments to the times... !*salute*!
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby PapaXpress » Sat Mar 29, 2014 2:40 pm

Are you aware of seasonal textures?
Image
"Just post some random unrelated text. We have members here who can help you with that." ~ Chacal
"When all else fails, read the instructions... if that doesn't work either, try following them." ~ Old Prof
Image
The Grade Crossing - Atlanta North Project - Virtual Rail Creations
User avatar
PapaXpress
 
Posts: 5147
Joined: Sat Oct 23, 2010 10:30 pm
Location: that "other" timezone

Re: Animating textures/exporting from Blender

Unread postby dogrokket » Sat Mar 29, 2014 11:18 pm

Yes, the SysCall that mrennie referenced. I just have to figure out how to use it economically... *!lol!*
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

Re: Animating textures/exporting from Blender

Unread postby PapaXpress » Sun Mar 30, 2014 12:02 am

No. no. There is another (better) way.

The trick is to add a suffix to the ACE file name. No suffix (what you are using now) is what is used when there are no other seasonal textures to use. So. If you want to add a winter texture then use _Wi for Autumn use _Au, Spring is _Sp, and Summer is _Su (or default which would be no suffix).

You don't have to do anything special in the blueprint to get this to work. The editor will notice the extra files and build the logic into the BIN or GEO file as the model requires.
Image
"Just post some random unrelated text. We have members here who can help you with that." ~ Chacal
"When all else fails, read the instructions... if that doesn't work either, try following them." ~ Old Prof
Image
The Grade Crossing - Atlanta North Project - Virtual Rail Creations
User avatar
PapaXpress
 
Posts: 5147
Joined: Sat Oct 23, 2010 10:30 pm
Location: that "other" timezone

Seasonal textures

Unread postby dogrokket » Sun Mar 30, 2014 1:40 am

I don't know if that will work, and here's why i think that: The game ignored the _night_fx designation of the nodes, like they didn't exist. I think it did this because the script over-rode the designation and they ran during the day, as long as they were called for in the script; which originally, called for them all the time. If I understand your suggestion, I would create duplicates of the ace files with suffixes for each season. It's an interesting thought, and I could give it a try, but...

What I was thinking was to create a sub-routine in the script to adjust the span of how the script decided what was day and what was night. This is decided in the time of day blueprint. It would have to conform to the standard RSC blueprint times for each season. Since summer is the longest day period, which, in the script as present, is between 3600 * 5.5 (0530) and 3600 * 21 (2100), I could use SysCall ScenarioManagerGetSeason to devise a way to reduce that period, as a variable. This is a lot of brain surgery for a stupid little scenery item, but it's pretty cool, since I don't know if it's been done before *!!wink!!* The problem with this is, if someone is using a time of day blueprint other than the default, it doesn't work. I guess that's the rub. What would solve all this, is if we could figure out a way to call day or night in the script by some other means other than a math multiplier of SecenarioManagerGetTimeofDay. That way, the animation would run whenever the game was in night mode. Is there a way to call that???

It reminds me of a Yogi Berra quote: "When you arrive at a fork in the road, take it".
Down another rabbit hole we go....
User avatar
dogrokket
 
Posts: 176
Joined: Wed May 08, 2013 2:18 pm

PreviousNext

Return to Scenery Design

Who is online

Users browsing this forum: No registered users and 1 guest