17#include <fmt/format.h>
32 size_t buffer_chunk_size_;
35 FormatHandler(
size_t buffer_chunk_size = 64 * 1024) : buffer_chunk_size_(buffer_chunk_size) {}
40 for (
const auto &
b : blocks_) {
41 fwrite(
b.data(), 1,
b.size(), f);
49 for (
const auto &
b : blocks_) {
50 s.append(
b.data(),
b.size());
56 return blocks_.size();
61 blocks_.insert(blocks_.end(),
62 std::make_move_iterator(
v.blocks_.begin()),
63 std::make_move_iterator(
v.blocks_.end()));
69 write_impl(
"v {:.6f} {:.6f} {:.6f}\n",
x,
y,
z);
73 write_impl(
"v {:.6f} {:.6f} {:.6f} {:.4f} {:.4f} {:.4f}\n",
x,
y,
z, r, g,
b);
77 write_impl(
"vt {:.6f} {:.6f}\n",
x,
y);
81 write_impl(
"vn {:.4f} {:.4f} {:.4f}\n",
x,
y,
z);
93 write_impl(
" {}/{}/{}",
v, uv, n);
97 write_impl(
" {}//{}",
v, n);
101 write_impl(
" {}/{}",
v, uv);
105 write_impl(
" {}",
v);
109 write_impl(
"usemtl {}\n", s);
113 write_impl(
"mtllib {}\n", s);
117 write_impl(
"s {}\n", s);
121 write_impl(
"g {}\n", s);
125 write_impl(
"o {}\n", s);
129 write_impl(
"l {} {}\n", a,
b);
133 write_impl(
"cstype bspline\n");
137 write_impl(
"deg {}\n",
deg);
149 write_impl(
"parm u");
153 write_impl(
" {:.6f}",
v);
170 write_impl(
"newmtl {}\n", s);
174 write_impl(
"{} {:.6f}\n", type,
v);
178 write_impl(
"{} {:.6f} {:.6f} {:.6f}\n", type, r, g,
b);
182 write_impl(
"illum {}\n", mode);
187 write_impl(
"{}{} {}\n", type,
options, value);
192 write_impl(
"{}\n", s);
198 void ensure_space(
size_t at_least)
200 if (blocks_.
is_empty() || (blocks_.
last().capacity() - blocks_.
last().size() < at_least)) {
201 blocks_.
append(VectorChar());
202 blocks_.
last().reserve(std::max(at_least, buffer_chunk_size_));
206 template<
typename...
T>
void write_impl(fmt::format_string<T...> fmt,
T &&...args)
209 fmt::memory_buffer buf;
210 fmt::format_to(fmt::appender(buf), fmt, std::forward<T>(args)...);
211 size_t len = buf.size();
213 VectorChar &bb = blocks_.
last();
214 bb.insert(bb.end(), buf.begin(), buf.end());
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
void append(const T &value)
const T & last(const int64_t n=0) const
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
CCL_NAMESPACE_BEGIN struct Options options
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ATTR_WARN_UNUSED_RESULT const BMVert * v