def ExportBuild(endianstring, inzip, buildxml, outzip, antialias, platform, textureformat, hardalphatextureformat, force, ignore_exceptions):
    hashcollection = {}

    doc = xml.dom.minidom.parseString(buildxml)
    
    imnames = {frame.attributes["image"].value.encode('ascii') for frame in doc.getElementsByTagName("Frame")}

    images = []

    for imname in imnames:
        img = Image.open( StringIO( inzip.read( imname + ".png" ) ) )
        img.name = imname
        img.regions = optimizeimage.GetImageRegions(img, 32)

        images.append( img )
    
    atlases = AtlasImages( images, "atlas", outzip, 2048, antialias, platform, textureformat, hardalphatextureformat, force, ignore_exceptions)

    opaqueverts = []
    alphaverts = []

    outfile = StringIO()

    outfile.write(struct.pack(endianstring +  'cccci', 'B', 'I', 'L', 'D', BUILDVERSION))

    outfile.write(struct.pack(endianstring + 'I', len(doc.getElementsByTagName("Symbol"))))
    outfile.write(struct.pack(endianstring + 'I', len(doc.getElementsByTagName("Frame"))))

    buildname = doc.getElementsByTagName("Build")[0].attributes["name"].value.encode('ascii')
    buildname = os.path.splitext(buildname)[0]
    outfile.write(struct.pack(endianstring + 'i' + str(len(buildname)) + 's', len(buildname), buildname))

    #write out the number of atlases:
    outfile.write(struct.pack(endianstring + 'I', len(atlases)))
    for atlas_idx in range( len( atlases ) ):
        atlasdata = atlases[ atlas_idx ]
        mip = atlasdata.mips[0]
        name = mip.name + ".tex"

        outfile.write(struct.pack(endianstring + 'i' + str(len(name)) + 's', len(name), name))

    symbol_nodes = sorted(doc.getElementsByTagName("Symbol"), key=lambda x: strhash(x.attributes["name"].value.encode('ascii'), hashcollection))

    for symbol_node in symbol_nodes:#doc.getElementsByTagName("Symbol"):
        symbolname = symbol_node.attributes["name"].value.encode('ascii')
        outfile.write(struct.pack(endianstring + 'I', strhash(symbolname, hashcollection)))
        outfile.write(struct.pack(endianstring + 'I', len(symbol_node.getElementsByTagName("Frame"))))

        for frame_node in symbol_node.getElementsByTagName("Frame"):
            framenum = int(frame_node.attributes["framenum"].value)
            duration = int(frame_node.attributes["duration"].value)

            w = float(frame_node.attributes["w"].value)
            h = float(frame_node.attributes["h"].value)
            x = float(frame_node.attributes["x"].value)
            y = float(frame_node.attributes["y"].value)

            imagename = frame_node.attributes["image"].value.encode('ascii')

            xoff = x - w/2
            yoff = y - h/2
            z = 0

            alphaidx = len(alphaverts)
            alphacount = AddVertsToVB( imagename, "alpha", atlases, xoff, yoff, z, alphaverts )
            
            #opaqueidx = len(opaqueverts)
            alphacount += AddVertsToVB( imagename, "opaque", atlases, xoff, yoff, z, alphaverts )

            outfile.write(struct.pack(endianstring + 'I', framenum))
            outfile.write(struct.pack(endianstring + 'I', duration))
            outfile.write(struct.pack(endianstring + 'ffff', x,y,w,h))
            
            outfile.write(struct.pack(endianstring + 'I', alphaidx))
            outfile.write(struct.pack(endianstring + 'I', alphacount))
            #outfile.write(struct.pack(endianstring + 'I', opaqueidx))
            #outfile.write(struct.pack(endianstring + 'I', opaquecount))

    outfile.write(struct.pack(endianstring + 'I', len(alphaverts)))
    for vert in alphaverts:
        outfile.write(struct.pack(endianstring + 'ffffff', vert.x, vert.y, vert.z, vert.u, vert.v, vert.w))
    #outfile.write(struct.pack(endianstring + 'I', len(opaqueverts)))
    #for vert in opaqueverts:
    #    outfile.write(struct.pack(endianstring + 'ffffff', vert.x, vert.y, vert.z, vert.u, vert.v, vert.w))
    
    #write out a lookup table of the pre-hashed strings
    outfile.write(struct.pack(endianstring + 'I', len(hashcollection)))
    for hash_idx,name in hashcollection.iteritems():
        outfile.write(struct.pack(endianstring + 'I', hash_idx))
        outfile.write(struct.pack(endianstring + 'i' + str(len(name)) + 's', len(name), name))

    info = zipfile.ZipInfo( "build.bin", date_time=ZIP_ZERO_TIME )
    info.compress_type = zipfile.ZIP_DEFLATED
    info.external_attr = 0644 << 16L
    outzip.writestr(info, outfile.getvalue())
dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/unix/mod_tools/tools/scripts/buildanimation.py/ExportBuild/original