Zarosath Posted October 27, 2017 Share Posted October 27, 2017 Hi, i would like to utilize OpenNN into my torque3d project but i'm a newb on c++.. is it easy at all to include the lib into script? Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted October 29, 2017 Share Posted October 29, 2017 Adding a library is pretty simple, if your familiar with compiling torque. In CMAKE, it is relatively easy, just look at how BulletPhysics is added. You just add the paths to the libraries. In VS it is even more simple I believe, its a matter of rigjtclicking tour solution window and linking your libs. The real question is how these libraries will be integrated into torque. This I believe will take a bit of understanding of c++ and how to debug. Quote Link to comment Share on other sites More sharing options...
Zarosath Posted October 31, 2017 Author Share Posted October 31, 2017 Can you tell me Whether the library may be accessible via function pointers in TorqueScript? Quote Link to comment Share on other sites More sharing options...
Jason Campbell Posted November 1, 2017 Share Posted November 1, 2017 I wish Azaezel or Timmy would pop in and answer because I am no expert. I feel that with a bit of work you could integrate OpenNN into Torque but as I said it would most likely involve a grasp of C++. Quote Link to comment Share on other sites More sharing options...
irei1as Posted November 2, 2017 Share Posted November 2, 2017 Torque3d uses a marshalling (?) thing to comunicate between torquescript and C++, I think.What you want is, probably, to use "DefineConsoleFunction".I don't understand much the C++ base to really help you directly, sorry, but what I do is to check the source code for examples.If you know what function you want to check you could do a global search for all the source code for key words with things like notepad++.For reference, the definition of the macro thing is in source\console\engineAPI.hand some examples could be found for example insource\console\consoleFunctions.cpp Quote Link to comment Share on other sites More sharing options...
JeffR Posted November 3, 2017 Share Posted November 3, 2017 Sorry guys! Halloween was busy for me!Ok, so yeah the just of what everyone is saying is correct.If you want to add a new library and then have it be accessable in script, you have a few steps to do:1) add it to the engine via a library in CMAKE, and then compile it into the engine. As Jason said, you can look at the existing libraries for how to do that(though a wiki page should get made about it). But you'll have a file for the library in cmake, and then add a reference to that via addLibrary(myLibrary) in the torque3d.cmake file so it gets actually included on generation.2) Once it's in and compiling, you'll want to have a way to actually call it to do things. This is where what @irei1as said comes in. You have 2 main macro functions you can add to a file in the engine so that you can call stuff from script:DefineEngineMethod and DefineConsoleFunction.DefineEngineMethod basically attaches a script function to the namespace/object class in question.So if you made a new object derived from ScriptObject to do whatever your library does, you could then add something like: DefineEngineMethod(MyNewObject, myFunction, void, (Point3F position), (Point3F::Zero), "This is a test function that calls a function in myNewObject") { object->myEngineSideFunction(position); } As you can see from above, if we have our new ScriptObject derived class in the engine - MyNewObject in this case, this will add/expose a script-side function 'myFunction' to any object of MyNewObject type.So in script, you could then do: %myObject = new MyNewObject(); %myObject.myFunction(%aPosition); And it will go 'ok, so %myObject is of the class MyNewObject, and yep, there's a script function myFunction, so we'll pass %aPosition in and that gets turned into the 'position' argument.This then calls object->myEngineSideFunction (object in this case being the object you're calling this script function on, and myEngineSideFunction being whatever function in that class you're trying to call) and we pass our position argument into it.If you're not making a new object class and just want to call something, like say, a math function, you do DefineConsoleFunction, which would look like this: DefineConsoleFunction(myFunction, Point3F, (Point3F position), (Point3F::Zero), "This is a test function") { Point3F magicNumber = Point3F(10,9,100); return magicNumber + position; } As you can see, it's similar, but not identical. We don't have the MyNewObject bit in there, because this doesn't associate to any given class or namespace, it exists in the global namespace.We also have a different return type after the function name, instead of void like in the prior example, this one will return a Point3F vector. We similarly pass in a vector argument.So in script, you would do: %result = myFunction(%aPosition); We don't have a namespace, so we call the function directly, passing in our argument and it'll return a result.In practice, you would have your function there call into your library's functions to do whatever you're trying to accomplish, but the setup is the same.Hopefully that explains it! Let me know if you have any other questions or something doesn't make sense :) Quote Link to comment Share on other sites More sharing options...
Zarosath Posted November 9, 2017 Author Share Posted November 9, 2017 I think that will be sufficient, Excellent information dandyman, It requires a certain understanding level of c++ but otherwise quite straightforward.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.