Link error fixed and ObjReader

This commit is contained in:
Tobias Grundel 2013-11-19 13:30:46 +01:00
parent ab70bed60b
commit 86aac0c72a
21 changed files with 167 additions and 284 deletions

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@
// http://lolengine.net/blog/2011/3/4/fuck-you-microsoft-near-far-macros // http://lolengine.net/blog/2011/3/4/fuck-you-microsoft-near-far-macros
#include <windows.h> #include <windows.h>
#include <D3D11.h> #include <D3D11.h>
#include <d3dCompiler.h> #include <d3dcompiler.h>
#pragma comment(lib, "d3d11.lib") #pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dcompiler.lib") #pragma comment(lib, "d3dcompiler.lib")

View File

@ -140,7 +140,7 @@ namespace Oyster
case Core::ShaderManager::ShaderType::Pixel: case Core::ShaderManager::ShaderType::Pixel:
ID3D11PixelShader* pixel; ID3D11PixelShader* pixel;
if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"ps_5_0",0,0,&Shader,&Error))) if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"ps_5_0",0,0,&Shader,&Error)))
{ {
std::string fel = (char*)Error->GetBufferPointer(); std::string fel = (char*)Error->GetBufferPointer();
@ -168,7 +168,7 @@ namespace Oyster
case Core::ShaderManager::ShaderType::Geometry: case Core::ShaderManager::ShaderType::Geometry:
ID3D11GeometryShader* geometry; ID3D11GeometryShader* geometry;
if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"gs_5_0",0,0,&Shader,&Error))) if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"gs_5_0",0,0,&Shader,&Error)))
{ {
std::string fel = (char*)Error->GetBufferPointer(); std::string fel = (char*)Error->GetBufferPointer();

View File

@ -1,268 +1,122 @@
#include "ObjReader.h" #include "OBJReader.h"
#include "Utilities.h" #include <sstream>
#include "..\Core\Core.h"
#include <fstream> #include <fstream>
#include <map>
using namespace std; using namespace std;
using namespace Oyster::FileLoaders; OBJReader::OBJReader()
using namespace Oyster;
using namespace Oyster::Math;
ObjReader *ObjReader::LoadFile(std::string fileName, Oyster::Math::Float4x4 transform)
{ {
static std::map<std::string, ObjReader *> cache; _mPos = 0;
_mNormal = 0;
ObjReader *reader = NULL; _mTexel = 0;
if (cache.count(fileName))
{
reader = cache[fileName];
}
else
{
reader = new ObjReader();
reader->ParseFile(fileName, transform);
cache[fileName] = reader;
}
return reader;
} }
ObjReader::ObjReader(void) OBJReader::~OBJReader()
{ {
} }
void OBJReader::readOBJFile( wstring fileName )
ObjReader::~ObjReader(void)
{ {
} fstream inStream;
string typeOfData = " ";
float vertexData;
string face1, face2, face3;
void ObjReader::ParseFile(std::string fileName, Float4x4 transform) inStream.open( fileName, fstream::in );
{
ifstream input; if( inStream.is_open() )
input.open(fileName.c_str());
if(!input.is_open())
{ {
return; while( !inStream.eof() )
}
string path;
Utility::String::extractDirPath(path,fileName,'\\');
std::vector<Vertex> VertexList;
std::vector<Float3> vList;
std::vector<Float3> nList;
std::vector<Float2> uvList;
Vertex vertex1, vertex2, vertex3;
Float3 face[3];
Float3 position, normal;
Float2 uv;
string s;
while(!input.eof())
{
getline(input,s);
int offset = (int)s.find(' ');
if(offset!=-1)
{ {
string c = s.substr(0,offset); inStream >> typeOfData;
if(c=="v") if( typeOfData == "v" )
{ {
position = readVertex(offset,s); Oyster::Math::Float3 position;
vList.push_back(position);
inStream >> vertexData;
position.x = vertexData;
inStream >> vertexData;
position.y = vertexData;
inStream >> vertexData;
position.z = vertexData;
_mVertexCoord.push_back( position );
} }
else if(c=="vt") else if( typeOfData == "vt" )
{ {
uv = readUV(offset,s); Oyster::Math::Float2 texel;
uvList.push_back(uv); inStream >> vertexData;
texel.x = vertexData;
inStream >> vertexData;
texel.y = 1 - vertexData;
_mVertexTexture.push_back( texel );
} }
else if(c=="vn") else if( typeOfData == "vn" )
{ {
normal = readNormal(offset,s); Oyster::Math::Float3 normal;
nList.push_back(normal); inStream >> vertexData;
normal.x = vertexData;
inStream >> vertexData;
normal.y = vertexData;
inStream >> vertexData;
normal.z = vertexData;
_mVertexNormal.push_back( normal );
} }
else if(c=="f") else if( typeOfData == "f" )
{ {
readFace(offset, s, face); inStream >> face1;
stringSplit( face1 );
addToOBJarray();
vertex1.Position = vList[(int)face[0].x]; inStream >> face2;
vertex1.UV = uvList[(int)face[0].y]; stringSplit( face2 );
vertex1.Normal = nList[(int)face[0].z];
vertex2.Position = vList[(int)face[1].x]; addToOBJarray();
vertex2.UV = uvList[(int)face[1].y];
vertex2.Normal = nList[(int)face[1].z];
vertex3.Position = vList[(int)face[2].x]; inStream >> face3;
vertex3.UV = uvList[(int)face[2].y]; stringSplit( face3 );
vertex3.Normal = nList[(int)face[2].z];
VertexList.push_back(vertex1); addToOBJarray();
VertexList.push_back(vertex3);
VertexList.push_back(vertex2);
}
else if(c=="mtllib")
{
this->materials = GetMaterials(path+s.substr(offset+1));
} }
} }
} }
input.close(); inStream.close();
this->numVertices = VertexList.size();
this->vertices = new Vertex[this->numVertices];
for(size_t i=0;i<this->numVertices;++i)
{
vertices[i].Position=Math::transformVector(Math::Float4(VertexList[i].Position,1),transform);
vertices[i].Normal=Math::transformVector(Math::Float4(VertexList[i].Normal,0),transform);
vertices[i].UV = VertexList[i].UV;
}
} }
void ObjReader::GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &Textures) //Private functions
void OBJReader::stringSplit( string strToSplit )
{ {
numVertex=(int)this->numVertices; char delim = '/';
(*vertex)=this->vertices; string vPos, vNormal, vTexel;
Textures = this->materials; stringstream aStream(strToSplit);
getline( aStream, vPos, delim );
getline( aStream, vTexel, delim );
getline( aStream, vNormal );
_mPos = atoi( vPos.c_str() );
_mNormal = atoi( vNormal.c_str() );
_mTexel = atoi( vTexel.c_str() );
} }
Float3 ObjReader::extract(std::string d) void OBJReader::addToOBJarray()
{ {
Float3 data; OBJFormat temp;
int offset=(int)d.find('/');
data.x=(float)atoi(d.substr(1,offset).c_str())-1;
int newOffset = (int)d.find('/',offset+1); temp._d3VertexCoord = _mVertexCoord.at( _mPos - 1 );
string d2=d.substr(offset+1,newOffset-offset-1); temp._d3VertexNormal = _mVertexNormal.at( _mNormal - 1 );
data.y=(float)atoi(d2.c_str())-1; temp._d3VertexTexture = _mVertexTexture.at( _mTexel - 1 );
offset=newOffset;
newOffset = (int)d.find('/',offset+1); _myOBJ.push_back( temp );
string d3=d.substr(offset+1,newOffset-offset-1); }
data.z=(float)atoi(d3.c_str())-1;
return data;
}
Float3 ObjReader::readVertex(int offset,string s)
{
int newOffset = (int)s.find(' ',offset+1);
Float3 vertex;
string d = s.substr(offset,newOffset-offset);
vertex.x = (float)atof(d.c_str());
offset=newOffset;
newOffset = (int)s.find(' ',offset+1);
vertex.y = (float)atof(s.substr(offset,newOffset-offset).c_str());
offset=newOffset;
newOffset = (int)s.find(' ',offset+1);
vertex.z = (float)-atof(s.substr(offset,newOffset-offset).c_str());
return vertex;
}
Float2 ObjReader::readUV(int offset,string s)
{
int newOffset = (int)s.find(' ',offset+1);
Float2 uv;
string d = s.substr(offset,newOffset-offset);
uv.x =(float)atof(d.c_str());
offset=newOffset;
newOffset = (int)s.find(' ',offset+1);
d = s.substr(offset,newOffset-offset);
uv.y =1- (float)atof(d.c_str());
offset=newOffset;
return uv;
}
Float3 ObjReader::readNormal(int offset,string s)
{
int newOffset = (int)s.find(' ',offset+1);
Float3 vertex;
string d = s.substr(offset,newOffset-offset);
vertex.x = (float)atof(d.c_str());
offset=newOffset;
newOffset = (int)s.find(' ',offset+1);
vertex.y = (float)atof(s.substr(offset,newOffset-offset).c_str());
offset=newOffset;
newOffset = (int)s.find(' ',offset+1);
vertex.z = (float)-atof(s.substr(offset,newOffset-offset).c_str());
return vertex;
}
void ObjReader::readFace(int offset,string s, Oyster::Math::Float3 face[3])
{
int newOffset = (int)s.find(' ',offset+1);
string point1 = s.substr(offset,newOffset-offset);
offset = newOffset;
newOffset = (int)s.find(' ',offset+1);
string point2 = s.substr(offset,newOffset-offset);
offset = newOffset;
newOffset = (int)s.find(' ',offset+1);
string point3 = s.substr(offset,newOffset-offset);
face[0] = extract(point1);
face[1] = extract(point2);
face[2] = extract(point3);
}
std::map<std::string, ID3D11ShaderResourceView *> ObjReader::GetMaterials(std::string fileName)
{
ifstream input;
input.open(fileName.c_str());
std::map<std::string, ID3D11ShaderResourceView *> materials;
ID3D11ShaderResourceView *srv;
string texture;
string s;
string path;
Utility::String::extractDirPath(path,fileName,'\\');
if(!input.is_open())
return materials;
while(!input.eof())
{
getline(input,s);
int offset = (int)s.find(' ');
if(offset!=-1)
{
string c = s.substr(0,offset);
if(c=="map_Kd")
{
texture = path+s.substr(offset+1);
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
materials["Diffuse"] = srv;
}
if(c=="map_G")
{
texture = path+s.substr(offset+1);
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
materials["Glow"] = srv;
}
if(c=="map_Ks")
{
texture = path+s.substr(offset+1);
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
materials["Specular"] = srv;
}
}
}
input.close();
return materials;
}

View File

@ -1,42 +1,53 @@
#pragma once #ifndef OBJREADER_H
#include "..\Core\CoreIncludes.h" #define OBJREADER_H
#include "..\Math\OysterMath.h" #include "..\..\Misc\Utilities.h"
#include "..\..\OysterMath\OysterMath.h"
namespace Oyster //#include <fstream>
class OBJReader
{ {
namespace FileLoaders public:
{ struct OBJFormat
class ObjReader
{ {
public: Oyster::Math::Float3 _d3VertexCoord;
struct Vertex Oyster::Math::Float2 _d3VertexTexture;
{ Oyster::Math::Float3 _d3VertexNormal;
Oyster::Math::Float3 Position;
Oyster::Math::Float3 Normal;
Oyster::Math::Float2 UV;
};
static ObjReader *LoadFile(std::string fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
ObjReader(void);
~ObjReader(void);
void GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &textures);
private:
Vertex *vertices;
size_t numVertices;
std::map<std::string, ID3D11ShaderResourceView *> materials;
void ParseFile(std::string fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
Oyster::Math::Float3 extract(std::string d);
Oyster::Math::Float3 readVertex(int offset,std::string s);
Oyster::Math::Float2 readUV(int offset,std::string s);
Oyster::Math::Float3 readNormal(int offset,std::string s);
void readFace(int offset,std::string s, Oyster::Math::Float3 face[3]);
std::map<std::string, ID3D11ShaderResourceView *> GetMaterials(std::string fileName);
}; };
}
} struct OBJMaterialData
{
string _name;
string _mapKd;
float _kd[3];
float _ka[3];
float _tf[3];
float _ni;
OBJMaterialData()
{
_name = " ";
_mapKd = " ";
}
};
std::vector<OBJFormat> _myOBJ;
private:
vector<Oyster::Math::Float3> _mVertexCoord, _mVertexNormal;
vector<Oyster::Math::Float2> _mVertexTexture;
int _mNrOfCoords, _mNrOfNormals, _mNrOfTexels, _mNrOfFaces;
int _mPos, _mNormal, _mTexel;
void stringSplit( string strToSplit );
void addToOBJarray();
public:
OBJReader();
~OBJReader();
void readOBJFile( wstring fileName);
};
#endif

View File

@ -69,6 +69,9 @@
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(WindowsSDK_IncludePath);$(VCInstallDir)atlmfc\include;$(VCInstallDir)include</IncludePath>
<LibraryPath>$(WindowsSDK_LibraryPath_x86);$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</LibraryPath>
<ExecutablePath>$(VCInstallDir)bin;$(WindowsSDK_ExecutablePath_x86);$(VSInstallDir)Common7\Tools\bin;$(VSInstallDir)Common7\tools;$(VSInstallDir)Common7\ide;$(ProgramFiles)\HTML Help Workshop;$(MSBuildToolsPath32);$(VSInstallDir);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH)</ExecutablePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
@ -79,6 +82,10 @@
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(WindowsSDK_IncludePath);$(VCInstallDir)atlmfc\include;$(VCInstallDir)include</IncludePath>
<LibraryPath>$(WindowsSDK_LibraryPath_x86);$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</LibraryPath>
<ExecutablePath>$(VCInstallDir)bin;$(WindowsSDK_ExecutablePath_x86);$(VSInstallDir)Common7\Tools\bin;$(VSInstallDir)Common7\tools;$(VSInstallDir)Common7\ide;$(ProgramFiles)\HTML Help Workshop;$(MSBuildToolsPath32);$(VSInstallDir);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH)</ExecutablePath>
<ReferencePath>$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</ReferencePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
@ -101,7 +108,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OysterPhysic3D\Collision;..\OysterPhysics3D;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -142,6 +149,7 @@
<ClCompile Include="Core\Core.cpp" /> <ClCompile Include="Core\Core.cpp" />
<ClCompile Include="Core\ShaderManager.cpp" /> <ClCompile Include="Core\ShaderManager.cpp" />
<ClCompile Include="Engine.cpp" /> <ClCompile Include="Engine.cpp" />
<ClCompile Include="FileLoader\ObjReader.cpp" />
<ClCompile Include="Render\Model.cpp" /> <ClCompile Include="Render\Model.cpp" />
<ClCompile Include="Render\TextBox.cpp" /> <ClCompile Include="Render\TextBox.cpp" />
<ClCompile Include="Resourses\Buffers.cpp" /> <ClCompile Include="Resourses\Buffers.cpp" />

View File

@ -45,6 +45,9 @@
<ClCompile Include="Core\ShaderManager.cpp"> <ClCompile Include="Core\ShaderManager.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="FileLoader\ObjReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Core\Buffer.h"> <ClInclude Include="Core\Buffer.h">

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
#v4.0:v110:false #v4.0:v110:false
Debug|Win32|C:\DanBias\Danbias\| Debug|Win32|C:\Users\Tobias\Documents\GitHub\Danbias\|

View File

@ -1,13 +1,17 @@
Build started 11/15/2013 11:04:26 AM. Build started 2013-11-19 09:36:20.
1>Project "C:\DanBias\Danbias\Tester\Tester.vcxproj" on node 3 (Build target(s)). 1>Project "C:\Users\Tobias\Documents\GitHub\Danbias\Tester\Tester.vcxproj" on node 2 (Build target(s)).
1>Link: 1>InitializeBuildStatus:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\DanBias\Danbias\Debug\Tester.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\DanBias\Danbias\Debug\Tester.pdb" /SUBSYSTEM:WINDOWS /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\DanBias\Danbias\Debug\Tester.lib" /MACHINE:X86 Debug\MainTest.obj Creating "Debug\Tester.unsuccessfulbuild" because "AlwaysCreate" was specified.
C:\DanBias\External\Lib\Misc\Misc_x86D.lib ClCompile:
C:\DanBias\External\Lib\OysterMath\OysterMath_x86D.lib All outputs are up-to-date.
C:\DanBias\External\Lib\OysterGraphics\OysterGraphics_x86D.lib Link:
Tester.vcxproj -> C:\DanBias\Danbias\Debug\Tester.exe All outputs are up-to-date.
1>Done Building Project "C:\DanBias\Danbias\Tester\Tester.vcxproj" (Build target(s)). Tester.vcxproj -> C:\Users\Tobias\Documents\GitHub\Danbias\Debug\Tester.exe
FinalizeBuildStatus:
Deleting file "Debug\Tester.unsuccessfulbuild".
Touching "Debug\Tester.lastbuildstate".
1>Done Building Project "C:\Users\Tobias\Documents\GitHub\Danbias\Tester\Tester.vcxproj" (Build target(s)).
Build succeeded. Build succeeded.
Time Elapsed 00:00:00.98 Time Elapsed 00:00:00.30

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -41,6 +41,9 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>$(WindowsSDK_IncludePath);$(VCInstallDir)atlmfc\include;$(VCInstallDir)include</IncludePath>
<LibraryPath>$(WindowsSDK_LibraryPath_x86);$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</LibraryPath>
<ExecutablePath>$(VCInstallDir)bin;$(WindowsSDK_ExecutablePath_x86);$(VSInstallDir)Common7\Tools\bin;$(VSInstallDir)Common7\tools;$(VSInstallDir)Common7\ide;$(ProgramFiles)\HTML Help Workshop;$(MSBuildToolsPath32);$(VSInstallDir);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH)</ExecutablePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>