Example #1
0
void BatchedMesh::regenerateVboMesh(MaterialRef material) {
  // cout << "BatchedMesh::regenerateVboMesh(): Regenerating VboMesh for
  // material:"
  //     << material << endl;

  TriMesh combinedMesh;
  vector<Vec3f> vertices;
  vector<ColorAf> colors;
  vector<Vec2f> texCoords;
  vector<uint32_t> indices;
  uint32_t vertCount = 0;
  _materialBounds[material] = AxisAlignedBox3f();

  for (BatchInfoRef batchInfo : _meshes[material]) {
    TriMesh *internalMesh = batchInfo->mesh->getInternalMesh(
        batchInfo->transform->getTransformMatrixLocal());

    vertices = internalMesh->getVertices();
    combinedMesh.appendVertices(vertices.data(), vertices.size());

    colors = internalMesh->getColorsRGBA();
    combinedMesh.appendColorsRgba(colors.data(), colors.size());

    texCoords = internalMesh->getTexCoords();
    combinedMesh.appendTexCoords(texCoords.data(), texCoords.size());

    indices = internalMesh->getIndices();
    std::transform(std::begin(indices), std::end(indices), std::begin(indices),
                   [vertCount](uint32_t x) { return x + vertCount; });
    combinedMesh.appendIndices(indices.data(), indices.size());

    vertCount += vertices.size();

    _materialBounds[material].include(internalMesh->calcBoundingBox());
  }

  _vboMeshes[material] = gl::VboMesh::create(combinedMesh);

  // Recalculate master bounds
  _bounds = AxisAlignedBox3f();
  for (auto &kvp : _materialBounds) {
    _bounds.include(kvp.second);
  }
}
 static void appendTexCoords( TriMesh& mesh, const std::vector<Vec2f>& texCoords )
 {
     mesh.appendTexCoords( &texCoords[0], texCoords.size() );
 }
Example #3
0
void TextureTestApp::setup()
{
  Vec3f vertices[] = {
    { -1, -1, 0 }, {  1, -1, 0 }, {  1, 1, 0 },
    { -1, -1, 0 }, {  1,  1, 0 }, { -1, 1, 0 }, 
  };
  
  mesh.appendVertices(vertices,
                      sizeof(vertices) / sizeof(vertices[0]));

  Vec2f tex_coords[] = {
    { 0, 0.5 }, { 0.5, 0.5 }, { 0.5, 0 },
    { 0, 0.5 }, { 0.5, 0 }, { 0, 0 },
  };
  
  mesh.appendTexCoords(tex_coords,
                       sizeof(tex_coords) / sizeof(tex_coords[0]));

  uint32_t indices[] = {
    0, 1, 2,
    3, 4, 5,
  };
  
  mesh.appendIndices(indices,
                     sizeof(indices) / sizeof(indices[0]));

  mesh.recalculateNormals();
  
  // assetフォルダから画像を読み込む
  // 幅と高さは2のべき乗でなくてもよい
  image = loadImage(loadAsset("miku.png"));

  // 平行光源を1つ用意
  light = std::unique_ptr<gl::Light>(new gl::Light(gl::Light::DIRECTIONAL, 0));
  light->setAmbient(Color(0.0, 0.0, 0.0));
  light->setDiffuse(Color(1.0, 1.0, 1.0));
  light->setDirection(Vec3f(0.0, 0.0, 1.0));

  // カメラの準備
  camera = CameraPersp(getWindowWidth(), getWindowHeight(),
                       35.0, 0.5, 1000.0);

  camera.lookAt(Vec3f(0.0, 0.0, 700.0),
                Vec3f(0.0, 0.0, 0.0));

 
  // テクスチャON
  gl::enable(GL_TEXTURE_2D);
  // 半透明処理を有効化
  gl::enableAlphaBlending(true);
 
  // カリングON
  gl::enable(GL_CULL_FACE);

  // gl::color or 頂点カラーを対象にしてライティングの計算を行う
  gl::enable(GL_COLOR_MATERIAL);
  
  // ライティングON
  gl::enable(GL_LIGHTING);
  // 法線を正規化する
  gl::enable(GL_NORMALIZE);

  rx = ry = rz = 0.0;
}