Here is how I have done a handful of foam cutouts for cases.
I made a template using Fusion360. The template has parameters for length and height of the slide, overall length and height, grip angle, etc. That covers the basics for most autos. Things like the trigger guard and any unique profile of the grip, etc have to be added as appropriate, and with however much detail you want. I will say I arrived at this method after several attempts trying to capture every last detail of the shape. In the end less turned out to be more. On odd shaped protrusions like some sights or hammer, I tend to just cut a relief oversized rather than match it exactly.
So far all the pieces I've done were from the typical black or grey foam that comes with many cases. I have also done some tests in more rigid EVA foam. The EVA machines very nicely, and may be something that would work well for what you're trying to do.
Here's a screen shot of the template I made in Fusion. I will find some pics of the finished pieces also.