118 lines
3.7 KiB
ActionScript
118 lines
3.7 KiB
ActionScript
import FrameBuffer renderMeshPreview(GPUMesh mesh) from "Previewer";
|
|
string selectedResource = "";
|
|
|
|
class ResourceExplorer : Panel {
|
|
string currentPath = "";
|
|
array<string> subFolders;
|
|
array<string> subFiles;
|
|
bool alreadyRendered = false;
|
|
|
|
dictionary meshFrameBuffer;
|
|
|
|
void init() {
|
|
setPath("");
|
|
}
|
|
|
|
void setPath(string&in path) {
|
|
meshFrameBuffer.deleteAll();
|
|
currentPath = path;
|
|
subFolders = Resource::getResourceFolders(path);
|
|
subFiles = Resource::getResourceFiles(path);
|
|
}
|
|
|
|
void render() {
|
|
alreadyRendered = false;
|
|
renderMenuBar();
|
|
UI::space();
|
|
UI::automaticColumns(182);
|
|
|
|
string temp_path = currentPath;
|
|
|
|
// Render navigation folders
|
|
for (uint i = 0; i < subFolders.length(); i++) {
|
|
if (UI::cartIconButton(Path::getName(subFolders[i]), "folder.png", 128, UI::getAvailableSizeX())) {
|
|
setPath(subFolders[i]);
|
|
}
|
|
UI::nextColumn();
|
|
}
|
|
|
|
for (uint i = 0; i < subFiles.length(); i++) {
|
|
drawResource(subFiles[i]);
|
|
}
|
|
}
|
|
|
|
void drawResource(string&in filename) {
|
|
ResourceType resType = Resource::getResourceType(filename);
|
|
bool selected = filename == selectedResource;
|
|
|
|
if (resType == ResourceType::Mesh && !alreadyRendered) {
|
|
FrameBuffer frameBuffer;
|
|
if (meshFrameBuffer.exists(filename)) {
|
|
frameBuffer = FrameBuffer(meshFrameBuffer[filename]);
|
|
|
|
} else {
|
|
GPUMesh mesh = Resource::loadGPUMesh(filename);
|
|
frameBuffer = renderMeshPreview(mesh);
|
|
meshFrameBuffer[filename] = frameBuffer;
|
|
alreadyRendered = true;
|
|
}
|
|
|
|
if (UI::cartIconButton(Path::getName(filename), frameBuffer, 128, UI::getAvailableSizeX())) {
|
|
selectedResource = filename;
|
|
}
|
|
UI::dragDropSource("MESH", any(filename), filename);
|
|
UI::nextColumn();
|
|
return;
|
|
}
|
|
|
|
if (resType == ResourceType::Shader) {
|
|
if (UI::cartIconButton(Path::getName(filename), "shader.png", 128, UI::getAvailableSizeX())) {
|
|
selectedResource = filename;
|
|
}
|
|
UI::dragDropSource("SHADER", any(filename), filename);
|
|
UI::nextColumn();
|
|
return;
|
|
}
|
|
|
|
if (resType == ResourceType::Texture) {
|
|
Texture texture = Resource::loadTexture(filename);
|
|
if (UI::cartIconButton(Path::getName(filename), "texture.png", 128, UI::getAvailableSizeX())) {
|
|
selectedResource = filename;
|
|
}
|
|
UI::dragDropSource("TEXTURE", any(filename), filename);
|
|
UI::nextColumn();
|
|
return;
|
|
}
|
|
|
|
UI::cartIconButton(Path::getName(filename), "file.png", 128, UI::getAvailableSizeX());
|
|
UI::nextColumn();
|
|
}
|
|
|
|
void renderMenuBar() {
|
|
// If we select that path
|
|
if (UI::button("Resources")) {
|
|
setPath("");
|
|
}
|
|
array<string>@ paths = Path::divide(currentPath);
|
|
for (uint i = 0; i < paths.length(); i++) {
|
|
UI::sameline();
|
|
UI::text("/");
|
|
UI::sameline();
|
|
|
|
// If we select that path
|
|
if (UI::button(paths[i])) {
|
|
|
|
// We obtain that pat
|
|
string changePath = "";
|
|
for (uint z = 0; z <= i; z++) {
|
|
if (z != 0)
|
|
changePath += "/";
|
|
changePath += paths[z];
|
|
}
|
|
|
|
setPath(changePath);
|
|
}
|
|
}
|
|
}
|
|
}
|