Class: OpenUSD::AssetResolver

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

Overview

Resolves authored asset paths relative to their containing layer.

Constant Summary collapse

MISSING_POLICIES =

Supported unresolved-asset behaviors.

%i[error warn ignore].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_paths: [], missing_assets: :error) ⇒ AssetResolver

Returns a new instance of AssetResolver.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/openusd/asset_resolver.rb', line 13

def initialize(search_paths: [], missing_assets: :error)
  @search_paths = search_paths.map { |path| File.expand_path(path) }.freeze
  @missing_assets = missing_assets.to_sym
  return if MISSING_POLICIES.include?(@missing_assets)

  raise ArgumentError, "invalid missing-assets policy: #{missing_assets.inspect}"
end

Instance Attribute Details

#missing_assetsObject (readonly)

Returns the value of attribute missing_assets.



11
12
13
# File 'lib/openusd/asset_resolver.rb', line 11

def missing_assets
  @missing_assets
end

#search_pathsObject (readonly)

Returns the value of attribute search_paths.



11
12
13
# File 'lib/openusd/asset_resolver.rb', line 11

def search_paths
  @search_paths
end

Instance Method Details

#resolve(asset_path, anchor: nil) ⇒ String?

Resolve an asset path, optionally anchored to a layer identifier.

Returns:

  • (String, nil)


23
24
25
26
27
28
29
30
31
32
# File 'lib/openusd/asset_resolver.rb', line 23

def resolve(asset_path, anchor: nil)
  authored = asset_path.is_a?(AssetPath) ? asset_path.path : asset_path.to_s
  return resolve_package_asset(authored, anchor) if package_uri?(anchor)
  return File.expand_path(anchor) if authored.empty? && anchor

  resolved = candidates(authored, anchor).find { |candidate| File.file?(candidate) }
  return resolved if resolved

  missing(authored, anchor)
end