Skip to content

Smile-SA/Threelon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Threelon

Threelon is a domain-specific language (DSL) that lets you describe 3D scenes once and generate them for Three.js, Babylon.js, or Unity — making your 3D workflow engine-agnostic and future-ready.

Threelon is a lightweight 3D scene abstraction system that converts high-level, engine-independent instructions into working code for some of the most widely-used rendering platforms. Whether you're building web-based or native 3D applications, Threelon helps you keep your logic in one place and output to many.

Threelon is still in early development — APIs may change. Contributions and feedback are welcome!

Threelon

🚀 Motivation

The idea behind this project is to simplify multi-engine 3D development. Instead of rewriting logic for different platforms, Threelon enables you to write your scene logic once using a common DSL and export it to Three.js, Babylon.js, Unity, or Unreal Engine.

This approach not only reduces development time but also promotes code consistency across platforms.

output

📦 Requirements

  • Node.js v18 or later
  • Yarn package manager (recommended)

⚙️ Setup

Install project dependencies:

yarn install

Run the project:

yarn dev

🧪 Default Script Example

const canvas = document.createElement("canvas");
document.body.appendChild(canvas);
const renderer = threelon.createRenderer(canvas);
const scene = threelon.createScene("#000000");
const camera = threelon.createCamera(Math.PI / 4, Math.PI / 4, 10, 75, 0.1, 1000, [0, 0, 0]);
const controls = threelon.createControls(camera, canvas);
threelon.attachLight("#ffffff", "#444444", scene);
const box = threelon.createBox(2, "#ffffff", scene);
threelon.animateRotate([0, 0, 0], [90, 180, 0], 3000, box);
threelon.addResizeEvent(renderer, camera);
threelon.render(camera, scene, renderer, controls);

📄 API Documentation

Method Description Parameters Returns
threelon.render Renders the scene using the camera and renderer. Optionally uses controls and a container. camera, scene, renderer, controls (optional), container (optional) void
threelon.createCamera Creates and returns a camera. alpha, beta, distance, fov, near, far, target, scene (optional) camera object
threelon.createControls Creates camera controls for Three.js. camera, container controls object
threelon.attachLight Adds a hemispheric light to the scene. skyColor, groundColor, scene light object | void
threelon.createBox Creates a box mesh. size, color, scene mesh object
threelon.createSphere Creates a sphere mesh. radius, color, scene mesh object
threelon.createCylinder Creates a cylinder mesh. height, diameter, color, scene mesh object
threelon.createPlane Creates a plane mesh. width, height, color, scene mesh object
threelon.createTorus Creates a torus mesh. radius, tube, color, scene mesh object
threelon.createCone Creates a cone mesh. radius, height, color, scene mesh object
threelon.addResizeEvent Adds a window resize listener to update renderer and camera. renderer, camera (optional) void
threelon.animateMove Animates an object's position from start to end. from, to, duration, object void
threelon.animateRotate Animates an object's rotation from start to end. from, to, duration, object void

This format is fully plain Markdown and easy to read in any Markdown viewer.

See source folders for details:

  • core/: language and AST logic
  • engines/: engine-specific implementation
  • CodeGenerator.ts: JavaScript generator
  • CSharpCodeGenerator.ts: Unity C# generator

📦 Supported Shapes

The following 3D primitives are currently supported across engines:

Shape Supported in Three.js Supported in Babylon.js Supported in Unity Supported in Unreal Engine 5.7
Box
Sphere
Cylinder
Plane
Torus (not yet) (not yet)
Cone (via workaround)

🎞️ Animation Functions

Function Description Supported in Three.js Supported in Babylon.js Supported in Unity Supported in Unreal
animateMove(from, to, duration, obj) Moves an object smoothly between two positions over a set duration (ms). ✅ (via transform logic) (not yet)
animateRotate(from, to, duration, obj) Rotates an object between angles (in degrees) over time. Supports 2D and 3D rotation. ✅ (via Euler angles) (not yet)

🧱 Implementation Details

Use the appropriate code generator depending on your target engine:

JavaScript output (Three.js / Babylon.js)

const generator = new CodeGenerator(script, new ThreeEngine());
const output = generator.generateCode();

Unity C# output

const generator = new CSharpCodeGenerator(script, new UnityEngine());
const output = generator.generateCode();

Unreal Engine C# output

const generator = new UnrealCodeGenerator(script, new UnrealEngine());
const result = generator.generateCode();
  • ThreeEngine: renders to Three.js
  • BabylonEngine: renders to Babylon.js
  • UnityEngine: generates Unity C# MonoBehaviour class

👥 Contribute

Pull requests and feature discussions are welcome. Please open an issue to suggest improvements or file bugs.

👏 Credits

📜 License

Licensed under the MIT License.

About

Threelon is a domain-specific language (DSL) that lets you describe 3D scenes once and generate them for Three.js, Babylon.js, or Unity — making your 3D workflow engine-agnostic and future-ready.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages