bug fixes
This commit is contained in:
@ -9,10 +9,11 @@ cmd_marchtoy = on_command("march")
|
|||||||
async def _(args: Message = CommandArg()):
|
async def _(args: Message = CommandArg()):
|
||||||
if cmd := args.extract_plain_text():
|
if cmd := args.extract_plain_text():
|
||||||
try:
|
try:
|
||||||
img = await render.render(cmd, (256, 256))
|
img = await render.render(cmd, (512, 512))
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
|
# img.show()
|
||||||
img.save(buffer, format="PNG")
|
img.save(buffer, format="PNG")
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
await cmd_marchtoy.send(await UniMessage().image(raw=buffer).export())
|
await cmd_marchtoy.send(await UniMessage().image(raw=buffer).export())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await cmd_marchtoy.send(await Message(message=f"发生了错误: {e}"))
|
await cmd_marchtoy.send(await UniMessage.text(f"发生了错误: {e}").export())
|
||||||
@ -67,7 +67,6 @@ class CommandParser:
|
|||||||
return Command(cmd_id, cmd_args)
|
return Command(cmd_id, cmd_args)
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
class Scene:
|
class Scene:
|
||||||
def __init__(self, _instruction: str) -> None:
|
def __init__(self, _instruction: str) -> None:
|
||||||
self.canvas_objs: list[tuple[Object, str]] = []
|
self.canvas_objs: list[tuple[Object, str]] = []
|
||||||
|
|||||||
@ -19,8 +19,8 @@ async def render(command: str, res: tuple[int, int]):
|
|||||||
vertex_shader=vs,
|
vertex_shader=vs,
|
||||||
fragment_shader=fs
|
fragment_shader=fs
|
||||||
)
|
)
|
||||||
except Exception as _:
|
except Exception as e:
|
||||||
raise Exception("cannot compile glsl")
|
raise Exception(f"cannot compile glsl: {e}") from e
|
||||||
uniform = program['u_resolution']
|
uniform = program['u_resolution']
|
||||||
uniform.write(np.array(res, dtype=np.float32))
|
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)
|
vertices = np.array([-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0], dtype=np.float32)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class Transform:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def normalize(p: np.ndarray) -> np.ndarray:
|
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):
|
def translate(self, x: float, y: float, z: float):
|
||||||
mat = np.identity(4, dtype=np.float32)
|
mat = np.identity(4, dtype=np.float32)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#define float2 vec2
|
#define float2 vec2
|
||||||
|
|
||||||
const float EPS = 0.001;
|
const float EPS = 0.001;
|
||||||
const int MAX_ITER = 64;
|
const int MAX_ITER = 128;
|
||||||
|
|
||||||
uniform vec2 u_resolution;
|
uniform vec2 u_resolution;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user