Jump to content

change groundcover via script


subabrain
 Share

Recommended Posts

hi there,



here a little video of my try on changing groundcover with torque 3d:


https://www.youtube.com/watch?v=obYls7lnc-8


its not finished - just an idea from me.


what i need is to set the player to the position of the brush :)


thanks a lot!


greetings

Robert


PS: im not klicking anything - it shows the material automatically by code - im just moving around with the view ;)

Link to comment
Share on other sites

  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

Hi Guys,


after working endless i found the key function... how to change material on a specific Position - but im not ready now with it ...

 

void TerrainEditor::on3DMouseDown(const Gui3DMouseEvent & event)
{   
   getRoot()->showCursor( false );
 
   if(mTerrainBlocks.size() == 0)
      return;
 
   if (!dStrcmp(getCurrentAction(),"paintMaterial"))
   {
      Point3F pos;
      TerrainBlock* hitTerrain = collide(event, pos);
 
      if(!hitTerrain)
         return;
 
      // Set the active terrain
      bool changed = mActiveTerrain != hitTerrain;
      mActiveTerrain = hitTerrain;
 
      if (changed)
      {
         Con::executef(this, "onActiveTerrainChange", Con::getIntArg(hitTerrain->getId()));
         mMouseBrush->setTerrain(mActiveTerrain);
         //if(mRenderBrush)
            //mCursorVisible = false;
         mMousePos = pos;
 
         mMouseBrush->setPosition(mMousePos);         
 
         return;
      }
   }
   else if ((event.modifier & SI_ALT) && !dStrcmp(getCurrentAction(),"setHeight"))
   {
      // Set value to terrain height at mouse position
      GridInfo info;
      getGridInfo(mMouseBrush->getGridPoint(), info);
      mSetHeightVal = info.mHeight;
      mBrushChanged = true;
      return;
   }
 
   mMousePlane.set( mMousePos, Point3F(0,0,1) );
   mMouseDown = true;
 
   mSelectionLocked = false;
 
   mouseLock();
   mMouseDownSeq++;
   mUndoSel = new Selection;
   mCurrentAction->process(mMouseBrush, event, true, TerrainAction::Begin);
   // process on ticks - every 30th of a second.
   Sim::postEvent(this, new TerrainProcessActionEvent(mMouseDownSeq), Sim::getCurrentTime() + 30);
 
}

 

now i just have to get it running :)


if you can help me please answer 8)



Greetings

Robert

Link to comment
Share on other sites

Hey,


here a cool thing - this is the solution:

 

void TerrainEditor::processAction(const char* sAction)
{
   if(!checkTerrainBlock(this, "processAction"))
      return;
 
   TerrainAction * action = mCurrentAction;
   if (dStrcmp(sAction, "") != 0)
   {
      action = lookupAction(sAction);
 
      if(!action)
      {
         Con::errorf(ConsoleLogEntry::General, "TerrainEditor::cProcessAction: invalid action name '%s'.", sAction);
         return;
      }
   }
 
   if(!getCurrentSel()->size() && !mProcessUsesBrush)
      return;
 
   mUndoSel = new Selection;
 
   Gui3DMouseEvent event;
   if(mProcessUsesBrush)
      action->process(mMouseBrush, event, true, TerrainAction::Process);
   else
      action->process(getCurrentSel(), event, true, TerrainAction::Process);
 
   // check if should delete the undo
   if(mUndoSel->size())
      submitUndo( mUndoSel );
   else
      delete mUndoSel;
 
   mUndoSel = 0;
}

 

this code makes all you need!


and call it from torque script like this:

 

ETerrainEditor.processAction("paintMaterial");

 

but it needs some specific things i didnt know at the moment but it has to do like this!



So stay tuned and good luck!!!



Greetings

Robert

Link to comment
Share on other sites

Hello there,


okay - its almost perfect - just have to move the brush position - but its working:

 

//Set the Brush size here - not necessary
 ETerrainEditor.setBrushSize(30, 30);
 
//Read the index from a specific material - in this case the material with name "sand"
   %matIndex = ETerrainEditor.getMaterialIndex( "sand" );
 
//Here set the paint material and paint it - "test" is in this case the name of your terrain
   ETerrainEditor.setPaintMaterial(%matIndex, "test" ); 
   ETerrainEditor.processAction("paintMaterial");

 

i hope i could help you 8-)


the only thing to do is the brush position .... but thats all you need - you dont have to make anything with c++ ;)



so thanks a lot!


Greetings Robert

Link to comment
Share on other sites

Okay now,


i get it 8-)



So for change the groundcover (here the terrain Material which can layered by Groundcover) from torquescript do the following (without c++):



go to the file "EditorGui.ed.gui" in the folder "tools/worldEditor/gui" and change the line:

 

processUsesBrush = "0";

 

into

 

processUsesBrush = "1";

 

then go to "scripts/server/" and create a File - name it "grass.cs" with the following content:

 

function grass(%this) {
 
   //Make the size of the brush
   ETerrainEditor.setBrushSize(2, 2);
 
   //Set the Shape of the brush
   ETerrainEditor.setBrushType("box");
 
   //Change "grass1" to the material you like
   %matIndex = ETerrainEditor.getMaterialIndex( "grass1" );
 
   //Change "test" to a terrain id you like
   ETerrainEditor.setPaintMaterial(%matIndex, "test"); 
 
   //%curPos = LocalClientConnection.Player.getPosition();
 
   //%x = getword(%curPos, 0);  
   //%y = getword(%curPos, 1);  
   //%pZ = getword(%trans, 2);   
 
   //ETerrainEditor.processAction(%pX, %pY, %pZ, "paintMaterial");
 
   //ETerrainEditor.setBrushPos(getWord(%curPos, 0) + %x, getWord(%curPos, 1) + %y);
 
   //Run the thing
   ETerrainEditor.processAction("paintMaterial");
   //$eventID = schedule(230,0,grass); 
 
}

 

please recognize that the Comments are important for make the brush pos to the player ...


Then add a entry in "scriptExec.cs" with the folder "scripts/server/" somewhere in the file:

 

...
exec("./grass.cs");
...

 

Okay now you can add a material texture with run the command "grass();"

in the console (can be opened with "^" in game).


There is a thing to get the Ground of the Player to be changed ->


From C++ it works with some arguments...


But it should do it also with the TorqueScript -> therefore is a function:

 

%curPos = LocalClientConnection.Player.getPosition();
 
   %x = getword(%curPos, 0);  
   %y = getword(%curPos, 1);  
   //%pZ = getword(%trans, 2);  
 
ETerrainEditor.setBrushPos(getWord(%curPos, 0) + %x, getWord(%curPos, 1) + %y);

 

But its not working in my case :/


I get the following error:

 

scripts/server/grass.cs (19): ETerrainEditor::setBrushPos - wrong number of arguments (got 4, expected min 3 and max 3).

 

maybe someone could help me here :roll:



but thats the way how to do it without C++ ;)


Greetings

Robert


PS: As soon as it works perfect ill make a bigger tutorial - but i think im not getting it without c++ :roll:

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


×
×
  • Create New...