#include "GeometricModeling.h"
int g_nSampleCount = 16;
double PI = 3.1415926535897932384626433832795;
bool GeometricModeling::GetModel_RoundPipe(const ParamRoundPipe& Param, OUT DataModel& Model)
{
Model = DataModel();
DataModel SubModel;
SubModel.sName = L"圆管侧壁";
DataBatch Batch;
//构造管线侧面顶点和法线
{
AcGeVector3d PipeOffset = Param.EndPoint - Param.BeginPoint;
AcGeVector3d PipeDirection = PipeOffset.normal();
AcGeVector3d PipePlanDirection = fabs(PipeDirection.dotProduct(AcGeVector3d::kXAxis)) < fabs(PipeDirection.dotProduct(AcGeVector3d::kYAxis)) ? AcGeVector3d::kXAxis : AcGeVector3d::kYAxis;
AcGeVector3d PipeFirstSampleDirection = PipeDirection.crossProduct(PipePlanDirection).normal();
AcGePoint3d PipeFirstSamplePoint = Param.BeginPoint + PipeFirstSampleDirection * (Param.diameter / 2);
double fSampleAngleDiff = (2 * PI) / g_nSampleCount;
//起点
{
for (int i = 0; i <= g_nSampleCount; ++i)
{
AcGeMatrix3d Trans;
Trans.setToRotation(i * fSampleAngleDiff, PipeDirection, Param.BeginPoint);
AcGePoint3d EachPointBegin = PipeFirstSamplePoint;
EachPointBegin.transformBy(Trans);
AcGeVector3d EachSampleDirection = PipeFirstSampleDirection;
EachSampleDirection.transformBy(Trans);
Batch.PushPoint(
DataPoint(
EachPointBegin.x, EachPointBegin.y, EachPointBegin.z,
EachSampleDirection.x, EachSampleDirection.y, EachSampleDirection.z,
0, Param.fVRepeatCount * (double(i) / g_nSampleCount)
)
);
}
}
//终点
{
for (int i = 0; i <= g_nSampleCount; ++i)
{
AcGeMatrix3d Trans;
Trans.setToRotation(i * fSampleAngleDiff, PipeDirection, Param.BeginPoint);
AcGePoint3d EachPointBegin = PipeFirstSamplePoint;
EachPointBegin.transformBy(Trans);
AcGeVector3d EachSampleDirection = PipeFirstSampleDirection;
EachSampleDirection.transformBy(Trans);
AcGePoint3d EachPointEnd = EachPointBegin + PipeOffset;
Batch.PushPoint(
DataPoint(
EachPointEnd.x, EachPointEnd.y, EachPointEnd.z,
EachSampleDirection.x, EachSampleDirection.y, EachSampleDirection.z,
Param.fURepeatCount, Param.fVRepeatCount * (double(i) / g_nSampleCount)
)
);
}
}
}
//构造管线侧面三角形
{
int VertexIndexOffset = g_nSampleCount;
for (int i = 0; i <= g_nSampleCount; ++i)
{
Batch.PushIndexFace(DataIndexFace(i, VertexIndexOffset + i + 1, VertexIndexOffset + i));
Batch.PushIndexFace(DataIndexFace(i, i + 1, VertexIndexOffset + i + 1));
}
}
SubModel.BatchArray.push_back(Batch);
Model.ModelArray.push_back(SubModel);
return true;
}
bool GeometricModeling::GetModel_PipeElbow(const ParamPipeElbow& Param, OUT DataModel& Model)
{
//创建对应圆弧
AcGePoint3d cent;
AcGeVector3d nrm;
AcGeVector3d refVec;
double radius;
double startAngle;
double endAngle;
{
AcGeVector3d BeginSide = Param.pt3dBegin - Param.pt3dCross;
AcGeVector3d EndSide = Param.pt3dEnd - Param.pt3dCross;
AcGePoint3d BeginPoint = Param.pt3dBegin;
AcGePoint3d EndPoint = Param.pt3dEnd;
if (BeginSide.length() >= EndSide.length())
{
radius = BeginSide.length();
EndPoint = Param.pt3dCross + EndSide.normal() * radius;
}
else
{
radius = EndSide.length();
BeginPoint = Param.pt3dCross + BeginSide.normal() * radius;
}
BeginSide = BeginPoint - Param.pt3dCross;
EndSide = EndPoint - Param.pt3dCross;
endAngle = fabs(PI - BeginSide.angleTo(EndSide));
startAngle = 0;
nrm = (-BeginSide).crossProduct(EndSide).normal();
radius = BeginSide.length() / tan(endAngle / 2);
AcGeVector3d vt3dA = (BeginPoint - Param.pt3dCross).normal().rotateBy(PI / 2, nrm);
AcGeVector3d vt3dB = (BeginPoint - Param.pt3dCross).normal().rotateBy(PI / 2, -nrm);
AcGePoint3d centA = BeginPoint + vt3dA * radius;
AcGePoint3d centB = BeginPoint + vt3dB * radius;
cent = (centA.distanceTo(EndPoint) < centB.distanceTo(EndPoint)) ? centA : centB;
refVec = (BeginPoint - cent).normal();
}
AcGeCircArc3d Arc(cent, nrm, refVec, radius, startAngle, endAngle);
double fTotalLength = endAngle * radius;
//管侧面
{
DataModel SubModel;
SubModel.sName = L"弯头侧面";
DataBatch Batch;
//构造管线侧面顶点和法线
{
AcGePoint3dArray SamplePointArray;
Arc.getSamplePoints(g_nSampleCount, SamplePointArray);
for (int iA = 0; iA < SamplePointArray.length() - 1; ++iA)
{
AcGePoint3d BeginPoint = SamplePointArray[iA];
AcGePoint3d EndPoint = SamplePointArray[iA + 1];
double fSampleAngleDiff = (2 * PI) / g_nSampleCount;
//起点
if (0 == iA)
{
AcGeLine3d TangentLine;
Arc.tangent(BeginPoint, TangentLine);
AcGeVector3d pt3dDirection = -TangentLine.direction();
AcGeVector3d PipeFirstSampleDirection = pt3dDirection.crossProduct(nrm).normal();
AcGePoint3d PipeFirstSamplePoint = BeginPoint + PipeFirstSampleDirection * (Param.fD / 2);
for (int i = 0; i <= g_nSampleCount; ++i)
{
AcGeMatrix3d Trans;
Trans.setToRotation(i * fSampleAngleDiff, pt3dDirection, BeginPoint);
AcGePoint3d EachPointBegin = PipeFirstSamplePoint;
EachPointBegin.transformBy(Trans);
AcGeVector3d EachSampleDirection = PipeFirstSampleDirection;
EachSampleDirection.transformBy(Trans);
double fU = Param.fURepeatCount * double(iA) / (SamplePointArray.length() - 1);
Batch.PushPoint(
DataPoint(
EachPointBegin.x, EachPointBegin.y, EachPointBegin.z,
EachSampleDirection.x, EachSampleDirection.y, EachSampleDirection.z,
fU, Param.fVRepeatCount * (double(i) / g_nSampleCount)
)
);
}
}
//终点
{
AcGeLine3d TangentLine;
Arc.tangent(EndPoint, TangentLine);
AcGeVector3d pt3dDirection = -TangentLine.direction();
AcGeVector3d PipeFirstSampleDirection = pt3dDirection.crossProduct(nrm).normal();
AcGePoint3d PipeFirstSamplePoint = EndPoint + PipeFirstSampleDirection * (Param.fD / 2);
for (int i = 0; i <= g_nSampleCount; ++i)
{
AcGeMatrix3d Trans;
Trans.setToRotation(i * fSampleAngleDiff, pt3dDirection, EndPoint);
AcGePoint3d EachPointEnd = PipeFirstSamplePoint;
EachPointEnd.transformBy(Trans);
AcGeVector3d EachSampleDirection = PipeFirstSampleDirection;
EachSampleDirection.transformBy(Trans);
double fU = Param.fURepeatCount * double(iA + 1) / (SamplePointArray.length() - 1);
Batch.PushPoint(
DataPoint(
EachPointEnd.x, EachPointEnd.y, EachPointEnd.z,
EachSampleDirection.x, EachSampleDirection.y, EachSampleDirection.z,
fU, Param.fVRepeatCount * (double(i) / g_nSampleCount)
)
);
}
}
//构造管线侧面三角形
{
int ArcSampleVertexIndexOffset = iA * (g_nSampleCount + 1);
int BeginEndVertexIndexOffset = g_nSampleCount;
for (int i = 0; i <= g_nSampleCount; ++i)
{
Batch.PushIndexFace(DataIndexFace(
ArcSampleVertexIndexOffset + i,
ArcSampleVertexIndexOffset + BeginEndVertexIndexOffset + i + 1,
ArcSampleVertexIndexOffset + BeginEndVertexIndexOffset + i));
Batch.PushIndexFace(DataIndexFace(
ArcSampleVertexIndexOffset + i,
ArcSampleVertexIndexOffset + i + 1,
ArcSampleVertexIndexOffset + BeginEndVertexIndexOffset + i + 1));
}
}
}
}
SubModel.BatchArray.push_back(Batch);
Model.ModelArray.push_back(SubModel);
}
//起点法兰
//{
// AcGePoint3d BeginPoint = Param.pt3dBegin;
// AcGePoint3d EndPoint = Param.pt3dCross;
// AcGeVector3d PipeOffset = EndPoint - BeginPoint;
// AcGeVector3d PipeDirection = PipeOffset.normal();
// EndPoint = BeginPoint + PipeDirection * Param.fFlange_Thickness;
// PipeOffset = EndPoint - BeginPoint;
// ParamFlange ParamF;
// ParamF.pt3dBegin = BeginPoint;
// P
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、实现几何计算来创建管道和弯头模型,然后将计算所得的点、法线、面索引转换为osg::Geometry及osg::Geode。支持纹理材质。不需要依赖建模三方库。 2、用户可以通过传入路径点进行管道的自动创建,包括弯头。 3、实现多条管道路径的路径动画模拟。
资源推荐
资源详情
资源评论
收起资源包目录
OSGPipePathAnimation.7z (9个子文件)
OSGPipePathAnimation
DataModel.h 16KB
GeometricModeling.h 2KB
OSGPathAnimationTest.vcxproj 8KB
GeometricModeling.cpp 14KB
OSGPathAnimationTest.vcxproj.filters 1KB
main.cpp 8KB
x64
Release
acge24.dll 1.49MB
OSGPathAnimationTest.exe 110KB
OSGPathAnimationTest.sln 1KB
共 9 条
- 1
资源评论
- wanghaiYang1212024-10-04资源内容详尽,对我有使用价值,谢谢资源主的分享。
- wang198689jian2024-06-27资源中能够借鉴的内容很多,值得学习的地方也很多,大家一起进步!
欧特克_Glodon
- 粉丝: 5w+
- 资源: 73
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术资料分享基于JPEG标准的图像处理及其在MCF5329上的实现很好的技术资料.zip
- 技术资料分享基于FPGA的JPEG解码算法的研究与实现很好的技术资料.zip
- 技术资料分享基于ENC28J60以太网控制器及其应用很好的技术资料.zip
- 技术资料分享基于ENC28J60的嵌入式网络接口的设计很好的技术资料.zip
- 技术资料分享基于ARM的嵌入式静态图像显示系统的研究与实现很好的技术资料.zip
- 技术资料分享关于STM32的IAP总结很好的技术资料.zip
- 技术资料分享高通CAMIF和Ov-sensor-调试总结很好的技术资料.zip
- 技术资料分享二阶RC滤波试验很好的技术资料.zip
- 技术资料分享多核处理器构架的高速JPEG解码算法很好的技术资料.zip
- 技术资料分享第24章 性能和资源占用很好的技术资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功