Normally, every call to create a Stator, Actor, Mesh, Material or Texture goes through a Factory object.
The Pkg.ManagedFactory class provides the standard, default factory behavior.
However, it is possible to define custom factories that can alter the loading behavior for 3D models.
For example:
-- Factory
local factory = Pkg.ManagedFactory.New()
local CreateTextureOld = factory.CreateTexture
function factory:CreateTexture (info) -- Override the CreateTexture function
if string.find(info.url, "map") then
info.width = 256
info.height = 256
end
return CreateTextureOld(self, info)
end
-- Model
App.Model = factory:CreateStator({meshUrl = "foo.obj", texturePath = "bar/", scale = 0.2})
The above code first creates a new factory based on the standard ManagedFactory.
It then overrides the factory's CreateTexture function.
The new CreateTexture function forces all textures with 'map' in their url to load at a resolution of 256x256, whetever their original dimensions were.
A Stator is then created using the new factory. Any textures with 'map' in the url loaded for this Stator will be 256x256.
The same approach can be used with the CreateMaterial function to override material properties such as color, specular, reflection, texture and so on.
Factories can be useful, especially for overriding material and texture properties.
For example, it is possible to force a particular material to use anisotropic filtering, or to make a light map texture use the L8 format instead of DXT.