Error in three.js :- Materials[json.type] is not a constructor #9944

Closed
IamRizban opened this Issue Oct 26, 2016 · 2 comments

Projects

None yet

2 participants

@IamRizban
IamRizban commented Oct 26, 2016 edited
Description of the problem

Hi, i am working on a web app which will render 3D animated models. These models made by 'Maya 2016'. I am exporting these models using three.js (r81) 'maya exporter plugin'. Everything goes fine. But when i am loading this json model using below code:

var objectLoader = new THREE.ObjectLoader(manager); objectLoader.load( 'assets/New-Heart/full_heart.json', function (object) { scene.add(object); }, onProgress, onError );

then getting this error (Error in three.js :- Materials[json.type] is not a constructor) on line no. - 31381
I have asked the same on StackOverflow. Here it is link:
I am attaching my json file (in txt format, because i was unable to attach .json file)
heart-new.txt
.

Three.js version
  • Dev
  • [x ] r81
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
@mrdoob
Owner
mrdoob commented Oct 26, 2016

That file needs to be loaded with THREE.JSONLoader instead. I'll add a check for that in THREE.ObjectLoader.

@mrdoob mrdoob closed this Oct 26, 2016
@IamRizban
IamRizban commented Oct 27, 2016 edited

Hi,
@mrdoob , thank for your quick reply. As per your suggestion i am moving with JSONLoader but still i am not getting model on my webpage.

Here it is changed code:

        var jsonloader = new THREE.JSONLoader( manager );
        jsonloader.load( jsonFileName, function( geometry, materials ) {
            for ( var i = 0; i < materials.length; i ++ ) {
                var m = materials[ i ];
                 m.morphTargets = true;
                 console.log(m);
            }
            mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
            scene.add( mesh );
        } );

I have set camera.position.z = 100

My console screen o/p:

MeshLambertMaterial {uuid: "5F9A718B-031F-45CC-9AF4-055345D2DA75", name: "Full_Heart1", type: "MeshLambertMaterial", fog: true, lights: true…}

So i used 'MeshLabmertMaterial', but it is just showing white model (not with textures). I am attaching screentshot.

screenshot

Here it is my json materials array :

    "materials": [{
        "opacity": 0.0, 
        "mapDiffuseRepeat": [1, 1], 
        "mapNormalFactor": 1, 
        "depthTest": true, 
        "colorDiffuse": [0.5, 0.5, 0.5], 
        "vertexColors": false, 
        "blending": "NormalBlending", 
        "mapDiffuseAnisotropy": 4, 
        "shading": "Blinn", 
        "transparent": true, 
        "depthWrite": true, 
        "mapNormalRepeat": [1, 1], 
        "mapNormalWrap": ["repeat", "repeat"], 
        "DbgName": "orange", 
        "mapNormalAnisotropy": 4, 
        "mapNormal": "orange_bump.jpg", 
        "mapDiffuseWrap": ["repeat", "repeat"], 
        "mapDiffuse": "orange.jpg"
    }, {
        "opacity": 0.0, 
        "mapDiffuseRepeat": [1, 1], 
        "mapNormalFactor": 1, 
        "depthTest": true, 
        "colorDiffuse": [0.5, 0.5, 0.5], 
        "vertexColors": false, 
        "blending": "NormalBlending", 
        "mapDiffuseAnisotropy": 4, 
        "shading": "Blinn", 
        "transparent": true, 
        "depthWrite": true, 
        "mapNormalRepeat": [1, 1], 
        "mapNormalWrap": ["repeat", "repeat"], 
        "DbgName": "orange", 
        "mapNormalAnisotropy": 4, 
        "mapNormal": "orange_bump.jpg", 
        "mapDiffuseWrap": ["repeat", "repeat"], 
        "mapDiffuse": "orange.jpg"
    }, {
        "opacity": 0.0, 
        "colorDiffuse": [0.10324621354410368, 0.19598565393664913, 0.35121951626568304], 
        "depthWrite": true, 
        "blending": "NormalBlending", 
        "shading": "Blinn", 
        "DbgName": "plate", 
        "transparent": true, 
        "depthTest": true, 
        "vertexColors": false
    }, {
        "opacity": 0.0, 
        "mapDiffuseRepeat": [1, 1], 
        "mapNormalFactor": 1, 
        "depthTest": true, 
        "colorDiffuse": [0.5, 0.5, 0.5], 
        "vertexColors": false, 
        "blending": "NormalBlending", 
        "mapDiffuseAnisotropy": 4, 
        "shading": "Blinn", 
        "transparent": true, 
        "depthWrite": true, 
        "mapNormalRepeat": [1, 1], 
        "mapNormalWrap": ["repeat", "repeat"], 
        "DbgName": "orange", 
        "mapNormalAnisotropy": 4, 
        "mapNormal": "orange_bump.jpg", 
        "mapDiffuseWrap": ["repeat", "repeat"], 
        "mapDiffuse": "orange.jpg"
    }, {
        "opacity": 0.0, 
        "mapDiffuseRepeat": [1, 1], 
        "mapNormalFactor": 1, 
        "depthTest": true, 
        "colorDiffuse": [0.5, 0.5, 0.5], 
        "vertexColors": false, 
        "blending": "NormalBlending", 
        "mapDiffuseAnisotropy": 4, 
        "shading": "Blinn", 
        "transparent": true, 
        "depthWrite": true, 
        "mapNormalRepeat": [1, 1], 
        "mapNormalWrap": ["repeat", "repeat"], 
        "DbgName": "orange", 
        "mapNormalAnisotropy": 4, 
        "mapNormal": "orange_bump.jpg", 
        "mapDiffuseWrap": ["repeat", "repeat"], 
        "mapDiffuse": "orange.jpg"
    }, {
        "opacity": 0.0, 
        "mapDiffuseRepeat": [1, 1], 
        "mapNormalFactor": 1, 
        "depthTest": true, 
        "colorDiffuse": [0.5, 0.5, 0.5], 
        "vertexColors": false, 
        "blending": "NormalBlending", 
        "mapDiffuseAnisotropy": 4, 
        "shading": "Blinn", 
        "transparent": true, 
        "depthWrite": true, 
        "mapNormalRepeat": [1, 1], 
        "mapNormalWrap": ["repeat", "repeat"], 
        "DbgName": "orange", 
        "mapNormalAnisotropy": 4, 
        "mapNormal": "orange_bump.jpg", 
        "mapDiffuseWrap": ["repeat", "repeat"], 
        "mapDiffuse": "orange.jpg"
    }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment