MengeCrowdSim / Menge

The source code for the Menge crowd simulation framework
Apache License 2.0
139 stars 63 forks source link

Menge as windows DLL #3

Closed JimSEOW closed 7 years ago

JimSEOW commented 9 years ago

is it possible to integrate Menge to be called by a third party software which provide the two input files and receive e.g. as callback the simulated agent coordinates? If so, how to go about it

MengeCrowdSim commented 9 years ago

Sorry for the delayed response. The simple answer to your question is theoretical "yes". The core menge functionality is written to the dll, MengeCore.dll. In fact, the executable that you've been running is an example of how you would integrate it into arbitrary code.

That said, there are some details. Right now, the running of the simulation is a bit too tightly coupled with the machinery for visualizing it. Ultimately, you need a handle to the simulator that gets constructed and, through that, you can advance the simulation and query agent properties per time step.

We're definitely interested in creating an API that is more amenable to dropping into to other systems. If you'd like to contact us directly (menge@cs.unc.edu) we can work through your particular needs and see if we can't streamline the process.

JimSEOW commented 9 years ago

Thanks for the reply. Going through the features of Menge which make it unique are agent's FSM and impressive list of examples. Ideally, create a .NET API which opens Menge to e.g. Unity. Which means managed c++/CLI making callback straight forwards as well as applying backgroundworker thread. After looking through your comment, I look into codes. The lack of sufficient documents will mean more time to understand the API. If the exe dumps out the paths of agents, this step by step output could be passed through callback. Ideally, agent FSM and goals can be adjusted in response to new environmental conditions. Not sure how straight forwards this can be done. The code can be compiled using visual studio 2013, but not visual studio 2015 RC.

MengeCrowdSim commented 9 years ago

You are not the first person to make this request. And I'm sure you won't be the last. Being able to use this in Unity seems to be a popular feature. So, we'll push it to the top of the list.

The Menge Team

On Sun, Jun 7, 2015 at 3:47 PM, DaveTomas notifications@github.com wrote:

Thanks for the reply. Going through the features of Menge which make it unique are agent's FSM and impressive list of examples. Ideally, create a .NET API which opens Menge to e.g. Unity. Which means managed c++/CLI making callback straight forwards as well as applying backgroundworker thread. After looking through your comment, I look into codes. The lack of sufficient documents will mean more time to understand the API. If the exe dumps out the paths of agents, this step by step output could be passed through callback. Ideally, agent FSM and goals can be adjusted in response to new environmental conditions. Not sure how straight forwards this can be done. The code can be compiled using visual studio 2013, but not visual studio 2015 RC.

— Reply to this email directly or view it on GitHub https://github.com/MengeCrowdSim/Menge/issues/3#issuecomment-109792607.

JimSEOW commented 9 years ago

Menge has uniquely addressed many missing features in other crowd simulator. This explains why there are many requests including mine to create a wrapper on top of your existing c++ DLL, thereby bringing more developers to provide feedback and support, especially the documentation part, which unless we go through the code, we do not really know how to do with many claimed features. Looking forwards to see a wrapper soon.

MengeCrowdSim commented 7 years ago

After extensive experimentation, it appears that this issue is dependent on #34. Unity currently has some obnoxious limitations. It's Mono 2 dependencies limit what versions of .NET can be used to wrap an unmanaged dll into a managed dll.

After dropping back and attempting to create an alternative version, in which we expose a C-style API that can be directly invoked in C# using InteropServices, we found that Unity was failing in loading the MengeCore.dll. Unfortunately, Unity's feedback is notoriously bad:

DllNotFoundException: MengeCore.dll
  at (wrapper managed-to-native) MengeCS.MengeWrapper:InitSimulator (string,string,string)
  at MengeCS.Simulator.Initialize (System.String behaveXml, System.String sceneXml, System.String model) [0x00000] in <filename unknown>:0 
  at SimController.Start () [0x00000] in <filename unknown>:0 

The dll exists, but this message is the default message thrown if there is an error loading the dll (and not necessarily just being absent.) Currently MengeCore.dll has dependencies on extensive numbers of other dlls (SDL, images, etc.) Technically, the core Menge simulation logic should not depend on those external libraries; those are all purely visualization considerations. So, by refactoring Menge's binaries into simulation and visualization, binding it into something Unity can handle would be greatly facilitated..

JimSEOW commented 7 years ago

Due to innovative Microsoft ecosystem e.g. Hololens which supprot UWP that favour c#, it makes sense to consider a C# wrapper. Similar activities are happening in many deep learning github projects which traditionally only favour python, but now are facing strong interest to create wrappers in C#. Hololens do not mean ONLY unity. Hololens means OpenGL through Angel for C# or UrhoSharp for C#. A good way to create c# wrapper without limitations of Unity is to consider cppSharp. Which is the basis how Urho3D c++ project is ported to UrhoSharp. cppSharp simply compile the latest c++ codes and generate the most-up-to-date c# binders. No more manual tweak involved in SWIG. I am responding to this discussion because ALL these wonderful crowd algorithms are "untouchable" to latest innovation in Mixed Realities using e.g Hololens using Unity or alternative through c#

JimSEOW commented 7 years ago

FYI: Please check out UrhoSharp feature examples for 3D Crowd simulation which is already far better than any open source available for c# community.

curds01 commented 7 years ago

Just an FYI; this is being addressed by #39. It's getting a quick review and then it will be pushed. Close on the heels of this will be an example of Unity integration.

curds01 commented 7 years ago

39 has landed. This is now resolved. Information about Unity integration will be released in a day or so.