Hey all!
I’ve been using haxe with three.js for professional work for a couple years now and I love it. I thought I’d share my base project in case it’s useful to anyone else:
github.com/haxiomic/haxe-threejs-template
Here’s the README
Haxe Three.js starter project
This is a batteries-included template project using three.js with the haxe language. Main.hx sets up a physically based rendering pipeline and some optimized HDR lighting environments are include in assets/
Building and running
-
Download haxe 4.2
-
cd
into this directory and install node modules withnpm install
-
Start an live server with
npm start
-
run
haxe build.hxml
to recompile the project into bin/
Editing
VSCode has great haxe IDE support with the haxe extension
I recommend installing the trigger task on save extension – this will trigger the project to recompile when you save haxe files, which is helpful for live editing
Project Overview
We can interact with three.js through externs generated from the typescript type definitions using the dts2hx tool. The generated externs are included in this repository in the .haxelib directory. To regenerate these files you can call npm run externs
three.js is included as a module by using require()
, since browsers don’t have require
we use a bundler (esbuild) so we generate a single file – this is called by build.hxml. Alternatively we could have used three.js globally via a script tag if we generated the externs with --global
A haxe library, three-toolkit is included, which provides useful utilities for working with three.js and haxe, including
-
Post processing pipeline tools
-
A dat.gui extension: DevUI
-
CustomPhysicalMaterial for making pbr materials with custom shaders
-
Objects such as a soft mirror plane
-
Spring physics animation tooling
Have fun :D, feel free to open issues if you have questions