Game Development Reference
In-Depth Information
Converting Box.obj to Box.json
To import the
Box.obj
file with JavaScript in our code, we need to convert it to the
JSON format as shown in the following command-line code:
python ./convert_obj_three.py -i ./Box.obj -o ./Box.json
Understanding the JSON file with UV
coordinates
Let's understand our JSON file format with texture coordinates. Open
Box.json
in
your favorite text editor. The content of the file is as follows:
{
"metadata" :
{
"formatVersion" : 3.1,
"sourceFile" : "Box_Blender.obj",
"generatedBy" : "OBJConverter",
"vertices" : 8,
"faces" : 12,
"normals" : 6,
"colors" : 0,
"uvs" : 14,
"materials" : 1
},
"scale" : 1.000000,
"materials": [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" :"initialShadingGroup.004",
"colorAmbient" : [1.0, 1.0, 1.0],
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorSpecular" : [0.5, 0.5, 0.5],
"illumination" : 2,
"mapDiffuse" : "boxDiffuse.jpg",
"opticalDensity" : 1.0,
"specularCoef" : 96.078431,
"transparency" : 0.0
}],
"vertices": [...],
"morphTargets": [],
"morphColors": [],
"normals": [0,-0,1,0,1,0,0,0,-1,0,-1,-0,1,0,0,-1,-0,-0],
"colors": [],
"uvs": [[0.375,0,0.625,0,0.625,0.25,0.375,0.25,0.625,0.5,0.375,0.5,
0.375,0.75,0.625,1,0.375,1,0.625,0.75,0.875,0,0.875,0.25,0.125,0,0.12
5,0.25]],