2026-03-01 17:48:56 +01:00

86 lines
2.3 KiB
ActionScript

class MeshComponentRender {
Entity entity;
MeshComponent meshComponent;
MeshComponentRender(Entity _entity) {
entity = _entity;
meshComponent = entity.getComponent<MeshComponent>();
}
void render() {
if (!entity.hasComponent<MeshComponent>())
return;
ImGui::title("Mesh Component");
ImGui::sameline();
if (ImGui::buttonEnd("Clear")) {
meshComponent.clear();
}
ImGui::space(10, 10);
ImGui::text("Mesh ");
ImGui::sameline();
if (meshComponent.hasMesh) {
ImGui::textColor(0.6, 1, 0.7,meshComponent.meshResource.name);
} else {
ImGui::text("Empty");
}
ImGui::dragDropTarget("MESH", ReciverFunction(this.setMesh));
ImGui::text("Shader ");
ImGui::sameline();
if (meshComponent.hasShader) {
ImGui::textColor(0.6, 1, 0.7,meshComponent.shader.name);
} else {
ImGui::text("Empty");
}
ImGui::dragDropTarget("SHADER", ReciverFunction(this.setShader));
ImGui::text("Texture ");
ImGui::sameline();
if (meshComponent.hasTexture) {
ImGui::textColor(0.6, 1, 0.7,meshComponent.texture.name);
} else {
ImGui::text("Empty");
}
ImGui::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
// Mesh icon
/*
if (meshComponent.hasMesh) {
FrameBuffer frameBuffer = Previewer::getMeshPreview(meshComponent.meshResource);
ImGui::drawFrameBufferCentered(frameBuffer, 128, 128);
} else {
ImGui::drawIconCentered(StudioAPI::loadIcon("empty.png"), 128);
}
*/
}
void setMesh(any@ meshData) {
GPUMesh mesh;
if (meshData.retrieve(mesh)) {
meshComponent.meshResource = mesh;
}
}
void setShader(any@ meshData) {
Shader shader;
if (meshData.retrieve(shader)) {
meshComponent.shader = shader;
}
}
void setTexture(any@ meshData) {
Texture texture;
if (meshData.retrieve(texture)) {
meshComponent.texture = texture;
}
}
void remove() {
if (ImGui::menuItem("Remove")) {
entity.removeComponent<MeshComponent>();
}
}
}