OpenInventor实现三维模型的拖动
来源:互联网 发布:迅雷端口被屏蔽 编辑:程序博客网 时间:2024/06/05 01:16
OpenInventor是SGI公司开发的基于OpenGL的面向对象三维图形软件开发包。这里不多说,相必点击进来看的都是了解的。
本文主要介绍如何实现三维模型的拖动。本文中的模型是wrl格式的模型文件,通过SoVRMLGroup类进行读取,很多三维设计软件,比如SolidWorks,catia等都可以另存为该格式的文件。当然了,也可以是由open Inventor自带的内建的模型,比如SoCylinder,SoCone等之类的。
初始化:
this->selection = new SoSelection;
this->root = new SoSeparator;
root->ref();
selection->addChild(root);
searcher = new SoSearchAction;
selection->addSelectionCallback(selectionCB, this); selection->addDeselectionCallback(deselectionCB, this);myViewer = new SoQtExaminerViewer(ui.widget);myViewer->setSceneGraph(selection);myViewer->setBackgroundColor(SbColor(0.7,0.6,0.92));myViewer->viewAll();myViewer->show();
打开模型文件,并加入到场景中
void Select_Drag::openModel()
{
SoSeparator *tmpRoot = new SoSeparator;
tmpRoot->ref();
tmpRoot->setName(“Root_tmp”);
SoTransform *tmpTrans = new SoTransform;
tmpTrans->setName(“Trans”);
tmpRoot->addChild(tmpTrans);
QString filename = QFileDialog::getOpenFileName(this,"Open VRML file","/","VRML files(*.wrl)");if(filename != NULL){ SoInput myInput; if(!myInput.openFile(filename.toStdString().data())) { qDebug()<<"file read failed!"; return; } SoVRMLGroup *objectModel = SoDB::readAllVRML(&myInput); objectModel->setName("VRMLModel"); tmpRoot->addChild(objectModel); root->addChild(tmpRoot); myViewer->viewAll();}
}
关键部分代码
void Select_Drag::deselectionCB(void * userdata, SoPath * deselection)
{
isDragged = false;
Select_Drag *s = (Select_Drag *)userdata;SoPath * transform = s->findRelatedTransform(s,deselection); assert(transform != NULL); SoTransformManip * manip = (SoTransformManip *) transform->getTail();SoTransform *tmpTrans = new SoTransform;SbVec3f pos = manip->translation.getValue();tmpTrans->translation.setValue(pos[0],pos[1],pos[2]);manip->replaceManip(transform, tmpTrans); qDebug()<<pos[0]*1000<<" "<<pos[1]*1000<<" "<<pos[2]*1000<<"\n";
}
void Select_Drag::selectionCB(void * userdata, SoPath * selection)
{
Select_Drag s = (Select_Drag )userdata;
SoPath * transform = s->findRelatedTransform(s,selection);
assert(transform != NULL);
SoTransformBoxManip * manip = new SoTransformBoxManip;
manip->replaceNode(transform);
///增加传感器节点,实时感知模型位姿变化SoFieldSensor *mySensor = new SoFieldSensor(positionChangedCB,manip);mySensor->attach(&manip->translation);SoFieldSensor *mySensor2 = new SoFieldSensor(rotationChangedCB,manip);mySensor2->attach(&manip->rotation);isDragged = true;s->timer->start();
}
SoPath Select_Drag::findRelatedTransform(void userdata,SoPath * pathtocube)
{
Select_Drag s = (Select_Drag )userdata;
SoSearchAction *sear = s->searcher;
sear->reset();
sear->setInterest(SoSearchAction::LAST);
sear->setType(SoTransform::getClassTypeId());
sear->apply(pathtocube);
return sear->getPath();
}
原创,不可侵权!
- OpenInventor实现三维模型的拖动
- 三维模型的数据格式
- 【iOS】用Layer创建一个三维模型以及拖动
- 在VB环境中操作三维模型的实现方法
- 在VB环境中操作三维模型的实现方法
- 使用矩阵和四元数实现三维模型的空间定位
- 三维模型自动添加支撑的几种实现思路
- OpenGL 三维模型的导入
- 三维模型的网格细化
- 纠结的三维模型格式
- 三维模型的网格细化
- 三维模型的网格细化
- 三维模型的网格细化
- 三维模型的网格细化
- 三维模型的网格细化
- 三维模型的normal map
- OpenInventor三维图形建模开发软件包
- 三维高斯模型 opencv实现
- Thinking in java Chapter11
- 三个数从小到大排序
- 数据结构课程总结
- 动态规划:最长子序列问题
- react-native-splash-screen--RN 0.5以上报错集合
- OpenInventor实现三维模型的拖动
- myeclipse安装后需要修改的配置
- 天津讨债要债公司联系13125821917联系13125821917,不成功不收费不成功不收费
- 爱壁纸的简单批量下载--Python
- Android-指定路径创建 SQLite
- Laravel5.5源码详解 -- 中间件MiddleWare分析
- AI编程员系统多次迭代自主编程,首次完爆初级程序员
- 使用 Spring Data JPA 简化 JPA 开发
- 【EasyUI】输入框box、linkbutton、menubutton、提示控件