Example #1
0
 def _gcodeToVBO_lines(self, gcodeLayers):
     verts = numpy.zeros((0, 3), numpy.float32)
     indices = numpy.zeros((0), numpy.uint32)
     for layer in gcodeLayers:
         for path in layer:
             if path['type'] == 'move':
                 a = path['points'] + numpy.array([0, 0, 0.02],
                                                  numpy.float32)
                 i = numpy.arange(len(verts),
                                  len(verts) + len(a), 1, numpy.uint32)
                 i = numpy.dstack((i[0:-1], i[1:])).flatten()
                 verts = numpy.concatenate((verts, a))
                 indices = numpy.concatenate((indices, i))
             if path['type'] == 'retract':
                 a = path['points'] + numpy.array([0, 0, 0.02],
                                                  numpy.float32)
                 a = numpy.concatenate(
                     (a[:-1],
                      a[1:] + numpy.array([0, 0, 1], numpy.float32)), 1)
                 a = a.reshape((len(a) * 2, 3))
                 i = numpy.arange(len(verts),
                                  len(verts) + len(a), 1, numpy.uint32)
                 verts = numpy.concatenate((verts, a))
                 indices = numpy.concatenate((indices, i))
     return openglHelpers.GLVBO(GL_LINES, verts, indicesArray=indices)
Example #2
0
    def _gcodeToVBO_quads(self, gcodeLayers, extrudeType):
        useFilamentArea = profile.getMachineSetting(
            'gcode_flavor') == 'UltiGCode'
        filamentRadius = profile.getProfileSettingFloat(
            'filament_diameter') / 2
        filamentArea = math.pi * filamentRadius * filamentRadius

        if ':' in extrudeType:
            extruder = int(extrudeType[extrudeType.find(':') + 1:])
            extrudeType = extrudeType[0:extrudeType.find(':')]
        else:
            extruder = None

        verts = numpy.zeros((0, 3), numpy.float32)
        indices = numpy.zeros((0), numpy.uint32)
        for layer in gcodeLayers:
            for path in layer:
                if path['type'] == 'extrude' and path[
                        'pathType'] == extrudeType and (
                            extruder is None or path['extruder'] == extruder):
                    a = path['points']
                    if extrudeType == 'FILL':
                        a[:, 2] += 0.01

                    #Construct the normals of each line 90deg rotated on the X/Y plane
                    normals = a[1:] - a[:-1]
                    lengths = numpy.sqrt(normals[:, 0]**2 + normals[:, 1]**2)
                    normals[:,
                            0], normals[:,
                                        1] = -normals[:,
                                                      1] / lengths, normals[:,
                                                                            0] / lengths
                    normals[:, 2] /= lengths

                    ePerDist = path['extrusion'][1:] / lengths
                    if useFilamentArea:
                        lineWidth = ePerDist / path['layerThickness'] / 2.0
                    else:
                        lineWidth = ePerDist * (filamentArea /
                                                path['layerThickness'] / 2)

                    normals[:, 0] *= lineWidth
                    normals[:, 1] *= lineWidth

                    b = numpy.zeros((len(a) - 1, 0), numpy.float32)
                    b = numpy.concatenate((b, a[1:] + normals), 1)
                    b = numpy.concatenate((b, a[1:] - normals), 1)
                    b = numpy.concatenate((b, a[:-1] - normals), 1)
                    b = numpy.concatenate((b, a[:-1] + normals), 1)
                    b = b.reshape((len(b) * 4, 3))

                    i = numpy.arange(len(verts),
                                     len(verts) + len(b), 1, numpy.uint32)

                    verts = numpy.concatenate((verts, b))
                    indices = numpy.concatenate((indices, i))
        return openglHelpers.GLVBO(GL_QUADS, verts, indicesArray=indices)
Example #3
0
	def _polygonsToVBO_quads(self, polygons):
		verts = numpy.zeros((0, 3), numpy.float32)
		indices = numpy.zeros((0), numpy.uint32)
		for poly in polygons:
			i = numpy.arange(len(verts), len(verts) + len(poly) + 1, 1, numpy.uint32)
			i2 = numpy.arange(len(verts) + len(poly), len(verts) + len(poly) + len(poly) + 1, 1, numpy.uint32)
			i[-1] = len(verts)
			i2[-1] = len(verts) + len(poly)
			i = numpy.dstack((i[0:-1],i2[0:-1],i2[1:],i[1:])).flatten()
			indices = numpy.concatenate((indices, i), 0)
			verts = numpy.concatenate((verts, poly), 0)
			verts = numpy.concatenate((verts, poly * numpy.array([1,0,1],numpy.float32) + numpy.array([0,-100,0],numpy.float32)), 0)
		return openglHelpers.GLVBO(GL_QUADS, verts, indicesArray=indices)
Example #4
0
	def _polygonsToVBO_lines(self, polygons):
		verts = numpy.zeros((0, 3), numpy.float32)
		indices = numpy.zeros((0), numpy.uint32)
		for poly in polygons:
			if len(poly) > 2:
				i = numpy.arange(len(verts), len(verts) + len(poly) + 1, 1, numpy.uint32)
				i[-1] = len(verts)
				i = numpy.dstack((i[0:-1],i[1:])).flatten()
			else:
				i = numpy.arange(len(verts), len(verts) + len(poly), 1, numpy.uint32)
			indices = numpy.concatenate((indices, i), 0)
			verts = numpy.concatenate((verts, poly), 0)
		return openglHelpers.GLVBO(GL_LINES, verts, indicesArray=indices)
Example #5
0
	def _gcodeToVBO_lines(self, gcodeLayers, extrudeType):
		if ':' in extrudeType:
			extruder = int(extrudeType[extrudeType.find(':')+1:])
			extrudeType = extrudeType[0:extrudeType.find(':')]
		else:
			extruder = None
		verts = numpy.zeros((0, 3), numpy.float32)
		indices = numpy.zeros((0), numpy.uint32)
		for layer in gcodeLayers:
			for path in layer:
				if path['type'] == 'extrude' and path['pathType'] == extrudeType and (extruder is None or path['extruder'] == extruder):
					i = numpy.arange(len(verts), len(verts) + len(path['points']), 1, numpy.uint32)
					i = numpy.dstack((i[0:-1],i[1:])).flatten()
					indices = numpy.concatenate((indices, i), 0)
					verts = numpy.concatenate((verts, path['points']))
		return openglHelpers.GLVBO(GL_LINES, verts, indicesArray=indices)