void Entity3D::add3DModel() {
QString path = _entity->getEntityInfo(EIC_3D_MODEL).toString();
std::string modelPath = path.toLocal8Bit().data();
osg::ref_ptr<osg::Node> nodeFile = osgDB::readNodeFile(modelPath);
osg::ref_ptr<osg::MatrixTransform> nodeMt = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> nodeMtR = new osg::MatrixTransform;
nodeMt->addChild(nodeMtR);
osg::ref_ptr<osg::MatrixTransform> nodeMtS = new osg::MatrixTransform;
nodeMtR->addChild(nodeMtS);
nodeMtS->addChild(nodeFile);
EarthMapMgr()->getModelRoot()->addChild(nodeMt);
osg::Matrix m;
EarthMapMgr()->getMapNode()->getMapSRS()->getEllipsoid()->computeLocalToWorldTransformFromLatLongHeight(
osg::DegreesToRadians(_entity->getLat()),
osg::DegreesToRadians(_entity->getLon()),
_entity->getAlt(),
m);
nodeMt->setMatrix(m);
nodeMt->addDescription("model-3d");
#if 0
nodeMt->getOrCreateStateSet()->setMode(GL_LIGHT0, osg::StateAttribute::ON);
nodeMt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
nodeMt->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
#endif
nodeMt->getOrCreateStateSet()->setMode(GL_LIGHT1, osg::StateAttribute::ON);
nodeMt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
nodeMt->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
nodeMt->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
nodeMtS->setMatrix(osg::Matrix::scale(_scale, _scale, _scale));
_entityNode = nodeMt;
}
}
void Entity3D::createLabel(std::string label, double fontSize) {
osg::ref_ptr<osgText::Text> textPtr = new osgText::Text;
textPtr->setFont("./Map/3D/fonts/simsun.ttc");
textPtr->setCharacterSize(fontSize);
QString context = QString::fromLocal8Bit(label.data());
textPtr->setText(context.toStdString(), osgText::String::Encoding::ENCODING_UTF8);
osg::ref_ptr<osg::Geode> geodePtr = new osg::Geode;
geodePtr->addDrawable(textPtr);
osg::ref_ptr<osg::AutoTransform> nodeAT = new osg::AutoTransform;
nodeAT->setAutoRotateMode(osg::AutoTransform::AutoRotateMode::ROTATE_TO_SCREEN);
nodeAT->setAutoScaleToScreen(true);
nodeAT->setMinimumScale(1.0);
nodeAT->addChild(geodePtr);
osg::MatrixTransform* mt = dynamic_cast<osg::MatrixTransform*>(_entityNode.get());
osg::MatrixTransform* mtR = dynamic_cast<osg::MatrixTransform*>(mt->getChild(0));
osg::MatrixTransform* mtS = dynamic_cast<osg::MatrixTransform*>(mtR->getChild(0));
mtS->addChild(nodeAT);
}