March 28, 2018 at 12:06 pm #14156
I have no idea how to do this. I want to put different textures on a custom cube model. Actually I want to texture an entire chunk with maybe dozens of different textures.
Is there a command that I should look at or maybe a example?March 28, 2018 at 6:46 pm #14160
Not near a computer with Monkey right now, so I may overlooking important details, but the main two ways are:
1. (Simpler to make the textures, more expensive to render) Create multiple materials, each one with its own color textures, and add them to Model.Materials, and then specify the material index for each triangle.
2. (More complicated to create the textures, less flexible, but cheaper to render). Create a single material with a single color texture, but arrange the texture map in a sort of “spritesheet” containing all other “subtextures”. When creating the vertices, specify the texture coordinates for each subtexture. Example: If there are 4 subtextures in a 2×2 grid, the coordinates for the first one are (0,0), (0.5,0), (0.5,0.5) and (0,0.5).
Will look for examples when I get home.
Cheers!March 28, 2018 at 7:04 pm #14161
Nice! I think I understand the second method. Not complex at all. I will try to get that working.March 28, 2018 at 8:27 pm #14163
Quick question. If i need to copy one texture on top of another(block damage) would these textures be rendered to every block. Or would i need to create another sheet with these modified textures? Curious how that would be done.March 28, 2018 at 9:13 pm #14164
Hmm, good question. I don’t think there’s a way currently with PbrMaterial to apply a decal or a layer like that.
One stopgap solution would be to create a damage “card” and place it slightly offset from the surface you’re damaging. It’s actually quite flexible, since you could place the damage texture in any orientation for more variety, if needed.
The other way would be generating pre-damaged textures in the spritesheet, and just switch the texture coordinates accordingly, with the obvious downside of having to generate a ton of combinations – but that can be automated with Monkey2 code and creating new texture from pixmaps! This would be faster than cards for large scenes.
One thing that can help you is my Atlas class. You can load spritesheets, and it even creates a “color expanded border” (to prevent flickering around edges) around each texture on the fly, via pixmap manipulation. You could take a look at the code and create damaged textures after loading the main textures, via code. Heck, you could even modify it to load individual textures and combine them into spritesheets in memory only!
There’s a bug right now in this version, though. I have a more up-to-date version at home. Will update it later.
<edit> Atlas code is updated in the repository.
You must be logged in to reply to this topic.