connections(连接件)——Object和Property的桥梁

来源:互联网 发布:武林外传细思极恐 知乎 编辑:程序博客网 时间:2024/04/30 14:46

一个连接件就是Fbx sdk中用来处理对象(Object)和特性(Property)之间关系的数据结构。连接件数据结构不开源,但可以通过以下函数来操作: FbxObject::ConnectSrcObject(),FbxObject::ConnectDstObject()FbxProperty::ConnectDstObject(),FbxProperty::ConnectSrcProperty()

     这里我们来讨论一下特性(Property)和属性(Attribute)的区别:特性是一个类中特有的;属性可以是一个类特有的,也可以是几个类都有的。在程序中,特性就是类中的属性(比如节点类FbxNode和它内部的转换向量),属性就是一个独立的类(比如FbxNodeAttribute)。

     连接件可以视为目的层(destination)和资源层(source),以下是各种连接关系的操作函数:

     对象-特性 连接:FbxObject::GetSrcProperty() ,FbxProperty::GetDstObject() 

     对象-对象 连接:FbxObject::GetSrcObject(),FbxObject::GetDstObject().

     特性-特性 连接:FbxProperty::GetSrcProperty(),FbxProperty::GetDstProperty()。

     下图是对象与特性间的关系(从fbx教程里复制的):


      上图的关系可以有下面的代码来操作:

      得到obj0中的资源对象并用obj1和obj2表示:

      

// ... Assume obj0 has been initialized to reflect the diagram above...// For illustrative purposes, count the number of source objects connected to obj0.int numSrcObjects = obj0->GetSrcObjectCount(); // numSrcObjects = 2// Access the two source objects connected to obj0// Note that obj0->GetSrcObject(0) is equivalent to calling obj0->GetSrcObject()FbxObject* obj1 = obj0->GetSrcObject(0);FbxObject* obj2 = obj0->GetSrcObject(1);
得到obj0的资源特性:

// ... Assume obj0 has been initialized to reflect the diagram above...FbxProperty* prop0 = obj0->GetSrcProperty();
得到obj1的目的对象:
// ... assume obj1 has been initialized to reflect the diagram above...FbxObject* obj0 = obj1->GetDstObject();
从obj2开始操作:

// ... Assume obj2 has been initialized to reflect the diagram above...// Access prop2 using obj2.FbxProperty* prop2 = obj2->GetSrcProperty();// For illustrative purposes, count the number of source properties of prop2.int numSrcProperties = prop2->GetSrcPropertyCount(); // numSrcProperties = 2// Access prop3 and prop4, which are sources with respect to prop2, // respectively indexed at 0 and 1.FbxProperty* prop3 = prop2->GetSrcProperty(0);FbxProperty* prop4 = prop2->GetSrcProperty(1);// Access obj0 using obj2.FbxObject* obj0 = obj2->GetDstObject();// Access prop0 using obj0.FbxProperty* prop0 = obj0->GetSrcProperty();// Access obj1 using obj0. // Here, we assume obj1 is indexed at 0, whereas obj2 is indexed at 1.FbxObject* obj1 = obj0->GetSrcObject(0);// Access prop1 using obj1.FbxProperty* prop1 = obj1->GetSrcProperty();

连接件的概念就是能够让FbxProperty能够动态的加入到FbxObject中。这让用户能够灵活的定义自己的数据类型,可以用FbxProperty::SetUserDataPtr()加入到FBX property中,并且用FbxObject::ConnectSrcProperty()将特性绑定到FbxObject上。


下面讲几个例子在讲之前,简要介绍一下,节点(FbxNode)对象和一个属性(FbxNodeAttribute)对象之间的对象-对象联系。在FbxScene中同一层次的FbxNodes是用来定义几何变换信息的。举个例子,FbxMeshFbxCamera和FbxLight都是从FbxNodeAttribute继承而来的,它们描述了场景中所有元素,而一个FbxNodeAttribute是用来表示mesh,camera或者light在3D场景中的哪个位置。


例1:场景对象中nodes之间的亲子关系利用了对象-对象连接件。下面演示FbxNode:AddChild()来为一个父节点增加子节点的代码:

// ... Assume lScene has been initialized as a FbxScene*,// Obtain the root node of a scene.FbxNode* lParentNode = lScene->GetRootNode();// Create a child node.FbxNode* lChildNode = FbxNode::Create(lScene, "child");// Add the child node to the root node.lParentNode->AddChild(lChildNode);

代码中该孩子节点就是父节点的资源对象,父亲节点就是孩子节点的目的对象。同理父亲节点是lScene场景对象的资源对象。。。

例:2对象-对象):当一个FbxNodeAttribute被FbxNode::SetNodeAttribute()建立时,它和FbxNode对象的关系(对象-对象关系)已经被确认。那么一个场景中的节点可以绑定一个FbxMesh(继承与FbxNodeAttribute)示例。注意:材质(FbxSurfaceMaterial)也可以作为资源对象。但是一个节点可以和许多材质联系在一起,一种材质也可以和很多材质联系在一起,因为材质不是FbxNodeAttribute的子类。FbxNodeAttribute的子类由下图表示:

例3(对象-特性):节点(FbxNode)中的转换信息会被定义为一种FbxTypeProperty,那么这个FbxTypeProperty是FbxNode的资源特性,FbxNode是FbxTypeProperty的目的对象。

















原创粉丝点击