Loading Spine Player...
Rendered with the official
Spine Web Player.
Use the controls to switch animations, adjust speed, and toggle debug views.
"""
return html
def main():
parser = argparse.ArgumentParser(
description="Generate a self-contained HTML preview using the official Spine Web Player"
)
parser.add_argument("--skeleton", required=True, help="Spine JSON or binary (.skel) file")
parser.add_argument("--atlas", required=True, help="Spine .atlas file")
parser.add_argument("--atlas-image", default=None,
help="Atlas PNG image (auto-detected from atlas if omitted)")
parser.add_argument("--output", default="preview.html", help="Output HTML file")
parser.add_argument("--animation", default=None, help="Default animation to play")
parser.add_argument("--skin", default=None, help="Default skin")
parser.add_argument("--background", default="#1a1a2eff", help="Background color (hex RGBA)")
parser.add_argument("--title", default="Spine Animation Preview", help="Page title")
parser.add_argument("--no-controls", action="store_true", help="Hide player controls")
args = parser.parse_args()
# Verify files exist
for path, name in [(args.skeleton, "Skeleton"), (args.atlas, "Atlas")]:
if not os.path.exists(path):
print(f"ERROR: {name} file not found: {path}")
sys.exit(1)
# Find atlas images
atlas_images = []
if args.atlas_image:
img_name = os.path.basename(args.atlas_image)
atlas_images.append((img_name, args.atlas_image))
else:
atlas_images = find_atlas_images(args.atlas)
if not atlas_images:
print("ERROR: No atlas images found. Specify --atlas-image or ensure atlas references valid PNGs.")
sys.exit(1)
print(f"Skeleton: {args.skeleton}")
print(f"Atlas: {args.atlas}")
for img_name, img_path in atlas_images:
print(f"Atlas image: {img_name} ({os.path.getsize(img_path) / 1024:.1f} KB)")
# Generate HTML
print("Generating HTML with embedded Spine Web Player...")
html = generate_html(
skeleton_path=args.skeleton,
atlas_path=args.atlas,
atlas_images=atlas_images,
animation=args.animation,
skin=args.skin,
bg_color=args.background,
show_controls=not args.no_controls,
title=args.title,
)
with open(args.output, "w") as f:
f.write(html)
size_kb = os.path.getsize(args.output) / 1024
print(f"\nPreview saved: {args.output} ({size_kb:.1f} KB)")
print("Open in a browser to see your animation (requires internet for the Spine Player CDN).")
if __name__ == "__main__":
main()
```