Class: Mittsu::Material
- Inherits:
-
Object
- Object
- Mittsu::Material
- Includes:
- EventDispatcher
- Defined in:
- lib/mittsu/materials/material.rb
Direct Known Subclasses
LineBasicMaterial, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, PointCloudMaterial, ShaderMaterial, SpriteMaterial
Instance Attribute Summary collapse
-
#alpha_map ⇒ Object
Returns the value of attribute alpha_map.
-
#alpha_test ⇒ Object
Returns the value of attribute alpha_test.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#blend_dst ⇒ Object
Returns the value of attribute blend_dst.
-
#blend_dst_alpha ⇒ Object
Returns the value of attribute blend_dst_alpha.
-
#blend_equation ⇒ Object
Returns the value of attribute blend_equation.
-
#blend_equation_alpha ⇒ Object
Returns the value of attribute blend_equation_alpha.
-
#blend_src ⇒ Object
Returns the value of attribute blend_src.
-
#blend_src_alpha ⇒ Object
Returns the value of attribute blend_src_alpha.
-
#blending ⇒ Object
Returns the value of attribute blending.
-
#bump_map ⇒ Object
Returns the value of attribute bump_map.
-
#color ⇒ Object
Returns the value of attribute color.
-
#color_write ⇒ Object
Returns the value of attribute color_write.
-
#combine ⇒ Object
Returns the value of attribute combine.
-
#default_attribute_values ⇒ Object
Returns the value of attribute default_attribute_values.
-
#defines ⇒ Object
Returns the value of attribute defines.
-
#depth_test ⇒ Object
Returns the value of attribute depth_test.
-
#depth_write ⇒ Object
Returns the value of attribute depth_write.
-
#env_map ⇒ Object
Returns the value of attribute env_map.
-
#fog ⇒ Object
Returns the value of attribute fog.
-
#fragment_shader ⇒ Object
Returns the value of attribute fragment_shader.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#light_map ⇒ Object
Returns the value of attribute light_map.
-
#lights ⇒ Object
Returns the value of attribute lights.
-
#map ⇒ Object
Returns the value of attribute map.
-
#metal ⇒ Object
Returns the value of attribute metal.
-
#morph_normals ⇒ Object
Returns the value of attribute morph_normals.
-
#morph_targets ⇒ Object
Returns the value of attribute morph_targets.
-
#name ⇒ Object
Returns the value of attribute name.
-
#normal_map ⇒ Object
Returns the value of attribute normal_map.
-
#opacity ⇒ Object
Returns the value of attribute opacity.
-
#overdraw ⇒ Object
Returns the value of attribute overdraw.
-
#polygon_offset ⇒ Object
Returns the value of attribute polygon_offset.
-
#polygon_offset_factor ⇒ Object
Returns the value of attribute polygon_offset_factor.
-
#polygon_offset_units ⇒ Object
Returns the value of attribute polygon_offset_units.
-
#program ⇒ Object
Returns the value of attribute program.
-
#reflectivity ⇒ Object
Returns the value of attribute reflectivity.
-
#refraction_ratio ⇒ Object
Returns the value of attribute refraction_ratio.
-
#shading ⇒ Object
Returns the value of attribute shading.
-
#side ⇒ Object
Returns the value of attribute side.
-
#size_attenuation ⇒ Object
Returns the value of attribute size_attenuation.
-
#skinning ⇒ Object
Returns the value of attribute skinning.
-
#specular_map ⇒ Object
Returns the value of attribute specular_map.
-
#transparent ⇒ Object
Returns the value of attribute transparent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uniforms ⇒ Object
Returns the value of attribute uniforms.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
-
#vertex_colors ⇒ Object
Returns the value of attribute vertex_colors.
-
#vertex_shader ⇒ Object
Returns the value of attribute vertex_shader.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#wireframe ⇒ Object
Returns the value of attribute wireframe.
-
#wrap_around ⇒ Object
Returns the value of attribute wrap_around.
Instance Method Summary collapse
- #clone(material = Material.new) ⇒ Object
- #dispose ⇒ Object
-
#initialize ⇒ Material
constructor
A new instance of Material.
- #needs_update=(value) ⇒ Object
- #needs_update? ⇒ Boolean
- #set_values(values = nil) ⇒ Object
- #to_json ⇒ Object
- #update ⇒ Object
Methods included from EventDispatcher
#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener
Constructor Details
#initialize ⇒ Material
Returns a new instance of Material.
17 18 19 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 |
# File 'lib/mittsu/materials/material.rb', line 17 def initialize super @id = (@@id ||= 1).tap { @@id += 1 } @uuid = SecureRandom.uuid @name = '' @type = 'Material' @side = FrontSide @opacity = 1.0 @transparent = false @blending = NormalBlending @blend_src = SrcAlphaFactor @blend_dst = OneMinusSrcAlphaFactor @blend_equation = AddEquation @blend_src_alpha = nil @blend_dst_alpha = nil @blend_equation_alpha = nil @depth_test = true @depth_write = true @color_write = true @polygon_offset = false @polygon_offset_factor = 0 @polygon_offset_units = 0 @alpha_test = 0 # TODO: remove this maybe??? @overdraw = 0 # Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer @visible = true @_needs_update = true end |
Instance Attribute Details
#alpha_map ⇒ Object
Returns the value of attribute alpha_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def alpha_map @alpha_map end |
#alpha_test ⇒ Object
Returns the value of attribute alpha_test.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def alpha_test @alpha_test end |
#attributes ⇒ Object
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def attributes @attributes end |
#blend_dst ⇒ Object
Returns the value of attribute blend_dst.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_dst @blend_dst end |
#blend_dst_alpha ⇒ Object
Returns the value of attribute blend_dst_alpha.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_dst_alpha @blend_dst_alpha end |
#blend_equation ⇒ Object
Returns the value of attribute blend_equation.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_equation @blend_equation end |
#blend_equation_alpha ⇒ Object
Returns the value of attribute blend_equation_alpha.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_equation_alpha @blend_equation_alpha end |
#blend_src ⇒ Object
Returns the value of attribute blend_src.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_src @blend_src end |
#blend_src_alpha ⇒ Object
Returns the value of attribute blend_src_alpha.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blend_src_alpha @blend_src_alpha end |
#blending ⇒ Object
Returns the value of attribute blending.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def blending @blending end |
#bump_map ⇒ Object
Returns the value of attribute bump_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def bump_map @bump_map end |
#color ⇒ Object
Returns the value of attribute color.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def color @color end |
#color_write ⇒ Object
Returns the value of attribute color_write.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def color_write @color_write end |
#combine ⇒ Object
Returns the value of attribute combine.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def combine @combine end |
#default_attribute_values ⇒ Object
Returns the value of attribute default_attribute_values.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def default_attribute_values @default_attribute_values end |
#defines ⇒ Object
Returns the value of attribute defines.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def defines @defines end |
#depth_test ⇒ Object
Returns the value of attribute depth_test.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def depth_test @depth_test end |
#depth_write ⇒ Object
Returns the value of attribute depth_write.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def depth_write @depth_write end |
#env_map ⇒ Object
Returns the value of attribute env_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def env_map @env_map end |
#fog ⇒ Object
Returns the value of attribute fog.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def fog @fog end |
#fragment_shader ⇒ Object
Returns the value of attribute fragment_shader.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def fragment_shader @fragment_shader end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/mittsu/materials/material.rb', line 7 def id @id end |
#light_map ⇒ Object
Returns the value of attribute light_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def light_map @light_map end |
#lights ⇒ Object
Returns the value of attribute lights.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def lights @lights end |
#map ⇒ Object
Returns the value of attribute map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def map @map end |
#metal ⇒ Object
Returns the value of attribute metal.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def @metal end |
#morph_normals ⇒ Object
Returns the value of attribute morph_normals.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def morph_normals @morph_normals end |
#morph_targets ⇒ Object
Returns the value of attribute morph_targets.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def morph_targets @morph_targets end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def name @name end |
#normal_map ⇒ Object
Returns the value of attribute normal_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def normal_map @normal_map end |
#opacity ⇒ Object
Returns the value of attribute opacity.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def opacity @opacity end |
#overdraw ⇒ Object
Returns the value of attribute overdraw.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def overdraw @overdraw end |
#polygon_offset ⇒ Object
Returns the value of attribute polygon_offset.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def polygon_offset @polygon_offset end |
#polygon_offset_factor ⇒ Object
Returns the value of attribute polygon_offset_factor.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def polygon_offset_factor @polygon_offset_factor end |
#polygon_offset_units ⇒ Object
Returns the value of attribute polygon_offset_units.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def polygon_offset_units @polygon_offset_units end |
#program ⇒ Object
Returns the value of attribute program.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def program @program end |
#reflectivity ⇒ Object
Returns the value of attribute reflectivity.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def reflectivity @reflectivity end |
#refraction_ratio ⇒ Object
Returns the value of attribute refraction_ratio.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def refraction_ratio @refraction_ratio end |
#shading ⇒ Object
Returns the value of attribute shading.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def shading @shading end |
#side ⇒ Object
Returns the value of attribute side.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def side @side end |
#size_attenuation ⇒ Object
Returns the value of attribute size_attenuation.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def size_attenuation @size_attenuation end |
#skinning ⇒ Object
Returns the value of attribute skinning.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def skinning @skinning end |
#specular_map ⇒ Object
Returns the value of attribute specular_map.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def specular_map @specular_map end |
#transparent ⇒ Object
Returns the value of attribute transparent.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def transparent @transparent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/mittsu/materials/material.rb', line 7 def type @type end |
#uniforms ⇒ Object
Returns the value of attribute uniforms.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def uniforms @uniforms end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/mittsu/materials/material.rb', line 7 def uuid @uuid end |
#vertex_colors ⇒ Object
Returns the value of attribute vertex_colors.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def vertex_colors @vertex_colors end |
#vertex_shader ⇒ Object
Returns the value of attribute vertex_shader.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def vertex_shader @vertex_shader end |
#visible ⇒ Object
Returns the value of attribute visible.
9 10 11 |
# File 'lib/mittsu/materials/material.rb', line 9 def visible @visible end |
#wireframe ⇒ Object
Returns the value of attribute wireframe.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def wireframe @wireframe end |
#wrap_around ⇒ Object
Returns the value of attribute wrap_around.
13 14 15 |
# File 'lib/mittsu/materials/material.rb', line 13 def wrap_around @wrap_around end |
Instance Method Details
#clone(material = Material.new) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/mittsu/materials/material.rb', line 110 def clone(material = Material.new) material.name = @name material.side = @side material.opacity = @opacity material.transparent = @transparent material.blending = @blending material.blend_src = @blend_src material.blend_dst = @blend_dst material.blend_equation = @blend_equation material.blend_src_alpha = @blend_src_alpha material.blend_dst_alpha = @blend_dst_alpha material.blend_equation_alpha = @blend_equation_alpha material.depth_test = @depth_test material.depth_write = @depth_write material.color_write = @color_write material.polygon_offset = @polygon_offset material.polygon_offset_factor = @polygon_offset_factor material.polygon_offset_units = @polygon_offset_units material.alpha_test = @alpha_test material.overdraw = @overdraw material.visible = @visible end |
#dispose ⇒ Object
137 138 139 |
# File 'lib/mittsu/materials/material.rb', line 137 def dispose dispatch_event type: :dispose end |
#needs_update=(value) ⇒ Object
63 64 65 66 |
# File 'lib/mittsu/materials/material.rb', line 63 def needs_update=(value) update if value @_needs_update = value end |
#needs_update? ⇒ Boolean
59 60 61 |
# File 'lib/mittsu/materials/material.rb', line 59 def needs_update? @_needs_update end |
#set_values(values = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mittsu/materials/material.rb', line 68 def set_values(values = nil) return if values.nil? values.each do |(key, new_value)| if new_value.nil? puts "WARNING: Mittsu::Material: #{key} parameter is undefined" next end if has_property? key current_value = get_property(key) if current_value.is_a? Color current_value.set(new_value) elsif current_value.is_a?(Vector3) && new_value.is_a?(Vector3) current_value.copy(new_value) else set_property(key, new_value) end end end end |
#to_json ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mittsu/materials/material.rb', line 91 def to_json output = { metadata: { version: 4.2, type: 'material', generator: 'MaterialExporter' }, uuid: @uuid, type: @type } output[:name] = @name if !@name.nil? && !@name.empty? output[:opacity] = @opacity if @opacity < 1.0 output[:transparent] = @transparent if @transparent output[:wireframe] = @wireframe if @wireframe output end |
#update ⇒ Object
133 134 135 |
# File 'lib/mittsu/materials/material.rb', line 133 def update dispatch_event type: :update end |