Here’s a quick tutorial of how to apply textures to a Collada model in PV3D. I hope this helps someone, It’s handy to know this so you can preload the materials. Otherwise they get loaded in their own time once the model has been initialised – which leaves you with a plain model for x amount of time.
Here’s how to do it:
// Load your material
// (Which I wont explain here)
// Create your material(s) from the loaded file(s) (i.e. BitmapMaterial / MovieMaterial).
var myBitmapMaterial:BitmapMaterial = new BitmapMaterial(myLoadedTexture);
// Add each material to a MaterialsList
var myMaterialsList:MaterialsList = new MaterialsList();
myMaterialsList.addMaterial(myBitmapMaterial, "materialID");
Here is the bit you need to watch out for. Note the second parameter “materialID”. You should replace this with the correct material id in the DAE file.
If you have named the material something obvious in the 3D package you used, you should be able to find the id associated with it by looking at the ‘library_materials’ node in your DAE file.
See example below:
The material name in DAE file I would like to apply the loaded image to is seagull_mat. I know this because I named it this in the 3D package I used. BUT – a big BUT…
You don’t use the ‘name’ attribute to link the material to the model, you use the ‘id’ attribute! So the material I am referring to is ‘ID3’ – the ‘id’ of the ‘seagull_mat’ material.
This has caught me out a few times, and can be a real pain in the bum to find!! You don’t get any errors thrown if you state an incorrect material id, Papervision will just apply a default WireframeMaterial to the model.
So here is the rest of the code:
// Load your material and collada file.
// (Which I wont explain here)
// Create your material(s) from the loaded file(s) (i.e. BitmapMaterial / MovieMaterial).
var myBitmapMaterial:BitmapMaterial = new BitmapMaterial(myLoadedTexture);
// Add each material to a MaterialsList
var myMaterialsList:MaterialsList = new MaterialsList();
myMaterialsList.addMaterial(myBitmapMaterial, "ID3");
var myColladaModel:DAE = new DAE();
myColladaModel.load(myModelXML, myMaterialsList);
scene.addChild(myColladaModel);
QuickTip:
Because we are preloading and applying the materials ourselves, make sure you delete the original material references inside the Collada file to prevent Papervision from trying to initialise from them. (I’ve commented out the code that should be removed in this case: