Api Donation - June 2021 #348
Replies: 6 comments 6 replies
-
Just a few off the top of my head: I posted an issue about this before but some extension methods for the VertexBuffer would be nice to automatically calculate tangents and normals: Introduction of the shader equivalent "fract" function within the math library: The remaining easing function from https://easings.net/ Introduction of Fraction property to public struct TimeUtilTillFraction : IEquatable<TimeUtilTillFraction>
{
private float _targetTime;
private float _endOffset;
public static implicit operator TimeUtilTillFraction( float offset ) => new TimeUtilTillFraction()
{
_targetTime = Time.Now + offset,
_endOffset = offset
};
public static implicit operator float( TimeUtilTillFraction current ) => current._targetTime - Time.Now;
public static implicit operator bool( TimeUtilTillFraction current ) => Time.Now >= current._targetTime;
public float Absolute => _targetTime;
public float Remaining => (float)this;
public float Fraction => (1.0f - ((_targetTime - Time.Now) / _endOffset)).Clamp(0.0f, 1.0f);
public override string ToString() => Remaining.ToString();
public bool Equals( TimeUtilTillFraction other )
{
return _targetTime.Equals( other._targetTime ) && _endOffset.Equals( other._endOffset );
}
public override bool Equals( object obj )
{
return obj is TimeUtilTillFraction other && Equals( other );
}
public override int GetHashCode()
{
unchecked
{
return (_targetTime.GetHashCode() * 397) ^ _endOffset.GetHashCode();
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I’d like to standardize permissions, and a object storage system. I have both and more in my minimal-extended repo: the benefit is we can have a common language for storage and permissions that will be useable anywhere, yet flexible enough to adapt to anyones needs. |
Beta Was this translation helpful? Give feedback.
-
HSVtoRGB. Pretty clear how useful it is to have something like this: Color HsvToRgb( float h, float s, float v )
{
if ( s <= 0.0f )
{
int c = (int)(v * 255.0f);
return Color.FromBytes( c, c, c );
}
float hh = h;
while ( hh >= 360.0f )
{
hh -= 360.0f;
}
hh /= 60.0f;
int i = (int)hh;
float ff = hh - i;
int p = (int)((v * (1.0f - s)) * 255.0f);
int q = (int)((v * (1.0f - (s * ff))) * 255.0f);
int t = (int)((v * (1.0f - (s * (1.0f - ff)))) * 255.0f);
int vs = (int)(v * 255.0f);
switch ( i )
{
case 0:
return Color.FromBytes( vs, t, p );
case 1:
return Color.FromBytes( q, vs, p );
case 2:
return Color.FromBytes( p, vs, t );
case 3:
return Color.FromBytes( p, q , vs );
case 4:
return Color.FromBytes( t, p , vs );
default:
return Color.FromBytes( vs, p , q );
}
} |
Beta Was this translation helpful? Give feedback.
-
I have a few Hammer.MetaDataAttribute's I needed to write to get my FGD up to scratch. Might not fit overall with where you're going with this but they enabled me to do things I had to do so figured I'd share. I put all the attributes in the following gist: // Set the wireframe color in Hammer.
[Hammer.Color( 255, 0, 0 )]
// Draw the entity's transform angle or specific angles property in Hammer. ( Parameters are optional )
[Hammer.DrawAngles( "angles", "angles_islocal" )]
// Use this to indicate to the map builder that any meshes associated with this entity should have a different default physics type.
// Adds the base class PhysicsTypeOverride_* that the map builder is hard coded to use internally.
[Hammer.PhysicsTypeOverride( PhysicsTypeOverride.Mesh )]
// Use this to add Render Properties to the entity, these are used by the map builder.
// Adds base( RenderFields ) as well as hard coded properties vrad_brush_cast_shadows and disableshadows.
// Without this you can't cast lighting properly from static brush entities.
[Hammer.RenderProperties]
// Basic sphere overlay that gets it size from the given property_name.
[Hammer.SphereAttribute( "property_name" )] Overall I'm enjoying the new FGD writer, I feel like the end goal is probably to ditch FGD and have Hammer get these directly from C# which would be great to write Hammer plugins directly in C#. One thing I'm not sure will work is multiple I was also trying to think of a creative way for these class attributes to target specific [Property] attributes but couldn't figure shit. Couple of suggestions on the
|
Beta Was this translation helpful? Give feedback.
-
Wrote a quick simple replacement entity for func_rotating. using Sandbox;
using Sandbox.Internal;
[Library( "simple_rotating", Description = "A rotating mesh entity." )]
[Hammer.Solid]
[Hammer.RenderProperties]
[Hammer.DrawAngles( nameof( AxisDirection ), nameof( AxisIsLocal ) )]
public partial class SimpleRotating : ModelEntity
{
[Property]
[DefaultValue( true )]
public bool Enabled { get; set; } = true;
/// <summary>
/// The rotation speed of the entity in degrees per second.
/// Negative speed can be used to change direction.
/// </summary>
[Property]
[DefaultValue( 100.0f )]
public float Speed { get; set; } = 100.0f;
/// <summary>
/// The direction of the axis the mesh will rotate on.
/// If AxisIsLocal is defined this is relative to the entitiy's current rotation.
/// </summary>
/// <remarks>
/// We define this as Angles rather then a normalized Vector3 so we can take
/// advantage of Hammer's drawangles.
/// </remarks>
[Property( Title = "Axis Direction (Pitch Yaw Roll)" )]
public Angles AxisDirection { get; set; }
/// <summary>
/// Is the axis local to the entity's current rotation?
/// This can be useful for more specific behaviour in nested entities.
/// </summary>
[Property( Title = "Axis Direction Is Local" )]
[DefaultValue( true )]
public bool AxisIsLocal { get; set; } = true;
protected bool _solid;
/// <summary>
/// Whether this entity has collisions.
/// </summary>
[Property]
[DefaultValue( true )]
public bool Solid
{
get => _solid;
set
{
_solid = value;
EnableAllCollisions = value;
}
}
// On spawn use the world rotation for an easy World -> Local direction transform.
protected Rotation InitialWorldRotation;
protected Vector3 Axis
{
get => Angles.AngleVector( AxisDirection ) * (AxisIsLocal ? Rotation.Identity : InitialWorldRotation);
}
public override void Spawn()
{
base.Spawn();
// Keep track of initial rotation for world axis
InitialWorldRotation = Rotation;
EnableAllCollisions = Solid;
SetupPhysicsFromModel( PhysicsMotionType.Static );
}
[Event.Tick]
protected void UpdateRotation()
{
// This entity makes sense to sometimes be created clientside only for aethestic purposes.
// Otherwise we should only set it serverside.
if ( IsClient && !IsClientOnly )
return;
if ( !Enabled )
return;
// Make sure we use the quaternion directly instead of using angles, prevents any locks.
// Tick rate can be variable, so use the tick interval on our speed in degrees per second.
LocalRotation *= Rotation.FromAxis( Axis, Speed * Global.TickInterval );
}
/// <summary>
/// Start the rotator rotating.
/// </summary>
[Input]
protected void Start() => Enabled = true;
/// <summary>
/// Stop the rotator from rotating.
/// </summary>
[Input]
protected void Stop() => Enabled = false;
/// <summary>
/// Toggle the rotator between rotating and not rotating.
/// </summary>
[Input]
protected void Toggle() => Enabled = !Enabled;
} |
Beta Was this translation helpful? Give feedback.
-
public static Vector3 Approach( Vector3 current, Vector3 target, float maxDistanceDelta )
{
Vector3 delta = (target - current);
if ( maxDistanceDelta > delta.Length )
{
return target;
}
else
{
return current + (delta.Normal * maxDistanceDelta);
}
} Can be used to move the vector smoothly towards the target. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Have you coded something you think should be included by default?
Have you made any extension methods for any of the types that you think would be useful to everyone?
Beta Was this translation helpful? Give feedback.
All reactions