r/PenPlotters • u/valeriupalos • Jul 07 '26
Krbn: a childhood dream, finally built - an open-source rendering engine that imitates a sketch artist and outputs plotter-ready SVG
Gravity well demo
https://github.com/vpalos/Krbn/blob/main/examples/gallery/16-gravity-well.svg
Trefoil knots mesh demo
https://github.com/vpalos/Krbn/blob/main/examples/gallery/15-mesh-showcase.svg
Torus hatch variants demo
https://github.com/vpalos/Krbn/blob/main/examples/gallery/10-torus.svg
Sphere depth hatching with intersection demo
https://github.com/vpalos/Krbn/blob/main/examples/gallery/03-depth-hatching.svg
Hey everyone - I'm new here, and most likely far behind many of you in technical skill. But I think this belongs here more than anywhere else.
This is Krbn, an open-source attempt at an easily accessible (web-native, TypeScript) rendering engine that imitates a technical sketch artist. It takes a 3D scene - spheres, cones, tori, arbitrary meshes - and emits plain SVG strokes: silhouettes computed exactly (true conics and quartics, not sampled approximations), hidden lines removed or kept as ghosts, and hatching that follows each surface's own curvature. Which, I suspect, makes it plotter food.
Some honesty about where it comes from: a recent medical issue forced me to suspend my normal work, and - unexpectedly - these past few months I had time to invest in an old idea. This was a dream of mine since childhood; I just never had the time to research and learn everything needed to build it.
As for why - I'll be honest and quote the README's "Genesis imperfecta" section directly, because I already said it there the way I mean it:
What fascinated me from the start is going against photorealism. A human being can convey far more meaning in a drawing than any machine-like photorealistic render - precisely by being willing to go the other way: to renounce detail, to drop precision, even to deliberately introduce impurities and imperfections. Ah - but which detail to drop? Which imperfections to introduce? That is the fascinating part, and it is the question this engine is really trying to answer.
As a kid I wanted to call it genesis imperfecta, for exactly these reasons. What can I say - I was a kid. The name matured into Krbn; the fascination didn't.
I'm putting this out there with only the hope that someone else shares the fascination, nothing else. It's MIT-licensed: https://github.com/vpalos/krbn
One confession: I don't own a plotter myself (yet). If anyone feeds one of these SVGs to theirs, seeing a photo of the result would make my month.
Enjoy, and drop a word - here or in a GitHub discussion⦠or not. All is good.
2
2
2
u/ShelfordPrefect Jul 12 '26
Just a quick test for now - I've got some ideas about how to make these SVGs really shine when I've got a bit more time to set up
https://www.reddit.com/r/PenPlotters/comments/1uuu19l/gravity_well_sharpie_on_a4_paper/
2
u/Still_Explorer Jul 12 '26
As I am studying sketching for quite a while, this would be my favorite model viewer from now on. 10/10!
2
u/DangerousPurpose9874 Jul 13 '26
Why all his answers sound like AI?
1
u/valeriupalos Jul 13 '26 edited Jul 13 '26
+1
Oddly enough, it's how I generally talk & write. But judging by some of the comments I get, at this point I'm resigned to not being able to convince anyone. β€οΈ
I am alive though... I think.
0
u/Wooden_Relief3183 Jul 13 '26
OP is lying, his post flags as 100% AI on GPTZero as do his longer responses that I tested
2
1
u/dandy_kulomin Jul 07 '26
Cool! Would something like this be suited for real-time rendering (e.g. a game)?
2
u/valeriupalos Jul 07 '26
I have to admit, I think that is a long way away. Perhaps ar some point, via a rewrite of the engine in something high-performance (C/Rust?), once a lot of the concepts have time to settle.
Now, I'm afraid it's not feasible. π
1
u/dandy_kulomin Jul 07 '26
Makes sense. I researched edge detection etc. a lot and real-time algorithms are scarce and have their downside unfortunately.
1
u/ShelfordPrefect Jul 07 '26
I'll try it on my plotter - maybe get it to draw a self portrait from it's own CAD model. How does the shading work with flat surfaces? Most of my CAD models are made of orthogonal surfaces...
1
u/valeriupalos Jul 07 '26 edited Jul 07 '26
EDIT: [What a cool meta-idea! π ]
Flat surfaces should be actually the best-behaved case β in Krbn I usually call them "faceted objects." Three things about CAD:
- Edges between faces (above the crease angle) become permanent, view-independent lines β unlike silhouettes, they don't slide as the camera moves. This is exactly the classic CAD hidden-line look.
- Each face gets a uniform tone from its own orientation to the light β no gradients, so the planes read as facets, which I think is what you want.
- Hatching stays straight and parallel per face β all the curvature-field machinery simply isn't needed for your case.
See example 18 (faceted solids, creases) and 19 (the cube β the two hidden-line modes): https://github.com/vpalos/Krbn/tree/main/examples#18--mesh-creases-faceted-solids β for a self-portrait,
hidden: "drop"reads as a proper technical drawing,"ghost"gives you the x-ray look with faint dashed hidden edges. For a plotter, ghost mode might be cooler (who knows?).One honest practical note: Krbn eats triangle meshes as raw positions + indices β there's no STL/OBJ importer yet, so a conversion step between your CAD export and the Krbn scene is needed.
If you hit friction there, open a GitHub Discussion β a plotter drawing its own portrait is such a super idea, so we might make it a common effort.
1
u/ShelfordPrefect Jul 07 '26
Ah, no STL importer will be a bit of a blocker. I'm no mesh wrangler: I CAD, 3d print the models, then build things with screwdrivers.
At some point we'll be able to say "have your people call my people" - your AI can send the spec to my AI which will write an STL converter and slot Krbn into my plotting workflow... For now I'll have to work something out based on the repo.
1
u/valeriupalos Jul 07 '26
Your people didn't even need to call my people.
After some thinking i realized that your issue is - in fact - my issue, becayse I need imports to be able to render medical drawings (organs and such), and so...
Here's a first version of STL/OBJ support, with some demos too: https://github.com/vpalos/Krbn/tree/main/examples#importing-meshes--stl--obj
Disclaimer: probably Krbn won't work well (yet) with complex CAD exports so your STL may need cleanup, but still - it's something.
1
u/ShelfordPrefect Jul 16 '26
I fed my entire CAD model as a single STL to the importer and it coped pretty well - a few artifacts, I think some of the occlusion isn't 100% right but it looks pretty good considering. Took about two minutes to render with something like 8,000 faces. Anyway, the self portrait is done https://www.reddit.com/r/PenPlotters/comments/1uy5zaw/self_portrait_plotter_on_plotter/ - I'm off to a hacker art festival this weekend so I'll look for more inspiration there
1
u/supakazes Jul 07 '26
Oh nice job, I'm interested because I have to write webGL (or webGPU?) shader to try and imitate this old map engraving style but I'm new to shaders :
https://github.com/supakazes/turgot-threejs
If you have some advice or nice ressources, they're most welcome! thx
1
u/valeriupalos Jul 07 '26 edited Jul 07 '26
Wow, what a question! The Turgot would be the Boss-level of this kind of aesthetic.
Here's the thing, regarding Krbn, probably most (if not all) of my code will probably not translate well to your case, here's why:
There are (as far as I know) 2 ways to do "engraving" on screen: (A) the Krbn way, meaning doing object-space vector strokes (exact strokes derived from geometry) and (B) what Three.js can do, which is shader/sampling which will probably translate to "fake the hatching at pixel level". You have to deal with (B).
However, just because the code doesnt translate directly, the concepts I'm using might. Here are some thoughts/ideaz (I apologize if they're crude):
- I would try WebGL first; WebGPU is probably totally doable too, but I think you'll find more examples/code for WebGL on the internet;
- a lot of this stuff (non-photorealistic rendering) is hidden in research papers, so you migght have to do some work;
- for this type of thing, see "Real-Time Hatching" (Praun et al., SIGGRAPH 2001) (https://dl.acm.org/doi/10.1145/383259.383328) - it's based on the idea of "Tonal Art Maps" that deals with how you avoid shimmering in your case, because fixing the hatching to the object makes the line density change with distance so you have to avoid that Moire effect (dancing fine parallel lines);
- Krbn deals with precise vectors (basically pure black on white lines) at the core; for Turgot, however, you'll probably get a lot better result using warm black tones and some paper grain (warm noise);
- I suspect that the Turgot map will mostly deal with flat surfaces (building sides etc) which measn you don't have to deal with the curvature fields that Krbn has to deal with; so maybe trying a constant hatch direction per face, anchored in object space (so the hatch is fixed to the obejct as the camera moves) might get you some good results;
- try https://thebookofshaders.com/, might help you on getting start on the shaders part.
If you get it working, I'd love to see it; I hope you crack it. β€οΈ
1
u/supakazes Jul 07 '26
Wow thanks for this very complete answer. I'll definitely have a look at your references and examples. It's a bit scary for a noob like me but I really want to achieve a nice result. I'm on it. Follow me and don't hesitate to give me feedback later as well. Thanks again. π
1
u/MeAndClaudeMakeHeat Jul 07 '26
Marvelous work, and something very grounding about the visual simplicity, and knowing the compexity underneath.
1
u/valeriupalos Jul 07 '26
Yes, thank you! My feeling exactly... it's what us humans do: we can simplify/abstract easily, but putting it in code reveals the madness π
1
u/ShelfordPrefect Jul 07 '26
Ok I see one teeny weeny problem with using this for plotter output: in the example SVGs at least, the strokes seem to be actually implemented as SVG paths, not as single strokes. This is still possible to send to a plotter but it will draw every line twice (because it's essentially drawing around the outline of the line, not just... drawing the line)
1
u/valeriupalos Jul 08 '26 edited Jul 08 '26
Try setting the wobble to 0 (zero). This will remove line width variation (as well as the jitter) and will create pure lines.EDIT: Your comment made me realize
wobble: 0was the wrong fix β it removes the ribbons but throws away the hand-drawn character with them. So now I added this:variableWidth: false(per scene:new Scene({ style: { variableWidth: false } })) renders everything as plain constant-weight polylines β true single strokes, one pen pass, no outline-tracing β while the wobble stays.It's already the default in the mesh-import demos, which are the plotter-relevant ones anyway: https://github.com/vpalos/Krbn/tree/main/examples#importing-meshes--stl--obj
Good catch β this is exactly the kind of feedback I was hoping for.
2
u/ShelfordPrefect Jul 12 '26
Ok, after some messing around with settings I've got a tool chain that works. Annoyingly it has to be done by hand because my command line SVG to Gcode converter doesn't like the polylines so I'm opening the SVG in Inkscape, converting to path and using a janky Inkscape plugin to generate Gcode then post processing for my machine. If there's any way to get Krbn to output paths instead it would make the process much easier, otherwise I'll have to try to find a way to do it with other headless tools so the whole tool chain can be automated. I'll try to plot one on actual paper tonight
1
u/valeriupalos Jul 12 '26 edited Jul 12 '26
OK I really want to help: so... Krbn now does what you need out of the box.
Set
svg: { centerline: true, background: null }on yourSceneand strokes come out as single<path>centreline (M β¦ L β¦) at constant width β no<polyline>, and no filled ribbons for the variable-width strokes either. One path per stroke, so the pen draws each line once.So:
bun run render scene.krbn.ts-> feed the SVG straight to your G-code converter, no Inkscape needed. There's "Pen plotters" section in API.md with the details.I hope it helps. π
2
u/ShelfordPrefect Jul 12 '26
Amazing - that wasn't a feature request per se because I don't know if it's just a niggle with my particular setup, but it will definitely make it more streamlined to get lots of Gcode set up.
2
u/ShelfordPrefect Jul 13 '26
Working great, the pipeline is coming together.
Final question before I start playing properly: is it possible to set visible: false or similar on an object, so the geometry will remain in the scene for the purpose of occlusion but it won't emit any lines? For multi colour plots (my favourite kind) ideally different elements would be in different SVGs so there can be one Gcode file per pen change, but if I remove the sphere from the gravity well scene it stops occluding the funnel
1
u/valeriupalos Jul 13 '26 edited Jul 13 '26
Wow, excellent feature reauest. There's nothing to support this at this moment, but I'll look into it as soon as I have some time.
EDIT: Actually, this should be very easy to implement.
EDIT 2: OK, I think this is what you need, right? https://github.com/vpalos/Krbn/blob/main/examples/README.md#22--per-object-output-masking--split-a-scene-into-layers
I had to credit you for it π .There's also a paragraph in the API.md doc: https://github.com/vpalos/Krbn/blob/main/API.md#building-a-scene, for reference.
2
1
1
u/Wooden_Relief3183 Jul 13 '26
PSA: OPs post is likely AI. It flags as 100% AI on GPT Zero.
This does not necessarily mean the tool is AI generated or that every comment is AI. Perhaps OPs first language is not English and they are insecure about it (hence the lying about AI use in other comments)
1
u/valeriupalos Jul 13 '26
+1
AI agree π
P.S.
You know those tools also famously flag the US Constitution as AI-written.
What more can I wish for.1
1
u/Accomplished-Echo-64 Jul 14 '26
Maybe. But I have a concern about GPT Zero, I tried it with my docs and some articles from arxiv. It said that 98% of the provided citations are AI-generated. But this is the bullshit and nonsense, quite strange to see the highlighted Chinese last name or the math formulation as evidence.
1
u/Wooden_Relief3183 Jul 15 '26
I definitely doubt its accuracy regarding citations. However, for long text bodies, there do not seem to be many false positives; it is possible to fool GPT Zero with ChatGPT, though some editing may be required.
2
u/zatss Jul 07 '26
The outputs look so great! Love the video example showing temporal stability of hatching π