Browse Source

Add support for naming groups

Godzil 4 years ago
parent
commit
314da11005
2 changed files with 12 additions and 0 deletions
  1. 2 0
      source/include/group.h
  2. 10 0
      source/shapes/group.cpp

+ 2 - 0
source/include/group.h

@@ -25,6 +25,8 @@ private:
     Shape* *unboxableObjectList;
     uint32_t unboxableObjectCount;
 
+    char name[32 + 1];
+
 protected:
     Intersect localIntersect(Ray r);
     Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);

+ 10 - 0
source/shapes/group.cpp

@@ -11,6 +11,7 @@
 #include <group.h>
 #include <math_helper.h>
 #include <renderstat.h>
+#include <string.h>
 
 #define MIN_ALLOC (2)
 
@@ -25,6 +26,14 @@ Group::Group(const char *name) : Shape(Shape::GROUP)
     this->unboxableObjectList = (Shape **)calloc(sizeof(Shape **), MIN_ALLOC);
     this->unboxableObjectCount = 0;
 
+    if (name != nullptr)
+    {
+        strncpy(this->name, name, 32);
+    }
+    else
+    {
+        strncpy(this->name, "untitled", 32);
+    }
 }
 
 Intersect Group::intersect(Ray r)
@@ -204,6 +213,7 @@ void Group::dumpMe(FILE *fp)
 {
     int i;
     fprintf(fp, "\"Type\": \"Group\",\n");
+    fprintf(fp, "\"Name\": \"%s\",\n", this->name);
     if (this->objectCount > 0)
     {
         fprintf(fp, "\"Objects\": {\n");