Started working on parsing OBJ Files.

Why string manipulation is so tedious in C/++ :(
This commit is contained in:
Godzil
2020-03-05 17:46:40 +00:00
parent 6bef6a1b77
commit c17bfadc76
8 changed files with 256 additions and 6 deletions

51
source/include/objfile.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* DoRayMe - a quick and dirty Raytracer
* OBJ File header
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#ifndef DORAYME_OBJFILE_H
#define DORAYME_OBJFILE_H
#include <shape.h>
#include <renderstat.h>
class OBJFile : public Shape
{
private:
uint32_t allocatedFaceGroupCount;
Shape* *faceGroupList;
uint32_t faceGroupCount;
uint32_t allocatedVertexCount;
Tuple* *vertexList;
uint32_t vertexCount;
private:
Intersect localIntersect(Ray r);
Tuple localNormalAt(Tuple point);
public:
/* Some stats */
uint32_t ignoredLines;
protected:
void addGroup(Shape *group);
void addVertex(Tuple *vertex);
BoundingBox bounds;
public:
OBJFile();
OBJFile(const char *filepath);
int parseOBJFile(const char *content);
BoundingBox getLocalBounds();
bool haveFiniteBounds() { return true; };
};
#endif /* DORAYME_OBJFILE_H */

View File

@@ -15,13 +15,14 @@ class RenderStats
{
private:
uint64_t coneCount; /* Total number of cones */
uint64_t cylinderCount; /* Total number of cylinder */
uint64_t cylinderCount; /* Total number of cylinder */
uint64_t cubeCount; /* Total number of cubes */
uint64_t groupCount; /* Total number of groups */
uint64_t lightCount; /* Total number of light */
uint64_t planeCount; /* Total number of plane */
uint64_t sphereCount; /* Total number of sphere */
uint64_t triangleCount; /* Total number of triangle */
uint64_t triangleCount; /* Total number of triangle */
uint64_t objfileCount; /* Total number of OBJ File */
uint64_t pixelCount; /* Total number of rendered pixels */
uint64_t rayCount; /* Total number of rays */
@@ -40,7 +41,7 @@ public:
RenderStats() : coneCount(0), cylinderCount(0), cubeCount(0), groupCount(0), lightCount(0), planeCount(0), sphereCount(0), triangleCount(0),
pixelCount(0), rayCount(0), lightRayEmitedCount(0), reflectionRayCount(0), refractedRayCount(0),
intersectCount(0), intersectionCount(0), reallocCallCount(0), mallocCallCount(0),
discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0) {};
discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0), objfileCount(0) {};
#ifdef RENDER_STATS
void addCone();
void addCylinder();
@@ -49,6 +50,7 @@ public:
void addLight();
void addPlane();
void addSphere();
void addOBJFile();
void addTriangle();
void printStats();
void addPixel();
@@ -85,6 +87,7 @@ public:
static void addMalloc() {};
static void addRealloc() {};
static void setMaxIntersect(uint32_t count) {};
static void void RenderStats::addOBJFile() {};
#endif
};

View File

@@ -29,7 +29,7 @@ enum ShapeType
SHAPE_CONE,
SHAPE_GROUP,
SHAPE_TRIANGLE,
SHAPE_OBJFILE,
};
/* Base class for all object that can be presented in the world */