def addCylinder(faces, inradius, sides, topOverBottom, vertexes): 'Add cylinder by inradius.' polygonBottom = euclidean.getComplexPolygonByComplexRadius(complex(inradius.x, inradius.y), sides) polygonTop = polygonBottom if topOverBottom <= 0.0: polygonTop = [complex()] elif topOverBottom != 1.0: polygonTop = euclidean.getComplexPathByMultiplier(topOverBottom, polygonTop) bottomTopPolygon = [ triangle_mesh.getAddIndexedLoop(polygonBottom, vertexes, -inradius.z), triangle_mesh.getAddIndexedLoop(polygonTop, vertexes, inradius.z)] triangle_mesh.addPillarByLoops(faces, bottomTopPolygon)
def addSphere(faces, radius, vertexes, xmlElement): 'Add sphere by radius.' bottom = -radius.z sides = evaluate.getSidesMinimumThreeBasedOnPrecision(max(radius.x, radius.y, radius.z), xmlElement ) sphereSlices = max(sides / 2, 2) equator = euclidean.getComplexPolygonByComplexRadius(complex(radius.x, radius.y), sides) polygons = [triangle_mesh.getAddIndexedLoop([complex()], vertexes, bottom)] zIncrement = (radius.z + radius.z) / float(sphereSlices) z = bottom for sphereSlice in xrange(1, sphereSlices): z += zIncrement zPortion = abs(z) / radius.z multipliedPath = euclidean.getComplexPathByMultiplier(math.sqrt(1.0 - zPortion * zPortion), equator) polygons.append(triangle_mesh.getAddIndexedLoop(multipliedPath, vertexes, z)) polygons.append(triangle_mesh.getAddIndexedLoop([complex()], vertexes, radius.z)) triangle_mesh.addPillarByLoops(faces, polygons)