#include "IEportModel.h"
IMPLEMENT_STANDARD_RTTIEXT(IEportModel,AIS_Shape)
IEportModel::IEportModel(const TopoDS_Shape &_shape)
:AIS_Shape(_shape),m_model_name("Unnamed"),m_model_type(MODEL_COMPONENT)
{}
IEportModel::IEportModel(const QString _filepath)
:AIS_Shape(TopoDS_Shape()),m_model_name("Unnamed"),m_model_type(MODEL_COMPONENT)
{
// 提取文件名字,作为模型名字
QString t_model_name = _filepath;
t_model_name.remove(QRegularExpression("(.*/)|([.].+)"));
m_model_name = t_model_name;
//从外部文件中加载模型
Importer t_importer;
const aiScene *t_scene=t_importer.ReadFile(_filepath.toStdString(),aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_CalcTangentSpace);
if(!t_scene || t_scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !t_scene->mRootNode) // if is Not Zero
{
qDebug() << "ERROR::ASSIMP:: " << t_importer.GetErrorString();
return;
}
// 构造根节点及所有子节点
m_process_nodes(t_scene->mRootNode, t_scene, true);
}
void IEportModel::m_process_nodes(const aiNode *_node, const aiScene *_scene, bool _is_root)
{
Graphic3d_MaterialAspect t_occ_material;
// [0] 模型名字信息
QString t_node_name = _node->mName.C_Str();
// [1] 坐标系信息
aiMatrix4x4 t_matrix=_node->mTransformation; // 获取转换坐标系
// 获取旋转矩阵的缩放比例
ai_real t_scaling_x = aiVector3D(t_matrix.a1,t_matrix.a2,t_matrix.a3).Length();
ai_real t_scaling_y = aiVector3D(t_matrix.b1,t_matrix.b2,t_matrix.b3).Length();
ai_real t_scaling_z = aiVector3D(t_matrix.c1,t_matrix.c2,t_matrix.c3).Length();
// 从 aiMatrix4x4 转换成 gp_Trsf 形式
gp_Trsf t_transfer;
t_transfer.SetValues(t_matrix.a1 / t_scaling_x, t_matrix.a2 / t_scaling_x, t_matrix.a3 / t_scaling_x, t_matrix.a4,
t_matrix.b1 / t_scaling_y, t_matrix.b2 / t_scaling_y, t_matrix.b3 / t_scaling_y, t_matrix.b4,
t_matrix.c1 / t_scaling_z, t_matrix.c2 / t_scaling_z, t_matrix.c3 / t_scaling_z, t_matrix.c4);
// [2] 拓扑形状信息
// 构造拓扑形状
BRepBuilderAPI_Sewing t_sewing_tool;
t_sewing_tool.Init (1.0e-06, Standard_True);
// 复合拓扑结构
TopoDS_Compound t_compound;
BRep_Builder t_build_tool;
t_build_tool.MakeCompound (t_compound);
TopoDS_Face t_topo_face; // 储存拓扑面
// 遍历节点的所有网格
for(unsigned int imesh = 0; imesh < _node->mNumMeshes; imesh++)
{
aiMesh* t_mesh = _scene->mMeshes[_node->mMeshes[imesh]]; // 获取当前网格
// 遍历网格的所有面
for(unsigned int iface = 0; iface < t_mesh->mNumFaces; iface++)
{
t_mesh->mMaterialIndex;
aiFace t_face = t_mesh->mFaces[iface];
BRepBuilderAPI_MakePolygon t_polygon;
// 遍历面的所有顶点
for(unsigned int ivertex = 0; ivertex < t_face.mNumIndices; ivertex++)
{
// 转换顶点储存模式
gp_Pnt t_pnt=gp_Pnt(t_mesh->mVertices[t_face.mIndices[ivertex]].x,
t_mesh->mVertices[t_face.mIndices[ivertex]].y,
t_mesh->mVertices[t_face.mIndices[ivertex]].z);
t_polygon.Add(t_pnt); // 添加顶点
}
t_polygon.Close(); // 闭合顶点
t_topo_face = BRepBuilderAPI_MakeFace (t_polygon); // 通过闭合的线构造面
if(!t_topo_face.IsNull())
{
t_build_tool.Add (t_compound, t_topo_face); // 将面加入到复合体中
}
}
// 材质信息
aiMaterial* material = _scene->mMaterials[t_mesh->mMaterialIndex]; //通过索引获取网格在环境中的材质
t_occ_material = m_material_transfer(material); // 从ASSIMP格式转换到OCC材质格式
}
t_sewing_tool.Load (t_compound);
t_sewing_tool.Perform();
TopoDS_Shape t_topo_shape = t_sewing_tool.SewedShape();
if (t_topo_shape.IsNull())
{
t_topo_shape = t_compound;
}
bool t_is_next_root = false; // 下一处理的节点是否根节点
// 分别处理根节点和子节点
if(_is_root)
{
// 根节点无形状、只有一个子节点、无孙节点
if(_node->mNumChildren == 1 && _node->mNumMeshes ==0 && _node->mChildren[0]->mNumChildren == 0)
{
t_is_next_root = true; // 将子节点提升为根节点
m_set_model_type(MODEL_COMPONENT);
}
else if(_node->mNumMeshes == 0)
{
TopoDS_Shape t_vertex_topo = BRepBuilderAPI_MakeVertex(t_transfer.TranslationPart());
SetShape(t_vertex_topo);
m_set_model_type(MODEL_COMP_GROUP);
}
else
{
SetShape(t_topo_shape); // 设置拓扑形状
}
SetLocalTransformation(t_transfer); // 设置模型位姿
SetMaterial(t_occ_material);
}
else
{
if(_node->mNumMeshes>0)
{
Handle(IEportModel) t_child = new IEportModel(t_topo_shape); // 设置拓扑形状
t_child->m_set_model_name(t_node_name); // 设置模型名字
t_child->SetLocalTransformation(t_transfer); // 设置模型位姿
t_child->SetMaterial(t_occ_material);
t_child->m_set_model_type(MODEL_COMPONENT);
AddChild(t_child); // 将以上模型作为本对象的子节点
}
else
{}
}
// 遍历子节点
for(unsigned int i = 0; i < _node->mNumChildren; i++)
{
m_process_nodes(_node->mChildren[i], _scene , t_is_next_root); // 构造子节点
}
}
Graphic3d_MaterialAspect IEportModel::m_material_transfer(aiMaterial *_material)
{// 模型材质转换,由ASSIMP转成OCC表示方式
// 声明并初始化OCC材质参数
Graphic3d_MaterialAspect t_result;
t_result.SetMaterialType(Graphic3d_MATERIAL_PHYSIC);
Quantity_Color t_occ_colors[Graphic3d_TypeOfReflection_NB];
t_occ_colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
t_occ_colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
t_occ_colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (1.0f, 1.0f, 1.0f));
Standard_ShortReal t_occ_shininess = 0.039f;
aiString name; // 材质名称 原始数据
if (AI_SUCCESS==aiGetMaterialString(_material,AI_MATKEY_NAME,&name))
{
t_result.SetMaterialName(name.C_Str());
}
// 环境光
aiColor4D ambient; // 环境光 原始数据
if(AI_SUCCESS ==aiGetMaterialColor(_material, AI_MATKEY_COLOR_AMBIENT, &ambient))
{
t_occ_colors[Graphic3d_TOR_AMBIENT]=Quantity_Color(ambient.r,ambient.g,ambient.b,Quantity_TOC_RGB);
t_result.SetAmbientColor(t_occ_colors[Graphic3d_TOR_AMBIENT]);
}
// 漫反射
aiColor4D diffuse; // 漫反射 原始数据
if(AI_SUCCESS ==aiGetMaterialColor(_material, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
{
t_occ_colors[Graphic3d_TOR_DIFFUSE]=Quantity_Color(diffuse.r,diffuse.g,diffuse.b,Quantity_TOC_RGB);
t_result.SetDiffuseColor(t_occ_colors[Graphic3d_TOR_DIFFUSE]);
}
// 镜面光
aiColor4D specular; // 镜面光 原始数据
if(AI_SUCCESS ==aiGetMaterialColor(_material, AI_MATKEY_COLOR_SPECULAR, &specular))
{
t_occ_colors[Graphic3d_TOR_SPECULAR]=Quantity_Color(specular.r,specular.g,specular.b,Quantity_TOC_RGB);
t_result.SetSpecularColor(t_occ_colors[Graphic3d_TOR_SPECULAR]);
}
// 反光度
float shininess; // 反光度 原始数据
if(AI_SUCCESS ==aiGetMaterialFloat(_material, AI_MATKEY_SHININESS, &shininess))
{
没有合适的资源?快使用搜索试试~ 我知道了~
Qt+OpenCASCADE三维建模平台
共94个文件
dll:66个
png:11个
cpp:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 5 下载量 143 浏览量
2024-03-08
23:02:06
上传
评论
收藏 18.05MB RAR 举报
温馨提示
Qt+OpenCASCADE三维建模平台,实现功能如下: 1、将OCC三维视图嵌入Qt,实现控件的封装方便使用; 2、封装建模类,可以实现常规三维建模。 详情地址:https://blog.csdn.net/m0_37251750/article/details/136573741
资源推荐
资源详情
资源评论
收起资源包目录
qt-occ-modeling-proj.rar (94个子文件)
qt-occ-modeling-proj
QOCCTModeling.pro 3KB
QOCCTModeling.vcxproj 15KB
data
mk_cone.png 16KB
mk_sphere.png 13KB
mk_torus.png 14KB
mk_box.png 9KB
mk_bottle.png 13KB
background.png 16KB
export.png 2KB
mk_pipe.png 1KB
import.png 2KB
mk_cylinder.png 6KB
main.cpp 500B
cmainwindow.h 1KB
release
TKIVtkDraw.dll 143KB
TKGeomAlgo.dll 3.4MB
TKIVtk.dll 181KB
TKExpress.dll 174KB
TKMesh.dll 579KB
TKSTL.dll 103KB
TKViewerTest.dll 1.09MB
TKernel.dll 1.5MB
TKCAF.dll 472KB
TKD3DHost.dll 61KB
TKD3DHostTest.dll 14KB
TKVRML.dll 440KB
TKXSDRAW.dll 292KB
TKTObj.dll 194KB
TKXCAF.dll 755KB
TKIGES.dll 2.48MB
assimp-vc142-mt.dll 5.25MB
TKMeshVS.dll 275KB
TKService.dll 913KB
TKG2d.dll 253KB
TKBinTObj.dll 58KB
TKCDF.dll 254KB
TKTObjDRAW.dll 46KB
TKMath.dll 1.46MB
TKBO.dll 1.9MB
TKV3d.dll 2.23MB
TKStdL.dll 218KB
TKSTEPBase.dll 1.35MB
TKLCAF.dll 595KB
TKBRep.dll 818KB
TKXSBase.dll 1.72MB
TKXMesh.dll 12KB
TKOpenGl.dll 1.18MB
TKShHealing.dll 2.33MB
TKDraw.dll 577KB
TKGeomBase.dll 3.52MB
QOCCTModeling.exe 250KB
TKBool.dll 3.22MB
TKVCAF.dll 178KB
TKRWMesh.dll 422KB
TKSTEPAttr.dll 1.05MB
TKXDECascade.dll 88KB
TKFeat.dll 1.03MB
TKXDEDRAW.dll 525KB
TKBin.dll 111KB
TKXDESTEP.dll 702KB
TKXmlTObj.dll 57KB
TKXml.dll 163KB
TKOpenGlTest.dll 67KB
TKPrim.dll 281KB
TKDCAF.dll 783KB
TKSTEP.dll 2.51MB
TKHLR.dll 840KB
TKXmlXCAF.dll 139KB
TKTopAlgo.dll 2.1MB
TKOffset.dll 1.77MB
TKQADraw.dll 1.75MB
TKBinXCAF.dll 112KB
TKSTEP209.dll 376KB
TKBinL.dll 237KB
TKG3d.dll 777KB
TKXDE.dll 81KB
TKStd.dll 569KB
TKTopTest.dll 1.57MB
Data
background.png 16KB
TKFillet.dll 1.99MB
TKXDEIGES.dll 157KB
TKXmlL.dll 320KB
OCCTWidget.h 3KB
OCCTWidget.cpp 6KB
cmainwindow.ui 5KB
QOCCTModeling.sln 1KB
OCCTModeling.cpp 9KB
QOCCTModeling.vcxproj.user 356B
cmainwindow.cpp 7KB
res.qrc 405B
QOCCTModeling.vcxproj.filters 4KB
OCCTModeling.h 2KB
IEportModel.cpp 15KB
IEportModel.h 3KB
共 94 条
- 1
资源评论
- weixin_430136252024-04-03感谢大佬分享的资源,对我启发很大,给了我新的灵感。
- vekingbear2024-04-20超赞的资源,感谢资源主分享,大家一起进步!
- lhwfriend2024-04-25感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
- daniel_wang_19832024-04-29资源不错,很实用,内容全面,介绍详细,很好用,谢谢分享。
- 2301_767926742024-03-18感谢大佬分享的资源给了我灵感,果断支持!感谢分享~
欧特克_Glodon
- 粉丝: 4w+
- 资源: 64
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功