def AddVertsToVB( image_name, region_type, atlases, xoff, yoff, zoff, VB, sampleroffset = 0 ):
    numverts = 0

    for atlas_idx in range( len( atlases ) ):
        atlas = atlases[atlas_idx]
        bboxes = atlas.bboxes
        src_images = atlas.src_images

        sampler = atlas_idx + sampleroffset

        imsizex = float(atlas.mips[0].im.size[0])
        imsizey = float(atlas.mips[0].im.size[1])

        for img in src_images:
            if img.name != image_name:
                continue

            src_regions = None

            if region_type == "alpha":
                src_regions = img.regions.alpha
            elif region_type == "opaque":
                src_regions = img.regions.opaque

            if not src_regions:
                continue

            dest_bbox = bboxes[ img.name ]

            # new_img = Image.new( "RGBA", img.size )
            # for region in img.regions.opaque:
            #     cropped = img.crop( ( region.x, region.y, region.x + region.w, region.y + region.h ) )
            #     new_img.paste( cropped, ( region.x, region.y, region.x + region.w, region.y + region.h ) )
            # new_img.save( "test.png" )
            # sys.exit ( 5 )

            for region in src_regions:
                assert region.x <= img.size[0]
                assert region.y <= img.size[1]
                assert region.x + region.w <= img.size[0]
                assert region.y + region.h <= img.size[1]

                left = xoff + region.x
                right = left + region.w

                top = yoff + region.y
                bottom = top + region.h

                z = zoff

                umin = max( 0.0, min( 1.0, ( dest_bbox.x + region.x ) / imsizex ) )
                umax = max( 0.0, min( 1.0, ( dest_bbox.x + region.x + region.w ) / imsizex ) )
                vmin = max( 0.0, min( 1.0, 1 - ( dest_bbox.y + region.y ) / imsizey ) )
                vmax = max( 0.0, min( 1.0, 1 - ( dest_bbox.y + region.y + region.h ) / imsizey ) )

                #print( umin, umax, vmin, vmax )

                assert 0 <= umin and umin <= 1
                assert 0 <= umax and umax <= 1
                assert 0 <= vmin and vmin <= 1
                assert 0 <= vmax and vmax <= 1


                VB.append(Vert(left, top , z, umin, vmin, sampler))
                VB.append(Vert(right, top, z, umax, vmin, sampler))
                VB.append(Vert(left, bottom, z, umin, vmax, sampler))
                VB.append(Vert(right, top, z, umax, vmin, sampler))
                VB.append(Vert(right, bottom, z, umax, vmax, sampler))
                VB.append(Vert(left, bottom, z, umin, vmax, sampler))

                numverts += 6

    return numverts
dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/unix/mod_tools/tools/scripts/buildanimation.py/AddVertsToVB/original