Class: Mittsu::STLLoader

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

Constant Summary collapse

FLOAT =
/[\d|.|+|\-|e]+/
NORMAL_PATTERN =
/normal\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/
VERTEX_PATTERN =
/^\s*vertex\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/

Instance Method Summary collapse

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(manager = DefaultLoadingManager) ⇒ STLLoader

Returns a new instance of STLLoader.



11
12
13
14
# File 'lib/mittsu/loaders/stl_loader.rb', line 11

def initialize(manager = DefaultLoadingManager)
  @manager = manager
  @_listeners = {}
end

Instance Method Details

#load(url) ⇒ Object



16
17
18
19
20
21
# File 'lib/mittsu/loaders/stl_loader.rb', line 16

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

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

#parse(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mittsu/loaders/stl_loader.rb', line 23

def parse(data)
  reset_loader_vars
  stream = StringIO.new(data, "rb")
  # Load STL header (first 80 bytes max)
  header = stream.read(80)
  if header.slice(0,5) === "solid"
    stream.rewind
    parse_ascii(stream)
  else
    parse_binary(stream)
  end
  @group
end