The easiest way to create a plane is, of course, to create a plane in the Editor:
The problem here is: how do you rotate the plane such that the points you specify lie in that plane? Well, you can:
- Calculate the normal of the plane defined by those 4 points.
- Figure out the quaternion that rotates [0, 1, 0] (the default plane normal) to the normal of your plane.
Alternatively, you can create a plane from the 4 points in code, using the pc.createMesh function. So something like:
var mesh = pc.createMesh(
[ x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4 ],
normals: [ nx, ny, nz, nx, ny, nz, nx, ny, nz, nx, ny, nz ],
uvs: [ 0, 0, 0, 1, 1, 1, 1, 0 ],
indices: [ 0, 1, 2, 0, 2, 3 ]
Notice the normal is the same for each vertex, as you’d expect. Let’s say your vertices are v1, v2, v3, v4. The normal is (v2 - v1) cross (v4 - v1)
… where ‘cross’ is a cross product operation.
A much more complex example app showing how to create a mesh from a bunch of points is the terrain example.