def mapSceneLighting(scn, object=None, res=(1024, 1024), border=1): """ Create a lightmap for a scene with one or multiple lights. This happens by adding the lightmaps produced by each light, plus the scene ambience. """ if object is None: object = G.app.selectedHuman objrot = G.app.modelCamera.getRotation() def calcLightPos(light): return tuple( matrix.transform3( matrix.rotx(-objrot[0]) * matrix.roty(-objrot[1]) * matrix.rotz(-objrot[2]), light.position)) def getLightmap(light): lmap = mapLighting(calcLightPos(light), object.mesh, res, border) return image_operations.Image(data=lmap.data * light.color.values) progress = Progress(1 + len(scn.lights)) # Ambience lmap = image_operations.colorAsImage( (scn.environment.ambience * object.material.diffuseColor).values, None, *res) if (object.material.shaderConfig['ambientOcclusion'] and not object.material.aoMapTexture is None): aomap = image_operations.Image(data=object.material.aoMapTexture) aomap = image_operations.resized(aomap, *lmap.size) lmap = image_operations.multiply( lmap, image_operations.mix(aomap, image_operations.getWhite(lmap), object.material.aoMapIntensity)) progress.step() # Lights if (scn.lights): amb = lmap lmap = getLightmap(scn.lights[0]).data progress.step() for light in scn.lights[1:]: lmap = image_operations.mixData(lmap, getLightmap(light).data, 1, 1) progress.step() lmap = image_operations.Image(data=lmap) if len(scn.lights) > 1: lmap = image_operations.normalize(lmap) # Ambience calculation function: lmap = lmap + (1 - lmap) * amb lmap = image_operations.mix( lmap, image_operations.multiply(image_operations.invert(lmap), amb), 1, 1) return lmap
def povrayProcessSSS(stuffs, outDir, settings, progressCallback=None): def progress(prog): if progressCallback == None: gui3d.app.progress(prog) else: progressCallback(prog) progress(0) progbase = 0 nextpb = 1 - 0.65 * settings['usebump'] # get lightmap lmap = projection.mapSceneLighting( settings['scene'], progressCallback=lambda p: progress(0.3 * nextpb * p)) lmap = imgop.getChannel(lmap, 1) # prepare channels black = imgop.Image(data=imgop.numpy.zeros((lmap.height, lmap.width, 1), dtype=imgop.numpy.uint8)) # calculate blur level of each cannel, according to settings sssa = float(settings['SSSA']) # blue channel imgop.compose([black, black, lmap]).save( os.path.join(outDir, '%s_sss_bluelmap.png' % stuffs[0].name)) # green channel progress(0.4 * nextpb) lmap2 = imgop.blurred(lmap, 16 * sssa, 13, lambda p: progress( (0.4 + 0.3 * p) * nextpb)) imgop.compose([black, lmap2, black]).save( os.path.join(outDir, '%s_sss_greenlmap.png' % stuffs[0].name)) # red channel progress(0.7 * nextpb) lmap2 = imgop.blurred(lmap2, 32 * sssa, 13, lambda p: progress( (0.7 + 0.3 * p) * nextpb)) imgop.compose([lmap2, black, black]).save( os.path.join(outDir, '%s_sss_redlmap.png' % stuffs[0].name)) progbase = nextpb progress(progbase) if settings['usebump']: # Export blurred bump maps lmap = imgop.Image(os.path.join(stuffs[0].bump[0], stuffs[0].bump[1])) lmap = imgop.getChannel(lmap, 1) lmap = imgop.blurred( lmap, (float(lmap.width) / 1024) * 1.6 * sssa, 15, lambda p: progress(progbase + 0.5 * p * (1 - progbase))) progress(progbase + 0.5 * (1 - progbase)) lmap.save(os.path.join(outDir, '%s_sss_greenbump.png' % stuffs[0].name)) lmap = imgop.blurred( lmap, (float(lmap.width) / 1024) * 3.2 * sssa, 15, lambda p: progress(progbase + (0.5 + 0.5 * p) * (1 - progbase))) lmap.save(os.path.join(outDir, '%s_sss_redbump.png' % stuffs[0].name)) progress(1.0)
import connection_methods import image_operations import container_operations import sys container_obj = container_operations.Container() image_object = image_operations.Image() def localhost_security_scanning(): host_os_name = connection_methods.check_host_os() if host_os_name == 'windows': print("we are not supporting the windows os") print("exiting from security scan...") sys.exit() docker_running_status = connection_methods.is_docker_running() print("after status: ", docker_running_status) if docker_running_status == True: docker_connected_status, docker_client = connection_methods.connect_docker_daemon( ) if docker_connected_status == True: images_list = image_object.get_images(docker_client) print("image list :", images_list) image_info = image_object.get_image('redis', docker_client) print("image :", image_info) # container_list = container_obj.get_containers() # print("container list:", container_list) def remote_host_security_scanning(): remote_host_ip, username, password, port_number = connection_methods.get_remote_host_information(
def getLightmap(light): lmap = mapLighting(calcLightPos(light), object.mesh, res, border) return image_operations.Image(data=lmap.data * light.color.values)
def Render(settings): progress = Progress.begin() if not mh.hasRenderToRenderbuffer(): settings['dimensions'] = (G.windowWidth, G.windowHeight) if settings['lightmapSSS']: progress(0, 0.05, "Storing data") import material human = G.app.selectedHuman materialBackup = material.Material(human.material) progress(0.05, 0.1, "Projecting lightmaps") diffuse = imgop.Image(data=human.material.diffuseTexture) lmap = projection.mapSceneLighting(settings['scene'], border=human.material.sssRScale) progress(0.1, 0.4, "Applying medium scattering") lmapG = imgop.blurred(lmap, human.material.sssGScale, 13) progress(0.4, 0.7, "Applying high scattering") lmapR = imgop.blurred(lmap, human.material.sssRScale, 13) lmap = imgop.compose([lmapR, lmapG, lmap]) if not diffuse.isEmpty: progress(0.7, 0.8, "Combining textures") lmap = imgop.resized(lmap, diffuse.width, diffuse.height, filter=image.FILTER_BILINEAR) progress(0.8, 0.9) lmap = imgop.multiply(lmap, diffuse) lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture" progress(0.9, 0.95, "Setting up renderer") human.material.diffuseTexture = lmap human.configureShading(diffuse=True) human.shadeless = True progress(0.95, 0.98, None) else: progress(0, 0.99, None) if not mh.hasRenderToRenderbuffer(): # Limited fallback mode, read from screen buffer log.message("Fallback render: grab screen") img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight) alphaImg = None else: # Render to framebuffer object renderprog = Progress() renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering") width, height = settings['dimensions'] log.message("Rendering at %sx%s", width, height) if settings['AA']: width = width * 2 height = height * 2 img = mh.renderToBuffer(width, height) alphaImg = mh.renderAlphaMask(width, height) img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0)) if settings['AA']: renderprog(0.4, 0.99, "AntiAliasing") # Resize to 50% using bi-linear filtering img = img.resized(width / 2, height / 2, filter=image.FILTER_BILINEAR) # TODO still haven't figured out where components get swapped, but this hack appears to be necessary img.data[:, :, :] = img.data[:, :, (2, 1, 0, 3)] renderprog.finish() if settings['lightmapSSS']: progress(0.98, 0.99, "Restoring data") human.material = materialBackup progress(1, None, 'Rendering complete') gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img) mh.changeTask('Rendering', 'Viewer') gui3d.app.statusPersist('Rendering complete')
def Render(settings): progress = Progress.begin() if not mh.hasRenderToRenderbuffer(): settings['dimensions'] = (G.windowWidth, G.windowHeight) if settings['lightmapSSS']: progress(0, 0.05, "Storing data") import material human = G.app.selectedHuman materialBackup = material.Material(human.material) progress(0.05, 0.1, "Projecting lightmaps") diffuse = imgop.Image(data=human.material.diffuseTexture) lmap = projection.mapSceneLighting(settings['scene'], border=human.material.sssRScale) progress(0.1, 0.4, "Applying medium scattering") lmapG = imgop.blurred(lmap, human.material.sssGScale, 13) progress(0.4, 0.7, "Applying high scattering") lmapR = imgop.blurred(lmap, human.material.sssRScale, 13) lmap = imgop.compose([lmapR, lmapG, lmap]) if not diffuse.isEmpty: progress(0.7, 0.8, "Combining textures") lmap = imgop.resized(lmap, diffuse.width, diffuse.height) progress(0.8, 0.9) lmap = imgop.multiply(lmap, diffuse) lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture" progress(0.9, 0.95, "Setting up renderer") human.material.diffuseTexture = lmap human.mesh.configureShading(diffuse=True) human.mesh.shadeless = True progress(0.95, 0.98, None) else: progress(0, 0.99, None) if not mh.hasRenderToRenderbuffer(): # Limited fallback mode, read from screen buffer log.message("Fallback render: grab screen") img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight) alphaImg = None else: # Render to framebuffer object renderprog = Progress() renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering") width, height = settings['dimensions'] log.message("Rendering at %sx%s", width, height) if settings['AA']: width = width * 2 height = height * 2 img = mh.renderToBuffer(width, height) alphaImg = mh.renderAlphaMask(width, height) img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0)) if settings['AA']: renderprog(0.4, 0.99, "AntiAliasing") # Resize to 50% using Qt image class qtImg = img.toQImage() del img # Bilinear filtered resize for anti-aliasing scaledImg = qtImg.scaled( width / 2, height / 2, transformMode=gui.QtCore.Qt.SmoothTransformation) del qtImg img = scaledImg #img = image.Image(scaledImg) # Convert back to MH image #del scaledImg renderprog.finish() if settings['lightmapSSS']: progress(0.98, 0.99, "Restoring data") human.material = materialBackup progress(1, None, 'Rendering complete') gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img) mh.changeTask('Rendering', 'Viewer') gui3d.app.statusPersist('Rendering complete.')
else: # Else, use the first provided definition-writer function # if the texture exists, else the second # (2nd and 3rd map tuple item respectively). func = mapitem[(1 if self.__nonzero__() else 2)] return analyzeDef(func) import image_operations as imgop imgopfuncs = { 'black': lambda img: imgop.getBlack(img) if img else None, 'white': lambda img: imgop.getWhite(img) if img else None, 'blur': lambda img, lev, ker: imgop.blurred(imgop.Image(data=img), lev, ker) if img else None, 'compose': lambda l: imgop.compose(l), 'getChannel': lambda t, c: imgop.getChannel(imgop.Image(data=t), c) if t else None, 'getAlpha': lambda t: imgop.getAlpha(imgop.Image(data=t)) if t else None, 'growMask': lambda t, p: imgop.growMask(imgop.Image(data=t), p) if t else None, 'shrinkMask': lambda t, p: imgop.shrinkMask(imgop.Image(data=t), p) if t else None }