Skip to content

TextureAtlas class for PBR / custom materials #1263

@oxplay2

Description

@oxplay2

recently @yaRnMcDonuts had issues to use TextureAtlas generator for his PBR models.

not sure if issue or feature.

but:
Geometry geom = TextureAtlas.makeAtlasBatch(scene, assetManager, 2048);

within TextureAtlass class, it refer only for Lightning.j3md material.

i would suggest do one of below options:

  • create TextureAtlasMaterialMerger interface, and provide 2 classes TextureAtlasPBRMerger and TextureAtlasLightningMerger

  • create TextureAtlasLightning and TextureAtlasPBR(but it might have dupplicated code, so its bad)

  • create "in-code" if/else conditions to check material of element (but here it will break if one model is PBR and second is Lightning material type)

  • create "in-code" additional if/else conditions, but also add new variable in initialization like:
    TextureAtlas.makeAtlasBatch(scene, assetManager, 2048, TextureAtlas.MATERIAL_PBR);
    to allow set what materials should be gathered.

  • like above, but: TextureAtlas.makeAtlasBatch(scene, assetManager, 2048, materialToPutTexturesAndReadType);
    what i mean with last param is that TextureAtlas would put just textures into new user created material. This should throw exception if batching geometry have different material type.

imo last option sounds best. - reasons:

  • because each geometry also have float/vector/etc material data, not just textures, we might "get averate values" but anyway i think best would be if user would provide material with defined values and TextureAtlas would just update its textures and apply for all geometries. current class do it ugly way by just setting mat.setFloat("Shininess", 16.0f); that might not be expected by user anyway.
    Last option also allow "custom material" batching.

below is Lightning.j3md related code:

    public boolean addGeometry(Geometry geometry) {
        Texture diffuse = getMaterialTexture(geometry, "DiffuseMap");
        Texture normal = getMaterialTexture(geometry, "NormalMap");
        Texture specular = getMaterialTexture(geometry, "SpecularMap");
        if (diffuse == null) {
            diffuse = getMaterialTexture(geometry, "ColorMap");

        }
        if (diffuse != null && diffuse.getKey() != null) {
            String keyName = diffuse.getKey().toString();
            if (!addTexture(diffuse, "DiffuseMap")) {
                return false;
            } else {
                if (normal != null && normal.getKey() != null) {
                    addTexture(normal, "NormalMap", keyName);
                }
                if (specular != null && specular.getKey() != null) {
                    addTexture(specular, "SpecularMap", keyName);
                }
            }
            return true;
        }
        return true;
    }

and:

        Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
        Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
        Texture normalMap = atlas.getAtlasTexture("NormalMap");
        Texture specularMap = atlas.getAtlasTexture("SpecularMap");
        if (diffuseMap != null) {
            mat.setTexture("DiffuseMap", diffuseMap);
        }
        if (normalMap != null) {
            mat.setTexture("NormalMap", normalMap);
        }
        if (specularMap != null) {
            mat.setTexture("SpecularMap", specularMap);
        }
        mat.setFloat("Shininess", 16.0f);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions