Setting camera position

I’ve seen the docs at GitHub - shapespark/shapespark-viewer-api: JavaScript API for interacting with the Shapespark 3D scene., but the API doesn’t appear to have the functionality described to set the camera position.

WALK.View appears to be a function for me and it returns undefined. There is no WALK.View.position or WALK.View.rotation properties either.

Are the docs out of date? How do I know what version I’m using? My downloaded bundle has a VERSION file as 592 if that helps. Has the API changed?

Hi

Please take a look at the example file to see how to create a new View and assign position and rotation:

1 Like

Thanks… the docs weren’t clear that I had to instantiate a new object. I thought it was already supposed to be present and I could manipulate it directly. Good now.

Is there a way to determine if the viewer is in a TOP, ORBIT or WALK view? And is there a way to manually set the view type?

edit: I see the Viewer.onViewSwitchDone callback returns view objects and I see a mode field on the View object with orbit or fps values. I also see isTop and isOrbit functions. Should I be setting the mode for my custom view for proper navigation between views? Any other properties to track? I assume to mimic a TOP view, I need to manually remove any roof object?

edit 2: I now see that the objects that are to be hidden in named views is configured for each named view. It’d be nice to get a View object by name and then just make some camera adjustments, but looking at the API, is this possible? I don’t see anything so far.

Hi

You are correct, there is no direct way to get current view parameters, however you can store current view returned from ‘onViewSwitchDone’ and store it in a mutable variable.

Please take a look at this post:

You could infer the view parameters from the last view used.
To set view to ORBIT or WALK you would need to set view.mode to either orbit or fps
TOP view is special mode of ‘orbit’ view with parameters:

  • view.noPitchRotate set to true
  • view.rotation[1] set to -90;

There might be some other adjustments you need to consider, like minDistance, and maxDistance, depending on your specific needs.

1 Like