Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Adding instanced mesh react fiber threejs

I'm making a project where I need to generate pretty huge map. I need to generate a lot of ground blocks with trees or rocks, kinda similar to minecraft (each block must be clickable). But I have a problem with optimization. I tried cutting render distance, adding fog, and playing with three instances (I'm using threejs fiber library for react). Could anyone help me explain how instances work and tell me how to apply them to my project? Hre's the code to generate it in normal way, without instancing.

import React, { Suspense } from "react";
import { useEffect, useState } from "react";
import Box from "./Box";
export default function Ground({
  layout,
  selectBox,
  selectedBox,
  position,
}) {
  const [boxArray, setBoxArray] = useState([]);
  const size = 20;
  let id = 0;
  useEffect(() => {
    const boxArrayCopy = [];
    for (let i = -(size / 2); i < size / 2; i++) {
      let hasTree = Math.random() > 0.99;
      for (let j = -(size / 2); j < size / 2; j++) {
        const layoutObject = layout.filter(
          (layoutObject) => layoutObject.x === i && layoutObject.y === j
        );
        const box = (
          <Box
            key={id}
            coords={{ x: j * 5, y: 0, z: i * 5 }}
            color={layoutObject.length > 0 ? layoutObject[0].color : 0x61892f}
            selectBox={selectBox}
            selectedBox={selectedBox}
            hasTree={hasTree}
            hasStone={Math.random() < 0.2}
            // just a random condition to add tree to box
          />
        );
        boxArrayCopy.push(box);
        id++;
        if (hasTree) hasTree = Math.random() > 0.5;
      }
      setBoxArray([...boxArrayCopy]);
    }
    console.log("GROUND DONE");
  }, []);
  return (
    <group position={position ?? [0, 0, 0]}>
      <Suspense fallback={null}>{boxArray}</Suspense>
    </group>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!