Add locking mechanism to prevent updating transform/parent
This commit is contained in:
@@ -17,8 +17,8 @@ CSG::CSG(OperationType operation, Shape *left, Shape *right) : Shape(Shape::CSG)
|
||||
{
|
||||
stats.addCsg();
|
||||
|
||||
this->left->parent = this;
|
||||
this->right->parent = this;
|
||||
this->left->setParent(this);
|
||||
this->right->setParent(this);
|
||||
|
||||
this->bounds | this->left->getBounds();
|
||||
this->bounds | this->right->getBounds();
|
||||
@@ -134,6 +134,19 @@ void CSG::filterIntersections(Intersect &xs, Intersect &ret)
|
||||
}
|
||||
}
|
||||
|
||||
void CSG::lock()
|
||||
{
|
||||
Shape::lock();
|
||||
if(this->left)
|
||||
{
|
||||
this->left->lock();
|
||||
}
|
||||
if(this->right)
|
||||
{
|
||||
this->right->lock();
|
||||
}
|
||||
}
|
||||
|
||||
void CSG::dumpMe(FILE *fp)
|
||||
{
|
||||
|
||||
|
||||
@@ -90,7 +90,6 @@ bool Group::includes(Shape *b)
|
||||
}
|
||||
}
|
||||
|
||||
/* We are force to do them all the time */
|
||||
if (this->unboxableObjectCount > 0)
|
||||
{
|
||||
int i;
|
||||
@@ -126,7 +125,7 @@ void Group::addObject(Shape *s)
|
||||
this->objectList = (Shape **)realloc(this->objectList, sizeof(Shape **) * this->allocatedObjectCount);
|
||||
}
|
||||
|
||||
s->parent = this;
|
||||
s->setParent(this);
|
||||
s->updateTransform();
|
||||
|
||||
this->objectList[this->objectCount++] = s;
|
||||
@@ -142,7 +141,7 @@ void Group::addObject(Shape *s)
|
||||
this->unboxableObjectList = (Shape **)realloc(this->unboxableObjectList, sizeof(Shape **) * this->allocatedUnboxableObjectCount);
|
||||
}
|
||||
|
||||
s->parent = this;
|
||||
s->setParent(this);
|
||||
s->updateTransform();
|
||||
|
||||
this->unboxableObjectList[this->unboxableObjectCount++] = s;
|
||||
@@ -269,4 +268,28 @@ void Group::dumpMe(FILE *fp)
|
||||
fprintf(fp, "},\n");
|
||||
}
|
||||
Shape::dumpMe(fp);
|
||||
}
|
||||
|
||||
void Group::lock()
|
||||
{
|
||||
Shape::lock();
|
||||
|
||||
/* Now notify included object they have to lock */
|
||||
int i;
|
||||
if (this->objectCount > 0)
|
||||
{
|
||||
for (i = 0 ; i < this->objectCount ; i++)
|
||||
{
|
||||
this->objectList[i]->lock();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->unboxableObjectCount > 0)
|
||||
{
|
||||
for(i = 0; i < this->unboxableObjectCount; i++)
|
||||
{
|
||||
this->unboxableObjectList[i]->lock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void OBJFile::addGroup(Group *group)
|
||||
{
|
||||
this->baseGroup->addObject(group);
|
||||
|
||||
group->parent = this;
|
||||
group->setParent(this);
|
||||
group->updateTransform();
|
||||
this->bounds | group->getBounds();
|
||||
|
||||
@@ -461,3 +461,10 @@ int OBJFile::execLine(int argc, char *argv[], uint32_t currentLine)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OBJFile::lock()
|
||||
{
|
||||
Shape::lock();
|
||||
|
||||
this->baseGroup->lock();
|
||||
}
|
||||
@@ -15,12 +15,14 @@
|
||||
|
||||
Shape::Shape(ShapeType type)
|
||||
{
|
||||
this->locked = false;
|
||||
this->parent = nullptr;
|
||||
this->dropShadow = true;
|
||||
this->type = type;
|
||||
this->localTransformMatrix = Matrix4().identity();
|
||||
this->updateTransform();
|
||||
this->materialSet = false;
|
||||
|
||||
this->updateTransform();
|
||||
}
|
||||
|
||||
Intersect Shape::intersect(Ray r)
|
||||
@@ -51,6 +53,8 @@ Tuple Shape::normalAt(Tuple point, Intersection *hit)
|
||||
|
||||
void Shape::updateTransform()
|
||||
{
|
||||
if (this->locked) return;
|
||||
|
||||
this->transformMatrix = this->localTransformMatrix;
|
||||
if (this->parent != nullptr)
|
||||
{
|
||||
@@ -63,6 +67,8 @@ void Shape::updateTransform()
|
||||
|
||||
void Shape::setTransform(Matrix transform)
|
||||
{
|
||||
if (this->locked) return;
|
||||
|
||||
this->localTransformMatrix = transform;
|
||||
this->updateTransform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user