Page 5 of 8

Re: change groundcover via script

Posted: Mon Jul 24, 2017 12:58 am
by Bloodknight
look for TerrainEditor::autoMaterialLayer in terrainEditor.cpp, this shows how to paint the terrain via code.

Re: change groundcover via script

Posted: Sun Sep 10, 2017 9:59 am
by subabrain
Hello Guys,

sorry for the long delay but i dont get it :/

i tried all things - to manipulate the c++ methods and try to search for solutions but i dont get it!

i now get it to execute c++ functions with torque 3d but they dont get it to run -> for example:

---------------------------------------------------------------------------------------------------------------------------

grass.cpp

#include "grass.h"
#include "console/simBase.h"
#include "console/console.h"
#include "gui/worldEditor/terrainEditor.h"
#include "gui/worldEditor/terrainActions.h"

IMPLEMENT_CONOBJECT(grass);

void grass::set_grass()
{

TerrainEditor *edit = new TerrainEditor();

edit->autoMaterialLayer(-10000, 10000, 0, 90, 100);

}


---------------------------------------------------------------------------------------------------------------------------


grass.h

#ifndef _SIMBASE_H_  
#include "console/simBase.h"
#include "gui/worldEditor/terrainEditor.h"
#endif

class grass : public SimObject

private:
typedef SimObject Parent;

public:
grass() { grass::set_grass(); }
virtual ~grass() {}
virtual void set_grass();

DECLARE_CONOBJECT(grass);
};

---------------------------------------------------------------------------------------------------------------------------

And the TorqueScript:
grass.cs

function grasses() {

%obj = new grass();
%obj.set_grass();

}


---------------------------------------------------------------------------------------------------------------------------

okay - but i just need to now how i can paint the material on a certain position :roll:

please help me - thx a lot!


Greetings - Robert!

Re: change groundcover via script

Posted: Wed Sep 13, 2017 5:16 pm
by subabrain
Duion wrote:Then it will probably be in the C++ source code.
I looked it up for you and it may be this one:
https://github.com/GarageGames/Torque3D ... #L197-L247


i think this is the key - but how to execute this method?

i tried to make an instance and all the method ... but whats with the arguments?

please help me -.-


Greetz
Robert

Re: change groundcover via script

Posted: Thu Sep 14, 2017 10:50 am
by Duion
The arguments are named, you pass them along when you use the function.
If you miss arguments you usually get an error message like "invalid number of arguments got 2 expected 3" etc.
If you use debug mode in Visual Studio you can even see the data that is passed along with the function.

Re: change groundcover via script

Posted: Thu Sep 14, 2017 4:18 pm
by JeffR
If that's the whole code for your object, you still need a consoleMethod definition so the script system knows what the function is

Similar to [ur=]https://github.com/GarageGames/Torque3D/blob/development/Engine/source/T3D/shapeBase.cpp#L4936-L4947lthis,[/url] you would do something like:

DefineEngineMethod( grass, set_grass, void, (),,
"@Paints some grass.\n\n" )
{
object->set_grass();
}


What this does, is informs the script engine that objects of the 'grass' class have a function called set_grass() that can be called. When it's called, the above is executed by the script engine. So it'll take object(which is automatically the class of the first argument in the DefineEngineMethod function - in this case, "grass" - and then we call set_grass for it.

2 minor nitpicks from your examples I spotted(just to encourage good habits ;) ) you wouldn't want to have the grass::set_grass() call in the constructor. The method isn't static for one thing. Secondly, set_grass doesn't need to be virtual unless you plan to have classes inherit from grass and also have their own set_grass() function. You can leave that as a regular old function, since we'll be calling it through the DefineEngineMethod stuff :)

Re: change groundcover via script

Posted: Thu Sep 14, 2017 10:23 pm
by subabrain
Hello,

first - thanks alot for your help - i did the steps you told.
Its working like you said. but how can i get these arguments in the method:

void PaintMaterialAction::process(Selection * sel, const Gui3DMouseEvent &, bool selChanged, Type)

?

Okay - gn8 ;)

Greetz Robert

Re: change groundcover via script

Posted: Fri Sep 15, 2017 10:39 pm
by subabrain
Hello Friends,

okay now i found something useful

http://abighole.hngamers.com/terrainDeformer.zip

i hope i get it with this one ;)

greetz
Robert :D

Re: change groundcover via script

Posted: Sat Sep 16, 2017 1:20 am
by Azaezel
You won't. The terrain has undergone 3 revisions since then. Though the general principles do still apply.

Re: change groundcover via script

Posted: Sat Sep 16, 2017 9:47 am
by subabrain
Hi,

omg - what shall i do now?

sorry for penetrating you but i am at the end of my knowledge :?

please help!


greetings
Robert

Re: change groundcover via script

Posted: Sun Sep 17, 2017 2:46 pm
by subabrain
Hello,

i have a plan now - i let you know if its ready ;)

greetz
Robert