本文整理汇总了C++中SMesh类的典型用法代码示例。如果您正苦于以下问题:C++ SMesh类的具体用法?C++ SMesh怎么用?C++ SMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SAnimatedMesh
//! 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;
}
示例2: 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();
}
示例3: 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;
}
示例4: in
CGAL::Three::Scene_item*
Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
// Open file
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios::in | std::ios::binary);
if(!in) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL;
}
std::vector<CGAL::cpp11::array<double, 3> > points;
std::vector<CGAL::cpp11::array<int, 3> > triangles;
if (!CGAL::read_STL(in, points, triangles))
{
std::cerr << "Error: invalid STL file" << std::endl;
return NULL;
}
try{
// Try building a surface_mesh
SMesh* SM = new SMesh();
if (CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(triangles))
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, triangles, *SM);
if(!SM->is_valid() || SM->is_empty()){
std::cerr << "Error: Invalid facegraph" << std::endl;
}
else{
Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM);
item->setName(fileinfo.completeBaseName());
return item;
}
}
catch(...){}
Scene_polygon_soup_item* item = new Scene_polygon_soup_item();
item->setName(fileinfo.completeBaseName());
item->load(points, triangles);
return item;
}
示例5: getMeshTextureLoader
//! Creates/loads an animated mesh from the file.
IAnimatedMesh* CSMFMeshFileLoader::createMesh(io::IReadFile* file)
{
if ( !file )
return 0;
if ( getMeshTextureLoader() )
getMeshTextureLoader()->setMeshFile(file);
// create empty mesh
SMesh *mesh = new SMesh();
// load file
u16 version;
u8 flags;
s32 limbCount;
s32 i;
io::BinaryFile::read(file, version);
io::BinaryFile::read(file, flags);
io::BinaryFile::read(file, limbCount);
// load mesh data
core::matrix4 identity;
for (i=0; i < limbCount; ++i)
loadLimb(file, mesh, identity);
// recalculate buffer bounding boxes
for (i=0; i < (s32)mesh->getMeshBufferCount(); ++i)
mesh->getMeshBuffer(i)->recalculateBoundingBox();
mesh->recalculateBoundingBox();
SAnimatedMesh *am = new SAnimatedMesh();
am->addMesh(mesh);
mesh->drop();
am->recalculateBoundingBox();
return am;
}
示例6: ZERO
SBsp3 *SBsp3::FromMesh(SMesh *m) {
SBsp3 *bsp3 = NULL;
int i;
SMesh mc; ZERO(&mc);
for(i = 0; i < m->l.n; i++) {
mc.AddTriangle(&(m->l.elem[i]));
}
srand(0); // Let's be deterministic, at least!
int n = mc.l.n;
while(n > 1) {
int k = rand() % n;
n--;
SWAP(STriangle, mc.l.elem[k], mc.l.elem[n]);
}
for(i = 0; i < mc.l.n; i++) {
bsp3 = bsp3->Insert(&(mc.l.elem[i]), NULL);
}
mc.Clear();
return bsp3;
}
示例7: ExportMeshTo
//-----------------------------------------------------------------------------
// Export a triangle mesh, in the requested format.
//-----------------------------------------------------------------------------
void SolveSpace::ExportMeshTo(char *filename) {
SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh);
if(m->IsEmpty()) {
Error("Active group mesh is empty; nothing to export.");
return;
}
FILE *f = fopen(filename, "wb");
if(!f) {
Error("Couldn't write to '%s'", filename);
return;
}
if(StringEndsIn(filename, ".stl")) {
ExportMeshAsStlTo(f, m);
} else if(StringEndsIn(filename, ".obj")) {
ExportMeshAsObjTo(f, m);
} else {
Error("Can't identify output file type from file extension of "
"filename '%s'; try .stl, .obj.", filename);
}
fclose(f);
}
示例8: SMesh
//! 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
//.........这里部分代码省略.........
示例9: ZERO
void SolveSpace::ExportViewOrWireframeTo(char *filename, bool wireframe) {
int i;
SEdgeList edges;
ZERO(&edges);
SBezierList beziers;
ZERO(&beziers);
SMesh *sm = NULL;
if(SS.GW.showShaded) {
Group *g = SK.GetGroup(SS.GW.activeGroup);
g->GenerateDisplayItems();
sm = &(g->displayMesh);
}
if(sm && sm->IsEmpty()) {
sm = NULL;
}
for(i = 0; i < SK.entity.n; i++) {
Entity *e = &(SK.entity.elem[i]);
if(!e->IsVisible()) continue;
if(e->construction) continue;
if(SS.exportPwlCurves || (sm && !SS.GW.showHdnLines) ||
fabs(SS.exportOffset) > LENGTH_EPS)
{
// We will be doing hidden line removal, which we can't do on
// exact curves; so we need things broken down to pwls. Same
// problem with cutter radius compensation.
e->GenerateEdges(&edges);
} else {
e->GenerateBezierCurves(&beziers);
}
}
if(SS.GW.showEdges) {
Group *g = SK.GetGroup(SS.GW.activeGroup);
g->GenerateDisplayItems();
SEdgeList *selr = &(g->displayEdges);
SEdge *se;
for(se = selr->l.First(); se; se = selr->l.NextAfter(se)) {
edges.AddEdge(se->a, se->b, Style::SOLID_EDGE);
}
}
if(SS.GW.showConstraints) {
Constraint *c;
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
c->GetEdges(&edges);
}
}
if(wireframe) {
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
if(out) {
ExportWireframeCurves(&edges, &beziers, out);
}
} else {
Vector u = SS.GW.projRight,
v = SS.GW.projUp,
n = u.Cross(v),
origin = SS.GW.offset.ScaledBy(-1);
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
if(out) {
ExportLinesAndMesh(&edges, &beziers, sm,
u, v, n, origin, SS.CameraTangent()*SS.GW.scale,
out);
}
if(out && !out->HasCanvasSize()) {
// These file formats don't have a canvas size, so they just
// get exported in the raw coordinate system. So indicate what
// that was on-screen.
SS.justExportedInfo.draw = true;
SS.justExportedInfo.pt = origin;
SS.justExportedInfo.u = u;
SS.justExportedInfo.v = v;
InvalidateGraphics();
}
}
edges.Clear();
beziers.Clear();
}
示例10: PHYSFS_setWriteDir
// ----------------------------------------------------------------------------
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);
//.........这里部分代码省略.........
示例11: vector2di
IMesh* MeshTools::createMeshFromHeightmap(IImage* image, dimension2du tileSizeInPixels, vector2di tilePosInTiles, bool extraStripsOnEdges)
{
// Use top corner of image to get bias for centering the Z axis.
float imageZeroBias = image->getPixel(0,0).getAverage();
dimension2du imageDimension = image->getDimension();
// Easier to think of script working in whole tile units, so handle conversion to pixel pos in this method:
vector2di startAtPixel = tilePosInTiles * vector2di(tileSizeInPixels.Width, tileSizeInPixels.Height);
// However we're going to invert the image Y axis so that the bottom of the picture will be at 0,0 in world space,
// and the top of the picture will be at +Y in world space.
startAtPixel.Y = (imageDimension.Height-1) - startAtPixel.Y;
// Return nothing if the tile is outside the image, or if the resulting mesh would have only 0 or 1 rows or columns.
// Doing this check early prevents getting underflow when we clip the tile size to the image dimensions a few statements down.
if (startAtPixel.X < 0 || startAtPixel.X >= (imageDimension.Width-1) || startAtPixel.Y <= 0 || startAtPixel.Y > (imageDimension.Height-1))
return NULL;
// Calculate whether to use tile size or tile size + 1 (for generating overlap)
// Adding the extra strip amount before clipping to image dimensions prevents overflowing the image edges after clipping.
dimension2du useTileSize = tileSizeInPixels + (extraStripsOnEdges? dimension2du(1,1) : dimension2du(0,0));
// Clip the tile size if we're dealing with a "leftover" amount at the edge that's not a whole tile's width or height.
// Most heightmap implementations require exactly a power of 2 + 1 square dimensions like 257x257, but supporting
// image sizes that are not whole multiples of tile size is as simple as this one line of code and supporting
// image sizes that are not square is a nice feature for a platformer game so you can have levels that are longer
// than they are tall.
useTileSize.set(min(useTileSize.Width, imageDimension.Width-startAtPixel.X), min(useTileSize.Height, (u32)startAtPixel.Y+1));
SMeshBuffer* buffer = new SMeshBuffer();
// Preallocate vertex buffer to the size we know we'll need.
buffer->Vertices.set_used(useTileSize.Width*useTileSize.Height);
// Amount of TCoord per unit of x,y in image.
vector2df tCoordsScale(1.0f / useTileSize.Width, 1.0f / useTileSize.Height);
// Whether we put y on the outside or x on the outside, doesn't matter, because we are
// using getIndex() to find where x and y map too. However, I happen to know I made getIndex
// put x's together, y in rows, and looping in the same rank order might have better cache performance
// because it should access the vertices in the same order they are in the array.
for (u32 y=0; y < useTileSize.Height; ++y)
{
for (u32 x=0; x < useTileSize.Width; ++x)
{
u32 index = getIndex(useTileSize, x, y);
S3DVertex& vert = buffer->Vertices[index];
// No special coloration
vert.Color = SColor(255,255,255,255);
// Scale texture to tile.
vert.TCoords = vector2df(x,y) * tCoordsScale;
// y axis starts with 0 at image bottom and goes up.
vector2di pixelPos(
startAtPixel.X+x,
startAtPixel.Y-y
);
SColor heightColor = image->getPixel(pixelPos.X, pixelPos.Y);
float thisHeight = imageZeroBias - heightColor.getAverage();
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
//.........这里部分代码省略.........
示例12: SMeshBuffer
MeshTools::SplitMeshResult MeshTools::splitMeshZ(IMesh* oldMesh, float zCut, float zInsert, bool marginalTrisInLeft, bool marginalTrisInRight)
{
IMeshBuffer* oldMeshBuf = oldMesh->getMeshBuffer(0);
u16* oldInd = oldMeshBuf->getIndices();
SMeshBuffer* leftMeshBuf = new SMeshBuffer();
SMeshBuffer* rightMeshBuf = new SMeshBuffer();
LinkSplitter linkSplitter(oldMeshBuf, zCut);
vector3df const offset(0,0, zInsert);
set<pair<PsblVertPtr, PsblVertPtr>> leftEdgeLinks;
set<pair<PsblVertPtr, PsblVertPtr>> rightEdgeLinks;
for (u32 i=0; i < oldMeshBuf->getIndexCount(); i += 3)
{
// Calling these shapes instead of triangles because they could be triangle or a quad after slice,
// (it could also be a degenerate case of a line or a point - those will be discarded by addConvexShape)
vector<PsblVertPtr> leftShape;
vector<PsblVertPtr> rightShape;
int a = oldInd[i];
int b = oldInd[i+1];
int c = oldInd[i+2];
PsblVertPtr mid1;
PsblVertPtr mid2;
PsblVertPtr mid3;
// Don't create a copy just for a triangle that is just kissing the edge. Leave it in the background.
if (linkSplitter.compareZ(a)==0 && linkSplitter.compareZ(b)==0 && linkSplitter.compareZ(c)==0)
{
if (marginalTrisInLeft)
{
leftShape.push_back(linkSplitter.getVert(a));
leftShape.push_back(linkSplitter.getVert(b));
leftShape.push_back(linkSplitter.getVert(c));
}
if (marginalTrisInRight)
{
rightShape.push_back(linkSplitter.getVert(a));
rightShape.push_back(linkSplitter.getVert(b));
rightShape.push_back(linkSplitter.getVert(c));
}
}
else
{
// This is something I had to think hard about so I'm writing this comment so I don't
// have to think it through again or forget it:
//
// Both the left shape and the right shape, and both the triangle and the quad, "magically"
// come out with correct winding order when the triangle is split. Here's why:
// Let the original triangle vertices be A-B-C.
// Let the split midpoints be AB' and CA' as A-B is split and C-A are split respectively.
// The shapes (ignore which shape is left or right, call them P and Q instead)
// will be filled in the following order:
//
// round P Q Comment
// 1 A - A is not in Q at all
// 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);
//.........这里部分代码省略.........
示例13: GLlink
GLlink(ISceneNode *i_parent, ISceneManager *i_mgr, s32 i_id,
const LinkInfo &i_li, BodyInfo_var i_binfo) :
ISceneNode(i_parent, i_mgr, i_id),
m_jointId(i_li.jointId) {
setAutomaticCulling(scene::EAC_OFF);
setPosition(vector3df( i_li.translation[0],
-i_li.translation[1],
i_li.translation[2]));
Vector3 axis(i_li.rotation[0],
i_li.rotation[1],
i_li.rotation[2]);
Matrix33 R;
hrp::calcRodrigues(R, axis, i_li.rotation[3]);
Vector3 rpy(rpyFromRot(R));
//std::cout << "rpy:" << rpy << std::endl;
setRotation(vector3df(-180/M_PI*rpy[0],
180/M_PI*rpy[1],
-180/M_PI*rpy[2]));
m_axis << i_li.jointAxis[0], i_li.jointAxis[1], i_li.jointAxis[2];
ShapeInfoSequence_var sis = i_binfo->shapes();
AppearanceInfoSequence_var ais = i_binfo->appearances();
MaterialInfoSequence_var mis = i_binfo->materials();
TextureInfoSequence_var txs = i_binfo->textures();
const TransformedShapeIndexSequence& tsis = i_li.shapeIndices;
core::vector3df vertex;
core::vector3df normal;
for (unsigned int l=0; l<tsis.length(); l++) {
SMesh* mesh = new SMesh();
SMeshBuffer* meshBuffer = new SMeshBuffer();
mesh->addMeshBuffer(meshBuffer);
meshBuffer->drop();
const TransformedShapeIndex &tsi = tsis[l];
short index = tsi.shapeIndex;
ShapeInfo& si = sis[index];
const float *vertices = si.vertices.get_buffer();
const LongSequence& triangles = si.triangles;
const AppearanceInfo& ai = ais[si.appearanceIndex];
const float *normals = ai.normals.get_buffer();
//std::cout << "length of normals = " << ai.normals.length() << std::endl;
const LongSequence& normalIndices = ai.normalIndices;
//std::cout << "length of normalIndices = " << normalIndices.length() << std::endl;
const int numTriangles = triangles.length() / 3;
//std::cout << "numTriangles = " << numTriangles << std::endl;
video::SColor color(0xffffffff);
if (ai.colors.length()) {
color.set(0xff,
0xff*ai.colors[0],
0xff*ai.colors[1],
0xff*ai.colors[2]);
} else if (ai.materialIndex >= 0) {
const MaterialInfo& mi = mis[ai.materialIndex];
color.set(0xff,
0xff*mi.diffuseColor[0],
0xff*mi.diffuseColor[1],
0xff*mi.diffuseColor[2]);
} else {
std::cout << "no material" << std::endl;
}
SMeshBuffer* mb = reinterpret_cast<SMeshBuffer*>(mesh->getMeshBuffer(mesh->getMeshBufferCount()-1));
u32 vCount = mb->getVertexCount();
const DblArray12& tfm = tsi.transformMatrix;
CMatrix4<f32> cmat;
for (int i=0; i<3; i++) {
for (int j=0; j<4; j++) {
cmat[j*4+i] = tfm[i*4+j];
}
}
cmat[3] = cmat[7] = cmat[11] = 0.0;
cmat[15] = 1.0;
vector3df pos = cmat.getTranslation();
pos.Y *= -1;
vector3df rpy = cmat.getRotationDegrees();
rpy.X *= -1;
rpy.Z *= -1;
vector3df scale = cmat.getScale();
const float *textureCoordinate = NULL;
if (ai.textureIndex >= 0) {
textureCoordinate = ai.textureCoordinate.get_buffer();
//std::cout << "length of textureCoordinate:" << ai.textureCoordinate.length() << std::endl;
//std::cout << "length of vertices:" << si.vertices.length() << std::endl;
}
for(int j=0; j < numTriangles; ++j) {
if (!ai.normalPerVertex) {
int p;
if (normalIndices.length() == 0) {
//.........这里部分代码省略.........
示例14: SMeshBuffer
// 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;
}
示例15: SMesh
IMeshSceneNode* CustomSceneNodeManager::CreateCylinderSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height)
{
/*if (!cylinderMesh)
{*/
if (resolution >= 4)
{
SMesh* newCylinderMesh = new SMesh();
SMeshBuffer* buf = new SMeshBuffer();
newCylinderMesh->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;
temp1.Pos.X = x;
temp1.Pos.Z = z;
temp1.TCoords.X = currentTheta / 2.0f*PI;
temp2.Pos.X = x;
temp2.Pos.Z = z;
temp2.TCoords.X = currentTheta / 2.0f*PI;
buf->Vertices.push_back(temp1);
buf->Vertices.push_back(temp2);
currentTheta += skipAmount;
}
temp1.Pos.X = 0.0f;
temp1.Pos.Z = 0.0f;
temp1.TCoords.X = 0.0f;
temp2.Pos.X = 0.0f;
temp2.Pos.Z = 0.0f;
temp1.TCoords.X = 0.0f;
buf->Vertices.push_back(temp1);
buf->Vertices.push_back(temp2);
//Get indices
for(int i = 0; i < noWarningSignedResolution - 1; i++)
{
buf->Indices.push_back(i*2);
buf->Indices.push_back(i*2+2);
buf->Indices.push_back(i*2+1);
buf->Indices.push_back(i*2+1);
buf->Indices.push_back(i*2+2);
buf->Indices.push_back(i*2+3);
buf->Indices.push_back(i*2);
buf->Indices.push_back(buf->Vertices.size()-2);
buf->Indices.push_back(i*2+2);
buf->Indices.push_back(i*2+1);
buf->Indices.push_back(i*2+3);
buf->Indices.push_back(buf->Vertices.size()-1);
}
buf->Indices.push_back(buf->Vertices.size()-4);
buf->Indices.push_back(0);
buf->Indices.push_back(buf->Vertices.size()-3);
buf->Indices.push_back(buf->Vertices.size()-3);
buf->Indices.push_back(0);
buf->Indices.push_back(1);
buf->Indices.push_back(buf->Vertices.size()-4);
buf->Indices.push_back(buf->Vertices.size()-2);
buf->Indices.push_back(0);
buf->Indices.push_back(buf->Vertices.size()-3);
buf->Indices.push_back(1);
buf->Indices.push_back(buf->Vertices.size()-1);
//Calculate normals
CalculateNormals(buf->Vertices, buf->Indices);
buf->recalculateBoundingBox();
newCylinderMesh->recalculateBoundingBox();
IMeshSceneNode* node = sceneManager->addMeshSceneNode(newCylinderMesh);
newCylinderMesh->drop();
return node;
}
/* return NULL;
//.........这里部分代码省略.........