Hello, I’d like to create a custom material from Lua code instead of loading it from the ResourceCache, but I just don’t find a proper way.
I tried to modify a previously loaded one via ‘SetShaderParameter’, but it seems to modify the material to nullify its previous effects (I wouldn’t recommend this option, anyway, as it is a cached resource):
local node = scene:CreateChild('CustomNode')
local component = node:CreateComponent('CustomGeometry')
component:DefineVertex(Vector3(-1.2, 1.2, 0))
component:DefineVertex(Vector3(-1, 1.2, 0))
component:DefineVertex(Vector3(-1.2, -1, 0))
component.material = cache:GetResource('Material', 'Materials/RedUnlit.xml')
component.material:SetShaderParameter('MatDiffColor', Vector4(0, 1, 0, 1)) -- to make it green, for example
component:Commit()
I was trying to create it manually, but if I do
local material = Material()
the engine crashes. I guess it is because they must be created via resource factory, but how? I read in the docs about the global CreateObject method, but it does not seems to work, either. A little example would be very much appreciated!