OGRECave / ogre-procedural

procedural geometry for Ogre3D
https://ogrecave.github.io/ogre-procedural/
MIT License
40 stars 15 forks source link

Add support to choose mesh material during its creation #160

Closed TaaTT4 closed 3 years ago

TaaTT4 commented 3 years ago

As the title says, add support to choose meshes material during the invocation of realizeMesh and transformToMesh methods. Indeed, there's no way of doing it and the material name is hardcoded to BaseWhiteNoLighting. The PR doesn't break the API since the material name is specified as a default parameter.

With very little changes, the PR should be also applicable to master branch too.

paroj commented 3 years ago

this is incomplete, as the material is only uniquely identified by name and group.

Why dont you use mesh->getSubMesh(xx)->setMaterialName(...) instead, to set the material after creation?

TaaTT4 commented 3 years ago

this is incomplete, as the material is only uniquely identified by name and group.

You're right. The habit of using a single resource group led me to forget it. I can integrate the PR if you're open to accept it.

Why dont you use mesh->getSubMesh(xx)->setMaterialName(...) instead, to set the material after creation?

I could, but setting the material at the mesh creation phase seems a nice convenience addition to me.

paroj commented 3 years ago

sorry, forgot about this. instead of introducing the resource group, I would rather pass a MaterialPtr to keep things simple.

However, this requires a update of ManualObject in ogre-next, adding MaterialPtr overloads like in ogre1.

TaaTT4 commented 3 years ago

But MaterialPtr in ogre-next represent an old style material whose use is mainly for compositor quad passes and/or Entity. 99% of the times you use HlmsDatablock for ManualObject and or Item.

The need to changing also OGRE source code to support this little convenience PR seems a bit overkill to me. So it's probably better to leave the world as it is. I'll keep using mesh->getSubMesh(...)->setMaterialName(...) to change mesh material as I'm doing right now.

paroj commented 3 years ago

so you say

have different results in ogre-next even if mat->getName() == name?

TaaTT4 commented 3 years ago

Nope, I'm saying that in ogre-next 99% ot the times you call setDatablock or setDatablockOrMaterialName. MaterialPtr is a material as we know it from OGRE 1.x. HlmsDatablock is an HLMS material (PBS or Unlit). And 99% of the times you use this latter kind of materials on ogre-next.

paroj commented 3 years ago

but this particular PR is about setting the Material and not the Datablock!?

TaaTT4 commented 3 years ago

This PR is about to set a material name to the procedurally generated mesh. Which it ends in set an HlmsDatablock to the instances (Item or Entity) of that mesh (see here and here).

paroj commented 3 years ago

this implies

have different results in ogre-next even if mat->getName() == name

as if a Datablock with the same name exists, you get that instead of a material.

Of course results can differ depending on which Datablocks are available when you create an Mesh instance.

In Ogre1 I therefore got rid of all the name string caching and instead immediately resolve the resource.

Anyway.. implementing the feature of this PR would require different code-paths for ogre and ogre-next, thus diverging the branches. I do not think this is worth it. Therefore closing it.