Hi there,
I’m trying to figure out what’s the best way to structure my code.
At the moment I’d like to define a number of functions before the main createScene() function.
This to keep the code organised and structured, so I can declare all my functions on top of the code, and then call them in the createScene() among others.
This will also allow me to easily turn on and off a number of features in the code, which in my opinion helps to debug more easily.
Any advice on this is more than welcome.
However at the moment I’m having some issues with this kind of layout, because I’m getting errors when some objects or items aren’t declared yet, which could be caused by the way the code is structured.
In the createScene() I’m calling on this func:
CamAutoRotate(scene, "active", true, 4000, 500, 0.8) // (scene, input, io, spinupTime, waitTime, rotSpeed)
This returns the following error:
Below is the code which causes that error.
Also when I try to log my camera’s which is commented out here, I get undefined.
Is this because the camera’s aren’t fully created yet?
// >>> FilterCameras FromList
var CamFilter = function (scene, input) {
var camLst = [];
var camAll = scene.cameras;
// console.log(camAll);
if (input == "all") {
var camLst = camAll;
} else if (input == "active") {
var camLst = [scene.activeCamera];
} else {
for (var c of camAll) {
if (c.name == input) {
camLst = [c];
}
}
}
return camLst
}
// CamFilter(scene, "active") // (scene, input) // (scene, ["all", "active", "CameraName"])
How can I keep working like this while preventing these kind of errors?
Thanks a lot!
Pieter