Voxels are a relatively new feature, which is one reason for why I may not know all the details here. But I’ll try…
Right now, your voxelPrimitive
defines the modelMatrix
, which is supposed to move the primitive to a certain position on the globe. This does seem to work in general (although I’m not sure whether the orientation of the primitive is correct here). But there is another matrix that might be better suited for this, namely the VoxelProvider#globalTransform
.
The difference appears to be, roughly speaking, that the voxelPrimitive.modelMatrix
is more “local”. This is what you can edit with the ‘Voxel Inspector’. When you open the ‘Voxel Inspector’ in your sandcastle, then it shows values like “Translation X = -1214991,7329005932”, which basically is “the global placement on earth” (and these values can not be edited sensibly).
When defining the voxelProvider.globalTransform
instead, this will place the primitive at the respective position on earth, and you can still use the ‘Voxel Inspector’ to change the “Translation X”. (It is 0 initally, and you can move the primitive along -10 … +10).
(Maybe someone else can give a profound recommendation of whether to use the modelMatrix
or the globalTransform
…?)
About the voxels disappearing when moving the camera:
This is not directly related to the bounding sphere. The bounding sphere is correct, which can be seen by flyToBoundingSphere
ending up with the voxels centered accordingly. But when you use flyToBoundingSphere
and afterwards drag the camera to rotate it, then it will basically rotate around the point on the surface of the earth that you clicked. And given that the voxel object is 25km above earth, it wildly rotates … out of sight.
One way of solving this could be to set the camera reference frame, using camera.lookAtTransform
. There still are some degrees of freedom, related to the final orientation of the camera and its behavior when dragging the view. But the following sandcastle applies the two suggested changes:
- It uses the
globalTransform
(not entirely sure what to prefer here) - It uses
camera.lookAtTransform
instead offlyToBoundingSphere
This centers the voxel primitive, allows you to modify it with the ‘Voxel Inspector’, and the camera rotates around the reference frame that is defined by the voxel bounding sphere. Maybe this can serve as a basis for further adjustments that you may need for your application case.