# hello.py: one avatar, waving, read as plain data. # python3 hello.py [--dir ] # Credit: show "Powered by 360sona" where your users see the avatar. import os import sys import sona args = sys.argv[1:] source = ("gate", None) # the gate: item files from 360sona if len(args) >= 4 and args[-2] == "--dir": source = ("dir", args[-1]) args = args[:-2] licence, manifest = args[:2] # SONA_APP_ID unset: the app id your download is made for with sona.Context(app_id=os.environ.get("SONA_APP_ID"), licence=licence, sources=[source]) as ctx: avatar = ctx.add_base64(manifest) while not avatar.settled: ctx.update(1 / 60) if not avatar.ready: sys.exit("the avatar did not load") avatar.play("GenericWave") for _ in range(60): ctx.update(1 / 60) pose = avatar.pose() head = avatar.joint_world("Head") print(len(pose.meshes), "meshes;", "head at", tuple(round(v, 3) for v in head[12:15])) with sona.Headless(ctx) as h: rgba = h.render(avatar, width=480, height=600, clip="GenericWave", time=1.5) with open("avatar.png", "wb") as f: f.write(ctx.png_encode(rgba, 480, 600)) print("saved avatar.png (480 x 600)")