Answer: It came to him in a dream
I know most science fiction films these days are from Philip K. Dick stories, but not this one. Cameron was in Venice with a fever when the idea came to him in a dream. He dreamt about a robot exo-skeleton rising from the flames, which became one of the classic scenes in the movie. If you're wondering about the Philip K. Dick films, they are "Screamers", "Blade Runner", "Total Recall", "Minority Report" and I think that his book "Ubik" was the inspiration behind "Vanilla Sky".