roamwright 0.61.26 → 0.61.28
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/README.md +3 -1
- package/examples/set-pieces.html +52 -0
- package/examples/set-pieces.js +284 -0
- package/examples/troops.html +56 -0
- package/examples/troops.js +309 -0
- package/geometry/camp-layout.js +150 -0
- package/geometry/cavern-rock.js +309 -0
- package/geometry/cliff-sheets.js +457 -0
- package/geometry/creased-sheet.js +39 -0
- package/geometry/curtain-sheets.js +67 -0
- package/geometry/ice-cliff.js +339 -0
- package/geometry/ice-shards.js +247 -0
- package/geometry/index.js +203 -0
- package/geometry/instances.js +50 -1
- package/geometry/plant-roots.js +115 -0
- package/geometry/primitives.js +4 -0
- package/geometry/rock-sheets.js +259 -0
- package/geometry/strata-rocks.js +4 -3
- package/index.js +6 -469
- package/math/index.js +9 -0
- package/math/scalar.js +3 -1
- package/motion/index.js +100 -0
- package/motion/troop-director.js +482 -0
- package/motion/troop-volleys.js +197 -0
- package/package.json +1 -1
- package/rendering/camp-layout.js +55 -0
- package/rendering/curtain-sheets.js +271 -0
- package/rendering/flame-sources.js +105 -0
- package/rendering/ice-material.js +143 -0
- package/rendering/index.js +201 -0
- package/rendering/rock-materials.js +27 -0
- package/rendering/ruins-fittings.js +110 -17
- package/rendering/troop-director.js +374 -0
- package/rendering/troop-mounts.js +326 -0
- package/rendering/troop-standards.js +259 -0
- package/rendering/troop-volleys.js +143 -0
- package/runtime/index.js +95 -0
- package/runtime/lazy-sets.js +24 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roamwright's public rendering, materials and drawn systems, grouped by subsystem. Re-exported whole from `roamwright`.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ── Context, math & core geometry ────────────────────────────────────────
|
|
7
|
+
export { RENDER_LAYERS, createRenderContext } from './context.js';
|
|
8
|
+
export {
|
|
9
|
+
UNSIGNED_HDR_SENTINEL,
|
|
10
|
+
createMatchedRenderTarget,
|
|
11
|
+
createMatchingRenderTarget,
|
|
12
|
+
describeRenderTargetFormat,
|
|
13
|
+
isUnsignedFloatInternalFormat,
|
|
14
|
+
} from './target-format.js';
|
|
15
|
+
export { createPipelineWarmup } from './warm-pipelines.js';
|
|
16
|
+
export { createDaylightSky, createSkyPanorama, createSkyTexture } from './daylight-sky.js';
|
|
17
|
+
export { bindKeyboardOrbit, createOrbitCamera } from './orbit-camera.js';
|
|
18
|
+
export { createDayCycle, luminanceOf } from './day-cycle.js';
|
|
19
|
+
export { DEFAULT_DAY_CYCLE, DEFAULT_SKY_PALETTE } from './day-cycle-defaults.js';
|
|
20
|
+
export { createSurfaceMaterialFactory } from './surface-material.js';
|
|
21
|
+
export { createClothMaterial } from './cloth-material.js';
|
|
22
|
+
export { createFacadeGlassMaterial, DEFAULT_ROOM_SHADE } from './facade-glass-material.js';
|
|
23
|
+
export { createStainMaterial } from './stain-material.js';
|
|
24
|
+
|
|
25
|
+
// ── Terrain & land baking ────────────────────────────────────────────────
|
|
26
|
+
export { createSimpleWater } from './water-simple.js';
|
|
27
|
+
export { createCrystalMaterial } from './rock-materials.js';
|
|
28
|
+
export { ICE_SHADER_PARTS, createIceMaterial, createIceSheetTexture } from './ice-material.js';
|
|
29
|
+
export { createStrataCliffs } from './strata-cliffs.js';
|
|
30
|
+
export { meshTalusStones } from './strata-talus.js';
|
|
31
|
+
export { MOUND_RUINS_LOD, raiseMoundRuins, registerMoundRuins } from './ruins-mound.js';
|
|
32
|
+
export {
|
|
33
|
+
FLAME_DEFAULTS,
|
|
34
|
+
LIGHT_POOL,
|
|
35
|
+
addFlame,
|
|
36
|
+
addLampStand,
|
|
37
|
+
addLightPool,
|
|
38
|
+
addStillPool,
|
|
39
|
+
addWallLantern,
|
|
40
|
+
createLightPoolTexture,
|
|
41
|
+
} from './ruins-fittings.js';
|
|
42
|
+
export { GROUND_DRAPE_FRAGMENT, createGroundDrape, createGroundDrapeMaterial } from './ground-drape.js';
|
|
43
|
+
export { meshStreamBanks } from './stream-banks.js';
|
|
44
|
+
export { meshSprings } from './stream-springs.js';
|
|
45
|
+
export { layRoads } from './road-ribbons.js';
|
|
46
|
+
export { createAvenueHandover, farRoadPavingMaterial, layPavedRoad, layRoadAvenue } from './paved-road.js';
|
|
47
|
+
export { PAVED_GROUND_LIMITS, createPavedGroundMaterial } from './paved-ground.js';
|
|
48
|
+
export { TUFT_SHADER, createGrassTuft, createTuftMaterial } from './plant-tuft.js';
|
|
49
|
+
export { createTrailMarks, trailMarksGLSL } from './land-trail-surface.js';
|
|
50
|
+
export { createIrrigatedFieldSurface, IRRIGATED_FIELD_KIND, IRRIGATED_FIELD_SURFACE } from './irrigated-field-surface.js';
|
|
51
|
+
export { scatterInstances, scatterTreeGrove, scatterTrees, scatterTussocks } from './scatter-instances.js';
|
|
52
|
+
export { meshFarmCells, scatterFarmLots } from './farm-cells.js';
|
|
53
|
+
export { DEFAULT_LIVESTOCK_CASTS, createLivestockCache } from './farm-livestock.js';
|
|
54
|
+
export {
|
|
55
|
+
DEFAULT_OX_COATS,
|
|
56
|
+
DEFAULT_PLOUGHMAN_LOOK,
|
|
57
|
+
PLOUGHMAN_SEEN_DISTANCE,
|
|
58
|
+
PLOUGHMAN_STANCE,
|
|
59
|
+
buildPloughman,
|
|
60
|
+
createPloughTeam,
|
|
61
|
+
posePloughman,
|
|
62
|
+
} from './farm-plough.js';
|
|
63
|
+
|
|
64
|
+
// ── Settlements, houses, fortifications & interiors ──────────────────────
|
|
65
|
+
export { createHouseKitMaterials, createHouseKitMeshes } from './house-kit-meshes.js';
|
|
66
|
+
export { createQuarterStream } from './settlement-quarter.js';
|
|
67
|
+
export { createTowns } from './settlement-town.js';
|
|
68
|
+
export { createSettlementApproach } from './settlement-approach.js';
|
|
69
|
+
export { createSettlementSwitch } from './settlement-switch.js';
|
|
70
|
+
export { createGardenPlants } from './plant-garden.js';
|
|
71
|
+
export { CITY_GLOW_FALLOFF, createCityGlow, createStreetLampNight, createStreetLamps } from './street-lamps.js';
|
|
72
|
+
export { createLampLightMap } from './lamp-light-map.js';
|
|
73
|
+
export { createCityLamplight, createNearestLampMaps, lampMapTexture } from './lamp-maps.js';
|
|
74
|
+
export { createRoomMaterials } from './room-materials.js';
|
|
75
|
+
export { finishRoom } from './room-space.js';
|
|
76
|
+
|
|
77
|
+
// ── Vessels ──────────────────────────────────────────────────────────────
|
|
78
|
+
export { createShipMeshes } from './ship-meshes.js';
|
|
79
|
+
|
|
80
|
+
// ── Figures, animals & fliers ────────────────────────────────────────────
|
|
81
|
+
export { createFigureAssembler } from './figure-skeleton.js';
|
|
82
|
+
export { createShields } from './figure-shield.js';
|
|
83
|
+
export { createCastStage, createStandIn, uploadCastMeshes, warmFigureShaders } from './cast-stage.js';
|
|
84
|
+
export { createNameplateGroups } from './nameplate-groups.js';
|
|
85
|
+
export { createNameplates, renderNameplateCanvas, wrapSubtitle } from './nameplates.js';
|
|
86
|
+
export { rigHorse } from './animal-horse-figure.js';
|
|
87
|
+
export { buildCattle } from './animal-cattle-figure.js';
|
|
88
|
+
export { buildCamel } from './animal-camel-figure.js';
|
|
89
|
+
export { buildCanine } from './animal-canine-figure.js';
|
|
90
|
+
export { createFlierShapes, createSwarm, FLY_WINGS } from './flier-swarm.js';
|
|
91
|
+
export { CARPET_LEVELS, canineStrideSteps, createCanineStrideCast, createCarpetSwarm } from './flier-carpet.js';
|
|
92
|
+
export { createCrawlerPack, createGiantSpiderPack } from './crawler-pack.js';
|
|
93
|
+
export { updateNearGroups } from './detail-range.js';
|
|
94
|
+
export { createPenFlocks, packPenAnimals } from './pen-flocks.js';
|
|
95
|
+
export { createLongFlierCompany } from './flier-long-body-company.js';
|
|
96
|
+
export { createCorvidFigure } from './flier-corvid-figure.js';
|
|
97
|
+
|
|
98
|
+
// ── Crowds ───────────────────────────────────────────────────────────────
|
|
99
|
+
export { createCrowdVisibility } from './crowd-visibility.js';
|
|
100
|
+
export { createHerdRenderer, createHerdSkins } from './crowd-herd.js';
|
|
101
|
+
export {
|
|
102
|
+
DEFAULT_BEARERS,
|
|
103
|
+
DEFAULT_BY_ROLE,
|
|
104
|
+
DEFAULT_CROWD_HAIR,
|
|
105
|
+
DEFAULT_CROWD_LOOKS,
|
|
106
|
+
DEFAULT_CROWD_SKINS,
|
|
107
|
+
DEFAULT_SOLDIER_BEARER,
|
|
108
|
+
DEFAULT_UNIFORMS,
|
|
109
|
+
bakeCrowdWalks,
|
|
110
|
+
createCrowdBatches,
|
|
111
|
+
createLookPicker,
|
|
112
|
+
} from './crowd-batches.js';
|
|
113
|
+
export { createCrowdUpdater, registerCrowd } from './crowd-update.js';
|
|
114
|
+
export { createCrowdLifecycle } from './crowd-lifecycle.js';
|
|
115
|
+
export { ContactShadows, createFootShadows } from './contact-shadows.js';
|
|
116
|
+
export { createCrowdSystem } from './crowd-system.js';
|
|
117
|
+
export { TROOP_HORSE_COATS, TROOP_HORSE_PACES, TROOP_MOUNT_KINDS, createTroopMounts } from './troop-mounts.js';
|
|
118
|
+
export {
|
|
119
|
+
STANDARD_BELOW,
|
|
120
|
+
STANDARD_CARRIED,
|
|
121
|
+
STANDARD_CLEAR,
|
|
122
|
+
STANDARD_GRIP_UP,
|
|
123
|
+
STANDARD_LAID_FLAT,
|
|
124
|
+
createTroopStandards,
|
|
125
|
+
poleDroppedMatrix,
|
|
126
|
+
poleInFistMatrix,
|
|
127
|
+
} from './troop-standards.js';
|
|
128
|
+
export { createTroopVolleys } from './troop-volleys.js';
|
|
129
|
+
export { createTroopDirector } from './troop-director.js';
|
|
130
|
+
|
|
131
|
+
// ── Effects, audio, pacing & runtime ─────────────────────────────────────
|
|
132
|
+
export { DEFAULT_PARTICLE_LOOK, createParticleNoiseTexture, createParticleSystem } from './particles.js';
|
|
133
|
+
export { FLAME_KINDS, addFireSites, createFireSite, createFlameSources, createSmokeSite } from './flame-sources.js';
|
|
134
|
+
export { createFireLightWatch } from './fire-light-watch.js';
|
|
135
|
+
export { createEffectsFrame, syncEffectsUniforms } from './effects-frame.js';
|
|
136
|
+
export { createRippleRingMaterial, createWaterRises, fishGeometry } from './effects-water-rises.js';
|
|
137
|
+
export { STORM_WALL_COLORS, createStormWall, stormWallGeometry, stormWallNoise } from './storm-wall.js';
|
|
138
|
+
export {
|
|
139
|
+
DUST_CURTAIN_DEFAULTS,
|
|
140
|
+
FALLING_WATER_DEFAULTS,
|
|
141
|
+
VALUE_NOISE_3D_GLSL,
|
|
142
|
+
createDustCurtain,
|
|
143
|
+
createDustCurtainMaterial,
|
|
144
|
+
createFallingWaterMaterial,
|
|
145
|
+
createFallingWaterSheets,
|
|
146
|
+
dustCurtainGeometry,
|
|
147
|
+
} from './curtain-sheets.js';
|
|
148
|
+
export { FALLEN_BEAST_DEFAULTS, placeFallenBeasts } from './camp-layout.js';
|
|
149
|
+
export { createPracticalFlame, createSceneLights } from './scene-lights.js';
|
|
150
|
+
export { createPerfBox } from './perf-box.js';
|
|
151
|
+
export { PERF_BOX_DEFAULTS, attachPerfBoxWorker, createPerfBoxRenderer } from './perf-box-worker.js';
|
|
152
|
+
export { flyProbeRoute, runSelfProbe } from './perf-probe.js';
|
|
153
|
+
|
|
154
|
+
// ── Scene playback, melee, projectiles, beams, props & markers ───────────
|
|
155
|
+
export { createBladeTrailPool } from './blade-trails.js';
|
|
156
|
+
export { createProjectilePool } from './scene-projectiles.js';
|
|
157
|
+
export { DEFAULT_BEAM_COLORS, DEFAULT_BEAM_STYLE, DEFAULT_BEAM_STYLES, createEnergyBeams } from './scene-beams.js';
|
|
158
|
+
export { DEFAULT_POSE_SHOTS, actorHeadTop, createSceneCoverage } from './scene-coverage.js';
|
|
159
|
+
export { createSceneShots, gallopTremorLevel, protectMasterHeadroom, trackOrigin } from './scene-shots.js';
|
|
160
|
+
export { createSceneProps } from './scene-props.js';
|
|
161
|
+
export { createSceneFlash } from './scene-flash.js';
|
|
162
|
+
export { createSceneMarkers, createShaftLabel, DEFAULT_MARKER_COLORS, projectWaypoint } from './scene-markers.js';
|
|
163
|
+
|
|
164
|
+
// ── Map kit ──────────────────────────────────────────────────────────────
|
|
165
|
+
export {
|
|
166
|
+
DEFAULT_MAP_FONT,
|
|
167
|
+
MAP_COLORS,
|
|
168
|
+
MAP_GLYPHS,
|
|
169
|
+
drawDune,
|
|
170
|
+
drawMapArch,
|
|
171
|
+
drawMapCompass,
|
|
172
|
+
drawMapDisc,
|
|
173
|
+
drawMapGlyph,
|
|
174
|
+
drawMapLabel,
|
|
175
|
+
drawMapNote,
|
|
176
|
+
drawMapPoly,
|
|
177
|
+
drawMapScaleBar,
|
|
178
|
+
drawPeak,
|
|
179
|
+
drawTree,
|
|
180
|
+
} from './map-glyphs.js';
|
|
181
|
+
export { createMapLabelSet, spacedCaps, turnAlongLine } from './map-labels.js';
|
|
182
|
+
export { paintMapPick, paintMapVisitor } from './map-signs.js';
|
|
183
|
+
export { createAtlasRelief, paintTerrainSheet } from './map-relief.js';
|
|
184
|
+
export { bindMapInput, fitMapCanvas } from './map-input.js';
|
|
185
|
+
|
|
186
|
+
// ── Controls, HUD & wayfinding ───────────────────────────────────────────
|
|
187
|
+
export {
|
|
188
|
+
DEFAULT_BACKDROP_RANGES,
|
|
189
|
+
DEFAULT_BACKDROP_SKY,
|
|
190
|
+
DEFAULT_BACKDROP_VEIL,
|
|
191
|
+
applyBackdropFinish,
|
|
192
|
+
createCanvasSprite,
|
|
193
|
+
createTitleBackdrop,
|
|
194
|
+
paintCumulusSprite,
|
|
195
|
+
paintMountainRange,
|
|
196
|
+
paintSkyGradient,
|
|
197
|
+
ridgeNoise,
|
|
198
|
+
} from './title-backdrop.js';
|
|
199
|
+
export { DEFAULT_PLACE_TAG_STYLES, DEFAULT_SMALL_TAG_STYLES, createPlaceNames } from './place-names.js';
|
|
200
|
+
export { DEFAULT_PORTRAIT_GROUND, convertPortraitPixels, createPortraitStudio } from './portrait-studio.js';
|
|
201
|
+
export { pickScreenActor, pickScreenTag } from './screen-pick.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specialized rock and mineral materials for subterranean and geological sets.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a glossy, flat-shaded, softly self-lit `MeshStandardMaterial` for faceted cavern crystals.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} [options]
|
|
12
|
+
* @param {number} [options.roughness=0.12] - Surface roughness.
|
|
13
|
+
* @param {number} [options.metalness=0] - Metallic factor.
|
|
14
|
+
* @param {number} [options.emissive=0x2a2838] - Faint inner mineral glow sRGB hex colour.
|
|
15
|
+
* @param {boolean} [options.flatShading=true] - Keep crystal facets crisp.
|
|
16
|
+
* @param {boolean} [options.vertexColors=true] - Read per-prism tints from vertex colours.
|
|
17
|
+
* @returns {THREE.MeshStandardMaterial}
|
|
18
|
+
*/
|
|
19
|
+
export function createCrystalMaterial({
|
|
20
|
+
roughness = 0.12,
|
|
21
|
+
metalness = 0,
|
|
22
|
+
emissive = 0x2a2838,
|
|
23
|
+
flatShading = true,
|
|
24
|
+
vertexColors = true,
|
|
25
|
+
} = {}) {
|
|
26
|
+
return new THREE.MeshStandardMaterial({ vertexColors, roughness, metalness, emissive, flatShading });
|
|
27
|
+
}
|
|
@@ -86,22 +86,32 @@ export function addLightPool(group, x, y, z, radius, options = {}) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* Add a
|
|
89
|
+
* Add a glossy oval or circular pool of still water (or liquid decal) lying flat in a basin, spring
|
|
90
|
+
* or hollow. Pass `material` to share an existing water/liquid material, or omit it to create a
|
|
91
|
+
* `MeshStandardMaterial` from `color`, `roughness`, `metalness`, `transparent` and `opacity`.
|
|
92
|
+
* Pass `radius` (with optional `scaleX`/`scaleZ`) to size the `CircleGeometry` directly, or omit it
|
|
93
|
+
* to scale a unit-diameter disc by `(width, depth)`.
|
|
90
94
|
*
|
|
91
|
-
* @param {THREE.Object3D} group - Destination scene or group.
|
|
92
|
-
* @param {object} options
|
|
95
|
+
* @param {THREE.Object3D | null} group - Destination scene or group.
|
|
96
|
+
* @param {object} [options]
|
|
93
97
|
* @param {{ x: number, z: number }} [options.origin={ x: 0, z: 0 }] - Local frame world origin.
|
|
94
98
|
* @param {number} [options.x=0] - Local X position in metres.
|
|
95
|
-
* @param {number} [options.y=0] -
|
|
99
|
+
* @param {number} [options.y=0] - Surface elevation in metres.
|
|
96
100
|
* @param {number} [options.z=0] - Local Z position in metres.
|
|
97
|
-
* @param {number} [options.width=2] - Pool width in metres.
|
|
98
|
-
* @param {number} [options.depth=2] - Pool depth in metres.
|
|
101
|
+
* @param {number} [options.width=2] - Pool width in metres (when `radius` is omitted).
|
|
102
|
+
* @param {number} [options.depth=2] - Pool depth in metres (when `radius` is omitted).
|
|
103
|
+
* @param {number | null} [options.radius=null] - Explicit `CircleGeometry` radius in metres.
|
|
104
|
+
* @param {number} [options.scaleX=1] - X scale multiplier when `radius` is set.
|
|
105
|
+
* @param {number} [options.scaleZ=1] - Z scale multiplier when `radius` is set.
|
|
99
106
|
* @param {number} [options.yaw=0] - Rotation around Y in radians.
|
|
100
|
-
* @param {number} [options.color=0x1c2a2a] -
|
|
101
|
-
* @param {number} [options.roughness=0.05] - Surface roughness.
|
|
102
|
-
* @param {number} [options.metalness=0.4] - Surface reflectivity factor.
|
|
103
|
-
* @param {
|
|
107
|
+
* @param {number} [options.color=0x1c2a2a] - Base sRGB colour when `material` is omitted.
|
|
108
|
+
* @param {number} [options.roughness=0.05] - Surface roughness when `material` is omitted.
|
|
109
|
+
* @param {number} [options.metalness=0.4] - Surface reflectivity factor when `material` is omitted.
|
|
110
|
+
* @param {boolean} [options.transparent=true] - Whether the default material is transparent.
|
|
111
|
+
* @param {number} [options.opacity=0.88] - Opacity when `material` is omitted and `transparent` is true.
|
|
112
|
+
* @param {THREE.Material | null} [options.material=null] - Optional shared material to reuse.
|
|
104
113
|
* @param {number} [options.segments=20] - Perimeter circle segments.
|
|
114
|
+
* @param {number | null} [options.renderOrder=null] - Optional Three.js `renderOrder`.
|
|
105
115
|
* @returns {THREE.Mesh}
|
|
106
116
|
*/
|
|
107
117
|
export function addStillPool(group, options = {}) {
|
|
@@ -112,24 +122,107 @@ export function addStillPool(group, options = {}) {
|
|
|
112
122
|
z = 0,
|
|
113
123
|
width = 2,
|
|
114
124
|
depth = 2,
|
|
125
|
+
radius = null,
|
|
126
|
+
scaleX = 1,
|
|
127
|
+
scaleZ = 1,
|
|
115
128
|
yaw = 0,
|
|
116
129
|
color = 0x1c2a2a,
|
|
117
130
|
roughness = 0.05,
|
|
118
131
|
metalness = 0.4,
|
|
132
|
+
transparent = true,
|
|
119
133
|
opacity = 0.88,
|
|
134
|
+
material = null,
|
|
120
135
|
segments = 20,
|
|
136
|
+
renderOrder = null,
|
|
121
137
|
} = options;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
new THREE.MeshStandardMaterial(
|
|
125
|
-
|
|
138
|
+
const mat =
|
|
139
|
+
material ??
|
|
140
|
+
new THREE.MeshStandardMaterial(
|
|
141
|
+
transparent ? { color, roughness, metalness, transparent: true, opacity } : { color, roughness, metalness },
|
|
142
|
+
);
|
|
143
|
+
const geo = new THREE.CircleGeometry(radius ?? 0.5, segments).rotateX(-Math.PI / 2);
|
|
144
|
+
const water = new THREE.Mesh(geo, mat);
|
|
126
145
|
water.position.set(origin.x + x, y, origin.z + z);
|
|
127
|
-
water.scale.set(width, 1, depth);
|
|
128
|
-
water.
|
|
129
|
-
|
|
146
|
+
if (radius === null) water.scale.set(width, 1, depth);
|
|
147
|
+
else if (scaleX !== 1 || scaleZ !== 1) water.scale.set(scaleX, 1, scaleZ);
|
|
148
|
+
if (yaw) water.rotation.y = yaw;
|
|
149
|
+
if (renderOrder !== null) water.renderOrder = renderOrder;
|
|
150
|
+
if (group) group.add(water);
|
|
130
151
|
return water;
|
|
131
152
|
}
|
|
132
153
|
|
|
154
|
+
/** Default emissive core and lamp-threshold settings for {@link addFlame}. */
|
|
155
|
+
export const FLAME_DEFAULTS = Object.freeze({
|
|
156
|
+
color: 0xffb24a,
|
|
157
|
+
boost: 1.5,
|
|
158
|
+
lampSize: 0.2,
|
|
159
|
+
lampLight: Object.freeze({ lift: 0.25, light: 0.14 }),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Place a glowing flame core at `(x, y, z)` in local coordinates offset by `origin` and invoke an
|
|
164
|
+
* optional `onSite` callback with the fire-site parameters (attaching `lampLight` overrides when
|
|
165
|
+
* `size < lampSize` so small lamp wicks keep low, tight lighting).
|
|
166
|
+
*
|
|
167
|
+
* @param {THREE.Object3D | null} group - Destination group receiving the glowing flame core.
|
|
168
|
+
* @param {object} options
|
|
169
|
+
* @param {{ x: number, z: number }} [options.origin={ x: 0, z: 0 }] - Local frame world origin.
|
|
170
|
+
* @param {number} [options.x=0] - Local X in metres.
|
|
171
|
+
* @param {number} [options.y=0] - World Y in metres.
|
|
172
|
+
* @param {number} [options.z=0] - Local Z in metres.
|
|
173
|
+
* @param {number} [options.size=0.3] - Flame size in metres.
|
|
174
|
+
* @param {number} [options.color=FLAME_DEFAULTS.color] - Emissive core sRGB hex colour.
|
|
175
|
+
* @param {number} [options.boost=FLAME_DEFAULTS.boost] - Emissive intensity multiplier.
|
|
176
|
+
* @param {number} [options.lampSize=FLAME_DEFAULTS.lampSize] - Threshold below which `lampLight` is applied.
|
|
177
|
+
* @param {{ lift: number, light: number }} [options.lampLight=FLAME_DEFAULTS.lampLight] - Light override for small wicks.
|
|
178
|
+
* @param {object} [options.shapes] - Unit shapes containing `sph`.
|
|
179
|
+
* @param {((geo: THREE.BufferGeometry, hex: number, boost: number, group: THREE.Object3D | null) => THREE.Mesh) | null} [options.makeGlowMesh=null] - Custom emissive mesh factory.
|
|
180
|
+
* @param {((site: object) => void) | null} [options.onSite=null] - Optional callback receiving the fire effect-site record.
|
|
181
|
+
* @param {string} [options.space='world'] - Host space id stored on the emitted site record.
|
|
182
|
+
* @returns {{ core: THREE.Mesh, site: object }}
|
|
183
|
+
*/
|
|
184
|
+
export function addFlame(group, options = {}) {
|
|
185
|
+
const {
|
|
186
|
+
origin = { x: 0, z: 0 },
|
|
187
|
+
x = 0,
|
|
188
|
+
y = 0,
|
|
189
|
+
z = 0,
|
|
190
|
+
size = 0.3,
|
|
191
|
+
color = FLAME_DEFAULTS.color,
|
|
192
|
+
boost = FLAME_DEFAULTS.boost,
|
|
193
|
+
lampSize = FLAME_DEFAULTS.lampSize,
|
|
194
|
+
lampLight = FLAME_DEFAULTS.lampLight,
|
|
195
|
+
shapes = defaultShapes(),
|
|
196
|
+
makeGlowMesh = null,
|
|
197
|
+
onSite = null,
|
|
198
|
+
space = 'world',
|
|
199
|
+
} = options;
|
|
200
|
+
const core = makeGlowMesh
|
|
201
|
+
? makeGlowMesh(shapes.sph, color, boost, group)
|
|
202
|
+
: (() => {
|
|
203
|
+
const m = new THREE.Mesh(shapes.sph, new THREE.MeshBasicMaterial({ color: new THREE.Color(color).multiplyScalar(boost) }));
|
|
204
|
+
if (group) group.add(m);
|
|
205
|
+
return m;
|
|
206
|
+
})();
|
|
207
|
+
core.position.set(origin.x + x, y, origin.z + z);
|
|
208
|
+
core.scale.set(size * 0.5, size * 1.1, size * 0.5);
|
|
209
|
+
const lamp = size < lampSize;
|
|
210
|
+
const site = {
|
|
211
|
+
space,
|
|
212
|
+
type: 'fire',
|
|
213
|
+
x: origin.x + x,
|
|
214
|
+
y,
|
|
215
|
+
z: origin.z + z,
|
|
216
|
+
rate: 3 + size * 8,
|
|
217
|
+
size: size * 0.9,
|
|
218
|
+
hot: 1,
|
|
219
|
+
soot: 0.1,
|
|
220
|
+
...(lamp && lampLight),
|
|
221
|
+
};
|
|
222
|
+
onSite?.(site);
|
|
223
|
+
return { core, site };
|
|
224
|
+
}
|
|
225
|
+
|
|
133
226
|
/**
|
|
134
227
|
* Build a tall brass oil-lamp stand and invoke an optional flame callback at its wick.
|
|
135
228
|
*
|