I’m trying to load JSON into THREE.
I have the JSON just hardcoded into the project atm so from what I gather I should be using ObjectLoader
and .parse
, but I’m getting an error
TypeError: Materials[json.type] is not a constructor
My code is
const loader = new ObjectLoader()
loader.parse(json, (theObj) => {
/*...*/
})
and the json is (shortened the faces and vertices arrays for brevity)
{
"metadata" :
{
"formatVersion" : 3,
"generatedBy" : "ParametricParts",
"vertices" : 3426,
"faces" : 3776,
"normals" : 0,
"colors" : 0,
"uvs" : 0,
"materials" : 1,
"morphTargets" : 0
},
"scale" : 1.0,
"materials": [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material",
"colorAmbient" : [0.0, 0.0, 0.0],
"colorDiffuse" : [0.6400000190734865, 0.10179081114814892, 0.126246120426746],
"colorSpecular" : [0.5, 0.5, 0.5],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"vertexColors" : false
}],
"vertices": ["..."],
"morphTargets": [],
"normals": [],
"colors": [],
"uvs": [[]],
"faces": ["..."]
}
So I think the probably is either the JSON is misformed, or that I’m doing something wrong, with the latter when I search about json and Three.js, I get lot of out-of-date results show up so I’m not sure if the ObjectLoader
is what I should be using?
If it’s the former, the JSON is produced by this project, so I’ll raise it with them
but I wanted to double check it’s not my fault first.
Any insights would be appreciated.