Build and export as nanos map/asset pack #94

Open
Superkooka wants to merge 21 commits from feat/nanos-scene into main
Owner
No description provided.
Add BookAtlas.Nanos, a separate executable that reads the game through
the exporter's GameSession. Its export:nanos:scene command reads a
hand-written scene layout and writes one glb per model, the textures as
PNG and a scene.json. tool/nanos/unreal/import_scene.py imports that
folder into a level in a headless Unreal 5.7. The tool/nanos scripts
build, cook, deploy and run it on a local server. tool/nanos/scenes/step1.json
is the first test scene: rocks, a pine and a shrub on a dirt ground.

NifSceneShape now reads Double_Sided and Tree_Anim. Under Tree_Anim, the
vertex alpha weighs the wind and isn't an opacity, so the scene leaves
it out.

Add BookAtlas.Nanos.Tests, the nix packages and the docs/src/nanos pages.
The game unit length, Tree_Anim and the material approximations go in
spec-deviations.
feat(nanos): export a window of exterior cells as terrain tiles
All checks were successful
/ docs (push) Successful in 4s
/ format (push) Successful in 2m33s
/ test (push) Successful in 3m0s
e7803b6723
Add export:nanos:cells: a window of up to 4x4 cells of a worldspace
becomes one glb tile per cell from its LAND (VHGT heights, VNML normals,
VCLR colors, mesh collision), centered on Unreal's origin, with a spawn
point above the cell at the window's center. Each tile is an actor
Terrain_<x>_<y> in the Cells/<x>_<y> folder, tagged with its cell and
EditorID.

Every scene now imports into one library under /Game/Skyrim/ (Meshes,
Textures, Materials, Maps): the export names each asset (SM_, T_, a
folder suffix when two files share a name) and scene.json moves to
format 2 with origin, assetName, source, and each placement's label,
folder and tags. The import deletes a scene's old folder; master
materials default to a white diffuse (V3). build-scene.sh takes the
export command as its arguments.

LandscapeReader reads VNML as signed bytes; the reading and its check on
Tamriel go in spec-deviations.
feat(nanos): bake each cell's ground texture onto its terrain tile
All checks were successful
/ docs (push) Successful in 5s
/ format (push) Successful in 2m29s
/ test (push) Successful in 2m55s
07129a775b
export:nanos:cells draws each cell's landscape textures as the map's
--terrain texture render does (BTXT, ATXT, VTXT, VCLR), one 2048 px PNG
per cell, and gives each tile its own opaque material; the tile's vertex
colors turn white. scene.json moves to formatVersion 3: textures gain
`clamp`, and `source` is null for a texture the export draws. The import
samples clamped textures without wrapping.
The baked 2048 px ground was blurry up close and had no normal maps.
Each terrain tile's material now blends the cell's landscape textures,
color and normal map repeated 24 times per cell, through 33x33 RGBA
weight maps computed from BTXT, ATXT and VTXT; VCLR goes back to the
vertex colors. A cell keeps 16 textures at most (Tamriel blends 13).

scene.json moves to formatVersion 4: materials gain a `terrain` block and
textures a `weights` usage. The import builds terrain masters with
shared samplers, and no longer deletes a current master another scene
uses.
Cells side by side whose water stands at the same height form one
outline in scene.json (formatVersion 5, water[]); water under all of
a cell's ground is left out, a group with a hole splits into rows.
The import builds a WaterZone, then one WaterBodyLake per outline.
build-scene.sh lets UE_EDITOR_CMD carry arguments, for
"ue-proton editor-cmd".
Cells side by side whose water stands at the same height form one
outline in scene.json (formatVersion 5, water[]), counter-clockwise
in Unreal's frame as the plugin's lake triangulation requires; water
under all of a cell's ground is left out, a group with a hole splits
into rows. The import builds a WaterZone, then one WaterBodyLake per
outline, without the plugin's default waves: Skyrim's water is flat.
build-scene.sh lets UE_EDITOR_CMD carry arguments, for
"ue-proton editor-cmd".
Cells side by side whose water stands at the same height form one
outline in scene.json (water[]), counter-clockwise in Unreal's frame
as the plugin's lake triangulation requires; water under all of a
cell's ground is left out, a group with a hole splits into rows. The
import builds a WaterZone, then one WaterBodyLake per outline, without
the plugin's default waves (Skyrim's water is flat) and with a darker
instance of its lake material.

scene.json loses formatVersion: on this development branch the export
and the import change together. build-scene.sh lets UE_EDITOR_CMD
carry arguments, for "ue-proton editor-cmd".
The STAT and MSTT references of the window become placements with their
full rotation: an actor for a model placed once in its cell, instances
of one Statics_<x>_<y> actor per cell for the others. scene.json gives
each placement its REFR and base key, and lists the bases; the import
tags each mesh with its bases and writes catalog.json. Under Proton,
the import reaches the scene folder through Z:, which Interchange needs.
The window gets one weather: its center cell's highest-priority weather
region, else the worldspace's climate, the highest chance, a Pleasant
one on a tie; --weather overrides it. scene.json (sky) carries its NAM0
colors at the four times of day, fog, enabled cloud layers, the
climate's sunrise and sunset, sun, moons and night sky textures, and
the TimeScale and GameHour globals. New readers for WTHR, CLMT, REGN,
GLOB, CELL XCLR and BSSkyShaderProperty, merged by the SkyRecords
dataset.

The import builds BP_SkyrimSky_<Scene>, components without a graph:
a dome whose Custom HLSL material reads the hour back from the sun's
direction, sun and moon lights scaled as Skyrim's image spaces do, a
sky light that captures the weather's ambient color, an atmosphere
that only tints the lights, a volumetric fog and a post process with
histogram exposure and no global illumination, as Skyrim has none. The
level holds an editor-only instance turned to the start hour; the
Blueprint is in catalog.json.
import_scene.py and sky.py become a package with one module per import
step: textures, materials, meshes, the level (placements, water) and the
sky (material, HLSL, Blueprint, hour to rotation, calibration values).
The material graph helpers, component creation and old master deletion
were written twice and now exist once; the import counters move from a
global dict to an object passed to each step. The import's outputs are
byte-identical on Riverwood, from scratch and incrementally.
The level's BP_SkyrimSky instance was editor only, so Play and a cooked
level had no sky. It is now a plain level actor at the scene's start
hour; the cook takes the Blueprint through the level's references.
A cell's water type is its XCWT, else its worldspace's NAM2 (or its
parent's with "Use Water Data"). WATR's DNAM deep color and fog far plane
go into scene.json, and cells of two types make two surfaces. The import
gives each type its own instance of the Water plugin's lake material: the
deep color's hue tints its scattering and absorption, and the fog
distance sets how far light goes through it (16 per meter, set by eye on
Riverwood's river). The surfaces stay still lakes.

build-scene.sh takes --proton for the Windows editor under Proton.
The Water plugin's quadtree splits a lake's collision pieces along its
2400 cm tile lines, which pass through the origin. A corner lying exactly
on a line goes to the negative side only, so the tiles beside it got no
water: Riverwood's river showed two tile-sized holes where the outline
has corners on the window's center lines.
TREE references join the cells export as instances of one Trees_<x>_<y>
actor per cell. HavokShapeReader reads a body's bhkCapsuleShape, or a
bhkListShape of capsules, and NifScene lists each drawn node's collision
body with its transform to the model's space. A tree model's capsules go
to scene.json in the imported mesh's frame (meshes[].capsules, collision
"capsules"); the import writes them as capsule elements, keeping the
collision in a metadata tag so it is set again when only the capsules
change. A model without capsules, ferns, shrubs, harvestable plants,
doesn't collide.
feat(nanos): export the cells' doors, containers and other objects a game uses
All checks were successful
/ docs (push) Successful in 5s
/ format (push) Successful in 3m6s
/ test (push) Successful in 3m32s
Benchmarks / compare (pull_request) Successful in 18m27s
97bcc6a82c
DOOR, CONT, FURN, ACTI, FLOR and item references (MISC, ALCH, WEAP, ARMO,
BOOK, INGR, KEYM, SLGM, AMMO) join the cells export as movable actors of
their own, however many times their model repeats, in a folder per type
under their cell. A door carries the door its XTEL leads to as a
skyrim.door.to tag. Their models collide by their triangles when they have
a Havok collision object. scene.json gains placements[].mobility, which
the import applies to the actor's component.

ModeledObjectReader reads MODS (MO2S or MO4S for an armor's ground model),
and a TextureSets dataset merges the TXST records. A base swapping
textures is drawn as a mesh of its own, the texture set's color and normal
maps on the shapes its 3D names give: Riverwood's snowy and mossy rocks.

Folders holding a space or punctuation, as clutter\chopping block, are
written with '_' in their place: Unreal refuses such package paths.
CellStatics becomes CellObjects.

Benchmarks

Base 87317f5c against head 1df9541c, alternating over 5 rounds on the same runner.
Times are per operation, the fastest round of each side. A change counts only when every round shows it beyond the error margins of both runs; otherwise it is marked as noise.
A shared runner is noisy: trust the allocations more than the times, and confirm a time on an idle machine.

No benchmark changed beyond its error margins in every round, and no allocation changed.

All benchmarks (10)
Benchmark Parameters Base Head Change Rounds Base allocated Head allocated
LandscapeRasterizerBenchmarks.Draw Kernel=bicubic 17.61 ns 17.6 ns -0.04 % (noise) -22.49 % to +13.73 % 0 B 0 B
LandscapeRasterizerBenchmarks.Draw Kernel=bilinear 16.03 ns 16.03 ns -0.02 % (noise) -35.42 % to +2.78 % 0 B 0 B
ObjectRasterizerBenchmarks.Draw Scenario=texture 52.6 ns 52.5 ns -0.2 % (noise) -1.68 % to +10.01 % 0 B 0 B
ObjectRasterizerBenchmarks.Draw Scenario=texture-blended 64.32 ns 63.69 ns -0.98 % (noise) -3.57 % to +7.44 % 24 B 24 B
ObjectRasterizerBenchmarks.Draw Scenario=texture-cut 30.62 ns 29.6 ns -3.33 % (noise) -8.46 % to +1.8 % 0 B 0 B
ObjectRasterizerBenchmarks.Draw Scenario=texture-lit 33.39 ns 33.38 ns -0.02 % (noise) -1.67 % to +9.73 % 0 B 0 B
ObjectRasterizerBenchmarks.Draw Scenario=wireframe 10.51 ns 10.44 ns -0.65 % (noise) -2.33 % to -0.43 % 0 B 0 B
ObjectTextureBenchmarks.Sample Kernel=bicubic 93.66 ns 95.46 ns +1.93 % (noise) +1.65 % to +6.72 % 0 B 0 B
ObjectTextureBenchmarks.Sample Kernel=bilinear 56.91 ns 58.03 ns +1.96 % (noise) +1.06 % to +4.33 % 0 B 0 B
PngEncoderBenchmarks.Encode 88.78 ns 88.74 ns -0.05 % (noise) -12.56 % to +8.7 % 4 B 4 B
<!-- benchmark-report --> ### Benchmarks Base `87317f5c` against head `1df9541c`, alternating over 5 rounds on the same runner. Times are per operation, the fastest round of each side. A change counts only when every round shows it beyond the error margins of both runs; otherwise it is marked as noise. A shared runner is noisy: trust the allocations more than the times, and confirm a time on an idle machine. No benchmark changed beyond its error margins in every round, and no allocation changed. <details> <summary>All benchmarks (10)</summary> | Benchmark | Parameters | Base | Head | Change | Rounds | Base allocated | Head allocated | |---|---|---|---|---|---|---|---| | `LandscapeRasterizerBenchmarks.Draw` | Kernel=bicubic | 17.61 ns | 17.6 ns | -0.04 % (noise) | -22.49 % to +13.73 % | 0 B | 0 B | | `LandscapeRasterizerBenchmarks.Draw` | Kernel=bilinear | 16.03 ns | 16.03 ns | -0.02 % (noise) | -35.42 % to +2.78 % | 0 B | 0 B | | `ObjectRasterizerBenchmarks.Draw` | Scenario=texture | 52.6 ns | 52.5 ns | -0.2 % (noise) | -1.68 % to +10.01 % | 0 B | 0 B | | `ObjectRasterizerBenchmarks.Draw` | Scenario=texture-blended | 64.32 ns | 63.69 ns | -0.98 % (noise) | -3.57 % to +7.44 % | 24 B | 24 B | | `ObjectRasterizerBenchmarks.Draw` | Scenario=texture-cut | 30.62 ns | 29.6 ns | -3.33 % (noise) | -8.46 % to +1.8 % | 0 B | 0 B | | `ObjectRasterizerBenchmarks.Draw` | Scenario=texture-lit | 33.39 ns | 33.38 ns | -0.02 % (noise) | -1.67 % to +9.73 % | 0 B | 0 B | | `ObjectRasterizerBenchmarks.Draw` | Scenario=wireframe | 10.51 ns | 10.44 ns | -0.65 % (noise) | -2.33 % to -0.43 % | 0 B | 0 B | | `ObjectTextureBenchmarks.Sample` | Kernel=bicubic | 93.66 ns | 95.46 ns | +1.93 % (noise) | +1.65 % to +6.72 % | 0 B | 0 B | | `ObjectTextureBenchmarks.Sample` | Kernel=bilinear | 56.91 ns | 58.03 ns | +1.96 % (noise) | +1.06 % to +4.33 % | 0 B | 0 B | | `PngEncoderBenchmarks.Encode` | | 88.78 ns | 88.74 ns | -0.05 % (noise) | -12.56 % to +8.7 % | 4 B | 4 B | </details>
Each LIGH reference of the window goes to scene.json's lights[] in the units
of nanos world's Light constructor: linear color, intensity (FNAM plus the
XLIG fade offset, times pi), attenuation radius (the base's plus XRDS) in
centimeters, shadows, and whether it is on when the game starts. Its model
goes with it. A level's light isn't a nanos world entity, so a script
creates the lights it drives.

The import builds a BP_<base key> per LIGH base (point light, Skyrim's
1 - (d/r)^2 falloff, its model when it has one) and places one instance per
light that is on, set to its reference's look through the component's
setters: a second set_editor_property on a placed Blueprint instance isn't
saved. build-scene.sh --without-lights leaves the lights out of the level.

LightReader reads FNAM, ReferenceReader XLIG's fade offset. Base keys no
longer start with BP_.
The map's grass placement moves from GrassTufts to GrassPlaces, without models, so the
scene and the map share it; maps stay byte for byte identical. export:nanos:cells writes
grass[] in scene.json, each cell's tufts by model, and the import places one actor per cell
with a hierarchical instanced mesh per model, without collision or shadow, culled at the
game's grass fade distance (7000 units).
feat(nanos): export a window of cells of any size, Riverwood to Whiterun in one level
All checks were successful
/ docs (push) Successful in 5s
/ format (push) Successful in 2m32s
/ test (push) Successful in 3m25s
Benchmarks / compare (pull_request) Successful in 18m56s
70ba6fa939
A window no longer stops at 4 cells a side. From Riverwood to Whiterun
(3,-13:7,1, 75 cells, Whiterun from Open Cities) the export takes 45 s
and the headless import 25 minutes.

Three vanilla Whiterun models hold UVs that aren't numbers; the scene
writes them as 0, so Unreal's glTF import no longer ends in an error.
fix(nanos): draw instanced statics and decals right in a cooked game
All checks were successful
/ docs (push) Successful in 5s
/ format (push) Successful in 2m51s
/ test (push) Successful in 3m31s
Benchmarks / compare (pull_request) Successful in 18m50s
a3395a3d22
The master materials now carry the instanced static mesh usage, which a
cook can't add: without it nanos world drew the statics, trees and grass
instances with Unreal's default checker. A decal shape is pulled toward
the camera by 0.1 % of its distance, standing in for the game's depth bias.
feat(nanos): turn the Skyrim sky with a server clock, two moons and the game's cloud shapes
All checks were successful
/ docs (push) Successful in 6s
/ format (push) Successful in 2m41s
/ test (push) Successful in 3m26s
Benchmarks / compare (pull_request) Successful in 18m51s
1df9541c6e
The sky splits into three Blueprints: BP_SkyrimSky (the dome, the night sky
model's and the cloud layers' shapes, the sky light, the atmosphere, the fog
and the exposure), BP_SkyrimSun and BP_SkyrimMoon, one directional light
each. The level hides the light under the horizon: each shown directional
light renders its own virtual shadow map, and the moon's took half of the
shadow depth time in Riverwood's foliage.

The game mode keeps the time of day. Server/Clock.lua advances the hour at
the load order's TimeScale, sends it to a joining player and to every client
each minute, and answers /time, /time set <hour> and /time scale <n> for
every player. Client/SkyCycle.lua removes the level's sky, spawns the three
Blueprints, turns the dome each frame and the lights every 10 game minutes,
and shows the light above the horizon. write_pack.py gives the map's Lua data
what it needs: the Blueprints, the climate's hours and the orbit's angles.

Masser and Secunda follow their phases: the export writes the eight
Sky\<Moon>_<phase>.dds of each moon in the engine's order and the climate's
TNAM phase length, and the dome shows the phase of the clock's day.

The engine draws cloud layer i on shape i of Sky\Clouds.nif, with that
shape's UVs and its vertex alpha fading the patches' edges; the night sky
model's shapes carry their own UVs too. The export writes each such shape as
a mesh of its own, white with its vertex alpha; the import draws the clouds
as translucent components that stay in the world's frame and the stars as
additive ones that turn with the actor. One sphere mapping for every layer
pinched the clouds at the zenith and stretched the stars. The dome, the stars
and the clouds follow the camera through their World Position Offset. A
layer's opacity emulates the game's blend of gamma-encoded values over the
sky's gradient. The sky's masters are now M_SkyrimSky_V9, M_SkyrimCloud_V9
and M_SkyrimStars_V9.

The histogram exposure stops at EV100 0, which keeps a moonlit night dark.

The game mode's remote events pass a Reliability, which nanos world expects
since compatibility 1.139: the doors' events failed without it too.

Not settled: in game, a haze still ends on the outer edge of some cloud
shapes, where their vertex alpha is 0; the light switch and the shadow cost
in nanos world aren't measured yet.
Superkooka changed title from WIP: feat/nanos-scene to Build and export as nanos map/asset pack 2026-11-24 23:34:30 +00:00
All checks were successful
/ docs (push) Successful in 6s
Required
Details
/ format (push) Successful in 2m41s
Required
Details
/ test (push) Successful in 3m26s
Required
Details
Benchmarks / compare (pull_request) Successful in 18m51s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/nanos-scene:feat/nanos-scene
git switch feat/nanos-scene
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Superkooka/SkyrimSourceExporter!94
No description provided.