Parse a 3D obj file to a ruby data structure. Can compute tangent per vertex. Can merge vertice, normals, and textures indexes into a single index for OpenGL use case.
- Support triangle primitives
- Support only one model per obj file
- Did not support materials
Add this line to your application's Gemfile:
gem 'obj_parser'
And then execute:
$ bundle
Or install it yourself as:
$ gem install obj_parser
Sample to parse an obj file, generate tangents and transform to a single indexed 3D model.
@parser = ObjParser::ObjParser.new
obj = @parser.load(File.open("/Users/lcobos/development/ios/OpenGL-4/models/cube.obj"))
obj.compute_tangents
obj = ObjParser::SingleIndexedObj.build_with_obj(obj)
puts obj.vertice.map(&:data).join(",")
puts obj.normals.map(&:data).join(",")
puts obj.textures.map(&:data).join(",")
puts obj.tangents.map(&:data).join(",")
puts obj.indexes.join(",")
- Fork it ( http://github.com//obj_parser/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request