0
$\begingroup$

I need to load a model "somemodel.json" into my "movie.js".Can someone tell me where i am going wrong.I followed the steps given here.

index.html

<!DOCTYPE html>
<html>
    <head>
         <meta charset=utf-8>
         <title>Test</title>
         <style>
            body { margin: 0; }
            canvas { width: 100%; height: 100% }
         </style>
    </head>
    <body>
        <script src="three.min.js"></script>
        <script src="ObjectLoader.js"></script>
        <script src="movie.js"></script>
    </body>
</html>

movie.js

var camera;
var scene;
var renderer;
var loader;

frame();
animate();

function frame() {

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, window.innerWidth /     window.innerHeight, 0.1, 1000);
camera.position.y = 0;
camera.position.z = 10;
camera.rotation.x = 0;

var loader = new THREE.ObjectLoader();
loader.load(
'somemodel.json',
function () {
    var geometry = new THREE.SphereGeometry(3,32,32);
    var material = new THREE.MeshBasicMaterial();
    var object = new THREE.Mesh( geometry, material );
    scene.add( object );
}
);

renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
render();
}

function animate() {
render();
requestAnimationFrame( animate );
}

function render() {
renderer.render( scene, camera );
}

Or can your give an example with a sample model ?

When i run my file it raises an error in the console saying not well-formed male.json

$\endgroup$
0
2
$\begingroup$

The error not well-formed male.json doesn't appear to have anything to do with the code you've posted. I don't see any references to a JSON file called male.json.

If this file is in your code somewhere, the error is telling you the problem. It is malformed. Paste the contents of the file into an online validation tool such as JSONLint. It will tell you what is making it malformed.

Also, you're passing JSON into ObjectLoader.load but you don't do anything with the results. Instead try this:

var loader = new THREE.ObjectLoader();
loader.load('somemodel.json', function (object) {
    scene.add(object);
});

Check out the documentation for more information.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.