Updates to myconid's most recent multiple UV set patch. Refs #1497
This was SVN commit r12185.
This commit is contained in:
parent
1f15257987
commit
c1a3b8f171
@ -32,9 +32,12 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
typedef std::pair<float, float> uv_pair_type;
|
||||||
|
|
||||||
struct VertexData
|
struct VertexData
|
||||||
{
|
{
|
||||||
VertexData(const float* pos, const float* norm, const std::vector<float> &uvs, const std::vector<FCDJointWeightPair>& weights)
|
VertexData(const float* pos, const float* norm, const std::vector<uv_pair_type> &uvs,
|
||||||
|
const std::vector<FCDJointWeightPair>& weights)
|
||||||
: x(pos[0]), y(pos[1]), z(pos[2]),
|
: x(pos[0]), y(pos[1]), z(pos[2]),
|
||||||
nx(norm[0]), ny(norm[1]), nz(norm[2]),
|
nx(norm[0]), ny(norm[1]), nz(norm[2]),
|
||||||
uvs(uvs),
|
uvs(uvs),
|
||||||
@ -44,7 +47,7 @@ struct VertexData
|
|||||||
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
float nx, ny, nz;
|
float nx, ny, nz;
|
||||||
std::vector<float> uvs;
|
std::vector<uv_pair_type> uvs;
|
||||||
std::vector<FCDJointWeightPair> weights;
|
std::vector<FCDJointWeightPair> weights;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,6 +74,10 @@ bool operator<(const FCDJointWeightPair& a, const FCDJointWeightPair& b)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const uv_pair_type& a, const uv_pair_type& b)
|
||||||
|
{
|
||||||
|
return similar(a.first, b.first) && similar(a.second, b.second);
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const VertexData& a, const VertexData& b)
|
bool operator==(const VertexData& a, const VertexData& b)
|
||||||
{
|
{
|
||||||
@ -189,14 +196,16 @@ void ReindexGeometry(FCDGeometryPolygons* polys, FCDSkinController* skin)
|
|||||||
CanonicaliseWeights(weights);
|
CanonicaliseWeights(weights);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> uvs;
|
std::vector<uv_pair_type> uvs;
|
||||||
for (size_t set = 0; set < texcoordSources.size(); ++set)
|
for (size_t set = 0; set < texcoordSources.size(); ++set)
|
||||||
{
|
{
|
||||||
const float* dataTexcoord = texcoordSources[set]->GetData();
|
const float* dataTexcoord = texcoordSources[set]->GetData();
|
||||||
uint32 strideTexcoord = texcoordSources[set]->GetStride();
|
uint32 strideTexcoord = texcoordSources[set]->GetStride();
|
||||||
|
|
||||||
uvs.push_back(dataTexcoord[indicesTexcoord[i]*strideTexcoord]);
|
uv_pair_type p;
|
||||||
uvs.push_back(dataTexcoord[indicesTexcoord[i]*strideTexcoord + 1]);
|
p.first = dataTexcoord[indicesTexcoord[i]*strideTexcoord];
|
||||||
|
p.second = dataTexcoord[indicesTexcoord[i]*strideTexcoord + 1];
|
||||||
|
uvs.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexData vtx (
|
VertexData vtx (
|
||||||
@ -240,8 +249,8 @@ void ReindexGeometry(FCDGeometryPolygons* polys, FCDSkinController* skin)
|
|||||||
newDataTexcoord.clear();
|
newDataTexcoord.clear();
|
||||||
for (size_t i = 0; i < vertexes.size(); ++i)
|
for (size_t i = 0; i < vertexes.size(); ++i)
|
||||||
{
|
{
|
||||||
newDataTexcoord.push_back(vertexes[i].uvs[set * 2]);
|
newDataTexcoord.push_back(vertexes[i].uvs[set].first);
|
||||||
newDataTexcoord.push_back(vertexes[i].uvs[set * 2 + 1]);
|
newDataTexcoord.push_back(vertexes[i].uvs[set].second);
|
||||||
}
|
}
|
||||||
texcoordSources[set]->SetData(newDataTexcoord, 2);
|
texcoordSources[set]->SetData(newDataTexcoord, 2);
|
||||||
}
|
}
|
||||||
|
@ -504,6 +504,9 @@ public:
|
|||||||
output("PSMD", 4); // magic number
|
output("PSMD", 4); // magic number
|
||||||
write(output, (uint32)4); // version number
|
write(output, (uint32)4); // version number
|
||||||
write(output, (uint32)(
|
write(output, (uint32)(
|
||||||
|
// for UVs, we add one uint32 (i.e. 4 bytes) per model that gives the number of
|
||||||
|
// texcoord sets in the model, plus 2 floats per new UV
|
||||||
|
// pair per vertex (i.e. 8 bytes * number of pairs * vertex count)
|
||||||
4 + 11*4*vertexCount + 4 + 8*texcoords.size()*vertexCount + // vertices
|
4 + 11*4*vertexCount + 4 + 8*texcoords.size()*vertexCount + // vertices
|
||||||
4 + 6*faceCount + // faces
|
4 + 6*faceCount + // faces
|
||||||
4 + 7*4*boneCount + // bones
|
4 + 7*4*boneCount + // bones
|
||||||
|
@ -53,7 +53,7 @@ struct IModelDef : public CModelDefRPrivate
|
|||||||
VertexArray::Attribute m_BlendWeights; // valid iff gpuSkinning == true
|
VertexArray::Attribute m_BlendWeights; // valid iff gpuSkinning == true
|
||||||
|
|
||||||
/// The number of UVs is determined by the model
|
/// The number of UVs is determined by the model
|
||||||
VertexArray::Attribute m_UVs[5];
|
std::vector<VertexArray::Attribute> m_UVs;
|
||||||
|
|
||||||
/// Indices are the same for all models, so share them
|
/// Indices are the same for all models, so share them
|
||||||
VertexIndexArray m_IndexArray;
|
VertexIndexArray m_IndexArray;
|
||||||
@ -75,6 +75,7 @@ IModelDef::IModelDef(const CModelDefPtr& mdef, bool gpuSkinning)
|
|||||||
m_Normal.elems = 3;
|
m_Normal.elems = 3;
|
||||||
m_Array.AddAttribute(&m_Normal);
|
m_Array.AddAttribute(&m_Normal);
|
||||||
|
|
||||||
|
m_UVs.resize(mdef->GetNumUVsPerVertex());
|
||||||
for (size_t i = 0; i < mdef->GetNumUVsPerVertex(); i++)
|
for (size_t i = 0; i < mdef->GetNumUVsPerVertex(); i++)
|
||||||
{
|
{
|
||||||
m_UVs[i].type = GL_FLOAT;
|
m_UVs[i].type = GL_FLOAT;
|
||||||
|
Loading…
Reference in New Issue
Block a user