artoolkitx / jsartoolkit5

Javascript ARToolKit v5.x
https://artoolkitx.github.io/jsartoolkit5/examples/
Other
292 stars 69 forks source link

use typescript, runtime reports: artoolkit_api__WEBPACK_IMPORTED_MODULE_1__.ARCameraParam/ARController is not a constructor #80

Open sprhawk opened 5 years ago

sprhawk commented 5 years ago

I have been struggling between typescript and jsartoolkit5 for serveral days

I'm using webpack to bundle them. typescript version: 3.2.2

inside webpack.config.js, I set an alias for lib

resolve: {
    extensions: [".js", ".ts", "json"],
    modules: ["node_modules"],
    alias: {
      "artoolkit.api": path.resolve(__dirname, "thirdparties/jsartoolkit5/js/artoolkit.api.js"),
    },
  },

in typescript:

 import {ARController, ARCameraParam} from 'artoolkit.api';
this._cameraParam = new ARCameraParam("/static/dist/artoolkit/camera_para.dat", 
        function() {
            self._arcontroller = new ARController(320, 240, self._cameraParam);
            self._arcontroller.process(self._videoTexture.video);
            self._arcontroller.debugSetup();

            let camera = self._scene.getCameraByName("Camera");
            if (camera) {
                camera.freezeProjectionMatrix(Matrix.FromArray(self._arcontroller.getCameraMatrix()));
            }
        },
        function(err: Error) {
            console.log("failed to load ARCameraParam: " + err);
        });

in artoolkit.api.d.ts, I changed a bit, added:

constructor(src: string, onload: ()=> void, onerror: (err: Error)=> void);

for

export declare class ARCameraParam {
    onload(): void;
    load(cameraData: string): void;
    constructor(src: string, onload: ()=> void, onerror: (err: Error)=> void);
}

the transpile passed, but when running, the chrome reported: Uncaught TypeError: artoolkit_api__WEBPACK_IMPORTED_MODULE_1__.ARCameraParam is not a constructor