Semi-Noob programming question
by Ronald J Nelson · in Torque Game Engine · 09/15/2006 (8:41 pm) · 14 replies
I have the following code in projectile.cc:
first I added at the top:
#include "dgl/materialPropertyMap.h"
#include "game/tsStatic.h"
then in processTick I have this:
Then in class TSStatic : public SceneObject I have:
Finally in bool TSStatic::onAdd() I have:
I know that I have mShape->iflMaterial.materialSlot wrong, but I don't have a clue what to put there to get the materialIndex for the TSStatic object. Actually I would rather have this work for all ShapeBAse objects but frankly I haven't the foggiest where to start. I suppose to start off with I just need to figure out this part first.
Any help would really be appreciated.
first I added at the top:
#include "dgl/materialPropertyMap.h"
#include "game/tsStatic.h"
then in processTick I have this:
else if( rInfo.object->getTypeMask() & StaticObjectType )
{
TSStatic* staticShp = static_cast<TSStatic*>(rInfo.object);
S32 mapIndex = staticShp->mTSIndex[0];
if (mapIndex != -1)
{
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntryFromIndex(mapIndex);
if(pEntry)
{
pMatType = pEntry->matType;
pMatType = pEntry->matFlags;
}
Con::errorf(ConsoleLogEntry::General, "This is pMatType: %d", pEntry->matType);
Con::errorf(ConsoleLogEntry::General, "This is pMatFlag: %d", pEntry->matFlags);
}
Con::errorf(ConsoleLogEntry::General, "It at least knows it is a Static Object Type");
}Then in class TSStatic : public SceneObject I have:
enum {
tsMaterialIndex = 32
};
S32 mTSIndex[TSStatic::tsMaterialIndex];Finally in bool TSStatic::onAdd() I have:
// Scan out the collision hulls...
U32 i;
for (i = 0; i < mShape->details.size(); i++)
{
char* name = (char*)mShape->names[mShape->details[i].nameIndex];
//***Nelson's Material Mapping Update Start***
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
mTSIndex[i] = pMatMap->getMapEntryFromIndex( mShape->iflMaterial.materialSlot );I know that I have mShape->iflMaterial.materialSlot wrong, but I don't have a clue what to put there to get the materialIndex for the TSStatic object. Actually I would rather have this work for all ShapeBAse objects but frankly I haven't the foggiest where to start. I suppose to start off with I just need to figure out this part first.
Any help would really be appreciated.
#2
09/15/2006 (9:27 pm)
Simple I am trying to access propertyMap.cs to get information on the texture as it is done for terrain objects, I already have it working for interior objects, I just need it to work on dts objects.
#3
and in TSStatic.h:
finally in TSStatic.cc:
Now the mapIndex in the projectile code always equals -1. Any idea where it is I am making a mistake?
09/16/2006 (1:02 pm)
OK I changed it to this now in my projectile code:else if( rInfo.object->getTypeMask() & StaticObjectType )
{
TSStatic* staticShp = static_cast<TSStatic*>(rInfo.object);
S32 mapIndex = staticShp->mTSIndex[0];
if (mapIndex != -1)
{
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntryFromIndex(mapIndex);
if(pEntry)
{
pMatType = pEntry->matType;
pMatType = pEntry->matFlags;
}
Con::errorf(ConsoleLogEntry::General, "This is pMatType: %d", pEntry->matType);
Con::errorf(ConsoleLogEntry::General, "This is pMatFlag: %d", pEntry->matFlags);
}
Con::errorf(ConsoleLogEntry::General, "This is mapIndex: %d", mapIndex);
Con::errorf(ConsoleLogEntry::General, "It at least knows it is a Static Object Type");
}and in TSStatic.h:
//***Nelson's Material Mapping Update Start***
enum {
tsMaterialIndex = 8
};
S32 mTSIndex[TSStatic::tsMaterialIndex];
//***Nelson's Material Mapping Update Stop***
[finally in TSStatic.cc:
// Scan out the collision hulls...
U32 i;
for (i = 0; i < mShape->details.size(); i++)
{
char* name = (char*)mShape->names[mShape->details[i].nameIndex];
//***Nelson's Material Mapping Update Start***
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
mTSIndex[i] = pMatMap->getIndexFromName( name );
//***Nelson's Material Mapping Update Stop***Now the mapIndex in the projectile code always equals -1. Any idea where it is I am making a mistake?
#4
09/16/2006 (5:59 pm)
Aw come on, I know they did this in TSE for dts objects so can someone give me an idea how to do this here?
#5
09/16/2006 (7:48 pm)
As far as I can tell, my real issue here is a failure to find the value in either TSShape, TSStatic or TSShapeInstance that gives the name of the texture(or textures) used to skin the object. Does someone know where you can access this information?
#6
The material list is on the actual shape instance -- you don't need to go mucking with the properties at all.
09/17/2006 (10:37 am)
You can get the MaterialList. From that, you can get the TextureHandle for each texture in the material list. From that, you can get the texture (just call getName() on the handle). Or you can just get the material name from the material list.The material list is on the actual shape instance -- you don't need to go mucking with the properties at all.
#7
09/17/2006 (11:25 am)
YEs I saw something like that in TSShapeInstance::reSkin that last night about 4 a.m. . However I see a problem with trying to utilize that for what you can see are my needs. If I am to use the material mapping code as it is right now I need to either put this into an index, or just have the ability to pull the specific texture name up based on the static cast. However since this is a materiallist class and not an index, it leaves me with a problem of conversion or just being able to pull this one specific instance of texture. You have been very helpful to me, thank you. I don't suppose you have any idea how to get around my last dilemma do you?
#8
"hplus" you have been a huge help. However I am have trouble still trying to get the following:
1. getting the material list for a rInfo.object.
2. getting the specific bitmap from that materialList.
With those I can easily use a getIndexFromName then a getMapEntryFromIndex to get to my information in the propertyMap.cs for this specific texture.
I just really need more help with 1 and 2. I have to admit this is really not my strong point, but I am learning. I have to say this community rocks since in the past year I have learned so much and my project is already way ahead of schedule, I just really needed this one to finish up the projectile code.
09/17/2006 (7:56 pm)
What seems to be one stinking line of code is a complete halt to my entire project. I have even been looking at other forums and have yet to see how I could pull this off. "hplus" you have been a huge help. However I am have trouble still trying to get the following:
1. getting the material list for a rInfo.object.
2. getting the specific bitmap from that materialList.
With those I can easily use a getIndexFromName then a getMapEntryFromIndex to get to my information in the propertyMap.cs for this specific texture.
I just really need more help with 1 and 2. I have to admit this is really not my strong point, but I am learning. I have to say this community rocks since in the past year I have learned so much and my project is already way ahead of schedule, I just really needed this one to finish up the projectile code.
#9
2. Check out the declaration of MaterialList in the header. It has functions to get the texture handle and filename path for each material (by index).
09/17/2006 (9:16 pm)
1. Getting the material list varies based on what the type is. You already test for type TSStatic, so you can test for other types, too.2. Check out the declaration of MaterialList in the header. It has functions to get the texture handle and filename path for each material (by index).
#10
09/18/2006 (5:32 pm)
Man I just don't get it. I know that I have a SceneObject in rInfo.object and that I can get the TSStatic from that. That really is not helping though since anything I try to include getting information from the object as a TSShapeInstance fails since you cannot convert a TSStatic into a TSShapeInstance, You have to have a TSShape for that and I have no idea how to go with that since TSShape is not a class that can convert as I did with TSStatic from a SceneObject. Then to top it all off I have no idea how to get the material list based off of the object specifically towards the point of impact that would give me the specific bitmap. I see the sections you are pointing out but they do not seem to want to work with each other. I could really use an example of what to do.
#11
Once you have the material, and the shape, you need to raycast into the shape to find the specific triangle that you hit. Then extract the U/V coordinates of that triangle to calculate the exact U/V of the hit point, and use that to look up in the material texture, if you need the specific pixel.
If all you want is an attribute per material (steel has better armor than leather), you can just use the "material" field that comes out of the ray info.
Last, to get the shape instance from a TSStatic, you need to publish an accessor, because the declaration of mShapeInstance is protected (as you can clearly see if you just read the TSShape class declaration...)
09/19/2006 (8:48 am)
I'm assuming you're trying to test the specific impact point to be able to do things like not hit transparent pixels, or perhaps support different amounts of armor on different body parts. Thus, getting just the material won't be enough, as you need to sample the texture to get the alpha value.Once you have the material, and the shape, you need to raycast into the shape to find the specific triangle that you hit. Then extract the U/V coordinates of that triangle to calculate the exact U/V of the hit point, and use that to look up in the material texture, if you need the specific pixel.
If all you want is an attribute per material (steel has better armor than leather), you can just use the "material" field that comes out of the ray info.
Last, to get the shape instance from a TSStatic, you need to publish an accessor, because the declaration of mShapeInstance is protected (as you can clearly see if you just read the TSShape class declaration...)
#12
I also know that I am using this on DTS objects with more than one material, yet I still only get 0. No if that is all that needs to be then something is in fact wrong with rInfo.Material in terms of DTS objects. Also, yes I have read the TSShape class declaration and have tried to do exactly what you have said, however from what I am seeing, I think rInfo is not truly getting the material information from the object.
Is there perhaps a change that needs to be made to allow it to do so?
09/19/2006 (10:11 am)
J \"hplus\" W - All I need is an attribute per material. The problem I have with the material field that comes from the ray info is that it always reads 0. I know that it works because it works on interior objects just fine.I also know that I am using this on DTS objects with more than one material, yet I still only get 0. No if that is all that needs to be then something is in fact wrong with rInfo.Material in terms of DTS objects. Also, yes I have read the TSShape class declaration and have tried to do exactly what you have said, however from what I am seeing, I think rInfo is not truly getting the material information from the object.
Is there perhaps a change that needs to be made to allow it to do so?
#13
OK, now I understand what you're trying to do. Yes, that won't work, because DTS objects have a collision mesh which is totally separate from the rendered mesh.
Thus, you need to cast a ray into the (quite likely animated/posed) rendering mesh, to find the rendered triangle that the ray would hit. You'd have to write code for doing this yourself, although you can probably leverage a lot of the existing code. (Maybe there's a resource or something?)
Also, note that there's no guarantee that a ray that hits the collision geometry will actually hit any part of the posed/animated renderable shape.
09/19/2006 (1:09 pm)
Quote:something is in fact wrong with rInfo.Material in terms of DTS objects
OK, now I understand what you're trying to do. Yes, that won't work, because DTS objects have a collision mesh which is totally separate from the rendered mesh.
Thus, you need to cast a ray into the (quite likely animated/posed) rendering mesh, to find the rendered triangle that the ray would hit. You'd have to write code for doing this yourself, although you can probably leverage a lot of the existing code. (Maybe there's a resource or something?)
Also, note that there's no guarantee that a ray that hits the collision geometry will actually hit any part of the posed/animated renderable shape.
#14
09/19/2006 (3:20 pm)
Yes that is exactly what I am trying to do. Now to figure out how.
Torque Owner J "hplus" W