Fix for DTS Auto Billboards
by James Urquhart · in Torque Game Engine · 12/19/2003 (4:01 pm) · 18 replies
Hi there,
I noticed that in the SDK, there is support for some sort of DTS billboard,which uses images taken from various positions round the model in order to make a very simplified representation of the model.
(in ts/tsLastDetail.cc)
To cut it short, whilst the code was there to make this feature work, it wasn't quite working in torque. It expected a detail level in the shape to be present, with the subshape index < 0. However, some of the other code did not take into account that this value may be -1(or lower), so a crash would occur.
The code that needs to be fixed is TSShapeInstance::setStatics, in tsShapeInstance.cc, and it needs to look like :
If you want to try out these billboarded meshes, you need to mod the 3dsmax / ms2dts / whatever you use exporter to :
- Export a detail level with a small size, and subshape -1
- Store packed variables in the Detail Level's object variable.
For my blender exporter, you can do the following :
Add :
And in the DtsShape constructor :
I have not quite ironed out all the bugs i seem to be getting, but it works :)
I would apreciate it if anyone else could tell me if they can get it working :)
I have uploaded a sample DTS here :
--EDIT: no longer exists. Use the blender or max exporters to create a billboard detail in a dts shape--
(The billboard is the second detail level)
And lastly, a screenshot i did whilst trying to get it to work. Can you guess what it is? :)
--EDIT: screenshot no longer exists--
I noticed that in the SDK, there is support for some sort of DTS billboard,which uses images taken from various positions round the model in order to make a very simplified representation of the model.
(in ts/tsLastDetail.cc)
To cut it short, whilst the code was there to make this feature work, it wasn't quite working in torque. It expected a detail level in the shape to be present, with the subshape index < 0. However, some of the other code did not take into account that this value may be -1(or lower), so a crash would occur.
The code that needs to be fixed is TSShapeInstance::setStatics, in tsShapeInstance.cc, and it needs to look like :
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();
}
}(I think thats all you need to edit)If you want to try out these billboarded meshes, you need to mod the 3dsmax / ms2dts / whatever you use exporter to :
- Export a detail level with a small size, and subshape -1
- Store packed variables in the Detail Level's object variable.
For my blender exporter, you can do the following :
Add :
def encodeBillBoard(equator, polar, polarangle, dl, dim, includepoles): val = 0 # dim is width + height # 2, 2, 45, 0, 256, 0 val |= (equator & 0x7F) val |= (val & 0xF3) << 7 polarAngle = int(polarangle / (0.5 * 3.14159265358979323846 * (1.0/64.0)) ) val |= (polarAngle & 0x3F) << 13 # ^^ Not sure if we are encoding polarAngle properly, as it appears to be ~1.0 if we set it to 45 etc val |= (dl & 0x0F) << 19 val |= (dim & 0xFF) << 23 if includepoles == 1: val |= (1 & 0x80000000) # true else: val |= (0 & 0x80000000) # false return val
And in the DtsShape constructor :
# NEW: Add a billboard detail level for the billboard code
print "> Making Billboard Detail"
bbOb = encodeBillBoard(5, 5, 120, 0, 64, 0)
self.detaillevels.append(DetailLevel(self.addName("BILLBOARD_LEVEL"), -1, bbOb, 2.0, -1, -1, 0))I have not quite ironed out all the bugs i seem to be getting, but it works :)
I would apreciate it if anyone else could tell me if they can get it working :)
I have uploaded a sample DTS here :
--EDIT: no longer exists. Use the blender or max exporters to create a billboard detail in a dts shape--
(The billboard is the second detail level)
And lastly, a screenshot i did whilst trying to get it to work. Can you guess what it is? :)
--EDIT: screenshot no longer exists--
About the author
#2
Can someone explain how to get this working from the max6/7 exporter? I didn't quite understand from the instructions above,( and the test file seems to be gone):
what do you mean by subshape -1 ? and packed variables?
thanks.
01/27/2005 (1:18 pm)
I just ran across this last week in the code, this sounds wonderful! I saw that the exporter matrix claims this is supported in the max exporter also.Can someone explain how to get this working from the max6/7 exporter? I didn't quite understand from the instructions above,( and the test file seems to be gone):
Quote:
If you want to try out these billboarded meshes, you need to mod the 3dsmax / ms2dts / whatever you use exporter to :
- Export a detail level with a small size, and subshape -1
- Store packed variables in the Detail Level's object variable.
what do you mean by subshape -1 ? and packed variables?
thanks.
#3
01/28/2005 (6:28 pm)
Yeah me too - can someone please explain this as i would love to get it working.
#4
For the max and maya exporters, you don't have to do any "mods", just prefix the right string in front of what detail level you want BB'ed.
01/29/2005 (12:50 am)
Try prepending, ah... BB:: , maybe?For the max and maya exporters, you don't have to do any "mods", just prefix the right string in front of what detail level you want BB'ed.
#5
I thought this was something different than that, some sort of automatic billboarder, not that you are specifying a detail level to be billboarded, but that it will render the object from different directions creating a special kind of billboard detail level. chosing the proper one to use based on how you are looking at it.
I thought that BB and BBZ were just for making an object be rendered oriented in a certain way.
01/29/2005 (1:12 am)
Thanks for the reply Ben,I thought this was something different than that, some sort of automatic billboarder, not that you are specifying a detail level to be billboarded, but that it will render the object from different directions creating a special kind of billboard detail level. chosing the proper one to use based on how you are looking at it.
I thought that BB and BBZ were just for making an object be rendered oriented in a certain way.
#6
If you want to get this working.. perpend the detail marker you want a billboarded mesh for with a "BB::"
this is similar to a regular billboard mesh, but instead of prepending the mesh name, you prepend the marker (no mesh need exist at that detail level, the auto billboarder will gerneate it)
In the user properties of the marker.. you can use these paremeters:
BB::DIM= //use 64, 128, 256.. etc...
BB::EQUATOR_STEPS=//usually set betweeen 8-12
BB::POLAR_STEPS=// usually 4-6
so there is not confusion:
the marker in question should be named somethng like
BB::detail 2
and the info in user props should looks something like:
BB::DIM=128
BB::EQUATOR_STEPS=12
BB::POLAR_STEPS=6
Show Tool Pro should support viewing of shapes exported with automatically generated billboards..
01/29/2005 (7:32 am)
For 3dsMAX..If you want to get this working.. perpend the detail marker you want a billboarded mesh for with a "BB::"
this is similar to a regular billboard mesh, but instead of prepending the mesh name, you prepend the marker (no mesh need exist at that detail level, the auto billboarder will gerneate it)
In the user properties of the marker.. you can use these paremeters:
BB::DIM=
BB::EQUATOR_STEPS=
BB::POLAR_STEPS=
so there is not confusion:
the marker in question should be named somethng like
BB::detail 2
and the info in user props should looks something like:
BB::DIM=128
BB::EQUATOR_STEPS=12
BB::POLAR_STEPS=6
Show Tool Pro should support viewing of shapes exported with automatically generated billboards..
#7
thanks! I'll try it out.
Are you guys using this at BT at all?
01/29/2005 (7:53 am)
Ahh, I understand now, I was confused with the BB:: in front of the detail vs the mesh itself. thanks! I'll try it out.
Are you guys using this at BT at all?
#8
I'm using the exporter for max 6/7 right now( no source code for it ). I'll play around with a few things and look at the original exporter code ..see if I can figure it out.
01/29/2005 (9:19 am)
Hmm no luck, I'm getting some crashes.I'm using the exporter for max 6/7 right now( no source code for it ). I'll play around with a few things and look at the original exporter code ..see if I can figure it out.
#9
01/29/2005 (1:18 pm)
Where are the crashes?
#10
I put the water back in and within a few mins it crashes when i move the cameara over the game scene.
I then erased my water block and made a new one - and the same happened.
Another idea i had, was that because the water block was huge, and actually run underneath the terrain - that it maybe (in my mind of how things work) a probs with the raycasting, cos the engine may of thought the player was trying to enter water..... cos it was only mms beneath the terrain block. Not that my scene is a sea shore... so the water runs almost concurrent with the terrai level.
So,,,, i reduced the water block size so it just came up to the shore and didnt run underneath the terrain - it still crashed.
One last atempt, had me think... take the terrain out. So i did as most of my area is done with difs anyway - and it still crashed.
i took the waterblock out.. and no crashing for hours and hours and hours.. if at all
So i am baffled????
Instead of the waterblock.... is there a way i can use my own water plain 2 poly object, texture it, and then makes its alpha so it is see through( i have actually just posted this on here too - how do make the object so its ghostsed in affect? cos that would do as i wish to use the mirror object for a small reflective water scene elsewhere in the game).
Cheers
Steve
01/29/2005 (1:25 pm)
This is the problem Ben. When i have water in the level, the engine crashes at various points. Moreson... when i colide with an object. Originally i thought it was the collision that was causing it.. But guess what.. I loads all my objects into the starter fps, and noticed that it didnt crash at all. I then thought... at a long shot it could be the water so i took it out of my level and it doesnt crash!!! Torque can run for hours and be fine.I put the water back in and within a few mins it crashes when i move the cameara over the game scene.
I then erased my water block and made a new one - and the same happened.
Another idea i had, was that because the water block was huge, and actually run underneath the terrain - that it maybe (in my mind of how things work) a probs with the raycasting, cos the engine may of thought the player was trying to enter water..... cos it was only mms beneath the terrain block. Not that my scene is a sea shore... so the water runs almost concurrent with the terrai level.
So,,,, i reduced the water block size so it just came up to the shore and didnt run underneath the terrain - it still crashed.
One last atempt, had me think... take the terrain out. So i did as most of my area is done with difs anyway - and it still crashed.
i took the waterblock out.. and no crashing for hours and hours and hours.. if at all
So i am baffled????
Instead of the waterblock.... is there a way i can use my own water plain 2 poly object, texture it, and then makes its alpha so it is see through( i have actually just posted this on here too - how do make the object so its ghostsed in affect? cos that would do as i wish to use the mirror object for a small reflective water scene elsewhere in the game).
Cheers
Steve
#11
It crashes on export in 3dsmax, just grinds away for a while then crashes. I'll try it with a simpler shape, I'm using a tree I have with two meshes; one sorted.
@stevie
does this crash of yours have to do with DTS Auto Billboards somehow?
01/29/2005 (9:24 pm)
@benIt crashes on export in 3dsmax, just grinds away for a while then crashes. I'll try it with a simpler shape, I'm using a tree I have with two meshes; one sorted.
@stevie
does this crash of yours have to do with DTS Auto Billboards somehow?
#13
01/29/2005 (11:58 pm)
No Clint - i am not using billboards at all.
#14
I simlly saw your reply 'Where are the crashes and thought u was replying to the other one!!!
Funny...
01/30/2005 (12:01 am)
Ben - Just realised - i was obviously tired................ when i posted this - the reply i posted should have been put on another thread i have going at the moment not here!!! When i got the email confirmation that a new reply had been posted, i assumed it was to my other thread!!!! Hmmm.. Too many late nights doing torque!I simlly saw your reply 'Where are the crashes and thought u was replying to the other one!!!
Funny...
#15
Matt
01/30/2005 (6:54 am)
I don't have any problems with billboards of any kind. The above fix is in my version of the exporter.Matt
#16
01/30/2005 (6:56 am)
I know one problem i do have using the max exporter. If a BB is over a certain size, no matter which way it is positioned on the max layout, it doesnt seem to show, only at certai nangles in torque.
#17
- billboard detail export in max 7 might crash
- if it doesn't crash and does export, the show tool (ShowToolPro) and the engine might always choose the billboard detail for display even if there are geometry details which should be displayed instead
I believe that in the exporter code in ShapeMimic::initShape the section // compute detail errors... is handling billboard details although it shouldn't. I have added something like
// compute detail errors...
for (i=0; idetails.size(); i++)
{
TSShape::Detail & detail = pShape->details[i];
// Billboard detail - skip!
if (detail.subShapeNum < 0)
{
detail.averageError = 0.2f; // Would have to calculate a correct value here?
detail.maxError = 1.5f; // Would have to calculate a correct value here?
continue;
}
and at least I got around the crashes and billboard details are displayed in order as they should be.
Our next problem was that billboards in the game would be much too dark. At least for our tree billboards at 64x64 or 32x32 pixels.
To get around this, in TSLastDetail::TSLastDetail I changed the snapshot quality parameter (last parameter to TSShapeInstance::snapshot to false. This gave more correctly lighted billboards.
We still have some problems with billboards showing up as black or blue boxes on some computers at some resolutions or certain distances or within fog. If anybody has suggestions on this, please reply.
09/23/2006 (12:06 am)
Well, I am myself not at the bottom of things yet, but I have noticed the following. This is with the traditional exporter - not plus:- billboard detail export in max 7 might crash
- if it doesn't crash and does export, the show tool (ShowToolPro) and the engine might always choose the billboard detail for display even if there are geometry details which should be displayed instead
I believe that in the exporter code in ShapeMimic::initShape the section // compute detail errors... is handling billboard details although it shouldn't. I have added something like
// compute detail errors...
for (i=0; i
{
TSShape::Detail & detail = pShape->details[i];
// Billboard detail - skip!
if (detail.subShapeNum < 0)
{
detail.averageError = 0.2f; // Would have to calculate a correct value here?
detail.maxError = 1.5f; // Would have to calculate a correct value here?
continue;
}
and at least I got around the crashes and billboard details are displayed in order as they should be.
Our next problem was that billboards in the game would be much too dark. At least for our tree billboards at 64x64 or 32x32 pixels.
To get around this, in TSLastDetail::TSLastDetail I changed the snapshot quality parameter (last parameter to TSShapeInstance::snapshot to false. This gave more correctly lighted billboards.
We still have some problems with billboards showing up as black or blue boxes on some computers at some resolutions or certain distances or within fog. If anybody has suggestions on this, please reply.
#18
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13096
It completely circumvents the exporter's billboard stuff. You export the DTS without billboards, and instead "turn on" billboards within Torque itself. There's a TorqueScript command that allows you to specify the equator steps, polar steps, etc.
08/30/2007 (7:57 pm)
In cases where the trouble is with the art tool exporter, you can also try this resource:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13096
It completely circumvents the exporter's billboard stuff. You export the DTS without billboards, and instead "turn on" billboards within Torque itself. There's a TorqueScript command that allows you to specify the equator steps, polar steps, etc.
Associate Kyle Carter
Nice job, Mango!