Paint Material in Play Mode

There are no stupid questions, just stupid answers.
23 posts Page 2 of 3
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Sun Nov 19, 2017 2:04 pm
Hello Again,

this is now my status:

void TerrainEditor::mow()
{
GameConnection* connection = GameConnection::getConnectionToServer();

Player* playerObject = dynamic_cast< Player* >(connection->getControlObject());

Point3F pos = playerObject->getPosition();

// Fetch the terrain with a ray-trace.
TerrainBlock *terrain = TerrainEditor::getTerrainUnderWorldPoint(Point3F(pos));
F32 squareSize = terrain->getSquareSize();

Point2F p;

GridPoint gp;

gp.terrainBlock = terrain;
// Z-coordinate is not used
gp.gridPos = gp.terrainBlock->getGridPos(Point3F(pos));

GridInfo inf;
GridInfo gi;

TerrainEditor::getGridInfo(gp, gi);

// If grid is already set to our material, or it is an
// empty grid spot, then skip painting.
S32 mat = 1;

inf.mMaterialChanged = true;

// Painting is really simple now... set the one mat index.
inf.mMaterial = mat;
TerrainEditor::setGridInfo(inf, true);

TerrainEditor::scheduleMaterialUpdate();

}


it should work but i cannot run the Method mow - i have done this already after the method:

DefineEngineMethod(TerrainEditor, mow, void, (), ,"")
{
object->mow();
}


i try to run the following command in TorqueScript:

ETerrainEditor.mow();


and already added the method in the terrainEditor.h:

void mow();


so it seems that the function "mow" couldnt run of course there is NOT an Syntax error because it runs without any errors ... but i dont know fruther :roll:

Would be nice if you could help - thx!

Greetings
Robert
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Sun Nov 19, 2017 4:40 pm
Hi,

now i made a complete new class and make instances from the terrainEditor Object - im writing if it works ...

greetz
Robert
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Mon Nov 20, 2017 2:30 pm
Hello Guys,

okay - i get now made some changes with the above code:

first the "mow.cpp":

#include "mow.h"
#include "T3D/player.h"
#include "T3D/gameBase/gameConnection.h"
#include "gui/worldEditor/terrainEditor.h"
#include "gui/worldEditor/terrainActions.h"
#include "console/simBase.h"
#include "console/console.h"
#include "terrain/terrData.h"

IMPLEMENT_CONOBJECT(mow);

void mow::setTerrainMaterial()
{

Point2F pos = Point2F(10.0f, 10.0f);

Con::printf("durchlauf");

U32 mat = 1;

TerrainEditor *mTerrainEditor = new TerrainEditor();

// Fetch the terrain with a ray-trace.
TerrainBlock *terrain = mTerrainEditor->getTerrainUnderWorldPoint(Point3F(pos.x, pos.y, 1000.0f));
F32 squareSize = 2.0;

Point2F p;

GridPoint gp;

gp.terrainBlock = terrain;
// Z-coordinate is not used
gp.gridPos = gp.terrainBlock->getGridPos(Point3F(pos.x, pos.y, 0));

GridInfo inf;
GridInfo gi;

mTerrainEditor->getGridInfo(gp, gi);

// If grid is already set to our material, or it is an
// empty grid spot, then skip painting.
if (inf.mMaterial == mat || inf.mMaterial == U8_MAX)

inf.mMaterialChanged = true;

// Painting is really simple now... set the one mat index.
inf.mMaterial = mat;
mTerrainEditor->setGridInfo(inf, true);

mTerrainEditor->scheduleMaterialUpdate();

}

DefineEngineMethod(mow, setTerrainMaterial, void, (), , "")
{
object->setTerrainMaterial();
}


then the "mow.h":

#include "console/simBase.h"

class mow : public SimObject {

private:

typedef SimObject Parent;

public:

mow() { }

void setTerrainMaterial();

DECLARE_CONOBJECT(mow);

};


and now i run it with the following code in mow.cs: (first i add it to the scriptExec.cs):

function mowit() {

%obj = new mow();
%obj.setTerrainMaterial();

}


okay - now i call the function "mowit" via console in T3D - but it crashes :/

please help!


Thank you very much!

Greetz
Robert
LukasPJ
Site Admin
Posts: 358
Joined: Tue Feb 03, 2015 7:25 pm
 
by LukasPJ » Mon Nov 20, 2017 7:09 pm
Can you post the console.log file?
Try using hastebin or something similar.
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Mon Nov 20, 2017 7:14 pm
hi,

ok - ill do it - one moment.

greetz
Robert
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Tue Nov 21, 2017 8:20 am
Hello,

sorry i tried all but i cannot see any error in the console.log :/
but it crashes!

please help ...

Thx a lot!

Grettings
Robert
LukasPJ
Site Admin
Posts: 358
Joined: Tue Feb 03, 2015 7:25 pm
 
by LukasPJ » Tue Nov 21, 2017 7:29 pm
Alright, just post the console.log here, like all of it. :) I will have a look
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Tue Nov 21, 2017 8:07 pm
Hello,

thanks for your help - ill try another thing yet - if its not working ill post it here - Thanks!

Greetz
Robert
LukasPJ
Site Admin
Posts: 358
Joined: Tue Feb 03, 2015 7:25 pm
 
by LukasPJ » Wed Nov 22, 2017 4:15 pm
Alright, just know that I can't help you without the console.log file :)
subabrain
Posts: 136
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Wed Nov 22, 2017 8:34 pm
Hi there,

okay - i think the sorucecode is right now:

#include "mow.h"
#include "T3D/player.h"
#include "T3D/gameBase/gameConnection.h"
#include "gui/worldEditor/terrainEditor.h"
#include "gui/worldEditor/terrainActions.h"
#include "console/simBase.h"
#include "console/console.h"
#include "terrain/terrData.h"

IMPLEMENT_CONOBJECT(mow);


void mow::setTerrainMaterial() {

//Point3F pos = Point3F(100.0f, 100.0f, 0);

Point2F pos = Point2F(100.0f, 100.0f);

TerrainEditor *mTerrainEditor = new TerrainEditor();

GameConnection* connection = GameConnection::getConnectionToServer();

Player* playerObject = dynamic_cast< Player* >(connection->getControlObject());

//Point3F pos = playerObject->getPosition();

// Fetch the terrain with a ray-trace.
TerrainBlock *terrain = mTerrainEditor->getTerrainUnderWorldPoint(Point3F(pos.x, pos.y, 0));

//Point2F p;

GridInfo gi;
GridPoint gp;

gp.terrainBlock = terrain;
// Z-coordinate is not used
gp.gridPos = gp.terrainBlock->getGridPos(Point3F(pos.x, pos.y, 0));

GridInfo inf;

U32 mat = 1;

mTerrainEditor->getGridInfo(gp, gi);

inf.mMaterialChanged = true;

inf.mMaterial = mat;
mTerrainEditor->setGridInfo(inf, true);

mTerrainEditor->scheduleMaterialUpdate();

}

DefineEngineMethod(mow, setTerrainMaterial, void, (), , "")
{
object->setTerrainMaterial();
}


But i always get an exception with the following code:

"**m**" was "0x1CC".


okay - maybe you could help.

Thanks a lot for all Answers!


Greetings
Robert
23 posts Page 2 of 3

Who is online

Users browsing this forum: Rodnev and 1 guest