void Importer::importEffectElement(const QDomElement& element) { if (element.hasAttribute("effect")) { QFileInfo effectFile(m_sourceResourcePath, element.attribute("effect")); importEffectFile(effectFile, element.attribute("effect"), QString()); } QDomNodeList childs = element.childNodes(); for (int i=0; i<childs.count(); ++i) importEffectElement(childs.at(i).toElement()); }
void QEmitterNode::addRepresentation() { m_matResource = h3dAddResource(H3DResTypes::Material, qPrintable(m_xmlNode.attribute("material")), 0); // Load resource immediately since a later call to loadResourceFromDisk results in a bad behaviour of the Horde3D engine QString resourceName = h3dutGetResourcePath(H3DResTypes::Material); if( !resourceName.isEmpty() && !resourceName.endsWith('/') && !resourceName.endsWith('\\') ) resourceName += '/'; resourceName += m_xmlNode.attribute("material"); QFile matFile(QFileInfo(resourceName).absoluteFilePath()); if (!matFile.open(QIODevice::ReadOnly)) qWarning("Error opening resource %s", qPrintable(m_xmlNode.attribute("material"))); // Stupid return value, if false it can also be the case that the resource was loaded before instead of that their was an error h3dLoadResource(m_matResource, matFile.readAll().append('\0').constData(), matFile.size() + 1); matFile.close(); m_effectResource = h3dAddResource(H3DResTypes::ParticleEffect, qPrintable(m_xmlNode.attribute("particleEffect")), 0); // Load resource immediately since a later call to loadResourceFromDisk results in a bad behaviour of the Horde3D engine resourceName = h3dutGetResourcePath(H3DResTypes::ParticleEffect); if (!resourceName.isEmpty() && !resourceName.endsWith('/') && !resourceName.endsWith('\\')) resourceName += '/'; resourceName += m_xmlNode.attribute("particleEffect"); QFile effectFile(QFileInfo(resourceName).absoluteFilePath()); if (!effectFile.open(QIODevice::ReadOnly)) qWarning("Error opening resource %s", qPrintable(m_xmlNode.attribute("particleEffect"))); // Stupid return value, if false it can also be the case that the resource was loaded before instead of that their was an error h3dLoadResource(m_effectResource, effectFile.readAll().append('\0').constData(), effectFile.size()+1); effectFile.close(); QSceneNode* parentNode = static_cast<QSceneNode*>(parent()); unsigned int rootID = parentNode ? parentNode->hordeId() : H3DRootNode; m_hordeID = h3dAddEmitterNode( rootID, qPrintable(m_xmlNode.attribute("name", "ATTENTION No Node Name")), m_matResource, m_effectResource, m_xmlNode.attribute("maxCount").toUInt(), m_xmlNode.attribute("respawnCount").toInt() ); h3dSetNodeParamF(m_hordeID, H3DEmitter::ForceF3, 0, m_xmlNode.attribute("forceX", "0.0").toFloat()); h3dSetNodeParamF(m_hordeID, H3DEmitter::ForceF3, 1, m_xmlNode.attribute("forceY", "0.0").toFloat()); h3dSetNodeParamF(m_hordeID, H3DEmitter::ForceF3, 2, m_xmlNode.attribute("forceZ", "0.0").toFloat()); h3dSetNodeParamF(m_hordeID, H3DEmitter::DelayF, 0, m_xmlNode.attribute("delay", "0.0").toFloat()); h3dSetNodeParamF(m_hordeID, H3DEmitter::SpreadAngleF, 0, m_xmlNode.attribute("spreadAngle", "0.0").toFloat()); h3dSetNodeParamF(m_hordeID, H3DEmitter::EmissionRateF, 0, m_xmlNode.attribute("emissionRate", "0.0").toFloat()); // load transformation from file... float x, y, z, rx, ry, rz, sx, sy, sz; getTransformation(x,y,z,rx,ry,rz,sx,sy,sz); // ...and update scene representation h3dSetNodeTransform(m_hordeID, x, y, z, rx, ry, rz, sx, sy, sz); // Attachment QDomElement attachment = m_xmlNode.firstChildElement("Attachment"); SceneTreeModel* model = static_cast<SceneTreeModel*>(m_model); AttachmentPlugIn* plugIn = model->nodeFactory()->attachmentPlugIn(); if (!attachment.isNull() && plugIn != 0) plugIn->initNodeAttachment(this); startTimer(100); }
int main( int argc, char** argv ) { osg::ArgumentParser arguments( &argc, argv ); int displayMode = 1; if ( arguments.read("--simple-mode") ) displayMode = 0; else if ( arguments.read("--analysis-mode") ) displayMode = 1; else if ( arguments.read("--compare-mode") ) displayMode = 2; std::string effectFile("test.xml"); arguments.read( "--effect", effectFile ); bool shadowed = false; if ( arguments.read("--shadowed") ) shadowed = true; float lodscale = 1.0f; arguments.read( "--lod-scale", lodscale ); std::string normalSceneFile; arguments.read( "--normal-scene", normalSceneFile ); // Create the scene osg::Node* model = osgDB::readNodeFiles( arguments ); if ( !model ) model = osgDB::readNodeFile( "lz.osg" ); osg::ref_ptr<osg::Group> scene = new osg::Group; scene->addChild( createSkyBox() ); scene->addChild( shadowed ? createShadowedScene(model) : model ); // Create the effect compositor from XML file #ifdef HAVE_SILVERLINING osg::ref_ptr<osgDB::XmlNode> xmlRoot = osgDB::readXmlFile( effectFile ); if ( !xmlRoot ) { OSG_WARN << "Effect file " << effectFile << " can't be loaded!" << std::endl; return 1; } // FIXME: SilverLining seems to be uncomfortable with default FBO settings? // I'm not sure if this is a SilverLining bug or mine osgFX::EffectCompositor::XmlTemplateMap templateMap; osgFX::EffectCompositor* compositor = new osgFX::EffectCompositor; //compositor->setRenderTargetImplementation( osg::Camera::PIXEL_BUFFER ); // FIXME: PIXEL_BUFFER can't work with NVIDIA 310.70 driver? compositor->loadFromXML( xmlRoot.get(), templateMap, NULL ); #else osgFX::EffectCompositor* compositor = osgFX::readEffectFile( effectFile ); if ( !compositor ) { OSG_WARN << "Effect file " << effectFile << " can't be loaded!" << std::endl; return 1; } #endif // For the fastest and simplest effect use, this is enough! compositor->addChild( scene.get() ); // Add all to the root node of the viewer osg::ref_ptr<osg::Group> root = new osg::Group; root->addChild( compositor ); if ( !normalSceneFile.empty() ) { // root->addChild( osgDB::readNodeFile(normalSceneFile) ); } osgViewer::Viewer viewer; viewer.getCamera()->setLODScale( lodscale ); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::WindowSizeHandler ); viewer.setSceneData( root.get() ); if ( displayMode>0 ) configureViewerForMode( viewer, compositor, scene.get(), displayMode ); viewer.setUpViewOnSingleScreen( 0 ); return viewer.run(); }
bool ImageProcessor::initialize() { if (initialized_) { return initialized_; } if (!quadrilateral_) { return initialized_; } OpaqueProperties properties; properties.push_back(OpaqueProperty("cache_option", BaseResourceLoader::DoNoCacheResources)); // Force no cache, some processors are dynamically generated properties.push_back(OpaqueProperty("symbols", shader_symbols_)); SharedPointer<Program> program = CoreEngine::instance()->resourceManager().load<Program>( effectFile(), properties); if (program) { quadrilateral_->states()->setProgram(program); float width = float(inputs_[0]->getWidth()); float height = float(inputs_[0]->getHeight()); if (program->hasUniform("mvp")) { Matrix mvp = Matrix::ortho2D(0.0, width, 0.0f, height); program->uniform("mvp").set(mvp); } if (program->hasUniform("texture_0")) { program->uniform("texture_0").set(0); } if (program->hasUniform("pixel_size")) { Vector2D pixe_size(1.0f / width, 1.0f / height); program->uniform("pixel_size").set(pixe_size); } initialized_ = true; } return initialized_; }