Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.JSL: Does local server needed for loading Blender model?

Tags:

three.js

I am developing a web based 3D WebGL application using Three.js. I am trying to load a "Blender" model JS file using the following code:

var loader = new THREE.JSONLoader();
    var jsonLoader = new THREE.JSONLoader();
    jsonLoader.load( "../build/MySampleModel.js", addModelToScene );
    // addModelToScene function is called back after model has loaded

    var ambientLight = new THREE.AmbientLight(0x111111);
    scene.add(ambientLight);

    function addModelToScene( geometry, materials ) 
    {
        var material = new THREE.MeshFaceMaterial( materials );
        meshObj = new THREE.Mesh( geometry, material );
        meshObj.scale.set(10,10,10);
        meshObj.add( android );
    }      

When I tested this in Chrome browsers, it does NOT load the model and it gives the following error:

THREE.WebGLRenderer 59dev three.min.js:417
XMLHttpRequest cannot load file:///Users/xxxx/Desktop//THREE_JS_3DWEB/Dev/three.js-dev/build/MySampleModel.js. Cross origin requests are only supported for HTTP. three.min.js:211
THREE.JSONLoader: [../build/HouseModel.js] seems to be unreachable or file there is empty three.min.js:210
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 three.min.js:211

I am not running any local server in my machine. Is it necessary to have a local server running to load Blender model JS file in a Three.js based project?

(When I try running Three.js example file called "webgl_loader_json_blender.html" which uses loading of blender models, in Eclipse with a local apache server running, it is able to load the blender file properly when I'm running "webgl_loader_json_blender.html" in Chrome browser.)

like image 646
Stella Avatar asked Apr 25 '26 11:04

Stella


1 Answers

I'm not an expert, but yours seems to be a problem with the browsers' "same origin policy" security restriction. Check this link from the three.js repository: https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally

I've experienced that it is easier to load local models using Mozilla Firefox instead Chrome.

So the answer is no, server is not required to load a model.

Good luck!

like image 168
electronixG Avatar answered Apr 29 '26 13:04

electronixG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!