1

Possible Duplicate:
Three.js not possible to load textures

I am a beignner as far as ThreeJs and blender is concerned so this may seem a silly question. I am trying to load a model using JSONLoader. I used the threejs blender export and exported the collada model to js. However I am unable to get the material directly from the file.

Upon checking I found that the attribute to the image file is missing in the js file i.e "mapDiffuse" attribute is absent. Is that an error. If so any suggestions? Or is there some other way of loading the materials?

P.S This was a collada model i downloaded, so texture images were provided with it, though blendor export did not notice it.

A part of my model js file

{

"metadata" :
{
    "formatVersion" : 3.1,
    "generatedBy"   : "Blender 2.64 Exporter",
    "vertices"      : 1172,
    "faces"         : 2209,
    "normals"       : 736,
    "colors"        : 0,
    "uvs"           : [1722],
    "materials"     : 1,
    "morphTargets"  : 0,
    "bones"         : 0
},

"scale" : 1.000000,

"materials" : [ {
    "DbgColor" : 15658734,
    "DbgIndex" : 0,
    "DbgName" : "material_2_81_0",
    "blending" : "NormalBlending",
    "colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
    "colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
    "colorSpecular" : [0.5, 0.5, 0.5],
    "depthTest" : true,
    "depthWrite" : true,
    "shading" : "Lambert",
    "specularCoef" : 50,
    "transparency" : 1.0,
    "transparent" : false,
    "vertexColors" : false
},
.
.
.
.
.

"vertices" : [1159.45,531.608,-1808.68,......]
"morphTargets" : [],
"normals" : [-0.101077,0,-0.994873,......]
"colors" : [],
"uvs" : [[0,0,1,0,0,1,....]
"faces" : [42,0,1,2,0,0,1,2,0,1,2,42,0...]

"bones" : [],

"skinIndices" : [],

"skinWeights" : [],

"animation" : {}
}

Thank You

Community
  • 1
  • 1
arunondeck
  • 368
  • 6
  • 16

1 Answers1

1

I will point you toward this question that I answered not long ago, which is almost an exact duplicate. I am not sure whether it is possible to get your material loaded using only the file. The only way I have had luck is loading the textures manually from in my code and then applying them. Just use the exporter to export your geometry and UV mapping and don't worry about exporting the textures. Simply gather them up and if you are running this locally make sure you are using a server, otherwise you won't be able to load the images from the disk. At this point it is very simple code to load up your model and apply your texture. For future reference you should post up your code that you use to load your model as well. You need to utilize the arguments of the given functions to pass in callbacks so that you do not try to render anything before it is completely loaded.

var tex, mat, mesh;

$(window).load(function () {
    /** Load mesh from JSON, position, scale, add texture and add to scene */
    tex = THREE.ImageUtils.loadTexture('../img/texture.jpg', null, function () {
            mat = new THREE.MeshPhongMaterial({ map: tex });
            loader.load('model.js', function (geo) {
                mesh = new THREE.Mesh(geo, mat);
                mesh.position.set(0, 0, 0);
                mesh.scale.set(20, 20, 20);
                // etc, etc
                scene.add(mesh);
            });
        });
});
Community
  • 1
  • 1
Cory Gross
  • 36,833
  • 17
  • 68
  • 80
  • Hi, I have multiple images for the said model, So I am not sure how to do that without having the 'mapDiffuse' attribute in the js file. Also how do you bring texture into a model that has no images? But, the texture that is there in the model? http://threetest.ap01.aws.af.cm/ contains the code i'm doing. – arunondeck Oct 26 '12 at 08:37