I am trying to create a simple space partitioning algorithm using the TOctree type. I haven’t gotten incredibly far, in fact I have just gotten to the point where I can define and initialize a generic TOctree variable. I am sharing this little side project of mine with the Unreal Community because I realize that my C++ skills aren’t up to snuff to do the project alone.
I have done a few things already, so I will post those resources below for anyone who is interested in the project.
My current code should be attached to this post. Just drop it in an empty project to get going.
Links to the PrimitiveSceneInfo.h and NavigationOctree.h classes which also use TOctree and may prove useful in understanding it. You do have to be signed into Github to view these.
A postto on the Answerhub which explains the modifications to my constructor.
I want this space partitioning algorithm to be coded in a way that will make it easy for other users to pick up and modify to their liking. Meaning that first iterations of the project will only store simple objects like FVectors, AActors, etc. I also want to it with plenty of comments so that it can be easily understood by someone who is new to Unreal Engine C++ programming like myself.
Just to be clear, this is project open to everyone. I am not hoarding any files and I will post any progress I make on the project here. So please leave a post if you are interested in the project, if you have something to add, whether or not you like what the project is doing, etc.
I will try to revisit this post regularly to update my status on the project and answer any questions.
I’m interested to see how it goes, I’ve been meaning to look into how TOctree can be used for ages. Will help with any questions you have if I can.
Can I suggest putting it up on Github as a public repo? Makes sharing a lot easier than with just a source download.
One thing from a very quick look at your code - your FQuadrantOctreeElement struct should contain a pointer to an AActor, rather than embed an AActor directly.
Thank you for pointing out the error in FQuadrantOctreeElement. I have already made the change.
I was thinking about using Github for the project, but I have never used it to post my own projects. Should I post the whole Unreal project folder or just a small part of it like the Source folder?
I was wondering if anyone had any good ideas for a name of the primary class that will be holding the TOctree element. For right now it is called SpacePartioner.
You can put the whole project into a repo. See one of my projects here for an example.
Just make sure you configure it to ignore things like binaries and intermediate files. You need to set up a .gitignore file, you can see an example here, or just copy that one if you like.
Thank you for all the help kamrann. I watched some Youtube videos and finally got around to learning the ins and outs of Git. I created a Github repository with the latest changes which can be found here.
I did end up using your .gitignore and .gitattributes files. Which leads me to a quesiton. What does the .gitattributes files do exactly and is it necessary in the project?
Also, I was wondering how you use Git. Do you prefer the command line or the GUI?
Please also test what I put up on Github and make sure you can run the code, access the project, and open the blueprints because it all works here on my end.
Just to give an update of what I did today. Essentially, I added to the foundation of the code today. I also created a simple Blueprint to test for functionality. Next I will be working on the debug code to draw the regions of the Octree.
I hope Github will open up a whole new dimension of sharing and cooperation for this project,
Farshooter
I also chose to use that MIT license with this project. This essentially means that if you use code from the project then you need to credit it in some way, which I think is fair. More information can be found here.
I just thought I would give update on my progress. I have finally gotten some progress made on the visual debugging code. There still is some bugs to it. For some reason it doesn’t want to display certain nodes in the octree correctly while it displays others just fine, but for the most part it is looking really good. I have also restructured the project, removed a bunch of files which I thought were unnecessary like the starter content, and made the project compatible with UE 4.9. I also created a short video on YouTube to make the project easier to find and hopefully introduce it to a new audience. The video can be found here.
That’s pretty much what I have been working on.
Anyways, I hope you find this project helpful in your endeavors,
Farshooter
But it’s a void method that appears to return nothing. Have I missed something or is the documentation lying to me? How can I get an ID after adding an octree element?
You haven’t missed anything. The documentation and implementation don’t match here. At some point during the implementation the Epic devs decided to do it differently and forgot to change the comment accordingly. If I’d have to guess it was probably the consequence of calling AddElementToNode for the existing elements when the new element cannot be added to the node (turning a leaf into an actual node with children). With a single return value the caller would only know about a single ID but not all of them that may have changed.
How do you get the FOctreeElementId(s)? Whenever the element passed to AddElement/AddElementToNode is added to its final node in the octree the STATIC function SetElementId(const ElementType& Element, FOctreeElementId Id) is called on the OctreeSemantics type. The OctreeSemantics needs a few more things besides a SetElementId method. See FNavigationOctreeSemantics in NavigationOctree.h/.cpp for an example provided by the engine. In this example the SetElementId function simply stores the data in a TMap (see NavigationSystem.h). Also note there’s a special FNavigationOctree derived from TOctree and another TOctree in LMOctree.h