ThreeJS - JSONLoader "Unable to read ownership formula" undefined

I am trying to export a texture object from Blender. The exported JSON looks like this:

{ "metadata" : { "formatVersion" : 3.1, "generatedBy" : "Blender 2.66 Exporter", "vertices" : 8, "faces" : 6, "normals" : 8, "colors" : 0, "uvs" : [], "materials" : 1, "morphTargets" : 0, "bones" : 0 }, "scale" : 1.000000, "materials" : [ { "DbgColor" : 15658734, "DbgIndex" : 0, "DbgName" : "Material", "blending" : "NormalBlending", "colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865], "colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865], "colorSpecular" : [0.0, 0.0, 0.0], "depthTest" : true, "depthWrite" : true, "mapDiffuse" : "unicorn.jpg", "mapDiffuseWrap" : ["repeat", "repeat"], "shading" : "Lambert", "specularCoef" : 50, "transparency" : 1.0, "transparent" : false, "vertexColors" : false }], "vertices" : [1,-1,-1,1,-1,1,-1,-1,1,-0.999999,-1,-1,1,1,-0.999999,0.999999,1,1,-1,1,0.999999,-1,1,-1], "morphTargets" : [], "normals" : [0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,-0.577349,0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,0.577349,0.577349,0.577349], "colors" : [], "uvs" : [], "faces" : [35,0,1,2,3,0,0,1,2,3,35,4,7,6,5,0,4,5,6,7,35,0,4,5,1,0,0,4,7,1,35,1,5,6,2,0,1,7,6,2,35,2,6,7,3,0,2,6,5,3,35,4,0,3,7,0,4,0,3,5], "bones" : [], "skinIndices" : [], "skinWeights" : [], "animation" : {} } 

My Json bootloader:

  var object; var loader = new THREE.JSONLoader(); loader.load( "models/texturecube.js", function(geometry, materials) { var material = new THREE.MeshFaceMaterial(materials); object = new THREE.Mesh(geometry, materials); // throws object.scale.set(1, 1, 1); scene.add(object) }); 

The loader throws an exception "Unable to read property" uniform "undefined". I see that others must modify the exported JSON to make it work correctly. Does anyone have an idea of ​​what the uniform property is for? Should I define this in my JSON?

Thanks!

+4
source share
2 answers

Your material variable is not used. Do it:

 object = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); 

In addition, your geometry will have UV areas if you want to apply texture.


EDIT: A new template has appeared. If you have an array of materials, you can pass the array of materials directly to the Mesh constructor as follows:

 object = new THREE.Mesh( geometry, materials ); 

three.js r.87

+6
source

You only pass one material to your object in a line:

 var material = new THREE.MeshFaceMaterial(materials[0]); 

Instead, you need to pass a complete array of such materials:

 var material = new THREE.MeshFaceMaterial(materials); 

In fact, the cause of the error is that when your model tries to access any material other than the first, it throws an undefined error because the material does not exist, because you did not pass it to the object constructor.

0
source

Source: https://habr.com/ru/post/1489008/


All Articles