self.gcode = None\r
self.objectsMinV = None\r
self.objectsMaxV = None\r
+ self.objectsBounderyCircleSize = None\r
self.loadThread = None\r
self.machineSize = util3d.Vector3(profile.getPreferenceFloat('machine_width'), profile.getPreferenceFloat('machine_depth'), profile.getPreferenceFloat('machine_height'))\r
self.machineCenter = util3d.Vector3(self.machineSize.x / 2, self.machineSize.y / 2, 0)\r
\r
minV = self.objectList[0].mesh.getMinimum()\r
maxV = self.objectList[0].mesh.getMaximum()\r
+ objectsBounderyCircleSize = self.objectList[0].mesh.bounderyCircleSize\r
for obj in self.objectList:\r
if obj.mesh == None:\r
continue\r
obj.mesh.getMinimumZ()\r
minV = numpy.minimum(minV, obj.mesh.getMinimum())\r
maxV = numpy.maximum(maxV, obj.mesh.getMaximum())\r
+ objectsBounderyCircleSize = max(objectsBounderyCircleSize, obj.mesh.bounderyCircleSize)\r
\r
self.objectsMaxV = maxV\r
self.objectsMinV = minV\r
+ self.objectsBounderyCircleSize = objectsBounderyCircleSize\r
for obj in self.objectList:\r
if obj.mesh == None:\r
continue\r
\r
def OnMouseMotion(self,e):\r
cursorXY = 100000\r
- sizeXY = 0\r
+ radius = 0\r
if self.parent.objectsMaxV != None:\r
- size = (self.parent.objectsMaxV - self.parent.objectsMinV)\r
- sizeXY = math.sqrt((size[0] * size[0]) + (size[1] * size[1]))\r
+ radius = self.parent.objectsBounderyCircleSize * profile.getProfileSettingFloat('model_scale')\r
\r
p0 = numpy.array(gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 0, self.modelMatrix, self.projMatrix, self.viewport))\r
p1 = numpy.array(gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 1, self.modelMatrix, self.projMatrix, self.viewport))\r
cursorZ0 = p0 - (p1 - p0) * (p0[2] / (p1[2] - p0[2]))\r
cursorXY = math.sqrt((cursorZ0[0] * cursorZ0[0]) + (cursorZ0[1] * cursorZ0[1]))\r
- if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3 and False:\r
+ if cursorXY >= radius * 1.1 and cursorXY <= radius * 1.3:\r
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))\r
else:\r
self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))\r
if e.Dragging() and e.LeftIsDown():\r
if self.dragType == '':\r
#Define the drag type depending on the cursor position.\r
- if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3 and False:\r
+ if cursorXY >= radius * 1.1 and cursorXY <= radius * 1.3:\r
self.dragType = 'modelRotate'\r
self.dragStart = math.atan2(cursorZ0[0], cursorZ0[1])\r
else:\r
angle = math.atan2(cursorZ0[0], cursorZ0[1])\r
diff = self.dragStart - angle\r
self.tempRotate = diff * 180 / math.pi\r
+ rot = profile.getProfileSettingFloat('model_rotate_base')\r
+ self.tempRotate = round((self.tempRotate + rot) / 15) * 15 - rot\r
#Workaround for buggy ATI cards.\r
size = self.GetSizeTuple()\r
self.SetSize((size[0]+1, size[1]))\r
self.Refresh()\r
else:\r
if self.tempRotate != 0:\r
- profile.putProfileSetting('model_rotate_base', profile.getProfileSettingFloat('model_rotate_base') + self.tempRotate)\r
+ newRotation = profile.getProfileSettingFloat('model_rotate_base') + self.tempRotate\r
+ while newRotation >= 360:\r
+ newRotation -= 360\r
+ while newRotation < 0:\r
+ newRotation += 360\r
+ profile.putProfileSetting('model_rotate_base', newRotation)\r
+ self.parent.rotate.SetValue(newRotation)\r
self.parent.updateModelTransform()\r
self.tempRotate = 0\r
\r
glEnd()\r
glEnable(GL_DEPTH_TEST)\r
\r
- opengl.DrawMachine(machineSize)\r
-\r
glPushMatrix()\r
glTranslate(self.parent.machineCenter.x, self.parent.machineCenter.y, 0)\r
\r
#Draw the rotate circle\r
- if self.parent.objectsMaxV != None and False:\r
+ if self.parent.objectsMaxV != None:\r
glDisable(GL_LIGHTING)\r
glDisable(GL_CULL_FACE)\r
glEnable(GL_BLEND)\r
+ glRotate(self.tempRotate + profile.getProfileSettingFloat('model_rotate_base'), 0, 0, 1)\r
+ radius = self.parent.objectsBounderyCircleSize * profile.getProfileSettingFloat('model_scale')\r
+ glScalef(radius, radius, 1)\r
glBegin(GL_TRIANGLE_STRIP)\r
- size = (self.parent.objectsMaxV - self.parent.objectsMinV)\r
- sizeXY = math.sqrt((size[0] * size[0]) + (size[1] * size[1]))\r
for i in xrange(0, 64+1):\r
f = i if i < 64/2 else 64 - i\r
- glColor4ub(255,int(f*255/(64/2)),0,128)\r
- glVertex3f(sizeXY * 0.7 * math.cos(i/32.0*math.pi), sizeXY * 0.7 * math.sin(i/32.0*math.pi),0.1)\r
- glColor4ub( 0,128,0,128)\r
- glVertex3f((sizeXY * 0.7 + 3) * math.cos(i/32.0*math.pi), (sizeXY * 0.7 + 3) * math.sin(i/32.0*math.pi),0.1)\r
+ glColor4ub(255,int(f*255/(64/2)),0,255)\r
+ glVertex3f(1.1 * math.cos(i/32.0*math.pi), 1.1 * math.sin(i/32.0*math.pi),0.1)\r
+ glColor4ub( 0,128,0,255)\r
+ glVertex3f(1.3 * math.cos(i/32.0*math.pi), 1.3 * math.sin(i/32.0*math.pi),0.1)\r
+ glEnd()\r
+ glBegin(GL_TRIANGLES)\r
+ glColor4ub(0,0,0,192)\r
+ glVertex3f(1, 0.1,0.15)\r
+ glVertex3f(1,-0.1,0.15)\r
+ glVertex3f(1.4,0,0.15)\r
glEnd()\r
glEnable(GL_CULL_FACE)\r
\r
glPopMatrix()\r
+\r
+ opengl.DrawMachine(machineSize)\r
\r
glFlush()\r
\r
return self.size
def setRotateMirror(self, rotate, mirrorX, mirrorY, mirrorZ, swapXZ, swapYZ):
+ #Modify the vertexes with the rotation/mirror
rotate = rotate / 180.0 * math.pi
scaleX = 1.0
scaleY = 1.0
if swapYZ:
mat = numpy.array([mat[0],mat[2],mat[1]], numpy.float32)
self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA()
-
+
+ #Calculate the boundery box of the object
+ self.getMinimumZ()
+ #Calculate the boundery circle
+ center = (self.max + self.min) / 2.0
+ self.bounderyCircleSize = round(math.sqrt(numpy.max(((self.vertexes[::,0] - center[0]) * (self.vertexes[::,0] - center[0])) + ((self.vertexes[::,1] - center[1]) * (self.vertexes[::,1] - center[1])))), 3)
+
+ #Calculate the normals
tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3)
normals = numpy.cross( tris[::,1 ] - tris[::,0] , tris[::,2 ] - tris[::,0] )
lens = numpy.sqrt( normals[:,0]**2 + normals[:,1]**2 + normals[:,2]**2 )
n[:,6:9] = normals
self.normal = n.reshape(self.vertexCount, 3)
self.invNormal = -self.normal
-
- self.getMinimumZ()
def splitToParts(self, callback = None):
t0 = time.time()