Animating textures/exporting from Blender

Tips and discussion about scenery creation for RailWorks.

Re: Animating textures/exporting from Blender

Unread postby PapaXpress » Fri Mar 21, 2014 6:14 pm

Nope. You are looking at the node names.

I wonder if there is something else happening in the game engine that we don't know about. If could be that any node using a special suffix will be ignored by calls from the LUA. Not sure how to prove this theory.

Lets try this. For now remove the _fx_night suffix, and SignFront_fx_day so all you have left are the 10 Frame nodes. Edit your LUA so that the node name matches, and see if it works. What I want to prove here is that the LUA logic is working correctly. They we can add back the special stuff bit by bit and see where it breaks.
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 22, 2014 10:18 am

Reminds me of a line from a movie-- "Strip it down to a flying gas can..." Okay, here's what I did. I deleted everything but the 10 nodes. I also, just for consistency, renamed them 1_1000_Node_0 through 9. Script modified to reflect. (I Commented out the Call for the 1_1000_Daysign node)
Code: Select all
        -- set globals

        -- assumes the first frame is named Frame_0
        gNextFrame = 0;

        -- the maximum number of frames, remember we are 0 based
        --   so if there are ten frames then the last frame
        --   would be Frame_9
        MAX_FRAMES = 10;

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


        -- initialize, always needed
        function Initialise()
           SetFrame( 0 );
        end

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

        -- this is where all the heavy lifting is done
        function SetFrame( currTime )
           -- loop through each frame every three seconds
           --   if the current time is 0 then we are initializing the model
           if (math.mod(math.floor(currTime), INTERVAL_SEC) == 0 or currTime == 0) then
              local index = 0;
              while (index < MAX_FRAMES) do
                 -- if the frame is equal to the index then turn it on
                 if (index == gNextFrame) then
                   -- Call( "*:ActivateNode", "1_1000_Frame_" .. index .. "_fx_day",  1 );
                    Call( "*:ActivateNode", "1_1000_Node" .. index,  1 );
                 else -- turn the frame off
                   -- Call( "*:ActivateNode", "1_1000_Frame_" .. index .. "_fx_day",  0 );
                    Call( "*:ActivateNode", "1_1000_Node" .. index,  0 );
                end   
                 index = index + 1;
              end

              -- if we cycled through all the frames then reset to the first frame   
              if (gNextFrame < MAX_FRAMES) then
                 gNextFrame = gNextFrame + 1;
              else
                 gNextFrame = 0;
              end
           end
        end


I doesn't work yet, but I did stumble across something interesting: Each time I preview it in the BP editor or restart the game, it displays a new frame. So something is happening each time it's reloaded, but it's just not cycling after it's loaded. !**conf**!

I also tinkered around with the node name in the Call lines, e.g. "1_1000_Node", "1_1000_Node_" and just plain Node without quotes. It will cycle through each time I reload the preview. It doesn't cycle through if I change the Call to "fred" or something like that. It also won't export if you don't put quotes around 1_1000_Node. Call with just Node and no quotes, however, will export without the prefix. Don't know if that's anything signif, but just something I found.
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 22, 2014 1:20 pm

Mind if you package that up and allow me to look at it? It seems like you are missing something simple, and we just can't see it.
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 mrennie » Sat Mar 22, 2014 5:28 pm

OK, here's another thought ...

The parameter "time" in the Update function is a measure of the time that has passed (the interval) since the previous call to Update, so it's usually a small fraction of a second and doesn't vary much. To get the elapsed time since the simulation started, you can either add up "time" each time Update is invoked or you can Call(“*:GetSimulationTime”). As it stands, you're calling SetFrame with the same small value every time, and it never gets to 3 seconds.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby PapaXpress » Sat Mar 22, 2014 5:35 pm

That could be true Mike, but the code that snippet it originated from is working fine on the GP40. In fact I am wrote two more variations of it on our digital speedo.
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 mrennie » Sat Mar 22, 2014 5:43 pm

PapaXpress wrote:That could be true Mike, but the code that snippet it originated from is working fine on the GP40. In fact I am wrote two more variations of it on our digital speedo.


Come to think of it, if the "time" interval is a small value, then "if (math.mod(math.floor(currTime), INTERVAL_SEC) == 0 " will evaluate to true always, so I'd expect the frames to be changing on every call to Update (instead of every 3 seconds).
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby PapaXpress » Sat Mar 22, 2014 7:30 pm

The value is will gain, but it is a double (long float). I think I copied that line directly from my own code which does work. If I get time tonight I will check again to make sure.
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 » Sun Mar 23, 2014 12:05 am

Heh! Watching you Obie Wahns go back in forth with this script stuff- me: like a dog watching TV once again!
Here Ya go Papa: I copied the xml, igs, lua and aces to a dropbox folder. https://www.dropbox.com/s/vb8f9io7ng73jgr/H%26C_Sign.zip It contains the stripped down version with just the the nodes. Let me know if this works for you. This was created in blender and I'm interested to find out if it exports in some funky way.
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 23, 2014 11:05 am

I will try to export it tonight.

Update:

ACk!

I see what I did wrong. I am debugging the script but I may not be able to finish it tonight.

Update 2:
I have it working, but its in reverse.

oh, and if my wife kills me I blame you *!greengrin!*

Update 3:
I have it working.

I changed the whole timing mechanism. Mike was correct about Update( time ), and I forgot to add the very important function 'Call( "BeginUpdate" )' in the Initialise. Without that Update() will be called only once (if memory serves).

If you reverse the frames in the IGS you will need to change the logic in SetNode a bit (ie back to what it was):


Here is the code that works for me. I did not change your XML or IGS.
Code: Select all
-- set globals

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


-- the maximum number of frames, remember we are 0 based
--   so if there are ten frames then the last frame
--   would be Frame_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;
    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,  1 );
      else -- turn the frame off
        Call( "*:ActivateNode", "Node_" .. index,  0 );
      end
      index = index + 1;   
    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
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 » Sun Mar 23, 2014 10:21 pm

Oooooh BoY! And It's my birthday too! I will load this thing into the gizmo and report back. My wife wife thinks this whole trainsim thing is stupid, but as long as I make more than her, it's all good. !*brav*!
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 1:20 am

Many thanks Papa and Mike! !*salute*!
Here's what it looks like in the day:
hc.jpeg

No animation, because the sign isn't on in the day time.

Here's the night: https://www.youtube.com/watch?v=rTUG0C2coO0
Ooookay.... one little problem. The night animation starts playing under the day texture. Is there any way to make the script only call during night time running? It's not the end of the world, because I'm glad that we got it running at all. But, if there's a way to tweak this, that would be very cool. BTW, Papa, for some reason the igs file had the node order reversed. I tried a few things with the script and got it to play forward, but at the end of the sequence, it the pane disappeared for 2 seconds then it started again. So, I just reversed the order of the nodes in the final igs file and all is well. I also modded the script to add the night texture in the Call lines.
Code: Select all
    -- 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;
        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

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

Once again, thanks for the help! I haven't seen anything like this in a route yet, so very cool. !!*ok*!!

Here's what's happening in the day time when the game is running:
https://www.youtube.com/watch?v=IEhXBG-oKzo
I don't know if the game is capable of doing this....
You do not have the required permissions to view the files attached to this post.
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 Chacal » Mon Mar 24, 2014 2:02 am

Sure, in this line
Code: Select all
if (currTime > gNextTime) then

just add a test for the current time being between, say, 8PM and 8 AM.
I don't quite remember the syntax but I'm sure Papa does.
Over the hill and gathering speed
Chacal
Site Admin
 
Posts: 6746
Joined: Tue Jul 05, 2011 1:11 pm
Location: Quebec, Canada

Re: Animating textures/exporting from Blender

Unread postby mrennie » Mon Mar 24, 2014 7:03 am

PapaXpress wrote:...I forgot to add the very important function 'Call( "BeginUpdate" )' in the Initialise. Without that Update() will be called only once (if memory serves)....



Well spotted! I don't know why I didn't see that ... must've been asleep *!lol!*
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 7:08 am

Chacal wrote:Sure, in this line
Code: Select all
if (currTime > gNextTime) then

just add a test for the current time being between, say, 8PM and 8 AM.
I don't quite remember the syntax but I'm sure Papa does.


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.
User avatar
mrennie
 
Posts: 3214
Joined: Wed May 30, 2012 12:22 pm

Re: Animating textures/exporting from Blender

Unread postby arizonachris » Mon Mar 24, 2014 10:00 am

dogrokket wrote:Here's the night: https://www.youtube.com/watch?v=rTUG0C2coO0


dog, dude, that is absolutely brilliant!!!!!!!!!!!!!!!!!! You, Papa and Mike make one heck of a team! !!*ok*!! !*salute*!
Last edited by arizonachris on Mon Mar 24, 2014 10:02 am, edited 1 time in total.
Ryzen 7 2700K, Asus Prime X570P, 32Gb DDR4, 2x 1Tb M.2 SSD's, RTX2060 6Gb, Occulus Rift
Win 10 Pro 64bit, keyboard/ mouse/ wheel/ pedals/ baseball bat
Security Coordinator on the Battleship Iowa
User avatar
arizonachris
 
Posts: 3955
Joined: Sun Mar 21, 2010 10:36 am
Location: Southern California

PreviousNext

Return to Scenery Design

Who is online

Users browsing this forum: No registered users and 34 guests