Jump to content

How do I change the texture on an asteroid?


Recommended Posts

I'm pretty sure I can change the texture on an asteroid, and I know how to dynamically change textures in KSP, but does anybody know the name of the transform for the asteroid model itself? Basically I need the name of the mesh so I can call SetTexture on the Renderer. Also, what is the name of the texture file for the rocky asteroid texture (and for that matter, magic boulder)? Anybody know? @JPLRepo, can you shed some light on this?

 

Thanks for your help. :)

Link to comment
Share on other sites

19 hours ago, wasml said:

Have you seen Sarbian's DebugStuff

Great for figuring out how things are put together in game. Shows how things are related and their names.

Thanks I've got that mod, definitely helped during my investigation.

On 3/4/2017 at 11:01 AM, Phineas Freak said:

Checking the model file ("Cube.mu") reveals that:

  • The model transform name is "Cube" (same as the .mu file)
  • The texture name is "PotatoRoid"

(But this is probably not the correct transform name to use)

Trying to grab the "Cube" transform doesn't work, unfortunately. DebugStuff shows the transform as Squad/Parts/Misc/PotatoRoid/Cube(Clone).

I've written some code to get to that "Cube(Clone)" transform, but I'm still not seeing the texture replacement. Here's the code I have:

            Transform potatoRoid = this.part.gameObject.transform.Find("model");
            Transform childTransform;
            if (potatoRoid == null)
            {
                Debug.Log("[ModuleKerbalKomet] - potatoRoid is null.");
                return;
            }

            Texture kometTexture = GameDatabase.Instance.GetTexture(kometTextureURL, false);
            if (kometTexture == null)
            {
                Debug.Log("[ModuleKerbalKomet] - kometTexture is null.");
                return;
            }

            Renderer renderer = potatoRoid.GetComponent<Renderer>();
            for (int index = 0; index < potatoRoid.childCount; index++)
            {
                childTransform = potatoRoid.GetChild(index);
                if (childTransform.name.Contains("Cube"))
                {
                    renderer = childTransform.GetComponent<Renderer>();
                    if (renderer != null)
                    {
                        Debug.Log("[ModuleKerbalKomet] - Found renderer, changing texture for " + childTransform.name);
                        renderer.material.SetTexture("_MainTex", kometTexture);
                    }
                    else
                    {
                        Debug.Log("[ModuleKerbalKomet] - Can't find Renderer");
                    }
                }
            }

I'm hoping someone from SQUAD can help me figure out how to change the asteroid texture, as the above code compiles and runs and changes the Renderer texture, but the asteroid texture doesn't change. I've verified that kometTexture is a valid texture that's loaded into the game.

Link to comment
Share on other sites

The "cube" stuff is not what you're looking for -- it's a dummy object that's normally buried deep inside the asteroid. The surface is a PQSMod (like those used for planetary surfaces), and AFAIK the asteroid "texture" is a blend of several texture files as dictated by the PQS. Unfortunately, Thomas P. says that the asteroid's PQS is much harder to work with than the planetary equivalent:

xEvilReeperx did propose a hackier solution earlier in the same thread, though I have no idea whether it will work on recent versions of KSP. That might be what you're looking for, @Angel-125.

Link to comment
Share on other sites

52 minutes ago, Starstrider42 said:

The "cube" stuff is not what you're looking for -- it's a dummy object that's normally buried deep inside the asteroid. The surface is a PQSMod (like those used for planetary surfaces), and AFAIK the asteroid "texture" is a blend of several texture files as dictated by the PQS. Unfortunately, Thomas P. says that the asteroid's PQS is much harder to work with than the planetary equivalent:

xEvilReeperx did propose a hackier solution earlier in the same thread, though I have no idea whether it will work on recent versions of KSP. That might be what you're looking for, @Angel-125.

Thank you much, that is good to know. :)

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