Within my software, I come across numerous instances where I create geometries, each with its own meshing preferences (double-sided or not? Lambert or basic material?). Despite these variations, they all share the same texture. My goal is to load this common texture just once, presenting a design challenge:
While using TextureLoader.load()
to load the texture, it can only be utilized within the callback function provided to the load
method. This necessitates gathering information about all geometry instances and their specific preferences before loading the texture. By doing so, I can make this data accessible (via a closure) to the callback function when the loading process begins.
I wonder if there exists a standard solution to address this issue. Perhaps fellow three.js users have faced similar dilemmas. One possible approach involves utilizing promises: the load function returns a promise representing the texture, which can then be passed on to different locations requiring meshed geometries. This method proves convenient as it eliminates the need to accumulate large amounts of geometry data solely for later transmission in one go.
However, are there alternative solutions that offer similar convenience within the realm of callback semantics?