Hello, I have issue with lightmapper, I’m getting an error when I try to bake with lightmapper using engine only but works fine in editor. The code for the editor and engine is almost same. I have no idea what is causing the issue. The engine version I’m using is 1.68.0
.
This is my code inside editor:
Lightmapper.prototype.initialize = function () {
let omni = []
let walls = []
const property = this.app.root.findByName('missipi');
const lights = property.find('lights')[0]
const renders = property.findComponents('render');
renders.forEach((render) => {
if (render.entity.name.includes('walls')) {
render.castShadows = true;
render.castShadowsLightmap = true;
render.lightmapped = true;
walls.push(render.entity);
}
});
lights.forEach((light) => {
const lightOmni = new pc.Entity('Omni');
lightOmni.addComponent('render', {
type: 'box'
})
lightOmni.setLocalScale(0.1, 0.1, 0.1);
lightOmni.addComponent('light', {
type: 'omni',
affectDynamic: false,
affectLightmapped: true,
bake: true,
castShadows: true,
normalOffsetBias: 0.05,
shadowBias: 0.2,
shadowDistance: 25,
shadowResolution: 512,
shadowType: pc.SHADOW_PCF3,
color: pc.Color.WHITE,
range: 20,
intensity: 0.15
});
this.app.root.addChild(lightOmni);
omni.push(lightOmni);
lightOmni.setPosition(light.getPosition());
lightOmni.setRotation(light.getRotation());
});
this.app.lightmapper.bake(walls, pc.BAKE_COLORDIR);
console.log(this.app.lightmapper.stats.totalRenderTime.toFixed(2));
}
and result:
Engine Only:
App setup:
const app = new pc.Application(canvas, {
graphicsDeviceOptions: {
alpha: true,
antialias: true,
powerPreference: "high-performance",
},
});
app.setCanvasResolution("AUTO");
app.setCanvasFillMode("FILL_WINDOW");
app.start();
Ligntmapping:
private onload = async (asset) => {
const renderEntity = asset.resource.instantiateRenderEntity();
this.setPosition(0, -0.35, 0);
this.app.root.addChild(renderEntity);
this.setupOrbitCamera();
const renders = renderEntity.findComponents('render') as RenderComponent[];
const walls = [];
renders.forEach((render) => {
if (render.entity.name.includes('walls')) {
render.castShadows = true;
render.castShadowsLightmap = true;
render.lightmapped = true;
walls.push(render.entity);
}
});
const roomLights = renderEntity.children.find((entity) => entity.name === lightId);
roomLights?.forEach((roomLight) => {
const position = roomLight.getPosition();
const euler = roomLight.getEulerAngles();
const entity = new Entity(roomLight.name);
entity.addComponent('light', {
type: 'omni',
affectDynamic: false,
affectLightmapped: true,
bake: true,
castShadows: true,
normalOffsetBias: 0.05,
shadowBias: 0.2,
shadowDistance: 25,
shadowResolution: 512,
shadowType:pc.SHADOW_PCF3,
color: pc.Color.WHITE,
range: 20,
intensity: 0.15,
});
this.app.root.addChild(entity);
this._roomLights.push(entity);
entity.setPosition(position);
entity.setEulerAngles(euler);
});
};
this.app.scene.lightmapMode = pc.BAKE_COLORDIR;
this.app.scene.lightmapMaxResolution = 1024;
this.app.scene.lightmapSizeMultiplier = 512;
this.app.lightmapper.bake(walls, pc.BAKE_COLORDIR);
console.log(this.app.lightmapper.stats.totalRenderTime.toFixed(2));
};
I get these errors:
![Screenshot 2024-05-22 at 11.39.36 AM](http://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/9/5/959fa1e38591f38b321d30be38ac3b5823f89a2a.png)
Any idea how to fix this? Thanks