最后修改时间:
2009-9-22
适用OIV版本:
7.2
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 on SoQtRenderArea. If this function does not exist or returns FALSE, the Q event is either used directly by the viewer or translated to an SoEvent for further scene graph processing. If the viewer does not handle the event, and an overlay scene graph exists, the SoEvent is sent to that scene graph by way of an SoHandleEventAction. If no node in the overlay scene graph handles the event (i.e., calls setHandled() on the SoHandleEventAction), the SoEvent is passed to the normal scene graph in the same manner.
10、show/hide node的两种方法
a、SoGroup::addChild、SoGroup::removeChild;
b、SoSwitch;
经过简单测试:
add、remove会比SoSwitch速度快一些,同时SoSwitch还可能会多使用一个node(SoSwitch)的存储空间;
但是addChild会添加一个已经存在的node而没有任何提示,这通常不是想要的功能,所以在addChild前通常要判定目标node是否已经在SoGroup中,以保证只有一份node存在;此时,第一种方法速度上的优势就没有了,通常会更慢。
总之,如果你能保证不会添加同一node到SoGroup多次,请使用addChild和removeChild,既快又经济;否则,请使用SoSwitch。
补充一句:remove一个不在SoGroup中的node,会弹出oiv的error console window。
8、Adds application push button(以Qt为例):
viewer->addAppPushButton(new QPushButton(viewer->getAppPushButtonParent()))
7、double-sided lighting
SoVertexShape子类对象,如果是“面”的话,默认情况下是单面光照的,即有一面是暗的,如果要启用双面光照,可以在其前加入一个SoShapeHints:
SoShapeHints *lighting = new SoShapeHints;
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, one for the left eye, one for the right. Some sort of viewing hardware is used with the display, so each eye only sees the view created for it. The apparent depth of objects is a function of the difference in their positions from the left and right eye views. When done properly, objects appear to have actual depth, especially with respect to each other. When animating, the left and right back buffers are used, and must be updated each frame.
4、overlay plane
from IBM:
Graphical overlay planes are made up of additional memory positioned logically on top of the frame buffer (thus the name overlay). Typically, graphics applications would use this extra hardware for creating windows that would not disturb the contents of existing windows in the frame buffer.
The primary goals for implementing this feature are:
* To reduce the need for redrawing underlying complex images while the user is navigating through the user interface.
* To allow simple images, such as annotations, to be written over underlying images without overwriting the images.
from The Inventor Mentor:
The overlay planes are a separate set of bitplanes that can be used for special purposes in Inventor. The overlay planes are typically used for objects in the scene that appear on top of the main image and are redrawn independently. Although you are limited with respect to color and complexity of the scene graph placed in the overlay planes, using them enables you to quickly redraw a simple scene graph without having to redraw the “complete” scene graph.
3、Multiple-Value Fields: Setting and Getting Values
set1Value和setValues:
设置参数指定位置的值,同时保留其余各值,即不会自动释放空间。
如果参数index越界,自动扩充存储空间;如果新扩充的数据如果没有显示设值,则其内容未知。
在使用过程中,一个很容易犯的错误是,误认为setValues可以自动回收存储空间。所以当你使用该函数时,如果你的意思是同时释放内存,不要忘记手动调用setNum或者deleteValues。
setValue和赋值运算符(=):
设置第一个数据,删除其余数据,即:能够自动释放存储空间,设值后空间大小为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 on this class access information from the traversal state. They should be called only by callback functions that are invoked during traversal, so there is a valid state to work with.
1、setSceneGraph
各种viewer的成员函数setSceneGraph内部调用SoSceneManager的成员函数setSceneGraph。
SoSceneManager::setSceneGraph的大致工作流程如下(细节忽略,伪代码):
SoSceneManager::setSceneGraph(newSceneGraph):
oldSceneGraph = this->scene
this->scene = newSceneGraph
if newSceneGraph:
newSceneGraph->ref()
if oldSceneGraph:
oldSceneGraph->unref()
2009-9-22
适用OIV版本:
7.2
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 on SoQtRenderArea. If this function does not exist or returns FALSE, the Q event is either used directly by the viewer or translated to an SoEvent for further scene graph processing. If the viewer does not handle the event, and an overlay scene graph exists, the SoEvent is sent to that scene graph by way of an SoHandleEventAction. If no node in the overlay scene graph handles the event (i.e., calls setHandled() on the SoHandleEventAction), the SoEvent is passed to the normal scene graph in the same manner.
10、show/hide node的两种方法
a、SoGroup::addChild、SoGroup::removeChild;
b、SoSwitch;
经过简单测试:
add、remove会比SoSwitch速度快一些,同时SoSwitch还可能会多使用一个node(SoSwitch)的存储空间;
但是addChild会添加一个已经存在的node而没有任何提示,这通常不是想要的功能,所以在addChild前通常要判定目标node是否已经在SoGroup中,以保证只有一份node存在;此时,第一种方法速度上的优势就没有了,通常会更慢。
总之,如果你能保证不会添加同一node到SoGroup多次,请使用addChild和removeChild,既快又经济;否则,请使用SoSwitch。
补充一句:remove一个不在SoGroup中的node,会弹出oiv的error console window。
8、Adds application push button(以Qt为例):
viewer->addAppPushButton(new QPushButton(viewer->getAppPushButtonParent()))
7、double-sided lighting
SoVertexShape子类对象,如果是“面”的话,默认情况下是单面光照的,即有一面是暗的,如果要启用双面光照,可以在其前加入一个SoShapeHints:
SoShapeHints *lighting = new SoShapeHints;
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, one for the left eye, one for the right. Some sort of viewing hardware is used with the display, so each eye only sees the view created for it. The apparent depth of objects is a function of the difference in their positions from the left and right eye views. When done properly, objects appear to have actual depth, especially with respect to each other. When animating, the left and right back buffers are used, and must be updated each frame.
4、overlay plane
from IBM:
Graphical overlay planes are made up of additional memory positioned logically on top of the frame buffer (thus the name overlay). Typically, graphics applications would use this extra hardware for creating windows that would not disturb the contents of existing windows in the frame buffer.
The primary goals for implementing this feature are:
* To reduce the need for redrawing underlying complex images while the user is navigating through the user interface.
* To allow simple images, such as annotations, to be written over underlying images without overwriting the images.
from The Inventor Mentor:
The overlay planes are a separate set of bitplanes that can be used for special purposes in Inventor. The overlay planes are typically used for objects in the scene that appear on top of the main image and are redrawn independently. Although you are limited with respect to color and complexity of the scene graph placed in the overlay planes, using them enables you to quickly redraw a simple scene graph without having to redraw the “complete” scene graph.
3、Multiple-Value Fields: Setting and Getting Values
set1Value和setValues:
设置参数指定位置的值,同时保留其余各值,即不会自动释放空间。
如果参数index越界,自动扩充存储空间;如果新扩充的数据如果没有显示设值,则其内容未知。
在使用过程中,一个很容易犯的错误是,误认为setValues可以自动回收存储空间。所以当你使用该函数时,如果你的意思是同时释放内存,不要忘记手动调用setNum或者deleteValues。
setValue和赋值运算符(=):
设置第一个数据,删除其余数据,即:能够自动释放存储空间,设值后空间大小为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 on this class access information from the traversal state. They should be called only by callback functions that are invoked during traversal, so there is a valid state to work with.
1、setSceneGraph
各种viewer的成员函数setSceneGraph内部调用SoSceneManager的成员函数setSceneGraph。
SoSceneManager::setSceneGraph的大致工作流程如下(细节忽略,伪代码):
SoSceneManager::setSceneGraph(newSceneGraph):
oldSceneGraph = this->scene
this->scene = newSceneGraph
if newSceneGraph:
newSceneGraph->ref()
if oldSceneGraph:
oldSceneGraph->unref()
所以说,如果oldSceneGraph后续还要使用,务必在setSceneGraph前调用:oldSceneGraph->ref()。这点与action的apply函数比较像。