// Geode的Matrix 转换成IFC的TRS矩阵
bool DHWriteIfcObjectTrangle::ChangeGeoMatrixToIfcCTRS(osg::Matrixd mat, shared_ptr<IfcCartesianTransformationOperator3D> & pIfcCTRS)
{
if (!pIfcCTRS) {return false;}
if (mat.isIdentity())
{
pIfcCTRS.reset();
return true;
}
const osg::Vec3d & vScale = mat.getScale();
pIfcCTRS->m_Scale = shared_ptr<IfcReal>(new IfcReal(vScale.x()));
double* matData = mat.ptr();
shared_ptr<IfcCartesianPoint> pGeodeTrans(new IfcCartesianPoint(getIndexCount()));
InsertObject(pGeodeTrans);
{
const osg::Vec3d& vTrans = mat.getTrans();
shared_ptr<IfcLengthMeasure> pIfcLengthMeasure1(new IfcLengthMeasure(vTrans.x()));
pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure1);
shared_ptr<IfcLengthMeasure> pIfcLengthMeasure2(new IfcLengthMeasure(vTrans.y()));
pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure2);
shared_ptr<IfcLengthMeasure> pIfcLengthMeasure3(new IfcLengthMeasure(vTrans.z()));
pGeodeTrans->m_Coordinates.push_back(pIfcLengthMeasure3);
}
pIfcCTRS->m_LocalOrigin = pGeodeTrans;
shared_ptr<IfcDirection> pAxis1(new IfcDirection(getIndexCount()));
InsertObject(pAxis1);
{
shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 0* 4]/ vScale.x()));
shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 0* 4] / vScale.x()));
shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 0* 4] / vScale.x()));
pAxis1->m_DirectionRatios.push_back(Axisx);
pAxis1->m_DirectionRatios.push_back(Axisy);
pAxis1->m_DirectionRatios.push_back(Axisz);
}
pIfcCTRS->m_Axis1 = pAxis1;
shared_ptr<IfcDirection> pAxis2(new IfcDirection(getIndexCount()));
InsertObject(pAxis2);
{
shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 1* 4] / vScale.y()));
shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 1* 4] / vScale.y()));
shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 1* 4] / vScale.y()));
pAxis2->m_DirectionRatios.push_back(Axisx);
pAxis2->m_DirectionRatios.push_back(Axisy);
pAxis2->m_DirectionRatios.push_back(Axisz);
}
shared_ptr<IfcDirection> pAxis3(new IfcDirection(getIndexCount()));
InsertObject(pAxis3);
{
shared_ptr<IfcReal> Axisx(new IfcReal(matData[0 + 2* 4] / vScale.z()));
shared_ptr<IfcReal> Axisy(new IfcReal(matData[1 + 2* 4] / vScale.z()));
shared_ptr<IfcReal> Axisz(new IfcReal(matData[2 + 2* 4] / vScale.z()));
pAxis3->m_DirectionRatios.push_back(Axisx);
pAxis3->m_DirectionRatios.push_back(Axisy);
pAxis3->m_DirectionRatios.push_back(Axisz);
}
pIfcCTRS->m_Axis2 = pAxis2;
pIfcCTRS->m_Axis3 = pAxis3;
return true;
}
osg解析系列-osg中Geode的Matrix 转换成IFC的TRS矩阵 源码
于 2022-12-14 10:24:48 首次发布