⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertfrominventor.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    // Pop the state if the group is a Separator    if (node->isOfType(SoSeparator::getClassTypeId()))    {        thisPtr->soTexStack.pop();        thisPtr->lightStack.pop();    }     return SoCallbackAction::CONTINUE;}////////////////////////////////////////////////////////////SoCallbackAction::Response ConvertFromInventor::postLOD(void* data, SoCallbackAction *,                              const SoNode* node){#ifdef DEBUG_IV_PLUGIN    osg::notify(osg::INFO) << "postLOD()    "               << node->getTypeId().getName().getString() << std::endl;#endif    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    // Inventor and OSG LOD node    SoLOD *ivLOD = (SoLOD *) node;    osg::LOD *lod = dynamic_cast<osg::LOD*>(thisPtr->groupStack.top());    // Get the center of LOD and set it    SbVec3f ivCenter = ivLOD->center.getValue();    lod->setCenter(osg::Vec3(ivCenter[0], ivCenter[1], ivCenter[2]));    // Verify the number of children and range values    int num = thisPtr->groupStack.top()->getNumChildren();    if (ivLOD->range.getNum()+1 != num && !(num == 0 && ivLOD->range.getNum() == 0)) {        osg::notify(osg::WARN) << "IV import warning: SoLOD does not "            << "contain correct data in range field." << std::endl;        if (ivLOD->range.getNum()+1 < num) {            thisPtr->groupStack.top()->removeChildren(ivLOD->range.getNum() + 1,                                                      num - ivLOD->range.getNum() - 1);            num = ivLOD->range.getNum() + 1;        }    }    // Get the ranges and set it    if (num > 0) {        if (num == 1)            lod->setRange(0, 0.0, FLT_MAX);        else {            lod->setRange(0, 0.0, ivLOD->range[0]);            for (int i = 1; i < num-2; i++)                lod->setRange(i, ivLOD->range[i-1], ivLOD->range[i]);            lod->setRange(num-1, ivLOD->range[num-2], FLT_MAX);        }    }    // Pop the group from the stack    thisPtr->groupStack.pop();    return SoCallbackAction::CONTINUE;}/////////////////////////////////////////////////////////////SoCallbackAction::Response ConvertFromInventor::preRotor(void* data, SoCallbackAction *,                               const SoNode* node){#ifdef DEBUG_IV_PLUGIN    osg::notify(osg::INFO) << "preRotor()  "               << node->getTypeId().getName().getString() << std::endl;#endif    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    // Get the parameters for the inventor Rotor    SoRotor *ivRotor = (SoRotor *) node;    SbVec3f ivAxis;    float angle;    ivRotor->rotation.getValue(ivAxis, angle);    // Create a new osg::MatrixTransform    osg::ref_ptr<osg::MatrixTransform> rotorTransform = new osg::MatrixTransform;        // Create a Rotor Callback equivalent to the inventor Rotor    osg::Vec3 pivot(0, 0, 0);    osg::Vec3 axis(ivAxis[0], ivAxis[1], ivAxis[2]);    osg::ref_ptr<osgUtil::TransformCallback> rotorCallback         = new osgUtil::TransformCallback(pivot, axis,                                          2 * osg::PI * ivRotor->speed.getValue());    // Set the app callback    rotorTransform->setUpdateCallback(rotorCallback.get());        // Push the rotor transform onto the group stack    thisPtr->groupStack.top()->addChild(rotorTransform.get());    thisPtr->groupStack.push(rotorTransform.get());    return SoCallbackAction::CONTINUE;}////////////////////////////////////////////////////////////////SoCallbackAction::Response ConvertFromInventor::prePendulum(void* data, SoCallbackAction *,                                  const SoNode* node){#ifdef DEBUG_IV_PLUGIN    osg::notify(osg::INFO) << "prePendulum()  "               << node->getTypeId().getName().getString() << std::endl;#endif    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    // Get the parameters for the inventor Pendulum    SoPendulum *ivPendulum = (SoPendulum *) node;    SbVec3f ivAxis0, ivAxis1;    float startAngle, endAngle;    ivPendulum->rotation0.getValue(ivAxis0, startAngle);    ivPendulum->rotation1.getValue(ivAxis1, endAngle);    // Create a new osg::MatrixTransform    osg::ref_ptr<osg::MatrixTransform> pendulumTransform = new osg::MatrixTransform;        // Create a Pendulum Callback equivalent to the inventor Rotor    osg::Vec3 axis(ivAxis0[0], ivAxis0[1], ivAxis0[2]);    PendulumCallback* pendulumCallback         = new PendulumCallback(axis, startAngle, endAngle,                               ivPendulum->speed.getValue());    // Set the app callback    pendulumTransform->setUpdateCallback(pendulumCallback);        // Push the pendulum transform onto the group stack    thisPtr->groupStack.top()->addChild(pendulumTransform.get());    thisPtr->groupStack.push(pendulumTransform.get());    return SoCallbackAction::CONTINUE;}////////////////////////////////////////////////////////////////SoCallbackAction::Response ConvertFromInventor::preShuttle(void* data, SoCallbackAction *,                                 const SoNode* node){#ifdef DEBUG_IV_PLUGIN    osg::notify(osg::INFO) << "preShuttle()  "               << node->getTypeId().getName().getString() << std::endl;#endif    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    // Get the parameters for the inventor Shuttle    SoShuttle *ivShuttle = (SoShuttle *) node;    SbVec3f ivStartPos, ivEndPos;    ivStartPos = ivShuttle->translation0.getValue();    ivEndPos = ivShuttle->translation1.getValue();    // Create a new osg::MatrixTransform    osg::ref_ptr<osg::MatrixTransform> shuttleTransform = new osg::MatrixTransform;        // Create a shuttle Callback equivalent to the inventor Rotor    osg::Vec3 startPos(ivStartPos[0], ivStartPos[1], ivStartPos[2]);    osg::Vec3 endPos(ivEndPos[0], ivEndPos[1], ivEndPos[2]);    ShuttleCallback* shuttleCallback         = new ShuttleCallback(startPos, endPos, ivShuttle->speed.getValue());    // Set the app callback    shuttleTransform->setUpdateCallback(shuttleCallback);        // Push the shuttle transform onto the group stack    thisPtr->groupStack.top()->addChild(shuttleTransform.get());    thisPtr->groupStack.push(shuttleTransform.get());    return SoCallbackAction::CONTINUE;}////////////////////////////////////////////////////////////void ConvertFromInventor::addVertex(SoCallbackAction* action,                                    const SoPrimitiveVertex *v,                                     int index){    // Get the coordinates of the vertex    SbVec3f pt = v->getPoint();    vertices.push_back(osg::Vec3(pt[0], pt[1], pt[2]));    // Get the normal of the vertex    SbVec3f norm = v->getNormal();    if ((normalBinding == osg::Geometry::BIND_PER_VERTEX) ||        (normalBinding == osg::Geometry::BIND_PER_PRIMITIVE && index == 0))    {        if (vertexOrder == CLOCKWISE)            normals.push_back(osg::Vec3(-norm[0], -norm[1], -norm[2]));        else            normals.push_back(osg::Vec3(norm[0], norm[1], norm[2]));    }    if (colorBinding == osg::Geometry::BIND_PER_VERTEX ||            colorBinding == osg::Geometry::BIND_PER_PRIMITIVE)    {        // Get the material/color         SbColor ambient, diffuse, specular, emission;        float transparency, shininess;        action->getMaterial(ambient, diffuse, specular, emission, shininess,                             transparency, v->getMaterialIndex());        if (colorBinding == osg::Geometry::BIND_PER_VERTEX)            colors.push_back(osg::Vec4(diffuse[0], diffuse[1], diffuse[2],                                       1.0 - transparency));        else if (colorBinding == osg::Geometry::BIND_PER_PRIMITIVE && index == 0)            colors.push_back(osg::Vec4(diffuse[0], diffuse[1], diffuse[2],                                       1.0 - transparency));    }    // Get the texture coordinates    SbVec4f texCoord = v->getTextureCoords();    textureCoords.push_back(osg::Vec2(texCoord[0], texCoord[1]));}////////////////////////////////////////////////////////////////////////////void ConvertFromInventor::addMatrixTransform(const std::string& name, SbVec3f axis, float angle, SbVec3f center, SbVec3f trans, SbVec3f scale){    osg::Matrix mat;    if (trans.length() != 0.0 || name != "")    {        mat.makeIdentity();        mat.setTrans(trans[0], trans[1], trans[2]);        osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform(mat);        if (name != "") {            std::string name2 = name;            name2 += "_t";            mt->setName(name2);        }        groupStack.top()->addChild(mt.get());        groupStack.push(mt.get());    }    if (center.length() != 0.0) {        mat.makeIdentity();        mat.setTrans(center[0], center[1], center[2]);        osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform(mat);        groupStack.top()->addChild(mt.get());        groupStack.push(mt.get());    }    if (angle != 0.0 || name != "")    {        osg::Quat q(angle, osg::Vec3f(axis[0], axis[1], axis[2]));        mat.makeIdentity();        mat.setRotate(q);         osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform(mat);        if (name != "") {            std::string name2 = name;            name2 += "_r";            mt->setName(name2);        }        groupStack.top()->addChild(mt.get());        groupStack.push(mt.get());    }    if (center.length() != 0.0) {        center.negate();        mat.makeIdentity();        mat.setTrans(center[0], center[1], center[2]);        osg::ref_ptr<osg::MatrixTransform>  mt = new osg::MatrixTransform(mat);        groupStack.top()->addChild(mt.get());        groupStack.push(mt.get());    }    if (scale[0] != 1.0 || scale[1] != 1.0 || scale[2] != 1.0)    {        mat.makeIdentity();        mat.makeScale(scale[0], scale[1], scale[2]);        osg::ref_ptr<osg::MatrixTransform>  smt = new osg::MatrixTransform(mat);        groupStack.top()->addChild(smt.get());        groupStack.push(smt.get());    }}////////////////////////////////////////////////////////////////////////////void ConvertFromInventor::addTriangleCB(void* data, SoCallbackAction* action,                                        const SoPrimitiveVertex* v0,                                        const SoPrimitiveVertex* v1,                                        const SoPrimitiveVertex* v2){    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);        switch (thisPtr->vertexOrder)    {        case CLOCKWISE:            thisPtr->addVertex(action, v0, 0);            thisPtr->addVertex(action, v2, 1);            thisPtr->addVertex(action, v1, 2);            break;        case COUNTER_CLOCKWISE:            thisPtr->addVertex(action, v0, 0);            thisPtr->addVertex(action, v1, 1);            thisPtr->addVertex(action, v2, 2);            break;    }    thisPtr->numPrimitives++;    thisPtr->primitiveType = osg::PrimitiveSet::TRIANGLES;}////////////////////////////////////////////////////////////////////////////////void ConvertFromInventor::addLineSegmentCB(void* data, SoCallbackAction* action,                                           const SoPrimitiveVertex* v0,                                           const SoPrimitiveVertex* v1){    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    thisPtr->addVertex(action, v0, 0);    thisPtr->addVertex(action, v1, 1);    thisPtr->numPrimitives++;    thisPtr->primitiveType = osg::PrimitiveSet::LINES;}//////////////////////////////////////////////////////////////////////////void ConvertFromInventor::addPointCB(void* data, SoCallbackAction* action,                                     const SoPrimitiveVertex* v0){    ConvertFromInventor* thisPtr = (ConvertFromInventor *) (data);    thisPtr->addVertex(action, v0, 0);    thisPtr->numPrimitives++;    thisPtr->primitiveType = osg::PrimitiveSet::POINTS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -