Skip to content

Instantly share code, notes, and snippets.

View keenanwoodall's full-sized avatar
🛠️
Making stuff!

Keenan Woodall keenanwoodall

🛠️
Making stuff!
View GitHub Profile
@keenanwoodall
keenanwoodall / CCDIKConstraint.cs
Created September 20, 2024 15:06
Animation Rigging CCDIK
public class CCDIKConstraint : RigConstraint<CCDIKConstraint.Job, CCDIKConstraint.Data, CCDIKConstraint.Binder>
{
public struct Job : IWeightedAnimationJob
{
public FloatProperty jobWeight { get; set; }
public ReadOnlyTransformHandle target;
public NativeArray<ReadWriteTransformHandle> chain;
public NativeArray<Vector3> bindPositions;
public NativeArray<Quaternion> bindRotations;
public NativeArray<float> weights;
@keenanwoodall
keenanwoodall / DistanceConstraint.cs
Created September 20, 2024 01:39
Animation Rigging Distance Constraint
public class DistanceConstraint : RigConstraint<DistanceConstraint.Job, DistanceConstraint.Data, DistanceConstraint.Binder>
{
public struct Job : IWeightedAnimationJob
{
public FloatProperty jobWeight { get; set; }
public ReadOnlyTransformHandle source;
public ReadWriteTransformHandle target;
public Vector3 initialTargetLocalPos;
public float distance;
public void ProcessRootMotion(AnimationStream stream){}
@keenanwoodall
keenanwoodall / rlmui.odin
Last active December 10, 2024 14:00
Easy two-line raylib + microui integration for the Odin programming language
package rlmui
import "core:fmt"
import "core:unicode/utf8"
import mu "vendor:microui"
import rl "vendor:raylib"
@(private) Color32 :: [4]u8
State :: struct {
@keenanwoodall
keenanwoodall / Spring.cs
Created May 24, 2021 19:17
C# implementation of Ming-Lun "Allen" Chou's springing functions for Unity (aka my favorite functions)
// Source: http://allenchou.net/2015/04/game-math-precise-control-over-numeric-springing/
public void Spring(ref float x, ref float v, float xt, float zeta, float omega, float h)
{
float f = 1.0f + 2.0f * h * zeta * omega;
float oo = omega * omega;
float hoo = h * oo;
float hhoo = h * hoo;
float detInv = 1.0f / (f + hhoo);
float detX = f * x + h * v + hhoo * xt;
float detV = v + hoo * (xt - x);
@keenanwoodall
keenanwoodall / BoundedBendDeformer.cs
Created December 10, 2019 17:43
A modified bend deformer that only modifies vertices within a defined bounding box
using UnityEngine;
using Unity.Jobs;
using Unity.Burst;
using Unity.Collections;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Beans.Unity.Mathematics;
namespace Deform
{
@keenanwoodall
keenanwoodall / UnityObjectOperatorOverloadTest.cs
Last active November 9, 2019 18:10
Test if the equality operator for anything that derives from Unity.Object is still overridden. Just put the script in your project and press play in any scene to test.
// read this article for more info: https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/
using UnityEngine;
public class UnityObjectOperatorOverloadTest : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod]
public static void Test()
{
var gameObject = new GameObject("UnityEngine.Object Operator Overload Test");

I think using scopes greatly improves readability. Here's an example of converting a larger section of code. The indenting makes it immediately clear when a scopes begins and ends. Both snippets of code draw the exact same controls.

Before:

EditorGUILayout.BeginVertical("box");
disable = EditorGUILayout.Toggle("Disable Sliders", disable);
indent = EditorGUILayout.IntSlider("Indent Sliders", indent, 1, 4);
@keenanwoodall
keenanwoodall / PrefabUtilityMenuItems.cs
Created August 3, 2019 18:21
Makes creating more than one prefab at once possible
using UnityEngine;
using UnityEditor;
public static class PrefabUtilityMenuItems
{
[MenuItem("Tools/Prefab Utility/Create Prefabs From Selection")]
public static void CreateFromSelection()
{
var selections = Selection.gameObjects;
if (selections == null || selections.Length == 0)
@keenanwoodall
keenanwoodall / Automated Deformation Test
Created August 1, 2019 16:48
A test for deforming meshes without using a deformable component
using UnityEngine;
using UnityEditor;
using Unity.Jobs;
using Deform;
public class AutomatedDeformationTestWindow : EditorWindow
{
private Mesh mesh;
[MenuItem("Tools/Automated Deformation Window")]
@keenanwoodall
keenanwoodall / CustomFloatField.cs
Last active March 13, 2019 23:59
A helper class that lets you draw a float field with more control. You can define a rect where the value is drawn/set and another rect where you can drag to scroll the value.
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor;
public static class CustomFloatField
{
private static readonly int Hint = "EditorTextField".GetHashCode ();
private static readonly Type EditorGUIType = typeof (EditorGUI);
private static readonly Type RecycledTextEditorType = Assembly.GetAssembly (EditorGUIType).GetType ("UnityEditor.EditorGUI+RecycledTextEditor");