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

89
Visualizações
2D bounding rect from a mesh

I'm trying to figure out how to get the rect coords of a mesh for 2D projection.

I need X, Y, Width and Height.

After reading many SO posts and various blogs, it seems like none of them work with latest modern Three.JS and the documentation doesn't have a function for it.

How is this achieved?

Currently, I'm looking at using a Box3 and then project the Box3 to screen.

UPDATE My code looks like this

rect(mesh, camera, w, h){
        var bbox = new THREE.Box3().setFromObject(mesh);
        bbox.min.setFromMatrixPosition(mesh.matrixWorld);
        bbox.max.setFromMatrixPosition(mesh.matrixWorld);
        bbox = {
            min: bbox.min.project(camera),
            max: bbox.max.project(camera)
        }

        var to2D = which => {
            bbox[which] = {
                x: (bbox[which].x + 1) * w / 2,
                y: -(bbox[which].y - 1) * h / 2
            }
        }
        
        to2D('min')
        to2D('max')


        return {
            x: bbox.min.x,
            y: bbox.min.y,
            w: bbox.max.x - bbox.min.x,
            h: bbox.max.y - bbox.min.y
        }
    }

    return rect
}

The output is basically a single point with no rect width/height.

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