Skip to content

Generating the numbers

Telecotxesco edited this page Dec 15, 2020 · 32 revisions

There are multiple ways to generate the numbers:

  • Defining them manually
  • Sequence from starting number to ending number
  • Random secuence from a pattern
  • Advanced techniques

Before continue, we should have the model file look like this:

local kaminari_numbers 

-- Function to check if a module available
function isModuleAvailable(name)
    if package.loaded[name] then return true end
    for _, searcher in ipairs(package.searchers or package.loaders) do
      local loader = searcher(name)
      if type(loader) == 'function' then
        package.preload[name] = loader
        return true
      end
    end
    return false
end

-- Main model's data() function 
function data()
    local platesLeft  = {} -- Here we will place the identification numbers who will be shown on left side
    local platesRight = {} -- Here we will place the identification numbers who will be shown on right side

    -- If "kaminari_numbers" module is available, then we proceed loading the module. This way we prevent breaking any previous save game.
    if isModuleAvailable( "kaminari_numbers" ) then
        -- LOAD THE MOUDLE
        kaminari_numbers = require "kaminari_numbers"
        
        -- HERE WE WILL GENERATE THE NUMBERS
        
    else
        print("Warning: kaminari_numbers is not available/found. Please subscribe it on Steam Workshop, activate and make sure it is loaded before all the rest of mods.")
    end
    
-- HERE BEGINS THE USUAL RETURN DATA OF THE MODEL
return {
    boundingInfo = {
        bbMax = { 6.7790122032166, 1.5564205646515, 4.2407073974609, },
        bbMin = { -7.0255718231201, -1.5564205646515, -0.036832869052887, },
    },

    -- Rest of the model data [...]

    }
end

⚠️ IMPORTANT ⚠️ AVOID GENERATING TOO MUCH DIFFERENT NUMBERS

Each digit adds 2 polygons to the model, and because of each identification number may have numerous digits, and a group of generated identification numbers may have hundreds of polygons, even thousands. Be careful because this may cause user computer slow down!

NOTE From now we will insert the code after the -- HERE WE WILL GENERATE THE NUMBERS line.

Defining the numbers manually

To add a number from a manual list, simply call the following function:

local myList = {"V 100-1035","V 100-1023"}

platesLeft = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),
platesRight = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),

This will print and cycle throug "V 100-1035" and "V 100-1023". You can add as many you want.

💡 TIP the same way we can cycle throug names, like { "MALLARD","ROCKETER","ARROW" } or show random labels like hours or temperatures on a panel. Possibilites are countless.

Sequence from starting number to ending number

In this case we want to create a secuence of numbers starting from a number until a ending one. Because of we would like all the numbers shown on the model be the same, the list of numbers must be created separately from the function getChildrenColorNumber(). If not done like this, you will see different numbers on each label.

We can achieve this with the following code:

local myList = kaminari_numbers.buildListOfNumbers( 1, 35, true, 3, "1", "" )

platesLeft = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),
platesRight = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),

This will print and cycle from "1001" to"V 1035" but randomly. Note we only changed how myList is defined. The rest is all the same.

Please refer to buildlistofnumbers() definition on how to use this function.

Random secuence from a pattern

In this case we want to create a bunch of numbers from a defined pattern. Because of we would like all the numbers shown on the model be the same, the list of numbers must be created separately from the function getChildrenColorNumber(). If not done like this, you will see different numbers on each label.

We can achieve this with the following code:

local myDictionary = {
  "ABC",
  "012",
  "0123456789",
  "0123456789",
}

local myList = kaminari_numbers.generateRandomCharacters( myDictionary, 15, "", "" )

platesLeft = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),
platesRight = kaminari_numbers.getChildrenColorNumber( myList, "white", "Helvetica", 10.0, 2.20, -1.00, 2.05, 180, 0, 0 ),

This will print 15 numbers like "A001", "C208", "B017",... Note we only changed how myList is defined, but also defined a dictionary for a pattern. The rest is all the same.

Please refer to generaterandomcharacters() definition on how to use this function.

Advanced techniques

As far as we are programatically defining the list of numbers, we can do other pre and post processing. For example, if we have identification numbers like: 252-001, 252-002, 252-003, ... but also want to show somewere only the last digits, like 001, 002, 003, ...

In this case, we can achieve this by:

  1. Generate the short number list
  2. Generate a long number list iterating each number on the first list
  3. Create two groups of children number meshes.

This is an example how to do this:

    -- Generation of the plates: this will create numbers like 001, 002, ... 035.
    local numberPlates = kaminari_numbers.buildListOfNumbers( 1, 35, true, 3, "", "" )

    -- With this loop, we will create a secondary list derived from the first, in order
    -- to match the numbers
    local largeNumberPlates = {}
    for i, singleNumberPlate in ipairs(numberPlates) do
        table.insert( largeNumberPlates, "252-" .. singleNumberPlate )
    end

   -- Generation of the groups of numbers to display
    -- These two will be a big label with only que number like 1001, 1002, ... 1035
    local platesLeft  = kaminari_numbers.getChildrenColorNumber( numberPlates      , "white", "Helvetica", 24.0,  3.90,  1.00, 2.05,   0, 0, 0 )
    local platesRight = kaminari_numbers.getChildrenColorNumber( numberPlates      , "white", "Helvetica", 24.0,  1.90, -1.00, 2.05, 180, 0, 0 )
        
    -- These two will generate a larger label, derived from the mail numberPlates list, 
    -- but on front and rear of the unit
    local platesFront = kaminari_numbers.getChildrenColorNumber( largeNumberPlates , "white", "Helvetica",  4.0,  6.01, -0.38, 1.45, -90, 0, 0 )
    local platesBack  = kaminari_numbers.getChildrenColorNumber( largeNumberPlates , "white", "Helvetica",  4.0, -6.31,  0.38, 1.45,  90, 0, 0 )

Positioning the numbers

At the first time you open the model on ModelEditor you will see a mess with the numbers. This is because all are overlapped. In order to view how it will perform, you need to select forever animation and press PLAY button, as well the LOOP button.

On getChildrenColorNumber() or getChildrenRGBNumber() you need to place the numbers right in the correct place. That is:

  • Pararel to the surface
  • Almost on the surface, but few centimeters over it.
  • Not too much far away the surface, otherwise the rest of the numbers will not hide

In the following picture you can see how the numbers are all hidden backwards. Note this can only be seen with forever animation playing.

You will probably need to do trial and error until you get the correct position. Do a change with the notepad or text editor, save the MDL file, and ModelEditor will refresh the change. Press PLAY button to see if the backwards labels get behind the locomotive panel. In the next picture there is an example on how the X coordinate has to be correctly found in order to achieve a perfect result:

Inclination

The RotX, RotY and RotZ allows you to specify not only rotation but inclination of the number (i.e. inclined surface)

Sharp (angular) surface

On surfaces where are not totally flat, but like a triangle (i.e. the front of a locomotive), you may need to split the plates in two, the first on one side, and the second on the other side. On the next picture you can see how a) and b) are placed with different angle.

The left one is a unique single list {"252-"} with a 5 degree axis rotation clockwhise, and the right one contains the full list of random numbers, but with a -5 degree axis rotation, this is counter-clockwise.

Next section 👉 Functions