@wildshard/kit 0.0.0 → 0.4.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/GUIDE.md +221 -0
- package/content/abilities/bite.json +24 -0
- package/content/abilities/charge.json +25 -0
- package/content/abilities/claw.json +24 -0
- package/content/abilities/slam.json +24 -0
- package/content/abilities/swing.json +25 -0
- package/content/animated/bear/pbr/black-blaze.glb +0 -0
- package/content/animated/bear/pbr/black-blaze.json +1 -0
- package/content/animated/bear/pbr/black-old.glb +0 -0
- package/content/animated/bear/pbr/black-old.json +1 -0
- package/content/animated/bear/pbr/black.glb +0 -0
- package/content/animated/bear/pbr/black.json +1 -0
- package/content/animated/bear/pbr/brown-old.glb +0 -0
- package/content/animated/bear/pbr/brown-old.json +1 -0
- package/content/animated/bear/pbr/brown.glb +0 -0
- package/content/animated/bear/pbr/brown.json +1 -0
- package/content/animated/bear/toon/black-blaze.glb +0 -0
- package/content/animated/bear/toon/black-blaze.json +1 -0
- package/content/animated/bear/toon/black-old.glb +0 -0
- package/content/animated/bear/toon/black-old.json +1 -0
- package/content/animated/bear/toon/black.glb +0 -0
- package/content/animated/bear/toon/black.json +1 -0
- package/content/animated/bear/toon/brown-old.glb +0 -0
- package/content/animated/bear/toon/brown-old.json +1 -0
- package/content/animated/bear/toon/brown.glb +0 -0
- package/content/animated/bear/toon/brown.json +1 -0
- package/content/animated/boar/pbr/big.glb +0 -0
- package/content/animated/boar/pbr/big.json +1 -0
- package/content/animated/boar/pbr/black.glb +0 -0
- package/content/animated/boar/pbr/black.json +1 -0
- package/content/animated/boar/pbr/boar.glb +0 -0
- package/content/animated/boar/pbr/boar.json +1 -0
- package/content/animated/boar/pbr/ironhide.glb +0 -0
- package/content/animated/boar/pbr/ironhide.json +1 -0
- package/content/animated/boar/pbr/scarback.glb +0 -0
- package/content/animated/boar/pbr/scarback.json +1 -0
- package/content/animated/boar/pbr/sow.glb +0 -0
- package/content/animated/boar/pbr/sow.json +1 -0
- package/content/animated/boar/toon/big.glb +0 -0
- package/content/animated/boar/toon/big.json +1 -0
- package/content/animated/boar/toon/black.glb +0 -0
- package/content/animated/boar/toon/black.json +1 -0
- package/content/animated/boar/toon/boar.glb +0 -0
- package/content/animated/boar/toon/boar.json +1 -0
- package/content/animated/boar/toon/ironhide.glb +0 -0
- package/content/animated/boar/toon/ironhide.json +1 -0
- package/content/animated/boar/toon/scarback.glb +0 -0
- package/content/animated/boar/toon/scarback.json +1 -0
- package/content/animated/boar/toon/sow.glb +0 -0
- package/content/animated/boar/toon/sow.json +1 -0
- package/content/animated/catalogue.json +1 -0
- package/content/bodies/biped.json +5 -0
- package/content/bodies/quadruped.json +5 -0
- package/content/clips/quadruped.json +1 -0
- package/content/creatures/bear/look.json +199 -0
- package/content/creatures/bear/pbr/black-blaze.glb +0 -0
- package/content/creatures/bear/pbr/black-old.glb +0 -0
- package/content/creatures/bear/pbr/black.glb +0 -0
- package/content/creatures/bear/pbr/brown-old.glb +0 -0
- package/content/creatures/bear/pbr/brown.glb +0 -0
- package/content/creatures/bear/toon/black-blaze.glb +0 -0
- package/content/creatures/bear/toon/black-old.glb +0 -0
- package/content/creatures/bear/toon/black.glb +0 -0
- package/content/creatures/bear/toon/brown-old.glb +0 -0
- package/content/creatures/bear/toon/brown.glb +0 -0
- package/content/creatures/bear.json +257 -0
- package/content/creatures/boar/look.json +184 -0
- package/content/creatures/boar/pbr/big.glb +0 -0
- package/content/creatures/boar/pbr/black.glb +0 -0
- package/content/creatures/boar/pbr/boar.glb +0 -0
- package/content/creatures/boar/pbr/ironhide.glb +0 -0
- package/content/creatures/boar/pbr/scarback.glb +0 -0
- package/content/creatures/boar/pbr/sow.glb +0 -0
- package/content/creatures/boar/toon/big.glb +0 -0
- package/content/creatures/boar/toon/black.glb +0 -0
- package/content/creatures/boar/toon/boar.glb +0 -0
- package/content/creatures/boar/toon/ironhide.glb +0 -0
- package/content/creatures/boar/toon/scarback.glb +0 -0
- package/content/creatures/boar/toon/sow.glb +0 -0
- package/content/creatures/boar.json +275 -0
- package/content/creatures/bodies.json +4754 -0
- package/content/harvest-items.json +98 -0
- package/content/harvest.json +31 -0
- package/content/journal-icons/antlers.png +0 -0
- package/content/journal-icons/bear.png +0 -0
- package/content/journal-icons/boar.png +0 -0
- package/content/journal-icons/deer.png +0 -0
- package/content/journal-icons/elk.png +0 -0
- package/content/journal-icons/ghost.png +0 -0
- package/content/journal-icons/ironhide.png +0 -0
- package/content/journal-icons.json +9 -0
- package/content/shared/pickupCatalogue.json +1008 -0
- package/content/shared/starterBow.json +21 -0
- package/content/species/bear.json +144 -0
- package/content/species/boar.json +147 -0
- package/content/sword-debris.json +7 -0
- package/content/temperaments.json +519 -0
- package/content/tuning/bear.json +43 -0
- package/content/tuning/boar.json +32 -0
- package/content/tuning/deer.json +32 -0
- package/content/tuning/pursue.json +12 -0
- package/package.json +57 -4
- package/src/abilities.ts +85 -0
- package/src/body.ts +25 -0
- package/src/clips.ts +139 -0
- package/src/creatures.ts +76 -0
- package/src/geometry/arms.ts +725 -0
- package/src/geometry/bear.ts +521 -0
- package/src/geometry/boar.ts +604 -0
- package/src/geometry/bowProfile.ts +34 -0
- package/src/geometry/export.ts +101 -0
- package/src/geometry/meleeProfile.ts +261 -0
- package/src/geometry/nativeInteractionFacts.ts +7 -0
- package/src/geometry/nativeLooks.ts +54 -0
- package/src/geometry/riderArms.ts +215 -0
- package/src/geometry/sharedSpecs.ts +26 -0
- package/src/geometry/species.ts +768 -0
- package/src/geometry/specimenCatalogue.ts +80 -0
- package/src/geometry/starterCombat.ts +194 -0
- package/src/geometry/starterGlyphs.ts +12 -0
- package/src/geometry/starterMeleeProfile.ts +134 -0
- package/src/geometry/starterMoves.ts +172 -0
- package/src/index.ts +26 -0
- package/src/legacyCombat.ts +25 -0
- package/src/legacyHarvest.ts +104 -0
- package/src/legacyJournalIcons.ts +10 -0
- package/src/legacySpecies.ts +127 -0
- package/src/temperament.ts +97 -0
- package/README.md +0 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { skinnedGlb } from '@wildshard/sdk/bake/skinned'
|
|
2
|
+
import { Rng } from '@wildshard/sdk/random'
|
|
3
|
+
import { MeshStandardMaterial } from 'three'
|
|
4
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js'
|
|
5
|
+
|
|
6
|
+
import { quadrupedClips } from '../clips.ts'
|
|
7
|
+
import {
|
|
8
|
+
bakeCommonBody,
|
|
9
|
+
commonBodyVariants,
|
|
10
|
+
type CommonBodyKind,
|
|
11
|
+
withBodyGeometry,
|
|
12
|
+
type AnimalDims,
|
|
13
|
+
type BoneDef,
|
|
14
|
+
} from './species.ts'
|
|
15
|
+
|
|
16
|
+
import type { SkinClipName } from '@wildshard/shard-format/skinData'
|
|
17
|
+
|
|
18
|
+
/** Plain metadata beside a body GLB. Animation/admission bindings are separate content. */
|
|
19
|
+
export interface BodyExport {
|
|
20
|
+
readonly glb: Uint8Array
|
|
21
|
+
readonly kind: CommonBodyKind
|
|
22
|
+
readonly variant: string
|
|
23
|
+
readonly family: 'pbr' | 'toon'
|
|
24
|
+
readonly bones: BoneDef[]
|
|
25
|
+
readonly dims: AnimalDims
|
|
26
|
+
readonly clips?: readonly SkinClipName[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Build a deterministic body asset from the kit recipe with no engine dependency. */
|
|
30
|
+
function exportBody(
|
|
31
|
+
kind: CommonBodyKind,
|
|
32
|
+
variantId: string,
|
|
33
|
+
family: 'pbr' | 'toon',
|
|
34
|
+
animated: boolean,
|
|
35
|
+
): BodyExport {
|
|
36
|
+
const variant = commonBodyVariants(kind).find(row => row.id === variantId)
|
|
37
|
+
if (variant === undefined)
|
|
38
|
+
throw new Error(`Unknown kit ${kind} variant: ${variantId}`)
|
|
39
|
+
const { body } = withBodyGeometry(family === 'toon', {}, () =>
|
|
40
|
+
bakeCommonBody(kind, variant, new Rng(42).snapshot()),
|
|
41
|
+
)
|
|
42
|
+
const material = new MeshStandardMaterial({
|
|
43
|
+
vertexColors: true,
|
|
44
|
+
roughness: 0.9,
|
|
45
|
+
metalness: 0,
|
|
46
|
+
})
|
|
47
|
+
const geometries = [...body.furParts, ...body.hardParts, ...body.eyeParts]
|
|
48
|
+
const merged = animated
|
|
49
|
+
? [mergeGeometries(geometries)]
|
|
50
|
+
: [body.furParts, body.hardParts, body.eyeParts].map(parts =>
|
|
51
|
+
mergeGeometries(parts),
|
|
52
|
+
)
|
|
53
|
+
try {
|
|
54
|
+
const clips = animated ? quadrupedClips(body.bones) : undefined
|
|
55
|
+
const { glb } = skinnedGlb({
|
|
56
|
+
name: `kit.${kind}.${variantId}.${family}`,
|
|
57
|
+
bones: body.bones,
|
|
58
|
+
...(clips === undefined ? {} : { clips }),
|
|
59
|
+
parts: merged.map((geometry, index) => {
|
|
60
|
+
if (geometry === null) throw new Error('Kit body geometry cannot merge')
|
|
61
|
+
return {
|
|
62
|
+
geometry,
|
|
63
|
+
material,
|
|
64
|
+
name: ['fur', 'hard', 'eye'][index] ?? 'part',
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
})
|
|
68
|
+
return {
|
|
69
|
+
glb,
|
|
70
|
+
kind,
|
|
71
|
+
variant: variantId,
|
|
72
|
+
family,
|
|
73
|
+
bones: body.bones,
|
|
74
|
+
dims: body.dims,
|
|
75
|
+
...(clips === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: { clips: clips.map(clip => clip.name as SkinClipName) }),
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
for (const geometry of [...geometries, ...merged]) geometry?.dispose()
|
|
81
|
+
material.dispose()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Original plain body export, preserving every committed OF3a byte. */
|
|
86
|
+
export function exportCommonBody(
|
|
87
|
+
kind: CommonBodyKind,
|
|
88
|
+
variantId: string,
|
|
89
|
+
family: 'pbr' | 'toon',
|
|
90
|
+
): BodyExport {
|
|
91
|
+
return exportBody(kind, variantId, family, false)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The same exact body channels with the kit's admitted, named quadruped clips. */
|
|
95
|
+
export function exportAnimatedCommonBody(
|
|
96
|
+
kind: CommonBodyKind,
|
|
97
|
+
variantId: string,
|
|
98
|
+
family: 'pbr' | 'toon',
|
|
99
|
+
): BodyExport {
|
|
100
|
+
return exportBody(kind, variantId, family, true)
|
|
101
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MeleeWeaponProfileSchema,
|
|
3
|
+
type MeleeWeaponProfileRows,
|
|
4
|
+
} from '@wildshard/shard-format/weaponProfiles'
|
|
5
|
+
import * as THREE from 'three'
|
|
6
|
+
import { parse } from 'valibot'
|
|
7
|
+
|
|
8
|
+
import { SWORD_WOOD } from './starterMeleeProfile.ts'
|
|
9
|
+
|
|
10
|
+
import type { StrikeDebrisPolicy } from '@wildshard/shard-format/strikeDebris'
|
|
11
|
+
|
|
12
|
+
/** Numeric camera lag, bob and sway parameters, independent of a particular weapon model. */
|
|
13
|
+
export interface ViewmodelFeel {
|
|
14
|
+
lag: {
|
|
15
|
+
gain: number
|
|
16
|
+
clampYaw: number
|
|
17
|
+
clampPitch: number
|
|
18
|
+
k: number
|
|
19
|
+
c: number
|
|
20
|
+
posYaw: number
|
|
21
|
+
posPitch: number
|
|
22
|
+
}
|
|
23
|
+
bob: { x: number; y: number; rz: number; rx: number }
|
|
24
|
+
sway: { ax: number; fx: number; ay: number; fy: number }
|
|
25
|
+
fovHip: number
|
|
26
|
+
portraitFov?: number
|
|
27
|
+
}
|
|
28
|
+
/** How the held melee model sits in the view: shrink, offset, tilt and yaw. */
|
|
29
|
+
export interface MeleeFraming {
|
|
30
|
+
shrink: number
|
|
31
|
+
dx: number
|
|
32
|
+
dy: number
|
|
33
|
+
tilt: number
|
|
34
|
+
yaw: number
|
|
35
|
+
}
|
|
36
|
+
/** Author UI names; a host may specialize the vocabulary at its adapter. */
|
|
37
|
+
export interface EquipmentUi<
|
|
38
|
+
Icon extends string = string,
|
|
39
|
+
Touch extends string = string,
|
|
40
|
+
> {
|
|
41
|
+
name: string
|
|
42
|
+
icon: Icon
|
|
43
|
+
/** Magazine readouts offer touch reload; quivers keep their passive ammo chip. */
|
|
44
|
+
ammo?: {
|
|
45
|
+
label: string
|
|
46
|
+
segments: number
|
|
47
|
+
magazine?: boolean
|
|
48
|
+
bagLabel?: string
|
|
49
|
+
bagLabelFor?: string
|
|
50
|
+
}
|
|
51
|
+
inputContext?: string
|
|
52
|
+
touch: Touch
|
|
53
|
+
lockOn: boolean
|
|
54
|
+
melee: boolean
|
|
55
|
+
tracers: boolean
|
|
56
|
+
/** The existing 24px swap glyph and short label; menu icons use the shared 64px icon library. */
|
|
57
|
+
swapIcon: string
|
|
58
|
+
swapName?: string
|
|
59
|
+
huntersEye?: boolean
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Authored swept combo and view parameters; ordered contact rows are defined by the format's weaponProfiles module.
|
|
63
|
+
* These are the authored fields of the engine's `combat/meleeProfile` `MeleeProfile`; its `pickup` factory is lent by
|
|
64
|
+
* the runtime host and is not author data. `test/sdk-engine-types.test.ts` keeps the two assignable both ways.
|
|
65
|
+
*/
|
|
66
|
+
export interface MeleeProfile<
|
|
67
|
+
Icon extends string = string,
|
|
68
|
+
Slot extends string = string,
|
|
69
|
+
Touch extends string = string,
|
|
70
|
+
> {
|
|
71
|
+
id: `weapon.${string}` | `tool.${string}`
|
|
72
|
+
legacySlot?: Slot
|
|
73
|
+
ui: EquipmentUi<Icon, Touch>
|
|
74
|
+
meta: { name: string; icon: Icon; blurb: string; category: string }
|
|
75
|
+
/** Sound cues: fire, reload, impact, and the optional dry, hit, heavy and charge cues. */
|
|
76
|
+
cues?: {
|
|
77
|
+
fire: `cue.${string}`
|
|
78
|
+
reload: `cue.${string}`
|
|
79
|
+
impact: `cue.${string}`
|
|
80
|
+
dry?: `cue.${string}`
|
|
81
|
+
hit?: `cue.${string}`
|
|
82
|
+
heavy?: `cue.${string}`
|
|
83
|
+
charge?: Readonly<Record<string, `cue.${string}`>>
|
|
84
|
+
}
|
|
85
|
+
rangedFeel?: {
|
|
86
|
+
kick: {
|
|
87
|
+
body: number
|
|
88
|
+
head: number
|
|
89
|
+
kill: number
|
|
90
|
+
side: number
|
|
91
|
+
killSide: number
|
|
92
|
+
}
|
|
93
|
+
trauma: {
|
|
94
|
+
kill: number
|
|
95
|
+
head: number
|
|
96
|
+
killKinds: readonly string[]
|
|
97
|
+
headKinds: readonly string[]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
hitStop?: { body: number; head: number; kill: number }
|
|
101
|
+
tags?: readonly `${string}.${string}`[]
|
|
102
|
+
family: 'melee'
|
|
103
|
+
parent?: string
|
|
104
|
+
damage: number
|
|
105
|
+
reach: number
|
|
106
|
+
swingScale: number
|
|
107
|
+
portraitPullX: number
|
|
108
|
+
framing: MeleeFraming
|
|
109
|
+
feel: ViewmodelFeel
|
|
110
|
+
moves?: MeleeMoveSet
|
|
111
|
+
cooldown: number
|
|
112
|
+
comboGap: number
|
|
113
|
+
chainLag: number
|
|
114
|
+
heavyCharge: number
|
|
115
|
+
chargeBlend: number
|
|
116
|
+
lunge: {
|
|
117
|
+
range: number
|
|
118
|
+
heavyRange: number
|
|
119
|
+
cone: number
|
|
120
|
+
stop: number
|
|
121
|
+
speed: number
|
|
122
|
+
minTime: number
|
|
123
|
+
maxTime: number
|
|
124
|
+
}
|
|
125
|
+
sweep: {
|
|
126
|
+
rays: number
|
|
127
|
+
extensions: readonly number[]
|
|
128
|
+
step: number
|
|
129
|
+
maxSamples: number
|
|
130
|
+
maxHits: number
|
|
131
|
+
}
|
|
132
|
+
trail: { samples: number; subdivisions: number }
|
|
133
|
+
dodgeKick: { kick: number; k: number; c: number }
|
|
134
|
+
armFollow: number
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** An authored hand pose, independent of a live weapon controller. */
|
|
138
|
+
export interface MeleeKey {
|
|
139
|
+
t: number
|
|
140
|
+
pos: THREE.Vector3
|
|
141
|
+
q: THREE.Quaternion
|
|
142
|
+
}
|
|
143
|
+
/** An authored blade trail. */
|
|
144
|
+
export interface MeleeTrail {
|
|
145
|
+
from: number
|
|
146
|
+
color: THREE.Color
|
|
147
|
+
alpha: number
|
|
148
|
+
inner: number
|
|
149
|
+
life: number
|
|
150
|
+
}
|
|
151
|
+
/** A complete authored contact window and its three hand keys. */
|
|
152
|
+
export interface MeleeMove {
|
|
153
|
+
debris?: StrikeDebrisPolicy
|
|
154
|
+
name: 'slash' | 'backhand' | 'finisher' | 'heavy' | 'pass-left' | 'pass-right'
|
|
155
|
+
keys: [MeleeKey, MeleeKey, MeleeKey]
|
|
156
|
+
windup: number
|
|
157
|
+
slashEnd: number
|
|
158
|
+
total: number
|
|
159
|
+
damage: number
|
|
160
|
+
stagger: number
|
|
161
|
+
sweep: number
|
|
162
|
+
kick: { pitch: number; roll: number; fov?: number }
|
|
163
|
+
hitStop: number
|
|
164
|
+
reach?: number
|
|
165
|
+
trail: MeleeTrail
|
|
166
|
+
}
|
|
167
|
+
/** Ordered poses for the generic melee view. */
|
|
168
|
+
export interface MeleeMoveSet {
|
|
169
|
+
rest: MeleeKey
|
|
170
|
+
charge: MeleeKey
|
|
171
|
+
sprint: MeleeKey
|
|
172
|
+
combo: MeleeMove[]
|
|
173
|
+
heavy: MeleeMove
|
|
174
|
+
}
|
|
175
|
+
/** Owned geometry returned by a held melee recipe. */
|
|
176
|
+
export interface MeleeRig {
|
|
177
|
+
sword: THREE.BufferGeometry
|
|
178
|
+
arms: THREE.BufferGeometry
|
|
179
|
+
tipY: number
|
|
180
|
+
baseY: number
|
|
181
|
+
tipX?: number
|
|
182
|
+
material: THREE.Material
|
|
183
|
+
extras?: { geometry: THREE.BufferGeometry; material: THREE.Material }[]
|
|
184
|
+
left?: {
|
|
185
|
+
geometry: THREE.BufferGeometry
|
|
186
|
+
material: THREE.Material
|
|
187
|
+
pos: THREE.Vector3
|
|
188
|
+
q: THREE.Quaternion
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Admit an authored melee contact profile before constructing geometry or poses. */
|
|
193
|
+
export function parseMeleeWeaponProfile(
|
|
194
|
+
input: unknown,
|
|
195
|
+
): MeleeWeaponProfileRows {
|
|
196
|
+
return parse(MeleeWeaponProfileSchema, input)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Build the original +Y blade direction followed by its local roll. */
|
|
200
|
+
export function meleeKey(
|
|
201
|
+
t: number,
|
|
202
|
+
px: number,
|
|
203
|
+
py: number,
|
|
204
|
+
pz: number,
|
|
205
|
+
dx: number,
|
|
206
|
+
dy: number,
|
|
207
|
+
dz: number,
|
|
208
|
+
roll: number,
|
|
209
|
+
): MeleeKey {
|
|
210
|
+
const axis = new THREE.Vector3(0, 1, 0)
|
|
211
|
+
const q = new THREE.Quaternion().setFromUnitVectors(
|
|
212
|
+
axis,
|
|
213
|
+
new THREE.Vector3(dx, dy, dz).normalize(),
|
|
214
|
+
)
|
|
215
|
+
q.multiply(new THREE.Quaternion().setFromAxisAngle(axis, roll))
|
|
216
|
+
return { t, pos: new THREE.Vector3(px, py, pz), q }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Retain the held-model sRGB-to-linear paint law, including its optional gain. */
|
|
220
|
+
export function meleeColour(hex: number, gain = 1): THREE.Color {
|
|
221
|
+
return new THREE.Color(hex).convertSRGBToLinear().multiplyScalar(gain)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** A detached copy of the shared authored melee policy, including complete native poses.
|
|
225
|
+
* Preserve original property order and every metadata field; restore owned rich
|
|
226
|
+
* pose values after cloning plain state. No runtime view or owner is constructed. */
|
|
227
|
+
export function sharedMeleeAuthorBase(): MeleeProfile<
|
|
228
|
+
'sword',
|
|
229
|
+
'sword' | 'sword-iron',
|
|
230
|
+
'melee'
|
|
231
|
+
> {
|
|
232
|
+
const owned = structuredClone(SWORD_WOOD),
|
|
233
|
+
native = SWORD_WOOD.moves
|
|
234
|
+
if (native === undefined) return owned
|
|
235
|
+
const moves = owned.moves
|
|
236
|
+
if (moves === undefined)
|
|
237
|
+
throw new Error('Owned melee pose inventory is missing')
|
|
238
|
+
type Moves = NonNullable<MeleeProfile['moves']>
|
|
239
|
+
const restoreKey = (target: Moves['rest'], source: Moves['rest']): void => {
|
|
240
|
+
target.pos = source.pos.clone()
|
|
241
|
+
target.q = source.q.clone()
|
|
242
|
+
}
|
|
243
|
+
const restoreMove = (
|
|
244
|
+
target: Moves['heavy'],
|
|
245
|
+
source: Moves['heavy'],
|
|
246
|
+
): void => {
|
|
247
|
+
for (const index of [0, 1, 2] as const)
|
|
248
|
+
restoreKey(target.keys[index], source.keys[index])
|
|
249
|
+
target.trail.color = source.trail.color.clone()
|
|
250
|
+
}
|
|
251
|
+
restoreKey(moves.rest, native.rest)
|
|
252
|
+
restoreKey(moves.charge, native.charge)
|
|
253
|
+
restoreKey(moves.sprint, native.sprint)
|
|
254
|
+
native.combo.forEach((move, index) => {
|
|
255
|
+
const copy = moves.combo[index]
|
|
256
|
+
if (copy === undefined) throw new Error('Owned melee combo is missing')
|
|
257
|
+
restoreMove(copy, move)
|
|
258
|
+
})
|
|
259
|
+
restoreMove(moves.heavy, native.heavy)
|
|
260
|
+
return owned
|
|
261
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BARREL_BODY } from './sharedSpecs.ts'
|
|
2
|
+
|
|
3
|
+
/** The defining native puzzle barrel's complete physical declaration, without
|
|
4
|
+
* constructing a body, watch, query or live interaction owner. */
|
|
5
|
+
export function puzzleBarrelBody(): typeof BARREL_BODY {
|
|
6
|
+
return BARREL_BODY
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Rng } from '@wildshard/sdk/random'
|
|
2
|
+
import {
|
|
3
|
+
HullSpeciesSchema,
|
|
4
|
+
type HullSpeciesRows,
|
|
5
|
+
} from '@wildshard/shard-format/speciesLooks'
|
|
6
|
+
import * as v from 'valibot'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
BEAR_LOOK,
|
|
10
|
+
BOAR_LOOK,
|
|
11
|
+
bakeCommonBody,
|
|
12
|
+
commonBodyVariants,
|
|
13
|
+
commonSpeciesRows,
|
|
14
|
+
withBodyGeometry,
|
|
15
|
+
type CommonBodyKind,
|
|
16
|
+
} from './species.ts'
|
|
17
|
+
|
|
18
|
+
/** Complete native look metadata, independent of the runtime registry. */
|
|
19
|
+
export function commonHullSpecies(
|
|
20
|
+
kind: CommonBodyKind,
|
|
21
|
+
speciesId: string,
|
|
22
|
+
): HullSpeciesRows {
|
|
23
|
+
const look = kind === 'boar' ? BOAR_LOOK : BEAR_LOOK
|
|
24
|
+
const metadata = commonSpeciesRows(kind, speciesId)
|
|
25
|
+
const variant = commonBodyVariants(kind)[0]
|
|
26
|
+
if (variant === undefined) throw new Error('Missing native kit variant')
|
|
27
|
+
const { body } = withBodyGeometry(false, {}, () =>
|
|
28
|
+
bakeCommonBody(kind, variant, new Rng(42).snapshot()),
|
|
29
|
+
)
|
|
30
|
+
try {
|
|
31
|
+
return v.parse(HullSpeciesSchema, {
|
|
32
|
+
...metadata,
|
|
33
|
+
rigContract: structuredClone(look.rigContract),
|
|
34
|
+
fur: structuredClone(look.fur),
|
|
35
|
+
pose: structuredClone(look.pose),
|
|
36
|
+
variants: metadata.variants.map(row =>
|
|
37
|
+
Object.assign(
|
|
38
|
+
structuredClone(row),
|
|
39
|
+
structuredClone(look.variants?.[row.id] ?? {}),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
body: {
|
|
43
|
+
bones: structuredClone(body.bones),
|
|
44
|
+
dims: structuredClone(body.dims),
|
|
45
|
+
furParts: [],
|
|
46
|
+
hardParts: [],
|
|
47
|
+
eyeParts: [],
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
} finally {
|
|
51
|
+
for (const part of [...body.furParts, ...body.hardParts, ...body.eyeParts])
|
|
52
|
+
part.dispose()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReinPresentationSchema,
|
|
3
|
+
type ReinPresentationRows,
|
|
4
|
+
type ReinRibbonRows,
|
|
5
|
+
} from '@wildshard/shard-format/riding'
|
|
6
|
+
import {
|
|
7
|
+
Color,
|
|
8
|
+
Vector3,
|
|
9
|
+
BufferGeometry,
|
|
10
|
+
BufferAttribute,
|
|
11
|
+
DynamicDrawUsage,
|
|
12
|
+
} from 'three'
|
|
13
|
+
import { parse } from 'valibot'
|
|
14
|
+
|
|
15
|
+
import { forearm, gloveFist, riderArm } from './arms.ts'
|
|
16
|
+
|
|
17
|
+
/** Own a linear author colour: numeric hex retains the native sRGB conversion; triples are already linear. */
|
|
18
|
+
export function bakeArmColour(
|
|
19
|
+
value: number | readonly [number, number, number],
|
|
20
|
+
): Color {
|
|
21
|
+
return typeof value === 'number'
|
|
22
|
+
? new Color(value).convertSRGBToLinear().multiplyScalar(1)
|
|
23
|
+
: new Color(...value)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Independent colours in the original arm palette order, without a live view or shared mutable palette. */
|
|
27
|
+
export function bakeArmPalette(
|
|
28
|
+
style: Parameters<typeof gloveFist>[0],
|
|
29
|
+
): Record<keyof Parameters<typeof gloveFist>[0], Color> {
|
|
30
|
+
return {
|
|
31
|
+
leather: bakeArmColour(style.leather),
|
|
32
|
+
leatherLight: bakeArmColour(style.leatherLight),
|
|
33
|
+
leatherDark: bakeArmColour(style.leatherDark),
|
|
34
|
+
leatherEdge: bakeArmColour(style.leatherEdge),
|
|
35
|
+
thread: bakeArmColour(style.thread),
|
|
36
|
+
jade: bakeArmColour(style.jade),
|
|
37
|
+
jadeDark: bakeArmColour(style.jadeDark),
|
|
38
|
+
fleece: bakeArmColour(style.fleece),
|
|
39
|
+
fleeceShade: bakeArmColour(style.fleeceShade),
|
|
40
|
+
fleeceDeep: bakeArmColour(style.fleeceDeep),
|
|
41
|
+
wool: bakeArmColour(style.wool),
|
|
42
|
+
woolShade: bakeArmColour(style.woolShade),
|
|
43
|
+
red: bakeArmColour(style.red),
|
|
44
|
+
redDeep: bakeArmColour(style.redDeep),
|
|
45
|
+
redLine: bakeArmColour(style.redLine),
|
|
46
|
+
gold: bakeArmColour(style.gold),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A gloved first-person fist from an arm style (the engine's held-view fist law), for a held weapon's rest pool bake.
|
|
51
|
+
* Returns owned geometry and its wrist frame; nothing is drawn or installed. */
|
|
52
|
+
export function bakeGloveFist(
|
|
53
|
+
style: Parameters<typeof gloveFist>[0],
|
|
54
|
+
opts: Parameters<typeof gloveFist>[1],
|
|
55
|
+
): ReturnType<typeof gloveFist> {
|
|
56
|
+
return gloveFist(style, opts)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A rider's sleeved arm from an arm style (the engine's held-view arm law), for a held weapon's rest pool bake. */
|
|
60
|
+
export function bakeRiderArm(
|
|
61
|
+
style: Parameters<typeof riderArm>[0],
|
|
62
|
+
length?: number,
|
|
63
|
+
seed?: number,
|
|
64
|
+
): ReturnType<typeof riderArm> {
|
|
65
|
+
return riderArm(style, length, seed)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Construct owned fist/forearm geometry in the supplied grip direction, without a view or owner. */
|
|
69
|
+
export function bakeForearm(
|
|
70
|
+
...args: Parameters<typeof forearm>
|
|
71
|
+
): ReturnType<typeof forearm> {
|
|
72
|
+
return forearm(...args)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Admit the complete numeric strap/attachment policy without installing a riding view. */
|
|
76
|
+
export function reinPresentationRows(input: unknown): ReinPresentationRows {
|
|
77
|
+
return parse(ReinPresentationSchema, input)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function reinRgb(value: readonly number[]): [number, number, number] {
|
|
81
|
+
const [r, g, b] = value
|
|
82
|
+
if (
|
|
83
|
+
value.length !== 3 ||
|
|
84
|
+
r === undefined ||
|
|
85
|
+
g === undefined ||
|
|
86
|
+
b === undefined ||
|
|
87
|
+
!value.every(Number.isFinite)
|
|
88
|
+
)
|
|
89
|
+
throw new Error('Invalid rein colour')
|
|
90
|
+
return [r, g, b]
|
|
91
|
+
}
|
|
92
|
+
function reinCatmull(
|
|
93
|
+
out: Vector3,
|
|
94
|
+
p0: Vector3,
|
|
95
|
+
p1: Vector3,
|
|
96
|
+
p2: Vector3,
|
|
97
|
+
p3: Vector3,
|
|
98
|
+
t: number,
|
|
99
|
+
tangent: boolean,
|
|
100
|
+
): Vector3 {
|
|
101
|
+
const t2 = t * t,
|
|
102
|
+
t3 = t2 * t
|
|
103
|
+
const f = (a: number, b: number, c: number, d: number): number =>
|
|
104
|
+
tangent
|
|
105
|
+
? 0.5 *
|
|
106
|
+
(-a +
|
|
107
|
+
c +
|
|
108
|
+
2 * (2 * a - 5 * b + 4 * c - d) * t +
|
|
109
|
+
3 * (-a + 3 * b - 3 * c + d) * t2)
|
|
110
|
+
: 0.5 *
|
|
111
|
+
(2 * b +
|
|
112
|
+
(-a + c) * t +
|
|
113
|
+
(2 * a - 5 * b + 4 * c - d) * t2 +
|
|
114
|
+
(-a + 3 * b - 3 * c + d) * t3)
|
|
115
|
+
return out.set(
|
|
116
|
+
f(p0.x, p1.x, p2.x, p3.x),
|
|
117
|
+
f(p0.y, p1.y, p2.y, p3.y),
|
|
118
|
+
f(p0.z, p1.z, p2.z, p3.z),
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Bake the two camera-space straps from six Catmull-Rom anchors each.
|
|
123
|
+
* Returns owned position/normal/colour/index channels; no material or view is constructed. */
|
|
124
|
+
export function bakeReinsGeometry(
|
|
125
|
+
rows: ReinPresentationRows,
|
|
126
|
+
paths: readonly (readonly Vector3[])[],
|
|
127
|
+
): BufferGeometry {
|
|
128
|
+
if (
|
|
129
|
+
paths.length !== 2 ||
|
|
130
|
+
paths.some(
|
|
131
|
+
path =>
|
|
132
|
+
path.length !== 6 ||
|
|
133
|
+
path.some(point => ![point.x, point.y, point.z].every(Number.isFinite)),
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
throw new Error('Rein bake requires two finite six-anchor paths')
|
|
137
|
+
if (
|
|
138
|
+
!Number.isInteger(rows.span) ||
|
|
139
|
+
rows.span < 1 ||
|
|
140
|
+
rows.span > 64 ||
|
|
141
|
+
!Number.isFinite(rows.halfWidth) ||
|
|
142
|
+
rows.halfWidth <= 0
|
|
143
|
+
)
|
|
144
|
+
throw new Error('Invalid rein dimensions')
|
|
145
|
+
const SEG = rows.span * 3
|
|
146
|
+
const LEATHER = new Color(...reinRgb(rows.colour)),
|
|
147
|
+
LEATHER_EDGE = new Color(...reinRgb(rows.edge))
|
|
148
|
+
const verts = 2 * (SEG + 1) * 2
|
|
149
|
+
const pos = new Float32Array(verts * 3)
|
|
150
|
+
const nrm = new Float32Array(verts * 3),
|
|
151
|
+
col = new Float32Array(verts * 3),
|
|
152
|
+
idx: number[] = []
|
|
153
|
+
for (let v = 0; v < verts; v++) {
|
|
154
|
+
nrm[v * 3 + 2] = 1
|
|
155
|
+
const c = v % 2 === 0 ? LEATHER_EDGE : LEATHER
|
|
156
|
+
col[v * 3] = c.r
|
|
157
|
+
col[v * 3 + 1] = c.g
|
|
158
|
+
col[v * 3 + 2] = c.b
|
|
159
|
+
}
|
|
160
|
+
for (let r = 0; r < 2; r++) {
|
|
161
|
+
const o = r * (SEG + 1) * 2
|
|
162
|
+
for (let i = 0; i < SEG; i++) {
|
|
163
|
+
const a = o + i * 2
|
|
164
|
+
idx.push(a, a + 1, a + 2, a + 1, a + 3, a + 2)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const g = new BufferGeometry()
|
|
168
|
+
const attr = new BufferAttribute(pos, 3)
|
|
169
|
+
attr.setUsage(DynamicDrawUsage)
|
|
170
|
+
g.setAttribute('position', attr)
|
|
171
|
+
g.setAttribute('normal', new BufferAttribute(nrm, 3))
|
|
172
|
+
g.setAttribute('color', new BufferAttribute(col, 3))
|
|
173
|
+
g.setIndex(idx)
|
|
174
|
+
for (const [r, path] of paths.entries()) fillBakedRein(pos, r, path, rows)
|
|
175
|
+
return g
|
|
176
|
+
}
|
|
177
|
+
function fillBakedRein(
|
|
178
|
+
pos: Float32Array,
|
|
179
|
+
r: number,
|
|
180
|
+
K: readonly Vector3[],
|
|
181
|
+
rows: ReinRibbonRows,
|
|
182
|
+
): void {
|
|
183
|
+
const _p = new Vector3(),
|
|
184
|
+
_t = new Vector3(),
|
|
185
|
+
_s = new Vector3()
|
|
186
|
+
const SPAN = rows.span,
|
|
187
|
+
SEG = SPAN * 3
|
|
188
|
+
const o = r * (SEG + 1) * 2
|
|
189
|
+
for (let i = 0; i <= SEG; i++) {
|
|
190
|
+
const span = Math.min(2, Math.floor(i / SPAN)),
|
|
191
|
+
t = (i - span * SPAN) / SPAN
|
|
192
|
+
const p0 = K[span],
|
|
193
|
+
p1 = K[span + 1],
|
|
194
|
+
p2 = K[span + 2],
|
|
195
|
+
p3 = K[span + 3]
|
|
196
|
+
if (
|
|
197
|
+
p0 === undefined ||
|
|
198
|
+
p1 === undefined ||
|
|
199
|
+
p2 === undefined ||
|
|
200
|
+
p3 === undefined
|
|
201
|
+
)
|
|
202
|
+
continue
|
|
203
|
+
reinCatmull(_p, p0, p1, p2, p3, t, false)
|
|
204
|
+
reinCatmull(_t, p0, p1, p2, p3, t, true)
|
|
205
|
+
// a flat strap turned to the eye: its width across the tangent and the line of sight
|
|
206
|
+
_s.crossVectors(_t, _p).normalize().multiplyScalar(rows.halfWidth)
|
|
207
|
+
const k = (o + i * 2) * 3
|
|
208
|
+
pos[k] = _p.x + _s.x
|
|
209
|
+
pos[k + 1] = _p.y + _s.y
|
|
210
|
+
pos[k + 2] = _p.z + _s.z
|
|
211
|
+
pos[k + 3] = _p.x - _s.x
|
|
212
|
+
pos[k + 4] = _p.y - _s.y
|
|
213
|
+
pos[k + 5] = _p.z - _s.z
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const TREE_SPECS = [
|
|
2
|
+
{ height: 22, trunk: 0.42, seed: 1 },
|
|
3
|
+
{ height: 17, trunk: 0.34, seed: 2 },
|
|
4
|
+
{ height: 26, trunk: 0.5, seed: 3 },
|
|
5
|
+
{ height: 13, trunk: 0.27, seed: 4 },
|
|
6
|
+
] as const
|
|
7
|
+
|
|
8
|
+
export const BARREL_BODY: {
|
|
9
|
+
readonly shape: {
|
|
10
|
+
readonly cylinder: { readonly radius: 0.38; readonly halfHeight: 0.475 }
|
|
11
|
+
}
|
|
12
|
+
readonly material: 'wood'
|
|
13
|
+
readonly density: 250
|
|
14
|
+
readonly friction: 1
|
|
15
|
+
readonly angularDamping: 0.2
|
|
16
|
+
readonly rolling: 0.06
|
|
17
|
+
readonly keep: true
|
|
18
|
+
} = {
|
|
19
|
+
shape: { cylinder: { radius: 0.38, halfHeight: 0.475 } },
|
|
20
|
+
material: 'wood',
|
|
21
|
+
density: 250,
|
|
22
|
+
friction: 1.0,
|
|
23
|
+
angularDamping: 0.2,
|
|
24
|
+
rolling: 0.06,
|
|
25
|
+
keep: true,
|
|
26
|
+
} as const
|