### change groundcover via script

There are no stupid questions, just stupid answers.
• 1
• 3
• 4
• 5
• 6
• 7
• 8

#### Re: change groundcover via script

Bloodknight
Posts: 134
Joined: Tue Feb 03, 2015 8:58 pm
look for TerrainEditor::autoMaterialLayer in terrainEditor.cpp, this shows how to paint the terrain via code.

#### Re: change groundcover via script

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

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 SimObjectprivate:	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

Greetings - Robert!

#### Re: change groundcover via script

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

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?

Greetz
Robert

#### Re: change groundcover via script

Duion
Posts: 914
Joined: Sun Feb 08, 2015 1:51 am

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

JeffR
Steering Committee
Posts: 785
Joined: Tue Feb 03, 2015 9:49 pm

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

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

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

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

Hello Friends,

okay now i found something useful

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

i hope i get it with this one

greetz
Robert

#### Re: change groundcover via script

Azaezel
Posts: 393
Joined: Tue Feb 03, 2015 9:50 pm

You won't. The terrain has undergone 3 revisions since then. Though the general principles do still apply.

#### Re: change groundcover via script

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

Hi,

omg - what shall i do now?

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

greetings
Robert

#### Re: change groundcover via script

subabrain
Posts: 153
Joined: Sat Aug 20, 2016 4:58 pm

Hello,

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

greetz
Robert
• 1
• 3
• 4
• 5
• 6
• 7
• 8

#### Who is online

Users browsing this forum: No registered users and 1 guest