Changeset ee088cb in OpenModelica
- Timestamp:
- 2023-03-27T11:28:24+02:00 (13 months ago)
- Children:
- e757cda7
- Parents:
- 740a8c7
- git-author:
- anotheruserofgithub <96748782+anotheruserofgithub@…> (03/09/23 06:52:36)
- git-committer:
- anotheruserofgithub <96748782+anotheruserofgithub@…> (03/27/23 11:28:24)
- Location:
- OMEdit/OMEditLIB/Animation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
OMEdit/OMEditLIB/Animation/AnimationUtil.h
r6814223c ree088cb 140 140 } 141 141 142 143 142 inline bool stlFileType(const std::string& typeName) 144 143 { 145 144 return typeName.substr(typeName.size()-3) == std::string("stl"); 145 } 146 147 inline bool objFileType(const std::string& typeName) 148 { 149 return typeName.substr(typeName.size()-3) == std::string("obj"); 150 } 151 152 inline bool tdsFileType(const std::string& typeName) 153 { 154 return typeName.substr(typeName.size()-3) == std::string("3ds"); 146 155 } 147 156 -
OMEdit/OMEditLIB/Animation/Visualization.cpp
r740a8c7 ree088cb 42 42 #include <osg/GL> // for having direct access to glClear() 43 43 44 #include <osg/Array> 44 45 #include <osg/Drawable> 45 46 #include <osg/Shape> … … 332 333 } else if (stlFileType(shape._fileName)) { 333 334 shape._type = "stl"; 335 } else if (objFileType(shape._fileName)) { 336 shape._type = "obj"; 337 } else if (tdsFileType(shape._fileName)) { 338 shape._type = "3ds"; 334 339 } 335 340 } … … 792 797 for (ShapeObject& shape : relevantShapes) { 793 798 // Consider OpenSceneGraph shape drawables only 794 if (shape._type.compare("dxf") == 0 || shape._type.compare("stl") == 0) { 799 if (shape._type.compare("dxf") == 0 || shape._type.compare("stl") == 0 || 800 shape._type.compare("obj") == 0 || shape._type.compare("3ds") == 0) { 795 801 continue; 796 802 } … … 1282 1288 transf->setName(shape._id); 1283 1289 1284 if (shape._type.compare("stl") == 0) 1285 { //cad node 1290 if (shape._type.compare("obj") == 0 or shape._type.compare("3ds") == 0) 1291 { //advanced cad node 1292 //std::cout<<"It's an advanced cad and the filename is "<<shape._fileName<<std::endl; 1293 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(shape._fileName); 1294 if (node.valid()) 1295 { 1296 osg::ref_ptr<CADFile> cad = new CADFile(node.get()); 1297 1298 transf->addChild(cad.get()); 1299 } 1300 } 1301 else if (shape._type.compare("stl") == 0) 1302 { //stl node 1286 1303 //std::cout<<"It's a stl and the filename is "<<shape._fileName<<std::endl; 1287 1304 // Disable mesh optimization because it is too expensive (see OSG commit a082b57) … … 1413 1430 { 1414 1431 ShapeObject* shape = _visualizer->asShape(); 1415 if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) 1432 if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0 or 1433 shape->_type.compare("obj") == 0 or shape->_type.compare("3ds") == 0) 1416 1434 { 1417 1435 //it's a cad file so we have to rescale the underlying geometry vertices … … 1546 1564 osg::ref_ptr<osg::StateSet> stateSet = nullptr; 1547 1565 bool geometryColors = false; 1566 bool is3DSShape = false; 1548 1567 1549 1568 if (_visualizer->isShape()) { 1550 1569 ShapeObject* shape = _visualizer->asShape(); 1551 if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) { 1570 if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0 or 1571 shape->_type.compare("obj") == 0 or shape->_type.compare("3ds") == 0) { 1552 1572 osg::ref_ptr<osg::Transform> transformNode = shape->getTransformNode(); 1553 1573 if (transformNode.valid() && transformNode->getNumChildren() > 0) { … … 1556 1576 stateSet = cad->getOrCreateStateSet(); 1557 1577 geometryColors = !shape->getVisualProperties()->getColor().custom(); 1578 is3DSShape = shape->_type.compare("3ds") == 0; 1558 1579 } 1559 1580 } … … 1577 1598 changeTransparencyOfMaterial(ss, transparency); 1578 1599 if (geometryColors) { 1579 changeTransparencyOfGeometry(node, transparency); 1580 } 1581 } 1600 if (is3DSShape) { 1601 changeTransparencyOfGeometry<osg::Vec4ubArray, 255>(node, transparency); 1602 } else { 1603 changeTransparencyOfGeometry<osg::Vec4Array, 1> (node, transparency); 1604 } 1605 } 1606 } 1607 1582 1608 if (changeTexture) { 1583 1609 //set texture … … 1700 1726 * changes transparency of a geode's geometry 1701 1727 */ 1728 template<typename Vec4Array, unsigned int scale> 1702 1729 void UpdateVisitor::changeTransparencyOfGeometry(osg::Geode& geode, const float transparency) 1703 1730 { 1704 osg::Vec4::value_type opacity = 1.0 - transparency; 1731 using Vec4 = typename Vec4Array::ElementDataType; 1732 using type = typename Vec4::value_type; 1733 type opacity = (1.0 - transparency) * scale; 1705 1734 unsigned int num = geode.getNumDrawables(); 1706 1735 for (unsigned int i = 0; i < num; i++) { … … 1709 1738 osg::Geometry* geometry = drawable->asGeometry(); 1710 1739 if (geometry) { 1711 osg::Vec4Array* colors = dynamic_cast<osg::Vec4Array*>(geometry->getColorArray());1740 Vec4Array* colors = dynamic_cast<Vec4Array*>(geometry->getColorArray()); 1712 1741 if (colors) { 1713 for ( osg::Vec4& color : colors->asVector()) {1742 for (Vec4& color : colors->asVector()) { 1714 1743 color.a() = opacity; 1715 1744 } … … 1862 1891 1863 1892 osg::Matrix3 T0; 1864 if (type == " stl" || type == "dxf")1893 if (type == "dxf" || type == "stl" || type == "obj" || type == "3ds") 1865 1894 { 1866 1895 T0 = osg::Matrix3(dirs._lDir[0], dirs._lDir[1], dirs._lDir[2], -
OMEdit/OMEditLIB/Animation/Visualization.h
r740a8c7 ree088cb 100 100 void changeColorOfMaterial(osg::StateSet* ss, const osg::Material::ColorMode mode, const QColor color, const float specular); 101 101 void changeTransparencyOfMaterial(osg::StateSet* ss, const float transparency); 102 template<typename Vec4Array, unsigned int scale> 102 103 void changeTransparencyOfGeometry(osg::Geode& geode, const float transparency); 103 104 public:
Note: See TracChangeset
for help on using the changeset viewer.