mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Added support for grid snapping
This commit is contained in:
parent
cd6ec4c28c
commit
d1d8685fe5
@ -53,6 +53,9 @@ class DirectManipulationControl(DirectObject):
|
|||||||
# [gjeon] for new LE's multi-view support
|
# [gjeon] for new LE's multi-view support
|
||||||
self.fMultiView = 0
|
self.fMultiView = 0
|
||||||
|
|
||||||
|
# [gjeon] to support grid snapping
|
||||||
|
self.fGridSnap = 0
|
||||||
|
|
||||||
def scaleWidget(self, factor):
|
def scaleWidget(self, factor):
|
||||||
if hasattr(base.direct, 'widget'):
|
if hasattr(base.direct, 'widget'):
|
||||||
base.direct.widget.multiplyScalingFactorBy(factor)
|
base.direct.widget.multiplyScalingFactorBy(factor)
|
||||||
@ -270,8 +273,6 @@ class DirectManipulationControl(DirectObject):
|
|||||||
boundingSphereTest = marqueeFrustum.contains(bbc)
|
boundingSphereTest = marqueeFrustum.contains(bbc)
|
||||||
if boundingSphereTest > 1:
|
if boundingSphereTest > 1:
|
||||||
if boundingSphereTest == 7:
|
if boundingSphereTest == 7:
|
||||||
print "boundingSphere is all in, selecting ", geom
|
|
||||||
|
|
||||||
if nodePath not in selectionList:
|
if nodePath not in selectionList:
|
||||||
selectionList.append(nodePath)
|
selectionList.append(nodePath)
|
||||||
else:
|
else:
|
||||||
@ -551,6 +552,39 @@ class DirectManipulationControl(DirectObject):
|
|||||||
def removeTag(self, tag):
|
def removeTag(self, tag):
|
||||||
self.unmovableTagList.remove(tag)
|
self.unmovableTagList.remove(tag)
|
||||||
|
|
||||||
|
def gridSnapping(self, offset):
|
||||||
|
offsetX = offset.getX()
|
||||||
|
offsetY = offset.getY()
|
||||||
|
offsetZ = offset.getZ()
|
||||||
|
if math.fabs(offsetX) < base.direct.grid.gridSpacing / 2.0:
|
||||||
|
offsetX = 0
|
||||||
|
else:
|
||||||
|
if offsetX < 0:
|
||||||
|
offsetX = -1 * base.direct.grid.gridSpacing
|
||||||
|
else:
|
||||||
|
offsetX = base.direct.grid.gridSpacing
|
||||||
|
|
||||||
|
if math.fabs(offsetY) < base.direct.grid.gridSpacing / 2.0:
|
||||||
|
offsetY = 0
|
||||||
|
else:
|
||||||
|
if offsetY < 0:
|
||||||
|
offsetY = -1 * base.direct.grid.gridSpacing
|
||||||
|
else:
|
||||||
|
offsetY = base.direct.grid.gridSpacing
|
||||||
|
|
||||||
|
if math.fabs(offsetZ) < base.direct.grid.gridSpacing / 2.0:
|
||||||
|
offsetZ = 0
|
||||||
|
else:
|
||||||
|
if offsetZ < 0:
|
||||||
|
offsetZ = -1 * base.direct.grid.gridSpacing
|
||||||
|
else:
|
||||||
|
offsetZ = base.direct.grid.gridSpacing
|
||||||
|
|
||||||
|
offset.setX(offsetX)
|
||||||
|
offset.setY(offsetY)
|
||||||
|
offset.setZ(offsetZ)
|
||||||
|
|
||||||
|
return offset
|
||||||
|
|
||||||
### WIDGET MANIPULATION METHODS ###
|
### WIDGET MANIPULATION METHODS ###
|
||||||
def xlate1D(self, state):
|
def xlate1D(self, state):
|
||||||
@ -568,6 +602,10 @@ class DirectManipulationControl(DirectObject):
|
|||||||
else:
|
else:
|
||||||
# Move widget to keep hit point as close to mouse as possible
|
# Move widget to keep hit point as close to mouse as possible
|
||||||
offset = self.hitPt - self.prevHit
|
offset = self.hitPt - self.prevHit
|
||||||
|
|
||||||
|
if self.fGridSnap:
|
||||||
|
offset = self.gridSnapping(offset)
|
||||||
|
|
||||||
if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView:
|
if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView:
|
||||||
for widget in base.direct.manipulationControl.widgetList:
|
for widget in base.direct.manipulationControl.widgetList:
|
||||||
widget.setPos(widget, offset)
|
widget.setPos(widget, offset)
|
||||||
@ -588,6 +626,10 @@ class DirectManipulationControl(DirectObject):
|
|||||||
self.prevHit.assign(self.hitPt)
|
self.prevHit.assign(self.hitPt)
|
||||||
else:
|
else:
|
||||||
offset = self.hitPt - self.prevHit
|
offset = self.hitPt - self.prevHit
|
||||||
|
|
||||||
|
if self.fGridSnap:
|
||||||
|
offset = self.gridSnapping(offset)
|
||||||
|
|
||||||
if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView:
|
if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView:
|
||||||
for widget in base.direct.manipulationControl.widgetList:
|
for widget in base.direct.manipulationControl.widgetList:
|
||||||
widget.setPos(widget, offset)
|
widget.setPos(widget, offset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user