Esempio n. 1
0
	def _renderObject(self, obj, brightness = False, addSink = True):
		glPushMatrix()
		if addSink:
			glTranslate(obj.getPosition()[0], obj.getPosition()[1], obj.getSize()[2] / 2 - profile.getProfileSettingFloat('object_sink'))
		else:
			glTranslate(obj.getPosition()[0], obj.getPosition()[1], obj.getSize()[2] / 2)

		if self.tempMatrix is not None and obj == self._selectedObj:
			tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
			glMultMatrixf(tempMatrix)

		offset = obj.getDrawOffset()
		glTranslate(-offset[0], -offset[1], -offset[2] - obj.getSize()[2] / 2)

		tempMatrix = opengl.convert3x3MatrixTo4x4(obj.getMatrix())
		glMultMatrixf(tempMatrix)

		n = 0
		for m in obj._meshList:
			if m.vbo is None:
				m.vbo = opengl.GLVBO(m.vertexes, m.normal)
			if brightness:
				glColor4fv(map(lambda n: n * brightness, self._objColors[n]))
				n += 1
			m.vbo.render()
		glPopMatrix()
Esempio n. 2
0
	def drawModel(self, displayList):
		vMin = self.parent.objectsMinV
		vMax = self.parent.objectsMaxV
		offset = - vMin - (vMax - vMin) / 2

		matrix = opengl.convert3x3MatrixTo4x4(self.parent.matrix)

		glPushMatrix()
		glTranslate(0, 0, self.parent.objectsSize[2]/2)
		if self.tempMatrix is not None:
			tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
			glMultMatrixf(tempMatrix)
		glTranslate(0, 0, -self.parent.objectsSize[2]/2)
		glTranslate(offset[0], offset[1], -vMin[2])
		glMultMatrixf(matrix)
		glCallList(displayList)
		glPopMatrix()
Esempio n. 3
0
    def drawModel(self, displayList):
        vMin = self.parent.objectsMinV
        vMax = self.parent.objectsMaxV
        offset = -vMin - (vMax - vMin) / 2

        matrix = opengl.convert3x3MatrixTo4x4(self.parent.matrix)

        glPushMatrix()
        glTranslate(0, 0, self.parent.objectsSize[2] / 2)
        if self.tempMatrix is not None:
            tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
            glMultMatrixf(tempMatrix)
        glTranslate(0, 0, -self.parent.objectsSize[2] / 2)
        glTranslate(offset[0], offset[1], -vMin[2])
        glMultMatrixf(matrix)
        glCallList(displayList)
        glPopMatrix()
Esempio n. 4
0
	def OnDraw(self):
		machineSize = self.parent.machineSize
		extraSizeMin, extraSizeMax = self.parent.getExtraHeadSize()

		for item in self.parent.list:
			item.validPlacement = True
			item.gotHit = False
		
		for idx1 in xrange(0, len(self.parent.list)):
			item = self.parent.list[idx1]
			iMin1 =-item.getSize() / 2 + numpy.array([item.centerX, item.centerY, 0]) - extraSizeMin #- self.parent.extruderOffset[item.extruder]
			iMax1 = item.getSize() / 2 + numpy.array([item.centerX, item.centerY, 0]) + extraSizeMax #- self.parent.extruderOffset[item.extruder]
			if iMin1[0] < -self.parent.headSizeMin[0] or iMin1[1] < -self.parent.headSizeMin[1]:
				item.validPlacement = False
			if iMax1[0] > machineSize[0] + self.parent.headSizeMax[0] or iMax1[1] > machineSize[1] + self.parent.headSizeMax[1]:
				item.validPlacement = False
			for idx2 in xrange(0, idx1):
				item2 = self.parent.list[idx2]
				iMin2 =-item2.getSize() / 2 + numpy.array([item2.centerX, item2.centerY, 0])
				iMax2 = item2.getSize() / 2 + numpy.array([item2.centerX, item2.centerY, 0])
				if item != item2 and iMax1[0] >= iMin2[0] and iMin1[0] <= iMax2[0] and iMax1[1] >= iMin2[1] and iMin1[1] <= iMax2[1]:
					item.validPlacement = False
					item2.gotHit = True
		
		seenSelected = False
		for item in self.parent.list:
			if item == self.parent.selection:
				seenSelected = True
			if item.modelDisplayList is None:
				item.modelDisplayList = glGenLists(1);
			if item.modelDirty:
				item.modelDirty = False
				glNewList(item.modelDisplayList, GL_COMPILE)
				opengl.DrawMesh(item.mesh)
				glEndList()
			
			if item.validPlacement:
				if self.parent.selection == item:
					glLightfv(GL_LIGHT0, GL_DIFFUSE,  map(lambda x: x + 0.2, self.objColor))
					glLightfv(GL_LIGHT0, GL_AMBIENT,  map(lambda x: x / 2, self.objColor))
				else:
					glLightfv(GL_LIGHT0, GL_DIFFUSE,  self.objColor)
					glLightfv(GL_LIGHT0, GL_AMBIENT,  map(lambda x: x / 2, self.objColor))
			else:
				if self.parent.selection == item:
					glLightfv(GL_LIGHT0, GL_DIFFUSE,  [1.0, 0.0, 0.0, 0.0])
					glLightfv(GL_LIGHT0, GL_AMBIENT,  [0.2, 0.0, 0.0, 0.0])
				else:
					glLightfv(GL_LIGHT0, GL_DIFFUSE,  [1.0, 0.0, 0.0, 0.0])
					glLightfv(GL_LIGHT0, GL_AMBIENT,  [0.2, 0.0, 0.0, 0.0])
			glPushMatrix()
			
			glEnable(GL_LIGHTING)
			glTranslate(item.centerX, item.centerY, 0)
			vMin = item.getMinimum()
			vMax = item.getMaximum()
			offset = - vMin - (vMax - vMin) / 2
			matrix = opengl.convert3x3MatrixTo4x4(item.matrix)
			glPushMatrix()
			glTranslate(0, 0, item.getSize()[2]/2)
			if self.tempMatrix is not None and item == self.parent.selection:
				tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
				glMultMatrixf(tempMatrix)
			glTranslate(0, 0, -item.getSize()[2]/2)
			glTranslate(offset[0], offset[1], -vMin[2])
			glMultMatrixf(matrix)
			glCallList(item.modelDisplayList)
			glPopMatrix()

			vMin =-item.getSize() / 2
			vMax = item.getSize() / 2
			vMax[2] -= vMin[2]
			vMin[2] = 0
			vMinHead = vMin - extraSizeMin# - self.parent.extruderOffset[item.extruder]
			vMaxHead = vMax + extraSizeMax# - self.parent.extruderOffset[item.extruder]

			glDisable(GL_LIGHTING)

			if not self.parent.alwaysAutoPlace:
				glLineWidth(1)
				if self.parent.selection == item:
					if item.gotHit:
						glColor3f(1.0,0.0,0.3)
					else:
						glColor3f(1.0,0.0,1.0)
					opengl.DrawBox(vMin, vMax)
					if item.gotHit:
						glColor3f(1.0,0.3,0.0)
					else:
						glColor3f(1.0,1.0,0.0)
					opengl.DrawBox(vMinHead, vMaxHead)
				elif seenSelected:
					if item.gotHit:
						glColor3f(0.5,0.0,0.1)
					else:
						glColor3f(0.5,0.0,0.5)
					opengl.DrawBox(vMinHead, vMaxHead)
				else:
					if item.gotHit:
						glColor3f(0.7,0.1,0.0)
					else:
						glColor3f(0.7,0.7,0.0)
					opengl.DrawBox(vMin, vMax)
			
			glPopMatrix()
		
		opengl.DrawMachine(util3d.Vector3(machineSize[0], machineSize[1], machineSize[2]))

		if self.parent.selection is not None:
			glPushMatrix()
			glTranslate(self.parent.selection.centerX, self.parent.selection.centerY, self.parent.selection.getSize()[2]/2)
			self.parent.tool.OnDraw()
			glPopMatrix()
Esempio n. 5
0
    def OnDraw(self):
        machineSize = self.parent.machineSize
        extraSizeMin, extraSizeMax = self.parent.getExtraHeadSize()

        for item in self.parent.list:
            item.validPlacement = True
            item.gotHit = False

        for idx1 in xrange(0, len(self.parent.list)):
            item = self.parent.list[idx1]
            iMin1 = -item.getSize() / 2 + numpy.array([
                item.centerX, item.centerY, 0
            ]) - extraSizeMin  #- self.parent.extruderOffset[item.extruder]
            iMax1 = item.getSize() / 2 + numpy.array([
                item.centerX, item.centerY, 0
            ]) + extraSizeMax  #- self.parent.extruderOffset[item.extruder]
            if iMin1[0] < -self.parent.headSizeMin[0] or iMin1[
                    1] < -self.parent.headSizeMin[1]:
                item.validPlacement = False
            if iMax1[0] > machineSize[0] + self.parent.headSizeMax[0] or iMax1[
                    1] > machineSize[1] + self.parent.headSizeMax[1]:
                item.validPlacement = False
            for idx2 in xrange(0, idx1):
                item2 = self.parent.list[idx2]
                iMin2 = -item2.getSize() / 2 + numpy.array(
                    [item2.centerX, item2.centerY, 0])
                iMax2 = item2.getSize() / 2 + numpy.array(
                    [item2.centerX, item2.centerY, 0])
                if item != item2 and iMax1[0] >= iMin2[0] and iMin1[0] <= iMax2[
                        0] and iMax1[1] >= iMin2[1] and iMin1[1] <= iMax2[1]:
                    item.validPlacement = False
                    item2.gotHit = True

        seenSelected = False
        for item in self.parent.list:
            if item == self.parent.selection:
                seenSelected = True
            if item.modelDisplayList is None:
                item.modelDisplayList = glGenLists(1)
            if item.modelDirty:
                item.modelDirty = False
                glNewList(item.modelDisplayList, GL_COMPILE)
                opengl.DrawMesh(item.mesh)
                glEndList()

            if item.validPlacement:
                if self.parent.selection == item:
                    glLightfv(GL_LIGHT0, GL_DIFFUSE,
                              map(lambda x: x + 0.2, self.objColor))
                    glLightfv(GL_LIGHT0, GL_AMBIENT,
                              map(lambda x: x / 2, self.objColor))
                else:
                    glLightfv(GL_LIGHT0, GL_DIFFUSE, self.objColor)
                    glLightfv(GL_LIGHT0, GL_AMBIENT,
                              map(lambda x: x / 2, self.objColor))
            else:
                if self.parent.selection == item:
                    glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 0.0, 0.0, 0.0])
                    glLightfv(GL_LIGHT0, GL_AMBIENT, [0.2, 0.0, 0.0, 0.0])
                else:
                    glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 0.0, 0.0, 0.0])
                    glLightfv(GL_LIGHT0, GL_AMBIENT, [0.2, 0.0, 0.0, 0.0])
            glPushMatrix()

            glEnable(GL_LIGHTING)
            glTranslate(item.centerX, item.centerY, 0)
            vMin = item.getMinimum()
            vMax = item.getMaximum()
            offset = -vMin - (vMax - vMin) / 2
            matrix = opengl.convert3x3MatrixTo4x4(item.matrix)
            glPushMatrix()
            glTranslate(0, 0, item.getSize()[2] / 2)
            if self.tempMatrix is not None and item == self.parent.selection:
                tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
                glMultMatrixf(tempMatrix)
            glTranslate(0, 0, -item.getSize()[2] / 2)
            glTranslate(offset[0], offset[1], -vMin[2])
            glMultMatrixf(matrix)
            glCallList(item.modelDisplayList)
            glPopMatrix()

            vMin = -item.getSize() / 2
            vMax = item.getSize() / 2
            vMax[2] -= vMin[2]
            vMin[2] = 0
            vMinHead = vMin - extraSizeMin  # - self.parent.extruderOffset[item.extruder]
            vMaxHead = vMax + extraSizeMax  # - self.parent.extruderOffset[item.extruder]

            glDisable(GL_LIGHTING)

            if not self.parent.alwaysAutoPlace:
                glLineWidth(1)
                if self.parent.selection == item:
                    if item.gotHit:
                        glColor3f(1.0, 0.0, 0.3)
                    else:
                        glColor3f(1.0, 0.0, 1.0)
                    opengl.DrawBox(vMin, vMax)
                    if item.gotHit:
                        glColor3f(1.0, 0.3, 0.0)
                    else:
                        glColor3f(1.0, 1.0, 0.0)
                    opengl.DrawBox(vMinHead, vMaxHead)
                elif seenSelected:
                    if item.gotHit:
                        glColor3f(0.5, 0.0, 0.1)
                    else:
                        glColor3f(0.5, 0.0, 0.5)
                    opengl.DrawBox(vMinHead, vMaxHead)
                else:
                    if item.gotHit:
                        glColor3f(0.7, 0.1, 0.0)
                    else:
                        glColor3f(0.7, 0.7, 0.0)
                    opengl.DrawBox(vMin, vMax)

            glPopMatrix()

        opengl.DrawMachine(
            util3d.Vector3(machineSize[0], machineSize[1], machineSize[2]))

        if self.parent.selection is not None:
            glPushMatrix()
            glTranslate(self.parent.selection.centerX,
                        self.parent.selection.centerY,
                        self.parent.selection.getSize()[2] / 2)
            self.parent.tool.OnDraw()
            glPopMatrix()