def getLoopLayersSetCopy(elementNode, geometryOutput, importRadius, radius): 'Get the loop layers and set the copyShallow.' halfLayerHeight = 0.5 * radius copyShallow = elementNode.getCopyShallow() processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) if minimumZ == None: copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) return [] maximumZ = euclidean.getTopPath(transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * radius zoneArrangement = triangle_mesh.ZoneArrangement(radius, transformedVertexes) bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops( copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + halfLayerHeight loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, halfLayerHeight, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) return loopLayers
def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix): 'Get inset geometryOutput.' derivation = InsetDerivation(elementNode, prefix) if derivation.radius == 0.0: return geometryOutput copyShallow = elementNode.getCopyShallow() solid.processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) maximumZ = euclidean.getTopPath(transformedVertexes) layerThickness = setting.getLayerThickness(elementNode) importRadius = setting.getImportRadius(elementNode) zoneArrangement = triangle_mesh.ZoneArrangement(layerThickness, transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * layerThickness bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops(copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + layerThickness loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, layerThickness, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove(copyShallow.xmlObject) belowLoop = [] diagonalRadius = math.sqrt(0.5) * derivation.radius insetDiagonalLoops = [] loops = [] vertexes = [] for loopLayer in loopLayers: insetDiagonalLoops.append(intercircle.getLargestInsetLoopFromLoop(loopLayer.loops[0], diagonalRadius)) for loopLayerIndex, loopLayer in enumerate(loopLayers): vector3Loop = [] insetLoop = intercircle.getLargestInsetLoopFromLoop(loopLayer.loops[0], derivation.radius) loopLists = [[getLoopOrEmpty(loopLayerIndex - 1, insetDiagonalLoops)], [insetLoop]] largestLoop = euclidean.getLargestLoop(boolean_solid.getLoopsIntersection(importRadius, loopLists)) if evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'insetTop'): loopLists = [[getLoopOrEmpty(loopLayerIndex + 1, insetDiagonalLoops)], [largestLoop]] largestLoop = euclidean.getLargestLoop(boolean_solid.getLoopsIntersection(importRadius, loopLists)) for point in largestLoop: vector3Index = Vector3Index(len(vertexes), point.real, point.imag, loopLayer.z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) if len(vector3Loop) > 0: loops.append(vector3Loop) if evaluate.getEvaluatedBoolean(False, elementNode, prefix + 'addExtraTopLayer') and len(loops) > 0: topLoop = loops[-1] vector3Loop = [] loops.append(vector3Loop) z = topLoop[0].z + layerThickness for point in topLoop: vector3Index = Vector3Index(len(vertexes), point.x, point.y, z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) geometryOutput = triangle_mesh.getMeldedPillarOutput(loops) return geometryOutput
def addLighteningHoles(derivation, gearHolePaths, negatives, pitchRadius, positives): "Add lightening holes." extrudeDerivation = extrude.ExtrudeDerivation() positiveVertexes = matrix.getVertexes(positives) bottomPath = euclidean.getTopPath(positiveVertexes) topPath = euclidean.getBottomPath(positiveVertexes) extrudeDerivation.offsetPathDefault = [Vector3(0.0, 0.0, bottomPath), Vector3(0.0, 0.0, topPath)] extrudeDerivation.setToXMLElement(derivation.copyShallow) vector3LighteningHoles = getLighteningHoles(derivation, gearHolePaths, pitchRadius) extrude.addNegativesPositives(extrudeDerivation, negatives, vector3LighteningHoles, positives)
def addLighteningHoles(derivation, gearHolePaths, negatives, pitchRadius, positives): "Add lightening holes." positiveVertexes = matrix.getVertexes(positives) bottomPath = euclidean.getTopPath(positiveVertexes) topPath = euclidean.getBottomPath(positiveVertexes) copyShallow = derivation.xmlElement.getCopyShallow() copyShallow.attributeDictionary['path'] = [Vector3(0.0, 0.0, bottomPath), Vector3(0.0, 0.0, topPath)] extrudeDerivation = extrude.ExtrudeDerivation(copyShallow) vector3LighteningHoles = getLighteningHoles(derivation, gearHolePaths, pitchRadius) extrude.addNegativesPositives(extrudeDerivation, negatives, vector3LighteningHoles, positives)
def getGeometryOutput(derivation, xmlElement): "Get vector3 vertexes from attribute dictionary." if derivation == None: derivation = GearDerivation() derivation.setToXMLElement(xmlElement) creationFirst = derivation.creationType.lower()[: 1] toothProfileGear = getToothProfile(derivation, derivation.pitchRadiusGear, derivation.teethGear) gearProfileFirst = getGearProfileCylinder(derivation.teethPinion, derivation.pinionToothProfile) gearPaths = getGearPaths(derivation, derivation.pitchRadiusGear, derivation.teethGear, toothProfileGear) vector3GearProfileFirst = euclidean.getVector3Path(gearProfileFirst) vector3GearPaths = euclidean.getVector3Paths(gearPaths) translation = Vector3() moveFirst = derivation.moveType.lower()[: 1] if moveFirst != 'n': distance = derivation.pitchRadius + derivation.pitchRadiusGear if moveFirst != 'm': decimalPlaces = 1 - int(math.floor(math.log10(derivation.pitchRadius + abs(derivation.pitchRadiusGear)))) distance += derivation.halfWavelength + derivation.halfWavelength distance = round(1.15 * distance, decimalPlaces) translation = Vector3(0.0, -distance) if derivation.pinionThickness <=0.0: return getPathOutput( creationFirst, derivation, translation, vector3GearProfileFirst, vector3GearPaths, xmlElement) pitchRadius = derivation.pitchRadius teeth = derivation.teethPinion twist = derivation.helixThickness / derivation.pitchRadius extrudeOutputFirst = getOutputCylinder( derivation.pinionCollarThickness, derivation, None, pitchRadius, teeth, twist, [vector3GearProfileFirst], xmlElement) if creationFirst == 'f': return extrudeOutputFirst teeth = derivation.teethGear extrudeOutputSecond = None if teeth == 0: extrudeOutputSecond = getOutputRack(derivation, vector3GearPaths[0], xmlElement) else: twist = -derivation.helixThickness / derivation.pitchRadiusGear extrudeOutputSecond = getOutputCylinder( derivation.gearCollarThickness, derivation, derivation.gearHolePaths, derivation.pitchRadiusGear, teeth, twist, vector3GearPaths, xmlElement) if creationFirst == 's': return extrudeOutputSecond gearVertexes = matrix.getConnectionVertexes(extrudeOutputSecond) if moveFirst == 'v': translation = Vector3(0.0, 0.0, euclidean.getTopPath(gearVertexes)) euclidean.translateVector3Path(matrix.getConnectionVertexes(extrudeOutputFirst), translation) else: euclidean.translateVector3Path(gearVertexes, translation) return {'group' : {'shapes' : [extrudeOutputFirst, extrudeOutputSecond]}}
def addShaft(derivation, negatives, positives): "Add shaft." if len(derivation.shaftPath) < 3: return extrudeDerivation = extrude.ExtrudeDerivation() positiveVertexes = matrix.getVertexes(positives) bottomPath = euclidean.getTopPath(positiveVertexes) topPath = euclidean.getBottomPath(positiveVertexes) extrudeDerivation.offsetPathDefault = [Vector3(0.0, 0.0, bottomPath), Vector3(0.0, 0.0, topPath)] extrudeDerivation.setToXMLElement(derivation.copyShallow) extrude.addNegativesPositives(extrudeDerivation, negatives, [derivation.shaftPath], positives)
def addShaft(derivation, negatives, positives): "Add shaft." if len(derivation.shaftPath) < 3: return positiveVertexes = matrix.getVertexes(positives) bottomPath = euclidean.getTopPath(positiveVertexes) topPath = euclidean.getBottomPath(positiveVertexes) copyShallow = derivation.xmlElement.getCopyShallow() copyShallow.attributeDictionary['path'] = [Vector3(0.0, 0.0, bottomPath), Vector3(0.0, 0.0, topPath)] extrudeDerivation = extrude.ExtrudeDerivation(copyShallow) extrude.addNegativesPositives(extrudeDerivation, negatives, [derivation.shaftPath], positives)
def processElementNodeByDerivation(derivation, elementNode): 'Process the xml element by derivation.' if derivation == None: derivation = CarveDerivation(elementNode) targetElementNode = derivation.targetElementNode if targetElementNode == None: print('Warning, carve could not get target for:') print(elementNode) return xmlObject = targetElementNode.xmlObject if xmlObject == None: print( 'Warning, processElementNodeByDerivation in carve could not get xmlObject for:' ) print(targetElementNode) print(derivation.elementNode) return matrix.getBranchMatrixSetElementNode(targetElementNode) transformedVertexes = xmlObject.getTransformedVertexes() if len(transformedVertexes) < 1: print( 'Warning, transformedVertexes is zero in processElementNodeByDerivation in carve for:' ) print(xmlObject) print(targetElementNode) print(derivation.elementNode) return elementNode.localName = 'group' elementNode.getXMLProcessor().processElementNode(elementNode) minimumZ = boolean_geometry.getMinimumZ(xmlObject) maximumZ = euclidean.getTopPath(transformedVertexes) zoneArrangement = triangle_mesh.ZoneArrangement(derivation.layerThickness, transformedVertexes) oldVisibleString = targetElementNode.attributes['visible'] targetElementNode.attributes['visible'] = True z = minimumZ + 0.5 * derivation.layerThickness loopLayers = boolean_geometry.getLoopLayers([xmlObject], derivation.importRadius, derivation.layerThickness, maximumZ, False, z, zoneArrangement) targetElementNode.attributes['visible'] = oldVisibleString for loopLayerIndex, loopLayer in enumerate(loopLayers): if len(loopLayer.loops) > 0: pathElement = getLinkedElementNode('_carve_%s' % loopLayerIndex, elementNode, targetElementNode) vector3Loops = euclidean.getVector3Paths(loopLayer.loops, loopLayer.z) path.convertElementNode(pathElement, vector3Loops)
def processElementNodeByDerivation(derivation, elementNode): 'Process the xml element by derivation.' if derivation == None: derivation = CarveDerivation(elementNode) targetElementNode = derivation.targetElementNode if targetElementNode == None: print('Warning, carve could not get target for:') print(elementNode) return xmlObject = targetElementNode.xmlObject if xmlObject == None: print( 'Warning, processElementNodeByDerivation in carve could not get xmlObject for:' ) print(targetElementNode) print(derivation.elementNode) return matrix.getBranchMatrixSetElementNode(targetElementNode) transformedVertexes = xmlObject.getTransformedVertexes() if len(transformedVertexes) < 1: print( 'Warning, transformedVertexes is zero in processElementNodeByDerivation in carve for:' ) print(xmlObject) print(targetElementNode) print(derivation.elementNode) return elementNode.localName = 'group' elementNode.getXMLProcessor().processElementNode(elementNode) minimumZ = boolean_geometry.getMinimumZ(xmlObject) maximumZ = euclidean.getTopPath(transformedVertexes) zoneArrangement = triangle_mesh.ZoneArrangement(derivation.layerHeight, transformedVertexes) oldVisibleString = targetElementNode.attributes['visible'] targetElementNode.attributes['visible'] = True z = minimumZ + 0.5 * derivation.layerHeight loopLayers = boolean_geometry.getLoopLayers( [xmlObject], derivation.importRadius, derivation.layerHeight, maximumZ, False, z, zoneArrangement) targetElementNode.attributes['visible'] = oldVisibleString for loopLayerIndex, loopLayer in enumerate(loopLayers): if len(loopLayer.loops) > 0: pathElement = getLinkedElementNode('_carve_%s' % loopLayerIndex, elementNode, targetElementNode) vector3Loops = euclidean.getVector3Paths(loopLayer.loops, loopLayer.z) path.convertElementNode(pathElement, vector3Loops)
def addBevelGear(derivation, extrudeDerivation, pitchRadius, positives, teeth, vector3GearProfile): "Get extrude output for a cylinder gear." totalPitchRadius = derivation.pitchRadiusGear + derivation.pitchRadius totalTeeth = derivation.teethPinion + derivation.teethGear portionDirections = extrude.getSpacedPortionDirections(extrudeDerivation.interpolationDictionary) loopLists = extrude.getLoopListsByPath(extrudeDerivation, None, vector3GearProfile[0], portionDirections) firstLoopList = loopLists[0] gearOverPinion = float(totalTeeth - teeth) / float(teeth) thirdLayerThickness = 0.33333333333 * evaluate.getLayerThickness(derivation.xmlElement) pitchRadian = math.atan(math.sin(derivation.operatingRadian) / (gearOverPinion + math.cos(derivation.operatingRadian))) coneDistance = pitchRadius / math.sin(pitchRadian) apex = Vector3(0.0, 0.0, math.sqrt(coneDistance * coneDistance - pitchRadius * pitchRadius)) cosPitch = apex.z / coneDistance sinPitch = math.sin(pitchRadian) for loop in firstLoopList: for point in loop: alongWay = point.z / coneDistance oneMinusAlongWay = 1.0 - alongWay pointComplex = point.dropAxis() pointComplexLength = abs(pointComplex) deltaRadius = pointComplexLength - pitchRadius cosDeltaRadius = cosPitch * deltaRadius sinDeltaRadius = sinPitch * deltaRadius pointComplex *= (cosDeltaRadius + pitchRadius) / pointComplexLength point.x = pointComplex.real point.y = pointComplex.imag point.z += sinDeltaRadius point.x *= oneMinusAlongWay point.y *= oneMinusAlongWay addBottomLoop(-thirdLayerThickness, firstLoopList) topLoop = firstLoopList[-1] topAddition = [] topZ = euclidean.getTopPath(topLoop) + thirdLayerThickness oldIndex = topLoop[-1].index for point in topLoop: oldIndex += 1 topAddition.append(Vector3Index(oldIndex, 0.8 * point.x, 0.8 * point.y, topZ)) firstLoopList.append(topAddition) translation = Vector3(0.0, 0.0, -euclidean.getBottomPaths(firstLoopList)) euclidean.translateVector3Paths(firstLoopList, translation) geometryOutput = trianglemesh.getPillarsOutput(loopLists) positives.append(geometryOutput)
def getLoopLayersSetCopy(elementNode, geometryOutput, importRadius, radius): 'Get the loop layers and set the copyShallow.' halfLayerHeight = 0.5 * radius copyShallow = elementNode.getCopyShallow() processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) if minimumZ == None: copyShallow.parentNode.xmlObject.archivableObjects.remove(copyShallow.xmlObject) return [] maximumZ = euclidean.getTopPath(transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * radius zoneArrangement = triangle_mesh.ZoneArrangement(radius, transformedVertexes) bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops(copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + halfLayerHeight loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, halfLayerHeight, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove(copyShallow.xmlObject) return loopLayers
def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix): 'Get inset geometryOutput.' derivation = InsetDerivation(elementNode, prefix) if derivation.radius == 0.0: return geometryOutput copyShallow = elementNode.getCopyShallow() solid.processElementNodeByGeometry(copyShallow, geometryOutput) targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode) matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix) transformedVertexes = copyShallow.xmlObject.getTransformedVertexes() minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject) maximumZ = euclidean.getTopPath(transformedVertexes) layerThickness = setting.getLayerThickness(elementNode) importRadius = setting.getImportRadius(elementNode) zoneArrangement = triangle_mesh.ZoneArrangement(layerThickness, transformedVertexes) copyShallow.attributes['visible'] = True copyShallowObjects = [copyShallow.xmlObject] bottomLoopLayer = euclidean.LoopLayer(minimumZ) z = minimumZ + 0.1 * layerThickness bottomLoopLayer.loops = boolean_geometry.getEmptyZLoops( copyShallowObjects, importRadius, False, z, zoneArrangement) loopLayers = [bottomLoopLayer] z = minimumZ + layerThickness loopLayers += boolean_geometry.getLoopLayers(copyShallowObjects, importRadius, layerThickness, maximumZ, False, z, zoneArrangement) copyShallow.parentNode.xmlObject.archivableObjects.remove( copyShallow.xmlObject) belowLoop = [] diagonalRadius = math.sqrt(0.5) * derivation.radius insetDiagonalLoops = [] loops = [] vertexes = [] for loopLayer in loopLayers: insetDiagonalLoops.append( intercircle.getLargestInsetLoopFromLoop(loopLayer.loops[0], diagonalRadius)) for loopLayerIndex, loopLayer in enumerate(loopLayers): vector3Loop = [] insetLoop = intercircle.getLargestInsetLoopFromLoop( loopLayer.loops[0], derivation.radius) loopLists = [[getLoopOrEmpty(loopLayerIndex - 1, insetDiagonalLoops)], [insetLoop]] largestLoop = euclidean.getLargestLoop( boolean_solid.getLoopsIntersection(importRadius, loopLists)) if evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'insetTop'): loopLists = [[ getLoopOrEmpty(loopLayerIndex + 1, insetDiagonalLoops) ], [largestLoop]] largestLoop = euclidean.getLargestLoop( boolean_solid.getLoopsIntersection(importRadius, loopLists)) for point in largestLoop: vector3Index = Vector3Index(len(vertexes), point.real, point.imag, loopLayer.z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) if len(vector3Loop) > 0: loops.append(vector3Loop) if evaluate.getEvaluatedBoolean(False, elementNode, prefix + 'addExtraTopLayer') and len(loops) > 0: topLoop = loops[-1] vector3Loop = [] loops.append(vector3Loop) z = topLoop[0].z + layerThickness for point in topLoop: vector3Index = Vector3Index(len(vertexes), point.x, point.y, z) vector3Loop.append(vector3Index) vertexes.append(vector3Index) geometryOutput = triangle_mesh.getMeldedPillarOutput(loops) return geometryOutput