Game Development Community

How can I change texture on a TSStatic Shape ?

by Mark Johnston · in Torque Game Engine · 05/20/2008 (1:44 am) · 7 replies

I am currently working on a project recreating our town within the torque engine using version 1.5.
We want to load images of buildings onto a simple square dts shape, as we are dealing with thousands of buildings and don't have the time or resources to model individual buildings.

Is there a way to use the same TSStatic Shape dts file, and when loading the mission script tell it what image to use ?

I have tried %obj.mountImage, %obj.setSkin etc.. as discussed in forums but nothing seems to work.

Below is an example of the shape being loaded within the .mis file.

new TSStatic() {
canSaveDynamicFields = "1";
internalName = " 8016180 ";
position = "280.801 -130.406 24.8";
rotation = "0 0 1 19.4806";
scale = "1.28231 1 2";
shapeName = "~/data/shapes/buildings/building.dts";
receiveSunLight = "0";
receiveLMLighting = "1";
useAdaptiveSelfIllumination = "0";
useCustomAmbientLighting = "0";
customAmbientSelfIllumination = "0";
customAmbientLighting = "0 0 0 1";
};

building.dts was made in Milkshape and textured with base.building.png
Other images are named xxxx.building.png, so I want to do something like %obj.setSkin("xxx.building.png"); and have that image show on shape file rather than the base texture.

Any help of suggestions would be much appreciated as I have spent hours trawling the forums and site but have yet to figure it out, and there seems to be a very helpful community spirit here.

#1
05/20/2008 (5:00 am)
If original texture is base.building.png, and you have a texture named version1.building.png, use this:

%obj.setSkinName("version1");
#2
05/20/2008 (7:48 am)
It's very important that "base" is the first word in the default texture name, otherwise it doesn't work.
#3
05/20/2008 (7:55 am)
SetSkinName is a shapeBase function. If you want to use it, you will need to use StaticShape instead of TSStatic.
#4
05/20/2008 (2:28 pm)
Thanks for you input guys, I will try your advice today, as this will make it so much more efficent to be able to apply different textures at mission load.
Makes sense about using StaticShape as there was a can't find method error.
I will let you know how I get on.
#5
05/20/2008 (3:50 pm)
Hi all, I tried your suggestions.
From within console I can change texture using for example 2253.setSkinName("version1");
to the correct texture. But when I try to do this from the .mis file I get a parse error.

Below is the new shape loading code.

new StaticShape() {
canSaveDynamicFields = "1";
position = "78.6836 -46.8752 23.5012";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Building";
%obj.setSkinName = "8000770_1860"; // <==Parse error here !! String is a GIS code Reference_Year
receiveSunLight = "1";
receiveLMLighting = "1";
useAdaptiveSelfIllumination = "0";
useCustomAmbientLighting = "0";
customAmbientSelfIllumination = "0";
customAmbientLighting = "0 0 0 1";
};

Is there something I'm missing ??
#6
05/20/2008 (3:54 pm)
You can't execute code statements inside an object creation block.
you could do something like the following to set the skin name after the mission has been parsed:
new StaticShape(mySpecialShape)
{
   // stuff but not skinName stuff
};

// rest of mission file

//--- OBJECT WRITE END ---

mySpecialShape.setSkinName(whatever);
#7
05/20/2008 (4:19 pm)
Thanks Orion,

Your a legend, it now works.
Although I was trying to use the gis reference as StaticShape(8000770), but because its a number was looking for shape id# of 8000770. Figured out why it wasn't working by looking at console log, and now by adding StaticShape(my8000770) as name it works. Bit of a hassle as pulling the gis number from database to identify where that building is located, but at least I can now get it to load texture.

Thanks again all for you help.
Really impressed but the speed of answers and helpfulness.

Hopefully someday I'll be up to your guys level, but we all have to start somewhere.