4

When I make a JSON model and load it using THREE.JSONLoader.load it is loaded without any issues, but when I attempt to make a variable out of it and include data in the main script the THREE.JSONLoader.parse call throws an exception.

var lh_model = {
    "metadata" : { "formatVersion" : 3.1, ..., "morphTargets"  : 0 },
    "vertices": [
          0.001000,    0.001000,  -0.001000,
        102.616974,  -61.974983,  19.303007,
        102.108978,  -62.482986,  -7.620989,
        123.952972,  -49.274994,  -3.048992,
        123.952972,  -48.766994,  14.223002
    ],
    "uvs": [0.9458,0.5134,0.9419,0.5177,0.9513,0.5177,........],
    "faces": [ 0, 4, 1, 2 ],
    "morphTargets": []
}

var loader = new THREE.JSONLoader();
var geometry = loader.parse(lh_model);

load.parse causes the

Uncaught TypeError: Cannot read property 'length' of undefined

error somewhere deep inside of Three.js:

THREE.Mesh.prototype.updateMorphTargets = function () {

    if ( this.geometry.morphTargets.length > 0 ) {

The same happens when I take the working examples made by other people (http://stemkoski.github.io/Three.js/Model.html).

I am using Three.js r.58

1 Answer 1

4

Do this

var loader = new THREE.JSONLoader();
var model = loader.parse( lh_model );

var mesh = new THREE.Mesh( model.geometry, new THREE.MeshBasicMaterial() );
scene.add( mesh );

If your add a material into your model, you would do something like this

var mesh = new THREE.Mesh( model.geometry, materials[ 0 ] );

three.js r.58

Sign up to request clarification or add additional context in comments.

1 Comment

Note for all followers: pay attention to Three.js version. r.56 does not have parse method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.