Is it possible to iterate through the assets in the Assets folder within an Incisor project?
I need to access asset files from within my code and would like to iterate over the assets in the Assets folder. Additionally, I want to manipulate these assets at runtime. Is there a way to achieve this?
Is it possible to iterate through the assets in the Assets folder within an Incisor project?
I need to access asset files from within my code and would like to iterate over the assets in the Assets folder. Additionally, I want to manipulate these assets at runtime. Is there a way to achieve this?
Share Improve this question asked Feb 14 at 21:17 Matt CMatt C 853 bronze badges1 Answer
Reset to default 0There are a couple of approaches depending on your needs for accessing and manipulating file data in your project.
1. Using nc.fileIO.getDirectoryContents
to list files and directories:
You can retrieve a list of files and directories within the "Assets" directory using the nc.fileIO.getDirectoryContents
function:
class ProjectMain {
async init() {
try {
let directoryContentsList = await nc.fileIO.getDirectoryContents("Assets");
console.log(directoryContentsList);
} catch (error) {
console.error('Error fetching directory contents:', error);
}
}
}
Key points to remember:
Asynchronous behavior: Most fileIO
functions require await
as they are asynchronous.
Project restrictions: fileIO
is only available in un-published projects.
Usage in extensions: fileIO
can also be used in extensions scripting, making it helpful for asset manipulation.
2. Accessing runtime assets via Incisor dictionaries:
Instead of working with files directly, you can iterate through runtime asset dictionaries in Incisor to view or manipulate assets. These dictionaries contain the actual assets used at runtime, such as:
nc.graphicAssets
nc.textures
nc.geometries
nc.sounds
These can be helpful if you're more interested in accessing or modifying assets that are already loaded in the project.