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

162
Visualizações
Objeto de escala ThreeJs relativo a otro objeto

Estoy usando threejs para renderizar algunos modelos (gltf/glb). Todos ellos son de diferentes tamaños, algunos son grandes y otros son pequeños. Ahora quiero escalarlos todos al mismo tamaño.

si uso mesh.scale() eso escalaría el objeto en relación con su propio tamaño. ¿Hay alguna forma de lograr esto sin calcular manualmente la escala de cada modelo?

ACTUALIZAR:

Aquí está mi código

 function loadModels(points) { // loader const loader = new GLTFLoader(); const dl = new DRACOLoader(); dl.setDecoderPath("/scripts/decoder/"); loader.setDRACOLoader(dl); let lengthRatios; const meshes = []; for (let i = 0; i < store.length; i++) { loader.load( store[i].model, (gltf) => { const mesh = gltf.scene; const meshBounds = new THREE.Box3().setFromObject(mesh); // Calculate side lengths of model1 const lengthMeshBounds = { x: Math.abs(meshBounds.max.x - meshBounds.min.x), y: Math.abs(meshBounds.max.y - meshBounds.min.y), z: Math.abs(meshBounds.max.z - meshBounds.min.z), }; if (lengthRatios) { lengthRatios = [ lengthRatios[0] / lengthMeshBounds.x, lengthRatios[1] / lengthMeshBounds.y, lengthRatios[2] / lengthMeshBounds.z, ]; } else { lengthRatios = [ lengthMeshBounds.x, lengthMeshBounds.y, lengthMeshBounds.z, ]; } meshes.push(mesh); if (meshes.length == store.length) { addModels(); } }, (xhr) => { console.log((xhr.loaded / xhr.total) * 100 + "% loaded"); }, (error) => { console.log("An error happened"); } ); } function addModels() { // Select smallest ratio in order to contain the models within the scene const minRation = Math.min(...lengthRatios); for (let i = 0; i < meshes.length; i++) { // Use smallest ratio to scale the model meshes[i].scale.set(minRation, minRation, minRation); // position the model/mesh meshes[i].position.set(...points[i]); // add it to the scene scene.add(meshes[i]); } } }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Debe crear un cuadro delimitador alrededor de cada modelo.

 //Creating the actual bounding boxes mesh1Bounds = new THREE.Box3().setFromObject( model1 ); mesh2Bounds = new THREE.Box3().setFromObject( model2 ); // Calculate side lengths of model1 let lengthMesh1Bounds = { x: Math.abs(mesh1Bounds.max.x - mesh1Bounds.min.x), y: Math.abs(mesh1Bounds.max.y - mesh1Bounds.min.y), z: Math.abs(mesh1Bounds.max.z - mesh1Bounds.min.z), }; // Calculate side lengths of model2 let lengthMesh2Bounds = { x: Math.abs(mesh2Bounds.max.x - mesh2Bounds.min.x), y: Math.abs(mesh2Bounds.max.y - mesh2Bounds.min.y), z: Math.abs(mesh2Bounds.max.z - mesh2Bounds.min.z), }; // Calculate length ratios let lengthRatios = [ (lengthMesh1Bounds.x / lengthMesh2Bounds.x), (lengthMesh1Bounds.y / lengthMesh2Bounds.y), (lengthMesh1Bounds.z / lengthMesh2Bounds.z), ]; // Select smallest ratio in order to contain the models within the scene let minRatio = Math.min(...lengthRatios); // Use smallest ratio to scale the model model.scale.set(minRatio, minRatio, minRatio);
about 4 years ago · Juan Pablo Isaza Relatório
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