@bendyline/molen-ambient 0.0.13 → 0.0.15

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.
package/dist/client.d.mts CHANGED
@@ -216,7 +216,12 @@ declare class WildlifeRenderer {
216
216
  private frame;
217
217
  private cursor;
218
218
  private budget;
219
- constructor(prepare?: ((object: THREE.Object3D) => void) | undefined);
219
+ /**
220
+ * `prepare` builds an animal's shaders (a renderer's `prepareObject`). When it returns a
221
+ * promise, a new animal stays hidden until that settles: drawn at once, the first animal of a
222
+ * flight built its skinned program mid-frame, for well over 100 ms.
223
+ */
224
+ constructor(prepare?: ((object: THREE.Object3D) => unknown) | undefined);
220
225
  setBudget(budget: Partial<WildlifeRenderBudget>): void;
221
226
  get count(): number;
222
227
  get triangles(): number;
package/dist/client.mjs CHANGED
@@ -1028,6 +1028,22 @@ var VehicleDetail = class {
1028
1028
  has(id) {
1029
1029
  return this.active.has(id);
1030
1030
  }
1031
+ /**
1032
+ * Pool the models of agents that are gone (call every frame): a car a host takes out of traffic
1033
+ * leaves in the frame its replacement shows, not up to a `select` later as a double.
1034
+ */
1035
+ dropGone(exists) {
1036
+ for (const [id, entry] of this.active) if (!exists(id)) this.idleOut(id, entry);
1037
+ }
1038
+ idleOut(id, entry) {
1039
+ entry.visual.object.visible = false;
1040
+ this.active.delete(id);
1041
+ const pool = this.idle.get(entry.type) ?? [];
1042
+ pool.push(entry.visual);
1043
+ this.idle.set(entry.type, pool);
1044
+ const resident = this.resident.get(entry.visual);
1045
+ if (resident) resident.used = ++this.clock;
1046
+ }
1031
1047
  get count() {
1032
1048
  return this.active.size;
1033
1049
  }
@@ -1040,15 +1056,7 @@ var VehicleDetail = class {
1040
1056
  this.candidates = wanted;
1041
1057
  this.wanted = new Set(wanted.map((c) => c.type));
1042
1058
  for (const [type, controller] of this.loading) if (!this.wanted.has(type)) controller.abort();
1043
- for (const [id, entry] of this.active) if (!keep.has(id) || !exists(id)) {
1044
- entry.visual.object.visible = false;
1045
- this.active.delete(id);
1046
- const pool = this.idle.get(entry.type) ?? [];
1047
- pool.push(entry.visual);
1048
- this.idle.set(entry.type, pool);
1049
- const resident = this.resident.get(entry.visual);
1050
- if (resident) resident.used = ++this.clock;
1051
- }
1059
+ for (const [id, entry] of this.active) if (!keep.has(id) || !exists(id)) this.idleOut(id, entry);
1052
1060
  let started = 0;
1053
1061
  for (const candidate of wanted) {
1054
1062
  if (this.active.has(candidate.id)) continue;
@@ -1269,6 +1277,9 @@ function createAmbientRenderer(options) {
1269
1277
  aircraft: 0,
1270
1278
  boats: 0
1271
1279
  };
1280
+ const agentExists = (id) => world.has(id, AmbientAgent);
1281
+ detail?.dropGone(agentExists);
1282
+ boatDetail?.dropGone(agentExists);
1272
1283
  for (const [id, a, t] of world.query(AmbientAgent, Transform)) {
1273
1284
  const agent = a;
1274
1285
  if (agent.kind === "pedestrian") {
@@ -2265,6 +2276,11 @@ var WildlifeRenderer = class {
2265
2276
  radius: 180,
2266
2277
  posesPerFrame: 16
2267
2278
  };
2279
+ /**
2280
+ * `prepare` builds an animal's shaders (a renderer's `prepareObject`). When it returns a
2281
+ * promise, a new animal stays hidden until that settles: drawn at once, the first animal of a
2282
+ * flight built its skinned program mid-frame, for well over 100 ms.
2283
+ */
2268
2284
  constructor(prepare) {
2269
2285
  this.prepare = prepare;
2270
2286
  this.group.name = "ambient:wildlife";
@@ -2327,7 +2343,14 @@ var WildlifeRenderer = class {
2327
2343
  object.userData.walkIgnore = true;
2328
2344
  });
2329
2345
  this.group.add(root);
2330
- this.prepare?.(root);
2346
+ const prepared = this.prepare?.(root);
2347
+ if (prepared instanceof Promise) {
2348
+ root.visible = false;
2349
+ const show = () => {
2350
+ root.visible = true;
2351
+ };
2352
+ prepared.then(show, show);
2353
+ }
2331
2354
  animal = {
2332
2355
  root,
2333
2356
  mesh,
package/dist/kernel.d.mts CHANGED
@@ -606,6 +606,7 @@ declare class TransportNetwork implements GraphStore {
606
606
  readonly grid: LaneGrid;
607
607
  private readonly tunnels;
608
608
  private readonly ground;
609
+ private readonly gradedTiles;
609
610
  private classes;
610
611
  private readonly nodes;
611
612
  private readonly edges;
package/dist/kernel.mjs CHANGED
@@ -3,7 +3,7 @@ import { createRng, dmath, lookRotation, quatRotateVec3, seedToInt } from "@bend
3
3
  import { Transform, componentHandle, isBoostMode } from "@bendyline/molen-kernel/world";
4
4
  import { boostSpeedMultiplier, deepMergeJson, getSchema, registerSchema, resolvePrefab, validateByKind } from "@bendyline/molen-schema";
5
5
  import { z } from "zod";
6
- import { PATH_SURFACE_LIFT, ROAD_SURFACE_LIFT, bridgeDeckHeightFn, isArterialRoad, lineSegmentIndex, sampleTerrainLine } from "@bendyline/molen-terrain/kernel";
6
+ import { PATH_SURFACE_LIFT, ROAD_SURFACE_LIFT, bridgeDeckHeightFn, gradeHighwayBridges, isArterialRoad, lineSegmentIndex, sampleTerrainLine } from "@bendyline/molen-terrain/kernel";
7
7
  //#region src/kernel/agents/idm.ts
8
8
  /** Intelligent Driver Model: acceleration from speed, desired speed and the gap to a leader. */
9
9
  /**
@@ -1977,6 +1977,7 @@ var TransportNetwork = class {
1977
1977
  grid = new LaneGrid();
1978
1978
  tunnels;
1979
1979
  ground;
1980
+ gradedTiles = /* @__PURE__ */ new WeakMap();
1980
1981
  classes;
1981
1982
  nodes = /* @__PURE__ */ new Map();
1982
1983
  edges = /* @__PURE__ */ new Map();
@@ -2098,7 +2099,22 @@ var TransportNetwork = class {
2098
2099
  /** Build and add one map tile (replacing a previous registration under the same key). */
2099
2100
  registerTile(input) {
2100
2101
  if (this.tiles.has(input.key)) this.unregisterTile(input.key);
2101
- const { drafts, runways } = featureDrafts(input, { tunnels: this.tunnels });
2102
+ const ground = input.heightAt ?? this.ground;
2103
+ let graded = this.gradedTiles.get(input.features);
2104
+ if (!graded || graded.size !== input.tileSize || graded.ground !== ground || graded.origin[0] !== input.origin[0] || graded.origin[1] !== input.origin[1]) {
2105
+ graded = {
2106
+ origin: [...input.origin],
2107
+ size: input.tileSize,
2108
+ ground,
2109
+ features: gradeHighwayBridges(input.features, input.tileSize, (x, z) => ground(input.origin[0] + x, input.origin[1] + z))
2110
+ };
2111
+ this.gradedTiles.set(input.features, graded);
2112
+ }
2113
+ const features = graded.features;
2114
+ const { drafts, runways } = featureDrafts({
2115
+ ...input,
2116
+ features
2117
+ }, { tunnels: this.tunnels });
2102
2118
  for (const draft of drafts) draft.drivingSide = input.drivingSide ?? this.traffic;
2103
2119
  const pois = tilePois(input.pois, input.origin, input.tileSize, input.bounds);
2104
2120
  const rect = input.bounds ? [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/molen-ambient",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -41,14 +41,14 @@
41
41
  "dist"
42
42
  ],
43
43
  "dependencies": {
44
- "@bendyline/molen-figures": "0.0.11",
45
- "@bendyline/molen-kernel": "0.0.9",
46
- "@bendyline/molen-schema": "0.0.9",
47
- "@bendyline/molen-terrain": "0.0.13",
44
+ "@bendyline/molen-figures": "0.0.13",
45
+ "@bendyline/molen-kernel": "0.0.10",
46
+ "@bendyline/molen-schema": "0.0.10",
47
+ "@bendyline/molen-terrain": "0.0.15",
48
48
  "zod": "^4.6.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "@bendyline/molen-client": "0.0.11",
51
+ "@bendyline/molen-client": "0.0.13",
52
52
  "three": ">=0.184.0 <0.187.0"
53
53
  },
54
54
  "peerDependenciesMeta": {
@@ -60,7 +60,7 @@
60
60
  }
61
61
  },
62
62
  "devDependencies": {
63
- "@bendyline/molen-client": "0.0.11",
63
+ "@bendyline/molen-client": "0.0.13",
64
64
  "@biomejs/biome": "^2.5.0",
65
65
  "@types/three": "0.184.0",
66
66
  "fast-check": "^3.23.2",