/** * loads a minimal geometry resource */ bool Gaze::loadGazeAuxRes(H3DRes res) { unsigned int version = (int)Config::getParamF(IK_Param::H3DGVersion_F); unsigned int count = 0; //Generating the resource char* data = (char *)malloc(29); unsigned int dataSize = 0; memcpy( data + dataSize, "H3DG", 4 ); dataSize += 4; memcpy( data + dataSize, &version, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //version memcpy( data + dataSize, &count, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //joints memcpy( data + dataSize, &count, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //streams memcpy( data + dataSize, &count, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //vertices memcpy( data + dataSize, &count, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //triangles memcpy( data + dataSize, &count, sizeof( unsigned int ) ); dataSize += sizeof( unsigned int ); //morph targets char term = '\0'; memcpy( data +dataSize, &term, sizeof( char ) ); dataSize += sizeof( char ); if( !h3dLoadResource( res, data, dataSize ) ) return false; return true; }
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; } }
int loadTexture(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Texture, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load texture resource"); } int handle = TextureManager::addTexture(res); dumpMessages(); return handle; }
void setPipeline(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Pipeline, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load pipeline resource"); } else { if(_pipeline) h3dUnloadResource(_pipeline); _pipeline = res; Viewer::newCamera(res); dumpMessages(); } }
void setShader(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Shader, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load shader resource"); } else { if(_shader) h3dUnloadResource(_shader); _shader = res; _mat_builder->setShader(name); _mat_builder->build(); dumpMessages(); } }
void setGeo(const char* buffer, size_t size) { char name[64] = ""; snprintf(name, 64, "_res%i", _res_loaded++); H3DRes res = h3dAddResource(H3DResTypes::Geometry, name, 0); if(!h3dLoadResource(res, buffer, size)) { dumpMessages(); throw tgException("unable to load shader resource"); } else { if(_geometry) h3dUnloadResource(_geometry); _geometry = res; if(_geometry != 0 && _shader != 0) Viewer::newModel(_geometry, _mat_builder->getRes()); dumpMessages(); } }
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 QTerrainNode::addRepresentation() { m_heightMapID = h3dAddResource( H3DResTypes::Texture, qPrintable(m_xmlNode.attribute("heightmap")), H3DResFlags::NoTexCompression | H3DResFlags::NoTexMipmaps ); m_materialID = 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 QDir textureDir( QDir::current() ); QFile file(textureDir.absoluteFilePath(m_xmlNode.attribute("heightmap"))); if (!file.open(QIODevice::ReadOnly)) qWarning("Error opening resource %s", qPrintable(m_xmlNode.attribute("heightmap"))); // 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_heightMapID, file.readAll().constData(), file.size()); file.close(); QSceneNode* parentNode = static_cast<QSceneNode*>(parent()); unsigned int rootID = parentNode ? parentNode->hordeId() : H3DRootNode; m_hordeID = h3dextAddTerrainNode(rootID, qPrintable(m_xmlNode.attribute("name", "ATTENTION No Node Name")), m_heightMapID, m_materialID); h3dSetNodeParamI(m_hordeID, H3DEXTTerrain::BlockSizeI, blockSize()); h3dSetNodeParamF(m_hordeID, H3DEXTTerrain::MeshQualityF, 0, meshQuality()); h3dSetNodeParamF(m_hordeID, H3DEXTTerrain::SkirtHeightF, 0, skirtHeight()); 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); // 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); }