Game Development Community

please look at this script, its short, and i really need help

by Steve · in Torque 3D Professional · 06/16/2009 (8:20 am) · 13 replies

I posted this in Technical issues, and did get some advice, but the issue is unresolved, and, quite frankly, I'm stuck. If anyone could offer any explanation or advice at all, I'd appreciate it.

I loaded a collada file of a spinning wood crate with the following script:

datablock StaticShapeData(Cube)
{
category = "collada";
shapeFile = "art/shapes/collada/queb/cube.dae";
};

function Cube::OnAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}

It loaded fine, spun fine, and had the correct texture. Next I wanted to add a collision mesh so I scripted this (in addition to keeping the above script):

function Cube2::onPreload(%this)
{
%this.addMesh("cube","bounds", "Col-1");

}

datablock TSShapeConstructor(Cube2)
{
baseShape = "art/shapes/collada/queb/cube.dae";

};

This has caused me no end of problems. The cube now imports, has the wrong texture, will not spin, but does have a collision mesh. Even if I get rid of the STatic shape datablock and ::onadd scripts, the ::onpreload and TSShapeConstuctor do not work correctly: a collison mesh is added, but the texture is incorrect.

Finally and lastly, if I do this:

datablock TSShapeConstructor(Cube2)
{
baseShape = "art/shapes/collada/queb/cube.dae";


};

function Cube2::onPreload(%this)
{
%this.addMesh("cube","bounds", "Col-1");

}

the cube imports with a collision mesh but the wrong texture again. However, it is my understanding that the above code should not work! From the official documentation:

"Because the onPreload function is called as soon as the script containing the TSShapeConstructor datablock is executed by the engine, the function must appear before the datablock (otherwise the engine will not be able to find the function as it has not been parsed yet!)".

I don't know whether I have overlooked something simple or not, I hope so. If not, is it possible there is a bug in some of the new features of TSShapeConstructor?

Has anyone successfully added a mesh the way I am trying to do above?

Could it possibly be my collada file? I have looked at it, but it works for everything aside from when i start to use TSShapeConstructor, so I dont really know what to look for.

#1
06/16/2009 (10:26 am)
I think the collision mesh is visible for some reason. I saw that when adding one myself via script.

I think you're seeing the model with the wrong cube in the 2nd example because it was cached.
#2
06/16/2009 (11:00 am)
Um, I don't understand your answer, please forgive my ignorance. May I ask some more questions to make sure I understand what you are telling me?

Firstly, if you are refering to my 2nd attempt above, which is where I first added TSShapeConstructor and the ::preload function, then yes it is intriguing to think that the collision mesh is visible and that is why the texture appears to change....but....wouldn't that be a reportable bug then? I searched the forums and didn't see any reports of a bug in TSShapeConstructor. Anyone at GG know anything about this, please?

Secondly, in the second attempt above, if indeed the texture problem is caused by a visible collision mesh, how then can we explain the fact that the cube rotation animation fails to play?

Thirdly, If I do the same code as my second example above, but delete the cached.dts file, are you suggesting that it will work? And even if it does, just that once, what good would it be?

Fourthly, thank you once again, for taking the time to help. You can't imagine how valuable and appreciated your and other people's assistance is to those of us still teaching ourselves Torque!
#3
06/16/2009 (1:02 pm)
A visible collision meshes should be flagged as a bug, I think.

I *think* the first time you ran it created a cached DTS. Since the DAE didn't change, the cached file remained the same after you disabled the onPreload() function. This is a theory, but try deleting the cached DTS to see if the box goes away.
#4
06/16/2009 (1:46 pm)
Well, I did delete the .dts file. The cube showed up with the wrong texture, and NO collsion mesh (not to mention no animation, which I already knew would happen). Manoel, could I prevail on you to try the above code (or similar code) with any simple animated object you may have, to see if you can get it to work properly? If you can not, then I would know for sure that it is a bug, and could report it.
#5
06/24/2009 (1:11 am)

AFAIK there's been quite some changes to TSShapeConstructor for the impending Beta 3 release. Please retest with this one.

If it still doesn't work, please send me the files and I'll take a look.
#6
06/24/2009 (5:04 am)
Thank you so much for your reply, Rene. I will retest ASAP!
#7
06/29/2009 (11:13 am)
Ok, got your files and looking into this now. All I can say so far is that this here is the path to a range of colorful crashes. The TS shape code is another of those legacy TGE-days bits that knows only one single answer to any unexpected situation: crash and burn, baby.

BTW, TSShapeConstructor is a datablock no more as of B3, so it's now

new TSShapeConstructor( MyNiftyShapeConstructor )
{
   // ...
};

//Edit: And as another change, "onPreload" is now "onLoad"
#8
06/29/2009 (3:01 pm)

Ok, amongst a bunch of other crashy stuff, it appears the TS code is handling collision meshes incorrectly by adding them as non-rendered in its details record and as rendered in its mesh record thus causing a neat and nice crash in the rendering code.

Also, the shape referenced by TSShapeConstructor is a reference-counted resource and may disappear without the constructor noticing. Some more nice crashes here.
#9
06/29/2009 (3:34 pm)
Well, I'm relieved that I'm able to follow the docs and write 6 lines of script correctly. I spent an inordinate time on those 6 lines of code, trying to figure out what possibly could have been wrong.

So, does this mean not to bother using TSShapeConstructor (at least to add collision meshes) till Beta 4?

Thanks for looking into this Rene, I truly appreciate it.
#10
06/29/2009 (3:40 pm)

The collision mesh problem will likely be a simple change in tsShapeEdit.cpp. Right now, I'm too tired to go on but when I have fixed this, I will post the change here. The other fixes will be in B4, though TSShapeConstructor will work without them as long as you are careful not to set off a crash trigger.

Thanks to you for bringing this up and not letting go. This is important functionality.
#11
06/29/2009 (3:54 pm)
Logged as THREED-551

Thanks both of you!
#12
06/29/2009 (9:09 pm)
Hi Steve,

The addMesh issue is now fixed and will be in beta 4. If you don't want to wait, and are set up to build the engine from source you can grab the 2 updated files here.
#13
06/29/2009 (10:29 pm)

Awesome, Chris. Working fine now.

Goodbye THREED-551.