Jump to content

How to Add Multiple Textures on a Part


Recommended Posts

I have parts that have multiple objects. Each object should have its own material/texture. When importing from Blender 2.71 with an FBX file, I can assign only one texture. That texture is then applied to all objects. I'm not trying to put multiple textures on the same object, i.e., sub-meshes.

To provide a very simple example, this BLEND file contains two cubes; each has a different image texture applied. A collision mesh (node_collider) is also included. there are no animations.

Development file

Even though Unity allows me to import the two texture images, I cannot assign a different texture to each. I've found some discussion about how you import: By "Base Texture Name" or "Model’s Material", but I'm uncertain how to apply this info, if at all. I've found several tutorials on using multiple textures in Unity, but only when actually creating the models in Unity vice importing.

What is the method by which Unity can accept multiple textures for multiple objects that KSP will then allow? There must be a method, because I've opened MU files in Blender and have sen the multiple objects and materials/textures.

Thank you for your assistance.

Edited by Apollo13
Link to comment
Share on other sites

I have parts that have multiple objects. Each object should have its own material/texture.

I do NOT want to apply the SAME material/texture to all objects. that's easy. I want to apply a separate material/texture to each individual object. How do I do that, when Unity allows me to assign only one material/texture?

Link to comment
Share on other sites

I do NOT want to apply the SAME material/texture to all objects. that's easy. I want to apply a separate material/texture to each individual object. How do I do that, when Unity allows me to assign only one material/texture?

If it is applying one texture to all objects then you are using the same material name for all of your objects. Each object that needs a different texture needs its own material.

Link to comment
Share on other sites

not sure what you are exactly asking for here. texture is not the same as material. materials can use single texture or multiple textures, diffuse + normal + emissive for example. multiple objects that use multiple materials, well, requires multiple materials. KSP only allows 1 material per object. A part can have multiple objects, each with their own material.

each texture channel in a material must be assigned a texture, and the A texture of the same exact name must be in the same folder as the MU file for it to load.

Edited by nli2work
Link to comment
Share on other sites

If it is applying one texture to all objects then you are using the same material name for all of your objects. Each object that needs a different texture needs its own material.

If you view my Blender file, you'll note that each object has its own material assigned. Each material has a single texture, specifically, an image file.

In Unity, How can I assign one material to one object and another material to another object?

Edited by Apollo13
Link to comment
Share on other sites

If you view my Blender file, you'll note that each object has its own material assigned.

materials in blender don't matter. only material using KSP shaders assigned in Unity matters. You can assign multiple materials in Unity, but KSP on reads the 1st one. if you want multiple materials in a KSP part; you need multiple objects. Open the part heirarchy in Unity, drag/drop materials to objects in the heirarchy window. or assign new material in Mesh Renderer component.

Edited by nli2work
Link to comment
Share on other sites

I do have multiple objects in the Blender file. I'm not trying to apply sub-meshes to a single object.

This is what I'm seeing in the Materials assignment area. I can drag either the Leafy or Stone Wall to the upper right corner icon box. that causes it to be assigned to both objects. If I select another object in the Models folder and assign a different texture to it, that texture is applied to both objects. there is only one Materials, call "No Name". yet, i named each material in Blender. You'll note I set the shader to KSP/Diffuse.

Object cube_le(afy) is to have the leafy material which also has the leafy texture.

Object cube_br(icks) is to have the Stone Wall material and stone wall texture.

uB77NJ5.jpg

IVxLYBe.jpg

QGJhOnS.jpg

Edited by Apollo13
Link to comment
Share on other sites

I don't really know how to explain it better. What is in blender doesn't matter. In unity, look at the material set for each object, it is the same thing. You only have one material. It changes when you import from blender to unity and then switch to ksp shader. you will need to reassign material and texture. Add a second material in unity and assign a different texture to it.

Link to comment
Share on other sites

I can't help with blender side. It could be a simple check box in your export settings, it could be something more involved. I don't know.

in Unity, select the material (or create a new one), name it, assign texture A; CTRL-D, name it something new, assign assign texture B

Link to comment
Share on other sites

OK, so I figured out how to create Materials in Unity via the Assets->Create menu. I didn't know how to do that until five minutes ago. However, I can't seem to assign them to their respective Objects. when I click on the Models and objects within, it shows a pink image. I deleted the original "No name" material. Should I not have done that?

eG26cDL.jpg

b7By2Uq.jpg

I appreciate you all working through this with me.

Edited by Apollo13
Link to comment
Share on other sites

Hi, we've all been there buddy. Believe it or not it's as simple a dragging and dropping the named material onto the object/objects either directly in the scene view or in the hierarchy, makes no difference which method , though while dragging the material onto the part in the scene you can accidentally apply it to any other part , so for ease of use just drag the materiel not the texture onto the part in the hierarchy view

Link to comment
Share on other sites

you are trying to assign a material directly to the import file, which is read-only. drag the file into the scene, then you can assign material however you like by drag/dropping, or clicking the tiny bullseye next to "Element 0" field, or you can drag/drop the material into that field.

it's a good idea to create a prefab by dragging the object from scene heirarchy into project window (take care not to child to an existing object or prefab) once you finish setting up the heirarchy, materials, and everything else. The prefab has blue cube icon without the white paper in the lower right corner. Whenever you need to export the part again, drop the prefab into a scene and export.

Link to comment
Share on other sites

I see from the pic above my reply that you have a folder called materials, are your materials in there? is your model set up in the scene window,? ignore the inspector for now. If your model is set up in scene window you should be able to drag materials straight from your materials folder onto the model.

So this is the process, you have deleted the no name material, that's why the cube is pink, because no material means no shader, no problem as you can create a new one in unity, so create a new one, once you have it will appear in the materials folder. ok? cool, now click that new material, if you didn't name it on creation it will be called no name. and add a KSP shader to it , by clicking material and setting preference in the inspector window. now drag your model into the scene window. Next drag material from folder to model , that's it, to make sure of this I did exactly that as I was writing this, rinse and repeat until all parts have materials desired.

Link to comment
Share on other sites

you are trying to assign a material directly to the import file, which is read-only. drag the file into the scene, then you can assign material however you like by drag/dropping, or clicking the tiny bullseye next to "Element 0" field, or you can drag/drop the material into that field.

That worked. Did not know imports were read-only.

Do I create a GameObject and all that other stuff as we discussed in my "Simple Animation" thread? Does that process change?

it's a good idea to create a prefab by dragging the object from scene hierarchy into project window (take care not to child to an existing object or prefab) once you finish setting up the heirarchy, materials, and everything else. The prefab has blue cube icon without the white paper in the lower right corner. Whenever you need to export the part again, drop the prefab into a scene and export.
I'll try this, as soon as I figure out what you said.
I see from the pic above my reply that you have a folder called materials, are your materials in there? is your model set up in the scene window,? ignore the inspector for now. If your model is set up in scene window you should be able to drag materials straight from your materials folder onto the model.

I just now dragged model to the Scene. Usually, this happens when I create the GameObject, which I've not created yet. Should I not directly drag the model to the Scene? Rather, should I do so it after creating the GameObject?

Edited by Apollo13
Link to comment
Share on other sites

If your model has an origin of 0,0,0 and is aligned Y up and has a scale of 1 ( just like an empty game object) you can leave out creating another game object and apply the part tools directly to the root part, certain kSP addons like Infernal Robotics parts will not work if you make the model a child of another game object. tried to get a pic of what I mean but Imgur's having a legs in the air moment, ah no here we go,

2kSNbnb.png

Link to comment
Share on other sites

Continuing (forum was giving 502 errors last night in middle of our conversation).

@SpannerMonkey: thanks for that image and explanation.

I dragged the model into the Scene versus going through the GameObject. I did, however, create an empty GameObject and added the KSP/Part_Tools component. After dragging part to the Scene and setting Materials to each object, I selected the GameObject. I set "Model Name" to "model" and "Texture Format" to "MBM". I clicked the Write button. In my output folder "Processed Model", the MU appeared, but not the MBM files for the textures.

Compare that result to putting the model under the GameObject. When Write is clicked, the MU and MBM files are created.

Using your method, how do I create MBM files in this case? And, will the MU file contain references to the correct MBM files?

DvjUGqX.jpg

Sidebar:

Once I understood the full ramifications of these statements:

materials in blender don't matter. only material using KSP shaders assigned in Unity matters
What is in blender doesn't matter.

things became much clearer. And a bit depressing. I could create the most wonderful, carefully crafted, multiple Materials using Blender Nodes Editor, and it would all be for naught. I would need to recreate the material in Unity.

EDIT: I applied what I learned here to what I learned in my "Simple Animation" thread. I now have a working, animated part with the correct (placeholder) textures applied. I used the model in GameObject method. I want to understand and use SpannerMonkey's method as well (if I can get MBM files created and applied). THANK YOU ALL!!!!

Edited by Apollo13
Link to comment
Share on other sites

Unity works same way as KSP (really the other way around since KSP is built on Unity). everything is a GameObject at the base level in Unity (a Part in KSP). you attach components (Modules) to give them different behaviours. The simplest GameObject is a Transform, which stores data for position, rotation, and scale. Nothing else. What's visible as an object is a GameObject with 2 additional components, Mesh Filter (filters out meshes you don't want displayed); and Mesh Renderer (renders mesh you've selected with Mesh Filter). Mesh Renderer is where you do material set up. Knowing this, you can easily see object creation step in Unity is the same, whether you are creating a light; camera; or something else.

Model Imports are simply a series of automated steps of creating empty GameObject, add MeshFilter, add MeshRenderer. Imports are marked Read Only because they are your source, and you want them around in unmolested form in case you need to revert to it. Unity also refers to them so you manipulate them directly, Unity looses track and your actual unity assets get jumbled. Next to the Apply button in the import's Inspector Panel at the bottom right, there's "Reimport"; this reverts all the import settings to default so you can go back to the baseline you started with. similar to Photoshop's history window, by clicking on the very top of the window, you can revert to the initial state when you first opened the file, even though your history of actions has progressed far beyond the total steps tracked.

for exporting you want to write to a location outside of Unity's project folder tree (directly to KSP Gamedata; or some 3rd location). Creating files directly inside Unity project will slow Unity down, and can mess up Unity's file tracking system. For the exports, the MU file has texture references embedded, it expects A texture of the same exact name in the same folder that it resides in. whether the texture is the same as the original doesn't matter, as long as the name is exactly the same. This is where MODEL{} comes in to allow you to assign different textures during part compile time. For simplicity sake, any part you put into KSP's Gamedata should have MU, CFG, and as many Texture files as referred by the MU file; all in the same folder inside of GameData, as long as the asset is in GameData somewhere, KSP will attempt to load it. If you do a lot of texture sharing, every part must have at least a dummy texture, a 32x32 square, in order to allow the MU file to load properly. B9 uses this extensively to save on memory footprint; as does Karbonite and my parts.

things became much clearer. And a bit depressing. I could create the most wonderful, carefully crafted, multiple Materials using Blender Nodes Editor, and it would all be for naught. I would need to recreate the material in Unity.

welcome to real-time graphics. :) you have to make compromises when you need 60 frames per second, instead of 60 seconds per frame. Even the best Unreal 4, much less Unity, can offer is not as good as the least Vray or Renderman can do.

Edited by nli2work
Link to comment
Share on other sites

A dummy tex could also be 2x2.

welcome to real-time graphics. :) you have to make compromises when you need 60 frames per second, instead of 60 seconds per frame. Even the best Unreal 4, much less Unity, can offer is not as good as the least Vray or Renderman can do.

Not fully true. Even the old (even obsolete) gMotor2 engine used in GTL/GTR2/GTR EVO/rFactor and a few other sim racing game can manage a lot's of material per mesh (usually between 4 to 7 or more) with 20000 polygons or more cars, many cars at once + the track itself with many materials too, lot's of tex, blending (like KSP bodies surface textures) without the need of a hardware which is not available yet.

And as almost everything is limited by the CPU (the 1st core), GPU could have more duty to do, a lot more. Take a look at DX11 Nvidia demos, tesselation or Islands for example.

Link to comment
Share on other sites

no I'm talking about FX in films, that's what Vray and Renderman rendering systems are designed to do. That's closer to what Blender; 3DSMax; Maya; etc's rendering engines are.

Different beast from real-time engines. Unreal 4's tech demos look really good to gamer's eyes; but show it to a film FX artist they will complain to no end about wrong lighting and bad GI calculations.

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