mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Materials of color work!
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class Wavefront
|
class Wavefront
|
||||||
class Material
|
class Material
|
||||||
def initialize(material_file)
|
attr_accessor :name, :ambient, :diffuse, :specular
|
||||||
|
def initialize(name)
|
||||||
|
@name = name
|
||||||
|
@ambient = Wavefront::Model::Color.new(1, 1, 1, 1)
|
||||||
|
@diffuse = Wavefront::Model::Color.new(1, 1, 1, 1)
|
||||||
|
@specular= Wavefront::Model::Color.new(1, 1, 1, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ class IMICFPS
|
|||||||
include GLU
|
include GLU
|
||||||
TextureCoordinate = Struct.new(:u, :v, :weight)
|
TextureCoordinate = Struct.new(:u, :v, :weight)
|
||||||
Vertex = Struct.new(:x, :y, :z, :weight)
|
Vertex = Struct.new(:x, :y, :z, :weight)
|
||||||
Color = Struct.new(:red, :green, :blue)
|
Color = Struct.new(:red, :green, :blue, :alpha)
|
||||||
|
|
||||||
attr_accessor :objects, :vertexes, :texures, :normals, :faces
|
attr_accessor :objects, :materials, :vertexes, :texures, :normals, :faces
|
||||||
|
|
||||||
def initialize(object = "objects/cube.obj")
|
def initialize(object = "objects/cube.obj")
|
||||||
@object_path = object
|
@object_path = object
|
||||||
@file = File.open(object, 'r')
|
@file = File.open(object, 'r')
|
||||||
@material_file = nil
|
@material_file = nil
|
||||||
@current_object= nil
|
@current_object = nil
|
||||||
|
@current_material=nil
|
||||||
@vertex_count = 0
|
@vertex_count = 0
|
||||||
@objects = []
|
@objects = []
|
||||||
|
@materials= {}
|
||||||
@vertices = []
|
@vertices = []
|
||||||
@uvs = []
|
@uvs = []
|
||||||
@normals = []
|
@normals = []
|
||||||
@@ -47,13 +49,12 @@ class IMICFPS
|
|||||||
vertex = vert[0]
|
vertex = vert[0]
|
||||||
uv = vert[1]
|
uv = vert[1]
|
||||||
normal = vert[2]
|
normal = vert[2]
|
||||||
color = vert[3]
|
material = vert[3]
|
||||||
# p vert if i > 0
|
|
||||||
|
|
||||||
glColor3f(color.red, color.green, color.blue)
|
glColor3f(material.diffuse.red, material.diffuse.green, material.diffuse.blue)
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [@color.red, @color.green, @color.blue, 1.0])
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [material.ambient.red, material.ambient.green, material.ambient.blue, 1.0])
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [@color.red, @color.green, @color.blue, 1.0])
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [material.diffuse.red, material.diffuse.green, material.diffuse.blue, 1.0])
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1,1,1,1])
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [material.specular.red, material.specular.green, material.specular.blue, 1.0])
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0])
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0])
|
||||||
glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale)
|
glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale)
|
||||||
glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale)
|
glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale)
|
||||||
@@ -119,10 +120,16 @@ class IMICFPS
|
|||||||
# puts array.join
|
# puts array.join
|
||||||
case array.first
|
case array.first
|
||||||
when 'newmtl'
|
when 'newmtl'
|
||||||
|
material = Material.new(array.last)
|
||||||
|
@current_material = array.last
|
||||||
|
@materials[array.last] = material
|
||||||
when 'Ns' # Specular Exponent
|
when 'Ns' # Specular Exponent
|
||||||
when 'Ka' # Ambient
|
when 'Ka' # Ambient
|
||||||
|
@materials[@current_material].ambient = Color.new(Float(array[1]), Float(array[2]), Float(array[3]))
|
||||||
when 'Kd' # Diffuse
|
when 'Kd' # Diffuse
|
||||||
|
@materials[@current_material].diffuse = Color.new(Float(array[1]), Float(array[2]), Float(array[3]))
|
||||||
when 'Ks' # Specular
|
when 'Ks' # Specular
|
||||||
|
@materials[@current_material].specular = Color.new(Float(array[1]), Float(array[2]), Float(array[3]))
|
||||||
when 'Ke' # Emissive
|
when 'Ke' # Emissive
|
||||||
when 'Ni' # Unknown (Blender Specific?)
|
when 'Ni' # Unknown (Blender Specific?)
|
||||||
when 'd' # Dissolved (Transparency)
|
when 'd' # Dissolved (Transparency)
|
||||||
@@ -137,11 +144,11 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_material(name)
|
def set_material(name)
|
||||||
# @current_object.
|
@current_material = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def material
|
def material
|
||||||
Color.new(rand(0.1..1.0), rand(0.1..1.0), rand(0.1..1.0))
|
@materials[@current_material]
|
||||||
end
|
end
|
||||||
|
|
||||||
def faces_count
|
def faces_count
|
||||||
|
|||||||
Reference in New Issue
Block a user