T3D MIT version, Terrain Texture painting from Code
by Jack Stone · in Torque 3D Professional · 01/03/2013 (11:19 am) · 1 replies
I'm currently doing some work improving and modifying the T3D terrain system, to make it more suitable for my projects (See my other thread: http://www.garagegames.com/community/forums/viewthread/132654)
I am trying to create a Dynamic terrain painting system, where I could pass a terrain, a material, and a location to a function and it would alter the terrain material within a given radius of that location. I am basically trying to do the exact same thing the existing terrain painter does, but from code, instead of from a GUI.
From a server perspective, my game uses a custom Java server instead of the existing Torque server system, so I don't need to network things in the same way. Each client is essentially single player, as far as Torque is concerned. I can just store the changes that have occurred to the terrain on the server, and pass them to every client close enough to see them.
From what I've learned so far (correct me if I'm wrong):
In terrainEditor.cpp, the GUI calls a TerrainProcessActionEvent, which parses the users action (from Paint, to set height, to lower height, etc).
This calls:
PaintMaterialAction::process(Selection * sel, const Gui3DMouseEvent &, bool selChanged, Type)
in terrainActions.cpp, and passes in the "selection", which is a selection of the pixels currently under the players selection cursor in the gui.
This function then calls:
mTerrainEditor->setGridInfo(inf, true);
Which changes the mMaterial "index" of the pixels in the players selection to the new index.
I have successfully manage to change the heights of the terrain using this information, but I can't seem to change the material. I think the problem is with these indexes. I need to know more about what they are, and how they work.
They are in U8 format, but how do the work? Is there somewhere I can see an example of what a terrain index looks like?
Can I, for example, do this:
This compiles, but doesn't work.
Or are indexes numbers? So I would have to do this:
I'd appreciate a few pointers from people who know the terrain system better than me.
I am trying to create a Dynamic terrain painting system, where I could pass a terrain, a material, and a location to a function and it would alter the terrain material within a given radius of that location. I am basically trying to do the exact same thing the existing terrain painter does, but from code, instead of from a GUI.
From a server perspective, my game uses a custom Java server instead of the existing Torque server system, so I don't need to network things in the same way. Each client is essentially single player, as far as Torque is concerned. I can just store the changes that have occurred to the terrain on the server, and pass them to every client close enough to see them.
From what I've learned so far (correct me if I'm wrong):
In terrainEditor.cpp, the GUI calls a TerrainProcessActionEvent, which parses the users action (from Paint, to set height, to lower height, etc).
This calls:
PaintMaterialAction::process(Selection * sel, const Gui3DMouseEvent &, bool selChanged, Type)
in terrainActions.cpp, and passes in the "selection", which is a selection of the pixels currently under the players selection cursor in the gui.
This function then calls:
mTerrainEditor->setGridInfo(inf, true);
Which changes the mMaterial "index" of the pixels in the players selection to the new index.
I have successfully manage to change the heights of the terrain using this information, but I can't seem to change the material. I think the problem is with these indexes. I need to know more about what they are, and how they work.
They are in U8 format, but how do the work? Is there somewhere I can see an example of what a terrain index looks like?
Can I, for example, do this:
inf.mMaterial = U8("grass");
mTerrainEditor->setGridInfo2(inf, true);This compiles, but doesn't work.
Or are indexes numbers? So I would have to do this:
inf.mMaterial = U8(1); mTerrainEditor->setGridInfo2(inf, true);Where "1" is the index of the grass texture?
I'd appreciate a few pointers from people who know the terrain system better than me.
Torque 3D Owner Jack Stone
I tried:
Terrain->updateGridMaterials(Point2I::Zero,Point2I( 1024, 1024 ));
and
mTerrainEditor->scheduleMaterialUpdate();
but neither works. I can get it to work properly by setting the file:
Terrain->setFile(terrFileName);
but, bizarrely, this only works the first two times I call it, after that, the terrain refuses to update, and I have to restart Torque to trigger the update.
Any ideas why these functions don't work properly? This could be a very powerful feature if I can just figure these last few things out...