OBJを行走査して頂点数と三角形分割後の面数を事前計数する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | path |
走査対象のOBJファイルパス。 |
||
| integer(kind=i32), | intent(out) | :: | nvert |
頂点行 |
||
| integer(kind=i32), | intent(out) | :: | ntri |
頂点行 |
subroutine scan_obj(path, nvert, ntri) character(len=*), intent(in) :: path integer(i32), intent(out) :: nvert, ntri character(len=1024) :: line integer :: u, ios, ntok nvert = 0 ntri = 0 open (newunit=u, file=path, status='old', action='read', iostat=ios) if (ios /= 0) error stop "failed to open OBJ" do read (u, '(A)', iostat=ios) line if (ios /= 0) exit call strip_cr(line) if (is_vertex_line(line)) nvert = nvert + 1 if (is_face_line(line)) then ntok = count_face_tokens(line) if (ntok >= 3) ntri = ntri + (ntok - 2) end if end do close (u) end subroutine scan_obj