Dots Plus

Unit Test:

  • 5k Shapes
  • 5k Line and Shape overlap test

Brute Force Rectangle:
124ms (0ms build, 124ms find)

AABRectangle:
24ms (12ms build. 12ms find)

Brute Force Circle (Circumscribed of same rectangle)"
67ms (0ms build, 67ms find)

AABCircle:
41ms(19ms build, 22ms find)

All tests are bursted. Rectangle shows more than 5x improvement over brute, in case tree is re-used that would be 10x.
As expected circle is not showing that much of the win compared to brute force, not even 2x. It is mostly, because union and overlap functions more expensive. Also in case you wonder why brute force circle is faster, it just circle and line test is much cheaper.

1 Like

Released

[1.4.0] - 2022-08-25

  • Changed geometry overlap/intersection not include borders
  • Changed overlap logic to be more faster
  • Added to geometry structures debug display
  • Added AABBTree

For version 1.5 plan to add MeshSurface and VertexData for very fast mesh reading/writing/processing.
Plan to release dots mesh slicer that will use dots plus, to also show the advantages of this package.

Here is demo of mesh slicer in dots that is powered by DelaunayTriangulation and upcoming MeshSurface from dots plus. As example full sphere mesh slice takes somewhere 0.1ms on my *machine.
8430275--1116233--FruitNinja.gif

7 Likes

That’s really cool, can’t wait to try making a sequel to Metal Gear Revengeance.
.

1 Like

Hey Luckas,

Purchased this package yesterday, and while I still haven’t had a chance to check out absolutely everything, it’s looking great!

I did notice an issue during building though where the struct Node in UnsafeAABBTree.cs has a variable

#if ENABLE_UNITY_COLLECTIONS_CHECKS
    public bool IsFree;
#endif

Other places in the script there is logic which uses IsFree without the same wrappers which causes builds to terminate. I just wrapped that other logic with the same preprocessor logic and it worked fine.

Just wanted to let you know.

Anyways thanks for all your work!

1 Like

Oh darn. Fixed in 1.4.1 added for review.

8458286--1122656--Primitives.gif

New additions to upcoming version 1.5. Generating three primitives (Only positions currently).

Box - 0.004ms
Icosphere (2 subdivisions, 42 vertices, 240 indices) - 0.012ms
Icosphere (4 subdivisions, 642 vertices, 3840 indices) - 0.28ms

Box generation in this image

        var attributes = new NativeArray<VertexAttributeDescriptor>(1, Allocator.Temp);
        attributes[0] = new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3);
        var surface = new MeshSurface(1, attributes, Allocator.TempJob);
        JobHandle dependency = surface.Box(Box, default);
        if (TryGetComponent(out MeshFilter meshFilter))
        {
            var meshDataArray = Mesh.AllocateWritableMeshData(1);
            dependency = surface.Write(meshDataArray[0], MeshUpdateFlags.Default, dependency);
            dependency.Complete();
            if (meshFilter.sharedMesh == null)
                meshFilter.sharedMesh = new Mesh();
            Mesh.ApplyAndDisposeWritableMeshData(meshDataArray, meshFilter.sharedMesh);
        }
        attributes.Dispose();
        surface.Dispose();
1 Like

Landed

[1.5.0] - 2022-09-27

  • Changed IVoronoiOutput.ProcessVertex signature
  • Improved performance of DelaunayTriangulation drastically
  • Added VertexData structure for processing vertex information
  • Added MeshSurface structure for processing/reading/writing Mesh
  • Added box/icosphere/icohedron/icocapsule generation suing MeshSurface
  • Added NativeStructureList/UnsafeStructureList for building SoA (structure of array)
  • Added Plane structure (Exposed from Unity Collection package)
  • Added 3d/2d Capsule structure
3 Likes

Release dots mesh slicer that uses this package as dependency https://assetstore.unity.com/packages/tools/modeling/dots-mesh-slicer-233259.

Going to make short break on this package to finish my local avoidance new version (In case anyone is interested Local Avoidance 3.0.0 ). Feel free to put requests here or in discord.

2 Likes

I recently played around with fixed point type, basically the same as float just that point is fixed.
The main two advantages of fixed type over float type:

  • More control over precision. As example, in my mesh slicer package (https://assetstore.unity.com/packages/tools/modeling/dots-mesh-slicer-233259) I used integers as it makes easier to identify similar slices and zero check is more trivial.
  • Deterministic as it uses integer types behind the hood. Will be familiar for those who attempted lock step networking model.
  • There is possibility for some mathematically functions to be faster. For example, sin and cos could use lookup maps on lower precisions (Not confirmed yet).

Made small test with this new type.

// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
using ProjectDawn.Mathematics;
using ProjectDawn.Assertion;
// Int
Assert.AssertEqual(new fixe(5), 5);
Assert.AssertEqual(new fixe(39), 39);
Assert.AssertEqual(new fixe(625), 625);
// Float
Assert.AssertEqual(new fixe(1.5f), 1.5f);
Assert.AssertEqual(new fixe(2.25f), 2.25f);
Assert.AssertEqual(new fixe(0.625f), 0.625f);
// Add
Assert.AssertEqual(new fixe(1.5f) + new fixe(1.25f), 2.75f);
Assert.AssertEqual(new fixe(10.5f) + new fixe(6.5f), 17f);
// Sub
Assert.AssertEqual(new fixe(1.5f) - new fixe(1.25f), 0.25f);
Assert.AssertEqual(new fixe(10.5f) - new fixe(6.5f), 4f);
// Mul
Assert.AssertEqual(new fixe(1.5f) * new fixe(1.25f), 1.875f);
Assert.AssertEqual(new fixe(10.5f) * new fixe(6.5f), 68.25f);
// Div
Assert.AssertEqual(new fixe(1.5f) / new fixe(2f), 0.75f);
Assert.AssertEqual(new fixe(10.5f) / new fixe(4), 2.625f);
// ToString
fixe number = 5.625f;
Console.WriteLine($"number = {number}");
// Mul performance
float[] floats = new float[]
{
    0.5f,
    1.5f,
    2.5f,
    0.25f,
    1.45f,
};
{
    float result = 1;
    var sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 200; ++i)
    {
        result = result * floats[i % floats.Length];
    }
    sw.Stop();
    Console.WriteLine($"Float result:{result} time:{sw.Elapsed.TotalMilliseconds}");
}
{
    float result = 1;
    var sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 200; ++i)
    {
        result = result * floats[i % floats.Length];
    }
    sw.Stop();
    Console.WriteLine($"Float result:{result} time:{sw.Elapsed.TotalMilliseconds}");
}
{
    fixe[] fixes = new fixe[floats.Length];
    for (int i = 0; i < floats.Length; ++i)
        fixes[i] = floats[i];
    fixe result = 1;
    var sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 200; ++i)
    {
        result = result * fixes[i % fixes.Length];
    }
    sw.Stop();
    Console.WriteLine($"Fixe result:{(float)result} time:{sw.Elapsed.TotalMilliseconds}");
}

Result:
number = 5.625
Float result:1.9605227E-07 time:0.0046
Float result:1.9605227E-07 time:0.0003
Fixe result:0.00024414062 time:0.0004

Performance is almost same, result differs, because in this test there is only 8bits after the point.

I am curious if anyone would found this useful if it was in the package? Of course, it would also have vectorized variations too, with all same math functions.

5 Likes

100%. I would have purchased the asset just for the fixed math xD and I know us DOTS Devs working on Sanctuary have been curious about exploring fixed math for a while.

I would love to see some more benchmarks – especially inside bursted jobs!

3 Likes

Yes, definitely!
Also requesting it to have its own suffix like float does.
For example, just writing 1.05fx instead of new fixe(1.05f).

1 Like

I checked that C# has no support for custom type suffixes (At least that is response from stack https://stackoverflow.com/questions/11268213/create-custom-constant-suffix-in-c-sharp).

However, C# allows overloading implicit conversion. So you will be able to do this:

void Foo(fixe value)
{
...
}

Foo(1.5f);

I am actually already doing this in tests:

Assert.AssertEqual(new fixe(5), 5);

As AssertEqual expects integers here, fixe gets converted to integer.

In any case, I would expect in most cases vectorized variation would be used fixe3, so it would not differ much from using float3.

1 Like

One of the users complained that NativePriorityQueue is quite slow in big data, which is true as it uses linked list behind the hood. For this reason, I created additional NativePriorityQueue that is heap based. Also, added suffix to clarify each queue backend and heap one uses key instead of comparer for simplicity.

struct AscendingOrder : IComparer<int>
{
    public int Compare(int x, int y) => x.CompareTo(y);
}

var queue = new NativeLinkedPriorityQueue<int, AscendingOrder>(Allocator.Temp, new AscendingOrder());

queue.Enqueue(2);
queue.Enqueue(1);

Assert.AreEqual(1, queue.Dequeue());
Assert.AreEqual(2, queue.Dequeue());

queue.Dispose();
var queue = new NativeHeapPriorityQueue<int, int>(Allocator.Temp);

queue.Enqueue(2, 2);
queue.Enqueue(1, 1);

Assert.AreEqual(1, queue.Dequeue());
Assert.AreEqual(2, queue.Dequeue());

queue.Dispose();

[1.7.0] - 2022-12-21

  • Added NativeHeapPriorityQueue that uses heap
  • Added NativeLinkedPriorityQueue that uses linked list
  • Deprecated NativePriorityQueue should use now either NativeHeapPriorityQueue or NativeLinkedPriorityQueue

Heap Priority Queue, Peek = O(1), Enqueue = O(log n), Dequeue = O(log n).
LinkedList Priority Queue, Peek = O(1), Enqueue = O(n), Dequeue = O(1).

There is benchmark test that validates big O complexity

Documentation Dots Plus

1 Like

Hi @Lukas_Ch When you get a chance, can you change the bool Equals(object other) overrides (for Circle, Rectangle, etc…) to something like:

public override bool Equals(object other) => other is Rect other1 && this.Equals(other1);

Currently, they are all throw new NotImplementedException().

I could add it, but keep in mind this operation will be used with boxing, thus not working in Burst. What is ure use case?

Not really for an use case, but rather it seems that the EntityEditor (plus UI Toolkit binding) is using this? So if left unimplemented, there will be nonstop errors in the console if you click on an entity that has an compdata that’s using Rectangle for example.

2 Likes

Ohh k, that needs to be fixed for sure, will add to my backlog

3 Likes