ImpostorTexture::~ImpostorTexture() { //Delete textures assert(!texture.isNull()); String texName(texture->getName()); texture.setNull(); if (TextureManager::getSingletonPtr()) TextureManager::getSingleton().remove(texName); //Delete materials for (int o = 0; o < IMPOSTOR_YAW_ANGLES; ++o){ for (int i = 0; i < IMPOSTOR_PITCH_ANGLES; ++i){ assert (!material[i][o].isNull()); String matName(material[i][o]->getName()); material[i][o].setNull(); if (MaterialManager::getSingletonPtr()) MaterialManager::getSingleton().remove(matName); } } //Remove self from list of ImpostorTexture's selfList.erase(entityKey); }
int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const { int graphicsIndex = -1; btAlignedObjectArray<GLInstanceVertex> vertices; btAlignedObjectArray<int> indices; btTransform startTrans; startTrans.setIdentity(); btAlignedObjectArray<MyTexture> textures; const UrdfModel& model = m_data->m_urdfParser.getModel(); UrdfLink* const* linkPtr = model.m_links.getAtIndex(linkIndex); if (linkPtr) { const UrdfLink* link = *linkPtr; for (int v = 0; v < link->m_visualArray.size();v++) { const UrdfVisual& vis = link->m_visualArray[v]; btTransform childTrans = vis.m_linkLocalFrame; btHashString matName(vis.m_materialName.c_str()); UrdfMaterial *const * matPtr = model.m_materials[matName]; if (matPtr) { UrdfMaterial *const mat = *matPtr; //printf("UrdfMaterial %s, rgba = %f,%f,%f,%f\n",mat->m_name.c_str(),mat->m_rgbaColor[0],mat->m_rgbaColor[1],mat->m_rgbaColor[2],mat->m_rgbaColor[3]); m_data->m_linkColors.insert(linkIndex,mat->m_rgbaColor); } convertURDFToVisualShapeInternal(&vis, pathPrefix, localInertiaFrame.inverse()*childTrans, vertices, indices,textures); } } if (vertices.size() && indices.size()) { // graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size()); //graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size()); //CommonRenderInterface* renderer = m_data->m_guiHelper->getRenderInterface(); if (1) { int textureIndex = -1; if (textures.size()) { textureIndex = m_data->m_guiHelper->registerTexture(textures[0].textureData,textures[0].m_width,textures[0].m_height); } graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size(),B3_GL_TRIANGLES,textureIndex); } } //delete textures for (int i=0;i<textures.size();i++) { free( textures[i].textureData); } return graphicsIndex; }
int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame) const { btAlignedObjectArray<GLInstanceVertex> vertices; btAlignedObjectArray<int> indices; btTransform startTrans; startTrans.setIdentity(); int graphicsIndex = -1; #if USE_ROS_URDF_PARSER for (int v = 0; v < (int)m_data->m_links[linkIndex]->visual_array.size(); v++) { const Visual* vis = m_data->m_links[linkIndex]->visual_array[v].get(); btVector3 childPos(vis->origin.position.x, vis->origin.position.y, vis->origin.position.z); btQuaternion childOrn(vis->origin.rotation.x, vis->origin.rotation.y, vis->origin.rotation.z, vis->origin.rotation.w); btTransform childTrans; childTrans.setOrigin(childPos); childTrans.setRotation(childOrn); convertURDFToVisualShape(vis, pathPrefix, inertialFrame.inverse()*childTrans, vertices, indices); } #else const UrdfModel& model = m_data->m_urdfParser.getModel(); UrdfLink* const* linkPtr = model.m_links.getAtIndex(linkIndex); if (linkPtr) { const UrdfLink* link = *linkPtr; for (int v = 0; v < link->m_visualArray.size();v++) { const UrdfVisual& vis = link->m_visualArray[v]; btTransform childTrans = vis.m_linkLocalFrame; btHashString matName(vis.m_materialName.c_str()); UrdfMaterial *const * matPtr = model.m_materials[matName]; if (matPtr) { UrdfMaterial *const mat = *matPtr; //printf("UrdfMaterial %s, rgba = %f,%f,%f,%f\n",mat->m_name.c_str(),mat->m_rgbaColor[0],mat->m_rgbaColor[1],mat->m_rgbaColor[2],mat->m_rgbaColor[3]); m_data->m_linkColors.insert(linkIndex,mat->m_rgbaColor); } convertURDFToVisualShape(&vis, pathPrefix, inertialFrame.inverse()*childTrans, vertices, indices); } } #endif if (vertices.size() && indices.size()) { graphicsIndex = m_data->m_guiHelper->registerGraphicsShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size()); } return graphicsIndex; }
bool MaterialExporter::streamMaterial(std::ostream &of) { // serialize this information to the material file MaterialMap::iterator it = m_materialMap.begin(); while (it != m_materialMap.end()) { std::string matName(it->first); IGameMaterial *mtl = it->second; of << "material " << matName << std::endl; of << std::showpoint; of << "{" << std::endl; of << "\ttechnique" << std::endl; of << "\t{" << std::endl; int numSubMtl = 0; if (mtl != NULL) { numSubMtl = mtl->GetSubMaterialCount(); if (numSubMtl > 0) { int i; for (i=0; i<numSubMtl; i++) { streamPass(of, mtl->GetSubMaterial(i)); } } else streamPass(of, mtl); } else { streamPass(of, mtl); } of << "\t}" << std::endl; of << "}" << std::endl; it++; } m_materialMap.clear(); return true; }
void Streaker::PopulateDatabaseMetaData(avtDatabaseMetaData *md) { std::map<std::string, StreakInfo>::const_iterator it; for(it = streaks.begin(); it != streaks.end(); ++it) { std::string meshName = it->first + "_mesh"; avtMeshMetaData *mmd = new avtMeshMetaData; mmd->name = meshName; mmd->meshType = AVT_CURVILINEAR_MESH; mmd->spatialDimension = 2; mmd->topologicalDimension = 2; mmd->xLabel = it->second.xvar; if(it->second.integrate && it->second.log) mmd->yLabel = std::string("log10(integrated ") + it->second.yvar + std::string(")"); else if(it->second.integrate) mmd->yLabel = std::string("integrated ") + it->second.yvar; else if(it->second.log) mmd->yLabel = std::string("log10(") + it->second.yvar + std::string(")"); else mmd->yLabel = it->second.yvar; mmd->cellOrigin = 1; mmd->nodeOrigin = 1; md->Add(mmd); avtScalarMetaData *smd = new avtScalarMetaData; smd->name = it->first; smd->meshName = meshName; smd->centering = it->second.cellCentered ? AVT_ZONECENT : AVT_NODECENT; md->Add(smd); // Add a material for this streak plot if its ireg matched the size of zvar. if(it->second.hasMaterial) { std::string matName(it->first + "_mat"); matToStreak[matName] = it->first; avtMaterialMetaData *mmd = new avtMaterialMetaData(matName, meshName, matNames.size(), matNames); md->Add(mmd); } } }
void IR_affineImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); // detect image extension string ext; vector<string> fileNames; getDirList(path, fileNames); for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { string &name = *it; if (name.length()>=8 && name.substr(0, 3)=="img") { ext = name.substr(name.length()-4, 4); break; } } for (unsigned int i=1; i<=6; ++i) { Ptr<IR_affineObj> curr(new IR_affineObj); char tmp[2]; sprintf(tmp, "%u", i); curr->imageName = path + "img" + tmp + ext; if (i>1) { string matName(path + "H1to" + tmp + "p"); ifstream infile(matName.c_str()); for (int k=0; k<3; ++k) { for (int j=0; j<3; ++j) { infile >> curr->mat(k, j); } } } train.back().push_back(curr); }
RenderedTexture::~RenderedTexture() { //Delete texture assert(!texture.isNull()); std::string texName(texture->getName()); texture.setNull(); if (Ogre::TextureManager::getSingletonPtr()) Ogre::TextureManager::getSingleton().remove(texName); //Delete material assert (!material.isNull()); std::string matName(material->getName()); material.setNull(); if (Ogre::MaterialManager::getSingletonPtr()) Ogre::MaterialManager::getSingleton().remove(matName); //Remove self from list of RenderedTextures selfList.erase(entityKey); }
void TinyRendererVisualShapeConverter::convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfModel& model, class btCollisionObject* colObj) { UrdfLink* const* linkPtr = model.m_links.getAtIndex(linkIndex); if (linkPtr) { const UrdfLink* link = *linkPtr; for (int v = 0; v < link->m_visualArray.size();v++) { btAlignedObjectArray<MyTexture2> textures; btAlignedObjectArray<GLInstanceVertex> vertices; btAlignedObjectArray<int> indices; btTransform startTrans; startTrans.setIdentity(); int graphicsIndex = -1; const UrdfVisual& vis = link->m_visualArray[v]; btTransform childTrans = vis.m_linkLocalFrame; btHashString matName(vis.m_materialName.c_str()); UrdfMaterial *const * matPtr = model.m_materials[matName]; float rgbaColor[4] = {1,1,1,1}; if (matPtr) { UrdfMaterial *const mat = *matPtr; for (int i=0;i<4;i++) rgbaColor[i] = mat->m_rgbaColor[i]; //printf("UrdfMaterial %s, rgba = %f,%f,%f,%f\n",mat->m_name.c_str(),mat->m_rgbaColor[0],mat->m_rgbaColor[1],mat->m_rgbaColor[2],mat->m_rgbaColor[3]); //m_data->m_linkColors.insert(linkIndex,mat->m_rgbaColor); } TinyRendererObjectArray** visualsPtr = m_data->m_swRenderInstances[colObj]; if (visualsPtr==0) { m_data->m_swRenderInstances.insert(colObj,new TinyRendererObjectArray); } visualsPtr = m_data->m_swRenderInstances[colObj]; btAssert(visualsPtr); TinyRendererObjectArray* visuals = *visualsPtr; convertURDFToVisualShape(&vis, pathPrefix, localInertiaFrame.inverse()*childTrans, vertices, indices,textures); if (vertices.size() && indices.size()) { TinyRenderObjectData* tinyObj = new TinyRenderObjectData(m_data->m_rgbColorBuffer,m_data->m_depthBuffer); unsigned char* textureImage=0; int textureWidth=0; int textureHeight=0; if (textures.size()) { textureImage = textures[0].textureData; textureWidth = textures[0].m_width; textureHeight = textures[0].m_height; } tinyObj->registerMeshShape(&vertices[0].xyzw[0],vertices.size(),&indices[0],indices.size(),rgbaColor, textureImage,textureWidth,textureHeight); visuals->m_renderObjects.push_back(tinyObj); } for (int i=0;i<textures.size();i++) { delete textures[i].textureData; } } } }
// MilkShape 3D void ExportMS3D_M2(Attachment *att, Model *m, const char *fn, bool init) { wxFFileOutputStream f(wxString(fn, wxConvUTF8), wxT("w+b")); if (!f.IsOk()) { wxLogMessage(wxT("Error: Unable to open file '%s'. Could not export model."), fn); return; } LogExportData(wxT("MS3D"),m->modelname,wxString(fn, wxConvUTF8)); unsigned short numVerts = 0; unsigned short numFaces = 0; unsigned short numGroups = 0; ModelData *verts = NULL; GroupData *groups = NULL; //we need the initial position anyway InitCommon(att, true, verts, groups, numVerts, numGroups, numFaces); //wxLogMessage(wxT("Num Verts: %i, Num Faces: %i, Num Groups: %i"), numVerts, numFaces, numGroups); //wxLogMessage(wxT("Vert[0] BoneID: %i, Group[0].m.name = %s"),verts[0].boneid, groups[0].m->name); wxLogMessage(wxT("Init Common Complete.")); // Write the header ms3d_header_t header; strncpy(header.id, "MS3D000000", sizeof(header.id)); header.version = 4; // Header f.Write(reinterpret_cast<char *>(&header), sizeof(ms3d_header_t)); wxLogMessage(wxT("Header Data Written.")); // Vertex Count f.Write(reinterpret_cast<char *>(&numVerts), sizeof(numVerts)); //wxLogMessage(wxT("NumVerts: %i"),numVerts); // Write Vertex data? for (size_t i=0; i<numVerts; i++) { ms3d_vertex_t vert; vert.boneId = verts[i].boneid; vert.flags = 0; //SELECTED; vert.referenceCount = 0; // what the? vert.vertex[0] = verts[i].vertex.x; vert.vertex[1] = verts[i].vertex.y; vert.vertex[2] = verts[i].vertex.z; f.Write(reinterpret_cast<char *>(&vert), sizeof(ms3d_vertex_t)); } wxLogMessage(wxT("Vertex Data Written.")); // --------------------------- // Triangle Count f.Write(reinterpret_cast<char *>(&numFaces), sizeof(numFaces)); //wxLogMessage(wxT("NumFaces: %i"),numFaces); // Write Triangle Data? for (size_t i=0; i<(unsigned int)numVerts; i+=3) { ms3d_triangle_t tri; tri.flags = 0; //SELECTED; tri.groupIndex = (unsigned char)verts[i].groupIndex; tri.smoothingGroup = 1; // 1 - 32 for (ssize_t j=0; j<3; j++) { tri.vertexIndices[j] = (word)i+j; tri.s[j] = verts[i+j].tu; tri.t[j] = verts[i+j].tv; tri.vertexNormals[j][0] = verts[i+j].normal.x; tri.vertexNormals[j][1] = verts[i+j].normal.y; tri.vertexNormals[j][2] = verts[i+j].normal.z; } f.Write(reinterpret_cast<char *>(&tri), sizeof(ms3d_triangle_t)); } wxLogMessage(wxT("Triangle Data Written.")); // --------------------------- // Number of groups f.Write(reinterpret_cast<char *>(&numGroups), sizeof(numGroups)); //wxLogMessage(wxT("NumGroups: %i"),numGroups); unsigned short indiceCount = 0; for (unsigned short i=0; i<(unsigned int)numGroups; i++) { wxString groupName(wxString::Format(wxT("Geoset_%i"), i)); const char flags = 0; // SELECTED f.Write(&flags, sizeof(flags)); char name[32]; strncpy(name, groupName.mb_str(), sizeof(name)); f.Write(name, sizeof(name)); unsigned short faceCount = groups[i].p.indexCount / 3; f.Write(reinterpret_cast<char *>(&faceCount), sizeof(faceCount)); for (ssize_t k=0; k<faceCount; k++) { //triIndices[k] = indiceCount; f.Write(reinterpret_cast<char *>(&indiceCount), sizeof(indiceCount)); indiceCount++; } unsigned char gIndex = (char)i; f.Write(reinterpret_cast<char *>(&gIndex), sizeof(gIndex)); } wxLogMessage(wxT("Group Data Written.")); // Number of materials (pretty much identical to groups, each group has its own material) f.Write(reinterpret_cast<char *>(&numGroups), sizeof(numGroups)); for (unsigned short i=0; i<(unsigned int)numGroups; i++) { wxString matName(wxString::Format(wxT("Material_%i"), i)); ModelRenderPass p = groups[i].p; if (p.init(groups[i].m)) { ms3d_material_t mat; memset(mat.alphamap, '\0', sizeof(mat.alphamap)); strncpy(mat.name, matName.mb_str(), sizeof(mat.name)); mat.ambient[0] = 0.7f; mat.ambient[1] = 0.7f; mat.ambient[2] = 0.7f; mat.ambient[3] = 1.0f; mat.diffuse[0] = p.ocol.x; mat.diffuse[1] = p.ocol.y; mat.diffuse[2] = p.ocol.z; mat.diffuse[3] = p.ocol.w; mat.specular[0] = 0.0f; mat.specular[1] = 0.0f; mat.specular[2] = 0.0f; mat.specular[3] = 1.0f; mat.emissive[0] = p.ecol.x; mat.emissive[1] = p.ecol.y; mat.emissive[2] = p.ecol.z; mat.emissive[3] = p.ecol.w; mat.transparency = p.ocol.w; if (p.useEnvMap) { mat.shininess = 30.0f; mat.mode = 1; } else { mat.shininess = 0.0f; mat.mode = 0; } /* unsigned int bindtex = 0; if (groups[i].m->specialTextures[p.tex]==-1) bindtex = groups[i].m->textures[p.tex]; else bindtex = groups[i].m->replaceTextures[groups[i].m->specialTextures[p.tex]]; */ wxString texName = GetM2TextureName(m,p,i); texName << wxT(".tga"); strncpy(mat.texture, texName.mb_str(), sizeof(mat.texture)); f.Write(reinterpret_cast<char *>(&mat), sizeof(ms3d_material_t)); wxString texFilename(fn, wxConvUTF8); texFilename = texFilename.BeforeLast(SLASH); texFilename += SLASH; texFilename += texName; wxLogMessage(wxT("Exporting Image: %s"),texFilename.c_str()); SaveTexture(texFilename); } } wxLogMessage(wxT("Material Data Written.")); if (init) { float fps = 1.0f; float fCurTime = 0.0f; int totalFrames = 0; f.Write(reinterpret_cast<char *>(&fps), sizeof(fps)); f.Write(reinterpret_cast<char *>(&fCurTime), sizeof(fCurTime)); f.Write(reinterpret_cast<char *>(&totalFrames), sizeof(totalFrames)); // number of joints unsigned short numJoints = 0; f.Write(reinterpret_cast<char *>(&numJoints), sizeof(numJoints)); } else { float fps = 25.0f; float fCurTime = 0.0f; int totalFrames = ceil((m->anims[m->anim].timeEnd - m->anims[m->anim].timeStart) / 1000.0f * fps); f.Write(reinterpret_cast<char *>(&fps), sizeof(fps)); f.Write(reinterpret_cast<char *>(&fCurTime), sizeof(fCurTime)); f.Write(reinterpret_cast<char *>(&totalFrames), sizeof(totalFrames)); // number of joints unsigned short numJoints = (unsigned short)m->header.nBones; f.Write(reinterpret_cast<char *>(&numJoints), sizeof(numJoints)); for (size_t i=0; i<numJoints; i++) { ms3d_joint_t joint; int parent = m->bones[i].parent; joint.flags = 0; // SELECTED memset(joint.name, '\0', sizeof(joint.name)); snprintf(joint.name, sizeof(joint.name), "Bone_%i", i); memset(joint.parentName, '\0', sizeof(joint.parentName)); if (parent != -1) snprintf(joint.parentName, sizeof(joint.parentName), "Bone_%i", parent); joint.rotation[0] = 0; joint.rotation[1] = 0; joint.rotation[2] = 0; Vec3D p = FixPivot(m, (int)i, m->bones[i].pivot); joint.position[0] = p.x; joint.position[1] = p.y; joint.position[2] = p.z; joint.numKeyFramesRot = (unsigned short)m->bones[i].rot.data[m->anim].size(); joint.numKeyFramesTrans = (unsigned short)m->bones[i].trans.data[m->anim].size(); f.Write(reinterpret_cast<char *>(&joint), sizeof(ms3d_joint_t)); if (joint.numKeyFramesRot > 0) { ms3d_keyframe_rot_t *keyFramesRot = new ms3d_keyframe_rot_t[joint.numKeyFramesRot]; for (size_t j=0; j<joint.numKeyFramesRot; j++) { keyFramesRot[j].time = m->bones[i].rot.times[m->anim][j] / 1000.0f; Vec3D euler = QuatToEuler(m->bones[i].rot.data[m->anim][j]); keyFramesRot[j].rotation[0] = euler.x; keyFramesRot[j].rotation[1] = euler.y; keyFramesRot[j].rotation[2] = euler.z; } f.Write(reinterpret_cast<char *>(keyFramesRot), sizeof(ms3d_keyframe_rot_t) * joint.numKeyFramesRot); wxDELETEA(keyFramesRot); } if (joint.numKeyFramesTrans > 0) { ms3d_keyframe_pos_t *keyFramesTrans = new ms3d_keyframe_pos_t[joint.numKeyFramesTrans]; for (size_t j=0; j<joint.numKeyFramesTrans; j++) { keyFramesTrans[j].time = m->bones[i].trans.times[m->anim][j] / 1000.0f; keyFramesTrans[j].position[0] = m->bones[i].trans.data[m->anim][j].x; keyFramesTrans[j].position[1] = m->bones[i].trans.data[m->anim][j].y; keyFramesTrans[j].position[2] = m->bones[i].trans.data[m->anim][j].z; } f.Write(reinterpret_cast<char *>(keyFramesTrans), sizeof(ms3d_keyframe_pos_t) * joint.numKeyFramesTrans); wxDELETEA(keyFramesTrans); } } } f.Close(); wxLogMessage(wxT("Finished Milkshape Export.")); if (verts){ //wxLogMessage("verts found. Deleting..."); wxDELETEA(verts); } if (groups){ //wxLogMessage("groups found. Deleting..."); wxDELETEA(groups); } //wxLogMessage(wxT("Finished Milkshape Cleanup.\n")); }
void VBOWFModel::Tokenise_Data(std::string input) { float tempfloat[3]; //temporary float array of 3 StringTokens tokens(input,' '); if(tokens.First_token()=="v") //if vertices { tokens.Next_token(); tempfloat[0] = (float)atof(tokens.Next_token().c_str()); //x value tempfloat[1] = (float)atof(tokens.Next_token().c_str()); //y value tempfloat[2] = (float)atof(tokens.Next_token().c_str()); //z value verts.push_back(Vec3f(tempfloat[0],tempfloat[1],tempfloat[2])); } else if(tokens.First_token()=="vn") //if normals { tokens.Next_token(); tempfloat[0] = (float)atof(tokens.Next_token().c_str()); //x value tempfloat[1] = (float)atof(tokens.Next_token().c_str()); //y value tempfloat[2] = (float)atof(tokens.Next_token().c_str()); //z value norms.push_back(Vec3f(tempfloat[0],tempfloat[1],tempfloat[2])); } else if(tokens.First_token()=="vt") //if texture coords { tokens.Next_token(); tempfloat[0] = (float)atof(tokens.Next_token().c_str()); //x value tempfloat[1] = (float)atof(tokens.Next_token().c_str()); //y value tempfloat[2] = (float)atof(tokens.Next_token().c_str()); //z value tex.push_back(Vec2f(tempfloat[0],tempfloat[1])); } else if(tokens.First_token()=="f") //if face { tokens.Next_token(); Vec3f temp; for(int i=0; i<3; i++) //get 3 vert indexes, text coord index, normals index { StringTokens faceTokens(tokens.Next_token(),'/'); m_Vindices.push_back(atoi(faceTokens.Next_token().c_str())-1); //store vertex index m_Tindices.push_back(atoi(faceTokens.Next_token().c_str())-1); m_Nindices.push_back(atoi(faceTokens.Next_token().c_str())-1); } } else if(tokens.First_token()=="mtllib") //if material lib { string mtl = "Model/"; //mtl file location string image = "textures/wdworld/"; //image file location string temp2; tokens.Next_token(); mtl.append(tokens.Next_token()); //add it to the location ifstream material(mtl.c_str()); //create input filestream for MTL if(material) //if material exists { while(std::getline(material, temp2)) //tokenize MTL { istringstream matName(temp2); getline(matName,temp2); //get image name image.append(temp2); //add it to the location mtlName.push_back(image); //store it image = "textures/wdworld/"; //reset image to only location } m_texture = Texture(mtlName.back()); if(!(m_texture.LoadTexture()))//if loaded succesfully { cout << "File DNE" << endl; } } else //if material DNE { cout << "material file " << temp2 << " DNE" << endl; } } }