An HDRI Skybox Librarian is an HDRI skybox records database.
An HDRI skybox is a background image with real-world lighting data. See the hdri.py
example controller.
from tdw.librarian import HDRISkyboxLibrarian
lib = HDRISkyboxLibrarian()
from tdw.librarian import HDRISkyboxLibrarian
lib = HDRISkyboxLibrarian(library="path/to/your/database/file.json")
An HDRI Skybox Librarian contains HDRISkyboxRecord
objects.
record = lib.records[0]
print(record.name) # aft_lounge_4k
There is only one HDRI skybox library: hdri_skyboxes.json
. You can define it explicitly, or not.
from tdw.librarian import HDRISkyboxLibrarian
# These constructors will load the same records database.
lib = HDRISkyboxLibrarian()
lib = HDRISkyboxLibrarian(library="hdri_skyboxes.json")
Send the add_hdri_skybox
command to add an HDRI skybox from a remote or local asset bundle.
from tdw.controller import Controller
c = Controller()
init(c) # Initialize the scene. Your code here.
record = get_record() # Get an HDRI skybox record. Your code here.
c.communicate({"$type": "add_hdri_skybox",
"name": record.name,
"url": record.get_url(),
"exposure": record.exposure,
"initial_skybox_rotation": record.initial_skybox_rotation,
"sun_elevation": record.sun_elevation,
"sun_initial_angle": record.sun_initial_angle,
"sun_intensity": record.sun_intensity})
The Controller
class includes a few helper functions for adding HDRI skyboxes. See the Controller documentation.
A record of an HDRI Skybox asset bundle.
from tdw.librarian import HDRISkyboxRecord
record = HDRISkyboxRecord () # Creates a record with blank or default values.
from tdw.librarian import HDRISkyboxRecord
record = HDRISkyboxRecord(data=data) # Creates a record from JSON data.
Field | Type | Description |
---|---|---|
name |
str | The name of the skybox. |
urls |
Dict[str, str] | A dictionary of URLs or local filepaths of asset bundles per platform. See: HDRISkyboxRecord.get_url() |
color_temperature |
float | |
sun_elevation |
float | |
sun_initial_angle |
float | |
sun_intensity |
float | |
intial_skybox_rotation |
float | |
exposure |
float | |
location |
str | Interior or exterior. Useful for deciding what skybox to load. |
Returns the URL of the asset bundle for this platform. This is a wrapper for record.urls
.
lib = HDRISkyboxLibrarian()
record = lib.records[0]
print(record.get_url())
Field | Type | Description |
---|---|---|
library |
str | The path to the records database file. |
data |
dict | The raw JSON dictionary loaded from the records database file. |
description |
str | A brief description of the library. |
records |
List[HDRISkyboxRecord] | The list of HDRI skybox records. |
Create a new library JSON file.
HDRISkyboxLibrarian.create_library("My library", path="path/to/new/library.json")
Parameter | Type | Description |
---|---|---|
description |
str | A description of the library. |
path |
str | The absolute filepath to the .json records database file. |
Returns a list of the filenames of the libraries of this type in the tdw
module.
filenames = HDRISkyboxLibrarian.get_library_filenames()
print(filenames) # ['hdri_skyboxes.json']
Returns the filename of the default library (which is always the first element in the list returned by get_library_filenames()
.
default_library = HDRISkyboxLibrarian.get_default_library()
print(default_library) # hdri_skyboxes.json
Returns a record with the specified name. If that record can't be found, returns None.
lib = HDRISkyboxLibrarian()
record = lib.get_record("aft_lounge_4k")
print(record.name) # aft_lounge_4k
Parameter | Type | Description |
---|---|---|
name |
str | The name of the record. |
Returns a list of records whose names include the search keyword.
lib = HDRISkyboxLibrarian()
records = lib.search_records("lounge")
for record in records:
print(record.name) # aft_lounge_4k
Parameter | Type | Description |
---|---|---|
search |
str | The string to search for in the skybox name. |
def add_or_update_record(self, record: HDRISkyboxRecord, overwrite: bool, write: bool = True, quiet: bool = True) -> bool:
Add a new record or update an existing record.
record = define_record() # Provide your own code here.
lib = HDRISkyboxLibrarian()
lib.add_or_update_record(record, False, write=True, quiet=False)
Parameter | Type | Description |
---|---|---|
record |
HDRISkyboxRecord | The new or modified record. |
overwrite |
bool | If True: If there is a record with the same name as this record, replace it with the new record and return True. Otherwise, return False. If False: If there is a record with the same name as this record, don't add the skybox, and suggest a new name. |
write |
bool | If true, write the library data to disk (overwriting the existing file). |
quiet |
bool | If true, don't print out messages to the console. |
Remove a record. Returns true if the record was removed.
record = define_record() # Provide your own code here.
lib = HDRISkyboxLibrarian()
lib.remove_record(record) # Returns False.
lib = HDRISkyboxLibrarian()
lib.remove_record("aft_lounge_4k") # Returns True.
Parameter | Type | Description |
---|---|---|
record |
HDRISkyboxRecord or str | The record or the name of the record. |
write |
bool | If true, write the library data to disk (overwriting the existing file). |
Write the library data to disk (overwriting the existing file).
Parameter | Type | Description |
---|---|---|
pretty |
bool | "Pretty print" the JSON data with line breaks and indentations. |
Generates a valid record name. Returns: true if the name is good as-is, the new name, and a list of problems with the old name.
lib = HDRISkyboxLibrarian()
ok, name, problems = lib.get_valid_record_name("aft_lounge_4k", True)
print(ok) # True
print(name) # aft_lounge_4k
lib = HDRISkyboxLibrarian()
ok, name, problems = lib.get_valid_record_name("aft_lounge_4k", False)
print(ok) # False
print(name) # aft_lounge_4kabcd
print(problems) # ["A record named aft_lounge_4k already exists, and we don't want to overwrite it."]
Parameter | Type | Description |
---|---|---|
name |
str | The name of a record we'd like to add. |
overwrite |
str | If True: raise an exception if a record named name doesn't already exist.If False: If the record exists, suggest a new name. |