Exporting Static Meshs as TSStatics
by UZON · in Constructor · 02/07/2008 (3:40 pm) · 18 replies
My 3D crew put all the objects (DTS) of my cenario in the position as Static Meshs inside the constructor. It is like 800 objects, so i need a easy way to export them Torque to use as TSShape.
I already made an script in PHP to take this:
from the stage.csx and converted into this:
But the rotation of the constructor, dont match the rotation in Torque, this is what is holding me back. any idea of how i can make this conversion, or how it work?
I already made an script in PHP to take this:
<SceneShape id="12" type="2" file="Hterreo/refeitorio/mesas_refeitorio.dts" pos="-0.712652 -59.9478 -0.870075" rot="0 0 -1 4.71239" scale="1.5 1.5 1.5" transform="8.9407e-008 1.5 0 -0.712652 -1.5 8.9407e-008 0 -59.9478 0 0 1.5 -0.870075 0 0 0 1" group="-1" locked="0" />
from the stage.csx and converted into this:
new TSStatic() {
canSaveDynamicFields = "1";
position = "-0.712652 -59.9478 -0.870075";
scale = "1.5 1.5 1.5";
rotation = "0 0 -1 4.71239";
shapeName = "~/data/staticshapes/Hterreo/refeitorio/mesas_refeitorio.dts";
receiveSunLight = "1";
receiveLMLighting = "1";
useAdaptiveSelfIllumination = "0";
useCustomAmbientLighting = "0";
customAmbientSelfIllumination = "0";
customAmbientLighting = "0 0 0 1";
useLightingOcclusion = "1";
};But the rotation of the constructor, dont match the rotation in Torque, this is what is holding me back. any idea of how i can make this conversion, or how it work?
About the author
#2
02/08/2008 (3:39 am)
You are right, but the deal is... there is already like 900 objects placed in the constructor... and placing objects in constructor is a way easier than in torque. This is why i think they made that way.
#3
rot="-0.678598 -0.281085 -0.678598 1.49751"
and convert it to:
rotation = "0.678598 0.281085 0.678598 1.49751";
02/08/2008 (6:55 am)
I think you should just be able to take the negative of each of the three rotation axis components (the first three rotation values) and it should look correct inside Torque. So for example, your PHP script should take the line:rot="-0.678598 -0.281085 -0.678598 1.49751"
and convert it to:
rotation = "0.678598 0.281085 0.678598 1.49751";
#4
02/08/2008 (9:26 am)
I see what you mean, but i would only want to do that if we could at-least import terrain height maps in. I'm mean they don't even have to have collision, just there for building. i think a lot of this could be solved if when that juggernaut came out the merged Constructor with a version it, but it also possible that will cause more problems then solve....:) it feels like a lot of hoops just to get a model in was my only point i guess, good luck i wish i could be more help:)
#5
It didnt worked, im rotating the objects by hand... it will take 2 our 3 days, but it at least i got the right position from the constructor, which is the boring part of putting objects in torque...
Nice, just figured that this probaly is a radian format... will try to convert :)
@Bobby:
I didnt understand what you mean, but thanks ;D
02/08/2008 (9:36 am)
@Ryan:It didnt worked, im rotating the objects by hand... it will take 2 our 3 days, but it at least i got the right position from the constructor, which is the boring part of putting objects in torque...
Nice, just figured that this probaly is a radian format... will try to convert :)
@Bobby:
I didnt understand what you mean, but thanks ;D
#6
Awesome, now i can make the hole ambient in constructor, put the DTSs there and after everything is finish, export a script for the DTS.
02/08/2008 (10:16 am)
Yeah, it worked perfectlyAwesome, now i can make the hole ambient in constructor, put the DTSs there and after everything is finish, export a script for the DTS.
<?
///////////////////////////////////////////////////////////////////////////
// Script converter from CSX to TSStatic Script
// Use this to export your Static Mesh from constructor
// to your Torque Game
// Author: Diego Potapczuk
// E-Mail: potapczuk@gmail.com
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
$txt = "file.csx"; // Here is the file that you want to convert
$abre = fopen($txt, "r");
$informacao = fread($abre, filesize($txt));
fclose($abre);
preg_match_all( "/\<SceneShape (.*?)\/\>/s",
$informacao, $objetos );
echo " new SimGroup(ObjectGroup) {";
foreach( $objetos[1] as $objeto ) {
preg_match_all( "/file=\"(.*?)\"/",
$objeto, $arquivo );
preg_match_all( "/pos=\"(.*?)\"/",
$objeto, $pos );
$pos_array = null;
$pos_array = explode(" ",$pos[1][0]);
/////////////////////////////////////////////////////////////////////////////////////////
// Position modifier: Change this to match the world position in Torque
$pos_array[0] += 81.6545;
$pos_array[1] += 82.7989;
$pos_array[2] += 37.5555;
preg_match_all( "/rot=\"(.*?)\"/",
$objeto, $rot );
$rot_array = null;
$rot_array = explode(" ",$rot[1][0]);
$rot_array[3] = (180/3.14159) * $rot_array[3];
preg_match_all( "/scale=\"(.*?)\"/",
$objeto, $scale );
if($arquivo[1][0]){
echo "new TSStatic() {";echo "";
echo 'canSaveDynamicFields = "1";';echo "";
echo 'position = "'.$pos_array[0].' '.$pos_array[1].' '.$pos_array[2].'";';echo "";
if($scale[1][0] == "1 1 1"){
echo 'scale = "1.5 1.5 1.5";';echo "";
} else {
echo 'scale = "'.$scale[1][0].'";';echo "";
}
echo 'rotation = "'.$rot_array[0].' '.$rot_array[1].' '.$rot_array[2].' '.$rot_array[3].'";';echo "";
if(strchr($arquivo[1][0],"..")){
echo '<font color=red>';
echo 'shapeName = "~/data/staticshapes/'.$arquivo[1][0].'";';echo " // Erro de arquivo";
echo '</font>';
} else {
echo 'shapeName = "~/data/staticshapes/'.$arquivo[1][0].'";';echo "";
}
echo 'receiveSunLight = "1";';echo "";
echo 'receiveLMLighting = "1";';echo "";
echo 'useAdaptiveSelfIllumination = "0";';echo "";
echo 'useCustomAmbientLighting = "0";';echo "";
echo 'customAmbientSelfIllumination = "0";';echo "";
echo 'customAmbientLighting = "0 0 0 1";';echo "";
echo 'useLightingOcclusion = "1";';echo "";
echo '};';echo "";
echo "";
}
}
echo "};";
?>
#7
02/08/2008 (10:39 am)
Pretty cool.
#8
02/26/2008 (2:25 pm)
N00bish question... say I took that code and saved it as csx2mis.php, how would I run that script on a file in my windows box?
#9
02/26/2008 (11:37 pm)
Yes, I'm a php noob, please tell me how to use this, it looks wicked cool.
#10
Put this script (csx2mis.php) inside the xampp/htdocs folder
modify the name of the archive of the csx that you want to convert in the top of the script ($txt = "file.csx"; // Here is the file that you want to convert)
Run the server
Open mozilla and access: http://localhost/csx2mis.php
And if everything ok you will have the converted csx in your browser.
02/27/2008 (4:05 am)
You have to instal xampp, which is a php server where you can run php scripts inside your machine.Put this script (csx2mis.php) inside the xampp/htdocs folder
modify the name of the archive of the csx that you want to convert in the top of the script ($txt = "file.csx"; // Here is the file that you want to convert)
Run the server
Open mozilla and access: http://localhost/csx2mis.php
And if everything ok you will have the converted csx in your browser.
#11
02/29/2008 (12:12 pm)
Awesome, thanks. I'll try it.
#12
03/06/2008 (12:10 pm)
You should make a snazzy form with a browse button, it would make things much quicker than editing the PHP file to change the input file, as well as giving it some "face" if you know what I mean. But that's just a minor thing. Other than that, very cool idea.
#13
Maybe when i finish my project i spend some time giving back to the community the thing that i did.
Thanks for the suggestion
03/06/2008 (12:33 pm)
@Nathan: It would be better if someone could implement it as a constructor plug in, or a desktop program, and i did it that way because i needed it in a hurry.Maybe when i finish my project i spend some time giving back to the community the thing that i did.
Thanks for the suggestion
#14
awesome ... been looking/wanting something like this! I've been messing with Maya's MEL coding in relation to Torque/Constructor tools .. love to borrow your code as reference for some things if you don't mind. Also, if you can help me out with the rotation problems, let me know. I had thought that Torque was using Quaternions, and Maya Euler. I know the names, but not how to convert. :-) But if you have insight on how to convert Constructor and/or Torque into a readable xyz rotation (instead of xyz angle), I would really appreciate it!
Thanks in advance!
04/21/2008 (9:14 pm)
UZON,awesome ... been looking/wanting something like this! I've been messing with Maya's MEL coding in relation to Torque/Constructor tools .. love to borrow your code as reference for some things if you don't mind. Also, if you can help me out with the rotation problems, let me know. I had thought that Torque was using Quaternions, and Maya Euler. I know the names, but not how to convert. :-) But if you have insight on how to convert Constructor and/or Torque into a readable xyz rotation (instead of xyz angle), I would really appreciate it!
Thanks in advance!
#15
04/27/2008 (2:05 pm)
Jaimi, can you integrate this in Constructor?
#16
04/28/2008 (8:08 am)
It would require adding PHP to the Constructor base.
#17
04/28/2008 (9:49 am)
It would require translating the PHP algorithm to torque script or C++ (making it a constructor plug-in)
#18
Doing it "the right way" would require adding tags for the DTS to the DIF, and then coding it in to the mission editor to load and adjust the DTS models on the fly. It's not a herculean task, but it's not trivial either.
04/28/2008 (4:47 pm)
Yeah, I've thought several times about doing this. (Adding a flag on the dts whether or not to write it into the output DIF, and creating a mission fragment to paste it in). The only problem that without doing it "the right way", it is of limited use (ie, it would work for UZON, since he had a single map at one spot and location, but wouldn't work for many since they would want to add and position models later).Doing it "the right way" would require adding tags for the DTS to the DIF, and then coding it in to the mission editor to load and adjust the DTS models on the fly. It's not a herculean task, but it's not trivial either.
Torque Owner Bobby Leighton
Imagn' Games