Ben-Ho
Ben-Ho

Reputation: 53

libgdx texture from code on mesh of model

I want to render a few 3D models, to be concrete cards (but should have 3 dimensions) with different values on the front-side.

To accomplish this I thought it would be a good idea to create a model which represents the dimensions and form of a card, if possible already supply a default-texture for the card and add card-specific values like a number different for every rendered model.

I'm already able to load the model with default-texture and render to screen, but I don't have any clue how to add the dynamic texture to the front-side of the model.

Upvotes: 0

Views: 4936

Answers (2)

Thomas Williams
Thomas Williams

Reputation: 1548

You have probably worked this out ages ago, but to put a texture on the front side of the model depends on the uvs you create in your modelling sofware. So if you split the front side uvs on a separate island from your side uvs then that will be one of your numbers. For instance if have 4 uv islands your texture would go from 0 to 3. So your front side would be one of these numbers. The model would have to be unwrapped correctly for this to work though.

Also you have to add a multi/sub texture and number each one different. Then and only then will you see a different texture on each side. Only thing I haven't managed to do is to scale the texture correctly.

Upvotes: 0

Daahrien
Daahrien

Reputation: 10320

Create a TextureAttribute per each card type, then set it into the material of each model instance:

TextureAttribute textureAttribute1 = new TextureAttribute(TextureAttribute.Diffuse, yourtexture);

//

material = modelinstance.materials.get(0);
material.set(textureAttribute1);`

Upvotes: 4

Related Questions