Class: OpenUSD::Prim

Inherits:
Object
  • Object
show all
Defined in:
lib/openusd/prim.rb

Overview

Composed prim view on a Stage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage, path) ⇒ Prim

Returns a new instance of Prim.



8
9
10
11
# File 'lib/openusd/prim.rb', line 8

def initialize(stage, path)
  @stage = stage
  @path = Path.parse(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/openusd/prim.rb', line 6

def path
  @path
end

#stageObject (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

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/openusd/prim.rb', line 72

def active?
  authored = opinions.find { |opinion| opinion..key?("active") }
  authored ? authored.["active"] != false : true
end

#attribute(name) ⇒ Attribute?

Returns composed attribute by name.

Returns:

  • (Attribute, nil)

    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

#childrenArray<Prim>

Returns active direct children.

Returns:

  • (Array<Prim>)

    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.

Returns:



52
53
54
55
# File 'lib/openusd/prim.rb', line 52

def create_attribute(name, type_name)
  stage.author_attribute(path, name, type_name)
  Attribute.new(self, name)
end

#create_relationship(name) ⇒ Relationship

Create or return a relationship in the edit target.

Returns:



67
68
69
70
# File 'lib/openusd/prim.rb', line 67

def create_relationship(name)
  stage.author_relationship(path, name)
  Relationship.new(self, name)
end

#metadataMetadataView

Returns composed, writable metadata.

Returns:



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

#nameString

Returns final path component.

Returns:

  • (String)

    final path component



14
15
16
# File 'lib/openusd/prim.rb', line 14

def name
  path.to_s.split("/").last
end

#opinionsObject (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

#parentPrim, ...

Returns composed namespace parent.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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_nameString?

Returns strongest authored type name.

Returns:

  • (String, nil)

    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_setsHash

Returns composed variant-set definitions.

Returns:

  • (Hash)

    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