JavaScript · 31556 bytes Raw Blame History
1 // Building mesh factories for dougk
2 // Creates 3D meshes for placeable buildings
3
4 import * as THREE from 'three'
5
6 // Create a wooden dock
7 // Dock protrudes into water - shore side at origin, water side extends in -Z direction
8 export function createDock(gradientMap) {
9 const group = new THREE.Group()
10
11 const woodMaterial = new THREE.MeshToonMaterial({
12 color: 0x8b6914,
13 gradientMap
14 })
15
16 const darkWoodMaterial = new THREE.MeshToonMaterial({
17 color: 0x5c4a1a,
18 gradientMap
19 })
20
21 // Dock dimensions - extends into water
22 const dockWidth = 0.8
23 const dockLength = 1.2 // How far it protrudes into water
24 const dockHeight = 0.08
25
26 // Main platform - offset so shore edge is at z=0, water edge at z=-dockLength
27 const platformGeom = new THREE.BoxGeometry(dockWidth, dockHeight, dockLength)
28 const platform = new THREE.Mesh(platformGeom, woodMaterial)
29 platform.position.set(0, 0.04, -dockLength / 2)
30 group.add(platform)
31
32 // Planks (crosswise detail lines)
33 for (let i = 0; i < 6; i++) {
34 const plankGeom = new THREE.BoxGeometry(dockWidth - 0.02, 0.09, 0.03)
35 const plank = new THREE.Mesh(plankGeom, darkWoodMaterial)
36 plank.position.set(0, 0.045, -0.1 - i * 0.2)
37 group.add(plank)
38 }
39
40 // Support posts - two at shore, two at water end
41 const postGeom = new THREE.CylinderGeometry(0.05, 0.06, 0.5, 6)
42 const postPositions = [
43 // Shore posts (shorter, above ground)
44 { x: -dockWidth / 2 + 0.08, z: -0.1, height: 0.3, yOffset: -0.1 },
45 { x: dockWidth / 2 - 0.08, z: -0.1, height: 0.3, yOffset: -0.1 },
46 // Water posts (longer, go into water)
47 { x: -dockWidth / 2 + 0.08, z: -dockLength + 0.15, height: 0.6, yOffset: -0.25 },
48 { x: dockWidth / 2 - 0.08, z: -dockLength + 0.15, height: 0.6, yOffset: -0.25 }
49 ]
50
51 for (const pos of postPositions) {
52 const pGeom = new THREE.CylinderGeometry(0.05, 0.06, pos.height, 6)
53 const post = new THREE.Mesh(pGeom, darkWoodMaterial)
54 post.position.set(pos.x, pos.yOffset, pos.z)
55 group.add(post)
56 }
57
58 // Rope detail on water-end posts
59 const ropeMaterial = new THREE.MeshToonMaterial({
60 color: 0x8b7355,
61 gradientMap
62 })
63 const ropeGeom = new THREE.TorusGeometry(0.06, 0.015, 6, 12)
64
65 // Rope on left water post
66 const ropeLeft = new THREE.Mesh(ropeGeom, ropeMaterial)
67 ropeLeft.position.set(-dockWidth / 2 + 0.08, 0.08, -dockLength + 0.15)
68 ropeLeft.rotation.x = Math.PI / 2
69 group.add(ropeLeft)
70
71 // Rope on right water post
72 const ropeRight = new THREE.Mesh(ropeGeom, ropeMaterial)
73 ropeRight.position.set(dockWidth / 2 - 0.08, 0.08, -dockLength + 0.15)
74 ropeRight.rotation.x = Math.PI / 2
75 group.add(ropeRight)
76
77 return group
78 }
79
80 // Create a fishing hut
81 // Hut sits on shore with front porch extending toward water (-Z direction)
82 export function createFishingHut(gradientMap) {
83 const group = new THREE.Group()
84
85 const woodMaterial = new THREE.MeshToonMaterial({
86 color: 0x9b7653,
87 gradientMap
88 })
89
90 const roofMaterial = new THREE.MeshToonMaterial({
91 color: 0x654321,
92 gradientMap
93 })
94
95 const windowMaterial = new THREE.MeshBasicMaterial({
96 color: 0x87ceeb,
97 transparent: true,
98 opacity: 0.6
99 })
100
101 const darkWoodMaterial = new THREE.MeshToonMaterial({
102 color: 0x5c4a1a,
103 gradientMap
104 })
105
106 // Front porch/deck extending into water
107 const porchGeom = new THREE.BoxGeometry(0.7, 0.06, 0.5)
108 const porch = new THREE.Mesh(porchGeom, darkWoodMaterial)
109 porch.position.set(0, 0.02, -0.25)
110 group.add(porch)
111
112 // Porch support posts (in water)
113 const porchPostGeom = new THREE.CylinderGeometry(0.03, 0.04, 0.4, 6)
114 const porchPosts = [
115 { x: -0.3, z: -0.45 },
116 { x: 0.3, z: -0.45 }
117 ]
118 for (const pos of porchPosts) {
119 const post = new THREE.Mesh(porchPostGeom, darkWoodMaterial)
120 post.position.set(pos.x, -0.15, pos.z)
121 group.add(post)
122 }
123
124 // Main building base/floor - offset onto shore
125 const baseGeom = new THREE.BoxGeometry(0.9, 0.08, 0.7)
126 const base = new THREE.Mesh(baseGeom, woodMaterial)
127 base.position.set(0, 0.04, 0.35)
128 group.add(base)
129
130 // Walls
131 const wallGeom = new THREE.BoxGeometry(0.85, 0.5, 0.65)
132 const walls = new THREE.Mesh(wallGeom, woodMaterial)
133 walls.position.set(0, 0.33, 0.35)
134 group.add(walls)
135
136 // Roof
137 const roofGeom = new THREE.ConeGeometry(0.55, 0.35, 4)
138 const roof = new THREE.Mesh(roofGeom, roofMaterial)
139 roof.position.set(0, 0.75, 0.35)
140 roof.rotation.y = Math.PI / 4
141 group.add(roof)
142
143 // Window (on side wall)
144 const windowGeom = new THREE.PlaneGeometry(0.15, 0.15)
145 const window1 = new THREE.Mesh(windowGeom, windowMaterial)
146 window1.position.set(0.43, 0.37, 0.35)
147 window1.rotation.y = Math.PI / 2
148 group.add(window1)
149
150 // Door (facing water)
151 const doorFrameGeom = new THREE.BoxGeometry(0.22, 0.35, 0.03)
152 const doorFrame = new THREE.Mesh(doorFrameGeom, roofMaterial)
153 doorFrame.position.set(0, 0.26, 0.03)
154 group.add(doorFrame)
155
156 const doorGeom = new THREE.BoxGeometry(0.18, 0.32, 0.02)
157 const door = new THREE.Mesh(doorGeom, darkWoodMaterial)
158 door.position.set(0, 0.24, 0.02)
159 group.add(door)
160
161 return group
162 }
163
164 // Create a mini lighthouse
165 export function createLighthouse(gradientMap) {
166 const group = new THREE.Group()
167
168 const whiteMaterial = new THREE.MeshToonMaterial({
169 color: 0xf5f5f5,
170 gradientMap
171 })
172
173 const redMaterial = new THREE.MeshToonMaterial({
174 color: 0xcc3333,
175 gradientMap
176 })
177
178 const glassMaterial = new THREE.MeshBasicMaterial({
179 color: 0xffffaa,
180 transparent: true,
181 opacity: 0.8
182 })
183
184 // Base
185 const baseGeom = new THREE.CylinderGeometry(0.25, 0.3, 0.15, 8)
186 const base = new THREE.Mesh(baseGeom, whiteMaterial)
187 base.position.y = 0.075
188 group.add(base)
189
190 // Tower - alternating stripes
191 const stripeHeight = 0.2
192 for (let i = 0; i < 4; i++) {
193 const stripeGeom = new THREE.CylinderGeometry(
194 0.18 - i * 0.02,
195 0.2 - i * 0.02,
196 stripeHeight,
197 8
198 )
199 const stripe = new THREE.Mesh(stripeGeom, i % 2 === 0 ? whiteMaterial : redMaterial)
200 stripe.position.y = 0.25 + i * stripeHeight
201 group.add(stripe)
202 }
203
204 // Lamp housing
205 const housingGeom = new THREE.CylinderGeometry(0.12, 0.1, 0.15, 8)
206 const housing = new THREE.Mesh(housingGeom, redMaterial)
207 housing.position.y = 1.02
208 group.add(housing)
209
210 // Glass/light
211 const glassGeom = new THREE.SphereGeometry(0.08, 8, 6)
212 const glass = new THREE.Mesh(glassGeom, glassMaterial)
213 glass.position.y = 1.0
214 group.add(glass)
215
216 // Light beam (animated)
217 const beamGroup = new THREE.Group()
218 beamGroup.position.y = 1.0
219
220 const beamMaterial = new THREE.MeshBasicMaterial({
221 color: 0xffffaa,
222 transparent: true,
223 opacity: 0.3,
224 side: THREE.DoubleSide
225 })
226
227 // Create a cone-shaped beam - tip at lamp, wide end extending outward
228 const beamGeom = new THREE.ConeGeometry(0.8, 2.5, 8, 1, true)
229 beamGeom.rotateX(-Math.PI / 2) // Tip toward -Z, base toward +Z
230 beamGeom.translate(0, 0, 1.25) // Move so tip is at origin (lamp), base extends outward
231 const beam = new THREE.Mesh(beamGeom, beamMaterial)
232 beamGroup.add(beam)
233
234 // Mark for animation
235 beamGroup.userData.isLightBeam = true
236 group.add(beamGroup)
237
238 // Roof cap
239 const capGeom = new THREE.ConeGeometry(0.14, 0.12, 8)
240 const cap = new THREE.Mesh(capGeom, redMaterial)
241 cap.position.y = 1.15
242 group.add(cap)
243
244 // Mark group as lighthouse for animation
245 group.userData.isLighthouse = true
246
247 return group
248 }
249
250 // Create reed cluster
251 export function createReeds(gradientMap) {
252 const group = new THREE.Group()
253
254 const reedMaterial = new THREE.MeshToonMaterial({
255 color: 0x4a7c3f,
256 gradientMap
257 })
258
259 const tipMaterial = new THREE.MeshToonMaterial({
260 color: 0x8b7355,
261 gradientMap
262 })
263
264 // Create 5-7 reeds
265 const reedCount = 5 + Math.floor(Math.random() * 3)
266 const reeds = []
267
268 for (let i = 0; i < reedCount; i++) {
269 const height = 0.4 + Math.random() * 0.3
270 const angle = (i / reedCount) * Math.PI * 2 + Math.random() * 0.5
271 const dist = Math.random() * 0.15
272
273 // Reed group (stalk + tip together for swaying)
274 const reedGroup = new THREE.Group()
275 reedGroup.position.set(
276 Math.cos(angle) * dist,
277 0,
278 Math.sin(angle) * dist
279 )
280
281 // Reed stalk
282 const stalkGeom = new THREE.CylinderGeometry(0.015, 0.02, height, 4)
283 const stalk = new THREE.Mesh(stalkGeom, reedMaterial)
284 stalk.position.y = height / 2 - 0.1
285 reedGroup.add(stalk)
286
287 // Cattail tip
288 const tipGeom = new THREE.CylinderGeometry(0.03, 0.025, 0.1, 6)
289 const tip = new THREE.Mesh(tipGeom, tipMaterial)
290 tip.position.y = height - 0.05
291 reedGroup.add(tip)
292
293 // Mark for animation with random phase
294 reedGroup.userData.isReed = true
295 reedGroup.userData.phase = Math.random() * Math.PI * 2
296 reedGroup.userData.baseRotX = (Math.random() - 0.5) * 0.2
297 reedGroup.userData.baseRotZ = (Math.random() - 0.5) * 0.2
298
299 reeds.push(reedGroup)
300 group.add(reedGroup)
301 }
302
303 // Mark group as reeds cluster for animation
304 group.userData.isReeds = true
305 group.userData.reedChildren = reeds
306
307 return group
308 }
309
310 // Create fence segment
311 export function createFence(gradientMap) {
312 const group = new THREE.Group()
313
314 const woodMaterial = new THREE.MeshToonMaterial({
315 color: 0xa0826d,
316 gradientMap
317 })
318
319 // Two posts
320 const postGeom = new THREE.BoxGeometry(0.06, 0.4, 0.06)
321
322 const post1 = new THREE.Mesh(postGeom, woodMaterial)
323 post1.position.set(-0.25, 0.15, 0)
324 group.add(post1)
325
326 const post2 = new THREE.Mesh(postGeom, woodMaterial)
327 post2.position.set(0.25, 0.15, 0)
328 group.add(post2)
329
330 // Pointed tops
331 const pointGeom = new THREE.ConeGeometry(0.04, 0.08, 4)
332
333 const point1 = new THREE.Mesh(pointGeom, woodMaterial)
334 point1.position.set(-0.25, 0.39, 0)
335 group.add(point1)
336
337 const point2 = new THREE.Mesh(pointGeom, woodMaterial)
338 point2.position.set(0.25, 0.39, 0)
339 group.add(point2)
340
341 // Cross beams
342 const beamGeom = new THREE.BoxGeometry(0.5, 0.04, 0.03)
343
344 const beam1 = new THREE.Mesh(beamGeom, woodMaterial)
345 beam1.position.set(0, 0.25, 0)
346 group.add(beam1)
347
348 const beam2 = new THREE.Mesh(beamGeom, woodMaterial)
349 beam2.position.set(0, 0.1, 0)
350 group.add(beam2)
351
352 return group
353 }
354
355 // Create a giant onion house
356 export function createOnionHouse(gradientMap) {
357 const group = new THREE.Group()
358
359 // Onion colors - layered purples and whites
360 const outerSkinMaterial = new THREE.MeshToonMaterial({
361 color: 0x8b668b, // Dusty purple outer skin
362 gradientMap
363 })
364
365 const innerSkinMaterial = new THREE.MeshToonMaterial({
366 color: 0xdda0dd, // Lighter purple inner layer peeking through
367 gradientMap
368 })
369
370 const rootMaterial = new THREE.MeshToonMaterial({
371 color: 0xd2b48c, // Tan roots
372 gradientMap
373 })
374
375 const doorMaterial = new THREE.MeshToonMaterial({
376 color: 0x4a3728, // Dark wood door
377 gradientMap
378 })
379
380 const chimneyMaterial = new THREE.MeshToonMaterial({
381 color: 0x8b7355, // Stone chimney
382 gradientMap
383 })
384
385 // Main onion body - bulbous bottom
386 const bulbGeom = new THREE.SphereGeometry(0.5, 10, 8)
387 bulbGeom.scale(1, 0.85, 1)
388 const bulb = new THREE.Mesh(bulbGeom, outerSkinMaterial)
389 bulb.position.y = 0.4
390 group.add(bulb)
391
392 // Onion top/neck tapering up
393 const neckGeom = new THREE.CylinderGeometry(0.15, 0.35, 0.4, 8)
394 const neck = new THREE.Mesh(neckGeom, outerSkinMaterial)
395 neck.position.y = 0.95
396 group.add(neck)
397
398 // Dried top sprout/tip
399 const tipGeom = new THREE.ConeGeometry(0.08, 0.25, 6)
400 const tip = new THREE.Mesh(tipGeom, rootMaterial)
401 tip.position.y = 1.27
402 tip.rotation.z = 0.15 // Slight lean for whimsy
403 group.add(tip)
404
405 // Peeling skin detail (decorative flaps)
406 const peelGeom = new THREE.PlaneGeometry(0.2, 0.35)
407 const peel1 = new THREE.Mesh(peelGeom, innerSkinMaterial)
408 peel1.position.set(0.45, 0.5, 0.15)
409 peel1.rotation.y = -0.4
410 peel1.rotation.z = 0.3
411 group.add(peel1)
412
413 const peel2 = new THREE.Mesh(peelGeom, innerSkinMaterial)
414 peel2.position.set(-0.35, 0.6, 0.3)
415 peel2.rotation.y = 0.6
416 peel2.rotation.z = -0.2
417 group.add(peel2)
418
419 // Root tendrils at the bottom
420 for (let i = 0; i < 5; i++) {
421 const angle = (i / 5) * Math.PI * 2 + Math.random() * 0.3
422 const rootGeom = new THREE.CylinderGeometry(0.02, 0.01, 0.15 + Math.random() * 0.1, 4)
423 const root = new THREE.Mesh(rootGeom, rootMaterial)
424 root.position.set(
425 Math.cos(angle) * 0.15,
426 -0.02,
427 Math.sin(angle) * 0.15
428 )
429 root.rotation.x = (Math.random() - 0.5) * 0.4
430 root.rotation.z = (Math.random() - 0.5) * 0.4
431 group.add(root)
432 }
433
434 // Door - cute rounded top
435 const doorGroup = new THREE.Group()
436
437 // Door frame (arch)
438 const doorFrameGeom = new THREE.BoxGeometry(0.22, 0.35, 0.05)
439 const doorFrame = new THREE.Mesh(doorFrameGeom, doorMaterial)
440 doorFrame.position.y = 0.175
441 doorGroup.add(doorFrame)
442
443 // Door arch top
444 const archGeom = new THREE.SphereGeometry(0.11, 8, 4, 0, Math.PI * 2, 0, Math.PI / 2)
445 const arch = new THREE.Mesh(archGeom, doorMaterial)
446 arch.position.y = 0.35
447 arch.rotation.x = Math.PI
448 doorGroup.add(arch)
449
450 // Door knob
451 const knobGeom = new THREE.SphereGeometry(0.02, 6, 4)
452 const knobMaterial = new THREE.MeshToonMaterial({ color: 0xffd700, gradientMap })
453 const knob = new THREE.Mesh(knobGeom, knobMaterial)
454 knob.position.set(0.07, 0.2, 0.03)
455 doorGroup.add(knob)
456
457 doorGroup.position.set(0.48, 0.02, 0)
458 doorGroup.rotation.y = Math.PI / 2
459 group.add(doorGroup)
460
461 // Chimney - whimsically placed on the side/top
462 const chimneyGroup = new THREE.Group()
463
464 const chimneyBaseGeom = new THREE.CylinderGeometry(0.06, 0.07, 0.3, 6)
465 const chimneyBase = new THREE.Mesh(chimneyBaseGeom, chimneyMaterial)
466 chimneyBase.position.y = 0.15
467 chimneyGroup.add(chimneyBase)
468
469 // Chimney cap
470 const capGeom = new THREE.CylinderGeometry(0.08, 0.06, 0.04, 6)
471 const cap = new THREE.Mesh(capGeom, chimneyMaterial)
472 cap.position.y = 0.32
473 chimneyGroup.add(cap)
474
475 // Position chimney at a jaunty angle on the onion
476 chimneyGroup.position.set(-0.25, 0.75, 0.2)
477 chimneyGroup.rotation.z = 0.3 // Tilted for whimsy
478 chimneyGroup.rotation.x = -0.15
479 group.add(chimneyGroup)
480
481 // Smoke puffs - create several that will be animated
482 const smokeGroup = new THREE.Group()
483 smokeGroup.userData.isSmoke = true
484
485 const smokeMaterial = new THREE.MeshBasicMaterial({
486 color: 0xcccccc,
487 transparent: true,
488 opacity: 0.6
489 })
490
491 // Create 4 smoke puffs at different phases
492 for (let i = 0; i < 4; i++) {
493 const puffGeom = new THREE.SphereGeometry(0.04, 6, 4)
494 const puff = new THREE.Mesh(puffGeom, smokeMaterial.clone())
495 puff.userData.isSmokePuff = true
496 puff.userData.phase = i * 0.25 // Stagger the animation phases
497 puff.userData.baseY = 0
498 puff.position.set(
499 (Math.random() - 0.5) * 0.03,
500 0,
501 (Math.random() - 0.5) * 0.03
502 )
503 smokeGroup.add(puff)
504 }
505
506 // Position smoke at chimney top (in world space, accounting for chimney tilt)
507 // Chimney cap is at local y=0.32, chimney group at (-0.25, 0.75, 0.2)
508 smokeGroup.position.set(-0.35, 1.05, 0.15)
509 group.add(smokeGroup)
510
511 // Little window
512 const windowGeom = new THREE.CircleGeometry(0.08, 8)
513 const windowMaterial = new THREE.MeshBasicMaterial({
514 color: 0xffffcc,
515 transparent: true,
516 opacity: 0.7
517 })
518 const windowMesh = new THREE.Mesh(windowGeom, windowMaterial)
519 windowMesh.position.set(0.1, 0.55, 0.49)
520 group.add(windowMesh)
521
522 // Window frame
523 const windowFrameGeom = new THREE.TorusGeometry(0.08, 0.012, 4, 12)
524 const windowFrame = new THREE.Mesh(windowFrameGeom, doorMaterial)
525 windowFrame.position.set(0.1, 0.55, 0.485)
526 group.add(windowFrame)
527
528 return group
529 }
530
531 // Create a whimsical boot house with yard, sprites, and bendy chimney
532 export function createBootHouse(gradientMap) {
533 const group = new THREE.Group()
534
535 // Boot leather material - warm brown
536 const leatherMaterial = new THREE.MeshToonMaterial({
537 color: 0x8b4513,
538 gradientMap
539 })
540
541 // Darker leather for details
542 const darkLeatherMaterial = new THREE.MeshToonMaterial({
543 color: 0x5c3317,
544 gradientMap
545 })
546
547 // Sole material - darker rubber-like
548 const soleMaterial = new THREE.MeshToonMaterial({
549 color: 0x2d1f14,
550 gradientMap
551 })
552
553 // Lace/tongue material
554 const laceMaterial = new THREE.MeshToonMaterial({
555 color: 0xdaa520,
556 gradientMap
557 })
558
559 // Chimney brick
560 const brickMaterial = new THREE.MeshToonMaterial({
561 color: 0x8b4513,
562 gradientMap
563 })
564
565 // Window glow
566 const windowMaterial = new THREE.MeshBasicMaterial({
567 color: 0xffffcc,
568 transparent: true,
569 opacity: 0.8
570 })
571
572 // Grass material
573 const grassMaterial = new THREE.MeshToonMaterial({
574 color: 0x4a7c3f,
575 gradientMap
576 })
577
578 // Sprite body colors
579 const spriteColors = [0xff6b9d, 0x9b59b6, 0x3498db, 0x2ecc71]
580
581 // === BOOT STRUCTURE (Extruded 2D profile for smooth continuous shape) ===
582
583 // Create a boot profile as a 2D shape, then extrude it
584 // This creates ONE continuous mesh that looks like a real boot
585
586 const bootShape = new THREE.Shape()
587
588 // Boot profile (side view, starting from heel bottom, going clockwise)
589 // Scale: roughly 1 unit tall, 1.2 units long
590
591 // Start at heel bottom
592 bootShape.moveTo(0.45, 0)
593
594 // Sole - flat bottom with slight curve at toe
595 bootShape.lineTo(-0.35, 0)
596
597 // Toe curves up
598 bootShape.quadraticCurveTo(-0.55, 0, -0.55, 0.15)
599 bootShape.quadraticCurveTo(-0.55, 0.35, -0.4, 0.4)
600
601 // Vamp/instep - curves up toward ankle
602 bootShape.quadraticCurveTo(-0.15, 0.45, 0.05, 0.55)
603
604 // Front of ankle/shaft - rises up
605 bootShape.quadraticCurveTo(0.15, 0.65, 0.15, 0.95)
606
607 // Top opening - slight outward flare
608 bootShape.quadraticCurveTo(0.15, 1.05, 0.22, 1.08)
609
610 // Across the top opening
611 bootShape.lineTo(0.42, 1.08)
612
613 // Back of shaft curves down
614 bootShape.quadraticCurveTo(0.5, 1.05, 0.5, 0.95)
615 bootShape.quadraticCurveTo(0.5, 0.5, 0.48, 0.25)
616
617 // Heel curves to bottom
618 bootShape.quadraticCurveTo(0.48, 0.08, 0.45, 0)
619
620 // Extrude settings - depth gives the boot width, bevel rounds edges
621 const extrudeSettings = {
622 steps: 1,
623 depth: 0.45,
624 bevelEnabled: true,
625 bevelThickness: 0.08,
626 bevelSize: 0.06,
627 bevelOffset: 0,
628 bevelSegments: 4
629 }
630
631 const bootGeometry = new THREE.ExtrudeGeometry(bootShape, extrudeSettings)
632
633 // Center the boot (extrude goes in +Z, so offset by half depth)
634 bootGeometry.translate(0, 0, -0.225)
635
636 const bootMesh = new THREE.Mesh(bootGeometry, leatherMaterial)
637 group.add(bootMesh)
638
639 // === SOLE (darker strip along bottom) ===
640 const soleShape = new THREE.Shape()
641 soleShape.moveTo(0.45, 0)
642 soleShape.lineTo(-0.35, 0)
643 soleShape.quadraticCurveTo(-0.55, 0, -0.55, 0.08)
644 soleShape.lineTo(-0.5, 0.1)
645 soleShape.lineTo(0.45, 0.1)
646 soleShape.quadraticCurveTo(0.48, 0.08, 0.48, 0.05)
647 soleShape.lineTo(0.45, 0)
648
649 const soleExtrudeSettings = {
650 steps: 1,
651 depth: 0.48,
652 bevelEnabled: true,
653 bevelThickness: 0.03,
654 bevelSize: 0.02,
655 bevelSegments: 2
656 }
657
658 const soleGeometry = new THREE.ExtrudeGeometry(soleShape, soleExtrudeSettings)
659 soleGeometry.translate(0, 0, -0.24)
660 const soleMesh = new THREE.Mesh(soleGeometry, soleMaterial)
661 group.add(soleMesh)
662
663 // === HEEL TAB (back loop) ===
664 const heelTabGeom = new THREE.BoxGeometry(0.08, 0.12, 0.25)
665 const heelTab = new THREE.Mesh(heelTabGeom, darkLeatherMaterial)
666 heelTab.position.set(0.48, 1.0, 0)
667 group.add(heelTab)
668
669 // Heel tab loop
670 const heelLoopGeom = new THREE.TorusGeometry(0.04, 0.015, 6, 12, Math.PI)
671 const heelLoop = new THREE.Mesh(heelLoopGeom, darkLeatherMaterial)
672 heelLoop.position.set(0.52, 1.04, 0)
673 heelLoop.rotation.z = -Math.PI / 2
674 group.add(heelLoop)
675
676 // === TONGUE ===
677 const tongueShape = new THREE.Shape()
678 tongueShape.moveTo(-0.06, 0)
679 tongueShape.lineTo(-0.07, 0.25)
680 tongueShape.quadraticCurveTo(-0.07, 0.35, 0, 0.38)
681 tongueShape.quadraticCurveTo(0.07, 0.35, 0.07, 0.25)
682 tongueShape.lineTo(0.06, 0)
683 tongueShape.lineTo(-0.06, 0)
684
685 const tongueExtrudeSettings = {
686 steps: 1,
687 depth: 0.04,
688 bevelEnabled: true,
689 bevelThickness: 0.015,
690 bevelSize: 0.01,
691 bevelSegments: 2
692 }
693
694 const tongueGeometry = new THREE.ExtrudeGeometry(tongueShape, tongueExtrudeSettings)
695 tongueGeometry.translate(0, 0, -0.02)
696 const tongue = new THREE.Mesh(tongueGeometry, laceMaterial)
697 tongue.position.set(0.0, 0.55, 0.18)
698 tongue.rotation.x = 0.3
699 group.add(tongue)
700
701 // === LACING ===
702 const laceCordMaterial = new THREE.MeshToonMaterial({
703 color: 0xf5deb3,
704 gradientMap
705 })
706
707 // Lace eyelets
708 const eyeletGeom = new THREE.TorusGeometry(0.02, 0.006, 6, 10)
709 for (let i = 0; i < 4; i++) {
710 const y = 0.58 + i * 0.1
711 const x = 0.08 - i * 0.015
712
713 const eyeletL = new THREE.Mesh(eyeletGeom, darkLeatherMaterial)
714 eyeletL.position.set(x - 0.07, y, 0.2)
715 eyeletL.rotation.x = Math.PI / 2 - 0.3
716 group.add(eyeletL)
717
718 const eyeletR = new THREE.Mesh(eyeletGeom, darkLeatherMaterial)
719 eyeletR.position.set(x + 0.07, y, 0.2)
720 eyeletR.rotation.x = Math.PI / 2 - 0.3
721 group.add(eyeletR)
722 }
723
724 // Cross laces
725 for (let i = 0; i < 4; i++) {
726 const y = 0.58 + i * 0.1
727 const x = 0.08 - i * 0.015
728 const cordGeom = new THREE.CylinderGeometry(0.006, 0.006, 0.14, 4)
729 const cord = new THREE.Mesh(cordGeom, laceCordMaterial)
730 cord.position.set(x, y, 0.21)
731 cord.rotation.z = Math.PI / 2
732 group.add(cord)
733 }
734
735 // Bow loops
736 const bowLoopGeom = new THREE.TorusGeometry(0.035, 0.01, 6, 10, Math.PI)
737 const bowL = new THREE.Mesh(bowLoopGeom, laceCordMaterial)
738 bowL.position.set(-0.03, 0.95, 0.19)
739 bowL.rotation.y = Math.PI / 2
740 bowL.rotation.x = 0.4
741 group.add(bowL)
742
743 const bowR = new THREE.Mesh(bowLoopGeom, laceCordMaterial)
744 bowR.position.set(0.08, 0.95, 0.19)
745 bowR.rotation.y = -Math.PI / 2
746 bowR.rotation.x = 0.4
747 group.add(bowR)
748
749 // Bow tails
750 const tailGeom = new THREE.CylinderGeometry(0.008, 0.005, 0.1, 4)
751 const tailL = new THREE.Mesh(tailGeom, laceCordMaterial)
752 tailL.position.set(-0.04, 0.9, 0.2)
753 tailL.rotation.z = 0.5
754 group.add(tailL)
755
756 const tailR = new THREE.Mesh(tailGeom, laceCordMaterial)
757 tailR.position.set(0.09, 0.9, 0.2)
758 tailR.rotation.z = -0.5
759 group.add(tailR)
760
761 // === WINDOWS ===
762
763 // Round window on toe (front of boot)
764 const toeWindowGeom = new THREE.CircleGeometry(0.06, 12)
765 const toeWindow = new THREE.Mesh(toeWindowGeom, windowMaterial)
766 toeWindow.position.set(-0.48, 0.25, 0)
767 toeWindow.rotation.y = -Math.PI / 2
768 group.add(toeWindow)
769
770 const toeFrameGeom = new THREE.TorusGeometry(0.06, 0.01, 4, 14)
771 const toeFrame = new THREE.Mesh(toeFrameGeom, darkLeatherMaterial)
772 toeFrame.position.set(-0.47, 0.25, 0)
773 toeFrame.rotation.y = -Math.PI / 2
774 group.add(toeFrame)
775
776 // Side windows on the shaft
777 const sideWindowGeom = new THREE.CircleGeometry(0.05, 10)
778 const sideFrameGeom = new THREE.TorusGeometry(0.05, 0.008, 4, 12)
779
780 // Left side window
781 const windowL = new THREE.Mesh(sideWindowGeom, windowMaterial)
782 windowL.position.set(0.3, 0.75, -0.2)
783 windowL.rotation.y = Math.PI / 2
784 group.add(windowL)
785
786 const frameL = new THREE.Mesh(sideFrameGeom, darkLeatherMaterial)
787 frameL.position.set(0.29, 0.75, -0.2)
788 frameL.rotation.y = Math.PI / 2
789 group.add(frameL)
790
791 // Right side window
792 const windowR = new THREE.Mesh(sideWindowGeom, windowMaterial)
793 windowR.position.set(0.3, 0.75, 0.2)
794 windowR.rotation.y = -Math.PI / 2
795 group.add(windowR)
796
797 const frameR = new THREE.Mesh(sideFrameGeom, darkLeatherMaterial)
798 frameR.position.set(0.29, 0.75, 0.2)
799 frameR.rotation.y = -Math.PI / 2
800 group.add(frameR)
801
802 // === BENDY CHIMNEY ===
803
804 const chimneyGroup = new THREE.Group()
805 chimneyGroup.userData.isChimney = true
806
807 // Build a crooked/bendy chimney from segments
808 const segments = [
809 { y: 0, height: 0.15, radius: 0.06, tiltX: 0, tiltZ: 0.15 },
810 { y: 0.14, height: 0.12, radius: 0.055, tiltX: 0.1, tiltZ: -0.2 },
811 { y: 0.25, height: 0.12, radius: 0.05, tiltX: -0.15, tiltZ: 0.25 },
812 { y: 0.36, height: 0.1, radius: 0.045, tiltX: 0.05, tiltZ: -0.1 }
813 ]
814
815 let lastPos = new THREE.Vector3(0, 0, 0)
816 for (const seg of segments) {
817 const segGeom = new THREE.CylinderGeometry(seg.radius * 0.9, seg.radius, seg.height, 6)
818 const segMesh = new THREE.Mesh(segGeom, brickMaterial)
819 segMesh.position.copy(lastPos)
820 segMesh.position.y += seg.height / 2
821 segMesh.rotation.x = seg.tiltX
822 segMesh.rotation.z = seg.tiltZ
823 chimneyGroup.add(segMesh)
824
825 // Track where next segment starts (approximate offset from tilt)
826 lastPos.y += seg.height
827 lastPos.x += Math.sin(seg.tiltZ) * seg.height * 0.5
828 lastPos.z += Math.sin(seg.tiltX) * seg.height * 0.5
829 }
830
831 // Chimney cap
832 const capGeom = new THREE.CylinderGeometry(0.06, 0.04, 0.04, 6)
833 const cap = new THREE.Mesh(capGeom, darkLeatherMaterial)
834 cap.position.copy(lastPos)
835 cap.position.y += 0.02
836 chimneyGroup.add(cap)
837
838 // Smoke puffs
839 const smokeGroup = new THREE.Group()
840 const smokeMaterial = new THREE.MeshBasicMaterial({
841 color: 0xdddddd,
842 transparent: true,
843 opacity: 0.5
844 })
845
846 for (let i = 0; i < 4; i++) {
847 const puffGeom = new THREE.SphereGeometry(0.035, 6, 4)
848 const puff = new THREE.Mesh(puffGeom, smokeMaterial.clone())
849 puff.userData.isSmokePuff = true
850 puff.userData.phase = i * 0.25
851 puff.position.set(
852 lastPos.x + (Math.random() - 0.5) * 0.02,
853 lastPos.y + 0.05,
854 lastPos.z + (Math.random() - 0.5) * 0.02
855 )
856 smokeGroup.add(puff)
857 }
858 chimneyGroup.add(smokeGroup)
859
860 chimneyGroup.position.set(0.35, 1.08, 0)
861 group.add(chimneyGroup)
862
863 // === DOOR ===
864
865 const doorGroup = new THREE.Group()
866
867 // Arched door on the toe area
868 const doorGeom = new THREE.BoxGeometry(0.1, 0.18, 0.03)
869 const door = new THREE.Mesh(doorGeom, darkLeatherMaterial)
870 door.position.y = 0.09
871 doorGroup.add(door)
872
873 // Door arch
874 const doorArchGeom = new THREE.SphereGeometry(0.05, 8, 4, 0, Math.PI * 2, 0, Math.PI / 2)
875 const doorArch = new THREE.Mesh(doorArchGeom, darkLeatherMaterial)
876 doorArch.position.y = 0.18
877 doorArch.rotation.x = Math.PI
878 doorGroup.add(doorArch)
879
880 // Door knob
881 const knobGeom = new THREE.SphereGeometry(0.012, 6, 4)
882 const knobMat = new THREE.MeshToonMaterial({ color: 0xffd700, gradientMap })
883 const knob = new THREE.Mesh(knobGeom, knobMat)
884 knob.position.set(0.03, 0.08, 0.02)
885 doorGroup.add(knob)
886
887 // Position door on the side of the toe
888 doorGroup.position.set(-0.4, 0.1, 0.18)
889 doorGroup.rotation.y = -0.6
890 group.add(doorGroup)
891
892 // === YARD WITH TALL GRASS PATCHES ===
893
894 const yardGroup = new THREE.Group()
895 yardGroup.userData.isYard = true
896
897 // Create grass patches around the boot
898 const grassPositions = [
899 { x: -0.7, z: 0.4, count: 8 },
900 { x: -0.7, z: -0.4, count: 6 },
901 { x: 0.65, z: 0.4, count: 7 },
902 { x: 0.65, z: -0.4, count: 5 },
903 { x: -0.1, z: -0.55, count: 6 },
904 { x: -0.1, z: 0.55, count: 5 }
905 ]
906
907 for (const patch of grassPositions) {
908 for (let i = 0; i < patch.count; i++) {
909 const bladeHeight = 0.12 + Math.random() * 0.15
910 const bladeGeom = new THREE.ConeGeometry(0.015, bladeHeight, 4)
911 const blade = new THREE.Mesh(bladeGeom, grassMaterial)
912
913 const offsetX = (Math.random() - 0.5) * 0.2
914 const offsetZ = (Math.random() - 0.5) * 0.2
915
916 blade.position.set(
917 patch.x + offsetX,
918 bladeHeight / 2,
919 patch.z + offsetZ
920 )
921
922 // Random lean
923 blade.rotation.x = (Math.random() - 0.5) * 0.3
924 blade.rotation.z = (Math.random() - 0.5) * 0.3
925
926 blade.userData.isGrassBlade = true
927 blade.userData.phase = Math.random() * Math.PI * 2
928 blade.userData.baseRotX = blade.rotation.x
929 blade.userData.baseRotZ = blade.rotation.z
930
931 yardGroup.add(blade)
932 }
933 }
934
935 group.add(yardGroup)
936
937 // === TINY SPRITES ===
938
939 const spritesGroup = new THREE.Group()
940 spritesGroup.userData.isSpritesGroup = true
941
942 // Create 4 tiny sprites that will run around
943 for (let i = 0; i < 4; i++) {
944 const sprite = new THREE.Group()
945 sprite.userData.isBootSprite = true
946
947 // Sprite body (small sphere)
948 const bodyGeom = new THREE.SphereGeometry(0.04, 8, 6)
949 const bodyMat = new THREE.MeshToonMaterial({
950 color: spriteColors[i],
951 gradientMap
952 })
953 const body = new THREE.Mesh(bodyGeom, bodyMat)
954 body.position.y = 0.06
955 sprite.add(body)
956
957 // Tiny legs (2 little cylinders)
958 const legGeom = new THREE.CylinderGeometry(0.008, 0.01, 0.04, 4)
959 const legMat = new THREE.MeshToonMaterial({ color: 0x333333, gradientMap })
960
961 const legL = new THREE.Mesh(legGeom, legMat)
962 legL.position.set(-0.02, 0.02, 0)
963 legL.userData.isLeg = true
964 legL.userData.legSide = 'left'
965 sprite.add(legL)
966
967 const legR = new THREE.Mesh(legGeom, legMat)
968 legR.position.set(0.02, 0.02, 0)
969 legR.userData.isLeg = true
970 legR.userData.legSide = 'right'
971 sprite.add(legR)
972
973 // Little eyes (2 white dots)
974 const eyeGeom = new THREE.SphereGeometry(0.012, 6, 4)
975 const eyeMat = new THREE.MeshBasicMaterial({ color: 0xffffff })
976 const pupilGeom = new THREE.SphereGeometry(0.006, 4, 3)
977 const pupilMat = new THREE.MeshBasicMaterial({ color: 0x000000 })
978
979 const eyeL = new THREE.Mesh(eyeGeom, eyeMat)
980 eyeL.position.set(-0.015, 0.07, 0.03)
981 sprite.add(eyeL)
982
983 const pupilL = new THREE.Mesh(pupilGeom, pupilMat)
984 pupilL.position.set(-0.015, 0.07, 0.04)
985 sprite.add(pupilL)
986
987 const eyeR = new THREE.Mesh(eyeGeom, eyeMat)
988 eyeR.position.set(0.015, 0.07, 0.03)
989 sprite.add(eyeR)
990
991 const pupilR = new THREE.Mesh(pupilGeom, pupilMat)
992 pupilR.position.set(0.015, 0.07, 0.04)
993 sprite.add(pupilR)
994
995 // Animation data
996 sprite.userData.orbitRadius = 0.55 + Math.random() * 0.2
997 sprite.userData.orbitSpeed = 0.8 + Math.random() * 0.6
998 sprite.userData.orbitPhase = (i / 4) * Math.PI * 2
999 sprite.userData.bobPhase = Math.random() * Math.PI * 2
1000 sprite.userData.orbitCenterX = -0.05 // Center of boot footprint
1001 sprite.userData.orbitCenterZ = 0
1002
1003 // Initial position
1004 const angle = sprite.userData.orbitPhase
1005 sprite.position.set(
1006 sprite.userData.orbitCenterX + Math.cos(angle) * sprite.userData.orbitRadius,
1007 0,
1008 sprite.userData.orbitCenterZ + Math.sin(angle) * sprite.userData.orbitRadius
1009 )
1010
1011 spritesGroup.add(sprite)
1012 }
1013
1014 group.add(spritesGroup)
1015
1016 // Mark for building identification
1017 group.userData.isBootHouse = true
1018
1019 return group
1020 }
1021
1022 // Factory function to create building by type
1023 export function createBuilding(type, gradientMap) {
1024 switch (type) {
1025 case 'dock_wooden':
1026 return createDock(gradientMap)
1027 case 'fishing_hut':
1028 return createFishingHut(gradientMap)
1029 case 'lighthouse':
1030 return createLighthouse(gradientMap)
1031 case 'reeds':
1032 return createReeds(gradientMap)
1033 case 'fence':
1034 return createFence(gradientMap)
1035 case 'onion_house':
1036 return createOnionHouse(gradientMap)
1037 case 'boot_house':
1038 return createBootHouse(gradientMap)
1039 default:
1040 console.warn('Unknown building type:', type)
1041 return new THREE.Group()
1042 }
1043 }
1044
1045 // Create ghost (preview) version of a building
1046 export function createGhostBuilding(type, gradientMap, isValid) {
1047 const building = createBuilding(type, gradientMap)
1048
1049 // Make all materials transparent and tinted
1050 const color = isValid ? 0x44ff44 : 0xff4444
1051 const opacity = 0.5
1052
1053 building.traverse((child) => {
1054 if (child.isMesh) {
1055 child.material = new THREE.MeshBasicMaterial({
1056 color,
1057 transparent: true,
1058 opacity
1059 })
1060 }
1061 })
1062
1063 return building
1064 }