Open oxplay2 opened 4 years ago
I'm thinking of working on this issue soon unless anyone else has started, and I'm in the early planning stages.
I agree that the last proposal of yours sounds like the best way to do it.
The only concern I have is with the way this utility currently works to create the batch at the same time as the atlas. I'm not sure if I would be better off making an entirely new utility and just use the old converter as a reference.
The way it currently works seems to be great if you only have one set of objects that need batched - but in a large scene where you might have several of the same models occurring in more than one batch, then you will end up with an entirely new Texture Atlas and new material for every new batch, even though those batches might have many of the same models/textures, so if you create a scene with 10 batched foilage squares (separated into squared areas for distance culling) then you would end up with 10 very similar texture atlases, although they may not be interchangeable, and that would be a lot of extra memory usage that could be saved if they all just shared a texture atlas
So unless I'm misunderstanding anything, then I think I will need to rewrite the whole utility so that it doesn't actually batch the models, but so it would instead just create the texture atlas and a new folder containing individual copies of the models (with adjusted texCoords to match the atlas of course) that use the same material with the new texture atlas, so then they could be batched together any way at anytime during the scene building process, while all using 1 single material and texture atlas. Essentially separating the batching process from the texture atlas creation process.
Any thoughts?
well, it was long time ago, but as i remember it was just about PBR version of "makeAtlasBatch"
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:
below is Lightning.j3md related code:
and: