How can I start porting Terrain to SWIG?

Problems building or running the engine, queries about how to use features etc.
Post Reply
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

How can I start porting Terrain to SWIG?

Post by r0ut »

Ogre Version: 1.12.11
Since there's no Terrain support and the guy who were making it just disappeared I wanted to start doing it on my own. However I'm pretty new to SWIG and I would like to have some guidance. Here's what I have so far in the .i file:

Code: Select all

%module(package="Ogre") Terrain
%{
/* Includes the header in the wrapper code */
#include "Ogre.h"
%}

%include std_string.i
%include exception.i 
%import "Ogre.i"

#define _OgreTerrainExport

%include "../src/OgreTerrainMaterialShaderHelpers.h"
I also added this to CMakeLists.txt

Code: Select all

if (OGRE_BUILD_COMPONENT_TERRAIN)
  add_subdirectory(Terrain)
endif ()
What should be the next steps?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

r0ut wrote: Fri Mar 19, 2021 3:09 pm Ogre Version: 1.12.11
Since there's no Terrain support and the guy who were making it just disappeared I wanted to start doing it on my own. However I'm pretty new to SWIG and I would like to have some guidance. Here's what I have so far in the .i file:

Code: Select all

%module(package="Ogre") Terrain
%{
/* Includes the header in the wrapper code */
#include "Ogre.h"
%}

%include std_string.i
%include exception.i 
%import "Ogre.i"

#define _OgreTerrainExport

%include "../src/OgreTerrainMaterialShaderHelpers.h"
you should not have to include anything from the src folder.
r0ut wrote: Fri Mar 19, 2021 3:09 pm I also added this to CMakeLists.txt

Code: Select all

if (OGRE_BUILD_COMPONENT_TERRAIN)
  add_subdirectory(Terrain)
endif ()
this sounds wrong. What you should have done is this:
https://github.com/OGRECave/ogre/blob/0 ... ts.txt#L30
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

Thank you for replying Pavel, you're being extremelly gently and helpful with my noob questions
paroj wrote: Fri Mar 19, 2021 3:29 pm this sounds wrong. What you should have done is this:
https://github.com/OGRECave/ogre/blob/0 ... ts.txt#L30
I also did this:

Code: Select all

if(OGRE_BUILD_COMPONENT_TERRAIN)
	set_source_files_properties(../Terrain/include/OgreTerrain.i PROPERTIES CPLUSPLUS ON)
	list(APPEND SWIG_INPUT_MODULES ../Terrain/include/OgreTerrain.i)
endif()
Also, when building it throws me a lot of erros because it doesn't have any definition of the classes and methods. I don't know where, how and if I should reference the files.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

for compile time errors, you probably need #include instead of %include like:
https://github.com/OGRECave/ogre/blob/e ... hader.i#L5

if you are speaking of SWIG warnings, you should rather start with a self-contained class (that only depends on OgreMain) like:
https://github.com/OGRECave/ogre/blob/m ... enerator.h

and add the other classes afterwards.
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

Image
Those are the errors I meant. "X does not contain a definition for Y"
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

you might need to run cmake again or delete the build/csharp folder.

Furthermore, I recommend doing a small SWIG sample project outside of ogre to get used to SWIG without being thrown at with 10 000 lines of generated code and having to wait for 5min so it compiles.
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

I've deleted the folder and it worked! Thanks
Now it has only the constructor in the class file. To add the members and methods, should I use SHARED_PTR, templates or there are more includes needed?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

Ideally you would create a draft pull-request at this point, as I am not quite sure what exactly you are doing
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

Sorry for the late reply. That's what I have so far:

Code: Select all

%module(package="Ogre") Terrain
%{
/* Includes the header in the wrapper code */
#include "Ogre.h"
#include "OgrePrerequisites.h"
#include "OgreTerrain.h"
%}
I have an error in all lines:
#include "Ogre.h":
cannot open source file "Ogre.h"
#include "OgrePrerequisites.h":
cannot open source file "OgrePrerequisites.h"
#include "OgreTerrain.h":
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit.
cannot open source file "OgrePrerequisites.h" (dependency of "OgreTerrain.h")
Then when I try to compile it it throws:
Cannot open include file: 'OgreTerrain.h': No such file or directory
However if I only #include Ogre.h it compiles but then I don't have any methods inside the Terrain class
Last edited by r0ut on Mon Mar 22, 2021 4:00 pm, edited 1 time in total.
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

I have the exact same errors in OgreRTShader.i and it compiles without errors but somehow with Terrain it throws it can't find the .h file
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

Thanks again!
Now I've another error when compiling the wrapper:
'Terrain': undeclared identifier
However if I change that to Ogre::Terrain::Terrain it works.
How can I fix this in the interface? I already tried %rename and %template but had no success

My interface atm

Code: Select all

%module(package="Ogre") Terrain
%{
#include "Ogre.h"
#include "OgreTerrain.h"
#include "OgreTerrainAutoUpdateLod.h"
#include "OgreTerrainGroup.h"
#include "OgreTerrainPagedWorldSection.h"
%}

%include std_string.i
%include exception.i 
%import "Ogre.i"

#define _OgreTerrainExport
%include "OgreTerrainLayerBlendMap.h"
%include "OgreTerrainLodManager.h"
%include "OgreTerrainMaterialGenerator.h"
%include "OgreTerrainPaging.h"
%include "OgreTerrainPrerequisites.h"
%include "OgreTerrainQuadTreeNode.h"
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

please create a draft pull-request at this point, as I am not quite sure what exactly you are doing
r0ut
Halfling
Posts: 44
Joined: Mon Feb 22, 2021 6:25 pm
x 2

Re: How can I start porting Terrain to SWIG?

Post by r0ut »

How can I modify the current Terrain.i to use this function?

Code: Select all

    float* TerrainLayerBlendMap::getBlendPointer()
    {
        return mData.getData<float>();
    }
At the moment the type is SWIGTYPE_p_float. I didn't find anywhere how to wrap pointers in swig.

Is it something like

Code: Select all

%apply float& OUTPUT { float& outX, float& outY };
?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: How can I start porting Terrain to SWIG?

Post by paroj »

the easiest way is something like this:
https://github.com/OGRECave/ogre/commit ... 25ab81dfcc

alternatively, you would need to create a typemap for float*
Post Reply