@bendyline/molen-ambient 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -203,7 +203,7 @@ function featureDrafts(input, options) {
203
203
  const width = classified.class === "water" ? feature.width ?? 60 : classified.class === "walk" ? dmath.max(1.2, feature.width ?? 2.4) : classified.class === "rail" ? 3 : transportWidth(feature, kind);
204
204
  const lanes = classified.class === "road" ? roadLanes(feature, width).total : 2;
205
205
  const link = isTransportLink(feature);
206
- for (const line of joinTerrainLines(feature.lines)) for (const piece of clipPolyline(toWorld(line), minX, minZ, maxX, maxZ)) {
206
+ for (const line of joinTerrainLines(feature.lines, feature.oneway === true)) for (const piece of clipPolyline(toWorld(line), minX, minZ, maxX, maxZ)) {
207
207
  const draft = {
208
208
  class: classified.class,
209
209
  kind: classified.kind,
@@ -237,6 +237,8 @@ const POI_KINDS = new Set([
237
237
  "tram_stop",
238
238
  "bus_stop",
239
239
  "traffic_signals",
240
+ "give_way",
241
+ "stop",
240
242
  "crossing",
241
243
  "aerodrome"
242
244
  ]);
@@ -247,13 +249,20 @@ function tilePois(pois, origin, tileSize) {
247
249
  const kind = (poi.subclass ?? poi.class).toLowerCase();
248
250
  const matched = POI_KINDS.has(kind) ? kind : POI_KINDS.has(poi.class) ? poi.class : void 0;
249
251
  if (matched === void 0) continue;
252
+ if ([
253
+ "traffic_signals",
254
+ "stop",
255
+ "give_way"
256
+ ].includes(matched) && (poi.bridge || poi.tunnel)) continue;
250
257
  const [u, v] = poi.point;
251
258
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
252
259
  result.push({
253
- kind: matched,
260
+ kind: matched === "stop" ? "give_way" : matched,
254
261
  x: origin[0] + u * tileSize,
255
262
  z: origin[1] + v * tileSize,
256
- ...poi.name !== void 0 ? { name: poi.name } : {}
263
+ ...poi.name !== void 0 ? { name: poi.name } : {},
264
+ ...poi.stop === "all" ? { allWay: true } : {},
265
+ layer: poi.layer ?? 0
257
266
  });
258
267
  }
259
268
  return result;
@@ -288,6 +297,7 @@ function wayDraft(way) {
288
297
  const points = way.points.map((p) => p.length === 3 ? [p[0], p[2]] : [p[0], p[1]]);
289
298
  const heights = way.points.every((p) => p.length === 3) ? way.points.map((p) => p[1]) : void 0;
290
299
  const common = {
300
+ ...way.drivingSide !== void 0 ? { drivingSide: way.drivingSide } : {},
291
301
  points,
292
302
  ...heights !== void 0 ? { heights } : {},
293
303
  layer: way.layer ?? 0,
@@ -513,6 +523,7 @@ const ambientStateSchema = z.strictObject({
513
523
  });
514
524
  const point = z.union([vec2, vec3]);
515
525
  const waySchema = z.strictObject({
526
+ drivingSide: z.enum(["right", "left"]).describe("Overrides the document road driving side.").optional(),
516
527
  id: z.string().min(1).describe("Optional stable id.").optional(),
517
528
  class: z.enum([
518
529
  "road",
package/dist/kernel.d.mts CHANGED
@@ -1,6 +1,8 @@
1
+ import { a as WildlifeWorld, c as WILDLIFE_FAMILIES, d as WildlifeHabitat, f as WildlifeMotion, i as WildlifeBudget, l as WildlifeChoice, m as wildlifeSpeciesSchema, n as WILDLIFE_TICK_RATE, o as stepWildlife, p as WildlifeSpecies, r as WildlifeAgent, s as wildlifeCandidates, t as WILDLIFE_CELL_METERS, u as WildlifeFamily } from "./wildlife-B4EL0z-N.mjs";
1
2
  import { Quat } from "@bendyline/molen-kernel/determinism";
2
3
  import { ComponentType, JsonObject, World } from "@bendyline/molen-kernel/world";
3
4
  import { ComponentMap, EntityId, SceneManifest } from "@bendyline/molen-schema";
5
+ import { z } from "zod";
4
6
  import { TerrainLinePath, TerrainPoiFeature, TerrainTransportationFeature } from "@bendyline/molen-terrain/kernel";
5
7
 
6
8
  //#region src/kernel/components.d.ts
@@ -204,6 +206,8 @@ interface TransportEdge {
204
206
  readonly tunnel: boolean;
205
207
  readonly link: boolean;
206
208
  readonly oneway: boolean;
209
+ /** Regional road traffic rule, retained through junction rebuilds and export. */
210
+ readonly drivingSide: "right" | "left";
207
211
  readonly lanes: string[];
208
212
  /** Source feature name, when mapped. */
209
213
  readonly name?: string;
@@ -215,7 +219,7 @@ interface TransportLane {
215
219
  readonly class: TransportClass;
216
220
  /** 1 travels the edge path forward (from → to), -1 backward. */
217
221
  readonly dir: 1 | -1;
218
- /** 0 = innermost (nearest the centreline for two-way roads, leftmost for one-way). */
222
+ /** 0 = innermost (leftmost for right-hand one-way roads, rightmost for left-hand). */
219
223
  readonly index: number;
220
224
  /** Signed lateral offset from the centreline, positive to the right of travel. */
221
225
  readonly offset: number;
@@ -339,6 +343,7 @@ declare function allRed(junction: TransportJunction, tick: number, tickRate: num
339
343
  type Point2 = [number, number];
340
344
  /** A polyline awaiting the planar split, in world metres. */
341
345
  interface EdgeDraft {
346
+ drivingSide?: "right" | "left";
342
347
  class: TransportClass;
343
348
  kind: RoadKind;
344
349
  points: Point2[];
@@ -399,6 +404,8 @@ interface WorldPoi {
399
404
  name?: string;
400
405
  /** Stations: dwell time in seconds. */
401
406
  dwell?: number;
407
+ allWay?: boolean;
408
+ layer?: number;
402
409
  }
403
410
  //#endregion
404
411
  //#region src/kernel/graph/doc.d.ts
@@ -406,6 +413,8 @@ declare const TRANSPORT_NETWORK_FORMAT: "molen/transport-network@1";
406
413
  /** A way's point: `[x, z]` or `[x, y, z]` in scene metres. */
407
414
  type TransportNetworkPoint = [number, number] | [number, number, number];
408
415
  interface TransportNetworkWay {
416
+ /** Overrides the document's road driving side. */
417
+ drivingSide?: "right" | "left";
409
418
  id?: string;
410
419
  class: "road" | "rail" | "path" | "air" | "water";
411
420
  subclass?: string;
@@ -468,11 +477,12 @@ interface GraphStore {
468
477
  setJunction(junction: TransportJunction): void;
469
478
  deleteJunction(id: string): void;
470
479
  /** Whether a mapped traffic-signal point lies within `radius` of a point. */
471
- signalNear(x: number, z: number, radius: number): boolean;
480
+ signalNear(x: number, z: number, radius: number, layer?: number): boolean;
472
481
  /** Stop and yield signs within `radius` of a point. */
473
- giveWayNear(x: number, z: number, radius: number): readonly {
482
+ giveWayNear(x: number, z: number, radius: number, layer?: number): readonly {
474
483
  x: number;
475
484
  z: number;
485
+ allWay?: boolean;
476
486
  }[];
477
487
  }
478
488
  /** Monotone stand-in for atan2 in [0, 4): orders directions without transcendental math. */
@@ -510,6 +520,8 @@ declare class LaneGrid {
510
520
  //#region src/kernel/graph/network.d.ts
511
521
  /** One streamed map tile's transport data. */
512
522
  interface AmbientTileInput {
523
+ /** Regional road driving side; defaults to the network's traffic setting. */
524
+ drivingSide?: "right" | "left";
513
525
  /** Unique tile key, e.g. `terrainPyramidTileKey(address)`. */
514
526
  key: string;
515
527
  /** World X/Z of the tile's north-west corner, in metres. */
@@ -544,6 +556,7 @@ interface TransportNetworkStats {
544
556
  }
545
557
  /** A script-added polyline. */
546
558
  interface AmbientPolyline {
559
+ drivingSide?: "right" | "left";
547
560
  class: "road" | "rail" | "path" | "water";
548
561
  subclass?: string;
549
562
  /** `[x, z]` or `[x, y, z]` points in scene metres. */
@@ -586,8 +599,8 @@ declare class TransportNetwork implements GraphStore {
586
599
  junction(id: string): TransportJunction | undefined;
587
600
  setJunction(junction: TransportJunction): void;
588
601
  deleteJunction(id: string): void;
589
- signalNear(x: number, z: number, radius: number): boolean;
590
- giveWayNear(x: number, z: number, radius: number): readonly WorldPoi[];
602
+ signalNear(x: number, z: number, radius: number, layer?: number): boolean;
603
+ giveWayNear(x: number, z: number, radius: number, layer?: number): readonly WorldPoi[];
591
604
  private controlsNear;
592
605
  /** Whether a tile key is registered. */
593
606
  hasTile(key: string): boolean;
@@ -733,6 +746,8 @@ interface AmbientOptions {
733
746
  policy?: DeepPartial<AmbientPolicy>;
734
747
  /** Vehicle and pedestrian types per class (default: proxy dimensions). */
735
748
  types?: Partial<AmbientTypes>;
749
+ /** Deterministic local road fleet at a prospective spawn point. An empty list suppresses it. */
750
+ carsAt?: (x: number, z: number) => readonly AmbientVehicleType[];
736
751
  /** Extra components per class; `null` spawns bare agents (ambientAgent + transform only). */
737
752
  templates?: Partial<Record<AmbientKind, AmbientTemplate | null>>;
738
753
  /** Seed for spawn draws (default: 'ambient'). */
@@ -808,6 +823,34 @@ interface AmbientCapabilityOptions extends Omit<AmbientOptions, "classes" | "see
808
823
  /** Build-world capability hook: `buildWorld(scene, setup, { capabilities: [ambientCapability()] })`. */
809
824
  declare function ambientCapability(opts?: AmbientCapabilityOptions): (world: World, manifest: SceneManifest) => Record<string, object> | undefined;
810
825
  //#endregion
826
+ //#region src/kernel/fleet.d.ts
827
+ interface FleetCatalog {
828
+ format: "molen/fleet-catalog@1";
829
+ id: string;
830
+ version: number;
831
+ description: string;
832
+ fallback: string;
833
+ regions: Record<string, string>;
834
+ profiles: Array<{
835
+ id: string;
836
+ title: string;
837
+ extends?: string;
838
+ weights: Record<string, number>;
839
+ }>;
840
+ }
841
+ declare const fleetCatalogSchema: z.ZodType<FleetCatalog>;
842
+ interface FleetMix {
843
+ profile: string;
844
+ weights: ReadonlyMap<string, number>;
845
+ }
846
+ interface FleetLibrary {
847
+ regions: ReadonlyMap<string, string>;
848
+ /** Stable bounded shortlist; never depends on camera motion, downloads or wall time. */
849
+ select(region?: string): FleetMix;
850
+ }
851
+ declare function createFleetLibrary(documents: readonly FleetCatalog[], available: ReadonlySet<string>, maxModels?: number): FleetLibrary;
852
+ declare function registerFleetSchema(): void;
853
+ //#endregion
811
854
  //#region src/kernel/graph/export.d.ts
812
855
  /** Every road, rail and path edge as a way (with surface heights), plus stations and signals. */
813
856
  declare function networkToDocument(network: TransportNetwork, meta?: Pick<TransportNetworkDocument, "name" | "origin">, options?: {
@@ -892,4 +935,4 @@ interface ObserverView {
892
935
  keep?: number;
893
936
  }
894
937
  //#endregion
895
- export { AMBIENT_AGENT_COMPONENT, AMBIENT_ENTITY, AMBIENT_KINDS, AMBIENT_OBSERVER_COMPONENT, AMBIENT_ROLE_COMPONENT, AMBIENT_STATE_COMPONENT, type AgentEnv, AmbientAgent, type AmbientAgentData, type AmbientAirCorridor, type AmbientBox, type AmbientBudget, type AmbientCapabilityOptions, type AmbientClassPolicy, type AmbientHandle, type AmbientKind, AmbientObserver, type AmbientObserverData, type AmbientObserverState, type AmbientOptions, type AmbientPedestrianType, type AmbientPolicy, type AmbientPolyline, AmbientRole, type AmbientRoleData, type AmbientRoleVisual, type AmbientSolid, type AmbientSpawnInfo, AmbientState, type AmbientStateData, type AmbientStats, type AmbientTemplate, type AmbientTileInput, type AmbientTypes, type AmbientVehicleType, CAR_COLORS, DEFAULT_POLICY, DEFAULT_TEMPLATES, DEFAULT_TYPES, type DeepPartial, type DriverParams, type EdgeDraft, type EdgeSpan, GRID_CELL, type JunctionArm, type JunctionControl, KIND_SPEED, LaneGrid, type LaneMovement, type LaneSample, type LaneStop, type ObserverView, type PlanarNode, type PlanarPiece, type PlanarResult, type RoadKind, type SignalColor, type SignalTiming, TRANSPORT_NETWORK_EXAMPLE, TRANSPORT_NETWORK_FORMAT, type TransportClass, type TransportCrossing, type TransportEdge, type TransportJunction, type TransportLane, TransportNetwork, type TransportNetworkAerodrome, type TransportNetworkDocument, type TransportNetworkOptions, type TransportNetworkPoint, type TransportNetworkSignal, type TransportNetworkStation, type TransportNetworkStats, type TransportNetworkWay, type TransportNode, type TransportRunway, type TurnKind, type WorldPoi, agentRotation, agentSample, allRed, ambientCapability, ambientOf, ambientScriptApi, chooseNext, classifyFeature, clipPolyline, edgeHeight, featureDrafts, fmix32, idmAcceleration, installAmbient, laneCoordinate, laneEdgeDistance, laneSample, mergePolicy, networkToDocument, pickWeighted, planarSplit, policyForBudget, pseudoAngle, registerAmbientSchema, sampleConnector, sampleLaneBody, signalColor, signalTiming, stepAgents, stoppingDistance, unit01, walkBack };
938
+ export { AMBIENT_AGENT_COMPONENT, AMBIENT_ENTITY, AMBIENT_KINDS, AMBIENT_OBSERVER_COMPONENT, AMBIENT_ROLE_COMPONENT, AMBIENT_STATE_COMPONENT, type AgentEnv, AmbientAgent, type AmbientAgentData, type AmbientAirCorridor, type AmbientBox, type AmbientBudget, type AmbientCapabilityOptions, type AmbientClassPolicy, type AmbientHandle, type AmbientKind, AmbientObserver, type AmbientObserverData, type AmbientObserverState, type AmbientOptions, type AmbientPedestrianType, type AmbientPolicy, type AmbientPolyline, AmbientRole, type AmbientRoleData, type AmbientRoleVisual, type AmbientSolid, type AmbientSpawnInfo, AmbientState, type AmbientStateData, type AmbientStats, type AmbientTemplate, type AmbientTileInput, type AmbientTypes, type AmbientVehicleType, CAR_COLORS, DEFAULT_POLICY, DEFAULT_TEMPLATES, DEFAULT_TYPES, type DeepPartial, type DriverParams, type EdgeDraft, type EdgeSpan, type FleetCatalog, type FleetLibrary, type FleetMix, GRID_CELL, type JunctionArm, type JunctionControl, KIND_SPEED, LaneGrid, type LaneMovement, type LaneSample, type LaneStop, type ObserverView, type PlanarNode, type PlanarPiece, type PlanarResult, type RoadKind, type SignalColor, type SignalTiming, TRANSPORT_NETWORK_EXAMPLE, TRANSPORT_NETWORK_FORMAT, type TransportClass, type TransportCrossing, type TransportEdge, type TransportJunction, type TransportLane, TransportNetwork, type TransportNetworkAerodrome, type TransportNetworkDocument, type TransportNetworkOptions, type TransportNetworkPoint, type TransportNetworkSignal, type TransportNetworkStation, type TransportNetworkStats, type TransportNetworkWay, type TransportNode, type TransportRunway, type TurnKind, WILDLIFE_CELL_METERS, WILDLIFE_FAMILIES, WILDLIFE_TICK_RATE, type WildlifeAgent, type WildlifeBudget, type WildlifeChoice, type WildlifeFamily, type WildlifeHabitat, type WildlifeMotion, type WildlifeSpecies, type WildlifeWorld, type WorldPoi, agentRotation, agentSample, allRed, ambientCapability, ambientOf, ambientScriptApi, chooseNext, classifyFeature, clipPolyline, createFleetLibrary, edgeHeight, featureDrafts, fleetCatalogSchema, fmix32, idmAcceleration, installAmbient, laneCoordinate, laneEdgeDistance, laneSample, mergePolicy, networkToDocument, pickWeighted, planarSplit, policyForBudget, pseudoAngle, registerAmbientSchema, registerFleetSchema, sampleConnector, sampleLaneBody, signalColor, signalTiming, stepAgents, stepWildlife, stoppingDistance, unit01, walkBack, wildlifeCandidates, wildlifeSpeciesSchema };