本文整理汇总了C++中SMesh::addMeshBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ SMesh::addMeshBuffer方法的具体用法?C++ SMesh::addMeshBuffer怎么用?C++ SMesh::addMeshBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMesh
的用法示例。
在下文中一共展示了SMesh::addMeshBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMeshFromSoftBody
IMesh* MeshTools::createMeshFromSoftBody(btSoftBody* softBody)
{
SMeshBuffer* buffer = new SMeshBuffer();
video::S3DVertex vtx;
vtx.Color.set(255,255,255,255);
/* Each soft body contain an array of vertices (nodes/particles_mass) */
btSoftBody::tNodeArray& nodes(softBody->m_nodes);
// Convert bullet nodes to vertices
for(int i=0;i<nodes.size();++i)
{
const btSoftBody::Node& n=nodes[i];
const btVector3 normal=n.m_n;
const btVector3 pos=n.m_x;
vtx.Pos.set(pos.getX(), pos.getY(), pos.getZ());
vtx.Normal.set(normal.getX(), normal.getY(), normal.getZ());
// TODO: calculate texture coords
//vtx.TCoords.set(tsx, tsy);
buffer->Vertices.push_back(vtx);
}
// Convert triangles of the softbody to an index list
for(int i=0;i<softBody->m_faces.size();++i)
{
auto faces = softBody->m_faces;
btSoftBody::Node* node_0=faces[i].m_n[0];
btSoftBody::Node* node_1=faces[i].m_n[1];
btSoftBody::Node* node_2=faces[i].m_n[2];
const int indices[] =
{
int(node_0-&nodes[0]),
int(node_1-&nodes[0]),
int(node_2-&nodes[0])
};
for(int j=0;j<3;++j)
buffer->Indices.push_back(indices[j]);
}
buffer->recalculateBoundingBox();
// Default the mesh to stream because most likely we will be updating
// the vertex positions every frame to deal with softbody movement.
buffer->setHardwareMappingHint(EHM_STREAM);
SMesh* mesh = new SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
buffer->drop();
return mesh;
}
示例2: readMesh
//! reads a mesh sections and creates a mesh from it
IAnimatedMesh* CIrrMeshFileLoader::readMesh(io::IXMLReader* reader)
{
SAnimatedMesh* animatedmesh = new SAnimatedMesh();
SMesh* mesh = new SMesh();
animatedmesh->addMesh(mesh);
mesh->drop();
core::stringc bbSectionName = "boundingBox";
core::stringc bufferSectionName = "buffer";
core::stringc meshSectionName = "mesh";
if (!reader->isEmptyElement())
while(reader->read())
{
if (reader->getNodeType() == io::EXN_ELEMENT)
{
const wchar_t* nodeName = reader->getNodeName();
if (bbSectionName == nodeName)
{
// inside a bounding box, ignore it for now because
// we are calculating this anyway ourselves later.
}
else
if (bufferSectionName == nodeName)
{
// we've got a mesh buffer
IMeshBuffer* buffer = readMeshBuffer(reader);
if (buffer)
{
mesh->addMeshBuffer(buffer);
buffer->drop();
}
}
else
skipSection(reader, true); // unknown section
} // end if node type is element
else
if (reader->getNodeType() == io::EXN_ELEMENT_END)
{
if (meshSectionName == reader->getNodeName())
{
// end of mesh section reached, cancel out
break;
}
}
} // end while reader->read();
mesh->recalculateBoundingBox();
animatedmesh->recalculateBoundingBox();
return animatedmesh;
}
示例3: addstrip
void addstrip(const HeightMap &hm, colour_func cf, u16 y0, u16 y1, u32 bufNum)
{
SMeshBuffer *buf = 0;
if (bufNum<Mesh->getMeshBufferCount())
{
buf = (SMeshBuffer*)Mesh->getMeshBuffer(bufNum);
}
else
{
// create new buffer
buf = new SMeshBuffer();
Mesh->addMeshBuffer(buf);
// to simplify things we drop here but continue using buf
buf->drop();
}
buf->Vertices.set_used((1 + y1 - y0) * Width);
u32 i=0;
for (u16 y = y0; y <= y1; ++y)
{
for (u16 x = 0; x < Width; ++x)
{
const f32 z = hm.get(x, y);
const f32 xx = (f32)x/(f32)Width;
const f32 yy = (f32)y/(f32)Height;
S3DVertex& v = buf->Vertices[i++];
v.Pos.set(x, Scale * z, y);
v.Normal.set(hm.getnormal(x, y, Scale));
v.Color=cf(xx, yy, z);
v.TCoords.set(xx, yy);
}
}
buf->Indices.set_used(6 * (Width - 1) * (y1 - y0));
i=0;
for(u16 y = y0; y < y1; ++y)
{
for(u16 x = 0; x < Width - 1; ++x)
{
const u16 n = (y-y0) * Width + x;
buf->Indices[i]=n;
buf->Indices[++i]=n + Width;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + 1;
buf->Indices[++i]=n;
++i;
}
}
buf->recalculateBoundingBox();
}
示例4: SMesh
irr::scene::IMesh* CGWIC_Cell::TerrainToMesh(int LOD)
{
SMesh* out = new SMesh();
CDynamicMeshBuffer* buff = new CDynamicMeshBuffer(EVT_2TCOORDS,EIT_16BIT);
terrain->getMeshBufferForLOD(*buff,LOD);
const u32 vertCnt = buff->getVertexCount();
S3DVertex2TCoords* mbv = reinterpret_cast<S3DVertex2TCoords*> (buff->getVertexBuffer().getData());
vector3df scale = terrain->getScale();
for (u32 i=0; i<vertCnt; i++) mbv[i].Pos *= scale;
out->addMeshBuffer(buff);
out->recalculateBoundingBox();
buff->drop();
terrain->setPosition(terrain->getPosition());
return out;
}
示例5: 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* COCTLoader::createMesh(io::IReadFile* file)
{
if (!file)
return 0;
octHeader header;
file->read(&header, sizeof(octHeader));
octVert * verts = new octVert[header.numVerts];
octFace * faces = new octFace[header.numFaces];
octTexture * textures = new octTexture[header.numTextures];
octLightmap * lightmaps = new octLightmap[header.numLightmaps];
octLight * lights = new octLight[header.numLights];
file->read(verts, sizeof(octVert) * header.numVerts);
file->read(faces, sizeof(octFace) * header.numFaces);
//TODO: Make sure id is in the legal range for Textures and Lightmaps
u32 i;
for (i = 0; i < header.numTextures; i++) {
octTexture t;
file->read(&t, sizeof(octTexture));
textures[t.id] = t;
}
for (i = 0; i < header.numLightmaps; i++) {
octLightmap t;
file->read(&t, sizeof(octLightmap));
lightmaps[t.id] = t;
}
file->read(lights, sizeof(octLight) * header.numLights);
//TODO: Now read in my extended OCT header (flexible lightmaps and vertex normals)
// This is the method Nikolaus Gebhardt used in the Q3 loader -- create a
// meshbuffer for every possible combination of lightmap and texture including
// a "null" texture and "null" lightmap. Ones that end up with nothing in them
// will be removed later.
SMesh * Mesh = new SMesh();
for (i=0; i<(header.numTextures+1) * (header.numLightmaps+1); ++i)
{
scene::SMeshBufferLightMap* buffer = new scene::SMeshBufferLightMap();
buffer->Material.MaterialType = video::EMT_LIGHTMAP;
buffer->Material.Lighting = false;
Mesh->addMeshBuffer(buffer);
buffer->drop();
}
// Build the mesh buffers
for (i = 0; i < header.numFaces; i++)
{
if (faces[i].numVerts < 3)
continue;
const f32* const a = verts[faces[i].firstVert].pos;
const f32* const b = verts[faces[i].firstVert+1].pos;
const f32* const c = verts[faces[i].firstVert+2].pos;
const core::vector3df normal =
core::plane3df(core::vector3df(a[0],a[1],a[2]), core::vector3df(b[0],c[1],c[2]), core::vector3df(c[0],c[1],c[2])).Normal;
const u32 textureID = core::min_(s32(faces[i].textureID), s32(header.numTextures - 1)) + 1;
const u32 lightmapID = core::min_(s32(faces[i].lightmapID),s32(header.numLightmaps - 1)) + 1;
SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(lightmapID * (header.numTextures + 1) + textureID);
const u32 base = meshBuffer->Vertices.size();
// Add this face's verts
u32 v;
for (v = 0; v < faces[i].numVerts; ++v)
{
octVert * vv = &verts[faces[i].firstVert + v];
video::S3DVertex2TCoords vert;
vert.Pos.set(vv->pos[0], vv->pos[1], vv->pos[2]);
vert.Color = video::SColor(0,255,255,255);
vert.Normal.set(normal);
if (textureID == 0)
{
// No texture -- just a lightmap. Thus, use lightmap coords for texture 1.
// (the actual texture will be swapped later)
vert.TCoords.set(vv->lc[0], vv->lc[1]);
}
else
{
vert.TCoords.set(vv->tc[0], vv->tc[1]);
vert.TCoords2.set(vv->lc[0], vv->lc[1]);
}
meshBuffer->Vertices.push_back(vert);
}
// Now add the indices
// This weird loop turns convex polygons into triangle strips.
// I do it this way instead of a simple fan because it usually looks a lot better in wireframe, for example.
//.........这里部分代码省略.........
示例6: 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
//.........这里部分代码省略.........
示例7: 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;
}
示例8: createMeshFromHeightmap
//.........这里部分代码省略.........
vert.Pos.set(x, y, thisHeight);
// I'm only averaging normals along the 4 compass directions. It's
// arguable whether diagonals should count; I chose to ignore diagonals.
// Ignoring diagonals allows me to assume the "run" in rise/run is always
// just one unit; if you add diagonals here you'll also need to change
// the slope calculation to use the actual distance instead of assuming 1.
vector2di offsetsArray[] = {
vector2di( 1, 0), // 3 o'clock
vector2di( 0, 1), // 12 o'clock
vector2di(-1, 0), // 9 o'clock
vector2di( 0,-1) // 6 o'clock
};
// Calculate the normals of the surrounding slopes.
// Uses the image, not just the tile patch size, so it will
// calculate correct normals for vertices on tile edges.
for (size_t i=-0; i < 4; ++i)
{
vector2di offset = vector2di(x,y) + offsetsArray[i];
// Skip this offset if it's outside the image
if (offset.X < 0 || offset.Y < 0 || offset.X >= (s32)imageDimension.Width || offset.Y >= (s32)imageDimension.Height)
continue;
vector2di otherPixelPos(
startAtPixel.X+x+offset.X,
startAtPixel.Y-y-offset.Y
);
float otherHeight = 255 - image->getPixel((u32)otherPixelPos.X, (u32)otherPixelPos.Y).getAverage();
// The code Irrlicht's in terrain scene node does all kinds of complicated
// business with cross products and such - waaay over complicated. You don't need
// all that stuff. Dude it' s a heightmap: all you need to worray about is
// rise over run on unit intervals! Algebra 1 type stuff, y = mx + c
// Calculate the rise of the line over the run, taking into account the fact
// that the offset could be in either direction.
float rise = (offset.X < 0 || offset.Y < 0)? thisHeight - otherHeight : otherHeight - thisHeight;
// Assuming that run = 1, m = rise / run is just m = rise.
float m = rise;
// The the slope of the normal is just the negative of the reciprocal of the line slope.
float n = -1.0f / rise;
// The X,Y of the normal vector is just going to be the X and Y of the offset
// (think about it - obviously the normal of the slope must tilt in the direction of the run)
// and the Z of the normal vector is just the slope of the normal over that run.
vector3df normVect(offset.X, offset.Y, n);
//vert.Normal += normVect;
}
//vert.Normal.normalize();
vert.Normal.set(0,0,-1.0f);
}
}
// Pre-allocate index data to 2*3*Width*Height for triangles.
// There is actually 1 less square per count of vertices though,
// for instance if you had 2x2 vertices, you only have 1 square.
buffer->Indices.set_used(2*3*(useTileSize.Width-1)*(useTileSize.Height-1));
// Start with 1 and generate all the triangles from their top right corners.
// Like this (A is top right corner at x,y):
//
// y=1 B---A
// | / |
// y=0 C---D
// x=0 x=1
for (u32 dst=0, x=1; x < useTileSize.Width; ++x)
{
for (u32 y=1; y < useTileSize.Height; ++y)
{
u32 A = getIndex(useTileSize, x, y );
u32 B = getIndex(useTileSize, x-1, y );
u32 C = getIndex(useTileSize, x-1, y-1 );
u32 D = getIndex(useTileSize, x, y-1 );
buffer->Indices[dst++] = C;
buffer->Indices[dst++] = B;
buffer->Indices[dst++] = A;
buffer->Indices[dst++] = D;
buffer->Indices[dst++] = C;
buffer->Indices[dst++] = A;
}
}
buffer->recalculateBoundingBox();
buffer->setHardwareMappingHint(EHM_STATIC);
SMesh* mesh = new SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
buffer->drop();
return mesh;
}
示例9: build
// ----------------------------------------------------------------------------
void Track::build()
{
IrrlichtDevice* device = Editor::getEditor()->getDevice();
PHYSFS_setWriteDir(Editor::getEditor()->getTrackDir().c_str());
PHYSFS_mkdir(m_file_name.c_str());
path p = Editor::getEditor()->getTrackDir() + m_file_name;
CMeshBuffer<S3DVertex2TCoords>* mb = m_terrain->build(p);
SMesh smesh;
smesh.addMeshBuffer(mb);
for (u32 i = 1; i < m_roads.size(); i++)
{
IRoad* r = m_roads[i];
if (r->getSpline()->getPointNum()>1)
smesh.addMeshBuffer(((Road*)r)->getMeshBuffer());
}
B3DMeshWriter* writer = new B3DMeshWriter(device->getFileSystem());
IWriteFile *file;
file = device->getFileSystem()->createAndWriteFile((p + "/track.b3d").c_str());
writer->writeMesh(file, &smesh);
file->drop();
delete writer;
m_driveline->build(p);
std::ofstream mat;
mat.open((p + "/materials.xml").c_str());
mat << "<materials>\n";
mat << " <material name=\"splatt.png\" graphical-effect=\"splatting\"";
SMaterial m = m_terrain->getMaterial(0);
for (int i = 1; i < 5; i++)
{
mat << " splatting-texture-" << i << "=\"";
mat << Editor::toRelative(m.getTexture(i+1)->getName()).c_str();
mat << "\"";
}
mat << "/>\n";
if (m_gravity_road)
{
for (u32 i = 1; i < m_roads.size(); i++)
{
stringc tex = m_roads[i]->getTexName();
if (tex.size()>0)
{
mat << " <material name=\"";
mat << tex.c_str();
mat << "\" has-gravity=\"yes\" />\n";
}
} // roads
} // gravity road mode
mat <<"</materials>\n";
mat.close();
stringw track;
track += "<track name = \"";
track += m_track_name + L"\"\n";
track += " version = \"5\"\n";
track += " groups = \"made-by-STK-TE\"\n";
track += " designer = \"";
track += m_designer + "\"\n";
track += " music = \"";
track += m_music.c_str();
track += "\"\n";
track += " screenshot = \"screenshot.jpg\"\n";
track += " smooth-normals = \"true\"\n";
track += " reverse = \"Y\"\n>\n";
track += "</track>\n";
PHYSFS_uint64 len = 4 * track.size();
char* dst = new char[len];
#ifdef _WIN32
PHYSFS_utf8FromUcs2((PHYSFS_uint16*)track.c_str(),dst,len);
#else
PHYSFS_utf8FromUcs4((PHYSFS_uint32*)track.c_str(), dst, len);
#endif
FILE* f;
f = fopen((p + "/track.xml").c_str(), "wb");
fwrite(dst, sizeof(char), strlen(dst), f);
fclose(f);
delete[] dst;
std::ofstream scene;
scene.open((p + "/scene.xml").c_str());
scene << "<scene>\n";
scene << " <track model=\"track.b3d\" x=\"0\" y=\"0\" z=\"0\">\n";
exportElements(scene, true);
scene << " </track>\n";
exportElements(scene, false);
//.........这里部分代码省略.........
示例10: splitMeshZ
//.........这里部分代码省略.........
// 1 cont. AB' AB' AB' replaces B in P
// 2 - B B proper is in Q and not in P
// 2 cont. - - Link B-C is not split
// 3 - C C proper is in Q and not in P
// 3 cont. CA' CA' CA' replaces C in P
//
// Now, read the columns P and Q vertically top to bottom to see the resultant vertex order.
// The triangle P is trivially still the correct winding order; it is just a smaller triangle now.
// The new quad Q retains the old triangle's winding order property for the following reason:
// As you wrapped around a full circle in old triangle A-B-C you would have traversed C-A then A-B.
// The link C-A has been cut and vertex CA' inserted.
// The link A-B has been cut and vertex AB' inserted.
// If you traverse the new shape starting from the _middle_ you follow the following path:
// B-C C-CA' CA'-AB' AB'-B B-C (again)
// Compare to old triangle:
// B-C C-A A-B B-C (again)
// Even though vertex A has been cut off and replaced with two vertices, the two
// new vertices lie along the path that the old links took and are in the new shape in the right order.
mid1 = linkSplitter.processLink(leftShape, rightShape, a, b);
mid2 = linkSplitter.processLink(leftShape, rightShape, b, c);
mid3 = linkSplitter.processLink(leftShape, rightShape, c, a);
}
// If a triangle was split then two of those three midpoints are inhabited by a vertex.
// We want to get them both in mid1 and mid2 AND we need them in correct order.
PsblVertPtr cut1 = (mid1 && mid2)? mid1 : mid2;
PsblVertPtr cut2 = (mid2 && mid3)? mid3 : mid2;
if (cut1 && cut2)
{
vector<PsblVertPtr> chain = linkSplitter.chopLink(cut1, cut2, 1);
linkSplitter.insertPoints(leftShape, cut1, cut2, chain);
linkSplitter.insertPoints(rightShape, cut1, cut2, chain);
}
linkSplitter.addConvexShape(leftShape, leftMeshBuf, -offset/2);
linkSplitter.addConvexShape(rightShape, rightMeshBuf, offset/2);
// Add any edges of the left shape that lie along the border.
linkSplitter.addEdgeLinks(leftShape, leftEdgeLinks);
// Right side polys that share a border with left side ones will have
// opposite winding order. In order for set_intersection to consider them
// as matches, we'll store the right side links in reversed order.
std::reverse(rightShape.begin(), rightShape.end());
linkSplitter.addEdgeLinks(rightShape, rightEdgeLinks);
}
SMesh* leftMesh = new SMesh();
leftMeshBuf->recalculateBoundingBox();
leftMeshBuf->setHardwareMappingHint(EHM_STATIC);
leftMesh->addMeshBuffer(leftMeshBuf);
leftMesh->recalculateBoundingBox();
leftMeshBuf->drop(); // we drop the buf, mesh obj has it now
SMesh* rightMesh = new SMesh();
rightMeshBuf->recalculateBoundingBox();
rightMeshBuf->setHardwareMappingHint(EHM_STATIC);
rightMesh->addMeshBuffer(rightMeshBuf);
rightMesh->recalculateBoundingBox();
rightMeshBuf->drop(); // we drop the buf, mesh obj has it now
SMesh* middleMesh = NULL;
if (zInsert > 0)
{
set<pair<PsblVertPtr,PsblVertPtr>> result;
std::set_intersection(
leftEdgeLinks.begin(), leftEdgeLinks.end(),
rightEdgeLinks.begin(), rightEdgeLinks.end(),
std::inserter(result, result.begin())
);
size_t debugsize = result.size();
if (result.size() > 0)
{
SMeshBuffer* middleMeshBuf = new SMeshBuffer();
vector<PsblVertPtr> shape(4);
for (auto it=result.begin(); it!=result.end(); ++it)
{
shape[0] = it->second;
shape[1] = it->first;
shape[2] = it->first->duplicate(offset);
shape[3] = it->second->duplicate(offset);
linkSplitter.addConvexShape(shape, middleMeshBuf, -offset/2);
}
middleMesh = new SMesh();
middleMeshBuf->recalculateBoundingBox();
middleMeshBuf->setHardwareMappingHint(EHM_STATIC);
middleMesh->addMeshBuffer(middleMeshBuf);
middleMesh->recalculateBoundingBox();
middleMeshBuf->drop(); // we drop the buf, mesh obj has it now
}
}
return SplitMeshResult {leftMesh, middleMesh, rightMesh};
}
示例11: 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;
}
示例12: clr
//.........这里部分代码省略.........
// lets add the indices to the buffer
buffer->Indices.set_used( (u32)(3 * nb_of_faces) );
u32 i = 0;
// this is one line : inface >> index >> p1 >> p2 >> p3;
inface.read(reinterpret_cast < char * > (&p1), sizeof(int));
inface.read(reinterpret_cast < char * > (&p2), sizeof(int));
inface.read(reinterpret_cast < char * > (&p3), sizeof(int));
while (!inface.eof() && inface.good())
{
// check if we are not out of bounds
if (i > (u32)(3 * nb_of_faces - 3) || p1 > nb_of_points || p2 > nb_of_points || p3 > nb_of_points)
{
device->getLogger()->log("ERROR: the face file does not seem to be valid. ");
buffer->drop();
error = true;
break;
}
// add 1 polygon per face.
s32 ajust_index = -1;
buffer->Indices[(u32)(i+0)] = (u32)(p1 + ajust_index);
buffer->Indices[(u32)(i+1)] = (u32)(p3 + ajust_index);
buffer->Indices[(u32)(i+2)] = (u32)(p2 + ajust_index);
core::triangle3df t(
buffer->Vertices[(u32)(p1 + ajust_index)].Pos,
buffer->Vertices[(u32)(p3 + ajust_index)].Pos,
buffer->Vertices[(u32)(p2 + ajust_index)].Pos);
i += 3;
buffer->Vertices[(u32)(p1 + ajust_index)].Normal = t.getNormal();
buffer->Vertices[(u32)(p2 + ajust_index)].Normal = t.getNormal();
buffer->Vertices[(u32)(p3 + ajust_index)].Normal = t.getNormal();
// this is one line : inface >> index >> p1 >> p2 >> p3;
inface.read(reinterpret_cast < char * > (&p1), sizeof(int));
inface.read(reinterpret_cast < char * > (&p2), sizeof(int));
inface.read(reinterpret_cast < char * > (&p3), sizeof(int));
}
inface.close();
inface.clear();
}
else // we do not need to reload from the file !
{
buffer->Indices.reallocate(PlayerFrame::lastBuffers[faceLoadedIndex]->Indices.size());
buffer->Indices = PlayerFrame::lastBuffers[faceLoadedIndex]->Indices;
for (u32 j=0; j < buffer->Vertices.size(); j++)
buffer->Vertices[j].Normal = PlayerFrame::lastBuffers[faceLoadedIndex]->Vertices[j].Normal;
}
// -----------------------------------------------------------------------
}
if (error)
continue;
// lets recalculate the bounding box and create the mesh
for (u32 j=0; j < buffer->Vertices.size(); ++j)
buffer->BoundingBox.addInternalPoint(buffer->Vertices[j].Pos);
SMesh* mesh = new SMesh;
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
// here we go, lets create the node that will owns the mesh data
node = smgr->addMeshSceneNode( mesh );
mesh->drop();
if (!node)
{
node = NULL;
continue;
}
node->setVisible(false);
//node->setMaterialFlag(video::EMF_WIREFRAME, true);
this->nodes.push_back( node );
// updating last
_lastEleFileNames.push_back( eleFileName );
_lastFaceFileNames.push_back( faceFileName );
_lastBuffers.push_back( buffer );
}
// clean history and update it
PlayerFrame::lastEleFileNames = _lastEleFileNames;
PlayerFrame::lastFaceFileNames = _lastFaceFileNames;
for (u32 e=0; e < lastBuffers.size(); e++)
{
if (_lastBuffers.binary_search(PlayerFrame::lastBuffers[e]) == -1)
{
PlayerFrame::lastBuffers[e]->drop();
}
}
PlayerFrame::lastBuffers = _lastBuffers;
PlayerFrame::last_was_volumic = load_volumic;
// that's it !
device->getLogger()->log("Loaded.");
}
示例13: 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;
}
示例14: crosses
//.........这里部分代码省略.........
}
};
Visitor visitor;
tree.triangulate(triangles, section, min_height, max_height, &visitor);
//tree.sweep(triangles, section, &visitor);
//cout << "num triangle points: " << triangles.size() << endl;
vector<QuadTreePtr> leaves;
tree.dumpLeaves(leaves);
//cout << "num leaves: " << leaves.size() << endl;
/*
for (QuadTreePtr p1 : leaves)
for (QuadTreePtr p2 : leaves)
if (p1 != p2)
if (p1->isAdjacent(p2))
if (!visitor.has(p1, p2))
{
auto sz1 = p1->region.getSize();
auto sz2 = p2->region.getSize();
auto c1 = p1->region.getCenter();
auto c2 = p2->region.getCenter();
char const* path1 = p1->getPath().c_str();
char const* path2 = p2->getPath().c_str();
cout << path1 << endl;
cout << path2 << endl;
cout << "Missing pair of adjacent vertices." << endl;
}
float x1 = section.UpperLeftCorner.X;
float x2 = section.LowerRightCorner.X;
float y1 = section.UpperLeftCorner.Y;
float y2 = section.LowerRightCorner.Y;
*/
/*
d---c
| / |
a---b
*/
/*
S3DVertex sa;
sa.Pos = vector3df(x1, y1, 0);
PsblVertPtr a = new PossibleVertex(sa);
S3DVertex sb;
sb.Pos = vector3df(x2, y1, 0);
PsblVertPtr b = new PossibleVertex(sb);
S3DVertex sc;
sc.Pos = vector3df(x2, y2, 0);
PsblVertPtr c = new PossibleVertex(sc);
S3DVertex sd;
sd.Pos = vector3df(x1, y2, 0);
PsblVertPtr d = new PossibleVertex(sd);
// a-b-c
// a-c-d
triangles.push_back(a);
triangles.push_back(b);
triangles.push_back(c);
triangles.push_back(a);
triangles.push_back(c);
triangles.push_back(d);
triangles.push_back(c);
triangles.push_back(b);
triangles.push_back(a);
triangles.push_back(d);
triangles.push_back(c);
triangles.push_back(a);
*/
SMeshBuffer* buffer = new SMeshBuffer();
for (auto pv : triangles)
pv->addToMeshBuf(buffer, vector3df());
if (buffer->getIndexCount() % 3 > 0)
throw std::logic_error("SurfaceQuadTree triangulation added a 'triangle' with less than 3 vertices in it.");
//cout << "num vertices " << buffer->getVertexCount() << endl;
//cout << "num indices " << buffer->getIndexCount() << endl;
buffer->recalculateBoundingBox();
buffer->setHardwareMappingHint(EHM_STATIC);
SMesh* mesh = new SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
buffer->drop();
return mesh;
}
示例15: if
//.........这里部分代码省略.........
if (meshHeader.TChannelCnt>1)
{
VertexB.TCoords2.X = TVertex2[TFace2[f].B].TCoord.X;
VertexB.TCoords2.Y = TVertex2[TFace2[f].B].TCoord.Y;
}
// vertex C
VertexC.Pos.X = Vertex[Face[f].A].Coord.X;
VertexC.Pos.Y = Vertex[Face[f].A].Coord.Y;
VertexC.Pos.Z = Vertex[Face[f].A].Coord.Z;
VertexC.Normal.X = Vertex[Face[f].A].Normal.X;
VertexC.Normal.Y = Vertex[Face[f].A].Normal.Y;
VertexC.Normal.Z = Vertex[Face[f].A].Normal.Z;
if (meshHeader.TChannelCnt>0)
{
VertexC.TCoords.X = TVertex1[TFace1[f].A].TCoord.X;
VertexC.TCoords.Y = TVertex1[TFace1[f].A].TCoord.Y;
}
if (meshHeader.TChannelCnt>1)
{
VertexC.TCoords2.X = TVertex2[TFace2[f].A].TCoord.X;
VertexC.TCoords2.Y = TVertex2[TFace2[f].A].TCoord.Y;
}
// store 3d data in mesh buffer
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexA);
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexB);
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexC);
//*****************************************************************
// !!!!!! W A R N I N G !!!!!!!
//*****************************************************************
// For materials with alpha channel we duplicate all faces.
// This has be done for proper lighting calculation of the back faces.
// So you must remember this while you creating your models !!!!!
//*****************************************************************
// !!!!!! W A R N I N G !!!!!!!
//*****************************************************************
if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
{
VertexA.Normal = core::vector3df(-VertexA.Normal.X, -VertexA.Normal.Y, -VertexA.Normal.Z);
VertexB.Normal = core::vector3df(-VertexB.Normal.X, -VertexB.Normal.Y, -VertexB.Normal.Z);
VertexC.Normal = core::vector3df(-VertexC.Normal.X, -VertexC.Normal.Y, -VertexC.Normal.Z);
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexC);
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexB);
buffer->getIndexBuffer()->addIndex(buffer->getVertexBuffer()->getVertexCount());
buffer->getVertexBuffer()->addVertex(&VertexA);
}
}
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
}
// creating mesh
SMesh* mesh = new SMesh();
for (u32 num=0; num<MeshBufferEntry.size(); ++num)
{
CMeshBuffer<video::S3DVertex2TCoords>* buffer = MeshBufferEntry[num].MeshBuffer;
if (!buffer)
continue;
mesh->addMeshBuffer(buffer);
buffer->recalculateBoundingBox();
buffer->drop();
}
mesh->recalculateBoundingBox();
if (id != MY3D_FILE_END_ID)
os::Printer::log("Loading finished, but can not find MY3D_FILE_END_ID token.", ELL_WARNING);
SAnimatedMesh* am = new SAnimatedMesh();
am->addMesh(mesh);
mesh->drop();
am->recalculateBoundingBox();
return am;
}