Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda