# Rules

This chapter outlines all requirements a Digital Twin must meet to be successfully ingested and used in Grip. It is
organized into several subsections, each covering a different part of the specification.

The following conventions are used throughout this page:

- **SHALL** / **MUST**: Indicates a mandatory requirement
- **SHOULD**: Indicates a recommended practice
- **MAY**: Indicates an optional feature

## Minimum specification validation rules

### [C-1] File MUST be named `asset.usda`

A Digital Twin MUST have an `asset.usda` file. This is the entrypoint into the Digital Twin and has to be fixed for consitency and automatic processes to easily pick up the Digital Twin.

- **Error**: When no `asset.usda` file exists in the root of the delivery
- **Success**: When the `asset.usda` exists

### [C-2] A `defaultPrim` MUST be defined

The `asset.usda` file must define a `defaultPrim` that references the prim to be imported.

Example:

```usda
#usda 1.0
(
    defaultPrim = "Root"
)

def Xform "Root"
{
}
```

- **Error**: `defaultPrim` is missing OR `defaultPrim` is referencing an unknown prim
- **Success**: `defaultPrim` exists AND references an existing prim

### [C-3] Up-Axis MUST be defined

Each Digital Twin MUST have the `upAxis` defined in the stage. Grip will respect the value when placing the asset in
scenes, so the chosen value must align with the placement of your asset in the OpenUSD file. The specification does not
mandate a particular up axis.

Example:

```usda
#usda 1.0
(
    upAxis = "Y"
)
```

- **Error**: `upAxis` is missing
- **Success**: `upAxis` exists

**External documentation:** [OpenUSD up-axis documentation](https://openusd.org/release/api/group___usd_geom_up_axis__group.html) / [Setting the stage up axis in NVIDIA Omniverse](https://docs.omniverse.nvidia.com/dev-guide/latest/programmer_ref/usd/stage/set-stage-up-axis.html)

### [C-4] Scene unit MUST be defined and set to 'mm'

In the `asset.usda` file, the stage's `metersPerUnit` metadata MUST be defined with the value `0.001`, which
represents a scale of millimeters. Grip will not scale objects if another value is used for `metersPerUnit`.

Verify that the geometry has the correct scale by importing the Digital Twin into one of
our [reference scenes](../references/README.md#reference-scenes), which include helper geometry for size validation.

Example:

```usda
#usda 1.0
(
    metersPerUnit = 0.001
)
```

- **Error**: `metersPerUnit` is missing OR has a value that doesn't match `0.001`
- **Success**: `metersPerUnit` exists AND has a value of `0.001`

**External documentation:** [Units in OpenUSD from NVIDIA](https://docs.nvidia.com/learn-openusd/latest/beyond-basics/units.html)

### [C-5] `defaultPrim` is a `Xform`

For Grip to place the asset in scenes, the prim referenced by the stage's `defaultPrim` attribute MUST be an `Xform`
so that transformations can be applied.

Example:

```usda
#usda 1.0
(
    defaultPrim = "Root"
)

def Xform "Root"
{
}
```

- **Error**: The prim referenced by `defaultPrim` is not an `Xform`
- **Success**: The prim referenced by `defaultPrim` is an `Xform`

### [C-6] No transformation ops are set on the `defaultPrim`

For assets to be positioned correctly in a scene using transformations applied by Grip, the `defaultPrim` MUST NOT have
any transformations of any kind applied to it.

- **Error**: The transformOps contains at least one operation
- **Success**: The transformOps list is empty (`UsdGeomXformable::GetOrderedXformOps()` returns empty list)

### [C-7] Digital Twin MUST be self-contained

All asset paths defined in the Digital Twin's USD structure and shaders MUST be relative to the file that references
them. No absolute paths or paths using asset resolver schemas are allowed.

- **Error**: At least one asset path is not relative
- **Success**: All assets are relative

## Variant validation rules

### [V-1] Configurations MUST only contain certain names

Grip only supports a limited number of variants with specific names.

The following names are supported:

- `default`
- `empty`
- `inner_out_of_pack`
- `open`
- `wet`
- `wet_closed`

Using any other name will result in an error. The check is case-insensitive.

- **Error**: At least one variant name is not supported, or the `Configurations` variant set is missing.
- **Success**: All defined variants for the `Configurations` variant set in the `asset.usda` file use one of the
  supported names.

## Artwork validation rules

### [A-1] Artwork names MUST only contain certain names

At the moment, Grip supports only a limited number of artworks with specific names.

The following names are supported:

- `default`
- `clean`
- `optimized`
- `campaign`
- `default_angled`
- `clean_angled`
- `optimized_angled`

Using any other names in the `metadata.json` will result in an error. The check is case-insensitive.

- **Error**: At least one artwork name is not supported.
- **Success**: All artwork names defined in `data/digital_twin/artworks` in the `metadata.json` file use one of the
    supported names in the `name` field.
