-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
358 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# find lib3ds includes and library | ||
# | ||
# LIB3DS_INCLUDE_DIR - where the lib3ds directory containing the headers can be | ||
# found | ||
# LIB3DS_LIBRARY - full path to the lib3ds library | ||
# LIB3DS_FOUND - TRUE if lib3ds was found | ||
|
||
FIND_PATH(LIB3DS_INCLUDE_DIR lib3ds/file.h | ||
/usr/include | ||
/usr/local/include | ||
$ENV{INCLUDE} | ||
) | ||
FIND_LIBRARY(LIB3DS_LIBRARY NAMES 3ds lib3ds) | ||
|
||
IF(LIB3DS_INCLUDE_DIR) | ||
MESSAGE(STATUS "Found lib3ds include dir: ${LIB3DS_INCLUDE_DIR}") | ||
ELSE(LIB3DS_INCLUDE_DIR) | ||
MESSAGE(STATUS "Could NOT find lib3ds headers.") | ||
ENDIF(LIB3DS_INCLUDE_DIR) | ||
|
||
IF(LIB3DS_LIBRARY) | ||
MESSAGE(STATUS "Found lib3ds library: ${LIB3DS_LIBRARY}") | ||
ELSE(LIB3DS_LIBRARY) | ||
MESSAGE(STATUS "Could NOT find lib3ds library.") | ||
ENDIF(LIB3DS_LIBRARY) | ||
|
||
|
||
IF(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) | ||
SET(LIB3DS_FOUND TRUE) | ||
ELSE(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) | ||
SET(LIB3DS_FOUND FALSE) | ||
IF(Lib3ds_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find lib3ds. Please install lib3ds (http://lib3ds.sourceforge.net)") | ||
ENDIF(Lib3ds_FIND_REQUIRED) | ||
ENDIF(LIB3DS_INCLUDE_DIR AND LIB3DS_LIBRARY) | ||
|
||
# vim: et sw=4 ts=4 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "Model3DS.h" | ||
|
||
#include <lib3ds/mesh.h> | ||
#include <lib3ds/vector.h> | ||
|
||
#include <assert.h> | ||
#include <cstring> | ||
|
||
using namespace Engine; | ||
|
||
Model3DS::Model3DS(std::string&& filename) { | ||
this->model = lib3ds_file_load(filename.c_str()); | ||
|
||
if (!model) { | ||
throw "Unable to load model"; | ||
} | ||
} | ||
|
||
Model3DS::~Model3DS() { | ||
|
||
} | ||
|
||
unsigned int Model3DS::getTotalFaces() { | ||
assert(model != NULL); | ||
|
||
unsigned int totalFaces = 0; | ||
Lib3dsMesh* mesh; | ||
for (mesh = this->model->meshes; mesh != NULL; mesh = mesh->next) { | ||
totalFaces += mesh->faces; | ||
} | ||
|
||
return totalFaces; | ||
} | ||
|
||
void Model3DS::createVBO() { | ||
unsigned int totalFaces = getTotalFaces(); | ||
|
||
Lib3dsVector* vertices = new Lib3dsVector[totalFaces * 3]; | ||
Lib3dsVector* normals = new Lib3dsVector[totalFaces * 3]; | ||
Lib3dsMesh* mesh; | ||
|
||
unsigned int finishedFaces = 0; | ||
|
||
for (mesh = this->model->meshes; mesh != NULL; mesh = mesh->next) { | ||
lib3ds_mesh_calculate_normals(mesh, &normals[finishedFaces * 3]); | ||
|
||
for (unsigned int curFace = 0; curFace < mesh->faces; ++curFace) { | ||
Lib3dsFace* face = &mesh->faceL[curFace]; | ||
|
||
for (unsigned int i = 0; i < 3; ++i) { | ||
std::memcpy(&vertices[finishedFaces * 3 + 1], mesh->pointL[face->points[i]].pos, sizeof(Lib3dsVector)); | ||
} | ||
finishedFaces++; | ||
} | ||
} | ||
|
||
unsigned int size = sizeof(Lib3dsVector) * 3 * totalFaces; | ||
|
||
this->vertexVBO.stride = sizeof(Lib3dsVector) * 3; | ||
this->vertexVBO.pushData(vertices, size); | ||
|
||
this->normalsVBO.stride = sizeof(Lib3dsVector) * 3; | ||
this->normalsVBO.pushData(normals, size); | ||
|
||
delete vertices; | ||
delete normals; | ||
|
||
lib3ds_file_free(this->model); | ||
this->model = NULL; | ||
} | ||
|
||
void Model3DS::render() { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <lib3ds/file.h> | ||
#include <GL/glew.h> | ||
|
||
#include "../../Buffer.h" | ||
|
||
#include <string> | ||
|
||
namespace Engine { | ||
class Model3DS { | ||
private: | ||
Lib3dsFile* model; | ||
|
||
unsigned int getTotalFaces(); | ||
public: | ||
Engine::Buffer vertexVBO; | ||
Engine::Buffer normalsVBO; | ||
|
||
Model3DS(std::string&& filename); | ||
~Model3DS(); | ||
void render(); | ||
void createVBO(); | ||
}; | ||
} |
Oops, something went wrong.