Jump to content

Dislay part image in flight GUI window


Recommended Posts

I've searched high and low and cannot locate this information anywhere.

Problem:

  • I have the inflight vessel's part list and can access all properties and methods. Fine.
  • I would like to take this list of vessel parts and display a list of images matching each part in the same way as the VAB/SPH parts list
  • I have no idea how to access the name of the image to display(the .mu file?), and the function calls for putting that image on a button like the VAB/SPH

I have assumed this is possible given that it is being done in the VAB/SPH but, I don't know of any modules that do something similar. So, does anyone know how this can be done or, can you point me to some module code where this is being done?

Link to comment
Share on other sites

afaik, the (rotating) images are inside an "animator" of the part..

I have no details - but this is my understanding after making part in unity..

I would try the first animator you find - but maybe I'm wrong on this..

In my IDE, if I search in Object Browser, I get several results for

"PartIcon" - maybe that helps..

Link to comment
Share on other sites

Those VAB icons aren't simple textures. As far as I know they use the actual part and make it rotate when you select it. It's easy to trigger this while in the VAB, but the readily accessible methods to do so don't work outside of the editor.

There is an EditorPartIcon class, which seems to get its info from an AvailablePart instance, and a PartListTooltips, but I'm not sure how usable any of those are outside of the editor.

Link to comment
Share on other sites

I hadn't considered that the model icon would be stored on the animator(component?) property. I'm not a modeller so this would all be new territory for me. :)

The current community documentation on parts has:


Animation[] FindModelAnimators ()
Animation[] FindModelAnimators (string clipName)
T FindModelComponent< T > ()
T FindModelComponent< T > (string childName)
T[] FindModelComponents< T > ()
T[] FindModelComponents< T > (string childName)

How you pull out an image from an animation, or even play and animation in the GUI, is unknown at this point in time. Unfortunately, the above API describes the model components with the generic type(which is probably why I missed this) so, working with that is going to be a pain. Hopefully I can dig around and come up with same usable images from these collections.

I'll update to where I'm at with my current understanding of the problem:

What I'm looking to do exists in the UnityPro editor as AssetPreview but, this is simply not available as it is productivity functionality only. Obviously to help sell the pro version.

I suspect that in the VAB/SPH the parts are being listed using a GUI.Button with the image parameter being a Texture which is rendered from the part model using RenderTexture class to convert the 3D model into a 2D image.

To do this, I think SQUAD has used the RenderTexture class when the game loads to generate temporary images from objects in scene snapshots to attach to the GameObjects. Which might help explain why loading objects takes so long.

As a side note, I've been looking at Loading textures only as required but this mod seems to loop through all the DameData folders to pull out all the model.mu files on load and stores them in the GameDatabase, which I have no idea what that is, against their part names. Then in flight all part names are found and the texture location is matached to the name of the part in the GameDatabase. So, far I have no clear indication how to call a function like part.getModelMesh, apart from the potential FindModelComponent method.

EDIT: I didn't realize you could rotate those images!

Edited by O-Doc
Link to comment
Share on other sites

So, I'm looking at the exception logs posted to Real Fuels and it seems that EditorLogic is the controller class and EditorPartList is a wrapper class for the parts navigation collection of EditorPartIcon objects which is a view class that holds some event handling in the editor. I get the feeling they will be pulling their data from the gerneric parts GameObject. Hopefully...

Thanks for the help peeps. Do keep it coming, this is the last piece of a larger puzzle which I want to solve before coding up a GUI.

Link to comment
Share on other sites

How you pull out an image from an animation

I think you're thinking of the wrong type of animation here. In Unity the common type of an "animation" would be one where it's not a sequence of single static images (or key frames being interpolated a play time), but rather a sequence of value key frames. For example, an animation can be used to modify the transform of a 3D object to displace it, or have it rotate, or scale it, or have lights go on/off slowly, or flicker. So you see, there's quite a variety of things you can do with these animations, but they are not your typical movie animation with individual image frames (or key frames.)

I suspect that in the VAB/SPH the parts are being listed using a GUI.Button with the image parameter being a Texture which is rendered from the part model using RenderTexture class to convert the 3D model into a 2D image.

Either that, or they could be using several cameras. You can set up a camera so that its output (which is what you as the player see on screen) does not fill the whole screen, but only a tiny portion of the screen (such as an editor button.) In addition, because the object in question is part of the same scene, they would have to use layers so that the object does not interfere with the rest of the scene and vice versa (lighting and shadows, for example.)

Link to comment
Share on other sites

Either that, or they could be using several cameras. You can set up a camera so that its output (which is what you as the player see on screen) does not fill the whole screen, but only a tiny portion of the screen (such as an editor button.) In addition, because the object in question is part of the same scene, they would have to use layers so that the object does not interfere with the rest of the scene and vice versa (lighting and shadows, for example.)

This seems to be the approach to take. Vessel Viewer is only pulling out the mesh of the part using the following code:


//now we need to get all meshes in the part
List<MeshFilter> meshFList = new List<MeshFilter>();
foreach (MeshFilter mf in part.transform.GetComponentsInChildren<MeshFilter>())
{
meshFList.Add(mf);
}

I then takes this list of of mesh co-ordinates and draws the wireframes using Vector3() and renderLine() oupting straight to GL. Alot of the work is then focused on reshaping the draw to fit into the VV bounding box. Not exactly the approach I'm looking for.

It did give me and understanding of GameObject components and lead me to this tutorial on rendering GameObjects. So I guess I need to figure out how to generate a camera on the fly. Lazor and HullCam seem to be the next steps in research.

These steps in that tutorial pretty much sum up the approach I'll need to take:

  1. We've set up a camera on its own layer.
  2. We cloned the object we want to take a picture of.
  3. We positioned the object in front of our camera, and changed the object to the render camera layer.
  4. We acquired a temporary render texture and assigned it as the camera's target texture.
  5. We told the camera to render.

Link to comment
Share on other sites

Here's the code for instantiating a camera object from Lazor:

go = new GameObject();
go.name = name +" "+ go.GetInstanceID();
cam = go.AddComponent<Camera>();

That looks like enough to get an icon into my GUI. :)

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