Ogre: Use C++11 range-based for loop
parent
3eb9b8e91b
commit
32e4dd0bd1
|
@ -501,10 +501,8 @@ void OgreBinarySerializer::NormalizeBoneWeights(VertexData *vertexData) const
|
||||||
Some exporters wont care if the sum of all bone weights
|
Some exporters wont care if the sum of all bone weights
|
||||||
for a single vertex equals 1 or not, so validate here. */
|
for a single vertex equals 1 or not, so validate here. */
|
||||||
const float epsilon = 0.05f;
|
const float epsilon = 0.05f;
|
||||||
for(std::set<uint32_t>::const_iterator iter=influencedVertices.begin(), end=influencedVertices.end(); iter != end; ++iter)
|
for (const uint32_t vertexIndex : influencedVertices)
|
||||||
{
|
{
|
||||||
const uint32_t vertexIndex = (*iter);
|
|
||||||
|
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
for (VertexBoneAssignmentList::const_iterator baIter=vertexData->boneAssignments.begin(), baEnd=vertexData->boneAssignments.end(); baIter != baEnd; ++baIter)
|
for (VertexBoneAssignmentList::const_iterator baIter=vertexData->boneAssignments.begin(), baEnd=vertexData->boneAssignments.end(); baIter != baEnd; ++baIter)
|
||||||
{
|
{
|
||||||
|
@ -513,10 +511,10 @@ void OgreBinarySerializer::NormalizeBoneWeights(VertexData *vertexData) const
|
||||||
}
|
}
|
||||||
if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon)))
|
if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon)))
|
||||||
{
|
{
|
||||||
for (VertexBoneAssignmentList::iterator baIter=vertexData->boneAssignments.begin(), baEnd=vertexData->boneAssignments.end(); baIter != baEnd; ++baIter)
|
for (auto &boneAssign : vertexData->boneAssignments)
|
||||||
{
|
{
|
||||||
if (baIter->vertexIndex == vertexIndex)
|
if (boneAssign.vertexIndex == vertexIndex)
|
||||||
baIter->weight /= sum;
|
boneAssign.weight /= sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,12 +258,11 @@ void IVertexData::AddVertexMapping(uint32_t oldIndex, uint32_t newIndex)
|
||||||
|
|
||||||
void IVertexData::BoneAssignmentsForVertex(uint32_t currentIndex, uint32_t newIndex, VertexBoneAssignmentList &dest) const
|
void IVertexData::BoneAssignmentsForVertex(uint32_t currentIndex, uint32_t newIndex, VertexBoneAssignmentList &dest) const
|
||||||
{
|
{
|
||||||
for (VertexBoneAssignmentList::const_iterator iter=boneAssignments.begin(), end=boneAssignments.end();
|
for (const auto &boneAssign : boneAssignments)
|
||||||
iter!=end; ++iter)
|
|
||||||
{
|
{
|
||||||
if (iter->vertexIndex == currentIndex)
|
if (boneAssign.vertexIndex == currentIndex)
|
||||||
{
|
{
|
||||||
VertexBoneAssignment a = (*iter);
|
VertexBoneAssignment a = boneAssign;
|
||||||
a.vertexIndex = newIndex;
|
a.vertexIndex = newIndex;
|
||||||
dest.push_back(a);
|
dest.push_back(a);
|
||||||
}
|
}
|
||||||
|
@ -289,10 +288,9 @@ AssimpVertexBoneWeightList IVertexData::AssimpBoneWeights(size_t vertices)
|
||||||
std::set<uint16_t> IVertexData::ReferencedBonesByWeights() const
|
std::set<uint16_t> IVertexData::ReferencedBonesByWeights() const
|
||||||
{
|
{
|
||||||
std::set<uint16_t> referenced;
|
std::set<uint16_t> referenced;
|
||||||
for (VertexBoneAssignmentList::const_iterator iter=boneAssignments.begin(), end=boneAssignments.end();
|
for (const auto &boneAssign : boneAssignments)
|
||||||
iter!=end; ++iter)
|
|
||||||
{
|
{
|
||||||
referenced.insert(iter->boneIndex);
|
referenced.insert(boneAssign.boneIndex);
|
||||||
}
|
}
|
||||||
return referenced;
|
return referenced;
|
||||||
}
|
}
|
||||||
|
@ -318,10 +316,10 @@ void VertexData::Reset()
|
||||||
uint32_t VertexData::VertexSize(uint16_t source) const
|
uint32_t VertexData::VertexSize(uint16_t source) const
|
||||||
{
|
{
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
for(VertexElementList::const_iterator iter=vertexElements.begin(), end=vertexElements.end(); iter != end; ++iter)
|
for(const auto &element : vertexElements)
|
||||||
{
|
{
|
||||||
if (iter->source == source)
|
if (element.source == source)
|
||||||
size += iter->Size();
|
size += element.Size();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -335,9 +333,8 @@ MemoryStream *VertexData::VertexBuffer(uint16_t source)
|
||||||
|
|
||||||
VertexElement *VertexData::GetVertexElement(VertexElement::Semantic semantic, uint16_t index)
|
VertexElement *VertexData::GetVertexElement(VertexElement::Semantic semantic, uint16_t index)
|
||||||
{
|
{
|
||||||
for(VertexElementList::iterator iter=vertexElements.begin(), end=vertexElements.end(); iter != end; ++iter)
|
for(auto & element : vertexElements)
|
||||||
{
|
{
|
||||||
VertexElement &element = (*iter);
|
|
||||||
if (element.semantic == semantic && element.index == index)
|
if (element.semantic == semantic && element.index == index)
|
||||||
return &element;
|
return &element;
|
||||||
}
|
}
|
||||||
|
@ -427,16 +424,16 @@ void Mesh::Reset()
|
||||||
OGRE_SAFE_DELETE(skeleton)
|
OGRE_SAFE_DELETE(skeleton)
|
||||||
OGRE_SAFE_DELETE(sharedVertexData)
|
OGRE_SAFE_DELETE(sharedVertexData)
|
||||||
|
|
||||||
for(size_t i=0, len=subMeshes.size(); i<len; ++i) {
|
for(auto &mesh : subMeshes) {
|
||||||
OGRE_SAFE_DELETE(subMeshes[i])
|
OGRE_SAFE_DELETE(mesh)
|
||||||
}
|
}
|
||||||
subMeshes.clear();
|
subMeshes.clear();
|
||||||
for(size_t i=0, len=animations.size(); i<len; ++i) {
|
for(auto &anim : animations) {
|
||||||
OGRE_SAFE_DELETE(animations[i])
|
OGRE_SAFE_DELETE(anim)
|
||||||
}
|
}
|
||||||
animations.clear();
|
animations.clear();
|
||||||
for(size_t i=0, len=poses.size(); i<len; ++i) {
|
for(auto &pose : poses) {
|
||||||
OGRE_SAFE_DELETE(poses[i])
|
OGRE_SAFE_DELETE(pose)
|
||||||
}
|
}
|
||||||
poses.clear();
|
poses.clear();
|
||||||
}
|
}
|
||||||
|
@ -739,8 +736,8 @@ void MeshXml::Reset()
|
||||||
OGRE_SAFE_DELETE(skeleton)
|
OGRE_SAFE_DELETE(skeleton)
|
||||||
OGRE_SAFE_DELETE(sharedVertexData)
|
OGRE_SAFE_DELETE(sharedVertexData)
|
||||||
|
|
||||||
for(size_t i=0, len=subMeshes.size(); i<len; ++i) {
|
for(auto &mesh : subMeshes) {
|
||||||
OGRE_SAFE_DELETE(subMeshes[i])
|
OGRE_SAFE_DELETE(mesh)
|
||||||
}
|
}
|
||||||
subMeshes.clear();
|
subMeshes.clear();
|
||||||
}
|
}
|
||||||
|
@ -988,12 +985,12 @@ Skeleton::~Skeleton()
|
||||||
|
|
||||||
void Skeleton::Reset()
|
void Skeleton::Reset()
|
||||||
{
|
{
|
||||||
for(size_t i=0, len=bones.size(); i<len; ++i) {
|
for(auto &bone : bones) {
|
||||||
OGRE_SAFE_DELETE(bones[i])
|
OGRE_SAFE_DELETE(bone)
|
||||||
}
|
}
|
||||||
bones.clear();
|
bones.clear();
|
||||||
for(size_t i=0, len=animations.size(); i<len; ++i) {
|
for(auto &anim : animations) {
|
||||||
OGRE_SAFE_DELETE(animations[i])
|
OGRE_SAFE_DELETE(anim)
|
||||||
}
|
}
|
||||||
animations.clear();
|
animations.clear();
|
||||||
}
|
}
|
||||||
|
@ -1082,11 +1079,11 @@ void Bone::CalculateWorldMatrixAndDefaultPose(Skeleton *skeleton)
|
||||||
defaultPose = aiMatrix4x4(scale, rotation, position);
|
defaultPose = aiMatrix4x4(scale, rotation, position);
|
||||||
|
|
||||||
// Recursively for all children now that the parent matrix has been calculated.
|
// Recursively for all children now that the parent matrix has been calculated.
|
||||||
for (size_t i=0, len=children.size(); i<len; ++i)
|
for (auto boneId : children)
|
||||||
{
|
{
|
||||||
Bone *child = skeleton->BoneById(children[i]);
|
Bone *child = skeleton->BoneById(boneId);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
throw DeadlyImportError(Formatter::format() << "CalculateWorldMatrixAndDefaultPose: Failed to find child bone " << children[i] << " for parent " << id << " " << name);
|
throw DeadlyImportError(Formatter::format() << "CalculateWorldMatrixAndDefaultPose: Failed to find child bone " << boneId << " for parent " << id << " " << name);
|
||||||
}
|
}
|
||||||
child->CalculateWorldMatrixAndDefaultPose(skeleton);
|
child->CalculateWorldMatrixAndDefaultPose(skeleton);
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,7 +453,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
|
||||||
}
|
}
|
||||||
else if (uvs > 0 && m_currentNodeName == nnTexCoord)
|
else if (uvs > 0 && m_currentNodeName == nnTexCoord)
|
||||||
{
|
{
|
||||||
for(size_t i=0, len=dest->uvs.size(); i<len; ++i)
|
for(auto &uvs : dest->uvs)
|
||||||
{
|
{
|
||||||
if (m_currentNodeName != nnTexCoord) {
|
if (m_currentNodeName != nnTexCoord) {
|
||||||
throw DeadlyImportError("Vertex buffer declared more UVs than can be found in a vertex");
|
throw DeadlyImportError("Vertex buffer declared more UVs than can be found in a vertex");
|
||||||
|
@ -462,7 +462,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
|
||||||
aiVector3D uv;
|
aiVector3D uv;
|
||||||
uv.x = ReadAttribute<float>("u");
|
uv.x = ReadAttribute<float>("u");
|
||||||
uv.y = (ReadAttribute<float>("v") * -1) + 1; // Flip UV from Ogre to Assimp form
|
uv.y = (ReadAttribute<float>("v") * -1) + 1; // Flip UV from Ogre to Assimp form
|
||||||
dest->uvs[i].push_back(uv);
|
uvs.push_back(uv);
|
||||||
|
|
||||||
NextNode();
|
NextNode();
|
||||||
}
|
}
|
||||||
|
@ -657,10 +657,8 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest)
|
||||||
Some exporters wont care if the sum of all bone weights
|
Some exporters wont care if the sum of all bone weights
|
||||||
for a single vertex equals 1 or not, so validate here. */
|
for a single vertex equals 1 or not, so validate here. */
|
||||||
const float epsilon = 0.05f;
|
const float epsilon = 0.05f;
|
||||||
for(std::set<uint32_t>::const_iterator iter=influencedVertices.begin(), end=influencedVertices.end(); iter != end; ++iter)
|
for (const uint32_t vertexIndex : influencedVertices)
|
||||||
{
|
{
|
||||||
const uint32_t vertexIndex = (*iter);
|
|
||||||
|
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
for (VertexBoneAssignmentList::const_iterator baIter=dest->boneAssignments.begin(), baEnd=dest->boneAssignments.end(); baIter != baEnd; ++baIter)
|
for (VertexBoneAssignmentList::const_iterator baIter=dest->boneAssignments.begin(), baEnd=dest->boneAssignments.end(); baIter != baEnd; ++baIter)
|
||||||
{
|
{
|
||||||
|
@ -669,10 +667,10 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest)
|
||||||
}
|
}
|
||||||
if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon)))
|
if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon)))
|
||||||
{
|
{
|
||||||
for (VertexBoneAssignmentList::iterator baIter=dest->boneAssignments.begin(), baEnd=dest->boneAssignments.end(); baIter != baEnd; ++baIter)
|
for (auto &boneAssign : dest->boneAssignments)
|
||||||
{
|
{
|
||||||
if (baIter->vertexIndex == vertexIndex)
|
if (boneAssign.vertexIndex == vertexIndex)
|
||||||
baIter->weight /= sum;
|
boneAssign.weight /= sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue