Game Development Community

tsstatic crashes (delve into insanity with me)

by TrapHouseGaming · in Torque 3D Beginner · 06/26/2019 (1:50 pm) · 4 replies

EDIT: I've worked past OP as main issue here. Read comment #2 for the updated issue at hand.


I want to spawn a tsstatic shape through script. afaik this code works in its current state:

function addShape(%parent, %shapeName, %transform)
{
//add child
%child = new TSStatic()
{
shapeName = %shapeName;
// parent = %parent;
};
%child.setTransform(%transform);
//%parent.children = %parent.children SPC %child;
//%parent.numChildren++;
return %child;
}


I can spawn my "corners" no problem. the path for the shape is hard coded into the parent datablock.

datablock StaticShapeData(BambooCube)
{
shapeFile = "art/shapes/constructor/jungle/cube/BambooCubeCollision.dts";
type = "cube";
height = 3;
segmentLen = 3;
//shapes
wallShape = "art/shapes/constructor/jungle/cube/BambooCubeWall"; //[i].dts";
floorShape = "art/shapes/constructor/jungle/cube/BambooCubeFloor";//[i].dts
cornerShape = "art/shapes/constructor/jungle/cube/BambooCubeCorner.dts";
};


when it comes to the walls I can echo a perfect looking path to my shape. But when I run the custom path through "new tsstatic()" I get an instant ctd.

//cube creation
function genCube(%parent)
{
if(!isObject(%parent))
{
echo("no %parent");
return;
}

%datablock = %parent.getDatablock();
%width = getWord(%parent.scale,0);
%length = getWord(%parent.scale,1);
%widthVec = %parent.gridVec;
%lengthVec = getWord(%widthVec,1) SPC -1*getWord(%widthVec,0) SPC getWord(%widthVec,2);
for(%side = 1; %side <= 4; %side++)
{
//corners
switch(%side)
{
case 1:
%corner1 = vectorAdd(vectorAdd(getwords(%parent.getTransform(),0,2),vectorScale(%widthVec,-0.5*%width)),vectorScale(%lengthVec,0.5*%length));//frontleft
%direction = %widthVec;
%distance = %width;
case 2:
%corner2 = vectorAdd(%corner1,vectorScale(%direction,%distance));//frontright
%direction = vectorScale(%lengthVec,-1);
%distance = %length;
case 3:
%corner3 = vectorAdd(%corner2,vectorScale(%direction,%distance));//backright
%direction = vectorScale(%widthVec,-1);
%distance = %width;
case 4:
%corner4 = vectorAdd(%corner3,vectorScale(%direction,%distance));//backleft
%direction = %lengthVec;
%distance = %length;
}
%theta = mAtan(getWord(%direction,0), getWord(%direction,1));
//corners
if(%datablock.cornerShape !$= "")
{
%child = addShape(%parent, %datablock.cornerShape, %corner[%side] SPC "0 0 1" SPC %theta);
echo(%child);
}
//walls
%segment = 0;
while(%segment < %distance)
{
%transform = VectorAdd(%corner[%side],VectorScale(%direction,%segment)) SPC "0 0 1" SPC %theta;
%remainingLen = %distance - %segment;
if(%remainingLen > %datablock.segmentLen)
{
%segment = %segment + %datablock.segmentLen;
%shapeName = %datablock.wallShape @ %datablock.segmentLen @ ".dts";
echo(%shapeName);
}
else
{
%segment = %segment + %remainingLen;
%shapeName = %datablock.wallShape @ %remainingLen @ ".dts";
echo(%shapeName);
}
%child = addShape(%parent, %shapeName, %transform);
}
}
//top/bottom
//genFloor(%parent);
}

About the author

long time torque player, decent at scripting and modeling, no good at textures, I primarily work with milkshape and blender. Follow progress on my shitty lil game: https://discord.gg/qsXb9CG


#1
06/26/2019 (1:53 pm)
Is there a cleaner way to post code on this forum?

Also for redundancy purposes. Can I check if a file path leads to an actual file?
#2
06/26/2019 (2:28 pm)
Ok starting to think it's the shape file itself. I manually spawned a corner through console and no crash. Then manually spawned a wall and instant crash.

walls worked fine when they were spawned as staticShapes but have no collision on my physx build, as expected. All I've done to them before spawning as tsstatic is rename the files.

Here are my shapes in ms3d and dts format: https://hostr.co/n6ltxWhslddA

EDIT: its definitely my shapes. Whenever I add collision to a tsstatic and spawn it by any means it crashes. tested by adding collision to my working corner pieces. instant ctd. even by spawning through level editor.
But why now can I not have collisions? models I've made by the exact same means with collision still work fine. It seems like any model that was once a working static shape with collisions is now a tsstatic that will crash the game instantly.

Tried renaming and loading from the same file paths as my terrain props (working tsstatics with collision) to no avail. Is there like a cache file I should delete or something? I'm really at a dead end here...
#3
06/27/2019 (8:38 am)
@TrapHouseGaming - You might want to post your question in the more active Torque3D forums. Someone there should be able to help.
#4
06/30/2019 (6:32 am)
Thanks, got it resolved over there. for anyone else having similar issues- https://forums.torque3d.org/viewtopic.php?f=12&t=1632