I want to create a ExtrudeGeometry
on an arbitrary plane with a particular shape on the plane along the plane’s normal direction. Referring to the screenshot as the example, the green triangle is the plane and the yellow geometry is the ExtrudeGeometry
I wish to create. What I have is the vertical projection of their boundary vertices on the ground (the red triangle for the plane and the blue rectangle for the shape). I also know the vertex positions of the actual plane (the green triangle). So to create the ExtrudeGeometry
, I am taking these steps:
- Project the shape’s vertices vertically upward onto the plane
- Make the rotation matrix using green triangle’s edge as the rotation axis and apply on the projected shape’s vertices so they become horizontal
- This is necessary because I cannot just make
Vector2
with thex
&z
of the shape’s vertices (that would be the ground projected shape instead of the actual shape on the plane). Maybe there’s a better way to to this?
- Calculate the center of the rotated shape’s vertices and sub each vertex with the center. Now the shape is centered at origin.
- Create extrude shape with
x
&z
coords of the shape’s vertices and the extrude geometry.
→ 5. Rotate the extrude mesh (negative or positive 90deg?). Translate the mesh with distance of shape on plane’s center subtract origin. Make quaternion with up vector and plane’s normal and apply to the mesh. As you can see in the first screenshot, I kind of get it working. But once the plane’s facing direction changes, things do not work properly (screenshot 2).