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.
If you load
three.js
properly, so e.g.the
JSONLoader
is already there, soTHREE.JSONLoader
should work just fine.BTW, the reason why you're getting this error is because the code of
JSONLoader.js
depends on existance ofTHREE
object in the global scope. But, it's not there because yourTHREE
object is local.Thank you to your help.
I replace my code, indeed it's works better, i don't know why I have had JSONLoader.js into variable.
However, I have my second problem. This code run at reception to a socket in node.js.
But my error is :
After search, i have try to replace url json by
http://localhost:2999/js/essai/test.js
like this : https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally And I have acces to my json with this url.But XMLHttpRequest is not defined, so it's change nothing, I think it's because I try to do this with a socket function but i'm not sure.
I have a last one question. In node server I load .json file and put in to the scene to detect collisions.
Node:
To detect collision :
When I have try collision on the client , it's work fine, but on the server, he doesn't detect collisions. So, I have try to load json file in my client to see if the load is correctly.
When I load like this in my Client, the scene is ok:
And when I load like this in Client, it's not ok:
No error, but nothing appear.
So I think is the same to the server side, and why collisions are never detect.
In the server side, I don't use animate() , because I think it's not necessary. And the calcul to deplace my car it's ok.
So I think maybe the loader don't load the mesh correctly, or I can't make detection collisions as on Client. What do you think?
Thx.
To detect collisions on Client I use:
When I up, I set the direction : this.direction.set(0,0,1); When I down,I set the direction : this.direction.set(0,0,-1); ...