+GLuint setupBuffersWithIndices(GLuint progId, GLuint vao,
+ std::vector<glm::vec3> vertices,
+ std::vector<GLuint> indices) {
+ GLuint vbos[2];
+ glBindVertexArray(vao);
+ glGenBuffers(2, vbos);
+
+ int verticesSize = vertices.size() * sizeof(glm::vec3);
+ // positions
+ glBindBuffer(GL_ARRAY_BUFFER, vbos[0]);
+ glBufferData(GL_ARRAY_BUFFER, verticesSize, NULL, GL_STATIC_DRAW);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, verticesSize,
+ glm::value_ptr(vertices[0]));
+
+ GLuint posLoc = glGetAttribLocation(progId, "vPosition");
+ glEnableVertexAttribArray(posLoc);
+ glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
+
+ // indices
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[1]);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_STATIC_DRAW);
+
+ return indices.size();
+}
+
+bool needToCalculateClosestVertex = false;
+bool needToInterpolateBlendshapes = false;
+
+class Delegate : public ControlWindowDelegate {
+ public:
+
+ virtual void weightChanged(int blendshape, float weight) {
+ bsModel.blendshapes[blendshape].weight = weight;
+ needToInterpolateBlendshapes = true;
+ }
+
+ virtual void solveWeights(std::vector<float> &newWeights) {
+ ::solveWeights(&bsModel, manipulators);
+ for (int i = 0; i < newWeights.size(); i++)
+ newWeights[i] = bsModel.blendshapes[i].weight;
+ needToInterpolateBlendshapes = true;
+ }
+
+ virtual void resetManipulators() {
+ manipulators.clear();
+ curManipulator = { -1, -1 };
+ }
+
+ virtual void playbackChanged(bool playing) {
+ playBlendshapeAnim = playing;
+ }
+};
+
+Delegate cwDelegate;
+