Files
Fishing/assets/rods/make_rod_basic.ps1
2026-11-06 12:34:01 +05:00

106 lines
4.3 KiB
PowerShell

param([string]$Out)
# Builds Rod_Basic.bbmodel. Units: Blockbench pixels (16 = 1 block). Rod runs along +Z.
# Colors: 1 = wood (yellow), 2 = rope (orange), 7 = brass (lime), 4 = reel, 3 = tip
$script:n = 0
$elements = New-Object System.Collections.ArrayList
function New-Id { $script:n++; return ('c0de0000-0000-4000-8000-{0:D12}' -f $script:n) }
function Cube($name, $from, $to, $color, $origin = $null) {
if (-not $origin) { $origin = @(0, 0, 0) }
$id = New-Id
$faces = [ordered]@{}
foreach ($f in 'north','east','south','west','up','down') { $faces[$f] = [ordered]@{ uv = @(0, 0, 1, 1) } }
[void]$elements.Add([ordered]@{
name = $name; type = 'cube'; uuid = $id; box_uv = $false; autouv = 0; color = $color
visibility = $true; export = $true; locked = $false; shade = $true; rescale = $false; inflate = 0
from = $from; to = $to; origin = $origin; rotation = @(0, 0, 0); faces = $faces
})
return $id
}
function BbGroup($name, $origin, $children, $rotation = $null) {
if (-not $rotation) { $rotation = @(0, 0, 0) }
return [ordered]@{
name = $name; origin = $origin; rotation = $rotation; color = 0; uuid = (New-Id)
export = $true; isOpen = $true; locked = $false; visibility = $true; autouv = 0
children = @($children)
}
}
# Line guide: small foot on top of the rod plus a square loop (2x2 outside, hole in the middle)
function Ring($name, $yTop, $z) {
$y0 = $yTop + 0.8; $z0 = $z - 0.25; $z1 = $z + 0.25
$ids = @(
(Cube "${name}_Foot" @(-0.4, $yTop, ($z - 0.4)) @(0.4, $y0, ($z + 0.4)) 7),
(Cube "${name}_Bottom" @(-1, $y0, $z0) @(1, ($y0 + 0.4), $z1) 7),
(Cube "${name}_Top" @(-1, ($y0 + 1.6), $z0) @(1, ($y0 + 2), $z1) 7),
(Cube "${name}_Left" @(-1, ($y0 + 0.4), $z0) @(-0.6, ($y0 + 1.6), $z1) 7),
(Cube "${name}_Right" @(0.6, ($y0 + 0.4), $z0) @(1, ($y0 + 1.6), $z1) 7)
)
return (BbGroup $name @(0, $y0, $z) $ids)
}
# --- Handle: wooden grip, rope wrap, brass bands, pommel
$handle = @(
(Cube 'Handle' @(-1.5, -1.5, 0) @(1.5, 1.5, 24) 1),
(Cube 'Pommel' @(-2, -2, -2) @(2, 2, 0) 7),
(Cube 'PommelKnob' @(-1, -1, -3) @(1, 1, -2) 7),
(Cube 'GripRope' @(-1.8, -1.8, 3) @(1.8, 1.8, 12) 2),
(Cube 'GripBand1' @(-2, -2, 2) @(2, 2, 3) 7),
(Cube 'GripBand2' @(-2, -2, 12) @(2, 2, 13) 7),
(Cube 'Ferrule0' @(-1.9, -1.9, 22) @(1.9, 1.9, 24.5) 7)
)
# --- Reel: bracket under the handle; Spool rotates around the X axis at (0,-5.5,16)
$axis = @(0, -5.5, 16)
$spool = BbGroup 'Spool' $axis @(
(Cube 'Drum' @(-1.5, -7, 14.5) @(1.5, -4, 17.5) 2),
(Cube 'PlateL' @(-2.5, -8, 13.5) @(-1.5, -3, 18.5) 4),
(Cube 'PlateR' @(1.5, -8, 13.5) @(2.5, -3, 18.5) 4),
(Cube 'Axle' @(-3, -6, 15.5) @(3, -5, 16.5) 7),
(Cube 'CrankArm' @(3, -9, 15.5) @(3.6, -5, 16.5) 7),
(Cube 'CrankKnob' @(3.6, -9.2, 15.3) @(5.2, -7.8, 16.7) 1)
)
$reel = BbGroup 'Reel' $axis @(
(Cube 'Reel_Bracket' @(-0.5, -3, 15) @(0.5, -1.5, 17) 7),
$spool
)
# --- Rod sections, nested so each one bends from the joint before it
$seg3 = BbGroup 'Seg3' @(0, 0, 82) @(
(Cube 'Section3' @(-0.5, -0.5, 82) @(0.5, 0.5, 110) 1),
(Ring 'Ring3' 0.5 97),
(Cube 'Tip' @(-0.5, -0.5, 110) @(0.5, 0.5, 111) 3)
) @(-5, 0, 0)
$seg2 = BbGroup 'Seg2' @(0, 0, 54) @(
(Cube 'Section2' @(-1, -1, 54) @(1, 1, 82) 1),
(Ring 'Ring2' 1 68),
(Cube 'Ferrule2' @(-1.3, -1.3, 80.5) @(1.3, 1.3, 82.5) 7),
$seg3
) @(-5, 0, 0)
$seg1 = BbGroup 'Seg1' @(0, 0, 24) @(
(Cube 'Section1' @(-1, -1, 24) @(1, 1, 54) 1),
(Ring 'Ring1' 1 40),
(Cube 'Ferrule1' @(-1.4, -1.4, 52.5) @(1.4, 1.4, 55) 7),
$seg2
)
$outliner = @($handle) + @($reel, $seg1)
$model = [ordered]@{
meta = [ordered]@{ format_version = '4.10'; model_format = 'free'; box_uv = $false }
name = 'Rod_Basic'; model_identifier = ''; visible_box = @(1, 1, 0)
variable_placeholders = ''; variable_placeholder_buttons = @(); timeline_setups = @(); unhandled_root_fields = @{}
resolution = [ordered]@{ width = 64; height = 64 }
elements = $elements
outliner = $outliner
textures = @()
}
$json = $model | ConvertTo-Json -Depth 30
[IO.File]::WriteAllText($Out, $json, (New-Object Text.UTF8Encoding $false))
"elements: $($elements.Count)"