Jump to content

Changing the EVA Kerbal model


Recommended Posts

I've been messing around with lightly modifying KSP for awhile without any goal or purpose. After starting to use unity myself and learning blender, I thought that changing the model used for EVA Kerbals would be a simple but very interesting modification to make to KSP.

So does anyone know where one would make that change? I've seen people change the textures of the suits and faces, but haven't seen anyone change the actual model. I imagine it must not be too difficult, mostly just creating a new unity rag doll object, and then telling KSP/Unity to look at the new object instead of the standard one.

If anyone could share any information regarding getting KSP/Unity to look in a different location for the EVA Kerbal model, that would be extremely appreciated!

Link to comment
Share on other sites

  • 5 weeks later...

I have seen some threads talking about the same thing as you and most of the replys are people saying it is either 'impossible' or 'too hard'. However they also said that about multiplayer and n-body but they are both now mods. The only plugin I could find that forces KSP to load a different asset is this: https://bitbucket.org/xEvilReeperx/ksp_navballtexturechanger/src/dc236d49c3a91a0002cb1ba3af381a78012a1da4/NavBallTextureExport/NBTexExport.cs?at=master though I am not sure how helpful this will be, seeing as it is a texture.

I wish I could help but I am not a plugin maker. I can, however bit of help regarding the model itself. The kerbal model most likely is embedded somewhere in the .asset files. To replace it without redoing the animations you'll need to find out exactly how it is rigged. The only way I can think of doing this is digging the model out of the .asset files. Alternatively you could use a brand new rig and redo all the animations but that could quite a lot of work. If you want any help modeling or texturing just PM me. Good luck!

Link to comment
Share on other sites

I'm actually doing something like this at the moment, and I may have found a way to change the models at runtime.

For now it's very basic, and I don't think this could be used to load a human model yet.

Still, one can mess around with the SkinnedMeshRenderer of a GameObject, and change the SharedMesh and SharedMaterial.

I'm actually having a lot of problems with those:

The thing is, I don't know how to access a model from an asset, so, when I want to use a particular in-game model, I have to load the scene where the model come from (for instance the VAB), make a copy of what I need, then use this copy elsewhere.

I can't just use props (drillers, screwdrivers, etc...) without this shenanigan.

And, when I try to load a model from a file (a .dae or a .mu), I get a GameObject containing only MeshRenderers.

Those meshes can't be used to change a SharedMesh property, so I wonder if anyone knows how to load (or how to model a correct mesh) for this purpose.

Edit: (kind of proof of concept, click it to view the others) DAQp5b7.jpg

Edited by Lilleman
Link to comment
Share on other sites

Eventually, what I'm working on will become a mod, but it will take some time.

I can still share some snippets, since I need help from people who actually know how animated meshes works in Unity.

Here is a basic (and naive) example that modify the Kerbal from the main menu.

The source code from Toolbar (and his easter egg) has been very useful, and the main difference is this time I actually changed some meshes in the scene.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

//For this example, we will modify the Main Menu Kerbal, but this is possible in any other scene in the game.

namespace KSPMMModifyDemo
{
//This will be loaded at the main menu
[KSPAddon(KSPAddon.Startup.MainMenu,true)]
public class MessWithMMKerb : MonoBehaviour
{
//The kerbal from the Main Menu
GameObject MMKerb = null;

//Will be called at start
public void Awake()
{
MMKerb = getGOByName("kbEVA@idle");
MessWithKerb(MMKerb);
}

//return a GameObject from the scene by his name
private GameObject getGOByName(string sName)
{
//A naive (but working) way is to go trough all our loaded GameObjects, and find the one we want
foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)))
{
if (go.name == sName)
{
return go;
}
}
return null;
}

//actually modify the skinnedMeshRenderers
private void MessWithKerb(GameObject kb)
{
//this will be a very simple example, let's just replace the Kerbal's helmet mesh by the one from the visor
SkinnedMeshRenderer smrHelmet = null;
SkinnedMeshRenderer smrVisor = null;

foreach (SkinnedMeshRenderer smr in kb.GetComponentsInChildren(typeof(SkinnedMeshRenderer)))
{
if (smr.name == "helmet")
{
smrHelmet = smr;
}
if (smr.name == "visor")
{
smrVisor = smr;
}
}
if ((smrHelmet != null) && (smrVisor != null))
{
smrHelmet.sharedMesh = smrVisor.sharedMesh;//Replace the mesh
smrHelmet.sharedMaterial = smrVisor.sharedMaterial;//Replace the material
smrVisor.enabled = false;//disable the visor
}
}
}
}


That will show something like this:

fgeF0NV.jpg

Still, I can't find some animated models to test this in-game. This is so frustrating: Anyone knows of a tutorial for a beginner in modelling that would allow me to create a basic animated stick figure?

Also, I found how to spawn objects from assets now.

Link to comment
Share on other sites

Thanks, I will make some tests with the astronaut, and I also found a Minion from Despicable Me, that could be fun.

I also found this page, wich let me think it's possible to copy an armature and keyframes from an existing animation, or at least create new ones in-game for a static mesh.

Well, that's enough things to test tonight (who need sleep anyway?). The sad part is, changing the EVA models is only one of the things I want my mod to do, and it's been days since I made actual progress on the remaining code...

Coding is one hell of a drug...

Edit: Okay, It's driving me crazy. I tried everything I thought of starting with a static mesh, with no success. Whatever I try, all I get is "SkinnedMeshRenderer requires a mesh with skinning or blendshape information." all over my log file.

I have a lot of things to learn about animation (I'm starting from scratch), obviously.

I will continue my mod and get back to it later. For info, I want to make a small mod to spawn NPCs around the KSC. I can already spawn a bunch of Kerbals and make them move, but it will be nice to actually change their models, and not only their textures.

Next thing I have to try is to load an already animated model. That means I have to create one...

Edited by Lilleman
Link to comment
Share on other sites

I don't like to "up" my posts, but this thread only had 10 views since I edited my last one.

Also, I thought I'd found a way to load objects from assets. I was wrong: I can clone objects from the main scene and the main menu at almost anytime, but I can't access objects from VAB/SPH. They are loaded from a different asset, and are destroyed once the game is loaded.

As I said earlier, I can make a clone of these objects once an editor is open, and use those clones later in-game. But didn't found anything to instantiate them otherwise.

There are lots of props that could be useful here: pencils, drillers, hammer, wrench, etc... Also some Kerbals employees (that's the thing I really want to mess with).

Link to comment
Share on other sites

  • 2 weeks later...

I don't really want to start a thread in the plugin section yet, since I have no working code to share: I still didn't managed to create a skinnedMeshRenderer, or to import one.

But I really want to make my plugin, even if it will be completely useless. So I guess I will create a thread in the plugin development section just to ask for help...

Lately I was only trying to spawn new Kerbals. So my actual plugin can clone some, then it summons the Kraken as soon as the scene change a bit.

Not exactly the plugin I want to release...

Saddest part being that those two points (spawning Kerbals and changing their meshes) will be a very small part of my plugin, the biggest parts will probably be the spawning logic, the pathfinding and the AI.

Still, maybe with the help of someone who knows how to import a skinned mesh, the most interesting part can be done. I need to make some new snippets of code, some screenshots, and I will make this thread.

Link to comment
Share on other sites

Sorry, double post again, but with some news., I finally found a way to import SkinnedMeshRenderers and Bones.

The process was actually the same as before, with the internal meshes, but I needed some correct models to load.

I found a trick, since I still don't know how to model : convert a Half-Life mdl file to fbx, then convert this fbx to MU using PartTools.

There is a known problem with Unity and the way it load materials from fbx, so they have to be reset manually, like in TextureReplacer, or fixed during the conversion.

The problem I have now is the animation, not working. I also have to learn how to convert an animated part properly.

Some screenshots.

Edit: a small snippet of code:

GameObject goModel = GameDatabase.Instance.GetModel("GSL/TestHumanoid");//My file is named "TestHumanoid.mu"
goModel.transform.position = MMKerb.transform.position + new Vector3(-0.5f, 1, 0);//Spawn the model close to the Main menu Kerbal
goModel.transform.rotation = MMKerb.transform.rotation;
goModel.SetActive(true);

Once the model is loaded, it contains a SkinnedMeshRenderer, some bones, and an Animation module if possible.

Edited by Lilleman
Link to comment
Share on other sites

awesome progress..

I'm eager to reproduce this as an alien sickness for kerbals in NCI - suddenly he grows tentacles..

lol

You seem to have experimented a lot with the EVA animations..

Did you by any chance stumble over a way to trigger the walk animation while in space?

I've made working magboots but the animation needs to be called by script somehow..

sorry for offtopic - but maybe you found that out in the experimenting process..

Link to comment
Share on other sites

I didn't tried to set the animation without scripts yet. But maybe you can try to force the EVA's vessel to consider itself landed:

vessel.situation = Vessel.Situations.LANDED;

By the way, since we're off-topic, how did you managed to spawn vessels with your plugin? Kerbals in EVA are single-part vessels, so I could use something like this. For now everytime I spawn Kerbals, it summon the Kraken.

Link to comment
Share on other sites

I'll try the landed - but I'm pretty sure, this will also summon the kraken..

I did that with LCARS vessels and it's unstable to have something landed while it's not..

spawn:

I learned how to do it from some code from KAS..

it seems, the parts on the back of kerbals are also one part vessels - after some experimenting, I had it working..

Kerbals - in LCARS, I have a transporter system - to spawn EVAKerbal out of a vessel is simple..

never tried to spawn out of thin air though..

Elaborate, where from and with what functions did you try to sapwn?

Link to comment
Share on other sites

Long story short: I tried creating vessels from thin air, create some from Protovessels, loading some from confignodes... The only working thing was to clone a kerbal already in EVA.

I didn't tought of spawning kerbals from a vessel... I guess I could make a Spawn Point using an invisible pod, with no collider, then spawn Kerbals from there...

For your magboots, if you can't change the status to landed, maybe there's a way to consider the ship as the reference body? I don't know if it's possible to create a celestialBody from a vessel...

Link to comment
Share on other sites

I see, my spawn code uses valid "Parts" and requires a part cfg - since we don't have that for KerbalEVA, it could become a problem in the details once more..

I'd like to give you advise on what to try further with your project - but, honestly, I have no clue where you plan to go. - why do you want to spawn kerbals, how many, where?

I can't seem to find the post now, but didn't I read something about planning an AI ? - similiar plans at NCI for an AI for shooting satelites and hostile ships that come after you..

but what your plans are, no clue - so if you care to elaborate in more detail, I'll do my best to make valid suggestions as far as my knowledge goes..

If you prefere to keep a low profile for now, I (or most likely no one else) will be able to suggest anything more.. at least for the best way to spawn..

it depends on the planned use.. :-)

Magboots: lol, I guess not..

that wouldn't be practical anyways, since I need force perpendicular to the ground you are standing on and not centered to the CoM of the "Celestial-Ship-Body"

However - that part works anyways.. it's just while I move them around, the Kerbals hang there in space coma - I'd like to call the walk animation while I push the button..

it's no big deal though, just a quite tricky, totally undocumented and extremly well hidden thing - in other words - default KSP API work.. :-D

but enough of the magboots - back on topic..

Link to comment
Share on other sites

The plan for my plugin is to spawn some NPCs around the KSC; tourists, crew, technicians, scientists, and eventually make this compatible with KerbTown. Since I already know how to change the skin of a Kerbal in EVA, and control it, I thought the easiest way to do so was to spawn some around...

As for the AI, it will be more like a Finite State Machine, I don't plan it to be too complex: Tourists will watch your ship take off (the distance will vary depending on their courage), and technicians will recover debris in their range. Scientists may eventually provide sciences points from watching the launch (not sure about this one: gaining science is easy enough) and crew will be Kerbals from the CrewRoster, ready to get aboard a ship.

For the number of spawned Kerbs, it will depend on the framerate (Kerbals are Polygons-heavy). Ideally, there will be between 50 and 100 Kerbals around the center.

Changing the models for a low-poly one could have been nice in this case...

So, yeah, this will be a useless plugin, only meant to get some life around the KSC (in fact "Get Some Life" should be the name).

For your animation problem, i don't really get it, I thought you had it working when setting the animation manually?

Something like this:

_eva.animation.CrossFade("wkC_forward"); //_eva is a KerbalEVA

should do the trick, the problem being you'll have to check every update if the animation changed.

To get back to the original subject: no progress made. I tried several way to convert mdl files, but I can't get the Animation module to load in Unity, so my newly imported meshes won't move a bit...

Link to comment
Share on other sites

omg - that sounds horrifyingly aweseom..

An other mod I won't be able to install because of framerate.. - I mean, one of those I would love to install hahah

my PC has a crappy graphix card u no.. lol

Well, to your problem - I'd try it that way - since you can change crew capacity on the fly, I say a setting will spawn an invisible vessel (inside a building mesh or so) with exactly the amount of kerbals in it as the setting calls for.

Then you use something like my transporter code to position them on scene start at the calculated locations you intend to provide..

After that, the vessel will just sit there and be "hidden"

The hard part will be the locations - the spawning is copy paste from my code..

(just a dirty outdated version - but the transport is stable)

https://github.com/philotical/StarTrekImpulseDrive/blob/master/Beta6/LCARS_TransporterSystem.01.cs#L791-L811

that's it - it's even more than you need, it ads stuff to the kerbalEVA.

HTH

the spawnEVA-function has one downside - it switches vessel to that kerbal - I guess you need to find a way to stop that if you want to loop through 200 of them..

Or better - try to do it while in space center - then the vessel change does probbably not happen

But let me ask an other stupid question..

There is a class named "GroundCrew" or so - I assume those kerbals are less load intensive - wouldn't it be a good idea to hoock in there?

About magboots - I got the code that holds the kerbal in place, rotated to the ship wall he's standing on and he can move around by appling forces to invisible game objects..

then I went on to other projects for now - next on my to-do list is the animations - all I have so far is a list of clip names but I have no clue how to use them..

your snippet might allready help a lot, thank's - I will consult it when I get back to the boots in a few days..

Link to comment
Share on other sites

Thanks. I think I better not spawn too much EVAs, it might be a problem...

I'm trying to get at least models from the ground crew, but I don't think they'll handle physics if I just instantiate some(edit: plus, I don't know how to instantiate them outside the VAB/SPH scenes). Ground crew could be fun, but it will be funnier if you can mess with him.

I finally found how to import animations. I think I will go this way:

-The ground crew will be made from custom objects, so it will not mess with any of my savegame informations and be destroyed every time a scene change. I'll have to find a way to make those objects as light as possible.

-the selectable kerbonauts will be spawned from an invisible vessel near a door of the Crew Facility. If the CrewRoster is empty, no Kerbal is spawned. I'll have to add a custom behaviour to those EVAs.

You should take a look at EVAFollowers sources for the animations.

Edited by Lilleman
Link to comment
Share on other sites

Well, now I've managed to load animated objects, I can't figure the best way to switch the model at runtime:

-instantiate the model, make the Kerbal's model invisible, then change the position and the status of the imported model every update (probably the dirtiest but easiest solution)

-create a new part from the imported model, then add the "kerbalEVA" module to it (didnt' tried that yet).

-keep as much informations as possible from the original kerbalEVA, then mess with SkinnedMeshRenderers and animation...

And probably other tricks I didn't think of.

A challenge indeed, and I don't think I could come up with the best solution. But eventually I can make a quick tutorial on how to convert an animated mdl file to mu and load it, if it can help someone to make some tests. Could it help?

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...