20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/mittsu/loaders/loader.rb', line 20
def create_material(m, texture_path)
mtype = 'MeshLambertMaterial'
mpars = {
color: 0xeeeeee,
opactity: 1.0,
map: nil,
light_map: nil,
normal_map: nil,
bump_map: nil,
wireframe: false
}
if m.shading
shading = m.shading.downcase
if shading == 'phong'
mtype = 'MeshPhongMaterial'
elsif shading == 'basic'
mtype = 'MeshBasicMaterial'
end
end
if m.blending && Mittsu.const_get(m.blending)
mpars[:blending] = Mittsu.const_get(m.blending)
end
mpars[:transparent] = m.transparent if !m.transparent.nil?
mpars[:transparent] = true if m.opacity && m.opacity < 1.0
mpars[:depth_test] = m.depth_test if !m.depth_test.nil?
mpars[:depth_write] = m.depth_write if !m.depth_write.nil?
mpars[:visible] = m.visible if !m.visible.nil?
mpars[:flip_sided] = BackSide if !m.flip_sided.nil?
mpars[:double_sided] = DoubleSide if !m.double_sided.nil?
mpars[:wireframe] = m.wireframe if !m.wireframe.nil?
if !m.vertex_colors.nil?
if m.vertex_colors == 'face'
mpars[:vertex_colors] = FaceColors
elsif !m.vertex_colors.empty?
mpars[:vertex_colors] = VertexColors
end
end
if m.color_diffuse
mpars[:color] = rgb2hex(m.color_diffuse)
elsif m.dgb_color
mpars[:color] = m.dgb_color
end
if m.color_specular
mpars[:specular] = rgb2hex(m.color_specular)
end
if m.color_emissive
mpars[:emissive] = rgb2hex(m.color_emissive)
end
if !m.transparency.nil?
puts "WARNING: Mitsu::Loader: transparency has been renamed to opacity"
m.opacity = m.transparency
end
if !m.opacity.nil?
mpars[:opacity] = m.opacity
end
if m.specular_coef
mpars[:shininess] = m.specular_coef
end
if m.map_diffuse && texture_path
create_texture(mpars, 'map', m.map_diffuse, m.map_diffuse_repeat, m.map_diffuse_offset, m.map_diffuse_wrap, m.map_diffuse_anisotropy)
end
if m.map_light && texture_path
create_texture(mpars, 'light_map', m.map_light, m.map_light_repeat, m.map_light_offset, m.map_light_wrap, m.map_light_anisotropy)
end
if m.map_bump && texture_path
create_texture(mpars, 'bump_map', m.map_bump, m.map_bump_repeat, m.map_bump_offset, m.map_bump_wrap, m.map_bump_anisotropy)
end
if m.map_normal && texture_path
create_texture(mpars, 'normal_map', m.map_normal, m.map_normal_repeat, m.map_normal_offset, m.map_normal_wrap, m.map_normal_anisotropy)
end
if m.map_specular && texture_path
create_texture(mpars, 'specular_map', m.map_specular, m.map_specular_repeat, m.map_specular_offset, m.map_specular_wrap, m.map_specular_anisotropy)
end
if m.map_alpha && texture_path
create_texture(mpars, 'alpha_map', m.map_alpha, m.map_alpha_repeat, m.map_alpha_offset, m.map_alpha_wrap, m.map_alpha_anisotropy)
end
if m.map_bump_scale
mpars[:bump_scale] = m.map_bump_scale
end
if m.map_normal_factor
mpars[:normal_scale] = Vector2.new(m.map_normal_factor, m.map_normal_factor)
end
Mittsu.const_get(mtype).new(mpars).tap do |material|
material.name = m.dbg_name if !m.dbg_name.nil?
end
end
|