本文整理汇总了C++中SAnimatedMesh类的典型用法代码示例。如果您正苦于以下问题:C++ SAnimatedMesh类的具体用法?C++ SAnimatedMesh怎么用?C++ SAnimatedMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SAnimatedMesh类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: sizeof
//.........这里部分代码省略.........
file->seek(userSize,true);
// TEXTURES
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x54584554) { // "TEXT"
os::Printer::log("LMTS ERROR: wrong texture magic id!", ELL_ERROR);
return 0;
}
Textures = new SLMTSTextureInfoEntry[Header.TextureCount];
file->read(Textures, sizeof(SLMTSTextureInfoEntry)*Header.TextureCount);
if (FlipEndianess)
{
for (i=0; i<Header.TextureCount; ++i)
Textures[i].Flags = os::Byteswap::byteswap(Textures[i].Flags);
}
// SUBSETS
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x53425553) // "SUBS"
{
os::Printer::log("LMTS ERROR: wrong subset magic id!", ELL_ERROR);
cleanup();
return 0;
}
Subsets = new SLMTSSubsetInfoEntry[Header.SubsetCount];
const s32 subsetUserSize = Header.SubsetSize - sizeof(SLMTSSubsetInfoEntry);
for (i=0; i<Header.SubsetCount; ++i)
{
file->read(&Subsets[i], sizeof(SLMTSSubsetInfoEntry));
if (FlipEndianess)
{
Subsets[i].Offset = os::Byteswap::byteswap(Subsets[i].Offset);
Subsets[i].Count = os::Byteswap::byteswap(Subsets[i].Count);
Subsets[i].TextID1 = os::Byteswap::byteswap(Subsets[i].TextID1);
Subsets[i].TextID2 = os::Byteswap::byteswap(Subsets[i].TextID2);
}
if (subsetUserSize>0)
file->seek(subsetUserSize,true);
}
// TRIANGLES
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x53495254) // "TRIS"
{
os::Printer::log("LMTS ERROR: wrong triangle magic id!", ELL_ERROR);
cleanup();
return 0;
}
Triangles = new SLMTSTriangleDataEntry[(Header.TriangleCount*3)];
const s32 triUserSize = Header.VertexSize - sizeof(SLMTSTriangleDataEntry);
for (i=0; i<(Header.TriangleCount*3); ++i)
{
file->read(&Triangles[i], sizeof(SLMTSTriangleDataEntry));
if (FlipEndianess)
{
Triangles[i].X = os::Byteswap::byteswap(Triangles[i].X);
Triangles[i].Y = os::Byteswap::byteswap(Triangles[i].Y);
Triangles[i].Z = os::Byteswap::byteswap(Triangles[i].Z);
Triangles[i].U1 = os::Byteswap::byteswap(Triangles[i].U1);
Triangles[i].V1 = os::Byteswap::byteswap(Triangles[i].U2);
Triangles[i].U2 = os::Byteswap::byteswap(Triangles[i].V1);
Triangles[i].V2 = os::Byteswap::byteswap(Triangles[i].V2);
}
if (triUserSize>0)
file->seek(triUserSize,true);
}
/////////////////////////////////////////////////////////////////
SMesh* mesh = new SMesh();
constructMesh(mesh);
loadTextures(mesh);
cleanup();
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_LMTS; // not unknown to irrlicht anymore
am->addMesh(mesh);
am->recalculateBoundingBox();
mesh->drop();
return am;
}
示例3: SMesh
//.........这里部分代码省略.........
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
{
file->read(&attrib, 2);
#ifdef __BIG_ENDIAN__
attrib = os::Byteswap::byteswap(attrib);
#endif
}
SMeshBuffer* mb = reinterpret_cast<SMeshBuffer*>(mesh->getMeshBuffer(mesh->getMeshBufferCount()-1));
u32 vCount = mb->getVertexCount();
video::SColor color(0xffffffff);
if (attrib & 0x8000)
color = video::A1R5G5B5toA8R8G8B8(attrib);
if (normal==core::vector3df())
normal=core::plane3df(vertex[2],vertex[1],vertex[0]).Normal;
mb->Vertices.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df()));
mb->Vertices.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df()));
mb->Vertices.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df()));
mb->Indices.push_back(vCount);
mb->Indices.push_back(vCount+1);
mb->Indices.push_back(vCount+2);
} // end while (file->getPos() < filesize)
mesh->getMeshBuffer(0)->recalculateBoundingBox();
// Create the Animated mesh if there's anything in the mesh
SAnimatedMesh* pAM = 0;
if ( 0 != mesh->getMeshBufferCount() )
{
mesh->recalculateBoundingBox();
pAM = new SAnimatedMesh();
pAM->Type = EAMT_OBJ;
pAM->addMesh(mesh);
pAM->recalculateBoundingBox();
}
mesh->drop();
return pAM;
}
示例4: sizeof
//.........这里部分代码省略.........
const core::dimension2d<u32> lmapsize(lightmapWidth, lightmapHeight);
bool oldMipMapState = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
video::CImage tmpImage(video::ECF_R8G8B8, lmapsize);
for (i = 1; i < (header.numLightmaps + 1); ++i)
{
core::stringc lightmapname = file->getFileName();
lightmapname += ".lightmap.";
lightmapname += (int)i;
const octLightmap* lm = &lightmaps[i-1];
for (u32 x=0; x<lightmapWidth; ++x)
{
for (u32 y=0; y<lightmapHeight; ++y)
{
tmpImage.setPixel(x, y,
video::SColor(255,
lm->data[x][y][2],
lm->data[x][y][1],
lm->data[x][y][0]));
}
}
lig[i] = SceneManager->getVideoDriver()->addTexture(lightmapname.c_str(), &tmpImage);
}
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
// Free stuff
delete [] verts;
delete [] faces;
delete [] textures;
delete [] lightmaps;
delete [] lights;
// attach materials
for (i = 0; i < header.numLightmaps + 1; i++)
{
for (u32 j = 0; j < header.numTextures + 1; j++)
{
u32 mb = i * (header.numTextures + 1) + j;
SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(mb);
meshBuffer->Material.setTexture(0, tex[j]);
meshBuffer->Material.setTexture(1, lig[i]);
if (meshBuffer->Material.getTexture(0) == 0)
{
// This material has no texture, so we'll just show the lightmap if there is one.
// We swapped the texture coordinates earlier.
meshBuffer->Material.setTexture(0, meshBuffer->Material.getTexture(1));
meshBuffer->Material.setTexture(1, 0);
}
if (meshBuffer->Material.getTexture(1) == 0)
{
// If there is only one texture, it should be solid and lit.
// Among other things, this way you can preview OCT lights.
meshBuffer->Material.MaterialType = video::EMT_SOLID;
meshBuffer->Material.Lighting = true;
}
}
}
// delete all buffers without geometry in it.
i = 0;
while(i < Mesh->MeshBuffers.size())
{
if (Mesh->MeshBuffers[i]->getVertexCount() == 0 ||
Mesh->MeshBuffers[i]->getIndexCount() == 0 ||
Mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
{
// Meshbuffer is empty -- drop it
Mesh->MeshBuffers[i]->drop();
Mesh->MeshBuffers.erase(i);
}
else
{
++i;
}
}
// create bounding box
for (i = 0; i < Mesh->MeshBuffers.size(); ++i)
{
Mesh->MeshBuffers[i]->recalculateBoundingBox();
}
Mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_OCT;
AMesh->addMesh(Mesh);
AMesh->recalculateBoundingBox();
Mesh->drop();
return AMesh;
}
示例5: GLlink
//.........这里部分代码省略.........
normal.X = normals[p];
normal.Y = -normals[p+1]; //left-handed->right-handed
normal.Z = normals[p+2];
} else {
normal.X = 0;
normal.Y = 0;
normal.Z = 1;
}
}
for(int k=0; k < 3; ++k) {
long orgVertexIndex = si.triangles[j * 3 + k];
if (ai.normalPerVertex) {
int p;
if (normalIndices.length()) {
p = normalIndices[j*3+k]*3;
} else {
p = orgVertexIndex*3;
}
normal.X = normals[p];
normal.Y = -normals[p+1]; //left-handed -> right-handed
normal.Z = normals[p+2];
}
int p = orgVertexIndex * 3;
vertex.X = scale.X*vertices[p];
vertex.Y = -scale.Y*vertices[p+1]; // left-handed -> right-handed
vertex.Z = scale.Z*vertices[p+2];
//std::cout << vertices[p] <<"," << vertices[p+1] << "," << vertices[p+2] << std::endl;
vector2df texc;
if (textureCoordinate) {
texc.X = textureCoordinate[ai.textureCoordIndices[j*3+k]*2];
texc.Y = textureCoordinate[ai.textureCoordIndices[j*3+k]*2+1];
}
// redundant vertices
mb->Vertices.push_back(video::S3DVertex(vertex,normal,color, texc));
}
mb->Indices.push_back(vCount);
mb->Indices.push_back(vCount+2);
mb->Indices.push_back(vCount+1);
vCount += 3;
}
mesh->getMeshBuffer(0)->recalculateBoundingBox();
// Create the Animated mesh if there's anything in the mesh
SAnimatedMesh* pAM = 0;
if ( 0 != mesh->getMeshBufferCount() )
{
mesh->recalculateBoundingBox();
pAM = new SAnimatedMesh();
pAM->Type = EAMT_OBJ;
pAM->addMesh(mesh);
pAM->recalculateBoundingBox();
}
mesh->drop();
vector3df noscale(1,1,1);
IMeshSceneNode *node
= i_mgr->addMeshSceneNode(mesh, this, -1,
pos,
rpy,
noscale);
if (ai.textureIndex >= 0) {
const TextureInfo& ti = txs[ai.textureIndex];
//std::cout << "url:" << ti.url << std::endl;
video::IVideoDriver* driver = i_mgr->getVideoDriver();
const char *path = ti.url;
SMaterial& mat = node->getMaterial(0);
ITexture *texture = driver->getTexture(path);
mat.setTexture( 0, texture);
}
}
const SensorInfoSequence& sensors = i_li.sensors;
for (unsigned int i=0; i<sensors.length(); i++) {
const SensorInfo& si = sensors[i];
std::string type(si.type);
if (type == "Vision") {
//std::cout << si.name << std::endl;
ISceneNode *camera = i_mgr->addEmptySceneNode(this);
camera->setName(si.name);
camera->setPosition(vector3df( si.translation[0],
-si.translation[1],
si.translation[2]));
Vector3 axis(si.rotation[0],
si.rotation[1],
si.rotation[2]);
Matrix33 R;
hrp::calcRodrigues(R, axis, si.rotation[3]);
Vector3 rpy(rpyFromRot(R));
camera->setRotation(vector3df(-180/M_PI*rpy[0],
180/M_PI*rpy[1],
-180/M_PI*rpy[2]));
m_cameraInfos.push_back(new GLcamera(si, camera));
}
}
}
示例6: sizeof
IAnimatedMesh* CLMTSMeshFileLoader::createMesh(irr::io::IReadFile* file) {
u32 i;
u32 id;
// HEADER
file->read(&Header, sizeof(SLMTSHeader));
if (Header.MagicID != 0x53544D4C) { // "LMTS"
LMTS_LOG("LMTS ERROR: wrong header magic id!", ELL_ERROR);
return 0;
}
// TEXTURES
file->read(&id, sizeof(u32));
if (id != 0x54584554) { // "TEXT"
LMTS_LOG("LMTS ERROR: wrong texture magic id!", ELL_ERROR);
return 0;
}
Textures = new SLMTSTextureInfoEntry[Header.TextureCount];
TextureIDs = new u16[Header.TextureCount];
NumLightMaps = NumTextures = 0;
for (i=0; i<Header.TextureCount; i++) {
file->read(&Textures[i], sizeof(SLMTSTextureInfoEntry));
if (Textures[i].Flags & 1) {
TextureIDs[i] = NumLightMaps;
NumLightMaps++;
} else {
TextureIDs[i] = NumTextures;
NumTextures++;
}
}
// SUBSETS
file->read(&id, sizeof(u32));
if (id != 0x53425553) { // "SUBS"
LMTS_LOG("LMTS ERROR: wrong subset magic id!", ELL_ERROR);
cleanup();
return 0;
}
Subsets = new SLMTSSubsetInfoEntry[Header.SubsetCount];
for (i=0; i<Header.SubsetCount; i++) {
file->read(&Subsets[i], sizeof(SLMTSSubsetInfoEntry));
}
// TRIANGLES
file->read(&id, sizeof(u32));
if (id != 0x53495254) { // "TRIS"
LMTS_LOG("LMTS ERROR: wrong triangle magic id!", ELL_ERROR);
cleanup();
return 0;
}
Triangles = new SLMTSTriangleDataEntry[(Header.TriangleCount*3)];
for (i=0; i<(Header.TriangleCount*3); i++) {
file->read(&Triangles[i], sizeof(SLMTSTriangleDataEntry));
}
/////////////////////////////////////////////////////////////////
constructMesh();
loadTextures();
cleanup();
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_LMTS; // not unknown to irrlicht anymore
am->addMesh(Mesh);
am->recalculateBoundingBox();
Mesh->drop();
Mesh = 0;
return am;
}
示例7: buildMesh
static IAnimatedMesh* buildMesh(
mqo::Loader &loader, video::IVideoDriver *driver)
{
int vertexCount=0;
int triangleCount=0;
int qudrangleCount=0;
int originalVertexCount=0;
// convert to irrlicht mesh.
// mqo is shared vertex that has different uv (and normal).
// therefore, the indexed array is expanded here.
//
// index array is [0, 1, 2, 3, 4, 5...]
SMesh *mesh=new SMesh;
TEXTURE_MAP texture_map;
for(auto it=loader.objects.begin(); it!=loader.objects.end(); ++it){
mqo::Object &o=*it;
////////////////////////////////////////////////////////////
// each mqo object
////////////////////////////////////////////////////////////
originalVertexCount+=o.vertices.size();
std::map<int, SMeshBuffer*> mesh_map;
for(auto it=o.faces.begin(); it!=o.faces.end(); ++it){
mqo::Face &f=*it;
////////////////////////////////////////////////////////////
// each mqo face
////////////////////////////////////////////////////////////
// split by material
int material_index=f.material_index;
std::map<int, SMeshBuffer*>::iterator found=
mesh_map.find(material_index);
SMeshBuffer *meshBuffer=0;
if(found==mesh_map.end()){
// not found. new meshBuffer.
meshBuffer=createMeshBuffer(
loader, material_index, texture_map, driver);
mesh_map.insert(std::make_pair(material_index, meshBuffer));
mesh->MeshBuffers.push_back(meshBuffer);
}
else{
// use found meshBuffer.
meshBuffer=found->second;
}
// material
mqo::Material &m=loader.materials[material_index];
// append face
switch(f.index_count)
{
case 3:
// triangle
push_vertex(meshBuffer, o.vertices[f.indices[0]], f.uv[0],
m.vcol ? f.color[0] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[1]], f.uv[1],
m.vcol ? f.color[1] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[2]], f.uv[2],
m.vcol ? f.color[2] : m.color);
vertexCount+=3;
triangleCount+=1;
break;
case 4:
// qudrangle
// triangle 0
push_vertex(meshBuffer, o.vertices[f.indices[0]], f.uv[0],
m.vcol ? f.color[0] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[1]], f.uv[1],
m.vcol ? f.color[1] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[2]], f.uv[2],
m.vcol ? f.color[2] : m.color);
// triangle 1
push_vertex(meshBuffer, o.vertices[f.indices[2]], f.uv[2],
m.vcol ? f.color[2] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[3]], f.uv[3],
m.vcol ? f.color[3] : m.color);
push_vertex(meshBuffer, o.vertices[f.indices[0]], f.uv[0],
m.vcol ? f.color[0] : m.color);
vertexCount+=6;
triangleCount+=2;
qudrangleCount+=1;
break;
}
}
}
// finalize
mesh->recalculateBoundingBox();
SAnimatedMesh *animMesh = new SAnimatedMesh();
animMesh->Type = EAMT_UNKNOWN;
animMesh->recalculateBoundingBox();
animMesh->addMesh(mesh);
mesh->drop();
// summary
std::cout
<< originalVertexCount << " vertices"
<< " is expand to " << vertexCount << " vertices" << std::endl
<< triangleCount << " triangles ("
<< qudrangleCount << "quadrangles)" << std::endl
//.........这里部分代码省略.........
示例8: sizeof
//.........这里部分代码省略.........
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;
}
示例9: LoadFromFile
//.........这里部分代码省略.........
//if texture is present mirror vertically owing to DeleD representation
if (tex && header.dmfVersion<1.1)
{
const core::dimension2d<u32> texsize = tex->getSize();
void* pp = tex->lock();
if (pp)
{
const video::ECOLOR_FORMAT format = tex->getColorFormat();
if (format == video::ECF_A1R5G5B5)
{
s16* p = (s16*)pp;
s16 tmp=0;
for (u32 x=0; x<texsize.Width; x++)
for (u32 y=0; y<texsize.Height/2; y++)
{
tmp=p[y*texsize.Width + x];
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
}
}
else
if (format == video::ECF_A8R8G8B8)
{
s32* p = (s32*)pp;
s32 tmp=0;
for (u32 x=0; x<texsize.Width; x++)
for (u32 y=0; y<texsize.Height/2; y++)
{
tmp=p[y*texsize.Width + x];
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
}
}
}
tex->unlock();
tex->regenerateMipMapLevels();
}
//if lightmap is present mirror vertically owing to DeleD rapresentation
if (lig && header.dmfVersion<1.1)
{
const core::dimension2d<u32> ligsize=lig->getSize();
void* pp = lig->lock();
if (pp)
{
video::ECOLOR_FORMAT format = lig->getColorFormat();
if (format == video::ECF_A1R5G5B5)
{
s16* p = (s16*)pp;
s16 tmp=0;
for (u32 x=0; x<ligsize.Width; x++)
{
for (u32 y=0; y<ligsize.Height/2; y++)
{
tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
}
}
}
else if (format == video::ECF_A8R8G8B8)
{
s32* p = (s32*)pp;
s32 tmp=0;
for (u32 x=0; x<ligsize.Width; x++)
{
for (u32 y=0; y<ligsize.Height/2; y++)
{
tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
}
}
}
}
lig->unlock();
lig->regenerateMipMapLevels();
}
mat.setTexture(0, tex);
mat.setTexture(1, lig);
}
}
// create bounding box
for (i = 0; i < mesh->MeshBuffers.size(); ++i)
{
mesh->MeshBuffers[i]->recalculateBoundingBox();
}
mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_UNKNOWN;
AMesh->addMesh(mesh);
AMesh->recalculateBoundingBox();
mesh->drop();
return AMesh;
}
示例10: 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;
}
示例11: SMesh
//.........这里部分代码省略.........
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;
}
示例12: sizeof
//.........这里部分代码省略.........
{
s32* p = (s32*)pp;
octLightmap* lm;
lm = &lightmaps[i-1];
for (u32 x=0; x<lightmapWidth; ++x)
for (u32 y=0; y<lightmapHeight; ++y)
{
p[x*128 + y] = video::SColor(255,
lm->data[x][y][2],
lm->data[x][y][1],
lm->data[x][y][0]).color;
}
}
else
os::Printer::log(
"OCTLoader: Could not create lightmap, unsupported texture format.", ELL_ERROR);
}
lig[i]->unlock();
}
else
os::Printer::log("OCTLoader: Could not create lightmap, driver created no texture.", ELL_ERROR);
}
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
// Free stuff
delete [] verts;
delete [] faces;
delete [] textures;
delete [] lightmaps;
delete [] lights;
// attach materials
for (i = 0; i < header.numLightmaps + 1; i++)
{
for (u32 j = 0; j < header.numTextures + 1; j++)
{
u32 mb = i * (header.numTextures + 1) + j;
SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(mb);
meshBuffer->Material.setTexture(0, tex[j]);
meshBuffer->Material.setTexture(1, lig[i]);
if (meshBuffer->Material.getTexture(0) == 0)
{
// This material has no texture, so we'll just show the lightmap if there is one.
// We swapped the texture coordinates earlier.
meshBuffer->Material.setTexture(0, meshBuffer->Material.getTexture(1));
meshBuffer->Material.setTexture(1, 0);
}
if (meshBuffer->Material.getTexture(1) == 0)
{
// If there is only one texture, it should be solid and lit.
// Among other things, this way you can preview OCT lights.
meshBuffer->Material.MaterialType = video::EMT_SOLID;
meshBuffer->Material.Lighting = true;
}
}
}
// delete all buffers without geometry in it.
i = 0;
while(i < Mesh->MeshBuffers.size())
{
if (Mesh->MeshBuffers[i]->getVertexCount() == 0 ||
Mesh->MeshBuffers[i]->getIndexCount() == 0 ||
Mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
{
// Meshbuffer is empty -- drop it
Mesh->MeshBuffers[i]->drop();
Mesh->MeshBuffers.erase(i);
}
else
{
++i;
}
}
// create bounding box
for (i = 0; i < Mesh->MeshBuffers.size(); ++i)
{
Mesh->MeshBuffers[i]->recalculateBoundingBox();
}
Mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_OCT;
AMesh->addMesh(Mesh);
AMesh->recalculateBoundingBox();
Mesh->drop();
return AMesh;
}