@adatechnology/game-urban-three

中文文档
0.3.10发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 2103

Draws the urban pattern of game-urban with three.js: parts as meshes with the team's rounded boxes, instanced road dashes and windows (lit and dark), canvas signs and labels, point and spot lights from the light budget, and the animations (flickering lamp

原始使用文档

@adatechnology/game-urban-three

Draws the scenes of @adatechnology/game-urban with three.js, the way the team's Galeria do Vale Cinzento does.

import * as THREE from 'three'
import { createUrban } from '@adatechnology/game-urban'
import { createUrbanThree } from '@adatechnology/game-urban-three'

const urban = createUrban()
const b = urban.builder({ seed: 7 })
urban.streets.grid(b, { block: 36, count: 2, width: 10 })
urban.poles.get('led_double').build(b, { x: 18, z: 5 })

const three = createUrbanThree(THREE, { document })   // `document` only for signs and labels
const drawn = three.draw(b.scene())
scene.add(drawn.root)
// each frame: drawn.animate(elapsedSeconds)            // flickering lamps, sweeping searchlights
// when done:  drawn.dispose()
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • draw(scene, { root }) draws into a group of yours. Works on three r160 and later.

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.

Geometry

Planes, cylinders, cones, boxes (and the rounded box built on one), the prism's extrusion and the test area's light reach spheres are made through shapeGeometries(THREE) of @adatechnology/game-shapes-three: the same bytes as three's constructors (tests/exact-golden.test.ts), cached by parameters. The dodecahedron rock is still three's own.

Test area

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).

  • 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.
  • 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.
  • 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.
  • 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).
  • 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.

版本与发布记录

@adatechnology/game-urban-three 共发布 23 个版本,首次发布于 2026/10/25;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.10latest2026/11/08今天
0.3.92026/11/07今天
0.3.82026/11/07今天
0.3.72026/11/07今天
0.3.62026/11/071 天前
0.3.52026/11/061 天前

关于 @adatechnology/game-urban-three 的常见问题

@adatechnology/game-urban-three 是什么?

Draws the urban pattern of game-urban with three.js: parts as meshes with the team's rounded boxes, instanced road dashes and windows (lit and dark), canvas signs and labels, point and spot lights from the light budget, and the animations (flickering lamp

如何安装 @adatechnology/game-urban-three?

在项目目录运行 npm install @adatechnology/game-urban-three,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:three(^0.160.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adatechnology/game-urban-three 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adatechnology/game-urban-three 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adatechnology/game-urban-three 可以商用吗?

@adatechnology/game-urban-three 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adatechnology/game-urban-three 的下载量有多少?

根据 npm 官方下载统计,@adatechnology/game-urban-three 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,103 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adatechnology/game-urban-three 还在维护吗?

最新版本 0.3.10 发布于 2026/11/08(今天);至今共发布 23 个版本,其中过去 12 个月发布了 23 个;首次发布于 2026/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。