0.0
No commit activity in last 3 years
No release in over 3 years
This library provides a handy interface to create wavefront .obj files. You can add vertex and faces to define a 3d object. It handles the syntax of the .obj file format and takes care of vertex definition (no vertex is defined twice which reduces filesize). You can access the result in raw data or write it into a file.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

wavefront-obj

Description

Ruby library to create wavefront .obj files.

This library provides a handy interface to create wavefront .obj files. You can add vertex and faces to define a 3d object. It handles the syntax of the .obj file format and takes care of vertex definition (no vertex is defined twice which reduces filesize). You can access the result in raw data or write it into a file.

Obj-Files can be used to feed a 3d printer.

Usage

install

gem install wavefront-obj	

require library, create an object and give it a name

require 'wavefront_obj'
cube = WavefrontObj.new
cube.name = "my awesome cube"

add faces

cube.add_face [[1, -1, -1],[1, -1, 1],[-1, -1, 1],[-1, -1, -1]]
cube.add_face [[1, 1, -1],[-1, 1, -1],[-1, 1, 1],[1, 1, 1]]
cube.add_face [[1, -1, -1],[1, 1, -1],[1, 1, 1],[1, -1, 1]]
cube.add_face [[1, -1, 1],[1, 1, 1],[-1, 1, 1],[-1, -1, 1]]
cube.add_face [[-1, -1, 1],[-1, 1, 1],[-1, 1, -1],[-1, -1, -1]]
cube.add_face [[1, 1, -1],[1, -1, -1],[-1, -1, -1],[-1, 1, -1]]

access the raw data

puts cube.get_raw_data

which will look like this

o my awesome cube
v 1 -1 -1
v 1 -1 1
v -1 -1 1
v -1 -1 -1
v 1 1 -1
v -1 1 -1
v -1 1 1
v 1 1 1
f 1 2 3 4
f 5 6 7 8
f 1 5 8 2
f 2 8 7 3
f 3 7 6 4
f 5 1 4 6

or save it as a file

cube.save "my_awesome_cube.obj"

You can open .obj files with most 3d programs like blender or some newer Photoshop versions as well.

Version History

v1.0.0 02/25/2013

  • initial release (yanked)

v1.0.1 02/25/2013

  • renamed export_obj_path method to save

v1.0.2 03/02/2013

  • make add_face method return true instead of void
  • added dependency injection to mock ruby file class
  • added test for save method
  • added yard documentation
  • updated README.md - Fixed some typos, adjust structure, added version history