Class: CyberarmEngine::Model::Mesh
- Inherits:
-
Object
- Object
- CyberarmEngine::Model::Mesh
- Defined in:
- lib/cyberarm_engine/model/mesh.rb
Instance Attribute Summary collapse
-
#bounding_box ⇒ Object
readonly
Returns the value of attribute bounding_box.
-
#debug_color ⇒ Object
readonly
Returns the value of attribute debug_color.
-
#faces ⇒ Object
Returns the value of attribute faces.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#materials ⇒ Object
readonly
Returns the value of attribute materials.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#normals ⇒ Object
readonly
Returns the value of attribute normals.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#uvs ⇒ Object
readonly
Returns the value of attribute uvs.
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
Instance Method Summary collapse
- #flattened_materials ⇒ Object
- #flattened_normals ⇒ Object
- #flattened_uvs ⇒ Object
- #flattened_vertices ⇒ Object
- #flattened_vertices_size ⇒ Object
- #has_texture? ⇒ Boolean
-
#initialize(id, name) ⇒ Mesh
constructor
A new instance of Mesh.
- #reflatten ⇒ Object
Constructor Details
#initialize(id, name) ⇒ Mesh
Returns a new instance of Mesh.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 7 def initialize(id, name) @id = id @name = name @vertices = [] @uvs = [] @normals = [] @faces = [] @materials = [] @bounding_box = BoundingBox.new @debug_color = Color.new(1.0, 1.0, 1.0) @scale = 1.0 # Faces array packs everything: # vertex = index[0] # uv = index[1] # normal = index[2] # material = index[3] end |
Instance Attribute Details
#bounding_box ⇒ Object (readonly)
Returns the value of attribute bounding_box.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def bounding_box @bounding_box end |
#debug_color ⇒ Object (readonly)
Returns the value of attribute debug_color.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def debug_color @debug_color end |
#faces ⇒ Object
Returns the value of attribute faces.
5 6 7 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 5 def faces @faces end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def id @id end |
#materials ⇒ Object (readonly)
Returns the value of attribute materials.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def materials @materials end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def name @name end |
#normals ⇒ Object (readonly)
Returns the value of attribute normals.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def normals @normals end |
#scale ⇒ Object
Returns the value of attribute scale.
5 6 7 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 5 def scale @scale end |
#uvs ⇒ Object (readonly)
Returns the value of attribute uvs.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def uvs @uvs end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
4 5 6 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 4 def vertices @vertices end |
Instance Method Details
#flattened_materials ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 108 def flattened_materials unless @materials_list list = [] @faces.each do |face| material = face.material next unless material face.vertices.each do # Add material to each vertex list << material.diffuse.red list << material.diffuse.green list << material.diffuse.blue # list << material.alpha end end @materials_list_size = list.size @materials_list = list.pack("f*") end @materials_list end |
#flattened_normals ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 88 def flattened_normals unless @normals_list list = [] @faces.each do |face| face.normals.each do |n| next unless n list << n.x list << n.y list << n.z end end @normals_list_size = list.size @normals_list = list.pack("f*") end @normals_list end |
#flattened_uvs ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 68 def flattened_uvs unless @uvs_list list = [] @faces.each do |face| face.uvs.each do |v| next unless v list << v.x list << v.y list << v.z end end @uvs_list_size = list.size @uvs_list = list.pack("f*") end @uvs_list end |
#flattened_vertices ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 41 def flattened_vertices unless @vertices_list @debug_color = @faces.first.material.diffuse list = [] @faces.each do |face| face.vertices.each do |v| next unless v list << v.x * @scale list << v.y * @scale list << v.z * @scale list << v.weight end end @vertices_list_size = list.size @vertices_list = list.pack("f*") end @vertices_list end |
#flattened_vertices_size ⇒ Object
64 65 66 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 64 def flattened_vertices_size @vertices_list_size end |
#has_texture? ⇒ Boolean
27 28 29 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 27 def has_texture? @materials.find { |mat| mat.texture_id } ? true : false end |
#reflatten ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cyberarm_engine/model/mesh.rb', line 31 def reflatten @vertices_list = nil @uvs_list = nil @normals_list = nil flattened_vertices flattened_uvs flattened_normals end |