本文整理汇总了C++中SMeshBuffer::drop方法的典型用法代码示例。如果您正苦于以下问题:C++ SMeshBuffer::drop方法的具体用法?C++ SMeshBuffer::drop怎么用?C++ SMeshBuffer::drop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMeshBuffer
的用法示例。
在下文中一共展示了SMeshBuffer::drop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateCapsuleSceneNode
IMeshSceneNode* CustomSceneNodeManager::CreateCapsuleSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float heightFromSphereCenters)
{
if (resolution >= 4)
{
SMesh* newCapsuleMesh = new SMesh();
SMeshBuffer* buf = new SMeshBuffer();
newCapsuleMesh->addMeshBuffer(buf);
buf->MappingHint_Vertex = EHM_STATIC;
buf->MappingHint_Index = EHM_STATIC;
buf->drop();
int noWarningSignedResolution = resolution;
float thetaSkipAmount = 2.0f*PI / (float)resolution;
float halfHeight = heightFromSphereCenters / 2.0f;
float phiSkipAmount = PI*0.5f / (float)resolution;
S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f));
S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f));
float currentTheta = 0.0f;
float currentPhi = phiSkipAmount;
temp1.Pos.Y = halfHeight + radius;
buf->Vertices.push_back(temp1);
//Semi-sphere Tips
for(unsigned int i = 1; i < resolution; i++)
{
for(unsigned int j = 0; j < resolution; j++)
{
float x = sinf(currentPhi) * cosf(currentTheta) * radius;
float y = cosf(currentPhi) * radius;
float z = sinf(currentPhi) * sinf(currentTheta) * radius;
temp1.Pos.X = x;
temp1.Pos.Y = y + halfHeight;
temp1.Pos.Z = z;
temp1.TCoords.X = currentTheta / 2.0f*PI;
temp1.TCoords.Y = currentPhi / PI;
buf->Vertices.push_back(temp1);
currentTheta += thetaSkipAmount;
}
currentTheta = 0.0f;
currentPhi += phiSkipAmount;
}
currentTheta = 0.0f;
currentPhi = PI/2.0f;
//Semi-sphere Tips
for(unsigned int i = 1; i < resolution; i++)
{
for(unsigned int j = 0; j < resolution; j++)
{
float x = sinf(currentPhi) * cosf(currentTheta) * radius;
float y = cosf(currentPhi) * radius;
float z = sinf(currentPhi) * sinf(currentTheta) * radius;
temp1.Pos.X = x;
temp1.Pos.Y = y - halfHeight;
temp1.Pos.Z = z;
temp1.TCoords.X = currentTheta / 2.0f*PI;
temp1.TCoords.Y = currentPhi / PI;
buf->Vertices.push_back(temp1);
currentTheta += thetaSkipAmount;
}
currentTheta = 0.0f;
currentPhi += phiSkipAmount;
}
temp1.Pos.X = 0.0f;
temp1.Pos.Y = -(halfHeight + radius);
temp1.Pos.Z = 0.0f;
buf->Vertices.push_back(temp1);
//Top vertex indices
for(unsigned int i = 1; i <= resolution; i++)
{
if (i == resolution)
{
buf->Indices.push_back(i);
buf->Indices.push_back(0);
buf->Indices.push_back(1);
}
else
{
buf->Indices.push_back(i);
buf->Indices.push_back(0);
buf->Indices.push_back(i + 1);
}
}
//Get indices
//.........这里部分代码省略.........
示例2: CreateConeSceneNode
IMeshSceneNode* CustomSceneNodeManager::CreateConeSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height)
{
if (resolution >= 4)
{
/*IMesh* newConeMesh = sceneManager->getGeometryCreator()->createConeMesh(radius, height, resolution, color, color);
IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);
sceneManager->getMeshCache()->addMesh(irr::io::path("ConeMesh"), (irr::scene::IAnimatedMesh*)newConeMesh);
newConeMesh->drop();*/
SMesh* newConeMesh = new SMesh();
SMeshBuffer* buf = new SMeshBuffer();
newConeMesh->addMeshBuffer(buf);
buf->MappingHint_Vertex = EHM_STATIC;
buf->MappingHint_Index = EHM_STATIC;
buf->drop();
int noWarningSignedResolution = resolution;
float currentTheta = 0.0f;
float skipAmount = 2.0f*PI / (float)resolution;
float halfHeight = height / 2.0f;
S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f));
S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f));
for(int i = 0; i < noWarningSignedResolution; i++)
{
float x = cosf(currentTheta) * radius;
float z = sinf(currentTheta) * radius;
temp2.Pos.X = x;
temp2.Pos.Z = z;
temp2.TCoords.X = currentTheta / 2.0f*PI;
buf->Vertices.push_back(temp2);
currentTheta += skipAmount;
}
buf->Vertices.push_back(temp1);
//Get side indices
for(int i = 0; i < noWarningSignedResolution - 1; i++)
{
buf->Indices.push_back(i);
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(i+1);
}
buf->Indices.push_back(buf->Vertices.size()-2);
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(0);
temp2.Pos.X = 0.0f;
temp2.Pos.Z = 0.0f;
buf->Vertices.push_back(temp2);
//Get bottom indices
for(int i = 0; i < noWarningSignedResolution - 1; i++)
{
buf->Indices.push_back(i);
buf->Indices.push_back(i+1);
buf->Indices.push_back(buf->Vertices.size()-1);
}
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(buf->Vertices.size()-3);
buf->Indices.push_back(0);
//Calculate normals
CalculateNormals(buf->Vertices, buf->Indices);
buf->recalculateBoundingBox();
newConeMesh->recalculateBoundingBox();
IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);
newConeMesh->drop();
return node;
}
return NULL;
}
示例3: createHillPlaneMesh
// creates a hill plane
IAnimatedMesh* CGeometryCreator::createHillPlaneMesh(const core::dimension2d<f32>& tileSize, const core::dimension2d<s32>& tc,
video::SMaterial* material, f32 hillHeight, const core::dimension2d<f32>& ch,
const core::dimension2d<f32>& textureRepeatCount)
{
core::dimension2d<s32> tileCount = tc;
tileCount.Height += 1;
tileCount.Width += 1;
core::dimension2d<f32> countHills = ch;
SMeshBuffer* buffer = new SMeshBuffer();
SMesh* mesh = new SMesh();
video::S3DVertex vtx;
vtx.Color.set(255,255,255,255);
vtx.Normal.set(0,0,0);
if (countHills.Width < 0.01f) countHills.Width = 1;
if (countHills.Height < 0.01f) countHills.Height = 1;
f32 halfX = (tileSize.Width * tileCount.Width) / 2;
f32 halfY = (tileSize.Height * tileCount.Height) / 2;
// create vertices
s32 x = 0;
s32 y = 0;
core::dimension2d<f32> tx;
tx.Width = 1.0f / (tileCount.Width / textureRepeatCount.Width);
tx.Height = 1.0f / (tileCount.Height / textureRepeatCount.Height);
for (x=0; x<tileCount.Width; ++x)
for (y=0; y<tileCount.Height; ++y)
{
vtx.Pos.set(tileSize.Width * x - halfX, 0, tileSize.Height * y - halfY);
vtx.TCoords.set(-(f32)x * tx.Width, (f32)y * tx.Height);
if (hillHeight)
vtx.Pos.Y = (f32)(sin(vtx.Pos.X * countHills.Width * engine::core::PI / halfX) *
cos(vtx.Pos.Z * countHills.Height * engine::core::PI / halfY))
*hillHeight;
buffer->Vertices.push_back(vtx);
}
// create indices
for (x=0; x<tileCount.Width-1; ++x)
for (y=0; y<tileCount.Height-1; ++y)
{
s32 current = y*tileCount.Width + x;
buffer->Indices.push_back(current);
buffer->Indices.push_back(current + 1);
buffer->Indices.push_back(current + tileCount.Width);
buffer->Indices.push_back(current + 1);
buffer->Indices.push_back(current + 1 + tileCount.Width);
buffer->Indices.push_back(current + tileCount.Width);
}
// recalculate normals
for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
{
core::plane3d<f32> p(
buffer->Vertices[buffer->Indices[i+0]].Pos,
buffer->Vertices[buffer->Indices[i+1]].Pos,
buffer->Vertices[buffer->Indices[i+2]].Pos);
p.Normal.normalize();
buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
}
if (material)
buffer->Material = *material;
buffer->recalculateBoundingBox();
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
animatedMesh->addMesh(mesh);
animatedMesh->recalculateBoundingBox();
mesh->drop();
buffer->drop();
return animatedMesh;
}
示例4: createMesh
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
{
const long filesize = file->getSize();
if (filesize < 6) // we need a header
return 0;
const u32 WORD_BUFFER_LENGTH = 512;
SMesh* mesh = new SMesh();
SMeshBuffer* meshBuffer = new SMeshBuffer();
mesh->addMeshBuffer(meshBuffer);
meshBuffer->drop();
core::vector3df vertex[3];
core::vector3df normal;
c8 buffer[WORD_BUFFER_LENGTH];
bool binary = false;
file->read(buffer, 5);
if (strncmp("solid", buffer, 5))
binary = true;
// read/skip header
u32 binFaceCount = 0;
if (binary)
{
file->seek(80);
file->read(&binFaceCount, 4);
#ifdef __BIG_ENDIAN__
binFaceCount = os::Byteswap::byteswap(binFaceCount);
#endif
}
else
goNextLine(file);
u16 attrib=0;
core::stringc token;
token.reserve(32);
while (file->getPos() < filesize)
{
if (!binary)
{
if (getNextToken(file, token) != "facet")
{
if (token=="endsolid")
break;
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "normal")
{
mesh->drop();
return 0;
}
}
getNextVector(file, normal, binary);
if (!binary)
{
if (getNextToken(file, token) != "outer")
{
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "loop")
{
mesh->drop();
return 0;
}
}
for (u32 i=0; i<3; ++i)
{
if (!binary)
{
if (getNextToken(file, token) != "vertex")
{
mesh->drop();
return 0;
}
}
getNextVector(file, vertex[i], binary);
}
if (!binary)
{
if (getNextToken(file, token) != "endloop")
{
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "endfacet")
{
mesh->drop();
return 0;
}
}
else
//.........这里部分代码省略.........
示例5: createTerrainMesh
//.........这里部分代码省略.........
blockSize.Width = hMapSize.Width - processed.X;
if (processed.Y + blockSize.Height > hMapSize.Height)
blockSize.Height = hMapSize.Height - processed.Y;
SMeshBuffer* buffer = new SMeshBuffer();
s32 x,y;
// add vertices of vertex block
for (y=0; y<blockSize.Height; ++y)
for (x=0; x<blockSize.Width; ++x)
{
video::SColor clr = heightmap->getPixel(x+processed.X, y+processed.Y);
f32 height = ((clr.getRed() + clr.getGreen() + clr.getBlue()) / 3.0f)/255.0f * maxHeight;
vtx.Pos.set((f32)(x+processed.X) * stretchSize.Width,
height, (f32)(y+processed.Y) * stretchSize.Height);
vtx.TCoords.set((f32)(x+0.5f) / ((f32)blockSize.Width),
(f32)(y+0.5f) / ((f32)blockSize.Height));
buffer->Vertices.push_back(vtx);
}
// add indices of vertex block
for (y=0; y<blockSize.Height-1; ++y)
for (x=0; x<blockSize.Width-1; ++x)
{
s32 c = (y*blockSize.Width) + x;
buffer->Indices.push_back(c);
buffer->Indices.push_back(c + blockSize.Width);
buffer->Indices.push_back(c + 1);
buffer->Indices.push_back(c + 1);
buffer->Indices.push_back(c + blockSize.Width);
buffer->Indices.push_back(c + 1 + blockSize.Width);
}
// recalculate normals
for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
{
core::plane3d<f32> p(
buffer->Vertices[buffer->Indices[i+0]].Pos,
buffer->Vertices[buffer->Indices[i+1]].Pos,
buffer->Vertices[buffer->Indices[i+2]].Pos);
p.Normal.normalize();
buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
}
if (buffer->Vertices.size())
{
// create texture for this block
video::IImage* img = new video::CImage(texture,
core::position2d<s32>((s32)(processed.X*thRel.X), (s32)(processed.Y*thRel.Y)),
core::dimension2d<s32>((s32)(blockSize.Width*thRel.X), (s32)(blockSize.Height*thRel.Y)));
sprintf(textureName, "terrain%d_%d", tm, mesh->getMeshBufferCount());
material.Texture1 = driver->addTexture(textureName, img);
if (material.Texture1)
{
sprintf(tmp, "Generated terrain texture (%dx%d): %s",
material.Texture1->getSize().Width,
material.Texture1->getSize().Height,
textureName);
os::Printer::log(tmp);
}
else
os::Printer::log("Could not create terrain texture.", textureName, ELL_ERROR);
buffer->Material = material;
img->drop();
}
buffer->recalculateBoundingBox();
mesh->addMeshBuffer(buffer);
buffer->drop();
// keep on processing
processed.X += maxVtxBlockSize.Width - borderSkip;
}
// keep on processing
processed.X = 0;
processed.Y += maxVtxBlockSize.Height - borderSkip;
}
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
mesh->recalculateBoundingBox();
animatedMesh->addMesh(mesh);
animatedMesh->recalculateBoundingBox();
mesh->drop();
return animatedMesh;
}