def SnapPoint(pnt, amt): """ Return a new point based on the indicated point but snapped to the nearest indicated amount. """ return pm.Vec3(ROUND_TO(pnt[0], amt), ROUND_TO(pnt[1], amt), ROUND_TO(pnt[2], amt))
def guiDragTask(self, state): mwn = base.mouseWatcherNode if mwn.hasMouse(): vMouse2render2d = Point3(mwn.getMouse()[0], 0, mwn.getMouse()[1]) newPos = vMouse2render2d + state.editVec self.setPos(render2d, newPos) if DirectGuiWidget.snapToGrid: newPos = self.getPos() newPos.set(ROUND_TO(newPos[0], DirectGuiWidget.gridSpacing), ROUND_TO(newPos[1], DirectGuiWidget.gridSpacing), ROUND_TO(newPos[2], DirectGuiWidget.gridSpacing)) self.setPos(newPos) return Task.cont
def _Snap( self, vec ): if vec.length(): snpLen = ROUND_TO( vec.length(), self._snpAmt ) snapVec = vec / vec.length() * snpLen return snapVec else: return pm.Vec3( 0 )