Search Unity

Assets Open source C# library for Unity developers

Discussion in 'Works In Progress - Archive' started by chillersanim, Aug 20, 2019.

  1. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hi all.

    Introduction
    I'm currently in the progress of creating a class library for Unity software developers and want to share it with you.

    The goal of that library is, to provide building blocks for components and game logic.
    It consists of many classes I wrote in the past and deemed useful for general game development.
    The whole library is open source and available on GitHub.

    Link
    https://github.com/chillersanim/CSharp-Tools-for-Unity3D

    Overview
    To give you an idea of what it contains, here a few key components:
    • Spatial3DTree
      A data structure that allows efficient spatial lookup for 3D points using an customized Octree implementation.
    • Polylines
      Basic polyline data structures that allow for efficient point-at-distance and nearest-point lookup.
    • Pipeline
      A framework that allows to pipeline workload and run it in manageable time batches
    • Triangulation
      Triangulates polygons in 3D space using the cutting ears algorithm
    • Call provider
      A singleton class that provides event like callback functionality for various uses (update, fixed update, on draw gizmos, etc.)
    • Helper classes
      Math3D, Nums, VectorMath, CollectionUtil, MeshUtil, etc.
    • Special collections
      AVL Tree, mapping collection, filter collection, etc.
    • Mesh Data
      A data structure that supports building and using polygonized meshes with fast mesh querries ("get all polygons using vertex X", "get connected points to vertex X", etc.)
    Where possible, I made the classes general purpose.

    Note
    The library is a work in progress and prone to (unannounced) changes.
    You may use code you find there under the provided license.
    The wiki contains some information, but is far from complete.

    If you want to contribute your own code, feel free to contact me, or write in this forum thread.
    Also if you find bugs, unclean code or have any kind of improvements, please let me know.

    Regards
    Chillersanim
     
    Last edited: Aug 22, 2019
  2. sharkapps

    sharkapps

    Joined:
    Apr 4, 2016
    Posts:
    145
    Sounds like it has some useful code to puke around in, and a good license. I look forward to taking an in-depth look when I’ve got some cycles.
     
    chillersanim likes this.
  3. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    By now, I added most of my existing code to the repo.
    I need to clean it up a little, add tests and documentation and update the wiki.

    Whats next:
    I'm planning on developing more data structures, that I wanted to implement since quite a while.
    One such data structure is the AabbTree, that stores lots of Bounds and offers efficient 3d querries (intersection, union, etc).
    Here an explanation in 2d.

    Also I want to add more polyline interpolations, like spline or cubic interpolation.

    Changes:
    I added an examle scene that demonstrates an use case for the Spatial3DTree class.
    It shows how data points can be added, moved and searched, and includes some other components as well.
    While doing that, I improved the search performance of the sphere cast and bounds cast in the Spatial3DTree by about 40-50%.

    I refactored some methods and classes, so that the API is more consistent.
    I added some interfaces for better code separation, and fixed some little bugs.

    Here an image that show the Spatial3DTree in action.


    More images can be found in the wiki.
     
    sharkapps likes this.
  4. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    So after some while, another update.

    I added more collections and helper classes.
    The most notable addition being the polygon and the graph classes.

    The polygon allows storage and manipulation of polygonal data.
    That includes generation, querrying, polyToMesh and polygon combination (for touching polygons).

    The graph allows storage and manipulation of graph data.
    It supports directed and undirected graph representations and uses any type as node key.
    Currently there are a few algorithms for simple queries available, such as shortest path, shortest path to nearest from set and finding all connected nodes that match a predicate.
    In order to support custom queries, the graph offers access to internal data via interfaces.

    Additionally, I cleaned up the code base, and added simple versions of 3d aabb (bounds) collection and sphere collection, which allow for inclusion/exclusion querries.
    They are similar to the point collections, only that they store volumes instead of points.
    They provide a basis to test more optimized versions, but can also be used for small data sets.

    The new classes have been used extensivly in some projects, so should be rather safe to use.
    As always, if you find any bugs, please let me know.
    Thanks :)
     
    sharkapps likes this.
  5. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hi all.

    I had to take a break duo to my studies, but now I'm back with a new version.
    A note beforehand: This version has many breaking changes and can cause problems when updating, so make a backup of your code first.


    That being said, lets look at what was done.

    IPoint3DCollection (Collections and Core/Interfaces)
    I changed the way casting in a IPoint3DCollection works.
    Now you provide a shape, which needs to implement IVolume, and the collection uses this shape to cast.
    This allows for many custom shapes and lightweight code for the casting.

    MultiCastExample02.png
    Combination shape of a sphere and an aabb (using VolumeUnion for combination).
    MultiCastExample01.png
    Combination shape of a sphere and an sphere (using VolumeUnion for combination).
    ShapeCastExample01.png
    A volume plane, that represents all the volume on the back side of the plane.

    PointOctree (Collections)
    I implemented a new high performance 3d point collection; PointOctree.cs
    It has fixed bounds, but is about 30-50% faster than Spatial3DTree, and produces less GC and memory cluttering.

    MainThreadDispatch (Core/Common)
    I implemented a main thread dispatcher, that allows you to dispatch calls to the main thread.
    It uses the update loop to execute your calls.
    It supports Await, Invoke(Action), Invoke(Func<T>), Invoke(Delegate), InvokeAsync(Action) and InvokeAsync(Delegate).
    That allows you to invoke blocking or non-blocking actions, functions and delegates on the main thread.
    This can be very useful, if you need to access Unity scripts from a worker thread.

    Interpolation (Core/Interpolation)
    I created a bunch of scalar interpolations, which allow you to interpolate data in the way you want.
    Currently supported are linear, polynomial and catmull-rom (Hermite) interpolations.

    Matrix and Vector (Core/Matrix)
    If you need more flexibility with matrices and vectors, for example double precision or n-dimensional vectors and matrices, this could be for you.
    However, for a full fledged matrix/vector solution, I would recommend dedicated repos, such as c# eigen-wrappers or something similar.

    Utils (Core/Utils)
    I split the utility classes into dedicated classes to clean up the mess I created.
    Also I added a few new utilities, such as NumericsUtility that allows to numerically differentiate a function.

    StreamReplacement (Text)
    Some time ago, I wrote a string replacer for character streams and now added it to the repo.
    If you ever feel like streaming text and need to replace character or string occurrences while doing so, this class can help you do it.


    I made a lot of other changes, however, I just started documenting those changes today.
    So if there are changes I didn't mention here or in the change log, please let me know.

    That's it, feel free to try the new changes and let me know if you have any problems or suggestions.

    Regards
    Chillersanim
     
  6. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Small update

    I moved the MainThreadDispatch to Core/Common, as it's actually not a component.
    Also, I fixed a small mistake, MainThreadDispatch.Invoke<T>(Func<T>) didn't return a task like all other invokes did.

    I added some documentation to some classes and started updating the Wiki on Github with API references.

    Please let me know if you have suggestions or troubles with the new API reference pages.

    Regards
    Chillersanim
     
    manpower13 likes this.