217 lines
6.5 KiB
ActionScript
217 lines
6.5 KiB
ActionScript
bool allowRender = false;
|
|
|
|
class MeshResource {
|
|
string displayName;
|
|
string path;
|
|
GPUMesh meshResource;
|
|
FrameBuffer frameBuffer;
|
|
|
|
bool loaded = false;
|
|
|
|
MeshResource(string _meshPath) {
|
|
path = _meshPath;
|
|
}
|
|
|
|
void render() {
|
|
if (!loaded) {
|
|
if (allowRender) {
|
|
meshResource = StudioAPI::loadGPUMesh(path);
|
|
frameBuffer = Previewer::getMeshPreview(meshResource);
|
|
displayName = meshResource.name;
|
|
allowRender = false;
|
|
loaded = true;
|
|
} else {
|
|
ImGui::text("Loading");
|
|
return;
|
|
}
|
|
}
|
|
|
|
ImGui::cartIconButton(displayName, frameBuffer, 128, ImGui::getAvailableSizeX());
|
|
ImGui::dragDropSource("MESH", any(meshResource), displayName);
|
|
}
|
|
}
|
|
|
|
class ShaderResource {
|
|
string displayName;
|
|
string path;
|
|
Shader shaderResource;
|
|
FrameBuffer frameBuffer;
|
|
|
|
bool loaded = false;
|
|
|
|
ShaderResource(string _path) {
|
|
path = _path;
|
|
}
|
|
|
|
void render() {
|
|
if (!loaded) {
|
|
if (allowRender) {
|
|
shaderResource = StudioAPI::loadShader(path);
|
|
frameBuffer = Previewer::getShaderPreview(shaderResource);
|
|
displayName = shaderResource.name;
|
|
allowRender = false;
|
|
loaded = true;
|
|
} else {
|
|
ImGui::text("Loading");
|
|
return;
|
|
}
|
|
}
|
|
|
|
ImGui::cartIconButton(displayName, frameBuffer, 128, ImGui::getAvailableSizeX());
|
|
ImGui::dragDropSource("SHADER", any(shaderResource), displayName);
|
|
}
|
|
}
|
|
|
|
class TextureResource {
|
|
string displayName;
|
|
string path;
|
|
Texture texture;
|
|
|
|
TextureResource(string _path) {
|
|
path = _path;
|
|
texture = StudioAPI::loadTexture(_path);
|
|
displayName = texture.name;
|
|
}
|
|
|
|
void render() {
|
|
ImGui::cartIconButton(displayName, texture, 128, ImGui::getAvailableSizeX());
|
|
ImGui::dragDropSource("TEXTURE", any(texture), displayName);
|
|
}
|
|
}
|
|
|
|
class ResourceExplorer : Panel {
|
|
string selectedResource = "";
|
|
string currentPath = "";
|
|
array<string> subFolders;
|
|
array<MeshResource@> meshes;
|
|
array<ShaderResource@> shaders;
|
|
array<TextureResource@> textures;
|
|
|
|
array<string> subFiles;
|
|
bool alreadyRendered = false;
|
|
float fase = 0;
|
|
|
|
dictionary meshFrameBuffer;
|
|
|
|
void onInit() {
|
|
setPath("");
|
|
}
|
|
|
|
void setPath(string&in path) {
|
|
meshFrameBuffer.deleteAll();
|
|
currentPath = path;
|
|
subFolders = StudioAPI::getResourceFolders(path);
|
|
subFiles = StudioAPI::getResourceFiles(path);
|
|
meshes = array<MeshResource@>(0);
|
|
shaders = array<ShaderResource@>(0);
|
|
textures = array<TextureResource@>(0);
|
|
|
|
for ( uint i = 0; i < subFiles.length(); i++) {
|
|
ResourceType resType = StudioAPI::getResourceType(subFiles[i]);
|
|
if (resType == ResourceType::Mesh) {
|
|
MeshResource@ meshRes = @MeshResource(subFiles[i]);
|
|
meshes.insertLast(@meshRes);
|
|
}
|
|
if (resType == ResourceType::Shader) {
|
|
ShaderResource@ shaderRes = @ShaderResource(subFiles[i]);
|
|
shaders.insertLast(@shaderRes);
|
|
}
|
|
if (resType == ResourceType::Texture) {
|
|
TextureResource@ texture = @TextureResource(subFiles[i]);
|
|
textures.insertLast(@texture);
|
|
}
|
|
}
|
|
}
|
|
|
|
void onImGui() {
|
|
renderMenuBar();
|
|
ImGui::space();
|
|
fase += 0.3;
|
|
ImGui::automaticColumns(182);
|
|
|
|
string temp_path = currentPath;
|
|
|
|
// Render navigation folders
|
|
for (uint i = 0; i < subFolders.length(); i++) {
|
|
Texture folder = StudioAPI::loadIcon("folder.png");
|
|
if (ImGui::cartIconButton(Path::getName(subFolders[i]), folder, 128, ImGui::getAvailableSizeX())) {
|
|
setPath(subFolders[i]);
|
|
}
|
|
ImGui::nextColumn();
|
|
}
|
|
|
|
allowRender = true;
|
|
for ( uint i = 0; i < meshes.length(); i++) {
|
|
meshes[i].render();
|
|
ImGui::nextColumn();
|
|
}
|
|
for ( uint i = 0; i < shaders.length(); i++) {
|
|
shaders[i].render();
|
|
ImGui::nextColumn();
|
|
}
|
|
for ( uint i = 0; i < textures.length(); i++) {
|
|
textures[i].render();
|
|
ImGui::nextColumn();
|
|
}
|
|
|
|
}
|
|
|
|
void drawResource(string&in filename) {
|
|
ResourceType resType = StudioAPI::getResourceType(filename);
|
|
bool selected = filename == selectedResource;
|
|
|
|
if (resType == ResourceType::Shader) {
|
|
Texture shaderTexture = StudioAPI::loadIcon("shader.png");
|
|
Shader shader = StudioAPI::loadShader(filename);
|
|
FrameBuffer frame = Previewer::getShaderPreview(shader);
|
|
if (ImGui::cartIconButton(Path::getName(filename), frame, 128, ImGui::getAvailableSizeX())) {
|
|
selectedResource = filename;
|
|
}
|
|
ImGui::dragDropSource("SHADER", any(shader), filename);
|
|
ImGui::nextColumn();
|
|
return;
|
|
}
|
|
|
|
if (resType == ResourceType::Texture) {
|
|
Texture texture = StudioAPI::loadTexture(filename);
|
|
if (ImGui::cartIconButton(Path::getName(filename), texture, 128, ImGui::getAvailableSizeX())) {
|
|
selectedResource = filename;
|
|
}
|
|
ImGui::dragDropSource("TEXTURE", any(texture), filename);
|
|
ImGui::nextColumn();
|
|
return;
|
|
}
|
|
|
|
Texture fileTexture = StudioAPI::loadIcon("file.png");
|
|
ImGui::cartIconButton(Path::getName(filename), fileTexture, 128, ImGui::getAvailableSizeX());
|
|
ImGui::nextColumn();
|
|
}
|
|
|
|
void renderMenuBar() {
|
|
// If we select that path
|
|
if (ImGui::button("Resources")) {
|
|
setPath("");
|
|
}
|
|
|
|
array<string>@ paths = Path::divide(currentPath);
|
|
for (uint i = 0; i < paths.length(); i++) {
|
|
ImGui::sameline();
|
|
ImGui::text("/");
|
|
ImGui::sameline();
|
|
|
|
// If we select that path
|
|
if (ImGui::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);
|
|
}
|
|
}
|
|
}
|
|
}
|