{"TotalCount":290,"Files":[{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Analysis/AnimationClassifier.cs","FileName":"AnimationClassifier.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nnamespace WeaponImporter.EditorTools.Core.Analysis;\n\n/// \u003Csummary\u003E\n/// Maps animation names onto \u003Csee cref=\u0022AnimationRole\u0022/\u003Es using aliases common across game\n/// rigs and marketplace packs (\u003Cc\u003Eshoot\u003C/c\u003E, \u003Cc\u003Ereload_empty\u003C/c\u003E, \u003Cc\u003Edeploy\u003C/c\u003E, \u003Cc\u003Elookat\u003C/c\u003E,\n/// \u003Cc\u003Eads_fire\u003C/c\u003E, \u003Cc\u003Erechamber\u003C/c\u003E...). Scoring is token based so prefixes, numbering and\n/// casing do not matter.\n/// \u003C/summary\u003E\npublic static class AnimationClassifier\n{\n    private sealed record Rule(AnimationRole Role, string[] Any, string[]? Joined = null, string[]? Requires = null, string[]? Excludes = null, float Weight = 1f);\n\n    private static readonly string[] AimTokens = { \u0022ads\u0022, \u0022aim\u0022, \u0022aiming\u0022, \u0022iron\u0022, \u0022ironsight\u0022, \u0022ironsights\u0022, \u0022sight\u0022, \u0022sights\u0022, \u0022zoom\u0022, \u0022scope\u0022 };\n    private static readonly string[] AimLoopTokens = { \u0022idle\u0022, \u0022loop\u0022, \u0022hold\u0022, \u0022pose\u0022, \u0022static\u0022, \u0022aiming\u0022, \u0022breathing\u0022, \u0022breath\u0022 };\n    private static readonly string[] AimOutTokens = { \u0022out\u0022, \u0022exit\u0022, \u0022end\u0022, \u0022lower\u0022, \u0022leave\u0022, \u0022stop\u0022, \u0022release\u0022 };\n\n    // Order matters only for ties; more specific rules carry higher weights.\n    private static readonly Rule[] Rules =\n    {\n        new(AnimationRole.AdsFire, new[] { \u0022fire\u0022, \u0022shoot\u0022, \u0022shot\u0022, \u0022attack\u0022, \u0022firing\u0022 }, new[] { \u0022adsfire\u0022, \u0022aimfire\u0022, \u0022ironfire\u0022, \u0022firead\u0022, \u0022fireaim\u0022, \u0022fireiron\u0022, \u0022sightfire\u0022, \u0022scopefire\u0022 }, Requires: new[] { \u0022ads\u0022, \u0022aim\u0022, \u0022iron\u0022, \u0022ironsight\u0022, \u0022ironsights\u0022, \u0022sight\u0022, \u0022scope\u0022, \u0022zoom\u0022 }, Weight: 1.35f),\n        new(AnimationRole.FireEmpty, new[] { \u0022fire\u0022, \u0022shoot\u0022, \u0022shot\u0022, \u0022attack\u0022, \u0022dry\u0022, \u0022dryfire\u0022 }, new[] { \u0022fireempty\u0022, \u0022firelast\u0022, \u0022shootempty\u0022, \u0022shootlast\u0022, \u0022dryfire\u0022, \u0022lastshot\u0022, \u0022emptyfire\u0022 }, Requires: new[] { \u0022empty\u0022, \u0022last\u0022, \u0022dry\u0022, \u0022final\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Fire, new[] { \u0022fire\u0022, \u0022shoot\u0022, \u0022shot\u0022, \u0022attack\u0022, \u0022firing\u0022, \u0022recoil\u0022, \u0022primary\u0022, \u0022burst\u0022, \u0022auto\u0022, \u0022semi\u0022 }, Excludes: new[] { \u0022reload\u0022, \u0022select\u0022, \u0022mode\u0022, \u0022switch\u0022 }),\n\n        new(AnimationRole.EmptyReload, new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022 }, new[] { \u0022reloadempty\u0022, \u0022emptyreload\u0022, \u0022reloadlong\u0022, \u0022reloaddry\u0022, \u0022reloadfull\u0022 }, Requires: new[] { \u0022empty\u0022, \u0022dry\u0022, \u0022long\u0022, \u0022full\u0022, \u0022outofammo\u0022 }, Weight: 1.3f),\n        new(AnimationRole.TacticalReload, new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022 }, new[] { \u0022reloadtac\u0022, \u0022tacreload\u0022, \u0022reloadtactical\u0022, \u0022tacticalreload\u0022, \u0022reloadshort\u0022, \u0022reloadpartial\u0022 }, Requires: new[] { \u0022tac\u0022, \u0022tactical\u0022, \u0022short\u0022, \u0022partial\u0022, \u0022fast\u0022, \u0022speed\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Reload, new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022, \u0022magswap\u0022, \u0022magchange\u0022 }, Excludes: new[] { \u0022start\u0022, \u0022end\u0022, \u0022loop\u0022, \u0022insert\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022finish\u0022, \u0022exit\u0022, \u0022shell\u0022, \u0022single\u0022 }),\n        // Shell-by-shell reloads (shotguns, tube-fed rifles): start / one shell / end.\n        new(AnimationRole.ReloadStart, new[] { \u0022start\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022open\u0022, \u0022in\u0022, \u0022intro\u0022 }, new[] { \u0022reloadstart\u0022, \u0022startreload\u0022, \u0022reloadbegin\u0022, \u0022reloadenter\u0022, \u0022reloadopen\u0022, \u0022reloadintro\u0022, \u0022idletoreload\u0022, \u0022toreload\u0022 }, Requires: new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022, \u0022load\u0022, \u0022loading\u0022 }, Excludes: new[] { \u0022fire\u0022, \u0022shoot\u0022 }, Weight: 1.3f),\n        new(AnimationRole.ReloadInsert, new[] { \u0022insert\u0022, \u0022loop\u0022, \u0022shell\u0022, \u0022single\u0022, \u0022load\u0022, \u0022inserting\u0022, \u0022step\u0022 }, new[] { \u0022reloadinsert\u0022, \u0022reloadstep\u0022, \u0022insertshell\u0022, \u0022shellinsert\u0022, \u0022reloadloop\u0022, \u0022loadshell\u0022, \u0022shellload\u0022, \u0022reloadshell\u0022, \u0022reloadsingle\u0022, \u0022insertround\u0022, \u0022loadround\u0022 }, Requires: new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022, \u0022insert\u0022, \u0022shell\u0022, \u0022round\u0022, \u0022load\u0022 }, Excludes: new[] { \u0022start\u0022, \u0022begin\u0022, \u0022end\u0022, \u0022finish\u0022, \u0022exit\u0022, \u0022fire\u0022, \u0022shoot\u0022 }, Weight: 1.3f),\n        new(AnimationRole.ReloadEnd, new[] { \u0022end\u0022, \u0022finish\u0022, \u0022exit\u0022, \u0022close\u0022, \u0022out\u0022, \u0022outro\u0022, \u0022stop\u0022 }, new[] { \u0022reloadend\u0022, \u0022endreload\u0022, \u0022reloadfinish\u0022, \u0022reloadexit\u0022, \u0022reloadclose\u0022, \u0022reloadoutro\u0022, \u0022reloadtoidle\u0022, \u0022reloadto\u0022 }, Requires: new[] { \u0022reload\u0022, \u0022rld\u0022, \u0022reloading\u0022, \u0022load\u0022, \u0022loading\u0022 }, Excludes: new[] { \u0022fire\u0022, \u0022shoot\u0022 }, Weight: 1.3f),\n\n        new(AnimationRole.Unjam, new[] { \u0022unjam\u0022, \u0022clear\u0022, \u0022clearjam\u0022, \u0022fixjam\u0022, \u0022malfunctionclear\u0022, \u0022tapack\u0022, \u0022remedy\u0022 }, new[] { \u0022unjam\u0022, \u0022clearjam\u0022, \u0022fixjam\u0022, \u0022jamclear\u0022, \u0022jamfix\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Jam, new[] { \u0022jam\u0022, \u0022jammed\u0022, \u0022malfunction\u0022, \u0022misfire\u0022, \u0022stovepipe\u0022 }, Excludes: new[] { \u0022clear\u0022, \u0022fix\u0022, \u0022un\u0022 }),\n        new(AnimationRole.Bolt, new[] { \u0022bolt\u0022, \u0022rechamber\u0022, \u0022chamber\u0022, \u0022pump\u0022, \u0022charge\u0022, \u0022charging\u0022, \u0022cock\u0022, \u0022cocking\u0022, \u0022rack\u0022, \u0022cycle\u0022, \u0022lever\u0022, \u0022slide\u0022 }, Excludes: new[] { \u0022reload\u0022, \u0022fire\u0022, \u0022shoot\u0022, \u0022idle\u0022 }),\n\n        new(AnimationRole.Draw, new[] { \u0022draw\u0022, \u0022deploy\u0022, \u0022equip\u0022, \u0022pullout\u0022, \u0022raise\u0022, \u0022unholster\u0022, \u0022takeout\u0022, \u0022ready\u0022, \u0022select\u0022, \u0022pickup\u0022 }, new[] { \u0022firstdraw\u0022, \u0022drawfirst\u0022, \u0022pullout\u0022, \u0022takeout\u0022 }, Excludes: new[] { \u0022reload\u0022 }),\n        new(AnimationRole.Holster, new[] { \u0022holster\u0022, \u0022putaway\u0022, \u0022unequip\u0022, \u0022lower\u0022, \u0022stow\u0022, \u0022putdown\u0022, \u0022deselect\u0022, \u0022hide\u0022 }, new[] { \u0022putaway\u0022, \u0022putdown\u0022 }, Excludes: new[] { \u0022unholster\u0022 }),\n        new(AnimationRole.Inspect, new[] { \u0022inspect\u0022, \u0022lookat\u0022, \u0022examine\u0022, \u0022check\u0022, \u0022fidget\u0022, \u0022admire\u0022, \u0022showoff\u0022, \u0022look\u0022 }, new[] { \u0022lookat\u0022, \u0022checkmag\u0022, \u0022magcheck\u0022, \u0022showoff\u0022 }),\n\n        new(AnimationRole.Sprint, new[] { \u0022sprint\u0022, \u0022run\u0022, \u0022running\u0022, \u0022dash\u0022 }),\n        new(AnimationRole.Walk, new[] { \u0022walk\u0022, \u0022walking\u0022, \u0022move\u0022, \u0022moving\u0022, \u0022jog\u0022, \u0022strafe\u0022, \u0022bob\u0022 }),\n        // Aiming, any naming style: raising the sights (\u0022Aim_In\u0022, \u0022ADS\u0022, \u0022IronIn\u0022, \u0022Zoom_Enter\u0022),\n        // the held loop (\u0022Aim_Idle\u0022, \u0022ADS_Loop\u0022), lowering them (\u0022Aim_Out\u0022, \u0022ADS_Exit\u0022, \u0022Unaim\u0022).\n        new(AnimationRole.Ads, AimTokens.Concat(new[] { \u0022adsin\u0022, \u0022aimin\u0022 }).ToArray(), new[] { \u0022aimin\u0022, \u0022adsin\u0022, \u0022ironin\u0022, \u0022zoomin\u0022, \u0022sightin\u0022, \u0022scopein\u0022, \u0022aimenter\u0022, \u0022adsenter\u0022, \u0022aimstart\u0022, \u0022adsstart\u0022 }, Excludes: AimOutTokens.Concat(AimLoopTokens).Concat(new[] { \u0022fire\u0022, \u0022shoot\u0022, \u0022unaim\u0022, \u0022unads\u0022 }).ToArray()),\n        new(AnimationRole.AdsIdle, AimLoopTokens, new[] { \u0022aimidle\u0022, \u0022adsidle\u0022, \u0022aimloop\u0022, \u0022adsloop\u0022, \u0022ironidle\u0022, \u0022zoomidle\u0022, \u0022aimhold\u0022, \u0022adshold\u0022, \u0022aimingidle\u0022 }, Requires: AimTokens, Excludes: AimOutTokens.Concat(new[] { \u0022fire\u0022, \u0022shoot\u0022 }).ToArray(), Weight: 1.3f),\n        new(AnimationRole.AdsOut, AimOutTokens.Concat(new[] { \u0022unaim\u0022, \u0022unads\u0022, \u0022adsout\u0022, \u0022aimout\u0022 }).ToArray(), new[] { \u0022aimout\u0022, \u0022adsout\u0022, \u0022ironout\u0022, \u0022zoomout\u0022, \u0022sightout\u0022, \u0022scopeout\u0022, \u0022unaim\u0022, \u0022unads\u0022, \u0022aimexit\u0022, \u0022adsexit\u0022, \u0022aimend\u0022, \u0022adsend\u0022 }, Requires: AimTokens.Concat(new[] { \u0022unaim\u0022, \u0022unads\u0022, \u0022adsout\u0022, \u0022aimout\u0022 }).ToArray(), Excludes: new[] { \u0022fire\u0022, \u0022shoot\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Melee, new[] { \u0022melee\u0022, \u0022bash\u0022, \u0022stab\u0022, \u0022slash\u0022, \u0022swing\u0022, \u0022hit\u0022, \u0022knife\u0022, \u0022punch\u0022, \u0022butt\u0022, \u0022strike\u0022, \u0022attackmelee\u0022, \u0022jab\u0022, \u0022hook\u0022, \u0022uppercut\u0022, \u0022chop\u0022, \u0022thrust\u0022 }, new[] { \u0022meleeattack\u0022 }, Excludes: new[] { \u0022heavy\u0022, \u0022strong\u0022, \u0022power\u0022, \u0022charged\u0022, \u0022secondary\u0022, \u0022alt\u0022, \u0022get\u0022, \u0022react\u0022, \u0022reaction\u0022, \u0022damage\u0022, \u0022hurt\u0022, \u0022gethit\u0022, \u0022hitreact\u0022 }, Weight: 1.1f),\n        new(AnimationRole.Attack2, new[] { \u0022heavy\u0022, \u0022strong\u0022, \u0022power\u0022, \u0022charged\u0022, \u0022secondary\u0022, \u0022alt\u0022, \u0022attack2\u0022, \u0022special\u0022 }, new[] { \u0022heavyattack\u0022, \u0022attackheavy\u0022, \u0022secondaryattack\u0022, \u0022attacksecondary\u0022, \u0022attack2\u0022, \u0022altattack\u0022, \u0022attackalt\u0022, \u0022powerattack\u0022, \u0022chargedattack\u0022, \u0022strongattack\u0022, \u0022heavyslash\u0022, \u0022heavyswing\u0022 }, Requires: new[] { \u0022attack\u0022, \u0022slash\u0022, \u0022swing\u0022, \u0022stab\u0022, \u0022hit\u0022, \u0022strike\u0022, \u0022punch\u0022, \u0022melee\u0022, \u0022chop\u0022, \u0022attack2\u0022 }, Weight: 1.3f),\n        // Guarding: raise / hold / lower.\n        new(AnimationRole.BlockStart, new[] { \u0022start\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022in\u0022, \u0022raise\u0022, \u0022up\u0022 }, new[] { \u0022blockstart\u0022, \u0022startblock\u0022, \u0022blockin\u0022, \u0022blockbegin\u0022, \u0022parrystart\u0022, \u0022guardstart\u0022, \u0022guardup\u0022, \u0022blockenter\u0022 }, Requires: new[] { \u0022block\u0022, \u0022parry\u0022, \u0022guard\u0022, \u0022defend\u0022, \u0022defense\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Block, new[] { \u0022block\u0022, \u0022parry\u0022, \u0022guard\u0022, \u0022defend\u0022, \u0022defense\u0022, \u0022blocking\u0022 }, new[] { \u0022blockloop\u0022, \u0022blockidle\u0022, \u0022blockhold\u0022, \u0022parryloop\u0022, \u0022guardloop\u0022, \u0022guardidle\u0022 }, Excludes: new[] { \u0022start\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022end\u0022, \u0022stop\u0022, \u0022exit\u0022, \u0022out\u0022 }),\n        new(AnimationRole.BlockEnd, new[] { \u0022end\u0022, \u0022stop\u0022, \u0022exit\u0022, \u0022out\u0022, \u0022lower\u0022, \u0022down\u0022, \u0022release\u0022 }, new[] { \u0022blockend\u0022, \u0022blockstop\u0022, \u0022endblock\u0022, \u0022blockout\u0022, \u0022blockexit\u0022, \u0022parryend\u0022, \u0022guardend\u0022, \u0022guarddown\u0022 }, Requires: new[] { \u0022block\u0022, \u0022parry\u0022, \u0022guard\u0022, \u0022defend\u0022, \u0022defense\u0022 }, Weight: 1.3f),\n        // Items: use once, or start / hold / finish a use.\n        new(AnimationRole.Use, new[] { \u0022use\u0022, \u0022drink\u0022, \u0022eat\u0022, \u0022inject\u0022, \u0022heal\u0022, \u0022consume\u0022, \u0022apply\u0022, \u0022bandage\u0022, \u0022smoke\u0022, \u0022injection\u0022, \u0022healing\u0022, \u0022sip\u0022, \u0022gulp\u0022, \u0022swallow\u0022, \u0022spray\u0022, \u0022activate\u0022, \u0022press\u0022, \u0022toggle\u0022 }, new[] { \u0022useitem\u0022, \u0022itemuse\u0022 }, Excludes: new[] { \u0022start\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022loop\u0022, \u0022hold\u0022, \u0022end\u0022, \u0022stop\u0022, \u0022exit\u0022, \u0022finish\u0022, \u0022takeout\u0022, \u0022out\u0022 }),\n        new(AnimationRole.UseStart, new[] { \u0022start\u0022, \u0022begin\u0022, \u0022enter\u0022, \u0022in\u0022, \u0022raise\u0022, \u0022up\u0022, \u0022open\u0022 }, new[] { \u0022usestart\u0022, \u0022startuse\u0022, \u0022drinkstart\u0022, \u0022eatstart\u0022, \u0022takestart\u0022, \u0022healstart\u0022, \u0022injectstart\u0022 }, Requires: new[] { \u0022use\u0022, \u0022drink\u0022, \u0022eat\u0022, \u0022inject\u0022, \u0022heal\u0022, \u0022consume\u0022, \u0022take\u0022, \u0022apply\u0022, \u0022bandage\u0022, \u0022smoke\u0022 }, Weight: 1.3f),\n        new(AnimationRole.UseLoop, new[] { \u0022loop\u0022, \u0022hold\u0022, \u0022idle\u0022, \u0022holding\u0022, \u0022continue\u0022 }, new[] { \u0022useloop\u0022, \u0022drinkloop\u0022, \u0022eatloop\u0022, \u0022takeloop\u0022, \u0022healloop\u0022, \u0022usehold\u0022 }, Requires: new[] { \u0022use\u0022, \u0022drink\u0022, \u0022eat\u0022, \u0022inject\u0022, \u0022heal\u0022, \u0022consume\u0022, \u0022take\u0022, \u0022apply\u0022, \u0022bandage\u0022, \u0022smoke\u0022 }, Weight: 1.3f),\n        new(AnimationRole.UseEnd, new[] { \u0022end\u0022, \u0022stop\u0022, \u0022exit\u0022, \u0022finish\u0022, \u0022out\u0022, \u0022lower\u0022, \u0022down\u0022, \u0022close\u0022 }, new[] { \u0022useend\u0022, \u0022usestop\u0022, \u0022drinkend\u0022, \u0022eatend\u0022, \u0022takestop\u0022, \u0022takeend\u0022, \u0022healend\u0022, \u0022injectend\u0022 }, Requires: new[] { \u0022use\u0022, \u0022drink\u0022, \u0022eat\u0022, \u0022inject\u0022, \u0022heal\u0022, \u0022consume\u0022, \u0022take\u0022, \u0022apply\u0022, \u0022bandage\u0022, \u0022smoke\u0022 }, Weight: 1.3f),\n        new(AnimationRole.Throw, new[] { \u0022throw\u0022, \u0022toss\u0022, \u0022lob\u0022, \u0022pitch\u0022, \u0022hurl\u0022 }, new[] { \u0022throwgrenade\u0022, \u0022grenadethrow\u0022 }, Weight: 1.2f),\n        new(AnimationRole.Idle, new[] { \u0022idle\u0022, \u0022rest\u0022, \u0022hold\u0022, \u0022static\u0022, \u0022pose\u0022, \u0022bind\u0022, \u0022stand\u0022, \u0022base\u0022, \u0022breathing\u0022, \u0022breath\u0022, \u0022breathe\u0022 }, new[] { \u0022breathing\u0022, \u0022idleloop\u0022 }, Excludes: new[] { \u0022to\u0022, \u0022fire\u0022, \u0022reload\u0022 }, Weight: 0.9f),\n    };\n\n    private static readonly string[] FirstPersonTokens = { \u0022fp\u0022, \u00221p\u0022, \u0022vm\u0022, \u0022v\u0022, \u0022view\u0022, \u0022viewmodel\u0022, \u0022arms\u0022, \u0022firstperson\u0022, \u0022fps\u0022 };\n    private static readonly string[] ThirdPersonTokens = { \u0022tp\u0022, \u00223p\u0022, \u0022wm\u0022, \u0022w\u0022, \u0022world\u0022, \u0022worldmodel\u0022, \u0022thirdperson\u0022, \u0022tps\u0022, \u0022body\u0022, \u0022player\u0022, \u0022citizen\u0022 };\n\n    /// \u003Csummary\u003EClassifies one animation name.\u003C/summary\u003E\n    public static AnimationGuess Classify(string name, AnimationMotionHint? motion = null)\n    {\n        var tokens = NameTokens.Split(name);\n        var joined = NameTokens.Joined(tokens);\n        var perspective = NameTokens.Has(tokens, ThirdPersonTokens) ? AnimationPerspective.ThirdPerson\n            : NameTokens.Has(tokens, FirstPersonTokens) ? AnimationPerspective.FirstPerson\n            : AnimationPerspective.Any;\n\n        AnimationRole best = AnimationRole.Unknown;\n        float bestScore = 0f;\n        string reason = \u0022no matching name\u0022;\n\n        foreach (var rule in Rules)\n        {\n            var score = 0f;\n            string why = \u0022\u0022;\n            if (rule.Joined is { } joinedAliases \u0026\u0026 joinedAliases.Any(j =\u003E joined.Contains(j, StringComparison.Ordinal)))\n            {\n                score = 1f;\n                why = $\u0022name contains \u0027{joinedAliases.First(j =\u003E joined.Contains(j, StringComparison.Ordinal))}\u0027\u0022;\n            }\n            else if (NameTokens.Has(tokens, rule.Any))\n            {\n                if (rule.Requires is { } req \u0026\u0026 !NameTokens.Has(tokens, req))\n                    continue;\n                score = rule.Requires is null ? 0.8f : 0.95f;\n                why = $\u0022\u0027{tokens.First(t =\u003E rule.Any.Any(a =\u003E t == a || (a.Length \u003E= 4 \u0026\u0026 t.StartsWith(a, StringComparison.Ordinal))))}\u0027 in name\u0022;\n            }\n            else\n            {\n                continue;\n            }\n\n            if (rule.Excludes is { } ex \u0026\u0026 NameTokens.Has(tokens, ex))\n                score *= 0.45f;\n            // The role\u0027s own word (\u0022Idle\u0022) beats a synonym (\u0022Hold\u0022) on a tie.\n            if (tokens.Contains(rule.Any[0]))\n                score \u002B= 0.02f;\n            score *= rule.Weight;\n\n            if (score \u003E bestScore)\n            {\n                bestScore = score;\n                best = rule.Role;\n                reason = why;\n            }\n        }\n\n        // Motion evidence breaks ties and rescues meaningless names (\u0022anim_03\u0022).\n        if (motion is { } m)\n        {\n            var (role, conf, why) = FromMotion(m);\n            if (best == AnimationRole.Unknown \u0026\u0026 role != AnimationRole.Unknown)\n            {\n                best = role;\n                bestScore = conf;\n                reason = why;\n            }\n            else if (role == best \u0026\u0026 role != AnimationRole.Unknown)\n            {\n                bestScore = MathF.Min(1f, bestScore \u002B 0.1f);\n            }\n        }\n\n        return new AnimationGuess(name, best, MathF.Min(1f, bestScore), reason) { Perspective = perspective };\n    }\n\n    /// \u003Csummary\u003E\n    /// Classifies a set of animations and resolves duplicates: each role goes to the clip with\n    /// the highest confidence, preferring shorter base names (\u0022reload\u0022 over \u0022reload_02\u0022).\n    /// \u003C/summary\u003E\n    public static IReadOnlyDictionary\u003CAnimationRole, AnimationGuess\u003E Assign(IEnumerable\u003CAnimationGuess\u003E guesses, AnimationPerspective prefer = AnimationPerspective.Any)\n    {\n        var result = new Dictionary\u003CAnimationRole, AnimationGuess\u003E();\n        foreach (var group in guesses.Where(g =\u003E g.Role != AnimationRole.Unknown).GroupBy(g =\u003E g.Role))\n        {\n            var pick = group\n                .OrderByDescending(g =\u003E g.Confidence \u002B (prefer != AnimationPerspective.Any \u0026\u0026 g.Perspective == prefer ? 0.15f : 0f) - (prefer != AnimationPerspective.Any \u0026\u0026 g.Perspective != AnimationPerspective.Any \u0026\u0026 g.Perspective != prefer ? 0.3f : 0f))\n                .ThenBy(g =\u003E g.Animation.Count(char.IsDigit))\n                .ThenBy(g =\u003E g.Animation.Length)\n                .First();\n            result[group.Key] = pick;\n        }\n\n        // A lone \u0022reload\u0022 that is actually the empty one leaves Reload itself free: promote.\n        if (!result.ContainsKey(AnimationRole.Reload))\n        {\n            if (result.TryGetValue(AnimationRole.TacticalReload, out var tac))\n                result[AnimationRole.Reload] = tac with { Role = AnimationRole.Reload, Confidence = tac.Confidence * 0.9f, Reason = \u0022tactical reload used as reload\u0022 };\n            else if (result.TryGetValue(AnimationRole.EmptyReload, out var empty))\n                result[AnimationRole.Reload] = empty with { Role = AnimationRole.Reload, Confidence = empty.Confidence * 0.85f, Reason = \u0022empty reload used as reload\u0022 };\n        }\n        // \u0022IdleToReload\u0022 / \u0022Reload\u0022 / \u0022ReloadToIdle\u0022: between a start and an end, the plain\n        // reload is the one-shell part.\n        if (result.ContainsKey(AnimationRole.ReloadStart) \u0026\u0026 result.ContainsKey(AnimationRole.ReloadEnd)\n            \u0026\u0026 !result.ContainsKey(AnimationRole.ReloadInsert) \u0026\u0026 result.TryGetValue(AnimationRole.Reload, out var middle))\n        {\n            result[AnimationRole.ReloadInsert] = middle with { Role = AnimationRole.ReloadInsert, Reason = \u0022reload between a reload start and end\u0022 };\n            result.Remove(AnimationRole.Reload);\n        }\n        if (!result.ContainsKey(AnimationRole.Fire) \u0026\u0026 result.TryGetValue(AnimationRole.AdsFire, out var adsFire))\n            result[AnimationRole.Fire] = adsFire with { Role = AnimationRole.Fire, Confidence = adsFire.Confidence * 0.8f, Reason = \u0022ADS fire used as fire\u0022 };\n        return result;\n    }\n\n    private static (AnimationRole, float, string) FromMotion(AnimationMotionHint m)\n    {\n        if (m.MagazineTravel \u003E 2f \u0026\u0026 m.Duration \u003E 1f)\n            return (AnimationRole.Reload, 0.6f, \u0022magazine leaves the weapon\u0022);\n        if (m.BoltTravel \u003E 0.3f \u0026\u0026 m.Duration \u003C 0.6f)\n            return (AnimationRole.Fire, 0.55f, \u0022short clip with slide/bolt cycling\u0022);\n        if (m.BoltTravel \u003E 0.3f \u0026\u0026 m.Duration \u003E= 0.6f)\n            return (AnimationRole.Bolt, 0.5f, \u0022bolt cycles without magazine change\u0022);\n        if (m.RootTravel \u003C 0.05f \u0026\u0026 m.Duration \u003E 0.5f \u0026\u0026 m.MaxBoneMotion \u003C 0.1f)\n            return (AnimationRole.Idle, 0.5f, \u0022almost no motion\u0022);\n        return (AnimationRole.Unknown, 0f, \u0022motion inconclusive\u0022);\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Analysis/AnimationGuess.cs","FileName":"AnimationGuess.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nnamespace WeaponImporter.EditorTools.Core.Analysis;\n\n/// \u003Csummary\u003EA guess at an animation\u0027s role, with how sure the classifier is.\u003C/summary\u003E\npublic sealed record AnimationGuess(string Animation, AnimationRole Role, float Confidence, string Reason)\n{\n    /// \u003Csummary\u003EFirst-person (view model) or third-person (world / body) clip, when the name says so.\u003C/summary\u003E\n    public AnimationPerspective Perspective { get; init; }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Formats/Fbx/FbxAnimStack.cs","FileName":"FbxAnimStack.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System;\nusing System.Collections.Generic;\nusing System.Numerics;\n\nnamespace WeaponImporter.EditorTools.Core.Formats.Fbx;\n\nusing Vector3 = System.Numerics.Vector3; // s\u0026box compat: shadow engine\u0027s global-namespace Vector3 (see Editor/Core/Assembly.cs)\n\n/// \u003Csummary\u003EOne AnimationStack with its curve bindings, flattened across its layers.\u003C/summary\u003E\npublic sealed class FbxAnimStack\n{\n    /// \u003Csummary\u003EThe stack object (its Name is the clip name, e.g. \u0022mixamo.com\u0022).\u003C/summary\u003E\n    public FbxObject Object { get; }\n\n    /// \u003Csummary\u003E\n    /// Curve nodes bound to model transform properties:\n    /// (model id, property name) \u2192 curve node. When several layers animate the same property\n    /// the first connected layer wins (layer blending is not supported).\n    /// \u003C/summary\u003E\n    public Dictionary\u003C(long ModelId, string Property), FbxAnimCurveNode\u003E Bindings { get; } = new();\n\n    /// \u003Csummary\u003ELocalStart from the stack\u0027s Properties70, in KTIME ticks (0 when absent).\u003C/summary\u003E\n    public long LocalStart { get; internal set; }\n\n    /// \u003Csummary\u003ELocalStop from the stack\u0027s Properties70, in KTIME ticks (0 when absent).\u003C/summary\u003E\n    public long LocalStop { get; internal set; }\n\n    internal FbxAnimStack(FbxObject obj) =\u003E Object = obj;\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Formats/Fbx/FbxLegacy.cs","FileName":"FbxLegacy.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nnamespace WeaponImporter.EditorTools.Core.Formats.Fbx;\n\n/// \u003Csummary\u003E\n/// Upgrades an FBX 6.x document (FBX 2006-2010, e.g. Blender 2.7x\u0027s exporter) to the FBX 7\n/// layout the rest of the importer reads. FBX 6 links objects by name (\u0022Model::bone\u0022) instead\n/// of ids, keeps each mesh inside its model, writes properties as \u003Cc\u003EProperty\u003C/c\u003E entries in a\n/// \u003Cc\u003EProperties60\u003C/c\u003E block, and stores animation as \u003Cc\u003ETakes\u003C/c\u003E with per-channel key lists.\n/// The upgrade gives every object an id, moves mesh data into a Geometry object, rewrites\n/// properties as \u003Cc\u003EP\u003C/c\u003E entries and turns each take into an AnimationStack with a layer,\n/// curve nodes and curves, wired with the same connections an FBX 7 file has.\n/// \u003C/summary\u003E\npublic static class FbxLegacy\n{\n    /// \u003Csummary\u003EFBX version the document declares (FBXHeaderExtension/FBXVersion), 0 when absent.\u003C/summary\u003E\n    public static int Version(FbxNode root)\n    {\n        var v = root.Child(\u0022FBXHeaderExtension\u0022)?.Child(\u0022FBXVersion\u0022);\n        if (v is null || v.Properties.Count == 0)\n            return 0;\n        try\n        {\n            return v.Prop\u003Cint\u003E(0);\n        }\n        catch (FormatException)\n        {\n            return 0;\n        }\n    }\n\n    public static bool IsLegacy(FbxNode root) =\u003E Version(root) is \u003E 0 and \u003C 7000;\n\n    /// \u003Csummary\u003EThe document in FBX 7 layout (a new tree; \u003Cparamref name=\u0022root\u0022/\u003E is not changed).\u003C/summary\u003E\n    public static FbxNode Upgrade(FbxNode root)\n    {\n        var objects6 = root.Child(\u0022Objects\u0022) ?? new FbxNode(\u0022Objects\u0022);\n        var result = new FbxNode(\u0022(root)\u0022);\n        foreach (var header in root.Children.Where(c =\u003E c.Name is \u0022FBXHeaderExtension\u0022 or \u0022Creator\u0022 or \u0022CreationTime\u0022))\n            result.Children.Add(header);\n\n        var objects = new FbxNode(\u0022Objects\u0022);\n        var connections = new FbxNode(\u0022Connections\u0022);\n        long nextId = 1_000_000;\n        var ids = new Dictionary\u003Cstring, long\u003E(StringComparer.Ordinal);    // \u0022Model::bone\u0022 -\u003E id\n        var geometryOf = new Dictionary\u003Clong, long\u003E();                       // model id -\u003E geometry id\n        var kinds = new Dictionary\u003Clong, string\u003E();                          // id -\u003E node type\n\n        long IdOf(string full)\n        {\n            if (!ids.TryGetValue(full, out var id))\n                ids[full] = id = nextId\u002B\u002B;\n            return id;\n        }\n\n        void Connect(string kind, long child, long parent, string? property = null)\n        {\n            var c = new FbxNode(\u0022C\u0022);\n            c.Properties.Add(kind);\n            c.Properties.Add(child);\n            c.Properties.Add(parent);\n            if (property is not null)\n                c.Properties.Add(property);\n            connections.Children.Add(c);\n        }\n\n        // Global settings (FBX 6 keeps them inside Objects).\n        if (objects6.Child(\u0022GlobalSettings\u0022) is { } globals)\n            result.Children.Add(WithProperties70(new FbxNode(\u0022GlobalSettings\u0022), globals));\n\n        foreach (var node in objects6.Children)\n        {\n            if (node.Name is \u0022GlobalSettings\u0022 || node.Properties.Count == 0 || node.Properties[0] is not string full)\n                continue;\n            var subClass = node.Properties.Count \u003E 1 \u0026\u0026 node.Properties[1] is string s ? s : \u0022\u0022;\n            var id = IdOf(full);\n            switch (node.Name)\n            {\n                case \u0022Model\u0022:\n                {\n                    var model = NewObject(\u0022Model\u0022, id, full, subClass == \u0022Limb\u0022 ? \u0022LimbNode\u0022 : subClass);\n                    WithProperties70(model, node);\n                    // FBX 6 cameras aim with points (in the scene\u0027s space) instead of their axes.\n                    foreach (var aim in node.Children.Where(c =\u003E c.Name is \u0022Position\u0022 or \u0022LookAt\u0022 or \u0022Up\u0022))\n                        model.Children.Add(aim);\n                    kinds[id] = \u0022Model\u0022;\n                    if (node.Child(\u0022Vertices\u0022) is not null)\n                    {\n                        var geometryId = nextId\u002B\u002B;\n                        var geometry = NewObject(\u0022Geometry\u0022, geometryId, \u0022Geometry::\u0022 \u002B NameOf(full), \u0022Mesh\u0022);\n                        foreach (var child in node.Children)\n                            if (IsGeometryChild(child.Name))\n                                geometry.Children.Add(child);\n                        objects.Children.Add(geometry);\n                        geometryOf[id] = geometryId;\n                        kinds[geometryId] = \u0022Geometry\u0022;\n                        Connect(\u0022OO\u0022, geometryId, id);\n                    }\n                    objects.Children.Add(model);\n                    break;\n                }\n                case \u0022Deformer\u0022:\n                {\n                    var deformer = NewObject(\u0022Deformer\u0022, id, full, subClass);\n                    foreach (var child in node.Children)\n                        if (child.Name is not (\u0022Properties60\u0022 or \u0022Properties70\u0022))\n                            deformer.Children.Add(child);\n                    objects.Children.Add(deformer);\n                    kinds[id] = \u0022Deformer\u0022;\n                    break;\n                }\n                case \u0022Pose\u0022:\n                {\n                    var pose = NewObject(\u0022Pose\u0022, id, full, subClass);\n                    foreach (var child in node.Children)\n                    {\n                        if (child.Name != \u0022PoseNode\u0022)\n                        {\n                            pose.Children.Add(child);\n                            continue;\n                        }\n                        var poseNode = new FbxNode(\u0022PoseNode\u0022);\n                        foreach (var entry in child.Children)\n                        {\n                            if (entry.Name == \u0022Node\u0022 \u0026\u0026 entry.Properties.Count \u003E 0 \u0026\u0026 entry.Properties[0] is string target)\n                            {\n                                var n = new FbxNode(\u0022Node\u0022);\n                                n.Properties.Add(IdOf(target));\n                                poseNode.Children.Add(n);\n                            }\n                            else\n                            {\n                                poseNode.Children.Add(entry);\n                            }\n                        }\n                        pose.Children.Add(poseNode);\n                    }\n                    objects.Children.Add(pose);\n                    break;\n                }\n                case \u0022Material\u0022 or \u0022Texture\u0022 or \u0022Video\u0022:\n                {\n                    var obj = NewObject(node.Name, id, full, subClass);\n                    WithProperties70(obj, node);\n                    foreach (var child in node.Children)\n                        if (child.Name is not (\u0022Properties60\u0022 or \u0022Properties70\u0022))\n                            obj.Children.Add(child);\n                    objects.Children.Add(obj);\n                    kinds[id] = node.Name;\n                    break;\n                }\n            }\n        }\n\n        // Connections by name.\n        foreach (var c in root.Child(\u0022Connections\u0022)?.ChildrenNamed(\u0022Connect\u0022) ?? Enumerable.Empty\u003CFbxNode\u003E())\n        {\n            if (c.Properties.Count \u003C 3 || c.Properties[0] is not string kind || c.Properties[1] is not string child || c.Properties[2] is not string parent)\n                continue;\n            if (!ids.TryGetValue(child, out var childId))\n                continue;\n            var parentId = parent is \u0022Model::Scene\u0022 || !ids.TryGetValue(parent, out var p) ? 0L : p;\n            kinds.TryGetValue(childId, out var childKind);\n            kinds.TryGetValue(parentId, out var parentKind);\n            // A skin deforms the mesh\u0027s geometry, which FBX 6 kept inside the model.\n            if (childKind == \u0022Deformer\u0022 \u0026\u0026 parentKind == \u0022Model\u0022 \u0026\u0026 geometryOf.TryGetValue(parentId, out var geometryId))\n                parentId = geometryId;\n            // FBX 6 links a texture to its material without naming the slot: it is the colour map.\n            if (childKind == \u0022Texture\u0022 \u0026\u0026 parentKind == \u0022Material\u0022 \u0026\u0026 kind == \u0022OO\u0022)\n            {\n                Connect(\u0022OP\u0022, childId, parentId, \u0022DiffuseColor\u0022);\n                continue;\n            }\n            if (kind == \u0022OP\u0022 \u0026\u0026 c.Properties.Count \u003E 3 \u0026\u0026 c.Properties[3] is string property)\n                Connect(\u0022OP\u0022, childId, parentId, property);\n            else\n                Connect(\u0022OO\u0022, childId, parentId);\n        }\n\n        // Takes -\u003E animation stacks.\n        foreach (var take in root.Child(\u0022Takes\u0022)?.ChildrenNamed(\u0022Take\u0022) ?? Enumerable.Empty\u003CFbxNode\u003E())\n        {\n            var takeName = take.Properties.Count \u003E 0 \u0026\u0026 take.Properties[0] is string tn ? tn : \u0022Take\u0022;\n            var stackId = nextId\u002B\u002B;\n            var stack = NewObject(\u0022AnimationStack\u0022, stackId, \u0022AnimStack::\u0022 \u002B takeName, \u0022\u0022);\n            var props = new FbxNode(\u0022Properties70\u0022);\n            if (take.Child(\u0022LocalTime\u0022) is { Properties.Count: \u003E= 2 } local)\n            {\n                props.Children.Add(P(\u0022LocalStart\u0022, \u0022KTime\u0022, \u0022Time\u0022, \u0022\u0022, local.Prop\u003Clong\u003E(0)));\n                props.Children.Add(P(\u0022LocalStop\u0022, \u0022KTime\u0022, \u0022Time\u0022, \u0022\u0022, local.Prop\u003Clong\u003E(1)));\n            }\n            stack.Children.Add(props);\n            objects.Children.Add(stack);\n            var layerId = nextId\u002B\u002B;\n            objects.Children.Add(NewObject(\u0022AnimationLayer\u0022, layerId, \u0022AnimLayer::BaseLayer\u0022, \u0022\u0022));\n            Connect(\u0022OO\u0022, layerId, stackId);\n\n            foreach (var modelTake in take.ChildrenNamed(\u0022Model\u0022))\n            {\n                if (modelTake.Properties.Count == 0 || modelTake.Properties[0] is not string modelName || !ids.TryGetValue(modelName, out var modelId))\n                    continue;\n                var transform = modelTake.ChildrenNamed(\u0022Channel\u0022).FirstOrDefault(ch =\u003E ch.Properties.Count \u003E 0 \u0026\u0026 ch.Properties[0] as string == \u0022Transform\u0022);\n                if (transform is null)\n                    continue;\n                foreach (var channel in transform.ChildrenNamed(\u0022Channel\u0022))\n                {\n                    var which = channel.Properties.Count \u003E 0 ? channel.Properties[0] as string : null;\n                    var property = which switch { \u0022T\u0022 =\u003E \u0022Lcl Translation\u0022, \u0022R\u0022 =\u003E \u0022Lcl Rotation\u0022, \u0022S\u0022 =\u003E \u0022Lcl Scaling\u0022, _ =\u003E null };\n                    if (property is null)\n                        continue;\n                    var curveNodeId = nextId\u002B\u002B;\n                    var curveNode = NewObject(\u0022AnimationCurveNode\u0022, curveNodeId, \u0022AnimCurveNode::\u0022 \u002B which, \u0022\u0022);\n                    var cnProps = new FbxNode(\u0022Properties70\u0022);\n                    var curves = new List\u003C(string Axis, long Id)\u003E();\n                    foreach (var axisChannel in channel.ChildrenNamed(\u0022Channel\u0022))\n                    {\n                        var axis = axisChannel.Properties.Count \u003E 0 ? axisChannel.Properties[0] as string : null;\n                        if (axis is not (\u0022X\u0022 or \u0022Y\u0022 or \u0022Z\u0022))\n                            continue;\n                        var def = axisChannel.Child(\u0022Default\u0022) is { Properties.Count: \u003E 0 } d ? d.Prop\u003Cdouble\u003E(0) : 0.0;\n                        cnProps.Children.Add(P(\u0022d|\u0022 \u002B axis, \u0022Number\u0022, \u0022\u0022, \u0022A\u0022, def));\n                        var (times, values) = ReadKeys(axisChannel.Child(\u0022Key\u0022));\n                        if (times.Length == 0)\n                            continue;\n                        var curveId = nextId\u002B\u002B;\n                        var curve = NewObject(\u0022AnimationCurve\u0022, curveId, \u0022AnimCurve::\u0022, \u0022\u0022);\n                        var kt = new FbxNode(\u0022KeyTime\u0022);\n                        kt.Properties.Add(times);\n                        var kv = new FbxNode(\u0022KeyValueFloat\u0022);\n                        kv.Properties.Add(values);\n                        curve.Children.Add(kt);\n                        curve.Children.Add(kv);\n                        objects.Children.Add(curve);\n                        curves.Add((axis, curveId));\n                    }\n                    curveNode.Children.Add(cnProps);\n                    objects.Children.Add(curveNode);\n                    Connect(\u0022OO\u0022, curveNodeId, layerId);\n                    Connect(\u0022OP\u0022, curveNodeId, modelId, property);\n                    foreach (var (axis, curveId) in curves)\n                        Connect(\u0022OP\u0022, curveId, curveNodeId, \u0022d|\u0022 \u002B axis);\n                }\n            }\n        }\n\n        result.Children.Add(objects);\n        result.Children.Add(connections);\n        return result;\n    }\n\n    /// \u003Csummary\u003E\n    /// FBX 6 key list: \u003Cc\u003Etime, value, interpolation[, extra...]\u003C/c\u003E per key. Times are integer\n    /// ticks that only grow; everything between a value and the next such time (interpolation\n    /// letters, tangents) is skipped.\n    /// \u003C/summary\u003E\n    public static (long[] Times, float[] Values) ReadKeys(FbxNode? key)\n    {\n        if (key is null)\n            return (Array.Empty\u003Clong\u003E(), Array.Empty\u003Cfloat\u003E());\n        var p = key.Properties;\n        var times = new List\u003Clong\u003E();\n        var values = new List\u003Cfloat\u003E();\n        var i = 0;\n        while (i \u003C p.Count)\n        {\n            if (p[i] is long or int \u0026\u0026 i \u002B 1 \u003C p.Count \u0026\u0026 IsNumber(p[i \u002B 1]))\n            {\n                var t = Convert.ToInt64(p[i], System.Globalization.CultureInfo.InvariantCulture);\n                if (times.Count == 0 || t \u003E times[^1])\n                {\n                    times.Add(t);\n                    values.Add((float)Convert.ToDouble(p[i \u002B 1], System.Globalization.CultureInfo.InvariantCulture));\n                    i \u002B= 2;\n                    continue;\n                }\n            }\n            i\u002B\u002B;\n        }\n        return (times.ToArray(), values.ToArray());\n    }\n\n    private static bool IsNumber(object o) =\u003E o is long or int or double or float or short;\n\n    private static bool IsGeometryChild(string name)\n        =\u003E name is \u0022Vertices\u0022 or \u0022PolygonVertexIndex\u0022 or \u0022Edges\u0022 or \u0022GeometryVersion\u0022 or \u0022Layer\u0022 or \u0022Shape\u0022\n            || name.StartsWith(\u0022LayerElement\u0022, StringComparison.Ordinal);\n\n    private static string NameOf(string full)\n    {\n        var i = full.IndexOf(\u0022::\u0022, StringComparison.Ordinal);\n        return i \u003E= 0 ? full[(i \u002B 2)..] : full;\n    }\n\n    private static FbxNode NewObject(string type, long id, string fullName, string subClass)\n    {\n        var node = new FbxNode(type);\n        node.Properties.Add(id);\n        node.Properties.Add(fullName);\n        node.Properties.Add(subClass);\n        return node;\n    }\n\n    private static FbxNode P(string name, string type, string label, string flags, params object[] values)\n    {\n        var p = new FbxNode(\u0022P\u0022);\n        p.Properties.Add(name);\n        p.Properties.Add(type);\n        p.Properties.Add(label);\n        p.Properties.Add(flags);\n        p.Properties.AddRange(values);\n        return p;\n    }\n\n    /// \u003Csummary\u003ECopies \u003Cparamref name=\u0022source\u0022/\u003E\u0027s Properties60 into a Properties70 block on \u003Cparamref name=\u0022target\u0022/\u003E.\u003C/summary\u003E\n    private static FbxNode WithProperties70(FbxNode target, FbxNode source)\n    {\n        var block = new FbxNode(\u0022Properties70\u0022);\n        foreach (var property in source.Child(\u0022Properties60\u0022)?.ChildrenNamed(\u0022Property\u0022) ?? Enumerable.Empty\u003CFbxNode\u003E())\n        {\n            // FBX 6: name, type, flags, values...  FBX 7: name, type, label, flags, values...\n            if (property.Properties.Count \u003C 2 || property.Properties[0] is not string name)\n                continue;\n            var p = new FbxNode(\u0022P\u0022);\n            p.Properties.Add(name);\n            p.Properties.Add(property.Properties[1]);\n            p.Properties.Add(\u0022\u0022);\n            p.Properties.AddRange(property.Properties.Skip(2));\n            if (property.Properties.Count == 2)\n                p.Properties.Add(\u0022\u0022);\n            block.Children.Add(p);\n        }\n        target.Children.Add(block);\n        return target;\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Graph/GraphKvObject.cs","FileName":"GraphKvObject.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Collections;\nusing System.Globalization;\nusing System.Text;\n\nnamespace WeaponImporter.EditorTools.Core.Graph;\n\n/// \u003Csummary\u003EA KV3 object: insertion-ordered string-keyed map.\u003C/summary\u003E\npublic sealed class GraphKvObject : GraphKvValue\n{\n    private readonly List\u003Cstring\u003E _keys = new();\n    private readonly Dictionary\u003Cstring, GraphKvValue\u003E _map = new(StringComparer.Ordinal);\n\n    /// \u003Csummary\u003EKeys in insertion order.\u003C/summary\u003E\n    public IReadOnlyList\u003Cstring\u003E Keys =\u003E _keys;\n\n    public int Count =\u003E _keys.Count;\n\n    /// \u003Csummary\u003EGets a value (throws when absent) or sets it (appends new keys at the end).\u003C/summary\u003E\n    public GraphKvValue this[string key]\n    {\n        get =\u003E _map[key];\n        set\n        {\n            if (value is null)\n                throw new ArgumentNullException(nameof(value));\n            if (_map.TryAdd(key, value))\n                _keys.Add(key);\n            else\n                _map[key] = value;\n        }\n    }\n\n    public GraphKvValue? GetOrNull(string key) =\u003E _map.TryGetValue(key, out var v) ? v : null;\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Graph/WeaponGraphGenerator.cs","FileName":"WeaponGraphGenerator.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing WeaponImporter.EditorTools.Core.Analysis;\n\nnamespace WeaponImporter.EditorTools.Core.Graph;\n\n/// \u003Csummary\u003E\n/// Generates a first-person weapon AnimGraph: one state machine whose states exist only for the\n/// clips the weapon actually has, driven by the Facepunch parameter names (b_attack, b_reload,\n/// b_empty, b_holster, b_deploy_skip, b_sprint, ironsights) so existing first-person weapon code\n/// works unchanged. Ported from the original importer\u0027s DefaultGraphGenerator; the graph logic\n/// is unchanged, only the input is now a flat clip list.\n/// \u003C/summary\u003E\npublic static class WeaponGraphGenerator\n{\n    private const float QuickBlend = 0.05f;\n    private const float Blend = 0.15f;\n    private const float LocomotionBlend = 0.25f;\n\n    /// \u003Csummary\u003EDefault cycles when the clip carries no holster_complete / shell_insert event.\u003C/summary\u003E\n    private const float HolsterFinishCycle = 0.9f;\n    private const float InsertCycle = 0.55f;\n\n    /// \u003Csummary\u003E\n    /// The original importer\u0027s role set. v3 roles map onto a subset of these (see \u003Csee cref=\u0022SlotFor\u0022/\u003E);\n    /// the shell-reload / fire-mode / jump branches are kept so the graph logic stays identical.\n    /// \u003C/summary\u003E\n    private enum Slot\n    {\n        Idle, Fire, FireLast, FireAds, DryFire, Reload, ReloadEmpty, ReloadStart, ReloadInsert, ReloadEnd,\n        Deploy, Holster, Inspect, Walk, Sprint, AdsIn, AdsIdle, AdsOut, FireMode, Pump, Bolt, Melee, Jump,\n        Attack2, BlockStart, Block, BlockEnd, Use, UseStart, UseLoop, UseEnd, Throw,\n    }\n\n    private static Slot? SlotFor(AnimationRole role) =\u003E role switch\n    {\n        AnimationRole.Idle =\u003E Slot.Idle,\n        AnimationRole.Fire =\u003E Slot.Fire,\n        AnimationRole.FireEmpty =\u003E Slot.FireLast,       // attack while empty (b_attack \u002B b_empty)\n        AnimationRole.Reload =\u003E Slot.Reload,\n        AnimationRole.TacticalReload =\u003E Slot.Reload,    // used only when there is no plain reload\n        AnimationRole.EmptyReload =\u003E Slot.ReloadEmpty,\n        AnimationRole.Draw =\u003E Slot.Deploy,\n        AnimationRole.Holster =\u003E Slot.Holster,\n        AnimationRole.Inspect =\u003E Slot.Inspect,\n        AnimationRole.Sprint =\u003E Slot.Sprint,\n        AnimationRole.Walk =\u003E Slot.Walk,\n        // ADS raises the sights: the graph\u0027s \u0022Aim\u0022 state plays it and holds its last frame.\n        AnimationRole.Ads =\u003E Slot.AdsIn,\n        AnimationRole.AdsOut =\u003E Slot.AdsOut,\n        AnimationRole.AdsIdle =\u003E Slot.AdsIdle,\n        AnimationRole.ReloadStart =\u003E Slot.ReloadStart,\n        AnimationRole.ReloadInsert =\u003E Slot.ReloadInsert,\n        AnimationRole.ReloadEnd =\u003E Slot.ReloadEnd,\n        AnimationRole.AdsFire =\u003E Slot.FireAds,\n        AnimationRole.Melee =\u003E Slot.Melee,\n        AnimationRole.Bolt =\u003E Slot.Bolt,\n        AnimationRole.Attack2 =\u003E Slot.Attack2,\n        AnimationRole.BlockStart =\u003E Slot.BlockStart,\n        AnimationRole.Block =\u003E Slot.Block,\n        AnimationRole.BlockEnd =\u003E Slot.BlockEnd,\n        AnimationRole.Use =\u003E Slot.Use,\n        AnimationRole.UseStart =\u003E Slot.UseStart,\n        AnimationRole.UseLoop =\u003E Slot.UseLoop,\n        AnimationRole.UseEnd =\u003E Slot.UseEnd,\n        AnimationRole.Throw =\u003E Slot.Throw,\n        _ =\u003E null,                                      // Jam / Unjam / Unknown: no graph state\n    };\n\n    /// \u003Csummary\u003E\n    /// Builds the graph text. Throws when there is no idle clip (the graph is built around it).\n    /// \u003Cparamref name=\u0022cameraBone\u0022/\u003E is the engine bone name the editor preview camera locks to;\n    /// \u003Cparamref name=\u0022previewModel\u0022/\u003E is the vmdl shown in the AnimGraph editor.\n    /// \u003Cparamref name=\u0022fireCyclesAction\u0022/\u003E: when false, the bolt clip plays after every shot (bolt-action);\n    /// when true (default) it only plays on b_pump, since a v3 \u0022Bolt / Charge\u0022 clip is often a charging handle.\n    /// \u003C/summary\u003E\n    public static string Generate(string weaponName, IReadOnlyList\u003CGraphClip\u003E clips, string? cameraBone, out GraphSummary summary,\n        string? previewModel = null, bool fireCyclesAction = true)\n        =\u003E GraphKv.Serialize(AnimGraphBuilder.Header, GenerateDocument(weaponName, clips, cameraBone, out summary, previewModel, fireCyclesAction));\n\n    /// \u003Csummary\u003EThe graph \u003Csee cref=\u0022Generate\u0022/\u003E writes, as a document (see \u003Csee cref=\u0022AnimGraph2Writer\u0022/\u003E).\u003C/summary\u003E\n    public static GraphKvObject GenerateDocument(string weaponName, IReadOnlyList\u003CGraphClip\u003E clips, string? cameraBone, out GraphSummary summary,\n        string? previewModel = null, bool fireCyclesAction = true)\n    {\n        if (clips is null)\n            throw new ArgumentNullException(nameof(clips));\n\n        // First clip per slot wins; a plain reload beats a tactical one.\n        var bySlot = new Dictionary\u003CSlot, GraphClip\u003E();\n        foreach (var clip in clips.OrderBy(c =\u003E c?.Role ==AnimationRole.TacticalReload ? 1 : 0))\n        {\n            if (clip is null || string.IsNullOrEmpty(clip.Sequence) || SlotFor(clip.Role) is not { } slot)\n                continue;\n            // Locomotion (walk, sprint) stays out of the weapon graph, as in Facepunch\u0027s own\n            // first-person weapon graphs: sway and bob belong to the game\u0027s code. The clips are\n            // still in the model for games that want to play them.\n            if (clip.Role is AnimationRole.Walk or AnimationRole.Sprint)\n                continue;\n            bySlot.TryAdd(slot, clip);\n        }\n\n        var graph = new AnimGraphBuilder(weaponName);\n        var sm = new StateMachineBuilder(graph);\n        var states = new List\u003Cstring\u003E();\n\n        bool Has(Slot role) =\u003E bySlot.ContainsKey(role);\n        GraphClip Seq(Slot role) =\u003E bySlot[role];\n\n        if (!Has(Slot.Idle))\n            throw new InvalidOperationException(\u0022The weapon has no idle animation to build the graph around.\u0022);\n\n        // ---------------------------------------------------------------- tags\n        var busy = graph.Tag(\u0022Busy\u0022, eventTag: false);\n        var aiming = Has(Slot.AdsIdle) || Has(Slot.AdsIn) ? graph.Tag(\u0022Aiming\u0022, eventTag: false) : 0;\n        var holstering = Has(Slot.Holster) ? graph.Tag(\u0022Holstering\u0022, eventTag: false) : 0;\n        var discouraged = graph.Tag(WeaponParams.TagAttackDiscouraged, eventTag: true);\n        var holsterFinished = Has(Slot.Holster) ? graph.Tag(WeaponParams.TagHolsterFinished, eventTag: true) : 0;\n        var shellReload = Has(Slot.ReloadInsert);\n        var reloadIncrement = shellReload ? graph.Tag(WeaponParams.TagReloadIncrement, eventTag: true) : 0;\n\n        // ---------------------------------------------------------------- params\n        var pAttack = Has(Slot.Fire) || Has(Slot.FireAds) || Has(Slot.Melee) \u0026\u0026 !Has(Slot.Fire)\n            ? graph.BoolParam(WeaponParams.Attack, autoReset: true) : 0;\n        var pDry = Has(Slot.DryFire) ? graph.BoolParam(WeaponParams.AttackDry, autoReset: true) : 0;\n        var pEmpty = Has(Slot.ReloadEmpty) || Has(Slot.FireLast) ? graph.BoolParam(WeaponParams.Empty, autoReset: false) : 0;\n        var hasReload = Has(Slot.Reload) || Has(Slot.ReloadEmpty) || shellReload;\n        // Shell-by-shell reloads keep b_reload held (Facepunch shotgun convention); magazine reloads auto-reset.\n        var pReload = hasReload ? graph.BoolParam(WeaponParams.Reload, autoReset: !shellReload) : 0;\n        var pSpeedReload = hasReload ? graph.FloatParam(WeaponParams.SpeedReload, 0.1f, 4f, 1f) : 0;\n        var pSkip = Has(Slot.Deploy) ? graph.BoolParam(WeaponParams.DeploySkip, autoReset: false) : 0;\n        var pSpeedDeploy = Has(Slot.Deploy) ? graph.FloatParam(WeaponParams.SpeedDeploy, 0.1f, 4f, 1f) : 0;\n        var pHolster = Has(Slot.Holster) ? graph.BoolParam(WeaponParams.Holster, autoReset: false) : 0;\n        var pInspect = Has(Slot.Inspect) ? graph.BoolParam(WeaponParams.Inspect, autoReset: true) : 0;\n        var pSprint = Has(Slot.Sprint) ? graph.BoolParam(WeaponParams.Sprint, autoReset: false) : 0;\n        var pBob = Has(Slot.Walk) ? graph.FloatParam(WeaponParams.MoveBob, 0f, 1f, 0f) : 0;\n        var hasAds = Has(Slot.AdsIdle) || Has(Slot.AdsIn);\n        var pIron = hasAds ? graph.EnumParam(WeaponParams.Ironsights, new[] { \u0022None\u0022, \u0022Normal\u0022 }) : 0;\n        var pSpeedIron = hasAds ? graph.FloatParam(WeaponParams.SpeedIronsights, 0.1f, 4f, 1f) : 0;\n        var pMode = Has(Slot.FireMode) ? graph.BoolParam(WeaponParams.FireMode, autoReset: true) : 0;\n        var pPump = Has(Slot.Pump) || Has(Slot.Bolt) ? graph.BoolParam(WeaponParams.Pump, autoReset: true) : 0;\n        var pMelee = Has(Slot.Melee) \u0026\u0026 Has(Slot.Fire) ? graph.BoolParam(WeaponParams.Melee, autoReset: true) : 0;\n        var pJump = Has(Slot.Jump) ? graph.BoolParam(WeaponParams.Jump, autoReset: true) : 0;\n        var pAttack2 = Has(Slot.Attack2) ? graph.BoolParam(WeaponParams.Attack2, autoReset: true) : 0;\n        var hasBlock = Has(Slot.Block) || Has(Slot.BlockStart);\n        var pBlock = hasBlock ? graph.BoolParam(WeaponParams.Block, autoReset: false) : 0;\n        // A held use (start / loop / end) keeps b_use on while in use; a one-shot use resets itself.\n        var heldUse = Has(Slot.UseLoop) || Has(Slot.UseStart) \u0026\u0026 Has(Slot.UseEnd);\n        var pUse = Has(Slot.Use) || Has(Slot.UseStart) || Has(Slot.UseLoop) ? graph.BoolParam(WeaponParams.Use, autoReset: !heldUse) : 0;\n        var pThrow = Has(Slot.Throw) ? graph.BoolParam(WeaponParams.Throw, autoReset: true) : 0;\n        // Several clips for one attack: attack_variant picks which plays (1-based).\n        var variantCount = new[] { Slot.Fire, Slot.Melee, Slot.Attack2 }.Where(Has).Select(s =\u003E 1 \u002B Seq(s).Variants.Count).DefaultIfEmpty(1).Max();\n        var pVariant = variantCount \u003E 1 ? graph.EnumParam(WeaponParams.AttackVariant, Enumerable.Range(1, variantCount).Select(i =\u003E i.ToString()).ToList()) : 0;\n\n        // ---------------------------------------------------------------- nodes / states\n        float y = 0;\n        long Node(Slot role, long speedParam = 0, params (long Tag, float Start, float Duration)[] spans)\n        {\n            var sequence = Seq(role);\n            var node = graph.Sequence(sequence.Sequence, sequence.Sequence, sequence.Loop, -600, y, 1f, spans);\n            y \u002B= 96;\n            return speedParam != 0 ? graph.SpeedScale(sequence.Sequence \u002B \u0022 speed\u0022, node, speedParam, -380, y - 96) : node;\n        }\n\n        // With several clips for an attack, the first plays on attack_variant 1 only.\n        GraphKvObject[] First(Slot slot, params GraphKvObject[] conditions)\n            =\u003E pVariant != 0 \u0026\u0026 Seq(slot).Variants.Count \u003E 0 ? conditions.Append(StateMachineBuilder.Enum(pVariant, CompareOp.Equal, 0)).ToArray() : conditions;\n\n        // A variant clip: same settings as its role\u0027s clip (never looping).\n        long VariantNode(string sequence)\n        {\n            var node = graph.Sequence(sequence, sequence, false, -600, y, 1f);\n            y \u002B= 96;\n            return node;\n        }\n\n        float column = 0;\n        StateMachineBuilder.State State(string name, long input, bool start = false, params long[] tags)\n        {\n            var state = sm.Add(name, input, 200 \u002B (column % 4) * 220, 80 \u002B (float)Math.Floor(column / 4) * 140, start);\n            column\u002B\u002B;\n            state.Tags.AddRange(tags.Where(t =\u003E t != 0));\n            states.Add(name);\n            return state;\n        }\n\n        var idle = State(\u0022Idle\u0022, Node(Slot.Idle), start: !Has(Slot.Deploy));\n        var any = sm.Add(\u0022Any\u0022, null, 40, -80, start: false, alwaysEvaluate: true);\n\n        StateMachineBuilder.State? deploy = null;\n        if (Has(Slot.Deploy))\n        {\n            deploy = State(\u0022Deploy\u0022, Node(Slot.Deploy, pSpeedDeploy, (discouraged, 0f, 0.9f)), start: true, busy);\n            sm.Transition(deploy, idle, Blend, false, StateMachineBuilder.Finished());\n            sm.Transition(deploy, idle, QuickBlend, false, StateMachineBuilder.Bool(pSkip, true));\n            // b_deploy plays the draw again (switching back to this weapon).\n            var pDeploy = graph.BoolParam(WeaponParams.Deploy, autoReset: true);\n            sm.Transition(any, deploy, 0f, true, StateMachineBuilder.Bool(pDeploy, true));\n        }\n\n        if (Has(Slot.Holster))\n        {\n            var holster = State(\u0022Holster\u0022, Node(Slot.Holster, 0, (holsterFinished, HolsterFinishCycle, 0.02f), (discouraged, 0f, 1f)), false, busy, holstering);\n            sm.Transition(any, holster, Blend, true, StateMachineBuilder.Bool(pHolster, true), StateMachineBuilder.TagActive(holstering, false));\n            sm.Transition(holster, deploy ?? idle, Blend, true, StateMachineBuilder.Bool(pHolster, false));\n        }\n\n        // Aiming first: while aimed, attack plays the aimed fire.\n        StateMachineBuilder.State? adsIdle = null;\n        if (hasAds)\n        {\n            var adsIdleRole = Has(Slot.AdsIdle) ? Slot.AdsIdle : Slot.AdsIn;\n            adsIdle = State(\u0022Aim\u0022, Node(adsIdleRole == Slot.AdsIn ? Slot.AdsIn : Slot.AdsIdle), false, aiming);\n            if (Has(Slot.AdsIn) \u0026\u0026 adsIdleRole == Slot.AdsIdle)\n            {\n                var aimIn = State(\u0022Aim In\u0022, Node(Slot.AdsIn, pSpeedIron), false, aiming);\n                sm.Transition(idle, aimIn, QuickBlend, true, StateMachineBuilder.Enum(pIron, CompareOp.NotEqual, 0));\n                sm.Transition(aimIn, adsIdle, QuickBlend, false, StateMachineBuilder.Finished());\n                sm.Transition(aimIn, idle, Blend, false, StateMachineBuilder.Enum(pIron, CompareOp.Equal, 0));\n            }\n            else\n            {\n                sm.Transition(idle, adsIdle, Blend, true, StateMachineBuilder.Enum(pIron, CompareOp.NotEqual, 0));\n            }\n            if (Has(Slot.AdsOut))\n            {\n                var aimOut = State(\u0022Aim Out\u0022, Node(Slot.AdsOut, pSpeedIron));\n                sm.Transition(adsIdle, aimOut, QuickBlend, true, StateMachineBuilder.Enum(pIron, CompareOp.Equal, 0));\n                sm.Transition(aimOut, idle, Blend, false, StateMachineBuilder.Finished());\n                sm.Transition(aimOut, adsIdle, QuickBlend, true, StateMachineBuilder.Enum(pIron, CompareOp.NotEqual, 0));\n            }\n            else\n            {\n                sm.Transition(adsIdle, idle, Blend, false, StateMachineBuilder.Enum(pIron, CompareOp.Equal, 0));\n            }\n\n            if (Has(Slot.FireAds) \u0026\u0026 pAttack != 0)\n            {\n                var fireAds = State(\u0022Fire Aimed\u0022, Node(Slot.FireAds), false, aiming);\n                sm.Transition(any, fireAds, 0f, true, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.TagActive(aiming, true), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(fireAds, adsIdle, Blend, false, StateMachineBuilder.Finished());\n            }\n        }\n\n        // Reloads before fire so a reload request wins over a held trigger.\n        if (hasReload \u0026\u0026 !shellReload)\n        {\n            if (Has(Slot.ReloadEmpty))\n            {\n                var empty = State(\u0022Reload Empty\u0022, Node(Slot.ReloadEmpty, pSpeedReload, (discouraged, 0f, 0.9f)), false, busy);\n                sm.Transition(any, empty, Blend, true, StateMachineBuilder.Bool(pReload, true), StateMachineBuilder.Bool(pEmpty, true), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(empty, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n            var reloadRole = Has(Slot.Reload) ? Slot.Reload : Slot.ReloadEmpty;\n            var reload = State(\u0022Reload\u0022, Node(reloadRole, pSpeedReload, (discouraged, 0f, 0.9f)), false, busy);\n            sm.Transition(any, reload, Blend, true, StateMachineBuilder.Bool(pReload, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(reload, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n        else if (shellReload)\n        {\n            var insertSeq = Seq(Slot.ReloadInsert);\n            StateMachineBuilder.State? start = Has(Slot.ReloadStart)\n                ? State(\u0022Reload Start\u0022, Node(Slot.ReloadStart, pSpeedReload), false, busy) : null;\n            // Two insert states ping-pong so every shell restarts the insert animation.\n            var insertA = State(\u0022Reload Insert A\u0022, graph.Sequence(\u0022reload_insert_a\u0022, insertSeq.Sequence, false, -600, y, 1f, new[] { (reloadIncrement, InsertCycle, 0.02f) }), false, busy);\n            y \u002B= 96;\n            var insertB = State(\u0022Reload Insert B\u0022, graph.Sequence(\u0022reload_insert_b\u0022, insertSeq.Sequence, false, -600, y, 1f, new[] { (reloadIncrement, InsertCycle, 0.02f) }), false, busy);\n            y \u002B= 96;\n            StateMachineBuilder.State? end = Has(Slot.ReloadEnd)\n                ? State(\u0022Reload End\u0022, Node(Slot.ReloadEnd, pSpeedReload), false, busy) : null;\n\n            var entry = start ?? insertA;\n            sm.Transition(any, entry, Blend, true, StateMachineBuilder.Bool(pReload, true), StateMachineBuilder.TagActive(busy, false));\n            if (start is not null)\n            {\n                sm.Transition(start, insertA, QuickBlend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, true));\n                sm.Transition(start, end ?? idle, Blend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, false));\n            }\n            sm.Transition(insertA, insertB, QuickBlend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, true));\n            sm.Transition(insertB, insertA, QuickBlend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, true));\n            sm.Transition(insertA, end ?? idle, Blend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, false));\n            sm.Transition(insertB, end ?? idle, Blend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pReload, false));\n            if (end is not null)\n                sm.Transition(end, idle, Blend, false, StateMachineBuilder.Finished());\n            if (Has(Slot.Reload) || Has(Slot.ReloadEmpty))\n            {\n                // A full-magazine style reload also exists: play it when the gun is empty.\n                var fullRole = Has(Slot.ReloadEmpty) ? Slot.ReloadEmpty : Slot.Reload;\n                if (pEmpty != 0)\n                {\n                    var full = State(\u0022Reload Full\u0022, Node(fullRole, pSpeedReload), false, busy);\n                    sm.Transition(any, full, Blend, true, StateMachineBuilder.Bool(pReload, true), StateMachineBuilder.Bool(pEmpty, true), StateMachineBuilder.TagActive(busy, false));\n                    sm.Transition(full, idle, Blend, false, StateMachineBuilder.Finished());\n                }\n            }\n        }\n\n        if (pDry != 0)\n        {\n            var dry = State(\u0022Dry Fire\u0022, Node(Slot.DryFire));\n            sm.Transition(any, dry, 0f, true, StateMachineBuilder.Bool(pDry, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(dry, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        if (Has(Slot.Fire) \u0026\u0026 pAttack != 0)\n        {\n            // Aimed without an aimed-fire clip: a hip-fire clip would drop the sights, so shots\n            // keep the aimed pose (the viewmodel adds its own kick). Hip fire only when not aimed.\n            var hipOnly = adsIdle is not null \u0026\u0026 !Has(Slot.FireAds);\n            var fire = State(\u0022Fire\u0022, Node(Slot.Fire));\n            // Extra attack clips: attack_variant 2, 3... play them instead of the first.\n            foreach (var (variant, index) in Seq(Slot.Fire).Variants.Select((v, i) =\u003E (v, i \u002B 1)))\n            {\n                var other = State($\u0022Fire {index \u002B 1}\u0022, VariantNode(variant));\n                sm.Transition(any, other, 0f, true, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.Enum(pVariant, CompareOp.Equal, index), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(other, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n            if (Has(Slot.FireLast) \u0026\u0026 pEmpty != 0)\n            {\n                var last = State(\u0022Fire Last\u0022, Node(Slot.FireLast));\n                if (hipOnly)\n                    sm.Transition(any, last, 0f, true, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.Bool(pEmpty, true), StateMachineBuilder.TagActive(busy, false), StateMachineBuilder.TagActive(aiming, false));\n                else\n                    sm.Transition(any, last, 0f, true, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.Bool(pEmpty, true), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(last, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n            if (hipOnly)\n                sm.Transition(any, fire, 0f, true, First(Slot.Fire, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.TagActive(busy, false), StateMachineBuilder.TagActive(aiming, false)));\n            else\n                sm.Transition(any, fire, 0f, true, First(Slot.Fire, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.TagActive(busy, false)));\n\n            // Bolt/pump actions chain after the shot when the fire clip does not cycle the action itself.\n            var actionRole = Has(Slot.Pump) ? Slot.Pump : Has(Slot.Bolt) ? Slot.Bolt : (Slot?)null;\n            if (actionRole is { } role)\n            {\n                var action = State(role == Slot.Pump ? \u0022Pump\u0022 : \u0022Bolt\u0022, Node(role), false, busy);\n                sm.Transition(any, action, Blend, true, StateMachineBuilder.Bool(pPump, true), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(action, idle, Blend, false, StateMachineBuilder.Finished());\n                if (!fireCyclesAction)\n                {\n                    if (pEmpty != 0)\n                        sm.Transition(fire, action, QuickBlend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pEmpty, false));\n                    else\n                        sm.Transition(fire, action, QuickBlend, true, StateMachineBuilder.Finished());\n                }\n            }\n            if (adsIdle is not null)\n                sm.Transition(fire, adsIdle, Blend, false, StateMachineBuilder.Finished(), StateMachineBuilder.Enum(pIron, CompareOp.NotEqual, 0));\n            sm.Transition(fire, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n        else if (Has(Slot.Melee) \u0026\u0026 pAttack != 0)\n        {\n            var swing = State(\u0022Melee\u0022, Node(Slot.Melee));\n            sm.Transition(any, swing, 0f, true, First(Slot.Melee, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.TagActive(busy, false)));\n            sm.Transition(swing, idle, Blend, false, StateMachineBuilder.Finished());\n            foreach (var (variant, index) in Seq(Slot.Melee).Variants.Select((v, i) =\u003E (v, i \u002B 1)))\n            {\n                var other = State($\u0022Melee {index \u002B 1}\u0022, VariantNode(variant));\n                sm.Transition(any, other, 0f, true, StateMachineBuilder.Bool(pAttack, true), StateMachineBuilder.Enum(pVariant, CompareOp.Equal, index), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(other, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n        }\n\n        if (pAttack2 != 0)\n        {\n            var heavy = State(\u0022Heavy Attack\u0022, Node(Slot.Attack2), false, busy);\n            sm.Transition(any, heavy, QuickBlend, true, First(Slot.Attack2, StateMachineBuilder.Bool(pAttack2, true), StateMachineBuilder.TagActive(busy, false)));\n            sm.Transition(heavy, idle, Blend, false, StateMachineBuilder.Finished());\n            foreach (var (variant, index) in Seq(Slot.Attack2).Variants.Select((v, i) =\u003E (v, i \u002B 1)))\n            {\n                var other = State($\u0022Heavy Attack {index \u002B 1}\u0022, VariantNode(variant), false, busy);\n                sm.Transition(any, other, QuickBlend, true, StateMachineBuilder.Bool(pAttack2, true), StateMachineBuilder.Enum(pVariant, CompareOp.Equal, index), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(other, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n        }\n\n        // Guard: raise on b_block, hold while it stays on, lower when it goes off.\n        if (hasBlock)\n        {\n            var guard = graph.Tag(\u0022Blocking\u0022, eventTag: false);\n            var holdRole = Has(Slot.Block) ? Slot.Block : Slot.BlockStart;\n            var hold = State(\u0022Block\u0022, Node(holdRole), false, guard);\n            var start = Has(Slot.BlockStart) \u0026\u0026 Has(Slot.Block) ? State(\u0022Block Start\u0022, Node(Slot.BlockStart), false, guard) : null;\n            var end = Has(Slot.BlockEnd) ? State(\u0022Block End\u0022, Node(Slot.BlockEnd), false, busy) : null;\n            sm.Transition(any, start ?? hold, Blend, true, StateMachineBuilder.Bool(pBlock, true), StateMachineBuilder.TagActive(busy, false), StateMachineBuilder.TagActive(guard, false));\n            if (start is not null)\n            {\n                sm.Transition(start, hold, QuickBlend, false, StateMachineBuilder.Finished());\n                sm.Transition(start, end ?? idle, Blend, true, StateMachineBuilder.Bool(pBlock, false));\n            }\n            sm.Transition(hold, end ?? idle, Blend, true, StateMachineBuilder.Bool(pBlock, false));\n            if (end is not null)\n                sm.Transition(end, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        // Items: use once, or start / hold / finish while b_use stays on.\n        if (pUse != 0)\n        {\n            var inUse = graph.Tag(\u0022Using\u0022, eventTag: false);\n            if (!heldUse)\n            {\n                var useRole = Has(Slot.Use) ? Slot.Use : Has(Slot.UseStart) ? Slot.UseStart : Slot.UseLoop;\n                var use = State(\u0022Use\u0022, Node(useRole), false, busy, inUse);\n                sm.Transition(any, use, Blend, true, StateMachineBuilder.Bool(pUse, true), StateMachineBuilder.TagActive(busy, false));\n                sm.Transition(use, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n            else\n            {\n                var start = Has(Slot.UseStart) ? State(\u0022Use Start\u0022, Node(Slot.UseStart), false, busy, inUse) : null;\n                var loop = Has(Slot.UseLoop) ? State(\u0022Use Loop\u0022, Node(Slot.UseLoop), false, busy, inUse) : null;\n                var end = Has(Slot.UseEnd) ? State(\u0022Use End\u0022, Node(Slot.UseEnd), false, busy, inUse) : null;\n                var entry = start ?? loop!;\n                sm.Transition(any, entry, Blend, true, StateMachineBuilder.Bool(pUse, true), StateMachineBuilder.TagActive(busy, false));\n                if (start is not null \u0026\u0026 loop is not null)\n                    sm.Transition(start, loop, QuickBlend, false, StateMachineBuilder.Finished());\n                if (start is not null)\n                    sm.Transition(start, end ?? idle, Blend, true, StateMachineBuilder.Finished(), StateMachineBuilder.Bool(pUse, false));\n                if (loop is not null)\n                    sm.Transition(loop, end ?? idle, Blend, true, StateMachineBuilder.Bool(pUse, false));\n                if (end is not null)\n                    sm.Transition(end, idle, Blend, false, StateMachineBuilder.Finished());\n            }\n            // A one-shot use clip alongside a held one: the held use wins, the single clip is unused.\n        }\n\n        if (pThrow != 0)\n        {\n            var toss = State(\u0022Throw\u0022, Node(Slot.Throw), false, busy);\n            sm.Transition(any, toss, QuickBlend, true, StateMachineBuilder.Bool(pThrow, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(toss, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        if (pMelee != 0)\n        {\n            var melee = State(\u0022Melee\u0022, Node(Slot.Melee), false, busy);\n            sm.Transition(any, melee, QuickBlend, true, StateMachineBuilder.Bool(pMelee, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(melee, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        if (pInspect != 0)\n        {\n            var inspect = State(\u0022Inspect\u0022, Node(Slot.Inspect), false, busy);\n            sm.Transition(any, inspect, Blend, true, StateMachineBuilder.Bool(pInspect, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(inspect, idle, Blend, false, StateMachineBuilder.Finished());\n            // Inspecting is cancelled by any action.\n            if (pAttack != 0) sm.Transition(inspect, idle, QuickBlend, false, StateMachineBuilder.Bool(pAttack, true));\n        }\n\n        if (pMode != 0)\n        {\n            var mode = State(\u0022Fire Mode\u0022, Node(Slot.FireMode), false, busy);\n            sm.Transition(any, mode, Blend, true, StateMachineBuilder.Bool(pMode, true), StateMachineBuilder.TagActive(busy, false));\n            sm.Transition(mode, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        if (pJump != 0)\n        {\n            var jump = State(\u0022Jump\u0022, Node(Slot.Jump));\n            sm.Transition(idle, jump, QuickBlend, true, StateMachineBuilder.Bool(pJump, true));\n            sm.Transition(jump, idle, Blend, false, StateMachineBuilder.Finished());\n        }\n\n        // Locomotion: walk on move_bob, sprint on b_sprint.\n        StateMachineBuilder.State? walk = null;\n        if (pBob != 0)\n        {\n            walk = State(\u0022Walk\u0022, Node(Slot.Walk));\n            sm.Transition(idle, walk, LocomotionBlend, false, StateMachineBuilder.Float(pBob, CompareOp.Greater, 0.1f));\n            sm.Transition(walk, idle, LocomotionBlend, false, StateMachineBuilder.Float(pBob, CompareOp.LessOrEqual, 0.1f));\n            if (adsIdle is not null)\n                sm.Transition(walk, idle, QuickBlend, false, StateMachineBuilder.Enum(pIron, CompareOp.NotEqual, 0));\n        }\n        if (pSprint != 0)\n        {\n            var sprint = State(\u0022Sprint\u0022, Node(Slot.Sprint), false, discouraged);\n            sm.Transition(idle, sprint, LocomotionBlend, false, StateMachineBuilder.Bool(pSprint, true));\n            if (walk is not null)\n                sm.Transition(walk, sprint, LocomotionBlend, false, StateMachineBuilder.Bool(pSprint, true));\n            if (adsIdle is not null)\n                sm.Transition(adsIdle, sprint, LocomotionBlend, false, StateMachineBuilder.Bool(pSprint, true));\n            sm.Transition(sprint, walk ?? idle, LocomotionBlend, false, StateMachineBuilder.Bool(pSprint, false));\n        }\n\n        var machine = graph.StateMachine(\u0022Weapon\u0022, sm, -100, 0);\n        graph.Root(machine, 200, 0);\n\n        summary = new GraphSummary(\n            states,\n            graph.Parameters.Keys.OrderBy(k =\u003E k, StringComparer.Ordinal).ToList(),\n            new[] { WeaponParams.TagAttackDiscouraged, WeaponParams.TagHolsterFinished, WeaponParams.TagReloadIncrement }\n                .Where(t =\u003E t switch\n                {\n                    WeaponParams.TagHolsterFinished =\u003E holsterFinished != 0,\n                    WeaponParams.TagReloadIncrement =\u003E reloadIncrement != 0,\n                    _ =\u003E true,\n                }).ToList());\n\n        return graph.Document(previewModel is null ? Array.Empty\u003Cstring\u003E() : new[] { previewModel }, cameraBone);\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Grasp/GraspEvaluator.cs","FileName":"GraspEvaluator.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Numerics;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\n\nnamespace WeaponImporter.EditorTools.Core.Grasp;\n\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003EScores a hand pose against the weapon (and the other hand).\u003C/summary\u003E\npublic static class GraspEvaluator\n{\n    public static GraspQuality Evaluate(GraspRequest r, HandPose pose)\n    {\n        var shape = HandShape.Of(r.Hand, pose);\n        var touching = 0;\n        var floating = 0;\n        var maxPen = 0f;\n        foreach (var finger in r.Hand.Fingers)\n        {\n            var segs = shape.Segments.Where(s =\u003E s.Finger == finger.Kind).ToList();\n            var fingerTouch = false;\n            foreach (var seg in segs)\n                for (var k = 1; k \u003C= 4; k\u002B\u002B)\n                {\n                    if (r.Weapon.Closest(seg.Point(k / 4f), seg.Radius * 3f \u002B 0.5f) is not { } c)\n                        continue;\n                    var gap = c.Inside ? -c.Distance : c.Distance;\n                    if (gap \u003C seg.Radius \u002B 0.08f)\n                        fingerTouch = true;\n                    maxPen = MathF.Max(maxPen, seg.Radius - gap);\n                }\n            if (fingerTouch)\n                touching\u002B\u002B;\n            else if (!(finger.Kind == FingerKind.Index \u0026\u0026 r.Trigger is not null))\n                floating\u002B\u002B;\n        }\n\n        var palmPen = 0f;\n        var palmGap = float.MaxValue;\n        foreach (var p in shape.PalmPoints)\n        {\n            if (r.Weapon.Closest(p, 4f) is not { } c)\n                continue;\n            var gap = c.Inside ? -c.Distance : c.Distance;\n            palmPen = MathF.Max(palmPen, -gap);\n            palmGap = MathF.Min(palmGap, MathF.Max(0f, gap));\n        }\n        if (palmGap == float.MaxValue)\n            palmGap = 4f;\n\n        var overlap = 0f;\n        if (r.OtherHand is { } other)\n            foreach (var seg in shape.Segments)\n                overlap = MathF.Max(overlap, ProceduralGripGenerator.OverlapsOther(seg, other));\n\n        var deviation = r.PreferredWrist is { } pref ? MathQ.AngleBetween(pref.Rot, pose.Wrist.Rot) * 180f / MathF.PI : 0f;\n\n        return new GraspQuality\n        {\n            TouchingFingers = touching,\n            FloatingFingers = floating,\n            MaxPenetration = MathF.Max(0f, maxPen - 0.06f),\n            PalmPenetration = palmPen,\n            PalmGap = palmGap,\n            HandOverlap = overlap,\n            WristDeviationDegrees = deviation,\n        };\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Grip/GripPreset.cs","FileName":"GripPreset.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Numerics;\nusing System.Text.Json;\nusing System.Text.Json.Serialization;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Geometry;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing WeaponImporter.EditorTools.Core.Setup;\n\nnamespace WeaponImporter.EditorTools.Core.Grip;\n\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003E\n/// A hand grip captured from an animation (any rig) in a form that transfers to another hand\n/// and another weapon: finger angles, and the palm\u0027s place and orientation relative to the grip\n/// surface it holds, normalised by hand length. Anatomical axes (fingers, palm) are used, never\n/// bone axes, so rigs with different bone orientations agree.\n/// \u003C/summary\u003E\npublic sealed class GripPreset\n{\n    public string Name { get; set; } = \u0022\u0022;\n\n    /// \u003Csummary\u003EWhere it came from: \u0022this weapon\u0027s first-person animation\u0022, a pack file, \u0022built-in\u0022.\u003C/summary\u003E\n    public string Source { get; set; } = \u0022\u0022;\n\n    public Side Side { get; set; }\n    public GripStyle Style { get; set; }\n\n    /// \u003Csummary\u003EPalm centre in the grip surface frame, divided by the hand length.\u003C/summary\u003E\n    public float[] Palm { get; set; } = new float[3];\n\n    /// \u003Csummary\u003EAnatomical hand frame (x = fingers, y = out of the palm) in the grip surface frame.\u003C/summary\u003E\n    public float[] Orientation { get; set; } = { 0, 0, 0, 1 };\n\n    /// \u003Csummary\u003E\n    /// Each finger\u0027s segment directions (x,y,z per joint, proximal first) in the anatomical hand\n    /// frame. Applied by fitting the target hand\u0027s joint angles to them.\n    /// \u003C/summary\u003E\n    public Dictionary\u003CFingerKind, float[]\u003E Directions { get; set; } = new();\n\n    /// \u003Csummary\u003E\n    /// Preference added to the fit score when grips compete. A grip captured from this very\n    /// weapon\u0027s own first-person animation gets \u003Csee cref=\u0022GripExtractor.OwnPriority\u0022/\u003E: it was\n    /// authored for exactly this geometry, so it wins unless it fits clearly worse.\n    /// \u003C/summary\u003E\n    [JsonIgnore] public float Priority { get; set; }\n\n    /// \u003Csummary\u003EWeapon type it was captured on (ranking prefers the same kind).\u003C/summary\u003E\n    public string WeaponType { get; set; } = \u0022\u0022;\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Grip/LearnedGrasp.cs","FileName":"LearnedGrasp.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Globalization;\nusing System.Numerics;\nusing System.Text;\nusing System.Text.Json;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Geometry;\nusing WeaponImporter.EditorTools.Core.Grasp;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing WeaponImporter.EditorTools.Core.Rig;\nusing WeaponImporter.EditorTools.Core.Weapon;\n\nnamespace WeaponImporter.EditorTools.Core.Grip;\n\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003EOne hand from a learned grasp generator: 21 keypoints in canonical weapon space (inches).\u003C/summary\u003E\npublic sealed record LearnedGrasp(Side Side, Vector3[] Joints);\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Import/ArmsFit.cs","FileName":"ArmsFit.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Numerics;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Geometry;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing WeaponImporter.EditorTools.Core.Rig;\nusing WeaponImporter.EditorTools.Core.Weapon;\n\nnamespace WeaponImporter.EditorTools.Core.Import;\n\nusing Vector2 = System.Numerics.Vector2;\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003EHow the weapon was placed in separate first-person arms.\u003C/summary\u003E\npublic sealed record ArmsFit(string ArmsPath, string AttachBone, float RightError, float LeftError, float Shift, int Clips, string Reason);\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Output/PrefabBuilder.cs","FileName":"PrefabBuilder.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Security.Cryptography;\nusing System.Text;\nusing System.Text.Json;\nusing System.Text.Json.Nodes;\n\nnamespace WeaponImporter.EditorTools.Core.Output;\n\n/// \u003Csummary\u003E\n/// Writes s\u0026amp;box prefab JSON. GUIDs are derived from the prefab path and each object\u0027s role,\n/// so re-baking keeps references stable.\n/// \u003C/summary\u003E\npublic static class PrefabBuilder\n{\n    public static string Build(string prefabPath, PrefabObject root)\n    {\n        var doc = new JsonObject\n        {\n            [\u0022RootObject\u0022] = Object(prefabPath, root, \u0022root\u0022),\n            [\u0022ShowInMenu\u0022] = false,\n            [\u0022MenuPath\u0022] = null,\n            [\u0022MenuIcon\u0022] = null,\n            [\u0022DontBreakAsTemplate\u0022] = false,\n            [\u0022ResourceVersion\u0022] = 2,\n            [\u0022__references\u0022] = new JsonArray(),\n            [\u0022__version\u0022] = 2,\n        };\n        return doc.ToJsonString(new JsonSerializerOptions { WriteIndented = true }).Replace(\u0022\\r\\n\u0022, \u0022\\n\u0022);\n    }\n\n    private static JsonObject Object(string prefab, PrefabObject o, string role)\n    {\n        var components = new JsonArray();\n        var index = 0;\n        foreach (var c in o.Components)\n        {\n            var node = new JsonObject\n            {\n                [\u0022__type\u0022] = c.Type,\n                [\u0022__guid\u0022] = Guid(prefab, $\u0022{role}/component:{index\u002B\u002B}:{c.Type}\u0022),\n            };\n            foreach (var (k, v) in c.Properties)\n                node[k] = v?.DeepClone();\n            components.Add(node);\n        }\n        var children = new JsonArray();\n        foreach (var child in o.Children)\n            children.Add(Object(prefab, child, $\u0022{role}/{child.Name}\u0022));\n        return new JsonObject\n        {\n            [\u0022__guid\u0022] = Guid(prefab, role),\n            [\u0022__version\u0022] = 1,\n            [\u0022Flags\u0022] = 0,\n            [\u0022Name\u0022] = o.Name,\n            [\u0022Position\u0022] = $\u0022{F(o.Position.X)},{F(o.Position.Y)},{F(o.Position.Z)}\u0022,\n            [\u0022Rotation\u0022] = $\u0022{F(o.Rotation.X)},{F(o.Rotation.Y)},{F(o.Rotation.Z)},{F(o.Rotation.W)}\u0022,\n            [\u0022Scale\u0022] = $\u0022{F(o.Scale)},{F(o.Scale)},{F(o.Scale)}\u0022,\n            [\u0022Tags\u0022] = o.Tags,\n            [\u0022Enabled\u0022] = true,\n            [\u0022NetworkMode\u0022] = 2,\n            [\u0022NetworkInterpolation\u0022] = true,\n            [\u0022NetworkOrphaned\u0022] = 0,\n            [\u0022OwnerTransfer\u0022] = 1,\n            [\u0022Components\u0022] = components,\n            [\u0022Children\u0022] = children,\n        };\n    }\n\n    private static string F(float v) =\u003E v.ToString(\u00220.######\u0022, System.Globalization.CultureInfo.InvariantCulture);\n\n    /// \u003Csummary\u003EStable name-based GUID (SHA-256 of prefab path \u002B role, formatted as a v5-style GUID).\u003C/summary\u003E\n    public static string Guid(string prefab, string role)\n    {\n        var hash = SHA256.HashData(Encoding.UTF8.GetBytes(prefab.ToLowerInvariant() \u002B \u0022|\u0022 \u002B role));\n        var bytes = hash.Take(16).ToArray();\n        bytes[7] = (byte)((bytes[7] \u0026 0x0F) | 0x50);\n        bytes[8] = (byte)((bytes[8] \u0026 0x3F) | 0x80);\n        return new System.Guid(bytes).ToString(\u0022D\u0022);\n    }\n\n    /// \u003Csummary\u003EThe SkinnedModelRenderer entry for a weapon model.\u003C/summary\u003E\n    public static PrefabComponent ModelRenderer(string model, bool useAnimGraph = false) =\u003E new(\u0022Sandbox.SkinnedModelRenderer\u0022, new Dictionary\u003Cstring, JsonNode?\u003E\n    {\n        [\u0022__enabled\u0022] = true,\n        [\u0022BodyGroups\u0022] = 18446744073709551615UL,\n        [\u0022CreateAttachments\u0022] = true,\n        [\u0022CreateBoneObjects\u0022] = false,\n        [\u0022Model\u0022] = model,\n        [\u0022RenderType\u0022] = \u0022On\u0022,\n        [\u0022Tint\u0022] = \u00221,1,1,1\u0022,\n        [\u0022UseAnimGraph\u0022] = useAnimGraph,\n        [\u0022PlaybackRate\u0022] = 1,\n    });\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Setup/AutoSetup.cs","FileName":"AutoSetup.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Numerics;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Geometry;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing WeaponImporter.EditorTools.Core.Rig;\nusing WeaponImporter.EditorTools.Core.Weapon;\n\nnamespace WeaponImporter.EditorTools.Core.Setup;\n\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003E\n/// One-click setup: turns an analysis into a complete \u003Csee cref=\u0022WeaponSetup\u0022/\u003E with sensible\n/// defaults, keeping anything the user already marked manual in \u003Cparamref name=\u0022previous\u0022/\u003E.\n/// \u003C/summary\u003E\npublic static class AutoSetup\n{\n    /// \u003Cparam name=\u0022stock\u0022\u003EThe installed stock third-person sequences (none when not installed).\u003C/param\u003E\n    public static WeaponSetup Build(WeaponAnalysis a, WeaponSetup? previous = null, IReadOnlyCollection\u003Cstring\u003E? stock = null)\n    {\n        var s = previous ?? new WeaponSetup();\n        s.Name = string.IsNullOrEmpty(s.Name) || s.Name == \u0022weapon\u0022 ? a.Asset.Name : s.Name;\n        s.Source = string.IsNullOrEmpty(s.Source) ? a.Asset.SourcePath : s.Source;\n        if (!s.TypeManual)\n            s.Type = a.Type.Type;\n        if (!s.OrientationManual)\n        {\n            s.ModelRotationQ = a.ModelToCanonical;\n            s.Scale = a.Scale;\n        }\n        s.ReferenceClip = a.ReferenceClip;\n        s.RootBone = a.Asset.Skeleton[a.RootBone].Name;\n\n        // Parts: keep manual ones, refresh the rest.\n        var manualParts = s.Parts.Where(p =\u003E p.Manual).ToList();\n        s.Parts = manualParts.Concat(a.Parts.Where(p =\u003E manualParts.All(m =\u003E m.Kind != p.Kind)).Select(p =\u003E new PartSetup\n        {\n            Kind = p.Kind,\n            Bone = p.Bone,\n            Meshes = p.Meshes.ToList(),\n            Confidence = p.Confidence,\n            Center = V.A(p.Center),\n        })).ToList();\n\n        if (s.Muzzle is not { Manual: true })\n            s.Muzzle = a.Muzzle is null ? null : Point(a, a.Muzzle);\n        if (s.Eject is not { Manual: true })\n            s.Eject = a.Eject is null || s.Type is WeaponType.Revolver or WeaponType.Melee or WeaponType.Launcher ? null : Point(a, a.Eject);\n\n        if (!s.Primary.Manual \u0026\u0026 a.Primary is { } primary)\n            s.Primary = Grip(primary);\n        if (s.Support is not { Manual: true })\n            s.Support = a.Support is { } support ? Grip(support) : null;\n        // One copy in each hand: the left hand holds its own, not the right one\u0027s.\n        if (!s.DualManual)\n            s.Dual = a.Dual;\n        s.UseSupportHand = s.Support is not null \u0026\u0026 (WeaponTypes.TwoHanded(s.Type) || s.Type == WeaponType.Melee) \u0026\u0026 !s.Dual;\n\n        // Weapon clips per role.\n        foreach (var role in AnimationRoles.All)\n        {\n            if (s.WeaponAnimations.TryGetValue(role, out var existing) \u0026\u0026 existing.Manual)\n                continue;\n            if (a.AssignedAnimations.TryGetValue(role, out var guess))\n                s.WeaponAnimations[role] = new AnimationBinding\n                {\n                    Clip = guess.Animation,\n                    Confidence = guess.Confidence,\n                    Variants = a.AnimationVariants.TryGetValue(role, out var more) ? more.ToList() : new List\u003Cstring\u003E(),\n                };\n            else\n                s.WeaponAnimations.Remove(role);\n        }\n\n        // Third person: the character\u0027s animgraph handles every role unless told otherwise.\n        foreach (var role in AnimationRoles.All)\n            if (!s.ThirdPerson.TryGetValue(role, out var tp) || !tp.Manual)\n                s.ThirdPerson[role] = new CharacterAnimation { Source = CharacterAnimationSource.Graph };\n\n        // Stock animations, when installed: a hold and actions suited to the weapon.\n        if (!s.StockStyleManual)\n            s.StockStyle = StockThirdPerson.Suggest(s.Type, StockThirdPerson.NameOf(a.Asset), a.Length, s.UseSupportHand \u0026\u0026 s.Support is not null, s.Dual);\n        if (stock is { Count: \u003E 0 })\n            StockThirdPerson.Apply(s, s.StockStyle, stock);\n\n        DefaultContacts(s, a);\n        DetectEvents(s, a);\n        return s;\n    }\n\n    public static PointSetup Point(WeaponAnalysis a, PointDetection p)\n    {\n        // Stored in model units relative to the bone; convert canonical offsets back.\n        var bone = a.Asset.Skeleton.IndexOf(p.Bone);\n        var local = p.Local;\n        var scale = a.Scale \u003E 1e-6f ? a.Scale : 1f;\n        return new PointSetup\n        {\n            Bone = p.Bone,\n            Position = V.A(local.Pos / scale),\n            Rotation = V.A(local.Rot),\n            Canonical = V.A(p.Model.Pos),\n            Confidence = p.Confidence,\n            Manual = p.Manual,\n        };\n    }\n\n    public static GripSetup Grip(GripCandidate g) =\u003E new()\n    {\n        Style = g.Style,\n        Contact = V.A(g.Surface.Contact),\n        Normal = V.A(g.Surface.Normal),\n        Axis = V.A(g.Surface.Axis),\n        Confidence = g.Confidence,\n        Reason = g.Reason,\n        Manual = g.Manual,\n    };\n\n    /// \u003Csummary\u003ERe-measures a stored grip on the geometry (after edits or a template copy).\u003C/summary\u003E\n    public static GripCandidate? Candidate(WeaponAnalysis a, GripSetup g)\n    {\n        if (!g.Enabled)\n            return null;\n        var contact = V.Of(g.Contact);\n        var surface = SurfaceProbe.FromPoint(a.WeaponBvh, contact \u002B V.Of(g.Normal) * 0.05f, V.Of(g.Axis));\n        if (surface is null)\n            return null;\n        // The stored normal was measured robustly (from inside the part, or facing the camera\n        // for a click); keep it and only take the fresh contact/extent measurements.\n        var normal = V.Of(g.Normal);\n        if (normal.LengthSquared() \u003E 0.5f)\n            surface = surface with { Normal = Vector3.Normalize(normal) };\n        var axis = V.Of(g.Axis);\n        if (axis.LengthSquared() \u003E 0.5f)\n        {\n            var n = surface.Normal;\n            var projected = axis - n * Vector3.Dot(axis, n);\n            if (projected.LengthSquared() \u003E 1e-4f)\n                surface = surface with { Axis = Vector3.Normalize(projected) };\n        }\n        return new GripCandidate { Surface = surface, Style = g.Style, Confidence = g.Confidence, Reason = g.Reason, Manual = g.Manual };\n    }\n\n    /// \u003Csummary\u003E\n    /// Support hand stays on through idle and fire, lets go for reloads and melee, and the\n    /// bolt/pump hand follows the part it works.\n    /// \u003C/summary\u003E\n    public static void DefaultContacts(WeaponSetup s, WeaponAnalysis a)\n    {\n        void Set(AnimationRole role, params ContactKey[] keys)\n        {\n            if (s.Contacts.TryGetValue(role, out var existing) \u0026\u0026 existing.Keys.Any() \u0026\u0026 !existing.Generated)\n                return; // user or template already defined it\n            s.Contacts[role] = new ContactTrack { Keys = keys.ToList(), Generated = true };\n        }\n        if (!s.UseSupportHand)\n            return;\n        var reloadRelease = s.Type is WeaponType.Pistol or WeaponType.Revolver ? 0.12f : 0.18f;\n        var reloadReturn = s.Type is WeaponType.Pistol or WeaponType.Revolver ? 0.82f : 0.86f;\n        foreach (var role in new[] { AnimationRole.Reload, AnimationRole.TacticalReload, AnimationRole.EmptyReload })\n            Set(role,\n                new ContactKey { Hand = Side.Left, Time = reloadRelease, State = ContactState.Released, Blend = 0.3f },\n                new ContactKey { Hand = Side.Left, Time = reloadReturn, State = ContactState.Locked, Blend = 0.3f });\n        // Shell-by-shell reloads: the support hand loads the shells, then takes the grip back.\n        Set(AnimationRole.ReloadStart, new ContactKey { Hand = Side.Left, Time = 0.15f, State = ContactState.Released, Blend = 0.25f });\n        Set(AnimationRole.ReloadInsert, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Released, Blend = 0f });\n        Set(AnimationRole.ReloadEnd, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Released, Blend = 0f },\n            new ContactKey { Hand = Side.Left, Time = 0.7f, State = ContactState.Locked, Blend = 0.25f });\n        Set(AnimationRole.Melee, new ContactKey { Hand = Side.Left, Time = 0.05f, State = ContactState.Released, Blend = 0.1f },\n            new ContactKey { Hand = Side.Left, Time = 0.85f, State = ContactState.Locked, Blend = 0.2f });\n        Set(AnimationRole.Sprint, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Released, Blend = 0.2f });\n        Set(AnimationRole.Holster, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Released, Blend = 0.15f });\n        Set(AnimationRole.Draw, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Released, Blend = 0f },\n            new ContactKey { Hand = Side.Left, Time = 0.7f, State = ContactState.Locked, Blend = 0.2f });\n        if (s.Type == WeaponType.Shotgun \u0026\u0026 a.Part(PartKind.Pump) is { Bone: { Length: \u003E 0 } pumpBone })\n            Set(AnimationRole.Bolt, new ContactKey { Hand = Side.Left, Time = 0f, State = ContactState.Locked, Blend = 0f, Follow = pumpBone });\n    }\n\n    /// \u003Csummary\u003E\n    /// Events from part motion: magazine detach/insert from the magazine leaving and returning,\n    /// bolt pull/release from its travel, fire effects on the first frame of fire clips.\n    /// \u003C/summary\u003E\n    public static void DetectEvents(WeaponSetup s, WeaponAnalysis a)\n    {\n        s.Events.RemoveAll(e =\u003E !e.Manual);\n        void Add(AnimationRole role, WeaponEventKind kind, float time)\n        {\n            if (s.Events.Any(e =\u003E e.Role == role \u0026\u0026 e.Kind == kind))\n                return;\n            s.Events.Add(new WeaponEvent { Role = role, Kind = kind, Time = Math.Clamp(time, 0f, 1f) });\n        }\n\n        foreach (var role in new[] { AnimationRole.Fire, AnimationRole.AdsFire, AnimationRole.FireEmpty })\n        {\n            if (!WeaponTypes.IsFirearm(s.Type))\n                break;\n            // Events live on clips; roles the weapon has no clip for get none.\n            if (!s.WeaponAnimations.ContainsKey(role))\n                continue;\n            Add(role, WeaponEventKind.Fire, 0f);\n            Add(role, WeaponEventKind.MuzzleFlash, 0f);\n            if (s.Eject is not null)\n            {\n                var bolt = Bone(a, PartKind.Slide) ?? Bone(a, PartKind.Bolt);\n                var clip = Clip(a, s, role);\n                var peak = bolt is { } b \u0026\u0026 clip is not null ? PeakTravel(a.Asset, clip, b) : 0.15f;\n                Add(role, WeaponEventKind.ShellEject, peak);\n            }\n        }\n\n        foreach (var role in new[] { AnimationRole.Reload, AnimationRole.TacticalReload, AnimationRole.EmptyReload })\n        {\n            var clip = Clip(a, s, role);\n            if (clip is null)\n                continue;\n            if (Bone(a, PartKind.Magazine) is { } mag)\n            {\n                var (leave, back) = LeaveAndReturn(a.Asset, clip, mag, 0.35f);\n                if (leave is { } l) Add(role, WeaponEventKind.MagazineDetach, l);\n                if (back is { } r) Add(role, WeaponEventKind.MagazineInsert, r);\n            }\n            if (role == AnimationRole.EmptyReload || role == AnimationRole.Reload)\n                if ((Bone(a, PartKind.Bolt) ?? Bone(a, PartKind.ChargingHandle) ?? Bone(a, PartKind.Slide)) is { } bolt)\n                {\n                    var (pull, release) = LeaveAndReturn(a.Asset, clip, bolt, 0.25f);\n                    if (pull is { } p) Add(role, WeaponEventKind.BoltPull, p);\n                    if (release is { } r) Add(role, WeaponEventKind.BoltRelease, r);\n                }\n            Add(role, WeaponEventKind.ReloadComplete, 0.95f);\n        }\n\n        if (Clip(a, s, AnimationRole.Bolt) is { } boltClip \u0026\u0026 (Bone(a, PartKind.Bolt) ?? Bone(a, PartKind.Pump) ?? Bone(a, PartKind.ChargingHandle)) is { } bb)\n        {\n            var (pull, release) = LeaveAndReturn(a.Asset, boltClip, bb, 0.25f);\n            if (pull is { } p) Add(AnimationRole.Bolt, WeaponEventKind.BoltPull, p);\n            if (release is { } r) Add(AnimationRole.Bolt, WeaponEventKind.BoltRelease, r);\n        }\n    }\n\n    private static int? Bone(WeaponAnalysis a, PartKind kind)\n        =\u003E a.Part(kind) is { Bone: { Length: \u003E 0 } name } \u0026\u0026 a.Asset.Skeleton.IndexOf(name) is var i \u0026\u0026 i \u003E= 0 ? i : null;\n\n    private static Clip? Clip(WeaponAnalysis a, WeaponSetup s, AnimationRole role)\n        =\u003E s.WeaponAnimations.TryGetValue(role, out var b) ? a.Asset.FindClip(b.Clip) : null;\n\n    /// \u003Csummary\u003ENormalized times where a bone first moves away from rest by \u003Cparamref name=\u0022threshold\u0022/\u003E of its peak travel, and settles back.\u003C/summary\u003E\n    public static (float? Leave, float? Return) LeaveAndReturn(WeaponAsset asset, Clip clip, int bone, float threshold)\n    {\n        if (clip.FrameCount \u003C 3)\n            return (null, null);\n        var rest = clip.Frames[0][bone].Pos;\n        var travel = clip.Frames.Select(f =\u003E Vector3.Distance(f[bone].Pos, rest)).ToArray();\n        var peak = travel.Max();\n        if (peak \u003C 0.05f)\n            return (null, null);\n        var limit = peak * threshold;\n        var leave = Array.FindIndex(travel, d =\u003E d \u003E limit);\n        var back = Array.FindLastIndex(travel, d =\u003E d \u003E limit);\n        float Norm(int f) =\u003E f / (float)(clip.FrameCount - 1);\n        return (leave \u003E= 0 ? Norm(leave) : null, back \u003E= 0 \u0026\u0026 back \u003C clip.FrameCount - 1 ? Norm(back \u002B 1) : null);\n    }\n\n    private static float PeakTravel(WeaponAsset asset, Clip clip, int bone)\n    {\n        if (clip.FrameCount \u003C 2)\n            return 0f;\n        var rest = clip.Frames[0][bone].Pos;\n        var best = 0;\n        var max = 0f;\n        for (var f = 0; f \u003C clip.FrameCount; f\u002B\u002B)\n        {\n            var d = Vector3.Distance(clip.Frames[f][bone].Pos, rest);\n            if (d \u003E max) { max = d; best = f; }\n        }\n        return best / (float)(clip.FrameCount - 1);\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Setup/HandPoseSetup.cs","FileName":"HandPoseSetup.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System.Numerics;\nusing System.Text.Json;\nusing System.Text.Json.Serialization;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Hands;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing WeaponImporter.EditorTools.Core.Weapon;\n\nnamespace WeaponImporter.EditorTools.Core.Setup;\n\nusing Vector3 = System.Numerics.Vector3;\n\n/// \u003Csummary\u003ESerializable \u003Csee cref=\u0022HandPose\u0022/\u003E.\u003C/summary\u003E\npublic sealed class HandPoseSetup\n{\n    public float[] WristPosition { get; set; } = new float[3];\n    public float[] WristRotation { get; set; } = { 0, 0, 0, 1 };\n    public Dictionary\u003CFingerKind, float[]\u003E Flex { get; set; } = new();\n    public Dictionary\u003CFingerKind, float\u003E Spread { get; set; } = new();\n    public float ThumbOpposition { get; set; }\n\n    public static HandPoseSetup From(HandPose pose) =\u003E new()\n    {\n        WristPosition = V.A(pose.Wrist.Pos),\n        WristRotation = V.A(pose.Wrist.Rot),\n        Flex = pose.Flex.ToDictionary(kv =\u003E kv.Key, kv =\u003E kv.Value.ToArray()),\n        Spread = pose.Spread.ToDictionary(kv =\u003E kv.Key, kv =\u003E kv.Value),\n        ThumbOpposition = pose.ThumbOpposition,\n    };\n\n    public HandPose ToPose()\n    {\n        var pose = new HandPose(new XForm(V.Of(WristPosition), V.Q(WristRotation))) { ThumbOpposition = ThumbOpposition };\n        foreach (var (k, v) in Flex) pose.Flex[k] = v.ToArray();\n        foreach (var (k, v) in Spread) pose.Spread[k] = v;\n        return pose;\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Engine/BuiltInGrips.cs","FileName":"BuiltInGrips.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"namespace WeaponImporter.EditorTools.Engine;\n\n/// \u003Csummary\u003E\n/// Grip presets shipped with the importer, captured from open-licence first-person animation\n/// packs (see README credits). Generated by tests/WeaponImporter.Tests/BuiltInGripsGenerator.cs;\n/// kept as source so the library needs no data files at runtime.\n/// \u003C/summary\u003E\npublic static class BuiltInGrips\n{\n    public const string Json = @\u0022[\n  {\n    \u0022\u0022Name\u0022\u0022: \u0022\u0022AK-74 (first person) \\u00B7 right\u0022\u0022,\n    \u0022\u0022Source\u0022\u0022: \u0022\u0022\\u0022FPS AK-74m animations\\u0022 by Cransh, CC-BY-4.0\u0022\u0022,\n    \u0022\u0022Side\u0022\u0022: \u0022\u0022Right\u0022\u0022,\n    \u0022\u0022Style\u0022\u0022: \u0022\u0022Wrap\u0022\u0022,\n    \u0022\u0022Palm\u0022\u0022: [\n      -0.21685363,\n      0.24778111,\n      0.117897764\n    ],\n    \u0022\u0022Orientation\u0022\u0022: [\n      0.54129326,\n      -0.3987288,\n      0.4542242,\n      -0.5845488\n    ],\n    \u0022\u0022Directions\u0022\u0022: {\n      \u0022\u0022Thumb\u0022\u0022: [\n        0.63804275,\n        0.6942943,\n        0.33295208,\n        0.9264066,\n        0.3411738,\n        0.15928334,\n        0.9264066,\n        0.3411738,\n        0.15928331\n      ],\n      \u0022\u0022Index\u0022\u0022: [\n        0.97303915,\n        0.22906889,\n        0.026874194,\n        0.9371261,\n        0.3481497,\n        0.024216706,\n        0.93712616,\n        0.34814972,\n        0.024216676\n      ],\n      \u0022\u0022Middle\u0022\u0022: [\n        0.7635799,\n        0.61251384,\n        -0.20438331,\n        0.03134125,\n        0.9962124,\n        -0.08110789,\n        0.031340953,\n        0.9962124,\n        -0.08110778\n      ],\n      \u0022\u0022Ring\u0022\u0022: [\n        0.7943668,\n        0.59417975,\n        -0.12622197,\n        -0.06070585,\n        0.9943864,\n        0.08666353,\n        -0.06070572,\n        0.99438643,\n        0.086663395\n      ],\n      \u0022\u0022Pinky\u0022\u0022: [\n        0.79727346,\n        0.6031869,\n        -0.022817964,\n        0.13298786,\n        0.97028965,\n        0.20211966,\n        0.13298818,\n        0.9702896,\n        0.20211966\n      ]\n    },\n    \u0022\u0022WeaponType\u0022\u0022: \u0022\u0022Rifle\u0022\u0022\n  },\n  {\n    \u0022\u0022Name\u0022\u0022: \u0022\u0022AK-74 (first person) \\u00B7 left\u0022\u0022,\n    \u0022\u0022Source\u0022\u0022: \u0022\u0022\\u0022FPS AK-74m animations\\u0022 by Cransh, CC-BY-4.0\u0022\u0022,\n    \u0022\u0022Side\u0022\u0022: \u0022\u0022Left\u0022\u0022,\n    \u0022\u0022Style\u0022\u0022: \u0022\u0022Cradle\u0022\u0022,\n    \u0022\u0022Palm\u0022\u0022: [\n      -0.20595458,\n      0.016000982,\n      0.113755085\n    ],\n    \u0022\u0022Orientation\u0022\u0022: [\n      -0.80909944,\n      -0.12014536,\n      0.18176872,\n      0.5457868\n    ],\n    \u0022\u0022Directions\u0022\u0022: {\n      \u0022\u0022Thumb\u0022\u0022: [\n        0.69909,\n        0.5097619,\n        -0.501414,\n        0.8245201,\n        0.4467241,\n        -0.3472813,\n        0.8245201,\n        0.44672412,\n        -0.34728125\n      ],\n      \u0022\u0022Index\u0022\u0022: [\n        0.9241414,\n        0.17367288,\n        0.3402947,\n        0.89073247,\n        0.31763384,\n        0.32512218,\n        0.8907324,\n        0.317634,\n        0.32512227\n      ],\n      \u0022\u0022Middle\u0022\u0022: [\n        0.8958153,\n        0.33235422,\n        0.29505205,\n        0.6341079,\n        0.743513,\n        0.21235739,\n        0.634108,\n        0.74351287,\n        0.21235734\n      ],\n      \u0022\u0022Ring\u0022\u0022: [\n        0.8457776,\n        0.4977336,\n        0.19215004,\n        0.13906185,\n        0.98987985,\n        0.028280184,\n        0.13906161,\n        0.9898799,\n        0.028280172\n      ],\n      \u0022\u0022Pinky\u0022\u0022: [\n        0.63530046,\n        0.7659571,\n        0.09850433,\n        -0.29930398,\n        0.9246807,\n        -0.23533556,\n        -0.2993038,\n        0.9246807,\n        -0.23533545\n      ]\n    },\n    \u0022\u0022WeaponType\u0022\u0022: \u0022\u0022Rifle\u0022\u0022\n  },\n  {\n    \u0022\u0022Name\u0022\u0022: \u0022\u0022Uzi (first person) \\u00B7 right\u0022\u0022,\n    \u0022\u0022Source\u0022\u0022: \u0022\u0022Uzi first-person animations by 1Matzh\u0022\u0022,\n    \u0022\u0022Side\u0022\u0022: \u0022\u0022Right\u0022\u0022,\n    \u0022\u0022Style\u0022\u0022: \u0022\u0022Wrap\u0022\u0022,\n    \u0022\u0022Palm\u0022\u0022: [\n      -0.23954436,\n      0.25670823,\n      0.01567302\n    ],\n    \u0022\u0022Orientation\u0022\u0022: [\n      -0.6363334,\n      0.2761651,\n      -0.46779382,\n      0.5477059\n    ],\n    \u0022\u0022Directions\u0022\u0022: {\n      \u0022\u0022Thumb\u0022\u0022: [\n        0.871179,\n        0.4748856,\n        -0.12462307,\n        0.8887276,\n        0.3952979,\n        -0.23216996,\n        0.8887276,\n        0.39529768,\n        -0.23217005\n      ],\n      \u0022\u0022Index\u0022\u0022: [\n        0.98904425,\n        0.11524666,\n        -0.09224774,\n        0.4908976,\n        0.84187347,\n        -0.22420658,\n        0.4908973,\n        0.84187365,\n        -0.22420655\n      ],\n      \u0022\u0022Middle\u0022\u0022: [\n        0.6676163,\n        0.60718954,\n        -0.4308241,\n        -0.5987688,\n        0.79672736,\n        0.08186344,\n        -0.59876865,\n        0.7967274,\n        0.0818634\n      ],\n      \u0022\u0022Ring\u0022\u0022: [\n        0.62776995,\n        0.68354994,\n        -0.37237677,\n        -0.5002942,\n        0.8619599,\n        0.08204282,\n        -0.500294,\n        0.8619599,\n        0.08204284\n      ],\n      \u0022\u0022Pinky\u0022\u0022: [\n        0.73244727,\n        0.6569236,\n        -0.1788083,\n        0.13267002,\n        0.9899125,\n        -0.049719814,\n        0.13267054,\n        0.9899124,\n        -0.049719706\n      ]\n    },\n    \u0022\u0022WeaponType\u0022\u0022: \u0022\u0022Smg\u0022\u0022\n  },\n  {\n    \u0022\u0022Name\u0022\u0022: \u0022\u0022Uzi (first person) \\u00B7 left\u0022\u0022,\n    \u0022\u0022Source\u0022\u0022: \u0022\u0022Uzi first-person animations by 1Matzh\u0022\u0022,\n    \u0022\u0022Side\u0022\u0022: \u0022\u0022Left\u0022\u0022,\n    \u0022\u0022Style\u0022\u0022: \u0022\u0022Cradle\u0022\u0022,\n    \u0022\u0022Palm\u0022\u0022: [\n      -0.27904075,\n      -0.0528938,\n      0.1627435\n    ],\n    \u0022\u0022Orientation\u0022\u0022: [\n      0.66920006,\n      0.11822077,\n      -0.16324258,\n      -0.7152251\n    ],\n    \u0022\u0022Directions\u0022\u0022: {\n      \u0022\u0022Thumb\u0022\u0022: [\n        0.95815724,\n        0.23623316,\n        -0.16164333,\n        0.94813514,\n        0.21088736,\n        -0.2378366,\n        0.9481351,\n        0.21088766,\n        -0.23783667\n      ],\n      \u0022\u0022Index\u0022\u0022: [\n        0.8309968,\n        0.33160543,\n        0.44663435,\n        -0.35073477,\n        0.85627484,\n        0.37918139,\n        -0.3507347,\n        0.85627484,\n        0.37918139\n      ],\n      \u0022\u0022Middle\u0022\u0022: [\n        0.77723044,\n        0.38221577,\n        0.49982405,\n        -0.4313805,\n        0.8973259,\n        -0.093366124,\n        -0.43138018,\n        0.897326,\n        -0.09336614\n      ],\n      \u0022\u0022Ring\u0022\u0022: [\n        0.69433063,\n        0.56967634,\n        0.43974286,\n        -0.36678955,\n        0.8908167,\n        -0.2681625,\n        -0.3667896,\n        0.8908166,\n        -0.26816252\n      ],\n      \u0022\u0022Pinky\u0022\u0022: [\n        0.7428318,\n        0.66165394,\n        0.10205394,\n        -0.36805674,\n        0.89733946,\n        -0.24354905,\n        -0.3680566,\n        0.8973396,\n        -0.24354899\n      ]\n    },\n    \u0022\u0022WeaponType\u0022\u0022: \u0022\u0022Smg\u0022\u0022\n  }\n]\u0022;\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Engine/EngineLog.cs","FileName":"EngineLog.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"using Editor;\nusing Sandbox;\n\nnamespace WeaponImporter.EditorTools.Engine;\n\n/// \u003Csummary\u003EReads the editor log file (the only place compile errors show up).\u003C/summary\u003E\npublic static class EngineLog\n{\n    public static string LogPath\n    {\n        get\n        {\n            foreach ( var dir in new[] { Environment.CurrentDirectory, AppContext.BaseDirectory, System.IO.Path.GetDirectoryName( Environment.ProcessPath ?? \u0022\u0022 ) ?? \u0022\u0022 } )\n            {\n                var candidate = System.IO.Path.Combine( dir, \u0022logs\u0022, \u0022sbox-dev.log\u0022 );\n                if ( System.IO.File.Exists( candidate ) )\n                    return candidate;\n                var parent = System.IO.Path.GetDirectoryName( dir.TrimEnd( \u0027\\\\\u0027, \u0027/\u0027 ) );\n                if ( parent is not null \u0026\u0026 System.IO.File.Exists( System.IO.Path.Combine( parent, \u0022logs\u0022, \u0022sbox-dev.log\u0022 ) ) )\n                    return System.IO.Path.Combine( parent, \u0022logs\u0022, \u0022sbox-dev.log\u0022 );\n            }\n            return \u0022\u0022;\n        }\n    }\n\n    public static long Length()\n    {\n        try\n        {\n            var path = LogPath;\n            return path.Length \u003E 0 ? new System.IO.FileInfo( path ).Length : 0;\n        }\n        catch ( Exception )\n        {\n            return 0;\n        }\n    }\n\n    public static List\u003Cstring\u003E Since( long offset )\n    {\n        var lines = new List\u003Cstring\u003E();\n        try\n        {\n            var path = LogPath;\n            if ( path.Length == 0 )\n                return lines;\n            using var fs = new System.IO.FileStream( path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite | System.IO.FileShare.Delete );\n            if ( offset \u003E fs.Length )\n                offset = 0;\n            fs.Seek( offset, System.IO.SeekOrigin.Begin );\n            using var reader = new System.IO.StreamReader( fs );\n            string line;\n            while ( (line = reader.ReadLine()) is not null )\n                lines.Add( line );\n        }\n        catch ( Exception )\n        {\n        }\n        return lines;\n    }\n\n    /// \u003Csummary\u003EError-looking lines that mention the file, ModelDoc or the resource compiler (last 12).\u003C/summary\u003E\n    public static List\u003Cstring\u003E ErrorsFor( IEnumerable\u003Cstring\u003E lines, string fileName )\n    {\n        return lines\n            .Where( l =\u003E (l.Contains( \u0022error\u0022, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022failed\u0022, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022missing\u0022, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022warning\u0022, StringComparison.OrdinalIgnoreCase ))\n                \u0026\u0026 (l.Contains( fileName, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022resourcecompiler\u0022, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022ModelDoc\u0022, StringComparison.OrdinalIgnoreCase ) || l.Contains( \u0022dmx\u0022, StringComparison.OrdinalIgnoreCase )) )\n            .Select( l =\u003E l.Trim() )\n            .TakeLast( 12 )\n            .ToList();\n    }\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Engine/EngineMath.cs","FileName":"EngineMath.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"using Sandbox;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing N = System.Numerics;\n\nnamespace WeaponImporter.EditorTools.Engine;\n\n/// \u003Csummary\u003EConversions between the core\u0027s System.Numerics types and s\u0026amp;box types.\u003C/summary\u003E\npublic static class EngineMath\n{\n    public static Vector3 ToEngine( this N.Vector3 v ) =\u003E new( v.X, v.Y, v.Z );\n    public static N.Vector3 ToCore( this Vector3 v ) =\u003E new( v.x, v.y, v.z );\n    public static Rotation ToEngine( this N.Quaternion q ) =\u003E new( q.X, q.Y, q.Z, q.W );\n    public static N.Quaternion ToCore( this Rotation r ) =\u003E new( r.x, r.y, r.z, r.w );\n    public static Transform ToEngine( this XForm x ) =\u003E new( x.Pos.ToEngine(), x.Rot.ToEngine() );\n    public static XForm ToCore( this Transform t ) =\u003E new( t.Position.ToCore(), t.Rotation.ToCore() );\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/UI/Preview/WeaponViewport.FirstPerson.cs","FileName":"WeaponViewport.FirstPerson.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"using Editor;\nusing Sandbox;\nusing WeaponImporter.EditorTools.Core.Analysis;\nusing WeaponImporter.EditorTools.Core.Maths;\nusing CoreClip = WeaponImporter.EditorTools.Core.Rig.Clip;\nusing CorePose = WeaponImporter.EditorTools.Core.Rig.Pose;\n\nnamespace WeaponImporter.EditorTools.UI.Preview;\nusing WeaponImporter.EditorTools.Engine;\n\n/// \u003Csummary\u003E\n/// View-only first-person preview: the imported file\u0027s own animation (weapon and, when the file\n/// has them, its first-person arms) exactly as authored, before anything is compiled. The mesh is\n/// rigidly skinned to each triangle\u0027s dominant bone: one render piece per bone, moved every frame\n/// by boneWorld(frame) \u00B7 restWorld\u207B\u00B9, so nothing is uploaded per frame.\n/// \u003C/summary\u003E\npublic sealed partial class WeaponViewport\n{\n\t/// \u003Csummary\u003EKeeps huge files responsive (the Uzi pack is 42k triangles / 1072 bones).\u003C/summary\u003E\n\tprivate const int MaxFirstPersonTriangles = 120_000;\n\n\tprivate GameObject _fpRoot;\n\tprivate readonly List\u003C(int Bone, GameObject Piece)\u003E _fpPieces = new();\n\tprivate WeaponAnalysis _fpAnalysis;\n\tprivate XForm[] _fpInverseRest;\n\tprivate int _fpCameraBone = -1;\n\tprivate Material[] _fpMaterials;\n\tprivate int _fpFrame = -1;\n\tprivate CoreClip _fpClip;\n\n\t// The bone most of the weapon\u0027s triangles follow, and the pose shown this frame (canonical\n\t// space, which is also the first-person scene\u0027s world space).\n\tprivate int _fpWeaponBone = -1;\n\tprivate XForm[] _fpWorld;\n\n\t/// \u003Csummary\u003EThe weapon (canonical space) in the first-person scene as its animation moves it.\u003C/summary\u003E\n\tpublic Transform FirstPersonWeaponWorld =\u003E _fpWorld is { } world \u0026\u0026 _fpWeaponBone \u003E= 0 \u0026\u0026 _fpWeaponBone \u003C world.Length\n\t\t? XForm.Compose( world[_fpWeaponBone], _fpInverseRest[_fpWeaponBone] ).ToEngine()\n\t\t: Transform.Zero;\n\n\t/// \u003Csummary\u003E\n\t/// How a weapon part\u0027s bone has moved the canonical weapon this frame: the bone itself when it\n\t/// is the weapon\u0027s bone or one of its children (a slide, a bolt), else the weapon\u0027s bone (a\n\t/// point parented to the rig root must still follow the weapon). Null outside first person.\n\t/// \u003C/summary\u003E\n\tpublic Transform? FirstPersonBoneFrame( int bone )\n\t{\n\t\tif ( _fpWorld is not { } world || _fpWeaponBone \u003C 0 )\n\t\t\treturn null;\n\t\tvar skeleton = _fpAnalysis.Asset.Skeleton;\n\t\tvar follow = _fpWeaponBone;\n\t\tfor ( var b = bone; b \u003E= 0 \u0026\u0026 b \u003C skeleton.Count; b = skeleton[b].ParentIndex )\n\t\t\tif ( b == _fpWeaponBone )\n\t\t\t{\n\t\t\t\tfollow = bone;\n\t\t\t\tbreak;\n\t\t\t}\n\t\treturn XForm.Compose( world[follow], _fpInverseRest[follow] ).ToEngine();\n\t}\n\n\t// The file\u0027s own arms as anatomical segments (upper arm, forearm, finger joints).\n\tprivate readonly List\u003C(int Parent, int Bone)\u003E _fpArmSegments = new();\n\n\t/// \u003Csummary\u003EArm bones worth drawing in first person: forearms, hands and fingers (no body, no camera).\u003C/summary\u003E\n\tprivate bool IsOwnArmDisplayBone( int bone )\n\t{\n\t\tvar skeleton = _fpAnalysis?.Asset.Skeleton;\n\t\treturn skeleton is not null \u0026\u0026 bone \u003E= 0 \u0026\u0026 bone \u003C skeleton.Count \u0026\u0026 !IsBodyBone( skeleton, bone )\n\t\t\t\u0026\u0026 !skeleton[bone].Name.Contains( \u0022camera\u0022, StringComparison.OrdinalIgnoreCase );\n\t}\n\n\t/// \u003Csummary\u003EA bone of the imported file in the first-person scene this frame.\u003C/summary\u003E\n\tpublic Vector3? FirstPersonBone( int bone ) =\u003E _fpWorld is { } world \u0026\u0026 bone \u003E= 0 \u0026\u0026 bone \u003C world.Length ? world[bone].Pos.ToEngine() : null;\n\n\tpublic bool FirstPerson =\u003E CameraMode == ViewportCamera.FirstPerson;\n\n\t/// \u003Csummary\u003E\n\t/// First person with the file\u0027s own arms (its first-person rig plays as authored). Weapons without\n\t/// arms show first person through the character\u0027s eyes instead: its arms, the fitted grip and the\n\t/// same correction as third person.\n\t/// \u003C/summary\u003E\n\tpublic bool OwnArmsView =\u003E FirstPerson \u0026\u0026 (_c.Analysis?.ArmBones.Count ?? 0) \u003E 0;\n\n\t/// \u003Csummary\u003EThe weapon\u0027s own clip for a role (or the role it falls back to), or null.\u003C/summary\u003E\n\tpublic CoreClip WeaponClip( AnimationRole role )\n\t{\n\t\tvar setup = _c.Setup;\n\t\tvar asset = _c.Analysis?.Asset;\n\t\tif ( setup is null || asset is null )\n\t\t\treturn null;\n\t\tfor ( AnimationRole? r = role; r is { } current; r = AnimationRoles.Fallback( current ) )\n\t\t\tif ( setup.WeaponAnimations.TryGetValue( current, out var b ) \u0026\u0026 !string.IsNullOrEmpty( b.Clip ) \u0026\u0026 asset.FindClip( b.Clip ) is { FrameCount: \u003E 0 } clip )\n\t\t\t\treturn clip;\n\t\treturn null;\n\t}\n\n\tprivate void EnsureFirstPersonPieces()\n\t{\n\t\tvar analysis = _c.Analysis;\n\t\tif ( analysis is null || ReferenceEquals( analysis, _fpAnalysis ) \u0026\u0026 ReferenceEquals( _fpMaterials, _materials ) \u0026\u0026 _fpRoot.IsValid() )\n\t\t\treturn;\n\t\t_fpAnalysis = analysis;\n\t\t_fpMaterials = _materials;\n\t\t_fpRoot?.Destroy();\n\t\t_fpPieces.Clear();\n\t\t_fpRoot = new GameObject( true, \u0022first person\u0022 );\n\n\t\tvar asset = analysis.Asset;\n\t\tvar mesh = asset.Mesh;\n\t\tvar skeleton = asset.Skeleton;\n\t\tvar byBone = WeaponImporter.EditorTools.Core.Rig.ViewmodelParts.TrianglesByBone( analysis, Math.Max( 1, (mesh.TriangleCount \u002B MaxFirstPersonTriangles - 1) / MaxFirstPersonTriangles ) );\n\t\tforeach ( var (bone, triangles) in byBone )\n\t\t{\n\t\t\tvar piece = new GameObject( _fpRoot, true, skeleton.Count \u003E 0 ? skeleton[bone].Name : \u0022mesh\u0022 );\n\t\t\tvar renderer = piece.AddComponent\u003CModelRenderer\u003E();\n\t\t\trenderer.Model = PreviewModels.Build( mesh, triangles, _materials );\n\t\t\t_fpPieces.Add( (bone, piece) );\n\t\t}\n\n\t\t_fpInverseRest = new XForm[skeleton.Count];\n\t\tfor ( var i = 0; i \u003C skeleton.Count; i\u002B\u002B )\n\t\t\t_fpInverseRest[i] = skeleton.RestWorld[i].Inverse();\n\t\t_fpCameraBone = WeaponImporter.EditorTools.Core.Generation.FirstPersonRig.FindCamera( analysis );\n\t\t// Without a camera bone, the eye the baked viewmodel uses (the file\u0027s origin, the character\u0027s eyes...).\n\t\tvar rig = analysis.ArmBones.Count \u003E 0 ? WeaponImporter.EditorTools.Core.Generation.FirstPersonRig.Build( analysis ) : null;\n\t\t_fpRigEye = _fpCameraBone \u003C 0 ? rig?.Eye.ToEngine() : null;\n\t\t// The camera\u0027s viewing axes as the baked viewmodel uses them.\n\t\t_fpCameraAxes = rig is not null \u0026\u0026 _fpCameraBone \u003E= 0 ? rig.CameraAxes.ToEngine() : null;\n\t\t_fpFrame = -1;\n\t\t_fpClip = null;\n\t\t_fpWorld = null;\n\t\t_fpArmSegments.Clear();\n\t\tforeach ( var side in new[] { WeaponImporter.EditorTools.Core.Hands.Side.Right, WeaponImporter.EditorTools.Core.Hands.Side.Left } )\n\t\t{\n\t\t\tif ( analysis.ArmBones.Count == 0 || WeaponImporter.EditorTools.Core.Hands.HandRig.Build( skeleton, side ) is not { } arm || !analysis.ArmBones.Contains( arm.Hand ) )\n\t\t\t\tcontinue;\n\t\t\t_fpArmSegments.Add( (arm.UpperArm, arm.LowerArm) );\n\t\t\t_fpArmSegments.Add( (arm.LowerArm, arm.Hand) );\n\t\t\tforeach ( var finger in arm.Fingers )\n\t\t\t{\n\t\t\t\tvar previous = arm.Hand;\n\t\t\t\tforeach ( var joint in finger.Joints )\n\t\t\t\t{\n\t\t\t\t\t_fpArmSegments.Add( (previous, joint) );\n\t\t\t\t\tprevious = joint;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_fpWeaponBone = analysis.WeaponTriangles.Length == 0 || skeleton.Count == 0 ? -1\n\t\t\t: analysis.WeaponTriangles.GroupBy( t =\u003E Math.Clamp( mesh.TriangleBone( t ), 0, skeleton.Count - 1 ) ).MaxBy( g =\u003E g.Count() )!.Key;\n\t}\n\n\tprivate static bool IsBodyBone( WeaponImporter.EditorTools.Core.Rig.Skeleton skeleton, int bone ) =\u003E WeaponImporter.EditorTools.Core.Rig.ViewmodelParts.IsBodyBone( skeleton, bone );\n\n\t/// \u003Csummary\u003EOne first-person frame: advance time, pose the pieces, place the camera.\u003C/summary\u003E\n\tprivate void TickFirstPerson( float dt )\n\t{\n\t\tEnsureFirstPersonPieces();\n\t\tif ( _fpRoot.IsValid() )\n\t\t\t_fpRoot.Enabled = true;\n\t\tvar role = _c.Role;\n\t\tvar clip = WeaponClip( role );\n\t\tif ( _c.Playing )\n\t\t{\n\t\t\tif ( _c.RestartRequested )\n\t\t\t{\n\t\t\t\t_c.RestartRequested = false;\n\t\t\t\t_c.Time = _c.Time \u003E= 0.999f ? 0f : _c.Time;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t_c.Time \u002B= dt * _c.Speed / Seconds( role );\n\t\t\t\tif ( _c.Time \u003E= 1f )\n\t\t\t\t{\n\t\t\t\t\tif ( _c.Loop || AnimationRoles.Loops( role ) )\n\t\t\t\t\t\t_c.Time %= 1f;\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_c.Time = 1f;\n\t\t\t\t\t\t_c.Playing = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tTickScene( dt );\n\n\t\tvar skeleton = _fpAnalysis?.Asset.Skeleton;\n\t\tif ( skeleton is null || skeleton.Count == 0 )\n\t\t\treturn;\n\t\tvar frame = clip is null ? -1 : Math.Clamp( (int)MathF.Round( _c.Time * (clip.FrameCount - 1) ), 0, clip.FrameCount - 1 );\n\t\tif ( frame != _fpFrame || !ReferenceEquals( clip, _fpClip ) )\n\t\t{\n\t\t\t_fpFrame = frame;\n\t\t\t_fpClip = clip;\n\t\t\tvar world = clip is null ? skeleton.RestWorld.ToArray() : new CorePose( clip.Frames[frame] ).ToWorld( skeleton );\n\t\t\t_fpWorld = world;\n\t\t\tforeach ( var (bone, piece) in _fpPieces )\n\t\t\t\tif ( piece.IsValid() )\n\t\t\t\t\tpiece.WorldTransform = XForm.Compose( world[bone], _fpInverseRest[bone] ).ToEngine();\n\t\t\t_fpEye = _fpCameraBone \u003E= 0 ? world[_fpCameraBone].ToEngine() : (Transform?)null;\n\t\t}\n\t\tUpdateFirstPersonCamera();\n\t}\n\n\tprivate Transform? _fpEye;\n\tprivate Transform? _fpRigEye;\n\tprivate Rotation? _fpCameraAxes;\n\n\tprivate void UpdateFirstPersonCamera()\n\t{\n\t\tvar analysis = _fpAnalysis;\n\t\tif ( analysis is null || !Camera.IsValid() )\n\t\t\treturn;\n\t\tvar b = analysis.WeaponBounds;\n\t\tvar center = new Vector3( b.Center.X, b.Center.Y, b.Center.Z );\n\t\tvar length = MathF.Max( 4f, b.Size.X );\n\t\tVector3 eye, look;\n\t\tvar up = Vector3.Up;\n\t\tif ( _fpEye is { } cameraBone )\n\t\t{\n\t\t\t// The rig\u0027s own camera, looking the way it was authored. Exporters disagree on the\n\t\t\t// camera\u0027s axes: forward is the bone axis pointing most at the weapon, up the one\n\t\t\t// closest to world up. Aim at the weapon when no axis fits.\n\t\t\teye = cameraBone.Position;\n\t\t\tif ( _fpCameraAxes is { } fix )\n\t\t\t{\n\t\t\t\t// The baked viewmodel\u0027s view: the camera bone turned by its axis fix.\n\t\t\t\tvar view = cameraBone.Rotation * fix;\n\t\t\t\tlook = eye \u002B view.Forward * 10f;\n\t\t\t\tup = view.Up;\n\t\t\t\tgoto placed;\n\t\t\t}\n\t\t\tvar toWeapon = (center - eye).Normal;\n\t\t\tvar axes = new[] { Vector3.Forward, Vector3.Backward, Vector3.Left, Vector3.Right, Vector3.Up, Vector3.Down }\n\t\t\t\t.Select( a =\u003E cameraBone.Rotation * a ).ToArray();\n\t\t\tvar forward = axes.OrderByDescending( a =\u003E Vector3.Dot( a, toWeapon ) ).First();\n\t\t\tif ( Vector3.Dot( forward, toWeapon ) \u003E 0.6f )\n\t\t\t{\n\t\t\t\tup = axes.Where( a =\u003E MathF.Abs( Vector3.Dot( a, forward ) ) \u003C 0.5f ).OrderByDescending( a =\u003E Vector3.Dot( a, Vector3.Up ) ).First();\n\t\t\t\tlook = eye \u002B forward * 10f;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlook = center;\n\t\t\t}\n\t\t}\n\t\telse if ( _fpRigEye is { } rigEye )\n\t\t{\n\t\t\t// Upright the way the eye is (the weapon may be turned on its side in model space).\n\t\t\teye = rigEye.Position;\n\t\t\tlook = eye \u002B rigEye.Rotation.Forward * 10f;\n\t\t\tup = rigEye.Rotation.Up;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// No camera in the file (weapon only): a steady three-quarter view from behind the\n\t\t\t// right shoulder, far enough that moving parts stay in frame.\n\t\t\tvar radius = MathF.Max( length, MathF.Max( b.Size.Y, b.Size.Z ) ) * 0.75f;\n\t\t\tvar distance = MathX.SphereCameraDistance( radius, 60f );\n\t\t\tvar dir = new Vector3( -0.72f, -0.55f, 0.42f ).Normal;\n\t\t\teye = center \u002B dir * distance;\n\t\t\tlook = center;\n\t\t}\n\t\tplaced:\n\t\tCamera.FieldOfView = 60f;\n\t\tCamera.ZNear = _fpEye is null ? 0.5f : 2f; // clip the arm stubs right at a rig camera\n\t\tCamera.WorldPosition = eye;\n\t\tCamera.WorldRotation = Rotation.LookAt( (look - eye).Normal, up );\n\t}\n\n\tprivate void HideFirstPerson()\n\t{\n\t\tif ( _fpRoot.IsValid() )\n\t\t\t_fpRoot.Enabled = false;\n\t\tif ( Camera.IsValid() )\n\t\t\tCamera.ZNear = 1f;\n\t}\n\n\tprivate void DrawFirstPersonHud()\n\t{\n\t\tvar clip = WeaponClip( _c.Role );\n\t\tGizmo.Draw.Color = Theme.TextLight;\n\t\tvar text = clip is null\n\t\t\t? $\u0022First person \u00B7 {AnimationRoles.Label( _c.Role )} has no weapon clip (bind pose)\u0022\n\t\t\t: $\u0022First person \u00B7 {clip.Name} \u00B7 as imported, view only\u0022;\n\t\tGizmo.Draw.ScreenText( text, new Vector2( 12, 10 ), \u0022Roboto\u0022, 12, TextFlag.LeftTop );\n\t}\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/UI/Steps/TemplateDialog.cs","FileName":"TemplateDialog.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"using Editor;\nusing Sandbox;\nusing WeaponImporter.EditorTools.Core.Setup;\n\nnamespace WeaponImporter.EditorTools.UI.Steps;\nusing WeaponImporter.EditorTools.UI.Widgets;\n\n/// \u003Csummary\u003EAsks which parts of a configured weapon to copy onto the current one.\u003C/summary\u003E\npublic sealed class TemplateDialog : Dialog\n{\n\tprivate static readonly (TemplateParts Part, string Label, string Tip)[] Options =\n\t{\n\t\t(TemplateParts.AnimationMappings, \u0022Animation mapping\u0022, \u0022Which clip plays for each role, matched by role rather than by name\u0022),\n\t\t(TemplateParts.ThirdPerson, \u0022Third-person animations\u0022, \u0022What the character plays per role\u0022),\n\t\t(TemplateParts.Grips, \u0022Grips\u0022, \u0022Hand placement, carried over by its place on the weapon and re-measured on the new surface\u0022),\n\t\t(TemplateParts.Attachments, \u0022Muzzle and shell eject\u0022, \u0022Attachment points, adapted to the new barrel\u0022),\n\t\t(TemplateParts.Events, \u0022Events\u0022, \u0022Fire, magazine and bolt events; times are normalized to fit clips of any length\u0022),\n\t\t(TemplateParts.Contacts, \u0022Hand contacts\u0022, \u0022When the support hand lets go and grabs again\u0022),\n\t\t(TemplateParts.Ik, \u0022Fine tuning\u0022, \u0022Wrist preference, weapon nudge and smoothing\u0022),\n\t\t(TemplateParts.TypeDefaults, \u0022Type and defaults\u0022, \u0022Weapon type, trigger finger and support-hand choice\u0022),\n\t};\n\n\tpublic TemplateDialog( Widget parent, string templatePath, Action\u003CTemplateParts\u003E apply ) : base( parent )\n\t{\n\t\tWindow.Title = \u0022Copy from existing weapon\u0022;\n\t\tWindow.SetWindowIcon( \u0022content_copy\u0022 );\n\t\tWindow.SetModal( true, true );\n\t\tLayout = Layout.Column();\n\t\tLayout.Margin = 14;\n\t\tLayout.Spacing = 8;\n\t\tLayout.Add( UiStyle.Bold( new Label( System.IO.Path.GetFileName( templatePath ), this ) ) );\n\t\tLayout.Add( UiStyle.Muted( new Label( \u0022Choose what to take from it. Everything is adapted to this weapon\u0027s geometry and clips.\u0022, this ) { WordWrap = true }, small: true ) );\n\t\tLayout.AddSpacingCell( 4 );\n\t\tvar boxes = new List\u003C(TemplateParts, Checkbox)\u003E();\n\t\tforeach ( var (part, label, tip) in Options )\n\t\t\tboxes.Add( (part, Layout.Add( new Checkbox( label, this ) { Value = true, ToolTip = tip } )) );\n\t\tLayout.AddSpacingCell( 6 );\n\t\tvar row = Layout.AddRow();\n\t\trow.Spacing = 8;\n\t\trow.AddStretchCell();\n\t\trow.Add( new UiButton( this, \u0022Cancel\u0022, \u0022close\u0022, Close, \u0022Keep the current setup\u0022, 30 ) );\n\t\trow.Add( new Button.Primary( \u0022Apply\u0022, this ) { Icon = \u0022content_copy\u0022, Tint = Theme.Green, ToolTip = \u0022Copy the checked parts onto this weapon\u0022, Clicked = () =\u003E\n\t\t{\n\t\t\tvar parts = TemplateParts.None;\n\t\t\tforeach ( var (part, box) in boxes )\n\t\t\t\tif ( box.Value )\n\t\t\t\t\tparts |= part;\n\t\t\tClose();\n\t\t\tapply( parts );\n\t\t} } );\n\t\tWindow.MinimumSize = new Vector2( 360, 360 );\n\t\tWindow.Size = new Vector2( 400, 400 );\n\t}\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Code/WeaponImporter/Engine/ArmSolution.cs","FileName":"ArmSolution.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":444432,"IsPrivate":false,"Code":"namespace WeaponImporter.Engine;\n\n/// \u003Csummary\u003E\n/// Result of an analytic two-bone solve. Both rotations are deltas expressed in the space the\n/// input joints were given in (character model space in practice): \u003Csee cref=\u0022UpperDelta\u0022/\u003E\n/// rotates the whole arm about the shoulder, \u003Csee cref=\u0022LowerDelta\u0022/\u003E is applied afterwards and\n/// rotates the forearm (and everything below it) about the corrected elbow.\n/// \u003C/summary\u003E\npublic struct ArmSolution\n{\n    /// \u003Csummary\u003ERotation about the shoulder applied to the upper arm and all its descendants.\u003C/summary\u003E\n    public Rotation UpperDelta;\n\n    /// \u003Csummary\u003ERotation about the corrected elbow applied after \u003Csee cref=\u0022UpperDelta\u0022/\u003E.\u003C/summary\u003E\n    public Rotation LowerDelta;\n\n    /// \u003Csummary\u003ECorrected elbow position.\u003C/summary\u003E\n    public Vector3 Elbow;\n\n    /// \u003Csummary\u003ECorrected wrist position (equals the target unless it was out of reach).\u003C/summary\u003E\n    public Vector3 Wrist;\n\n    /// \u003Csummary\u003EDistance from the shoulder to the requested target.\u003C/summary\u003E\n    public float TargetDistance;\n\n    /// \u003Csummary\u003EFull reach of the chain (upper length \u002B lower length).\u003C/summary\u003E\n    public float Reach;\n\n    /// \u003Csummary\u003EHow far the wrist stays short of the target (0 when reached).\u003C/summary\u003E\n    public float Shortfall;\n}\n"},{"Ident":"notpointless.chomnr_weapon_importer","Path":"Editor/Core/Formats/Fbx/FbxAnimCurve.cs","FileName":"FbxAnimCurve.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":444432,"IsPrivate":false,"Code":"#nullable enable annotations\n\nusing System;\nusing System.Collections.Generic;\nusing System.Numerics;\n\nnamespace WeaponImporter.EditorTools.Core.Formats.Fbx;\n\nusing Vector3 = System.Numerics.Vector3; // s\u0026box compat: shadow engine\u0027s global-namespace Vector3 (see Editor/Core/Assembly.cs)\n\n/// \u003Csummary\u003EA single animation curve: keyframes for one scalar channel.\u003C/summary\u003E\npublic sealed class FbxAnimCurve\n{\n    /// \u003Csummary\u003EKTIME ticks per second (FBX constant).\u003C/summary\u003E\n    public const long TicksPerSecond = 46186158000L;\n\n    /// \u003Csummary\u003EKey times in KTIME ticks, ascending.\u003C/summary\u003E\n    public long[] KeyTimes { get; }\n\n    /// \u003Csummary\u003EKey values, parallel to \u003Csee cref=\u0022KeyTimes\u0022/\u003E.\u003C/summary\u003E\n    public float[] KeyValues { get; }\n\n    internal FbxAnimCurve(long[] keyTimes, float[] keyValues)\n    {\n        KeyTimes = keyTimes;\n        KeyValues = keyValues;\n    }\n\n    /// \u003Csummary\u003E\n    /// Samples the curve at a KTIME tick: linear interpolation between keys, constant\n    /// extrapolation outside the key range.\n    /// \u003C/summary\u003E\n    public float Evaluate(long ticks)\n    {\n        var times = KeyTimes;\n        int n = times.Length;\n        if (n == 0)\n            return 0f;\n        if (ticks \u003C= times[0])\n            return KeyValues[0];\n        if (ticks \u003E= times[n - 1])\n            return KeyValues[n - 1];\n\n        int hi = Array.BinarySearch(times, ticks);\n        if (hi \u003E= 0)\n            return KeyValues[hi];\n        hi = ~hi; // first index with time \u003E ticks; \u003E=1 and \u003C=n-1 here\n        int lo = hi - 1;\n        double span = times[hi] - times[lo];\n        double t = span \u003C= 0 ? 0.0 : (ticks - times[lo]) / span;\n        return (float)(KeyValues[lo] \u002B (KeyValues[hi] - KeyValues[lo]) * t);\n    }\n}\n"}]}