You could hardly hope for a more colorful and tender cultural history lesson than “Hugo,” Martin Scorsese’s love letter to childhood, Paris and the early days of cinema.

Scorsese has always had a roving, restless camera eye; generally it’s trained at Mafiosi doing dreadful things with baseball bats. Working for the first time in whimsical fantasy frees him to send us floating high above the Arc de Triomphe, then zooming through the rafters of an old train station, in 3-D no less. Scorsese wields his new technical toys with breathtaking energy. It’s hard not to be swept along with his excitement.

“Hugo” is set in a once-upon-a-time era after World War I. The title character (Asa Butterfield of “Nanny McPhee Returns”) is a resourceful orphan who lives in the walls of the station, tending to the clocks and evading his nemesis, the stern policeman (Sacha Baron Cohen) who patrols the place. Hugo’s father (Jude Law) was a clockmaker who bequeathed his boy a mechanical man with many gears and relays missing. The boy’s quest to repair the automaton requires that he leave the safety of his hiding place. When he attempts to filch a wind-up runabout mouse from the station’s toy seller, Monsieur Georges (Ben Kingsley), he opens the door to a secret that reaches back to the infant days of cinema.

Scorsese tells his tale as if he were a doting uncle with the audience on his knee. The director is, of course, a notable film historian and preservationist, and much of the fun here is seeing how he can take cues from old beloved films and spark them to life for today’s audiences. Cohen, playing a war veteran with a balky leg brace, gets the worst of it in several chases that Jerry Lewis would applaud. There’s a staircase pursuit from “Vertigo,” a clock tower dangle borrowed from Harold Lloyd, and enough references to other classics for a rousing game of Homage Bingo. Yet the dreamlike power of films is such that the old tricks amaze and delight us anew.

This being Paris, there must be love stories, and the film piles them on thick and sweet. There’s the warming friendship between Hugo and his clever accomplice Isabelle (Chloe Grace Moretz); the comic courtship between Cohen’s decidedly nonromantic Frenchman and a sweet flower seller (Emily Mortimer), and a December-December flirtation between a portly violinist (Richard Griffiths) and a cafe owner (endearingly homely Frances de la Tour). There’s also the long, sweet partnership of Georges and his Jeanne (Helen McCrory).

Above all, there’s Scorsese’s mad infatuation with films and filmmaking. The way he incorporates snippets of antique film, tributes to the mesmerizing power of illusion, and little lectures on cinema history is nothing less than captivating. It’s wonderful to think how young viewers of this film will react to incorporated footage from the 1902 “A Trip to the Moon,” in which a rocket ship hits the Man in the Moon squarely in the eye.

The screenplay by John Logan (“Gladiator,” “Rango”) is a bit top-heavy with story in the first half, and Butterfield, a splendid camera object, isn’t quite up to the very heaviest emotional moments. Still this is the rarest sort of film, one from the heart of a great artist. For all its focus on precisely machined gears and clockwork construction, “Hugo” flows.