I am trying to create a script to insert entities at runtime to a specific model. When I tried parsing it it gave me a script error. I deleted things one by one to find out the source of the error. Here is my script.
var InsertEntityIntoPicture = pc.createScript('insertEntityIntoPicture');
var mainModel = this;
var entity = new pc.Entity();
InsertEntityIntoPicture.attributes.add('Rhino_model',{type:'entity',title:'rhinoModel'});
entity.addComponent("model",{type:'box'});
// this.app.root.addChild(entity);
// initialize code called once per entity
InsertEntityIntoPicture.prototype.initialize = function() {
// this.app.root.addChild(entity);
this.app.mouse.disableContextMenu();
this.app.keyboard.on(pc.EVENT_KEYDOWN,this.onKeyboardPress,this);
};
InsertEntityIntoPicture.prototype.onKeyboardPress = function(event){
};
I found out that the error is due to the line
entity.addComponent(“model”,{type:‘box’});
Is this the correct way?? Or is there some other way to do it??
That was an alternate solution I was thinking. I was just wondering if putting all the models in the scene from start might increase the time taken to load.
Thanks. I was able to do that.
But there is still an error that I am facing. I have a model which has sub models. When I try to apply the script to the whole model as whole, the model does not hide but when I apply the same script to a single element inside the model, the particular element hides.