Is it possible to turn off a 3d model via the screen grab attached? and is there a reference some where for that that I can put in my script?
thanks!
Is it possible to turn off a 3d model via the screen grab attached? and is there a reference some where for that that I can put in my script?
thanks!
Hi @Mattturner2021 ,
Do you want to simply turn off the model? You can do it like this
this.entity.render.enabled = false;
You can reference the entity in a script either by finding the entity like this
let entityRef = this.app.root.findByName("entity");
or by making an script attribute and drag/drop the entity to it
TestScript.attributes.add("entity", { type: "entity", title: "Ref to entity" });
brill will give that a try!
so basically I have two objects one is the child of the other… I would like to turn off the parent but keep on the child on. So if I turn off the parent the child gets turned off too. So I was thinking if I can just switch off the render of the model component that could work… seems to work thank you
this worked very well for me… I’m trying to add a second attribute though and that doesn’t seem to work.
is there anything obviously wrong with this?
var Turnoff = pc.createScript('turnoff');
// initialize code called once per entity
Turnoff.attributes.add("entity", { type: "entity", title: "Ref to entity" });
// second one is added here
Turnoff.attributes.add("test", { type: "entity", title: "Ref to particles" });
Turnoff.prototype.initialize = function() {
// Whether the element is currently hovered or not
this.hovered = false;
// mouse events
this.entity.element.on('mouseenter', this.onEnter, this);
this.entity.element.on('mousedown', this.onPress, this);
this.entity.element.on('mouseup', this.onRelease, this);
this.entity.element.on('mouseleave', this.onLeave, this);
// touch events
this.entity.element.on('touchstart', this.onPress, this);
this.entity.element.on('touchend', this.onRelease, this);
test.this.entity.element.on('mouseup', this.onRelease, this);
};
Turnoff.prototype.onRelease = function (event) {
if (this.entity.element.on) {
this.entity.render.enabled = !this.entity.render.enabled;
}
//second one is added here
if (this.entity.element.on) {
this.entity.render.enabled = !this.entity.render.enabled;
}
};
The issue is that you are doing this.entity
for both the attributes, the second one is named “test”, so it should be this.test.render.enabled
thanks! works great