I’m creating scenes that can have any number of entities.
Each can have any of the models in the builtin
Each needs to use a glow effect at any given time, like in this demo.
In the demo, each robot’s glow relies on materials prepared like this:
robot.model = craft.model(asset.builtin.Blocky_Characters.Robot) robot.material = craft.material(asset.builtin.Materials.Specular) robot.material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
Notice that for
material.map I have to directly read the image used for the model’s skin.
But as I said, in the real project, entities can use any craft model, not just robots.
So is there a way to access this skin dynamically, in other words, without knowing what it is beforehand?
Because if there isn’t, in order to be able to use this effect in my project, I think I will need to manually hand-code the image that goes with every single craft model.
And if the models or skins are ever changed in the future the project will break.
So, like, that’s not good, man.
To use this approach, I think I have to be able to do something like this:
function assignMaterial(thisEntity) local skinImage = thisEntity.skin thisEntity.material = craft.material(asset.builtin.Materials.Specular) thisEntity.material.map = skinImage end
…but I can’t do that because
thisEntity.skin isn’t an attribute that actually exists.
Is there some way to do this without hand-coding the value for
skin for each model?