19#include <fmt/format.h>
34 size_t buffer_chunk_size_;
37 FormatHandler(
size_t buffer_chunk_size = 64 * 1024) : buffer_chunk_size_(buffer_chunk_size) {}
42 for (
const auto &
b : blocks_) {
43 fwrite(
b.data(), 1,
b.size(), f);
51 for (
const auto &
b : blocks_) {
52 s.append(
b.data(),
b.size());
58 return blocks_.size();
63 blocks_.insert(blocks_.end(),
64 std::make_move_iterator(
v.blocks_.begin()),
65 std::make_move_iterator(
v.blocks_.end()));
71 write_impl(
"v {:.6f} {:.6f} {:.6f}\n",
x,
y,
z);
75 write_impl(
"v {:.6f} {:.6f} {:.6f} {:.4f} {:.4f} {:.4f}\n",
x,
y,
z, r, g,
b);
79 write_impl(
"vt {:.6f} {:.6f}\n",
x,
y);
83 write_impl(
"vn {:.4f} {:.4f} {:.4f}\n",
x,
y,
z);
95 write_impl(
" {}/{}/{}",
v, uv, n);
99 write_impl(
" {}//{}",
v, n);
103 write_impl(
" {}/{}",
v, uv);
107 write_impl(
" {}",
v);
111 write_impl(
"usemtl {}\n", s);
115 write_impl(
"mtllib {}\n", s);
119 write_impl(
"s {}\n", s);
123 write_impl(
"g {}\n", s);
127 write_impl(
"o {}\n", s);
131 write_impl(
"l {} {}\n", a,
b);
135 write_impl(
"cstype bspline\n");
139 write_impl(
"deg {}\n",
deg);
151 write_impl(
"parm u");
155 write_impl(
" {:.6f}",
v);
172 write_impl(
"newmtl {}\n", s);
176 write_impl(
"{} {:.6f}\n", type,
v);
180 write_impl(
"{} {:.6f} {:.6f} {:.6f}\n", type, r, g,
b);
184 write_impl(
"illum {}\n", mode);
189 write_impl(
"{}{} {}\n", type,
options, value);
194 write_impl(
"{}\n", s);
200 void ensure_space(
size_t at_least)
202 if (blocks_.
is_empty() || (blocks_.
last().capacity() - blocks_.
last().size() < at_least)) {
203 blocks_.
append(VectorChar());
204 blocks_.
last().reserve(std::max(at_least, buffer_chunk_size_));
208 template<
typename...
T>
void write_impl(fmt::format_string<T...> fmt,
T &&...args)
211 fmt::memory_buffer buf;
212 fmt::format_to(fmt::appender(buf), fmt, std::forward<T>(args)...);
213 size_t len = buf.size();
215 VectorChar &bb = blocks_.
last();
216 bb.insert(bb.end(), buf.begin(), buf.end());
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
void append(const T &value)
const T & last(const int64_t n=0) const
CCL_NAMESPACE_BEGIN struct Options options