# Three.js starter project

**URL:** <https://community.haxe.org/t/three-js-starter-project/3412>\
**Category:** Haxe\
**Created:** [January 10, 2022, 12:45pm UTC](https://community.haxe.org/t/three-js-starter-project/3412 "2022-01-10T12:45:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haxiomic](https://community.haxe.org/user_avatar/community.haxe.org/haxiomic/32/75_2.png) [@haxiomic](https://community.haxe.org/u/haxiomic)\
**Post date:** [January 10, 2022, 12:45pm UTC](https://community.haxe.org/t/three-js-starter-project/3412/1 "2022-01-10T12:45:32Z")

</div>

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](https://github.com/haxiomic/haxe-threejs-template)

[![Screenshot 2022-01-10 at 15.43.34](https://community.haxe.org/uploads/default/original/2X/0/09c1cb9c1cc760a924265df8b2755e01f8182c02.jpeg)](https://haxiomic.github.io/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](https://haxe.org) language. Main.hx sets up a physically based rendering pipeline and some optimized HDR lighting environments are include in [assets/](https://github.com/haxiomic/haxe-threejs-template/blob/master/assets/)

[See live](https://haxiomic.github.io/haxe-threejs-template)

## Building and running

- Download [haxe 4.2](https://haxe.org/download/version/4.2.4/)

- `cd` into this directory and install node modules with `npm install`

- Start an live server with `npm start`

- run `haxe build.hxml` to recompile the project into [bin/](https://github.com/haxiomic/haxe-threejs-template/blob/master/bin/)

## Editing

[VSCode](https://code.visualstudio.com/) has great haxe IDE support with the haxe [extension](https://marketplace.visualstudio.com/items?itemName=nadako.vshaxe&ssr=false#review-details)

I recommend installing the [trigger task on save](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.triggertaskonsave) 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](https://github.com/haxiomic/dts2hx) tool. The generated externs are included in this repository in the [.haxelib](https://github.com/haxiomic/haxe-threejs-template/blob/master/.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](https://github.com/evanw/esbuild)) so we generate a single file – this is called by [build.hxml](https://github.com/haxiomic/haxe-threejs-template/blob/master/build.hxml). Alternatively we could have used three.js globally via a script tag if we generated the externs with [`--global`](https://github.com/haxiomic/dts2hx#faq)

A haxe library, [three-toolkit](https://github.com/haxiomic/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](https://github.com/haxiomic/haxe-threejs-template/blob/master/.haxelib/three-toolkit/git/ui/DevUI.hx)

- [CustomPhysicalMaterial](https://github.com/haxiomic/haxe-threejs-template/blob/master/.haxelib/three-toolkit/git/material/CustomPhysicalMaterial.hx) 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

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [January 12, 2022, 9:37am UTC](https://community.haxe.org/t/three-js-starter-project/3412/2 "2022-01-12T09:37:02Z")

</div>

thank you for your great tool dts2hx. I have a project use dts2hx +three.js +react +mui now ,and I got

some small suggestions here?

1. support direct property instead of ts.AnyOf2 or 3 or 4… . like native js

2.add some help tool like array.push(…args);

1. consider dts2hx support react framework,vue?

4.support [gens](https://github.com/benmerckx/genes) lib.right now everything seems ok .

1. it’s better to support the overload feature.

---

<div class="post-metadata">

**Author:** ![rathewolf](https://community.haxe.org/user_avatar/community.haxe.org/rathewolf/32/1335_2.png) [@rathewolf](https://community.haxe.org/u/rathewolf)\
**Post date:** [March 12, 2022, 1:39am UTC](https://community.haxe.org/t/three-js-starter-project/3412/3 "2022-03-12T01:39:27Z")

</div>

😮

this is ginormous!

even an entire typescript binding generator? 😮

i stumbled upon this after you linked me MathVector class 😃
