// Meshes Mesh* ResourceManager::getSpriteMesh(int width, int height, float pivotx, float pivoty, float uvwidth, float uvheight, int circle, int which) { char buf[64]; // should be big enough: "1024x1024_0.50000x0.50000_1.00000x1.00000_0_60" sprintf(buf, "%dx%d_%.5fx%.5f_%.5fx%.5f_%d_%d", width, height, pivotx, pivoty, uvwidth, uvheight, circle, which); std::string meshname(buf); if (_meshes[meshname] != NULL) { //std::cout << "return existing resource: " << meshname << " (mesh)" << std::endl; return _meshes[meshname]; } else { Mesh* m = new Mesh(); if (circle != 0) { if (which >= 0) { m->generateSegmentMesh(width/2, circle, which); } else { m->generateCircleMesh(width/2, circle, uvwidth, uvheight); } } else { m->generateSpriteMesh(width, height, pivotx, pivoty, uvwidth, uvheight); } _meshes[meshname] = m; std::cout << "return new resource: " << meshname << " (mesh)" << std::endl; return m; } return NULL; }
bool CMainFrame::_CreateMeshPanel( CImageList& imageList, Ogre::StringVectorPtr& meshNames ) { if (!m_resourceSelector.Create(WS_CHILD|WS_VISIBLE, CRect(200,100,400,300), this, IDS_ResourceSelector)) return false; m_resourceSelector.SetOwner(this); m_resourceSelector.SetIconSize(CSize(MESH_ICON_SIZE, MESH_ICON_SIZE)); CXTPTaskPanelGroup* pGroup = m_resourceSelector.AddGroup(IDS_ResourceSelector_Mesh); int itemCount = imageList.GetImageCount(); m_resourceSelector.GetImageManager()->SetImageList(imageList.Detach(), 0); for (int i=0; i<itemCount; ++i) { std::wstring meshname(Utility::EngineToUnicode(meshNames->at(i))); meshname.erase(meshname.length()-5); // Add folder entries CXTPTaskPanelGroupItem* pItem = pGroup->AddLinkItem(i, 0); pItem->SetIconIndex(i); pItem->SetCaption(meshname.c_str()); } m_resourceSelector.SetBehaviour(xtpTaskPanelBehaviourList); m_resourceSelector.SetSelectItemOnFocus(TRUE); m_resourceSelector.SetMultiColumn(TRUE); m_resourceSelector.SetColumnWidth(RES_SELECTOR_COLUMN_WIDTH); m_resourceSelector.GetAt(0)->SetExpanded(TRUE); //拖拽支持 m_resourceSelector.AllowDrag(xtpTaskItemAllowDragCopyOutsideControl); return true; }
/** \brief Processes a single URDF link, creates renderable for it */ void URDFRenderer::process_link (boost::shared_ptr<urdf::Link> link) { for(std::vector<boost::shared_ptr<urdf::Visual> >::iterator it=link->visual_array.begin(); it != link->visual_array.end(); ++it) { boost::shared_ptr<urdf::Visual> visual = *it; if (visual.get() == NULL || visual->geometry.get() == NULL) continue; ROS_DEBUG_STREAM("Processing link: "<<link->name); boost::shared_ptr<Renderable> r; if (visual->geometry->type == urdf::Geometry::BOX) { boost::shared_ptr<urdf::Box> box = boost::dynamic_pointer_cast<urdf::Box> (visual->geometry); r.reset (new RenderableBox (box->dim.x, box->dim.y, box->dim.z)); } else if (visual->geometry->type == urdf::Geometry::CYLINDER) { boost::shared_ptr<urdf::Cylinder> cylinder = boost::dynamic_pointer_cast<urdf::Cylinder> (visual->geometry); r.reset (new RenderableCylinder (cylinder->radius, cylinder->length)); } else if (visual->geometry->type == urdf::Geometry::SPHERE) { boost::shared_ptr<urdf::Sphere> sphere = boost::dynamic_pointer_cast<urdf::Sphere> (visual->geometry); r.reset (new RenderableSphere (sphere->radius)); } else if (visual->geometry->type == urdf::Geometry::MESH) { boost::shared_ptr<urdf::Mesh> mesh = boost::dynamic_pointer_cast<urdf::Mesh> (visual->geometry); std::string meshname (mesh->filename); RenderableMesh* rm = new RenderableMesh (meshname); rm->setScale (mesh->scale.x, mesh->scale.y, mesh->scale.z); r.reset (rm); } r->setLinkName (tf_prefix_+ "/" + link->name); urdf::Vector3 origin = visual->origin.position; urdf::Rotation rotation = visual->origin.rotation; r->link_offset = tf::Transform ( tf::Quaternion (rotation.x, rotation.y, rotation.z, rotation.w).normalize (), tf::Vector3 (origin.x, origin.y, origin.z)); if (visual && (visual->material)) r->color = visual->material->color; renderables_.push_back (r); } }
void PhysicsSim::drawVector(Vector3D init, Vector3D end, Color c) { Vector3D vec = end-init; float length = vec.getLength(); stringw meshname("ArrowMesh"); meshname += (int)arrows.size(); IAnimatedMesh* arrow = smgr->addArrowMesh (meshname, c, c, 4, 8, length, (length - 0.4 < 0.0) ? length*0.4 : (length-0.4)); IAnimatedMeshSceneNode *arrownode = smgr->addAnimatedMeshSceneNode(arrow); arrownode->setPosition(init); //arrownode->setScale(vector3df(1.0, length, 1.0)); vec.normalize(); quaternion q; q.rotationFromTo(vector3df(0,1,0), vec); vector3df rot; q.toEuler(rot); arrownode->setRotation(vector3df(rot.X*180.0/M_PI, rot.Y*180.0/M_PI, rot.Z*180.0/M_PI)); arrows.push_back(arrownode); }
bool PhysicsSim::loadPhysicalObjects(PhysicalStructure &structure, stringc mesh_filename, Vector3D position, bool lock2d) { stringc physics_filename = mesh_filename; physics_filename.remove(".dae"); physics_filename.append(".bullet"); physics_filename = mediaDirectory + physics_filename; if(smgr->getFileSystem()->existFile(physics_filename)) { stringw collada_filename = smgr->getFileSystem()->getAbsolutePath(mediaDirectory) + mesh_filename; if(smgr->getFileSystem()->existFile(collada_filename)) { btBlenderImporter* fileLoader = new btBlenderImporter(position); fileLoader->loadFile(physics_filename.c_str()); smgr->getMesh(collada_filename); for(int i = 0; i < fileLoader->getNumRigidBodies(); i++) { btRigidBody* rb = (btRigidBody*)fileLoader->getRigidBodyByIndex(i); if(lock2d) { rb->setLinearFactor(btVector3(1,0,1)); rb->setAngularFactor(btVector3(0,1,0)); } stringc meshname(fileLoader->getNameForPointer(rb)); stringc bodyname = meshname; stringc tex_file = meshname; s32 underline = tex_file.findFirst('_'); if(underline < 0) underline = tex_file.findFirst('.'); if(underline > -1) tex_file = tex_file.subString(0, underline+1); tex_file = mediaDirectory + tex_file + ".jpg"; if(fileLoader->getNumRigidBodies() > 1) meshname = collada_filename + "#" + meshname + "-mesh"; else meshname = collada_filename; IAnimatedMesh *mesh = smgr->getMeshCache()->getMeshByName(meshname); if(mesh){ IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh, smgr->getRootSceneNode()); node->setMaterialFlag(EMF_LIGHTING, true); node->setMaterialFlag(EMF_TEXTURE_WRAP, false); node->setMaterialFlag(EMF_BACK_FACE_CULLING, false); node->addShadowVolumeSceneNode(0,-1,false); if(smgr->getFileSystem()->existFile(tex_file)) { node->setMaterialTexture(0, driver->getTexture(tex_file)); } PhysicalObject* pobj = new PhysicalObject(node, rb, bodyname); objects_list.push_back(pobj); structure.bodies.push_back(pobj); dynamicsWorld->addRigidBody(pobj->getRigidBody()); } } for(int i = 0; i < fileLoader->getNumConstraints(); i++) { Joint* jt = new Joint(fileLoader->getConstraintByIndex(i)); joints_list.push_back(jt); structure.joints.push_back(jt); btTypedConstraint* constr = jt->getConstraint(); dynamicsWorld->addConstraint(constr, true); } delete fileLoader; updateObjects(); return true; } } return false; }