{"TotalCount":56,"Files":[{"Ident":"lastfish.particlesystemplus","Path":"Code/EmittersShapes/ConchplexCylinderEmitter.cs","FileName":"ConchplexCylinderEmitter.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing static Sandbox.VertexLayout;\r\n\r\nnamespace ConchplexEmitters;\r\n\r\n\r\n\r\n/// \u003Csummary\u003E\r\n/// Emits particles within a cylinder / disk\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Conchplex Cylinder Emitter\u0022 ), Category( \u0022Particles\u0022 ), Icon( \u0022donut_large\u0022 )]\r\npublic sealed class ConchplexCylinderEmitter : ConchplexEmitter\r\n{\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// 1 = spawns on edge, 0 = spawns in centre\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(0f, 1f), Step(0.01f)]\r\n\tpublic float DistanceBias { get; set; } = 0.5f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Direction \u002B intensity to bias particles to spawn towards\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(-1, 1)]\r\n\tpublic Vector3 PositionBias { get; set; } = 0f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Particles only spawn on the axes marked\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\tpublic AxisClampFlags AxisClamp { get; set; }\r\n\t/// \u003Csummary\u003E\r\n\t/// Which axis to clamp to / in between\r\n\t/// \u003C/summary\u003E\r\n\tpublic enum EmitFaces\r\n\t{\r\n\t\tBoth,\r\n\t\tSides,\r\n\t}\r\n\r\n\tpublic enum ThicknessMode\r\n\t{\r\n\t\tHollow,\r\n\t\thole\r\n\t}\r\n\r\n\t[Property]\r\n\tpublic float OutterRadius { get; set; } = 25f;\r\n\r\n\t[Property]\r\n\t[Range(0, 1)]\r\n\tpublic float Thickness { get; set; } = 0;\r\n\r\n\t[Property]\r\n\tpublic float height { get; set; } = 50f;\r\n\r\n\t[Property]\r\n\tpublic ThicknessMode ThickMode { get; set; }\r\n\r\n\r\n\t[Property, Group( \u0022Initial Velocity\u0022 )]\r\n\tpublic float VelocityFromCylinder = 0f;\r\n\r\n\tprivate float ThickRadius =\u003E MathX.Lerp(0, 1, Thickness);\r\n\tprivate float MidRadius =\u003E Thickness \u003E 0 ? (ThickRadius \u002B 1) * 0.5f : 0f;\r\n\tprivate float MidHeight =\u003E (1 \u002B Thickness) * 0.5f;\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\t// TODO - THIS IS FUCKED \r\n\r\n\t\tif (!Gizmo.IsSelected) return;\r\n\t\t\r\n\t\tGizmo.Draw.Color = Color.White.WithAlpha(0.5f);\r\n\t\tGizmo.GizmoDraw draw = Gizmo.Draw;\r\n\r\n\t\t// draw outter ring\r\n\t\tvar top = Vector3.Zero.WithZ(height * 0.5f);\r\n\t\tvar bottom = top.WithZ(-top.z);\r\n\t\tdraw.LineCylinder(bottom, top, OutterRadius, OutterRadius, 12);\r\n\r\n\t\tvar sThick = ThickRadius * OutterRadius;\r\n\t\tvar sMid = MidRadius * OutterRadius;\r\n\t\tvar sThickHeight = MidHeight * height; \r\n\r\n\t\r\n\t\t// draw thickness\r\n\t\tif( Thickness != 0 )\r\n\t\t{\r\n\t\t\tvar thickTop = ThickMode == ThicknessMode.Hollow ? top * Thickness : top;\r\n\t\t\tdraw.LineCylinder(thickTop.WithZ(-thickTop.z), thickTop, sThick, sThick, 12);\r\n\t\t}\r\n\r\n\r\n\t\t// draw distance bias\r\n\t\tif( DistanceBias != 0 )\r\n\t\t{\r\n\t\t\tdraw.Color = Color.Red.WithAlpha(0.5f);\r\n\t\t\tvar biasHeight = MathX.Lerp(sThickHeight * 0.5f, top.z, DistanceBias);\r\n\t\t\tvar thickBiasHeight = ThickMode == ThicknessMode.Hollow ? top.z * Thickness : top.z;\r\n\t\t\tvar fucksake = MathX.Lerp(sThickHeight * 0.5f, thickBiasHeight, DistanceBias);\r\n\t\t\tvar biasOutterRadius = MathX.Lerp(sMid, OutterRadius, DistanceBias);\r\n\t\t\tvar biasInnerRadius = MathX.Lerp(sMid, sThick, DistanceBias);\r\n\r\n\t\t\tif(ThickMode == ThicknessMode.Hollow)\r\n\t\t\t{\r\n\t\t\t\tvar biasHollowRadius = MathX.Lerp(sThick, OutterRadius, DistanceBias);\r\n\t\t\t\tvar biasHollowHeight = MathX.Lerp(top.z * Thickness, top.z, DistanceBias);\r\n\t\t\t\tdraw.LineCylinder(bottom.WithZ(-biasHollowHeight), top.WithZ(biasHollowHeight), biasHollowRadius, biasHollowRadius, 12);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tdraw.LineCylinder(bottom.WithZ(-biasHeight), top.WithZ(biasHeight), biasOutterRadius, biasOutterRadius, 12);\r\n\t\t\t\tdraw.LineCylinder(bottom.WithZ(-fucksake), top.WithZ(fucksake), biasInnerRadius, biasInnerRadius, 12);\r\n\t\t\t}\r\n\t\t\t\t\r\n\t\t}\r\n\r\n\t\t// draw Position Bias\r\n\t\tif (PositionBias.IsNearlyZero()) return;\r\n\t\tGizmo.Draw.Color = Color.Red.WithAlpha(0.8f);\r\n\t\tVector3 biasClamped = Vector3.Clamp(PositionBias, new Vector3(-1f), new Vector3(1f)) * (OutterRadius) * 1.1f;\r\n\t\tdraw.Arrow(Vector3.Zero, biasClamped, biasClamped.Length * 0.1f, biasClamped.Length * 0.1f);\r\n\t\t\r\n\r\n\t}\r\n\r\n\tpublic override Particle Emit(ParticleEffect target )\r\n\t{\r\n\r\n\t\t// Random point in a unity cylinder\r\n\t\tVector3 random = Random.Shared.VectorInCircle(1f);\r\n\t\trandom.z = Random.Shared.Float(-0.5f, 0.5f);\r\n\r\n\t\t// POSITION BIAS\r\n\t\tvar positionBias = PositionBias.Clamp(-1, 1);\r\n\t\trandom = random \u002B positionBias;\r\n\t\t// Correct bounds\r\n\t\tvar randomXY = new Vector2(random.x, random.y);\r\n\t\tVector2 randomXYNormal = randomXY.Normal;\r\n\t\trandom.x = random.x.Clamp(0f, randomXYNormal.x);\r\n\t\trandom.y = random.y.Clamp(0f, randomXYNormal.y);\r\n\t\trandom.z = random.z.Clamp(0.5f,-0.5f);\r\n\t\trandomXY = new Vector2(random.x, random.y);\r\n\r\n\t\t// get probabilty if a particle should be shoved to sides or top\r\n\t\tvar outterTopBottom = 2 * (OutterRadius* OutterRadius);\r\n\t\tvar innerTopBottom = 2 * ((OutterRadius * Thickness) * (OutterRadius * Thickness));\r\n\t\toutterTopBottom = positionBias.z != 0f ? outterTopBottom * 0.5f : outterTopBottom;\r\n\t\tinnerTopBottom = positionBias.z != 0f ? innerTopBottom * 0.5f : innerTopBottom;\r\n\r\n\t\tvar outterSides = (height * OutterRadius);\r\n\t\tvar innerSides = (height * (Thickness * OutterRadius));\r\n\r\n\t\tvar totalArea = outterTopBottom \u002B outterSides \u002B innerTopBottom \u002B innerSides;\r\n\t\tvar totalTopBottomArea = outterTopBottom \u002B innerTopBottom;\r\n\t\tvar sidesProbability = (outterSides \u002B innerSides) / totalArea;\r\n\t\tvar innerChance = (innerTopBottom \u002B innerSides) / totalArea;\r\n\r\n\r\n\r\n\t\t// TODO\r\n\t\t/*\r\n\t\t\t- get all points pushed to cylinder outter edges\r\n\t\t\t- get all points pushed to cylinder inner thickness edges\r\n\t\t\t- get all points pushed into the \u0022middle\u0022\r\n\r\n\t\t\t- new Random\r\n\t\t\t\t- lerp between Outter edge / Inner edge, based on old random.length\r\n\t\t\t- Max pos\r\n\t\t\t\t- if pointsXY \u0026 or pointsZ are greater than the mid bounds\r\n\t\t\t\t\tTRUE - use outter edge\r\n\t\t\t\t\tFALSE - use innter edge\r\n\t\t\t- Min pos\r\n\t\t\t\t- use middle points\r\n\t\t*/\r\n\r\n\t\t// Prepare min/max bounds for hollow/hole modes\r\n\t\tVector3 randomHollowMin = random, randomHollowMax = random;\r\n\t\tVector2 minHollowRandomXY = randomXY, maxHollowRandomXY = randomXY;\r\n\t\tVector3 randomHoleMax = random;\r\n\t\tVector2 maxHoleRandomXY = randomXY;\r\n\r\n\t\tfloat randVal = Random.Shared.Float();\r\n\r\n\t\t// Only calculate min/max for the current mode\r\n\t\tif (ThickMode == ThicknessMode.Hollow)\r\n\t\t{\r\n\t\t\tif (randVal \u003E sidesProbability)\r\n\t\t\t{\r\n\t\t\t\t// Top/bottom face\r\n\t\t\t\tbool isTop = random.z \u003E= 0;\r\n\t\t\t\tif (positionBias.z \u003E 0f) isTop = true;\r\n\t\t\t\telse if (positionBias.z \u003C 0f) isTop = false;\r\n\t\t\t\tfloat zPos = isTop ? 0.5f : -0.5f;\r\n\t\t\t\trandomHollowMin *= Thickness;\r\n\t\t\t\trandomHollowMin.z = zPos * Thickness;\r\n\t\t\t\trandomHollowMax.z = zPos;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// Sides\r\n\t\t\t\tminHollowRandomXY = minHollowRandomXY.Normal * Thickness;\r\n\t\t\t\trandomHollowMin.x = minHollowRandomXY.x;\r\n\t\t\t\trandomHollowMin.y = minHollowRandomXY.y;\r\n\t\t\t\trandomHollowMin.z *= Thickness;\r\n\t\t\t\tmaxHollowRandomXY = maxHollowRandomXY.Normal;\r\n\t\t\t\trandomHollowMax.x = maxHollowRandomXY.x;\r\n\t\t\t\trandomHollowMax.y = maxHollowRandomXY.y;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse // Hole mode\r\n\t\t{\r\n\t\t\tif (randVal \u003E sidesProbability)\r\n\t\t\t{\r\n\t\t\t\tbool isTop = random.z \u003E= 0;\r\n\t\t\t\tif (positionBias.z \u003E 0f) isTop = true;\r\n\t\t\t\telse if (positionBias.z \u003C 0f) isTop = false;\r\n\t\t\t\tfloat zPos = isTop ? 0.5f : -0.5f;\r\n\t\t\t\trandomHoleMax.z = zPos;\r\n\t\t\t\t// Remap for hole\r\n\t\t\t\trandomHoleMax.x = MathX.Remap(randomHoleMax.x, 0f, maxHoleRandomXY.Normal.x, maxHoleRandomXY.Normal.x * Thickness, maxHoleRandomXY.Normal.x);\r\n\t\t\t\trandomHoleMax.y = MathX.Remap(randomHoleMax.y, 0f, maxHoleRandomXY.Normal.y, maxHoleRandomXY.Normal.y * Thickness, maxHoleRandomXY.Normal.y);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tfloat innerSideChance = innerSides / totalArea;\r\n\t\t\t\tmaxHoleRandomXY = Random.Shared.Float() \u003C innerSideChance ? maxHoleRandomXY.Normal * Thickness : maxHoleRandomXY.Normal;\r\n\t\t\t\trandomHoleMax.x = maxHoleRandomXY.x;\r\n\t\t\t\trandomHoleMax.y = maxHoleRandomXY.y;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Interpolate between min/max for hollow/hole\r\n\t\tif (ThickMode == ThicknessMode.Hollow)\r\n\t\t{\r\n\t\t\tfloat bias = 1 - MathF.Pow(randVal, (Thickness \u002B 1) * 10);\r\n\t\t\trandom = Vector3.Lerp(randomHollowMin, randomHollowMax, bias);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\trandom.x = MathX.Remap(random.x, 0, randomXYNormal.x, randomXYNormal.x * Thickness, randomXYNormal.x);\r\n\t\t\trandom.y = MathX.Remap(random.y, 0, randomXYNormal.y, randomXYNormal.y * Thickness, randomXYNormal.y);\r\n\t\t}\r\n\r\n\t\t// Midpoint for distance bias\r\n\t\tVector3 randomMid = random;\r\n\t\trandomMid.z *= MidHeight;\r\n\t\trandomXY = randomXYNormal * MidRadius;\r\n\t\trandomMid.x = randomXY.x;\r\n\t\trandomMid.y = randomXY.y;\r\n\r\n\t\t// Distance bias\r\n\t\tif (DistanceBias \u003C= 0.5f)\r\n\t\t{\r\n\t\t\tfloat scaledBias = DistanceBias / 0.5f;\r\n\t\t\tvar lowBias = ThickMode == ThicknessMode.Hollow ? randomHollowMin : randomMid;\r\n\t\t\trandom = Vector3.Lerp(lowBias, random, scaledBias);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tvar maxRandom = ThickMode == ThicknessMode.Hollow ? randomHollowMax : randomHoleMax;\r\n\t\t\tfloat scaledBias = (DistanceBias - 0.5f) / 0.5f;\r\n\t\t\trandom = Vector3.Lerp(random, maxRandom, scaledBias);\r\n\t\t}\r\n\r\n\t\t// Scale to world\r\n\t\trandom.x *= OutterRadius;\r\n\t\trandom.y *= OutterRadius;\r\n\t\trandom.z *= height;\r\n\r\n\t\tvar cylinderVelocity = random.WithZ(0f).Normal;\r\n\r\n\t\tvar clampedParticlePoint = ProcessClampPosition(random, cylinderVelocity, AxisClamp);\r\n\t\tVector3 pos = (clampedParticlePoint.Position * LocalScale * WorldRotation) \u002B WorldPosition;\r\n\t\t\r\n\t\tParticle particle = target.Emit(pos, base.Delta);\r\n\t\tparticle.Velocity \u002B= (clampedParticlePoint.Velocity * WorldRotation) * VelocityFromCylinder;\r\n\r\n\t\treturn particle;\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/ModelShaderAttributes.cs","FileName":"ModelShaderAttributes.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing Sandbox;\r\nnamespace Sandbox;\r\n[Title(\u0022ModelShaderAttributes\u0022)]\r\n[Category(\u0022Shaders\u0022)]\r\n[Description(\u0022Let\u0027s you set the render attributes of the scene object of a ModelRenderer\u0022)]\r\npublic sealed class ModelShaderAttributes : Component, Component.ExecuteInEditor, IResetable\r\n{\r\n\t[Property] private ModelRenderer ModelRenderer { get; set; }\r\n\t[Property, Group( \u0022Floats1\u0022 )] public Dictionary\u003CString, ParticleFloat\u003E Floats { get; set; }\r\n\t[Property, Group(\u0022Floats2\u0022)] public Dictionary\u003CString, Vector2\u003E Floats2 { get; set; }\r\n\t[Property, Group(\u0022Colors\u0022)] public Dictionary\u003CString, Color\u003E Colors {get; set;}\r\n\t[Property, Group(\u0022Textures\u0022)] public Dictionary\u003CString, Texture\u003E Textures { get; set; }\r\n\t\r\n\t[Property, Group(\u0022Floats4\u0022)] public Dictionary\u003CString, Vector4\u003E Floats4 { get; set; }\r\n\t\r\n\t[Property, Group(\u0022DynamicCombos\u0022)] public Dictionary\u003CString, int\u003E DynamicCombos { get; set; }\r\n\t\r\n\t[Property] public bool Batchable { get; set; } = true;\r\n\t[Property] public float Duration { get; set; } = 1.0f;\r\n\t[Property] public bool Loop { get; set; } = false;\r\n\r\n\tpublic float Delta { get; set; }\r\n\r\n\tprivate TimeSince _elapsed;\r\n\r\n\tpublic void ResetTime()\r\n\t{\r\n\t\t_elapsed = 0;\r\n\t}\r\n\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tFloats = Floats == null ? new Dictionary\u003Cstring, ParticleFloat\u003E() : Floats;\r\n\t\tFloats2 = Floats2 == null ? new Dictionary\u003Cstring, Vector2\u003E() : Floats2;\r\n\t\tFloats4 = Floats4 == null ? new Dictionary\u003Cstring, Vector4\u003E() : Floats4;\r\n\t\tTextures = Textures == null ? new Dictionary\u003Cstring, Texture\u003E() : Textures;\r\n\t\tColors = Colors == null ? new Dictionary\u003CString, Color\u003E() : Colors;\r\n\t\tDynamicCombos = DynamicCombos == null ? new Dictionary\u003Cstring, int\u003E() : DynamicCombos;\r\n\t\t_elapsed = 0;\r\n\t\tApplyAttributes();\r\n\t\t\r\n\t}\r\n\t[Button]\r\n\tprivate void ReadAttributes()\r\n\t{\r\n\t\tif ( ModelRenderer.MaterialOverride == null || !FileSystem.Mounted.FileExists( ModelRenderer.MaterialOverride.Shader.ResourcePath )) return;\r\n\t\tvar parsedFloats = new Dictionary\u003Cstring, float\u003E();\r\n\t\tAttributesParser\u003Cfloat,Color\u003E parser = new AttributesParser\u003Cfloat,Color\u003E(new NativeAttributeTypeSet());\r\n\t\tparser.Floats = parsedFloats;\r\n\t\tparser.Floats2 = Floats2;\r\n\t\tparser.Floats4 = Floats4;\r\n\t\tparser.Textures = Textures;\r\n\t\tparser.DynamicCombos = DynamicCombos;\r\n\t\tparser.Colors = Colors;\r\n\t\tparser.ParseAttributes( ModelRenderer.MaterialOverride.Shader.ResourcePath );\r\n\r\n\t\tforeach (var pair in parsedFloats)\r\n\t\t{\r\n\t\t\tif (Floats.ContainsKey(pair.Key))\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tFloats.Add(pair.Key, new ParticleFloat { ConstantValue = pair.Value });\r\n\t\t}\r\n\t\t\r\n\t}\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t// _elapsed is a TimeSince, it already advances with real time on its own.\r\n\t\t// Don\u0027t manually add Time.Delta or it runs at 2x speed.\r\n\t\tApplyAttributes();\r\n\t}\r\n\r\n\tprivate void ApplyAttributes()\r\n\t{\r\n\t\tif ( ModelRenderer == null || !ModelRenderer.SceneObject.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\t// ModelRenderer.OnEnabled constructs a brand new SceneObject on every enable\r\n\t\t// cycle, and a fresh SceneObject defaults to Batchable = true. Setting this\r\n\t\t// once in OnStart loses it on the first disable/enable (and races\r\n\t\t// ModelRenderer.OnEnabled on the very first spawn).\r\n\t\t//\r\n\t\t// It has to hold for as long as we\u0027re stamping per-object attributes: the\r\n\t\t// engine batches by material, and an instanced draw has exactly one\r\n\t\t// attribute binding and one shader permutation. Two layers sharing a model\r\n\t\t// and material would collapse into one draw and a single layer\u0027s Colors /\r\n\t\t// DynamicCombos would win for all of them.\r\n\t\tModelRenderer.SceneObject.Batchable = Batchable;\r\n\r\n\t\tSetColorAttributes();\r\n\t\tSetFloatAttributes();\r\n\t\tSetFloat2Attributes();\r\n\t\tSetTexturesAttributes();\r\n\t\tSetFloat4Attributes();\r\n\t\tSetDynamicCombos();\r\n\t}\r\n\r\n\tprivate void SetDynamicCombos()\r\n\t{\r\n\t\tforeach ( var dynamicCombo in DynamicCombos )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.SetCombo( dynamicCombo.Key, dynamicCombo.Value );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetFloat4Attributes()\r\n\t{\r\n\t\tforeach ( var float4Attribute in Floats4 )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.Set( float4Attribute.Key, float4Attribute.Value );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetTexturesAttributes()\r\n\t{\r\n\t\tforeach ( var textureAttribute in Textures )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.Set( textureAttribute.Key, textureAttribute.Value );\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tprivate void SetColorAttributes()\r\n\t{\r\n\t\tforeach ( var colorAttribute in Colors )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.Set( colorAttribute.Key, colorAttribute.Value );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetFloatAttributes()\r\n\t{\r\n\t\tfloat t = 0f;\r\n\t\tif ( Duration \u003E 0f )\r\n\t\t{\r\n\t\t\tvar raw = (float)_elapsed / Duration;\r\n\t\t\tt = Loop ? raw % 1f : raw.Clamp( 0f, 1f );\r\n\t\t}\r\n\t\tforeach ( var float1 in Floats )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.Set( float1.Key, float1.Value.Evaluate( t, 6211 ) );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetFloat2Attributes()\r\n\t{\r\n\t\tforeach ( var float2 in Floats2 )\r\n\t\t{\r\n\t\t\tModelRenderer.SceneObject.Attributes.Set( float2.Key, float2.Value );\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"EmitterModelAttributes.cs","FileName":"EmitterModelAttributes.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing Sandbox;\r\nnamespace Sandbox;\r\n\r\n[Title( \u0022EmitterModelAttributes\u0022 )]\r\n[Category( \u0022Shaders\u0022 )]\r\n[Description(\r\n\t\u0022Drives the shader render attributes of a ShaderParticleModelRenderer over the lifetime of a ParticleEmitter. \u0022 \u002B\r\n\t\u0022The animated values are sampled from the emitter\u0027s normalized time and pushed into the renderer so every live particle shares them.\u0022 )]\r\npublic sealed class EmitterModelAttributes : Component, Component.ExecuteInEditor\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// The renderer whose shader attribute dictionaries get overwritten each frame.\r\n\t/// \u003C/summary\u003E\r\n\t[Property] public ShaderParticleModelRenderer Renderer { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The emitter whose lifetime (Duration \u002B Delay) drives the normalized time used to sample the curves.\r\n\t/// \u003C/summary\u003E\r\n\t[Property] public ParticleEmitter Emitter { get; set; }\r\n\r\n\t[Property, Group( \u0022Floats1\u0022 )] public Dictionary\u003CString, ParticleFloat\u003E Floats { get; set; }\r\n\t[Property, Group( \u0022Colors\u0022 )] public Dictionary\u003CString, Gradient\u003E Colors { get; set; }\r\n\t[Property, Group( \u0022Floats2\u0022 )] public Dictionary\u003CString, Vector2\u003E Floats2 { get; set; }\r\n\t[Property, Group( \u0022Floats4\u0022 )] public Dictionary\u003CString, Vector4\u003E Floats4 { get; set; }\r\n\t[Property, Group( \u0022Textures\u0022 )] public Dictionary\u003CString, Texture\u003E Textures { get; set; }\r\n\t[Property, Group( \u0022DynamicCombos\u0022 )] public Dictionary\u003CString, int\u003E DynamicCombos { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// When true, the emitter\u0027s Delay is included so the time stays at 0 during the delay.\r\n\t/// \u003C/summary\u003E\r\n\t[Property] public bool IncludeDelay { get; set; } = true;\r\n\r\n\t// Looping is driven by the emitter, never by a local flag. In the editor we always\r\n\t// loop so the animation previews continuously.\r\n\tprivate bool ShouldLoop =\u003E Scene.IsEditor || (Emitter.IsValid() \u0026\u0026 Emitter.Loop);\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tFloats ??= new Dictionary\u003Cstring, ParticleFloat\u003E();\r\n\t\tColors ??= new Dictionary\u003Cstring, Gradient\u003E();\r\n\t\tFloats2 ??= new Dictionary\u003Cstring, Vector2\u003E();\r\n\t\tFloats4 ??= new Dictionary\u003Cstring, Vector4\u003E();\r\n\t\tTextures ??= new Dictionary\u003Cstring, Texture\u003E();\r\n\t\tDynamicCombos ??= new Dictionary\u003Cstring, int\u003E();\r\n\r\n\t\tApplyAttributes();\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tApplyAttributes();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Normalized emitter time in [0,1] accounting for delay and looping.\r\n\t/// Driven entirely off the emitter\u0027s own playback clock so it can never drift out of\r\n\t/// sync, including on restart, playback scrubbing or time scaling.\r\n\t/// \u003C/summary\u003E\r\n\tprivate float ComputeTime()\r\n\t{\r\n\t\tif ( !Emitter.IsValid() )\r\n\t\t\treturn 0f;\r\n\r\n\t\tvar duration = Emitter.Duration.Evaluate( 0f, 0f );\r\n\t\tif ( duration \u003C= 0f )\r\n\t\t\treturn 0f;\r\n\r\n\t\tvar delay = IncludeDelay ? Emitter.Delay.Evaluate( 0f, 0f ) : 0f;\r\n\r\n\t\t// Emitter.time spans the whole [0, delay \u002B duration] lifetime; the animation only\r\n\t\t// starts once the delay has elapsed.\r\n\t\tvar elapsed = Emitter.time - delay;\r\n\t\tif ( elapsed \u003C= 0f )\r\n\t\t\treturn 0f;\r\n\r\n\t\tvar raw = elapsed / duration;\r\n\t\treturn ShouldLoop ? raw % 1f : raw.Clamp( 0f, 1f );\r\n\t}\r\n\r\n\tprivate void ApplyAttributes()\r\n\t{\r\n\t\tif ( !Renderer.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\t// The renderer initializes its dictionaries in its own OnStart; component start\r\n\t\t// order isn\u0027t guaranteed, so make sure they exist before we write into them.\r\n\t\tRenderer.Floats ??= new Dictionary\u003Cstring, ParticleFloat\u003E();\r\n\t\tRenderer.Colors ??= new Dictionary\u003Cstring, ParticleGradient\u003E();\r\n\t\tRenderer.Floats2 ??= new Dictionary\u003Cstring, ParticleVector2\u003E();\r\n\t\tRenderer.Floats4 ??= new Dictionary\u003Cstring, Vector4\u003E();\r\n\t\tRenderer.Textures ??= new Dictionary\u003Cstring, Texture\u003E();\r\n\t\tRenderer.DynamicCombos ??= new Dictionary\u003Cstring, int\u003E();\r\n\r\n\t\tvar t = ComputeTime();\r\n\r\n\t\tSetFloatAttributes( t );\r\n\t\tSetColorAttributes( t );\r\n\t\tSetFloat2Attributes();\r\n\t\tSetFloat4Attributes();\r\n\t\tSetTextureAttributes();\r\n\t\tSetDynamicCombos();\r\n\t}\r\n\r\n\tprivate void SetFloatAttributes( float t )\r\n\t{\r\n\t\tforeach ( var pair in Floats )\r\n\t\t{\r\n\t\t\tRenderer.Floats[pair.Key] = new ParticleFloat { ConstantValue = pair.Value.Evaluate( t, 6211 ) };\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetColorAttributes( float t )\r\n\t{\r\n\t\tforeach ( var pair in Colors )\r\n\t\t{\r\n\t\t\t// Color implicitly converts to a constant ParticleGradient.\r\n\t\t\tRenderer.Colors[pair.Key] = pair.Value.Evaluate( t );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetFloat2Attributes()\r\n\t{\r\n\t\tforeach ( var pair in Floats2 )\r\n\t\t\tRenderer.Floats2[pair.Key] = pair.Value;\r\n\t}\r\n\r\n\tprivate void SetFloat4Attributes()\r\n\t{\r\n\t\tforeach ( var pair in Floats4 )\r\n\t\t\tRenderer.Floats4[pair.Key] = pair.Value;\r\n\t}\r\n\r\n\tprivate void SetTextureAttributes()\r\n\t{\r\n\t\tforeach ( var pair in Textures )\r\n\t\t\tRenderer.Textures[pair.Key] = pair.Value;\r\n\t}\r\n\r\n\tprivate void SetDynamicCombos()\r\n\t{\r\n\t\tforeach ( var pair in DynamicCombos )\r\n\t\t\tRenderer.DynamicCombos[pair.Key] = pair.Value;\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"ParticleRingEmitterEven.cs","FileName":"ParticleRingEmitterEven.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\n\r\nnamespace Sandbox;\r\n[Title(\u0022Particle Ring Emitter Even\u0022)]\r\n[Category( \u0022Particles\u0022 )]\t\r\n[Description(\u0022Let\u0027s you ensure that the particles are placed evenly around the ring when emitted. Simply check the \\\u0022Even Angle\\\u0022 checkbox and you are set !\u0022)]\r\npublic class ParticleRingEmitterEven : ParticleEmitter\r\n{\r\n\t[Property] public ParticleFloat Radius { get; set; } = 50.0f;\r\n\t\r\n\t[Property] public Vector2 RadiusXy { get; set; }\r\n\t[Property] public ParticleFloat Thickness { get; set; } = 10.0f;\r\n\t[Property, Range( 0, 360 )] public ParticleFloat AngleStart { get; set; } = 0.0f;\r\n\t[Property, Range( 0, 360 )] public ParticleFloat Angle { get; set; } = 360.0f;\r\n\t[Property, Range( 0, 1 )] public ParticleFloat Flatness { get; set; } = 0.0f;\r\n\t[Property, Range( -100, 100 )] public ParticleFloat VelocityFromCenter { get; set; } = 0.0f;\r\n\t[Property, Range( -100, 100 )] public ParticleFloat VelocityFromRing { get; set; } = 0.0f;\r\n\t[Property] public bool EvenAngle { get; set; } = false;\r\n\t[Property] public bool FaceCenter { get; set; } = false;\r\n\r\n\tprivate float _angleStep = 0.0f;\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic override bool Emit( ParticleEffect target )\r\n\t{\r\n\t\t\r\n\t\tif ( target.Particles.Count == 0 )\r\n\t\t{\r\n\t\t\t_angleStep = 0.0f;\r\n\t\t}\r\n\t\t\r\n\t\tvar angle = 0f;\r\n\t\tif ( !EvenAngle )\r\n\t\t{\r\n\t\t\tangle = Random.Shared.Float( 0, Angle.Evaluate( Delta, EmitRandom ).DegreeToRadian() );\r\n\t\t\tangle \u002B= AngleStart.Evaluate( Delta, EmitRandom ).DegreeToRadian();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tangle = _angleStep;\r\n\t\t\tAngleStepBurst();\r\n\t\t}\r\n\r\n\t\tvar x = MathF.Sin( angle );\r\n\t\tvar y = MathF.Cos( angle );\r\n\r\n\t\tvar size = new Vector3( x, y, 0 )  * new Vector3(RadiusXy, 0);\r\n\t\tvar ringOffset = Vector3.Zero;\r\n\r\n\t\tvar thickness = Thickness.Evaluate( Delta, EmitRandom );\r\n\r\n\t\tif ( thickness \u003E 0 )\r\n\t\t{\r\n\t\t\tringOffset = Vector3.Random * thickness;\r\n\t\t\tringOffset.z *= (1 - Flatness.Evaluate( Delta, EmitRandom ));\r\n\r\n\t\t\tsize \u002B= ringOffset;\r\n\t\t}\r\n\r\n\t\tsize = (size * WorldScale) * WorldRotation;\r\n\r\n\t\tvar p = target.Emit( WorldPosition \u002B size, Delta );\r\n\t\t\r\n\t\tif ( p is not null )\r\n\t\t{\r\n\t\t\tp.Angles = Rotation.LookAt( Vector3.Direction( p.Position, WorldPosition ) ).Angles();\r\n\t\t\tvar velFromCenter = VelocityFromCenter.Evaluate( Delta, EmitRandom );\r\n\t\t\tif ( velFromCenter != 0 )\r\n\t\t\t{\r\n\t\t\t\tp.Velocity \u002B= (size.Normal * velFromCenter);\r\n\t\t\t}\r\n\r\n\t\t\tvar velFromRing = VelocityFromRing.Evaluate( Delta, EmitRandom );\r\n\t\t\tif ( velFromRing != 0 )\r\n\t\t\t{\r\n\t\t\t\tringOffset = (ringOffset * WorldScale) * WorldRotation;\r\n\t\t\t\tp.Velocity \u002B= (ringOffset.Normal * velFromRing);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\tprivate void AngleStepBurst()\r\n\t{\r\n\t\t_angleStep \u002B= Angle.Evaluate( Delta, EmitRandom ).DegreeToRadian() / Burst.Evaluate( Delta, EmitRandom );\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"ShaderParticleModelRenderer.cs","FileName":"ShaderParticleModelRenderer.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text.Json.Nodes;\r\nusing System.Text.Json.Serialization;\r\nusing Sandbox;\r\n\r\nnamespace Sandbox;\r\n\r\n[Title( \u0022Shader Particle Model Renderer\u0022 )]\r\n[Category( \u0022Particles\u0022 )]\r\n[Description(\r\n\t\u0022Adds the \\\u0022Particle Shader\\\u0022 feature which let\u0027s you set shader parameters on the particles model using the particle system !\u0022 )]\r\npublic class ShaderParticleModelRenderer : ParticleController, Component.ExecuteInEditor\r\n{\r\n\tprivate ParticleModelRenderer _particleModelRenderer { get; set; } = new ParticleModelRenderer();\r\n\r\n\t[Property]\r\n\tpublic bool Batchable { get; set; } = true;\r\n\r\n\t/**\r\n\t *  These are the dictionaries used to set the values for the render attributes in the particle system\r\n\t */\r\n\t[Property, FeatureEnabled(\u0022ParticleShader\u0022)]\r\n\tpublic bool ParticleShaderEnabled { get; set; } = true;\r\n\t\r\n\t\r\n\t[Property, Group( \u0022ColorParameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleGradient\u003E Colors { get; set; }\r\n\r\n\t[Property, Group( \u0022FloatParameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleFloat\u003E Floats { get; set; }\r\n\r\n\t[Property, Group( \u0022Float2Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleVector2\u003E Floats2 { get; set; }\r\n\r\n\t[Property, Group( \u0022Float3Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleVector3\u003E Floats3 { get; set; }\r\n\r\n\t[Property, Group( \u0022Float4Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, Vector4\u003E Floats4 { get; set; }\r\n\r\n\t[Property, Group( \u0022Textures\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, Texture\u003E Textures { get; set; }\r\n\r\n\t[Property, Group( \u0022DynamicCombos\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, int\u003E DynamicCombos { get; set; }\r\n\r\n\t\r\n\t\r\n\t/// \u003Csummary\u003E\r\n\t/// Particle rotation is world space: the emitter rotation does not orient the particle at all.\r\n\t/// When clear, the particle rotation follows the emitter rotation every frame (local space).\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool IsWorldRotation { get; set; } = false;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// World rotation, but seeded with the emitter rotation sampled at spawn: the particle is born\r\n\t/// facing the emitter\u0027s direction and is never re-oriented afterwards. Keeps rate-over-distance\r\n\t/// trails spawning in the right direction while staying in world space.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, ShowIf( nameof(IsWorldRotation), true )]\r\n\tpublic bool InheritSpawnRotation { get; set; } = false;\r\n\r\n\t[Property, FeatureEnabled( \u0022SheetSequence\u0022 )]\r\n\tpublic bool SheetSequence { get; set; } = false;\r\n\r\n\t[Property, Feature( \u0022SheetSequence\u0022 )]\r\n\tpublic float SheetSequenceSpeed { get; set; } = 1f;\r\n\t\r\n\t\r\n\r\n\t[RequireComponent] public new ParticleEffect ParticleEffect { get; set; }\r\n\r\n\t[Property, Order( -100 ), InlineEditor( Label = false ), Group( \u0022Advanced Rendering\u0022, StartFolded = true )]\r\n\tpublic RenderOptions RenderOptions =\u003E _particleModelRenderer.RenderOptions;\r\n\t\r\n\t\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tFloats = Floats == null ? new Dictionary\u003Cstring, ParticleFloat\u003E() : Floats;\r\n\t\tFloats2 = Floats2 == null ? new Dictionary\u003Cstring, ParticleVector2\u003E() : Floats2;\r\n\t\tFloats3 = Floats3 == null ? new Dictionary\u003Cstring, ParticleVector3\u003E() : Floats3;\r\n\t\tFloats4 = Floats4 == null ? new Dictionary\u003Cstring, Vector4\u003E() : Floats4;\r\n\t\tTextures = Textures == null ? new Dictionary\u003Cstring, Texture\u003E() : Textures;\r\n\t\tColors = Colors == null ? new Dictionary\u003CString, ParticleGradient\u003E() : Colors;\r\n\t\tDynamicCombos = DynamicCombos == null ? new Dictionary\u003Cstring, int\u003E() : DynamicCombos;\r\n\t\t\r\n\t\tif( ParticleShaderEnabled ) ReadAttributes();\r\n\t}\r\n\t\r\n\t[Button, Feature(\u0022ParticleShader\u0022)]\r\n\tprivate void ReadAttributes()\r\n\t{\r\n\t\tif ( MaterialOverride == null || !FileSystem.Mounted.FileExists( MaterialOverride.Shader.ResourcePath )) return;\r\n\t\tvar parsedFloats2 = new Dictionary\u003Cstring, Vector2\u003E();\r\n\t\tvar parsedFloats3 = new Dictionary\u003Cstring, Vector3\u003E();\r\n\t\tAttributesParser\u003CParticleFloat, ParticleGradient\u003E parser = new AttributesParser\u003CParticleFloat, ParticleGradient\u003E(new ParticleAttributeTypeSet());\r\n\t\tparser.Floats = Floats;\r\n\t\tparser.Floats2 = parsedFloats2;\r\n\t\tparser.Floats3 = parsedFloats3;\r\n\t\tparser.Floats4 = Floats4;\r\n\t\tparser.Textures = Textures;\r\n\t\tparser.DynamicCombos = DynamicCombos;\r\n\t\tparser.Colors = Colors;\r\n\t\tparser.ParseAttributes( MaterialOverride.Shader.ResourcePath );\r\n\r\n\t\tforeach ( var pair in parsedFloats2 )\r\n\t\t{\r\n\t\t\tif ( Floats2.ContainsKey( pair.Key ) ) continue;\r\n\t\t\tFloats2.Add( pair.Key, pair.Value ); // implicit Vector2 -\u003E ParticleVector2\r\n\t\t}\r\n\r\n\t\tforeach ( var pair in parsedFloats3 )\r\n\t\t{\r\n\t\t\tif ( Floats3.ContainsKey( pair.Key ) ) continue;\r\n\t\t\tFloats3.Add( pair.Key, pair.Value ); // implicit Vector3 -\u003E ParticleVector3\r\n\t\t}\r\n\t}\r\n\r\n\tpublic sealed class ModelEntry\r\n\t{\r\n\t\tprivate Model _model;\r\n\r\n\t\t[KeyProperty]\r\n\t\tpublic Model Model\r\n\t\t{\r\n\t\t\tget =\u003E _model;\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\tif ( _model == value )\r\n\t\t\t\t\treturn;\r\n\r\n\t\t\t\t_model = value;\r\n\r\n\t\t\t\tMaterialGroup = default;\r\n\t\t\t\tBodyGroups = _model?.DefaultBodyGroupMask ?? default;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t[Model.MaterialGroup, ShowIf( nameof(HasMaterialGroups), true )]\r\n\t\tpublic string MaterialGroup { get; set; }\r\n\r\n\t\t[Model.BodyGroupMask, ShowIf( nameof(HasBodyGroups), true )]\r\n\t\tpublic ulong BodyGroups { get; set; }\r\n\r\n\t\t[Hide, JsonIgnore] public bool HasMaterialGroups =\u003E Model?.MaterialGroupCount \u003E 0;\r\n\r\n\t\t[Hide, JsonIgnore] public bool HasBodyGroups =\u003E Model?.BodyParts.Sum( x =\u003E x.Choices.Count ) \u003E 1;\r\n\r\n\t\tpublic static implicit operator ModelEntry( Model model ) =\u003E new() { Model = model };\r\n\t}\r\n\r\n\t[Hide, Obsolete( \u0022Use Choices\u0022 )] public List\u003CModel\u003E Models { get; set; } = new();\r\n\r\n\t[Property] public List\u003CModelEntry\u003E Choices { get; set; } = new List\u003CModelEntry\u003E { Model.Cube };\r\n\r\n\t[Property] public Material MaterialOverride { get; set; }\r\n\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleX { get; set; } = 1;\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleY { get; set; } = 1;\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleZ { get; set; } = 1;\r\n\r\n\t[Property, FeatureEnabled( \u0022ScaleXYZ\u0022 )]\r\n\tpublic bool ApplyScaleXYZ { get; set; } = true;\r\n\r\n\t[Property] public ParticleFloat Scale { get; set; } = 1;\r\n\t\r\n\t[Property] public bool CastShadows { get; set; } = true;\r\n\r\n\t[Property] public Allignement Allignement { get; set; }\r\n\r\n\tprotected override void OnParticleCreated( Particle p )\r\n\t{\r\n\t\tvar particleModel = new CustomParticleModel( this );\r\n\t\tp.AddListener( particleModel, this );\r\n\t\t\r\n\t}\r\n\r\n\t// Scene objects of dead particles, kept hidden and handed to new particles of the same model instead of\r\n\t// creating and deleting one per particle. Particles spawn and die on the parallel particle step, so it\u0027s locked.\r\n\tprivate readonly Dictionary\u003CModel, Stack\u003CSceneObject\u003E\u003E _pool = new();\r\n\tprivate bool _poolOpen;\r\n\r\n\tinternal SceneObject RentSceneObject( Model model )\r\n\t{\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\tif ( _poolOpen \u0026\u0026 _pool.TryGetValue( model, out var stack ) )\r\n\t\t\t{\r\n\t\t\t\twhile ( stack.TryPop( out var so ) )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( !so.IsValid() ) continue;\r\n\r\n\t\t\t\t\tso.RenderingEnabled = true;\r\n\t\t\t\t\treturn so;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn new SceneObject( Scene.SceneWorld, model );\r\n\t}\r\n\r\n\tinternal void ReturnSceneObject( SceneObject so, Model model )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\tif ( _poolOpen )\r\n\t\t\t{\r\n\t\t\t\tso.RenderingEnabled = false;\r\n\r\n\t\t\t\tif ( !_pool.TryGetValue( model, out var stack ) )\r\n\t\t\t\t\t_pool[model] = stack = new Stack\u003CSceneObject\u003E();\r\n\r\n\t\t\t\tstack.Push( so );\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tso.Delete();\r\n\t}\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tlock ( _pool ) _poolOpen = true;\r\n\r\n\t\tbase.OnEnabled();\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\t// Live particles hand their scene objects back while the base disables, so close the pool after\r\n\t\tbase.OnDisabled();\r\n\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\t_poolOpen = false;\r\n\r\n\t\t\tforeach ( var stack in _pool.Values )\r\n\t\t\t{\r\n\t\t\t\tforeach ( var so in stack )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( so.IsValid() ) so.Delete();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_pool.Clear();\r\n\t\t}\r\n\t}\r\n\r\n\t// Read by every particle on the parallel step; sampled once per step here instead of once per particle\r\n\tinternal Vector3 StepWorldScale { get; private set; } = Vector3.One;\r\n\tinternal Rotation StepWorldRotation { get; private set; } = Rotation.Identity;\r\n\tinternal Vector3? StepCameraPosition { get; private set; }\r\n\r\n\tprotected override void OnBeforeStep( float delta )\r\n\t{\r\n\t\tbase.OnBeforeStep( delta );\r\n\r\n\t\tStepWorldScale = WorldScale;\r\n\t\tStepWorldRotation = WorldRotation;\r\n\t\tvar camera = Scene.Camera;\r\n\t\tStepCameraPosition = camera.IsValid() ? camera.WorldPosition : null;\r\n\r\n\t\tif ( ParticleShaderEnabled )\r\n\t\t\tAnimatedAttributes.Rebuild( Floats, Floats2, Floats3, Colors );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Shader attributes that change over a particle\u0027s life, shared by this renderer\u0027s particles.\r\n\t/// \u003C/summary\u003E\r\n\tinternal AnimatedAttributes AnimatedAttributes { get; } = new();\r\n\r\n\tpublic override int ComponentVersion =\u003E 2;\r\n\r\n\t[JsonUpgrader( typeof(ParticleModelRenderer), 1 )]\r\n\tstatic void Upgrader_v1( JsonObject obj )\r\n\t{\r\n\t\tif ( obj.TryGetPropertyValue( \u0022Models\u0022, out var node ) )\r\n\t\t{\r\n\t\t\tvar choices = new JsonArray();\r\n\r\n\t\t\tforeach ( var model in node.AsArray() )\r\n\t\t\t{\r\n\t\t\t\tif ( model is null )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tchoices.Add( new JsonObject { [\u0022Model\u0022] = model.ToString() } );\r\n\t\t\t}\r\n\r\n\t\t\tobj[\u0022Choices\u0022] = choices;\r\n\t\t\tobj.Remove( \u0022Models\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\t// Floats2 used to be a Dictionary\u003Cstring, Vector2\u003E (each value serialized as an\r\n\t// \u0022x,y\u0022 string). It is now a Dictionary\u003Cstring, ParticleVector2\u003E; convert each\r\n\t// entry into a ParticleVector2 with constant X/Y components.\r\n\t[JsonUpgrader( typeof(ShaderParticleModelRenderer), 2 )]\r\n\tstatic void Upgrader_v2( JsonObject obj )\r\n\t{\r\n\t\tif ( !obj.TryGetPropertyValue( \u0022Floats2\u0022, out var node ) || node is not JsonObject floats2 )\r\n\t\t\treturn;\r\n\r\n\t\tforeach ( var kv in floats2.ToList() )\r\n\t\t{\r\n\t\t\tif ( kv.Value is not JsonValue val || !val.TryGetValue\u003Cstring\u003E( out var str ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tvar parts = str.Split( \u0027,\u0027 );\r\n\t\t\tif ( parts.Length \u003C 2 )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tif ( !float.TryParse( parts[0].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var x ) ||\r\n\t\t\t     !float.TryParse( parts[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var y ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tfloats2[kv.Key] = new JsonObject { [\u0022X\u0022] = x, [\u0022Y\u0022] = y };\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n}\r\n\r\npublic enum Allignement\r\n{\r\n\tSimulationSpace,\r\n\tFaceCamera,\r\n\tFaceVelocity,\r\n\t\r\n}\r\n\r\n\r\n\r\n\r\n\r\npublic class CustomParticleModel : Particle.BaseListener\r\n{\r\n\tpublic ShaderParticleModelRenderer Renderer;\r\n\r\n\tpublic SceneObject so;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Emitter rotation sampled when the particle spawned. Used as the fixed base rotation when\r\n\t/// \u003Csee cref=\u0022ShaderParticleModelRenderer.InheritSpawnRotation\u0022/\u003E is set, so a particle inherits\r\n\t/// the emitter\u0027s orientation at birth but is not re-oriented afterwards.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Rotation _spawnRotation = Rotation.Identity;\r\n\r\n\tprivate ParticleAttributesSetter _particleAttributesSetter;\r\n\r\n\t// Last values pushed to the scene object; each set is a native call plus a change notification\r\n\t// Nullable so the first frame always sets them: a reused scene object still holds the last particle\u0027s values\r\n\tprivate Color? _tint;\r\n\tprivate bool? _castShadows;\r\n\tprivate int _renderOptionsMask = -1;\r\n\tprivate Material _material;\r\n\r\n\t// Model the scene object was rented for, to hand it back to the right pool\r\n\tprivate Model _model;\r\n\r\n\tpublic CustomParticleModel( ShaderParticleModelRenderer renderer )\r\n\t{\r\n\t\tRenderer = renderer;\r\n\t}\r\n\r\n\tpublic override void OnEnabled( Particle p )\r\n\t{\r\n\t\t_spawnRotation = Renderer.StepWorldRotation;\r\n\r\n\t\tvar entry = Random.Shared.FromList( Renderer.Choices );\r\n\t\tvar model = entry?.Model;\r\n\t\t_model = model ?? Model.Cube;\r\n\t\tso = Renderer.RentSceneObject( _model );\r\n\t\tso.Batchable = false;\r\n\t\tif ( model is not null )\r\n\t\t{\r\n\t\t\tso.MeshGroupMask = entry.BodyGroups;\r\n\t\t\tso.SetMaterialGroup( entry.MaterialGroup );\r\n\t\t}\r\n\r\n\t\tif ( Renderer.SheetSequence )\r\n\t\t{\r\n\t\t\tso.Attributes.Set( \u0022AnimSpeed\u0022, Renderer.SheetSequenceSpeed / p.LifeTimeRemaining );\r\n\t\t}\r\n\r\n\t\tif ( !Renderer.ParticleShaderEnabled ) return;\r\n\t\t_particleAttributesSetter = new ParticleAttributesSetter( so.Attributes, p );\r\n\t\tSetRenderAttributes();\r\n\t}\r\n\r\n\tpublic override void OnDisabled( Particle p )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\t\tRenderer.ReturnSceneObject( so, _model );\r\n\t\tso = null;\r\n\t}\r\n\r\n\tpublic override void OnUpdate( Particle p, float dt )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\r\n\r\n\t\tvar angles = ComputeRotation( p );\r\n\t\t\r\n\t\tvar scale = p.Size * Renderer.StepWorldScale;\r\n\t\tif ( Renderer.ApplyScaleXYZ )\r\n\t\t{\r\n\t\t\tscale *= EvaluateScale( p );\r\n\t\t}\r\n\r\n\t\tso.Transform = new Transform( p.Position, angles, scale * Renderer.Scale.Evaluate( p, 6211 ) );\r\n\t\tvar tint = p.Color.WithAlphaMultiplied( p.Alpha );\r\n\t\tif ( tint != _tint )\r\n\t\t{\r\n\t\t\tso.ColorTint = tint;\r\n\t\t\t_tint = tint;\r\n\t\t}\r\n\r\n\t\tif ( _castShadows != Renderer.CastShadows )\r\n\t\t{\r\n\t\t\tso.Flags.CastShadows = Renderer.CastShadows;\r\n\t\t\t_castShadows = Renderer.CastShadows;\r\n\t\t}\r\n\r\n\t\tif ( _material != Renderer.MaterialOverride )\r\n\t\t{\r\n\t\t\tso.SetMaterialOverride( Renderer.MaterialOverride );\r\n\t\t\t_material = Renderer.MaterialOverride;\r\n\t\t}\r\n\r\n\t\t// Constant attributes were set at spawn and stay on the scene object. While editing the scene\r\n\t\t// everything is re-set every frame, so inspector changes show on live particles straight away.\r\n\t\tif ( Renderer.ParticleShaderEnabled )\r\n\t\t{\r\n\t\t\tif ( Renderer.Scene.IsEditor ) _particleAttributesSetter.SetAttributes();\r\n\t\t\telse _particleAttributesSetter.SetAnimatedAttributes();\r\n\t\t}\r\n\t\t\r\n\r\n\t\t// Apply sets four native flags; only redo it when the options change\r\n\t\tvar renderOptions = Renderer.RenderOptions;\r\n\t\tif ( renderOptions != null )\r\n\t\t{\r\n\t\t\tvar mask = (renderOptions.Game ? 1 : 0) | (renderOptions.Overlay ? 2 : 0) | (renderOptions.Bloom ? 4 : 0) | (renderOptions.AfterUI ? 8 : 0);\r\n\t\t\tif ( mask != _renderOptionsMask )\r\n\t\t\t{\r\n\t\t\t\trenderOptions.Apply( so );\r\n\t\t\t\t_renderOptionsMask = mask;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t\r\n\r\n\r\n\tprivate Vector3 EvaluateScale( Particle p )\r\n\t{\r\n\t\t\r\n\t\tvar scaleX = Renderer.ScaleX.Evaluate( p, 6211 );\r\n\t\tvar scaleY = Renderer.ScaleY.Evaluate( p, 6211 );\r\n\t\tvar scaleZ = Renderer.ScaleZ.Evaluate( p, 6211 );\r\n\t\treturn new Vector3( scaleX, scaleY, scaleZ );\r\n\t}\r\n\r\n\r\n\tprivate Angles ComputeRotation(Particle p)\r\n\t{\r\n\t\tvar angles = new Rotation();\r\n\t\tswitch ( Renderer.Allignement )\r\n\t\t{\r\n\t\t\tcase Allignement.FaceCamera :\r\n\t\t\t\tif ( Renderer.StepCameraPosition is not { } cameraPosition ) break;\r\n\t\t\t\tvar dir = cameraPosition - p.Position;\r\n\t\t\t\tangles = Rotation.LookAt( dir, Vector3.Up ) * p.Angles.ToRotation();\r\n\t\t\t\tbreak;\r\n\t\t\tcase Allignement.FaceVelocity :\r\n\t\t\t\tangles = Rotation.LookAt( p.Velocity.Normal, Vector3.Up ) * p.Angles.ToRotation();\r\n\t\t\t\tbreak;\r\n\t\t\tcase Allignement.SimulationSpace :\r\n\t\t\t\tangles = BaseRotation().Angles();\r\n\t\t\t\tangles *= p.Angles;\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\treturn angles;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Base rotation the particle\u0027s own \u003Csee cref=\u0022Particle.Angles\u0022/\u003E are applied on top of, for\r\n\t/// \u003Csee cref=\u0022Allignement.SimulationSpace\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Rotation BaseRotation()\r\n\t{\r\n\t\tif ( !Renderer.IsWorldRotation )\r\n\t\t\treturn Renderer.StepWorldRotation; // follows the emitter every frame\r\n\r\n\t\treturn Renderer.InheritSpawnRotation ? _spawnRotation : Rotation.Identity;\r\n\t}\r\n\r\n\tprivate void SetRenderAttributes()\r\n\t{\r\n\t\t_particleAttributesSetter.Floats = Renderer.Floats;\r\n\t\t_particleAttributesSetter.Floats2 = Renderer.Floats2;\r\n\t\t_particleAttributesSetter.Floats3 = Renderer.Floats3;\r\n\t\t_particleAttributesSetter.Floats4 = Renderer.Floats4;\r\n\t\t_particleAttributesSetter.Textures = Renderer.Textures;\r\n\t\t_particleAttributesSetter.Colors = Renderer.Colors;\r\n\t\t_particleAttributesSetter.DynamicCombos = Renderer.DynamicCombos;\r\n\t\t_particleAttributesSetter.Animated = Renderer.AnimatedAttributes;\r\n\t\t_particleAttributesSetter.SetAttributes();\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"utils/attributes/ParticleAttributeTypeSet.cs","FileName":"ParticleAttributeTypeSet.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"namespace Sandbox;\r\n// The code in this file is ai generated\r\npublic class ParticleAttributeTypeSet : IAttributeTypeSet\u003CParticleFloat, ParticleGradient\u003E\r\n{\r\n\tpublic ParticleFloat GetDefaultFloat() =\u003E new ParticleFloat();\r\n\tpublic ParticleFloat ParseFloat( string value ) =\u003E new ParticleFloat(  ){ConstantValue =  float.Parse( value, System.Globalization.CultureInfo.InvariantCulture )};\r\n\tpublic ParticleGradient GetDefaultColor() =\u003E new ParticleGradient();\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"utils/ParticleVector2.cs","FileName":"ParticleVector2.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// A two component vector whose X and Y are \u003Csee cref=\u0022ParticleFloat\u0022/\u003Es, so each\r\n/// component can be a constant, a random range, or a curve evaluated per particle.\r\n/// Mirrors the engine\u0027s \u003Csee cref=\u0022ParticleVector3\u0022/\u003E for the float2 case.\r\n/// \u003C/summary\u003E\r\npublic class ParticleVector2\r\n{\r\n\t[Property] public ParticleFloat X { get; set; }\r\n\t[Property] public ParticleFloat Y { get; set; }\r\n\r\n\tpublic ParticleVector2()\r\n\t{\r\n\t\t// Default to constant-zero components so Evaluate never dereferences a null\r\n\t\t// ParticleFloat when the editor creates a fresh entry. JSON deserialization\r\n\t\t// overwrites these from the serialized X/Y.\r\n\t\tX = new ParticleFloat();\r\n\t\tY = new ParticleFloat();\r\n\t}\r\n\r\n\tpublic ParticleVector2( ParticleFloat x, ParticleFloat y )\r\n\t{\r\n\t\tX = x;\r\n\t\tY = y;\r\n\t}\r\n\r\n\tpublic Vector2 Evaluate( Particle particle, int seed )\r\n\t{\r\n\t\treturn new Vector2( X.Evaluate( particle, seed ), Y.Evaluate( particle, seed ) );\r\n\t}\r\n\r\n\tpublic static implicit operator ParticleVector2( Vector2 v ) =\u003E new ParticleVector2( v.x, v.y );\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/Controllers/TornadoForce.Cs","FileName":"TornadoForce.Cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// Tornado motion around an axis (default world up).\r\n/// Combines a tangential swirl (rotation around the axis) with a radial force\r\n/// that keeps particles confined to a funnel radius, so they form a rotating\r\n/// column instead of spiralling outward like a plain tangential vortex.\r\n/// Lift (upward motion) is optional - you can also drive it from initial velocity.\r\n/// \u003C/summary\u003E\r\npublic class TornadoForce() : ParticleController\r\n{\r\n    [Property]\r\n    public Vector3 VortexCenterOffset { get; set; }\r\n\r\n    [Property]\r\n    public Vector3 Axis { get; set; } = Vector3.Up;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// When true the Axis and center offset follow the controller\u0027s rotation/position,\r\n    /// so the tornado tilts and moves with the emitter. When false they are world-space.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public bool LocalSpace { get; set; } = false;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Target tangential speed around the axis. This is the rotation.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public ParticleFloat SwirlSpeed { get; set; } = 100f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Radius of the funnel the particles are pulled toward. Use a curve over\r\n    /// particle life to widen/narrow the tornado into a cone shape.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public ParticleFloat FunnelRadius { get; set; } = 40f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// How hard particles are pulled back toward FunnelRadius. Higher = tighter column.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public ParticleFloat RadialPull { get; set; } = 2f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Optional target upward speed along the axis. Leave 0 if you drive lift from velocity.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public ParticleFloat LiftSpeed { get; set; } = 0f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// How quickly velocity converges to the targets (swirl / radial / lift). Higher = snappier.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public ParticleFloat Responsiveness { get; set; } = 4f;\r\n\r\n    protected override void OnParticleStep(Particle particle, float delta)\r\n    {\r\n        var vortexCenter = LocalSpace\r\n            ? WorldTransform.PointToWorld(VortexCenterOffset)\r\n            : WorldPosition \u002B VortexCenterOffset;\r\n        var axis = (LocalSpace ? WorldTransform.NormalToWorld(Axis) : Axis).Normal;\r\n\r\n        var r = particle.Position - vortexCenter;\r\n\r\n        // Radial vector in the plane perpendicular to the axis (ignore height along the axis).\r\n        var rPlane = r - Vector3.Dot(r, axis) * axis;\r\n        var radius = rPlane.Length;\r\n        if (radius \u003C 0.0001f)\r\n            return;\r\n\r\n        var radialDir = rPlane / radius;                 // outward, unit\r\n        var tangent = Vector3.Cross(axis, radialDir);    // rotation direction, unit\r\n\r\n        var responsiveness = Responsiveness.Evaluate(particle, 71011);\r\n\r\n        // --- Swirl: drive tangential velocity toward SwirlSpeed ---\r\n        var swirlSpeed = SwirlSpeed.Evaluate(particle, 71012);\r\n        var curTangential = Vector3.Dot(particle.Velocity, tangent);\r\n        particle.Velocity \u002B= tangent * (swirlSpeed - curTangential) * responsiveness * delta;\r\n\r\n        // --- Confinement: drive radial velocity toward closing the gap to FunnelRadius ---\r\n        var funnelRadius = FunnelRadius.Evaluate(particle, 71013);\r\n        var radialPull = RadialPull.Evaluate(particle, 71014);\r\n        // Negative when outside the funnel (pull in), positive when inside (push out).\r\n        var targetRadial = (funnelRadius - radius) * radialPull;\r\n        var curRadial = Vector3.Dot(particle.Velocity, radialDir);\r\n        particle.Velocity \u002B= radialDir * (targetRadial - curRadial) * responsiveness * delta;\r\n\r\n        // --- Lift: drive velocity along the axis toward LiftSpeed (optional) ---\r\n        var liftSpeed = LiftSpeed.Evaluate(particle, 71015);\r\n        if (liftSpeed != 0f)\r\n        {\r\n            var curAxial = Vector3.Dot(particle.Velocity, axis);\r\n            particle.Velocity \u002B= axis * (liftSpeed - curAxial) * responsiveness * delta;\r\n        }\r\n    }\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/EmittersShapes/ConchplexDonutEmitter.cs","FileName":"ConchplexDonutEmitter.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace ConchplexEmitters;\r\n\r\npublic sealed class ConchplexDonutEmitter : ConchplexEmitter\r\n{\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// 1 = spawns on edge, 0 = spawns in centre\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(0f, 1f), Step(0.01f)]\r\n\tpublic float DistanceBias { get; set; } = 0.5f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Direction \u002B intensity to bias particles to spawn towards\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(-1, 1)]\r\n\tpublic Vector3 PositionBias { get; set; } = 0f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Bias partcles inwards or outwards on a each axis\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(-1, 1)]\r\n\tpublic Vector3 AxisBias { get; set; } = 0f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Particles only spawn on the axes marked\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\tpublic AxisClampFlags AxisClamp { get; set; }\r\n\r\n\t[Property]\r\n\tpublic float MainRadius { get; set; } = 20f;\r\n\r\n\t[Property]\r\n\tpublic float RingRadius { get; set; } = 7.5f;\r\n\r\n\t[Property]\r\n\t[Range(0f, 1f), Step(0.01f)]\r\n\tpublic float Thickness { get; set; } = 0f;\r\n\r\n\r\n\t[Property, Group(\u0022Initial Velocity\u0022)]\r\n\tpublic ParticleFloat VelocityFromDonut { get; set; } = 0f;\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tif (!Gizmo.IsSelected) return;\r\n\r\n\t\tGizmo.Draw.Color = Color.White.WithAlpha(0.5f);\r\n\t\tGizmo.GizmoDraw draw = Gizmo.Draw;\r\n\r\n\t\t// draw shape\r\n\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius \u002B RingRadius, 16);\r\n\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius - RingRadius, 16);\r\n\t\tdraw.LineCircle(Vector3.Zero.WithZ(RingRadius), Vector3.Up, MainRadius, 16);\r\n\t\tdraw.LineCircle(Vector3.Zero.WithZ(-RingRadius), Vector3.Up, MainRadius, 16);\r\n\r\n\t\tdraw.LineCircle(Vector3.Zero.WithX(MainRadius), Vector3.Left, RingRadius, 8);\r\n\t\tdraw.LineCircle(Vector3.Zero.WithX(-MainRadius), Vector3.Left, RingRadius, 8);\r\n\t\tdraw.LineCircle(Vector3.Zero.WithY(MainRadius), Vector3.Forward, RingRadius, 8);\r\n\t\tdraw.LineCircle(Vector3.Zero.WithY(-MainRadius), Vector3.Forward, RingRadius, 8);\r\n\r\n\t\t// draw thickness\r\n\t\tif (Thickness \u003E 0f \u0026\u0026 Thickness \u003C 1f)\r\n\t\t{\r\n\t\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius \u002B (RingRadius * Thickness), 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius - (RingRadius * Thickness), 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithZ(RingRadius), Vector3.Up, MainRadius, 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithZ(-RingRadius * Thickness), Vector3.Up, MainRadius, 16);\r\n\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithX(MainRadius), Vector3.Left, RingRadius * Thickness, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithX(-MainRadius), Vector3.Left, RingRadius * Thickness, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithY(MainRadius), Vector3.Forward, RingRadius * Thickness, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithY(-MainRadius), Vector3.Forward, RingRadius * Thickness, 8);\r\n\t\t}\r\n\r\n\t\t// draw Distance Bias\r\n\t\tif (DistanceBias \u003E 0f \u0026\u0026 DistanceBias \u003C 1f)\r\n\t\t{\r\n\t\t\tGizmo.Draw.Color = Color.Red.WithAlpha(0.4f);\r\n\t\t\tvar biasRadius = MathX.Lerp(RingRadius * Thickness, RingRadius, DistanceBias);\r\n\r\n\t\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius \u002B biasRadius, 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero, Vector3.Up, MainRadius - biasRadius, 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithZ(biasRadius), Vector3.Up, MainRadius, 16);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithZ(-biasRadius), Vector3.Up, MainRadius, 16);\r\n\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithX(MainRadius), Vector3.Left, biasRadius, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithX(-MainRadius), Vector3.Left, biasRadius, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithY(MainRadius), Vector3.Forward, biasRadius, 8);\r\n\t\t\tdraw.LineCircle(Vector3.Zero.WithY(-MainRadius), Vector3.Forward, biasRadius, 8);\r\n\t\t}\r\n\r\n\t\tif (PositionBias.IsNearlyZero()) return;\r\n\t\tGizmo.Draw.Color = Color.Red.WithAlpha(0.8f);\r\n\t\tVector3 biasClamped = Vector3.Clamp(PositionBias, new Vector3(-1f), new Vector3(1f)) * (MainRadius \u002B RingRadius);\r\n\t\tdraw.Arrow(Vector3.Zero, biasClamped, biasClamped.Length * 0.1f, biasClamped.Length * 0.1f);\r\n\t}\r\n\r\n\tpublic override Particle Emit(ParticleEffect target)\r\n\t{\r\n\t\t// radius point.\r\n\t\tvar mainRadius = Random.Shared.VectorInCircle();\r\n\r\n\t\t// radius pos bias\r\n\t\tmainRadius \u002B= new Vector2(PositionBias.x, PositionBias.y);\r\n\t\tmainRadius = mainRadius.Normal;\r\n\r\n\t\t\r\n\r\n\t\t// Random point around the edge of a unit circle\r\n\t\tVector3 random = new Vector3(mainRadius.x, mainRadius.y, 0f);\r\n\t\trandom *= MainRadius;\r\n\r\n\t\t// get random point on the ring \r\n\t\tvar randomRing = Random.Shared.VectorInCircle();\r\n\r\n\t\t\r\n\r\n\t\tvar biasedRing = randomRing;\r\n\t\tbiasedRing.y \u002B= PositionBias.z;\r\n\t\tvar ringPosBias = new Vector2(PositionBias.x, PositionBias.y).Length;\r\n\t\tbiasedRing.x \u002B= ringPosBias;\r\n\r\n\t\tvar outterRing = biasedRing.Normal * RingRadius;\r\n\t\tvar innerRing = outterRing * Thickness;\r\n\t\tvar betweenRandomRing = Vector2.Lerp(innerRing, outterRing, randomRing.Length);\r\n\r\n\t\tvar ringAdjustment = Vector2.Zero;\r\n\t\t// apply distance bias\r\n\t\tif (DistanceBias \u003C= 0.5f)\r\n\t\t{\r\n\t\t\tfloat scaledBias = DistanceBias / 0.5f;\r\n\t\t\tringAdjustment = Vector2.Lerp(innerRing, betweenRandomRing, scaledBias);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tfloat scaledBias = (DistanceBias - 0.5f) / 0.5f;\r\n\t\t\tringAdjustment = Vector2.Lerp(betweenRandomRing, outterRing, scaledBias);\r\n\t\t}\r\n\r\n\t\tvar randomXY = new Vector2(random.x, random.y);\r\n\r\n\t\trandom.x \u002B= randomXY.Normal.x * ringAdjustment.x;\r\n\t\trandom.y \u002B= randomXY.Normal.y * ringAdjustment.x;\r\n\t\trandom.z \u002B= ringAdjustment.y;\r\n\r\n\t\t// AXIS BIAS\r\n\t\trandom = ApplyAxisBias(random, AxisBias);\r\n\r\n\t\t// TODO - we should clamp position and velocity before calculating world position/rotation position/velocity\r\n\t\tvar donutVelocityDir = new Vector3(randomXY.Normal.x * ringAdjustment.x, randomXY.Normal.y * ringAdjustment.x, ringAdjustment.y).Normal;\r\n\r\n\t\tvar clampedParticlePoint = ProcessClampPosition(random, donutVelocityDir, AxisClamp);\r\n\t\tvar finalPos = (clampedParticlePoint.Position * LocalScale * WorldRotation) \u002B WorldPosition;\r\n\t\tvar finalParticleVel = clampedParticlePoint.Velocity * WorldRotation;\r\n\r\n\t\tParticle particle = target.Emit(finalPos, base.Delta);\r\n\t\tparticle.Velocity \u002B= finalParticleVel * VelocityFromDonut.Evaluate(Delta,Random.Shared.Float());\r\n\r\n\t\treturn particle;\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/ShaderParticleModelRenderer.cs","FileName":"ShaderParticleModelRenderer.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text.Json.Nodes;\r\nusing System.Text.Json.Serialization;\r\nusing Sandbox;\r\n\r\nnamespace Sandbox;\r\n\r\n[Title( \u0022Shader Particle Model Renderer\u0022 )]\r\n[Category( \u0022Particles\u0022 )]\r\n[Description(\r\n\t\u0022Adds the \\\u0022Particle Shader\\\u0022 feature which let\u0027s you set shader parameters on the particles model using the particle system !\u0022 )]\r\npublic class ShaderParticleModelRenderer : ParticleController, Component.ExecuteInEditor\r\n{\r\n\tprivate ParticleModelRenderer _particleModelRenderer { get; set; } = new ParticleModelRenderer();\r\n\r\n\t[Property]\r\n\tpublic bool Batchable { get; set; } = true;\r\n\r\n\t/**\r\n\t *  These are the dictionaries used to set the values for the render attributes in the particle system\r\n\t */\r\n\t[Property, FeatureEnabled(\u0022ParticleShader\u0022)]\r\n\tpublic bool ParticleShaderEnabled { get; set; } = true;\r\n\t\r\n\t\r\n\t[Property, Group( \u0022ColorParameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleGradient\u003E Colors { get; set; }\r\n\r\n\t[Property, Group( \u0022FloatParameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleFloat\u003E Floats { get; set; }\r\n\r\n\t[Property, Group( \u0022Float2Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleVector2\u003E Floats2 { get; set; }\r\n\r\n\t[Property, Group( \u0022Float3Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, ParticleVector3\u003E Floats3 { get; set; }\r\n\r\n\t[Property, Group( \u0022Float4Parameters\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, Vector4\u003E Floats4 { get; set; }\r\n\r\n\t[Property, Group( \u0022Textures\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, Texture\u003E Textures { get; set; }\r\n\r\n\t[Property, Group( \u0022DynamicCombos\u0022 ), Feature( \u0022ParticleShader\u0022 )]\r\n\tpublic Dictionary\u003CString, int\u003E DynamicCombos { get; set; }\r\n\r\n\t\r\n\t\r\n\t/// \u003Csummary\u003E\r\n\t/// Particle rotation is world space: the emitter rotation does not orient the particle at all.\r\n\t/// When clear, the particle rotation follows the emitter rotation every frame (local space).\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool IsWorldRotation { get; set; } = false;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// World rotation, but seeded with the emitter rotation sampled at spawn: the particle is born\r\n\t/// facing the emitter\u0027s direction and is never re-oriented afterwards. Keeps rate-over-distance\r\n\t/// trails spawning in the right direction while staying in world space.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, ShowIf( nameof(IsWorldRotation), true )]\r\n\tpublic bool InheritSpawnRotation { get; set; } = false;\r\n\r\n\t[Property, FeatureEnabled( \u0022SheetSequence\u0022 )]\r\n\tpublic bool SheetSequence { get; set; } = false;\r\n\r\n\t[Property, Feature( \u0022SheetSequence\u0022 )]\r\n\tpublic float SheetSequenceSpeed { get; set; } = 1f;\r\n\t\r\n\t\r\n\r\n\t[RequireComponent] public new ParticleEffect ParticleEffect { get; set; }\r\n\r\n\t[Property, Order( -100 ), InlineEditor( Label = false ), Group( \u0022Advanced Rendering\u0022, StartFolded = true )]\r\n\tpublic RenderOptions RenderOptions =\u003E _particleModelRenderer.RenderOptions;\r\n\t\r\n\t\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tFloats = Floats == null ? new Dictionary\u003Cstring, ParticleFloat\u003E() : Floats;\r\n\t\tFloats2 = Floats2 == null ? new Dictionary\u003Cstring, ParticleVector2\u003E() : Floats2;\r\n\t\tFloats3 = Floats3 == null ? new Dictionary\u003Cstring, ParticleVector3\u003E() : Floats3;\r\n\t\tFloats4 = Floats4 == null ? new Dictionary\u003Cstring, Vector4\u003E() : Floats4;\r\n\t\tTextures = Textures == null ? new Dictionary\u003Cstring, Texture\u003E() : Textures;\r\n\t\tColors = Colors == null ? new Dictionary\u003CString, ParticleGradient\u003E() : Colors;\r\n\t\tDynamicCombos = DynamicCombos == null ? new Dictionary\u003Cstring, int\u003E() : DynamicCombos;\r\n\t\t\r\n\t\tif( ParticleShaderEnabled ) ReadAttributes();\r\n\t}\r\n\t\r\n\t[Button, Feature(\u0022ParticleShader\u0022)]\r\n\tprivate void ReadAttributes()\r\n\t{\r\n\t\tif ( MaterialOverride == null || !FileSystem.Mounted.FileExists( MaterialOverride.Shader.ResourcePath )) return;\r\n\t\tvar parsedFloats2 = new Dictionary\u003Cstring, Vector2\u003E();\r\n\t\tvar parsedFloats3 = new Dictionary\u003Cstring, Vector3\u003E();\r\n\t\tAttributesParser\u003CParticleFloat, ParticleGradient\u003E parser = new AttributesParser\u003CParticleFloat, ParticleGradient\u003E(new ParticleAttributeTypeSet());\r\n\t\tparser.Floats = Floats;\r\n\t\tparser.Floats2 = parsedFloats2;\r\n\t\tparser.Floats3 = parsedFloats3;\r\n\t\tparser.Floats4 = Floats4;\r\n\t\tparser.Textures = Textures;\r\n\t\tparser.DynamicCombos = DynamicCombos;\r\n\t\tparser.Colors = Colors;\r\n\t\tparser.ParseAttributes( MaterialOverride.Shader.ResourcePath );\r\n\r\n\t\tforeach ( var pair in parsedFloats2 )\r\n\t\t{\r\n\t\t\tif ( Floats2.ContainsKey( pair.Key ) ) continue;\r\n\t\t\tFloats2.Add( pair.Key, pair.Value ); // implicit Vector2 -\u003E ParticleVector2\r\n\t\t}\r\n\r\n\t\tforeach ( var pair in parsedFloats3 )\r\n\t\t{\r\n\t\t\tif ( Floats3.ContainsKey( pair.Key ) ) continue;\r\n\t\t\tFloats3.Add( pair.Key, pair.Value ); // implicit Vector3 -\u003E ParticleVector3\r\n\t\t}\r\n\t}\r\n\r\n\tpublic sealed class ModelEntry\r\n\t{\r\n\t\tprivate Model _model;\r\n\r\n\t\t[KeyProperty]\r\n\t\tpublic Model Model\r\n\t\t{\r\n\t\t\tget =\u003E _model;\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\tif ( _model == value )\r\n\t\t\t\t\treturn;\r\n\r\n\t\t\t\t_model = value;\r\n\r\n\t\t\t\tMaterialGroup = default;\r\n\t\t\t\tBodyGroups = _model?.DefaultBodyGroupMask ?? default;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t[Model.MaterialGroup, ShowIf( nameof(HasMaterialGroups), true )]\r\n\t\tpublic string MaterialGroup { get; set; }\r\n\r\n\t\t[Model.BodyGroupMask, ShowIf( nameof(HasBodyGroups), true )]\r\n\t\tpublic ulong BodyGroups { get; set; }\r\n\r\n\t\t[Hide, JsonIgnore] public bool HasMaterialGroups =\u003E Model?.MaterialGroupCount \u003E 0;\r\n\r\n\t\t[Hide, JsonIgnore] public bool HasBodyGroups =\u003E Model?.BodyParts.Sum( x =\u003E x.Choices.Count ) \u003E 1;\r\n\r\n\t\tpublic static implicit operator ModelEntry( Model model ) =\u003E new() { Model = model };\r\n\t}\r\n\r\n\t[Hide, Obsolete( \u0022Use Choices\u0022 )] public List\u003CModel\u003E Models { get; set; } = new();\r\n\r\n\t[Property] public List\u003CModelEntry\u003E Choices { get; set; } = new List\u003CModelEntry\u003E { Model.Cube };\r\n\r\n\t[Property] public Material MaterialOverride { get; set; }\r\n\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleX { get; set; } = 1;\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleY { get; set; } = 1;\r\n\t[Property, Feature( \u0022ScaleXYZ\u0022 )] public ParticleFloat ScaleZ { get; set; } = 1;\r\n\r\n\t[Property, FeatureEnabled( \u0022ScaleXYZ\u0022 )]\r\n\tpublic bool ApplyScaleXYZ { get; set; } = true;\r\n\r\n\t[Property] public ParticleFloat Scale { get; set; } = 1;\r\n\t\r\n\t[Property] public bool CastShadows { get; set; } = true;\r\n\r\n\t[Property] public Allignement Allignement { get; set; }\r\n\r\n\tprotected override void OnParticleCreated( Particle p )\r\n\t{\r\n\t\tvar particleModel = new CustomParticleModel( this );\r\n\t\tp.AddListener( particleModel, this );\r\n\t\t\r\n\t}\r\n\r\n\t// Scene objects of dead particles, kept hidden and handed to new particles of the same model instead of\r\n\t// creating and deleting one per particle. Particles spawn and die on the parallel particle step, so it\u0027s locked.\r\n\tprivate readonly Dictionary\u003CModel, Stack\u003CSceneObject\u003E\u003E _pool = new();\r\n\tprivate bool _poolOpen;\r\n\r\n\tinternal SceneObject RentSceneObject( Model model )\r\n\t{\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\tif ( _poolOpen \u0026\u0026 _pool.TryGetValue( model, out var stack ) )\r\n\t\t\t{\r\n\t\t\t\twhile ( stack.TryPop( out var so ) )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( !so.IsValid() ) continue;\r\n\r\n\t\t\t\t\tso.RenderingEnabled = true;\r\n\t\t\t\t\treturn so;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn new SceneObject( Scene.SceneWorld, model );\r\n\t}\r\n\r\n\tinternal void ReturnSceneObject( SceneObject so, Model model )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\tif ( _poolOpen )\r\n\t\t\t{\r\n\t\t\t\tso.RenderingEnabled = false;\r\n\r\n\t\t\t\tif ( !_pool.TryGetValue( model, out var stack ) )\r\n\t\t\t\t\t_pool[model] = stack = new Stack\u003CSceneObject\u003E();\r\n\r\n\t\t\t\tstack.Push( so );\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tso.Delete();\r\n\t}\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tlock ( _pool ) _poolOpen = true;\r\n\r\n\t\tbase.OnEnabled();\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\t// Live particles hand their scene objects back while the base disables, so close the pool after\r\n\t\tbase.OnDisabled();\r\n\r\n\t\tlock ( _pool )\r\n\t\t{\r\n\t\t\t_poolOpen = false;\r\n\r\n\t\t\tforeach ( var stack in _pool.Values )\r\n\t\t\t{\r\n\t\t\t\tforeach ( var so in stack )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( so.IsValid() ) so.Delete();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_pool.Clear();\r\n\t\t}\r\n\t}\r\n\r\n\t// Read by every particle on the parallel step; sampled once per step here instead of once per particle\r\n\tinternal Vector3 StepWorldScale { get; private set; } = Vector3.One;\r\n\tinternal Rotation StepWorldRotation { get; private set; } = Rotation.Identity;\r\n\tinternal Vector3? StepCameraPosition { get; private set; }\r\n\r\n\tprotected override void OnBeforeStep( float delta )\r\n\t{\r\n\t\tbase.OnBeforeStep( delta );\r\n\r\n\t\tStepWorldScale = WorldScale;\r\n\t\tStepWorldRotation = WorldRotation;\r\n\t\tvar camera = Scene.Camera;\r\n\t\tStepCameraPosition = camera.IsValid() ? camera.WorldPosition : null;\r\n\r\n\t\tif ( ParticleShaderEnabled )\r\n\t\t\tAnimatedAttributes.Rebuild( Floats, Floats2, Floats3, Colors );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Shader attributes that change over a particle\u0027s life, shared by this renderer\u0027s particles.\r\n\t/// \u003C/summary\u003E\r\n\tinternal AnimatedAttributes AnimatedAttributes { get; } = new();\r\n\r\n\tpublic override int ComponentVersion =\u003E 2;\r\n\r\n\t[JsonUpgrader( typeof(ParticleModelRenderer), 1 )]\r\n\tstatic void Upgrader_v1( JsonObject obj )\r\n\t{\r\n\t\tif ( obj.TryGetPropertyValue( \u0022Models\u0022, out var node ) )\r\n\t\t{\r\n\t\t\tvar choices = new JsonArray();\r\n\r\n\t\t\tforeach ( var model in node.AsArray() )\r\n\t\t\t{\r\n\t\t\t\tif ( model is null )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tchoices.Add( new JsonObject { [\u0022Model\u0022] = model.ToString() } );\r\n\t\t\t}\r\n\r\n\t\t\tobj[\u0022Choices\u0022] = choices;\r\n\t\t\tobj.Remove( \u0022Models\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\t// Floats2 used to be a Dictionary\u003Cstring, Vector2\u003E (each value serialized as an\r\n\t// \u0022x,y\u0022 string). It is now a Dictionary\u003Cstring, ParticleVector2\u003E; convert each\r\n\t// entry into a ParticleVector2 with constant X/Y components.\r\n\t[JsonUpgrader( typeof(ShaderParticleModelRenderer), 2 )]\r\n\tstatic void Upgrader_v2( JsonObject obj )\r\n\t{\r\n\t\tif ( !obj.TryGetPropertyValue( \u0022Floats2\u0022, out var node ) || node is not JsonObject floats2 )\r\n\t\t\treturn;\r\n\r\n\t\tforeach ( var kv in floats2.ToList() )\r\n\t\t{\r\n\t\t\tif ( kv.Value is not JsonValue val || !val.TryGetValue\u003Cstring\u003E( out var str ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tvar parts = str.Split( \u0027,\u0027 );\r\n\t\t\tif ( parts.Length \u003C 2 )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tif ( !float.TryParse( parts[0].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var x ) ||\r\n\t\t\t     !float.TryParse( parts[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var y ) )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tfloats2[kv.Key] = new JsonObject { [\u0022X\u0022] = x, [\u0022Y\u0022] = y };\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n}\r\n\r\npublic enum Allignement\r\n{\r\n\tSimulationSpace,\r\n\tFaceCamera,\r\n\tFaceVelocity,\r\n\t\r\n}\r\n\r\n\r\n\r\n\r\n\r\npublic class CustomParticleModel : Particle.BaseListener\r\n{\r\n\tpublic ShaderParticleModelRenderer Renderer;\r\n\r\n\tpublic SceneObject so;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Emitter rotation sampled when the particle spawned. Used as the fixed base rotation when\r\n\t/// \u003Csee cref=\u0022ShaderParticleModelRenderer.InheritSpawnRotation\u0022/\u003E is set, so a particle inherits\r\n\t/// the emitter\u0027s orientation at birth but is not re-oriented afterwards.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Rotation _spawnRotation = Rotation.Identity;\r\n\r\n\tprivate ParticleAttributesSetter _particleAttributesSetter;\r\n\r\n\t// Last values pushed to the scene object; each set is a native call plus a change notification\r\n\t// Nullable so the first frame always sets them: a reused scene object still holds the last particle\u0027s values\r\n\tprivate Color? _tint;\r\n\tprivate bool? _castShadows;\r\n\tprivate int _renderOptionsMask = -1;\r\n\tprivate Material _material;\r\n\r\n\t// Model the scene object was rented for, to hand it back to the right pool\r\n\tprivate Model _model;\r\n\r\n\tpublic CustomParticleModel( ShaderParticleModelRenderer renderer )\r\n\t{\r\n\t\tRenderer = renderer;\r\n\t}\r\n\r\n\tpublic override void OnEnabled( Particle p )\r\n\t{\r\n\t\t_spawnRotation = Renderer.StepWorldRotation;\r\n\r\n\t\tvar entry = Random.Shared.FromList( Renderer.Choices );\r\n\t\tvar model = entry?.Model;\r\n\t\t_model = model ?? Model.Cube;\r\n\t\tso = Renderer.RentSceneObject( _model );\r\n\t\tso.Batchable = false;\r\n\t\tif ( model is not null )\r\n\t\t{\r\n\t\t\tso.MeshGroupMask = entry.BodyGroups;\r\n\t\t\tso.SetMaterialGroup( entry.MaterialGroup );\r\n\t\t}\r\n\r\n\t\tif ( Renderer.SheetSequence )\r\n\t\t{\r\n\t\t\tso.Attributes.Set( \u0022AnimSpeed\u0022, Renderer.SheetSequenceSpeed / p.LifeTimeRemaining );\r\n\t\t}\r\n\r\n\t\tif ( !Renderer.ParticleShaderEnabled ) return;\r\n\t\t_particleAttributesSetter = new ParticleAttributesSetter( so.Attributes, p );\r\n\t\tSetRenderAttributes();\r\n\t}\r\n\r\n\tpublic override void OnDisabled( Particle p )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\t\tRenderer.ReturnSceneObject( so, _model );\r\n\t\tso = null;\r\n\t}\r\n\r\n\tpublic override void OnUpdate( Particle p, float dt )\r\n\t{\r\n\t\tif ( !so.IsValid() ) return;\r\n\r\n\r\n\t\tvar angles = ComputeRotation( p );\r\n\t\t\r\n\t\tvar scale = p.Size * Renderer.StepWorldScale;\r\n\t\tif ( Renderer.ApplyScaleXYZ )\r\n\t\t{\r\n\t\t\tscale *= EvaluateScale( p );\r\n\t\t}\r\n\r\n\t\tso.Transform = new Transform( p.Position, angles, scale * Renderer.Scale.Evaluate( p, 6211 ) );\r\n\t\tvar tint = p.Color.WithAlphaMultiplied( p.Alpha );\r\n\t\tif ( tint != _tint )\r\n\t\t{\r\n\t\t\tso.ColorTint = tint;\r\n\t\t\t_tint = tint;\r\n\t\t}\r\n\r\n\t\tif ( _castShadows != Renderer.CastShadows )\r\n\t\t{\r\n\t\t\tso.Flags.CastShadows = Renderer.CastShadows;\r\n\t\t\t_castShadows = Renderer.CastShadows;\r\n\t\t}\r\n\r\n\t\tif ( _material != Renderer.MaterialOverride )\r\n\t\t{\r\n\t\t\tso.SetMaterialOverride( Renderer.MaterialOverride );\r\n\t\t\t_material = Renderer.MaterialOverride;\r\n\t\t}\r\n\r\n\t\t// Constant attributes were set at spawn and stay on the scene object. While editing the scene\r\n\t\t// everything is re-set every frame, so inspector changes show on live particles straight away.\r\n\t\tif ( Renderer.ParticleShaderEnabled )\r\n\t\t{\r\n\t\t\tif ( Renderer.Scene.IsEditor ) _particleAttributesSetter.SetAttributes();\r\n\t\t\telse _particleAttributesSetter.SetAnimatedAttributes();\r\n\t\t}\r\n\t\t\r\n\r\n\t\t// Apply sets four native flags; only redo it when the options change\r\n\t\tvar renderOptions = Renderer.RenderOptions;\r\n\t\tif ( renderOptions != null )\r\n\t\t{\r\n\t\t\tvar mask = (renderOptions.Game ? 1 : 0) | (renderOptions.Overlay ? 2 : 0) | (renderOptions.Bloom ? 4 : 0) | (renderOptions.AfterUI ? 8 : 0);\r\n\t\t\tif ( mask != _renderOptionsMask )\r\n\t\t\t{\r\n\t\t\t\trenderOptions.Apply( so );\r\n\t\t\t\t_renderOptionsMask = mask;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t\r\n\r\n\r\n\tprivate Vector3 EvaluateScale( Particle p )\r\n\t{\r\n\t\t\r\n\t\tvar scaleX = Renderer.ScaleX.Evaluate( p, 6211 );\r\n\t\tvar scaleY = Renderer.ScaleY.Evaluate( p, 6211 );\r\n\t\tvar scaleZ = Renderer.ScaleZ.Evaluate( p, 6211 );\r\n\t\treturn new Vector3( scaleX, scaleY, scaleZ );\r\n\t}\r\n\r\n\r\n\tprivate Angles ComputeRotation(Particle p)\r\n\t{\r\n\t\tvar angles = new Rotation();\r\n\t\tswitch ( Renderer.Allignement )\r\n\t\t{\r\n\t\t\tcase Allignement.FaceCamera :\r\n\t\t\t\tif ( Renderer.StepCameraPosition is not { } cameraPosition ) break;\r\n\t\t\t\tvar dir = cameraPosition - p.Position;\r\n\t\t\t\tangles = Rotation.LookAt( dir, Vector3.Up ) * p.Angles.ToRotation();\r\n\t\t\t\tbreak;\r\n\t\t\tcase Allignement.FaceVelocity :\r\n\t\t\t\tangles = Rotation.LookAt( p.Velocity.Normal, Vector3.Up ) * p.Angles.ToRotation();\r\n\t\t\t\tbreak;\r\n\t\t\tcase Allignement.SimulationSpace :\r\n\t\t\t\tangles = BaseRotation().Angles();\r\n\t\t\t\tangles *= p.Angles;\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\treturn angles;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Base rotation the particle\u0027s own \u003Csee cref=\u0022Particle.Angles\u0022/\u003E are applied on top of, for\r\n\t/// \u003Csee cref=\u0022Allignement.SimulationSpace\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Rotation BaseRotation()\r\n\t{\r\n\t\tif ( !Renderer.IsWorldRotation )\r\n\t\t\treturn Renderer.StepWorldRotation; // follows the emitter every frame\r\n\r\n\t\treturn Renderer.InheritSpawnRotation ? _spawnRotation : Rotation.Identity;\r\n\t}\r\n\r\n\tprivate void SetRenderAttributes()\r\n\t{\r\n\t\t_particleAttributesSetter.Floats = Renderer.Floats;\r\n\t\t_particleAttributesSetter.Floats2 = Renderer.Floats2;\r\n\t\t_particleAttributesSetter.Floats3 = Renderer.Floats3;\r\n\t\t_particleAttributesSetter.Floats4 = Renderer.Floats4;\r\n\t\t_particleAttributesSetter.Textures = Renderer.Textures;\r\n\t\t_particleAttributesSetter.Colors = Renderer.Colors;\r\n\t\t_particleAttributesSetter.DynamicCombos = Renderer.DynamicCombos;\r\n\t\t_particleAttributesSetter.Animated = Renderer.AnimatedAttributes;\r\n\t\t_particleAttributesSetter.SetAttributes();\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/utils/attributes/ParticleAttributeTypeSet.cs","FileName":"ParticleAttributeTypeSet.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"namespace Sandbox;\r\n// The code in this file is ai generated\r\npublic class ParticleAttributeTypeSet : IAttributeTypeSet\u003CParticleFloat, ParticleGradient\u003E\r\n{\r\n\tpublic ParticleFloat GetDefaultFloat() =\u003E new ParticleFloat();\r\n\tpublic ParticleFloat ParseFloat( string value ) =\u003E new ParticleFloat(  ){ConstantValue =  float.Parse( value, System.Globalization.CultureInfo.InvariantCulture )};\r\n\tpublic ParticleGradient GetDefaultColor() =\u003E new ParticleGradient();\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/utils/AttributesParser.cs","FileName":"AttributesParser.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text.RegularExpressions;\r\n\r\nnamespace Sandbox;\r\n\r\npublic class AttributesParser\u003CTFloat, TGradient\u003E\r\n{\r\n\tprivate readonly IAttributeTypeSet\u003CTFloat, TGradient\u003E _typeSet;\r\n\tpublic AttributesParser(IAttributeTypeSet\u003CTFloat, TGradient\u003E typeSet)\r\n\t{\r\n\t\tif (!((typeof(TFloat) == typeof(ParticleFloat) \u0026\u0026 typeof(TGradient) == typeof(ParticleGradient)) ||\r\n\t\t      (typeof(TFloat) == typeof(float) \u0026\u0026 typeof(TGradient) == typeof(Color))))\r\n\t\t{\r\n\t\t\tthrow new InvalidOperationException(\u0022Only Particle or Native types allowed.\u0022);\r\n\t\t}\r\n\t\t_typeSet = typeSet;\r\n\t}\r\n\tpublic Dictionary\u003CString, TGradient\u003E Colors { get; set; }\r\n\t\r\n\tpublic Dictionary\u003CString, TFloat\u003E Floats { get; set; }\r\n\t\r\n\tpublic Dictionary\u003CString, Vector2\u003E Floats2 { get; set; }\r\n\r\n\tpublic Dictionary\u003CString, Vector3\u003E Floats3 { get; set; }\r\n\t\r\n\tpublic Dictionary\u003CString, Vector4\u003E Floats4 { get; set; }\r\n\t\r\n\tpublic Dictionary\u003CString, Texture\u003E Textures { get; set; }\r\n\t\r\n\tpublic Dictionary\u003CString, int\u003E DynamicCombos { get; set; }\r\n\r\n\r\n\tprivate const string AttributesPattern = @\u0022(float(?:[2,3,4])?|Texture2D) \u002B.\u002B \u002B\u003C *Attribute\\(.?\u0022\u0022(.\u002B)\u0022\u0022.?\\)\\;(?:[^\u003E]*?Default(?:[1,2,3,4])?\\(([^)]*)\\))?[^\u003E]*\u003E\\;\u0022;\r\n\tprivate const string DynamicComboPattern = \u0022DynamicCombo\\\\(([^,]\u002B),.\u002B\\\\)\\\\;\u0022;\r\n\r\n\tpublic void ParseAttributes( string filePath )\r\n\t{\r\n\t\tstring fileContent = FileSystem.Mounted.ReadAllText( filePath );\r\n\t\tvar attributeMatches = Regex.Matches(fileContent, AttributesPattern);\r\n\t\tvar dynamicComboMatches = Regex.Matches(fileContent, DynamicComboPattern);\r\n\r\n\t\tforeach ( Match match in dynamicComboMatches )\r\n\t\t{\r\n\t\t\tvar value = match.Groups[1].Value.Trim();\r\n\t\t\tif(!DynamicCombos.ContainsKey(value)) DynamicCombos.Add(value, 0);\r\n\t\t}\r\n\r\n\t\tforeach (Match match in attributeMatches)\r\n\t\t{\r\n\t\t\tvar type = match.Groups[1].Value;\r\n\t\t\tvar value = match.Groups[2].Value;\r\n\t\t\tvar defaultValue = match.Groups[3].Value;\r\n\t\t\tSetAttribute(type, value, defaultValue);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetAttribute( string attributeType, string attributeName, string defaultValue )\r\n\t{\r\n\r\n\t\tswitch ( attributeType )\r\n\t\t{\r\n\t\t\tcase \u0022float\u0022:\r\n\t\t\t\tif ( !Floats.ContainsKey( attributeName ) ) SetFloat( attributeName, defaultValue );\r\n\t\t\t\tbreak;\r\n\t\t\tcase \u0022float2\u0022:\r\n\t\t\t\tif ( !Floats2.ContainsKey( attributeName ) ) SetFloat2( attributeName, defaultValue );\r\n\t\t\t\tbreak;\r\n\t\t\tcase \u0022float3\u0022:\r\n\t\t\t\tif ( !Floats3.ContainsKey( attributeName ) ) SetFloat3( attributeName, defaultValue );\r\n\t\t\t\tbreak;\r\n\t\t\tcase \u0022float4\u0022:\r\n\t\t\t\tif ( !Floats4.ContainsKey( attributeName ) \u0026\u0026 !Colors.ContainsKey( attributeName ) ) SetFloat4( attributeName );\r\n\t\t\t\tbreak;\r\n\t\t\tcase \u0022Texture2D\u0022:\r\n\t\t\t\tif ( !Textures.ContainsKey( attributeName ) ) Textures.Add( attributeName, Texture.White );\r\n\t\t\t\tbreak;\r\n\t\t\tdefault: break;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetFloat( string attributeName, string defaultValue )\r\n\t{\r\n\t\tTFloat value = !string.IsNullOrEmpty( defaultValue )\r\n\t\t\t? _typeSet.ParseFloat( defaultValue )\r\n\t\t\t: _typeSet.GetDefaultFloat();\r\n\t\tFloats.Add( attributeName, value );\r\n\t}\r\n\r\n\tprivate void SetFloat2( string attributeName, string defaultValue )\r\n\t{\r\n\t\tVector2 value = !string.IsNullOrEmpty( defaultValue )\r\n\t\t\t? ParseVector2( defaultValue )\r\n\t\t\t: new Vector2();\r\n\t\tFloats2.Add( attributeName, value );\r\n\t}\r\n\r\n\tprivate void SetFloat3( string attributeName, string defaultValue )\r\n\t{\r\n\t\tVector3 value = !string.IsNullOrEmpty( defaultValue )\r\n\t\t\t? ParseVector3( defaultValue )\r\n\t\t\t: new Vector3();\r\n\t\tFloats3.Add( attributeName, value );\r\n\t}\r\n\r\n\tprivate static Vector2 ParseVector2( string raw )\r\n\t{\r\n\t\tvar p = raw.Split( \u0027,\u0027 );\r\n\t\treturn new Vector2(\r\n\t\t\tfloat.Parse( p[0].Trim(), System.Globalization.CultureInfo.InvariantCulture ),\r\n\t\t\tfloat.Parse( p[1].Trim(), System.Globalization.CultureInfo.InvariantCulture )\r\n\t\t);\r\n\t}\r\n\r\n\tprivate static Vector3 ParseVector3( string raw )\r\n\t{\r\n\t\tvar p = raw.Split( \u0027,\u0027 );\r\n\t\treturn new Vector3(\r\n\t\t\tfloat.Parse( p[0].Trim(), System.Globalization.CultureInfo.InvariantCulture ),\r\n\t\t\tfloat.Parse( p[1].Trim(), System.Globalization.CultureInfo.InvariantCulture ),\r\n\t\t\tfloat.Parse( p[2].Trim(), System.Globalization.CultureInfo.InvariantCulture )\r\n\t\t);\r\n\t}\r\n\r\n\tprivate void SetFloat4( string attributeName)\r\n\t{\r\n\t\tif ( attributeName.ToLower().Contains( \u0022color\u0022 ) )\r\n\t\t{\r\n\t\t\tColors.Add( attributeName, _typeSet.GetDefaultColor() );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tFloats4.Add( attributeName, new Vector4(  ) );\t\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"EmittersShapes/ConchplexBoxEmitter.cs","FileName":"ConchplexBoxEmitter.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Security.Cryptography;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace ConchplexEmitters;\r\n\r\n/// \u003Csummary\u003E\r\n/// Emits particles within a box min/max bounds\r\n/// \u003C/summary\u003E\r\n[Title(\u0022Conchplex Box Emitter\u0022), Category(\u0022Particles\u0022), Icon(\u0022border_outer\u0022)]\r\npublic sealed class ConchplexBoxEmitter : ConchplexEmitter\r\n{\r\n\t// Emitter shape\r\n\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// 1 = spawns on edge, 0 = spawns in centre\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(0f, 1f), Step(0.01f)]\r\n\tpublic float DistanceBias { get; set; } = 0.5f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Direction \u002B intensity to bias particles to spawn towards\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(-1, 1)]\r\n\tpublic Vector3 PositionBias { get; set; } = 0f;\r\n\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\t[Range(-1, 1)]\r\n\tpublic Vector3 AxisBias { get; set; } = 0f;\r\n\t/// \u003Csummary\u003E\r\n\t/// Particles only spawn on the axes marked\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group(\u0022Spawn Bias\u0022), Order(0)]\r\n\tpublic AxisClampFlags AxisClamp { get; set; }\r\n\r\n\t[Property]\r\n\tpublic Vector3 Size { get; set; } = 50f;\r\n\r\n\t[Property]\r\n\t[Range(0f, 1f), Step(0.01f)]\r\n\tpublic float Thickness { get; set; } = 0f;\r\n\r\n\t[Property, Group(\u0022Initial Velocity\u0022)]\r\n\tpublic float VelocityFromSquare { get; set; } = 0f;\r\n\r\n\r\n\tprotected override void DrawGizmos()\r\n\t{\r\n\t\tif (Gizmo.IsSelected)\r\n\t\t{\r\n\t\t\tvar point = Vector3.Zero;\r\n\t\t\tGizmo.Draw.Color = Color.White.WithAlpha(0.5f);\r\n\t\t\tGizmo.GizmoDraw draw = Gizmo.Draw;\r\n\r\n\t\t\t// Draw max bounds\r\n\t\t\tBBox box = BBox.FromPositionAndSize(point, Size);\r\n\t\t\tdraw.LineBBox(box);\r\n\r\n\t\t\t// Draw min bounds\r\n\t\t\tBBox boxMin = BBox.FromPositionAndSize(point, Size * Thickness);\r\n\t\t\tdraw.LineBBox(boxMin);\r\n\r\n\t\t\t// Draw Distance Bias\r\n\t\t\tGizmo.Draw.Color = Color.Red.WithAlpha(0.5f);\r\n\t\t\tfloat biasX = MathX.Lerp(Size.x, Size.x * Thickness, 1 - DistanceBias);\r\n\t\t\tfloat biasY = MathX.Lerp(Size.y, Size.y * Thickness, 1 - DistanceBias);\r\n\t\t\tfloat biasZ = MathX.Lerp(Size.z, Size.z * Thickness, 1 - DistanceBias);\r\n\t\t\tBBox biasBox = BBox.FromPositionAndSize(point, new Vector3(biasX, biasY, biasZ) \u002B point);\r\n\t\t\tdraw.LineBBox(biasBox);\r\n\r\n\t\t\tif (PositionBias.IsNearlyZero()) return;\r\n\t\t\tGizmo.Draw.Color = Color.Red.WithAlpha(0.8f);\r\n\t\t\tVector3 biasClamped = Vector3.Clamp(PositionBias * 300f, new Vector3(-Size * 0.5f), new Vector3(Size * 0.5f));\r\n\t\t\tdraw.Arrow(point, biasClamped, biasClamped.Length * 0.1f, biasClamped.Length * 0.1f);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override Particle Emit(ParticleEffect target)\r\n\t{\r\n\t\tVector3 random = Random.Shared.VectorInCube(0.5f);\r\n\t\tVector3 sizeMin = Size * Thickness;\r\n\t\tVector3 sizeMax = Size;\r\n\t\tVector3 targetSize = Vector3.Lerp(sizeMin, sizeMax, DistanceBias);\r\n\t\tVector3 surfaceDirrection = Vector3.Zero;\r\n\r\n\t\t// POSITION BIAS\r\n\t\tvar posBias = Vector3.Clamp(PositionBias, new Vector3(-1f), new Vector3(1f));\r\n\t\tfloat biasStrength = posBias.Length;\r\n\t\tif (biasStrength \u003E 0f)\r\n\t\t{\r\n\t\t\tfloat randomFlipChance = Random.Shared.Float();\r\n\t\t\tif (MathF.Abs(posBias.x) \u003E randomFlipChance \u0026\u0026 MathF.Sign(posBias.x) != MathF.Sign(random.x))\r\n\t\t\t\trandom.x = -random.x;\r\n\t\t\tif (MathF.Abs(posBias.y) \u003E randomFlipChance \u0026\u0026 MathF.Sign(posBias.y) != MathF.Sign(random.y))\r\n\t\t\t\trandom.y = -random.y;\r\n\t\t\tif (MathF.Abs(posBias.z) \u003E randomFlipChance \u0026\u0026 MathF.Sign(posBias.z) != MathF.Sign(random.z))\r\n\t\t\t\trandom.z = -random.z;\r\n\r\n\t\t\trandom = Vector3.Lerp(random, random \u002B posBias * 0.5f, biasStrength);\r\n\t\t}\r\n\r\n\t\t// Figure out Min / Max Distance bias\r\n\t\tvar maxEdgePos = RandomPositionOnBoxFace(random, Size, posBias, out surfaceDirrection);\r\n\t\tvar minEdgePos = maxEdgePos * Thickness;\r\n\t\t// lol this is really stupid and nasty but it works!\r\n\t\tvar fuckedUpRandom = Random.Shared.Float();\r\n\t\tvar randomBetweenPos = Vector3.Lerp(maxEdgePos, minEdgePos, fuckedUpRandom * fuckedUpRandom * fuckedUpRandom);\r\n\t\t// Apply Distance Bias\r\n\r\n\t\tif (DistanceBias \u003C= 0.5f)\r\n\t\t{\r\n\t\t\tfloat scaledBias = DistanceBias / 0.5f;\r\n\t\t\trandom = Vector3.Lerp(minEdgePos, randomBetweenPos, scaledBias);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tfloat scaledBias = (DistanceBias - 0.5f) / 0.5f;\r\n\t\t\trandom = Vector3.Lerp(randomBetweenPos, maxEdgePos, scaledBias);\r\n\t\t}\r\n\r\n\t\tvar clampedParticlePoint = ProcessClampPosition(random, surfaceDirrection, AxisClamp);\r\n\t\tvar pos = (clampedParticlePoint.Position * LocalScale * WorldRotation) \u002B WorldPosition;\r\n\t\tvar velocity = clampedParticlePoint.Velocity * LocalRotation;\r\n\r\n\t\tParticle particle = target.Emit(pos, base.Delta);\r\n\t\tparticle.Velocity \u002B= velocity * VelocityFromSquare;\r\n\r\n\t\treturn particle;\r\n\t}\r\n\r\n\t// this ensure particles are placed evenly on faces \u002B corrects any overshooting\r\n\tVector3 RandomPositionOnBoxFace(Vector3 randomPos, Vector3 boxSize, Vector3 positionBias, out Vector3 surfaceDirrection)\r\n\t{\r\n\t\t// Scale the random position to the box size\r\n\t\trandomPos = Vector3.Clamp(randomPos, new Vector3(-0.5f), new Vector3(0.5f));\r\n\r\n\t\tvar scaledPos = randomPos * boxSize;\r\n\t\t// Determine valid faces for selection\r\n\t\tList\u003C(int axis, bool positiveSide)\u003E validFaces = new List\u003C(int, bool)\u003E();\r\n\r\n\t\tfor (int i = 0; i \u003C 3; i\u002B\u002B) // Iterate over X, Y, Z axes\r\n\t\t{\r\n\t\t\tif (positionBias[i] \u003E= 0) // Allow positive face if bias is \u003E= 0\r\n\t\t\t\tvalidFaces.Add((i, true));\r\n\t\t\tif (positionBias[i] \u003C= 0) // Allow negative face if bias is \u003C= 0\r\n\t\t\t\tvalidFaces.Add((i, false));\r\n\t\t}\r\n\r\n\t\tif (validFaces.Count == 0)\r\n\t\t\tthrow new InvalidOperationException(\u0022No valid faces available due to position bias.\u0022);\r\n\r\n\t\t// Randomly select a valid face\r\n\t\tvar selectedFace = validFaces[Random.Shared.Next(validFaces.Count)];\r\n\t\tint fixedAxis = selectedFace.axis;\r\n\t\tbool positiveSide = selectedFace.positiveSide;\r\n\r\n\t\t// Push the position to the selected face\r\n\t\tscaledPos[fixedAxis] = positiveSide ? (boxSize[fixedAxis] * 0.5f) : -(boxSize[fixedAxis] * 0.5f);\r\n\t\tsurfaceDirrection = Vector3.Zero;\r\n\t\tsurfaceDirrection[fixedAxis] = positiveSide ? 1f : -1f;\r\n\r\n\t\treturn scaledPos;\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"ParticleEffectPlus.cs","FileName":"ParticleEffectPlus.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n[Description(\u0022This component let\u0027s you set values for particles over the emitters lifetime instead of the particles lifetimes\u0022)]\r\npublic class ParticleEffectPlus : ParticleController\r\n{\r\n\r\n\t[Property, RequireComponent] private ParticleEmitter ParticleEmitter { get; set; }\r\n\r\n\t[Property, FeatureEnabled( \u0022ShapeXYZ\u0022 )]\r\n\tprivate bool ShapeXyzEnabled { get; set; }\r\n\r\n\t[Property, Feature( \u0022ShapeXYZ\u0022 )] private ParticleFloat ScaleX { get; set; }\r\n\t[Property, Feature( \u0022ShapeXYZ\u0022 )] private ParticleFloat ScaleY { get; set; }\r\n\t[Property, Feature( \u0022ShapeXYZ\u0022 )] private ParticleFloat ScaleZ { get; set; }\r\n\r\n\t[Property, FeatureEnabled (\u0022Rotate\u0022)]\r\n\tprivate bool RotateXyzEnabled {get; set;}\r\n\r\n    [Property, Feature( \u0022Rotate\u0022 )] private ParticleFloat RotateX { get; set; }\r\n\t[Property, Feature( \u0022Rotate\u0022 )] private ParticleFloat RotateY { get; set; }\r\n\t[Property, Feature( \u0022Rotate\u0022 )] private ParticleFloat RotateZ { get; set; }\r\n\r\n\r\n\t[Property, FeatureEnabled( \u0022Shape\u0022 )] private bool ShapeEnabled { get; set; }\r\n\r\n\t[Property, FeatureEnabled( \u0022Shape\u0022 )] private ParticleFloat Scale { get; set; }\r\n\r\n\r\n\tprotected override void OnParticleStep( Particle particle, float delta )\r\n\t{\r\n\t\tif(ParticleEmitter == null) return;\r\n\t\tSetSize( particle, delta );\r\n\t}\r\n\r\n\tprivate void SetSize( Particle particle, float delta )\r\n\t{\r\n\t\tVector3 size;\r\n\t\tif ( ShapeXyzEnabled )\r\n\t\t{\r\n\t\t\tvar x = ScaleX.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tvar y = ScaleY.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tvar z = ScaleZ.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tparticle.Size = new Vector3( x, y, z );\r\n\t\t}\r\n\r\n\t\tif ( ShapeEnabled )\r\n\t\t{\r\n\t\t\tparticle.Size = Scale.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t}\r\n\r\n\t\tif ( RotateXyzEnabled )\r\n\t\t{\r\n\t\t\tvar x = RotateX.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tvar y = RotateY.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tvar z = RotateZ.Evaluate( ParticleEmitter.Delta, 65343 );\r\n\t\t\tparticle.Angles = new Angles(x,y,z);\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/MyLibraryComponent.cs","FileName":"MyLibraryComponent.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// This is a component - in your library!\r\n/// \u003C/summary\u003E\r\n[Title( \u0022ParticleSystemPlus - My Component\u0022 )]\r\npublic class MyLibraryComponent : Component\r\n{\r\n\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/utils/ParticleVector2.cs","FileName":"ParticleVector2.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// A two component vector whose X and Y are \u003Csee cref=\u0022ParticleFloat\u0022/\u003Es, so each\r\n/// component can be a constant, a random range, or a curve evaluated per particle.\r\n/// Mirrors the engine\u0027s \u003Csee cref=\u0022ParticleVector3\u0022/\u003E for the float2 case.\r\n/// \u003C/summary\u003E\r\npublic class ParticleVector2\r\n{\r\n\t[Property] public ParticleFloat X { get; set; }\r\n\t[Property] public ParticleFloat Y { get; set; }\r\n\r\n\tpublic ParticleVector2()\r\n\t{\r\n\t\t// Default to constant-zero components so Evaluate never dereferences a null\r\n\t\t// ParticleFloat when the editor creates a fresh entry. JSON deserialization\r\n\t\t// overwrites these from the serialized X/Y.\r\n\t\tX = new ParticleFloat();\r\n\t\tY = new ParticleFloat();\r\n\t}\r\n\r\n\tpublic ParticleVector2( ParticleFloat x, ParticleFloat y )\r\n\t{\r\n\t\tX = x;\r\n\t\tY = y;\r\n\t}\r\n\r\n\tpublic Vector2 Evaluate( Particle particle, int seed )\r\n\t{\r\n\t\treturn new Vector2( X.Evaluate( particle, seed ), Y.Evaluate( particle, seed ) );\r\n\t}\r\n\r\n\tpublic static implicit operator ParticleVector2( Vector2 v ) =\u003E new ParticleVector2( v.x, v.y );\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/IResetable.cs","FileName":"IResetable.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"public interface IResetable\r\n{\r\n    public float Duration{get;set;}\r\n    public float Delta {get; set;}\r\n    public void ResetTime();\r\n}"},{"Ident":"lastfish.particlesystemplus","Path":"Code/ParticleEffectsManager.cs","FileName":"ParticleEffectsManager.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text.Json.Serialization;\r\nusing Sandbox;\r\n\r\n[Title( \u0022Particle Effects Manager\u0022 )]\r\n[Category( \u0022Particle\u0022 )]\r\n[Description(\r\n\t\u0022This component let\u0027s you manage the TimeScale , the pause and restart of every particle effect component present in the childrens of this component gameobject so it is easier to preview the whole system\u0022 )]\r\npublic sealed class ParticleEffectsManager : Component, Component.ExecuteInEditor\r\n{\r\n\t[Property] public List\u003CParticleEffect\u003E ParticleEffects { get; set; }\r\n\r\n\t[Property] public List\u003CParticleEmitter\u003E ParticleEmitters { get; set; }\r\n\r\n\t[Property] List\u003CIResetable\u003E Resetables {get; set;}\r\n\r\n\t[Property] List\u003CIPhaseDriven\u003E PhaseDriven { get; set; }\r\n\r\n\t[Property, Group( \u0022Parameters\u0022 )]\r\n\tpublic bool DrivePhaseFromEmitter { get; set; } = true;\r\n\r\n\t[Property, Group( \u0022Parameters\u0022 ), ShowIf( nameof( DrivePhaseFromEmitter ), true )]\r\n\tpublic ParticleEmitter PhaseMaster { get; set; }\r\n\r\n\t[Property, Group( \u0022Parameters\u0022 ), Range( -1f, 1f ), Step( 0.1f )]\r\n\tfloat TimeScale { get; set; } = 1f;\r\n\r\n\t[JsonIgnore] public bool IsPaused { get; set; }\r\n\t[JsonIgnore] public bool IsRestart { get; set; }\r\n\t\r\n\t\r\n\r\n\t[JsonIgnore]\r\n\tpublic float LongestDuration\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tvar duration = 0f;\r\n\t\t\tforeach ( var emitter in ParticleEmitters )\r\n\t\t\t{\r\n\t\t\t\tif ( emitter.Duration.Evaluate(0,0) \u002B emitter.Delay.Evaluate(0,0) \u003E duration )\r\n\t\t\t\t{\r\n\t\t\t\t\tduration = emitter.Duration.Evaluate(0,0) \u002B emitter.Delay.Evaluate(0,0);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// foreach (var resetable in Resetables )\r\n\t\t\t// {\r\n\t\t\t// \tif(resetable.Duration \u003E duration )\r\n\t\t\t// \t{\r\n\t\t\t// \t\tduration = resetable.Duration;\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\treturn duration;\r\n\t\t}\r\n\t}\r\n\r\n\t[Property, Group( \u0022Actions\u0022 )] private bool Emit { get; set; }\r\n\r\n\t[JsonIgnore, Range( 0f, 1f ), Step( 0.001f )]\r\n\tpublic float PlayBack { get; set; }\r\n\r\n\t[JsonIgnore] public bool IsPlayBack { get; set; }\r\n\r\n\t[Property, Range( 0, 10 ), Step( 0.001f )]\r\n\tpublic float DelayEffect { get; set; }\r\n\r\n\tpublic int ParticleCount\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tint count = 0;\r\n\t\t\tforeach ( var particleEffect in ParticleEffects )\r\n\t\t\t{\r\n\t\t\t\tcount \u002B= particleEffect.ParticleCount;\r\n\t\t\t}\r\n\r\n\t\t\treturn count;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic float PlaybackTime\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tfloat playbackTime = 0;\r\n\t\t\tforeach ( var emitter in ParticleEmitters )\r\n\t\t\t{\r\n\t\t\t\tif ( emitter.IsValid() \u0026\u0026 emitter.time \u003E playbackTime )\r\n\t\t\t\t{\r\n\t\t\t\t\tplaybackTime = emitter.time;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn playbackTime;\r\n\t\t}\r\n\t}\r\n\t\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tSetParticleSystems();\r\n\t\tif ( Scene.IsEditor ) return;\r\n\t\tforeach ( var particleEmitter in ParticleEmitters )\r\n\t\t{\r\n\t\t\tparticleEmitter.Delay = particleEmitter.Delay.Evaluate(0,0) \u002B DelayEffect;\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tPushPhase();\r\n\r\n\t\tif ( !Scene.IsEditor ) return;\r\n\t\tCheckForNullEmitters();\r\n\t\tif ( Emit ) EmitParticles();\r\n\t\tif ( IsRestart ) Restart();\r\n\t\tforeach ( var particleEffect in ParticleEffects )\r\n\t\t{\r\n\t\t\tCheckForNullEffect( particleEffect );\r\n\t\t\tif ( IsPlayBack )\r\n\t\t\t{\r\n\t\t\t\tPlayBacking( particleEffect );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tTimeScaling( particleEffect );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t[Button]\r\n\t[Group( \u0022Actions\u0022 )]\r\n\t[Description( \u0022Gathers all ParticleEffects and ParticleEmitters in this gameobject hierarchy\u0022 )]\r\n\tprivate void SetParticleSystems()\r\n\t{\r\n\t\tParticleEffects = GameObject.GetComponentsInChildren\u003CParticleEffect\u003E().ToList();\r\n\t\tParticleEmitters = GameObject.GetComponentsInChildren\u003CParticleEmitter\u003E().ToList();\r\n\t\tResetables = GameObject.GetComponentsInChildren\u003CIResetable\u003E().ToList();\r\n\t\tPhaseDriven = GameObject.GetComponentsInChildren\u003CIPhaseDriven\u003E().ToList();\r\n\t\t_resolvedPhaseMaster = null;\r\n\t}\r\n\r\n\tprivate ParticleEmitter _resolvedPhaseMaster;\r\n\r\n\t// Single clock for the whole effect. The engine clamps the particle step to\r\n\t// 1/30s (ParticleGameSystem) and zeroes the emitter\u0027s time on each loop\r\n\t// instead of wrapping it, so anything keeping its own accumulator slides out\r\n\t// of phase a little every cycle - visibly, after a handful of loops in the\r\n\t// editor where frame hitches are routine. Slaving those components to the\r\n\t// emitter\u0027s own Delta makes that drift structurally impossible.\r\n\tprivate void PushPhase()\r\n\t{\r\n\t\tif ( !DrivePhaseFromEmitter ) return;\r\n\t\tif ( PhaseDriven is null || PhaseDriven.Count == 0 ) return;\r\n\r\n\t\tvar master = ResolvePhaseMaster();\r\n\t\tif ( master is null ) return;\r\n\r\n\t\tvar phase = master.Delta;\r\n\r\n\t\tforeach ( var driven in PhaseDriven )\r\n\t\t{\r\n\t\t\tif ( driven is null ) continue;\r\n\t\t\tdriven.SetPhase( phase );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate ParticleEmitter ResolvePhaseMaster()\r\n\t{\r\n\t\tif ( PhaseMaster.IsValid() ) return PhaseMaster;\r\n\t\tif ( _resolvedPhaseMaster.IsValid() ) return _resolvedPhaseMaster;\r\n\t\tif ( ParticleEmitters is null ) return null;\r\n\r\n\t\tvar longest = -1f;\r\n\t\tforeach ( var emitter in ParticleEmitters )\r\n\t\t{\r\n\t\t\tif ( !emitter.IsValid() ) continue;\r\n\r\n\t\t\tvar cycle = emitter.Duration.Evaluate( 0, 0 ) \u002B emitter.Delay.Evaluate( 0, 0 );\r\n\t\t\tif ( cycle \u003C= longest ) continue;\r\n\r\n\t\t\tlongest = cycle;\r\n\t\t\t_resolvedPhaseMaster = emitter;\r\n\t\t}\r\n\r\n\t\treturn _resolvedPhaseMaster;\r\n\t}\r\n\r\n\tprivate void EmitParticles()\r\n\t{\r\n\t\tEmit = false;\r\n\t\tforeach ( var effect in ParticleEffects )\r\n\t\t{\r\n\t\t\teffect.Emit( 0, 0 );\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tprivate void TimeScaling( ParticleEffect particleEffect )\r\n\t{\r\n\t\tparticleEffect.TimeScale = TimeScale;\r\n\t\tvar particleEmitter = particleEffect.Components.Get\u003CParticleEmitter\u003E();\r\n\t\tif ( TimeScale \u003C 0 \u0026\u0026 particleEmitter.time \u003C= 0 \u0026\u0026 !IsPaused )\r\n\t\t{\r\n\t\t\tvar timing = particleEmitter.Duration.Evaluate(0,0) - 0.01f;\r\n\t\t\tSetParticulesTiming( particleEffect, timing );\r\n\t\t\tparticleEmitter.time = timing;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tparticleEffect.Paused = IsPaused;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void PlayBacking( ParticleEffect particleEffect )\r\n\t{\r\n\t\tparticleEffect.TimeScale = 0;\r\n\t\tvar particleEmitter = particleEffect.Components.Get\u003CParticleEmitter\u003E();\r\n\t\tvar remappedTiming = PlayBack.Remap( 0, 1f, 0, particleEmitter.Duration.Evaluate(0,0) \u002B particleEmitter.Delay.Evaluate(0,0) );\r\n\t\tparticleEmitter.time = remappedTiming;\r\n\t\tSetParticulesTiming( particleEffect, remappedTiming );\r\n\t}\r\n\r\n\tprivate void Restart()\r\n\t{\r\n\t\tIsPaused = false;\r\n\t\tIsRestart = false;\r\n\t\tforeach ( var particleEffect in ParticleEffects )\r\n\t\t{\r\n\t\t\tparticleEffect.Clear();\r\n\t\t\tparticleEffect.ResetEmitters();\r\n\t\t}\r\n\r\n\t\tforeach( var resetable in Resetables )\r\n\t\t{\r\n\t\t\tresetable.ResetTime();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void SetParticulesTiming( ParticleEffect particleEffect, float timing )\r\n\t{\r\n\t\tvar particleEmitter = particleEffect.Components.Get\u003CParticleEmitter\u003E();\r\n\t\tparticleEmitter.time = timing;\r\n\t\tforeach ( var particule in particleEffect.Particles )\r\n\t\t{\r\n\t\t\tparticule.Age = timing;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void CheckForNullEffect( ParticleEffect particleEffect )\r\n\t{\r\n\t\tif ( !particleEffect.IsValid ) ParticleEffects.Remove( particleEffect );\r\n\t}\r\n\t\r\n\tprivate void CheckForNullEmitters(  )\r\n\t{\r\n\t\tParticleEmitters.RemoveAll( e =\u003E !e.IsValid() );\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Code/ParticleRingEmitterEven.cs","FileName":"ParticleRingEmitterEven.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using System;\r\n\r\nnamespace Sandbox;\r\n[Title(\u0022Particle Ring Emitter Even\u0022)]\r\n[Category( \u0022Particles\u0022 )]\t\r\n[Description(\u0022Let\u0027s you ensure that the particles are placed evenly around the ring when emitted. Simply check the \\\u0022Even Angle\\\u0022 checkbox and you are set !\u0022)]\r\npublic class ParticleRingEmitterEven : ParticleEmitter\r\n{\r\n\t[Property] public ParticleFloat Radius { get; set; } = 50.0f;\r\n\t\r\n\t[Property] public Vector2 RadiusXy { get; set; }\r\n\t[Property] public ParticleFloat Thickness { get; set; } = 10.0f;\r\n\t[Property, Range( 0, 360 )] public ParticleFloat AngleStart { get; set; } = 0.0f;\r\n\t[Property, Range( 0, 360 )] public ParticleFloat Angle { get; set; } = 360.0f;\r\n\t[Property, Range( 0, 1 )] public ParticleFloat Flatness { get; set; } = 0.0f;\r\n\t[Property, Range( -100, 100 )] public ParticleFloat VelocityFromCenter { get; set; } = 0.0f;\r\n\t[Property, Range( -100, 100 )] public ParticleFloat VelocityFromRing { get; set; } = 0.0f;\r\n\t[Property] public bool EvenAngle { get; set; } = false;\r\n\t[Property] public bool FaceCenter { get; set; } = false;\r\n\r\n\tprivate float _angleStep = 0.0f;\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic override bool Emit( ParticleEffect target )\r\n\t{\r\n\t\t\r\n\t\tif ( target.Particles.Count == 0 )\r\n\t\t{\r\n\t\t\t_angleStep = 0.0f;\r\n\t\t}\r\n\t\t\r\n\t\tvar angle = 0f;\r\n\t\tif ( !EvenAngle )\r\n\t\t{\r\n\t\t\tangle = Random.Shared.Float( 0, Angle.Evaluate( Delta, EmitRandom ).DegreeToRadian() );\r\n\t\t\tangle \u002B= AngleStart.Evaluate( Delta, EmitRandom ).DegreeToRadian();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tangle = _angleStep;\r\n\t\t\tAngleStepBurst();\r\n\t\t}\r\n\r\n\t\tvar x = MathF.Sin( angle );\r\n\t\tvar y = MathF.Cos( angle );\r\n\r\n\t\tvar size = new Vector3( x, y, 0 )  * new Vector3(RadiusXy, 0);\r\n\t\tvar ringOffset = Vector3.Zero;\r\n\r\n\t\tvar thickness = Thickness.Evaluate( Delta, EmitRandom );\r\n\r\n\t\tif ( thickness \u003E 0 )\r\n\t\t{\r\n\t\t\tringOffset = Vector3.Random * thickness;\r\n\t\t\tringOffset.z *= (1 - Flatness.Evaluate( Delta, EmitRandom ));\r\n\r\n\t\t\tsize \u002B= ringOffset;\r\n\t\t}\r\n\r\n\t\tsize = (size * WorldScale) * WorldRotation;\r\n\r\n\t\tvar p = target.Emit( WorldPosition \u002B size, Delta );\r\n\t\t\r\n\t\tif ( p is not null )\r\n\t\t{\r\n\t\t\tp.Angles = Rotation.LookAt( Vector3.Direction( p.Position, WorldPosition ) ).Angles();\r\n\t\t\tvar velFromCenter = VelocityFromCenter.Evaluate( Delta, EmitRandom );\r\n\t\t\tif ( velFromCenter != 0 )\r\n\t\t\t{\r\n\t\t\t\tp.Velocity \u002B= (size.Normal * velFromCenter);\r\n\t\t\t}\r\n\r\n\t\t\tvar velFromRing = VelocityFromRing.Evaluate( Delta, EmitRandom );\r\n\t\t\tif ( velFromRing != 0 )\r\n\t\t\t{\r\n\t\t\t\tringOffset = (ringOffset * WorldScale) * WorldRotation;\r\n\t\t\t\tp.Velocity \u002B= (ringOffset.Normal * velFromRing);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\tprivate void AngleStepBurst()\r\n\t{\r\n\t\t_angleStep \u002B= Angle.Evaluate( Delta, EmitRandom ).DegreeToRadian() / Burst.Evaluate( Delta, EmitRandom );\r\n\t}\r\n}\r\n"},{"Ident":"lastfish.particlesystemplus","Path":"Controllers/VortexForce.Cs","FileName":"VortexForce.Cs","PackageType":"library","CodeKind":"Game","AssetVersionId":423080,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\npublic class VortexForce() : ParticleController\r\n{\r\n    [Property]\r\n    public Vector3 VortexCenterOffset { get; set; }\r\n\r\n    [Property]\r\n    public Vector3 Axis { get; set; } = Vector3.Up;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// When true the Axis and center offset follow the controller\u0027s rotation/position,\r\n    /// so the vortex tilts and moves with the emitter. When false they are world-space.\r\n    /// \u003C/summary\u003E\r\n    [Property]\r\n    public bool LocalSpace { get; set; } = false;\r\n\r\n    [Property]\r\n    public ParticleFloat Strength { get; set; } = 100f;\r\n\r\n    [Property]\r\n    public ParticleFloat Responsiveness { get; set; } = 1f;\r\n\r\n    protected override void OnParticleStep(Particle particle, float delta)\r\n    {\r\n        var vortexCenter = LocalSpace\r\n            ? WorldTransform.PointToWorld(VortexCenterOffset)\r\n            : WorldPosition \u002B VortexCenterOffset;\r\n        var axis = LocalSpace ? WorldTransform.NormalToWorld(Axis) : Axis;\r\n\r\n        var r = particle.Position - vortexCenter;\r\n\r\n        var rPlane = r - Vector3.Dot(r, axis) / Vector3.Dot(axis, axis) * axis;\r\n\r\n        if (rPlane.LengthSquared \u003C 0.0001f)\r\n            return;\r\n\r\n        var tangent = Vector3.Cross(axis, rPlane.Normal);\r\n\r\n        var strength = Strength.Evaluate(delta, 6555f);\r\n        var responsiveness = Responsiveness.Evaluate(delta, 6555f);\r\n\r\n        var currentTangentialSpeed = Vector3.Dot(particle.Velocity, tangent);\r\n        var targetDelta = (strength - currentTangentialSpeed) * responsiveness;\r\n        particle.Velocity \u002B= tangent * targetDelta * delta;\r\n    }\r\n}"}]}