Commit 174ccfef authored by Michele Bosi's avatar Michele Bosi

Fixed problem with Actor enableMasks vs picking/adjustView/etc.

Now an Actor's enable state is respected when picking an adjustView-ing
parent 8c870f48
......@@ -61,7 +61,7 @@ public:
/*
// specify the Actor[s] to be tested
intersector.actors()->clear();
sceneManager()->extractActors( *intersector.actors() );
sceneManager()->extractVisibleActors( *intersector.actors(), NULL );
// set the intersecting ray
intersector.setRay(ray);
// run intersection test
......
......@@ -94,12 +94,13 @@ bool Actor::boundsDirty() const
//-----------------------------------------------------------------------------
void Actor::computeBounds()
{
if ( lod(0) == NULL )
if ( ! lod(0) ) {
return;
}
bool geom_update = lod(0)->boundsDirty() || lod(0)->boundsUpdateTick() != mBoundsUpdateTick;
if ( transform() && (geom_update || transform()->worldMatrixUpdateTick() != mTransformUpdateTick) )
if ( transform() && ( geom_update || transform()->worldMatrixUpdateTick() != mTransformUpdateTick ) )
{
lod(0)->boundingBox().transformed( mAABB, transform()->worldMatrix() );
mTransformUpdateTick = transform()->worldMatrixUpdateTick();
......
......@@ -93,7 +93,6 @@ namespace vl
virtual void onActorDelete(Actor* actor) = 0;
void setEnabled(bool enabled) { mEnabled = enabled; }
bool isEnabled() const { return mEnabled; }
protected:
......@@ -262,17 +261,19 @@ namespace vl
/** The enable mask of an Actor is usually used to defines whether the actor should be rendered or not
* depending on the Rendering::enableMask() but it can also be used for user-specific tasks (set to 0xFFFFFFFF by default).
* See also vl::Actor::setEnabled(), vl::Rendering::effectOverrideMask() and vl::Renderer::shaderOverrideMask(). */
* \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask(). */
void setEnableMask(unsigned int mask) { mEnableMask = mask; }
/** The enable mask of an Actor is usually used to defines whether the actor should be rendered or not
* depending on the Rendering::enableMask() but it can also be used for user-specific tasks (set to 0xFFFFFFFF by default).
* See also vl::Actor::enabled(), vl::Rendering::effectOverrideMask() and vl::Renderer::shaderOverrideMask(). */
* \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask(). */
unsigned int enableMask() const { return mEnableMask; }
/** A disabled Actor should behave as if it had EnableMask == 0. */
//! Whether an Actor should be considered for rendering, picking, scene bounding box calculation etc.
//! \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask().
void setEnabled(bool enabled) { mEnabled = enabled; }
/** A disabled Actor should behave as if it had EnableMask == 0. */
//! Whether an Actor should be considered for rendering, picking, scene bounding box calculation etc.
//! \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask().
bool isEnabled() const { return mEnabled; }
// uniforms methods
......
......@@ -68,7 +68,7 @@ namespace vl
virtual const ActorTreeAbstract* child(int i) const;
/**
* Builds a ActorKdTree with the given list of Actor[s].
* Builds a ActorKdTree with the given list of Actors.
* The ActorKdTree generation routine will try to minimize the ActorKdTree depth. Note that this function
* is relatively quick, but is not for free. Consider that using a Core 2 Duo @2.0GHz you can
* process around 22.000 objects/sec.
......@@ -76,7 +76,7 @@ namespace vl
*/
void buildKdTree(ActorCollection& actors, int max_depth=100, float minimum_volume=0);
//! Builds a ActorKdTree with the Actor[s] contained in the tree.
//! Builds a ActorKdTree with the Actors contained in the tree.
//! \note This method calls prepareActors() before computing the KdTree.
void rebuildKdTree(int max_depth=100, float minimum_volume=0);
......@@ -96,8 +96,8 @@ namespace vl
/**
* Inserts an Actor in the ActorKdTree node hierarchy.
* Note that the Actor is likely to be inserted in a node whose bounding volume does not surround the Actor's bounding volume.
* For this reason after you inserted one or more Actor[s] in the ActorKdTree you should call computeAABB() on the root node of
* the ActorKdTree. Inserting and removing Actor[s] is an expensive operation and produces an ActorKdTree that is
* For this reason after you inserted one or more Actors in the ActorKdTree you should call computeAABB() on the root node of
* the ActorKdTree. Inserting and removing Actors is an expensive operation and produces an ActorKdTree that is
* less balanced than the one you would get by recompiling the whole ActorKdTree from scratch.
*
* \return
......@@ -109,12 +109,12 @@ namespace vl
ActorKdTree* insertActor(Actor* actor);
/**
* Removes the Actor[s] in the internal nodes of the ActorKdTree and uses them to create a new ActorKdTree.
* Removes the Actors in the internal nodes of the ActorKdTree and uses them to create a new ActorKdTree.
*/
ref<ActorKdTree> kdtreeFromNonLeafyActors(int max_depth=100, float minimum_volume=0);
/**
* Removes the Actor[s] in the internal nodes of the ActorKdTree and appends them in the given ActorCollection.
* Removes the Actors in the internal nodes of the ActorKdTree and appends them in the given ActorCollection.
*/
void harvestNonLeafActors(ActorCollection& actors);
......
......@@ -181,13 +181,14 @@ void EdgeExtractor::extractEdges(ActorCollection* actors)
void EdgeExtractor::extractEdges(SceneManager* scene_manager)
{
ref<ActorCollection> actors = new ActorCollection;
scene_manager->extractActors(*actors);
scene_manager->extractVisibleActors( *actors, NULL );
extractEdges(actors.get());
}
//-----------------------------------------------------------------------------
void EdgeExtractor::extractEdges(Rendering* rendering)
{
for(int i=0; i<rendering->sceneManagers()->size(); ++i)
extractEdges(rendering->sceneManagers()->at(i));
for(int i=0; i<rendering->sceneManagers()->size(); ++i) {
extractEdges( rendering->sceneManagers()->at(i) );
}
}
//-----------------------------------------------------------------------------
......@@ -38,7 +38,7 @@ using namespace vl;
void RayIntersector::intersect(const Ray& ray, SceneManager* scene_manager)
{
actors()->clear();
scene_manager->extractActors( *actors() );
scene_manager->extractVisibleActors( *actors(), NULL );
setRay(ray);
intersect();
}
......
......@@ -195,22 +195,27 @@ void Rendering::render()
}
actorQueue()->clear();
for(int i=0; i<sceneManagers()->size(); ++i)
for(int i = 0; i < sceneManagers()->size(); ++i )
{
if ( isEnabled(sceneManagers()->at(i)->enableMask()) )
if ( isEnabled( sceneManagers()->at(i)->enableMask() ) )
{
if (cullingEnabled() && sceneManagers()->at(i)->cullingEnabled())
if ( cullingEnabled() && sceneManagers()->at(i)->cullingEnabled() )
{
if (sceneManagers()->at(i)->boundsDirty())
if ( sceneManagers()->at(i)->boundsDirty() ) {
sceneManagers()->at(i)->computeBounds();
}
// try to cull the scene with both bsphere and bbox
bool visible = !camera()->frustum().cull(sceneManagers()->at(i)->boundingSphere()) &&
!camera()->frustum().cull(sceneManagers()->at(i)->boundingBox());
if ( visible )
if ( camera()->frustum().cull( sceneManagers()->at(i)->boundingSphere() ) ||
camera()->frustum().cull( sceneManagers()->at(i)->boundingBox() ) ) {
continue;
} else {
sceneManagers()->at(i)->extractVisibleActors( *actorQueue(), camera() );
}
}
else {
sceneManagers()->at(i)->extractVisibleActors( *actorQueue(), NULL );
}
else
sceneManagers()->at(i)->extractActors( *actorQueue() );
}
}
......
......@@ -77,14 +77,14 @@ namespace vl
//! Constructor.
SceneManager();
//! Performs frustum culling and appends the enabled and visible Actor[s] to the given ActorCollection.
//! See also enableMask(), Actor::enableMask()
virtual void extractVisibleActors(ActorCollection& list, const Camera* camera)= 0;
//! Appends all the Actor[s] contained in the scene manager without performing frustum culling or checking enable masks.
//! Appends all the Actors contained in the scene manager without performing frustum culling or checking enable masks.
virtual void extractActors(ActorCollection& list) = 0;
//! Computes the bounding box and bounding sphere of the scene manager and of all the Actor[s] contained in the SceneManager.
//! Extracts all the enabled and visible Actors contained in the ActorTree hierarchy and appends them to the given ActorCollection.
//! \see SceneManager::enableMask(), Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled()
virtual void extractVisibleActors(ActorCollection& list, const Camera* camera) = 0;
//! Computes the bounding box and bounding sphere of the scene manager and of all the Actors contained in the SceneManager.
virtual void computeBounds();
//! Explicitly set the scene manager's bounding sphere. See also computeBounds().
......@@ -107,8 +107,13 @@ namespace vl
//! Used to enable or disable frustum culling or whichever culling system the scene manager implements.
bool cullingEnabled() const { return mCullingEnabled; }
//! The enable mask to be used by extractVisibleActors()
//! \see \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask().
void setEnableMask(unsigned int enabled) { mEnableMask = enabled; }
//! The enable mask to be used by extractVisibleActors()
//! \see \see Actor::enableMask(), Actor::isEnabled(), ActorTreeAbstract::isEnabled(), SceneManager::enableMask(), Rendering::enableMask(), Rendering::effectOverrideMask(), Renderer::enableMask(), Renderer::shaderOverrideMask().
unsigned int enableMask() const { return mEnableMask; }
//! Returns \p true if \p "a->enableMask() & enableMask()) != 0"
bool isEnabled(Actor*a) const;
......
......@@ -66,17 +66,19 @@ namespace vl
virtual void extractVisibleActors(ActorCollection& list, const Camera* camera)
{
// extracts Actor[s] from the hierarchical volume tree
if (cullingEnabled())
tree()->extractVisibleActors(list, camera, enableMask());
else
// extracts Actors from the hierarchical volume tree
if ( cullingEnabled() ) {
tree()->extractVisibleActors( list, camera, enableMask() );
}
else {
extractActors(list);
}
}
virtual void extractActors(ActorCollection& list)
{
// extracts Actor[s] from the hierarchical volume tree
tree()->extractActors(list);
// extracts Actors from the hierarchical volume tree
tree()->extractActors( list );
}
protected:
......
......@@ -100,7 +100,7 @@ namespace vl
bool mIsOpen;
};
//-----------------------------------------------------------------------------
/** Defines an area containg a set if Actor[s] that is connected to other Sector[s] through its Portal[s].
/** Defines an area containg a set if Actors that is connected to other Sector[s] through its Portal[s].
* See also:
* - SceneManagerPortals
* - Portal
......@@ -154,7 +154,7 @@ namespace vl
//! The volumes of a sector must not intersecate with the volumes of another sector.
const std::vector< AABB >& volumes() const { return mVolumes; }
//! Returns the bounding box of all the Actor[s] in the sector.
//! Returns the bounding box of all the Actors in the sector.
AABB computeBoundingBox();
std::vector< ref<VisibilityCallback> >& callbacks() { return mCallbacks; }
......@@ -192,9 +192,9 @@ namespace vl
VL_DEBUG_SET_OBJECT_NAME()
}
//! Appends to the given list all the Actor[s] contained in the scene regardless of their visibility.
//! Appends to the given list all the Actors contained in the scene regardless of their visibility.
void extractActors(ActorCollection& list);
//! Appends to the given list all the visible Actor[s] using the portal culling algorithm.
//! Appends to the given list all the visible Actors using the portal culling algorithm.
void extractVisibleActors(ActorCollection& list, const Camera* camera);
//! The Sectors that are part of the scene.
......
......@@ -244,15 +244,16 @@ void TrackballManipulator::adjustView(ActorCollection& actors, const vec3& dir,
void TrackballManipulator::adjustView(SceneManager* scene, const vec3& dir, const vec3& up, real bias)
{
ActorCollection actors;
scene->extractActors(actors);
scene->extractVisibleActors( actors, NULL );
adjustView(actors, dir, up, bias);
}
//-----------------------------------------------------------------------------
void TrackballManipulator::adjustView(Rendering* rendering, const vec3& dir, const vec3& up, real bias)
{
ActorCollection actors;
for(int i=0; i<rendering->sceneManagers()->size(); ++i)
rendering->sceneManagers()->at(i)->extractActors(actors);
for(int i = 0; i < rendering->sceneManagers()->size(); ++i ) {
rendering->sceneManagers()->at( i )->extractVisibleActors( actors, NULL );
}
adjustView(actors, dir, up, bias);
}
//-----------------------------------------------------------------------------
......
......@@ -165,7 +165,7 @@ namespace vl
//! Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB. See also Camera::adjustView().
void adjustView(const AABB& aabb, const vec3& dir, const vec3& up, real bias=1.0f);
//! Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the Actor[s]. See also Camera::adjustView().
//! Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the Actors. See also Camera::adjustView().
void adjustView(ActorCollection& actors, const vec3& dir, const vec3& up, real bias=1.0f);
//! Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the given scene manager. See also Camera::adjustView().
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment