当前位置: 首页>>代码示例>>C++>>正文


C++ ModelPtr::set_material方法代码示例

本文整理汇总了C++中ModelPtr::set_material方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelPtr::set_material方法的具体用法?C++ ModelPtr::set_material怎么用?C++ ModelPtr::set_material使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelPtr的用法示例。


在下文中一共展示了ModelPtr::set_material方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rotation

void
Scene::parse_istream(std::istream& in)
{
  // This is not a fully featured .obj file reader, it just takes some
  // inspiration from it:
  // http://www.martinreddy.net/gfx/3d/OBJ.spec
  std::unordered_map<std::string, SceneNode*> nodes;
  std::unordered_map<std::string, std::unique_ptr<SceneNode> > unattached_children;

  std::string name;
  std::string parent;
  std::string material = "phong";
  glm::vec3 location(0.0f, 0.0f, 0.0f);
  glm::quat rotation(1.0f, 0.0f, 0.0f, 0.0f);
  glm::vec3 scale(1.0f, 1.0f, 1.0f);
  std::vector<glm::vec3>  normal;
  std::vector<glm::vec3>  position;
  std::vector<glm::vec3>  texcoord;
  std::vector<int>        index;
  std::vector<glm::vec4>  bone_weight;
  std::vector<glm::ivec4> bone_index;
  std::vector<int>        bone_count;

  auto commit_object = [&]{
    if (!name.empty())
    {
      ModelPtr model;

      if (!position.empty())
      {
        // fill in some texcoords if there aren't enough
        if (texcoord.size() < position.size())
        {
          texcoord.resize(position.size());
          for(FaceLst::size_type i = position.size()-1; i < texcoord.size(); ++i)
          {
            texcoord[i] = glm::vec3(0.0f, 0.0f, 0.0f);
          }
        }

        {
          // create Mesh
          std::unique_ptr<Mesh> mesh(new Mesh(GL_TRIANGLES));

          mesh->attach_float_array("position", position);
          mesh->attach_float_array("texcoord", texcoord);
          mesh->attach_float_array("normal",   normal);
          mesh->attach_element_array(index);

          if (!bone_weight.empty() && !bone_index.empty())
          {
            mesh->attach_float_array("bone_weight", bone_weight);
            mesh->attach_int_array("bone_index", bone_index);
          }

          // create Model
          model = std::make_shared<Model>();
          model->add_mesh(std::move(mesh));

          if (boost::algorithm::ends_with(material, ".material"))
          {
            model->set_material(MaterialFactory::get().from_file(m_directory / boost::filesystem::path(material)));
          }
          else
          {
            model->set_material(MaterialFactory::get().create(material));
          }
        }
      }

      // create SceneNode
      {
        std::unique_ptr<SceneNode> node(new SceneNode(name));
        node->set_position(location);
        node->set_orientation(rotation);
        node->set_scale(scale);

        if (model)
        {
          node->attach_model(model);
        }

        if (nodes.find(name) != nodes.end())
        {
          throw std::runtime_error("duplicate object name: " + name);
        }

        nodes[name] = node.get();
        if (parent.empty())
        {
          m_node->attach_child(std::move(node));
        }
        else
        {
          unattached_children[parent] = std::move(node);
        }
      }

      // clear for the next mesh
      name.clear();
//.........这里部分代码省略.........
开发者ID:xianyinchen,项目名称:viewer,代码行数:101,代码来源:scene.cpp

示例2: ctx

void
Compositor::render(Viewer& viewer)
{
  // render the world, twice if stereo is enabled
  if (true)
  {
    OpenGLState state;

#ifndef HAVE_OPENGLES2
    if (m_render_shadowmap)
    {
      g_shadowmap->bind();
      render_shadowmap(viewer);
      g_shadowmap->unbind();
    }
#endif

    if (m_stereo_mode == StereoMode::None)
    {
      m_renderbuffer1->bind();
      render_scene(viewer, Stereo::Center);
      m_renderbuffer1->unbind();

      m_renderbuffer1->blit(*m_framebuffer1);
    }
    else
    {
      m_renderbuffer1->bind();
      render_scene(viewer, Stereo::Left);
      m_renderbuffer1->unbind();

      m_renderbuffer2->bind();
      render_scene(viewer, Stereo::Right);
      m_renderbuffer2->unbind();

      m_renderbuffer1->blit(*m_framebuffer1);
      m_renderbuffer2->blit(*m_framebuffer2);
    }
  }

  // composit the final image
  if (true)
  {
    OpenGLState state;

    MaterialPtr material = std::make_shared<Material>();
    { // setup material
      material->set_program(m_composition_prog);

      material->set_uniform("MVP", UniformSymbol::ModelViewProjectionMatrix);

      material->set_uniform("barrel_power", m_barrel_power);
      material->set_uniform("left_eye",  0);
      material->set_uniform("right_eye", 1);

      if (!viewer.m_cfg.m_show_calibration)
      {
        material->set_texture(0, m_framebuffer1->get_color_texture());
        material->set_texture(1, m_framebuffer2->get_color_texture());
      }
      else
      {
        material->set_texture(0, m_calibration_left_texture);
        material->set_texture(1, m_calibration_right_texture);
      }

      m_viewport_offset = {0, 0};
      switch(m_stereo_mode)
      {
        case StereoMode::Cybermaxx:
          m_viewport_offset = {-41, 16};
          m_composition_prog = m_cybermaxx_prog;
          break;

        case StereoMode::CrossEye:
          m_composition_prog = m_crosseye_prog;
          break;

        case StereoMode::Anaglyph:
          m_composition_prog = m_anaglyph_prog;
          break;

        case StereoMode::Depth:
          material->set_texture(0, m_framebuffer1->get_depth_texture());
          m_composition_prog = m_depth_prog;
          break;

        case StereoMode::Newsprint:
          m_composition_prog = m_newsprint_prog;
          break;

        default:
          m_composition_prog = m_mono_prog;
          break;
      }
    } // setup material

    ModelPtr model = std::make_shared<Model>();
    model->add_mesh(Mesh::create_rect(0.0f, 0.0f, m_screen_w, m_screen_h, -20.0f));
    model->set_material(material);
//.........这里部分代码省略.........
开发者ID:Grumbel,项目名称:viewer,代码行数:101,代码来源:compositor.cpp


注:本文中的ModelPtr::set_material方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。