Class: Mittsu::OBJLoader

Inherits:
Object
  • Object
show all
Includes:
EventDispatcher
Defined in:
lib/mittsu/loaders/obj_loader.rb

Constant Summary collapse

FLOAT =
/[\d|.|+|\-|e]+/
VERTEX_PATTERN =
/^v\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/
NORMAL_PATTERN =
/^vn\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/
UV_PATTERN =
/^vt\s+(#{FLOAT})\s+(#{FLOAT})/
FACE_PATTERN =
/^f\s+/
FACE_V_PATTERN =
/^f\s+(\d+)\s+(\d+)\s+(\d+)(?:\s+(\d+))?/
FACE_V_VT_PATTERN =
/^f\s+(\d+)\/(\d+)\s+(\d+)\/(\d+)\s+(\d+)\/(\d+)(?:\s+(\d+)\/(\d+))?/
FACE_V_VN_PATTERN =
/^f\s+(\d+)\/\/(\d+)\s+(\d+)\/\/(\d+)\s+(\d+)\/\/(\d+)(?:\s+(\d+)\/\/(\d+))?/
FACE_V_VT_VN_PATTERN =
/^f\s+(\d+)\/(\d+)\/(\d+)\s+(\d+)\/(\d+)\/(\d+)\s+(\d+)\/(\d+)\/(\d+)(?:\s+(\d+)\/(\d+)\/(\d+))?/
OBJECT_PATTERN =
/^o\s+(.+)$/
GROUP_PATTERN =
/^g\s+(.+)$/
SMOOTH_GROUP_PATTERN =
/^s\s+(\d|true|false|on|off)$/
USE_MTL_PATTERN =
/^usemtl\s+(.+)$/
LOAD_MTL_PATTERN =
/^mtllib\s+(.+)$/

Instance Method Summary collapse

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(manager = DefaultLoadingManager) ⇒ OBJLoader

Returns a new instance of OBJLoader.



24
25
26
27
28
29
30
# File 'lib/mittsu/loaders/obj_loader.rb', line 24

def initialize(manager = DefaultLoadingManager)
  @manager = manager
  @object = nil
  @mesh = nil
  @material = nil
  @_listeners = {}
end

Instance Method Details

#load(url) ⇒ Object



32
33
34
35
36
37
# File 'lib/mittsu/loaders/obj_loader.rb', line 32

def load(url)
  loader = FileLoader.new(@manager)

  text = loader.load(url)
  parse(text)
end

#parse(data) ⇒ Object



39
40
41
42
43
44
# File 'lib/mittsu/loaders/obj_loader.rb', line 39

def parse(data)
  init_parsing
  relevant_lines(data).each { |line| parse_line(line) }
  end_object
  @group
end