30 #ifndef EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_ 31 #define EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_ 33 #define MSGPACK_USE_DEFINE_MAP 36 #include <msgpack.hpp> 44 #if (MSGPACK_VERSION_MAJOR >= 2) 50 #define MSGPACK_FEATURE_NOT_SUPPORTED 55 namespace visualization
57 inline long RGB(
double R,
double G,
double B)
59 return static_cast<long>(std::min(std::max(R, 0.0), 1.0) * 255) * 65536L + static_cast<long>(std::min(std::max(G, 0.0), 1.0) * 255) * 256L + static_cast<long>(std::min(std::max(B, 0.0), 1.0) * 255);
64 std::random_device rd;
65 std::mt19937 gen(rd());
66 std::uniform_int_distribution<> dis(0, 255);
67 return static_cast<unsigned char>(dis(gen));
73 for (
auto i = 0; i < len; ++i)
76 std::stringstream hexstream;
77 hexstream << std::hex << int(rc);
78 auto hex = hexstream.str();
79 ss << (hex.length() < 2 ?
'0' + hex : hex);
92 Base(
const std::string& type_in,
const std::string& path_in) :
type(type_in),
path(path_in){};
101 Property(
const std::string& path_in,
const std::string& property_in,
const T& value_in) :
Base(
"set_property", path_in), property(property_in), value(value_in){};
102 std::string property;
104 MSGPACK_DEFINE(
type,
path, property, value);
113 MSGPACK_DEFINE(version, type);
118 Material(
long color_in,
double opacity_in = 1.0,
const std::string& type_in =
"MeshPhongMaterial",
const std::string& uuid_in =
"") : color(color_in), opacity(opacity_in), uuid(uuid_in),
type(type_in)
124 uuid =
"0000-0000-0000-0000";
126 std::string uuid =
"";
127 std::string
type =
"MeshPhongMaterial";
128 long color = 16777215;
131 long specular = 1118481;
132 double shininess = 30.0;
133 double opacity = 1.0;
134 bool transparent =
false;
135 bool wireframe =
false;
136 MSGPACK_DEFINE(uuid, type, color, ambient, emissive, specular, shininess, opacity, transparent, wireframe);
142 ObjectData(
const std::string& type_in,
const std::string& uuid_in,
143 const std::string& geometry_in,
const std::string& material_in) :
type(type_in), uuid(uuid_in), geometry(geometry_in), material(material_in){};
148 std::vector<double> matrix = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
149 MSGPACK_DEFINE(type, uuid, geometry, material, matrix);
152 template <
typename T>
159 MSGPACK_DEFINE(metadata, geometries, materials,
object);
162 template <
typename T>
169 MSGPACK_DEFINE(metadata, geometries, materials,
object);
172 template <
typename T>
176 SetObjectType(
const std::string& path_in,
const T& object_in) :
type(
"set_object"),
path(path_in), object(object_in){};
180 MSGPACK_DEFINE(type, path,
object);
183 template <
typename T>
192 Geometry(
const std::string& type_in,
const std::string& uuid_in =
"") :
type(type_in), uuid(uuid_in)
203 GeometryBox(
double width_in,
double height_in,
double depth_in,
const std::string& uuid_in =
"") :
Geometry(
"BoxGeometry", uuid_in), width(width_in), height(height_in), depth(depth_in){};
207 MSGPACK_DEFINE(uuid,
type, width, height, depth)
213 GeometryCylinder(
double radius_in,
double height_in,
int radialSegments_in = 50,
const std::string& uuid_in =
"") :
Geometry(
"CylinderGeometry", uuid_in), radiusTop(radius_in), radiusBottom(radius_in), height(height_in), radialSegments(radialSegments_in){};
218 MSGPACK_DEFINE(uuid,
type, height, radiusTop, radiusBottom, radialSegments)
224 GeometrySphere(
double radius_in,
int widthSegments_in = 50,
int heightSegments_in = 50,
const std::string& uuid_in =
"") :
Geometry(
"SphereGeometry", uuid_in), radius(radius_in), heightSegments(heightSegments_in), widthSegments(widthSegments_in){};
228 MSGPACK_DEFINE(uuid,
type, radius, widthSegments, heightSegments)
235 GeometryMesh(
const std::string& file_name_in,
const std::string& url_in =
"",
const std::string& format_in =
"",
const std::string& uuid_in =
"") :
Geometry(
"_meshfile_geometry", uuid_in), format(format_in)
240 std::string::size_type pos = file_name.rfind(
".");
241 if (pos != std::string::npos)
243 format = file_name.substr(pos + 1);
246 std::transform(format.begin(), format.end(), format.begin(), ::tolower);
248 std::ifstream file(file_name, std::ios::binary | std::ios::ate);
249 std::streamsize size = file.tellg();
250 file.seekg(0, std::ios::beg);
253 file.read(buffer.data(), size);
255 data.ptr = buffer.data();
256 data.size = buffer.size();
266 data.ptr = buffer.data();
267 data.size = buffer.size();
281 data.ptr = buffer.data();
282 data.size = buffer.size();
293 std::vector<double> matrix = {1.0, 0.0, 0.0, 0.0,
297 MSGPACK_DEFINE(uuid,
type, format, resources, url, data, matrix)
308 for (
unsigned int i = 0; i < size; ++i)
309 data[i] = static_cast<float>(data_in[i]);
310 #ifdef MSGPACK_FEATURE_NOT_SUPPORTED 312 WARNING(
"MSGPACK version does not support sending this type of data. Ignoring.");
314 array =
msgpack_ext(0x17, reinterpret_cast<const char*>(data.data()),
sizeof(
float) * data.size());
323 #ifdef MSGPACK_FEATURE_NOT_SUPPORTED 326 array =
msgpack_ext(0x17, reinterpret_cast<const char*>(data.data()),
sizeof(
float) * data.size());
331 std::string
type =
"Float32Array";
336 MSGPACK_DEFINE(itemSize, type, normalized, array)
346 for (
unsigned int i = 0; i < size; ++i)
351 std::string
type =
"Uint32Array";
355 MSGPACK_DEFINE(itemSize, type, normalized, array)
363 std::shared_ptr<shapes::Mesh> shape = std::static_pointer_cast<
shapes::Mesh>(shape_in);
364 attributes.insert(std::make_pair<std::string, ArrayFloat>(
"position",
ArrayFloat(shape->vertices, shape->vertex_count * 3)));
365 if (shape->vertex_normals)
366 attributes.insert(std::make_pair<std::string, ArrayFloat>(
"normal",
ArrayFloat(shape->vertex_normals, shape->vertex_count * 3)));
367 index =
ArrayInt(shape->triangles, shape->triangle_count * 3);
373 MSGPACK_DEFINE(attributes, index)
386 std::vector<double> matrix = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
387 MSGPACK_DEFINE(uuid,
type, data, matrix)
390 template <
typename T>
398 ret.
object.geometry = geometry_in.uuid;
399 ret.
object.material = material_in.uuid;
403 template <
typename T>
408 ret.
object.type =
"_meshfile_object";
415 SetTransform(
const std::string& path_in,
const std::vector<double>& matrix_in) :
type(
"set_transform"),
path(path_in), matrix(matrix_in){};
419 MSGPACK_DEFINE(type, path, matrix);
425 Key(
double time_in,
const std::vector<double>& value_in) : time(time_in), value(value_in){};
428 MSGPACK_DEFINE(time, value);
434 Track(
const std::string& name_in,
const std::string& type_in) : name(name_in),
type(type_in){};
438 MSGPACK_DEFINE(name, type, keys);
444 Clip(
double fps_in,
const std::string& name_in) : fps(fps_in), name(name_in){};
448 MSGPACK_DEFINE(fps, name, tracks);
457 MSGPACK_DEFINE(path, clip);
465 MSGPACK_DEFINE(play, repetitions);
471 std::string
type =
"set_animation";
475 MSGPACK_DEFINE(type, path, animations, options);
484 MSGPACK_DEFINE(type, path);
488 #endif // EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_
std::vector< Track > tracks
std::vector< float > msgpack_ext
Track(const std::string &name_in, const std::string &type_in)
Geometry(const std::string &type_in, const std::string &uuid_in="")
ArrayFloat(double *data_in, unsigned int size)
unsigned char random_char()
std::string generate_uuid()
std::vector< double > matrix
Material(long color_in, double opacity_in=1.0, const std::string &type_in="MeshPhongMaterial", const std::string &uuid_in="")
std::vector< char > buffer
GeometryMeshBufferData data
std::vector< Material > materials
long RGB(double R, double G, double B)
msgpack::type::raw_ref msgpack_raw_ref
std::shared_ptr< Shape > ShapePtr
std::string generate_hex(const unsigned int len)
std::vector< uint32_t > array
std::vector< Animation > animations
TFSIMD_FORCE_INLINE Vector3 normalized() const
ArrayInt(unsigned int *data, unsigned int size)
ArrayFloat(const ArrayFloat &other)
ObjectData(const std::string &type_in, const std::string &uuid_in, const std::string &geometry_in, const std::string &material_in)
GeometryMesh & operator=(const GeometryMesh &other)
GeometryMeshBufferData(shapes::ShapePtr shape_in)
SetObjectType< T > SetObject(const std::string &path_in, const T &object_in)
std::map< std::string, ArrayFloat > attributes
GeometryMesh(const std::string &file_name_in, const std::string &url_in="", const std::string &format_in="", const std::string &uuid_in="")
std::vector< T > geometries
std::vector< double > value
std::string ParsePath(const std::string &path)
Property(const std::string &path_in, const std::string &property_in, const T &value_in)
std::vector< float > data
GeometryMesh(const GeometryMesh &other)
Object< T > CreateGeometryObject(const T &geometry_in, const Material &material_in=Material(), const std::string &uuid_in="")
std::vector< T > geometries
std::map< std::string, std::string > resources
MeshObject< T > CreateMeshObject(const T &geometry_in, const Material &material_in=Material(), const std::string &uuid_in="")
std::vector< Material > materials
GeometryMeshBuffer(shapes::ShapePtr shape_in, const std::string &uuid_in="")
#define WARNING(x)
With endline.
Delete(const std::string &path_in)