Hello. I have an FBX model and loading it is ok but when I use vertices to add points on each vertex they appear somewhere different. It works ok with GLB models but every FBX model dots load with some offset.
Here is my code:
let pointsGeo = new THREE.BufferGeometry();
const vertices = [];
const indecies = [];
const vertex = new THREE.Vector3();
const positionAttribute = model.geometry.getAttribute('position');
for (let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex++) {
vertex.fromBufferAttribute(positionAttribute, vertexIndex);
vertices.push(vertex.x, vertex.y, vertex.z);
indecies.push(vertexIndex);
verticesCnt++;
}
pointsGeo.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
pointsGeo.setAttribute('index', new THREE.Float32BufferAttribute(indecies, 3));
let textureLoader = new THREE.TextureLoader();
let sprite = textureLoader.load(`/images/1.png`);
let pointOpacity = Math.min(Math.max(500 / verticesCnt, 0.12), 1);;
const pointsMaterial = new THREE.PointsMaterial({
size: 18, // / (window.devicePixelRatio || 1),
sizeAttenuation: false,
map: sprite,
transparent: true,
opacity: pointOpacity,
blending: THREE.NormalBlending
});
pointsMaterial.color.setRGB(.5, 1.0, .5)
// pointsMaterial.color.setRGB(1, 1, 1);
let points = new THREE.Points(pointsGeo, pointsMaterial);
points.geometry.attributes.position.needsUpdate = true;
points.position.set(0, 0, 0);
points.rotation.set(0, 0, 0);
wireframeModel.add(points);
This is my loader code:
const loader = new FBXLoader();
loader.load(url, function(object) {
object.traverse(function(child) {
if (child.isMesh) {
console.log(child);
model = child;
model.scale.set(1, 1, 1);
model.position.set(0, 1, 0);
scene.add(model);
modelAddLayers(model);
}
});
Can anyone tell me what is happening? I tried many things, updating matrix world and other things.