<commit_before>= md2

A Ruby library for loading MD2 3D model files. It doesn't actually render them; that part is up to you.

While I'm presently in the final stages of testing this gem, I've not yet finished doing so; that's why it hasn't been
released yet. It's probably usable, but I won't guarantee that until I actually render a model using data loaded with
this library.

== Installation

  gem install md2
  
== Usage

  require 'md2'
  
  md2 = MD2.new("/path/to/md2")
  md2.frames.each_with_index do |frame, index|
    puts frame.name
    puts frame.vertices.length
    puts frame.normal_indices
  end
  puts md2.triangles.length
  puts md2.texcoords.length
  # and so on.
  
See the MD2 class documentation for more, or scroll down for an example of how to render the model.

== Other Cool Stuff

The MD2 library works great with the 'json' gem. Just load an MD2 and then call #to_json:

  require 'md2'
  require 'json'
  
  md2 = MD2.new("/path/to/md2")
  json = md2.to_json
  
I think this will be pretty cool as WebGL and friends begin to take off. I was so psyched about not having to add any
code that I wrote a generator instead. You can convert an MD2 file into its JSON counterpart at the command line with:

  $ md2_to_json /path/to/md2 >/path/to/json
  
The generator just prints the JSON to stdout (which made it easier for me to test), so you have to redirect the output
into a file if you want to capture it.

  The ">" in the command above is used to redirect stdout. Check Wikipedia for
  Redirection (computing) for more details if you've never seen this before:
  http://en.wikipedia.org/wiki/Redirection_(computing)

== Note on Rendering

The preferred way to render an MD2 file is to make use of its GL Commands, which produce an optimized approach to
rendering by switching between triangle strips and triangle fans (as opposed to just rendering the entire model with
only triangles). This library parses the command information into an intuitive structure so you don't have to deal
with the nuances of the format. Instead, here's how you would go about rendering an MD2 using its GL commands:

  frame = md2.frames[current_frame]
  
  md2.gl_commands.each do |command|
    case command.type
      when :triangle_strip then glBegin(GL_TRIANGLE_STRIP)
      when :triangle_fan   then glBegin(GL_TRIANGLE_FAN)
    end
    
    command.segments.each do |segment|
      index = segment.vertex_index
    
      glTexCoord2f(segment.texture_s, segment.texture_t)
      glNormal3f(frame.normals[index].x, frame.normals[index].y, frame.normals[index].z)
      glVertex3f(frame.vertices[index].x, frame.vertices[index].y, frame.vertices[index].z)
    end
    
    glEnd
  end
  

== Note on Patches/Pull Requests
 
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
<commit_msg>Documentation update<commit_after>= md2

A Ruby library for loading MD2 3D model files. It doesn't actually render them; that part is up to you.

While I'm presently in the final stages of testing this gem, I've not yet finished doing so; that's why it hasn't been
released yet. It's probably usable, but I won't guarantee that until I actually render a model using data loaded with
this library.

== Installation

  gem install md2
  
== Usage

  require 'md2'
  
  md2 = MD2.new("/path/to/md2")
  md2.frames.each_with_index do |frame, index|
    puts frame.name
    puts frame.vertices.length
    puts frame.normal_indices
  end
  puts md2.triangles.length
  puts md2.texcoords.length
  # and so on.
  
See the MD2 class documentation for more, or scroll down for an example of how to render the model.

== Other Cool Stuff

The MD2 library works great with the 'json' gem. Just load an MD2 and then call #to_json:

  require 'md2'
  require 'json'
  
  md2 = MD2.new("/path/to/md2")
  json = md2.to_json
  
I think this will be pretty cool as WebGL and friends begin to take off. I was so psyched about not having to add any
code that I wrote a generator instead. You can convert an MD2 file into its JSON counterpart at the command line with:

  $ md2_to_json /path/to/md2 >/path/to/json
  
The generator just prints the JSON to stdout (which made it easier for me to test), so you have to redirect the output
into a file if you want to capture it.

  The ">" in the command above is used to redirect stdout. Check Wikipedia for
  Redirection (computing) for more details if you've never seen this before:
  http://en.wikipedia.org/wiki/Redirection_(computing)

== Note on Rendering

The preferred way to render an MD2 file is to make use of its GL Commands, which produce an optimized approach to
rendering by switching between triangle strips and triangle fans (as opposed to just rendering the entire model with
only triangles). This library parses the command information into an intuitive structure so you don't have to deal
with the nuances of the format. Instead, here's how you would go about rendering an MD2 using its GL commands:

  frame = md2.frames[current_frame]
  
  md2.gl_commands.each do |command|
    case command.type
      when :triangle_strip then glBegin(GL_TRIANGLE_STRIP)
      when :triangle_fan   then glBegin(GL_TRIANGLE_FAN)
    end
    
    command.segments.each do |segment|
      index = segment.vertex_index
    
      glTexCoord2f(segment.texture_s, segment.texture_t)
      glNormal3f(frame.normals[index].x, frame.normals[index].y, frame.normals[index].z)
      glVertex3f(frame.vertices[index].x, frame.vertices[index].y, frame.vertices[index].z)
    end
    
    glEnd
  end
  
== Limitations

Modifying and saving the MD2 file is not currently supported, although this may be implemented sometime in the future.

== Note on Patches/Pull Requests
 
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

{'fraction_non_alphanumeric': 0.06158631415241057, 'fraction_numerical': 0.009175738724727838, 'mean_word_length': 3.557760453579022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '44251', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1879, 'n_words': 891}