Hi,
I am generating a mesh with two different methods…
The mesh generated with 1st method is displayed properly but the other one is displayed messy. (Textures are not displayed properly)
I have implemented a test code to compare these two meshes. It says they are same.
The below is my test code.
I could not understand why the 2nd mesh is not working. Any clue?
Do we need to keep vertices in mesh.verts in any particular order?
Thanks in advance.
bool feq(const float3 &a, const float3 &b)
{
if (a.x != b.x) {
return false;
}
if (a.y != b.y) {
return false;
}
if (a.z != b.z) {
return false;
}
return true;
}
void compare(ccl::Mesh &m1, ccl::Mesh &m2)
{
if (m1.triangles.size() != m2.triangles.size()) {
std::cout << "Not same number of triangles\n";
return;
}
std::vector<int> attribute_element_sizes;
attribute_element_sizes.resize(0);
std::vector<const char *> m1_attribute_buffers;
m1_attribute_buffers.resize(0);
std::vector<const char *> m2_attribute_buffers;
m2_attribute_buffers.resize(0);
std::vector<ustring> attribute_names;
attribute_names.resize(0);
ccl::AttributeSet &m1_attribute_set = m1.attributes;
for (auto it = m1_attribute_set.attributes.begin(); it != m1_attribute_set.attributes.end(); it++) {
const ccl::Attribute &attribute = *it;
int element_size = attribute.data_sizeof();
const char *buffer = attribute.buffer.data();
attribute_element_sizes.push_back(element_size);
m1_attribute_buffers.push_back(buffer);
attribute_names.push_back(attribute.name);
}
int i = 0;
ccl::AttributeSet &m2_attribute_set = m2.attributes;
for (auto it = m2_attribute_set.attributes.begin(); it != m2_attribute_set.attributes.end(); it++) {
const ccl::Attribute &attribute = *it;
if (attribute_names[i] != attribute.name) {
std::cout << "Attribute names not same\n";
return;
}
int element_size = attribute.data_sizeof();
const char *buffer = attribute.buffer.data();
if (attribute_element_sizes[i] != element_size) {
std::cout << "Element sizes not same\n";
return;
}
m2_attribute_buffers.push_back(buffer);
i++;
}
for (i = 0; i < m1.triangles.size(); i++) {
int m1_vertex_index = m1.triangles[i];
int m2_vertex_index = m2.triangles[i];
if (!feq(m1.verts[m1_vertex_index], m2.verts[m2_vertex_index])) {
std::cout << "Vertex is not same\n";
return;
}
for (int j = 0; j < attribute_element_sizes.size(); j++) {
int element_size = attribute_element_sizes[j];
for (int k = 0; k < element_size; k++) {
if (m1_attribute_buffers[j][(m1_vertex_index * element_size) + k] !=
m2_attribute_buffers[j][(m2_vertex_index * element_size) + k]) {
std::cout << "Data not same: " << attribute_names[j] << "\t" << m1.name << "\t" << std::endl;
return;
}
}
}
}
int triangles_count = m1.triangles.size() / 3;
for (i = 0; i < triangles_count; i++) {
if (m1.shader[i] != m2.shader[i]) {
std::cout << "Shader not same\n";
return;
}
if (m1.smooth[i] != m2.smooth[i]) {
std::cout << "Smooth not same\n";
return;
}
}
std::cout << "______________________________SAME_________________________________________" << std::endl;
}