237 lines
6.9 KiB
ActionScript
237 lines
6.9 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(int size) {
|
|
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, size, 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(int size) {
|
|
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, size, 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(int size) {
|
|
ImGui::cartIconButton(displayName, texture, size, ImGui::getAvailableSizeX());
|
|
ImGui::dragDropSource("TEXTURE", any(texture), displayName);
|
|
}
|
|
}
|
|
|
|
class ResourceExplorer : Panel {
|
|
string selectedResource = "";
|
|
string currentPath = "";
|
|
|
|
int size = 96;
|
|
|
|
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 onMenuBar() {
|
|
// If we select that path
|
|
if (ImGui::menuItem("Resources")) {
|
|
setPath("");
|
|
}
|
|
|
|
array<string>@ paths = Path::divide(currentPath);
|
|
for (uint i = 0; i < paths.length(); i++) {
|
|
ImGui::text("/");
|
|
|
|
// If we select that path
|
|
if (ImGui::menuItem(paths[i])) {
|
|
// We obtain that pat
|
|
string changePath = "";
|
|
for (uint z = 0; z <= i; z++) {
|
|
if (z != 0)
|
|
changePath += "/";
|
|
changePath += paths[z];
|
|
}
|
|
|
|
setPath(changePath);
|
|
}
|
|
}
|
|
|
|
ImGui::drawComboEnd("##IconSize", "Icon Size : " + size, SimpleFunction(this.setIconSize));
|
|
}
|
|
|
|
void setIconSize() {
|
|
if (ImGui::drawComboItem("64", size == 64)) {
|
|
size = 64;
|
|
}
|
|
|
|
if (ImGui::drawComboItem("96", size == 96)) {
|
|
size = 96;
|
|
}
|
|
|
|
if (ImGui::drawComboItem("128", size == 128)) {
|
|
size = 128;
|
|
}
|
|
|
|
if (ImGui::drawComboItem("160", size == 160)) {
|
|
size = 160;
|
|
}
|
|
}
|
|
|
|
void onImGui() {
|
|
|
|
fase += 0.3;
|
|
ImGui::automaticColumns(size * 1.5);
|
|
|
|
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, size, ImGui::getAvailableSizeX())) {
|
|
setPath(subFolders[i]);
|
|
}
|
|
ImGui::nextColumn();
|
|
}
|
|
|
|
allowRender = true;
|
|
for ( uint i = 0; i < meshes.length(); i++) {
|
|
meshes[i].render(size);
|
|
ImGui::nextColumn();
|
|
}
|
|
for ( uint i = 0; i < shaders.length(); i++) {
|
|
shaders[i].render(size);
|
|
ImGui::nextColumn();
|
|
}
|
|
for ( uint i = 0; i < textures.length(); i++) {
|
|
textures[i].render(size);
|
|
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, size, 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, size, 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, size, ImGui::getAvailableSizeX());
|
|
ImGui::nextColumn();
|
|
}
|
|
}
|