Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Three on node.js with JSONLoader

Three on node.js with JSONLoader

Problem

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.

Problem courtesy of: gaet

Solution

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.

Solution courtesy of: Tomasz Lenarcik

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Three on node.js with JSONLoader

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×