Towards turning materials into materials
by Kirk Longendyke · in Torque Game Engine Advanced · 07/13/2007 (4:55 am) · 23 replies
(this is gonna get a bit spammy. apologies)
First up, let me start out by making it verry clear: this is a nasty, filthy, hacky kludge of a work in progress, and isn't likely to see the inside of a recource for quite a while at this rate.
That being said, till there's an official writeup on how to do this type of thing, more than willing to see if this doesn't start the ball rolling on something better.
So, with the disclaimer out of the way, on to the meat of the endeavor:
Theres several things that the current material system is highly defective for in terms of asset interactivity, that we'll be looking to adress as this goes on, namely:
1- decal placement on a per-material basis
2- sounds likewise
3- general expolosive behavior(you'll see what i mean by that one shortly)
4- damage modification
5- elasticity/friction modification
First up, let me start out by making it verry clear: this is a nasty, filthy, hacky kludge of a work in progress, and isn't likely to see the inside of a recource for quite a while at this rate.
That being said, till there's an official writeup on how to do this type of thing, more than willing to see if this doesn't start the ball rolling on something better.
So, with the disclaimer out of the way, on to the meat of the endeavor:
Theres several things that the current material system is highly defective for in terms of asset interactivity, that we'll be looking to adress as this goes on, namely:
1- decal placement on a per-material basis
2- sounds likewise
3- general expolosive behavior(you'll see what i mean by that one shortly)
4- damage modification
5- elasticity/friction modification
#22
Does get us multimaterial detection support. The bad news is the resultant performance benchmark is currently handshaking a few earthworms as far as laying on decals every few frames once aplied to the acid-tester 900 tri concave shell I'm testing against... could be the frequency of the routine call, could be the embeding it in the core opcode raycast itself. Will need to tinker a bit, but documenting it anyway since theres a few folks now I'm aware of using this stuff as a baseline for other things.
06/18/2008 (6:39 am)
Hrm... well, good news is:bool TSShapeInstance::castRayOpcode( S32 dl, const Point3F & startPos, const Point3F & endPos, RayInfo *info)
{
// if dl==-1, nothing to do
if (dl==-1)
return false;
AssertFatal(dl>=0 && dl<mShape->details.size(),"TSShapeInstance::castRayOpcode");
info->t = 100.f;
// get subshape and object detail
const TSDetail * detail = &mShape->details[dl];
S32 ss = detail->subShapeNum;
S32 od = detail->objectDetailNum;
// set up static data
setStatics(dl);
// nothing emitted yet...
bool emitted = false;
MeshObjectInstance * mesh;
MatrixF* saveMat = NULL;
S32 start = mShape->subShapeFirstObject[ss];
S32 end = mShape->subShapeNumObjects[ss] + start;
if (start<end)
{
MatrixF mat;
MatrixF * previousMat = mMeshObjects[start].getTransform();
mat = *previousMat;
mat.inverse();
Point3F localStart, localEnd;
mat.mulP(startPos, &localStart);
mat.mulP(endPos, &localEnd);
// run through objects and collide
for (S32 i=start; i<end; i++)
{
mesh = &mMeshObjects[i];
if (od >= mesh->object->numMeshes)
continue;
if (mesh->getTransform() != previousMat)
{
// different node from before, set up for this node
previousMat = mesh->getTransform();
if (previousMat != NULL)
{
mat = *previousMat;
mat.inverse();
mat.mulP(startPos, &localStart);
mat.mulP(endPos, &localEnd);
}
}
// collide...
if ( mesh->castRayOpcode(od,localStart, localEnd, info) )
{
saveMat = previousMat;
emitted = true;
}
}
}
if ( emitted )
{
saveMat->mulV(info->normal);
info->point = endPos - startPos;
info->point *= info->t;
info->point += startPos;
TriRayInfo triInfo;
if (mesh->meshList[0]->castRayTri(od,startPos, endPos, &triInfo))
info->material = triInfo.material;
if ( mMaterialList )
{
MatInstance* matInst = mMaterialList->getMaterialInst( info->material );
if ( matInst && matInst->getMaterial() )
info->material = matInst->getMaterial()->getId();
}
}
clearStatics();
return emitted;
}Does get us multimaterial detection support. The bad news is the resultant performance benchmark is currently handshaking a few earthworms as far as laying on decals every few frames once aplied to the acid-tester 900 tri concave shell I'm testing against... could be the frequency of the routine call, could be the embeding it in the core opcode raycast itself. Will need to tinker a bit, but documenting it anyway since theres a few folks now I'm aware of using this stuff as a baseline for other things.
#23
you'll also need to specify wich castray you default to under the quicklos:
As an adendum, you will of course want to check the new, previously altered funcs internally for RayInfo defs, and replace those with TriRayInfo, as well as shift the origional TriRayInfo definition it'sself to sceneobject.h
aaand just to relieve the sheer ammount of text, and action shot with a multimaterial concave polysoup having different sets of treds and dust knocked out on it(with the typical disclaimer that works in progress always look like crap;)):
piics
06/18/2008 (11:09 am)
Ok, so that's sorted. Rather than posting the full-bore changelog of every line for the function overloads, we'll just list the funcs for now, and I'll get those fullbore writeup up on tdn shortly:bool ShapeBase::castRay( const Point3F& start, const Point3F& end, TriRayInfo* rayInfo )
bool TSStatic::castRay(const Point3F &start, const Point3F &end, TriRayInfo* info)
bool SceneObject::castRay(const Point3F&, const Point3F&, TriRayInfo*)
bool Container::castRay(const Point3F &start, const Point3F &end, U32 mask, TriRayInfo* info)
bool TSShapeInstance::castRay(const Point3F & a, const Point3F & b, TriRayInfo * rayInfo, S32 dl)
bool TSShapeInstance::castRayOpcode( S32 dl, const Point3F & startPos, const Point3F & endPos, TriRayInfo *info)
bool TSMesh::castRayTri( S32 frame, const Point3F& start, const Point3F& end, TriRayInfo* rayInfo )
bool InteriorInstance::castRay(const Point3F& s, const Point3F& e, TriRayInfo* info)
bool Interior::castRay(const Point3F& s, const Point3F& e, TriRayInfo* info)
annnd
bool Interior::castRay_r(const U32 node,
const U16 planeIndex,
const Point3F& s,
const Point3F& e,
TriRayInfo* info)you'll also need to specify wich castray you default to under the quicklos:
bool quickLOS(const Point3F & start, const Point3F & end, S32 dl) { return castRay(start,end,(RayInfo *)(NULL),dl); }As an adendum, you will of course want to check the new, previously altered funcs internally for RayInfo defs, and replace those with TriRayInfo, as well as shift the origional TriRayInfo definition it'sself to sceneobject.h
aaand just to relieve the sheer ammount of text, and action shot with a multimaterial concave polysoup having different sets of treds and dust knocked out on it(with the typical disclaimer that works in progress always look like crap;)):
piics
Torque Owner Kirk Longendyke
tscollision.cpp
bool TSShapeInstance::castRayOpcode( S32 dl, const Point3F & startPos, const Point3F & endPos, RayInfo *info) { ... if ( emitted ) { saveMat->mulV(info->normal); info->point = endPos - startPos; info->point *= info->t; info->point += startPos; } ... }to
bool TSShapeInstance::castRayOpcode( S32 dl, const Point3F & startPos, const Point3F & endPos, RayInfo *info) { ... if ( emitted ) { saveMat->mulV(info->normal); info->point = endPos - startPos; info->point *= info->t; info->point += startPos; if ( mMaterialList ) { MatInstance* matInst = mMaterialList->getMaterialInst( info->material ); if ( matInst && matInst->getMaterial() ) info->material = matInst->getMaterial()->getId(); } } ... }unfortunately thats not quite right, since it's not accounting for the proper face-detection, just the primary material. Can't quite put my finger on the exact algorithm to hook in the triray...