Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

444 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity.mathx Documentation Donate

Banner

Read the documentation   API reference

Guides · Getting started · Fluent chains · Noise · SDF · Jobify


GitHub package.json version openupm GitHub Made for Unity


Extension Library for Unity.Mathematics & quality of life improvements !


Package name

[!NOTE]\

com.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 :

  1. Copy Git Package URL : https://github.com/ltmx/Unity.mathx.git?path=/package
  2. In Unity : Window > Package Manager > Add Package From Git URL

Method 2 :

  1. Download the package in releases
  2. Unity : Window > Package Manager > Add Package From Disk
  3. Select the package.json file inside the unzipped package

#️⃣ Usage

using static Unity.Mathematics.mathx;

♾ Linq-Style Syntax

return anyVector.length().clamp(0, 10).cos().sq().cube().rotate(anyQuaternion).clint().div(3.2f).rcp().mul(3.2f).sum();

📈 A Few Neat Features

// 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
  • Mathf function implementations missing from Unity.Mathematics
  • Random Extensions (Random.range and 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

struct 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:

Browse API →

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.


🌱 Contribute !

👉 Guidelines

  • All methods should exist in the Unity.Mathematics.mathx class (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.. Example : mathx.interpolation.common (common methods for interpolation) or mathx.logix.floatx (float type related logic functions)
    • File names for base types such as bounds or byte2 should only have their type as a title : bounds.cs // byte2.cs
  • 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

This project is licensed under the MIT License (License)

Releases

Sponsor this project

Packages

Used by

Contributors

Languages