Cpp Extension questions

Hi folks

I have a few questions on the topic of programming cpp extension.

How to make it possible to use NOT simple types like Mat44, Quat and so on in cpp and kl files before compiling?
cpp code line:
Fabric::EDK::KL::Traits< Fabric::EDK::KL::VariableArray< Fabric::EDK::KL::Mat44 > >::INParam transform,

kl code line:

require Math;

function customTest(Mat44 transform[],

All attempts to load extension lead to error: "error:no extension or type named Math"

Let's say NO to Autodesk®Fabric®

Comments

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited November 2016

    I want to revive the topic and show the first test. This is my first attempt to port a cpp sources. It's the aaOcean plugin (author: Amaan Akram)

    Let's say NO to Autodesk®Fabric®

  • craouettecraouette Posts: 113

    Hi @AlexanderM,

    Is it a port to kl of the plugin, or do you use the dynamic library?

    Pierre

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited November 2016

    Hi Pierre,
    I compiled dll. I like the automated approach with Scons and kl2edk

    Let's say NO to Autodesk®Fabric®

  • borjaborja Administrator, Fabric Employee Posts: 467 admin

    Very Nice @AlexanderM

    What framerates are you getting?

    Borja Morales
    Technical Product Manager
    Fabric Software Inc.

  • AlexanderMAlexanderM Posts: 132 ✭✭

    Hi Borja,
    At this time I get something about 7 fps. It's a bit slower than ICE version. But I made the rough implementation. Fabric creates and deletes a class in each frame. Instead, there needs simulation with the creation of a class only in the first frame and then change it.

    By the way this is my second question, how to manage construct/destruct, not to recreate the class in every frame?

    My first question still stands, I don't know how to load Vec2, Mat44 extensions to kl file involved in compilation, I have to create a similar structures.

    It would be nice to have more example files

    Let's say NO to Autodesk®Fabric®

  • malbrechtmalbrecht Fabric for Houdini Posts: 742 ✭✭✭

    Hi, Alexander,

    I am not sure I understand your first question, but on your second - if I understand that one correctly:

    how to manage construct/destruct, not to recreate the class in every frame?

    ... I would suggest creating a class (if you do not have done so already) in an extension, instanciate an object based on that class and put that into a "variable" (quotation marks to indicate that here I mean "Fabric language", i.e. something that remains active over evaluations of a graph). Have a look at the bullet examples or others that use a "world simulation object" that remains in memory until it gets purged actively.

    So: You'd create a variable that is based on your own class (e.g. "myaaOceanFE"), fill it with the required data, write to it "late" in the graph (after all calculations have been done) and read from it early (before the next iteration starts). Use Canvas' variable read/write functions for that.

    I hope this helps!

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • AhmidouAhmidou Posts: 159 ✭✭

    @AlexanderM, about your 1st question, you need to store your object in canvas variable by checking if you're at the 1st frame or if the object==null

  • AlexanderMAlexanderM Posts: 132 ✭✭

    @malbrecht, @Ahmidou
    Thanks guys, your advice helped me

    Let's say NO to Autodesk®Fabric®

  • MaxMax Fabric for Houdini Posts: 5

    Hi @AlexanderM,

    not sure why you can't use complex types like Vec3. I just did a function which takes a Vec3 array and print it and had no problems.
    Here is the code:

    in KL:

    require Math;
    
    function printPos(in Vec3 positions[]) = "printPos";
    

    in cpp:

    FABRIC_EXT_EXPORT void printPos(
      KL::VariableArray<KL::Vec3>::INParam positions
      )
    {
      int size = positions.size();
      std::cout << "positions (" << size << ")" << std::endl;
    
      for(int i = 0; i < size; ++i)
      {
        std::cout << positions[i].x << " " << positions[i].y << " " << positions[i].z << std::endl;
      }
    }
    
  • MaxMax Fabric for Houdini Posts: 5

    Also, I didn't see but kl2edk copied the whole Math lib in my directory...

  • AlexanderMAlexanderM Posts: 132 ✭✭

    Hi Max,
    Can you show the code in your SConstruct file? Do you have added something there besides the cpp and kl?

    Let's say NO to Autodesk®Fabric®

  • MaxMax Fabric for Houdini Posts: 5

    Hi,

    I didn't use SConstruct, I made a makefile. So I run manually kl2edk with the fpm.json file in parameter and then I run make.
    I only added my own cpp file to the makefile, nothing more.

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited November 2016

    I still have this problem. So I don't know how using SCons to connect third-party libraries. I really don't like dealing with Python and project builders syntax. Examples are very few.
    The Kludge generally requires knowledge of Linux, for me it's more difficult. It would be optimal to have some sort of add-on or base presets for MS Visual Studio

    Let's say NO to Autodesk®Fabric®

  • AhmidouAhmidou Posts: 159 ✭✭
    edited November 2016

    What about trying Kludge instead of kl2edk ?
    edit: sorry, I've just read you last comment.

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited November 2016

    I found the solution, simply add these actions in SConscript file:
    env['ENV']['FABRIC_EXTS_PATH'] = os.environ['FABRIC_EXTS_PATH'] env.AppendENVPath ('FABRIC_EXTS_PATH', env.Dir ('Math')) env.File ('Math/' + 'Math' + '.fpm.json'),
    It 's not difficult, but I just don't like Python :)

    Let's say NO to Autodesk®Fabric®

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited December 2016

    Is it possible using SCons to obtain an analogue of "Additional Include Directories", "Additional Library Directories", and "third-party Sources"? I can't find a detailed answer on Scons forums.
    I only found something similar to this code, but it doesn't help:
    env.Program(target = 'a.out', source = tpSources, LIBPATH = ['C:\FabricEngine\Exts\Builtin\customExtension\lib'], CPPPATH = ['C:\FabricEngine\Exts\Builtin\customExtension\include'])

    upd:
    It seems there is progress
    sourcesNew = env.StaticLibrary(Glob('src\lib\*.cpp')) env.Append( CPPPATH = 'src\include') return env.SharedLibrary( '-'.join([target, buildOS, buildArch]), [cppSources, sourcesNew]) fabricBuildEnv.AddMethod(buildExtension, 'Extension') Export('fabricBuildEnv')

    Let's say NO to Autodesk®Fabric®

  • AlexanderMAlexanderM Posts: 132 ✭✭

    I think I found the solution with Aditional Sources, Libs:

    sourcesNew = env.StaticLibrary(Glob('src\lib\*.cpp')) env.Append(CPPPATH = 'src\include') return env.SharedLibrary( '-'.join([target, buildOS, buildArch]), [cppSources, sourcesNew]) fabricBuildEnv.AddMethod(buildExtension, 'Extension') Export('fabricBuildEnv')

    Let's say NO to Autodesk®Fabric®

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited December 2016

    Does anyone know how to make Scons compile these directives "#pragma omp parallel"?

    upd: I found it
    fabricBuildEnv.Append(CCFLAGS = ['-openmp'])
    fabricBuildEnv.Append(LINKFLAGS = ['-openmp'])

    Let's say NO to Autodesk®Fabric®

  • AlexanderMAlexanderM Posts: 132 ✭✭

    I have one general question. Is there any ways to call a dll functions (from file not compiled for Fabric) like the python ctypes module or winapi LoadLibrary does? I mean a functions with simple types, which Fabric supports

    Let's say NO to Autodesk®Fabric®

  • pzionpzion Moderator, Fabric Employee Posts: 116 Fabric Employee

    No, I'm afraid you have to wrap it in an extension. There is no facility for directly loading a DLL from KL.

    Peter Zion
    Fabric Engine

Sign In or Register to comment.