Skip to content

Commit

Permalink
Try loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinresol committed Dec 3, 2019
1 parent 8002b4d commit ab29db1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Binary file added bin/playground/coco/models/human.fbx
Binary file not shown.
7 changes: 7 additions & 0 deletions src/react/three_fiber/Three.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import haxe.extern.EitherType;
// https://github.com/react-spring/react-three-fiber/blob/master/src/three-types.ts

class Three {
public static inline function primitive(attr:PrimitiveAttrs, ?children) return h('primitive', attr, children);

public static inline function line(attr:LineAttrs, ?children) return h('line', attr, children);
public static inline function mesh(attr:MeshAttrs, ?children) return h('mesh', attr, children);

Expand Down Expand Up @@ -124,6 +126,11 @@ typedef NodeAttrs = {
// onUpdate:Self->Void
}

typedef PrimitiveAttrs = {
> Object3DAttrs,
object:three.core.Object3D,
}

typedef Object3DAttrs = {
> EventAttrs,
?position:Vector3,
Expand Down
25 changes: 22 additions & 3 deletions tests/PlaygroundCoco.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import react.three_fiber.Three.*;
import react.three_fiber.Extensions;
import react.three_fiber.Extensions.*;
import react.three_fiber.Utils.*;

using coconut.ui.Renderer;
using tink.CoreApi;

class PlaygroundCoco extends coconut.ui.View {
static function main() {
trace('coco');
extend({OrbitControls: OrbitControls, PointerLockControls: PointerLockControls, FlyControls: FlyControls});
js.Browser.document.getElementById('app').mount(hxx('<PlaygroundCoco/>'));
}
Expand All @@ -22,16 +23,24 @@ class PlaygroundCoco extends coconut.ui.View {
function render() '
<Canvas onCreated=${v -> ctx = v}>
<if ${ctx != null}>
<Thing ctx=${ctx}/>
<Thing ctx=${ctx} data=${new Data()}/>
</if>
</Canvas>
';
}


class Data implements coconut.data.Model {
@:skipCheck @:loaded var human:three.core.Object3D = {
new Promise(function(resolve, reject) {
var loader = new FBXLoader();
loader.load('/models/human.fbx', resolve, function(progress) trace(progress), function(e) reject(Error.ofJsError(e)));
});
}
}

class Thing extends coconut.ui.View {
@:skipCheck @:attr var ctx:CanvasContext;
@:attr var data:Data;
@:state var t:Float = 0;

static var material = new LineBasicMaterial({color: 0x00ff00});
Expand Down Expand Up @@ -78,6 +87,11 @@ class Thing extends coconut.ui.View {
<pointLight color=${0x0000ff} position=${[1, 1, -1]}/>
<orbitControls args=${[ctx.camera, ctx.gl.domElement]} enableKeys />
<switch ${data.human}>
<case ${Done(human)}> <primitive object=${human} rotation=${[t, 0, t]}/>
<case ${_}>
</switch>
</>
';

Expand All @@ -89,4 +103,9 @@ class Thing extends coconut.ui.View {
}


}
@:jsRequire('three/examples/jsm/loaders/FBXLoader', 'FBXLoader')
extern class FBXLoader {
function new();
function load(url:String, onSuccess:haxe.Constraints.Function, onProgress:haxe.Constraints.Function, onError:haxe.Constraints.Function):Void;
}

0 comments on commit ab29db1

Please sign in to comment.