mrdoob/three.js — Issue #1201: Scene loader does not read multi-materials
Author: powerslave
Created: 2012-01-27 20:58:32+00:00
State: open

I tested this back and forth several times, now I'm pretty sure there's something wrong in the scene loader regarding multi-materials.

the files below are exported directly from blender (exporter 2.60)

** scene file multiMaterialCube.js **
* added a second light to clearly see colors on faces, otherwise no changes to exported file
* object Cube has two materials assigned. looks good.

** geometry file multiMaterialCube.Cube.js **
* no changes to exported file
* two materials are listed. looks good.

Loading the scene using example
webgl_scene_test_blender.html
the cube only has one color. (all faces are colored red)

by changing the order of the materials in the objects material list,

from "materials" : [ "Material.red", "Material.green" ],
to "materials" : [ "Material.green", "Material.red" ],

all faces are colored green.

Note: The top-left list [+] lists both materials

It looks like the scene loader simply ignores all materials in the objects material list, and assign the last material to all faces.

(tested with r46 and r47, same results)

multiMaterialCube.js

```javascript
{

"metadata" :
{
"formatVersion" : 3,
"sourceFile" : "",
"generatedBy" : "Blender 2.60 Exporter",
"objects" : 1,
"geometries" : 1,
"materials" : 2,
"textures" : 0
},

"type" : "scene",
"urlBaseType" : "relativeToScene",

"objects" :
{
"Cube" : {
"geometry" : "geo_Cube",
"groups" : [ ],
"materials" : [ "Material.red", "Material.green" ],
"position" : [ 0.000000, 0.000000, 0.000000 ],
"rotation" : [ 0.000000, -0.000000, 0.000000 ],
"quaternion": [ 1.000000, 0.000000, 0.000000, 0.000000 ],
"scale" : [ 1.000000, 1.000000, 1.000000 ],
"visible" : true,
"castsShadow" : false,
"meshCollider" : false,
"trigger" : "None"
}
},

"geometries" :
{
"geo_Cube" : {
"type" : "ascii_mesh",
"url" : "multiMaterialCube.Cube.js"
}
},

"materials" :
{
"Material.green" : {
"type": "MeshLambertMaterial",
"parameters": { "color": 1680128, "opacity": 1 }
},

"Material.red" : {
"type": "MeshLambertMaterial",
"parameters": { "color": 10682379, "opacity": 1 }
}
},

"cameras" :
{
"Camera" : {
"type" : "perspective",
"fov" : 49.159264,
"aspect": 1.333000,
"near" : 0.100000,
"far" : 100.000000,
"position": [ 8.975078, -9.568626, 7.248149 ],
"target" : [ 0.000000, 0.000000, 0.000000 ]
}
},

"lights" :
{
"default_light": {
"type"	: "directional",
"direction"	: [ 0.000000, 1.000000, 1.000000 ],
"color"	: 16777215,
"intensity"	: 0.80
},
"default_light2": {
"type"	: "directional",
"direction"	: [ 0.000000, -1.000000, -1.000000 ],
"color"	: 16777215,
"intensity"	: 0.80
}

},

"transform" :
{
"position" : [ 0.000000, 0.000000, 0.000000 ],
"rotation" : [ -1.570796, 0.000000, 0.000000 ],
"scale" : [ 1.000000, 1.000000, 1.000000 ]
},

"defaults" :
{
"bgcolor" : [ 0.000000, 0.000000, 0.000000 ],
"bgalpha" : 1.000000,
"camera" : "Camera"
}

}
```

multiMaterialCube.Cube.js

```javascript
{

"metadata" :
{
"formatVersion" : 3,
"generatedBy" : "Blender 2.60 Exporter",
"vertices" : 8,
"faces" : 6,
"normals" : 8,
"colors" : 0,
"uvs" : 0,
"materials" : 2,
"morphTargets" : 0
},

"scale" : 1.000000,

"materials": [	{
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material.green",
"colorAmbient" : [0.0, 0.0, 0.0],
"colorDiffuse" : [0.10073555858039196, 0.6400000190734865, 0.0],
"colorSpecular" : [0.5, 0.5, 0.5],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"vertexColors" : false
},

{
"DbgColor" : 15597568,
"DbgIndex" : 1,
"DbgName" : "Material.red",
"colorAmbient" : [0.0, 0.0, 0.0],
"colorDiffuse" : [0.6400000190734865, 0.0, 0.04691955815135773],
"colorSpecular" : [0.5, 0.5, 0.5],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"vertexColors" : false
}],

"vertices": [1.000000,1.000000,-1.000000,1.000000,-1.000000,-1.000000,-1.000000,-1.000000,-1.000000,-1.000000,1.000000,-1.000000,1.000000,0.999999,1.000000,0.999999,-1.000001,1.000000,-1.000000,-1.000000,1.000000,-1.000000,1.000000,1.000000],

"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,1,4,5,6,7,35,0,4,5,1,1,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]

}

PS: is there an easy way to add images to posts here?