User:Greys

From Kerbal Space Program Wiki
Revision as of 18:17, 17 September 2013 by Greys (talk | contribs) (Texture Assets: Corrected texture-in-memory information based on new found information)
Jump to: navigation, search
This page is amidst Major Rewrites, much of the content has been removed, moved around, reformated, etc. But still a lot of old content remains on this page. If you choose to use this page in it's current state as a reference, be very careful and pay attention to the notations, but overall I would highly suggest: Don't
Does not include the new 0.18 or 0.20 config format changes
  • Gamedata addressed
  • Config Nodes addressed
  • partModules not addressed
  • module deprecation partially addressed
  • Ø comments indicate notes on existing content that is incorrect or inadequate, and will need to be addressed
  • þ comments are formatting or structural changes that need to be made

GameData

Tentatively complete: I believe this section to be complete aside from inconsistent terminology and refining the exact text. Please discuss on the talk page if you have concerns or things to add

All add-on files should be placed in the GameData folder, located in the root KSP folder alongside the KSP executable. Everything related to a given Add-on should be contained within a folder created specifically for that Add-on. Inside the dedicated folder, the directory structure is largely unimportant.

All of the stock parts are contained within GameData as well, and Squad uses this structure:

/Flags/            -- Flags must go here or they won't be loaded as flags, Capitalization Matters
/Parts/Aero/       -- Aerodynamic parts
/Parts/Command/    -- Command pods, probe cores, and reaction wheels
/Parts/Electrical/ -- Parts that create and store electricity 
/Parts/Engine/     -- Engines
/Parts/FuelTank/   -- Fuel Tanks
/Parts/Structural/ -- Parts that don't do anything, and don't contain resources
/Parts/Utility/    -- Parts that do things and don't contain resources (except some of them do)
/Parts/Wheel/      -- Things that roll
/Props/            -- Props are the functional little elements in IVAs
/Resources/        -- This folder contains the file that declares all of the stock resources
/Sounds/           -- Can you hear the love tonight
/Spaces/           -- Spaces are IVAs

(This is just the way Squad does it, you can do it any way you want)


All assets will be loaded in a depth first alphabetic order, in sets based on file type. Parts will be displayed in the order they are loaded in. Because of this parts located in /GameData/Squad/Parts/Utility/ will always be listed before those in /GameData/Squad/Parts/Wheel/, even if the wheel part's name is before the utility part's name alphabetically.

Aside from load order, the directory structure of /GameData/YourFolder/ only serves as an organizational tool for the developer.

.CFG Files

Tentatively complete

File type .cfg is used for every configuration file in KSP except persistence files, which are stored in .sfs, these files are simply disk-storable containers for Config Nodes and as such their names and locations are almost entirely insignificant. Each .cfg file will be addressed in depth-first alphabetical order based on it's position within /GameData/, relative to other .cfg files, and that is the extent of the value that a file's name has.

It is entirely possible to merge all of the top level config nodes of a given add-on pack into a single file, but this is likely to make working with that file much more difficult. It's generally accepted that the best practice is to have a single top level config node per file, or put a small number of closely related parts in a single file. For example, if you have a command pod you could have the PART{}, INTERNAL{}, any custom PROP{}s and any custom RESOURCE_DEFINITION{}s in a single file, but as far as KSP is concerned, having a part.cfg, internal.cfg, props.cfg, etc, in one folder is functionally the same thing.

Note that the .cfg file is not loaded into RAM. The config nodes in it are used to build code objects, and the variables are populated into those objects. As such, reducing the total number of files has zero impact on RAM usage.

Model Assets

Goals:
  • Improve formatting
  • Include relevant links
  • Address Transform relevancy

There are only two model formats which KSP will load without outside forces, .MU, and .DAE

  • .DAE is a legacy mode option and should not be used for a multitude of reasons, the first is that .DAE is much more complex to set up, and more finicky about what will work. You also don't have a lot of the options that you would have with .mu
  • .MU is a compiled model format developed by our holy father Mu produced in Unity using PartTools. .MU files permit a large number options to be applied and changed, and stored inside the model itself. These include animations, manipulations to the texture sheets, customized and primative colliders, control over the shaders used on a part, and the inclusion of Transforms.

þ make 'Unity' and 'PartTools' links, give PartTools it's own page?

þ Transforms are maybe not relevant to this text

A Transform is a Unity Game Object in a specific place and with a specific orientation that is referenced by code to achieve many things, the Gimbal Transform is used to move an engine's nozzle mesh, which is a child of the transform, and the Thrust Transform is used as the coordinates and orientation to apply force to a part, RCS thrusters also use transforms for this.

Model assets can be located anywhere within /GameData/ and referenced by their address from .cfg files using MODEL{}, if not using MODEL{} they need to be in the same folder as the .cfg file.

Texture Assets

Goals:
  • Improve formatting
  • Suggest and link to some free graphics editors

þ Phrasing may be confusing, perhaps omit that Unity can natively handle texture formats KSP doesn't recognize There are a lot of kinds of textures which can be used in KSP but only 3 formats are currently accepted by the loader, .MBM, .TGA, and .PNG

Once loaded the format you choose Does Not Matter, KSP will convert everything into DXT1 or DXT5 depending on the presence of an alpha channel (transparency), both of which are lossy formats. Both formats are direct bits-per-pixel formats so the actual content of those pixels is unimportant but because DXT5 has an alpha channel, it is directly twice as large as DXT1. KSP chooses the format based on the image so make sure you don't have unnecessary alpha channels.

  • .TGA and .PNG are both editable, .MBM is technically editable, but it is not a format that graphics editing software will know what to do with, and you'll have to edit some stuff by hand before it can be opened.
  • .MBM is uncompressed, and .TGA has very little compression but is a lossy format.
  • .PNG is a very well compressed lossless format that allows for an alpha channel.

To repeat, the format of your files does not matter in game, it only impacts the amount of Data On Disk and the time it takes to read that data off the disk.

Sound Assets

Goals
  • Find someone who knows how this works
  • Make them write this section

They're not broken, they're just weird.

Config Nodes

Goals:
  • Suggest reviewing stock cfg files and the files of addons

(Note to plugin developers, this document only pertains to .cfgs) Starting in KSP 0.15 a .cfg structure known as Config Nodes was introduced, and later in KSP 0.20.0 alongside the game database system and /GameData/ directory structure. Config Nodes, generally seen as any string of upper case letters, numbers[confirmation needed] and underscores followed by an opening curly bracket ( { ) and later a closing one are a means of having more complexly organized data inside a part's configuration.

Prior to KSP 0.20.0 all parts had to exist by themselves in a file specifically named 'part.cfg', limiting any one folder to containing only one part, and due to restrictions on addressing assets, every part had to have it's own textures and models.

Following the release of KSP 0.20.0 parts must exist inside a .cfg file with any name, and must be wrapped in a PART{} config node. You are permitted to have multiple PART{}s in any given file, and the means of addressing assets has changed to be relative, treating /KSP/GameData/ as the root of any address.

Between the curly brackets of a config node you are able to define variables, their values, and other config nodes so long as they exist in that context. For an example:

PART{
    name = Example
    title = Superfly
    description = These are variables, they should be in lower case, and you can set any variable you want, but the code in game is only going to use what it needs
    banana = is a fully valid variable, that will not be used by anything in KSP

    RESOURCE{
        name = LiquidFuel
        amount = 400
    }
    MODULE{
        name = etc
    }
}

It is important to note that everything in KSP is Case Sensitive, from the variables and values in a .cfg file, to the names of asset files and folders. The capitalization scheme of keys and config nodes is defined entirely by the code that will use it, RESOURCE{} and Resource{} are not the same thing, and the later will do nothing, but also RESOURCE{Name=LiquidFuel} is not valid. Unfortunately within KSP there is no singular capitalization scheme to fall back on. "Generally" Config Nodes are in ALL CAPS, but sometimes they're in lowerCamelCase, but you always have to follow the code, or it won't work.

Proper tabulation in .cfg files is not necessary, but extremely useful in maintaining readability of complex configurations and will help to make sure all your config nodes are closed properly.

Keys

The order of keys in a .cfg file is completely unimportant. All config nodes and keys are loaded in one solid step, before any other code is given the chance to access the data, as such all of the information in a .cfg file is available to the code immediately. It will not occur that one thing doesn't load right because some piece of information has not been loaded yet. Organize your configurations as you see fit.

What does matter is the kinds of information that the code expects a key to contain. Also, Capitalization Always Matters. In both Keys and Values, if it's not capitalized the right way, it won't do what you want. This becomes problematic because KSP's capitalization scheme is rather inconsistent.

þ This table will likely need multiple revisions to achieve an optimal representation of the truth in a form that conveys the information adequately.

Data Type Something Example
Integer A Number without decimal values and without any formatting 40008
Float A number with decimal values but still no formatting 40.008
Text Plain text Hi, my name is Guacamole, and I'm stealing your car right now.
Identifier A set of letters and numbers, capital or lower case, without spaces or punctuation (exceptions...) SmallGearBay
Address An address relative to /KSP/GameData/ (always use /, never \) /Squad/Parts/Engine/liquidEngine2-2/
List A set of comma separated values, usually integers or floats 0.00, 0.147, 0.00, 0.0, 1.0, 0.0, 1
Binary A 0 or 1 indicating a yes or no to enable or disable certain things 1
Vector A list of 3 values, X, Y, and Z, used to describe coordinates, orientations, and complex scales 4.743, 7.853, 0.042

The format of defining a key and it's value is as follows regardless of the data being contained within it. No line end marker is necessary.

Key = Value

The keys you set in a .cfg files don't fit into many clear cut groups, some related to visual assets, some relate to aspects of that part in the world, but most of them fit into several groups, are used at various levels, and don't really do quite what you think. In the following tables they've been roughly organized by category as a factor of what they do, not where they're used.

Stock Config Nodes

Goals
  • Create table of keys for each node
  • Describe each node's function, and any nodular relationships
  • Describe glitches and limitations

Top Level Config Nodes

Node Used For
PART{} Defines a new part
RESOURCE_DEFINITION{} Defines a new resource to be used in and by PART{}s
INTERNAL{} Defines an internal space which can be used by PART{}s
PROP{} Defines an prop, a functional self contained element, which can be used in INTERNALS{}


PART{} Config Nodes

RESOURCE{} Sets a resource and quantity of resource for a part to contain

Key Data Type What it does
name Identifier The Resource the part will contain
amount Float The amount of resource the part will initially contain, will be rounded down to maxAmount if greater, so no overcharging.
maxAmount Float The amount of resource the part can contain

MODEL{} Alternate to mesh and texture variables, gives much better control but has some bugs

Key Data Type What it does
parent (Optional) Specifies what hierarchical element to append this model onto
model Address The model file (file.mu) that you wish to add to a part
texture List The texture you want to replace, comma, the address of the texture you want to replace it with
position Vector Offset from 0,0,0 in meters
rotation Vector Rotation along X,Y,Z (Units unconfirmed)
scale Vector Modifies the scale of the model along each of the three axis. 1=1:1 scale, 2=2:1 scale, etc

ATTACH{} Alternate to node_ definitions, very buggy, generally not used because of problems

MODULE{} Used to associate functionality with a part by linking a partModule to the PART{} instance

Part Modules

This section is grossly inadequate and outdated, as partModules are the primary way of attaching functionality to a part now
  • Write entire section
  • Come up with goals list

þ Merge into Config Nodes -> Stock Config Nodes -> PART{MODULE{}} þ Several available partModules deserve their own pages, explaining them sufficiently in this page would be unnecessary clutter.

PART Keys

Goals:
  • populate key table - Partially complete
  • Describe things


Key "Category" Data Type What it does
name Internal Identifier Internal designation of the part used by code
title Label Text External designation of the part used by players
author Label Text The names of the people who made it, often involved with add-on licensing
category Label Identifier Determines which tab of the VAB/SPH the part appears in; choose only one.
manufacturer Label Text Flavor text presented to the player, displays in a limited space
description Label Text Flavor text presented to the player, can be used to explain use of a part
cost Label Integer Representation of the value of a part in an undefined currency, not used by stock but used by some add-ons and challenges
subcategory Internal Integer Supposedly unused value for further sorting parts
scale Asset Float A value used for fixing the size of models which were not modeled correctly in meter scale. Further reading later on LINKHERE
rescaleFactor Asset Float A value used to manipulate the size of models after the fact, usually for reusing elements without needing to remake, or being able to remake the model differently
mass Physical Float The mass of the part, note, weight is a function of local gravity, so your Thrust to Weight ratio will vary by where you are, but your mass varies by how much resources you have.
maxTemp Physical Integer The temperature at which the part will explode to death
crashTolerance Physical Integer How hard the part can hit the ground and not explode
breakingForce Physical Integer The linear force at which a joint between two parts will fail, and the two parts will no longer be joined.
breakingTorque Physical Integer The rotational force at which a joint between two parts will fail, and the two parts will no longer be joined.
PhysicsSignificance Physical Binary If 1, the part doesn't really exist, doesn't have mass, drag, temperature, and can't do a bunch of other stuff.
specPower Asset Float
rimFalloff Asset Float
alphaCutoff Asset Float
dragModelType Physical  ???
maximum_drag Physical Float
minimum_drag Physical Float
stageOffset Internal Integer
fuelCrossFeed Internal Binary
NoCrossFeedNodeKey Internal  ???
specPower
The specular reflectivity of your part. It's best to leave it as it is.
rimFalloff
This defines the strength of the highlight effect in game. Higher values lead to a more pronounced effect near the edges.
alphaCutoff
This number defines the threshold for transparency on the part's texture. If your texture has an alpha channel (transparency), you can adjust this number to make sure your part is transparent or opaque where it should be. A value of 0 means nothing in the texture is considered to be transparent. A value of 1 means a completely transparent part.

þ Add subsection about MODEL{scale}, scale, rescaleFactor glitch and best practices

dragModelType - Leave this as default.

maximum_drag - What's the maximum amount of drag on your part? (Usually under 1.) Generally drag when part's direction of travel is along its y-axis.

minimum_drag - The minimum amount of drag your part will encounter. (Usually under 1 and lower than maximum_drag) (this value is unused if dragModelType is set to default) Generally drag when the part's direction of travel is perpendicular to its y-axis.

stageOffset and childStageOffset - Can be 0, 1, etc. defines whether this part will create a new stage before or after itself, or both (as do decouplers). This only applies for the automatically generated staging sequence. These replace stageBefore and stageAfter.

fuelCrossFeed - Will the part crossfeed fuel between parts attached to it?

NoCrossFeedNodeKey - if set to bottom will keep fuel from flowing FROM bottom nodes (avoiding some stack imbalances and partially mitigating the 0.15 bug of engines generating fuel). Used with parts with multiple bottom nodes, such as the TVR-1180C Mk1 Stack Tri-Coupler.

Node_s

Does not mention ATTACH{}, and ang_ notation can be confusing, should refer to rotation instead of angle

Another fairly easy section, this defines where we attach our part to other parts. You can have as many as you want, for example, tricouplers have four, three bottom and one top, while most parts simply have two, and a few parts have only one.

node_stack_bottom = x, y, z, angx, angy, angz, size
node_stack_top    = x, y, z, angx, angy, angz, size
node_attach       = x, y, z, angx, angy, angz, size

There's three example nodes. There are three different kinds, but only two are useful to us at the moment. We have node_stack and node_attach. Node stack is for defining where the part stacks vertically together with other parts, and node attach is used for defining where on the surface of your part other parts attach - so horizontal attachment.

All node attachment values are given with respect to an object's origin, and their values correspond to a model's units and scaling factors. A node_stack_bottom with x, y, and z values of (2.5, 5.0, 3.0) will have an attachment node 2.5 units to the right, 5.0 units up, and 3.0 units forward. The next three values refer to the orientation that a particular node will accept other attachments, on a scale of -1.0 to 1.0. These represent the vector that a part will orient itself on when attaching to the node. For example, a fuel tank with a node_stack_bottom will have angx, angy, and angz values of (0.0, -1.0, 0.0). This represents a vector downward relative to the part model, in the negative y direction. A value of (0.0, -1.0, 1.0) would represent a diagonal vector downward and forward, while a value of (1.0, 1.0, 1.0) would represent a vector to the right, up, and forward.

Generally, most parts will have angx, angy, and angz values of either (0.0, -1.0, 0.0) for a node_stack_bottom and (0.0, 1.0, 0.0) for a node_stack_top.

The last value indication the visual size of an attachment node. Values may be either 0 (small half-meter node), 1 (normal), or 2 (large). This parameter is optional and will default to 1 if nothing is specified. Keep in mind, naming conventions (_stack_bottom, _stack_top) for nodes only apply to node_attach; they are only helpful in identifying a node's position.

Attachment rules:

þ table This defines how your part attaches to other parts.

  • // attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
  • attachRules = 1,1,1,1,1

The rules correspond to the numbers below - 1 is allow, 0 is prevent. The tags are:

stack - Can your part be stacked on others?

SrfAttach - Can your part be placed onto a surface?

allowStack - Will you allow other parts to be stacked on your part?

allowSrfAttach Can other parts be placed on the surface of yours?

allowCollision - A special one: Can your part be placed if part of it is intersecting another part?


Note that you can also force parts attached to this part to attach in a specific symmetry.

  • // symmetry rules: 0=1x, 1=2x, 2=3x, 3=4x and so on...
  • stackSymmetry = 3

FX definitions:

More definitions! But this time, you're positioning the flame coming out the back of the rocket.

fx_exhaustFlame_yellow = x, y, z, angx, angy, angz, active
fx_exhaustLight_yellow = x, y, z, angx, angy, angz, active
fx_smokeTrail_medium   = x, y, z, angx, angy, angz, active

Okay, looks pretty similar to node_definitions, right?

You'll notice, just like node definitions, there are separate parts to each effect. You have fx_exhaustFlame, fx_exhaustLight, and fx_smokeTrail.

There are exactly what they sound like, the flame, the light, and the smoke trail.

There are variations on flame color, blue is also an option. To get a blue flame, you would use fx_exhaustFlame_blue. You would do the same for the exhaustLight.

The 'active' switch on the end is used to define when this effect will be visible. See the FX Groups listing to know which effect groups are available, and when they are used. It's also possible to assign an effect to more than just one FX Group. If for instance, you want a smoke effect to be visible both when the part activates and also when it deactivates itself, you can do this:

fx_gasBurst_white = x, y ,z, angx, angy, angz, activate, deactivate

This is particularly useful if you're defining a lot of effects, like the gas discharges on an RCS module


Easy enough, right? Adding to dummy file and continuing.

Modules

Nearly all modules have been depreciated and replaced with partModules which offer more control

So what part types can you have? þ Reorder rows based on frequency of use: Part, Winglet ControlSurface, HLandingLeg, FuelLine, Strut

Part Name Description
ControlSurface Movable wing-like surface. Can act as a rudder, aileron, elevator, canard or other aerodynamic control surface - function depends on placement on a ship.
Winglet A lift producing part. Not movable.
StrutConnector Used for making struts (the space ducttape kind)
FuelLine Allows for transfer of fuel.
HLandingLeg A moving landing leg, using .cfg parameters to move.
Part This module should be used for all parts except for a few specific instances where the module has not yet been replaced with a partModule


There is nothing special about module Part.


Module Settings

þ merge with Modules section

We're almost finished, a complete part is almost at our hands and you should know almost everything you need to create a part.cfg file. However, remember back when we were setting types? Well each type has an individual set of specific part parameters that change depending on what type of part it is.

You cannot mix and match parameters from different module types - it doesn't work.

These specific parameters are actually public variables defined in the Part classes themselves. The standard parameters are declared in the Part base class, and the specific ones in each Part extension (i.e., Modules)

Time to go through and see what special parameters each module can have.

Winglets

þ Make this a table

dragCoeff - The drag co-efficiency of the wings.

deflectionLiftCoeff - How much lift the wings generate.

Control Surfaces

þ Make this a table

ctrlSurfaceRange - How far off centre the control surface (rudder / aileron etc) can move under control

ctrlSurfaceArea - The effective surface area of the control surface - the bigger the surface, the bigger the surface area must be set to