During the total debugging-route within this topic, I did actually try something in regards to accessing those external nodes - as seen below:
var LoadGltfExternal = pc.createScript('loadGltfExternal');
LoadGltfExternal.attributes.add('baseUrl', {type: 'string'});
LoadGltfExternal.attributes.add('gltfFilename', {type: 'string'});
// initialize code called once per entity
LoadGltfExternal.prototype.initialize = function() {
var app = this.app;
var self = this; self.fr =0;
app.assets.loadFromUrl(self.baseUrl + self.gltfFilename, 'json', function (err, asset) {
var gltf = JSON.parse(asset.resource);
loadGltf(gltf, app.graphicsDevice, function (err, res) {
// Wrap the model as an asset and add to the asset registry
var asset = new pc.Asset('gltf', 'model', {
url: ''
});
asset.resource = res.model;
asset.loaded = true;
app.assets.add(asset);
// Add the loaded scene to the hierarchy
self.entity.addComponent('model', {
asset: asset
});
}, {
basePath: self.baseUrl
});
});
};
// update code called every frame
LoadGltfExternal.prototype.update = function(dt) {
var app = this.app;
var self = this;
self.fr++;
if(self.fr>100 && self.fr<110){
var testMat = self.app.root.findByName('TestMat'); console.log('TestMat @ ModelLoad : ',testMat.name);
var meshInstance = self.app.root.findByName('ModelLoad');
try{ console.log('meshInstance child Bn: '+ meshInstance.children[0].children[0].node); }catch(err){}
try{ console.log('meshInstance grandchild Sp: '+ meshInstance.children[0].children[0].children[0].material); }catch(err){}
try{ console.log('1: '+ meshInstance.meshes[0].name);}catch(err){}
try{ console.log('2: '+ meshInstance.children[0].meshes[0].material);}catch(err){}
try{ console.log('3: '+ meshInstance.children[0].children[0].meshes[0].name);}catch(err){}
try{ console.log('4: '+ meshInstance.children[0].children[0].meshes[1].name);}catch(err){}
try{ console.log('5: '+ meshInstance.children[0].meshes[0].name);}catch(err){}
try{ console.log('6: '+ meshInstance.children[0].meshes[1].name);}catch(err){}
try{ console.log('M1: '+ meshInstance.materials[0].name);}catch(err){} try{ console.log('M2: '+ meshInstance.materials[1].name);}catch(err){}
try{ console.log('MLD1: '+ meshInstance.children[0].materials[0].name);}catch(err){} try{ console.log('MLD2: '+ meshInstance.children[0].materials[1].name);}catch(err){}
}
};
(the reason I didn’t write was an answer from you, and then I did not get back to it)
From all the try{}catch(){}'es, the first two worked only - the rest fails [so I would argue that I don’t have access to all the nodes :-/ ]
Between the lines (and cf the blender-scrdmp above), I (we all want) to access the two mesh’es called:
“Ud” and “Ids”, that lies below the blender objects “Bn” and “Sp”.
At ‘post 4’; “Bn” and “Sp” are shown within the output list, yes. “Ud” and “Ids”; not.
Within the PyraMid_SB3.glTF-file one will find/read:
"meshes" : [
{
"name" : "Ud",
"primitives" : [
{
"attributes" : {
"NORMAL" : 2,
"POSITION" : 1
},
"indices" : 0,
"material" : 0
}
]
},
{
"name" : "ids",
"primitives" : [
{
"attributes" : {
"NORMAL" : 5,
"POSITION" : 4
},
"indices" : 3,
"material" : 1
}
]
}
As seen above they both have a material-reference in their ‘childrens’-list/sub-node list.
Is it possible to reach them and their material-reference?
In essence: [Did the API-responsible within the PlayCanvas-organization think of such functionality, and if so; do you have the method? ]
In case they did, it would help me a lot.
My ultimate goal:
- Load an external glTF-file with multiple objects (each having meshes).
- Change the color of each glTF-object at runtime/dynamically (regardless of level … if do-able at object-level, it is fine as well … cf the .glTF-file structure that contains different material-references).
My backup-plan (quite time consuming and an extra list-filling is required at ‘4’):
- Make a blender-project with multiple objects/meshes.
- Export each object/mesh as a glTF-file.
- Load each of these glTF-files separately.
- Change the color of each separate glTF-file at runtime/dynamically.