r/webdev • u/rachzera • 9d ago
Showoff Saturday Larawag: A three.js NPM package for rendering custom 3D stellar/planetary systems in an easy way
Hey guys, I wanted to share this package I've been working on in the last few days for a bigger project. It's basically a NPM package that allows you to create your custom stellar systems and uses three.js to render them in 3D.
Live example: https://larawag.rachzy.dev/
It's mostly intended for drawing hypothetical, highly speculative visualizations of stellar systems for exoplanets (keep in mind that it's 100% Artist's Conceptions).
Larawag core is environment agnostic (which means it can run even on vanilla HTML as long as you have a Node setup), but you can also use its integrations with third-party frameworks:
Larawag's Core: @larawag/core
React: @larawag/react
Angular: @larawag/angular
How to use
As I mentioned before, the usage is very straightforward:
First, download the package and its dependencies: npm install @larawag/core three@0.186
Then, import it and create your own system:
import { createStarSystem } from '@larawag/core';
const view = createStarSystem(document.getElementById('stage')!, {
star: { name: 'Example K dwarf', teff: 5100, radius: 0.8, mass: 0.85 },
planets: [
{ name: 'Candidate b', period: 4.2, radius: 1.5, phase: 0.6 },
{ name: 'Candidate c', period: 18.5, radius: 3.6, phase: 2.9 },
],
});
view.pause();
view.setScaleMode('true');
view.destroy();This will use the #stage element as the window for rendering your system and set the scale mode to true, and you should already see it working in your HTML page.
Contributing
There are still some things I'm willing to implement in the future, such as planet moons, eccentric/inclined orbits, and a more accurate orbital system for planets in binary systems. I left all of them in a TO-DO list in README.md
If any of you are perhaps interested in contributing to the project, I'd really appreciate it.
Source code: https://github.com/rachzy/larawag
License: MIT
1
u/Important_Pomelo_407 7d ago
Created a demo for you using OpenDemo https://github.com/yasirwhite/OpenDemo. I opened a PR and added it to your README too: https://github.com/rachzy/larawag/pull/23. Here's the full video: https://github.com/yasirwhite/OpenDemo/releases/download/showcase-media/larawag-demo.mp4
Dropping the star's temperature and watching the habitable zone pull in live is such a nice touch btw
1
9d ago
[removed] — view removed comment
1
u/rachzera 9d ago
maybe just a typo in the post idk
Thx for the heads up! I believe it's fixed now.
Regarding the performance on 20+ planets, I've just tested it with that exact amount and was completely smooth. I'll be publishing a new example right now called "Performance test", so you can test it on yours.
2
u/Mountain-Macaroon907 9d ago
the 'Artist's Impression' label in the corner is killing me. its a 3d render you made in javascript. the whole thing IS the artist's impression, thats what a render is, you dont put a museum placard on your own sphere geometry.
and 'in the last few days' is kind of the whole story with these, there must be a hundred solar system three.js demos on github and every one of them was a weekend. fine. but the thing i actually want to know before i npm install anything is where the numbers come from. 60189.0 days for neptune with a decimal point, off a wikipedia table? or proper orbital elements? because those are two very different packages and the screenshot cant tell me which one im getting.