Documentation
¶
Overview ¶
Package worldchunk defines build-generated render assets and conservative streaming visibility for one logical world. Geometry stays in authored space; a host may show one immutable asset through several transformed portal paths.
Index ¶
- Constants
- Variables
- func BalancedSolidOwners(document world.Document, options worldlightmap.Options) ([]int, error)
- func DecodedMeshBytes(mesh Mesh) uint64
- func DecodedShadowBytes(proxy ShadowProxy) uint64
- func EncodeCatalog(catalog Catalog, document *world.Document) ([]byte, error)
- func EncodeMesh(mesh Mesh, document *world.Document) ([]byte, error)
- func EncodeReady(ready Ready) ([]byte, error)
- func EncodeShadowProxy(proxy ShadowProxy, document *world.Document) ([]byte, error)
- func GeometryDigest(document *world.Document) (string, error)
- func ReadyBytes(ready *Ready) uint64
- func ValidateBakedSelection(catalog *Catalog, chunkID int, document *world.Document, ...) error
- func ValidateCatalog(catalog *Catalog, document *world.Document) error
- func ValidateMesh(mesh *Mesh, document *world.Document) error
- func ValidateMeshBinding(mesh *Mesh, layout *worldlightmap.Layout) error
- func ValidateReady(ready *Ready, mesh *Mesh, encodedMesh []byte, document *world.Document, ...) error
- func ValidateShadowProxy(proxy *ShadowProxy, document *world.Document) error
- type Band
- type Basis
- type Catalog
- type Chunk
- type Mesh
- type Options
- type PlanResult
- type PlannedChunk
- type Ready
- type ReadyAdmission
- type ReadyBatch
- type ReadyOptions
- type ReadyOwner
- type ReadySurface
- type Secondary
- type ShadowProxy
- type ShadowTriangle
- type Triangle
- type Vertex
Constants ¶
const ( Schema = "karty.world-chunks@1" MeshSchema = "karty.world-chunk-mesh@1" Feature = cartridge.FeatureWorldChunksV1 CatalogEntryName = "@world/chunks/catalog" MeshEntryName = "@world/chunks/mesh" MetadataKey = "kartyWorldChunks" ChunkMetadataKey = "kartyWorldChunk" MaxEncodedSize = level.MaxEntrySize MaxEncodedBytes = level.MaxEnvelopeSize * 2 MaxVertices = 196608 MaxTriangles = MaxVertices / 3 )
const ( ReadySchema = "karty.world-chunk-ready@1" ReadyEntryName = "@world/chunks/ready" ReadyMetadataKey = "kartyWorldChunkReady" ReadyFeature = cartridge.FeatureWorldChunkReadyV1 ReadyStride = 26 MaxReadyBytes = 64 << 20 )
ReadySchema identifies renderer-ready scalar streams, separate from the semantic mesh used by complete build-time source and lightmap validation.
const ( ShadowSchema = "karty.world-chunk-shadow@1" ShadowEntryName = "@world/chunks/shadow" MaxShadowEncodedSize = MaxEncodedSize MaxShadowTriangles = 8192 )
Variables ¶
var ErrChunk = errors.New("world chunk is invalid")
var ErrReadyCapacity = fmt.Errorf("prepared geometry capacity exceeded: %w", ErrChunk)
ErrReadyCapacity identifies derived renderer geometry exceeding the existing triangle/scalar limits. Builders may repartition a multi-sector child.
var ErrShadowBudget = fmt.Errorf("opaque caster triangle budget: %w", ErrChunk)
ErrShadowBudget identifies a valid world whose complete opaque caster asset exceeds the supported bound. Producers may omit this optional root asset for render-only worlds; malformed source and other errors must still fail.
Functions ¶
func BalancedSolidOwners ¶ added in v0.0.14
BalancedSolidOwners is an opt-in build policy for decorative structures that overlap several receiver sectors. Largest chart sets are placed first, then assigned to the least occupied eligible sector whose exact receiver layout fits. Narrow low solids grounded at the receiver floor then prefer the first exact-fitting owner so perimeter details do not fragment adjacent pages. It never changes density, page limits, geometry or physical components. The returned complete list can be supplied as Options.SolidOwners. The default Plan ownership remains unchanged.
func DecodedMeshBytes ¶
DecodedMeshBytes is the packed scalar array size, independent of Go padding: 21 float32 attributes per vertex, uint32 indices and 55 scalar words per triangle (including fixed identity/flags slots). It excludes the binary header and sector/solid ownership lists.
func DecodedShadowBytes ¶
func DecodedShadowBytes(proxy ShadowProxy) uint64
DecodedShadowBytes counts 12 float32 coordinates and five fixed scalar identity words per triangle. Hosts account for their object and GPU storage separately, rather than estimating from the encoded payload size.
func EncodeReady ¶ added in v0.0.18
EncodeReady writes bounded renderer streams. Builders check complete semantic association with DecodeReady/ValidateReady before publishing a catalog hash. Runtime uses DecodeReadyArtifact after whole-child integrity verification.
func EncodeShadowProxy ¶
func EncodeShadowProxy(proxy ShadowProxy, document *world.Document) ([]byte, error)
func ReadyBytes ¶ added in v0.0.18
func ValidateBakedSelection ¶
func ValidateBakedSelection(catalog *Catalog, chunkID int, document *world.Document, layout *worldlightmap.Layout) error
ValidateBakedSelection binds a child's source membership to its parent catalog. The recipe must contain exactly the parent union filtered to this ordinary physical component; ordering remains part of the prebake identity. A nil layout is valid only for a descriptor with no lightmap.
func ValidateMeshBinding ¶
func ValidateMeshBinding(mesh *Mesh, layout *worldlightmap.Layout) error
ValidateMeshBinding checks every final RNM coordinate against its semantic chart. Geometry validation is separate and never regenerates triangles.
func ValidateReady ¶ added in v0.0.18
func ValidateReady( ready *Ready, mesh *Mesh, encodedMesh []byte, document *world.Document, layout *worldlightmap.Layout, options ReadyOptions, ) error
ValidateReady checks complete source coverage and exact packed values without constructing a second renderer representation. Inputs are read-only.
func ValidateShadowProxy ¶
func ValidateShadowProxy(proxy *ShadowProxy, document *world.Document) error
ValidateShadowProxy checks each supplied triangle directly against its canonical authored polygon corners. It checks complete semantic coverage and winding without constructing a mesh or any new triangle/vertex arrays.
Types ¶
type Catalog ¶
type Catalog struct {
Schema string
GeometrySHA256 string
Chunks []Chunk
SectorChunks []int
// Candidates is directed graph reachability, a worst-case visibility
// superset. It is deduplicated by immutable chunk ID, not by portal path.
Candidates [][]int
// BakedLights is the sorted unique union of authored light indexes carried
// by completed child prebakes. Hosts partition these sources before loading
// children; they never consume runtime direct-light slots.
BakedLights []int
}
type Mesh ¶
type Mesh struct {
Schema string
GeometrySHA256 string
SurfaceSHA256 string
Sectors []int
Solids []int
Vertices []Vertex
Indices []uint32
Triangles []Triangle
Bounds [6]float64
}
func CompileMesh ¶
func CompileMesh(document world.Document, sectors, solids []int, layout worldlightmap.Layout) (Mesh, error)
CompileMesh triangulates immutable authored receiver polygons offline. Every boundary vertex, including collinear junctions, gets its own triangle edge. The runtime reads final arrays and never constructs or tessellates a face.
type Options ¶
type Options struct {
MaxMeshBytes uint64
MaxEncodedBytes uint64
MaxSectors int
// Lightmap.PageSize is a maximum: 1024 (or zero) first tries 512, then
// retries 1024 only when the receiver charts exceed page capacity.
Lightmap worldlightmap.Options
NoLightmap bool
// SectorGroups is an optional build-only authored-area preference. Nil keeps
// budget-only grouping. Otherwise every global sector has an ID in [0,256).
// Ordinary connectivity and hard budgets can still split an authored area.
SectorGroups []int
// SolidOwners optionally assigns every static solid to one overlapping
// receiver sector. Nil preserves first-overlap ownership. It is build policy
// only; complete bounds and ordinary-space validation remain mandatory.
SolidOwners []int
// CompactLightmaps optionally repacks complete valid receiver groups within
// one ordinary physical component. It preserves all hard budgets and never
// increases their total decoded lightmap cost. Nil/default policy is unchanged.
CompactLightmaps bool
}
type PlanResult ¶
type PlanResult struct {
Chunks []PlannedChunk
SectorChunks []int
Candidates [][]int
}
func Plan ¶
func Plan(document world.Document, options Options) (PlanResult, error)
Plan grows connected chunks deterministically in authored sector order. A budget failure never lowers density. An oversized single sector is an error. MaxEncodedBytes limits the mesh entry here; builders must also check the final child module including compressed lightmaps against that exact byte budget. Lightmap.PageSize is a maximum here: a 1024 maximum first tries a 512 page at identical density and padding, then retries 1024 only on page capacity.
type PlannedChunk ¶
type Ready ¶ added in v0.0.18
type Ready struct {
Schema string
MeshSHA256 string
Surfaces []ReadySurface
Batches []ReadyBatch
}
Ready is compiled with the level, not reconstructed by presentation. The associated semantic mesh is the build-time proof source. Runtime artifact admission checks structure after exact whole-child catalog integrity checks. Surface indexes refer to the provided level-wide table when compiled together.
func CompileReady ¶ added in v0.0.18
func CompileReady( mesh *Mesh, encodedMesh []byte, document *world.Document, layout *worldlightmap.Layout, options ReadyOptions, ) (Ready, error)
CompileReady groups and packs already tessellated source triangles at build time. Optional static cleanup cuts covered geometry while interpolating the source attributes; canonical source geometry and lighting remain unchanged.
func DecodeReady ¶ added in v0.0.18
func DecodeReady( encoded []byte, mesh *Mesh, encodedMesh []byte, document *world.Document, layout *worldlightmap.Layout, options ReadyOptions, ) (Ready, error)
DecodeReady proves renderer streams against an already validated semantic mesh and its accepted lightmap binding. Builders and offline cache acceptance use this complete source proof before publishing the whole-child catalog hash. Runtime compiled artifacts use DecodeReadyArtifact after integrity checking.
func DecodeReadyArtifact ¶ added in v0.0.18
func DecodeReadyArtifact(encoded []byte, admission ReadyAdmission) (Ready, error)
DecodeReadyArtifact decodes compiler-authoritative renderer data after whole artifact integrity verification. It checks binary/allocation limits, finite scalars and complete array/material/owner references. It does not decode a semantic mesh, reconstruct geometry, prove surface coverage, regenerate UVs or compare normals/bases against authored source. MeshSHA256 is build evidence; the verified whole-child catalog hash is the runtime artifact binding. Returned arrays are independently owned; inputs are read-only.
type ReadyAdmission ¶ added in v0.0.18
type ReadyAdmission struct {
MaterialCount int
Sectors, Solids []int
// Triangles is the catalog's canonical mesh-byte reservation divided by 484.
Triangles int
// Lightmap requires packed UV/basis streams on every non-sky batch. Image and
// layout dimensions/format/decoded-byte limits remain their own boundary.
Lightmap bool
// Surfaces optionally requires the mount's already accepted canonical table.
Surfaces []ReadySurface
}
ReadyAdmission binds compiled renderer streams to one accepted parent chunk. The asset pipeline proves geometry and authored attributes before publishing that parent's catalog. Callers must verify the complete child's exact catalog size and SHA-256 before using this structural admission API. This descriptor alone does not establish artifact authenticity or producer correctness.
type ReadyBatch ¶ added in v0.0.18
type ReadyOptions ¶ added in v0.0.18
type ReadyOptions struct {
// CleanupStatic derives visibility-safe static cuts at build time. It is for
// atomic streamed chunks, whose selected owners cannot move independently.
// Canonical Mesh stays unchanged; Ready Sources index the derived triangles.
CleanupStatic bool
Masked []bool
// Surfaces optionally fixes level-wide surface slot identities. Nil derives
// a local deterministic table; a supplied table must contain every source key.
Surfaces []ReadySurface
}
ReadyOptions selects build-time cleanup and material classification inputs. Masked uses the parent world's canonical material-slot order.
type ReadyOwner ¶ added in v0.0.18
type ReadySurface ¶ added in v0.0.18
type ReadySurface struct {
Primary, Secondary, Band int
SecondaryStrength float32
BandCoverage uint8
BandRepeatU, BandRepeatV bool
}
func ReadySurfaces ¶ added in v0.0.18
func ReadySurfaces(meshes []Mesh, document *world.Document) ([]ReadySurface, error)
ReadySurfaces derives a deterministic level-wide material surface table. Passing this table to every CompileReady call keeps streamed chunk vertex surface IDs stable without rewriting their scalar streams at runtime.
type ShadowProxy ¶
type ShadowProxy struct {
Schema string
GeometrySHA256 string
SurfaceSHA256 string
Triangles []ShadowTriangle
}
ShadowProxy is one bounded root-owned caster asset, independent of render chunk residency. It contains authored opaque rest geometry, without material seam junctions, center vertices, displaced-liquid subdivision or actors.
func CompileShadowProxy ¶
func CompileShadowProxy(document world.Document) (ShadowProxy, error)
CompileShadowProxy triangulates the complete opaque authored caster surfaces offline. Corner fans preserve legacy shadow semantics: static wall-frame UV bands do not change the underlying opening, sky has no caster, and a liquid material with opacity below one does not cast an opaque shadow.
func DecodeShadowProxy ¶
func DecodeShadowProxy(encoded []byte, document *world.Document) (ShadowProxy, error)
type ShadowTriangle ¶
Source Files
¶
- baked.go
- binary.go
- catalog_binary.go
- chunk.go
- codec.go
- compact.go
- compile.go
- cooperative_native.go
- liquid.go
- mesh_attributes.go
- mesh_binding.go
- mesh_coverage.go
- plan.go
- plan_mesh.go
- ready.go
- ready_artifact.go
- ready_binary.go
- ready_cleanup.go
- ready_cleanup_clip.go
- ready_cleanup_vertex.go
- ready_compile.go
- ready_surfaces.go
- ready_validate.go
- ready_vertex.go
- shadow.go
- shadow_binary.go
- sky.go
- solid_balance.go
- solid_grounded.go