Clean up headers/using namespace in cel3ds
parent
ec232b7fad
commit
ef10800e7c
|
@ -7,8 +7,7 @@
|
|||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#ifndef _3DSCHUNK_H_
|
||||
#define _3DSCHUNK_H_
|
||||
#pragma once
|
||||
|
||||
enum M3DChunkType
|
||||
{
|
||||
|
@ -56,5 +55,3 @@ enum M3DChunkType
|
|||
|
||||
M3DCHUNK_KFDATA = 0xb000,
|
||||
};
|
||||
|
||||
#endif // _3DSCHUNK_H_
|
||||
|
|
|
@ -9,12 +9,6 @@
|
|||
|
||||
#include "3dsmodel.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
|
||||
M3DColor::M3DColor() :
|
||||
red(0), green(0), blue(0)
|
||||
{
|
||||
|
@ -25,12 +19,12 @@ M3DColor::M3DColor(float _red, float _green, float _blue) :
|
|||
{
|
||||
}
|
||||
|
||||
string M3DMaterial::getName() const
|
||||
std::string M3DMaterial::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void M3DMaterial::setName(string _name)
|
||||
void M3DMaterial::setName(std::string _name)
|
||||
{
|
||||
name = std::move(_name);
|
||||
}
|
||||
|
@ -85,12 +79,12 @@ void M3DMaterial::setOpacity(float _opacity)
|
|||
opacity = _opacity;
|
||||
}
|
||||
|
||||
string M3DMaterial::getTextureMap() const
|
||||
std::string M3DMaterial::getTextureMap() const
|
||||
{
|
||||
return texmap;
|
||||
}
|
||||
|
||||
void M3DMaterial::setTextureMap(const string& _texmap)
|
||||
void M3DMaterial::setTextureMap(const std::string& _texmap)
|
||||
{
|
||||
texmap = _texmap;
|
||||
}
|
||||
|
@ -98,50 +92,50 @@ void M3DMaterial::setTextureMap(const string& _texmap)
|
|||
|
||||
M3DTriangleMesh::M3DTriangleMesh()
|
||||
{
|
||||
matrix = Matrix4f::Identity();
|
||||
matrix = Eigen::Matrix4f::Identity();
|
||||
}
|
||||
|
||||
Matrix4f M3DTriangleMesh::getMatrix() const
|
||||
Eigen::Matrix4f M3DTriangleMesh::getMatrix() const
|
||||
{
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::setMatrix(const Matrix4f& m)
|
||||
void M3DTriangleMesh::setMatrix(const Eigen::Matrix4f& m)
|
||||
{
|
||||
matrix = m;
|
||||
}
|
||||
|
||||
Vector3f M3DTriangleMesh::getVertex(uint16_t n) const
|
||||
Eigen::Vector3f M3DTriangleMesh::getVertex(std::uint16_t n) const
|
||||
{
|
||||
return points[n];
|
||||
}
|
||||
|
||||
uint16_t M3DTriangleMesh::getVertexCount() const
|
||||
std::uint16_t M3DTriangleMesh::getVertexCount() const
|
||||
{
|
||||
return (uint16_t) (points.size());
|
||||
return (std::uint16_t) (points.size());
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::addVertex(const Vector3f& p)
|
||||
void M3DTriangleMesh::addVertex(const Eigen::Vector3f& p)
|
||||
{
|
||||
points.push_back(p);
|
||||
}
|
||||
|
||||
Vector2f M3DTriangleMesh::getTexCoord(uint16_t n) const
|
||||
Eigen::Vector2f M3DTriangleMesh::getTexCoord(std::uint16_t n) const
|
||||
{
|
||||
return texCoords[n];
|
||||
}
|
||||
|
||||
uint16_t M3DTriangleMesh::getTexCoordCount() const
|
||||
std::uint16_t M3DTriangleMesh::getTexCoordCount() const
|
||||
{
|
||||
return (uint16_t) (texCoords.size());
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::addTexCoord(const Vector2f& p)
|
||||
void M3DTriangleMesh::addTexCoord(const Eigen::Vector2f& p)
|
||||
{
|
||||
texCoords.push_back(p);
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::getFace(uint16_t n, uint16_t& v0, uint16_t& v1, uint16_t& v2) const
|
||||
void M3DTriangleMesh::getFace(std::uint16_t n, std::uint16_t& v0, std::uint16_t& v1, std::uint16_t& v2) const
|
||||
{
|
||||
int m = (int) n * 3;
|
||||
v0 = faces[m];
|
||||
|
@ -149,31 +143,31 @@ void M3DTriangleMesh::getFace(uint16_t n, uint16_t& v0, uint16_t& v1, uint16_t&
|
|||
v2 = faces[m + 2];
|
||||
}
|
||||
|
||||
uint16_t M3DTriangleMesh::getFaceCount() const
|
||||
std::uint16_t M3DTriangleMesh::getFaceCount() const
|
||||
{
|
||||
return (uint16_t) (faces.size() / 3);
|
||||
return (std::uint16_t) (faces.size() / 3);
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::addFace(uint16_t v0, uint16_t v1, uint16_t v2)
|
||||
void M3DTriangleMesh::addFace(std::uint16_t v0, std::uint16_t v1, std::uint16_t v2)
|
||||
{
|
||||
faces.push_back(v0);
|
||||
faces.push_back(v1);
|
||||
faces.push_back(v2);
|
||||
}
|
||||
|
||||
uint32_t M3DTriangleMesh::getSmoothingGroups(uint16_t face) const
|
||||
std::uint32_t M3DTriangleMesh::getSmoothingGroups(uint16_t face) const
|
||||
{
|
||||
return face < smoothingGroups.size() ? smoothingGroups[face] : 0;
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::addSmoothingGroups(uint32_t smGroups)
|
||||
void M3DTriangleMesh::addSmoothingGroups(std::uint32_t smGroups)
|
||||
{
|
||||
smoothingGroups.push_back(smGroups);
|
||||
}
|
||||
|
||||
uint16_t M3DTriangleMesh::getSmoothingGroupCount() const
|
||||
std::uint16_t M3DTriangleMesh::getSmoothingGroupCount() const
|
||||
{
|
||||
return (uint16_t) (smoothingGroups.size());
|
||||
return (std::uint16_t) (smoothingGroups.size());
|
||||
}
|
||||
|
||||
void M3DTriangleMesh::addMeshMaterialGroup(M3DMeshMaterialGroup* matGroup)
|
||||
|
@ -181,12 +175,12 @@ void M3DTriangleMesh::addMeshMaterialGroup(M3DMeshMaterialGroup* matGroup)
|
|||
meshMaterialGroups.push_back(matGroup);
|
||||
}
|
||||
|
||||
M3DMeshMaterialGroup* M3DTriangleMesh::getMeshMaterialGroup(uint32_t index) const
|
||||
M3DMeshMaterialGroup* M3DTriangleMesh::getMeshMaterialGroup(std::uint32_t index) const
|
||||
{
|
||||
return meshMaterialGroups[index];
|
||||
}
|
||||
|
||||
uint32_t M3DTriangleMesh::getMeshMaterialGroupCount() const
|
||||
std::uint32_t M3DTriangleMesh::getMeshMaterialGroupCount() const
|
||||
{
|
||||
return meshMaterialGroups.size();
|
||||
}
|
||||
|
@ -198,12 +192,12 @@ M3DModel::~M3DModel()
|
|||
delete triMesh;
|
||||
}
|
||||
|
||||
M3DTriangleMesh* M3DModel::getTriMesh(uint32_t n)
|
||||
M3DTriangleMesh* M3DModel::getTriMesh(std::uint32_t n)
|
||||
{
|
||||
return n < triMeshes.size() ? triMeshes[n] : nullptr;
|
||||
}
|
||||
|
||||
uint32_t M3DModel::getTriMeshCount()
|
||||
std::uint32_t M3DModel::getTriMeshCount()
|
||||
{
|
||||
return triMeshes.size();
|
||||
}
|
||||
|
@ -213,12 +207,12 @@ void M3DModel::addTriMesh(M3DTriangleMesh* triMesh)
|
|||
triMeshes.push_back(triMesh);
|
||||
}
|
||||
|
||||
void M3DModel::setName(const string& _name)
|
||||
void M3DModel::setName(const std::string& _name)
|
||||
{
|
||||
name = _name;
|
||||
}
|
||||
|
||||
const string M3DModel::getName() const
|
||||
const std::string M3DModel::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@ -232,12 +226,12 @@ M3DScene::~M3DScene()
|
|||
delete material;
|
||||
}
|
||||
|
||||
M3DModel* M3DScene::getModel(uint32_t n) const
|
||||
M3DModel* M3DScene::getModel(std::uint32_t n) const
|
||||
{
|
||||
return n < models.size() ? models[n] : nullptr;
|
||||
}
|
||||
|
||||
uint32_t M3DScene::getModelCount() const
|
||||
std::uint32_t M3DScene::getModelCount() const
|
||||
{
|
||||
return models.size();
|
||||
}
|
||||
|
@ -247,12 +241,12 @@ void M3DScene::addModel(M3DModel* model)
|
|||
models.push_back(model);
|
||||
}
|
||||
|
||||
M3DMaterial* M3DScene::getMaterial(uint32_t n) const
|
||||
M3DMaterial* M3DScene::getMaterial(std::uint32_t n) const
|
||||
{
|
||||
return n < materials.size() ? materials[n] : nullptr;
|
||||
}
|
||||
|
||||
uint32_t M3DScene::getMaterialCount() const
|
||||
std::uint32_t M3DScene::getMaterialCount() const
|
||||
{
|
||||
return materials.size();
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#ifndef _3DSMODEL_H_
|
||||
#define _3DSMODEL_H_
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
class M3DColor
|
||||
|
@ -60,7 +61,7 @@ class M3DMeshMaterialGroup
|
|||
{
|
||||
public:
|
||||
std::string materialName;
|
||||
std::vector<uint16_t> faces;
|
||||
std::vector<std::uint16_t> faces;
|
||||
};
|
||||
|
||||
|
||||
|
@ -75,31 +76,31 @@ class M3DTriangleMesh
|
|||
Eigen::Matrix4f getMatrix() const;
|
||||
void setMatrix(const Eigen::Matrix4f&);
|
||||
|
||||
Eigen::Vector3f getVertex(uint16_t) const;
|
||||
uint16_t getVertexCount() const;
|
||||
Eigen::Vector3f getVertex(std::uint16_t) const;
|
||||
std::uint16_t getVertexCount() const;
|
||||
void addVertex(const Eigen::Vector3f&);
|
||||
|
||||
Eigen::Vector2f getTexCoord(uint16_t) const;
|
||||
uint16_t getTexCoordCount() const;
|
||||
Eigen::Vector2f getTexCoord(std::uint16_t) const;
|
||||
std::uint16_t getTexCoordCount() const;
|
||||
void addTexCoord(const Eigen::Vector2f&);
|
||||
|
||||
void getFace(uint16_t, uint16_t&, uint16_t&, uint16_t&) const;
|
||||
uint16_t getFaceCount() const;
|
||||
void addFace(uint16_t, uint16_t, uint16_t);
|
||||
void getFace(std::uint16_t, std::uint16_t&, std::uint16_t&, std::uint16_t&) const;
|
||||
std::uint16_t getFaceCount() const;
|
||||
void addFace(std::uint16_t, std::uint16_t, std::uint16_t);
|
||||
|
||||
void addSmoothingGroups(uint32_t);
|
||||
uint32_t getSmoothingGroups(uint16_t) const;
|
||||
uint16_t getSmoothingGroupCount() const;
|
||||
void addSmoothingGroups(std::uint32_t);
|
||||
std::uint32_t getSmoothingGroups(std::uint16_t) const;
|
||||
std::uint16_t getSmoothingGroupCount() const;
|
||||
|
||||
void addMeshMaterialGroup(M3DMeshMaterialGroup* matGroup);
|
||||
M3DMeshMaterialGroup* getMeshMaterialGroup(uint32_t) const;
|
||||
uint32_t getMeshMaterialGroupCount() const;
|
||||
M3DMeshMaterialGroup* getMeshMaterialGroup(std::uint32_t) const;
|
||||
std::uint32_t getMeshMaterialGroupCount() const;
|
||||
|
||||
private:
|
||||
std::vector<Eigen::Vector3f> points;
|
||||
std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f>> texCoords;
|
||||
std::vector<uint16_t> faces;
|
||||
std::vector<uint32_t> smoothingGroups;
|
||||
std::vector<std::uint16_t> faces;
|
||||
std::vector<std::uint32_t> smoothingGroups;
|
||||
std::vector<M3DMeshMaterialGroup*> meshMaterialGroups;
|
||||
Eigen::Matrix4f matrix;
|
||||
};
|
||||
|
@ -145,5 +146,3 @@ class M3DScene
|
|||
std::vector<M3DMaterial*> materials;
|
||||
M3DColor backgroundColor;
|
||||
};
|
||||
|
||||
#endif // _3DSMODEL_H_
|
||||
|
|
|
@ -7,52 +7,58 @@
|
|||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#include <iomanip>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
#include "celutil/bytes.h"
|
||||
#include "celutil/debug.h"
|
||||
#include "3dschunk.h"
|
||||
#include "3dsmodel.h"
|
||||
#include "3dsread.h"
|
||||
#include <celutil/bytes.h>
|
||||
#include <celutil/debug.h>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
using ProcessChunkFunc = bool (*)(ifstream &, unsigned short, int, void *);
|
||||
|
||||
static int read3DSChunk(ifstream& in,
|
||||
ProcessChunkFunc chunkFunc,
|
||||
void* obj);
|
||||
|
||||
// For pretty printing debug info
|
||||
static int logIndent = 0;
|
||||
|
||||
|
||||
static int32_t readInt(ifstream& in)
|
||||
namespace
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
using ProcessChunkFunc = bool (*)(std::istream &, unsigned short, int, void *);
|
||||
|
||||
|
||||
int read3DSChunk(std::istream& in,
|
||||
ProcessChunkFunc chunkFunc,
|
||||
void* obj);
|
||||
|
||||
|
||||
std::int32_t readInt(std::istream& in)
|
||||
{
|
||||
std::int32_t ret;
|
||||
in.read((char *) &ret, sizeof(int32_t));
|
||||
LE_TO_CPU_INT32(ret, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int16_t readShort(ifstream& in)
|
||||
|
||||
std::int16_t readShort(std::istream& in)
|
||||
{
|
||||
int16_t ret;
|
||||
std::int16_t ret;
|
||||
in.read((char *) &ret, sizeof(int16_t));
|
||||
LE_TO_CPU_INT16(ret, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint16_t readUshort(ifstream& in)
|
||||
|
||||
std::uint16_t readUshort(std::istream& in)
|
||||
{
|
||||
uint16_t ret;
|
||||
std::uint16_t ret;
|
||||
in.read((char *) &ret, sizeof(uint16_t));
|
||||
LE_TO_CPU_INT16(ret, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static float readFloat(ifstream& in)
|
||||
|
||||
float readFloat(std::istream& in)
|
||||
{
|
||||
float f;
|
||||
in.read((char*) &f, sizeof(float));
|
||||
|
@ -61,7 +67,7 @@ static float readFloat(ifstream& in)
|
|||
}
|
||||
|
||||
|
||||
static char readChar(ifstream& in)
|
||||
char readChar(std::istream& in)
|
||||
{
|
||||
char c;
|
||||
in.read(&c, 1);
|
||||
|
@ -69,21 +75,7 @@ static char readChar(ifstream& in)
|
|||
}
|
||||
|
||||
|
||||
/* Not currently used
|
||||
static int readString(ifstream& in, char* s, int maxLength)
|
||||
{
|
||||
int count;
|
||||
for (count = 0; count < maxLength; count++)
|
||||
{
|
||||
in.read(s + count, 1);
|
||||
if (s[count] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
return count;
|
||||
}*/
|
||||
|
||||
static string readString(ifstream& in)
|
||||
std::string readString(std::istream& in)
|
||||
{
|
||||
char s[1024];
|
||||
int maxLength = sizeof(s);
|
||||
|
@ -95,11 +87,11 @@ static string readString(ifstream& in)
|
|||
break;
|
||||
}
|
||||
|
||||
return string(s);
|
||||
return std::string(s);
|
||||
}
|
||||
|
||||
|
||||
static void skipBytes(ifstream& in, int count)
|
||||
void skipBytes(std::istream& in, int count)
|
||||
{
|
||||
char c;
|
||||
while (count-- > 0)
|
||||
|
@ -107,117 +99,14 @@ static void skipBytes(ifstream& in, int count)
|
|||
}
|
||||
|
||||
|
||||
void indent()
|
||||
{
|
||||
for (int i = 0; i < logIndent; i++)
|
||||
cout << " ";
|
||||
}
|
||||
|
||||
void logChunk(uint16_t /*chunkType*/ /*, int chunkSize*/)
|
||||
{
|
||||
#if 0
|
||||
const char* name = nullptr;
|
||||
|
||||
switch (chunkType)
|
||||
{
|
||||
case M3DCHUNK_NULL:
|
||||
name = "M3DCHUNK_NULL"; break;
|
||||
case M3DCHUNK_VERSION:
|
||||
name = "M3DCHUNK_VERSION"; break;
|
||||
case M3DCHUNK_COLOR_FLOAT:
|
||||
name = "M3DCHUNK_COLOR_FLOAT"; break;
|
||||
case M3DCHUNK_COLOR_24:
|
||||
name = "M3DCHUNK_COLOR_24"; break;
|
||||
case M3DCHUNK_LIN_COLOR_F:
|
||||
name = "M3DCHUNK_LIN_COLOR_F"; break;
|
||||
case M3DCHUNK_INT_PERCENTAGE:
|
||||
name = "M3DCHUNK_INT_PERCENTAGE"; break;
|
||||
case M3DCHUNK_FLOAT_PERCENTAGE:
|
||||
name = "M3DCHUNK_FLOAT_PERCENTAGE"; break;
|
||||
case M3DCHUNK_MASTER_SCALE:
|
||||
name = "M3DCHUNK_MASTER_SCALE"; break;
|
||||
case M3DCHUNK_BACKGROUND_COLOR:
|
||||
name = "M3DCHUNK_BACKGROUND_COLOR"; break;
|
||||
case M3DCHUNK_MESHDATA:
|
||||
name = "M3DCHUNK_MESHDATA"; break;
|
||||
case M3DCHUNK_MESH_VERSION:
|
||||
name = "M3DCHUNK_MESHVERSION"; break;
|
||||
case M3DCHUNK_NAMED_OBJECT:
|
||||
name = "M3DCHUNK_NAMED_OBJECT"; break;
|
||||
case M3DCHUNK_TRIANGLE_MESH:
|
||||
name = "M3DCHUNK_TRIANGLE_MESH"; break;
|
||||
case M3DCHUNK_POINT_ARRAY:
|
||||
name = "M3DCHUNK_POINT_ARRAY"; break;
|
||||
case M3DCHUNK_POINT_FLAG_ARRAY:
|
||||
name = "M3DCHUNK_POINT_FLAG_ARRAY"; break;
|
||||
case M3DCHUNK_FACE_ARRAY:
|
||||
name = "M3DCHUNK_FACE_ARRAY"; break;
|
||||
case M3DCHUNK_MESH_MATERIAL_GROUP:
|
||||
name = "M3DCHUNK_MESH_MATERIAL_GROUP"; break;
|
||||
case M3DCHUNK_MESH_TEXTURE_COORDS:
|
||||
name = "M3DCHUNK_MESH_TEXTURE_COORDS"; break;
|
||||
case M3DCHUNK_MESH_SMOOTH_GROUP:
|
||||
name = "M3DCHUNK_MESH_SMOOTH_GROUP"; break;
|
||||
case M3DCHUNK_MESH_MATRIX:
|
||||
name = "M3DCHUNK_MESH_MATRIX"; break;
|
||||
case M3DCHUNK_MAGIC:
|
||||
name = "M3DCHUNK_MAGIC"; break;
|
||||
case M3DCHUNK_MATERIAL_NAME:
|
||||
name = "M3DCHUNK_MATERIAL_NAME"; break;
|
||||
case M3DCHUNK_MATERIAL_AMBIENT:
|
||||
name = "M3DCHUNK_MATERIAL_AMBIENT"; break;
|
||||
case M3DCHUNK_MATERIAL_DIFFUSE:
|
||||
name = "M3DCHUNK_MATERIAL_DIFFUSE"; break;
|
||||
case M3DCHUNK_MATERIAL_SPECULAR:
|
||||
name = "M3DCHUNK_MATERIAL_SPECULAR"; break;
|
||||
case M3DCHUNK_MATERIAL_SHININESS:
|
||||
name = "M3DCHUNK_MATERIAL_SHININESS"; break;
|
||||
case M3DCHUNK_MATERIAL_SHIN2PCT:
|
||||
name = "M3DCHUNK_MATERIAL_SHIN2PCT"; break;
|
||||
case M3DCHUNK_MATERIAL_TRANSPARENCY:
|
||||
name = "M3DCHUNK_MATERIAL_TRANSPARENCY"; break;
|
||||
case M3DCHUNK_MATERIAL_XPFALL:
|
||||
name = "M3DCHUNK_MATERIAL_XPFALL"; break;
|
||||
case M3DCHUNK_MATERIAL_REFBLUR:
|
||||
name = "M3DCHUNK_MATERIAL_REFBLUR"; break;
|
||||
case M3DCHUNK_MATERIAL_TEXMAP:
|
||||
name = "M3DCHUNK_MATERIAL_TEXMAP"; break;
|
||||
case M3DCHUNK_MATERIAL_MAPNAME:
|
||||
name = "M3DCHUNK_MATERIAL_MAPNAME"; break;
|
||||
case M3DCHUNK_MATERIAL_ENTRY:
|
||||
name = "M3DCHUNK_MATERIAL_ENTRY"; break;
|
||||
case M3DCHUNK_KFDATA:
|
||||
name = "M3DCHUNK_KFDATA";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
indent();
|
||||
|
||||
if (name == nullptr)
|
||||
{
|
||||
cout << "Chunk ID " << setw(4) << hex << setfill('0') << chunkType;
|
||||
cout << setw(0) << dec << ", size = " << chunkSize << '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << name << ", size = " << chunkSize << '\n';
|
||||
}
|
||||
|
||||
cout.flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int read3DSChunk(ifstream& in,
|
||||
int read3DSChunk(std::istream& in,
|
||||
ProcessChunkFunc chunkFunc,
|
||||
void* obj)
|
||||
{
|
||||
unsigned short chunkType = readUshort(in);
|
||||
int32_t chunkSize = readInt(in);
|
||||
std::int32_t chunkSize = readInt(in);
|
||||
int contentSize = chunkSize - 6;
|
||||
|
||||
//logChunk(chunkType/*, chunkSize*/);
|
||||
bool chunkWasRead = chunkFunc(in, chunkType, contentSize, obj);
|
||||
|
||||
if (!chunkWasRead)
|
||||
|
@ -229,25 +118,23 @@ int read3DSChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
int read3DSChunks(ifstream& in,
|
||||
int read3DSChunks(std::istream& in,
|
||||
int nBytes,
|
||||
ProcessChunkFunc chunkFunc,
|
||||
void* obj)
|
||||
{
|
||||
int bytesRead = 0;
|
||||
|
||||
logIndent++;
|
||||
while (bytesRead < nBytes)
|
||||
bytesRead += read3DSChunk(in, chunkFunc, obj);
|
||||
logIndent--;
|
||||
|
||||
if (bytesRead != nBytes)
|
||||
cout << "Expected " << nBytes << " bytes but read " << bytesRead << '\n';
|
||||
std::cout << "Expected " << nBytes << " bytes but read " << bytesRead << '\n';
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
||||
M3DColor readColor(ifstream& in/*, int nBytes*/)
|
||||
M3DColor readColor(std::istream& in/*, int nBytes*/)
|
||||
{
|
||||
auto r = (unsigned char) readChar(in);
|
||||
auto g = (unsigned char) readChar(in);
|
||||
|
@ -259,7 +146,7 @@ M3DColor readColor(ifstream& in/*, int nBytes*/)
|
|||
}
|
||||
|
||||
|
||||
M3DColor readFloatColor(ifstream& in/*, int nBytes*/)
|
||||
M3DColor readFloatColor(std::istream& in/*, int nBytes*/)
|
||||
{
|
||||
float r = readFloat(in);
|
||||
float g = readFloat(in);
|
||||
|
@ -271,7 +158,7 @@ M3DColor readFloatColor(ifstream& in/*, int nBytes*/)
|
|||
}
|
||||
|
||||
|
||||
Matrix4f readMeshMatrix(ifstream& in/*, int nBytes*/)
|
||||
Eigen::Matrix4f readMeshMatrix(std::istream& in/*, int nBytes*/)
|
||||
{
|
||||
float m00 = readFloat(in);
|
||||
float m01 = readFloat(in);
|
||||
|
@ -293,7 +180,7 @@ Matrix4f readMeshMatrix(ifstream& in/*, int nBytes*/)
|
|||
cout << m30 << " " << m31 << " " << m32 << '\n';
|
||||
#endif
|
||||
|
||||
Matrix4f m;
|
||||
Eigen::Matrix4f m;
|
||||
m << m00, m01, m02, 0,
|
||||
m10, m11, m12, 0,
|
||||
m20, m21, m22, 0,
|
||||
|
@ -312,40 +199,40 @@ bool stubProcessChunk(/* ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
void readPointArray(ifstream& in, M3DTriangleMesh* triMesh)
|
||||
void readPointArray(std::istream& in, M3DTriangleMesh* triMesh)
|
||||
{
|
||||
uint16_t nPoints = readUshort(in);
|
||||
std::uint16_t nPoints = readUshort(in);
|
||||
|
||||
for (int i = 0; i < (int) nPoints; i++)
|
||||
{
|
||||
float x = readFloat(in);
|
||||
float y = readFloat(in);
|
||||
float z = readFloat(in);
|
||||
triMesh->addVertex(Vector3f(x, y, z));
|
||||
triMesh->addVertex(Eigen::Vector3f(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readTextureCoordArray(ifstream& in, M3DTriangleMesh* triMesh)
|
||||
void readTextureCoordArray(std::istream& in, M3DTriangleMesh* triMesh)
|
||||
{
|
||||
uint16_t nPoints = readUshort(in);
|
||||
std::uint16_t nPoints = readUshort(in);
|
||||
|
||||
for (int i = 0; i < (int) nPoints; i++)
|
||||
{
|
||||
float u = readFloat(in);
|
||||
float v = readFloat(in);
|
||||
triMesh->addTexCoord(Vector2f(u, -v));
|
||||
triMesh->addTexCoord(Eigen::Vector2f(u, -v));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool processFaceArrayChunk(ifstream& in,
|
||||
bool processFaceArrayChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int /*contentSize*/,
|
||||
void* obj)
|
||||
{
|
||||
auto* triMesh = (M3DTriangleMesh*) obj;
|
||||
uint16_t nFaces;
|
||||
std::uint16_t nFaces;
|
||||
M3DMeshMaterialGroup* matGroup;
|
||||
|
||||
switch (chunkType)
|
||||
|
@ -356,9 +243,9 @@ bool processFaceArrayChunk(ifstream& in,
|
|||
matGroup->materialName = readString(in);
|
||||
nFaces = readUshort(in);
|
||||
|
||||
for (uint16_t i = 0; i < nFaces; i++)
|
||||
for (std::uint16_t i = 0; i < nFaces; i++)
|
||||
{
|
||||
uint16_t faceIndex = readUshort(in);
|
||||
std::uint16_t faceIndex = readUshort(in);
|
||||
matGroup->faces.push_back(faceIndex);
|
||||
}
|
||||
|
||||
|
@ -368,9 +255,9 @@ bool processFaceArrayChunk(ifstream& in,
|
|||
case M3DCHUNK_MESH_SMOOTH_GROUP:
|
||||
nFaces = triMesh->getFaceCount();
|
||||
|
||||
for (uint16_t i = 0; i < nFaces; i++)
|
||||
for (std::uint16_t i = 0; i < nFaces; i++)
|
||||
{
|
||||
auto groups = (uint32_t) readInt(in);
|
||||
auto groups = (std::uint32_t) readInt(in);
|
||||
triMesh->addSmoothingGroups(groups);
|
||||
}
|
||||
return true;
|
||||
|
@ -379,15 +266,15 @@ bool processFaceArrayChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
void readFaceArray(ifstream& in, M3DTriangleMesh* triMesh, int contentSize)
|
||||
void readFaceArray(std::istream& in, M3DTriangleMesh* triMesh, int contentSize)
|
||||
{
|
||||
uint16_t nFaces = readUshort(in);
|
||||
std::uint16_t nFaces = readUshort(in);
|
||||
|
||||
for (int i = 0; i < (int) nFaces; i++)
|
||||
{
|
||||
uint16_t v0 = readUshort(in);
|
||||
uint16_t v1 = readUshort(in);
|
||||
uint16_t v2 = readUshort(in);
|
||||
std::uint16_t v0 = readUshort(in);
|
||||
std::uint16_t v1 = readUshort(in);
|
||||
std::uint16_t v2 = readUshort(in);
|
||||
/*uint16_t flags = */ readUshort(in);
|
||||
triMesh->addFace(v0, v1, v2);
|
||||
}
|
||||
|
@ -403,7 +290,7 @@ void readFaceArray(ifstream& in, M3DTriangleMesh* triMesh, int contentSize)
|
|||
}
|
||||
|
||||
|
||||
bool processTriMeshChunk(ifstream& in,
|
||||
bool processTriMeshChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int contentSize,
|
||||
void* obj)
|
||||
|
@ -430,7 +317,7 @@ bool processTriMeshChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
bool processModelChunk(ifstream& in,
|
||||
bool processModelChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int contentSize,
|
||||
void* obj)
|
||||
|
@ -449,7 +336,7 @@ bool processModelChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
bool processColorChunk(ifstream& in,
|
||||
bool processColorChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int /*contentSize*/,
|
||||
void* obj)
|
||||
|
@ -470,7 +357,7 @@ bool processColorChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
static bool processPercentageChunk(ifstream& in,
|
||||
static bool processPercentageChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int /*contentSize*/,
|
||||
void* obj)
|
||||
|
@ -491,7 +378,7 @@ static bool processPercentageChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
static bool processTexmapChunk(ifstream& in,
|
||||
static bool processTexmapChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int /*contentSize*/,
|
||||
void* obj)
|
||||
|
@ -500,7 +387,7 @@ static bool processTexmapChunk(ifstream& in,
|
|||
|
||||
if (chunkType == M3DCHUNK_MATERIAL_MAPNAME)
|
||||
{
|
||||
string name = readString(in);
|
||||
std::string name = readString(in);
|
||||
material->setTextureMap(name);
|
||||
return true;
|
||||
}
|
||||
|
@ -509,13 +396,13 @@ static bool processTexmapChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
bool processMaterialChunk(ifstream& in,
|
||||
bool processMaterialChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int contentSize,
|
||||
void* obj)
|
||||
{
|
||||
auto* material = (M3DMaterial*) obj;
|
||||
string name;
|
||||
std::string name;
|
||||
M3DColor color;
|
||||
float t;
|
||||
|
||||
|
@ -554,7 +441,7 @@ bool processMaterialChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
bool processSceneChunk(ifstream& in,
|
||||
bool processSceneChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int contentSize,
|
||||
void* obj)
|
||||
|
@ -563,7 +450,7 @@ bool processSceneChunk(ifstream& in,
|
|||
M3DModel* model;
|
||||
M3DMaterial* material;
|
||||
M3DColor color;
|
||||
string name;
|
||||
std::string name;
|
||||
|
||||
switch (chunkType)
|
||||
{
|
||||
|
@ -571,7 +458,6 @@ bool processSceneChunk(ifstream& in,
|
|||
name = readString(in);
|
||||
model = new M3DModel();
|
||||
model->setName(name);
|
||||
// indent(); cout << " [" << name << "]\n";
|
||||
read3DSChunks(in,
|
||||
contentSize - (name.length() + 1),
|
||||
processModelChunk,
|
||||
|
@ -598,7 +484,7 @@ bool processSceneChunk(ifstream& in,
|
|||
}
|
||||
|
||||
|
||||
bool processTopLevelChunk(ifstream& in,
|
||||
bool processTopLevelChunk(std::istream& in,
|
||||
unsigned short chunkType,
|
||||
int contentSize,
|
||||
void* obj)
|
||||
|
@ -614,8 +500,10 @@ bool processTopLevelChunk(ifstream& in,
|
|||
return false;
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
M3DScene* Read3DSFile(ifstream& in)
|
||||
|
||||
M3DScene* Read3DSFile(std::istream& in)
|
||||
{
|
||||
unsigned short chunkType = readUshort(in);
|
||||
if (chunkType != M3DCHUNK_MAGIC)
|
||||
|
@ -624,7 +512,7 @@ M3DScene* Read3DSFile(ifstream& in)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t chunkSize = readInt(in);
|
||||
std::int32_t chunkSize = readInt(in);
|
||||
if (in.bad())
|
||||
{
|
||||
DPRINTF(LOG_LEVEL_ERROR, "Read3DSFile: Error reading 3DS file.\n");
|
||||
|
@ -644,7 +532,7 @@ M3DScene* Read3DSFile(ifstream& in)
|
|||
|
||||
M3DScene* Read3DSFile(const fs::path& filename)
|
||||
{
|
||||
ifstream in(filename.string(), ios::in | ios::binary);
|
||||
std::ifstream in(filename.string(), std::ios::in | std::ios::binary);
|
||||
if (!in.good())
|
||||
{
|
||||
DPRINTF(LOG_LEVEL_ERROR, "Read3DSFile: Error opening %s\n", filename);
|
||||
|
|
|
@ -7,15 +7,12 @@
|
|||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#ifndef _3DSREAD_H_
|
||||
#define _3DSREAD_H_
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cel3ds/3dsmodel.h>
|
||||
#include <iosfwd>
|
||||
#include <celcompat/filesystem.h>
|
||||
|
||||
M3DScene* Read3DSFile(std::ifstream& in);
|
||||
M3DScene* Read3DSFile(const fs::path& filename);
|
||||
class M3DScene;
|
||||
|
||||
#endif // _3DSREAD_H_
|
||||
M3DScene* Read3DSFile(std::istream& in);
|
||||
M3DScene* Read3DSFile(const fs::path& filename);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "modelgeometry.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
#include <cel3ds/3dsmodel.h>
|
||||
#include <cel3ds/3dsread.h>
|
||||
#include <celmodel/modelfile.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue