The docs says that a renderlayer is optional. It says:
This needs to be supplied only if the ‘Immediate’ layer is not present in the scene.
But when I use the default “immediate”-Layer then the cube gets blueish for some reason.
When I define a new Layer called “Outline” then it works. Why to define a new Layer if the documentation says it’s optional?
Kind regards
Alain
var OutlineEffect = pc.createScript('outlineEffect');
OutlineEffect.prototype.initialize = function () {
var app = this.app;
// Kamera abrufen (falls vorhanden), ansonsten eine neue erstellen
this.camera = app.root.findByName("Camera");
if (!this.camera) {
this.camera = new pc.Entity();
this.camera.addComponent("camera", {
clearColor: new pc.Color(0.4, 0.45, 0.5)
});
app.root.addChild(this.camera);
this.camera.setPosition(0, 0, 5);
}
// Existierenden Cube mit Namen "Box" abrufen
this.cube = app.root.findByName("Box");
if (!this.cube) {
console.error("Kein Objekt mit dem Namen 'Box' gefunden!");
return;
}
// Outline Layer erstellen
this.outlineLayer = new pc.Layer({ name: 'Outline' });
app.scene.layers.push(this.outlineLayer);
// OutlineRenderer erstellen und mit Layer verbinden
this.outlineRenderer = new pc.OutlineRenderer(app, this.outlineLayer);
// Outline auf den Cube anwenden (entsprechend dem TypeScript-Code)
this.outlineRenderer.addEntity(this.cube, new pc.Color(1, 1, 1, 1));
console.log("OutlineRenderer erfolgreich initialisiert!");
};
// OutlineRenderer im Update-Zyklus aktualisieren
OutlineEffect.prototype.update = function (dt) {
if (this.outlineRenderer && this.cube) {
const immediateLayer = this.app.scene.layers.getLayerByName('Immediate');
if (immediateLayer) {
this.outlineRenderer.frameUpdate(this.camera, immediateLayer, false);
}
}
};