currently I am working on a project using the SpeckleViewer. One of the requirements is that the camera position of the viewer has to be at a certain angle after the viewer has finished initializing. I have already figured out how to rotate and zoom with the camera after initializing but right now I’m kinda stuck at changing the actual position of the camera afterwards.
I have already tried to change the camera position through the cameraHandler but the actual position didnt really change.
This is how I am trying it right now but the set-function doesnt really do much. I’m new to the viewer and have tried to solve it by sticking to Cristis demo here: https://github.com/specklesystems/speckle-server/blob/main/packages/viewer/src/modules/Viewer.js
Hey @christopher.menzel
Welcome to the Speckle community! Feel free to Introduce yourself to everyone if you haven’t already and are willing to share.
If the camera position changes, the scene will need to re-render to have an effect. Depending on the surrounding code you may not be triggering that within the async event.
I’m not sure which demo you are looking at, but it could be as simple as adding viewer.needsRender = true for example.
I have tried your solution and set viewer.needsRender to true after changing the camera position, but i don’t see any changes in viewer after that.
Is it the right way to set the camera positions with viewer.cameraHandler.camera.position.set() or should I use a another method to set the camera position?
Hey, sorry for the late reply - we’re on a company retreat! There is actually a method that should take care of all this for you - it’s not very nicely exposed yet as we still need to cleanup these parts.
viewer.interactions.setLookAt() works fine and I was able to set the camera position, but now I have one other problem.
Currently I zoom with viewer.cameraHandler.controls.zoom(), but this is not so optimal and I want to replace it with viewer.cameraHandler.controls.dollyTo().
If dollyTo() is called I can see that the viewer.cameraHandler.controls.distance changes, but it takes no effect in the viewer.
Hm, this is a bit strange. I’ve just tried this in a local viewer, and it works!
__viewer.cameraHandler.controls.dollyTo(10, true)
You can run the above in the console on any speckle page with the viewer and a loaded model and it zooms in as expected. Maybe share your code so we can have a deeper look if the problem persists?
where target should be your threejs object! This might be tricky, depending on wether you get your object from an actual interaction event or not.
You could write a zoomToObjectId function, which would go through the scene and find the specific object for you. I can give it a shot if this is what you’re looking for.
You could write a zoomToObjectId function, which would go through the scene and find the specific object for you. I can give it a shot if this is what you’re looking for.
I would appreciate it very much, it seems to be exactly what I need.
Sorry for the late reply, took me some time to get back to this! I’ve quickly hacked something in the viewer:
// InteractionsHandler.js
zoomToObjectId( id ) {
let obj = this.viewer.sceneManager.allObjects.find( o => o.uuid === id )
if( obj ) this.zoomToObject( obj )
else console.warn( `No object with id of ${id} found.` )
}
This seems to work! I’ll try and publish a new release with this quick feature addition, and will update the thread here.