"""JANCTION Render examples 21 and 22: an alarm clock, a real 3D model from Poly Haven (CC0, "alarm_clock_01").

Reproduce: render_final(scene_url="https://render.janction.jp/samples/ex21_product_clock.py",
                        asset_urls=["polyhaven:alarm_clock_01"], preset="product",
                        orbit_elevation=25, orbit_distance=0.85)      # 4 studio shots, 1440x1440
           render_final(scene_url="https://render.janction.jp/samples/ex21_product_clock.py",
                        asset_urls=["polyhaven:alarm_clock_01"], preset="turntable",
                        orbit_elevation=25, orbit_distance=0.85)      # 360-degree MP4
No files to upload: the service fetches the model by name. The model is CC0 (https://polyhaven.com/a/alarm_clock_01).
The preset lights the studio and orbits the camera (25 degrees above, a little closer than the default); jr_assets.frame_camera() fits the model in the frame.
"""
import bpy
import jr_assets  # provided by the service in front of every scene script

for ob in list(bpy.data.objects):
    bpy.data.objects.remove(ob, do_unlink=True)

jr_assets.import_model("alarm_clock_01")            # about 23 x 17 x 17 cm, textures included

# the glTF's glass uses the (JPEG, no alpha) colour texture, so it imports opaque and hides the dial: make it clear glass
for m in bpy.data.materials:
    if "glass" in m.name.lower() and m.use_nodes:
        g = next(n for n in m.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
        for link in list(g.inputs["Base Color"].links) + list(g.inputs["Alpha"].links):
            m.node_tree.links.remove(link)
        g.inputs["Base Color"].default_value = (1.0, 1.0, 1.0, 1.0)
        g.inputs["Roughness"].default_value = 0.02
        g.inputs["Alpha"].default_value = 0.12

# a soft light-grey floor that catches the shadow (frame_camera ignores floors)
bpy.ops.mesh.primitive_plane_add(size=60, location=(0.0, 0.0, 0.0))     # wide enough that its edge stays out of frame
floor = bpy.context.active_object
floor.name = "Floor"
mat = bpy.data.materials.new("Floor")
mat.use_nodes = True
bsdf = next(n for n in mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
bsdf.inputs["Base Color"].default_value = (0.80, 0.80, 0.82, 1.0)
bsdf.inputs["Roughness"].default_value = 0.65
floor.data.materials.append(mat)

cam = jr_assets.frame_camera(margin=1.25)    # adds the camera and points it at the model
bpy.context.scene.camera = cam
