]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/entity.cpp
fixed doom3 func_static creation bugs
[xonotic/netradiant.git] / radiant / entity.cpp
index bed3a6cf87ceea58c83e3d9288b83339d695bcb4..6fb499fd35589d202661a177d148b993a2534ce0 100644 (file)
@@ -178,7 +178,35 @@ void Entity_connectSelected()
   }
 }
 
+AABB Doom3Light_getBounds(const AABB& workzone)
+{
+  AABB aabb(workzone);
+
+  Vector3 defaultRadius(300, 300, 300);
+  if(!string_parse_vector3(EntityClass_valueForKey(*GlobalEntityClassManager().findOrInsert("light", false), "light_radius"), defaultRadius))
+  {
+    globalErrorStream() << "Doom3Light_getBounds: failed to parse default light radius\n";
+  }
 
+  if(aabb.extents[0] == 0)
+  {
+    aabb.extents[0] = defaultRadius[0];
+  }
+  if(aabb.extents[1] == 0)
+  {
+    aabb.extents[1] = defaultRadius[1];
+  }
+  if(aabb.extents[2] == 0)
+  {
+    aabb.extents[2] = defaultRadius[2];
+  }
+
+  if(aabb_valid(aabb))
+  {
+    return aabb;
+  }
+  return AABB(Vector3(0, 0, 0), Vector3(64, 64, 64));
+}
 
 int g_iLastLightIntensity;
 
@@ -199,12 +227,16 @@ void Entity_createFromSelection(const char* name, const Vector3& origin)
     || string_equal_nocase(name, "model_static")
     || (GlobalSelectionSystem().countSelected() == 0 && string_equal_nocase(name, "func_static"));
 
-  if(!(entityClass->fixedsize || isModel) && Scene_countSelectedBrushes(GlobalSceneGraph()) == 0)
+  bool brushesSelected = Scene_countSelectedBrushes(GlobalSceneGraph()) != 0;
+
+  if(!(entityClass->fixedsize || isModel) && !brushesSelected)
   {
     globalErrorStream() << "failed to create a group entity - no brushes are selected\n";
     return;
   }
 
+  AABB workzone(aabb_for_minmax(Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max));
+
 
   NodeSmartReference node(GlobalEntityCreator().createEntity(entityClass));
 
@@ -214,7 +246,7 @@ void Entity_createFromSelection(const char* name, const Vector3& origin)
   entitypath.push(makeReference(node.get()));
   scene::Instance& instance = findInstance(entitypath);
 
-  if(entityClass->fixedsize)
+  if(entityClass->fixedsize || (isModel && !brushesSelected))
   {
     Select_Delete();
     
@@ -232,6 +264,11 @@ void Entity_createFromSelection(const char* name, const Vector3& origin)
   }
   else
   {
+    if (g_pGameDescription->mGameType == "doom3")
+    {
+      Node_getEntity(node)->setKeyValue("model", Node_getEntity(node)->getKeyValue("name"));
+    }
+
     Scene_parentSelectedBrushesToEntity(GlobalSceneGraph(), node);
     Scene_forEachChildSelectable(SelectableSetSelected(true), instance.path());
   }
@@ -257,16 +294,29 @@ void Entity_createFromSelection(const char* name, const Vector3& origin)
       }
     }
   }
-  else if(g_pGameDescription->mGameType != "doom3" && string_equal_nocase(name, "light"))
+  else if(string_equal_nocase(name, "light"))
   {
-    int intensity = g_iLastLightIntensity;
+    if(g_pGameDescription->mGameType != "doom3")
+    {
+      int intensity = g_iLastLightIntensity;
 
-    if (DoLightIntensityDlg (&intensity) == eIDOK)
+      if (DoLightIntensityDlg (&intensity) == eIDOK)
+      {
+        g_iLastLightIntensity = intensity;
+        char buf[10];
+        sprintf( buf, "%d", intensity );
+        Node_getEntity(node)->setKeyValue("light", buf);
+      }
+    }
+    else if(brushesSelected) // use workzone to set light position/size for doom3 lights, if there are brushes selected
     {
-      g_iLastLightIntensity = intensity;
-      char buf[10];
-      sprintf( buf, "%d", intensity );
-      Node_getEntity(node)->setKeyValue("light", buf);
+      AABB bounds(Doom3Light_getBounds(workzone));
+      StringOutputStream key(64);
+      key << bounds.origin[0] << " " << bounds.origin[1] << " " << bounds.origin[2];
+      Node_getEntity(node)->setKeyValue("origin", key.c_str());
+      key.clear();
+      key << bounds.extents[0] << " " << bounds.extents[1] << " " << bounds.extents[2];
+      Node_getEntity(node)->setKeyValue("light_radius", key.c_str());
     }
   }