Sign in to follow this  
Followers 0
Mu.

0.20 - PartTools, GameDatabase and new features

90 posts in this topic

PartTools 0.20

Firstly, here is the new PartTools package for 0.20. Please read the included ReadMe.txt!

GameDatabase & PartLoader

The system that KSP uses to load game resources has changed, its called GameDatabase (GDb).

GDb iterates through the various game data directories creating a list of files. Each file is assigned a url and then the assets are loaded in a specific order; Assemblies (dlls), audio, textures, models and then configs.

Once GDb has finished loading files it hands control over to PartLoader which compiles all of the game's configs into parts, internal props and internal spaces.

GameDatabase URL system

GDb assigns a unique url to every asset and config in its directory structure. No file extensions are stored in the url, this allows you to reference models, textures and audio without needing to know what the file type is. The legacy directories (parts, internals, etc) are all prefixed with the directory name however the new data directory, GameData, is not. Lets look at some examples...

File: KSP\GameData\Squad\Parts\Command\landerCabinSmall\model.mu

URL: Squad\Parts\Command\landerCabinSmall\model

File: KSP\Parts\cupola\model000.mbm

URL: Parts\cupola\model000

GameDatabase 'Get' Methods

All of the assets held in the GDb are retrieved via the Get methods. They are seperated into asset type.

GetAudioClip - Gets audio clip from url

GetTexture - Gets texture from url

GetTextureIn - Gets a texture in the specified directory

GetModel - Gets model by url

GetModelIn - Gets model in specified directory

GetConfigNode - Gets a config node by url

GetConfigNodes - Gets all config nodes by type

For detailed information load the dll into VisualStudio or MonoDevleop.

KSPAddon & AddonLoader

AddonLoader is a simple system which allows modders to instantiate Unity MonoBehaviours without need to messily overload Part, PartModule or UnitTests. To do this you tag a component in your assembly with the KSPAddon attribute. This attribute allows you to set which scene the component is instantiated in and also if it should be repeatedly instantiated upon transition into that scene. If you want the component to not be destroyed then you should set 'once' to true and manually call DontDestroyOnLoad.

ATTACH Nodes

Previously, part configs had to define attach nodes with messy position values in the base config. Now you can define an attach node as being linked to a transform on the model. To do this you define an ATTACH config node like this..


NODE
{
name = top
transformName = myTopTransform
}
NODE
{
name = srfAttach
transformName = mySrfAttachmentTransform
}

There are two key names of attach nodes;

There is the 'top' node, this defines the traditional part heirarchy structure. If you only have one attach node then it should be called top.

There is also the 'srfAttach' node, this defines the surface attachment point. The name 'attach' is also valid for this node, you can only have one surface attachment node.

You can define two other values; size and method.

'size' allows you to change the node's sphere size in the editor and has no effect on gameplay.

'method' allows you to change the physic joint type. Its values can be; FIXED_JOINT, HINGE_JOINT, LOCKED_JOINT, MERGED_PHYSICS or NO_PHYSICS. Not sure what madness you can do with this value, will leave it to you all to play.

NOTE: Attach nodes defined in this way are not animated with respect to physics and should remain static on the model.

MODEL Nodes

In the old system, models were loaded directly from a part config's directory. This is still the case however can be overridden using MODEL config nodes.

MODEL nodes can be used to compile parts containing scaled, translated or rotated models. You can define multiple MODEL nodes to compile multiple models into one part. It also allows you to overload textures on the model.

Parts, Props and InternalSpaces can all use MODEL nodes instead of the traditional same-driectory loading system.

Here is a sample MODEL node showing all valid values


MODEL
{
model = Squad/Parts/Command/cupola/model
position = 0.25, 0.5, 1.0
scale = 2.0, 2.0, 4.0
rotation = 0, 90, 0
parent = anotherModelTransform
texture = model000 , Squad/Parts/Command/landerCabinSmall/model000
texture = oldTextureName , newTextureURL
}

NOTES:

The 'parent' value is only valid in the second or subsequent MODEL nodes as they refer to a transform which must already exist in the part model heirarchy.

Texture overloading value is delimited by comma or semicolon just in case you have spaces in your new texture's URL. All materials using the old texture are swapped to the new texture.

Edited by DYJ
Changed "ATTACH" to "NODE"
1 person likes this

Share this post


Link to post
Share on other sites
'size' allows you to change the node's sphere size in the editor and has no effect on gameplay.

I believe this used to affect snap distance, has that been removed/moved?

Also, what units are they in now? Is it unity distance measurements so that size 1 is a green sphere the diameter/radius of a fuel tank, rather than the previous fixed sizes?

'method' allows you to change the physic joint type. Its values can be; FIXED_JOINT, HINGE_JOINT, LOCKED_JOINT, MERGED_PHYSICS or NO_PHYSICS. Not sure what madness you can do with this value, will leave it to you all to play.

Squee! :D

I'm guessing LOCKED_JOINT is a configurableJoint with no movement allowed and FIXED_JOINT is the current default fixedJoint.

Hinge joint is an interesting one. Are the settings configurable in the config and if not then what are the default ones? Ball bearing type free movement with the axis through the connection? Does the rotation get saved in the persistence file?

Also, what's the distinction between MERGED_PHYSICS and NO_PHYSICS? Is the difference that the former moves the CoM while the later doesn't? Are they combining both parts under the same rigidbody? If so is there anything to dynamically separate them in a collision or are they stuck together forever once attached?

This applies to the part that's being attached, and has no influence from the value defined on the node it's attaching to. Is that correct?

MODEL nodes can be used to compile parts containing scaled, translated or rotated models.

Just a note generally: In the unity engine uneven scaling may result in funkyness of animations/gameObject rotation. I don't know if anything has changed for the KSP implementation, but if anyone is thinking of using it then bear that in mind.

Also, a neat trick in unity is that you can provide negative scaling values to mirror something. If you want left and right wing parts, for example, then you can now set the scale to something like 1,1,-1 and have a mirrored model without having to re-export. Although this does count as uneven scaling so the caveat above applies.

Share this post


Link to post
Share on other sites

Could you please elaborate on the physics joint types? Or just answer this; if I set NO_PHYSICS there should be no part wobble at all?

Edit: Reading it over again, can I take this bit

"NOTE: Attach nodes defined in this way are not animated with respect to physics and should remain static on the model."

to mean that if you use any of the physics joint types described above, there's no animation with regard to physics (= wobble)?

Edited by Borklund

Share this post


Link to post
Share on other sites
can I take this bit to mean that if you use any of the physics joint types described above, there's no animation with regard to physics (= wobble)?

I believe it means they're attached at the default location of the specified transform rather than to the transform itself, so moving the transform will destroy the illusion as the node won't move with it.

Share this post


Link to post
Share on other sites

I thought I had got used to the old part tools, and then this comes along :D Is the URL something that has to be assigned in the script in unity, or does it not matter? What happens if I change a folder name, do I need to re do the script?

Share this post


Link to post
Share on other sites

How do model nodes interact with other things based on models, like thrust transforms for engines, or jettison modules for fairings?

Share this post


Link to post
Share on other sites

heh, cool. any new info about how to use audio clips? thats something i dont think anyone has figured out without a plugin (and the legacy way doesnt work).

Share this post


Link to post
Share on other sites

When I import it and I try to add Part Tools as a component it says 'Script not found'?

I've tried installing it multiple times now

Fixed!

Edited by -Lysdal-

Share this post


Link to post
Share on other sites

NOTE: Attach nodes defined in this way are not animated with respect to physics and should remain static on the model.

You got me all excited there for a minute. I was hoping that I'd be able to child a transform to a mesh that gets animated and have the attachment node move. Are there any plans to add this sort of functionality, or is it just not possible due to Unity limitations?

Share this post


Link to post
Share on other sites

Is that possible to add a type value to a node defined the old way, entirely in the config? If so, could you provide an example of how it'd look like? I'd like to try out the new node types on the CSS, but I don't have access to source models, only to .mu files.

Share this post


Link to post
Share on other sites
You can define two other values; size and method.

How and where?

In Unity or in cfg ?

Share this post


Link to post
Share on other sites

cant figure out how to export prop configs now. where did the export button go?

e: fixed this. had to import an existing space and then copy the internal space script over. for some reason i cant add the script from the component window.

now its exporting my props config, sort of. some stuff doesnt work as expected. the cfg it outputs is loaded with a bunch of InternalCameraSwitch and one InternalSeat module entries with transform names that dont exist in my model. i just had to edit those out and replace them with my manually setup entries, so its workable if not ideal.

the import cfg just mangles the model, throwing out all those xform models that i painstakingly aligned. im just glad i saved first. so far this feature is only really useful if you need to copy the script over.

im also not able to get the new ATTACH system. i setup xform in the model, set up the attach entries, but when i try to use the part in game there are no nodes at all. i could be doing something wrong but idk.

the model nodes feature works great, i was able to finally accomplish texture sharing between different models. in one case i have 3 copies of the same model with different materials but the same textures, so that i can have different emission colors on each without needing more textures. my structural lattice system now only requires 2 textures for 8 parts. so this is really awesome.

Edited by Nuke

Share this post


Link to post
Share on other sites

I am also having trouble with the new nodes. I'm probably naming something wrong. Is there an example anyone has?

Share this post


Link to post
Share on other sites

When I open up the project in unity I get a bunch of errors. It tells me that the override command is wrong. Any answers?

Share this post


Link to post
Share on other sites

use forward slashes in your paths.

Share this post


Link to post
Share on other sites

Anyone else having a problem with Unity not outputting textures along with the model file? I keep trying but no textures are being output. Not as PNG, not as MBM.

I've learned how to use blender just to make a model, figured out I need to export as .fbx so this Unity thing will even import/use the model correctly. Now it's not even exporting things correctly. I've tried for a week, I give up.

Share this post


Link to post
Share on other sites

I'm having issues with the new Attach method. I am assuming an object transform is a named empty gameobject with it's location configured to where you want the attachment node to be. I've tried this and I'm not seeing the nodes. Does the axis have to point in a specific manner?

Share this post


Link to post
Share on other sites

Will tutorials based on 0.20 be posted?

Share this post


Link to post
Share on other sites

So I've spent the night playing with the particle emitter that was included in the part tools, but I'm struggling to find a way to export any custom fx that I can actually use. Anyone manage to export some fx using it? Any clues as to how to do so?

Share this post


Link to post
Share on other sites

To get the attachment nodes to work you must place them in your config like so:

NODE
{
name = top // attach / srfAttach may not work, you will probably need HINGE_JOINT for them to work.
transform = topTransform // Or whatever your transform name is.
size = 1 // Will always be 0 until fixed. Choices should be: 0, 1, 2
method = FIXED_JOINT // Will remain FIXED_JOINT until fixed.
}

Original post suggests:

ATTACH
{
name = top
transformName = topTransform
}

Size and Method are not being respected, so they will just be place-holders until it's fixed in the AttachNode class.

Place the transform (empty game object) in unity so that the blue arrow is facing away from the point you want to attach to.

I.e. Have the blue arrow facing down if the node is at the top of your model so that you can stack objects on top of your object.

Edited by Razchek
1 person likes this

Share this post


Link to post
Share on other sites

This is exactly what I discovered Razchek.

Share this post


Link to post
Share on other sites
To get the attachment nodes to work you must place them in your config like so:

NODE
{
name = top
transform = topTransform // Or whatever your transform name is.
size = 1.0 // Will always be 0 until fixed.
method = FIXED_JOINT // will always be FIXED_JOINT until fixed.
}

Original post suggests:

ATTACH
{
name = top
transformName = topTransform
}

Size and Method are not being respected, so they will just be place-holders until it's fixed in the AttachNode class.

Place the transform (empty game object) in unity so that the blue arrow is facing away from the point you want to attach to.

I.e. Have the blue arrow facing down if the node is at the top of your model so that you can stack objects on top of your object.

From my experience it seems that your nodes do not rescale with you model using this method. Is this what you're experiencing as well?

Share this post


Link to post
Share on other sites
From my experience it seems that your nodes do not rescale with you model using this method. Is this what you're experiencing as well?

Yeah. They will always be the smallest node size at the moment. Which is fine, as it doesn't seem to actually affect the joints - not to the point where I would notice at least. :)

Share this post


Link to post
Share on other sites
Yeah. They will always be the smallest node size at the moment. Which is fine, as it doesn't seem to actually affect the joints - not to the point where I would notice at least. :)

My issue is that the nodes remain in the same position regardless of the rescale factor on the part. Although the tiny nodes do irritate me.

Share this post


Link to post
Share on other sites
My issue is that the nodes remain in the same position regardless of the rescale factor on the part. Although the tiny nodes do irritate me.

Oh wow. I didn't even bother trying that out. That sucks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0