load texture coordinates

Signed-off by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
Arthur Brainville (Ybalrid) 2018-02-21 10:02:04 +01:00
parent b7bf01c679
commit 0dca478817
No known key found for this signature in database
GPG Key ID: BC05C4812A06BCF3
2 changed files with 53 additions and 0 deletions

View File

@ -240,6 +240,43 @@ bool LoadGLTF(const std::string &filename, float scale,
break;
}
}
if (attribute.first == "TEXCOORD_0") {
std::cout << "Found texture coordinates\n";
switch (attribAccessor.type) {
case TINYGLTF_TYPE_VEC2: {
switch (attribAccessor.componentType) {
case TINYGLTF_COMPONENT_TYPE_FLOAT: {
v2fArray uvs(
arrayAdapter<v2f>(dataPtr, count, byte_stride));
for (size_t i{0}; i < uvs.size(); ++i) {
const auto v = uvs[i];
std::cout << '(' << v.x << ", " << v.y << ")\n";
loadedMesh.facevarying_uvs.push_back(v.x);
loadedMesh.facevarying_uvs.push_back(v.y);
}
} break;
case TINYGLTF_COMPONENT_TYPE_DOUBLE: {
v2dArray uvs(
arrayAdapter<v2d>(dataPtr, count, byte_stride));
for (size_t i{0}; i < uvs.size(); ++i) {
const auto v = uvs[i];
std::cout << '(' << v.x << ", " << v.y << ")\n";
loadedMesh.facevarying_uvs.push_back(v.x);
loadedMesh.facevarying_uvs.push_back(v.y);
}
} break;
default:
break;
}
} break;
default:
break;
}
}
}
}

View File

@ -104,6 +104,14 @@ using v2d = v2<double>;
using v3d = v3<double>;
using v4d = v4<double>;
struct v2fArray {
arrayAdapter<v2f> adapter;
v2fArray(const arrayAdapter<v2f> &a) : adapter(a) {}
v2f operator[](size_t position) const { return adapter[position]; }
size_t size() const { return adapter.elemCount; }
};
struct v3fArray {
arrayAdapter<v3f> adapter;
v3fArray(const arrayAdapter<v3f> &a) : adapter(a) {}
@ -120,6 +128,14 @@ struct v4fArray {
size_t size() const { return adapter.elemCount; }
};
struct v2dArray {
arrayAdapter<v2d> adapter;
v2dArray(const arrayAdapter<v2d> &a) : adapter(a) {}
v2d operator[](size_t position) const { return adapter[position]; }
size_t size() const { return adapter.elemCount; }
};
struct v3dArray {
arrayAdapter<v3d> adapter;
v3dArray(const arrayAdapter<v3d> &a) : adapter(a) {}