added shape definition processing and shape cloning capabilities
git-svn-id: svn://anubis/fart/trunk@284 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
5308913bdb
commit
c1f39da3e2
@ -61,6 +61,10 @@ void Scene::processNode(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
processMaterialDefinition(node);
|
processMaterialDefinition(node);
|
||||||
}
|
}
|
||||||
|
else if ( typeid(*node) == typeid(ShapeDefinitionNode) )
|
||||||
|
{
|
||||||
|
processShapeDefinition(node);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << __FILE__ << ": " << __LINE__
|
cerr << __FILE__ << ": " << __LINE__
|
||||||
@ -143,6 +147,10 @@ refptr<Shape> Scene::processShape(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
return processExtrude(node);
|
return processExtrude(node);
|
||||||
}
|
}
|
||||||
|
else if ( typeid(*node) == typeid(ShapeRefNode) )
|
||||||
|
{
|
||||||
|
return processShapeRef(node);
|
||||||
|
}
|
||||||
|
|
||||||
return refptr<Shape>(NULL);
|
return refptr<Shape>(NULL);
|
||||||
}
|
}
|
||||||
@ -659,6 +667,20 @@ refptr<Polygon> Scene::processNGon(refptr<Node> node)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Scene::processShapeRef(refptr<Node> node)
|
||||||
|
{
|
||||||
|
if (m_shape_definitions.find(node->getString())
|
||||||
|
!= m_shape_definitions.end())
|
||||||
|
{
|
||||||
|
refptr<Shape> shape = m_shape_definitions[node->getString()]->clone();
|
||||||
|
shape->setTransform(m_transforms.top());
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
cerr << "Error: no shape definition for '" << node->getString()
|
||||||
|
<< "' found!" << endl;
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
bool Scene::processTransforms(refptr<Node> node)
|
bool Scene::processTransforms(refptr<Node> node)
|
||||||
{
|
{
|
||||||
bool did_any = false;
|
bool did_any = false;
|
||||||
@ -699,3 +721,9 @@ bool Scene::processTransforms(refptr<Node> node)
|
|||||||
|
|
||||||
return did_any;
|
return did_any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scene::processShapeDefinition(refptr<Node> node)
|
||||||
|
{
|
||||||
|
m_shape_definitions[node->getString()]
|
||||||
|
= processShape(node->getChildren()[0]);
|
||||||
|
}
|
||||||
|
@ -70,6 +70,7 @@ class Scene
|
|||||||
refptr<Shape> processShape(refptr<Node> node);
|
refptr<Shape> processShape(refptr<Node> node);
|
||||||
refptr<Shape> processBool(refptr<Node> node);
|
refptr<Shape> processBool(refptr<Node> node);
|
||||||
refptr<Shape> processExtrude(refptr<Node> node);
|
refptr<Shape> processExtrude(refptr<Node> node);
|
||||||
|
refptr<Shape> processShapeRef(refptr<Node> node);
|
||||||
refptr<Polygon> processPolygon(refptr<Node> node);
|
refptr<Polygon> processPolygon(refptr<Node> node);
|
||||||
refptr<Polygon> processNGon(refptr<Node> node);
|
refptr<Polygon> processNGon(refptr<Node> node);
|
||||||
bool processTransforms(refptr<Node> node);
|
bool processTransforms(refptr<Node> node);
|
||||||
@ -77,6 +78,7 @@ class Scene
|
|||||||
void processOptions(refptr<Node> node);
|
void processOptions(refptr<Node> node);
|
||||||
void processTransformBlock(refptr<Node> node);
|
void processTransformBlock(refptr<Node> node);
|
||||||
void processMaterialDefinition(refptr<Node> node);
|
void processMaterialDefinition(refptr<Node> node);
|
||||||
|
void processShapeDefinition(refptr<Node> node);
|
||||||
|
|
||||||
/* rendering parameters */
|
/* rendering parameters */
|
||||||
int m_width;
|
int m_width;
|
||||||
@ -90,7 +92,7 @@ class Scene
|
|||||||
|
|
||||||
/* private data */
|
/* private data */
|
||||||
std::vector< refptr<Shape> > m_shapes;
|
std::vector< refptr<Shape> > m_shapes;
|
||||||
std::vector< refptr<Shape> > m_shape_definitions;
|
std::map< std::string, refptr<Shape> > m_shape_definitions;
|
||||||
std::vector< refptr<Light> > m_lights;
|
std::vector< refptr<Light> > m_lights;
|
||||||
std::stack<Transform> m_transforms;
|
std::stack<Transform> m_transforms;
|
||||||
double m_view_plane_dist;
|
double m_view_plane_dist;
|
||||||
|
@ -7,3 +7,11 @@ void BoolShape::setMaterial(refptr<Material> material)
|
|||||||
m_shape1->setMaterial(material);
|
m_shape1->setMaterial(material);
|
||||||
m_shape2->setMaterial(material);
|
m_shape2->setMaterial(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoolShape::setTransform(Transform & t)
|
||||||
|
{
|
||||||
|
m_transform = t;
|
||||||
|
m_inverse = t.getInverse();
|
||||||
|
m_shape1->setTransform(t);
|
||||||
|
m_shape2->setTransform(t);
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@ class BoolShape : public Shape
|
|||||||
public:
|
public:
|
||||||
virtual IntersectionList intersect(refptr<Shape> _this, const Ray & ray) = 0;
|
virtual IntersectionList intersect(refptr<Shape> _this, const Ray & ray) = 0;
|
||||||
virtual void setMaterial(refptr<Material> material);
|
virtual void setMaterial(refptr<Material> material);
|
||||||
|
virtual void setTransform(Transform & t);
|
||||||
|
virtual refptr<Shape> clone() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
refptr<Shape> m_shape1;
|
refptr<Shape> m_shape1;
|
||||||
|
@ -70,3 +70,8 @@ Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Box::clone()
|
||||||
|
{
|
||||||
|
return new Box(*this);
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class Box : public Shape
|
|||||||
public:
|
public:
|
||||||
Box(refptr<Vector> size);
|
Box(refptr<Vector> size);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
virtual refptr<Shape> clone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Vector m_size;
|
Vector m_size;
|
||||||
|
@ -134,3 +134,8 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Cyl::clone()
|
||||||
|
{
|
||||||
|
return new Cyl(*this);
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class Cyl : public Shape
|
|||||||
public:
|
public:
|
||||||
Cyl(double bottom_radius, double top_radius, double height);
|
Cyl(double bottom_radius, double top_radius, double height);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
virtual refptr<Shape> clone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_bottom_radius;
|
double m_bottom_radius;
|
||||||
|
@ -166,3 +166,8 @@ void Extrude::addOffset(double distance,
|
|||||||
{
|
{
|
||||||
m_offsets.push_back(Offset(distance, scale, shift));
|
m_offsets.push_back(Offset(distance, scale, shift));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Extrude::clone()
|
||||||
|
{
|
||||||
|
return new Extrude(*this);
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@ class Extrude : public Shape
|
|||||||
Vector scale;
|
Vector scale;
|
||||||
Vector shift;
|
Vector shift;
|
||||||
};
|
};
|
||||||
|
virtual refptr<Shape> clone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector< refptr<Polygon> > m_polygons;
|
std::vector< refptr<Polygon> > m_polygons;
|
||||||
|
@ -98,3 +98,11 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Intersect::clone()
|
||||||
|
{
|
||||||
|
Intersect * s = new Intersect(*this);
|
||||||
|
s->m_shape1 = m_shape1->clone();
|
||||||
|
s->m_shape2 = m_shape2->clone();
|
||||||
|
return refptr<Shape>(s);
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ class Intersect : public BoolShape
|
|||||||
public:
|
public:
|
||||||
Intersect(const std::vector< refptr<Shape> > & shapes);
|
Intersect(const std::vector< refptr<Shape> > & shapes);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
refptr<Shape> clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,3 +50,8 @@ Shape::IntersectionList Plane::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Plane::clone()
|
||||||
|
{
|
||||||
|
return new Plane(*this);
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class Plane : public Shape
|
|||||||
public:
|
public:
|
||||||
Plane(double a, double b, double c, double d);
|
Plane(double a, double b, double c, double d);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
virtual refptr<Shape> clone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_a, m_b, m_c, m_d;
|
double m_a, m_b, m_c, m_d;
|
||||||
|
@ -101,8 +101,9 @@ class Shape
|
|||||||
virtual ~Shape();
|
virtual ~Shape();
|
||||||
virtual IntersectionList intersect(refptr<Shape> _this,
|
virtual IntersectionList intersect(refptr<Shape> _this,
|
||||||
const Ray & ray) = 0;
|
const Ray & ray) = 0;
|
||||||
|
virtual refptr<Shape> clone() = 0;
|
||||||
|
|
||||||
void setTransform(Transform & t)
|
virtual void setTransform(Transform & t)
|
||||||
{
|
{
|
||||||
m_transform = t;
|
m_transform = t;
|
||||||
m_inverse = t.getInverse();
|
m_inverse = t.getInverse();
|
||||||
|
@ -41,3 +41,8 @@ Shape::IntersectionList Sphere::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Sphere::clone()
|
||||||
|
{
|
||||||
|
return new Sphere(*this);
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class Sphere : public Shape
|
|||||||
public:
|
public:
|
||||||
Sphere(double radius);
|
Sphere(double radius);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
virtual refptr<Shape> clone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_radius;
|
double m_radius;
|
||||||
|
@ -98,3 +98,11 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Subtract::clone()
|
||||||
|
{
|
||||||
|
Subtract * s = new Subtract(*this);
|
||||||
|
s->m_shape1 = m_shape1->clone();
|
||||||
|
s->m_shape2 = m_shape2->clone();
|
||||||
|
return refptr<Shape>(s);
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ class Subtract : public BoolShape
|
|||||||
public:
|
public:
|
||||||
Subtract(const std::vector< refptr<Shape> > & shapes);
|
Subtract(const std::vector< refptr<Shape> > & shapes);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
refptr<Shape> clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,3 +99,11 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> Union::clone()
|
||||||
|
{
|
||||||
|
Union * s = new Union(*this);
|
||||||
|
s->m_shape1 = m_shape1->clone();
|
||||||
|
s->m_shape2 = m_shape2->clone();
|
||||||
|
return refptr<Shape>(s);
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ class Union : public BoolShape
|
|||||||
public:
|
public:
|
||||||
Union(const std::vector< refptr<Shape> > & shapes);
|
Union(const std::vector< refptr<Shape> > & shapes);
|
||||||
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
|
||||||
|
refptr<Shape> clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user