xeokit-sdk icon indicating copy to clipboard operation
xeokit-sdk copied to clipboard

Add pivot sphere

Open Kurtil opened this issue 3 years ago • 7 comments

Add a pivot sphere that resizes according to the distance between the camera and the pivot position. It is possible to enabled or disabled it (default) and change its size and material.

pivotSphere

Kurtil avatar Jan 12 '21 15:01 Kurtil

Don't merge it now.

The sphere geometry breaks with xkt v6 models.

Is there a way to create the sphere in performance mode to allow big coordinates?

Amoki avatar Jan 15 '21 14:01 Amoki

I read the section plane plugin's code and I didn't see anything special. Do you have an idea about why the sphere created like that doesn't render properly with xktv6? @xeolabs

Amoki avatar Jan 18 '21 13:01 Amoki

@Amoki to position the sphere using double-precision World-space coordinates, you need to split the coordinates into an 32-bit RTC center and a 32-bit offset - see how the SectionPlanePlugin edition control does this the link below.

The idea is that, given a dynamically-changing double-precision 3D world position, we can use worldtoRTCPos to split that into an RTC center and an offset from that center. The Mesh#rtcCenter is dynamically set to the center, and Mesh#position is dynamically set to the offset.

https://github.com/xeokit/xeokit-sdk/blob/master/src/plugins/SectionPlanesPlugin/Control.js#L96

xeolabs avatar Jan 18 '21 13:01 xeolabs

Should be good now!

Amoki avatar Jan 18 '21 15:01 Amoki

I might be misreading, but will this be destroying/creating the sphere mesh as the pivot pos updates?

https://github.com/xeokit/xeokit-sdk/blob/24cf44535f2bd59587a69a594ab6b79bf64f7bbd/src/viewer/scene/CameraControl/lib/controllers/PivotController.js#L128

I think you could just dynamically update Mesh#rtcCenter and Mesh#position here, reusing the same Mesh instance.

xeolabs avatar Jan 18 '21 16:01 xeolabs

The size of the sphere depends on the distance of the pivot point so we can't keep the geometry. I just fixed a bug where the geometry was constantly recreated even if the pivot point was not.

Amoki avatar Jan 18 '21 17:01 Amoki

We don't need a very precise sphere, but we can't reduce the resolution: https://github.com/xeokit/xeokit-sdk/blob/b01f6ddef6e33171dc247a7cced3f001570d2c75/src/viewer/scene/geometry/builders/buildSphereGeometry.js#L72

Is there a reason for these limits?

Amoki avatar Jan 18 '21 17:01 Amoki

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

ghost avatar Sep 21 '23 14:09 ghost

We've been using it for 3 years, it's stable.

https://github.com/xeokit/xeokit-sdk/assets/1349751/e08463ec-c2bd-417e-a801-c65905645028

If you don't want this feature, you can close this PR

Amoki avatar Sep 21 '23 14:09 Amoki