How it TSMesh processed?
by Joshua "The Power Nap" Taylor · in Torque Game Engine · 09/14/2003 (3:28 pm) · 9 replies
Okay,
So I've been working on adding binormals/tangents to the faces of TSMesh. I have it construct them when TSShape calls assembleShape in it's read function. Now I know it calls this fucntion twice, so I have it initial the tangent/binormal arrays on the second call. I have it print out a list of the results and it seems to compute the correct results. But when it goes to actually render the binormal/tangent values are all out of whack. They are either all the ceiling value for a float, or 0.
I've been pouring through the code for the past week or so and I can't seem to find the issue. Is there some step that I'm missing?
So I've been working on adding binormals/tangents to the faces of TSMesh. I have it construct them when TSShape calls assembleShape in it's read function. Now I know it calls this fucntion twice, so I have it initial the tangent/binormal arrays on the second call. I have it print out a list of the results and it seems to compute the correct results. But when it goes to actually render the binormal/tangent values are all out of whack. They are either all the ceiling value for a float, or 0.
I've been pouring through the code for the past week or so and I can't seem to find the issue. Is there some step that I'm missing?
#2
You gotta allocate memory in TSShape's assembleShape, not in TSMesh's assemble.
As far as my problem, I now at least have a clue. For some reason alot of the values are getting replaced. I think I might have an Idea why.
09/14/2003 (10:35 pm)
Yeah, I figured out the memory allocation stizzy.You gotta allocate memory in TSShape's assembleShape, not in TSMesh's assemble.
As far as my problem, I now at least have a clue. For some reason alot of the values are getting replaced. I think I might have an Idea why.
#3
09/15/2003 (12:21 pm)
Where in assembleShape are you calculating the values? It looks like all that function does is initialize some pointers.
#4
But since TSShape is a child of the ResourceManager it can allocate memory. It calls assembleShape twice in the read function. You have to allocate the memory on the second call, so you don't have a huge memory leak.
09/15/2003 (6:57 pm)
What TSShape::assembleShape does is initialize pointers in the memory the shape is loaded into.But since TSShape is a child of the ResourceManager it can allocate memory. It calls assembleShape twice in the read function. You have to allocate the memory on the second call, so you don't have a huge memory leak.
#5
09/15/2003 (8:02 pm)
I guess my real question is how you're allocating them. Are you going through the allocation process like the rest of it is doing, or are you just doing a new or two?
#6
But man, a bunch of crazy crap is going on now. All I really can say is it's allmost like my OS class when the kernel I was writting had a stack overflow error.
For instance:
In the for loop that I use to figure the binormal/tangent of the current primitive, if I change the type of the iterator from S32 to U32 it changes the outcome of an unrelated bitwise operation.
Well, here's the code
Argh!
09/16/2003 (1:11 am)
I'm using a new operator.But man, a bunch of crazy crap is going on now. All I really can say is it's allmost like my OS class when the kernel I was writting had a stack overflow error.
For instance:
In the for loop that I use to figure the binormal/tangent of the current primitive, if I change the type of the iterator from S32 to U32 it changes the outcome of an unrelated bitwise operation.
Well, here's the code
for (S32 k = 0; k < mesh->primitives.size()-1; ++k)
{
TSDrawPrimitive & draw = mesh->primitives[k];
AssertFatal(draw.matIndex & TSDrawPrimitive::Indexed,
"TSMesh::render: Binormal and Tangent computation of non-indexed meshes is not supported");works fine, as wherefor (U32 k = 0; k < mesh->primitives.size()-1; ++k)
{
TSDrawPrimitive & draw = mesh->primitives[k];
AssertFatal(draw.matIndex & TSDrawPrimitive::Indexed,
"TSMesh::render: Binormal and Tangent computation of non-indexed meshes is not supported");Throws the assertion.Argh!
#7
Also, you should never index by a signed integer - it gets hairy when you try to look up foo[-1].
09/16/2003 (6:06 am)
You're inviting bad mojo by not using the same allocation code as the rest of the TS library...Also, you should never index by a signed integer - it gets hairy when you try to look up foo[-1].
#8
So, since you can't use the TS's mMemBufferXX system, you need to allocate it yourself and go from there.
EDIT:
Ok, now I'm running into errors in TSShape::findName.
I got my stuff all allocated, but if I try to assign values to the data, it crashes there, in findName, saying it caused an access violation reading location 0xcccccccc. However, if I do all my calculations and NOT assign those vales to the tangent and binormal list, it's happy.
That is very strange....
ANOTHER EDIT:
It seems like indexing the tangents/binormals by:
mesh->indices[i]
for every element in indices is a bad thing... even though that's what OpenGL uses to index everything else. I did a huge console dump of it's contents, and it showed reasonable things like 23, 24, 25, 23, 27, 24...things like that. But, every once in a while there were 5-6 digit numbers, which leads me to believe that by adding those numbers to the address of the tangent or binormal list, I was overwriting memory used for something else (names). Bleh...this really sucks.
YET ANOTHER EDIT:
Ok, so I've occluded primitives that would cause the type of problem above, and everything seems to check out ok. I can loop through all of the primitives and calculate stuff for everything. Now I just have to figure out how to calculate this stuff...
09/16/2003 (11:46 am)
Ah ha, I think I'm finally understanding this now. You really can't allocate memory with versions >= 20 because from that point on, it reads how much memory to allocate from the .dts file, so you can't tell how much additional memory you need to allocate for the binormals and tangents. It is possible for older shapes because the code "counts" the amount of memory needed. So, since the mesh is constructed as a part of TSShape, you need to either allocate in the TSShape assemble function that is called per mesh, or allocate on the 2nd call to the TSMesh assemble, which is where it actually allocates the necessary memory.So, since you can't use the TS's mMemBufferXX system, you need to allocate it yourself and go from there.
EDIT:
Ok, now I'm running into errors in TSShape::findName.
I got my stuff all allocated, but if I try to assign values to the data, it crashes there, in findName, saying it caused an access violation reading location 0xcccccccc. However, if I do all my calculations and NOT assign those vales to the tangent and binormal list, it's happy.
That is very strange....
ANOTHER EDIT:
It seems like indexing the tangents/binormals by:
mesh->indices[i]
for every element in indices is a bad thing... even though that's what OpenGL uses to index everything else. I did a huge console dump of it's contents, and it showed reasonable things like 23, 24, 25, 23, 27, 24...things like that. But, every once in a while there were 5-6 digit numbers, which leads me to believe that by adding those numbers to the address of the tangent or binormal list, I was overwriting memory used for something else (names). Bleh...this really sucks.
YET ANOTHER EDIT:
Ok, so I've occluded primitives that would cause the type of problem above, and everything seems to check out ok. I can loop through all of the primitives and calculate stuff for everything. Now I just have to figure out how to calculate this stuff...
#9
Here's a little something to allow me to show off :)
hobbiticus.acm.jhu.edu/things/shinyTorque.jpg
09/17/2003 (7:00 pm)
HA! I got it! Hack it may be - it still works! Now I've got terrain, water, and models all speculared up, now it's time for interiors...Here's a little something to allow me to show off :)
hobbiticus.acm.jhu.edu/things/shinyTorque.jpg
Torque Owner Chris \"Hobbiticus\" Weiland
Also, is it possible that's it's calling that function once on the client and once on the server? If you are joining your own game, that's probably what's happening.