DiTransUnitPtr DiCullNode::DetachObject( unsigned short index ) { DiTransUnitPtr ret; if (index < mObjectsByName.size()) { ObjectMap::iterator i = mObjectsByName.begin(); while (index--)++i; ret = i->second; mObjectsByName.erase(i); if (ret->GetParentNode() == this) { ret->NotifyAttached((DiCullNode*)0); } NeedUpdate(); return ret; } else { DI_ERROR("Cannot detach object, invalid index"); return NULL; } }
void DiCullNode::AttachSilently(DiTransUnitPtr obj) { DI_ASSERT(!mObjectsByName.contains(obj->GetName())); mObjectsByName.insert(ObjectMap::value_type(obj->GetName(), obj)); NeedUpdate(); }
DiCullNode::~DiCullNode(void) { ObjectMap::iterator itr; DiTransUnitPtr ret; for ( itr = mObjectsByName.begin(); itr != mObjectsByName.end(); ++itr ) { ret = itr->second; ret->NotifyAttached((DiCullNode*)NULL); } mObjectsByName.clear(); }
void DiCullNode::ProcessVisibleObjects(std::function<void(DiTransUnitPtr)> func) { auto mit = mObjectsByName.begin(); while (mit != mObjectsByName.end()) { DiTransUnitPtr mo = mit->second; if (mo->GetVisible()) func(mo); ++mit; } }
void DiCullNode::AttachObject(DiTransUnitPtr obj) { if (obj->IsAttached()) { DI_ERROR("The object has been attached"); } obj->NotifyAttached(this); DI_ASSERT(!mObjectsByName.contains(obj->GetName())); mObjectsByName.insert(ObjectMap::value_type(obj->GetName(), obj)); NeedUpdate(); }
void DiCullNode::AttachObject(DiTransUnitPtr obj) { if (obj->IsAttached()) { DI_WARNING("The object has been attached"); return; } obj->NotifyAttached(this); mObjects.push_back(obj); NeedUpdate(); }
void DiCullNode::UpdateBounds() { mWorldAABB.SetNull(); mLocalAABB.SetNull(); ObjectMap::iterator itr; DiTransUnitPtr ret; for ( itr = mObjectsByName.begin(); itr != mObjectsByName.end(); ++itr ) { ret = itr->second; mWorldAABB.Merge(ret->GetWorldBoundingBox(true)); mLocalAABB.Merge( ret->GetBoundingBox() ); } if (!mWorldAABB.IsNull()) mCreator->UpdateOctreeNode( this ); }
void DiCullNode::DetachAllObjects( void ) { ObjectMap::iterator itr; DiTransUnitPtr ret; for ( itr = mObjectsByName.begin(); itr != mObjectsByName.end(); ++itr ) { ret = itr->second; if (ret->GetParentNode() == this) { ret->NotifyAttached((DiCullNode*)0); } } mObjectsByName.clear(); NeedUpdate(); }
DiTransUnitPtr DiCullNode::DetachObject( const DiString& name ) { ObjectMap::iterator it = mObjectsByName.find(name); if (it == mObjectsByName.end()) { DI_ERROR("Cannot find the object : %s", name.c_str()); } DiTransUnitPtr ret = it->second; mObjectsByName.erase(it); if (ret->GetParentNode() == this) { ret->NotifyAttached((DiCullNode*)0); } NeedUpdate(); return ret; }
void DiCullNode::DetachObject(DiTransUnitPtr obj) { ObjectMap::iterator i, iend; iend = mObjectsByName.end(); for (i = mObjectsByName.begin(); i != iend; ++i) { if (i->second == obj) { mObjectsByName.erase(i); break; } } if (obj->GetParentNode() == this) { obj->NotifyAttached((DiCullNode*)0); } NeedUpdate(); }
void DiCullNode::DetachObject(DiTransUnitPtr obj) { bool found = false; for (auto i = mObjects.begin(); i != mObjects.end(); ++i) { if (*i == obj) { mObjects.erase(i); found = true; break; } } if (!found) return; if (obj->GetParentNode() == this) { obj->NotifyAttached(nullptr); } NeedUpdate(); }
DiTransUnitPtr DiCullNode::DetachObject( uint32 index ) { if (index < mObjects.size()) { DiTransUnitPtr ret = mObjects[index]; if (ret->GetParentNode() == this) { ret->NotifyAttached((DiCullNode*)0); } ObjectMap::iterator i = mObjects.begin() + index; mObjects.erase(i); NeedUpdate(); return ret; } else { DI_WARNING("Cannot detach object, invalid index"); return nullptr; } }
void DiCullNode::ProcessBatchGroup( DiCamera* camera,DiRenderPipeline* pipeline, bool onlyShadowCaster, DiVisibleObjectsBoundsInfo* visbleBounds) { auto mit = mObjectsByName.begin(); while ( mit != mObjectsByName.end() ) { DiTransUnitPtr mo = mit->second; if (mo->GetVisible()) { DiRenderBatchGroup* gp = pipeline->GetBatchGroup(mo->GetBatchGroup()); bool receiveShadows = gp->GetShadowEnable(); if (!onlyShadowCaster || mo->GetShadowCastEnable()) { mo->NotifyCurrentCamera(camera); mo->CullingUpdate(gp,camera); if (visbleBounds) { visbleBounds->Merge(mo->GetWorldBoundingBox(true), mo->GetWorldBoundingSphere(this, true), camera, receiveShadows); } } else if (onlyShadowCaster && !mo->GetShadowCastEnable() && receiveShadows) { visbleBounds->MergeNonRenderedButInFrustum(mo->GetWorldBoundingBox(true), mo->GetWorldBoundingSphere(true), camera); } } ++mit; } }