Sha256: 8eee3213c48bcf553a8c3239d8b862ad4fb9cb6601ce7523669e1d9a1d037de0

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 KB

Contents

class Tracksperanto::NukeGrammarUtils
  SECTION_START = /^x(\d+)$/
  KEYFRAME = /^([-\d\.]+)$/
  
  # Scan a TCL curve expression into a number of tuples of [frame, value]
  def parse_curve(curve_text)
    # Replace the closing curly brace with a curly brace with space so that it gets caught by split
    atoms, tuples = curve_text.gsub(/\}/m, ' }').split, []
    # Nuke saves curves very efficiently. x(keyframe_number) means that an uninterrupted sequence of values will start,
    # after which values follow. When the curve is interrupted in some way a new x(keyframe_number) will signifu that we
    # skip to that specified keyframe and the curve continues from there, in gap size defined by the last fragment.
    # That is, x1 1 x3 2 3 4 will place 2, 3 and 4 at 2-frame increments
    
    last_processed_keyframe = 1
    intraframe_gap_size = 1
    while atom = atoms.shift
      if atom =~ SECTION_START
        last_processed_keyframe = $1.to_i
        if tuples.any?
          last_captured_frame = tuples[-1][0]
          intraframe_gap_size = last_processed_keyframe - last_captured_frame
        end
      elsif  atom =~ KEYFRAME
        tuples << [last_processed_keyframe, $1.to_f]
        last_processed_keyframe += intraframe_gap_size
      elsif atom == '}'
        return tuples
      end
    end
    tuples
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
tracksperanto-2.8.6 lib/import/nuke_grammar/utils.rb
tracksperanto-2.8.5 lib/import/nuke_grammar/utils.rb
tracksperanto-2.8.4 lib/import/nuke_grammar/utils.rb
tracksperanto-2.8.2 lib/import/nuke_grammar/utils.rb
tracksperanto-2.8.1 lib/import/nuke_grammar/utils.rb
tracksperanto-2.8.0 lib/import/nuke_grammar/utils.rb
tracksperanto-2.7.0 lib/import/nuke_grammar/utils.rb
tracksperanto-2.6.3 lib/import/nuke_grammar/utils.rb
tracksperanto-2.6.2 lib/import/nuke_grammar/utils.rb
tracksperanto-2.6.1 lib/import/nuke_grammar/utils.rb
tracksperanto-2.6.0 lib/import/nuke_grammar/utils.rb
tracksperanto-2.5.0 lib/import/nuke_grammar/utils.rb
tracksperanto-2.4.1 lib/import/nuke_grammar/utils.rb
tracksperanto-2.3.3 lib/import/nuke_grammar/utils.rb
tracksperanto-2.3.2 lib/import/nuke_grammar/utils.rb
tracksperanto-2.3.1 lib/import/nuke_grammar/utils.rb
tracksperanto-2.3.0 lib/import/nuke_grammar/utils.rb
tracksperanto-2.2.4 lib/import/nuke_grammar/utils.rb
tracksperanto-2.2.2 lib/import/nuke_grammar/utils.rb
tracksperanto-2.2.0 lib/import/nuke_grammar/utils.rb