{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/Project",
  "definitions": {
    "Project": {
      "type": "object",
      "properties": {
        "physicsTimestep": {
          "type": "number",
          "enum": [
            0.002,
            0.005
          ]
        },
        "format": {
          "type": "string",
          "const": "lucky-engine-web"
        },
        "version": {
          "type": "number",
          "enum": [
            1,
            2,
            3
          ]
        },
        "robots": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RobotInstance"
          }
        },
        "table": {
          "type": "boolean"
        },
        "contactSolver": {
          "type": "string",
          "enum": [
            "standard",
            "grasping"
          ]
        },
        "environment": {
          "type": "string",
          "enum": [
            "studio",
            "daylight"
          ]
        },
        "lights": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SceneLight"
          }
        },
        "scripts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Behavior"
          }
        },
        "prefabs": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Prefab"
          }
        },
        "animations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AnimationClip"
          }
        },
        "task": {
          "$ref": "#/definitions/TaskDefinition"
        },
        "name": {
          "type": "string"
        },
        "robot": {
          "type": "object",
          "properties": {
            "position": {
              "$ref": "#/definitions/Vec3"
            },
            "joints": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "gripper": {
              "type": "number"
            }
          },
          "required": [
            "position",
            "joints",
            "gripper"
          ],
          "additionalProperties": false
        },
        "objects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SceneObject"
          }
        },
        "camera": {
          "type": "object",
          "properties": {
            "position": {
              "$ref": "#/definitions/Vec3"
            },
            "target": {
              "$ref": "#/definitions/Vec3"
            },
            "fov": {
              "type": "number"
            }
          },
          "required": [
            "position",
            "target",
            "fov"
          ],
          "additionalProperties": false
        },
        "cameras": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CameraDefinition"
          },
          "description": "Additional recorded cameras (fixed or robot-mounted) beyond the scene camera."
        },
        "scenes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Scene"
          },
          "description": "Multi-scene documents (version 3): every authored scene, ordered."
        },
        "activeScene": {
          "type": "string",
          "description": "Version 3: the id of the scene surfaced by the top-level mirror fields."
        }
      },
      "required": [
        "format",
        "version",
        "name",
        "robot",
        "objects",
        "camera"
      ],
      "additionalProperties": false
    },
    "RobotInstance": {
      "type": "object",
      "properties": {
        "motion": {
          "type": "object",
          "properties": {
            "assetId": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "enabled": {
              "type": "boolean"
            }
          },
          "required": [
            "assetId",
            "name",
            "enabled"
          ],
          "additionalProperties": false,
          "description": "A portable learned motion; enabled policies own this robot during Play/Record."
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "assetId": {
          "type": "string"
        },
        "entry": {
          "type": "string"
        },
        "position": {
          "$ref": "#/definitions/Vec3"
        },
        "rotation": {
          "$ref": "#/definitions/Vec3"
        },
        "initialQpos": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "initialCtrl": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "pandaGripper": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "stiffness": {
                  "type": "number"
                },
                "damping": {
                  "type": "number"
                }
              },
              "required": [
                "stiffness",
                "damping"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ],
          "description": "Optional Panda tendon position-servo tuning. Source joint/control/force limits remain intact."
        }
      },
      "required": [
        "id",
        "name",
        "assetId",
        "entry",
        "position",
        "rotation"
      ],
      "additionalProperties": false
    },
    "Vec3": {
      "type": "array",
      "items": {
        "type": "number"
      },
      "minItems": 3,
      "maxItems": 3
    },
    "SceneLight": {
      "anyOf": [
        {
          "$ref": "#/definitions/AreaLight"
        },
        {
          "$ref": "#/definitions/EditableLight"
        }
      ]
    },
    "AreaLight": {
      "type": "object",
      "properties": {
        "position": {
          "$ref": "#/definitions/Vec3"
        },
        "target": {
          "$ref": "#/definitions/Vec3"
        },
        "width": {
          "type": "number"
        },
        "height": {
          "type": "number"
        },
        "color": {
          "type": "string"
        },
        "intensity": {
          "type": "number"
        }
      },
      "required": [
        "position",
        "target",
        "width",
        "height",
        "color",
        "intensity"
      ],
      "additionalProperties": false
    },
    "EditableLight": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/definitions/LightKind"
        },
        "color": {
          "type": "string"
        },
        "intensity": {
          "type": "number"
        },
        "castShadow": {
          "type": "boolean"
        },
        "position": {
          "$ref": "#/definitions/Vec3"
        },
        "target": {
          "$ref": "#/definitions/Vec3",
          "description": "Look-at point for directional and spot lights."
        },
        "distance": {
          "type": "number",
          "description": "Falloff distance in metres for point/spot lights (0 means no cutoff)."
        },
        "decay": {
          "type": "number",
          "description": "Falloff exponent for point/spot lights."
        },
        "angle": {
          "type": "number",
          "description": "Spot outer cone half-angle in radians."
        },
        "penumbra": {
          "type": "number",
          "description": "Spot penumbra (soft edge), 0–1."
        }
      },
      "required": [
        "id",
        "name",
        "kind",
        "color",
        "intensity",
        "castShadow",
        "position"
      ],
      "additionalProperties": false,
      "description": "An authored, editable light component. Directional and spot lights aim from `position` toward `target`; point lights radiate from `position`. Unlike a legacy `AreaLight` (a daylight/studio world light authored as bare JSON), every editable light carries a stable id and name so it can be selected and edited in the hierarchy."
    },
    "LightKind": {
      "type": "string",
      "enum": [
        "directional",
        "point",
        "spot"
      ],
      "description": "Authorable light component kinds."
    },
    "Behavior": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "entity": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        },
        "source": {
          "type": "string"
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "type": [
              "number",
              "boolean",
              "string"
            ]
          }
        }
      },
      "required": [
        "id",
        "entity",
        "name",
        "enabled",
        "source"
      ],
      "additionalProperties": false
    },
    "Prefab": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SceneObject"
          }
        },
        "scripts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Behavior"
          },
          "description": "Behaviors attached to saved nodes; ownership is remapped on instantiation."
        }
      },
      "required": [
        "id",
        "name",
        "nodes"
      ],
      "additionalProperties": false,
      "description": "A saved, reusable subtree: the root node first, then every descendant, with transforms stored relative to the root so the assembly can be placed anywhere. Node `parentId` references another node in the same prefab."
    },
    "SceneObject": {
      "type": "object",
      "properties": {
        "mesh": {
          "anyOf": [
            {
              "$ref": "#/definitions/GeneratedMesh"
            },
            {
              "type": "null"
            }
          ],
          "description": "Blender-authored visual and normalized compound collision geometry."
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "shape": {
          "$ref": "#/definitions/Shape"
        },
        "position": {
          "$ref": "#/definitions/Vec3"
        },
        "rotation": {
          "$ref": "#/definitions/Vec3"
        },
        "size": {
          "$ref": "#/definitions/Vec3"
        },
        "color": {
          "type": "string"
        },
        "baseColor": {
          "type": [
            "string",
            "null"
          ],
          "description": "Direct material edit: an authored base-color tint for glTF-backed materials, distinct from the primitive/proxy `color`. Applied only when present, so objects whose `color` was authored for the collision/primitve proxy before a visual was attached are never re-tinted."
        },
        "finish": {
          "$ref": "#/definitions/Finish"
        },
        "roughness": {
          "type": "number",
          "description": "Direct material edit: 0–1 override of the finish/surface-derived PBR values."
        },
        "metalness": {
          "type": "number"
        },
        "texture": {
          "type": [
            "string",
            "null"
          ],
          "description": "Albedo texture layered over the base color; validated against TEXTURES."
        },
        "collision": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "auto",
            "primitive",
            null
          ],
          "description": "Auto uses fitted collision assets when available; primitive is an explicit override."
        },
        "trigger": {
          "type": "boolean",
          "description": "A fixed, non-solid volume queried by ctx.onTrigger."
        },
        "surface": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "oak",
            "walnut",
            "marble",
            "plaster",
            "linen",
            null
          ]
        },
        "visual": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "plant",
            "herbs",
            "apple",
            "bowl",
            "board",
            "mug",
            "plate",
            "pendant",
            "stool-back",
            "pot",
            "cabinet-door",
            "kettle",
            null
          ]
        },
        "mass": {
          "type": "number"
        },
        "friction": {
          "type": "number"
        },
        "fixed": {
          "type": "boolean"
        },
        "parentId": {
          "type": [
            "string",
            "null"
          ],
          "description": "Authored transforms remain in world coordinates. Attached parts move rigidly with their root."
        },
        "joint": {
          "anyOf": [
            {
              "$ref": "#/definitions/ObjectJoint"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "name",
        "shape",
        "position",
        "rotation",
        "size",
        "color",
        "mass",
        "friction",
        "fixed"
      ],
      "additionalProperties": false
    },
    "GeneratedMesh": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "hulls": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/MeshHull"
          }
        }
      },
      "required": [
        "id",
        "source",
        "hulls"
      ],
      "additionalProperties": false
    },
    "MeshHull": {
      "type": "object",
      "properties": {
        "vertices": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "faces": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "volume": {
          "type": "number"
        }
      },
      "required": [
        "vertices",
        "faces",
        "volume"
      ],
      "additionalProperties": false,
      "description": "Portable, normalized convex collision pieces belonging to a generated visual asset."
    },
    "Shape": {
      "type": "string",
      "enum": [
        "box",
        "sphere",
        "cylinder",
        "empty"
      ]
    },
    "Finish": {
      "type": "string",
      "enum": [
        "matte",
        "satin",
        "metal",
        "gloss"
      ]
    },
    "ObjectJoint": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "hinge",
            "slide"
          ]
        },
        "axis": {
          "$ref": "#/definitions/Vec3"
        },
        "anchor": {
          "$ref": "#/definitions/Vec3"
        },
        "range": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "damping": {
          "type": "number"
        },
        "friction": {
          "type": "number"
        }
      },
      "required": [
        "type",
        "axis",
        "anchor",
        "range",
        "damping",
        "friction"
      ],
      "additionalProperties": false
    },
    "AnimationClip": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "entity": {
          "type": "string",
          "description": "Authored entity: a free primitive for `transform`, a robot for `joint`."
        },
        "target": {
          "$ref": "#/definitions/AnimationTarget"
        },
        "loop": {
          "type": "boolean"
        },
        "keyframes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AnimationKeyframe"
          }
        }
      },
      "required": [
        "id",
        "name",
        "entity",
        "target",
        "keyframes"
      ],
      "additionalProperties": false
    },
    "AnimationTarget": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "transform"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "joint"
            },
            "joint": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "joint"
          ],
          "additionalProperties": false
        }
      ]
    },
    "AnimationKeyframe": {
      "type": "object",
      "properties": {
        "time": {
          "type": "number",
          "description": "Seconds on the clip's local timeline. Strictly increasing, >= 0."
        },
        "value": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "description": "Component values: [x, y, z] for a transform, [v] for a joint target."
        }
      },
      "required": [
        "time",
        "value"
      ],
      "additionalProperties": false
    },
    "TaskDefinition": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "observation": {
          "$ref": "#/definitions/TaskObservationComponent"
        },
        "reward": {
          "$ref": "#/definitions/TaskRewardComponent"
        },
        "termination": {
          "$ref": "#/definitions/TaskTerminationComponent"
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false,
      "description": "A reusable task definition. Its authored components run every physics step while scripts are live and are saved in the portable project."
    },
    "TaskObservationComponent": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string"
        },
        "shape": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      },
      "required": [
        "source",
        "shape"
      ],
      "additionalProperties": false,
      "description": "A task's observation component: an authored `observe(ctx)` function plus the exact value shape it must return. A wrong-shaped observation (a different number of finite values than the shape describes) is rejected with an error rather than silently padded, truncated or coerced."
    },
    "TaskRewardComponent": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string"
        },
        "shape": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      },
      "required": [
        "source",
        "shape"
      ],
      "additionalProperties": false,
      "description": "A task's reward component: an authored `reward(ctx)` function plus the exact value shape it must return. It runs every 2 ms physics step; the validated measured values are accumulated and written into the recorded dataset's metadata."
    },
    "TaskTerminationComponent": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string"
        }
      },
      "required": [
        "source"
      ],
      "additionalProperties": false,
      "description": "A task's termination component: an authored `done(ctx)` function that returns false while the episode continues, or `{ success, reason }` to finish it."
    },
    "CameraDefinition": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Stable id, used as the recorded camera key (e.g. 'gripper_cam')."
        },
        "name": {
          "type": "string"
        },
        "position": {
          "$ref": "#/definitions/Vec3",
          "description": "Fixed: world pose. Mounted: offset in the mounted body's local frame."
        },
        "target": {
          "$ref": "#/definitions/Vec3"
        },
        "up": {
          "$ref": "#/definitions/Vec3",
          "description": "World up for a fixed camera; body-local up when mounted. Defaults to +Z."
        },
        "fov": {
          "type": "number",
          "description": "Vertical field of view in degrees."
        },
        "mount": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "robot": {
                  "type": "string"
                },
                "body": {
                  "type": "string"
                }
              },
              "required": [
                "robot",
                "body"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ],
          "description": "Attach to a robot instance body; when set, position/target become body-frame offsets."
        }
      },
      "required": [
        "id",
        "name",
        "position",
        "target",
        "fov"
      ],
      "additionalProperties": false,
      "description": "An additional recorded camera beyond the primary scene camera (`camera`). A fixed camera records from its authored world pose. A robot-mounted camera is authored as an offset in the mounted body's local frame and records from the body's live world pose each frame."
    },
    "Scene": {
      "type": "object",
      "properties": {
        "physicsTimestep": {
          "type": "number",
          "enum": [
            0.002,
            0.005
          ]
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "robots": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RobotInstance"
          }
        },
        "table": {
          "type": "boolean"
        },
        "contactSolver": {
          "type": "string",
          "enum": [
            "standard",
            "grasping"
          ]
        },
        "environment": {
          "type": "string",
          "enum": [
            "studio",
            "daylight"
          ]
        },
        "lights": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SceneLight"
          }
        },
        "scripts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Behavior"
          }
        },
        "prefabs": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Prefab"
          },
          "description": "Authoring libraries and task definitions belong to their scene."
        },
        "animations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AnimationClip"
          }
        },
        "task": {
          "$ref": "#/definitions/TaskDefinition"
        },
        "objects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SceneObject"
          }
        },
        "camera": {
          "type": "object",
          "properties": {
            "position": {
              "$ref": "#/definitions/Vec3"
            },
            "target": {
              "$ref": "#/definitions/Vec3"
            },
            "fov": {
              "type": "number"
            }
          },
          "required": [
            "position",
            "target",
            "fov"
          ],
          "additionalProperties": false
        },
        "cameras": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CameraDefinition"
          },
          "description": "Additional recorded cameras (fixed or robot-mounted) beyond the scene camera."
        }
      },
      "required": [
        "id",
        "name",
        "objects",
        "camera"
      ],
      "additionalProperties": false,
      "description": "One authored scene: every per-scene field except the legacy solo-robot pose."
    }
  }
}
