Class: ModraUp::Material
- Inherits:
-
ModraUp::Entity
- Object
- ModraUp::Entity
- ModraUp::Material
Overview
A material: name, color, transparency, and an optional texture. The parent class is ModraUp::Entity, not a Drawingelement. Textured shading is done using #colorize_type (COLORIZE_SHIFT / COLORIZE_TINT).
Constants # collapse
- ModraUp::Material::MATERIAL_SOLID
MATERIAL_SOLID = 0
ModraUp::Material#materialType: Solid color.
- ModraUp::Material::MATERIAL_TEXTURED
MATERIAL_TEXTURED = 1
ModraUp::Material#materialType: Textured.
- ModraUp::Material::MATERIAL_COLORIZED_TEXTURED
MATERIAL_COLORIZED_TEXTURED = 2
ModraUp::Material#materialType: colored textured material.
- ModraUp::Material::COLORIZE_SHIFT
COLORIZE_SHIFT = 0
ModraUp::Material#colorize_type: Colorize by hue shift (official default).
- ModraUp::Material::COLORIZE_TINT
COLORIZE_TINT = 1
ModraUp::Material#colorize_type:Colorize by target hue. When setting #color= for a material with a texture, the hue will be adjusted accordingly.
Instance Method Summary # collapse
-
#hatch_pattern ⇒ ModraUp::HatchPattern, nil
Read the hatch pattern of the material: returns the section fill pattern used for sections of groups and components (including nested content that inherits this material).
-
#hatch_pattern=(hatch_pattern) ⇒ ModraUp::HatchPattern, nil
Sets the material's hatch pattern; nil removes the pattern.
-
#name ⇒ String
Internal unique name. Interface display uses #display_name.
-
#name=(name) ⇒ String
Rename. Throws an error if the name already exists for another material.
-
#display_name ⇒ String
Display name. Remove square brackets when the name is in the format [Joe].
-
#write_thumbnail(path, max_size) ⇒ Boolean, nil
Write the material's color or texture thumbnail to an image file while maintaining the aspect ratio.
-
#color ⇒ ModraUp::Color
Material color.
-
#color=(color) ⇒ ModraUp::Color, Array<Numeric>
Set the color. Accepts ModraUp::Color or [r, g, b] (0–255).
-
#alpha ⇒ Float
Opacity, 0.0–1.0.
-
#alpha=(value) ⇒ Numeric
Set opacity, values outside the 0–1 range will be clamped.
-
#use_alpha? ⇒ Boolean
Returns true if the material's opacity is less than 1.
-
#texture ⇒ ModraUp::Texture, nil
Texture. Returns nil if no texture is set.
-
#texture=(filename) ⇒ Object
Set the texture. nil clears it. The path reads in raw bytes; the default tile size is 10x10 inches. The array format is [filename, width, height].
-
#materialType ⇒ Integer
MATERIAL_SOLID / MATERIAL_TEXTURED / MATERIAL_COLORIZED_TEXTURED。
-
#colorize_type ⇒ Integer
COLORIZE_SHIFT or COLORIZE_TINT. Readable even without a texture; defaults to SHIFT.
-
#colorize_type=(type) ⇒ Integer
Sets the coloring method. Only accepts COLORIZE_SHIFT / COLORIZE_TINT.
-
#colorize_deltas(Float, Float, Float) ⇒ Array<Float>
HLS delta from texture average color to material color: hue (degrees), saturation, lightness. Returns [0, 0, 0] when there is no texture or the pixels cannot be solved.
-
#== ⇒ Boolean
Returns true if the same model and slot are identical.
Inherited from ModraUp::Entity
-
#typename ⇒ String
Type name (e.g., Face / Edge / Group).
-
#entityID ⇒ Integer
Entity ID within the current session: A small integer starting from 1 that increments and remains constant for the lifetime of the entity, unchanged by undo/redo operations. This ID is not preserved when saving the file; it will be renumbered upon reopening the model. For cross-session identification, use #persistent_id. Copied entities will receive new IDs.
-
#add_observer(observer) ⇒ Boolean
Register a ModraUp::EntityObserver. Adding the same object a second time returns false. Locking, property, and material changes will dispatch an onChangeEntity event.
-
#remove_observer(observer) ⇒ Boolean
Remove the entity observer.
-
#persistent_id ⇒ Integer
Number assigned with the model: A unique, incrementing small integer starting from 1 that persists across model saves and reloads, independent of #entityID. Copied entities receive new numbers, and deleted entities do not reuse their numbers. Edges, faces, vertices, curves, groups, component instances/definitions, dimensions, leader lines/points, section planes, materials, layers, layer folders, and drawing sheets have assigned numbers; all others (rings, EdgeUses, attribute dictionaries, line types, sets, etc.) return 0.
-
#parent ⇒ ModraUp::Model, ModraUp::ComponentDefinition
Returns the owner of this drawing context. At the root this is the model. Inside a definition it is the definition itself.
-
#model ⇒ ModraUp::Model
The model it belongs to.
-
#to_s ⇒ String
String form. Returns "#<Deleted Entity>” when the entity has been deleted.
-
#inspect ⇒ String
Same as #to_s.
-
#attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
Collection of attribute dictionaries. Returns nil (evaluates to false) if there are no dictionaries.
-
#attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nil
Retrieve an attribute dictionary by name. If none exists, return nil; if create is true, create an empty dictionary. ModraUp::Loop / ModraUp::EdgeUse / ModraUp::Curve always return nil.
-
#valid? ⇒ Boolean
Returns true if the entity is valid, meaning it has not been deleted from the model. Revoked entities are false; even if new geometry is drawn occupying its original position, this object remains an invalid entity (still false). Repeating the action to restore it makes it valid again.
-
#deleted? ⇒ Boolean
Opposite of #valid?.
-
#set_attribute(dict_name, key, value) ⇒ Object
Write attribute values. Materials, groups, component instances, faces, and edges are supported. When dict_name and key are Symbols, they are converted to strings. The type of data written is the same type that will be read back.
-
#get_attribute(dict_name, key, default = nil) ⇒ Object
Read the attribute. If dict_name and key are Symbols, convert them to strings (similar to SketchUp). If the dictionary or key does not exist, return default. The return value type is the same as what is written by #set_attribute.
-
#delete_attribute(dict_name) ⇒ Boolean
Delete a key, or delete the entire dictionary when the key is omitted.
Instance Method Details
#hatch_pattern ⇒ ModraUp::HatchPattern, nil
Read the hatch pattern of the material: returns the section fill pattern used for sections of groups and components (including nested content that inherits this material).
#hatch_pattern=(hatch_pattern) ⇒ ModraUp::HatchPattern, nil
Sets the material's hatch pattern; nil removes the pattern.
material.name ⇒ String
Internal unique name. Interface display uses #display_name.
material.name=(name) ⇒ name
Rename. Throws an error if the name already exists for another material.
material.display_name ⇒ String
Display name. Remove square brackets when the name is in the format [Joe].
material.write_thumbnail(path, max_size) ⇒ Boolean, nil
Write the material's color or texture thumbnail to an image file while maintaining the aspect ratio.
material.color ⇒ ModraUp::Color
Material color.
material.color=(color) ⇒ color
Set the color. Accepts ModraUp::Color or [r, g, b] (0–255).
material.alpha ⇒ Float
Opacity, 0.0–1.0.
material.alpha=(value) ⇒ value
Set opacity, values outside the 0–1 range will be clamped.
material.use_alpha? ⇒ Boolean
Returns true if the material's opacity is less than 1.
material.texture ⇒ ModraUp::Texture, nil
Texture. Returns nil if no texture is set.
material.texture=(filename) ⇒ filenamematerial.texture=(properties) ⇒ propertiesmaterial.texture=(texture) ⇒ texturematerial.texture=(nil) ⇒ nil
Set the texture. nil clears it. The path reads in raw bytes; the default tile size is 10x10 inches. The array format is [filename, width, height].
Untextured materials use the average texture color for image decoding success, displaying as a solid color; existing textures retain their color.
material.materialType ⇒ Integer
MATERIAL_SOLID / MATERIAL_TEXTURED / MATERIAL_COLORIZED_TEXTURED。
material.colorize_type ⇒ Integer
COLORIZE_SHIFT or COLORIZE_TINT. Readable even without a texture; defaults to SHIFT.
material.colorize_type=(type) ⇒ type
Sets the coloring method. Only accepts COLORIZE_SHIFT / COLORIZE_TINT.
material.colorize_deltas ⇒ Array(Float, Float, Float)
HLS delta from texture average color to material color: hue (degrees), saturation, lightness. Returns [0, 0, 0] when there is no texture or the pixels cannot be solved.
material == other ⇒ Boolean
Returns true if the same model and slot are identical.