x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Adding textures to a ProceduralMeshComponent (C++)

I'm new to Unreal and I've been playing with the ProceduralMeshComponent the last few days, using only C++.

I wanted to import meshes at runtime, and I managed to do that with the help of the Assimp library. So, right now I can load any mesh at runtime and it works fine: the thing missing are the textures.

Suppose I have a .obj mesh, with a .mtl file and a single .png texture. Suppose that I have no idea of what mesh I'm going to create a runtime, so I don't know how many materials there are and so on. How can I create the materials at runtime for this?

I've been looking all day on the internet for this kind of situation, but I couldn't find anything related. People always use materials that are made from within the editor, they don't create it via C++ code, but that's what I need.

I've looked into instanced materials and tried to do something like this (it's just an example in which some properties of the material get changed):

 // This code is executed everytime a section is added to the procedural mesh
 UMaterialInstanceDynamic* dynamic = UMaterialInstanceDynamic::Create(mMesh->GetMaterial(mSectionsCurrentlyProcessed), this);
 
 FLinearColor RandomColor;
 RandomColor.R = FMath::RandRange(0, 1);
 RandomColor.G = FMath::RandRange(0, 1);
 RandomColor.B = FMath::RandRange(0, 1);
 RandomColor.A = FMath::RandRange(0, 1);
 
 if (dynamic)
 {
     dynamic->SetVectorParameterValue(FName("Base_Color"), RandomColor);
     dynamic->SetScalarParameterValue(FName("MetalParam"), FMath::RandRange(0, 1));
     dynamic->SetScalarParameterValue("Roughness", 1.0f);
 }

The problem is that there is no starting material in my case, and the parameters I'm "modifying" in the example aren't present since they weren't defined in the editor.

So, to sum up, I'm running out of ideas. Is there a way to create an empty material from scratch in C++ and then fill it, in particular with a texture?

Product Version: UE 4.14
Tags:
more ▼

asked Dec 22 '16 at 09:14 PM in C++ Programming

avatar image

Beriol
58 4 8 17

avatar image Fieol Feb 11 '19 at 06:30 PM

This is a good question. I liked your idea. How much you have move forwarded from this part ? Can you share me your process ?

avatar image Beriol Feb 12 '19 at 02:16 PM

I ended up doing pretty much what I was (indirectly) suggesting.

I set up a "BaseMaterial", which contained a param for all the standard properties ("Color", "Metallic", "Roughness", etc.). At runtime, whenever I load info regarding a material I create an instance of that material and set the properties, as I was hinting in the question.

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question