Module: Mittsu::ImageUtils

Defined in:
lib/mittsu/extras/image_utils.rb

Class Method Summary collapse

Class Method Details

.generate_data_texture(width, height, color) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mittsu/extras/image_utils.rb', line 44

def generate_data_texture(width, height, color)
  size = width * height
  data = Array.new(3 * size) # Uint8Array

  r = (color.r * 255).floor
  g = (color.g * 255).floor
  b = (color.b * 255).floor

  size.times do |i|
    data[i * 3]     = r
    data[i * 3 + 1] = g
    data[i * 3 + 2] = b
  end

  texture = DataTexture.new(data, width, height, RGBFormat)
  texture.needs_update = true

  texture
end

.get_normal_map(image, depth) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/mittsu/extras/image_utils.rb', line 33

def get_normal_map(image, depth)
  # adapted from http://www.paulbrunt.co.uk/lab/heightnormal/

  # depth |= 1
  #
  # width = image.width
  # height = image.height

  # TODO: original version uses browser features ...
end

.load_texture(url, mapping = Texture::DEFAULT_MAPPING, flip: true, flop: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/mittsu/extras/image_utils.rb', line 4

def load_texture(url, mapping = Texture::DEFAULT_MAPPING, flip: true, flop: false)
  loader = ImageLoader.new

  Texture.new(nil, mapping).tap do |texture|
    image = loader.load(url, flip: flip, flop: flop)
    texture.image = image
    texture.needs_update = true

    texture.source_file = url
  end
end

.load_texture_cube(array, mapping = Texture::DEFAULT_MAPPING) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mittsu/extras/image_utils.rb', line 16

def load_texture_cube(array, mapping = Texture::DEFAULT_MAPPING)
  images = HashArray.new

  loader = ImageLoader.new
  CubeTexture.new(images, mapping).tap do |texture|
    loaded = 0

    array.length.times do |i|
      texture.images[i] = loader.load(array[i])
      loaded += 1
      if loaded == 6
        texture.needs_update = true
      end
    end
  end
end