@umituz/web-virtual 2.2.0 → 2.3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-virtual",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Universal 3D Virtual Environment Engine for Web & React — Offices, Farms, Factories, Schools, Hospitals with 60fps performance, raycasting and interactive entities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -3,13 +3,24 @@ import * as THREE from 'three'
|
|
|
3
3
|
import { createAnimal, createHerd } from './AnimalBuilder'
|
|
4
4
|
|
|
5
5
|
describe('createAnimal', () => {
|
|
6
|
-
it.each(
|
|
6
|
+
it.each(
|
|
7
|
+
[
|
|
8
|
+
'cow', 'buffalo', 'sheep', 'goat', 'horse', 'pig', 'rabbit',
|
|
9
|
+
'chicken', 'turkey', 'quail', 'duck', 'goose',
|
|
10
|
+
] as const,
|
|
11
|
+
)('builds a %s with a head pivot', (species) => {
|
|
7
12
|
const animal = createAnimal({ species })
|
|
8
13
|
expect(animal.getObjectByName('animal-neck')).toBeTruthy()
|
|
9
14
|
expect(animal.getObjectByName('animal-head')).toBeTruthy()
|
|
10
15
|
expect(animal.children.length).toBeGreaterThan(3)
|
|
11
16
|
})
|
|
12
17
|
|
|
18
|
+
it('falls back to the cow silhouette for an unknown species instead of crashing', () => {
|
|
19
|
+
const junk = createAnimal({ species: 'space-whale' as never })
|
|
20
|
+
expect(junk.getObjectByName('animal-head')).toBeTruthy()
|
|
21
|
+
expect(junk.name).toBe('animal-space-whale')
|
|
22
|
+
})
|
|
23
|
+
|
|
13
24
|
it('scales uniformly', () => {
|
|
14
25
|
const animal = createAnimal({ species: 'cow', scale: 2 })
|
|
15
26
|
expect(animal.scale.x).toBe(2)
|
|
@@ -19,6 +30,14 @@ describe('createAnimal', () => {
|
|
|
19
30
|
})
|
|
20
31
|
|
|
21
32
|
describe('createHerd', () => {
|
|
33
|
+
it('never crashes a scene build on an unknown species (regression: live farm crash)', () => {
|
|
34
|
+
const herd = createHerd({ species: 'emu' as never, count: 3 })
|
|
35
|
+
expect(herd.children).toHaveLength(3)
|
|
36
|
+
for (const child of herd.children) {
|
|
37
|
+
expect(child.getObjectByName('animal-head')).toBeTruthy()
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
22
41
|
it('creates exactly count animals inside the grazing area', () => {
|
|
23
42
|
const herd = createHerd({ species: 'cow', count: 9, area: { width: 8, depth: 6 }, center: [3, 0, 4] })
|
|
24
43
|
const animals = herd.children.filter((c) => c.name === 'animal-cow')
|
|
@@ -9,7 +9,9 @@ import type { WorldTickFn, UnregisterTick } from '../../core/types'
|
|
|
9
9
|
* deterministically from a seed — same seed, same scene, every time.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export type AnimalSpecies =
|
|
12
|
+
export type AnimalSpecies =
|
|
13
|
+
| 'cow' | 'buffalo' | 'sheep' | 'goat' | 'horse' | 'pig' | 'rabbit'
|
|
14
|
+
| 'chicken' | 'turkey' | 'quail' | 'duck' | 'goose'
|
|
13
15
|
|
|
14
16
|
export interface AnimalOptions {
|
|
15
17
|
species?: AnimalSpecies
|
|
@@ -25,14 +27,30 @@ const SPECIES_DEFAULTS: Record<
|
|
|
25
27
|
{ body: string; accent: string; bodyW: number; bodyH: number; bodyD: number; legH: number; headScale: number }
|
|
26
28
|
> = {
|
|
27
29
|
cow: { body: '#f5f0e6', accent: '#3d3630', bodyW: 0.62, bodyH: 0.5, bodyD: 1.05, legH: 0.42, headScale: 1 },
|
|
30
|
+
buffalo: { body: '#4a443c', accent: '#2b2724', bodyW: 0.68, bodyH: 0.55, bodyD: 1.1, legH: 0.4, headScale: 1.05 },
|
|
28
31
|
sheep: { body: '#ece7db', accent: '#4a4038', bodyW: 0.46, bodyH: 0.44, bodyD: 0.72, legH: 0.3, headScale: 0.8 },
|
|
29
32
|
goat: { body: '#cbb8a0', accent: '#6b5a45', bodyW: 0.4, bodyH: 0.42, bodyD: 0.68, legH: 0.36, headScale: 0.75 },
|
|
33
|
+
horse: { body: '#7a5a3a', accent: '#3a2c1e', bodyW: 0.55, bodyH: 0.5, bodyD: 1.0, legH: 0.55, headScale: 0.9 },
|
|
34
|
+
pig: { body: '#e8b4b8', accent: '#c98a90', bodyW: 0.5, bodyH: 0.42, bodyD: 0.85, legH: 0.25, headScale: 0.85 },
|
|
35
|
+
rabbit: { body: '#c8c2b8', accent: '#8a8178', bodyW: 0.18, bodyH: 0.18, bodyD: 0.26, legH: 0.08, headScale: 0.6 },
|
|
30
36
|
chicken: { body: '#f8f4ec', accent: '#c2452d', bodyW: 0.2, bodyH: 0.22, bodyD: 0.28, legH: 0.12, headScale: 0.5 },
|
|
37
|
+
turkey: { body: '#5a4a3a', accent: '#c2452d', bodyW: 0.3, bodyH: 0.3, bodyD: 0.4, legH: 0.18, headScale: 0.55 },
|
|
38
|
+
quail: { body: '#b8a88a', accent: '#6b5a45', bodyW: 0.14, bodyH: 0.14, bodyD: 0.2, legH: 0.07, headScale: 0.5 },
|
|
39
|
+
duck: { body: '#f2ede0', accent: '#d97f2e', bodyW: 0.22, bodyH: 0.2, bodyD: 0.32, legH: 0.1, headScale: 0.5 },
|
|
40
|
+
goose: { body: '#e8e4da', accent: '#d97f2e', bodyW: 0.26, bodyH: 0.24, bodyD: 0.4, legH: 0.14, headScale: 0.5 },
|
|
31
41
|
}
|
|
32
42
|
|
|
43
|
+
/** Birds walk on slim legs and carry a beak; the crest is land-fowl only. */
|
|
44
|
+
const BIRD_SPECIES = new Set<AnimalSpecies>(['chicken', 'turkey', 'quail', 'duck', 'goose'])
|
|
45
|
+
const CRESTED_SPECIES = new Set<AnimalSpecies>(['chicken', 'turkey', 'quail'])
|
|
46
|
+
const HORNED_SPECIES = new Set<AnimalSpecies>(['goat', 'buffalo'])
|
|
47
|
+
|
|
33
48
|
export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
34
49
|
const { species = 'cow', bodyColor, scale = 1, seed = 1 } = options
|
|
35
|
-
|
|
50
|
+
// Unknown codes (junk data, a consumer's newer vocabulary) fall back to
|
|
51
|
+
// the cow silhouette instead of crashing the scene build.
|
|
52
|
+
const d = SPECIES_DEFAULTS[species] ?? SPECIES_DEFAULTS.cow
|
|
53
|
+
const isBird = BIRD_SPECIES.has(species)
|
|
36
54
|
const rng = createRng(seed)
|
|
37
55
|
|
|
38
56
|
const group = new THREE.Group()
|
|
@@ -53,8 +71,8 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
|
53
71
|
body.castShadow = true
|
|
54
72
|
group.add(body)
|
|
55
73
|
|
|
56
|
-
// Patch on
|
|
57
|
-
if (species === 'cow' || species === 'sheep') {
|
|
74
|
+
// Patch on bovids (a darker back patch reads as a breed marker)
|
|
75
|
+
if (species === 'cow' || species === 'buffalo' || species === 'sheep') {
|
|
58
76
|
const patch = new THREE.Mesh(
|
|
59
77
|
new THREE.BoxGeometry(bw * 1.02, bh * 0.5, bd * (0.3 + rng() * 0.3)),
|
|
60
78
|
accentMat,
|
|
@@ -71,20 +89,22 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
|
71
89
|
|
|
72
90
|
const head = new THREE.Mesh(
|
|
73
91
|
new THREE.BoxGeometry(bw * 0.45 * d.headScale, bh * 0.5 * d.headScale, bw * 0.5 * d.headScale),
|
|
74
|
-
|
|
92
|
+
isBird ? accentMat : bodyMat,
|
|
75
93
|
)
|
|
76
94
|
head.name = 'animal-head'
|
|
77
95
|
head.position.set(0, bh * 0.15, bw * 0.28 * d.headScale)
|
|
78
96
|
head.castShadow = true
|
|
79
97
|
neck.add(head)
|
|
80
98
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
new THREE.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
if (isBird) {
|
|
100
|
+
if (CRESTED_SPECIES.has(species)) {
|
|
101
|
+
const comb = new THREE.Mesh(
|
|
102
|
+
new THREE.BoxGeometry(bw * 0.12, bh * 0.22, bw * 0.2),
|
|
103
|
+
accentMat,
|
|
104
|
+
)
|
|
105
|
+
comb.position.set(0, bh * 0.42, 0)
|
|
106
|
+
neck.add(comb)
|
|
107
|
+
}
|
|
88
108
|
const beak = new THREE.Mesh(
|
|
89
109
|
new THREE.ConeGeometry(bw * 0.07, bh * 0.22, 4),
|
|
90
110
|
new THREE.MeshStandardMaterial({ color: '#d9a441', roughness: 0.8 }),
|
|
@@ -93,16 +113,17 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
|
93
113
|
beak.position.set(0, bh * 0.05, bw * 0.55 * d.headScale)
|
|
94
114
|
neck.add(beak)
|
|
95
115
|
} else {
|
|
96
|
-
// Ears
|
|
116
|
+
// Ears — tall and slender on a rabbit, stubby on the rest
|
|
117
|
+
const earH = species === 'rabbit' ? bh * 0.55 : bh * 0.14
|
|
97
118
|
for (const side of [-1, 1]) {
|
|
98
119
|
const ear = new THREE.Mesh(
|
|
99
|
-
new THREE.BoxGeometry(bw * 0.12,
|
|
120
|
+
new THREE.BoxGeometry(bw * 0.12, earH, bw * 0.08),
|
|
100
121
|
accentMat,
|
|
101
122
|
)
|
|
102
|
-
ear.position.set(side * bw * 0.25 * d.headScale, bh * 0.28, -bw * 0.05)
|
|
123
|
+
ear.position.set(side * bw * 0.25 * d.headScale, bh * 0.28 + earH * 0.4, -bw * 0.05)
|
|
103
124
|
neck.add(ear)
|
|
104
125
|
}
|
|
105
|
-
if (species
|
|
126
|
+
if (HORNED_SPECIES.has(species)) {
|
|
106
127
|
for (const side of [-1, 1]) {
|
|
107
128
|
const horn = new THREE.Mesh(
|
|
108
129
|
new THREE.ConeGeometry(bw * 0.05, bh * 0.35, 4),
|
|
@@ -115,11 +136,10 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
|
|
118
|
-
// Legs (
|
|
119
|
-
const legGeo =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: new THREE.BoxGeometry(bw * 0.16, d.legH, bw * 0.16)
|
|
139
|
+
// Legs (birds get slim cylinder legs; quadrupeds chunky boxes)
|
|
140
|
+
const legGeo = isBird
|
|
141
|
+
? new THREE.CylinderGeometry(0.015, 0.015, d.legH, 4)
|
|
142
|
+
: new THREE.BoxGeometry(bw * 0.16, d.legH, bw * 0.16)
|
|
123
143
|
for (const [lx, lz] of [
|
|
124
144
|
[-1, -1],
|
|
125
145
|
[1, -1],
|
|
@@ -134,7 +154,7 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
|
|
|
134
154
|
// Tail
|
|
135
155
|
const tail = new THREE.Mesh(
|
|
136
156
|
new THREE.BoxGeometry(bw * 0.12, bh * 0.3, bw * 0.08),
|
|
137
|
-
|
|
157
|
+
isBird ? bodyMat : accentMat,
|
|
138
158
|
)
|
|
139
159
|
tail.position.set(0, d.legH + bh * 0.9, -bd / 2 - bw * 0.02)
|
|
140
160
|
tail.name = 'animal-tail'
|