BILLUND, Denmark — At the heart of this town lies a building that is a veritable temple to the area’s most famous creation, the humble Lego brick. It is filled with complex creations, from a 50-foot tree to a collection of multicolored dinosaurs, all of them built with a product that has barely changed in more than 50 years.

A short walk away in its research lab, though, Lego is trying to refashion the product it is best known for: It wants to eliminate its dependence on petroleum-based plastics and build its toys entirely from plant-based or recycled materials by 2030.

The challenge is designing blocks that click together yet separate easily, retain bright colors and survive the rigors of being put through a laundry load or the weight of an unknowing parent’s foot. In essence, the company wants to switch the ingredients but keep the product exactly the same.

“We need to learn again how to do this,” said Henrik Ostergaard Nielsen, a production supervisor at Lego’s factory in Billund.

MBA BY THE BAY: See how an MBA could change your life with SFGATE's interactive directory of Bay Area programs.

With growing concern about the impact of plastic waste on the environment, companies are trying to use packaging materials that are recyclable or otherwise less polluting. Coca-Cola, for instance, plans to collect and recycle the equivalent of all the bottles and cans it uses by 2030. Unilever says all its plastic packaging will be recyclable or compostable by 2025. McDonald’s, Starbucks and Disney are doing away with plastic straws.

With so many large businesses changing their practices, recycling will “become the norm,” said David Blanchard, Unilever’s head of research and development.

Lego faces a more complex problem than other consumer businesses, though — for this Danish company, plastics are not the packaging, they are the product.

The toymaker’s highly automated manufacturing facility is a picture of clockwork. At a mammoth factory more than 500 yards long, machines arranged in rows melt plastic pellets into a molten paste and press them into molds. A few seconds later, a batch of colored bricks pops out and is deposited into driverless carts, taken to be stored for shipment. Each day, the facility churns out about 100 million “elements,” the term Lego uses for its bricks, trees and doll parts.

Lego — the name is a contraction of the Danish words for “play well” — traces its roots to the early 1930s, when a carpenter named Ole Kirk Kristiansen began making and selling fire engines and other wooden toys.

By the 1950s, he was experimenting with plastic bricks. His son Godtfred began marketing the distinctive little blocks not just as toys, but as a building system that could be expanded and passed on to later generations. Bricks that date to 1958 are still compatible with current products, according to Lego.

Today, the company sells its wares worldwide and has secured partnerships with film franchises like Batman and “Star Wars” to market not just themed brick sets, but also movies and video games featuring Lego toys. It brought in about $1.2 billion in profit last year, making it larger than Mattel and Hasbro. The Kirk Kristiansen family, which still controls Lego, was paid a $1.1 billion dividend.

Lego said Tuesday that its revenue dipped in the first half of 2018, with business in North America hurt by changes in the retail industry, including the bankruptcy of store chain Toys R Us.

Revenue fell 5 percent to $2.2 billion in the January-June period, compared with a year earlier. Profit dropped 10 percent to $467 million. The company also blamed the weakening of the dollar. At constant currency rates, it said sales were stable.

Revenue growth in Western Europe was in the low single digits, while it declined slightly in North America. China revenue grew by double digits.

CEO Niels Christiansen said Tuesday that the plan “is to stabilize the business” and said the results “show we’re on track.”

The company does not release quarterly figures.

But with more and more children using mobile devices for entertainment, Lego must compete with technology and gaming companies like Activision Blizzard, Microsoft and Sony as well as other toymakers. That has put the company under pressure. Lego said last year that it would cut 1,400 jobs after its revenue and profit both fell for the first time in a decade.

Lego emits about 1 million tons of carbon dioxide each year, about three-quarters of which comes from the raw materials that go into its factories, according to Tim Brooks, the company’s vice president for environmental responsibility.

It is taking a two-pronged approach to reducing the amount of pollution it causes. It wants to keep all of its packaging out of landfills by 2025 by eliminating things like plastic bags inside its cardboard packaging.

It is also pushing for the plastic in its toys to come from sources like plant fibers or recycled bottles by 2030.

However, virtually all of the plastic used worldwide — including that molded by Lego into toy bricks — is created from petroleum.

Lego mostly uses a substance known as ABS, short for acrylonitrile butadiene styrene, a common plastic also used for computer keys and mobile phone cases. It’s tough, yet slightly elastic, and has a polished surface.

To wean itself off products like ABS, Lego has begun an exhaustive search for new, sustainable materials.

It is making substantial investments and hiring about 100 people to work on these changes. Technicians methodically test promising materials to see whether they can take a whack without breaking, or survive a hard pull. They are checked to see whether they withstand the heat of a Saudi Arabian summer, and take on the bright color palette that Lego bricks are famous for. The bricks may look simple, but they are made with precision.

“We look at how does it look, and how does it feel,” said Nelleke van der Puil, Lego’s vice president for materials.

Lego is also already using polyethylene made from sugar-cane husks in flexible pieces like dragon wings, palm trees and fishing rods, but these constitute only 1 to 2 percent of its products, and the material is too soft for the toy blocks.

Some bricks made with new materials have broken, leaving sharp edges that could injure a child, or have popped out with ugly, muddied colors. Others have on occasion produced misshapen or pockmarked bricks.

The search for a substitute for petroleum-based plastic could yet take years, Brooks acknowledged. But executives argue that, as a company that models itself as an educator as much as a profitable enterprise, it has little option but to keep trying.

“It is important,” said Brooks, “that we can make a toy that doesn’t jeopardize” children’s future.

The Associated Press contributed to this report.

Stanley Reed is a New York Times writer.