Exemple #1
0
void Importer::load(std::string& file, DrawBuffer& s_) {
    std::cout << "Import using Assimp\n";

    // Create an instance of the Importer class
    Assimp::Importer importer;
    // And have it read the given file with some example postprocessing
    // Usually - if speed is not the most important aspect for you - you'll
    // propably to request more postprocessing than we do in this example.
    const aiScene* scene = importer.ReadFile(file,
	    aiProcess_CalcTangentSpace       |
	    aiProcess_Triangulate            |
	    aiProcess_JoinIdenticalVertices  |
	    aiProcess_SortByPType);

    // If the import failed, report it
    if( !scene) {
	std::cout << "fuu: " << importer.GetErrorString() << '\n';
    }
    genMesh(scene, s_);
    //scene->mCameras[0]->GetCameraMatrix(m);
    s_._cameras.emplace_back(s_._fb[0]);
    Camera& mainCamera = s_._cameras[0];
    /*if (scene->mNumCameras) {
	aiCamera* c = scene->mCameras[0];
	std::cout << "position: " << scene->mCameras[0]->mPosition[0] << ' ' << scene->mCameras[0]->mPosition[1] << ' ' << scene->mCameras[0]->mPosition[2] << '\n';
	//c->GetCameraMatrix(m);
	//_mainCamera.setMatrix(aiMatrix4x4ToGlm(m));

	mainCamera.lookAt(glm::vec3(c->mLookAt[0], c->mLookAt[1], c->mLookAt[2]));
	mainCamera.setPos(glm::vec3(c->mPosition[0] / 1.0f, c->mPosition[1] / 1.0f, c->mPosition[2] / 1.0f));
	//_mainCamera.fieldOfview(c->mHorizontalFOV);
	mainCamera.fieldOfview(1.571f);
	mainCamera.clipPlane(glm::vec2(c->mClipPlaneNear, c->mClipPlaneFar));
	mainCamera.upVector(glm::vec3(c->mUp[0], c->mUp[1], c->mUp[2]));
    } else {*/
	std::cout << "no Camera Detected\n";
	mainCamera.lookAt(glm::vec3(.0f, 3.7f, 8.4f)); // Nelo.obj
	//mainCamera.setPos(glm::vec3(-9.3, 4.4f, 15.9)); // Nelo.obj
	mainCamera.setPos(glm::vec3(-15.3, 4.4f, 0.0)); // NeloNOARM.obj

	//mainCamera.lookAt(glm::vec3(59.0f, 131.0f, 582.0f)); // DemoCity.obj
	//mainCamera.setPos(glm::vec3(136.0f, 231.0f, 218.0f)); //DemoCity.obj
	mainCamera.fieldOfview(1.623f);
	mainCamera.clipPlane(glm::vec2(0.1f, 10000.0f));
	mainCamera.upVector(glm::vec3(0.0f,1.0f,0.0f));
	s_._cameras.emplace_back(s_._cameras[0]);
	for(unsigned int i = 0; i < 250; ++i) {
	    s_._cameras.emplace_back(s_._cameras[0]);
	}
    //}
}
Exemple #2
0
void Importer::load(std::string& file, DrawBuffer& s_) {
    std::cout << "Import using tinyObjLoader\n";
    /*
       std::vector<Mesh> Scene::_meshes;
       std::vector<Camera> Scene::_cameras;
       */
    tinyobj::attrib_t attrib;
    std::vector<tinyobj::shape_t> shapes;
    std::vector<tinyobj::material_t> materials;

    std::string err;
    if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, file.c_str())) {
	std::cout << "the file is f****d: " << file << '\n';
    }
    std::cout << "loaded with warning:\n" << err << '\n';

    // Loop over shapes
    s_._meshes.reserve(shapes.size());
    for (tinyobj::shape_t object: shapes) {
	std::cout << "loading: " << object.name << '\n';
	genMesh(object, attrib, s_);
	std::cout << "finished...\n";
    }

    std::cout << "generating cameras\n";
    s_._cameras.emplace_back(s_._fb[0]);
    Camera& mainCamera = s_._cameras[0];

    mainCamera.lookAt(glm::vec3(.0f, 3.7f, 8.4f)); // Nelo.obj
    mainCamera.setPos(glm::vec3(-9.3, 4.4f, 15.9)); // Nelo.obj
    //mainCamera.lookAt(glm::vec3(59.0f, 131.0f, 582.0f)); // DemoCity.obj
    //mainCamera.setPos(glm::vec3(136.0f, 231.0f, 218.0f)); // DemoCity.obj
    mainCamera.fieldOfview(1.623f);
    mainCamera.clipPlane(glm::vec2(0.1f, 10000.0f));
    mainCamera.upVector(glm::vec3(0.0f,1.0f,0.0f));
    //for(unsigned int i = 0; i < 250; ++i) {
    //    s_._cameras.emplace_back(s_._cameras[0]);
    //}
}