I've recently delved into the world of three.js.
My current goal involves creating a curve within the scene and subsequently applying some transformations to it. The function responsible for generating the line is showcased below:
var random_degree = Math.round(Math.rand() * 180);
var tmp = [
new THREE.Vector3(-5, 0, 0),
new THREE.Vector3(0, 0, 5),
new THREE.Vector3(5, 0, 0),
new THREE.Vector3(0, 0, -5),
];
var canvasW = window.innerWidth;
var canvasH = window.innerHeight;
// Initially, the curve forms a circle on the x-z plane.
function get_line_geo() {
var angle = (random_degree + 1 * 0.25) % 360 * (Math.PI / 180);
var tx = Math.cos(angle) * canvasW * 0.25;
angle = (random_degree + 1 * 0.3) % 360 * (Math.PI / 180);
var ty = Math.sin(angle) * canvasH * 0.25;
var curve = new THREE.CatmullRomCurve3(tmp);
curve.closed = true;
var geometry = new THREE.Geometry();
geometry.vertices = curve.getPoints(300);
console.log(geometry.vertices[0].x + ' ' +geometry.vertices[0].y + ' ' +geometry.vertices[0].z);
var material = new THREE.LineBasicMaterial();
var curveObject = new THREE.Line(geometry, material);
curveObject.translateX((canvasW - margin * 2) / 2 + tx);
curveObject.translateY((canvasH - margin * 2) / 2 + ty);
curveObject.translateZ((canvasH - margin * 2) / 2 + ty);
curveObject.rotation.x = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;
curveObject.rotation.y = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;
curveObject.rotation.z = ((random_degree + 1 * 0.25) % 360) * Math.PI / 180;
curveObject.scale.x = 10;
curveObject.scale.y = 10;
curveObject.scale.z = 10;
console.log(curveObject.geometry.vertices[0].x + ' ' +curveObject.geometry.vertices[0].y + ' ' +curveObject.geometry.vertices[0].z);
return curveObject;
}
Upon closer inspection using console.log()
, I noticed that the vertices' positions remained unchanged in the geometry context. Is there a method available to calculate new positions for these vertices?