頂点ジオメトリビルダー
Description説明
TheCandera Candera:::VertexGeometryBuilder class helps effectively build クラスは、Candera::VertexGeometry objects.オブジェクトを効果的に構築するのに役立ちます。
Chapters章
Example Solutionソリューション例
VertexGeometryBuilderSolutionin the foldercgi_studio_player/content/Tutorials/03_SceneGraphAndNodesフォルダー内のVertexGeometryBuilderSolutionThe基本的な頂点ジオメトリbasicビルダー操作は、ウィジェットVertexGeometryBuilderWidgetで例示されています。基本的に、ウィジェットが行うことは、ウィジェットvertexプロパティ「モデルgeometryタイプ」に設定された値に応じて、シーン内で連続してレンダリングされるbuilder4operations are exemplified in the widgetVertexGeometryBuilderWidget. What the widget does, basically, is to generate the vertex buffer for the fourつの 3Dmodels which are rendered successively in the scene depending on the value set for the widget property "Model Type".モデルの頂点バッファーを生成することです。
Procedural Geometry手続き型ジオメトリ
Example: Wireframe Cube with例: LineList を使用したワイヤーフレーム キューブ
First最初の例は、 example shows how to generate a wireframe cube using a オブジェクトを使用してワイヤーフレーム object.キューブを生成する方法を示しています。
The頂点ジオメトリは、 vertex geometry will be generated procedurally using a objectオブジェクト (e.g.例: m_builder ).を使用して手続き的に生成されます。
Vertex頂点要素の形式: Element Format: Position and Color位置と色
At the beginning we have to specify what kind of information will be set in the vertices. Of course we need information about the position and, optionally, for an improved visual effect, we could also add color information.最初に、頂点にどのような情報を設定するかを指定する必要があります。もちろん、位置に関する情報が必要です。オプションで、視覚効果を向上させるために色情報を追加することもできます。
// Set the data type to be used: position & color
m_builder.SetVertexElementFormat(VertexGeometry::Position, 0, VertexGeometry::Float32_3);
m_builder.SetVertexElementFormat(VertexGeometry::Color, 0, VertexGeometry::Float32_4);
Vertex頂点データ: Data: Position位置
The position information for the vertices is obtained from the array 頂点の位置情報は配列c_cubeData which, in fact, stores the coordinates of the pointsから取得されます。この配列には、実際には点 A andと G.G The coordinates for the rest of the vertices are obtained relatively to this pointsの座標が格納されています。残りの頂点の座標は、この点に対して相対的に取得されます (e.g. たとえば、F(X A , Y G , Z G ) orまたは D(X G , Y A , Z A )

// Coordinates for the points A & G
static const Float c_cubeData[2][3] = {
{-1.0F, -1.0F, -1.0F },
{1.0F, 1.0F, 1.0F }
};
VertexGeometryBuilder: Set Vertex Elements頂点要素の設定
BecauseLineList theオブジェクトの LineType property of the LineList object will be set toプロパティが LineType::Lines,Lines the vertex buffer will have to contain a pair of vertices for each line of the cube:に設定されるため、頂点バッファーには立方体の各ラインの頂点のペアが含まれている必要があります: 2 vertices/line頂点/ライン * 12 linesライン = 24 vertices.頂点。
// Set the position & color information for each vertex
// Line segment AD
m_builder.SetVertexElement(VertexGeometry::Position, 0, c_cubeData[0][0], c_cubeData[0][1], c_cubeData[0][2]); // A
m_builder.SetVertexElement(VertexGeometry::Color, 0, 1.F, 0.F, 1.F, 1.F); // magenta
// Increment the vertex cursor
m_builder.IncrementVertexCursor();
m_builder.SetVertexElement(VertexGeometry::Position, 0, c_cubeData[1][0], c_cubeData[0][1], c_cubeData[0][2]); // D
m_builder.SetVertexElement(VertexGeometry::Color, 0, 1.F, 1.F, 1.F, 1.F); // white
m_builder.IncrementVertexCursor();
// Line segment AB
m_builder.SetVertexElement(VertexGeometry::Position, 0, c_cubeData[0][0], c_cubeData[0][1], c_cubeData[0][2]); // A
m_builder.SetVertexElement(VertexGeometry::Color, 0, 1.F, 0.F, 1.F, 1.F); // magenta
m_builder.IncrementVertexCursor();
m_builder.SetVertexElement(VertexGeometry::Position, 0, c_cubeData[0][0], c_cubeData[0][1], c_cubeData[1][2]); // B
m_builder.SetVertexElement(VertexGeometry::Color, 0, 1.F, 1.F, 0.F, 1.F); // yellow
// ...
Create Vertex Buffer頂点バッファを作成
Create a Candera::VertexBufferオブジェクトを作成し、 object and attach to it the vertex geometry obtained from the Candera::VertexGeometryBuilder:から取得した頂点ジオメトリをアタッチします。
VertexGeometry* vertexGeom = m_builder.GetVertexGeometry();
SharedPointer<VertexBuffer> vertexBuffer = VertexBuffer::Create();
static_cast<void>(vertexBuffer->SetVertexGeometry(vertexGeom, VertexBuffer::VertexGeometryDisposer::Dispose));
vertexBuffer->SetPrimitiveType(VertexBuffer::Lines);
CreateVertex Buffer を使用して LineList using the Vertex Bufferを作成する
Attach the vertex buffer to頂点バッファーを LineList object:オブジェクトにアタッチします。
// Create and configure the line list object
m_lineList = LineList::Create();
m_lineList->SetAppearance(Appearance::Create());
m_lineList->GetAppearance()->SetMaterial(Material::Create());
m_lineList->GetAppearance()->GetMaterial()->SetEmissive(Color(1.0F, 1.0F, 0.0F));
m_lineList->GetAppearance()->SetShader(m_shaderLightMaterial);
m_lineList->SetLineType(LineList::Lines);
m_lineList->SetWidth(1.0);
m_lineList->SetIntersectionTestEnabled(false);
m_lineList->SetVertexBuffer(vertexBuffer);
m_lineList->SetScopeMask(ScopeMask(false));
static_cast<void>(m_lineList->SetScopeEnabled(1, true));
m_lineList->SetRenderingEnabled(true);
m_lineList->SetName("Wireframe");
static_cast<void>(m_lineList->Upload());
Wireframeワイヤーフレーム Cube Resultキューブの結果
The下の画像は、結果のワイヤフレーム image below shows the resulting wireframe cube:キューブを示しています。

-
For an easier manipulation of the widget inSceneComposerallでウィジェットを簡単に操作するために、すべてのシェーダーがソースthe shaders are hardcoded in the source fileファイルにハードコードされ (seecgi_studio_player\src\LegacyWidgets\Tutorial\3D\VertexGeometryBuilderWidget.cpp を) and then created by the widget at the initialization time.参照)、初期化時にウィジェットによって作成されます。Alternativelyまたは、アプリケーションがアセットobtain shaders fromライブラリを使用する場合は、Candera::AssetProvider (e.g.例: GetAssetProvider()->GetShader("..."))in case the application uses an asset library.からシェーダーを取得します。
Indexed Geometry インデックス付きジオメトリ
Example:例: Solid1 Cubeつの三角形ストリップからのソリッド from one Triangle Stripキューブ
The次の例では、 next example will show how to create a solid cube from one triangle strip using a オブジェクトを使用して、1 object.つの三角形ストリップからソリッド In this case the cube is determined by onlyキューブを作成する方法を示します。この場合、立方体は、特別な方法で順序付けする必要がある 14 vertices which have to be ordered in a special way.個の頂点のみによって決定されます。
The figure below presents a cube unfolded and a possible solution of ordering the vertices:次の図は、展開された立方体と、頂点の順序付けの考えられる解決策を示しています。

Indexed Vertex Sequenceインデックス付き頂点シーケンス
The vertex sequence is stored in the 頂点シーケンスはc_index_order array, encoding the order:配列に格納され、順序がエンコードされます。
- G->C->F->B->A->C->D->H->A->E->F->H->G->C .
Each array element represents an offset it the vertex buffer.各配列要素は、頂点バッファー内のオフセットを表します。
// The vertex sequence - triangle strip
static const UInt16 c_index_order[] = { 12, 11, 7, 3, 0, 11, 1, 17, 0, 5, 7, 17, 12, 11 };
The前の例で使用された頂点ジオメトリ vertexビルダー geometry builder object used in the previous example has alreadyオブジェクトには、位置と色の情報が設定された 24 vertices個の頂点が既に含まれています。この場合、必要な頂点は set24 with position and color information. Because only個のうち 14 vertices個だけであり、それらのシーケンスも異なる必要があるため、インデックス out of 24 are needed in this case and, also, because their sequence has to be different, an index buffer is added:バッファーが追加されます。
// Change the order of the vertices using indexes
for (Int index = 0; index < 14; index++) {
// Define the value of the index
m_builder.SetIndexElement(c_index_order[index]);
// Increment the index cursor
m_builder.IncrementIndexCursor();
}
Create TriangleStrip Vertex Buffer頂点バッファーの作成
Create the vertex buffer using the geometry from the builder:ビルダーからのジオメトリを使用して頂点バッファーを作成します。
VertexGeometry* vertexGeom = m_builder.GetVertexGeometry();
SharedPointer<VertexBuffer> vertexBuffer = VertexBuffer::Create();
static_cast<void>(vertexBuffer->SetVertexGeometry(vertexGeom, VertexBuffer::VertexGeometryDisposer::Dispose));
vertexBuffer->SetPrimitiveType(VertexBuffer::TriangleStrip);
Create Mesh using the Vertex Buffer頂点バッファーを使用してメッシュを作成する
Configure mesh and attach the vertex buffer:メッシュを構成し、頂点バッファーをアタッチします。
m_mesh = Mesh::Create(); m_mesh->SetVertexBuffer(vertexBuffer); m_mesh->SetAppearance(appearance); m_mesh->SetRenderingEnabled(false); m_mesh->SetName("SolidNonTextured"); static_cast<void>(m_mesh->Upload());
Solidソリッド Cube Resultキューブの結果
The image below shows the resulting solid cube:以下の画像は、結果として得られる立体立方体を示しています。

Remove & Add Vertex Elements 頂点要素の削除と追加
Example:例: Texturedテクスチャ Cubeキューブ
Inこの例では、頂点ジオメトリ thisビルダ example the vertex geometry builder object will be used to generate the vertex geometry for a textured cube.オブジェクトを使用して、テクスチャ付き立方体の頂点ジオメトリを生成します。
Adding texture to a mesh requires that its vertices should contain specific information like メッシュにテクスチャを追加するには、その頂点にnormal法線 and やtexture coordinateテクスチャ座標. Also, the などの特定の情報が含まれている必要があります。また、color色 information is no longer needed so it can be removed:情報は不要になったため、削除できます。
// Vertex Elements Manipulation
// Remove color data associated to the vertices
m_builder.RemoveVertexElement(VertexGeometry::Color,0);
// Add data type to be used: texture coordinate & normal
m_builder.SetVertexElementFormat(VertexGeometry::TextureCoordinate, 0, VertexGeometry::Float32_2);
m_builder.SetVertexElementFormat(VertexGeometry::Normal, 0, VertexGeometry::Float32_3);
Vertex頂点データ: Data: Normals and Texture Coordinates法線とテクスチャ座標
After adding the new data types for the vertices it is time to add the corresponding information. First, add normals for vertices:頂点の新しいデータ型を追加したら、対応する情報を追加します。まず、頂点の法線を追加します。
// Move the cursor to the first vertex
m_builder.SetVertexCursor();
for (UInt32 i = 0; i < m_builder.GetVertexCount(); i++ )
{
m_builder.SetVertexElement(VertexGeometry::Normal, 0, 0.0F, 0.0F, 1.0F);
m_builder.IncrementVertexCursor();
}
In order to map the UV texture coordinate values correctly, the cube faces should be drawn usingテクスチャ座標値を正しくマッピングするには、面ごとに 4 vertices per face, so, in this case, allつの頂点を使用して立方体面を描画する必要があるため、この場合は 24 vertices will be used. Of course, the vertex order has to be adjusted.個の頂点すべてが使用されます。もちろん、頂点の順序を調整する必要があります。
The new vertex order is stored in the 新しい頂点の順序は、c_indexDataTexturedCube array.配列に格納されます。
// Vertex order - textured cube
static const UInt16 c_indexDataTexturedCube[24] = {
1,17,0,5,
2,6,3,7,
9,8,11,12,
13,14,19,21,
15,23,16,22,
4,10,20,18
};
Now, reorder the vertices:次に、頂点を並べ替えます。
// Overwrite the index buffer
// Move the cursor to the first index
m_builder.SetIndexCursor();
for (UInt32 i = 0; i < m_builder.GetVertexCount(); i++ )
{
// Define the value of the index
m_builder.SetIndexElement(c_indexDataTexturedCube[i]);
m_builder.IncrementIndexCursor();
}
The vertices of each face of the cube should be set with texture coordinate information as shown below:立方体の各面の頂点は、以下に示すようにテクスチャ座標情報で設定する必要があります。

Set the texture coordinates for vertices:頂点のテクスチャ座標を設定します。
Int idx = 0;
for (Int nb_of_faces = 0; nb_of_faces<6; nb_of_faces++) {
for (Int u=0; u<=1; u++) {
for (Int v=0; v<=1; v++) {
//Set the position of the vertex cursor
m_builder.SetVertexCursor(c_indexDataTexturedCube[idx]);
m_builder.SetVertexElement(VertexGeometry::TextureCoordinate, 0, static_cast<Float>(u), static_cast<Float>(v));
idx++;
}
}
}
The vertex buffer is created and configured in the same way as in the previous example頂点バッファーは、前の例.と同じ方法で作成および構成されます。
The mesh setup is also similar but, unlike the メッシュのセットアップも似ていますが、solidソリッド cubeキューブ,とは異なり、テクスチャ theキューブの外観はテクスチャとテクスチャ textured cube appearance has to be set with a texture and a texture shader.シェーダで設定する必要があります。
Texturedテクスチャ Cube Resultキューブの結果
Here is the final result:最終結果は次のとおりです。

Range Data Usage 範囲データの使用法
Example:例: Solid範囲データを使用したソリッド Cube using Range Dataキューブ
This example will show how to create a solid cube as in the secondこの例では、 example2 番目の例と同様にソリッド but using range data.キューブを作成する方法を示しますが、範囲データを使用します。
First,最初に、頂点ジオメトリ all existing data from the vertex geometry builder is removed.ビルダーからのすべての既存データが削除されます。
// Clear all data stored by the builder
m_builder.Clear();
The頂点データは、2 vertex data is taken from the two buffers つのバッファーc_positionData and およびc_colorData.から取得されます。
static const Float c_positionData[8][3] = {
{ -1.0F, 1.0F, 1.0F},
{ 1.0F, 1.0F, 1.0F},
{ -1.0F, -1.0F, 1.0F},
{ 1.0F, -1.0F, 1.0F},
{ -1.0F, 1.0F, -1.0F},
{ 1.0F, 1.0F, -1.0F},
{ -1.0F, -1.0F, -1.0F},
{ 1.0F, -1.0F, -1.0F}
};
static const Float c_colorData[8][4] = {
{ 0.0F, 0.0F, 1.0F, 1.0F},
{ 0.0F, 1.0F, 0.0F, 1.0F},
{ 0.0F, 1.0F, 1.0F, 1.0F},
{ 1.0F, 0.0F, 0.0F, 1.0F},
{ 1.0F, 0.0F, 1.0F, 1.0F},
{ 1.0F, 1.0F, 0.0F, 1.0F},
{ 1.0F, 1.0F, 1.0F, 1.0F},
{ 1.0F, 0.5F, 1.0F, 1.0F}
};
The vertex sequence is taken from the array 頂点シーケンスは、配列c_indexData.から取得されます。
// Range data index
static const UInt16 c_indexData[] = {3, 2, 1, 0, 4, 2, 6, 3, 7, 1, 5, 4, 7, 6 };
Use the methods メソッドCandera::VertexGeometryBuilder::SetVertexElementRange and およびCandera::VertexGeometryBuilder::SetIndexElementRange を to add the required information.使用して、必要な情報を追加します。
// Add position, color and an index from range data
// Splice values to the position buffer starting with the first vertex
static_cast<void>(m_builder.SetVertexElementRange(VertexGeometry::Position, 0, 0, VertexGeometry::Float32_3,
8, 3*sizeof(Float), c_positionData ));
// Splice values to the color buffer starting with the first vertex
static_cast<void>(m_builder.SetVertexElementRange(VertexGeometry::Color, 0, 0, VertexGeometry::Float32_4,
8, 4*sizeof(Float), c_colorData ));
// Splice values to the index buffer starting with the first index
static_cast<void>(m_builder.SetIndexElementRange(0, sizeof(c_indexData)/sizeof(UInt16),c_indexData));
The 頂点vertex buffer configurationバッファーの構成 and the とmesh setupメッシュのセットアップは、2 are identical with the ones from the second example.番目の例のものと同じです。
Here is the final result:最終結果は次のとおりです。

Concatenate Geometries ジオメトリの連結
VertexGeometryBuilder::SpliceGeometry
In場合によっては、2 some cases it might be useful to concatenate two vertex geometries. This can be done by using the つの頂点ジオメトリを連結すると便利な場合があります。これは、以下に示すように、Candera::VertexGeometryBuilder::SpliceGeometry method as shown below:メソッドを使用して実行できます。
m_builder.SpliceGeometry(0, 0, vertexGeometry1);
m_builder.SpliceGeometry(vertexGeometry1->GetVertexCount(), vertexGeometry1->GetIndexCount(), vertexGeometry2);
vertexGeometry1cat2 = builder.GetGeometry();