简体   繁体   中英

ThreeJS Limit TransformControl movement in Autodesk Forge Viewer

I have a TransformControl from ThreeJS attached to a custom mesh in a Forge Viewer Scene. I use the position of the custom mesh to modify to size of a custom cube. I would like to stop the movement of the TransformControl if the movement of the Control causes the size of the cube to shrink below the minimum size.

The flow is:

1 - User drags the Control

2 - Get the position of the attached mesh and determine the amount of size change.

3 - If the amount causes the size to go below minimum, set the size to minimum, set position of the Control and Attached mesh to the position the would cause the size to be minimum, and the Control cannot be dragged further. The user can keep holding the Control, and if the user drag the Control to the position that would not cause the size to be minimum, then the Control can move again and the size changes.

Unfortunately, in the version of three.js used by Forge Viewer (R71), the TransformControls class doesn't seem to provide any way to hook into the translation updates: https://github.com/mrdoob/three.js/blob/r71/examples/js/controls/TransformControls.js#L812-L853 . If you wanted to control the logic based on some custom condition, you'd probably have to hack it in some way, for example, by overriding the onPointerMove method, leaving it early if the length of the offset vector is below certain threshold.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM