Class: OpenUSD::Prim
- Inherits:
-
Object
- Object
- OpenUSD::Prim
- Defined in:
- lib/openusd/prim.rb
Overview
Composed prim view on a Stage.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#attribute(name) ⇒ Attribute?
Composed attribute by name.
-
#children ⇒ Array<Prim>
Active direct children.
-
#create_attribute(name, type_name) ⇒ Attribute
Create or return an attribute in the edit target.
-
#create_relationship(name) ⇒ Relationship
Create or return a relationship in the edit target.
-
#initialize(stage, path) ⇒ Prim
constructor
A new instance of Prim.
-
#metadata ⇒ MetadataView
Composed, writable metadata.
-
#name ⇒ String
Final path component.
-
#opinions ⇒ Object
protected
private
Return all composed opinions for this prim.
-
#parent ⇒ Prim, ...
Composed namespace parent.
- #property_opinions(name) ⇒ Array<AttributeSpec, RelationshipSpec> private
-
#relationship(name) ⇒ Relationship?
Composed relationship by name.
-
#set_variant_selection(set_name, choice) ⇒ Prim
Author a variant selection.
-
#type_name ⇒ String?
Strongest authored type name.
-
#type_name=(value) ⇒ Object
Author a type name in the edit target.
-
#variant_sets ⇒ Hash
Composed variant-set definitions.
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/openusd/prim.rb', line 6 def path @path end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
6 7 8 |
# File 'lib/openusd/prim.rb', line 6 def stage @stage end |
Instance Method Details
#active? ⇒ Boolean
72 73 74 75 |
# File 'lib/openusd/prim.rb', line 72 def active? = opinions.find { |opinion| opinion..key?("active") } ? .["active"] != false : true end |
#attribute(name) ⇒ Attribute?
Returns composed attribute by name.
43 44 45 46 47 48 |
# File 'lib/openusd/prim.rb', line 43 def attribute(name) properties = property_opinions(name) return unless properties.first.is_a?(AttributeSpec) Attribute.new(self, name) end |
#children ⇒ Array<Prim>
Returns active direct children.
38 39 40 |
# File 'lib/openusd/prim.rb', line 38 def children stage.child_paths(path).filter_map { |child_path| stage.prim_at(child_path) } end |
#create_attribute(name, type_name) ⇒ Attribute
Create or return an attribute in the edit target.
52 53 54 55 |
# File 'lib/openusd/prim.rb', line 52 def create_attribute(name, type_name) stage.(path, name, type_name) Attribute.new(self, name) end |
#create_relationship(name) ⇒ Relationship
Create or return a relationship in the edit target.
67 68 69 70 |
# File 'lib/openusd/prim.rb', line 67 def create_relationship(name) stage.(path, name) Relationship.new(self, name) end |
#metadata ⇒ MetadataView
Returns composed, writable metadata.
78 79 80 81 |
# File 'lib/openusd/prim.rb', line 78 def values = opinions.reverse_each.with_object({}) { |opinion, result| result.merge!(opinion.) } MetadataView.new(values, writer: method(:write_metadata)) end |
#name ⇒ String
Returns final path component.
14 15 16 |
# File 'lib/openusd/prim.rb', line 14 def name path.to_s.split("/").last end |
#opinions ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return all composed opinions for this prim.
107 108 109 |
# File 'lib/openusd/prim.rb', line 107 def opinions stage.opinions_for(path) end |
#parent ⇒ Prim, ...
Returns composed namespace parent.
29 30 31 32 33 34 35 |
# File 'lib/openusd/prim.rb', line 29 def parent parent_path = path.parent return stage.pseudo_root if parent_path&.to_s == "/" return unless parent_path stage.prim_at(parent_path) end |
#property_opinions(name) ⇒ Array<AttributeSpec, RelationshipSpec>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/openusd/prim.rb', line 99 def property_opinions(name) opinions.filter_map { |opinion| opinion.property_named(name) } end |
#relationship(name) ⇒ Relationship?
Returns composed relationship by name.
58 59 60 61 62 63 |
# File 'lib/openusd/prim.rb', line 58 def relationship(name) properties = property_opinions(name) return unless properties.first.is_a?(RelationshipSpec) Relationship.new(self, name) end |
#set_variant_selection(set_name, choice) ⇒ Prim
Author a variant selection.
92 93 94 95 |
# File 'lib/openusd/prim.rb', line 92 def set_variant_selection(set_name, choice) stage.set_variant_selection(path, set_name, choice) self end |
#type_name ⇒ String?
Returns strongest authored type name.
19 20 21 |
# File 'lib/openusd/prim.rb', line 19 def type_name opinions.filter_map(&:type_name).find { |value| !value.empty? } end |
#type_name=(value) ⇒ Object
Author a type name in the edit target.
24 25 26 |
# File 'lib/openusd/prim.rb', line 24 def type_name=(value) stage.set_prim_type(path, value) end |
#variant_sets ⇒ Hash
Returns composed variant-set definitions.
84 85 86 87 88 |
# File 'lib/openusd/prim.rb', line 84 def variant_sets opinions.reverse_each.with_object({}) do |opinion, result| result.merge!(opinion.variant_sets) if opinion.respond_to?(:variant_sets) end end |