[HN Gopher] Making a 3D modeler in C in a week
       ___________________________________________________________________
        
       Making a 3D modeler in C in a week
        
       Author : jasim
       Score  : 261 points
       Date   : 2024-05-02 17:48 UTC (5 hours ago)
        
 (HTM) web link (danielchasehooper.com)
 (TXT) w3m dump (danielchasehooper.com)
        
       | dhooper wrote:
       | Thanks for the share!
        
       | netule wrote:
       | I agree entirely with the author on the limitations of Raylib.
       | I'm currently working on a tower-defense style game that I
       | started in Raylib, but I'm running into many of the same
       | limitations (and more). Things such as toggling fullscreen not
       | working consistently across platforms, not being able to
       | enumerate screen modes, toggling rendering features at runtime,
       | saving compiled shaders etc., etc. Having said that, I appreciate
       | Ray's work on this library and will continue to sponsor him.
       | Raylib is great for quickly banging out a prototype, but not much
       | beyond that unless you're okay with living with severe
       | limitations.
       | 
       | Lesson learned, for sure, but I'm too far into the development to
       | swap all of the Raylib stuff out for SDL (or something else) now.
        
         | rwbt wrote:
         | Raylib is easy to get started but once the project gets a
         | little complex it bites back. SDL on the other hand takes more
         | time to setup everything but scales extremely well as the
         | project gets bigger and bigger. Also, SDL is exceptionally well
         | written code.
        
         | sgt wrote:
         | This made me want to look at raylib. It comes with some cute
         | examples that run using WebAssembly:
         | https://www.raylib.com/examples.html
         | 
         | One thing that's always bothered me about Wasm and browser
         | 3d/2d graphics is that I often find minor issues such as
         | scrolling. Look at the example called "Background scrolling &
         | parallax" here: https://www.raylib.com/examples.html
         | 
         | I've tested on several devices and it's definitely not smooth
         | scrolling, unless there's something wrong with my eyes.
         | 
         | How can 2D smooth scrolling not be a solved problem in 2024?
        
           | dekhn wrote:
           | the answer to your last question is "inner platform effect"
           | and "second system effect".
        
           | modeless wrote:
           | In that sample the foreground scrolls perfectly smoothly for
           | me, but the background looks jittery. This indicates to me
           | that it's not a platform issue at all. That sample is just
           | doing something weird with the background.
        
             | sgt wrote:
             | Yes, the background is odd but the foreground is definitely
             | not smooth. I see small little jitters occasionally. At one
             | point I had to wait 15 seconds for it to jitter, though.
        
               | jay_kyburz wrote:
               | Yes the BG is quite jittery for me on Firefox, and I'm
               | almost certain its the browsers own requestAnimationFrame
               | that's the problem.
        
         | oersted wrote:
         | Quick appreciation for the detail that Raylib is named after
         | the creator's name Ray and not ray-tracing, fun.
         | 
         | Things Unexpectedly Named After People:
         | https://notes.rolandcrosby.com/posts/unexpectedly-eponymous/
        
           | airstrike wrote:
           | Such a good list.. worth a submission of its own IMHO
        
             | WJW wrote:
             | I wish they'd add French drains.
        
             | oersted wrote:
             | It got good traction a couple times before, many more fun
             | examples in the comments.
             | 
             | https://news.ycombinator.com/item?id=39462516
             | 
             | https://news.ycombinator.com/item?id=23888725
        
           | TrainedMonkey wrote:
           | How do you know Ray was not named after ray-tracing?
        
             | dymk wrote:
             | The author's name is the first hint, and the lack of ray
             | tracing the second
        
               | oersted wrote:
               | I choose to interpret it as: How do you know that *the
               | author* was not named after ray-tracing?
               | 
               | Which is amusing :)
        
               | linkdd wrote:
               | You missed the joke, so let me ruin it by explaining it:
               | 
               | What if Ray the person was named after ray-tracing by his
               | parents?
        
         | pests wrote:
         | IIRC it defines some common words too like all the color names
         | and uses a lot of names that should be prefixed. Good
         | otherwise.
        
       | parasti wrote:
       | There's something really powerful about taking the tools that you
       | know very well and just making something cool with them. Really
       | enjoyed this writeup, thanks.
        
       | xixixao wrote:
       | Super impresssive for getting this done in a week. Being able to
       | make pretty demo models definitely helps too! :)
        
       | sandwichukulele wrote:
       | is the source code available? I looked through the blog post and
       | linked videos but could not find a github repo or anything
       | similar
        
         | TruthWillHurt wrote:
         | Or just being able to save/load creations would be nice :)
        
           | dhooper wrote:
           | yeah I never implemented saving/loading for the web. Thats
           | one example of how raylib doesn't totally abstract the
           | underlying platform for you.
        
         | dhooper wrote:
         | I just made it public:
         | https://github.com/danielchasehooper/ShapeUp-public
        
           | jbritton wrote:
           | How did you create / obtain the example shapes? Is there a
           | standard format your code parses?
        
             | dhooper wrote:
             | the example files in the repo were made using the macos
             | build of shapeUp and saved (the web build doesn't have
             | saving)
        
       | SoKamil wrote:
       | > The Shapes are kept in a statically allocated array [...] Can't
       | fail to allocate, can't be leaked, no fluff. Lovely. The 100
       | shape limit wasn't limiting in practice. With very little time to
       | optimize the renderer, the framerate would drop before you even
       | got to 100 shapes.
       | 
       | That's the best example of avoiding premature optimization I've
       | seen in a while.
        
       | ffitch wrote:
       | > The project is 2024 lines of C
       | 
       | got to appreciate the effort to make the irony possible : )
        
         | poopicus wrote:
         | As someone who has difficulty in detecting irony, could you
         | explain the irony in this statement?
        
           | booleandilemma wrote:
           | 2024 is the current year and it's the same as the number of
           | lines of code. I don't think describing it as ironic is
           | correct though.
        
       | runevault wrote:
       | Super interesting post, and appreciate him talking about the
       | various decisions like his handling of memory (and the issues he
       | ran into with raylib). As someone who's finally diving into part
       | 2 of crafting interpreters (and using it to refresh myself on C)
       | being reminded of what C does well is great.
        
       | fallingsquirrel wrote:
       | I really love the live demonstrations in the video. Forget
       | building the app, I couldn't even produce that video in a week if
       | I tried.
        
         | dhooper wrote:
         | The video took me longer to make than the app! I don't know how
         | youtubers do it so regularly.
        
           | an_aparallel wrote:
           | They have a team :)
        
             | movedx wrote:
             | Not all of us do. If you can get to an average of 300k+
             | view per video then you can hire an editor and maybe
             | someone else on a contract basis to assist. Must of don't
             | have a team though.
        
       | swiftcoder wrote:
       | That's some impressive development speed. Really enjoyed the
       | explainer video too!
        
       | emmanueloga_ wrote:
       | What is a stablished 3d modeler that uses the same kind of
       | modeling as this one?
        
         | Lichtso wrote:
         | Many 3D content creation tools such as Blender [0] have SDF [1]
         | (e.g. metaballs in Blender) and CSG [2] (e.g. boolean modifier
         | in Blender) features. But these are rarely used as they can
         | only define volumes, not surfaces. And we are usually
         | interested in surfaces for assigning textures and materials.
         | Thus, polygons / meshes and curves / splines dominate the
         | industry.
         | 
         | [0]: https://www.blender.org/ [1]:
         | https://en.wikipedia.org/wiki/Signed_distance_function [2]:
         | https://en.wikipedia.org/wiki/Constructive_solid_geometry
        
         | antirez wrote:
         | TinkerCAD.
        
         | starmole wrote:
         | Adobe/Substance3D Modeler
        
         | dantondwa wrote:
         | The two best SDF modelers in existence are MagicaCSG[1] and
         | Adobe Substance Modeler[2]. There are also a few others, like
         | Womp, but those two are the most feature-complete. Blender is
         | also adding them as part of geometry nodes, and there is also
         | an add-on that is working on adding SDF for hard-surface.
         | 
         | [1] https://ephtracy.github.io/index.html?page=magicacsg &
         | https://www.patreon.com/magicavoxel
         | 
         | [2]
         | https://www.adobe.com/products/substance3d/apps/modeler.html
        
       | RamiAwar wrote:
       | Amazing write up, thanks! Really enjoyed it, miss working on
       | C/C++ apps from scratch and having full control
        
       | jasonjmcghee wrote:
       | This looks like such a fun jam - wish I'd have known about it!
       | 
       | When's the next one?
        
       | antirez wrote:
       | I hope somebody will continue this project. It's a few months
       | away to be a serious alternative to Blender / FreeCAD for certain
       | use cases, with a much softer learning curve.
        
         | turtledragonfly wrote:
         | _EDIT_ aha, the program already supports exporting to a mesh
         | via marching cubes; see the youtube video on the site. I hadn
         | 't realized that (:
         | 
         | ----
         | 
         | Be aware that since it fundamentally works with SDFs, it is a
         | somewhat different modeling experience (and stores different
         | data) than traditional meshes with triangles, verts, etc.
         | 
         | Transforming it from SDFs into meshes could be done with
         | marching cubes or similar, but you'd likely need to "clean up"
         | such data afterwards in a Blender-style app anyway.
         | 
         | SDFs are great though, if your renderer is SDF-based, too (most
         | are not).
         | 
         | [sorry if you knew this already, wasn't sure]
        
           | antirez wrote:
           | Yep the export is already done! I used TinkerCAD a ton for
           | things ways more complex than it should be used to, so even
           | when I use more advanced CADs at this point I tend to think
           | in SDF terms. For many things it's faster and more natural
           | than extruding, rotating, ... But the fact is, the engine
           | behind TinkerCAD is quite good, but there is little interest
           | for AutoDesk to compete with its own Fusion360, so TinkerCAD
           | is left forever as a children / beginners tool, without the
           | more advanced stuff that could implement.
        
       ___________________________________________________________________
       (page generated 2024-05-02 23:00 UTC)