Class: Mittsu::OBJMTLLoader

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

Instance Method Summary collapse

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(manager = DefaultLoadingManager) ⇒ OBJMTLLoader

Returns a new instance of OBJMTLLoader.



5
6
7
# File 'lib/mittsu/loaders/obj_mtl_loader.rb', line 5

def initialize(manager = DefaultLoadingManager)
  @manager = manager
end

Instance Method Details

#load(url, mtlurl = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mittsu/loaders/obj_mtl_loader.rb', line 9

def load(url, mtlurl = nil)
  object = OBJLoader.new(@manager).load(url)

  if !mtlurl.nil?
    mtl_loader = MTLLoader.new(File.dirname(url))
    materials_creator = mtl_loader.load(mtlurl)

    materials_creator.preload

    object.traverse do |child_object|
      if child_object.is_a?(Mesh) && child_object.material.name && !child_object.material.name.empty?
        material = materials_creator.create(child_object.material.name)
        child_object.material = material if material
      end
    end
  end

  object
end