Serious 3Space Bug
by James Urquhart · in Torque Game Engine · 01/23/2004 (9:50 am) · 4 replies
There is a bug in the 3Space animation code; With normal .dts shapes, you wouldn't even realise it was there. But for odd shapes,
with inconsistent numbers of subshapes and detail levels, it becomes so apparent.
In ts/tsAnimate.cc, the function "TSShapeInstance::animateSubtrees" loops via using the number of subshapes. However, this is TOTALLY WRONG.
Rather, it should loop through the number of detail levels, check flags with the detail level's subshape, and call TSShapeInstance::animate() with the detail level number, since the animate() function uses the detail level number as the parameter, not the subshape number!
A fix for the function is as follows :
Without this fix, billboard detail levels(see my forum post on fixing those) would interfere with the visibility of regular detail levels.
e.g If i put a collision detail level AFTER the billboard detail, the collision would not render(in -show), nor would it work.
This fix does not seem to have any effect on existing shapes, so i think its safe for the moment :)
And to recap, heres the code to fix the billboards (replace setStatics in ts/tsShapeInstance.cc) :
And a small quick fix for unusual crashes when viewing certain parts of the billboard (under certain settings), add this to the end of "void TSLastDetail::chooseView(const MatrixF & mat, const Point3F & scale)" in ts/tsLastDetail.cc :
Please note that only the blender exporter supports these "billboard details" (>= v 5.0, which i will put up sooner or later..hehe), but it is quite simple to insert these details into existing .dts files.
I've still not quite figured out how to get the textures working properly in the billboards though, so they are still not textured yet.
I'd post a lovely screenshot of the billboards working in-game, but my ftp is not working atm :(
with inconsistent numbers of subshapes and detail levels, it becomes so apparent.
In ts/tsAnimate.cc, the function "TSShapeInstance::animateSubtrees" loops via using the number of subshapes. However, this is TOTALLY WRONG.
Rather, it should loop through the number of detail levels, check flags with the detail level's subshape, and call TSShapeInstance::animate() with the detail level number, since the animate() function uses the detail level number as the parameter, not the subshape number!
A fix for the function is as follows :
void TSShapeInstance::animateSubtrees(bool forceFull)
{
// animate all the subtrees
if (forceFull)
// force full animate
setDirty(AllDirtyMask);
for (S32 i=0; i<mShape->details.size(); i++) // details, NOT subshapes!
{
S32 ss = mShape->details[i].subShapeNum;
if (ss < 0) continue; // skip billboards
if (mDirtyFlags[ss] & TransformDirty)
{
animate(i);
mDirtyFlags[ss] = 0;
}
}
}Without this fix, billboard detail levels(see my forum post on fixing those) would interfere with the visibility of regular detail levels.
e.g If i put a collision detail level AFTER the billboard detail, the collision would not render(in -show), nor would it work.
This fix does not seem to have any effect on existing shapes, so i think its safe for the moment :)
And to recap, heres the code to fix the billboards (replace setStatics in ts/tsShapeInstance.cc) :
void TSShapeInstance::setStatics(S32 dl, F32 intraDL, const Point3F * objectScale)
{
ObjectInstance::smTransforms = mNodeTransforms.address();
smRenderData.objectScale = objectScale;
smRenderData.detailLevel = dl;
smRenderData.intraDetailLevel = intraDL;
smRenderData.alwaysAlpha = mAlphaAlways;
smRenderData.alwaysAlphaValue = getAlphaAlwaysValue();
smRenderData.balloonShape = mBalloonShape;
smRenderData.balloonValue = getBalloonValue();
smRenderData.useOverride = mUseOverrideTexture;
smRenderData.override = mOverrideTexture;
S32 ss = mShape->details[dl].subShapeNum;
S32 od = mShape->details[dl].objectDetailNum;
TSMesh::smSaveVerts.setSize(mShape->mMergeBufferSize);
TSMesh::smSaveTVerts.setSize(mShape->mMergeBufferSize);
// If we have a billboard, skip the rest
if (ss < 0)
return;
S32 start = smNoRenderNonTranslucent ? mShape->subShapeFirstTranslucentObject[ss] : mShape->subShapeFirstObject[ss];
S32 end = smNoRenderTranslucent ? mShape->subShapeFirstTranslucentObject[ss] : mShape->subShapeFirstObject[ss] + mShape->subShapeNumObjects[ss];
for (S32 i=start; i<end; i++)
{
TSMesh * mesh = mMeshObjects[i].getMesh(od);
if (mesh)
mesh->saveMergeVerts();
}
}And a small quick fix for unusual crashes when viewing certain parts of the billboard (under certain settings), add this to the end of "void TSLastDetail::chooseView(const MatrixF & mat, const Point3F & scale)" in ts/tsLastDetail.cc :
mBitmapIndex = mClamp(mBitmapIndex, 0, mTextures.size()-1); // make sure we don't get invalid bitmap index!
Please note that only the blender exporter supports these "billboard details" (>= v 5.0, which i will put up sooner or later..hehe), but it is quite simple to insert these details into existing .dts files.
I've still not quite figured out how to get the textures working properly in the billboards though, so they are still not textured yet.
I'd post a lovely screenshot of the billboards working in-game, but my ftp is not working atm :(
About the author
#2
01/23/2004 (11:29 pm)
Man... 3space is just crazy. 0.o
#3
01/27/2004 (2:06 pm)
These changes have been checked into the cvs HEAD, thanks James!
#4
Now if only i could figure out how to fix the materials on the billboard snapshots. They are currently white, since they are taken before materials on a shape are set up, however if i plonk the call to generate the billboards after the call to initialize the Material list, torque screws and the mesh isn't textured at all.
01/27/2004 (2:39 pm)
Thanks Tim :)Now if only i could figure out how to fix the materials on the billboard snapshots. They are currently white, since they are taken before materials on a shape are set up, however if i plonk the call to generate the billboards after the call to initialize the Material list, torque screws and the mesh isn't textured at all.
Torque Owner Tim Gift