Browse Source

Added script function to add a drawable to an octree manually.
Added an event for AnimatedModel hierarchy creation to remove need for special case attribute edit handling.

Lasse Öörni 14 years ago
parent
commit
0bbf38fcf5

+ 3 - 19
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -237,18 +237,9 @@ void EditAttribute(StringHash eventType, VariantMap& eventData)
     if (!intermediateEdit)
         UpdateAttributes(false);
 
-    // If a model was loaded, update the scene hierarchy in case bones were recreated
-    if (serializables[0].attributes[index].GetResourceRef().type == ShortStringHash("Model"))
-    {
-        if (editNode !is null)
-            UpdateSceneWindowNode(editNode);
-    }
-    else
-    {
-        // If node name changed, update it in the scene window also
-        if (serializables[0].attributeInfos[index].name == "Name" && editNode !is null)
-            UpdateSceneWindowNodeOnly(editNode);
-    }
+    // If node name changed, update it in the scene window also
+    if (serializables[0] is editNode && serializables[0].attributeInfos[index].name == "Name")
+        UpdateSceneWindowNodeOnly(editNode);
 }
 
 uint GetAttributeEditorCount(Array<Serializable@>@ serializables)
@@ -958,8 +949,6 @@ void PickResourceDone(StringHash eventType, VariantMap& eventData)
     if (res is null)
         return;
 
-    bool isModel = false;
-    
     for (uint i = 0; i < resourcePickIDs.length; ++i)
     {
         Component@ target = editorScene.GetComponent(resourcePickIDs[i]);
@@ -972,7 +961,6 @@ void PickResourceDone(StringHash eventType, VariantMap& eventData)
             ref.id = StringHash(resourceName);
             target.attributes[resourcePickIndex] = Variant(ref);
             target.ApplyAttributes();
-            isModel = ref.type == ShortStringHash("Model");
         }
         else if (info.type == VAR_RESOURCEREFLIST)
         {
@@ -988,10 +976,6 @@ void PickResourceDone(StringHash eventType, VariantMap& eventData)
 
     UpdateAttributes(false);
 
-    // If a model was loaded, update the scene hierarchy in case bones were recreated
-    if (isModel && editNode !is null)
-        UpdateSceneWindowNode(editNode);
-
     resourcePickIDs.Clear();
     @resourcePicker = null;
 }

+ 1 - 0
Bin/Data/Scripts/Editor/EditorScene.as

@@ -189,6 +189,7 @@ void LoadScene(const String&in fileName)
 
     // Clear the old scene
     ClearSelection();
+    ClearSceneWindow();
     editorScene.Clear();
 
     // Add the new resource path

+ 15 - 1
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -60,6 +60,7 @@ void CreateSceneWindow()
     SubscribeToEvent(newComponentList, "ItemSelected", "HandleCreateComponent");
     SubscribeToEvent("DragDropTest", "HandleDragDropTest");
     SubscribeToEvent("DragDropFinish", "HandleDragDropFinish");
+    SubscribeToEvent("BoneHierarchyCreated", "HandleBoneHierarchyCreated");
 }
 
 void ShowSceneWindow()
@@ -98,11 +99,17 @@ void CollapseSceneHierarchy()
     list.contentElement.UpdateLayout();
 }
 
-void UpdateSceneWindow()
+void ClearSceneWindow()
 {
+    if (sceneWindow is null)
+        return;
     ListView@ list = sceneWindow.GetChild("NodeList", true);
     list.RemoveAllItems();
+}
 
+void UpdateSceneWindow()
+{
+    ClearSceneWindow();
     UpdateSceneWindowNode(0, editorScene);
 
     // Clear copybuffer when whole window refreshed
@@ -727,6 +734,13 @@ void HandleCreateComponent(StringHash eventType, VariantMap& eventData)
     UpdateAndFocusComponent(newComponent);
 }
 
+void HandleBoneHierarchyCreated(StringHash eventType, VariantMap& eventData)
+{
+    ListView@ list = sceneWindow.GetChild("NodeList", true);
+    if (list.numItems > 0)
+        UpdateSceneWindowNode(eventData["Node"].GetNode());
+}
+
 bool CheckSceneWindowFocus()
 {
     // When we do scene operations based on key shortcuts, make sure either the 3D scene or the node list is focused,

+ 7 - 0
Engine/Engine/GraphicsAPI.cpp

@@ -875,6 +875,12 @@ 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>();
@@ -904,6 +910,7 @@ 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", "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);

+ 8 - 1
Engine/Graphics/AnimatedModel.cpp

@@ -29,6 +29,7 @@
 #include "Camera.h"
 #include "Context.h"
 #include "DebugRenderer.h"
+#include "DrawableEvents.h"
 #include "Geometry.h"
 #include "Graphics.h"
 #include "IndexBuffer.h"
@@ -589,7 +590,7 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
         
         skeleton_.Define(skeleton);
         
-        // Create scene nodes for the bones, or get from the master model if not master
+        // Create scene nodes for the bones
         if (createBones)
         {
             Vector<Bone>& bones = skeleton_.GetModifiableBones();
@@ -609,6 +610,12 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
                     bones[parentIndex].node_->AddChild(bones[i].node_);
             }
         }
+        
+        using namespace BoneHierarchyCreated;
+        
+        VariantMap eventData;
+        eventData[P_NODE] = (void*)node_;
+        SendEvent(E_BONEHIERARCHYCREATED, eventData);
     }
     else
     {