@adatechnology/game-urban-three 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anderson Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @adatechnology/game-urban-three
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Draws the scenes of `@adatechnology/game-urban` with three.js, the way the team's Galeria do Vale Cinzento does.
4
+
5
+ ```ts
6
+ import * as THREE from 'three'
7
+ import { createUrban } from '@adatechnology/game-urban'
8
+ import { createUrbanThree } from '@adatechnology/game-urban-three'
9
+
10
+ const urban = createUrban()
11
+ const b = urban.builder({ seed: 7 })
12
+ urban.streets.grid(b, { block: 36, count: 2, width: 10 })
13
+ urban.poles.get('led_double').build(b, { x: 18, z: 5 })
14
+
15
+ const three = createUrbanThree(THREE, { document }) // `document` only for signs and labels
16
+ const drawn = three.draw(b.scene())
17
+ scene.add(drawn.root)
18
+ // each frame: drawn.animate(elapsedSeconds) // flickering lamps, sweeping searchlights
19
+ // when done: drawn.dispose()
20
+ ```
21
+
22
+ - Each part becomes a mesh in the order it was added: boxes with the team's rounded edge (a 4x4x4 grid per face, edge vertices on an arc), tapered cylinders, flat-shaded cones and prisms, planes that only receive shadows, crowns that only cast, canvas signs and labels.
23
+ - The small boxes (road dashes, sandbags) are one instanced mesh, and the windows two (lit ones glow, dark ones are a dark pane). The instance matrices are the page's.
24
+ - Lights are real `PointLight` and `SpotLight` objects; `drawn.lights` lists them. `animate(t)` flickers the failing lamps (`I * (sin(23t + x) > 0.3 || sin(3.1t) > 0.85 ? 0.15 : 1)`) and moves each searchlight target around its tower.
25
+ - A `terrain` part becomes the square mesh with vertex colours (flat shaded, roughness 1, casts and receives shadows); the water is a plane part drawn after it.
26
+ - A `placement` part (a vehicle of the fleet, a species of the pack) becomes a group at the spot, turned and scaled, holding the object a resolver made: `createUrbanThree(THREE, { resolvers: { vehicle: createVehicleResolver(vehiclesThree), plant: createPlantResolver(THREE) } })`. The vehicle resolver uses the `lite` build of `game-vehicles-three` (six fused meshes) and the plant resolver `generate` and `createPlantObject` of `game-vegetation`; each is built once for an id and paint (or seed) and cloned for every spot, sharing geometry and materials. An id the package does not know leaves the spot empty. `resolver.dispose()` frees them.
27
+ - `draw(scene, { root })` draws into a group of yours. Works on three r128 and later.
28
+
29
+ The scene hash, the lists of instances and the surface of each material (shadows, roughness, metalness, flat shading) of 34 cases are tested against the page.
30
+
31
+ ## Test area
32
+
33
+ `createUrbanTestModule(options)` and `loadUrbanTestModule(room, options)` put the city in the shared test room (`?area=urban` in `examples/urban-test-area`; the module also loads in `examples/interactables-test-area`).
34
+
35
+ - Items (17): the five poles of the kit in a row, a street grid with a filled block, a patch of terrain (a rolling plain with a river and a lake; `terrain` replaces it) and the ten neighbourhoods of the sample sheet in the Galeria's cells. Everything is drawn by the kit and this package, so a game that passes `urban: { packs, patch, remove }` sees its own catalogues in the area. Each item is scenery: one anchored slab of concrete as large as the sample.
36
+ - Bench: the neighbourhood, the seed, the share of lamps on (the pattern's own, all, half, none), the budget of real lights and, when asked, the species of the region and the vehicles of the fleet (a game gives `vehicles: (THREE) => createVehiclesThree(...)`; without it the bench parks no cars). Actions draw and take away the neighbourhood in front of the player; changing a setting draws it again.
37
+ - Layers: the reach of every real light and the box of each sample. Metrics: samples, draw calls, triangles, real lights, instances, objects of the bench and the light budget left.
38
+ - Eight scenarios, with no object of the room: pole heights, the light budget (the counter goes below zero as the page's), the dash every 5 m, block heights, the seed, burnt-out lamps, the terrain (vertex height, river bed, lake level) and the providers (vehicles of the fleet, species of the region).
39
+ - The room's camera sees 140 m and the sample sheet is 240 m wide, so the module lends the camera a 600 m view while it is loaded and gives the old one back when it detaches.
@@ -0,0 +1,170 @@
1
+ import { PlacementPart, UrbanScene, UrbanOptions, TerrainOptions } from '@adatechnology/game-urban';
2
+ import { Lod, Condition, Season } from '@adatechnology/game-vegetation';
3
+ import { createVegetationMaterials } from '@adatechnology/game-vegetation/three';
4
+ import { BuildVehicleOptions } from '@adatechnology/game-vehicles-three';
5
+ import { TestableModule, ModuleScenario } from '@adatechnology/game-contracts';
6
+
7
+ type Three$3 = any;
8
+ /** What `document.createElement('canvas')` needs; a fake works in Node. */
9
+ type CanvasFactory = {
10
+ createElement(tag: string): any;
11
+ };
12
+ type TextTextureOptions = {
13
+ width: number;
14
+ height: number;
15
+ background: string;
16
+ foreground: string;
17
+ font: string;
18
+ };
19
+ /** Canvas texture with centred lines of text, shrunk to fit 92 % of the width, on a filled background. */
20
+ declare function createTextTexture(THREE: Three$3, document: CanvasFactory, lines: readonly string[], o: TextTextureOptions): any;
21
+
22
+ type Three$2 = any;
23
+ /** Makes the object of a placement; null when it cannot (an unknown id). The drawer clones it for each spot. */
24
+ type PlacementResolver = ((part: PlacementPart) => any | null) & {
25
+ dispose?: () => void;
26
+ };
27
+ type VehicleResolverOptions = {
28
+ /** `lite` fuses a vehicle into six meshes, the right cost for a street of parked cars. Default `lite`. */
29
+ quality?: BuildVehicleOptions['quality'];
30
+ };
31
+ /** What the vehicle resolver needs of `createVehiclesThree`. */
32
+ type VehicleBuilder = {
33
+ build(key: string, options?: BuildVehicleOptions): {
34
+ group: any;
35
+ dispose(): void;
36
+ };
37
+ };
38
+ /**
39
+ * Resolves vehicle placements with the vehicles of `game-vehicles-three`. A vehicle is built once for each id and paint and cloned
40
+ * (clones share geometry and materials) for each spot.
41
+ */
42
+ declare function createVehicleResolver(vehicles: VehicleBuilder, options?: VehicleResolverOptions): PlacementResolver;
43
+ type PlantResolverOptions = {
44
+ /** Level of detail of the plants of a street. Default 1. */
45
+ lod?: Lod;
46
+ condition?: Condition;
47
+ season?: Season;
48
+ /** Materials of the plants (wind included); default new ones. */
49
+ materials?: ReturnType<typeof createVegetationMaterials>;
50
+ };
51
+ /** Resolves plant placements with the species of `game-vegetation-species`, built with `game-vegetation`. One plant for each species and seed, cloned for each spot. */
52
+ declare function createPlantResolver(THREE: Three$2, options?: PlantResolverOptions): PlacementResolver;
53
+
54
+ type Three$1 = any;
55
+ type UrbanThreeOptions = {
56
+ /** Where canvases come from (the page's `document`). Needed only for signs and labels. */
57
+ document?: CanvasFactory;
58
+ /** Who makes the objects of the vehicles and plants a scene places. A kind without a resolver is left empty. */
59
+ resolvers?: {
60
+ vehicle?: PlacementResolver;
61
+ plant?: PlacementResolver;
62
+ };
63
+ };
64
+ /** What a drawn scene gives back: the group to add to a scene, the per-frame animation and the cleanup. */
65
+ type DrawnUrban = {
66
+ root: any;
67
+ /** Moves the animated parts to time `t` (seconds): flickering lamps and sweeping searchlights. */
68
+ animate(t: number): void;
69
+ /** Lights drawn, for a budget meter. */
70
+ readonly lights: any[];
71
+ dispose(): void;
72
+ };
73
+ type DrawOptions = {
74
+ /** Group the parts go into. Default a new `THREE.Group`. */
75
+ root?: any;
76
+ };
77
+ /**
78
+ * Draws urban scenes with three.js the way the team's page does: a mesh per part in the order they were added (boxes with the
79
+ * rounded edge, cylinders, flat-shaded cones and prisms, planes that only receive shadows, canvas signs), then one instanced mesh for
80
+ * the small boxes and one for each kind of window. Materials are shared by colour. The instance matrices are the page's.
81
+ */
82
+ declare function createUrbanThree(THREE: Three$1, options?: UrbanThreeOptions): {
83
+ THREE: any;
84
+ draw: (scene: UrbanScene, drawOptions?: DrawOptions) => DrawnUrban;
85
+ };
86
+ type UrbanThree = ReturnType<typeof createUrbanThree>;
87
+
88
+ type Three = any;
89
+ /** The team's rounded box: a 4x4x4 grid per face with the edge vertices pushed onto an arc of the given radius (smooth normals). A radius of 0 is a plain box. */
90
+ declare function createRoundedBox(THREE: Three, width: number, height: number, depth: number, radius: number): any;
91
+ /** Triangle prism: the triangle `width` wide and `height` high, extruded `depth` long and centred on z. Base at y = 0. */
92
+ declare function createPrism(THREE: Three, width: number, height: number, depth: number): any;
93
+
94
+ type UrbanTestOptions = {
95
+ /** `en` or `pt-BR` (default). The room asks `items(locale)` and `scenarios(locale)` itself; this is the language of the bench and of the signs of the neighbourhoods. */
96
+ readonly locale?: string;
97
+ /** Seed of the fixed samples of the area (default 7, the Galeria's). */
98
+ readonly seed?: number;
99
+ /** Options of the urban kit the area draws with (packs, patches, removals): a game's own catalogues show up in the area. */
100
+ readonly urban?: UrbanOptions;
101
+ /** The terrain of the terrain patch (default a small rolling plain with a river and a lake). */
102
+ readonly terrain?: TerrainOptions;
103
+ /** Where canvases come from for the signs; default the page's `document`. */
104
+ readonly document?: CanvasFactory;
105
+ /** Builds the vehicles of the fleet for the `vehicle` provider of the bench (`createVehiclesThree` of `game-vehicles-three`). Without it the bench parks no cars. */
106
+ readonly vehicles?: (THREE: unknown) => VehicleBuilder;
107
+ /** Where the bench draws its neighbourhood in the room, `[x, z]` (default `[0, -60]`). */
108
+ readonly benchOrigin?: readonly [number, number];
109
+ };
110
+ /** What a scenario needs of the room: the pass/fail line and time. The checks of this area are on the kit's own numbers, so no object of the room is touched. */
111
+ type UrbanContext = {
112
+ expect(condition: boolean, label: string, data?: Record<string, unknown>): void;
113
+ step(seconds: number): void;
114
+ };
115
+
116
+ declare const URBAN_AREA_ID = "urban";
117
+ /** The default terrain patch of the area: a rolling plain 96 m wide with a river across it and a round lake. A game passes its own through `terrain`. */
118
+ declare const DEFAULT_TEST_TERRAIN: TerrainOptions;
119
+ /**
120
+ * The urban test area as a `TestableModule`: the five poles of the Galeria in a row, a street grid with a filled block, a patch of terrain and the ten neighbourhoods of the
121
+ * sample sheet in its cells, each drawn by the kit and `game-urban-three` (so a game that patches the catalogues sees its own). The bench draws any neighbourhood in front of the player with
122
+ * a seed, a share of lamps on, a light budget and, when asked, the vehicles of the fleet and the species of the region; its layers show the reach of the real lights and the box of each sample.
123
+ */
124
+ declare function createUrbanTestModule(options?: UrbanTestOptions): TestableModule<UrbanContext> & {
125
+ readonly placed: ReadonlyMap<string, unknown>;
126
+ tick(t: number): void;
127
+ readonly itemIds: readonly string[];
128
+ };
129
+ /** What `loadUrbanTestModule` needs of a room: `TestRoom.loadModule` has it. */
130
+ type ModuleRoomLike = {
131
+ loadModule(module: never): unknown;
132
+ };
133
+ /** Loads the urban module into a room. */
134
+ declare function loadUrbanTestModule<Room extends ModuleRoomLike>(room: Room, options?: UrbanTestOptions): ReturnType<Room['loadModule']>;
135
+
136
+ /** Words and sentences of the urban area, by locale. `{0}`, `{1}`... are filled in order. */
137
+ type UrbanText = {
138
+ group: string;
139
+ name: string;
140
+ items: Record<string, string>;
141
+ controls: Record<'pattern' | 'seed' | 'lamps' | 'budget' | 'providers', string>;
142
+ hints: Record<'pattern' | 'seed' | 'lamps' | 'budget' | 'providers', string>;
143
+ options: {
144
+ lamps: Record<string, string>;
145
+ providers: Record<string, string>;
146
+ };
147
+ actions: Record<'compose' | 'clear', string>;
148
+ layers: Record<'light_radius' | 'bounds', string>;
149
+ metrics: Record<'samples' | 'draw_calls' | 'triangles' | 'real_lights' | 'instances' | 'bench_objects' | 'light_budget_left', string>;
150
+ log: Record<'composed' | 'cleared' | 'no_vehicles', string>;
151
+ scenarios: Record<string, string>;
152
+ checks: Record<string, string>;
153
+ };
154
+ declare const TEXT: Record<string, UrbanText>;
155
+
156
+ /** The heights of the five poles of the Galeria (m), the tops measured on the page's scenes. A game's own poles are not checked. */
157
+ declare const POLE_TOPS: Readonly<Record<string, number>>;
158
+ type ScenarioDeps = {
159
+ readonly text: UrbanText;
160
+ readonly urban: UrbanOptions | undefined;
161
+ readonly terrain: TerrainOptions;
162
+ };
163
+ /**
164
+ * The scenarios of the urban area: checks on the numbers the kit promises (the poles' heights, the light budget, the dashes of a road,
165
+ * the heights of a block, the determinism of a neighbourhood, burnt-out lamps, the terrain, the providers). They need no object of the
166
+ * room, so a game that patches the catalogues sees at once what it changed.
167
+ */
168
+ declare const createScenarios: (deps: ScenarioDeps) => ModuleScenario<UrbanContext>[];
169
+
170
+ export { type CanvasFactory, DEFAULT_TEST_TERRAIN, type DrawOptions, type DrawnUrban, type ModuleRoomLike, POLE_TOPS, type PlacementResolver, type PlantResolverOptions, TEXT, type TextTextureOptions, URBAN_AREA_ID, type UrbanContext, type UrbanTestOptions, type UrbanText, type UrbanThree, type UrbanThreeOptions, type VehicleBuilder, type VehicleResolverOptions, createPlantResolver, createPrism, createRoundedBox, createScenarios, createTextTexture, createUrbanTestModule, createUrbanThree, createVehicleResolver, loadUrbanTestModule };