#include "ik.hpp"
#include "blendshapes.hpp"
#include "ui.hpp"
+#include "mode/animationMode.hpp"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
BlendshapeModel bsModel;
bool playBlendshapeAnim = false;
-struct Light {
- glm::mat4 trans;
- glm::vec3 color;
-};
-
-std::vector<Light> lights;
-
-bool discoLights = false;
-
int windowWidth = 800, windowHeight = 600;
float aspect() {
return (float)windowWidth / (float)windowHeight;
glDrawArrays(GL_TRIANGLES, 0, 36);
}
-void drawLight(Light &light) {
- drawPlainProg(plainProg, lightVao, light.trans, light.color);
-}
-
int findNodeTrans(const struct aiNode *n, const struct aiString name, glm::mat4 *dest) {
if (strcmp(n->mName.data, name.data) == 0) {
*dest = aiMatrixToMat4(n->mTransformation);
keyStates[key] = true;
if (key == 'z')
activeSkybox = (activeSkybox + 1) % skyboxes.size();
- if (key == 'c')
- discoLights = !discoLights;
+ /* if (key == 'c') */
+ /* discoLights = !discoLights; */
}
void keyboardUp(unsigned char key, int x, int y) {
int mouseX, mouseY;
-struct Mode {
- virtual void display(float d) = 0;
- virtual void timer() = 0;
- virtual void motion(int x, int y, int dx, int dy) = 0;
- virtual void passiveMotion(int x, int y, int dx, int dy) = 0;
- virtual void mouse(int button, int state, int x, int y) = 0;
-};
-
-struct AnimationMode : public Mode {
- Model *sceneModel;
-
- AnimationMode(std::string modelPath) {
- const aiScene *scene = importer.ReadFile(
- modelPath, aiProcess_Triangulate | aiProcess_CalcTangentSpace |
- aiProcess_GenNormals | aiProcess_FlipUVs);
- if (!scene) {
- std::cerr << importer.GetErrorString() << std::endl;
- exit(1);
- }
-
- if (scene->mNumCameras > 0) {
- aiCamera *cam = scene->mCameras[0];
- glm::mat4 camTrans;
- if (findNodeTrans(scene->mRootNode, cam->mName, &camTrans) != 0)
- abort(); // there must be a node with the same name as camera
-
- camPos = {camTrans[3][0], camTrans[3][1], camTrans[3][2]};
-
- glm::vec3 camLookAt =
- glm::vec3(cam->mLookAt.x, cam->mLookAt.y, cam->mLookAt.z);
- camFront = camLookAt - camPos;
-
- camUp = glm::vec3(cam->mUp.x, cam->mUp.y, cam->mUp.z);
-
- fov = cam->mHorizontalFOV;
- // TODO: aspectRatio = cam->mAspect;
- znear = cam->mClipPlaneNear;
- zfar = cam->mClipPlaneFar;
- }
-
- for (int i = 0; i < scene->mNumLights; i++) {
- aiLight *light = scene->mLights[i];
- glm::mat4 trans;
- findNodeTrans(scene->mRootNode, light->mName, &trans);
- glm::vec3 col = {light->mColorAmbient.r, light->mColorAmbient.g,
- light->mColorAmbient.b};
- Light l = {trans, col};
- lights.push_back(l);
- }
-
- sceneModel = new Model(scene, *pbrProg);
- }
-
- void display(float d) override {
- sceneModel->draw(skyboxes[activeSkybox], d * 1000);
- }
-
- void timer() override {};
- void motion(int x, int y, int dx, int dy) override {}
- void passiveMotion(int x, int y, int dx, int dy) override {}
- void mouse(int button, int state, int x, int y) override {}
-};
-
-
// TODO: move these inside
bool needToCalculateClosestVertex = false;
bool needToInterpolateBlendshapes = false;
glUseProgram(pbrProg->progId);
setProjectionAndViewUniforms(pbrProg->progId);
- size_t numLights = lights.size() + (discoLights ? 3 : 0);
+ std::vector<Light> lights = curMode->getLights(d);
glm::vec3 lightPositions[numLights], lightColors[numLights];
for (int i = 0; i < lights.size(); i++) {
lightPositions[i] = glm::vec3(lights[i].trans[3]);
lightColors[i] = lights[i].color;
}
- if (discoLights) {
- for (int i = numLights - 3; i < numLights; i++) {
- auto m = glm::translate(glm::mat4(1.f), glm::vec3(-2.5, 0, 0));
- m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(1, 0, 0));
- m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(0, 1, 0));
- m = glm::rotate(m, glm::radians(d * 100 + i * 30), glm::vec3(0, 0, 1));
- lightPositions[i] = glm::vec3(m * glm::vec4(5, 0, 0, 1));
- lightColors[i] = glm::vec3(0.2);
- if (i % 3 == 0) lightColors[i].x = sin(d);
- if (i % 3 == 1) lightColors[i].y = cos(d * 3);
- if (i % 3 == 2) lightColors[i].z = cos(d);
- }
- }
glUniform1ui(glGetUniformLocation(pbrProg->progId, "numLights"), numLights);
glUniform3fv(glGetUniformLocation(pbrProg->progId, "lightPositions"), numLights, glm::value_ptr(lightPositions[0]));
curMode->display(d);
- for (Light &light: lights) drawLight(light);
-
// TODO: restore
/* if (discoLights) { */
/* for (int i = numLights - 3; i < numLights; i++) { */