فهرست منبع

Renamed AddUnculledDrawable() to AddManualDrawable().
Made it easier to select all gizmo axes.

Lasse Öörni 14 سال پیش
والد
کامیت
fd6a2ece9e
4فایلهای تغییر یافته به همراه36 افزوده شده و 27 حذف شده
  1. 3 2
      Bin/Data/Scripts/Editor/EditorGizmo.as
  2. 2 9
      Engine/Engine/GraphicsAPI.cpp
  3. 27 12
      Engine/Graphics/Octree.cpp
  4. 4 4
      Engine/Graphics/Octree.h

+ 3 - 2
Bin/Data/Scripts/Editor/EditorGizmo.as

@@ -37,7 +37,7 @@ class GizmoAxis
 
         // Update selected status only when not dragging
         if (!drag)
-            selected = d < axisMaxD * scale && t >= 0.0 && t <= axisMaxT * scale;
+            selected = d < axisMaxD * scale && t >= -axisMaxD * scale && t <= axisMaxT * scale;
     }
 }
 
@@ -55,8 +55,9 @@ void CreateGizmo()
     gizmo.materials[2] = cache.GetResource("Material", "Materials/BlueUnlit.xml");
     gizmo.visible = false;
 
+    // Add to the octree without culling. This also makes the gizmo invisible to raycasts
     if (editorScene.octree !is null)
-        editorScene.octree.AddUnculledDrawable(gizmo);
+        editorScene.octree.AddManualDrawable(gizmo, false);
 }
 
 void UpdateGizmo()

+ 2 - 9
Engine/Engine/GraphicsAPI.cpp

@@ -883,12 +883,6 @@ static CScriptArray* OctreeGetDrawablesSphere(const Sphere& sphere, unsigned cha
     return VectorToHandleArray<Drawable>(result, "Array<Node@>");
 }
 
-static void OctreeAddDrawable(Drawable* drawable, Octree* ptr)
-{
-    if (drawable && !drawable->GetOctant())
-        ptr->AddDrawable(drawable);
-}
-
 static Octree* SceneGetOctree(Scene* ptr)
 {
     return ptr->GetComponent<Octree>();
@@ -918,9 +912,8 @@ static void RegisterOctree(asIScriptEngine* engine)
     RegisterComponent<Octree>(engine, "Octree");
     engine->RegisterObjectMethod("Octree", "void Resize(const BoundingBox&in, uint)", asMETHOD(Octree, Resize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "void DrawDebugGeometry(bool) const", asMETHOD(Octree, DrawDebugGeometry), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Octree", "void AddDrawable(Drawable@+)", asFUNCTION(OctreeAddDrawable), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Octree", "void AddUnculledDrawable(Drawable@+)", asMETHOD(Octree, AddUnculledDrawable), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Octree", "void RemoveUnculledDrawable(Drawable@+)", asMETHOD(Octree, RemoveUnculledDrawable), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Octree", "void AddManualDrawable(Drawable@+, bool)", asMETHOD(Octree, AddManualDrawable), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Octree", "void RemoveManualDrawable(Drawable@+)", asMETHOD(Octree, RemoveManualDrawable), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "Array<RayQueryResult>@ Raycast(const Ray&in, RayQueryLevel level = RAY_TRIANGLE, float maxDistance = M_INFINITY, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeRaycast), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Vector3&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesPoint), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const BoundingBox&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesBox), asCALL_CDECL_OBJLAST);

+ 27 - 12
Engine/Graphics/Octree.cpp

@@ -366,31 +366,46 @@ void Octree::Update(const FrameInfo& frame)
     drawableReinsertions_.Clear();
 }
 
-void Octree::AddUnculledDrawable(Drawable* drawable)
+void Octree::AddManualDrawable(Drawable* drawable, bool culling)
 {
-    if (!drawable)
+    if (!drawable || drawable->GetOctant())
         return;
     
-    for (Vector<WeakPtr<Drawable> >::ConstIterator i = unculledDrawables_.Begin(); i != unculledDrawables_.End(); ++i)
+    if (culling)
+        AddDrawable(drawable);
+    else
     {
-        if ((*i) == drawable)
-            return;
+        for (Vector<WeakPtr<Drawable> >::ConstIterator i = unculledDrawables_.Begin(); i != unculledDrawables_.End(); ++i)
+        {
+            if ((*i) == drawable)
+                return;
+        }
+        
+        unculledDrawables_.Push(WeakPtr<Drawable>(drawable));
     }
-    
-    unculledDrawables_.Push(WeakPtr<Drawable>(drawable));
 }
 
-void Octree::RemoveUnculledDrawable(Drawable* drawable)
+void Octree::RemoveManualDrawable(Drawable* drawable)
 {
     if (!drawable)
         return;
     
-    for (Vector<WeakPtr<Drawable> >::Iterator i = unculledDrawables_.Begin(); i != unculledDrawables_.End(); ++i)
+    Octant* octant = drawable->GetOctant();
+    if (octant && octant->GetRoot() == this)
+    {
+        CancelUpdate(drawable);
+        CancelReinsertion(drawable);
+        octant->RemoveDrawable(drawable);
+    }
+    else
     {
-        if ((*i) == drawable)
+        for (Vector<WeakPtr<Drawable> >::Iterator i = unculledDrawables_.Begin(); i != unculledDrawables_.End(); ++i)
         {
-            unculledDrawables_.Erase(i);
-            return;
+            if ((*i) == drawable)
+            {
+                unculledDrawables_.Erase(i);
+                return;
+            }
         }
     }
 }

+ 4 - 4
Engine/Graphics/Octree.h

@@ -162,10 +162,10 @@ public:
     void Resize(const BoundingBox& box, unsigned numLevels);
     /// Update and reinsert drawable objects.
     void Update(const FrameInfo& frame);
-    /// Add a drawable that should not be subject to culling.
-    void AddUnculledDrawable(Drawable* drawable);
-    /// Remove an unculled drawable.
-    void RemoveUnculledDrawable(Drawable* drawable);
+    /// Add a drawable manually, which can optionally be unculled.
+    void AddManualDrawable(Drawable* drawable, bool culling);
+    /// Remove a manually added drawable.
+    void RemoveManualDrawable(Drawable* drawable);
     
     /// Return drawable objects by a query.
     void GetDrawables(OctreeQuery& query) const;