mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-16 05:55:52 +08:00
clang format
This commit is contained in:
parent
1af7c1d784
commit
52936a00e0
116
tiny_gltf.h
116
tiny_gltf.h
@ -817,7 +817,7 @@ struct SpotLight {
|
|||||||
double innerConeAngle;
|
double innerConeAngle;
|
||||||
double outerConeAngle;
|
double outerConeAngle;
|
||||||
|
|
||||||
SpotLight() : innerConeAngle(0.0), outerConeAngle(0.7853981634) { }
|
SpotLight() : innerConeAngle(0.0), outerConeAngle(0.7853981634) {}
|
||||||
|
|
||||||
bool operator==(const SpotLight &) const;
|
bool operator==(const SpotLight &) const;
|
||||||
|
|
||||||
@ -1061,7 +1061,6 @@ class TinyGLTF {
|
|||||||
const char *str, const unsigned int length,
|
const char *str, const unsigned int length,
|
||||||
const std::string &base_dir, unsigned int check_sections);
|
const std::string &base_dir, unsigned int check_sections);
|
||||||
|
|
||||||
|
|
||||||
const unsigned char *bin_data_;
|
const unsigned char *bin_data_;
|
||||||
size_t bin_size_;
|
size_t bin_size_;
|
||||||
bool is_binary_;
|
bool is_binary_;
|
||||||
@ -3704,17 +3703,16 @@ static bool ParsePerspectiveCamera(PerspectiveCamera *camera, std::string *err,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ParseSpotLight(SpotLight *light,
|
static bool ParseSpotLight(SpotLight *light, std::string *err, const json &o) {
|
||||||
std::string *err, const json &o) {
|
ParseNumberProperty(&light->innerConeAngle, err, o, "innerConeAngle", false);
|
||||||
ParseNumberProperty(&light->innerConeAngle, err, o, "innerConeAngle", false);
|
ParseNumberProperty(&light->outerConeAngle, err, o, "outerConeAngle", false);
|
||||||
ParseNumberProperty(&light->outerConeAngle, err, o, "outerConeAngle", false);
|
|
||||||
|
|
||||||
ParseExtensionsProperty(&light->extensions, err, o);
|
ParseExtensionsProperty(&light->extensions, err, o);
|
||||||
ParseExtrasProperty(&light->extras, o);
|
ParseExtrasProperty(&light->extras, o);
|
||||||
|
|
||||||
// TODO(syoyo): Validate parameter values.
|
// TODO(syoyo): Validate parameter values.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ParseOrthographicCamera(OrthographicCamera *camera,
|
static bool ParseOrthographicCamera(OrthographicCamera *camera,
|
||||||
@ -3823,42 +3821,42 @@ static bool ParseCamera(Camera *camera, std::string *err, const json &o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool ParseLight(Light *light, std::string *err, const json &o) {
|
static bool ParseLight(Light *light, std::string *err, const json &o) {
|
||||||
if (!ParseStringProperty(&light->type, err, o, "type", true)) {
|
if (!ParseStringProperty(&light->type, err, o, "type", true)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (light->type == "spot") {
|
||||||
|
if (o.find("spot") == o.end()) {
|
||||||
|
if (err) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Spot light description not found." << std::endl;
|
||||||
|
(*err) += ss.str();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (light->type == "spot") {
|
const json &v = o.find("spot").value();
|
||||||
if (o.find("spot") == o.end()) {
|
if (!v.is_object()) {
|
||||||
if (err) {
|
if (err) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Spot light description not found." << std::endl;
|
ss << "\"spot\" is not a JSON object." << std::endl;
|
||||||
(*err) += ss.str();
|
(*err) += ss.str();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
const json &v = o.find("spot").value();
|
|
||||||
if (!v.is_object()) {
|
|
||||||
if (err) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "\"spot\" is not a JSON object." << std::endl;
|
|
||||||
(*err) += ss.str();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ParseSpotLight(&light->spot, err, v.get<json>())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseStringProperty(&light->name, err, o, "name", false);
|
if (!ParseSpotLight(&light->spot, err, v.get<json>())) {
|
||||||
ParseNumberArrayProperty(&light->color, err, o, "color", false);
|
return false;
|
||||||
ParseNumberProperty(&light->range, err, o, "range", false);
|
}
|
||||||
ParseNumberProperty(&light->intensity, err, o, "intensity", false);
|
}
|
||||||
ParseExtensionsProperty(&light->extensions, err, o);
|
|
||||||
ParseExtrasProperty(&(light->extras), o);
|
ParseStringProperty(&light->name, err, o, "name", false);
|
||||||
return true;
|
ParseNumberArrayProperty(&light->color, err, o, "color", false);
|
||||||
|
ParseNumberProperty(&light->range, err, o, "range", false);
|
||||||
|
ParseNumberProperty(&light->intensity, err, o, "intensity", false);
|
||||||
|
ParseExtensionsProperty(&light->extensions, err, o);
|
||||||
|
ParseExtrasProperty(&(light->extras), o);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||||
@ -5113,9 +5111,9 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeSpotLight(SpotLight &spot, json &o) {
|
static void SerializeSpotLight(SpotLight &spot, json &o) {
|
||||||
SerializeNumberProperty("innerConeAngle", spot.innerConeAngle, o);
|
SerializeNumberProperty("innerConeAngle", spot.innerConeAngle, o);
|
||||||
SerializeNumberProperty("outerConeAngle", spot.outerConeAngle, o);
|
SerializeNumberProperty("outerConeAngle", spot.outerConeAngle, o);
|
||||||
SerializeExtensionMap(spot.extensions, o);
|
SerializeExtensionMap(spot.extensions, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfLight(Light &light, json &o) {
|
static void SerializeGltfLight(Light &light, json &o) {
|
||||||
@ -5268,7 +5266,6 @@ static void SerializeGltfTexture(Texture &texture, json &o) {
|
|||||||
/// Serialize all properties except buffers and images.
|
/// Serialize all properties except buffers and images.
|
||||||
///
|
///
|
||||||
static void SerializeGltfModel(Model *model, json &o) {
|
static void SerializeGltfModel(Model *model, json &o) {
|
||||||
|
|
||||||
// ACCESSORS
|
// ACCESSORS
|
||||||
json accessors;
|
json accessors;
|
||||||
for (unsigned int i = 0; i < model->accessors.size(); ++i) {
|
for (unsigned int i = 0; i < model->accessors.size(); ++i) {
|
||||||
@ -5296,7 +5293,6 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
SerializeGltfAsset(model->asset, asset);
|
SerializeGltfAsset(model->asset, asset);
|
||||||
o["asset"] = asset;
|
o["asset"] = asset;
|
||||||
|
|
||||||
|
|
||||||
// BUFFERVIEWS
|
// BUFFERVIEWS
|
||||||
json bufferViews;
|
json bufferViews;
|
||||||
for (unsigned int i = 0; i < model->bufferViews.size(); ++i) {
|
for (unsigned int i = 0; i < model->bufferViews.size(); ++i) {
|
||||||
@ -5308,8 +5304,7 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
|
|
||||||
// Extensions used
|
// Extensions used
|
||||||
if (model->extensionsUsed.size()) {
|
if (model->extensionsUsed.size()) {
|
||||||
SerializeStringArrayProperty("extensionsUsed", model->extensionsUsed,
|
SerializeStringArrayProperty("extensionsUsed", model->extensionsUsed, o);
|
||||||
o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions required
|
// Extensions required
|
||||||
@ -5441,8 +5436,7 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool WriteGltfStream(std::ostream &stream,
|
static bool WriteGltfStream(std::ostream &stream, const std::string &content) {
|
||||||
const std::string &content) {
|
|
||||||
stream << content << std::endl;
|
stream << content << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -5455,8 +5449,7 @@ static bool WriteGltfFile(const std::string &output,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void WriteBinaryGltfStream(std::ostream &stream,
|
static void WriteBinaryGltfStream(std::ostream &stream,
|
||||||
const std::string &content) {
|
const std::string &content) {
|
||||||
|
|
||||||
const std::string header = "glTF";
|
const std::string header = "glTF";
|
||||||
const int version = 2;
|
const int version = 2;
|
||||||
const int padding_size = content.size() % 4;
|
const int padding_size = content.size() % 4;
|
||||||
@ -5473,9 +5466,9 @@ static void WriteBinaryGltfStream(std::ostream &stream,
|
|||||||
const int model_length = int(content.size()) + padding_size;
|
const int model_length = int(content.size()) + padding_size;
|
||||||
const int model_format = 0x4E4F534A;
|
const int model_format = 0x4E4F534A;
|
||||||
stream.write(reinterpret_cast<const char *>(&model_length),
|
stream.write(reinterpret_cast<const char *>(&model_length),
|
||||||
sizeof(model_length));
|
sizeof(model_length));
|
||||||
stream.write(reinterpret_cast<const char *>(&model_format),
|
stream.write(reinterpret_cast<const char *>(&model_format),
|
||||||
sizeof(model_format));
|
sizeof(model_format));
|
||||||
stream.write(content.c_str(), content.size());
|
stream.write(content.c_str(), content.size());
|
||||||
|
|
||||||
// Chunk must be multiplies of 4, so pad with spaces
|
// Chunk must be multiplies of 4, so pad with spaces
|
||||||
@ -5492,8 +5485,8 @@ static void WriteBinaryGltfFile(const std::string &output,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
||||||
bool prettyPrint = true,
|
bool prettyPrint = true,
|
||||||
bool writeBinary = false) {
|
bool writeBinary = false) {
|
||||||
json output;
|
json output;
|
||||||
|
|
||||||
/// Serialize all properties except buffers and images.
|
/// Serialize all properties except buffers and images.
|
||||||
@ -5516,8 +5509,9 @@ bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
|||||||
json image;
|
json image;
|
||||||
|
|
||||||
std::string dummystring = "";
|
std::string dummystring = "";
|
||||||
// UpdateImageObject need baseDir but only uses it if embededImages is enable,
|
// UpdateImageObject need baseDir but only uses it if embededImages is
|
||||||
// since we won't write separte images when writing to a stream we use a dummystring
|
// enable, since we won't write separte images when writing to a stream we
|
||||||
|
// use a dummystring
|
||||||
UpdateImageObject(model->images[i], dummystring, int(i), false,
|
UpdateImageObject(model->images[i], dummystring, int(i), false,
|
||||||
&this->WriteImageData, this->write_image_user_data_);
|
&this->WriteImageData, this->write_image_user_data_);
|
||||||
SerializeGltfImage(model->images[i], image);
|
SerializeGltfImage(model->images[i], image);
|
||||||
@ -5553,8 +5547,8 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
if (baseDir.empty()) {
|
if (baseDir.empty()) {
|
||||||
baseDir = "./";
|
baseDir = "./";
|
||||||
}
|
}
|
||||||
/// Serialize all properties except buffers and images.
|
/// Serialize all properties except buffers and images.
|
||||||
SerializeGltfModel(model, output);
|
SerializeGltfModel(model, output);
|
||||||
|
|
||||||
// BUFFERS
|
// BUFFERS
|
||||||
std::vector<std::string> usedUris;
|
std::vector<std::string> usedUris;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user