I have this game that corrupted recently so I’m working on re doing the corrupted mode but it still has an old issue which is it lags like crazy so here I am.
For those that don’t know what I’m referring to here. Basically it makes far away things render in less detail.
You are referring a Level of Details System. I am also looking for/trying to create something like this lol
[SOLVED] Level of Details System - Help & Support - PlayCanvas Discussion
Hey @dkthegreat I read your thread and it works but enabling causes the game to lag a lot is there any way to reduce lag?
if you use entity.enabled or rendercomponent.enabled, try using meshInstance.visible
https://developer.playcanvas.com/api/pc.MeshInstance.html#visible
that is often faster, depending on what you do.
Can You Give An Example On How To Use meshInstance.visible I’ve Been Reading Documentation For 3 Hours Now And Have Made It No Where
Hey @mvaligursky I have an update. I’ve got it working but this project was made when renders were first added so it contains a little of both. it works just fine for renders but not legacy models. Is there a way to make this work with legacy models?
I’ve come up with a work around. Since in my case the legacy models were just the small details I just made them constant while the main level geometry only appears while close.
My system involves a lot of for loops.
Here It Is For Anyone Interested
var Lod = pc.createScript('lod');
Lod.attributes.add("Player", {type: 'entity'});
Lod.prototype.initialize = function() {
};
Lod.prototype.update = function(dt) {
for (let i = 0; i < this.entity.children.length; i++) {
var Pos = this.entity.children[i].getPosition();
var Dis = this.Player.getPosition().distance(Pos);
var Dist = localStorage.getItem("LOD");
if (Dist == null) {
Dist = 200;
}
if (Dis > Dist) {
for (let ii = 0; ii < this.entity.children[i].children.length ; ii++) {
if (this.entity.children[i].children[ii].children.length > 0) {
for (let iii = 0; iii < this.entity.children[i].children[ii].children.length; iii++) {
if (this.entity.children[i].children[ii].children[iii].render != null) {
this.entity.children[i].children[ii].children[iii].render.meshInstances[0].visible = false;
}else{
//this.entity.children[i].children[ii].children[iii].model.meshInstances[0].visible = false;
}
}
}else{
if (this.entity.children[i].children[ii].render != null) {
this.entity.children[i].children[ii].render.meshInstances[0].visible = false;
}else{
// this.entity.children[i].children[ii].model.meshInstances[0].visible = false;
}
}
}
}else{
for (let ii = 0; ii < this.entity.children[i].children.length ; ii++) {
if (this.entity.children[i].children[ii].children.length > 0) {
for (let iiii = 0; iiii < this.entity.children[i].children[ii].children.length; iiii++) {
if (this.entity.children[i].children[ii].children[iiii].render != null) {
this.entity.children[i].children[ii].children[iiii].render.meshInstances[0].visible = true;
}else{
// this.entity.children[i].children[ii].children[iiii].model.meshInstances[0].visible = true;
}
}
}else{
if (this.entity.children[i].children[ii].render != null) {
this.entity.children[i].children[ii].render.meshInstances[0].visible = true;
}else{
// this.entity.children[i].children[ii].model.meshInstances[0].visible = true;
}
}
}
}
}
};