Here is the link of the amazing water reflection project: link
I made a tiny patch to fix the bugs caused by multi-scene like this :
// Fix problems caused by skybox layers (when there are more than 1 scene exist)
var WaterPatch = pc.createScript('waterPatch');
WaterPatch.prototype.initialize = function() {
var comp = this.app.scene.layers;
var reflectionLayer = comp.getLayerByName("WaterReflection");
var self = this;
this.app.scene.on("set:skybox", function() {
reflectionLayer.addMeshInstances(self.app.scene.skyboxModel.meshInstances);
});
};
// Called when switching scenes
WaterPatch.prototype.removeSkyReflection = function () {
var comp = this.app.scene.layers;
var reflectionLayer = comp.getLayerByName("WaterReflection");
reflectionLayer.removeMeshInstances(this.app.scene.skyboxModel.meshInstances);
console.log("remove complete");
};
Add this patch script on ‘Root’ entity in each scene, and comment off the conflict code in the original ‘Water’ script to use it. Ensure this patch is loaded after ‘water.js’.
Hey, @kprimo, thank you for looking into this. I would like to understand the root of the error, so I can make a proper fix. However, I would need a simple project, where I could reproduce the problem you are describing. Do you think you could make a blank project that gives this error?
water.js (at line 360), comment on the conflict code.
// // Must comment this off when patching
// this.app.scene.on("set:skybox", function() {
// reflectionLayer.addMeshInstances(self.app.scene.skyboxModel.meshInstances);
// });
// Ask for depth
changelevel.js (at line 17), call ‘removeSkyReflection’ function
// Fix WaterReflection Layer Problem
var WaterPatch = this.app.root.findByName('Root').script.waterPatch;
if (WaterPatch){
WaterPatch.removeSkyReflection();
}