cherab / core

The core source repository for the Cherab project.
https://www.cherab.info
Other
44 stars 24 forks source link

Fix update bug of LaserMaterial #421

Closed Mateasek closed 9 months ago

Mateasek commented 10 months ago

Fixes problem described in #420

In short: Laser primitives are now dropped and recreated after Laser.transform changes which removes the problem of old transfomrs being cached in LaserMaterial

vsnever commented 10 months ago

Just as an option, wouldn't it be safer in general to cache affine matrices the first time the emission_function() is called, rather than when the LaserMaterial is initialised? In this case, the LaserMaterial must keep the references to laser and laser segment nodes, but the Laser does not have to rebuild its internal geometry when the node is transformed.

Mateasek commented 10 months ago

Hi @vsnever

thanks for looking into it. The reaction to the material change would mean that the laser primitives couldn't be regular Raysect primitives, which I would like to avoid.

I like the idea of caching the transforms in the emission function. It is indeed the safest option. Thanks for suggesting it. I will apply the changes. I don't think that rebuilding the primitives on every change is a big deal, but from the point of view of safety your idea is much better.

Mateasek commented 10 months ago

As suggested by @vsnever the transforms are now checked and cached in the emission function.

Also I added a check for the number of primitives the material is assigned to. Because of the transform caces the material should be assigned to only a single primitive for safety.

Mateasek commented 10 months ago

@vsnever, I merged the latest changes from development.