Unity.mathx
An Extension Library for Unity.Mathematics - Extension Methods, New Syntax, Optimized Functions, and more !
Guides · Getting started · Fluent chains · Noise · SDF · Jobify The project is written primarily in C#, first published in 2020. Key topics include: extension-methods, game-development, math, math-functions, math-helper.
Unity.mathx


Extension Library for Unity.Mathematics & quality of life improvements !
<br> <!-- <a href="https://ko-fi.com/I2I0IMQA9"> <img align="left" src="https://raw.githubusercontent.com/LTMX/Banners-And-Buttons/main/Support%20Me%20Kofi%20Banner%20Shader%20Graph%20Mastery.png" width="140px"/> </a><br><br> -->Package name
[!NOTE]\
rubycom.ltmx.mathematics.mathx
Repository layout
package/— Unity package (Runtime/,Tests/,package.json)website/— documentation site (MkDocs guides, DocFX API, GitHub Pages output)
⬇️ Install
Method 1 : <br>
- Copy Git Package URL :
https://github.com/ltmx/Unity.mathx.git?path=/package - In Unity :
Window > Package Manager > Add Package From Git URL
Method 2 : <br>
- Download the package in releases
- Unity :
Window > Package Manager > Add Package From Disk - Select the
package.jsonfile inside the unzipped package
#️⃣ Usage
<br>csusing static Unity.Mathematics.mathx;
♾ Linq-Style Syntax
<br>csreturn anyVector.length().clamp(0, 10).cos().sq().cube().rotate(anyQuaternion).clint().div(3.2f).rcp().mul(3.2f).sum();
📈 A Few Neat Features
<br>c// Example float3 x = new float3(1,1,1); // here x is set before computing lengthsq() var x = x.mult(4.2f).shuffle().set(out x).lengthsq() + x; // we would have to write two lines instead x = x.div(4.2f).shuffle(); x = x.lengthsq() + x; bool4.any(); // returns true if any component is true // or-gate bool4.all(); // returns true if all components are true // and-gate
🏛 Roadmap
- Fast Functions
- Constants (PI, HPI, EULER, TAU, and
many scientific constants -
Mathffunction implementations missing fromUnity.Mathematics - Random Extensions (
Random.rangeand others) - Component based functions (
cmax,cmin,cmul,cmaxAxis,cminAxis,sum) - Signed Distance Functions
- Component based logic (
any,all,select,approx,odd,even,isnan,anynan) - Multidimentional Array data accessors =>
anyfloat4[,,].Get(anyInt3) - Interpolation Functions (
InOutCubic,smoothstep,smoothstep11,smoothstep9, and others) -
smoothmin,smoothmax - Shorthands (
3D Directions,2D Directions, and others) - Data Construction (
append,float2.xyzw(), matrix construction, etc) - Data Conversion (
anyColortArray.tofloat4Array(), and others) - Noise Functions (
Simplex,Perlin,Worley,Layered,Voronoi) - Job Helpers
- Burst Compiled Function Pointers
- Function Iterators (prevents nested loops)
- Hashing Functions
- Vector Function Builders
- Generic Jobs
🎇 Structs
<br>cstruct bounds; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Bounds") struct ray; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Ray") struct color; // UnityEngine translation compatible with Unity.Mathematics (implicit cast to "UnityEngine.Color") struct byte4; // Useful for Color32 to byte conversion, Useful for image file export (implicit cast to "UnityEngine.Color32") //For Unity.QOI struct byte3; // For Unity.QOI struct byte2; struct byte1;
API & method reference
The full searchable API (thousands of overloads) is generated from XML docs:
Topic guides: fluent chains, noise, SDF, Jobify, and more on the docs home.
Tests
Edit Mode tests ship in package/Tests/ (Unity Test Framework). Package tests require "testables": ["com.ltmx.mathematics.mathx"] in your project Packages/manifest.json (plus com.unity.test-framework). Then open Window → General → Test Runner → Edit Mode.
See website/docs~/QUALITY.md or the Quality page for setup, golden-value regeneration, and IL2CPP validation.
<br>🌱 Contribute !
👉 Guidelines
- All methods should exist in the
Unity.Mathematics.mathxclass (To prevent multiple using declarations) - All Methods should follow a lower case syntax (shader like syntax)
- All methods names should be as short as possible while conserving their meaning or naming convension
- Everything must be Open Source
- Credits should (if the author can be found) figure above code snipets or in the file header (if reusing existing code)
- file mames should follow this convention : mathx.<usage>.<differentiation>
Example : mathx.interpolation.common (common methods for interpolation) or mathx.logix.floatx (float type related logic functions)- File names for base types such as
boundsorbyte2should only have their type as a title : bounds.cs // byte2.cs
- File names for base types such as
- Every method should be static (if applicable)
- Dependencies should not exist if applicable
- Code must be rewritten and optimized for Unity.Mathematics, compatibility checked
- Unification is key : if some functions are already available in math or Unity.Mathematics.math (sometimes under another name), use them !
- Documentation should be inherited from Unity.Mathematics.math methods for direct extension method translations
📜 LICENSING
<p>This project is licensed under the MIT License (<a href="https://github.com/ltmx/Unity.mathx/blob/master/package/LICENSE.md">License</a>)</p>Contributors
Showing top 5 contributors by commit count.
