Bruce Beasley needed a place to sculpt metal all day and crash at night when, in 1964, he bought the abandoned Sun Milling Co. factory in West Oakland for $12,000 and set up the shop that would help make him famous.

He built a second floor with a kitchen and bathroom, wired and plumbed the place, and lived there illegally for 20 years. After his abstract creations took off and were displayed around the world, he converted the factory — which once cranked out cereals called Wheatro and Nutro — into the impressive, and legal, live-work space it is today.

The ivy-covered building offers a window into the debate over what Oakland officials should do about warehouses around the city that are used as makeshift residences and sometimes event spaces without proper permits — like the one that burned in the Ghost Ship fire on Dec. 2, killing 36 people at an underground music show.

The tragedy didn’t happen in a vacuum. These old buildings — crumbling hulks that jut out like ghosts in many neighborhoods — are central figures in the unique story of Oakland, from its industrial past to its emergence as a refuge for artists seeking cheap housing and work space.

The question now, as city officials study whether to toughen building-code enforcement, is how this creative melding of old and new will evolve — safely. The Ghost Ship fire, which many say is a prime example of the danger of unregulated spaces, has left the future of the city’s eclectic artists community hanging in the balance.

“I just don’t know what’s going to happen with the creative community if they get kicked out of these places,” said Beasley, who calls the Ghost Ship an outlier, a labyrinth of electrical hazards where no responsible person would have held a concert. “Artists aren’t going to be able to afford to live in one place and work in another.”

Don Rich, a 68-year-old sculptor who legally lives and works in a restored carriage house on Third Street in West Oakland, said: “The whole glass revolution happened right here in Oakland in the late 1970s. That was because we had all these industrial buildings right here that we could just move into.”

Something like Beasley’s illegal conversion of 52 years ago might be impossible in the future if the city increases enforcement. And legal conversions of industrial buildings might price out artists who’ve accepted makeshift spaces because they’re cheap. Meanwhile, pot cultivation buoyed by legalization may be the next cycle for Oakland’s warehouses.

The dilemma is representative of a city in transition — again.

Oakland’s industrial past dates to the completion of the transcontinental railroad in 1869. The build-out began at the wharf, which was lined with cargo sheds, lumber and grain mills, canneries, and tanneries.

The city was second only to San Francisco as a transportation hub by the late 1800s, but really hit the big time after the 1906 earthquake and fire, which drove an exodus from San Francisco. And after the opening of the Panama Canal in 1914, Oakland’s port facilities were expanded to take on the increase in shipping.

It was 1910 when Sun Milling Co. opened. The 1911 book “Greater Oakland,” by Evarts Blake, described how owners L.J and M.W. Stoddard, sons of a California pioneer, produced Wheatro and Nutro in the 7,000-square-foot building. Both cereals, the book said, “are now recognized as standard articles.”

Numerous other factories and foundries opened as the port was built out during World War I. The growth continued during the Roaring Twenties as the auto and aviation industries grew. After a lull in the 1930s, warehouses and machine shops were built all over the city to support the World War II effort, with heavy emphasis on ship and aircraft manufacturing.

Then everything changed. Ships began carrying stackable containers of cargo, and suddenly many of Oakland’s warehouses weren’t needed.

By the 1970s, there were thousands of abandoned warehouses around the Bay Area. Many were torn down for new development, but a lot of the old behemoths lingered, including the Ghost Ship, which had been built in 1930 to store milk trucks and bottles and, later, metal piping. At this point, no one knows exactly how many dilapidated warehouses and factories are scattered through Oakland.

“There are many, many, many of those buildings,” said Naomi Schiff, a member of the Oakland Heritage Alliance Board of Directors. “There’s a lot of inherent value in those buildings. Many were built with good materials.”

Beasley’s elegantly renovated mill, complete with a sculpture garden, is an example of what can be done, but he had to buck the system. He fought for years to persuade the city to rezone his neighborhood and other industrial areas so artisans and entrepreneurs could convert warehouses and factories into residential space.

In 1996, he and architect Tom Dolan helped write Oakland’s live-work building code, creating a pathway for the restoration of abandoned buildings, a law that has become a model for other cities. It set ground rules for the kinds of conversions that have been going on in Oakland for years.

“It’s a way to use these buildings in a way that incubates small businesses,” said Dolan, a specialist in warehouse conversions and the author of a book on live-work spaces. “It’s a great way to combine living and working in this expensive economy and also not to have to commute and pollute.”

Among the buildings that have been converted is the old Dutch Boy Paint factory in East Oakland, where the bottoms of American warships were painted during the Second World War. The factory on San Leandro Boulevard has legally housed a community of artists since 1979.

Beasley retrofitted his warehouse after the Loma Prieta earthquake in 1989, bringing it up to code. But he doesn’t live there anymore and uses it instead as a guest house. He has since built a new home, along with a park-like garden where a junkyard once stood and two other work spaces, next to the factory building.

Recently, Beasley agreed to bequeath his studio complex at the restored mill to the Oakland Museum of California, which will name it the Bruce Beasley Sculpture Center.

“I saw this as a neighborhood and led the fight to get it rezoned,” said Beasley, as he walked through his sculpture garden. “There are hundreds of other situations like this — lots of derelict warehouses bought by artists — and they fill a need.”

In 1999, Beasley paid $40,000 for another wreck of a warehouse on Union Street in West Oakland, built in 1923 for the United Autograph Register Company. He and Dolan built 19 studios and an internal courtyard and kept the original architecture, including huge arching windows. It is now considered one of the live-work gems of Oakland.

“We have a citizenry around here that is very sensitive to historic buildings,” said John Protopappas, the developer of Lampwork Lofts, a renovated 1912 General Electric lightbulb factory. “A lot of folks object to the demolition of historic structures.”

But for every legal conversion, there may be several illegal ones. Dolan estimates that as many as 50 old Oakland warehouses are now occupied without permits.

The problem, Dolan said, is the cost of bringing buildings up to code. Besides construction costs and seismic retrofitting, live-work conversions generally require sprinklers, alarms, new windows, heating systems, soundproofing, fire escapes and proper exits. As a result, many owners of warehouses find themselves without tenants while still forking out money for maintenance and security.

“You might have a property owner who has a 50,000-square-foot warehouse and he doesn’t know what to do with it, and somebody comes along and says he wants to rent it,” Protopappas said. “Well, he’s got expenses, so the incentive is for him to say, ‘Wow, I’ll take it, but I don’t want to know anything about what you do in there.’”

That approach may describe the owner of the Ghost Ship, Chor Ng, who tenants have said collected rent and otherwise ignored the goings-on at her properties.

Beasley said legal live-work conversions can be done well and still be affordable for artists, as long as the city cooperates and the developer uses a utilitarian approach. The live-work units he converted at the Union Street warehouse rented for $700 to $1,200 a month before he sold the place seven years ago.

Prices have gone up since then, with single live-work units generally selling for $400,000 to $700,000.

According to online listings, there are about two dozen Oakland warehouses now listed for sale, ranging from giant industrial facilities to old body shops and garages — most of them at least 50 years old. Prices range from $550,000 to $5.5 million.

If vacant warehouses are a problem, there may be a solution dawning — but it won’t help many artists. James Anthony, a medical cannabis land-use lawyer, said derelict factories in Oakland have been used by growers for at least two years, and are likely to be snapped up faster than ever now that California has legalized recreational use of marijuana.

“One of the benefits of having a regulatory system is we will be able to take blighted substandard buildings and bring them up to code,” Anthony said.

The Dark Heart Nursery cultivates cannabis clones and strains in an Oakland warehouse. Jetty Extracts recently paid $3 million for a warehouse on 57th Avenue. A 200,000-square-foot plant on San Leandro Boulevard, built in 1929 to manufacture cans, was also bought recently by cannabis cultivators, according to a local Realtor.

And Oakland’s evolution as a destination for the avant-garde continues. Land-use experts say the cost of warehouse space has doubled in the past two years — an ominous sign for artists.

“It’s the classic thing about art,” Beasley said. “We make things better, we make them nicer, and then we get squeezed out.”

Peter Fimrite is a San Francisco Chronicle staff writer. Email: pfimrite@sfchronicle.com Twitter: @pfimrite