Quick bit of code assistance please
by Ronald J Nelson · in Torque Game Engine Advanced · 05/12/2008 (6:26 pm) · 6 replies
I am using this to provide a list of materials for my vehicles. For some reason the moment I call it it crashes the game.
For pity's sake it isn't even doing anything besides showing the value in the console. A little help here would be really nice.
void ShapeBase::generateMaterialList()
{
TSMaterialList* pMatList = mShapeInstance->getMaterialList();
Con::errorf("List Size: %d", pMatList->mMaterialNames.size());
/*
for (S32 j = 0; j < pMatList->mMaterialNames.size(); j++)
{
const char* pName = pMatList->mMaterialNames[j];
if(pName != NULL)
{
char buff1[256];
dSprintf(buff1,sizeof(buff1),"%s" ,pName);
Con::executef(mDataBlock,4,"getMaterialList",scriptThis(), getIdString(), buff1);
}
}
*/
}
ConsoleMethod( ShapeBase, generateMaterialList, void, 2, 2, "List all materials for object")
{
object->generateMaterialList();
}For pity's sake it isn't even doing anything besides showing the value in the console. A little help here would be really nice.
#2
05/12/2008 (7:47 pm)
Thank you Phillip. You hit the nail on the head. Now I just need to figure out why I do not have it.
#3
Can someone enlighten me?
05/12/2008 (10:17 pm)
While Phillip was correct in what was causing the crash I cannot understand how it is possible for the vehicle to not even have a materialList in the first place. It should have at the minimum given me the name of the base materials that were exported with the model.Can someone enlighten me?
#4
05/12/2008 (10:31 pm)
When are you calling this function? Make sure the vehicle materials are actually loaded.
#5
In this case, I am trying to avoid creating materials in script prior to loading the vehicle. What I am trying to get is the base material name that was exported with the DTS file itself. The method I am using above worked fine before in some other code I was working on, but not now. I also have see the same technique used in other resources.
So, what I would like to see is it provide me with, for example:
base
window
detail
Since those materials were exported with the DTS file, they should be readable without creating a scripted material.
05/12/2008 (10:38 pm)
I set up a quick echo in my createPlayer function that gives me the ID of the vehicle. Based upon that ID I call this function in the console window. This technique has serve me well in the past.In this case, I am trying to avoid creating materials in script prior to loading the vehicle. What I am trying to get is the base material name that was exported with the DTS file itself. The method I am using above worked fine before in some other code I was working on, but not now. I also have see the same technique used in other resources.
So, what I would like to see is it provide me with, for example:
base
window
detail
Since those materials were exported with the DTS file, they should be readable without creating a scripted material.
#6
Then the rest from above.
05/12/2008 (11:02 pm)
Nevermind. I figured it out on my own. The code that works is as follows:TSShape* tsShape = mShapeInstance->getShape(); TSMaterialList* pMatList = tsShape->materialList;
Then the rest from above.
Associate Phillip O'Shea
Violent Tulip
... TSMaterialList* pMatList = mShapeInstance->getMaterialList(); if (!pMatList) { Con::errorf("ShapeBase::generateMaterialList - Cannot locate material list"); return; } ...