added a convenience wrapper to permit direct animation of every type of shape without having to declare instances etc

metadata
Wenzel Jakob 2012-11-03 02:46:32 -04:00
parent 0c09791f47
commit 3881f295d8
12 changed files with 73 additions and 22 deletions

View File

@ -71,6 +71,10 @@ MTS_NAMESPACE_BEGIN
* Specifies the relative amount of samples
* allocated to this emitter. \default{1}
* }
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional sensor-to-world transformation.
* \default{none (i.e. sensor space $=$ world space)}
* }
* }
*
* \renderings{
@ -376,8 +380,7 @@ public:
bitmapData.ptr = (uint8_t *) bitmap.get();
bitmapData.size = sizeof(Bitmap);
props.setData("bitmap", bitmapData);
const Transform &trafo = m_worldTransform->eval(0);
props.setTransform("toWorld", trafo);
props.setAnimatedTransform("toWorld", m_worldTransform);
props.setFloat("samplingWeight", m_samplingWeight);
Emitter *emitter = static_cast<Emitter *>(
PluginManager::getInstance()->createObject(

View File

@ -221,8 +221,7 @@ public:
bitmapData.ptr = (uint8_t *) bitmap.get();
bitmapData.size = sizeof(Bitmap);
props.setData("bitmap", bitmapData);
const Transform &trafo = m_worldTransform->eval(0);
props.setTransform("toWorld", trafo);
props.setAnimatedTransform("toWorld", m_worldTransform);
props.setFloat("samplingWeight", m_samplingWeight);
Emitter *emitter = static_cast<Emitter *>(
PluginManager::getInstance()->createObject(

View File

@ -223,7 +223,7 @@ public:
bitmapData.ptr = (uint8_t *) bitmap.get();
bitmapData.size = sizeof(Bitmap);
envProps.setData("bitmap", bitmapData);
envProps.setTransform("toWorld", trafo);
envProps.setAnimatedTransform("toWorld", m_worldTransform);
envProps.setFloat("samplingWeight", m_samplingWeight);
m_envEmitter = static_cast<Emitter *>(
PluginManager::getInstance()->createObject(

View File

@ -198,9 +198,9 @@ Properties::~Properties() {
void Properties::operator=(const Properties &props) {
for (std::map<std::string, PropertyElement>::iterator it = m_elements->begin();
it != m_elements->end(); ++it) {
AnimatedTransform *trafo = boost::get<AnimatedTransform *>((*it).second.data);
AnimatedTransform **trafo = boost::get<AnimatedTransform *>(&(*it).second.data);
if (trafo)
trafo->decRef();
(*trafo)->decRef();
}
m_pluginName = props.m_pluginName;
@ -209,9 +209,9 @@ void Properties::operator=(const Properties &props) {
for (std::map<std::string, PropertyElement>::iterator it = m_elements->begin();
it != m_elements->end(); ++it) {
AnimatedTransform *trafo = boost::get<AnimatedTransform *>((*it).second.data);
AnimatedTransform **trafo = boost::get<AnimatedTransform *>(&(*it).second.data);
if (trafo)
trafo->incRef();
(*trafo)->incRef();
}
}
@ -223,6 +223,9 @@ bool Properties::removeProperty(const std::string &name) {
std::map<std::string, PropertyElement>::iterator it = m_elements->find(name);
if (it == m_elements->end())
return false;
AnimatedTransform **trafo = boost::get<AnimatedTransform *>(&(*it).second.data);
if (trafo)
(*trafo)->decRef();
m_elements->erase(it);
return true;
}

View File

@ -271,7 +271,7 @@ void SceneHandler::endElement(const XMLCh* const xmlName) {
if (context.attributes.find("id") != context.attributes.end())
context.properties.setID(context.attributes["id"]);
ref<ConfigurableObject> object = NULL;
ref<ConfigurableObject> object;
TagMap::const_iterator it = m_tags.find(name);
if (it == m_tags.end())
@ -686,11 +686,57 @@ void SceneHandler::endElement(const XMLCh* const xmlName) {
}
break;
default:
default: {
if (tag.second == NULL)
XMLLog(EError, "Internal error: could not instantiate an object "
"corresponding to the tag '%s'", name.c_str());
object = m_pluginManager->createObject(tag.second, context.properties);
Properties &props = context.properties;
/* Convenience hack: allow passing animated transforms to arbitrary shapes
and then internally rewrite this into a shape group + animated instance */
if (tag.second == MTS_CLASS(Shape) && props.getPluginName() != "instance" &&
props.hasProperty("toWorld") && props.getType("toWorld") == Properties::EAnimatedTransform) {
ref<const AnimatedTransform> trafo = props.getAnimatedTransform("toWorld");
props.removeProperty("toWorld");
if (trafo->isStatic())
props.setTransform("toWorld", trafo->eval(0));
object = m_pluginManager->createObject(tag.second, props);
if (!trafo->isStatic()) {
object = m_pluginManager->createObject(tag.second, props);
/* If the object has children, append them */
for (std::vector<std::pair<std::string, ConfigurableObject *> >
::iterator it = context.children.begin();
it != context.children.end(); ++it) {
if (it->second != NULL) {
object->addChild(it->first, it->second);
it->second->setParent(object);
it->second->decRef();
}
}
context.children.clear();
object->configure();
ref<Shape> shapeGroup = static_cast<Shape *> (
m_pluginManager->createObject(MTS_CLASS(Shape), Properties("shapegroup")));
shapeGroup->addChild(object);
shapeGroup->configure();
Properties instanceProps("instance");
instanceProps.setAnimatedTransform("toWorld", trafo);
object = m_pluginManager->createObject(instanceProps);
object->addChild(shapeGroup);
}
} else {
object = m_pluginManager->createObject(tag.second, props);
}
}
break;
}

View File

@ -43,7 +43,7 @@ MTS_NAMESPACE_BEGIN
* Is the cylinder inverted, i.e. should the normal vectors
* be flipped? \default{\code{false}, i.e. the normals point outside}
* }
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}

View File

@ -31,7 +31,7 @@ MTS_NAMESPACE_BEGIN
/*!\plugin{disk}{Disk intersection primitive}
* \order{4}
* \parameters{
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies a linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}

View File

@ -55,7 +55,7 @@ MTS_NAMESPACE_BEGIN
* this convention. \default{\code{true}, i.e. flip them to get the
* correct coordinates}.
* }
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}

View File

@ -62,7 +62,7 @@ MTS_NAMESPACE_BEGIN
* Optional flag to flip all normals. \default{\code{false}, i.e.
* the normals are left unchanged}.
* }
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}

View File

@ -30,7 +30,7 @@ MTS_NAMESPACE_BEGIN
/*!\plugin{rectangle}{Rectangle intersection primitive}
* \order{3}
* \parameters{
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies a linear object-to-world transformation.
* It is allowed to use non-uniform scaling, but no shear.
* \default{none (i.e. object space $=$ world space)}

View File

@ -48,7 +48,7 @@ MTS_NAMESPACE_BEGIN
* Optional flag to flip all normals. \default{\code{false}, i.e.
* the normals are left unchanged}.
* }
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}

View File

@ -37,7 +37,7 @@ MTS_NAMESPACE_BEGIN
* \parameter{radius}{\Float}{
* Radius of the sphere in object-space units \default{1}
* }
* \parameter{toWorld}{\Transform}{
* \parameter{toWorld}{\Transform\Or\ATransform}{
* Specifies an optional linear object-to-world transformation.
* Note that non-uniform scales are not permitted!
* \default{none (i.e. object space $=$ world space)}