tmp
This commit is contained in:
parent
e161fffc0c
commit
2160dfca34
22 changed files with 339 additions and 157 deletions
44
3DEditor/applications/Entry.cpp
Normal file
44
3DEditor/applications/Entry.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
#include "EditorWidget.hpp"
|
||||
|
||||
#include "GraphicApplication.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
bool loadMeshes(tp::Scene& scene, const std::string& objetsPath);
|
||||
|
||||
class EditorGUI : public Application {
|
||||
public:
|
||||
EditorGUI() {
|
||||
Vec2F renderResolution = { 1000, 1000 };
|
||||
auto canvas = this->mGraphics->getCanvas();
|
||||
mGui = new EditorWidget<EventHandler, Canvas>(canvas, &geometry, renderResolution);
|
||||
|
||||
loadMeshes(geometry, "rsc/scene.obj");
|
||||
|
||||
geometry.mCamera.lookAtPoint({ 0, 0, 0 }, { 3, 3, 2 }, { 0, 0, 1 });
|
||||
}
|
||||
|
||||
~EditorGUI() override { delete mGui; }
|
||||
|
||||
void processFrame(EventHandler* eventHandler) override {
|
||||
auto rec = RectF({ 0, 0 }, mWindow->getSize());
|
||||
mGui->proc(*eventHandler, rec, rec);
|
||||
}
|
||||
|
||||
void drawFrame(Canvas* canvas) override { mGui->draw(*canvas); }
|
||||
|
||||
private:
|
||||
Scene geometry;
|
||||
EditorWidget<EventHandler, Canvas>* mGui;
|
||||
};
|
||||
|
||||
int main() {
|
||||
GlobalGUIConfig mConfig;
|
||||
gGlobalGUIConfig = &mConfig;
|
||||
|
||||
{
|
||||
EditorGUI gui;
|
||||
gui.run();
|
||||
}
|
||||
}
|
||||
41
3DEditor/applications/SceneLoad.cpp
Normal file
41
3DEditor/applications/SceneLoad.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "Scene.hpp"
|
||||
|
||||
#include "obj/OBJ_Loader.h"
|
||||
#include <filesystem>
|
||||
|
||||
bool loadMeshes(tp::Scene& scene, const std::string& objetsPath) {
|
||||
using namespace tp;
|
||||
|
||||
objl::Loader Loader;
|
||||
|
||||
if (!Loader.LoadFile(objetsPath.c_str())) {
|
||||
std::cout << "Failed to Load File. May have failed to find it or it was not an .obj file.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& curMesh : Loader.LoadedMeshes) {
|
||||
scene.mObjects.append(Object());
|
||||
|
||||
auto object = &scene.mObjects.last();
|
||||
|
||||
for (auto& vertex : curMesh.Vertices) {
|
||||
// printf("{ %f, %f, %f }, \n", vertex.Position.X, vertex.Position.Y, vertex.Position.Z);
|
||||
object->mTopology.Points.append(Vec3F{ vertex.Position.X, vertex.Position.Y, vertex.Position.Z });
|
||||
object->mTopology.Normals.append(Vec3F{ vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z });
|
||||
}
|
||||
|
||||
for (int j = 0; j < curMesh.Indices.size(); j += 3) {
|
||||
uint idx1 = (int) curMesh.Indices[j];
|
||||
uint idx2 = (int) curMesh.Indices[j + 1];
|
||||
uint idx3 = (int) curMesh.Indices[j + 2];
|
||||
// printf("{ %i, %i, %i },\n", idx1, idx2, idx3);
|
||||
object->mTopology.Indexes.append({ idx1, idx2, idx3 });
|
||||
}
|
||||
|
||||
if (object->mTopology.Normals.size() != object->mTopology.Points.size()) {
|
||||
printf("Logic error loading normals\n");
|
||||
}
|
||||
}
|
||||
|
||||
return scene.mObjects.size();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue