From b720504e48d3757e4d3f5bef07f916d883a81336 Mon Sep 17 00:00:00 2001 From: alcoholicgirl <2680813175@qq.com> Date: Mon, 27 Apr 2026 01:26:42 +0800 Subject: [PATCH] bug fixes --- konabot/plugins/marchtoy/__init__.py | 5 +++-- konabot/plugins/marchtoy/command.py | 1 - konabot/plugins/marchtoy/gl_render.py | 4 ++-- konabot/plugins/marchtoy/obj.py | 2 +- konabot/plugins/marchtoy/shaders/frag.glsl | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/konabot/plugins/marchtoy/__init__.py b/konabot/plugins/marchtoy/__init__.py index 104f611..7e48840 100644 --- a/konabot/plugins/marchtoy/__init__.py +++ b/konabot/plugins/marchtoy/__init__.py @@ -9,10 +9,11 @@ cmd_marchtoy = on_command("march") async def _(args: Message = CommandArg()): if cmd := args.extract_plain_text(): try: - img = await render.render(cmd, (256, 256)) + img = await render.render(cmd, (512, 512)) buffer = io.BytesIO() + # img.show() img.save(buffer, format="PNG") buffer.seek(0) await cmd_marchtoy.send(await UniMessage().image(raw=buffer).export()) except Exception as e: - await cmd_marchtoy.send(await Message(message=f"发生了错误: {e}")) \ No newline at end of file + await cmd_marchtoy.send(await UniMessage.text(f"发生了错误: {e}").export()) \ No newline at end of file diff --git a/konabot/plugins/marchtoy/command.py b/konabot/plugins/marchtoy/command.py index 4c67868..536f30a 100644 --- a/konabot/plugins/marchtoy/command.py +++ b/konabot/plugins/marchtoy/command.py @@ -67,7 +67,6 @@ class CommandParser: return Command(cmd_id, cmd_args) raise StopIteration - class Scene: def __init__(self, _instruction: str) -> None: self.canvas_objs: list[tuple[Object, str]] = [] diff --git a/konabot/plugins/marchtoy/gl_render.py b/konabot/plugins/marchtoy/gl_render.py index b67ccc4..202ea2a 100644 --- a/konabot/plugins/marchtoy/gl_render.py +++ b/konabot/plugins/marchtoy/gl_render.py @@ -19,8 +19,8 @@ async def render(command: str, res: tuple[int, int]): vertex_shader=vs, fragment_shader=fs ) - except Exception as _: - raise Exception("cannot compile glsl") + except Exception as e: + raise Exception(f"cannot compile glsl: {e}") from e uniform = program['u_resolution'] uniform.write(np.array(res, dtype=np.float32)) vertices = np.array([-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0], dtype=np.float32) diff --git a/konabot/plugins/marchtoy/obj.py b/konabot/plugins/marchtoy/obj.py index cc6217a..8a12f25 100644 --- a/konabot/plugins/marchtoy/obj.py +++ b/konabot/plugins/marchtoy/obj.py @@ -21,7 +21,7 @@ class Transform: @staticmethod def normalize(p: np.ndarray) -> np.ndarray: - return p / np.sqrt(np.dot(p, p)) + return p / (np.sqrt(np.dot(p, p)) + 1e-8) def translate(self, x: float, y: float, z: float): mat = np.identity(4, dtype=np.float32) diff --git a/konabot/plugins/marchtoy/shaders/frag.glsl b/konabot/plugins/marchtoy/shaders/frag.glsl index 5dd62b0..34a12ac 100644 --- a/konabot/plugins/marchtoy/shaders/frag.glsl +++ b/konabot/plugins/marchtoy/shaders/frag.glsl @@ -6,7 +6,7 @@ #define float2 vec2 const float EPS = 0.001; -const int MAX_ITER = 64; +const int MAX_ITER = 128; uniform vec2 u_resolution; out vec4 fragColor;