OBJの頂点/面行を解析し、負インデックス対応で配列へ格納する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | path |
読み込み対象のOBJファイルパス。 |
||
| real(kind=dp), | intent(out) | :: | vertices(:,:) | |||
| integer(kind=i32), | intent(out) | :: | faces(:,:) |
subroutine parse_obj(path, vertices, faces) character(len=*), intent(in) :: path real(dp), intent(out) :: vertices(:, :) integer(i32), intent(out) :: faces(:, :) character(len=1024) :: line integer :: u, ios, i integer(i32) :: iv, itri, ntok, idx(512) iv = 0 itri = 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)) then iv = iv + 1 call parse_vertex_line(line, vertices(:, iv)) else if (is_face_line(line)) then call parse_face_line(line, iv, idx, ntok) if (ntok >= 3) then do i = 2, ntok - 1 itri = itri + 1 faces(:, itri) = [idx(1), idx(i), idx(i + 1)] end do end if end if end do close (u) end subroutine parse_obj