@umituz/web-virtual 2.0.1 → 2.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.
@@ -1,52 +1,82 @@
1
1
  import * as THREE from 'three'
2
2
  import type { WorldPreset, WorldSlot, WorldZone } from '../core/types'
3
- import { MaterialPalette } from '../engine/materials'
3
+ import { createCropPlot } from '../entities/nature/CropFieldBuilder'
4
+ import { createTree, createTreeRow, applyWindSway } from '../entities/nature/TreeBuilder'
5
+ import { createFence } from '../entities/nature/FenceBuilder'
6
+ import { createPond } from '../entities/nature/PondBuilder'
7
+ import { createHerd } from '../entities/animals/AnimalBuilder'
8
+ import { createTractor } from '../entities/vehicles/TractorBuilder'
9
+ import {
10
+ createBarn,
11
+ createSilo,
12
+ createGreenhouse,
13
+ createMachineShed,
14
+ createCoop,
15
+ } from '../entities/architecture/FarmArchitectureBuilder'
4
16
 
5
17
  export const DEFAULT_FARM_ZONES: WorldZone[] = [
6
18
  {
7
19
  id: 'greenhouse',
8
- name: 'Hydroponics & Greenhouse',
20
+ name: 'Greenhouse',
9
21
  color: '#22c55e',
10
- description: 'Automated irrigation and climate-controlled greenhouse area.',
11
- cameraFocus: [-8, 1, -5],
22
+ description: 'Climate-controlled growing area with benches and irrigation.',
23
+ cameraFocus: [-13, 1.2, -4],
12
24
  },
13
25
  {
14
26
  id: 'crop_fields',
15
- name: 'Open Crop Fields',
27
+ name: 'Crop Fields',
16
28
  color: '#84cc16',
17
- description: 'Seasonal organic crop plots.',
18
- cameraFocus: [6, 0.5, -4],
29
+ description: 'Open planting beds at varying growth stages.',
30
+ cameraFocus: [4, 0.8, -6],
31
+ },
32
+ {
33
+ id: 'pasture',
34
+ name: 'Pasture',
35
+ color: '#a3e635',
36
+ description: 'Grazing herds and the watering pond.',
37
+ cameraFocus: [4, 0.8, 8],
19
38
  },
20
39
  {
21
40
  id: 'barn_storage',
22
- name: 'Logistics Hangar & Storage',
41
+ name: 'Barn & Storage',
23
42
  color: '#b45309',
24
- description: 'Harvest collection, packaging and tractor parking area.',
25
- cameraFocus: [0, 1.5, 6],
43
+ description: 'Barn, silo and the machinery yard.',
44
+ cameraFocus: [-9, 1.4, 8],
45
+ },
46
+ {
47
+ id: 'poultry',
48
+ name: 'Poultry Yard',
49
+ color: '#f59e0b',
50
+ description: 'Coop and free-range chicken run.',
51
+ cameraFocus: [-15, 0.8, 10],
26
52
  },
27
53
  ]
28
54
 
29
55
  export const FARM_SLOTS: WorldSlot[] = [
30
- { id: 'slot-1', label: 'Greenhouse station', position: [-8, 0, -5], zoneId: 'greenhouse', pinNumber: 1, avatarColor: '#15803d' },
31
- { id: 'slot-2', label: 'Crop field unit', position: [6, 0, -4], zoneId: 'crop_fields', pinNumber: 2 },
32
- { id: 'slot-3', label: 'Barn & logistics station', position: [0, 0, 6], zoneId: 'barn_storage', pinNumber: 3, avatarColor: '#b45309' },
56
+ { id: 'slot-1', label: 'Greenhouse station', position: [-13, 0, -4], zoneId: 'greenhouse', pinNumber: 1, avatarColor: '#15803d' },
57
+ { id: 'slot-2', label: 'Crop field unit', position: [4, 0, -6], zoneId: 'crop_fields', pinNumber: 2 },
58
+ { id: 'slot-3', label: 'Pasture station', position: [4, 0, 8], zoneId: 'pasture', pinNumber: 3, avatarColor: '#65a30d' },
59
+ { id: 'slot-4', label: 'Barn & logistics station', position: [-9, 0, 8], zoneId: 'barn_storage', pinNumber: 4, avatarColor: '#b45309' },
60
+ { id: 'slot-5', label: 'Poultry station', position: [-15, 0, 10], zoneId: 'poultry', pinNumber: 5, avatarColor: '#f59e0b' },
33
61
  ]
34
62
 
35
-
36
63
  export const farmPreset: WorldPreset = {
37
64
  id: 'preset-farm',
38
65
  name: 'Smart Agriculture & Greenhouse Complex',
39
66
  type: 'farm',
40
- description: 'Agricultural farm featuring climate-controlled greenhouses, open crop fields, and automated machinery.',
67
+ description:
68
+ 'Agricultural farm with greenhouses, staged crop plots, grazing herds, a pond, machinery yard and a poultry run.',
41
69
  dimensions: {
42
- width: 40,
43
- height: 8,
44
- depth: 25,
70
+ width: 44,
71
+ height: 10,
72
+ depth: 30,
45
73
  },
46
74
  camera: {
47
- position: [28, 25, 28],
48
- target: [0, 0, 0],
75
+ position: [30, 22, 30],
76
+ target: [-2, 0, 1],
49
77
  fov: 42,
78
+ minDistance: 6,
79
+ maxDistance: 80,
50
80
  },
51
81
  lighting: {
52
82
  ambientColor: '#f0fdf4',
@@ -65,63 +95,153 @@ export const farmPreset: WorldPreset = {
65
95
  glassColor: '#bbf7d0',
66
96
  glassOpacity: 0.22,
67
97
  accentColor: '#22c55e',
68
- backgroundColor: '#0c1a0e',
69
- nightBackgroundColor: '#020d04',
98
+ backgroundColor: '#cfe4d8',
99
+ nightBackgroundColor: '#0a1420',
70
100
  },
71
101
  zones: DEFAULT_FARM_ZONES,
72
102
  slots: FARM_SLOTS,
73
103
 
74
- buildScene: (scene: THREE.Scene, options) => {
75
- const materials = new MaterialPalette()
76
-
77
- // 1. Soil ground
78
- const groundGeo = new THREE.PlaneGeometry(40, 25)
79
- const soilMat = materials.getDarkSlate(options.theme?.floorColor || '#365314')
80
- const ground = new THREE.Mesh(groundGeo, soilMat)
104
+ buildScene: (scene, options) => {
105
+ // 1. Ground — grass plane with a soil work strip
106
+ const grassMat = new THREE.MeshStandardMaterial({ color: '#679a4c', roughness: 1 })
107
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(46, 32), grassMat)
81
108
  ground.rotation.x = -Math.PI / 2
82
109
  ground.receiveShadow = true
83
110
  scene.add(ground)
84
111
 
85
- // 2. Greenhouse structure
86
- const ghGroup = new THREE.Group()
87
- ghGroup.position.set(-10, 0, -5)
112
+ // 2. Crop fields — four plots at staggered growth stages
113
+ const plots: Array<{ x: number; z: number; growth: number; color: string; rows: number }> = [
114
+ { x: 1, z: -9, growth: 0.85, color: '#5d8a2a', rows: 6 },
115
+ { x: 10, z: -9, growth: 0.45, color: '#7ba72f', rows: 5 },
116
+ { x: 1, z: -1, growth: 0.2, color: '#8fbf3f', rows: 6 },
117
+ { x: 10, z: -1, growth: 0.65, color: '#4d7c0f', rows: 5 },
118
+ ]
119
+ for (const plot of plots) {
120
+ const p = createCropPlot({
121
+ width: 7.5,
122
+ depth: 6,
123
+ rows: plot.rows,
124
+ growth: plot.growth,
125
+ cropColor: plot.color,
126
+ seed: 5 + plot.x + plot.z,
127
+ })
128
+ p.position.set(plot.x, 0, plot.z)
129
+ scene.add(p)
130
+ }
131
+
132
+ // 3. Greenhouse with interior benches
133
+ scene.add(
134
+ createGreenhouse({
135
+ width: 9,
136
+ depth: 6.4,
137
+ position: [-13, 0, -5.5],
138
+ benches: [
139
+ { color: '#3f8f3a', growth: 0.7 },
140
+ { color: '#58a34e', growth: 0.5 },
141
+ { color: '#77b852', growth: 0.9 },
142
+ ],
143
+ }),
144
+ )
145
+
146
+ // 4. Pasture — fenced paddock, cow herd, sheep, pond with ripples
147
+ const paddock = createFence({
148
+ points: [
149
+ [-1, 0, 4.5],
150
+ [12.5, 0, 4.5],
151
+ [12.5, 0, 13],
152
+ [-1, 0, 13],
153
+ [-1, 0, 4.5],
154
+ ],
155
+ })
156
+ scene.add(paddock)
88
157
 
89
- const ghFloor = new THREE.Mesh(
90
- new THREE.PlaneGeometry(12, 10),
91
- materials.getTileFloor('#a3e635'),
158
+ scene.add(
159
+ createHerd({
160
+ species: 'cow',
161
+ count: 5,
162
+ area: { width: 9, depth: 5.5 },
163
+ center: [2.5, 0, 8.2],
164
+ registerTick: options.registerTick,
165
+ }),
92
166
  )
93
- ghFloor.rotation.x = -Math.PI / 2
94
- ghFloor.position.set(0, 0.01, 0)
95
- ghGroup.add(ghFloor)
96
-
97
- // Glass arches
98
- const glassMat = materials.getGlassMaterial('#86efac', 0.25)
99
- const domeGeo = new THREE.CylinderGeometry(5, 5, 12, 16, 1, false, 0, Math.PI)
100
- const dome = new THREE.Mesh(domeGeo, glassMat)
101
- dome.rotation.z = Math.PI / 2
102
- dome.position.set(0, 3, 0)
103
- ghGroup.add(dome)
104
- scene.add(ghGroup)
105
-
106
- // 3. Barn / Storage building
107
- const barnGroup = new THREE.Group()
108
- barnGroup.position.set(0, 0, 7)
109
- const barnWalls = new THREE.Mesh(
110
- new THREE.BoxGeometry(14, 4, 8),
111
- materials.getWallMaterial('#7f1d1d'),
167
+ scene.add(
168
+ createHerd({
169
+ species: 'sheep',
170
+ count: 6,
171
+ area: { width: 4, depth: 4 },
172
+ center: [9, 0, 10.5],
173
+ scale: 0.9,
174
+ seed: 41,
175
+ registerTick: options.registerTick,
176
+ }),
112
177
  )
113
- barnWalls.position.set(0, 2, 0)
114
- barnWalls.castShadow = true
115
- barnGroup.add(barnWalls)
116
-
117
- // Roof
118
- const roof = new THREE.Mesh(
119
- new THREE.ConeGeometry(8, 2, 4),
120
- materials.getFrameMaterial('#1c1917'),
178
+
179
+ const pond = createPond({
180
+ radius: 2.4,
181
+ position: [9.4, 0, 6.2],
182
+ registerTick: options.registerTick,
183
+ })
184
+ scene.add(pond)
185
+
186
+ // 5. Barnyard — barn, silo, machine shed, working tractor
187
+ scene.add(createBarn({ width: 9, depth: 6.5, position: [-9, 0, 8.5] }))
188
+ scene.add(createSilo({ radius: 1.3, height: 5.5, position: [-14.4, 0, 8.5] }))
189
+ scene.add(
190
+ createMachineShed({ width: 8, depth: 5, position: [-8.5, 0, 14], rotationY: Math.PI }),
121
191
  )
122
- roof.position.set(0, 5, 0)
123
- roof.rotation.y = Math.PI / 4
124
- barnGroup.add(roof)
125
- scene.add(barnGroup)
192
+
193
+ const tractorWorking = createTractor({
194
+ status: 'running',
195
+ implement: 'mower',
196
+ registerTick: options.registerTick,
197
+ })
198
+ tractorWorking.position.set(6.5, 0, -4.5)
199
+ tractorWorking.rotation.y = -Math.PI / 2
200
+ scene.add(tractorWorking)
201
+
202
+ const tractorParked = createTractor({
203
+ bodyColor: '#1d6fb8',
204
+ status: 'idle',
205
+ implement: 'trailer',
206
+ })
207
+ tractorParked.position.set(-6.2, 0, 13.8)
208
+ tractorParked.rotation.y = Math.PI
209
+ scene.add(tractorParked)
210
+
211
+ // 6. Poultry yard
212
+ scene.add(createCoop({ position: [-15.5, 0, 12.5], rotationY: 0.5 }))
213
+ scene.add(
214
+ createHerd({
215
+ species: 'chicken',
216
+ count: 7,
217
+ area: { width: 3.4, depth: 3 },
218
+ center: [-14.6, 0, 14.6],
219
+ seed: 77,
220
+ registerTick: options.registerTick,
221
+ }),
222
+ )
223
+
224
+ // 7. Windbreak tree rows swaying in the breeze
225
+ const northRow = createTreeRow({ count: 8, spacing: 3.2, axis: 'x', shape: 'broad', height: 4.6, season: 'summer' })
226
+ northRow.position.set(0, 0, -14.5)
227
+ scene.add(northRow)
228
+ applyWindSway(northRow, options.registerTick, { intensity: 0.022, speed: 1.2 })
229
+
230
+ const eastRow = createTreeRow({ count: 5, spacing: 3.2, axis: 'z', shape: 'conifer', height: 5.2 })
231
+ eastRow.position.set(16.5, 0, 2)
232
+ scene.add(eastRow)
233
+ applyWindSway(eastRow, options.registerTick, { intensity: 0.016, speed: 0.9, phase: 1.9 })
234
+
235
+ // A few orchard-style round trees near the greenhouse
236
+ for (const [tx, tz] of [
237
+ [-17.5, 0.5],
238
+ [-17.5, 3.5],
239
+ [-16, -10.5],
240
+ ] as const) {
241
+ const tree = createTree({ shape: 'round', height: 3.6, season: 'autumn', seed: tx * 7 + tz })
242
+ tree.position.set(tx, 0, tz)
243
+ scene.add(tree)
244
+ applyWindSway(tree, options.registerTick, { intensity: 0.02, speed: 1.5, phase: tx })
245
+ }
126
246
  },
127
247
  }
@@ -1335,6 +1335,10 @@
1335
1335
  flex: 1;
1336
1336
  width: 100%;
1337
1337
  height: 100%;
1338
+ /* Flex items default to min-width:auto, so the pixel-sized 3D canvas
1339
+ inside blocks shrinking and pushes the roster sidebar off-screen.
1340
+ Allow the wrapper to shrink so sidebars stay in the viewport. */
1341
+ min-width: 0;
1338
1342
  }
1339
1343
 
1340
1344
  .wv-hq-loading-overlay {