bool Animation::loadFile(Agent_Gender::List gender) { m_file = m_data->getFile(gender); std::string filename(m_file->getFilename()); int resource = h3dAddResource( H3DResTypes::Animation, m_file->getFilename(), 0 ); if(h3dIsResLoaded(resource)) { // if the resource is already loaded, we'll create a duplicate for this animation to use resource = h3dCloneResource(resource, 0); setResource(resource); return true; } //find animation path std::string path = h3dutGetResourcePath(H3DResTypes::Animation); if ( path.size() > 0 && path[path.size()-1] != '\\' && path[path.size()-1] != '/' ) path += '/'; //Open file std::ifstream inf( (path + filename).c_str(), std::ios::binary ); if( inf ) // Resource file found { // Find size of resource file inf.seekg( 0, std::ios::end ); const int size = inf.tellg(); // Copy resource file to memory char *data = new char[size + 1]; inf.seekg( 0 ); inf.read( data, size ); inf.close(); // Null-terminate buffer - this is important for XML parsers data[size] = '\0'; // Load Resource h3dLoadResource( resource, data, size ); setResource(resource); delete[] data; data = 0; return true; } else { //file not found GameLog::errorMessage( "Animation %s failed to load - file not found", m_file->getFilename() ); return false; } }
void QModelNode::addRepresentation() { m_resourceID = h3dAddResource(H3DResTypes::Geometry, qPrintable(m_xmlNode.attribute("geometry")), 0); // Load resource immediately since a later call to loadResourceFromDisk results in a bad behaviour of the Horde3D engine QString resourceName = h3dutGetResourcePath(H3DResTypes::Geometry); if( !resourceName.isEmpty() && !resourceName.endsWith('/') && !resourceName.endsWith('\\')) resourceName += '/'; resourceName += geometry(); QFile file(QFileInfo(resourceName).absoluteFilePath()); if (!file.open(QIODevice::ReadOnly)) qWarning("Error opening resource %s (%s)", qPrintable(m_xmlNode.attribute("geometry")), qPrintable( QFileInfo(resourceName).absoluteFilePath() )); // 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_resourceID, file.readAll().constData(), file.size()); file.close(); QSceneNode* parentNode = static_cast<QSceneNode*>(parent()); unsigned int rootID = parentNode ? parentNode->hordeId() : H3DRootNode; m_hordeID = h3dAddModelNode(rootID, qPrintable(m_xmlNode.attribute("name", "ATTENTION No Node Name")), m_resourceID); float x, y, z, rx, ry, rz, sx, sy, sz; getTransformation(x,y,z,rx,ry,rz,sx,sy,sz); h3dSetNodeTransform(m_hordeID, x, y, z, rx, ry, rz, sx, sy, sz); h3dSetNodeParamI(m_hordeID, H3DModel::SWSkinningI, softwareSkinning()); h3dSetNodeParamF(m_hordeID, H3DModel::LodDist1F, 0, lodDist1()); h3dSetNodeParamF(m_hordeID, H3DModel::LodDist2F, 0, lodDist2()); h3dSetNodeParamF(m_hordeID, H3DModel::LodDist3F, 0, lodDist3()); h3dSetNodeParamF(m_hordeID, H3DModel::LodDist4F, 0, lodDist4()); // 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); }
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); }