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=:), allocatable :: line integer :: u, ios, i integer(i32) :: iv, itri integer(i32), allocatable :: idx(:) 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 call read_obj_line(u, line, ios) if (ios /= 0) exit 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) do i = 2, size(idx) - 1 itri = itri + 1 faces(:, itri) = [idx(1), idx(i), idx(i + 1)] end do end if end do close (u) end subroutine parse_obj