Ultimate space simulation software

 
User avatar
darth_biomech
Observer
Observer
Topic Author
Posts: 15
Joined: 05 Mar 2017

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 04:22

I wrote this bit for one of my ships, once I realized that it turned out to have 250 maneuvering thrusters and that I'll go insane trying to place them by typing in rotations and positions in SE's ship editor.

ImageImage

TxtFilePathName = "C:/tast.txt"
PositionScaleFactor =0.02649
EngineEffect = "Chemical"
EngineGroup = "Thruster"
EngineSize = "0.45 0.45 1.25"
EngineColor = "0.05 0.05 0.05"
EngineVolume = "0.5"
EngineSound = "Spacecraft/Shuttle_thruster.ogg"
RoundUp = false
AddToFile = true


fn round_to val n =
(
local mult = 10.0 ^ n
(floor ((val * mult) + 0.5)) / mult
)    
fn CreateTxtFile =
(
    close TXTfile

    if (AddToFile != false) then (
    TXTfile = openFile TXTfilePathName mode:"a"
    )
    else (
        TXTfile = createFile TxtFilePathName                 
        close TXTfile
    TXTfile = openFile TXTfilePathName mode:"wt"        
        )
  for a in selection do
  (
if (RoundUp != false) then (
    d_pos_x = (round_to(a.pos.x * PositionScaleFactor) 0) as integer
    d_pos_y = (round_to(a.pos.y * PositionScaleFactor) 0) as integer  
    d_pos_z = (round_to(a.pos.z * PositionScaleFactor) 0) as integer
)
else (
    d_pos_x = (formattedPrint (a.pos.x * PositionScaleFactor) format:"#.2f") as float
    d_pos_y = (formattedPrint (a.pos.y * PositionScaleFactor) format:"#.2f") as float  
    d_pos_z = (formattedPrint (a.pos.z * PositionScaleFactor) format:"#.2f") as float    
    )

    d_rot_x = (round_to a.rotation.x_rotation 0) as integer
    d_rot_y = (round_to a.rotation.y_rotation 0) as integer
    d_rot_z = (round_to a.rotation.z_rotation 0) as integer
      
  format ("EngineEffect \"" + a.name + "\"\n{\n\tGroup\t\"" + EngineGroup +"\"\n\tType\t\"" + EngineEffect + "\"\n") to: TXTfile
  format "%
" ("\tPos \t(" + d_pos_x as string + " " +  d_pos_y as string + " " +  d_pos_z as string + ")") to: TXTfile
  format "%
" ("\tRot \t(" + d_rot_x as string + " " + d_rot_y as string + " " + d_rot_z as string +")" ) to: TXTfile
 format ("\tSize\t(" + EngineSize + ")\n\tColor\t(" + EngineColor + ")\n\tVolume\t" + EngineVolume + "\n" + EngineSound + "}\n\n") to: TXTfile
   )
    close TXTfile   
    messagebox "Done!"
)
    rollout ThrustExport "Export Thrusters v1.2"
    (
        editText folderPathTxt text:"C:/test.txt"
        button btnBrowse "Select file"
        checkbox AddtheButt "Don't replace file" tooltip:"Check to add new thrusters to file instead of wiping it clean before adding thrusters"
        spinner ScaleFactorButt "Scale " type:#float range:[0, 1000, 0.02649] tooltip:"Scale position of objects by this amount, if the position in SE end up mismatching with positions in 3ds max"
        checkbox RoundUpButt "Strip decimals" tooltip:"SE sometimes defaults position to 0 0 0 if there's decimals in the values. Check this if that'll happen, it'll round position to nearest integer"
        dropdownlist EffectButt "Engine effect" items:#("Fusion", "Chemical", "Ion", "Ion2", "Aerospike", "Square")
        dropdownlist GroupType "Engine Group" items:#("Main", "Retro", "Thruster", "Hover", "Warp")
        edittext EngineSizeButt "Engine Size:" text:"0.45 0.45 1.25" tooltip:"I don't know what SE uses as scale measurement, so test what looks right"
        colorpicker theColor "Exhaust color:" color:[20,20,20]
        spinner ScaleSoundButt "Sound volume" type:#float range:[0, 1, 0.9999]
        dropdownlist SoundEffectButt "Sound effect" items:#("None", "Starship_engine", "Starship_thruster", "Starship_warp", "Shuttle_engine", "Shuttle_thruster", "Shuttle_hover") selection:2
        button bake_butt "Export thrusters!"
        
            on btnBrowse pressed do
    (
        local path = getSaveFileName types:"Text(*.txt)|*.txt|"
        if path != undefined do folderPathTxt.text = path
    )

        on bake_butt pressed do (
            TxtFilePathName = folderPathTxt.text
            PositionScaleFactor=ScaleFactorButt.value as float
            EngineEffect = EffectButt.selected
            EngineGroup = GroupType.selected
            EngineSize = EngineSizeButt.text -- "0.45 0.45 1.25"
            EngineColor = ((formattedPrint (theColor.color.red /255) format:"#.3f") as string  + " " + (formattedPrint (theColor.color.green /255) format:"#.3f") as string  + " " + (formattedPrint (theColor.color.blue /255) format:"#.3f") as string ) as string--"0.05 0.05 0.05"
            EngineVolume = ScaleSoundButt.value as string
            -- EngineSound = ("Spacecraft/" + SoundEffectButt.selected as string + ".ogg") as string
            RoundUp = RoundUpButt.checked
            AddToFile = AddtheButt.checked
            if (SoundEffectButt.selection != 1) then (
                EngineSound = ("\tSound\t\"" + ("Spacecraft/" + SoundEffectButt.selected as string + ".ogg") as string + "\"\n") as string
                )
                else (
                EngineSound = " " as string
                )
            if (selection.count != 0) then (
            CreateTxtFile()
            )
            else     messagebox "No objects selected"
        )
    )
createDialog ThrustExport width:180




Using it is pretty simple: place some objects on your ship's model where you want the thrusters to be (I use dummy points), orienting them in such way that negative Z axis was aligned outwards out of thruster (In the direction you want the flame to go). Then you select them all and run the script. It outputs a text file in a specified location (C:/test.txt in this example) which contains block of definitions for all selected thrusters. All these thrusters will be named accordingly to the object selected, so no more "Main_Retro_Thruster Copy Copy Copy Copy Copy Copy Copy Copy" (Although, maybe Main_Retro_Thruster026 is not that much better either... :oops:).

All options for the script are in the top, almost all mirror the settings in the definitions themselves and used to fill them in (I'd recommended to initially place one thruster in SE and set it up to your liking (Scale, color, etc), and then use it's parameters in the script).
The only outcast is the Scale Factor - It controls, well, relative scale of the positions relative to model. My model was done in a scale 1:100, using centimeters as display units (So every centimeter actually equals 1 meter... That ship is big) and inches as system units, and also was exported in obj in a scale of 1.0, according to export settings. In SE I had to set "Unit" parameter in .cfg file of the module to 2.649 in order for the thing to be 1:1 scale in the engine, and by experimenting with the script i found out that same 2.649 put in there provides correct offsets so that thruster flames in SE are in the same places as dummies are in the 3ds max. These conversions and juggling of several unit systems confuse me, so make out of that information what you will, I hope it'll help you.
One another thing is that for some reason in SE the pivot point of the model became shifted forward 90 meters, so I had to adjust the positions of the dummies accordingly. Maybe that was me borking something during either export or conversion, but I thought I'd mention that too just in case.

Current limitation of the script is that it is able to output only one thruster setup at once, so you'd need to edit it and run it multiple times with different parameters and selecting dummies in groups. I don't yet know how to streamline it into version that's capable of generating multiple thruster setups, but maybe I'll manage that in the future. Somehow.
Another limitation is that it it usable only by those who have 3ds max, but oh well, I work with what I use, sorry...

► Show Spoiler
Last edited by darth_biomech on 01 Jul 2019 20:26, edited 2 times in total.
 
User avatar
HarbingerDawn
SE Team Member
SE Team Member
Posts: 628
Joined: 22 Aug 2016
Location: CT, USA
Contact:

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 06:49

darth_biomech, you are one magnificent bastard. Hat's off to you.
Ryzen 7 3700X, 64 GB DDR4-3200 RAM, GTX 1080 Ti 11 GB VRAM
Posts on old forum: 8717
 
User avatar
DoctorOfSpace
Star Engineer
Star Engineer
Posts: 1262
Joined: 22 Aug 2016
Location: SpaceX Mars Colony
Contact:

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 06:50

darth_biomech wrote:
Source of the post I'll go insane trying to place them by typing in rotations and positions in SE's ship editor.


I often get asked to add more engine effects to ships I port and I tell people this often, its a real pain and ludicrously tedious.  

Will give this a try and see how it works for some ships.
CPU: Intel Core i7-5820K 4.2GHz 6-Core Processor - RAM: G.Skill Ripjaws V Series 32GB (4 x 8GB) DDR4-2400 - GPU: EVGA GeForce GTX 1080 Ti SC Black Edition
Quando omni flunkus, moritati
 
User avatar
NathanKerbonaut
Space Pilot
Space Pilot
Posts: 125
Joined: 02 Nov 2016
Location: Wisconsin
Contact:

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 06:58

Well done!! This is super useful.
May I suggest a version of this script for Blender?
I like cute pokemon and space games.
My mods: http://forum.spaceengine.org/viewtopic.php?f=3&t=173
Profile pic source: https://goo.gl/JdZX5v
 
User avatar
darth_biomech
Observer
Observer
Topic Author
Posts: 15
Joined: 05 Mar 2017

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 12:51

NathanKerbonaut wrote:
Source of the post
May I suggest a version of this script for Blender?

This was my first ever script for Maxscript and a lot of it was piggybacking on examples I saw on the internet. I'm not sure that I will be able to repeat it for Blender, since I never worked there. But honestly, it should be easy for someone who has experience with it, if even I managed to do that, after all, it's just taking name and transform of an object and writes them down in a file, basically, adding a bunch of stuff to format it into SE-compatible entry code.
 
User avatar
ettore_bilbo
Explorer
Explorer
Posts: 182
Joined: 11 Nov 2016
Location: Italy

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 13:34

NathanKerbonaut wrote:
Source of the post Well done!! This is super useful.
May I suggest a version of this script for Blender?

Times ago I tried to write a script for blender for export my ship modules. It was buggy, because in .sss file there is a rotation matrix that i don't know how to replicate, but for engines effects this problem there isn't...
with some small adjustement it should work.
 
User avatar
darth_biomech
Observer
Observer
Topic Author
Posts: 15
Joined: 05 Mar 2017

[Tool]3ds max script for exporting thruster position for ships

01 Jul 2019 20:27

I updated the script, now it have nice menu and everything. Should make exporting easier.

Who is online

Users browsing this forum: No registered users and 1 guest