inventor,Basic Ope Inventor

1、大数计算引起的一个问题
如果scene graph中有距离原点(0,0,0)比较大的位置,则矩阵计算引入的误差可能就比较大,由此带来的常见现象是:平移scene graph有晃动,甚至很厉害,而本不该晃动(当camera靠近观察scene graph中的某个node时更明显);场景中的polygon面上有白光闪烁等等。
解决此类问题的一个可行做法是对原始(大)数据做一个线性映射,映射到一个靠近原点的位置,然后计算,减小误差。

2、关于PoGroup6Axis3的使用
PoGroup6Axis3是MeshViz提供的一个SoBaseKit,它有一点特殊:它包含6个同样是SoBaseKit的PoLinearAxis。所以当你需要设置回调函数(比如addPostRebuildCallback)更改默认设置的时候,不要对PoGroup6Axis3本身设置回调函数,而要以其中特定的PoLinearAxis为对象设置,否则很可能达不到你要的效果。
PoGroup2Axis、PoGroup4Axis等axis节点也是如此。
1、继承自SoBaseKit的各个类,都可以通过setPart把某个part设置为NULL,即移除该节点。对于MeshViz类内的SoBaseKit子类,移除某个part后,内部rebuild(比如重新设置了某些field),已经移除的某个part可以再次创建出来并显示。
解决此问题的办法就是在rebuild的回调函数中调用setPart,设置MeshViz中的回调通常是利用函数addPostRebuildCallback,而不是利用SoCallback::setCallback。

13、RGBA texture如何影响object的颜色
文字性的说明总没有公式表达的清楚、正确。更加详细内容的可以参考OpenGL的manual。
约定:纹理的颜色、透明度为(texColor, texAlpha);object的颜色、透明度为(objColor, objAlpha);则不同的模式对应的颜色结果如下:
REPLACE:(texColor,                                         texAlpha)
MODULATE:(texColor*objColor, texAlpha*objAlpha)
ADD:(texColor+objColor, texAlpha*objAlpha)
DECAL:(texColor*texAlpha+objColor*(1-texAlpha), objAlpha)
BLEND:(texColor*blendColor+objColor*(1-blendColor), texAlpha*objAlpha)
12、reference count
SoCamera::viewAll内部会使用SoGetBoundingBoxAction对参数节点计算bounding box,调用该函数前注意设置参数节点的reference count。
11、事件处理
a、SoHandleEventAction
OIV默认处理方式。
b、SoEventCallback
如果默认的处理方式不能满足需求,或者说你想添加其他操作,可以使用这种方式。
该方式处理特定的事件、特定的path(如果指定的话)。
通过SoEventCallback可以获得SoHandleEventAction实例:SoHandleEventAction* SoEventCallback::getAction();SoEventCallback成员函数的功能幕后大多是由SoHandleEventAction来完成的。
c、SoCallback
处理action事件。
d、XRenderArea::setEventCallback
系统相关的一种实现(比如对于qt component,event是QEvent),其他三种方式均与系统无关。
该方式通过注册回调函数处理特定的事件。回调函数的返回值(可以理解为事件是否处理了)决定了SoHandleEventAction是否接手继续处理。
Q events that occur in the render area can be handled by the application, by the viewer (if this is really a viewer), or by the nodes in the scene graph. When a event occurs, it is first passed to the application event callback function registered with the setEventCallback() method _disibledevent=>    lighting->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
    lighting->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
    
与颜色、灯光相关的另外一个类是SoLightModel:它的BASE_COLOR model特别适合于一个较小的scene graph中,比如一个shape node,它使该node看起来更亮,从正反两个方向观察亮度差别不大。
6、node search
SoNode::getByName函数:
    应用在OIV创建的每一个节点上,无论该节点是否位于某个scene graph上;
    只要在搜索时刻,该节点依然存在,就能搜索到,即真正的全局搜索。
    只能按照name搜索。
    
SoSearchAction:
    应用在一个scene graph上,搜索整个子scene graph。
    可以按照name、type和特定node(实际地址)搜索,返回path。
    
SoGroup::findChild:
    搜索特定node(实际地址),返回index;
    只能搜索group节点的直接子node,不能搜索子node的子node,即不能隔层搜索。
    
搜索范围:SoNode::getByName > SoSearchAction > SoGroup::findChild。
SoShapeHints *shapeHints = new SoShapeHints;
shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; // not SOLID
5、stereo viewing
http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node13.html
Stereo viewing is a common technique to increase visual realism or enhance user interaction with 3D scenes. Two views of a scene are created, _disibledevent=>    设置第一个数据,删除其余数据,即:能够自动释放存储空间,设值后空间大小为1。
    
如果需要设置多个值,使用setValues和startEditing/endEditing(而非反复调用set1Value)则更有效。
startEditing/endEditing修改过程中,不会notify连接到该field的field、sensor和engine,直到finish;代码片段示例如下:  
    uint32_t *colors = MeshVtxProp->orderedRGBA.startEditing();
    for(int i = 0; i < MeshSize; ++i)
    {
        // reference manual中提到,在editing的过程中,调用该field的其他edit函数,如set1Value(),setValue(),非法;
        // 经测试,调用set1Value还是允许的。
        // 保险起见,还是直接操作返回的指针(此处的colors,使用colors[id])吧!
        colors[lineInd+j] = stripColor;
        // ...
    }
    MeshVtxProp->orderedRGBA.finishEditing() ;
2、traversal state
For each action, the database mananges a traversal state, which is a collection of elements or parameters in the action at a given time.
即:首先根据action得到其state;然后利用特定的element获取对应的state。获取traversal state信息总是出现在回调函数中。
获取traversal state的一种方法:
SoState *state = action->getState();
SbViewportRegion vport = SoViewportRegionElement::get(state);
SbMatrix viewMat = SoViewingMatrixElement::get(state);
常见的element以及相关state:
SoViewingMatrixElement:the current viewing matrix。
SoProjectionMatrixElement:the current projection matrix。
SoLazyElement:material,transparency,light model,blend enalbement。
SoViewportRegionElement:the current viewport region。
SoEnvironmentElement:ambient intensity,ambient color,attenuation,fog。
另外,一个有价值的参考是SoCallbackAction:Most of the methods _disibledevent=>    this->scene = newSceneGraph
    if newSceneGraph:
        newSceneGraph->ref()
    if oldSceneGraph:
        oldSceneGraph->unref()
所以说,如果oldSceneGraph后续还要使用,务必在setSceneGraph前调用:oldSceneGraph->ref()。这点与action的apply函数比较像。

Tags:  inventor

延伸阅读

最新评论

发表评论