[Fixed] TerrainSceneNode smoothFactor deserializeAttributes

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

[Fixed] TerrainSceneNode smoothFactor deserializeAttributes

Post by RdR »

I was unable to change the smooth factor when reading a terrain scene node from an irr scene, so I created a small patch.

Just simply add to the terrain scene node in irr scene file:

Code: Select all

 
<int name="SmoothFactor" value="4" />
 
Patch:

Code: Select all

 
Index: CTerrainSceneNode.cpp
===================================================================
--- CTerrainSceneNode.cpp       (revision 4028)
+++ CTerrainSceneNode.cpp       (working copy)
@@ -39,7 +39,7 @@
        VerticesToRender(0), IndicesToRender(0), DynamicSelectorUpdate(false),
        OverrideDistanceThreshold(false), UseDefaultRotationPivot(true), ForceRecalculation(true),
        CameraMovementDelta(10.0f), CameraRotationDelta(1.0f),CameraFOVDelta(0.1f),
-       TCoordScale1(1.0f), TCoordScale2(1.0f), FileSystem(fs)
+       TCoordScale1(1.0f), TCoordScale2(1.0f), SmoothFactor(0), FileSystem(fs)
        {
                #ifdef _DEBUG
                setDebugName("CTerrainSceneNode");
@@ -91,6 +91,7 @@
                }
 
                HeightmapFile = file->getFileName();
+               SmoothFactor = smoothFactor;
 
                // Get the dimension of the heightmap data
                TerrainData.Size = heightMap->getDimension().Width;
@@ -1398,6 +1399,7 @@
                out->addString("Heightmap", HeightmapFile.c_str());
                out->addFloat("TextureScale1", TCoordScale1);
                out->addFloat("TextureScale2", TCoordScale2);
+               out->addInt("SmoothFactor", SmoothFactor);
        }
 
 
@@ -1408,6 +1410,7 @@
                io::path newHeightmap = in->getAttributeAsString("Heightmap");
                f32 tcoordScale1 = in->getAttributeAsFloat("TextureScale1");
                f32 tcoordScale2 = in->getAttributeAsFloat("TextureScale2");
+               s32 smoothFactor = in->getAttributeAsInt("SmoothFactor");
 
                // set possible new heightmap
 
@@ -1416,7 +1419,7 @@
                        io::IReadFile* file = FileSystem->createAndOpenFile(newHeightmap.c_str());
                        if (file)
                        {
-                               loadHeightMap(file, video::SColor(255,255,255,255), 0);
+                               loadHeightMap(file, video::SColor(255,255,255,255), smoothFactor);
                                file->drop();
                        }
                        else
Index: CTerrainSceneNode.h
===================================================================
--- CTerrainSceneNode.h (revision 4028)
+++ CTerrainSceneNode.h (working copy)
@@ -316,6 +316,7 @@
                // needed for (de)serialization
                f32 TCoordScale1;
                f32 TCoordScale2;
+               s32 SmoothFactor;
                io::path HeightmapFile;
                io::IFileSystem* FileSystem;
        };
 
 
https://sourceforge.net/tracker/?func=d ... tid=540678
Last edited by RdR on Thu Jan 12, 2012 12:18 pm, edited 2 times in total.
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: [Patch] TerrainSceneNode smoothFactor deserializeAttribu

Post by ACE247 »

The simple things always do it. :)
I simply always passed a smooth factor to all terrain scene nodes after loading.

Since you're already doing it quite often RdR, I think I'm also going to crawl through irrlichts source and look for all the little things to add, should be fun! :D
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: [Patch] TerrainSceneNode smoothFactor deserializeAttribu

Post by RdR »

ACE247 wrote:The simple things always do it. :)
I simply always passed a smooth factor to all terrain scene nodes after loading.

Since you're already doing it quite often RdR, I think I'm also going to crawl through irrlichts source and look for all the little things to add, should be fun! :D
Haha, even a small patch of 2 lines can make the Irrlicht Engine better :D
Good luck on finding lots more^^

Btw, how do you apply the smooth factor without using ISceneManager::addTerrainSceneNode() ?
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: [Patch] TerrainSceneNode smoothFactor deserializeAttribu

Post by ACE247 »

I usually just loaded the normal irrlicht scene file, and let it create the terrain node. Then I get the terrain nodes parameters(I only use one terrain node), delete the node, but not the mesh data, then create the node again but pass it the old parameters and mesh data plus the smoothing factor. Its a little dirty since loading speed wasn't a problem. It works. :)
Obviously your changes make it far more elegant.

Also does Irrlichts particle node have full serialization? Last time I checked it didn't.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: [Patch] TerrainSceneNode smoothFactor deserializeAttribu

Post by RdR »

ACE247 wrote:I usually just loaded the normal irrlicht scene file, and let it create the terrain node. Then I get the terrain nodes parameters(I only use one terrain node), delete the node, but not the mesh data, then create the node again but pass it the old parameters and mesh data plus the smoothing factor. Its a little dirty since loading speed wasn't a problem. It works. :)
Obviously your changes make it far more elegant.

Also does Irrlichts particle node have full serialization? Last time I checked it didn't.
Ah yea the same way I create one before, after that I created a custom scene node factory which create a terrain scene node with a other default smooth Factor value.
Don't know, never loaded a particle node from irr scene :P
Post Reply