本文整理汇总了Python中panda3d.core.PNMImage.has_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.has_alpha方法的具体用法?Python PNMImage.has_alpha怎么用?Python PNMImage.has_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.has_alpha方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_atlas
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import has_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)