
# AnySurface → Unreal Blueprint Recipe

This recipe shows exactly which **Blueprint nodes** to use and in what order to configure a `CineCameraActor` with parameters from AnySurface.

---

## **Variables (Inputs)**
Create the following variables in your Blueprint (e.g., `AnySurfaceCameraDriver`):
- **fx** (float, pixels)
- **fy** (float, pixels)
- **cx** (float, pixels)
- **cy** (float, pixels)
- **ImageWidth** (float, pixels)
- **ImageHeight** (float, pixels)
- **X, Y, Z** (float, in meters)
- **Pitch, Yaw, Roll** (float, degrees)

Create constants or editable variables for:
- **SensorWidth** (float, mm) – e.g., 36.0
- **SensorHeight** (float, mm) – e.g., 24.0

Create a **CineCameraActor Reference** variable, e.g., `TargetCamera`.

---

## **Blueprint Steps**

### **Step 1: Convert Position to Unreal Units**
Use a **Multiply (float × float)** node for each of `X, Y, Z`:
```
X_cm = X * 100
Y_cm = Y * 100
Z_cm = Z * 100
```
Connect these to a **Make Vector** node → `SetActorLocation` (Target = `TargetCamera`).

### **Step 2: Set Rotation**
Use a **Make Rotator** node with `Pitch`, `Yaw`, `Roll` → `SetActorRotation` (Target = `TargetCamera`).

### **Step 3: Compute Focal Length**
Use:
```
FocalLength = (fx * SensorWidth) / ImageWidth
```
Nodes:  
`fx` → **Multiply** with `SensorWidth` → **Divide** by `ImageWidth`.  
Connect result → `Set Current Focal Length` (Target = `TargetCamera`).

### **Step 4: Compute Principal Point Offsets**
```
OffsetX = ((cx / ImageWidth) - 0.5) * SensorWidth
OffsetY = (0.5 - (cy / ImageHeight)) * SensorHeight
```
Nodes:  
- For **OffsetX**:  
  `cx / ImageWidth` → **Subtract (float)** `0.5` → **Multiply** with `SensorWidth`.  
- For **OffsetY**:  
  `cy / ImageHeight` → **Subtract** from `0.5` → **Multiply** with `SensorHeight`.  

Set these via:  
`Set Filmback Horizontal Offset` (OffsetX)  
`Set Filmback Vertical Offset` (OffsetY)

### **Step 5: Set Sensor Size**
Use **Set Filmback Sensor Width** → `SensorWidth`.  
Use **Set Filmback Sensor Height** → `SensorHeight`.

### **Step 6: Execution Flow**
- On **BeginPlay** (or custom event), run:  
  **Sequence** → Steps 1 → 2 → 3 → 4 → 5.

---

## **Optional Tips**
- Group all math nodes into **Macros** for "Compute Focal Length" and "Compute Offsets".  
- Use **Tick Event** if AnySurface updates continuously.
