From ddbc80897710a2a1a718909e16ee94958fcf3133 Mon Sep 17 00:00:00 2001 From: Tobias Grundel Date: Thu, 21 Nov 2013 12:47:47 +0100 Subject: [PATCH 1/2] Re-fixed ObjReader --- Code/OysterGraphics/FileLoader/ObjReader.cpp | 16 ++++++++-------- Code/OysterGraphics/FileLoader/ObjReader.h | 12 ++++++------ Code/OysterGraphics/OysterGraphics.vcxproj | 6 ++++-- .../OysterGraphics.vcxproj.filters | 18 ++++++++++++------ 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index b5ad5d4e..1723e776 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -15,14 +15,14 @@ OBJReader::~OBJReader() } -void OBJReader::readOBJFile( wstring fileName ) +void OBJReader::readOBJFile( std::wstring fileName ) { - fstream inStream; - string typeOfData = " "; + std::fstream inStream; + std::string typeOfData = " "; float vertexData; - string face1, face2, face3; + std::string face1, face2, face3; - inStream.open( fileName, fstream::in ); + inStream.open( fileName, std::fstream::in ); if( inStream.is_open() ) { @@ -95,11 +95,11 @@ void OBJReader::readOBJFile( wstring fileName ) } //Private functions -void OBJReader::stringSplit( string strToSplit ) +void OBJReader::stringSplit( std::string strToSplit ) { char delim = '/'; - string vPos, vNormal, vTexel; - stringstream aStream(strToSplit); + std::string vPos, vNormal, vTexel; + std::stringstream aStream(strToSplit); getline( aStream, vPos, delim ); getline( aStream, vTexel, delim ); getline( aStream, vNormal ); diff --git a/Code/OysterGraphics/FileLoader/ObjReader.h b/Code/OysterGraphics/FileLoader/ObjReader.h index 562d81fc..84e9a7a2 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.h +++ b/Code/OysterGraphics/FileLoader/ObjReader.h @@ -19,8 +19,8 @@ class OBJReader struct OBJMaterialData { - string _name; - string _mapKd; + std::string _name; + std::string _mapKd; float _kd[3]; float _ka[3]; float _tf[3]; @@ -35,19 +35,19 @@ class OBJReader std::vector _myOBJ; private: - vector _mVertexCoord, _mVertexNormal; - vector _mVertexTexture; + std::vector _mVertexCoord, _mVertexNormal; + std::vector _mVertexTexture; int _mNrOfCoords, _mNrOfNormals, _mNrOfTexels, _mNrOfFaces; int _mPos, _mNormal, _mTexel; - void stringSplit( string strToSplit ); + void stringSplit( std::string strToSplit ); void addToOBJarray(); public: OBJReader(); ~OBJReader(); - void readOBJFile( wstring fileName); + void readOBJFile( std::wstring fileName); }; #endif \ No newline at end of file diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj index 7dfb0e7a..4bf661a9 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj +++ b/Code/OysterGraphics/OysterGraphics.vcxproj @@ -145,8 +145,9 @@ - - + + + @@ -154,6 +155,7 @@ + diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.filters b/Code/OysterGraphics/OysterGraphics.vcxproj.filters index 734eba8b..e5d9b3ea 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.filters +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.filters @@ -27,15 +27,18 @@ Source Files - - Source Files - - - Source Files - Source Files + + Source Files + + + Source Files + + + Source Files + @@ -65,6 +68,9 @@ Header Files + + Header Files + From f08e9491ed00b00aedba0eabf1caed33830fc0e2 Mon Sep 17 00:00:00 2001 From: Tobias Grundel Date: Thu, 21 Nov 2013 13:45:11 +0100 Subject: [PATCH 2/2] ObjReader --- Code/OysterGraphics/FileLoader/ObjReader.cpp | 26 ++++++++++++++++++++ Code/OysterGraphics/FileLoader/ObjReader.h | 2 ++ Code/OysterGraphics/Model/Model.h | 4 +-- Code/OysterGraphics/Model/ModelInfo.h | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index 1723e776..e9839031 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -94,6 +94,32 @@ void OBJReader::readOBJFile( std::wstring fileName ) inStream.close(); } +Oyster::Graphics::Render::ModelInfo OBJReader::toModel() +{ + Oyster::Graphics::Buffer b; + Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc; + Oyster::Graphics::Render::ModelInfo modelInfo; + + desc.ElementSize = sizeof(OBJReader::OBJFormat); + desc.InitData = &this->_myOBJ[0]; + desc.NumElements = (UINT32)this->_myOBJ.size(); + desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS; + desc.Usage = Oyster::Graphics::Buffer::BUFFER_USAGE_IMMUTABLE; + HRESULT hr = S_OK; + + hr = b.Init(desc); + if(FAILED(hr)) + { + //Something isn't okay here + } + modelInfo.Indexed = false; + modelInfo.VertexCount = (int)desc.NumElements; + modelInfo.Vertices = b; + + + return modelInfo; +} + //Private functions void OBJReader::stringSplit( std::string strToSplit ) { diff --git a/Code/OysterGraphics/FileLoader/ObjReader.h b/Code/OysterGraphics/FileLoader/ObjReader.h index 84e9a7a2..e5e2f67a 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.h +++ b/Code/OysterGraphics/FileLoader/ObjReader.h @@ -2,6 +2,7 @@ #define OBJREADER_H #include "..\..\Misc\Utilities.h" #include "..\..\OysterMath\OysterMath.h" +#include "..\Model\ModelInfo.h" //#include @@ -48,6 +49,7 @@ class OBJReader ~OBJReader(); void readOBJFile( std::wstring fileName); + Oyster::Graphics::Render::ModelInfo toModel(); }; #endif \ No newline at end of file diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 05a9a5c3..ef0d1051 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -11,7 +11,7 @@ //#include "ICollideable.h" #include "ModelInfo.h" -using namespace Oyster::Math; +//using namespace Oyster::Math; namespace Oyster { @@ -22,7 +22,7 @@ namespace Oyster struct Model { ModelInfo* info; - Float4x4 *World; + Oyster::Math::Float4x4 *World; bool Visible; }; } diff --git a/Code/OysterGraphics/Model/ModelInfo.h b/Code/OysterGraphics/Model/ModelInfo.h index 2c968b00..e78df441 100644 --- a/Code/OysterGraphics/Model/ModelInfo.h +++ b/Code/OysterGraphics/Model/ModelInfo.h @@ -10,7 +10,7 @@ //#include "OysterMath.h" //#include "ICollideable.h" -using namespace Oyster::Math; +//using namespace Oyster::Math; namespace Oyster {