Jump to content

Part Tools 0.20, Blender, Unity, and KSP


Recommended Posts

This information seems to be scattered across a zillion threads, so I thought I would do others a favor and try to compile everything I've found here. Not much of this is stuff I actually figured out, but I can't say I was paying all that much attention when looking for it to be able to properly credit those who I got the info from. Suffice to say, I owe many thanks to several members of this forum.

Anywho, here is what I cobbled together:

1. Half the written tutorials on the internet will have you doing far more work than needed.

2. Get Unity. Don't groan. Just do it. Your stuff is not going to work right without it, and no, there is no way to convince Blender to do it. Import the KSP Part Tools package from the Assets -> Import Package -> Custom Package dialogue. Open Part Tools from the Tools menu and tell it where your KSP GameData folder is.

3. Use the "Assets" folder made by Unity as your storage place for developing parts. You may find it useful to add other folders inside there. For example I have "Textures", "Materials", "KSP Prefabs", and "UV layouts". Unity will detect changes to these files and folders automatically. Unity will export .mu and material files to the folder you set for each part when you give them a Part Tools component.

4. In KSP; Alt+F12 -> Database -> Reload All is your friend.

5. It's not a terrible idea to have a stock KSP install reserved for development. This will load faster and avoid the need to troubleshoot unforeseen conflicts with other mods until you're sure yours actually works.

To make the simplest of models:

Open up Blender, delete the default camera and light. Select the default cube and switch to edit mode. Select all the faces of the cube and UV map it. Split the viewport and put the new window into UV mode. Create a new image that's 512x512. A black image should appear in the UV window, and the cube should go dark too. Now you can switch the main viewport to Texture Paint and add some color to the cube. More often than not though you will want to export the UV layout from the window showing the UV map, and then use something like GIMP to make your textures.

Save both the .blend and your texture into the Unity Assets folder.

Open Unity. If you don't see your resources in the bottom center of the window, click on the "Assets" folder in the bottom left-ish of the window.

Drag and drop the .blend file into the Unity scene.

If the model is missing its texture look in your Assets folders for the material and drag and drop that onto the model. If the material was not generated, right click in the Asset preview area and select Material. Click on the new material, give it a KSP shader, and then click on the "Select" button in the box down and a little to the right from where you pick the shader. From there select your texture file, and then drop the material onto the model.

Since the only thing in the hierarchy for this should be the cube, click on that, then click "Add Component". Pick Physics -> Box Collider. Tick "Concave". Now add a KSP -> Part Tools component. Change the name (default: "NewModel") to "model". Set the directory to the directory you made to store the part (more on that in a sec). Click "Write". All the part should need now is a part.cfg file.

If you made your own collision mesh in Blender then your model will have an arrow next to it in the Unity hierarchy.

- Add the KSP Part Tools component to the very top level, or "parent", then add the colliders the appropriate child mesh.

- Remove the "MeshRenderer" component from any mesh you don't want to show up in game.

- Make sure you click Concave when using a Mesh Collider.

- If doing so causes your collider to warp way out of the shape you want then you need to break it down into several simpler meshes.

- Your collision mesh/es can have any name, you do not need to call them "node_collider".

There can also be other static meshes in the scene, like say, an antennae, which are rendered but play no role in collisions.

If you want to add a hatch; Make sure the origin of your main mesh in Blender is inside one of its collision meshes. Make a cube about 50cm high, 50cm wide and 5cm thick and place it where you want the hatch. In Unity the Y (green) goes up, and Z (blue) faces in the direction Kerbals are ejected. Name the cube something easy to remember. Repeat the same procedure for ladders, except make the cube however tall you want the ladder to be, and point the Z axis in the direction Kerbals should face while climbing. Place the face of the box closest to the model approximately where the hands and feet should go. Do not put it inside your other collision meshes. It may be possible to overlap hatches and ladders though. After doing that, select your boxes in Unity and give them Physics colliders, as well as remove the Mesh Renderer. I also tick the "Is Trigger" box, but I am not sure its needed. In the top right of Unity you should see Tags and Layers. Click Tags and go to Add Tag. Off to the right of "Element0" click, it's hard to tell, but there is a place to type there. Add a tag called "Ladder" for ladders and/or "Airlock" for airlocks. Name Layer 21 "Part Triggers". Apply the appropriate tag to the boxes you made, and add them to the Part Triggers layer.

Unfortunately this is as far as I have gotten. I know nothing about animations, or how to get engines working properly. If this doesn't turn out to be an entirely useless wall of text I will try and update it with those things as I get to them. If someone wants to add in an explanation to help me along, that would be great.

Oh, and in the part.cfg file. Note in Blender where you want attachment points to be. Apparently you can define them with empty Game Objects from Unity, but as far as I can tell that's not entirely functional yet, so it seems best to use the old way. I have however been using MODEL {} nodes to deal with rotation and scaling. (Shown in Part Tools 0.20 thread)

Directory structure is also more simple than implied by many internet guides. Take a look in the Squad folder for an idea of how to organize things. You choose the menu in which parts appear in the game from the config file for each part, so directory structure is more about logical organization than anything else. You will likely want a top level folder next to Squad, with Parts and other folders similar to theirs, but from there it's really up to you. No need for a texture and mesh folder for each part folder though, all the game uses now is part.cfg, model.mu, and any materials that go with it.

Also, if someone knows how I can more easily use the same material across multiple parts, and possibly even the same model at different scales, without having to duplicate the materials and mu files for each, that would be great, I haven't been able to get that working 100% yet.

Link to comment
Share on other sites

I did get a lot of info from hoojis thread, but also noticed there were about 12 Blender related threads on the first page of this forum. I was trying to condense just that stuff into a single location, as well as update/add to some of the things that are outdated or not well described in those links.

Link to comment
Share on other sites

I did get a lot of info from hoojis thread, but also noticed there were about 12 Blender related threads on the first page of this forum. I was trying to condense just that stuff into a single location, as well as update/add to some of the things that are outdated or not well described in those links.

You have posted alot of good information in the other thread, we should get hooji to link to that also.

Link to comment
Share on other sites

By all means link, or even just directly steal the text, I don't mind in the slightest if it's being put to use helping others learn.

Also, thanks. I can never tell if what I post is useful or just more confusing, haha.

Link to comment
Share on other sites

  • 2 weeks later...

2. Get Unity. Don't groan. Just do it. Your stuff is not going to work right without it, and no, there is no way to convince Blender to do it. Import the KSP Part Tools package from the Assets -> Import Package -> Custom Package dialogue. Open Part Tools from the Tools menu and tell it where your KSP GameData folder is.

3. Use the "Assets" folder made by Unity as your storage place for developing parts. You may find it useful to add other folders inside there. For example I have "Textures", "Materials", "KSP Prefabs", and "UV layouts". Unity will detect changes to these files and folders automatically. Unity will export .mu and material files to the folder you set for each part when you give them a Part Tools component.

4. In KSP; Alt+F12 -> Database -> Reload All is your friend.

5. It's not a terrible idea to have a stock KSP install reserved for development. This will load faster and avoid the need to troubleshoot unforeseen conflicts with other mods until you're sure yours actually works.

I am trying to follow these steps, but there seem to be some gaps. For example:

"Import the KSP Part Tools package from the Assets -> Import Package -> Custom Package dialogue. Open Part Tools from the Tools menu and tell it where your KSP GameData folder is."

Can you elaborate on the a lot please?

Specifically:

What is the "KSP Part Tools package? How do I get it?

Where is "Assets"? Is that in Unity?

Which Tools menu are you talking about?

Pictures would be great.

Please spell it out as if I know nothing about unity....because I don't.

I already read

http://forum.kerbalspaceprogram.com/showthread.php/25013-Compilation-of-modding-information-links-for-0-19-0-20-Last-updated-30-06-13

Which sent me to:

http://forum.kerbalspaceprogram.com/showthread.php/25040

But the tutorial is out of date and i cannot get it to work.

Edited by Smurfalot
Link to comment
Share on other sites

What is the "KSP Part Tools package? How do I get it?

Where is "Assets"? Is that in Unity?

Which Tools menu are you talking about?

The KSP Part Tools are a Unity plugin written by Mu (one of the KSP devs) that allows the creation of the .mu filetype for use in KSP. You can download them from the first link in this post.

Assets is a folder created by Unity upon install (or first load) that contains all the various materials, models etc. that you use when making something.

Tools menu is available on the top of the Unity window along with File, Edit, Assets etc. I can't remember for certain, but I suspect that it doesn't show up until after you have installed the Part Tools.

Link to comment
Share on other sites

The KSP Part Tools are a Unity plugin written by Mu (one of the KSP devs) that allows the creation of the .mu filetype for use in KSP. You can download them from the first link in this post.

Thank you very much for your help. I believe I have the right Part Tools now-- I had downloaded the old one PartTools18 as instructed by that tutorial, but could not get it to work because the file names have changed and I cannot get past creating a new project.

Assets is a folder created by Unity upon install (or first load) that contains all the various materials, models etc. that you use when making something.

Tools menu is available on the top of the Unity window along with File, Edit, Assets etc. I can't remember for certain, but I suspect that it doesn't show up until after you have installed the Part Tools.

This may be why I could not find it, I started a new project when I realized I had the wrong part tools and could no longer find the folder.

Edit: Created a new unity project and selected "UpgradeProject" and "PartTools" from the .20 download to create and set the KSP GameData, but I do not understand what Step 3 is talking about. The other tutorial said something about creating an empty game object.

Edited by Smurfalot
Link to comment
Share on other sites

  • 4 months later...

You can't just drag the .blend file into the Unity scene as stated, you need to save export as a .FBX file from Blender. It's a problem on Blender's side, apparently. Having figure that out, I'm now struggling to find this "concave" option in Unity, now that I have the model imported. Not that I'm not thankful, but if you're going to write something like this, screen caps are really useful. I recommend using Sharex to capture, edit (i.e. add arrows and text for emphasis, etc), upload, URL shorten and copy shortened URL into clipboard memory ready for pasting, all in one command: http://getsharex.com/

Link to comment
Share on other sites

I'm now struggling to find this "concave" option in Unity

There is no concave option, he meant convex. With a mesh object selected, add a mesh collider through the add component button on the right side of the screen(inspector window). The panel it opens up will have a convex option. You need to check that option if you are using a custom mesh for a collider and you want it to collide correctly with parts/environment. If your mesh is concave, unity will force the collision mesh to be convex.

Link to comment
Share on other sites

I can't see a convex option (if I'd seen one I would've assumed that was what was meant). What subsection of the inspector is it supposed to lie under? This is what I'm looking at: http://bit.ly/194rgzC.

What I don't understand is why we can't use the original model/mesh as the collider mesh when most of the time that is what you will want to do. I don't know what convex and concave mean in this context, either, even if I could find them ;)

Thanks for your help, btw.

Link to comment
Share on other sites

You added a BOX collider. It is convex by default since Unity generates the geometry.

A MESH collider is used to convert a 3d mesh imported from your modeling program into a collider. So you create a cube mesh in Blender or whatever and resize it so it provides the bounds for your model (can be a cylinder, sphere, or whatever, but it should be less than 256 polygons)

In the past before PartTools, it would have been named node_collder and the part loader would ignore its material and render it invisible and then calculate a convex mesh collider for it as it loads.

For part tools, you can import said mesh into Unity, then add Component -> Physics -> Mesh Collider - this will have a CONVEX check-box- which will generate a green wire-mesh to show its bounds. You can then remove the Mesh Renderer inspector element to make it invisible.

It doesn't have to be a separate mesh either, you can generate a mesh collider for your main part - just keep in mind if you have concave areas the convex solver will fill over the gaps so the collision will be 'above' your part.

Despite what someone said, if you do not check the convex box, Unity/KSP will not make your collider convex anyway. You can add a mesh collider to any part and leave it unchecked and it will work for surface-attachment functions like struts, fuel lines, decouplers, and should even collide with parts from other vessels - they WILL NOT collide with the ground at all though unless set convex - if anyone has used my shuttle wings in Tiberdyne, the wings themselves are not convex but you can attach things to them - they don't collide with the ground. I had to specifically add primitive wing-shaped meshes inside the wings and set those to convex to enable ground-collision - you can notice the wing edges will dip into the ground a bit before crashing.

Link to comment
Share on other sites

You added a BOX collider. It is convex by default since Unity generates the geometry.

Right, so there was nothing I was doing wrong, it was the instructions that were written incorrectly:

click "Add Component". Pick Physics -> Box Collider. Tick "Concave".

Thanks for all the info, Tiberion. I don't think I'm anywhere near using it yet, though, because I've just downloaded the programs involved, having never used them before, and am trying to simply get an object (Blender's default cube) into KSP as the bare minimum first step ;)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...