Fixes. Added vsh output/fsh input hash matching.

This commit is contained in:
bkaradzic
2012-11-25 18:24:50 -08:00
parent 838de2a095
commit a3b0dde24b
103 changed files with 1610 additions and 1380 deletions

2
3rdparty/fcpp/cpp.h vendored
View File

@@ -202,7 +202,7 @@ typedef struct sizes {
*/
#ifdef nomacarg
#define cput output /* cput concatenates tokens */
#define cput generate /* cput concatenates tokens */
#else
#if COMMENT_INVISIBLE
#define cput(c) { if (c != TOK_SEP && c != COM_SEP) putchar(c); }

View File

@@ -506,7 +506,7 @@ static void _ctmMakeNormalCoordSys(CTMfloat * aNormal, CTMfloat * aBasisAxes)
x[2] = aNormal[1];
// Normalize the new X axis (note: |x[2]| = |x[0]|)
len = sqrtf(2.0 * x[0] * x[0] + x[1] * x[1]);
len = sqrtf(2.0f * x[0] * x[0] + x[1] * x[1]);
if(len > 1.0e-20f)
{
len = 1.0f / len;

View File

@@ -913,7 +913,7 @@ CTMEXPORT void CTMCALL ctmFileComment(CTMcontext aContext,
// Get length of string (if empty, do nothing)
if(!aFileComment)
return;
len = strlen(aFileComment);
len = (int)strlen(aFileComment);
if(!len)
return;
@@ -1005,7 +1005,7 @@ static _CTMfloatmap * _ctmAddFloatMap(_CTMcontext * self,
if(aName)
{
// Get length of string (if empty, do nothing)
len = strlen(aName);
len = (CTMuint)strlen(aName);
if(len)
{
// Copy the string
@@ -1024,7 +1024,7 @@ static _CTMfloatmap * _ctmAddFloatMap(_CTMcontext * self,
if(aFileName)
{
// Get length of string (if empty, do nothing)
len = strlen(aFileName);
len = (CTMuint)strlen(aFileName);
if(len)
{
// Copy the string

View File

@@ -155,7 +155,7 @@ void _ctmStreamWriteSTRING(_CTMcontext * self, const char * aValue)
// Get string length
if(aValue)
len = strlen(aValue);
len = (CTMuint)strlen(aValue);
else
len = 0;
@@ -194,7 +194,7 @@ int _ctmStreamReadPackedInts(_CTMcontext * self, CTMint * aData,
self->mError = CTM_OUT_OF_MEMORY;
return CTM_FALSE;
}
_ctmStreamRead(self, (void *) packed, packedSize);
_ctmStreamRead(self, (void *) packed, (CTMuint)packedSize);
// Allocate memory for interleaved array
tmp = (unsigned char *) malloc(aCount * aSize * 4);
@@ -374,7 +374,7 @@ int _ctmStreamReadPackedFloats(_CTMcontext * self, CTMfloat * aData,
self->mError = CTM_OUT_OF_MEMORY;
return CTM_FALSE;
}
_ctmStreamRead(self, (void *) packed, packedSize);
_ctmStreamRead(self, (void *) packed, (CTMuint)packedSize);
// Allocate memory for interleaved array
tmp = (unsigned char *) malloc(aCount * aSize * 4);

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <vector>
#include <list>
@@ -174,16 +174,16 @@ void Import_3DS(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream f(aFileName, ios::in | ios::binary);
if(f.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// Get file size
f.seekg(0, ios::end);
uint32 fileSize = f.tellg();
uint32 fileSize = (uint32)f.tellg();
f.seekg(0, ios::beg);
// Check file size (rough initial check)
if(fileSize < 6)
throw runtime_error("Invalid 3DS file format.");
throw_runtime_error("Invalid 3DS file format.");
uint16 chunk, count;
uint32 chunkLen;
@@ -192,7 +192,7 @@ void Import_3DS(const char * aFileName, Mesh * aMesh)
chunk = ReadInt16(f);
chunkLen = ReadInt32(f);
if((chunk != CHUNK_MAIN) || (chunkLen != fileSize))
throw runtime_error("Invalid 3DS file format.");
throw_runtime_error("Invalid 3DS file format.");
// Parse chunks, and store the data in a temporary list, objList...
Obj3DS * obj = 0;
@@ -287,8 +287,8 @@ void Import_3DS(const char * aFileName, Mesh * aMesh)
for(list<Obj3DS>::iterator o = objList.begin(); o != objList.end(); ++ o)
{
// Append...
uint32 idxOffset = aMesh->mIndices.size();
uint32 vertOffset = aMesh->mVertices.size();
uint32 idxOffset = (uint32)aMesh->mIndices.size();
uint32 vertOffset = (uint32)aMesh->mVertices.size();
aMesh->mIndices.resize(idxOffset + (*o).mIndices.size());
aMesh->mVertices.resize(vertOffset + (*o).mVertices.size());
if(hasUVCoords)
@@ -317,7 +317,7 @@ void Export_3DS(const char * aFileName, Mesh * aMesh, Options &aOptions)
// First, check that the mesh fits in a 3DS file (at most 65535 triangles
// and 65535 vertices are supported).
if((aMesh->mIndices.size() > (3*65535)) || (aMesh->mVertices.size() > 65535))
throw runtime_error("The mesh is too large to fit in a 3DS file.");
throw_runtime_error("The mesh is too large to fit in a 3DS file.");
// What should we export?
bool exportTexCoords = aMesh->HasTexCoords() && !aOptions.mNoTexCoords;
@@ -327,16 +327,16 @@ void Export_3DS(const char * aFileName, Mesh * aMesh, Options &aOptions)
string matName("Material0");
// Get mesh properties
uint32 triCount = aMesh->mIndices.size() / 3;
uint32 vertCount = aMesh->mVertices.size();
uint32 triCount = (uint32)(aMesh->mIndices.size() / 3);
uint32 vertCount = (uint32)aMesh->mVertices.size();
// Calculate the material chunk size
uint32 materialSize = 0;
uint32 matGroupSize = 0;
if(exportTexCoords && aMesh->mTexFileName.size() > 0)
{
materialSize += 24 + matName.size() + 1 + aMesh->mTexFileName.size() + 1;
matGroupSize += 8 + matName.size() + 1 + 2 * triCount;
materialSize += 24 + (uint32)matName.size() + 1 + (uint32)aMesh->mTexFileName.size() + 1;
matGroupSize += 8 + (uint32)matName.size() + 1 + 2 * triCount;
}
// Calculate the mesh chunk size
@@ -345,12 +345,12 @@ void Export_3DS(const char * aFileName, Mesh * aMesh, Options &aOptions)
triMeshSize += 8 + 8 * vertCount;
// Calculate the total file size
uint32 fileSize = 38 + objName.size() + 1 + materialSize + triMeshSize;
uint32 fileSize = 38 + (uint32)objName.size() + 1 + materialSize + triMeshSize;
// Open the output file
ofstream f(aFileName, ios::out | ios::binary);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// Write file header
WriteInt16(f, CHUNK_MAIN);
@@ -361,7 +361,7 @@ void Export_3DS(const char * aFileName, Mesh * aMesh, Options &aOptions)
// 3D Edit chunk
WriteInt16(f, CHUNK_3DEDIT);
WriteInt32(f, 16 + materialSize + objName.size() + 1 + triMeshSize);
WriteInt32(f, 16 + materialSize + (uint32)objName.size() + 1 + triMeshSize);
WriteInt16(f, CHUNK_MESH_VERSION);
WriteInt32(f, 6 + 4);
WriteInt32(f, 0x00000003);
@@ -372,19 +372,19 @@ void Export_3DS(const char * aFileName, Mesh * aMesh, Options &aOptions)
WriteInt16(f, CHUNK_MAT_ENTRY);
WriteInt32(f, materialSize);
WriteInt16(f, CHUNK_MAT_NAME);
WriteInt32(f, 6 + matName.size() + 1);
f.write(matName.c_str(), matName.size() + 1);
WriteInt32(f, 6 + (uint32)matName.size() + 1);
f.write(matName.c_str(), (uint32)matName.size() + 1);
WriteInt16(f, CHUNK_MAT_TEXMAP);
WriteInt32(f, 12 + aMesh->mTexFileName.size() + 1);
WriteInt32(f, 12 + (uint32)aMesh->mTexFileName.size() + 1);
WriteInt16(f, CHUNK_MAT_MAPNAME);
WriteInt32(f, 6 + aMesh->mTexFileName.size() + 1);
f.write(aMesh->mTexFileName.c_str(), aMesh->mTexFileName.size() + 1);
WriteInt32(f, 6 + (uint32)aMesh->mTexFileName.size() + 1);
f.write(aMesh->mTexFileName.c_str(), (uint32)aMesh->mTexFileName.size() + 1);
}
// Object chunk
WriteInt16(f, CHUNK_OBJECT);
WriteInt32(f, 6 + objName.size() + 1 + triMeshSize);
f.write(objName.c_str(), objName.size() + 1);
WriteInt32(f, 6 + (uint32)objName.size() + 1 + triMeshSize);
f.write(objName.c_str(), (uint32)objName.size() + 1);
// Triangle Mesh chunk
WriteInt16(f, CHUNK_TRIMESH);

View File

@@ -30,6 +30,8 @@
#include <string>
void throw_runtime_error(std::string str);
// Convert a string to upper case.
std::string UpperCase(const std::string &aString);

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <string>
#include <sstream>
#include "convoptions.h"
@@ -106,7 +106,7 @@ void Options::GetFromArgs(int argc, char **argv, int aStartIdx)
else if(upaxis == string("-Z"))
mUpAxis = uaNZ;
else
throw runtime_error("Invalid up axis (use X, Y, Z, -X, -Y or -Z).");
throw_runtime_error("Invalid up axis (use X, Y, Z, -X, -Y or -Z).");
}
else if(cmd == string("--flip"))
{
@@ -139,13 +139,13 @@ void Options::GetFromArgs(int argc, char **argv, int aStartIdx)
else if(method == string("MG2"))
mMethod = CTM_METHOD_MG2;
else
throw runtime_error("Invalid method (use RAW, MG1 or MG2).");
throw_runtime_error("Invalid method (use RAW, MG1 or MG2).");
}
else if((cmd == string("--level")) && (i < (argc - 1)))
{
CTMint val = GetIntArg(argv[i + 1]);
if( (val < 0) || (val > 9) )
throw runtime_error("Invalid compression level (it must be in the range 0 - 9).");
throw_runtime_error("Invalid compression level (it must be in the range 0 - 9).");
mLevel = CTMuint(val);
++ i;
}
@@ -185,6 +185,6 @@ void Options::GetFromArgs(int argc, char **argv, int aStartIdx)
++ i;
}
else
throw runtime_error(string("Invalid argument: ") + cmd);
throw_runtime_error(string("Invalid argument: ") + cmd);
}
}

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <openctm.h>
#include "ctm.h"
@@ -123,8 +123,8 @@ void Export_CTM(const char * aFileName, Mesh * aMesh, Options &aOptions)
CTMfloat * normals = 0;
if(aMesh->HasNormals() && !aOptions.mNoNormals)
normals = &aMesh->mNormals[0].x;
ctm.DefineMesh((CTMfloat *) &aMesh->mVertices[0].x, aMesh->mVertices.size(),
(const CTMuint*) &aMesh->mIndices[0], aMesh->mIndices.size() / 3,
ctm.DefineMesh((CTMfloat *) &aMesh->mVertices[0].x, (CTMuint)aMesh->mVertices.size(),
(const CTMuint*) &aMesh->mIndices[0], (CTMuint)aMesh->mIndices.size() / 3,
normals);
// Define texture coordinates

View File

@@ -27,7 +27,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <vector>
#include <iostream>
#include <list>
@@ -113,7 +113,7 @@ static void PreProcessMesh(Mesh &aMesh, Options &aOptions)
// Flip trianlges?
if(aOptions.mFlipTriangles)
{
CTMuint triCount = aMesh.mIndices.size() / 3;
CTMuint triCount = (CTMuint)(aMesh.mIndices.size() / 3);
for(CTMuint i = 0; i < triCount; ++ i)
{
CTMuint tmp = aMesh.mIndices[i * 3];
@@ -131,6 +131,11 @@ static void PreProcessMesh(Mesh &aMesh, Options &aOptions)
cout << 1000.0 * dt << " ms" << endl;
}
void throw_runtime_error(std::string str)
{
cout << "Error: " << str << endl;
abort();
}
//-----------------------------------------------------------------------------
// main()
@@ -141,94 +146,84 @@ int main(int argc, char ** argv)
Options opt;
string inFile;
string outFile;
try
{
if(argc < 3)
throw runtime_error("Too few arguments.");
inFile = string(argv[1]);
outFile = string(argv[2]);
opt.GetFromArgs(argc, argv, 3);
}
catch(exception &e)
{
cout << "Error: " << e.what() << endl << endl;
cout << "Usage: " << argv[0] << " infile outfile [options]" << endl << endl;
cout << "Options:" << endl;
cout << endl << " Data manipulation (all formats)" << endl;
cout << " --scale arg Scale the mesh by a scalar factor." << endl;
cout << " --upaxis arg Set up axis (X, Y, Z, -X, -Y, -Z). If != Z, the mesh will" << endl;
cout << " be flipped." << endl;
cout << " --flip Flip triangle orientation." << endl;
cout << " --calc-normals If the source file does not contain any normals, calculate" << endl;
cout << " them." << endl;
cout << " --no-normals Do not export normals." << endl;
cout << " --no-texcoords Do not export texture coordinates." << endl;
cout << " --no-colors Do not export vertex colors." << endl;
cout << endl << " OpenCTM output" << endl;
cout << " --method arg Select compression method (RAW, MG1, MG2)" << endl;
cout << " --level arg Set the compression level (0 - 9)" << endl;
cout << endl << " OpenCTM MG2 method" << endl;
cout << " --vprec arg Set vertex precision" << endl;
cout << " --vprecrel arg Set vertex precision, relative method" << endl;
cout << " --nprec arg Set normal precision" << endl;
cout << " --tprec arg Set texture map precision" << endl;
cout << " --cprec arg Set color precision" << endl;
cout << endl << " Miscellaneous" << endl;
cout << " --comment arg Set the file comment (default is to use the comment" << endl;
cout << " from the input file, if any)." << endl;
cout << " --texfile arg Set the texture file name reference for the texture" << endl;
cout << " (default is to use the texture file name reference" << endl;
cout << " from the input file, if any)." << endl;
// Show supported formats
cout << endl << "Supported file formats:" << endl << endl;
list<string> formatList;
SupportedFormats(formatList);
for(list<string>::iterator i = formatList.begin(); i != formatList.end(); ++ i)
cout << " " << (*i) << endl;
cout << endl;
if(argc < 3)
{
cout << "Error: Too few arguments." << endl << endl;
cout << "Usage: " << argv[0] << " infile outfile [options]" << endl << endl;
cout << "Options:" << endl;
cout << endl << " Data manipulation (all formats)" << endl;
cout << " --scale arg Scale the mesh by a scalar factor." << endl;
cout << " --upaxis arg Set up axis (X, Y, Z, -X, -Y, -Z). If != Z, the mesh will" << endl;
cout << " be flipped." << endl;
cout << " --flip Flip triangle orientation." << endl;
cout << " --calc-normals If the source file does not contain any normals, calculate" << endl;
cout << " them." << endl;
cout << " --no-normals Do not export normals." << endl;
cout << " --no-texcoords Do not export texture coordinates." << endl;
cout << " --no-colors Do not export vertex colors." << endl;
cout << endl << " OpenCTM output" << endl;
cout << " --method arg Select compression method (RAW, MG1, MG2)" << endl;
cout << " --level arg Set the compression level (0 - 9)" << endl;
cout << endl << " OpenCTM MG2 method" << endl;
cout << " --vprec arg Set vertex precision" << endl;
cout << " --vprecrel arg Set vertex precision, relative method" << endl;
cout << " --nprec arg Set normal precision" << endl;
cout << " --tprec arg Set texture map precision" << endl;
cout << " --cprec arg Set color precision" << endl;
cout << endl << " Miscellaneous" << endl;
cout << " --comment arg Set the file comment (default is to use the comment" << endl;
cout << " from the input file, if any)." << endl;
cout << " --texfile arg Set the texture file name reference for the texture" << endl;
cout << " (default is to use the texture file name reference" << endl;
cout << " from the input file, if any)." << endl;
return 0;
// Show supported formats
cout << endl << "Supported file formats:" << endl << endl;
list<string> formatList;
SupportedFormats(formatList);
for(list<string>::iterator i = formatList.begin(); i != formatList.end(); ++ i)
cout << " " << (*i) << endl;
cout << endl;
return 0;
}
try
{
// Define mesh
Mesh mesh;
inFile = string(argv[1]);
outFile = string(argv[2]);
opt.GetFromArgs(argc, argv, 3);
// Create a timer instance
SysTimer timer;
double dt;
// Define mesh
Mesh mesh;
// Load input file
cout << "Loading " << inFile << "... " << flush;
timer.Push();
ImportMesh(inFile.c_str(), &mesh);
dt = timer.PopDelta();
cout << 1000.0 * dt << " ms" << endl;
// Create a timer instance
SysTimer timer;
double dt;
// Manipulate the mesh
PreProcessMesh(mesh, opt);
// Load input file
cout << "Loading " << inFile << "... " << flush;
timer.Push();
ImportMesh(inFile.c_str(), &mesh);
dt = timer.PopDelta();
cout << 1000.0 * dt << " ms" << endl;
// Override comment?
if(opt.mComment.size() > 0)
mesh.mComment = opt.mComment;
// Manipulate the mesh
PreProcessMesh(mesh, opt);
// Override texture file name?
if(opt.mTexFileName.size() > 0)
mesh.mTexFileName = opt.mTexFileName;
// Override comment?
if(opt.mComment.size() > 0)
mesh.mComment = opt.mComment;
// Save output file
cout << "Saving " << outFile << "... " << flush;
timer.Push();
ExportMesh(outFile.c_str(), &mesh, opt);
dt = timer.PopDelta();
cout << 1000.0 * dt << " ms" << endl;
}
catch(exception &e)
{
cout << "Error: " << e.what() << endl;
}
// Override texture file name?
if(opt.mTexFileName.size() > 0)
mesh.mTexFileName = opt.mTexFileName;
// Save output file
cout << "Saving " << outFile << "... " << flush;
timer.Push();
ExportMesh(outFile.c_str(), &mesh, opt);
dt = timer.PopDelta();
cout << 1000.0 * dt << " ms" << endl;
return 0;
}

View File

@@ -26,7 +26,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <sstream>
#include <vector>
@@ -454,7 +454,7 @@ void Import_DAE(const char * aFileName, Mesh * aMesh)
aMesh->mTexCoords.resize(texcoordOffset );
for(size_t i = 0; i < indexVector.size(); ++i)
aMesh->mIndices[indicesOff + i] = indexVector[i];
aMesh->mIndices[indicesOff + i] = (unsigned int)indexVector[i];
for(size_t i = 0; i < vertVector.size(); ++i)
aMesh->mVertices[vertexOff + i] = vertVector[i];
@@ -469,7 +469,7 @@ void Import_DAE(const char * aFileName, Mesh * aMesh)
}
}
else
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
}
/// Dump a float array to an XML text node.
@@ -563,7 +563,7 @@ void Export_DAE(const char * aFileName, Mesh * aMesh, Options &aOptions)
source_position->LinkEndChild(positions_array);
positions_array->SetAttribute("id", "Mesh-1-positions-array");
positions_array->SetAttribute("count", int(aMesh->mVertices.size() * 3));
FloatArrayToXML(positions_array, &aMesh->mVertices[0].x, aMesh->mVertices.size() * 3);
FloatArrayToXML(positions_array, &aMesh->mVertices[0].x, (unsigned int)aMesh->mVertices.size() * 3);
TiXmlElement * positions_technique = new TiXmlElement("technique_common");
source_position->LinkEndChild(positions_technique);
TiXmlElement * positions_technique_accessor = new TiXmlElement("accessor");
@@ -596,7 +596,7 @@ void Export_DAE(const char * aFileName, Mesh * aMesh, Options &aOptions)
source_normal->LinkEndChild(normals_array);
normals_array->SetAttribute("id", "Mesh-1-normals-array");
normals_array->SetAttribute("count", int(aMesh->mVertices.size() * 3));
FloatArrayToXML(normals_array, &aMesh->mNormals[0].x, aMesh->mNormals.size() * 3);
FloatArrayToXML(normals_array, &aMesh->mNormals[0].x, (unsigned int)aMesh->mNormals.size() * 3);
TiXmlElement * normals_technique = new TiXmlElement("technique_common");
source_normal->LinkEndChild(normals_technique);
TiXmlElement * normals_technique_accessor = new TiXmlElement("accessor");
@@ -630,7 +630,7 @@ void Export_DAE(const char * aFileName, Mesh * aMesh, Options &aOptions)
source_map1->LinkEndChild(map1_array);
map1_array->SetAttribute("id", "Mesh-1-map1-array");
map1_array->SetAttribute("count", int(aMesh->mVertices.size() * 3));
FloatArrayToXML(map1_array, &aMesh->mTexCoords[0].u, aMesh->mTexCoords.size() * 2);
FloatArrayToXML(map1_array, &aMesh->mTexCoords[0].u, (unsigned int)aMesh->mTexCoords.size() * 2);
TiXmlElement * map1_technique = new TiXmlElement("technique_common");
source_map1->LinkEndChild(map1_technique);
TiXmlElement * map1_technique_accessor = new TiXmlElement("accessor");
@@ -721,5 +721,5 @@ void Export_DAE(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Save the XML document to a file
xmlDoc.SaveFile(aFileName);
if(xmlDoc.Error())
throw runtime_error(string(xmlDoc.ErrorDesc()));
throw_runtime_error(string(xmlDoc.ErrorDesc()));
}

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <cstring>
#include <string>
@@ -216,14 +216,14 @@ static void WriteVEC12(ostream &aStream, Vector3 aValue)
/// Write a string to a stream (no zero termination).
static void WriteString(ostream &aStream, const char * aString)
{
int len = strlen(aString);
int len = (int)strlen(aString);
aStream.write(aString, len);
}
/// Write a zero terminated string to a stream.
static void WriteStringZ(ostream &aStream, const char * aString)
{
int len = strlen(aString) + 1;
int len = (int)strlen(aString) + 1;
aStream.write(aString, len);
if(len & 1)
{
@@ -262,8 +262,8 @@ static uint32 CalcPOLSSize(Mesh * aMesh)
/// account, but exclude the name string (at least two bytes)...
static uint32 CalcVMAPSize(Mesh * aMesh, uint32 aDimension)
{
uint32 size = 6 + aMesh->mVertices.size() * (2 + 4 * aDimension);
uint32 maxIdx = aMesh->mVertices.size() - 1;
uint32 size = (uint32)(6 + aMesh->mVertices.size() * (2 + 4 * aDimension));
uint32 maxIdx = (uint32)(aMesh->mVertices.size() - 1);
if(maxIdx >= 0x0000ff00)
size += (maxIdx - 0x0000feff) * 2;
return size;
@@ -280,14 +280,14 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream f(aFileName, ios::in | ios::binary);
if(f.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// File header
if(ReadString(f, 4) != string("FORM"))
throw runtime_error("Not a valid LWO file (missing FORM chunk).");
throw_runtime_error("Not a valid LWO file (missing FORM chunk).");
uint32 fileSize = ReadU4(f);
if(ReadString(f, 4) != string("LWO2"))
throw runtime_error("Not a valid LWO file (not LWO2 format).");
throw_runtime_error("Not a valid LWO file (not LWO2 format).");
// Start with an empty mesh
aMesh->Clear();
@@ -333,7 +333,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
// Check point count
uint32 newPoints = chunkSize / 12;
if((newPoints * 12) != chunkSize)
throw runtime_error("Not a valid LWO file (invalid PNTS chunk).");
throw_runtime_error("Not a valid LWO file (invalid PNTS chunk).");
// Read points (relative to current pivot point)
aMesh->mVertices.resize(pointCount + newPoints);
@@ -347,7 +347,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
{
// POLS before PNTS?
if(!havePoints)
throw runtime_error("Not a valid LWO file (POLS chunk before PNTS chunk).");
throw_runtime_error("Not a valid LWO file (POLS chunk before PNTS chunk).");
// Check that we have a FACE or PTCH descriptor.
string type = ReadString(f, 4);
@@ -424,7 +424,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
if((type == string("RGB ")) || (type == string("RGBA")))
{
// Resize the mesh colors array
uint32 oldSize = aMesh->mColors.size();
uint32 oldSize = (uint32)aMesh->mColors.size();
aMesh->mColors.resize(pointCount);
for(uint32 i = oldSize; i < pointCount; ++ i)
aMesh->mColors[i] = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
@@ -456,7 +456,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
else if((type == string("TXUV")))
{
// Resize the mesh UV array
uint32 oldSize = aMesh->mTexCoords.size();
uint32 oldSize = (uint32)aMesh->mTexCoords.size();
aMesh->mTexCoords.resize(pointCount);
for(uint32 i = oldSize; i < pointCount; ++ i)
aMesh->mTexCoords[i] = Vector2(0.0f, 0.0f);
@@ -491,7 +491,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
// Post-adjustment: color array (if any)
if((aMesh->mColors.size() > 0) && (aMesh->mColors.size() < pointCount))
{
uint32 oldSize = aMesh->mColors.size();
uint32 oldSize = (uint32)aMesh->mColors.size();
aMesh->mColors.resize(pointCount);
for(uint32 i = oldSize; i < pointCount; ++ i)
aMesh->mColors[i] = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
@@ -500,7 +500,7 @@ void Import_LWO(const char * aFileName, Mesh * aMesh)
// Post-adjustment: texture coordinate array (if any)
if((aMesh->mTexCoords.size() > 0) && (aMesh->mTexCoords.size() < pointCount))
{
uint32 oldSize = aMesh->mTexCoords.size();
uint32 oldSize = (uint32)aMesh->mTexCoords.size();
aMesh->mTexCoords.resize(pointCount);
for(uint32 i = oldSize; i < pointCount; ++ i)
aMesh->mTexCoords[i] = Vector2(0.0f, 0.0f);
@@ -515,7 +515,7 @@ void Export_LWO(const char * aFileName, Mesh * aMesh, Options &aOptions)
{
// Check if we can support this mesh (too many vertices?)
if(aMesh->mVertices.size() > 0x00ffffff)
throw runtime_error("Too large mesh (not supported by the LWO file format).");
throw_runtime_error("Too large mesh (not supported by the LWO file format).");
// What should we export?
bool exportComment = (aMesh->mComment.size() > 0);
@@ -523,7 +523,7 @@ void Export_LWO(const char * aFileName, Mesh * aMesh, Options &aOptions)
bool exportColors = aMesh->HasColors() && !aOptions.mNoColors;
// Calculate the sizes of the individual chunks
uint32 textSize = aMesh->mComment.size() + 1;
uint32 textSize = (uint32)aMesh->mComment.size() + 1;
if(textSize & 1) ++ textSize;
uint32 tagsSize = 8;
uint32 layrSize = 24;
@@ -548,7 +548,7 @@ void Export_LWO(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out | ios::binary);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// File header
WriteString(f, "FORM");

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <openctm.h>
#include <cmath>
#include "mesh.h"
@@ -73,8 +73,8 @@ void Mesh::Clear()
/// Automatic detection of the optimal normal calculation method
Mesh::NormalCalcAlgo Mesh::DetectNormalCalculationMethod()
{
unsigned int triCount = mIndices.size() / 3;
unsigned int vertexCount = mVertices.size();
unsigned int triCount = (unsigned int)(mIndices.size() / 3);
unsigned int vertexCount = (unsigned int)(mVertices.size() );
// Calculate the mean edge length
double meanEdgeLen = 0;
@@ -169,7 +169,7 @@ void Mesh::CalculateNormals(NormalCalcAlgo aAlgo)
mNormals[i] = Vector3(0.0f, 0.0f, 0.0f);
// Calculate sum of the flat normals of the neighbouring triangles
unsigned int triCount = mIndices.size() / 3;
unsigned int triCount = (unsigned int)(mIndices.size() / 3);
for(unsigned int i = 0; i < triCount; ++ i)
{
// Calculate the weighted flat normal for this triangle

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <string>
#include <list>
#include "mesh.h"
@@ -68,7 +68,7 @@ void ImportMesh(const char * aFileName, Mesh * aMesh)
else if(fileExt == string(".WRL"))
Import_WRL(aFileName, aMesh);
else
throw runtime_error("Unknown input file extension.");
throw_runtime_error("Unknown input file extension.");
}
/// Export a mesh to a file.
@@ -94,7 +94,7 @@ void ExportMesh(const char * aFileName, Mesh * aMesh, Options &aOptions)
else if(fileExt == string(".WRL"))
Export_WRL(aFileName, aMesh, aOptions);
else
throw runtime_error("Unknown output file extension.");
throw_runtime_error("Unknown output file extension.");
}
/// Return a list of supported formats.

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <iomanip>
#include <string>
@@ -108,9 +108,9 @@ class OBJFace {
if(value > 0)
value --;
else if(value < 0)
throw runtime_error("Negative vertex references in OBJ files are not supported.");
throw_runtime_error("Negative vertex references in OBJ files are not supported.");
else
throw runtime_error("Invalid index (zero) in OBJ file.");
throw_runtime_error("Invalid index (zero) in OBJ file.");
}
n.Set(j, value);
}
@@ -150,7 +150,7 @@ void Import_OBJ(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream inFile(aFileName, ios::in);
if(inFile.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// Mesh description - parsed from the OBJ file
list<Vector3> vertices;
@@ -201,7 +201,7 @@ void Import_OBJ(const char * aFileName, Mesh * aMesh)
int triCount = 0;
for(list<OBJFace>::iterator i = faces.begin(); i != faces.end(); ++ i)
{
int nodeCount = (*i).mNodes.size();
int nodeCount = (int)((*i).mNodes.size());
if(nodeCount >= 3)
triCount += (nodeCount - 2);
}
@@ -269,7 +269,7 @@ void Export_OBJ(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// What should we export?
bool exportTexCoords = aMesh->HasTexCoords() && !aOptions.mNoTexCoords;
@@ -312,7 +312,7 @@ void Export_OBJ(const char * aFileName, Mesh * aMesh, Options &aOptions)
}
// Write faces
unsigned int triCount = aMesh->mIndices.size() / 3;
unsigned int triCount = (unsigned int)(aMesh->mIndices.size() / 3);
f << "s 1" << endl; // Put all faces in the same smoothing group
for(unsigned int i = 0; i < triCount; ++ i)
{

View File

@@ -32,7 +32,7 @@
// http://people.sc.fsu.edu/~burkardt/data/off/off.html
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <iomanip>
#include <string>
@@ -99,7 +99,7 @@ void Import_OFF(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream f(aFileName, ios::in);
if(f.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// Some state variables that we need...
unsigned int numVertices;
@@ -110,16 +110,16 @@ void Import_OFF(const char * aFileName, Mesh * aMesh)
// Read header
ReadNextLine(f, line, comment);
if(line != string("OFF"))
throw runtime_error("Not a valid OFF format file (missing OFF signature).");
throw_runtime_error("Not a valid OFF format file (missing OFF signature).");
ReadNextLine(f, line, comment);
sstr.clear();
sstr.str(line);
sstr >> numVertices;
sstr >> numFaces;
if(numVertices < 1)
throw runtime_error("Not a valid OFF format file (bad vertex count).");
throw_runtime_error("Not a valid OFF format file (bad vertex count).");
if(numFaces < 1)
throw runtime_error("Not a valid OFF format file (bad face count).");
throw_runtime_error("Not a valid OFF format file (bad face count).");
// Read vertices
aMesh->mVertices.resize(numVertices);
@@ -199,7 +199,7 @@ void Export_OFF(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// Mesh information
unsigned int numVertices = (unsigned int) aMesh->mVertices.size();

View File

@@ -26,7 +26,7 @@
//-----------------------------------------------------------------------------
#include <iostream>
#include <stdexcept>
#include "common.h"
#include <string>
#include <fstream>
#include <iomanip>
@@ -169,9 +169,9 @@ void Import_PLY(const char * aFileName, Mesh * aMesh)
// Open the PLY file
p_ply ply = ply_open(aFileName, NULL);
if(!ply)
throw runtime_error("Unable to open PLY file.");
throw_runtime_error("Unable to open PLY file.");
if(!ply_read_header(ply))
throw runtime_error("Invalid PLY file.");
throw_runtime_error("Invalid PLY file.");
// Get the file comment (if any)
bool firstComment = true;
@@ -212,7 +212,7 @@ void Import_PLY(const char * aFileName, Mesh * aMesh)
// Sanity check
if((faceCount < 1) || (vertexCount < 1))
throw runtime_error("Empty PLY mesh - invalid file format?");
throw_runtime_error("Empty PLY mesh - invalid file format?");
// Prepare the mesh
aMesh->mIndices.resize(faceCount * 3);
@@ -223,7 +223,7 @@ void Import_PLY(const char * aFileName, Mesh * aMesh)
// Read the PLY file
if(!ply_read(ply))
throw runtime_error("Unable to load PLY file.");
throw_runtime_error("Unable to load PLY file.");
// Close the PLY file
ply_close(ply);
@@ -243,7 +243,7 @@ void Export_PLY(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out | ios::binary);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// Set floating point precision
f << setprecision(8);

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <string>
#include <vector>
@@ -115,14 +115,14 @@ void Import_STL(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream f(aFileName, ios::in | ios::binary);
if(f.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// Get the file size
f.seekg(0, ios::end);
uint32 fileSize = (uint32) f.tellg();
f.seekg(0, ios::beg);
if(fileSize < 84)
throw runtime_error("Invalid format - not a valid STL file.");
throw_runtime_error("Invalid format - not a valid STL file.");
// Read header (80 character comment + triangle count)
char comment[81];
@@ -131,7 +131,7 @@ void Import_STL(const char * aFileName, Mesh * aMesh)
aMesh->mComment = string(comment);
uint32 triangleCount = ReadInt32(f);
if(fileSize != (84 + triangleCount * 50))
throw runtime_error("Invalid format - not a valid STL file.");
throw_runtime_error("Invalid format - not a valid STL file.");
if(triangleCount > 0)
{
@@ -192,7 +192,7 @@ void Export_STL(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out | ios::binary);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// Write header (80-character comment + triangle count)
char comment[80];
@@ -204,7 +204,7 @@ void Export_STL(const char * aFileName, Mesh * aMesh, Options &aOptions)
comment[i] = 0;
}
f.write(comment, 80);
uint32 triangleCount = aMesh->mIndices.size() / 3;
uint32 triangleCount = (CTMuint)(aMesh->mIndices.size() / 3);
WriteInt32(f, triangleCount);
// Write the triangle data

View File

@@ -25,7 +25,7 @@
// distribution.
//-----------------------------------------------------------------------------
#include <stdexcept>
#include "common.h"
#include <fstream>
#include <iomanip>
#include <string>
@@ -55,14 +55,14 @@ class VRMLReader {
char GetNextChar()
{
if(!mStream)
throw runtime_error("VRML input stream undefined.");
throw_runtime_error("VRML input stream undefined.");
if(mBufPos >= mBufActual)
{
mBufPos = 0;
if(!mStream->eof())
{
mStream->read(mBuffer, mBufSize);
mBufActual = mStream->gcount();
mBufActual = (int)(mStream->gcount());
}
else
mBufActual = 0;
@@ -172,7 +172,7 @@ class VRMLReader {
// Read the header
string header = GetNextLine();
if(header.substr(0, 10) != string("#VRML V2.0"))
throw runtime_error("Not a valid VRML 2.0 file.");
throw_runtime_error("Not a valid VRML 2.0 file.");
// Read the rest of the file
while(!mEndOfFile)
@@ -201,7 +201,7 @@ class VRMLReader {
void Import_WRL(const char * aFileName, Mesh * aMesh)
{
// FIXME: The import functionality has not yet been fully implemented
throw runtime_error("VRML import is not yet supported.");
throw_runtime_error("VRML import is not yet supported.");
// Clear the mesh
aMesh->Clear();
@@ -209,7 +209,7 @@ void Import_WRL(const char * aFileName, Mesh * aMesh)
// Open the input file
ifstream f(aFileName, ios::in);
if(f.fail())
throw runtime_error("Could not open input file.");
throw_runtime_error("Could not open input file.");
// Initialize the reader object
VRMLReader reader;
@@ -228,7 +228,7 @@ void Export_WRL(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Open the output file
ofstream f(aFileName, ios::out);
if(f.fail())
throw runtime_error("Could not open output file.");
throw_runtime_error("Could not open output file.");
// Set floating point precision
f << setprecision(8);
@@ -284,7 +284,7 @@ void Export_WRL(const char * aFileName, Mesh * aMesh, Options &aOptions)
// Write faces
f << "\t\t\t\tcoordIndex [" << endl;
unsigned int triCount = aMesh->mIndices.size() / 3;
unsigned int triCount = (unsigned int)(aMesh->mIndices.size() / 3);
for(unsigned int i = 0; i < triCount; ++ i)
{
f << "\t\t\t\t\t" <<