Closed copycd closed 3 years ago
I'm glad that it was pretty easy for you to add _BATCHID support. gltfpack only supports official glTF extensions, and a subset at that; _BATCHID is non-standard. I plan to look into a work-in-progress extension EXT_mesh_features in the future which might help, but that would happen at some point in the future, be separate from _BATCHID as that's a different extension, and potentially have some further restrictions on how the data is generated or transformed.
first, thanks to meshoptimizer.
while converting my glb file, i had got error that is lost _BATCHID attribute. i have written code for _BATCHID attribute error. i don't know how to write beautifully. please, understand.
cgltf.h typedef enum cgltf_attribute_type { cgltf_attribute_type_invalid, cgltf_attribute_type_position, cgltf_attribute_type_normal, cgltf_attribute_type_tangent, cgltf_attribute_type_texcoord, cgltf_attribute_type_color, cgltf_attribute_type_joints, cgltf_attribute_type_weights, // add. cgltf_attribute_type_batchid, } cgltf_attribute_type;
static void cgltf_parse_attribute_type(const char name, cgltf_attribute_type out_type, int out_index) { const char us = strchr(name, '_'); size_t len = us ? (size_t)(us - name) : strlen(name);
}
write.cpp const char* attributeType(cgltf_attribute_type type) { switch (type) { case cgltf_attribute_type_position: return "POSITION"; case cgltf_attribute_type_normal: return "NORMAL"; case cgltf_attribute_type_tangent: return "TANGENT"; case cgltf_attribute_type_texcoord: return "TEXCOORD"; case cgltf_attribute_type_color: return "COLOR"; case cgltf_attribute_type_joints: return "JOINTS"; case cgltf_attribute_type_weights: return "WEIGHTS"; // add. case cgltf_attribute_type_batchid: return "_BATCHID"; default: return "ATTRIBUTE"; } }
void writeMeshAttributes(std::string& json, std::vector& views, std::string& json_accessors, size_t& accr_offset, const Mesh& mesh, int target, const QuantizationPosition& qp, const QuantizationTexture& qt, const Settings& settings)
{
.
.
.
// add
if (stream.type != cgltf_attribute_type_position && stream.type != cgltf_attribute_type_normal && stream.type != cgltf_attribute_type_tangent && stream.type != cgltf_attribute_typebatchid)
{
append(json, "");
append(json, size_t(stream.index));
}
append(json, "\":");
append(json, vertex_accr);
}
}
stream.cpp StreamFormat writeVertexStream(std::string& bin, const Stream& stream, const QuantizationPosition& qp, const QuantizationTexture& qt, const Settings& settings) { . . . // add else if (stream.type == cgltf_attribute_type_batchid) { int components = 1; //if (!settings.quantize) if( true) { for (size_t i = 0; i < stream.data.size(); ++i) { const Attr& a = stream.data[i];
sample.zip }