MCPcopy Create free account
hub / github.com/assimp/assimp / Subdivide

Function Subdivide

code/Common/StandardShapes.cpp:86–108  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Fast subdivision for a mesh whose verts have a magnitude of 1

Source from the content-addressed store, hash-verified

84// ------------------------------------------------------------------------------------------------
85// Fast subdivision for a mesh whose verts have a magnitude of 1
86void Subdivide(std::vector<aiVector3D> &positions) {
87 // assume this to be constant - (fixme: must be 1.0? I think so)
88 const ai_real fl1 = positions[0].Length();
89
90 unsigned int origSize = (unsigned int)positions.size();
91 for (unsigned int i = 0; i < origSize; i += 3) {
92 aiVector3D &tv0 = positions[i];
93 aiVector3D &tv1 = positions[i + 1];
94 aiVector3D &tv2 = positions[i + 2];
95
96 aiVector3D a = tv0, b = tv1, c = tv2;
97 aiVector3D v1 = aiVector3D(a.x + b.x, a.y + b.y, a.z + b.z).Normalize() * fl1;
98 aiVector3D v2 = aiVector3D(a.x + c.x, a.y + c.y, a.z + c.z).Normalize() * fl1;
99 aiVector3D v3 = aiVector3D(b.x + c.x, b.y + c.y, b.z + c.z).Normalize() * fl1;
100
101 tv0 = v1;
102 tv1 = v3;
103 tv2 = v2; // overwrite the original
104 ADD_TRIANGLE(v1, v2, a);
105 ADD_TRIANGLE(v2, v3, c);
106 ADD_TRIANGLE(v3, v1, b);
107 }
108}
109
110// ------------------------------------------------------------------------------------------------
111// Construct a mesh from given vertex positions

Callers 2

SubdivideMethod · 0.85
MakeSphereMethod · 0.85

Calls 4

aiVector3DClass · 0.85
LengthMethod · 0.45
sizeMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected