When Hugh Herr lost both of his legs — from just below the knees on down — in a rock-climbing accident at age 17, he feared he’d never walk again.

Thirty-five years later, he’s able to walk, run, dance, swim and, yes, climb mountains — and he has multiple sets of customized “legs” to make it possible.

Herr heads the biomechatronics group at the MIT Media Lab in Cambridge, Mass., designing such futuristic wearables as exoskeleton suits that feed energy into healthy limbs and computer-driven legs for fellow amputees.

The lab’s innovations have changed his life as well as the lives of many others. In fact, author Adam Piore is inclined to think Herr, along with a handful of other forward-thinkers from around the world, could bring an end to disability as we know it today.

“The amazing thing I found is that we finally have the power to reverse-engineer how humans work,” Piore told The Post. “Computers and medical technology have caught up to the point that we can look at things on the molecular level and hack the body.”

In his new book “The Body Builders: Inside the Science of the Engineered Human” (Ecco, out Tuesday), Piore explores things that, he admitted, “seem too implausible to be real.”

There’s the blind woman who learned to see with her ears, experimental science that can regrow fingertips, and even early stages of technology for deaf-mutes to communicate through a form of telepathy.

At the forefront of this movement is Herr, who was driven to get a masters in engineering from MIT and a PhD in biophysics from Harvard after his accident. Now, he proudly wears the self-designed high-tech prostheses. “Hugh likes to dress in a tuxedo [with] pants cut off at the knees, so he can show off his prosthetic legs,” Piore said.

Herr refers to his mechanical limbs —which help him out-climb people with flesh-and-blood body parts — as “wearable robots.”

“Someday soon, these kinds of devices will be no more unusual than a pair of glasses,” he says in “The Body Builders.”

Here is an up-close and detailed look at Herr’s amazing, self-designed prosthetic legs:

Shock absorbers

Originally, walking caused discomfort to the area below Herr’s knees, where his legs had been amputated and afterward attached to artificial rigs. “His prosthetic guy, inspired by shock absorbers he had seen in Vietnam, put in cushions for added comfort,” said Piore. “They’re made out of soft, flexible polyurethane membranes.”

Racecar technology

Carbon-fiber tops made from the same lightweight material as Formula 1 race-car chassis connect Herr to the socket of his prosthetic leg. “It is like slipping [your hand] inside a mitten,” said Dr. Charles Carignan, CEO of BionX, the company founded by Herr, which produces his legs. “A pin clicks into the socket that holds it [onto the leg].”

Walking tall

One advantage of being a double-amputee: no limit to your height. As Herr told a TED Talk audience, “I can be as short as 5 feet or as tall as I like.” Piore said that Herr analyzed horses’ gaits “to see how they . . . [gallop] in the air and keep from breaking their legs on the way down.” This influenced the degrees of stiffness in his own legs and the naturalness of the stride.

Take charge

Plastic-and-metal ankles hold the high-tech guts of the prosthesis, plus the lithium battery that must be recharged after eight or so hours of walking.

Missile-grade control

Sensors in the ankle continually analyze Herr’s walk. “They’re the same kinds of micro-processors used in guided missiles,” said Piore. Carignan added, “The sensors measure force-of-heel strike, torque and angle of step [to] determine how much power needs to be delivered from a motor that drives the propulsion.”

A foot for every need

The carbon fiber “feet” Herr wears day to day have treaded rubber bottoms, like on an athletic sandal. For this photo, said Carignan, “he added a rubber cosmesis which looks like a molded foot with toes. It . . . allows shoes to fit properly.” Herr opts for very small feet that fit into tiny crevices when rock-climbing; for scaling icy surfaces, he switches to spiked bottoms.