News for hackers. Stuff that matters.
Re:Ldraw: Lego Modeling in Rust by segfault87 on Tuesday September 17, 2019 @01:57AM (#20992035)
Hi, creator here. Never imagined this would make its way into HN. :)

I created this to study Rust(yes, I'm still new) and to explore what's possible with current Rust and WebAssembly. I think it turned out to be okay to continue with Rust and I'm more than happy.

Currently it comprises of a parser which reads LDraw(https://ldraw.org/) file format and a basic renderer. For now the page itself is just a single page with rotating 3d model but eventually would transform into a complete website for creating and sharing your own creations.

If you are interested you can track the development at the GitHub repository(https://github.com/segfault87/ldraw.rs) It's slightly outdated and the current code heavily relies on the bleeding edge of Rust (e.g., nightly, async await, futures 0.3, wasm-bindgen, ...) and needs to be cleaned up before pushing.

If you want more complex model you can try this instead: https://segfault87.github.io/ldraw-rs-preview/#models/6973.l...

Re:Ldraw: Lego Modeling in Rust by tenaciousDaniel on Tuesday September 17, 2019 @03:46PM (#20999313)
I've always been a JS-focused web developer, with only a bit of experience in other languages (ObjC, Java). I'm trying to build a web app that heavily focuses on 2D graphics. I'm considering going with Rust + WASM, but I don't know anything about Rust.

After doing this project, how would you say you feel about this stack? Yay? Nay? I know that's a vague question, but curious if you ran into any particular troubles. I'm not sure how ready WASM is for production apps.

Re:Ldraw: Lego Modeling in Rust by nicoburns on Tuesday September 17, 2019 @05:51PM (#21000453)
WASM is basically ready for 2 kinds of app:

1. Heavy computation with no UI.

2. Stuff that renders to Web GL.

For the rest your still best off with JavaScript. 2D graphics is pretty borderline I'd say. More work in Rust+WASM, but doable.

Rust itself is wonderful, and well worth learning for the backend if you ever do that kind of stuff.

Re:Ldraw: Lego Modeling in Rust by segfault87 on Tuesday September 17, 2019 @10:16PM (#21001915)
The overall experience has been great. Web APIs(web-sys) are direct translations of WebIDL for now, experiences could get better if we have more 'rustic' APIs. (stdweb looks promising)

Learning Rust can be tricky sometimes. Sometimes it requires you to rethink the way how you code - especially when dealing with the borrow checker.

If you have to do async tasks (fetch, promises, ...) wait until async-await lands on Rust. It's possible on nightly Rust and wasm-bindgen git but it's not stable. Proceed with caution.

Re:Ldraw: Lego Modeling in Rust by binthere on Tuesday September 17, 2019 @06:49PM (#21000871)
Re:Ldraw: Lego Modeling in Rust by grenoire on Tuesday September 17, 2019 @04:05PM (#20999488)
I ran through the source code of the renderer first, and then the implementation for the rest later. And I can honestly say this is one of the prettier Rust code I have seen so far.
Re:Ldraw: Lego Modeling in Rust by JoshTriplett on Tuesday September 17, 2019 @05:44PM (#21000397)
I'm excited about this; I remember using leocad to design complex models, and I'd love to have programmatic tools to work with the same formats in Rust.
Re:Ldraw: Lego Modeling in Rust by inetknght on Tuesday September 17, 2019 @06:38PM (#21000797)
When I run this (Firefox 69.0 on Linux), I see basically nothing. The developer console says:

  RuntimeError: "unreachable executed"
      r https://segfault87.github.io/ldraw-rs-preview/2.index.js:1
      r https://segfault87.github.io/ldraw-rs-preview/2.index.js:1
      Gt https://segfault87.github.io/ldraw-rs-preview/2.index.js:1
      __wbg_new_1719c88e1a2035ea https://segfault87.github.io/ldraw-rs-preview/index.js:1
      a https://segfault87.github.io/ldraw-rs-preview/2.index.js:1
      <anonymous> https://segfault87.github.io/ldraw-rs-preview/index.js:1
Re:Ldraw: Lego Modeling in Rust by tom_mellior on Wednesday September 18, 2019 @05:27AM (#21003572)
I have an Ubuntu machine where it works in both Firefox 69.0 (with glitches, as another commenter noted) and Chromium, and another Ubuntu machine where it works in neither. Might be a graphics driver issue?
Re:Ldraw: Lego Modeling in Rust by ameixaseca on Wednesday September 18, 2019 @04:57PM (#21010106)
It worked for me, but colours were a bit off.
Re:Ldraw: Lego Modeling in Rust by adamnemecek on Monday September 16, 2019 @08:58PM (#20990138)
Re:Ldraw: Lego Modeling in Rust by agumonkey on Tuesday September 17, 2019 @04:26PM (#20999695)
I get `RuntimeError: "unreachable executed"` on firefox nightly (two core2duo machines, linux and win10)

is wasm unsupported ?

Re:Ldraw: Lego Modeling in Rust by monocasa on Tuesday September 17, 2019 @06:32PM (#21000758)
Looks like a logic bug. You get that in an unreachable! macro, generally in a match statement where you think you covered everything by didn't.
Re:Ldraw: Lego Modeling in Rust by grawlinson on Tuesday September 17, 2019 @05:18PM (#21000184)
No issues on my machine on Linux 5.3, running today's build of Firefox Nightly.
Re:Ldraw: Lego Modeling in Rust by agumonkey on Wednesday September 18, 2019 @01:59AM (#21002711)
I didn't see some GL error prior this line, maybe the problem is my igpu.
Re:Ldraw: Lego Modeling in Rust by Phillips126 on Wednesday September 18, 2019 @11:39AM (#21006504)
Really nifty demo.

I've never used wasm before, but I am curious how people feel about the size of the binaries. I am a JS developer and am well aware how bloated a project can get quickly. I agree with the majority that we need to keep our projects lean - especially for the web/mobile, hence this general inquiry.

  - I built a simple hello world in Rust (alert message) and the binary weighed 1kb - nice!
  - I found some sample code ~100 lines of Conway's game of life[1] and that binary is 28kb.
  - I see Ldraw weighs around 131kb - still very impressive.
I don't know yet how wasm will be used in the world professionally, and it is very exciting to me as I am really interested in Rust, but will we start seeing some HUGE binaries out there?

[1] https://rustwasm.github.io/book/game-of-life/implementing.ht...

Re:Ldraw: Lego Modeling in Rust by shmerl on Tuesday September 17, 2019 @04:33PM (#20999764)
Is there actual modeling? The site just shows a rotating object.
Re:Ldraw: Lego Modeling in Rust by amelius on Tuesday September 17, 2019 @06:12PM (#21000610)
This is a legitimate question as the title says "Lego Modeling in Rust"

Perhaps the idea is that the user models the object entirely by writing Rust code.

Re:Ldraw: Lego Modeling in Rust by outworlder on Wednesday September 18, 2019 @07:12PM (#21011468)
No, it is rendering lego models loaded from a specific file format.
Re:Ldraw: Lego Modeling in Rust by brainlessdev on Wednesday September 18, 2019 @04:48AM (#21003425)
Any idea why this runs completely smoothly on Chromium but on Firefox it's glitchy (apparently missing colors on some surfaces) and the FPS are much lower?
Re:Ldraw: Lego Modeling in Rust by echelon on Tuesday September 17, 2019 @09:24PM (#21001688)
Rust is set up to take over the web. WASM with no need to GC will make for eye-bleedingly fast code.

Just wait for Rust to get a DOM API and MVC/data binding framework. UI responsiveness will be incredible, and webapps will feel light weight again. I see a good Rust web frontend library eating React/Vue's lunch.

Re:Ldraw: Lego Modeling in Rust by illuminati1911 on Tuesday September 17, 2019 @09:45PM (#21001776)
I'd hope this was the case, but big part of what has made web development popular and smooth is the easiness and flexibility of JavaScript as a language.

Rust is not exactly easy and flexible, but everything else about it is absolutely great. I think people who will use/learn Rust are top x% or xx% developers who have decent experience in programming and probably understand pretty well how computers and computer systems work.

Javascript has democratized programming and React/Redux stack is widely accepted by developers as well as people looking after business interests in companies doing software development.

Rust would probably make world (of software) a better place, but there would be much less developers available and there already is global shortage of devs while demand is increasing. I don't see Rust replacing JS or React/Vue anytime soon.

Re:Ldraw: Lego Modeling in Rust by fortran77 on Tuesday September 17, 2019 @10:24PM (#21001946)
Rust will absolutely replace JS! You can compile it down to WebASM and people will start doing that soon. No more runtime errors in browsers! Yipee!
Re:Ldraw: Lego Modeling in Rust by hu3 on Tuesday September 17, 2019 @10:36PM (#21001987)
Rust is great but too cognitive-heavy to have any shot at replacing JS.

One should not overestimate the importance of secure/fast over "gets shit done easily with minimal learning curve" on most projects.

Re:Ldraw: Lego Modeling in Rust by thrower123 on Wednesday September 18, 2019 @12:40AM (#21002431)
Most software that is slammed together in JS doesn't need the kind of performance and correctness that Rust can bring to the table.
Re:Ldraw: Lego Modeling in Rust by fortran77 on Tuesday September 17, 2019 @10:39PM (#21002003)
> too cognitive-heavy

Don't underestimate people's intelligence! (Or overestimate your own.) I think people will get it. Javascript is also very cognitive heavy.

Re:Ldraw: Lego Modeling in Rust by unionpivo on Wednesday September 18, 2019 @08:56AM (#21004859)
It has nothing to do with intelligence.

I can grab an average teenager without any kind of programming experience, and teach him enough in one day (maybe 2), for him to google, and copy paste him a working site with some interactive elements.

Sure it will have a ton of bugs, probably only work on his browser, but it will work.

For programming in rust, you need to have at least basic understanding of hardware model and operating systems, know concepts such as stack/heap, references/pointers etc.

Its a ton of additional stuff you need to know, before you can even start. None of that is particularly hard (well most of it). But it's a lot of it.

There are productive JS fronted developers who wouldn't be able to tell you what event based loop is.

Re:Ldraw: Lego Modeling in Rust by hu3 on Wednesday September 18, 2019 @12:26AM (#21002378)
At work, time and energy are best used solving real world problems. Not toying with technology for the sake of it.

And surely you're joking when comparing JS's cognitive load with Rust's...

Re:Ldraw: Lego Modeling in Rust by echelon on Wednesday September 18, 2019 @09:04AM (#21004946)
Have you used Rust with an IDE? It's not at all hard to write. Hard to learn, sure. But it's easy to produce once you know how it works.

Javascript without types and an IDE takes thought. You have to keep remembering which things are which type and how they get plumbed though the stack.

Honestly I'd even say Rust is easier. But I've written a lot of Rust.

Typescript with an IDE makes Javascript easier.

The "Rust is hard" meme needs to die. The language designers have worked tirelessly to ensure that the language is accessible and productive.

Re:Ldraw: Lego Modeling in Rust by nicoburns on Wednesday September 18, 2019 @02:44PM (#21008598)
> Just wait for Rust to get a DOM API and MVC/data binding framework. UI responsiveness will be incredible, and webapps will feel light weight again.

Alas, my experience (and I've benchmarked this extensively) is that it's almost always the DOM / rendering that is the bottleneck in web apps. JavaScript isn't as fast as Rust, but it's pretty damn fast. I wouldn't expect Rust bindings to the DOM to improve much. For that kind of thing, I think we need improvements to the DOM api (and CSS layout model) itself (perhaps a more restricted opt-in fast path).

Re:Ldraw: Lego Modeling in Rust by Hydraulix989 on Tuesday September 17, 2019 @09:09PM (#21001624)
This doesn't work on iOS even though I thought IOS supported wasm?
Re:Ldraw: Lego Modeling in Rust by segfault87 on Tuesday September 17, 2019 @10:05PM (#21001857)
Currently Safari does not support WebGL2. Currently renderer depends on WebGL2 (which supports vertex array object out of the box).
Re:Ldraw: Lego Modeling in Rust by alin23 on Wednesday September 18, 2019 @04:38AM (#21003383)
iOS 13 seems to support WebGL2 pretty well. The rendered model looks really good. You have to enable WebGL2 in the Safari settings under Advanced -> Experimental features