Rotate extruded geometry/mesh around local axis

Hello :slight_smile:

I have an array of lines and I want to extrude a geometry along these line axes.

Now I want to roate the single meshes around their own /local z-axis, but it rotates all the meshes around the global one.

var ipeShape = ProfilLibrary.IPEShapes[5];

for (let i = 0; i < columns.length; i++) {
	var colMesh = MemberViz.visualizeBar(columns[i], ipeShape);

	colMesh.rotation.z = Math.PI/2;
	scene.add( colMesh );					
}

function visualizeBar (bar, shape) {

	const path = new THREE.CatmullRomCurve3( [
		bar.start,
		bar.end
	] );

	const extrudeSettings = {
		steps: 2,
		// depth: bar.distance(),
		bevelEnabled: false,
		bevelThickness: 0,
		bevelSize: 0,
		bevelOffset: 0,
		bevelSegments: 0,
		extrudePath: path
	};
	
	const material = new THREE.MeshBasicMaterial( { color: 0x7bb0db, side: THREE.DoubleSide } );
	material.opacity = 0.7;
	material.transparent = true;
	// material.wireframe = true;

	const geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
	const mesh = new THREE.Mesh( geometry, material ) ;

	return mesh;
}

This is what I get:

I tried every possible rotation method I had in mind.
Could some help me out?
By the way I changed the default axis settings:

THREE.Object3D.DefaultUp.set(0, 0, 1);

My foremost advice is: reduce the problem’s complexity to a rotation of just a single mesh. Hint: any type of mesh will do - it doesn’t have to be the result of an extrusion. Then please describe, which result you want to achieve. A little sketch of the desired result would be ideal. Include the intended axis of rotation.

1 Like

Thanks for your answer @vielzutun.ch !
Before I posted this question I tried to simplify it and because it worked for a single mesh I thought maybe the loop or the extrusion may cause the problem.

Anyway, I simplified it in this little fiddle for a simpler example:

I want to achieve to rotate the extrusion around its own/local z-axis.
2

Because the documentation says for rotateZ: “Rotates the object around z axis in local space.”.

I though this would be right method.
And rotating the shape before extruding it, is not possible as far as I know

In a generic case the intended axis of rotation at the center of the mesh does not coincide with the world z-axis, like your sketch indicates. You need to

  1. translate the mesh by an x,y amount such that the mesh’s intended axis of rotation does coincide with the world z-axis.
  2. Rotate as desired.
  3. Revert the translation of step 1.

If you have an array of meshes, steps 1 and 3 have to be performed individually for each single mesh.

For better understanding of what’s going on, I also recommend interrupting the above three-step procedure after each step in order to view (and understand), what you have achieved so far.