33 #include "vertexBufferDist.h"
35 #include "vertexBufferLeaf.h"
40 VertexBufferDist::VertexBufferDist()
56 _left =
new VertexBufferDist( root, root->getLeft( ));
58 if( root->getRight( ))
59 _right =
new VertexBufferDist( root, root->getRight( ));
74 _left =
new VertexBufferDist( root, node->getLeft( ));
76 if( node->getRight( ))
77 _right =
new VertexBufferDist( root, node->getRight( ));
80 VertexBufferDist::~VertexBufferDist()
88 void VertexBufferDist::registerTree( co::LocalNodePtr node )
90 LBASSERT( !isAttached() );
91 LBCHECK( node->registerObject(
this ));
94 _left->registerTree( node );
97 _right->registerTree( node );
100 void VertexBufferDist::deregisterTree()
102 LBASSERT( isAttached() );
103 LBASSERT( isMaster( ));
105 getLocalNode()->deregisterObject(
this );
108 _left->deregisterTree();
110 _right->deregisterTree();
114 co::LocalNodePtr localNode,
115 const eq::uint128_t& modelID )
117 LBASSERT( !_root && !_node );
119 const uint32_t req = localNode->mapObjectNB(
this, modelID,
120 co::VERSION_OLDEST, master );
121 if( !localNode->mapObjectSync( req ))
123 LBWARN <<
"Mapping of model failed" << std::endl;
131 void VertexBufferDist::_unmapTree()
133 LBASSERT( isAttached() );
134 LBASSERT( !isMaster( ));
136 getLocalNode()->unmapObject(
this );
141 _right->_unmapTree();
144 void VertexBufferDist::getInstanceData( co::DataOStream& os )
149 if( _left && _right )
151 os << _left->getID() << _right->getID();
158 os << data.vertices << data.colors << data.normals << data.indices
164 os << co::UUID() << co::UUID();
166 LBASSERT( dynamic_cast< const mesh::VertexBufferLeaf* >( _node ));
170 os << leaf->_boundingBox[0] << leaf->_boundingBox[1]
171 << uint64_t( leaf->_vertexStart ) << uint64_t( leaf->_indexStart )
172 << uint64_t( leaf->_indexLength ) << leaf->_vertexLength;
175 os << _node->_boundingSphere << _node->_range;
178 void VertexBufferDist::applyInstanceData( co::DataIStream& is )
185 lunchbox::UUID leftID, rightID;
186 is >> _isRoot >> leftID >> rightID;
188 if( leftID != 0 && rightID != 0 )
195 is >> data.vertices >> data.colors >> data.normals >> data.indices
208 _left =
new VertexBufferDist( _root, 0 );
209 _right =
new VertexBufferDist( _root, 0 );
210 co::LocalNodePtr to = getLocalNode();
211 #if CO_VERSION_GE( 1,1,0 )
212 co::NodePtr from = is.getRemoteNode();
214 co::NodePtr from = is.getMaster();
216 const uint32_t sync1 = to->mapObjectNB( _left, leftID,
217 co::VERSION_OLDEST, from );
218 const uint32_t sync2 = to->mapObjectNB( _right, rightID,
219 co::VERSION_OLDEST, from );
221 LBCHECK( to->mapObjectSync( sync1 ));
222 LBCHECK( to->mapObjectSync( sync2 ));
229 LBASSERT( !_isRoot );
235 is >> leaf->_boundingBox[0] >> leaf->_boundingBox[1]
236 >> i1 >> i2 >> i3 >> leaf->_vertexLength;
237 leaf->_vertexStart = size_t( i1 );
238 leaf->_indexStart = size_t( i2 );
239 leaf->_indexLength = size_t( i3 );
245 is >> base->_boundingSphere >> base->_range;
Holds the final kd-tree data, sorted and reindexed.