I need to use three.js on my node.js server to control positions and collisions on players (I try to make a video game).
To use three on nodejs, I have install with "npm install three", and it's works.
But when I want call JSONLoader, I can't.
I my class, I add :
var THREE =require('three'); //or require('three/three.js');
var JSON=require('three/src/loaders/JSONLoader.js');
or
require('three'); //or require('three/three.js');
var JSON=require('three/src/loaders/JSONLoader.js');
It the same, I have an error, "THREE is not defined" and I don't undestand why?
To resolve this error i put the JSON code in the three.js file, but I find an other problem when I load json:
var loader = new THREE.JSONLoader();
loader.load(__dirname + '/public/js/essai/test.dae',function ( collada ){
...
});
Error : XMLHttpRequest is not defined.
I think, I don't use correctly but I don't undestand where is my fault?
Can you help me plz?
Thank you very much.
You don't need the socond line, i.e.
var JSON = require('three/src/loaders/JSONLoader.js');
If you load three.js
properly, so e.g.
var THREE = require('three/three.js')
the JSONLoader
is already there, so THREE.JSONLoader
should work just fine.
BTW, the reason why you're getting this error is because the code of JSONLoader.js
depends on existance of THREE
object in the global scope. But, it's not there because your THREE
object is local.