{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://hypersoniclabs.com/schemas/helix.city-source/1.json",
    "title": "helix.city-source/1 manifest (city-source.json); row shapes of the layer files are in $defs",
    "description": "The neutral city format. The validator (src/city/source/validate.ts) is authoritative: it also checks what a schema cannot (ring winding and self-intersection, graph references, extents, hashes). Winding: outer rings are counter-clockwise seen from +Y (negative shoelace sum over [x, z]); holes clockwise. Units are scene metres; x east, y up, z south.",
    "$ref": "#/$defs/manifest",
    "$defs": {
        "vec2": {
            "type": "array",
            "items": {
                "type": "number"
            },
            "minItems": 2,
            "maxItems": 2
        },
        "ring": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/vec2"
            },
            "minItems": 3
        },
        "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*:[A-Za-z0-9_.#~-]+$"
        },
        "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
        },
        "colour": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "src": {
            "type": "object",
            "additionalProperties": {
                "type": [
                    "string",
                    "number",
                    "boolean",
                    "null"
                ]
            }
        },
        "roof": {
            "type": "object",
            "required": [
                "shape"
            ],
            "additionalProperties": false,
            "properties": {
                "shape": {
                    "enum": [
                        "flat",
                        "gabled",
                        "hipped",
                        "pyramidal",
                        "skillion",
                        "dome",
                        "mansard"
                    ]
                },
                "heightM": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                },
                "directionDeg": {
                    "type": "number",
                    "minimum": 0,
                    "exclusiveMaximum": 360
                },
                "colour": {
                    "$ref": "#/$defs/colour"
                }
            }
        },
        "manifest": {
            "type": "object",
            "required": [
                "schema",
                "id",
                "frame",
                "layers",
                "provenance",
                "defaults"
            ],
            "additionalProperties": false,
            "properties": {
                "schema": {
                    "const": "helix.city-source/1"
                },
                "id": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
                },
                "frame": {
                    "type": "object",
                    "required": [
                        "units",
                        "axes",
                        "projection",
                        "verticalDatum",
                        "originAltitudeM",
                        "boundsXZ"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "units": {
                            "const": "meters"
                        },
                        "axes": {
                            "const": "helix"
                        },
                        "projection": {
                            "oneOf": [
                                {
                                    "type": "object",
                                    "required": [
                                        "kind",
                                        "originLonLat",
                                        "ellipsoid",
                                        "k0"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "local-tm"
                                        },
                                        "originLonLat": {
                                            "$ref": "#/$defs/vec2"
                                        },
                                        "ellipsoid": {
                                            "const": "WGS84"
                                        },
                                        "k0": {
                                            "type": "number",
                                            "exclusiveMinimum": 0
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "kind",
                                        "seaLevelMetres",
                                        "mirror"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "cs2"
                                        },
                                        "seaLevelMetres": {
                                            "type": "number"
                                        },
                                        "mirror": {
                                            "const": "x,y,-z"
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "kind"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "synthetic"
                                        }
                                    }
                                }
                            ]
                        },
                        "verticalDatum": {
                            "enum": [
                                "EGM2008",
                                "copernicus",
                                "cs2-sea-level",
                                "none"
                            ]
                        },
                        "originAltitudeM": {
                            "type": "number"
                        },
                        "boundsXZ": {
                            "type": "array",
                            "minItems": 2,
                            "maxItems": 2,
                            "items": {
                                "$ref": "#/$defs/vec2"
                            }
                        }
                    }
                },
                "layers": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "roads": {
                            "type": "object",
                            "required": [
                                "uri",
                                "sha256",
                                "count"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "uri": {
                                    "enum": [
                                        "roads.json",
                                        "roads.json.gz"
                                    ]
                                },
                                "sha256": {
                                    "$ref": "#/$defs/sha256"
                                },
                                "count": {
                                    "type": "object",
                                    "required": [
                                        "nodes",
                                        "edges"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "nodes": {
                                            "type": "integer",
                                            "minimum": 0
                                        },
                                        "edges": {
                                            "type": "integer",
                                            "minimum": 0
                                        }
                                    }
                                }
                            }
                        },
                        "buildings": {
                            "type": "object",
                            "required": [
                                "uri",
                                "sha256",
                                "count"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "uri": {
                                    "enum": [
                                        "buildings.ndjson.gz",
                                        "buildings.ndjson"
                                    ]
                                },
                                "sha256": {
                                    "$ref": "#/$defs/sha256"
                                },
                                "count": {
                                    "type": "integer",
                                    "minimum": 0
                                }
                            }
                        },
                        "areas": {
                            "type": "object",
                            "required": [
                                "uri",
                                "sha256",
                                "count"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "uri": {
                                    "enum": [
                                        "areas.json",
                                        "areas.json.gz"
                                    ]
                                },
                                "sha256": {
                                    "$ref": "#/$defs/sha256"
                                },
                                "count": {
                                    "type": "integer",
                                    "minimum": 0
                                }
                            }
                        },
                        "pois": {
                            "type": "object",
                            "required": [
                                "uri",
                                "sha256",
                                "count"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "uri": {
                                    "enum": [
                                        "pois.ndjson.gz",
                                        "pois.ndjson"
                                    ]
                                },
                                "sha256": {
                                    "$ref": "#/$defs/sha256"
                                },
                                "count": {
                                    "type": "integer",
                                    "minimum": 0
                                }
                            }
                        },
                        "overrides": {
                            "type": "object",
                            "required": [
                                "uri",
                                "sha256",
                                "count"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "uri": {
                                    "enum": [
                                        "overrides.json"
                                    ]
                                },
                                "sha256": {
                                    "$ref": "#/$defs/sha256"
                                },
                                "count": {
                                    "type": "integer",
                                    "minimum": 0
                                }
                            }
                        },
                        "terrain": {
                            "oneOf": [
                                {
                                    "type": "object",
                                    "required": [
                                        "kind",
                                        "y"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "flat"
                                        },
                                        "y": {
                                            "type": "number"
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "kind",
                                        "uri",
                                        "sha256"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "dem"
                                        },
                                        "uri": {
                                            "const": "terrain/dem.json"
                                        },
                                        "sha256": {
                                            "$ref": "#/$defs/sha256"
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "required": [
                                        "kind",
                                        "uri"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "kind": {
                                            "const": "terrain-source"
                                        },
                                        "uri": {
                                            "type": "string",
                                            "minLength": 1
                                        },
                                        "sha256": {
                                            "$ref": "#/$defs/sha256"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                },
                "provenance": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "source"
                        ],
                        "properties": {
                            "source": {
                                "type": "string",
                                "minLength": 1
                            }
                        }
                    }
                },
                "defaults": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "region": {
                            "type": "string"
                        },
                        "driveSide": {
                            "enum": [
                                "right",
                                "left"
                            ]
                        },
                        "style": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "roadsDocument": {
            "type": "object",
            "required": [
                "nodes",
                "edges"
            ],
            "additionalProperties": false,
            "properties": {
                "nodes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/roadNode"
                    }
                },
                "edges": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/roadEdge"
                    }
                }
            }
        },
        "roadNode": {
            "type": "object",
            "required": [
                "id",
                "p"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "p": {
                    "$ref": "#/$defs/vec2"
                },
                "y": {
                    "type": "number"
                },
                "control": {
                    "enum": [
                        "signal",
                        "stop",
                        "yield",
                        "roundabout",
                        "none"
                    ]
                },
                "crossing": {
                    "type": "boolean"
                }
            }
        },
        "roadEdge": {
            "type": "object",
            "required": [
                "id",
                "a",
                "b",
                "pts",
                "class"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "a": {
                    "$ref": "#/$defs/id"
                },
                "b": {
                    "$ref": "#/$defs/id"
                },
                "pts": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/vec2"
                    },
                    "minItems": 2
                },
                "ys": {
                    "type": "array",
                    "items": {
                        "type": "number"
                    },
                    "minItems": 2
                },
                "class": {
                    "enum": [
                        "motorway",
                        "trunk",
                        "primary",
                        "secondary",
                        "tertiary",
                        "residential",
                        "service",
                        "living",
                        "pedestrian",
                        "cycleway",
                        "footway",
                        "rail",
                        "tram"
                    ]
                },
                "lanes": {
                    "type": "object",
                    "required": [
                        "forward",
                        "backward"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "forward": {
                            "type": "integer",
                            "minimum": 0
                        },
                        "backward": {
                            "type": "integer",
                            "minimum": 0
                        },
                        "turn": {
                            "type": "string"
                        }
                    }
                },
                "widthM": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 100
                },
                "oneway": {
                    "type": "boolean"
                },
                "ramp": {
                    "type": "boolean"
                },
                "layer": {
                    "type": "integer"
                },
                "structure": {
                    "enum": [
                        "none",
                        "bridge",
                        "tunnel",
                        "embankment"
                    ]
                },
                "sidewalk": {
                    "type": "object",
                    "required": [
                        "left",
                        "right"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "left": {
                            "type": "number",
                            "minimum": 0
                        },
                        "right": {
                            "type": "number",
                            "minimum": 0
                        }
                    }
                },
                "surface": {
                    "enum": [
                        "asphalt",
                        "concrete",
                        "sett",
                        "gravel",
                        "dirt"
                    ]
                },
                "name": {
                    "type": "string"
                },
                "speedKph": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 400
                },
                "src": {
                    "$ref": "#/$defs/src"
                }
            }
        },
        "building": {
            "type": "object",
            "required": [
                "id",
                "ring"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "ring": {
                    "$ref": "#/$defs/ring"
                },
                "holes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/ring"
                    }
                },
                "heightM": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 1000
                },
                "minHeightM": {
                    "type": "number",
                    "minimum": 0
                },
                "levels": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 300
                },
                "minLevel": {
                    "type": "integer",
                    "minimum": 0
                },
                "roof": {
                    "$ref": "#/$defs/roof"
                },
                "use": {
                    "enum": [
                        "residential",
                        "commercial",
                        "office",
                        "retail",
                        "industrial",
                        "civic",
                        "religious",
                        "education",
                        "parking",
                        "other"
                    ]
                },
                "style": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "family": {
                            "type": "string"
                        },
                        "facadeColour": {
                            "$ref": "#/$defs/colour"
                        },
                        "material": {
                            "enum": [
                                "plaster",
                                "brick",
                                "stone",
                                "glass",
                                "concrete",
                                "metal"
                            ]
                        }
                    }
                },
                "parts": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "ring"
                        ],
                        "additionalProperties": false,
                        "properties": {
                            "ring": {
                                "$ref": "#/$defs/ring"
                            },
                            "holes": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/$defs/ring"
                                }
                            },
                            "minHeightM": {
                                "type": "number",
                                "minimum": 0
                            },
                            "heightM": {
                                "type": "number",
                                "exclusiveMinimum": 0
                            },
                            "roof": {
                                "$ref": "#/$defs/roof"
                            }
                        }
                    }
                },
                "mesh": {
                    "oneOf": [
                        {
                            "type": "null"
                        },
                        {
                            "type": "object",
                            "required": [
                                "kind",
                                "prefab"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "kind": {
                                    "const": "cs2-prefab"
                                },
                                "prefab": {
                                    "type": "string",
                                    "minLength": 1
                                },
                                "transform": {
                                    "type": "object",
                                    "additionalProperties": false,
                                    "properties": {
                                        "position": {
                                            "type": "array",
                                            "items": {
                                                "type": "number"
                                            },
                                            "minItems": 3,
                                            "maxItems": 3
                                        },
                                        "yawDeg": {
                                            "type": "number"
                                        },
                                        "scale": {
                                            "type": "number"
                                        }
                                    }
                                }
                            }
                        },
                        {
                            "type": "object",
                            "required": [
                                "kind",
                                "pin"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "kind": {
                                    "const": "package"
                                },
                                "pin": {
                                    "type": "object",
                                    "required": [
                                        "packageId",
                                        "version",
                                        "manifestCid"
                                    ],
                                    "properties": {
                                        "packageId": {
                                            "type": "string"
                                        },
                                        "version": {
                                            "type": "string"
                                        },
                                        "manifestCid": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    ]
                },
                "ground": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "storefront": {
                            "type": "boolean"
                        },
                        "entrances": {
                            "type": "array",
                            "items": {
                                "$ref": "#/$defs/vec2"
                            }
                        }
                    }
                },
                "src": {
                    "$ref": "#/$defs/src"
                }
            }
        },
        "areasDocument": {
            "type": "object",
            "required": [
                "areas",
                "water"
            ],
            "additionalProperties": false,
            "properties": {
                "areas": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "id",
                            "ring",
                            "kind"
                        ],
                        "additionalProperties": false,
                        "properties": {
                            "id": {
                                "$ref": "#/$defs/id"
                            },
                            "ring": {
                                "$ref": "#/$defs/ring"
                            },
                            "holes": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/$defs/ring"
                                }
                            },
                            "kind": {
                                "enum": [
                                    "park",
                                    "grass",
                                    "forest",
                                    "scrub",
                                    "farmland",
                                    "residential",
                                    "commercial",
                                    "industrial",
                                    "parking",
                                    "plaza",
                                    "pitch",
                                    "beach",
                                    "cemetery",
                                    "construction",
                                    "rail"
                                ]
                            },
                            "src": {
                                "$ref": "#/$defs/src"
                            }
                        }
                    }
                },
                "water": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "id",
                            "kind"
                        ],
                        "additionalProperties": false,
                        "properties": {
                            "id": {
                                "$ref": "#/$defs/id"
                            },
                            "kind": {
                                "enum": [
                                    "ocean",
                                    "sea",
                                    "lake",
                                    "river",
                                    "canal",
                                    "pond"
                                ]
                            },
                            "ring": {
                                "$ref": "#/$defs/ring"
                            },
                            "holes": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/$defs/ring"
                                }
                            },
                            "centreline": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/$defs/vec2"
                                },
                                "minItems": 2
                            },
                            "widthM": {
                                "type": "number",
                                "exclusiveMinimum": 0
                            },
                            "levelM": {
                                "type": "number"
                            },
                            "surfaces": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "required": [
                                        "box",
                                        "levelM",
                                        "floorM"
                                    ],
                                    "additionalProperties": false,
                                    "properties": {
                                        "box": {
                                            "type": "array",
                                            "items": {
                                                "type": "number"
                                            },
                                            "minItems": 4,
                                            "maxItems": 4
                                        },
                                        "levelM": {
                                            "type": "number"
                                        },
                                        "floorM": {
                                            "type": "number"
                                        }
                                    }
                                }
                            },
                            "src": {
                                "$ref": "#/$defs/src"
                            }
                        }
                    }
                },
                "coastline": {
                    "type": "object",
                    "required": [
                        "landRings"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "landRings": {
                            "type": "array",
                            "items": {
                                "$ref": "#/$defs/ring"
                            }
                        }
                    }
                }
            }
        },
        "poi": {
            "type": "object",
            "required": [
                "id",
                "p",
                "kind"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "p": {
                    "$ref": "#/$defs/vec2"
                },
                "kind": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]*$"
                },
                "tags": {
                    "type": "object",
                    "additionalProperties": {
                        "type": "string"
                    }
                },
                "headingDeg": {
                    "type": "number",
                    "minimum": 0,
                    "exclusiveMaximum": 360
                },
                "src": {
                    "$ref": "#/$defs/src"
                }
            }
        },
        "demMeta": {
            "type": "object",
            "required": [
                "schema",
                "file",
                "format",
                "samples",
                "metresPerSample",
                "originXZ",
                "heightRangeM",
                "sha256"
            ],
            "additionalProperties": false,
            "properties": {
                "schema": {
                    "const": "helix.city-source-dem/1"
                },
                "file": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._-]+$"
                },
                "format": {
                    "const": "r16"
                },
                "samples": {
                    "type": "array",
                    "items": {
                        "type": "integer",
                        "minimum": 2
                    },
                    "minItems": 2,
                    "maxItems": 2
                },
                "metresPerSample": {
                    "type": "number",
                    "exclusiveMinimum": 0
                },
                "originXZ": {
                    "$ref": "#/$defs/vec2"
                },
                "heightRangeM": {
                    "$ref": "#/$defs/vec2"
                },
                "sha256": {
                    "$ref": "#/$defs/sha256"
                },
                "note": {
                    "type": "string"
                }
            }
        },
        "overrides": {
            "type": "object",
            "required": [
                "schema",
                "ops"
            ],
            "additionalProperties": false,
            "properties": {
                "schema": {
                    "const": "helix.city-source-overrides/1"
                },
                "ops": {
                    "type": "array",
                    "items": {
                        "oneOf": [
                            {
                                "type": "object",
                                "required": [
                                    "op",
                                    "target"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                    "op": {
                                        "const": "delete"
                                    },
                                    "target": {
                                        "$ref": "#/$defs/id"
                                    },
                                    "note": {
                                        "type": "string"
                                    }
                                }
                            },
                            {
                                "type": "object",
                                "required": [
                                    "op",
                                    "target",
                                    "set"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                    "op": {
                                        "const": "set"
                                    },
                                    "target": {
                                        "$ref": "#/$defs/id"
                                    },
                                    "set": {
                                        "type": "object"
                                    },
                                    "note": {
                                        "type": "string"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    }
}
