Figured out texturing problems

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 4d48e2653e
commit d1cb4f97c5
  1. 20
      Artisans Hub.mtl
  2. 15078
      Artisans Hub.obj
  3. BIN
      Body.png
  4. BIN
      C++ProjectTemplate
  5. BIN
      High.png
  6. BIN
      ffdtex0.png
  7. BIN
      ffdtex1.png
  8. 109
      main.cpp
  9. 4123
      tonberry.obj
  10. 1242
      tonberry1.obj
  11. 1283
      tonberry2.obj

@ -0,0 +1,20 @@
# Exported from Wings 3D 2.2.9
newmtl Material.001
Ns 19.999999999999996
d 1.0
illum 2
Kd 0.512 0.512 0.512
Ka 0.0 0.0 0.0
Ks 0.21746077093979083 0.21746077093979083 0.21746077093979083
Ke 0.0 0.0 0.0
map_Kd High.png
newmtl default
Ns 19.999999999999996
d 1.0
illum 2
Kd 0.7898538076923077 0.8133333333333334 0.6940444444444445
Ka 0.0 0.0 0.0
Ks 0.1689853807692308 0.17133333333333334 0.15940444444444446
Ke 0.0 0.0 0.0

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 KiB

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

@ -31,6 +31,17 @@ struct triangle
struct mesh struct mesh
{ {
std::vector<triangle> tris; std::vector<triangle> tris;
Decal*texture;
void Parse(std::string str,int&v,int&uv) {
std::cout<<str<<"\n";
std::stringstream s(str.substr(0,str.find("/")+1));
s>>v;
str.erase(0,str.find("/")+1);
std::stringstream s2(str.substr(0,str.find("/")+1));
s2>>uv;
//std::cout<<" "<<v<<"/"<<uv<<"\n";
}
bool LoadFromObjectFile(std::string sFilename) bool LoadFromObjectFile(std::string sFilename)
{ {
@ -42,67 +53,33 @@ struct mesh
std::vector<vec3d> verts; std::vector<vec3d> verts;
std::vector<vec2d> uvs; std::vector<vec2d> uvs;
while (!f.eof()) std::string data;
{ while (f.good()) {
char line[128]; f>>data;
f.getline(line, 128); if (data=="v") {
float x,y,z;
std::strstream s; f>>x>>y>>z;
s << line; verts.push_back({x,y,z});
//std::cout<<x<<" "<<y<<" "<<z<<"\n";
char junk; } else
if (data=="vt") {
if (line[0] == 'v') float u,v;
{ f>>u>>v;
if (line[1]=='t') { uvs.push_back({u,v});
vec2d v; //std::cout<<u<<" "<<v<<"\n";
s >> junk >> junk >> v.u >> v.v; } else
uvs.push_back(v); if (data=="f") {
//std::cout<<"Line: "<<line<<"\n"; //std::cout<<"face\n";
//std::cout<<"Tex coords: "<<v.u<<","<<v.v<<"\n"; std::string t1,t2,t3;
} else f>>t1>>t2>>t3;
if (line[1] != 'n') int v1,v2,v3,uv1,uv2,uv3;
{ Parse(t1,v1,uv1);
vec3d v; Parse(t2,v2,uv2);
s >> junk >> v.x >> v.y >> v.z; Parse(t3,v3,uv3);
verts.push_back(v); tris.push_back({verts[v1-1],verts[v2-1],verts[v3-1],
//std::cout<<"Line: "<<line<<"\n"; uvs[uv1-1],uvs[uv2-1],uvs[uv3-1]});
//std::cout<<"Vertex: "<<v.x<<","<<v.y<<","<<v.z<<"\n";
}
} }
if (line[0] == 'f')
{
s >> junk;
std::string tokens[9];
int nTokenCount = -1;
while (!s.eof())
{
char c = s.get();
if (c == ' ' || c == '/')
nTokenCount++;
else
tokens[nTokenCount].append(1, c);
}
tokens[nTokenCount].pop_back();
triangle newtri{ verts[stoi(tokens[0]) - 1], verts[stoi(tokens[3]) - 1], verts[stoi(tokens[6]) - 1],
uvs[stoi(tokens[1]) - 1], uvs[stoi(tokens[4]) - 1], uvs[stoi(tokens[7]) - 1]};
if (newtri.p[0].y>16||newtri.p[1].y>16||newtri.p[2].y>16) {
newtri.col=WHITE;
} else
if (newtri.p[0].y>10||newtri.p[1].y>10||newtri.p[2].y>10) {
newtri.col=DARK_GREEN;
} else
if (newtri.p[0].y>6||newtri.p[1].y>6||newtri.p[2].y>6) {
newtri.col=Pixel(56, 38, 39);
} else {
newtri.col=Pixel(0,100,255);
}
tris.push_back(newtri);
}
} }
return true; return true;
@ -461,8 +438,8 @@ private:
public: public:
bool OnUserCreate() override bool OnUserCreate() override
{ {
//texture = new Decal(new Sprite("Body.png")); texture = new Decal(new Sprite("High.png"));
meshCube.LoadFromObjectFile("obj_1.obj"); meshCube.LoadFromObjectFile("Artisans Hub.obj");
matProj=Matrix_MakeProjection(90.0f,(float)ScreenHeight() / (float)ScreenWidth(),0.1f,1000.0f); matProj=Matrix_MakeProjection(90.0f,(float)ScreenHeight() / (float)ScreenWidth(),0.1f,1000.0f);
@ -477,7 +454,7 @@ public:
if (GetKey(olc::UP).bHeld) { if (GetKey(olc::UP).bHeld) {
pitch+=1*fElapsedTime; pitch+=1*fElapsedTime;
} }
vec3d vForward=Vector_Mul(vLookDir,8*fElapsedTime); vec3d vForward=Vector_Mul(vLookDir,20*fElapsedTime);
if (GetKey(olc::W).bHeld) { if (GetKey(olc::W).bHeld) {
vCamera=Vector_Add(vCamera,vForward); vCamera=Vector_Add(vCamera,vForward);
} }
@ -534,10 +511,10 @@ public:
vec3d vCameraRay=Vector_Sub(triTransformed.p[0],vCamera); vec3d vCameraRay=Vector_Sub(triTransformed.p[0],vCamera);
if (Vector_DotProduct(normal,vCameraRay)<0) { if (Vector_DotProduct(normal,vCameraRay)<0) {
vec3d light_dir=Vector_Mul(vCameraRay,-1); vec3d light_dir=Vector_Mul(vLookDir,-1);
light_dir=Vector_Normalise(light_dir); light_dir=Vector_Normalise(light_dir);
float dp = std::max(0.1f,Vector_DotProduct(light_dir,normal)); float dp = std::max(0.7f,Vector_DotProduct(light_dir,normal));
triViewed.p[0]=Matrix_MultiplyVector(matView,triTransformed.p[0]); triViewed.p[0]=Matrix_MultiplyVector(matView,triTransformed.p[0]);
triViewed.p[1]=Matrix_MultiplyVector(matView,triTransformed.p[1]); triViewed.p[1]=Matrix_MultiplyVector(matView,triTransformed.p[1]);
@ -545,7 +522,7 @@ public:
triViewed.uv[0]=triTransformed.uv[0]; triViewed.uv[0]=triTransformed.uv[0];
triViewed.uv[1]=triTransformed.uv[1]; triViewed.uv[1]=triTransformed.uv[1];
triViewed.uv[2]=triTransformed.uv[2]; triViewed.uv[2]=triTransformed.uv[2];
triViewed.col=Pixel(tri.col.r*dp*dp,tri.col.g*dp*dp,tri.col.b*dp*dp); triViewed.col=Pixel(255*dp*dp,255*dp*dp,255*dp*dp);
int nClippedTriangles = 0; int nClippedTriangles = 0;
triangle clipped[2]; triangle clipped[2];
@ -647,7 +624,7 @@ public:
// Rasterize triangle // Rasterize triangle
SetDecalStructure(DecalStructure::LIST); SetDecalStructure(DecalStructure::LIST);
SetDecalMode(DecalMode::NORMAL); SetDecalMode(DecalMode::NORMAL);
DrawPolygonDecal(nullptr,{ DrawPolygonDecal(texture,{
{t.p[0].x, t.p[0].y}, {t.p[0].x, t.p[0].y},
{t.p[1].x, t.p[1].y}, {t.p[1].x, t.p[1].y},
{t.p[2].x, t.p[2].y} {t.p[2].x, t.p[2].y}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save