user1879027
user1879027

Reputation:

MeshFaceMaterial/ JSON material error

My model loads fine with this code:

loader.load( "js/charWalk01.js", function( geometry, materials ) {
                mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
                scene.add( mesh );

            } );

However, when I try to use the MeshFaceMaterial (so as to use the material in the JSON file), I get two really odd three.min.js error messages (below).

loader.load( "js/charWalk01.js", function( geometry, materials ) {
                materials[ 0 ].morphTargets = true;
                mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial() );
                scene.add( mesh );
            } );

The errors are:

    TypeError: 'undefined' is not an object (evaluating 'a.map') three.min.js:347

    TypeError: 'undefined' is not an object (evaluating 'ma.attributes') three.min.js:429

The JSON file is perfectly normal (created with the OBJ converter), here's the material code from it:

    "materials": [  {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Mat.1",
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorSpecular" : [0.4, 0.52, 0.53],
"illumination" : 4,
"mapDiffuse" : "Character_01.jpg"
}],

Any help as to why those errors might appear?

Cheers, Ian

Upvotes: 0

Views: 1066

Answers (1)

WestLangley
WestLangley

Reputation: 104783

You need to pass materials as an argument to MeshFaceMaterials, like so:

loader.load( "js/charWalk01.js", function( geometry, materials ) {
    materials[ 0 ].morphTargets = true;
    mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
    scene.add( mesh );
} );

three.js r.53

Upvotes: 1

Related Questions