I have 3 default camera functions with different alpha value each with function name handleRight(), handleLeft(), handleCenter(). All 3 functions have different default camera with different alpha values.
I have one button with onclick event called “handleCount()”. handleCount function calls functions based on count value.
If count value is 0 then call handleCenter();
If count value is 1 then call handleLeft(); handleRight();
If count value is 2 then call handleCenter(); handleLeft(); handleRight();
But im not able to call 3 functions on click of button one after another.
What im trying to achive is : Onclick of button show 3 different view of mesh. if count value is 0 then show one angle view, if count value is 1 then show two views on click, if count value is 2 then show left right and center view of mesh.
I just want to preface this with the fact that I don’t know too much about React. Anyway, from what I’m seeing, I suspect that the handleLeft/Right/Center functions don’t have the context for the scene, so those functions are unable to get the camera and do anything with it. This might be related to how you’re assigning the instantiating your engine. In that code sandbox, I saw the following error (ModelComponent.js, line 67):
Assignments to the 'engine' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect.
It looks like as soon as your useEffect resolves, the engine reference will be lost.
Additionally, inside of your handle functions, you shouldn’t use createDefaultCameraOrLight more than once because it doesn’t do anything if you’ve already created a default light or camera. If you’ve already created a camera, you can just pull the reference scene.activeCamera or manually create a new camera (if you need one though I wouldn’t recommend it for what you want to do). From there you could just change the alpha/beta values: