Merging r6337 through r6363 from trunk to ogl-es branch

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6379 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2022-05-04 21:26:18 +00:00
parent 2d63fdba3d
commit 993f990036
28 changed files with 439 additions and 328 deletions

View File

@ -136,7 +136,8 @@ bool CB3DMeshFileLoader::load()
else
{
os::Printer::log("Unknown chunk found in mesh base - skipping");
B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length);
if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length))
return false;
B3dStack.erase(B3dStack.size()-1);
}
}
@ -232,7 +233,8 @@ bool CB3DMeshFileLoader::readChunkNODE(CSkinnedMesh::SJoint *inJoint)
else
{
os::Printer::log("Unknown chunk found in node chunk - skipping");
B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length);
if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length))
return false;
B3dStack.erase(B3dStack.size()-1);
}
}
@ -315,7 +317,8 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
else
{
os::Printer::log("Unknown chunk found in mesh - skipping");
B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length);
if (!B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length))
return false;
B3dStack.erase(B3dStack.size()-1);
}
}
@ -859,7 +862,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
while((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) //this chunk repeats
{
// This is what blitz basic calls a brush, like a Irrlicht Material
// This is what blitz basic calls a brush, like an Irrlicht material
core::stringc name;
readString(name);
@ -933,7 +936,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
}
}
//If a preceeding texture slot is empty move the others down:
//If a preceding texture slot is empty move the others down:
for (i=num_textures; i>0; --i)
{
for (u32 j=i-1; j<num_textures-1; ++j)

View File

@ -255,18 +255,36 @@ bool CB3DMeshWriter::writeMesh(io::IWriteFile* file, IMesh* const mesh, s32 flag
file->write(&i, 4);
u32 numIndices = mb->getIndexCount();
const u16 * const idx = (u16 *) mb->getIndices();
for (u32 j = 0; j < numIndices; j += 3)
if ( mb->getIndexType() == video::EIT_16BIT )
{
u32 tmp = idx[j] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
const u16 * const idx = mb->getIndices();
for (u32 j = 0; j < numIndices; j += 3)
{
u32 tmp = idx[j] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
tmp = idx[j + 1] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
tmp = idx[j + 1] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
tmp = idx[j + 2] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
}
tmp = idx[j + 2] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
}
}
else if ( mb->getIndexType() == video::EIT_32BIT )
{
const u32 * const idx = (const u32*) mb->getIndices();
for (u32 j = 0; j < numIndices; j += 3)
{
u32 tmp = idx[j] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
tmp = idx[j + 1] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
tmp = idx[j + 2] + currentMeshBufferIndex;
file->write(&tmp, sizeof(u32));
}
}
writeSizeFrom(file, trisSizeAdress+4, trisSizeAdress); // TRIS chunk size
currentMeshBufferIndex += mb->getVertexCount();

View File

@ -1217,7 +1217,7 @@ void CGUITable::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri
Column column;
label = "Column"; label += i; label += "name";
column.Name = core::stringw(in->getAttributeAsString(label.c_str()).c_str());
column.Name = in->getAttributeAsStringW(label.c_str());
label = "Column"; label += i; label += "width";
column.Width = in->getAttributeAsInt(label.c_str());
label = "Column"; label += i; label += "OrderingMode";
@ -1252,7 +1252,7 @@ void CGUITable::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri
Cell cell;
label = "Row"; label += i; label += "cell"; label += c; label += "text";
cell.Text = core::stringw(in->getAttributeAsString(label.c_str()).c_str());
cell.Text = in->getAttributeAsStringW(label.c_str());
breakText( cell.Text, cell.BrokenText, Columns[c].Width );
label = "Row"; label += i; label += "cell"; label += c; label += "color";
cell.Color = in->getAttributeAsColor(label.c_str());

View File

@ -821,6 +821,8 @@ void CIrrDeviceMacOSX::setResize(int width, int height)
{
NSRect driverFrame = [Window contentRectForFrameRect:[Window frame]];
getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)driverFrame.size.width, (s32)driverFrame.size.height));
DeviceWidth = (s32)driverFrame.size.width;
DeviceHeight = (s32)driverFrame.size.height;
}
else
getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height));

View File

@ -52,14 +52,14 @@ bool CMemoryReadFile::seek(long finalPos, bool relativeMovement)
{
if (relativeMovement)
{
if (Pos + finalPos > Len)
if (Pos + finalPos < 0 || Pos + finalPos > Len)
return false;
Pos += finalPos;
}
else
{
if (finalPos > Len)
if (finalPos < 0 || finalPos > Len)
return false;
Pos = finalPos;
@ -133,14 +133,14 @@ bool CMemoryWriteFile::seek(long finalPos, bool relativeMovement)
{
if (relativeMovement)
{
if (Pos + finalPos > Len)
if (Pos + finalPos < 0 || Pos + finalPos > Len)
return false;
Pos += finalPos;
}
else
{
if (finalPos > Len)
if (finalPos < 0 || finalPos > Len)
return false;
Pos = finalPos;

View File

@ -82,7 +82,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
core::array<core::vector3df, core::irrAllocatorFast<core::vector3df> > normalsBuffer(1000);
core::array<core::vector2df, core::irrAllocatorFast<core::vector2df> > textureCoordBuffer(1000);
SObjMtl * currMtl = new SObjMtl(PreferredIndexType);
SObjMtl * currMtl = new SObjMtl(getIndexTypeHint());
Materials.push_back(currMtl);
u32 smoothingGroup=0;
@ -330,19 +330,21 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
{
if ( Materials[m]->Meshbuffer->getIndexCount() > 0 )
{
if ( getIndexTypeHint() == EITH_OPTIMAL
&& Materials[m]->Meshbuffer->getVertexCount() <= 65536 )
{
Materials[m]->Meshbuffer->getIndexBuffer().setType(video::EIT_16BIT);
}
Materials[m]->Meshbuffer->recalculateBoundingBox();
if (Materials[m]->RecalculateNormals)
SceneManager->getMeshManipulator()->recalculateNormals(Materials[m]->Meshbuffer);
if (Materials[m]->Meshbuffer->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID)
{
SMesh tmp;
tmp.addMeshBuffer(Materials[m]->Meshbuffer);
IMesh* tangentMesh = SceneManager->getMeshManipulator()->createMeshWithTangents(&tmp);
mesh->addMeshBuffer(tangentMesh->getMeshBuffer(0));
tangentMesh->drop();
Materials[m]->Meshbuffer->getVertexBuffer().setType(video::EVT_TANGENTS);
}
else
mesh->addMeshBuffer( Materials[m]->Meshbuffer );
mesh->addMeshBuffer( Materials[m]->Meshbuffer );
}
}
@ -579,7 +581,7 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
c8 mtlNameBuf[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
currMaterial = new SObjMtl(PreferredIndexType);
currMaterial = new SObjMtl(getIndexTypeHint());
currMaterial->Name = mtlNameBuf;
}
break;

View File

@ -42,7 +42,9 @@ private:
struct SObjMtl
{
SObjMtl(irr::video::E_INDEX_TYPE indexType) : IndexType(indexType), Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
SObjMtl(E_INDEX_TYPE_HINT typeHint)
: IndexType(typeHint == EITH_16BIT ? video::EIT_16BIT : video::EIT_32BIT)
, Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
RecalculateNormals(false)
{
Meshbuffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, IndexType);

View File

@ -8,7 +8,8 @@
#include "CSTLMeshFileLoader.h"
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "CDynamicMeshBuffer.h"
#include "CMemoryFile.h"
#include "SAnimatedMesh.h"
#include "IReadFile.h"
#include "fast_atof.h"
@ -34,14 +35,29 @@ bool CSTLMeshFileLoader::isALoadableFileExtension(const io::path& filename) cons
//! \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)
IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* fileIn)
{
const long filesize = file->getSize();
const long filesize = fileIn->getSize();
if (filesize < 6) // we need a header
return 0;
// We copy the whole file into a memory-read file if it isn't already one.
io::CMemoryReadFile * memoryFile = 0;
if ( fileIn->getType() != io::ERFT_MEMORY_READ_FILE )
{
u8* fileBuffer = new u8[filesize];
if ( fileIn->read(fileBuffer, filesize) != (size_t)filesize )
{
delete[] fileBuffer;
return 0;
}
memoryFile = new io::CMemoryReadFile(fileBuffer, filesize, io::path(""), true); // takes over fileBuffer
}
io::IReadFile* file = memoryFile ? memoryFile : fileIn;
SMesh* mesh = new SMesh();
SMeshBuffer* meshBuffer = new SMeshBuffer();
CDynamicMeshBuffer* meshBuffer = new CDynamicMeshBuffer(video::EVT_STANDARD, video::EIT_16BIT);
IVertexBuffer& vertBuffer = meshBuffer->getVertexBuffer();
mesh->addMeshBuffer(meshBuffer);
meshBuffer->drop();
@ -49,8 +65,7 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
core::vector3df normal;
bool binary = false;
core::stringc token;
if (getNextToken(file, token) != "solid")
if (getNextToken(file) != "solid")
binary = true;
// read/skip header
u32 binFaceCount = 0;
@ -66,62 +81,64 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
goNextLine(file);
u16 attrib=0;
token.reserve(32);
Token.reserve(32);
bool failure = false;
while (file->getPos() < filesize)
{
if (!binary)
{
if (getNextToken(file, token) != "facet")
if (getNextToken(file) != "facet")
{
if (token=="endsolid")
break;
mesh->drop();
return 0;
if (Token!="endsolid")
failure = true;
break;
}
if (getNextToken(file, token) != "normal")
if (getNextToken(file) != "normal")
{
mesh->drop();
return 0;
failure = true;
break;
}
}
getNextVector(file, normal, binary);
if (!binary)
{
if (getNextToken(file, token) != "outer")
if (getNextToken(file) != "outer")
{
mesh->drop();
return 0;
failure = true;
break;
}
if (getNextToken(file, token) != "loop")
if (getNextToken(file) != "loop")
{
mesh->drop();
return 0;
failure = true;
break;
}
}
for (u32 i=0; i<3; ++i)
{
if (!binary)
{
if (getNextToken(file, token) != "vertex")
if (getNextToken(file) != "vertex")
{
mesh->drop();
return 0;
failure = true;
break;
}
}
getNextVector(file, vertex[i], binary);
}
if ( failure )
break;
if (!binary)
{
if (getNextToken(file, token) != "endloop")
if (getNextToken(file) != "endloop")
{
mesh->drop();
return 0;
failure = true;
break;
}
if (getNextToken(file, token) != "endfacet")
if (getNextToken(file) != "endfacet")
{
mesh->drop();
return 0;
failure = true;
break;
}
}
else
@ -132,41 +149,56 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
#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);
vertBuffer.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df()));
vertBuffer.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df()));
vertBuffer.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df()));
} // 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() )
if ( !failure && mesh->getMeshBufferCount() > 0 )
{
IIndexBuffer& indexBuffer = meshBuffer->getIndexBuffer();
u32 vertCount = vertBuffer.size();
if (vertCount > 65535 ) // Note 65535 instead of 65536 as it divides by 3
{
if ( getIndexTypeHint() != EITH_16BIT )
indexBuffer.setType(video::EIT_32BIT);
else
{
// Could split buffer, but probably no one really needs this anymore now with 32-bit support and necessary buffer manipulation functions are not there yet
vertCount = 65535;
}
}
indexBuffer.reallocate(vertCount);
for (u32 i=0; i<vertCount; ++i) //every vertex is unique, so we can just generate the indices
indexBuffer.push_back(i);
meshBuffer->recalculateBoundingBox();
mesh->recalculateBoundingBox();
pAM = new SAnimatedMesh();
pAM->Type = EAMT_OBJ;
pAM->Type = EAMT_STATIC;
pAM->addMesh(mesh);
pAM->recalculateBoundingBox();
}
mesh->drop();
Token.clear();
if ( memoryFile )
memoryFile->drop();
return pAM;
}
//! Read 3d vector of floats
void CSTLMeshFileLoader::getNextVector(io::IReadFile* file, core::vector3df& vec, bool binary) const
void CSTLMeshFileLoader::getNextVector(io::IReadFile* file, core::vector3df& vec, bool binary)
{
if (binary)
{
@ -182,34 +214,33 @@ void CSTLMeshFileLoader::getNextVector(io::IReadFile* file, core::vector3df& vec
else
{
goNextWord(file);
core::stringc tmp;
getNextToken(file, tmp);
core::fast_atof_move(tmp.c_str(), vec.X);
getNextToken(file, tmp);
core::fast_atof_move(tmp.c_str(), vec.Y);
getNextToken(file, tmp);
core::fast_atof_move(tmp.c_str(), vec.Z);
getNextToken(file);
core::fast_atof_move(Token.c_str(), vec.X);
getNextToken(file);
core::fast_atof_move(Token.c_str(), vec.Y);
getNextToken(file);
core::fast_atof_move(Token.c_str(), vec.Z);
}
vec.X=-vec.X;
}
//! Read next word
const core::stringc& CSTLMeshFileLoader::getNextToken(io::IReadFile* file, core::stringc& token) const
const core::stringc& CSTLMeshFileLoader::getNextToken(io::IReadFile* file)
{
goNextWord(file);
u8 c;
token = "";
Token = "";
while(file->getPos() != file->getSize())
{
file->read(&c, 1);
// found it, so leave
if (core::isspace(c))
break;
token.append(c);
Token.append(c);
}
return token;
return Token;
}

View File

@ -34,12 +34,15 @@ private:
// skips to the first non-space character available
void goNextWord(io::IReadFile* file) const;
// returns the next word
const core::stringc& getNextToken(io::IReadFile* file, core::stringc& token) const;
const core::stringc& getNextToken(io::IReadFile* file);
// skip to next printable character after the first line break
void goNextLine(io::IReadFile* file) const;
//! Read 3d vector of floats
void getNextVector(io::IReadFile* file, core::vector3df& vec, bool binary) const;
void getNextVector(io::IReadFile* file, core::vector3df& vec, bool binary);
//! Buffering last read token to avoid reallocating string all the time
core::stringc Token;
};
} // end namespace scene

View File

@ -92,17 +92,37 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, scene::IMesh* mesh, s
{
const u32 indexCount = buffer->getIndexCount();
const u16 attributes = 0;
for (u32 j=0; j<indexCount; j+=3)
if( buffer->getIndexType() == video::EIT_16BIT )
{
const core::vector3df& v1 = buffer->getPosition(buffer->getIndices()[j]);
const core::vector3df& v2 = buffer->getPosition(buffer->getIndices()[j+1]);
const core::vector3df& v3 = buffer->getPosition(buffer->getIndices()[j+2]);
const core::plane3df tmpplane(v1,v2,v3);
file->write(&tmpplane.Normal, 12);
file->write(&v1, 12);
file->write(&v2, 12);
file->write(&v3, 12);
file->write(&attributes, 2);
const u16* indices = buffer->getIndices();
for (u32 j=0; j<indexCount; j+=3)
{
const core::vector3df& v1 = buffer->getPosition(indices[j]);
const core::vector3df& v2 = buffer->getPosition(indices[j+1]);
const core::vector3df& v3 = buffer->getPosition(indices[j+2]);
const core::plane3df tmpplane(v1,v2,v3);
file->write(&tmpplane.Normal, 12);
file->write(&v1, 12);
file->write(&v2, 12);
file->write(&v3, 12);
file->write(&attributes, 2);
}
}
else if( buffer->getIndexType() == video::EIT_32BIT )
{
const u32* indices = (const u32*)buffer->getIndices();
for (u32 j=0; j<indexCount; j+=3)
{
const core::vector3df& v1 = buffer->getPosition(indices[j]);
const core::vector3df& v2 = buffer->getPosition(indices[j+1]);
const core::vector3df& v3 = buffer->getPosition(indices[j+2]);
const core::plane3df tmpplane(v1,v2,v3);
file->write(&tmpplane.Normal, 12);
file->write(&v1, 12);
file->write(&v2, 12);
file->write(&v3, 12);
file->write(&attributes, 2);
}
}
}
}
@ -127,12 +147,27 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s3
if (buffer)
{
const u32 indexCount = buffer->getIndexCount();
for (u32 j=0; j<indexCount; j+=3)
if ( buffer->getIndexType() == video::EIT_16BIT )
{
writeFace(file,
buffer->getPosition(buffer->getIndices()[j]),
buffer->getPosition(buffer->getIndices()[j+1]),
buffer->getPosition(buffer->getIndices()[j+2]));
const u16* indices = buffer->getIndices();
for (u32 j=0; j<indexCount; j+=3)
{
writeFace(file,
buffer->getPosition(indices[j]),
buffer->getPosition(indices[j+1]),
buffer->getPosition(indices[j+2]));
}
}
else if ( buffer->getIndexType() == video::EIT_32BIT )
{
const u32* indices = (const u32*)buffer->getIndices();
for (u32 j=0; j<indexCount; j+=3)
{
writeFace(file,
buffer->getPosition(indices[j]),
buffer->getPosition(indices[j+1]),
buffer->getPosition(indices[j+2]));
}
}
file->write("\n",1);
}

View File

@ -760,10 +760,12 @@ bool CXMeshFileLoader::parseDataObjectMesh(SXMesh &mesh)
// read vertices
mesh.Vertices.set_used(nVertices);
irr::video::S3DVertex vertex; // set_used doesn't call constructor, so we initalize it explicit here
vertex.Color = 0xFFFFFFFF;
for (u32 n=0; n<nVertices; ++n)
{
readVector3(mesh.Vertices[n].Pos);
mesh.Vertices[n].Color=0xFFFFFFFF;
readVector3(vertex.Pos);
mesh.Vertices[n] = vertex;
}
if (!checkForTwoFollowingSemicolons())