本文整理汇总了Python中panda3d.core.PNMImage.add_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.add_alpha方法的具体用法?Python PNMImage.add_alpha怎么用?Python PNMImage.add_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.add_alpha方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_atlas
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import add_alpha [as 别名]
def generate_atlas(files, dest_dat, dest_png):
entries = []
virtual_atlas_size = 32
all_entries_matched = False
print "Loading", len(files), "entries .."
for verbose_name, source in files:
entries.append(AtlasEntry(verbose_name, source))
entries = sorted(entries, key=lambda a: -a.area)
while not all_entries_matched:
print "Trying to pack into a", virtual_atlas_size, "x", virtual_atlas_size, "atlas .."
packer = LUIAtlasPacker(virtual_atlas_size)
all_entries_matched = True
for entry in entries:
uv = packer.find_position(entry.w, entry.h)
if uv.get_x() < 0:
# print " Not all images matched, trying next power of 2"
all_entries_matched = False
virtual_atlas_size *= 2
break
entry.assigned_pos = uv
print "Matched entries, writing atlas .."
atlas_description_content = ""
dest = PNMImage(virtual_atlas_size, virtual_atlas_size, 4)
for entry in entries:
src = PNMImage(entry.w, entry.h, 4)
entry.tex.store(src)
if not src.has_alpha():
src.add_alpha()
src.alpha_fill(1.0)
dest.copy_sub_image(
src, int(entry.assigned_pos.get_x()), int(entry.assigned_pos.get_y()))
atlas_description_content += "{0} {1} {2} {3} {4}\n".format(
entry.name.replace(" ", "_"),
int(entry.assigned_pos.get_x()),
int(entry.assigned_pos.get_y()),
entry.w, entry.h)
dest.write(dest_png)
with open(dest_dat, "w") as handle:
handle.write(atlas_description_content)
示例2: build
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import add_alpha [as 别名]
def build(self, exit_behav):
self.drv_info = self.props.gameprops.drivers_info
menu_props = self.menu_props
widgets = [Text(_('Select the driver'), pos=(0, .8),
**menu_props.text_args)]
t_a = self.menu_props.text_args.copy()
del t_a['scale']
self.name = Text(_('Write your name:'), pos=(-.1, .6), scale=.06,
align='right', wordwrap=128, **t_a)
self.drivers = []
for row, col in product(range(2), range(4)):
idx = col + row * 4
drv_btn = ImgBtn(
scale=(.24, .24), pos=(-.75 + col * .5, .3 - row * .64),
frame_col=(0, 0, 0, 0),
img=self.props.gameprops.drivers_img.path % idx,
cmd=self.on_click, extra_args=[idx],
**self.menu_props.imgbtn_args)
name = Text(
'',
pos=(-.75 + col * .5, .01 - row * .64),
scale=.046, **t_a)
drv_btn._name_txt = name
widgets += [drv_btn, name]
self.drivers += [widgets[-2]]
sign = lambda pos_x: '\1green\1+\2' if pos_x > 0 else ''
psign = lambda pos_x, sgn=sign: '+' if pos_x == 0 else sgn(pos_x)
def ppcol(x):
return '\1green\1%s\2' % x if x > 0 else '\1red\1%s\2' % x
pcol = lambda x: x if x == 0 else ppcol(x)
lab_lst = [(_('adherence'), .09), (_('speed'), .21),
(_('stability'), .15)]
widgets += list(map(
lambda lab_def: self._add_lab(*(lab_def + (row, col))),
lab_lst))
txt_lst = [(self.drv_info[idx - 1].adherence, .09),
(self.drv_info[idx - 1].speed, .21),
(self.drv_info[idx - 1].stability, .15)]
widgets += list(map(
lambda txt_def: self._add_txt(
*txt_def + (psign, pcol, col, row)),
txt_lst))
self.sel_drv_img = Img(
self.props.gameprops.cars_img % self.mediator.car,
parent=base.a2dBottomLeft, pos=(.3, .4), scale=.28)
instr_txt = _(
'If you use the keyboard, press FIRE to edit the field, then '
"ENTER when you're done")
instr = Text(instr_txt, pos=(1.4, .6), scale=.042, wordwrap=16, **t_a)
widgets += [self.sel_drv_img, self.name, instr]
self.add_widgets(widgets)
ffilterpath = self.eng.curr_path + 'yyagl/assets/shaders/filter.vert'
with open(ffilterpath) as ffilter:
vert = ffilter.read()
shader = load_shader(vert, frag)
if shader:
self.sel_drv_img.set_shader(shader)
self.sel_drv_img.set_transparent()
self.t_s = TextureStage('ts')
self.t_s.set_mode(TextureStage.MDecal)
empty_img = PNMImage(1, 1)
empty_img.add_alpha()
empty_img.alpha_fill(0)
tex = Texture()
tex.load(empty_img)
self.sel_drv_img.set_texture(self.t_s, tex)
ThanksPageGui.build(self, exit_behav=exit_behav)