Merge pull request #215 from wanqing0421/importStl

add scale and transform function during the stl model importing process
This commit is contained in:
PhasicFlow 2025-04-25 20:45:53 +03:30 committed by GitHub
commit c12022fb19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 55 additions and 25 deletions

View File

@ -26,32 +26,62 @@ Licence:
bool pFlow::stlWall::readSTLWall
(
const dictionary& dict
const dictionary& dict
)
{
auto fileName = dict.getVal<word>("file");
auto fileName = dict.getVal<word>("file");
fileSystem file("./stl",fileName);
real scale = dict.getValOrSet("scale", static_cast<real>(1.0));
stlFile stl(file);
if(!stl.read())
{
fatalErrorInFunction <<
" error in reading stl file "<< file <<endl;
return false;
}
realx3 transform = dict.getValOrSet<realx3>("transform", realx3(0));
for(uint64 i=0; i<stl.size(); i++)
{
auto it = triangles_.end();
triangles_.insert(it, stl.solid(i).begin(), stl.solid(i).end());
}
auto scaleFirst = dict.getValOrSet("scaleFirst", Logical("Yes"));
fileSystem file("./stl",fileName);
stlFile stl(file);
if(!stl.read())
{
fatalErrorInFunction <<
" error in reading stl file "<< file <<endl;
return false;
}
return true;
// Scale and transform the stl vertex
realx3x3Vector newStlVertx;
for(uint64 i = 0; i < stl.size(); i++)
{
for(uint64 j = 0; j < stl.solid(i).size(); j++)
{
realx3x3 tri;
if(scaleFirst)
{
tri.x() = stl.solid(i)[j].x() * scale + transform.x();
tri.y() = stl.solid(i)[j].y() * scale + transform.y();
tri.z() = stl.solid(i)[j].z() * scale + transform.z();
}
else
{
tri.x() = (stl.solid(i)[j].x() + transform.x()) * scale;
tri.y() = (stl.solid(i)[j].y() + transform.y()) * scale;
tri.z() = (stl.solid(i)[j].z() + transform.z()) * scale;
}
newStlVertx.push_back(tri);
}
}
// Insert the new vertex to the triangles_
for(uint64 i = 0; i < stl.size(); i++)
{
auto it = triangles_.end();
triangles_.insert(it, newStlVertx.begin(), newStlVertx.end());
}
return true;
}
pFlow::stlWall::stlWall()
@ -59,13 +89,13 @@ pFlow::stlWall::stlWall()
pFlow::stlWall::stlWall
(
const dictionary& dict
const dictionary& dict
)
:
Wall(dict)
Wall(dict)
{
if(!readSTLWall(dict))
{
fatalExit;
}
if(!readSTLWall(dict))
{
fatalExit;
}
}