--- name: dayz-p3d-inspector description: "Use when: inspect model, show me the p3d, view memory points, move points, recipe json, build p3d, round-trip p3d. Visual Recipe editor. Not structural/collision audits: dayz-p3d-audit; not textured PAA preview: dayz-3d-viewer." --- # DayZ P3D Inspector — Interactive 3D Model Viewer, Editor & Builder Full round-trip pipeline for DayZ .p3d files: ``` .p3d --extract--> Recipe JSON --viewer--> Edit visually --build--> new .p3d ``` Extract model data, visualize everything in Three.js, drag memory points interactively, export the edited Recipe, and rebuild a fresh .p3d from it. ## Scope (and what this skill delegates) This skill **owns** three things: 1. The **Recipe JSON** as a single, complete data contract over a .p3d file (all LODs + memory points + axes + selections + properties + referenced paths + bounding box). 2. The **interactive editor** (Three.js, drag&drop memory points and axis endpoints, snap-to-grid, modal Recipe export). 3. The **Recipe -> .p3d builder** (the inverse of the extractor; closes the round-trip loop). Anything else is delegated to a sibling skill — do **not** duplicate it here: | Task | Use this skill instead | |-------------------------------------------|-----------------------------------------| | ODOL (binarized) .p3d -> MLOD (editable) | external ODOL->MLOD converter (pre-step) | | Visual viewer with PAA textures / glTF | `dayz-3d-viewer` (or invoke before) | | PAA <-> PNG conversion | `dayz-3d-viewer` (`paa_to_png.py`) | | Deep config / path / structure validation | `dayz-p3d-audit` (post-step) | | Generating a .p3d from scratch (Blender) | `dayz-model-pipeline` | | Editing / aligning proxies on a host model | `dayz-proxy-align` | The viewer in this skill renders untextured flat-shaded geometry on purpose: its job is to make memory points, axes, selections, collision LODs, and bounds inspectable and editable. For texture-rich previews, generate the Recipe here and feed the source .p3d through `dayz-3d-viewer` separately. ## Install Dependencies ```bash # py3d DayZ fork >= 1.6.0. Pick ONE route; both end in the same assert below. # NEVER `pip install py3d` (PyPI = point-cloud lib) NOR git+upstream (no guards). # # Route A - this pack is checked out: pip install -e tools/py3d # Route B - a vendored wheel is present in this skill's wheels/ directory. That wheel # is placed by the local py3d rollout and is NOT shipped in this pack; the installer # fails closed when it is missing, and refuses to guess when legacy wheels sit beside it. # python3 scripts/install_py3d.py python3 -c "import py3d; assert getattr(py3d,'IS_DAYZ_FORK',False) and tuple(map(int,py3d.__version__.split('.')))>=(1,6,0), (py3d.__version__, py3d.__file__)" pip install numpy --break-system-packages ``` Only the extractor and builder need py3d — the viewer is pure Python that emits a self-contained HTML file. ## Scripts All in this skill's `scripts/` directory: | Script | Purpose | |--------|---------| | `p3d_inspector_extract.py` | P3D -> Recipe JSON extractor (all LODs, memory, axes, selections) | | `p3d_inspector_viewer.py` | Recipe JSON -> Interactive HTML viewer generator (Phase 2 — drag & drop) | | `p3d_inspector_build.py` | Recipe JSON -> .p3d builder (MLOD) with mass policy + auto-fix | ## Quick Start ### From a real .p3d file ```python import sys sys.path.insert(0, '/path/to/skill/scripts') from p3d_inspector_extract import extract_recipe from p3d_inspector_viewer import generate_inspector_html recipe = extract_recipe('model.p3d', verbose=True) generate_inspector_html(recipe, output_path='inspector.html', model_name='My Model') ``` ### Demo mode (no p3d needed) ```bash python scripts/p3d_inspector_viewer.py --demo inspector_demo.html ``` ### CLI ```bash # Extract recipe from p3d python scripts/p3d_inspector_extract.py model.p3d -v -o recipe.json # Generate viewer from recipe python scripts/p3d_inspector_viewer.py recipe.json inspector.html # Build .p3d from an edited Recipe python scripts/p3d_inspector_build.py recipe.json output.p3d -v ``` ### Build Recipe -> .p3d (Python) ```python import json from p3d_inspector_build import build_p3d with open('recipe_edited.json') as f: recipe = json.load(f) result = build_p3d(recipe, 'model_rebuilt.p3d', auto_fix_enabled=True, verbose=True) # result = { "output_path", "lods_written", "fixes_applied", "warnings" } ``` ## Recipe JSON Format The Recipe JSON is the central data contract between all pipeline stages: ```json { "meta": { "source": "model.p3d", "version": 1, "mode": "audit|propose|demo" }, "lods": [ { "type": "visual_0|visual_1|visual_2|visual_3|geometry|fire_geometry|view_geometry|landcontact|roadway|paths|hitpoints|memory|shadow", "resolution": 0.0, "num_points": 328, "num_faces": 640, "geometry": { "positions": [], "normals": [], "uvs": [], "material_groups": {} }, "wireframe": { "positions": [], "edges": [], "faces": [] }, "selections": { "name": { "vertices": [], "faces": [], "vertex_count": 0, "face_count": 0 } }, "properties": { "autocenter": "0" } } ], "memory_points": [ { "index": 0, "position": [x,y,z], "selections": ["name"], "category": "center|interaction|axis|placing|port|proxy|other", "label": "name" } ], "axes": { "axis_name": { "points": [[x1,y1,z1],[x2,y2,z2]], "direction": [dx,dy,dz], "length": 0.015 } }, "bounding_box": { "min": [], "max": [], "size": [], "center": [] }, "referenced_paths": { "textures": [], "materials": [] } } ``` `material_groups` keys use the format `"texture|material"` (pipe-separated; either side may be empty). UVs are stored in glTF V-flipped convention so they render correctly in the viewer; the builder un-flips them before writing back to the .p3d. ## LOD Types & Resolution Constants (BIS MLOD) The classifier maps `lod.resolution` to a logical type: | Resolution | Type | Has geometry/wireframe? | Notes | |------------|------|-------------------------|-------| | `0.0..10` | `visual_0..3` | full geometry | rendered LODs | | `1.0e3..1.5e4` | `shadow` | wireframe | shadow volumes | | `1.0e13` | `geometry` | wireframe | physical collision; needs `Component01..` + mass | | `1.0e15` | `memory` | points only | memory points + animation axes | | `2.0e15` | `landcontact` | wireframe | per-vertex ground contact points | | `3.0e15` | `roadway` | wireframe | walkable surfaces | | `4.0e15` | `paths` | wireframe | AI navigation paths | | `5.0e15` | `hitpoints` | wireframe | named-selection destruction points | | `6.0e15` | `view_geometry` | wireframe | line-of-sight occlusion | | `7.0e15` | `fire_geometry` | wireframe | bullet/projectile collision | Anything else falls back to `unknown_` and the builder skips it with a warning. ## Builder Behaviour - **Visual LODs** — rebuilds tri faces from `geometry.material_groups`, re-inverts UVs back to DayZ convention (Recipe stores glTF V-flip), deduplicates per-vertex normals into a shared face-normal pool. - **Wireframe LODs** (`geometry`, `fire_geometry`, `view_geometry`, `landcontact`, `roadway`, `paths`, `hitpoints`, `shadow`) — rebuilds faces from `wireframe.faces` (tris / quads; N-gons are fan-triangulated), preserves `properties`, auto-adds `autocenter=0` and `class=house` to the Geometry LOD only if absent. - **Mass** is applied **only** to `geometry` and `fire_geometry`. ViewGeo, Shadow, LandContact, Roadway, Paths, HitPoints get no per-point mass. - **Memory LOD** — ignores any `lod` entry of type `memory` in the Recipe and rebuilds from `memory_points` + `axes`, creating one Selection per unique selection name referenced in `memory_points[].selections[]`. - **Mass policy** for Geometry/Fire LOD points (priority): 1. `lod.properties["_point_mass"]` override (per-LOD float) 2. `recipe.meta.point_mass_default` override (global float) 3. Heuristic: scan `referenced_paths` for density keywords (metal/steel/iron=7800, wood=600, plastic=1200, default=2000 kg/m^3), then `per_point = (bbox_volume * density) / num_points`. - **Auto-fix** (on by default; disable with `auto_fix_enabled=False` or `--no-autofix`): - Detects inverted face winding in Visual LOD 0 (>50% faces with normal pointing opposite to geometric cross-product) and reverses winding on **all** LODs. - Reports every fix applied in `result["fixes_applied"]`. - **Deeper validation** (path existence, BB anchor, action targets, Component01 coverage, etc.) is intentionally **not** in scope here. Pipe the freshly built .p3d through the `dayz-p3d-audit` skill for that. ## Viewer Features ### Layer Toggles - **Visual**: Flat-shaded model mesh (no textures by design — see Scope above) - **Geometry**: Green wireframe overlay showing collision LOD - **Fire Geo**: Red wireframe showing ballistic geometry - **View Geo**: Blue wireframe showing view culling geometry - **LandContact**: Yellow-green wireframe showing ground contact points - **Roadway**: Cyan wireframe showing walkable surfaces - **Paths**: Magenta wireframe showing AI navigation paths - **HitPoints**: Orange wireframe showing destruction hit points - **Memory Pts**: Colored spheres at memory point positions - **Axes**: Purple arrows showing animation axes - **Bounds**: Bounding box (cyan) + box_placing bounds (orange) - **Labels**: Floating text labels on memory points and axes - **Grid**: Reference grid - **Wireframe**: Visual mesh wireframe overlay - **Export Recipe**: Opens modal with edited Recipe JSON for copy The 7 wireframe LOD layers are off by default; enable them as needed. ### Memory Point Categories (Color-Coded) - **Center** (cyan): `pos center`, `ce_center` - **Interaction** (red): `actionPos`, action-related points - **Axis** (purple): Animation axis endpoints (2 points per axis) - **Placing** (orange): `box_placing_min`, `box_placing_max` - **Port** (deep orange): `port_*`, `cable_*` (LFPG electrical) - **Proxy** (gray): Proxy attachment points - **Other** (light gray): Unclassified points ### Sidebar Panels - **Points**: List of all memory points with live coordinates, click to focus - **LODs**: Summary of all LODs with point/face counts and selections - **Selections**: All named selections across all LODs - **Paths**: Referenced texture/material paths with `P:\` drive warnings (UX hint; for full path/structure validation use `dayz-p3d-audit`) ### Interaction - **Orbit**: Left mouse drag on empty space - **Pan**: Right mouse button drag - **Zoom**: Scroll wheel - **Select point**: Click on a sphere -> shows info panel with coordinates - **Drag point**: Click sphere + drag -> moves it in camera-perpendicular plane - **Snap to grid**: Hold **Shift** while dragging to snap to grid - **Grid size**: Press **1** for 0.01m (1cm), **2** for 0.05m (5cm) - **Focus**: Click point in sidebar list -> camera flies to it - **Export**: Click "Export Recipe" -> modal with JSON, use Select All + Ctrl+C ### Drag & Drop Details (Phase 2) The drag system uses hover-based orbit disabling: when the cursor hovers over a memory point sphere, OrbitControls is pre-emptively disabled so that pointerdown on the sphere starts a drag instead of orbiting. Moving away from spheres re-enables orbit. When dragging a memory point, the following are updated in real-time: - Sphere position in 3D scene - HTML overlay label position - Axis line + arrow geometry (if the point is an axis endpoint) - Placing bounding box (if the point is `box_placing_min` / `box_placing_max`) - Sidebar coordinates text - Recipe JSON data (R object in memory) - Selection info panel coordinates A floating coordinate display shows X/Y/Z during drag. The coordinate display also shows the current snap grid size when Shift is held. ## Technical Notes ### Three.js Setup - Three.js **r0.147.0** via classic UMD `