本文整理汇总了Python中direct.filter.CommonFilters.CommonFilters.setCartoonInk方法的典型用法代码示例。如果您正苦于以下问题:Python CommonFilters.setCartoonInk方法的具体用法?Python CommonFilters.setCartoonInk怎么用?Python CommonFilters.setCartoonInk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类direct.filter.CommonFilters.CommonFilters
的用法示例。
在下文中一共展示了CommonFilters.setCartoonInk方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toggleToonShading
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
def toggleToonShading(self, checked):
filters = CommonFilters(base.win, base.cam)
if checked == True:
filters.setCartoonInk()
else:
filters.delCartoonInk()
示例2: filters
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
class filters():
def __init__(self):
self.filters = CommonFilters(base.win, base.cam)
self.initCartoonInk()
def initCartoonInk(self):
self.filters.setCartoonInk(separation= -1)
示例3: ToonMaker
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
class ToonMaker(DirectObject):
def __init__(self):
base.disableMouse()
base.cam.node().getLens().setNear(10.0)
base.cam.node().getLens().setFar(9999999)
camera.setPos(0, -50, 0)
# Check video card capabilities.
if (base.win.getGsg().getSupportsBasicShaders() == 0):
addTitle("Toon Shader: Video driver reports that shaders are not supported.")
return
# Enable a 'light ramp' - this discretizes the lighting,
# which is half of what makes a model look like a cartoon.
# Light ramps only work if shader generation is enabled,
# so we call 'setShaderAuto'.
tempnode = NodePath(PandaNode("temp node"))
tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4))
tempnode.setShaderAuto()
base.cam.node().setInitialState(tempnode.getState())
# Use class 'CommonFilters' to enable a cartoon inking filter.
# This can fail if the video card is not powerful enough, if so,
# display an error and exit.
self.separation = 1 # Pixels
self.filters = CommonFilters(base.win, base.cam)
filterok = self.filters.setCartoonInk(separation=self.separation)
if (filterok == False):
addTitle("Toon Shader: Video card not powerful enough to do image postprocessing")
return
# Create a non-attenuating point light and an ambient light.
plightnode = PointLight("point light")
plightnode.setAttenuation(Vec3(1,0,0))
plight = render.attachNewNode(plightnode)
plight.setPos(30,-50,0)
alightnode = AmbientLight("ambient light")
alightnode.setColor(Vec4(0.8,0.8,0.8,1))
alight = render.attachNewNode(alightnode)
render.setLight(alight)
render.setLight(plight)
# Panda contains a built-in viewer that lets you view the
# results of all render-to-texture operations. This lets you
# see what class CommonFilters is doing behind the scenes.
self.accept("v", base.bufferViewer.toggleEnable)
self.accept("V", base.bufferViewer.toggleEnable)
base.bufferViewer.setPosition("llcorner")
self.accept("s", self.filters.manager.resizeBuffers)
# These allow you to change cartooning parameters in realtime
self.accept("escape", sys.exit, [0])
示例4: ToonMaker
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
class ToonMaker(ShowBase):
def __init__(self):
# Initialize the ShowBase class from which we inherit, which will
# create a window and set up everything we need for rendering into it.
ShowBase.__init__(self)
self.disableMouse()
self.cam.node().getLens().setNear(10.0)
self.cam.node().getLens().setFar(200.0)
camera.setPos(0, -50, 0)
# Check video card capabilities.
if not self.win.getGsg().getSupportsBasicShaders():
addTitle("Toon Shader: Video driver reports that Cg shaders are not supported.")
return
# Enable a 'light ramp' - this discretizes the lighting,
# which is half of what makes a model look like a cartoon.
# Light ramps only work if shader generation is enabled,
# so we call 'setShaderAuto'.
tempnode = NodePath(PandaNode("temp node"))
tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4))
tempnode.setShaderAuto()
self.cam.node().setInitialState(tempnode.getState())
# Use class 'CommonFilters' to enable a cartoon inking filter.
# This can fail if the video card is not powerful enough, if so,
# display an error and exit.
self.separation = 1 # Pixels
self.filters = CommonFilters(self.win, self.cam)
filterok = self.filters.setCartoonInk(separation=self.separation)
if (filterok == False):
addTitle(
"Toon Shader: Video card not powerful enough to do image postprocessing")
return
# Show instructions in the corner of the window.
self.title = addTitle(
"Panda3D: Tutorial - Toon Shading with Normals-Based Inking")
self.inst1 = addInstructions(0.06, "ESC: Quit")
self.inst2 = addInstructions(0.12, "Up/Down: Increase/Decrease Line Thickness")
self.inst3 = addInstructions(0.18, "V: View the render-to-texture results")
# Load a dragon model and animate it.
self.character = Actor()
self.character.loadModel('models/nik-dragon')
self.character.reparentTo(render)
self.character.loadAnims({'win': 'models/nik-dragon'})
self.character.loop('win')
self.character.hprInterval(15, (360, 0, 0)).loop()
# Create a non-attenuating point light and an ambient light.
plightnode = PointLight("point light")
plightnode.setAttenuation((1, 0, 0))
plight = render.attachNewNode(plightnode)
plight.setPos(30, -50, 0)
alightnode = AmbientLight("ambient light")
alightnode.setColor((0.8, 0.8, 0.8, 1))
alight = render.attachNewNode(alightnode)
render.setLight(alight)
render.setLight(plight)
# Panda contains a built-in viewer that lets you view the
# results of all render-to-texture operations. This lets you
# see what class CommonFilters is doing behind the scenes.
self.accept("v", self.bufferViewer.toggleEnable)
self.accept("V", self.bufferViewer.toggleEnable)
self.bufferViewer.setPosition("llcorner")
self.accept("s", self.filters.manager.resizeBuffers)
# These allow you to change cartooning parameters in realtime
self.accept("escape", sys.exit, [0])
self.accept("arrow_up", self.increaseSeparation)
self.accept("arrow_down", self.decreaseSeparation)
def increaseSeparation(self):
self.separation = self.separation * 1.11111111
print("separation: %f" % (self.separation))
self.filters.setCartoonInk(separation=self.separation)
def decreaseSeparation(self):
self.separation = self.separation * 0.90000000
print("separation: %f" % (self.separation))
self.filters.setCartoonInk(separation=self.separation)
示例5: World
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
#.........这里部分代码省略.........
def createLights(self):
"""Create an ambient light and a spotlight for shadows"""
self.render.clearLight()
alight = AmbientLight("ambientLight")
alight.setColor(Vec4(0.7, 0.7, 0.7, 1))
alightNP = self.worldRender.attachNewNode(alight)
self.worldRender.setLight(alightNP)
# Create a directional light for shadows
dlight = DirectionalLight("dLight")
dlight.setColor(Vec4(0.6, 0.6, 0.6, 1))
dlight.setShadowCaster(True, 1024, 1024)
dlight.getLens().setNearFar(1, 15)
dlight.getLens().setFilmSize(128, 128)
dlightNP = self.worldRender.attachNewNode(dlight)
dlightNP.setPos(0, 0, 10)
dlightNP.lookAt(0, 0, 0)
self.worldRender.setLight(dlightNP)
def setupShaders(self):
"""
Creates shaders for cartoon outline and enables
shaders for shadows
"""
if self.base.win.getGsg().getSupportsBasicShaders() == 0:
return
thickness = 1.0
for camera in self.playerCameras:
self.filters = CommonFilters(self.base.win, camera)
filterEnabled = self.filters.setCartoonInk(separation=thickness)
if filterEnabled == False:
# Couldn't enable filter, video card probably
# doesn't support filter
return
self.worldRender.setShaderAuto()
def initialiseCollisionInfo(self):
"""
Sets up information required to later check for collisions
"""
self.previousContactForce = defaultdict(float)
self.collisionDetected = defaultdict(bool)
# List of node paths that we want to check for collisions on,
# with information about the collision sounds to play
self.collisionObjects = dict((v.rigidNode, v.collisionSound) for v in self.playerVehicles)
self.collisionObjects.update(self.level.collisionObjects)
# For assigning points etc, keep track of the player that
# controls each vehicle
self.vehicleControllers = dict(
(vehicle.rigidNode, player) for vehicle, player in zip(self.playerVehicles, self.playerControllers)
)
def checkCollisions(self, dt):
"""
Check to see what objects have collided and take actions
Eg. play sounds, update player points
"""
示例6: Dockit
# 需要导入模块: from direct.filter.CommonFilters import CommonFilters [as 别名]
# 或者: from direct.filter.CommonFilters.CommonFilters import setCartoonInk [as 别名]
#.........这里部分代码省略.........
self.residues_objects = []
for residue in residues:
r = loader.loadModel("models/atom_sphere")
x,y,z = residue.get_center_coordinates()
r.setPos(x, y, z)
r.setScale(4.0 / Dockit.radius_scale)
r.setColor(LVecBase4f(1.0, 0.59, 0.0, 1.0))
r.setColorScale(LVecBase4f(1, 1, 1, 1))
r.reparentTo(node)
node.flattenStrong()
def apply_color(self, a3d, atom, color_map):
''' Apply a color map to the element '''
if isinstance(color_map, BFactor):
color = color_map.get_color_by_bfactor(atom.get_b_factor())
else:
color = color_map.get_color_by_element(atom.get_element())
red, green, blue, alpha = color.get_rgba()
a3d.setColor(LVecBase4f(red, green, blue, alpha))
a3d.setColorScale(LVecBase4f(1, 1, 1, 1))
def toggle_cartoon(self):
''' Use Cartoon ink filter '''
self.cartoon = not self.cartoon
if self.cartoon:
tempnode = NodePath(PandaNode("temp node"))
tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.4, 0.6))
tempnode.setShaderAuto()
base.cam.node().setInitialState(tempnode.getState())
self.separation = 1.3 # Pixels
self.filters = CommonFilters(base.win, base.cam)
self.filters.setCartoonInk(separation=self.separation)
# Currently using MAuto antialias, uncomment to use different
#render.setAntialias(AntialiasAttrib.MBetter)
#self.filters.finalQuad.setAntialias(AntialiasAttrib.MBetter)
else:
self.filters.cleanup()
base.cam.node().setInitialState(self.alight.getState())
def toggle_control_structures(self):
''' Show control structures as lights and center nodes and bounds if required '''
self.structures = not self.structures
for light in self.lights:
if not self.structures:
light.detachNode()
else:
light.reparentTo(render)
if self.structures:
self.receptor_node.showBounds()
self.ligand_node.showBounds()
self.center.reparentTo(render)
print "Number of multisamples available: %d" % self.multisamples
else:
self.receptor_node.hideBounds()
self.ligand_node.hideBounds()
self.center.detachNode()
def center_proteins(self):
''' Move receptor and ligand to a centered position depending on its size '''
# Center the receptor
receptor_radius = self.receptor_node.getBounds().getRadius()