A new scene and some optimisations.

This commit is contained in:
Godzil
2020-03-12 17:45:29 +00:00
parent 7a43a98816
commit c858b4dcde
11 changed files with 259 additions and 50 deletions

View File

@@ -484,6 +484,9 @@ int OBJFile::execLine(int argc, char *argv[], uint32_t currentLine)
this->verticesNormal(vn[2]),
this->verticesNormal(vn[3]));
}
/* Set the object id to the OBJ one */
t->setObjectId(this->getObjectId());
this->currentGroup->addObject(t);
ret = 0;
}
@@ -523,7 +526,7 @@ int OBJFile::execLine(int argc, char *argv[], uint32_t currentLine)
this->verticesNormal(vn[i]),
this->verticesNormal(vn[i + 1]));
}
t->setObjectId(this->getObjectId());
this->currentGroup->addObject(t);
}
ret = 0;

View File

@@ -15,6 +15,7 @@
Shape::Shape(ShapeType type)
{
this->objectId = Shape::newObjectId();
this->locked = false;
this->parent = nullptr;
this->dropShadow = true;
@@ -25,6 +26,17 @@ Shape::Shape(ShapeType type)
this->updateTransform();
}
uint64_t Shape::newObjectId()
{
static uint64_t id = 0;
uint64_t ret;
ret = id++;
return ret;
}
void Shape::intersect(Ray &r, Intersect &xs)
{
this->localIntersect(this->invTransform(r), xs);
@@ -95,6 +107,16 @@ BoundingBox Shape::getBounds()
return ret;
}
Material *Shape::getMaterial()
{
Shape *s = this;
while((!s->materialSet) && (s->parent != nullptr))
{
s = s->parent;
}
return &s->material;
}
void Shape::dumpMe(FILE *fp)
{
if (this->materialSet)
@@ -112,9 +134,9 @@ void Shape::dumpMe(FILE *fp)
this->getBounds().dumpMe(fp);
fprintf(fp, "},\n");
}
fprintf(fp, "\"id\": %p,\n", this);
fprintf(fp, "\"id\": %ld,\n", this->getObjectId());
if (this->parent)
{
fprintf(fp, "\"parentId\": %p,\n", this->parent);
fprintf(fp, "\"parentId\": %ld,\n", this->parent->getObjectId());
}
}