But, it returning error Scene not found
src/Main.hx:11: characters 19-24 : Type not found : Scene
src/Main.hx:13: characters 22-33 : Type not found : BoxGeometry
src/Main.hx:14: characters 18-22 : Type not found : Mesh
src/Main.hx:18: characters 24-34 : Type not found : PointLight
src/Main.hx:22: characters 20-37 : Type not found : PerspectiveCamera
src/Main.hx:26: characters 22-35 : Type not found : WebGLRenderer
What other libraries do I need to install?
import js.Browser;
import js.three.*;
class Main {
public static function main() {
var w = Browser.window.innerWidth;
var h = Browser.window.innerHeight;
var scene = new Scene();
var geometry = new BoxGeometry(50, 50, 50, 1, 1, 1);
var cube = new Mesh(geometry, new MeshLambertMaterial({color: 0xcc0000}));
cube.position.set(0, 100, 0);
scene.add(cube);
var pointLight = new PointLight(0xffffff, 1, 0);
pointLight.position.set(10, 50, 130);
scene.add(pointLight);
var camera = new PerspectiveCamera(70, w / h, 1, 1000);
camera.position.z = 500;
scene.add(camera);
var renderer = new WebGLRenderer();
renderer.setSize(w, h);
Browser.document.body.appendChild(renderer.domElement);
var update = null;
update = function(f:Float):Bool {
Browser.window.requestAnimationFrame(update);
renderer.render(scene, camera);
return true;
}
update(0);
}
}
-cp src
-dce full
-lib threejs
# Generate three.js javascript in the threejs
-main Main
-js bin/threejs/Main.js
But, I started to get warming messages:
\HaxeToolkit\haxe\lib\threejs/84,0,0/js/three/Matrix.hx:10: characters 17-29 :
Warning : This typedef is deprecated in favor of js.lib.Float32Array
Since I when back to Haxe V3.x.x. It can compile the three.js example.
// package js.three;
import js.Browser;
//import js.Browser.window;
//import js.Browser.document;
import js.three.*;
// import js.html.*;
// import js.Dom;
//import js.Lib;
class Main {
public static function main() {
var w = Browser.window.innerWidth;
var h = Browser.window.innerHeight;
var scene = new Scene();
// var tst = new THREE.FontLoader();
var tst2 = new THREE.geometry();
var geometry = new BoxGeometry(50, 50, 50, 1, 1, 1);
var cube = new Mesh(geometry, new MeshLambertMaterial({color: 0xcc0000}));
cube.position.set(0, 100, 0);
scene.add(cube);
var pointLight = new PointLight(0xffffff, 1, 0);
pointLight.position.set(10, 50, 130);
scene.add(pointLight);
var camera = new PerspectiveCamera(70, w / h, 1, 1000);
camera.position.z = 500;
scene.add(camera);
var renderer = new WebGLRenderer();
renderer.setSize(w, h);
Browser.document.body.appendChild(renderer.domElement);
var update = null;
update = function(f:Float):Bool {
Browser.window.requestAnimationFrame(update);
renderer.render(scene, camera);
return true;
}
update(0);
}
}
But, when I want to start using other three.js syntax errors RG
you can not access the js package while targeting cross (for js.browser)
haxelib install threejs downloads the threejs haxe library which contains externs for the js target giving you access to the threejs js library when you include it in your project (-lib threejs).
See Getting Started - Haxelib Documentation for more information on haxelib.