Mojo3d: How to set more then 1 texture per model.

About Monkey 2 Forums Monkey 2 Programming Help Mojo3d: How to set more then 1 texture per model.

This topic contains 4 replies, has 2 voices, and was last updated by  Ethernaut 3 weeks, 1 day ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14156

    Pakz
    Participant

    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?

    #14160

    Ethernaut
    Participant

    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!

    #14161

    Pakz
    Participant

    Nice! I think I understand the second method. Not complex at all. I will try to get that working.

    #14163

    Pakz
    Participant

    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.

    #14164

    Ethernaut
    Participant

    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!

    https://github.com/DoctorWhoof/spriteTools
    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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.