My project takes a list of models located on my local server and loads them into the scene with a nametag hovering above them. I’m trying to implement the text script from https://playcanvas.com/project/362231/overview/tutorial-canvas-text for the nametags and it’s working well except that as my models load in and create their script, all previously loaded nametags update to the new text.
I’m just using the exact text.js script from the example for now until I can wrap my head around what’s happening.
The script to load the models is
function init_geometry(app){
var _geometry;
_geometry = new pc.Entity();
_geometry.name = "geometry";
for(var i in wayf.list){
app.assets.loadFromUrl("./Wayf/"+i+".json", "model", function(err, cbt){
if(cbt != undefined){
var id = cbt.name.substring(0,cbt.name.length - 5);
//Model
var modelE = new pc.Entity();
modelE.addComponent('model', {asset: cbt});
modelE.name = id;
//Label
var modelLabel = new pc.Entity();
modelE.addChild(modelLabel);
modelLabel.addComponent("model", {type:"plane"});
modelLabel.addComponent("script");
modelLabel.script.create("text", {attributes:{text:modelE.name}});
_geometry.addChild(modelE);
}
});
}
app.root.addChild(_geometry);
return _geometry;
}
Once it’s loaded it looks like
But each should be a different Id number.
As more models load in I can see the nametags change to the newest so I know it’s partially working.
I’m integrating the playcanvas engine into an existing project so I don’t have a project I can link to, sorry.