0

generate a circle by points

let arc = new THREE.ArcCurve(0, 0, 200, 0, 2 * Math.PI, true);
let points = arc.getPoints(50);
let geometry = new THREE.BufferGeometry().setFromPoints(points);
geometry.attributes.position.needsUpdate = true;
let material = new THREE.LineBasicMaterial({ color: 0x00ff00 });
let circle = new THREE.Line(geometry, material);

do some translate

circle.translateX(100);
circle.translateY(100);
circle.translateZ(100);
circle.rotation.y = Math.PI / 2;
scene.add(circle);

and now, i want to get points from Mesh circle

1.i can't find function from mesh to get points

2.i have tried to see circle.geometry.getAttribute('position').array and i write i float32ArrayToVector3Array like this

const float32ArrayToVector3Array = (arr: any) => {
  let _arr: THREE.Vector3[] = [];
  for (let i = 0; i < arr.length; i += 3) {
    _arr.push(new THREE.Vector3(arr[i], arr[i + 1], arr[i + 2]));
  }
  return _arr;
};

but circle.geometry.getAttribute('position').array seem like is not newest points

so i want to know how to get points from Mesh

1 Answer 1

3

.translateX doesn't change vertices, it changes mesh's matrix.

To get coordinates in world space, try this:

let gp = mesh.geometry.attributes.position;
let wPos = [];
for(let i = 0;i < gp.count; i++){
    let p = new THREE.Vector3().fromBufferAttribute(gp, i); // set p from `position`
    mesh.localToWorld(p); // p has wordl coords
    wPos.push(p);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.