本文整理汇总了C++中TriMesh::GetVertexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ TriMesh::GetVertexBuffer方法的具体用法?C++ TriMesh::GetVertexBuffer怎么用?C++ TriMesh::GetVertexBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriMesh
的用法示例。
在下文中一共展示了TriMesh::GetVertexBuffer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Response
//----------------------------------------------------------------------------
void CollisionsBoundTree::Response (CRecord& record0, int t0,
CRecord& record1, int t1, Intersector<float,Vector3f>*)
{
CollisionsBoundTree* app = (CollisionsBoundTree*)TheApplication;
// Mesh0 triangles that are intersecting change from blue to cyan.
TriMesh* mesh = record0.GetMesh();
VertexBufferAccessor vba(mesh);
const int* indices = (int*)mesh->GetIndexBuffer()->GetData();
int i0 = indices[3*t0];
int i1 = indices[3*t0 + 1];
int i2 = indices[3*t0 + 2];
vba.TCoord<Float2>(0, i0) = app->mCyanUV;
vba.TCoord<Float2>(0, i1) = app->mCyanUV;
vba.TCoord<Float2>(0, i2) = app->mCyanUV;
app->mRenderer->Update(mesh->GetVertexBuffer());
// Mesh1 triangles that are intersecting change from red to yellow.
mesh = record1.GetMesh();
vba.ApplyTo(mesh);
indices = (int*)mesh->GetIndexBuffer()->GetData();
i0 = indices[3*t1];
i1 = indices[3*t1 + 1];
i2 = indices[3*t1 + 2];
vba.TCoord<Float2>(0 ,i0) = app->mYellowUV;
vba.TCoord<Float2>(0, i1) = app->mYellowUV;
vba.TCoord<Float2>(0, i2) = app->mYellowUV;
app->mRenderer->Update(mesh->GetVertexBuffer());
// NOTE: See the comments in Wm5CollisionGroup.h about information that
// is available from the Intersector<float,Vector3f> object.
}
示例2: vba
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CopyNormalToTCoord1 (Object* object)
{
TriMesh* mesh = DynamicCast<TriMesh>(object);
if (mesh)
{
VertexBufferAccessor vba(mesh);
for (int i = 0; i < vba.GetNumVertices(); ++i)
{
vba.TCoord<Vector3f>(1, i) = vba.Normal<Vector3f>(i);
}
mRenderer->Update(mesh->GetVertexBuffer());
}
Node* node = DynamicCast<Node>(object);
if (node)
{
for (int i = 0; i < node->GetNumChildren(); ++i)
{
Spatial* child = node->GetChild(i);
if (child)
{
CopyNormalToTCoord1(child);
}
}
}
}
示例3: PhysicsTick
//----------------------------------------------------------------------------
void GelatinCube::PhysicsTick ()
{
mModule->Update((float)GetTimeInSeconds());
// Update spline surface. Remember that the spline maintains its own
// copy of the control points, so this update is necessary.
int numSlices = mModule->GetNumSlices() - 2;
int numRows = mModule->GetNumRows() - 2;
int numCols = mModule->GetNumCols() - 2;
for (int s = 0; s < numSlices; ++s)
{
for (int r = 0; r < numRows; ++r)
{
for (int c = 0; c < numCols; ++c)
{
mSpline->SetControlPoint(c, r, s,
mModule->Position(s + 1, r + 1, c + 1));
}
}
}
mBox->UpdateSurface();
for (int i = 0; i < mBox->GetNumChildren(); ++i)
{
TriMesh* mesh = StaticCast<TriMesh>(mBox->GetChild(i));
mRenderer->Update(mesh->GetVertexBuffer());
}
}
示例4: ModifyMesh
//----------------------------------------------------------------------------
void IntersectingBoxes::ModifyMesh (int i)
{
Vector3f center(
0.5f*(mBoxes[i].Min[0] + mBoxes[i].Max[0]),
0.5f*(mBoxes[i].Min[1] + mBoxes[i].Max[1]),
0.5f*(mBoxes[i].Min[2] + mBoxes[i].Max[2]));
float xExtent = 0.5f*(mBoxes[i].Max[0] - mBoxes[i].Min[0]);
float yExtent = 0.5f*(mBoxes[i].Max[1] - mBoxes[i].Min[1]);
float zExtent = 0.5f*(mBoxes[i].Max[2] - mBoxes[i].Min[2]);
Vector3f xTerm = xExtent*Vector3f::UNIT_X;
Vector3f yTerm = yExtent*Vector3f::UNIT_Y;
Vector3f zTerm = zExtent*Vector3f::UNIT_Z;
TriMesh* mesh = StaticCast<TriMesh>(mScene->GetChild(i));
VertexBufferAccessor vba(mesh);
vba.Position<Vector3f>(0) = center - xTerm - yTerm - zTerm;
vba.Position<Vector3f>(1) = center + xTerm - yTerm - zTerm;
vba.Position<Vector3f>(2) = center + xTerm + yTerm - zTerm;
vba.Position<Vector3f>(3) = center - xTerm + yTerm - zTerm;
vba.Position<Vector3f>(4) = center - xTerm - yTerm + zTerm;
vba.Position<Vector3f>(5) = center + xTerm - yTerm + zTerm;
vba.Position<Vector3f>(6) = center + xTerm + yTerm + zTerm;
vba.Position<Vector3f>(7) = center - xTerm + yTerm + zTerm;
mesh->UpdateModelSpace(Visual::GU_NORMALS);
mRenderer->Update(mesh->GetVertexBuffer());
}
示例5: vba
//----------------------------------------------------------------------------
RawTerrainPage::RawTerrainPage (VertexFormat* vformat, int size,
float* heights, const Float2& origin, float spacing)
:
mSize(size),
mSizeM1(size - 1),
mHeights(heights),
mOrigin(origin),
mSpacing(spacing)
{
// size = 2^p + 1, p <= 7
assertion(size == 3 || size == 5 || size == 9 || size == 17
|| size == 33 || size == 65 || size == 129, "Invalid page size\n");
mInvSpacing = 1.0f/mSpacing;
// 创建地形页网格
float ext = mSpacing*mSizeM1;
TriMesh* mesh = StandardMesh(vformat).Rectangle(mSize, mSize, ext, ext);
mVFormat = vformat;
mVBuffer = mesh->GetVertexBuffer();
mIBuffer = mesh->GetIndexBuffer();
delete0(mesh);
// 修改地形顶点数据
VertexBufferAccessor vba(mVFormat, mVBuffer);
int numVertices = mVBuffer->GetNumElements();
for (int i = 0; i < numVertices; ++i)
{
int x = i % mSize;
int y = i / mSize;
vba.Position<Float3>(i) = Float3(GetX(x), GetY(y), GetHeight(i));
vba.Normal<Float3>(i) = Float3(0.0f, 0.0f, 1.0f);
}
UpdateModelSpace(Renderable::GU_NORMALS);
mUV01 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV23 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV4 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV01Float = new0 ShaderFloat(1);
mUV23Float = new0 ShaderFloat(1);
mUV4Float = new0 ShaderFloat(1);
SetUV0(Float2(mUV01[0], mUV01[1]));
SetUV1(Float2(mUV01[2], mUV01[3]));
SetUV2(Float2(mUV23[0], mUV23[1]));
SetUV3(Float2(mUV23[2], mUV23[3]));
SetUV4(Float2(mUV4[0], mUV4[1]));
mTextureAlpha = new0 Texture2D(Texture::TF_A8R8G8B8, mSize, mSize, 1);
mTextureDefault = DynamicCast<Texture2D>(ResourceManager::GetSingleton()
.BlockLoad("Data/Images/Terrain/NiTu.dds"));
assertion(mTextureDefault!=0, "Load texture %s failed.",
"Data/Images/Terrain/NiTu.dds");
}
示例6: stdmesh
//----------------------------------------------------------------------------
RevolutionSurface::RevolutionSurface (Curve2f* curve, float xCenter,
TopologyType topology, int numCurveSamples, int numRadialSamples,
bool sampleByArcLength, bool outsideView, VertexFormat* vformat)
:
mCurve(curve),
mXCenter(xCenter),
mTopology(topology),
mNumCurveSamples(numCurveSamples),
mNumRadialSamples(numRadialSamples),
mSin(0),
mCos(0),
mSamples(0),
mSampleByArcLength(sampleByArcLength)
{
ComputeSampleData();
// The topology of the meshes is all that matters. The vertices will be
// modified later based on the curve of revolution.
StandardMesh stdmesh(vformat, !outsideView);
TriMesh* mesh = 0;
switch (mTopology)
{
case REV_DISK_TOPOLOGY:
mesh = stdmesh.Disk(mNumCurveSamples, mNumRadialSamples, 1.0f);
break;
case REV_CYLINDER_TOPOLOGY:
mesh = stdmesh.Cylinder(mNumCurveSamples, mNumRadialSamples, 1.0f,
1.0f, true);
break;
case REV_SPHERE_TOPOLOGY:
mesh = stdmesh.Sphere(mNumCurveSamples, mNumRadialSamples, 1.0f);
break;
case REV_TORUS_TOPOLOGY:
mesh = stdmesh.Torus(mNumCurveSamples, mNumRadialSamples, 1.0f,
0.25f);
break;
default:
assertion(false, "Unexpected condition\n");
break;
}
assertion(mesh != 0, "Failed to construct mesh\n");
mVFormat = vformat;
mVBuffer = mesh->GetVertexBuffer();
// Generate the actual surface by replacing the vertex values. NOTE:
// Setting mIBuffer to zero acts as a flag that tells UpdateSurface
// *not* to call Renderer::UpdateVertexBuffer(mVBuffer). Only when the
// application has constructed a RevolutionSurface wlil the update occur.
mIBuffer = 0;
UpdateSurface();
mIBuffer = mesh->GetIndexBuffer();
delete0(mesh);
}
示例7: vba
//----------------------------------------------------------------------------
RawTerrainPage::RawTerrainPage (VertexFormat* vformat, int size,
float* heights, const Float2& origin, float spacing)
:
TerrainPage(size, heights, origin, spacing)
{
float ext = mSpacing*mSizeM1;
TriMesh* mesh = StandardMesh(vformat).Rectangle(mSize, mSize, ext, ext);
mVFormat = vformat;
mVBuffer = mesh->GetVertexBuffer();
mIBuffer = mesh->GetIndexBuffer();
delete0(mesh);
VertexBufferAccessor vba(mVFormat, mVBuffer);
int numVertices = mVBuffer->GetNumElements();
for (int i = 0; i < numVertices; ++i)
{
int x = i % mSize;
int y = i / mSize;
vba.Position<Float3>(i) = Float3(GetX(x), GetY(y), GetHeight(i));
vba.Normal<Float3>(i) = Float3(0.0f, 0.0f, 1.0f);
vba.Color<Float3>(0, i) = Float3(0.0f, 0.0f, 0.0f);
}
UpdateModelSpace(Renderable::GU_NORMALS);
mUV01 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV23 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV4 = Float4(8.0f, 8.0f, 8.0f, 8.0f);
mUV01Float = new0 ShaderFloat(1);
mUV23Float = new0 ShaderFloat(1);
mUV4Float = new0 ShaderFloat(1);
SetUV0(Float2(mUV01[0], mUV01[1]));
SetUV1(Float2(mUV01[2], mUV01[3]));
SetUV2(Float2(mUV23[0], mUV23[1]));
SetUV3(Float2(mUV23[2], mUV23[3]));
SetUV4(Float2(mUV4[0], mUV4[1]));
mTextureAlpha = new0 Texture2D(Texture::TF_A8R8G8B8, mSize, mSize, 1);
mTextureDefaultFilename = "Data/engine/grass.png";
}
示例8: stdMesh
//----------------------------------------------------------------------------
PX2::Node *GeoObjFactory::CreateScaleCtrl_O()
{
// node
PX2::Node *node = new0 Node;
node->LocalTransform.SetUniformScale(2.0f);
node->SetName("Scale");
VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC);
StandardMesh stdMesh(vf);
VertexBuffer *vBufferTemp = 0;
VertexBufferAccessor vbaTemp;
// x
PX2::Node *nodeX = new0 Node;
nodeX->SetName("Scale_X");
VertexBuffer *vBufferX = new0 VertexBuffer(6, vf->GetStride());
VertexBufferAccessor vbaX(vf, vBufferX);
vbaX.Position<Float3>(0) = Float3(0.25f, 0.0f, 0.0f);
vbaX.Position<Float3>(1) = Float3(1.125f, 0.0f, 0.0f);
vbaX.Color<Float4>(0, 0) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
vbaX.Color<Float4>(0, 1) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
vbaX.Position<Float3>(2) = Float3(0.5f, 0.0f, 0.0f);
vbaX.Position<Float3>(3) = Float3(0.5f, 0.5f, 0.0f);
vbaX.Color<Float4>(0, 2) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
vbaX.Color<Float4>(0, 3) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
vbaX.Position<Float3>(4) = Float3(0.5f, 0.0f, 0.0f);
vbaX.Position<Float3>(5) = Float3(0.5f, 0.0f, 0.5f);
vbaX.Color<Float4>(0, 4) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
vbaX.Color<Float4>(0, 5) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
Polysegment *polysegmentX = new0 PX2::Polysegment(vf, vBufferX,
false);
polysegmentX->SetMaterialInstance(
VertexColor4Material::CreateUniqueInstance());
nodeX->AttachChild(polysegmentX);
TriMesh *meshX = stdMesh.Box(0.06f, 0.06f, 0.06f);
meshX->SetMaterialInstance(VertexColor4Material::CreateUniqueInstance());
//meshX->GetMaterialInstance()->GetPass(0)->GetWireProperty()->Enabled = true;
meshX->LocalTransform.SetTranslate(APoint(1.125f, 0.0f, 0.0f));
vBufferTemp = meshX->GetVertexBuffer();
vbaTemp.ApplyTo(vf, vBufferTemp);
for (int i = 0; i < vBufferTemp->GetNumElements(); i++)
{
vbaTemp.Color<Float4>(0, i) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
}
nodeX->AttachChild(meshX);
// y
PX2::Node *nodeY = new0 PX2::Node;
nodeX->SetName("Scale_Y");
VertexBuffer *vBufferY = new0 VertexBuffer(6, vf->GetStride());
VertexBufferAccessor vbaY(vf, vBufferY);
vbaY.Position<Float3>(0) = Float3(0.0f, 0.25f, 0.0f);
vbaY.Position<Float3>(1) = Float3(0.0f, 1.125f, 0.0f);
vbaY.Color<Float4>(0, 0) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
vbaY.Color<Float4>(0, 1) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
vbaY.Position<Float3>(2) = Float3(0.0f, 0.5f, 0.0f);
vbaY.Position<Float3>(3) = Float3(0.5f, 0.5f, 0.0f);
vbaY.Color<Float4>(0, 2) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
vbaY.Color<Float4>(0, 3) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
vbaY.Position<Float3>(4) = Float3(0.0f, 0.5f, 0.0f);
vbaY.Position<Float3>(5) = Float3(0.0f, 0.5f, 0.5f);
vbaY.Color<Float4>(0, 4) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
vbaY.Color<Float4>(0, 5) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
Polysegment *polysegmentY = new0 PX2::Polysegment(vf, vBufferY,
false);
polysegmentY->SetMaterialInstance(
VertexColor4Material::CreateUniqueInstance());
nodeY->AttachChild(polysegmentY);
TriMesh *meshY = stdMesh.Box(0.06f, 0.06f, 0.06f);
meshY->SetMaterialInstance(VertexColor4Material::CreateUniqueInstance());
//meshY->GetMaterialInstance()->GetPass(0)->GetWireProperty()->Enabled = true;
meshY->LocalTransform.SetTranslate(APoint(0.0f, 1.125f, 0.0f));
vBufferTemp = meshY->GetVertexBuffer();
vbaTemp.ApplyTo(vf, vBufferTemp);
for (int i = 0; i < vBufferTemp->GetNumElements(); i++)
{
vbaTemp.Color<Float4>(0, i) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
}
nodeY->AttachChild(meshY);
// z
PX2::Node *nodeZ = new0 PX2::Node();
nodeX->SetName("Scale_Z");
VertexBuffer *vBufferZ = new0 VertexBuffer(6, vf->GetStride());
VertexBufferAccessor vbaZ(vf, vBufferZ);
//.........这里部分代码省略.........
示例9: Cylinder
//.........这里部分代码省略.........
vba.Position<Float3>(i) = vba.Position<Float3>(save);
if (mHasNormals)
{
vba.Normal<Float3>(i) = vba.Normal<Float3>(save);
}
tcoord = Float2(1.0f, axisFraction);
for (unit = 0; unit < MAX_UNITS; ++unit)
{
if (mHasTCoords[unit])
{
vba.TCoord<Float2>(0, i) = tcoord;
}
}
++i;
}
TransformData(vba);
// Generate indices.
IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, 4, mUsage);
int* indices = (int*)ibuffer->GetData();
for (a = 0, aStart = 0; a < axisSamples-1; ++a)
{
int i0 = aStart;
int i1 = i0 + 1;
aStart += radialSamples + 1;
int i2 = aStart;
int i3 = i2 + 1;
for (i = 0; i < radialSamples; ++i, indices += 6)
{
if (mInside)
{
indices[0] = i0++;
indices[1] = i2;
indices[2] = i1;
indices[3] = i1++;
indices[4] = i2++;
indices[5] = i3++;
}
else // outside view
{
indices[0] = i0++;
indices[1] = i1;
indices[2] = i2;
indices[3] = i1++;
indices[4] = i3++;
indices[5] = i2++;
}
}
}
delete1(cs);
delete1(sn);
mesh = new0 TriMesh(mVFormat, vbuffer, ibuffer);
}
else
{
mesh = Sphere(axisSamples, radialSamples, radius);
VertexBuffer* vbuffer = mesh->GetVertexBuffer();
int numVertices = vbuffer->GetNumElements();
VertexBufferAccessor vba(mVFormat, vbuffer);
// Flatten sphere at poles.
float hDiv2 = 0.5f*height;
vba.Position<Float3>(numVertices-2)[2] = -hDiv2; // south pole
vba.Position<Float3>(numVertices-1)[2] = +hDiv2; // north pole
// Remap z-values to [-h/2,h/2].
float zFactor = 2.0f/(axisSamples-1);
float tmp0 = radius*(-1.0f + zFactor);
float tmp1 = 1.0f/(radius*(+1.0f - zFactor));
for (int i = 0; i < numVertices-2; ++i)
{
Float3& pos = vba.Position<Float3>(i);
pos[2] = hDiv2*(-1.0f + tmp1*(pos[2] - tmp0));
float adjust = radius*Mathf::InvSqrt(pos[0]*pos[0] +
pos[1]*pos[1]);
pos[0] *= adjust;
pos[1] *= adjust;
}
TransformData(vba);
if (mHasNormals)
{
mesh->UpdateModelSpace(Visual::GU_NORMALS);
}
}
// The duplication of vertices at the seam causes the automatically
// generated bounding volume to be slightly off center. Reset the bound
// to use the true information.
float maxDist = Mathf::Sqrt(radius*radius + height*height);
mesh->GetModelBound().SetCenter(APoint::ORIGIN);
mesh->GetModelBound().SetRadius(maxDist);
return mesh;
}
示例10: UpdateSurface
//----------------------------------------------------------------------------
void BoxSurface::UpdateSurface ()
{
int permute[3];
TriMesh* mesh;
VertexFormat* vformat;
VertexBuffer* vbuffer;
// u faces
permute[0] = 1;
permute[1] = 2;
permute[2] = 0;
// u = 0
mesh = StaticCast<TriMesh>(GetChild(0));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumWSamples, mNumVSamples, vformat, vbuffer, false, 0.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
// u = 1
mesh = StaticCast<TriMesh>(GetChild(1));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumWSamples, mNumVSamples, vformat, vbuffer, true, 1.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
// v faces
permute[0] = 0;
permute[1] = 2;
permute[2] = 1;
// v = 0
mesh = StaticCast<TriMesh>(GetChild(2));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumWSamples, mNumUSamples, vformat, vbuffer, true, 0.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
// v = 1
mesh = StaticCast<TriMesh>(GetChild(3));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumWSamples, mNumUSamples, vformat, vbuffer, false, 1.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
// w faces
permute[0] = 0;
permute[1] = 1;
permute[2] = 2;
// w = 0
mesh = StaticCast<TriMesh>(GetChild(4));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumVSamples, mNumUSamples, vformat, vbuffer, false, 0.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
// w = 1
mesh = StaticCast<TriMesh>(GetChild(5));
vformat = mesh->GetVertexFormat();
vbuffer = mesh->GetVertexBuffer();
UpdateFace(mNumVSamples, mNumUSamples, vformat, vbuffer, true, 1.0f,
permute);
mesh->UpdateModelSpace(Renderable::GU_NORMALS);
Renderer::UpdateAll(vbuffer);
}