s&box Package Code Search
Search C# source code, UI razor templates, shaders, and configs across s&box packages.
link Raw Facepunch API Link: https://public.facepunch.com/sbox/code/search/1/?ident=yeetsneet.lidar_test&take=20
Showing code results for query:
*
(5 total matches found)
Game
game
using System;
public sealed class Lidar : Component
{
[Property] public float RebuildRate { get; set; } = 0.25f;
[Property] public float PointSize { get; set; } = 5.0f;
[Property] public Material DotMaterial { get; set; }
[Property] public ModelRenderer Model { get; set; }
private float lastUpdate = 0f;
private bool isDirty = false;
private readonly List<Vertex> vertices = new();
private readonly List<int> indices = new();
protected override void OnStart()
{
DotMaterial ??= Material.Load( "materials/default.vmat" );
Model ??= Components.GetOrCreate<ModelRenderer>();
}
protected override void OnUpdate()
{
if ( !isDirty )
return;
float nowTime = Time.Now;
if ( (nowTime - lastUpdate) < RebuildRate )
return;
lastUpdate = nowTime;
RebuildModel();
}
public void AddPoint( Vector3 pos, Vector3 normal )
{
normal = normal.Normal;
Vector3 tangent = Vector3.Cross(
normal,
MathF.Abs( normal.z ) < 0.99f
? Vector3.Up
: Vector3.Forward
).Normal;
Vector3 bitangent = Vector3.Cross( normal, tangent ).Normal;
float half = PointSize * 0.5f;
int baseIndex = vertices.Count;
vertices.Add( new Vertex(
pos + (tangent + bitangent) * half,
normal,
new Vector4( tangent, 1 ),
new Vector2( 0, 0 )
) );
vertices.Add( new Vertex(
pos + (tangent - bitangent) * half,
normal,
new Vector4( tangent, 1 ),
new Vector2( 0, 1 )
) );
vertices.Add( new Vertex(
pos + (-tangent - bitangent) * half,
normal,
new Vector4( tangent, 1 ),
new Vector2( 1, 1 )
) );
vertices.Add( new Vertex(
pos + (-tangent + bitangent) * half,
normal,
new Vector4( tangent, 1 ),
new Vector2( 1, 0 )
) );
indices.Add( baseIndex + 0 );
indices.Add( baseIndex + 1 );
indices.Add( baseIndex + 2 );
indices.Add( baseIndex + 0 );
indices.Add( baseIndex + 2 );
indices.Add( baseIndex + 3 );
isDirty = true;
}
public void ClearPoints()
{
vertices.Clear();
indices.Clear();
isDirty = true;
}
public void RebuildModel()
{
isDirty = false;
if ( vertices.Count == 0 )
return;
var mesh = new Mesh( DotMaterial );
mesh.CreateVertexBuffer( vertices.Count, vertices );
mesh.CreateIndexBuffer( indices.Count, indices.ToArray() );
Model.Model = new ModelBuilder()
.AddMesh( mesh )
.Create();
}
}
Game
game
global using static Sandbox.Internal.GlobalGameNamespace;
global using Microsoft.AspNetCore.Components;
global using Microsoft.AspNetCore.Components.Rendering;
[assembly: global::System.Reflection.AssemblyMetadata( "AddonTitle", "lidar" )]
[assembly: global::System.Reflection.AssemblyMetadata( "AddonIdent", "lidar_test" )]
[assembly: global::System.Reflection.AssemblyMetadata( "OrgIdent", "yeetsneet" )]
[assembly: global::System.Reflection.AssemblyMetadata( "Ident", "yeetsneet.lidar_test" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineVersion", "29" )]
[assembly: global::System.Reflection.AssemblyMetadata( "EngineMinorVersion", "1" )]
[assembly: System.Runtime.Versioning.TargetFramework( ".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0" )]
[assembly: global::System.Reflection.AssemblyMetadata( "CompileTime", "2026-10-07T04:23:04.9395740Z" )]
[assembly: global::System.Reflection.AssemblyVersion("0.0.158.0")]
[assembly: global::System.Reflection.AssemblyFileVersion("0.0.158.0")]
Game
game
using Sandbox;
using Sandbox.Diagnostics;
using System;
public sealed class LidarControler : Component
{
[Property] public Lidar lidar;
[Property] public float randomFov = 0f;
[Property] public float fireRate = 1 / 30f;
[Property] public int rayBachCount = 5;
public float lastFire = 0f;
private CameraComponent camera;
private Random random;
protected override void OnUpdate()
{
if ( Input.Down( "Attack1" ) )
{
BasicRay();
}
base.OnUpdate();
}
protected override void OnStart()
{
camera = Scene.Camera;
random = new();
base.OnStart();
}
private Rotation randomRotionFov( float randomFov )
{
float angle = random.Float( 0f, MathF.PI * 2f );
float radius = MathF.Sqrt( random.Float( 0f, 1f ) ) * randomFov;
float x = MathF.Cos( angle ) * radius;
float y = MathF.Sin( angle ) * radius;
return Rotation.From( x, y, 0f );
}
private void FireRay( Vector3 pos, Rotation rot )
{
SceneTraceResult tr = Scene.Trace
.Ray( pos, pos + rot.Forward * 1e6f )
.WithoutTags( "lidar" )
.Run();
if ( tr.Hit == false ) { return; }
lidar.AddPoint(
tr.HitPosition - tr.Normal * 0.01f,
tr.Normal
);
}
private void BasicRay()
{
float nowTime = Time.Now;
if ( (nowTime - lastFire) < fireRate )
{
return;
}
Vector3 pos = camera.WorldPosition;
Rotation rot = camera.WorldRotation;
for ( var i = 0; i < rayBachCount; i++ )
{
FireRay( pos, rot * randomRotionFov( randomFov ) );
}
lastFire = nowTime;
}
}
Game
game
global using Sandbox; global using System.Collections.Generic; global using System.Linq;
Game
game
Debug: View Raw JSON Response
{
"TotalCount": 5,
"Files": [
{
"Ident": "yeetsneet.lidar_test",
"Path": "scripts/Lidar.cs",
"FileName": "Lidar.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 421300,
"IsPrivate": false,
"Code": "using System;\r\n\r\npublic sealed class Lidar : Component\r\n{\r\n\t[Property] public float RebuildRate { get; set; } = 0.25f;\r\n\t[Property] public float PointSize { get; set; } = 5.0f;\r\n\t[Property] public Material DotMaterial { get; set; }\r\n\r\n\t[Property] public ModelRenderer Model { get; set; }\r\n\r\n\tprivate float lastUpdate = 0f;\r\n\tprivate bool isDirty = false;\r\n\r\n\tprivate readonly List<Vertex> vertices = new();\r\n\tprivate readonly List<int> indices = new();\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tDotMaterial ??= Material.Load( \"materials/default.vmat\" );\r\n\t\tModel ??= Components.GetOrCreate<ModelRenderer>();\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif ( !isDirty )\r\n\t\t\treturn;\r\n\r\n\t\tfloat nowTime = Time.Now;\r\n\r\n\t\tif ( (nowTime - lastUpdate) < RebuildRate )\r\n\t\t\treturn;\r\n\r\n\t\tlastUpdate = nowTime;\r\n\r\n\t\tRebuildModel();\r\n\t}\r\n\r\n\tpublic void AddPoint( Vector3 pos, Vector3 normal )\r\n\t{\r\n\t\tnormal = normal.Normal;\r\n\r\n\t\tVector3 tangent = Vector3.Cross(\r\n\t\t\tnormal,\r\n\t\t\tMathF.Abs( normal.z ) < 0.99f\r\n\t\t\t\t? Vector3.Up\r\n\t\t\t\t: Vector3.Forward\r\n\t\t).Normal;\r\n\r\n\t\tVector3 bitangent = Vector3.Cross( normal, tangent ).Normal;\r\n\r\n\t\tfloat half = PointSize * 0.5f;\r\n\r\n\t\tint baseIndex = vertices.Count;\r\n\r\n\t\tvertices.Add( new Vertex(\r\n\t\t\tpos + (tangent + bitangent) * half,\r\n\t\t\tnormal,\r\n\t\t\tnew Vector4( tangent, 1 ),\r\n\t\t\tnew Vector2( 0, 0 )\r\n\t\t) );\r\n\r\n\t\tvertices.Add( new Vertex(\r\n\t\t\tpos + (tangent - bitangent) * half,\r\n\t\t\tnormal,\r\n\t\t\tnew Vector4( tangent, 1 ),\r\n\t\t\tnew Vector2( 0, 1 )\r\n\t\t) );\r\n\r\n\t\tvertices.Add( new Vertex(\r\n\t\t\tpos + (-tangent - bitangent) * half,\r\n\t\t\tnormal,\r\n\t\t\tnew Vector4( tangent, 1 ),\r\n\t\t\tnew Vector2( 1, 1 )\r\n\t\t) );\r\n\r\n\t\tvertices.Add( new Vertex(\r\n\t\t\tpos + (-tangent + bitangent) * half,\r\n\t\t\tnormal,\r\n\t\t\tnew Vector4( tangent, 1 ),\r\n\t\t\tnew Vector2( 1, 0 )\r\n\t\t) );\r\n\r\n\t\tindices.Add( baseIndex + 0 );\r\n\t\tindices.Add( baseIndex + 1 );\r\n\t\tindices.Add( baseIndex + 2 );\r\n\r\n\t\tindices.Add( baseIndex + 0 );\r\n\t\tindices.Add( baseIndex + 2 );\r\n\t\tindices.Add( baseIndex + 3 );\r\n\r\n\t\tisDirty = true;\r\n\t}\r\n\r\n\tpublic void ClearPoints()\r\n\t{\r\n\t\tvertices.Clear();\r\n\t\tindices.Clear();\r\n\r\n\t\tisDirty = true;\r\n\t}\r\n\r\n\tpublic void RebuildModel()\r\n\t{\r\n\t\tisDirty = false;\r\n\r\n\t\tif ( vertices.Count == 0 )\r\n\t\t\treturn;\r\n\r\n\t\tvar mesh = new Mesh( DotMaterial );\r\n\r\n\t\tmesh.CreateVertexBuffer( vertices.Count, vertices );\r\n\t\tmesh.CreateIndexBuffer( indices.Count, indices.ToArray() );\r\n\r\n\t\tModel.Model = new ModelBuilder()\r\n\t\t\t.AddMesh( mesh )\r\n\t\t\t.Create();\r\n\t}\r\n}\r\n"
},
{
"Ident": "yeetsneet.lidar_test",
"Path": ".obj/__compiler_extra.cs",
"FileName": "__compiler_extra.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 421300,
"IsPrivate": false,
"Code": "global using static Sandbox.Internal.GlobalGameNamespace;\r\nglobal using Microsoft.AspNetCore.Components;\r\nglobal using Microsoft.AspNetCore.Components.Rendering;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonTitle\", \"lidar\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"AddonIdent\", \"lidar_test\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"OrgIdent\", \"yeetsneet\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"Ident\", \"yeetsneet.lidar_test\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineVersion\", \"29\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"EngineMinorVersion\", \"1\" )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \".NETCoreApp,Version=v9.0\", FrameworkDisplayName = \".NET 9.0\" )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \"CompileTime\", \"2026-10-07T04:23:04.9395740Z\" )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\"0.0.158.0\")]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\"0.0.158.0\")]"
},
{
"Ident": "yeetsneet.lidar_test",
"Path": "scripts/LidarControler.cs",
"FileName": "LidarControler.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 421300,
"IsPrivate": false,
"Code": "using Sandbox;\r\nusing Sandbox.Diagnostics;\r\nusing System;\r\n\r\npublic sealed class LidarControler : Component\r\n{\r\n\t[Property] public Lidar lidar;\r\n\t[Property] public float randomFov = 0f;\r\n\t[Property] public float fireRate = 1 / 30f;\r\n\t[Property] public int rayBachCount = 5;\r\n\r\n\tpublic float lastFire = 0f;\r\n\tprivate CameraComponent camera;\r\n\tprivate Random random;\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif ( Input.Down( \"Attack1\" ) )\r\n\t\t{\r\n\t\t\tBasicRay();\r\n\t\t}\r\n\r\n\t\tbase.OnUpdate();\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tcamera = Scene.Camera;\r\n\t\trandom = new();\r\n\r\n\t\tbase.OnStart();\r\n\t}\r\n\r\n\tprivate Rotation randomRotionFov( float randomFov )\r\n\t{\r\n\t\tfloat angle = random.Float( 0f, MathF.PI * 2f );\r\n\t\tfloat radius = MathF.Sqrt( random.Float( 0f, 1f ) ) * randomFov;\r\n\r\n\t\tfloat x = MathF.Cos( angle ) * radius;\r\n\t\tfloat y = MathF.Sin( angle ) * radius;\r\n\r\n\t\treturn Rotation.From( x, y, 0f );\r\n\t}\r\n\r\n\tprivate void FireRay( Vector3 pos, Rotation rot )\r\n\t{\r\n\t\tSceneTraceResult tr = Scene.Trace\r\n\t\t\t.Ray( pos, pos + rot.Forward * 1e6f )\r\n\t\t\t.WithoutTags( \"lidar\" )\r\n\t\t\t.Run();\r\n\r\n\t\tif ( tr.Hit == false ) { return; }\r\n\r\n\t\tlidar.AddPoint(\r\n\t\t\ttr.HitPosition - tr.Normal * 0.01f,\r\n\t\t\ttr.Normal\r\n\t\t);\r\n\t}\r\n\r\n\r\n\tprivate void BasicRay()\r\n\t{\r\n\t\tfloat nowTime = Time.Now;\r\n\t\tif ( (nowTime - lastFire) < fireRate )\r\n\t\t{\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tVector3 pos = camera.WorldPosition;\r\n\t\tRotation rot = camera.WorldRotation;\r\n\r\n\t\tfor ( var i = 0; i < rayBachCount; i++ )\r\n\t\t{\r\n\t\t\tFireRay( pos, rot * randomRotionFov( randomFov ) );\r\n\t\t}\r\n\r\n\t\tlastFire = nowTime;\r\n\t}\r\n}\r\n"
},
{
"Ident": "yeetsneet.lidar_test",
"Path": "Assembly.cs",
"FileName": "Assembly.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 421300,
"IsPrivate": false,
"Code": "global using Sandbox;\r\nglobal using System.Collections.Generic;\r\nglobal using System.Linq;\r\n"
},
{
"Ident": "yeetsneet.lidar_test",
"Path": "scripts/Gputest.cs",
"FileName": "Gputest.cs",
"PackageType": "game",
"CodeKind": "Game",
"AssetVersionId": 421300,
"IsPrivate": false,
"Code": "\r\n"
}
]
}