瀏覽代碼

Use ordinary DRAWABLE_GEOMETRY flag on 2D drawables so that they can be raycasted against. Use a DRAWABLE_PROXYGEOMETRY flag on DrawableProxy2D so that it won't show up in normal raycasts or octree queries. Fixes #345.

Lasse Öörni 11 年之前
父節點
當前提交
bf6a054ac4

+ 1 - 1
Source/Engine/Graphics/Drawable.h

@@ -33,7 +33,7 @@ namespace Urho3D
 static const unsigned DRAWABLE_GEOMETRY = 0x1;
 static const unsigned DRAWABLE_LIGHT = 0x2;
 static const unsigned DRAWABLE_ZONE = 0x4;
-static const unsigned DRAWABLE_2D = 0x8;
+static const unsigned DRAWABLE_PROXYGEOMETRY = 0x8;
 static const unsigned DRAWABLE_ANY = 0xff;
 static const unsigned DEFAULT_VIEWMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_LIGHTMASK = M_MAX_UNSIGNED;

+ 10 - 9
Source/Engine/Graphics/View.cpp

@@ -108,8 +108,8 @@ public:
             Drawable* drawable = *start++;
             unsigned char flags = drawable->GetDrawableFlags();
             
-            if ((flags == DRAWABLE_ZONE || (flags == DRAWABLE_GEOMETRY && drawable->IsOccluder())) && (drawable->GetViewMask() &
-                viewMask_))
+            if ((flags == DRAWABLE_ZONE || ((flags == DRAWABLE_GEOMETRY || flags == DRAWABLE_PROXYGEOMETRY) &&
+                drawable->IsOccluder())) && (drawable->GetViewMask() & viewMask_))
             {
                 if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
                     result_.Push(drawable);
@@ -198,7 +198,7 @@ void CheckVisibilityWork(const WorkItem* item, unsigned threadIndex)
             drawable->MarkInView(view->frame_);
             
             // For geometries, find zone, clear lights and calculate view space Z range
-            if (drawable->GetDrawableFlags() & DRAWABLE_GEOMETRY)
+            if (drawable->GetDrawableFlags() & (DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY))
             {
                 Zone* drawableZone = drawable->GetZone();
                 if (!cameraZoneOverride && (drawable->IsZoneDirty() || !drawableZone || (drawableZone->GetViewMask() &
@@ -765,13 +765,13 @@ void View::GetDrawables()
     if (occlusionBuffer_)
     {
         OccludedFrustumOctreeQuery query(tempDrawables, camera_->GetFrustum(), occlusionBuffer_, DRAWABLE_GEOMETRY |
-            DRAWABLE_LIGHT, camera_->GetViewMask());
+            DRAWABLE_PROXYGEOMETRY | DRAWABLE_LIGHT, camera_->GetViewMask());
         octree_->GetDrawables(query);
     }
     else
     {
-        FrustumOctreeQuery query(tempDrawables, camera_->GetFrustum(), DRAWABLE_GEOMETRY | DRAWABLE_LIGHT,
-            camera_->GetViewMask());
+        FrustumOctreeQuery query(tempDrawables, camera_->GetFrustum(), DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY |
+            DRAWABLE_LIGHT, camera_->GetViewMask());
         octree_->GetDrawables(query);
     }
     
@@ -2067,7 +2067,8 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
         
     case LIGHT_SPOT:
         {
-            FrustumOctreeQuery octreeQuery(tempDrawables, light->GetFrustum(), DRAWABLE_GEOMETRY, camera_->GetViewMask());
+            FrustumOctreeQuery octreeQuery(tempDrawables, light->GetFrustum(), DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY,
+                camera_->GetViewMask());
             octree_->GetDrawables(octreeQuery);
             for (unsigned i = 0; i < tempDrawables.Size(); ++i)
             {
@@ -2080,7 +2081,7 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
     case LIGHT_POINT:
         {
             SphereOctreeQuery octreeQuery(tempDrawables, Sphere(light->GetNode()->GetWorldPosition(), light->GetRange()),
-                DRAWABLE_GEOMETRY, camera_->GetViewMask());
+                DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY, camera_->GetViewMask());
             octree_->GetDrawables(octreeQuery);
             for (unsigned i = 0; i < tempDrawables.Size(); ++i)
             {
@@ -2122,7 +2123,7 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
                 continue;
         
             // Reuse lit geometry query for all except directional lights
-            ShadowCasterOctreeQuery query(tempDrawables, shadowCameraFrustum, DRAWABLE_GEOMETRY,
+            ShadowCasterOctreeQuery query(tempDrawables, shadowCameraFrustum, DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY,
                 camera_->GetViewMask());
             octree_->GetDrawables(query);
         }

+ 2 - 2
Source/Engine/Graphics/Zone.cpp

@@ -317,14 +317,14 @@ void Zone::ClearDrawablesZone()
     if (octant_ && lastWorldBoundingBox_.defined_)
     {
         PODVector<Drawable*> result;
-        BoxOctreeQuery query(result, lastWorldBoundingBox_, DRAWABLE_GEOMETRY | DRAWABLE_ZONE);
+        BoxOctreeQuery query(result, lastWorldBoundingBox_, DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY | DRAWABLE_ZONE);
         octant_->GetRoot()->GetDrawables(query);
 
         for (PODVector<Drawable*>::Iterator i = result.Begin(); i != result.End(); ++i)
         {
             Drawable* drawable = *i;
             unsigned drawableFlags = drawable->GetDrawableFlags();
-            if (drawableFlags & DRAWABLE_GEOMETRY)
+            if (drawableFlags & (DRAWABLE_GEOMETRY | DRAWABLE_PROXYGEOMETRY))
                 drawable->SetZone(0);
             else if (drawableFlags & DRAWABLE_ZONE)
             {

+ 1 - 0
Source/Engine/LuaScript/pkgs/Graphics/Drawable.pkg

@@ -3,6 +3,7 @@ $#include "Drawable.h"
 static const unsigned DRAWABLE_GEOMETRY;
 static const unsigned DRAWABLE_LIGHT;
 static const unsigned DRAWABLE_ZONE;
+static const unsigned DRAWABLE_PROXYGEOMETRY;
 static const unsigned DRAWABLE_ANY;
 static const unsigned DEFAULT_VIEWMASK;
 static const unsigned DEFAULT_LIGHTMASK;

+ 1 - 0
Source/Engine/Script/GraphicsAPI.cpp

@@ -703,6 +703,7 @@ static void RegisterDrawable(asIScriptEngine* engine)
     engine->RegisterGlobalProperty("uint DRAWABLE_GEOMETRY", (void*)&DRAWABLE_GEOMETRY);
     engine->RegisterGlobalProperty("uint DRAWABLE_LIGHT", (void*)&DRAWABLE_LIGHT);
     engine->RegisterGlobalProperty("uint DRAWABLE_ZONE", (void*)&DRAWABLE_ZONE);
+    engine->RegisterGlobalProperty("uint DRAWABLE_PROXYGEOMETRY", (void*)&DRAWABLE_PROXYGEOMETRY);
     engine->RegisterGlobalProperty("uint DRAWABLE_ANY", (void*)&DRAWABLE_ANY);
     engine->RegisterGlobalProperty("uint DEFAULT_VIEWMASK", (void*)&DEFAULT_VIEWMASK);
     engine->RegisterGlobalProperty("uint DEFAULT_LIGHTMASK", (void*)&DEFAULT_LIGHTMASK);

+ 1 - 1
Source/Engine/Urho2D/Drawable2D.cpp

@@ -47,7 +47,7 @@ const float PIXEL_SIZE = 0.01f;
 extern const char* blendModeNames[];
 
 Drawable2D::Drawable2D(Context* context) :
-    Drawable(context, DRAWABLE_2D),
+    Drawable(context, DRAWABLE_GEOMETRY),
     layer_(0),
     orderInLayer_(0),
     blendMode_(BLEND_ALPHA),

+ 1 - 1
Source/Engine/Urho2D/DrawableProxy2D.cpp

@@ -43,7 +43,7 @@ namespace Urho3D
 {
 
 DrawableProxy2D::DrawableProxy2D(Context* context) :
-    Drawable(context, DRAWABLE_GEOMETRY),
+    Drawable(context, DRAWABLE_PROXYGEOMETRY),
     indexBuffer_(new IndexBuffer(context_)),
     vertexBuffer_(new VertexBuffer(context_)),
     orderDirty_(true),