There are services in the USA and I am sure elsewhere that will cut foam perfectly using a laser to match your supplied paper tracing of your gear.
custom cut foam inserts laser was my search term
https://www.mycasebuilder.com is an example.
Firearms cases are also done this way, so check with related websites for reviews.
Many people have moved away from foam, especially for long term storage, since it breaks down and also holds dust. Once you open a foam case in the field on a windy day the foam is now polluted with the sand and dust and it is difficult to remove.
To my thinking the safest way to travel with very delicate gear is to wrap it in easily replaceable bubble wrap and place it in smooth padded dividers. For most of my photo equipment I simply rely on the padded dividers or padded wraps and smaller cases... but ideally you'd want more protection for high vibrations like traveling overland on safari or on a motorcycle.
Good Luck