Can't scale a custom model in three js

when i scale the custom model it works , but its not effecting when it comes with particles. if you see this video you can understand waht i am saying .

see this

const sphereGeometry = new THREE.SphereGeometry(0.5, 16, 16);
    const particles = [];
    const originalPositions = [];
    const originalMaterials = [];
    const highlightMaterial = new THREE.MeshStandardMaterial({ color: 0x00ff00 });




    loader.load('/mesh3.glb', (gltf) => {
      const model = gltf.scene;
      model.scale.set(0.5,0.5,0.5);
      model.position.set(0,-0.5,0)
      scene.add(model)
      if (model) {
        model.traverse((child) => {
          if (child.isMesh) {
            const vertices = child.geometry.attributes.position;
            for (let i = 0; i < vertices.count; i++) {
              const x = vertices.getX(i);
              const y = vertices.getY(i);
              const z = vertices.getZ(i);

              const particle = new THREE.Mesh(sphereGeometry, new THREE.MeshStandardMaterial());
              particle.position.set(x, y, z);
              particles.push(particle);
              originalPositions.push(new THREE.Vector3(x, y, z));
              originalMaterials.push(particle.material.clone());
            }
          }
        });
        scene.add(...particles);
      }
    });

Could you try adding one line (the line with localToWorld) right after setting particle position:

particle.position.set(x, y, z);
particle.position.copy(child.localToWorld(particle.position)); // add this line
particles.push(particle);

thank you . very helpful

1 Like