Hey guys,
I'm taking a stab at wrapping the three.js library and ran into a problem...
when declaring variables for various three.js objects and other types, I have to prefix them with THREE like so:
var scene = new THREE.Scene(); or var renderer = new THREE.WebGLRenderer();
How can I go about implementing this as part of the wrapper, so these these types will export THREE. along with the object itself in the final output?
I think I came up with a hack.. it works but idk if it's the best way of doing things:
wrapper:
from dom import Node
type
Scene* = ref object
Camera* = ref object of RootObj
PerspectiveCamera* = ref object of Camera
fov*,far*{.importc.}: cint
aspect*, near* {.importc.}: cfloat
WebGLRenderer* = ref object
domElement*{.importc.}: Node
proc newScene*(): Scene {.importc: "new THREE.Scene".}
proc newCamera*(fov: cint, aspect, near: cfloat, far: cint): PerspectiveCamera {.importc: "new THREE.PerspectiveCamera".}
proc newWebGLRenderer*(): WebGLRenderer {.importc: "new THREE.WebGLREnderer".}
mainjs.nim
import threejs
var scene {.exportc.} = newScene()
var camera {.exportc.} = newCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
var renderer {.exportc.} = newWebGLRenderer()
output(js)
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, HEX2F_1555648(window.innerWidth, window.innerHeight), 1.0000000000000001e-01, 1000);
var renderer = new THREE.WebGLRenderer();
I think I came up with a hack..
It's not a hack, it's how you're supposed to do it. :-)