Your midpoint should be an average of all 3 verts:
midx = (vx1+vx2+vx3) / 3
midy = (vy1+vy2+vy3) / 3
midz = (vz1+vz2+vz3) / 3
Delete the mesh, and recreate the old 3 verts (v1,v2,v3) and the new midpoint vert (v4) using midx,midy,midz
Then create the new tris using this vert order:
tri1 v1,v2,v4
tri2 v2,v3,v4
tri3 v3,v1,v4
Tom
midx = (vx1+vx2+vx3) / 3
midy = (vy1+vy2+vy3) / 3
midz = (vz1+vz2+vz3) / 3
Delete the mesh, and recreate the old 3 verts (v1,v2,v3) and the new midpoint vert (v4) using midx,midy,midz
Then create the new tris using this vert order:
tri1 v1,v2,v4
tri2 v2,v3,v4
tri3 v3,v1,v4
Tom