Hey guys, how are you doing? I am working with particles and MeshSurfaceSampler.
I am trying to create a particle geometry from a model, and it’s all good but the problem is that the model can’t change its sizes. When I add it to the scene it shows me the gltf model with the correct size, but in the sampler it is still using its old sizes (like in the picture), so I think the problem is matrix related. Can you guys help me to figure it out?
Please, if someone can help me, i would be really grateful. Sorry for my english.
function createSamplerFromModel() {
const loader = new GLTFLoader();
loader.load(
'/man.glb',
function (gltf) {
const model = gltf.scene.children[0];
model.position.set(0, 0, 0);
model.scale.set(7, 7, 7);
model.matrix.makeScale( 7, 7, 7 );
model.updateMatrix()
const sampler = new MeshSurfaceSampler(model).build();
const tempPosition = new THREE.Vector3();
const vertices = [];
for (let i = 0; i < 10000; i++) {
sampler.sample(tempPosition);
vertices.push(tempPosition.x, tempPosition.y, tempPosition.z);
}
const pointsGeometry = new THREE.BufferGeometry();
pointsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
const pointsMaterial = new THREE.PointsMaterial({
color: 0xff61d5,
size: 0.001
});
const points = new THREE.Points(pointsGeometry, pointsMaterial);
scene.add(points);
},
function (xhr) {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
function (error) {
console.log('An error happened');
console.log(error);
}
);
}