void TextureEditor::update(ofEventArgs& args) { if (surface == NULL) return; // update surface if one of the joints is being dragged ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), surface->getSource()->getTexture()->getHeight()); // Get selected joint index int selectedJointIndex = 0; bool bJointSelected = false; for (int i = 0; i < joints.size(); i++) { if (joints[i]->isDragged() || joints[i]->isSelected()) { selectedJointIndex = i; bJointSelected = true; break; } } // for // Constrain quad texture selection if (joints.size() == 4) { if (bJointSelected) { constrainJointsToQuad(selectedJointIndex); for (int i = 0; i < joints.size(); i++) { surface->setTexCoord(i, joints[i]->position / textureSize); } } // if } else { if (bJointSelected) { surface->setTexCoord(selectedJointIndex, joints[selectedJointIndex]->position / textureSize); } } // else }
void TextureEditorWidget::update(){ if(surface == 0){ return; } if(_pollCreateJoints){ createJoints(); } // update surface if one of the joints is being dragged Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(), surface->getSource()->getTexture()->getHeight()); // Get selected joint index int selectedJointIndex = 0; bool bJointSelected = false; for(int i = 0; i < joints.size(); i++){ if(joints[i]->isDragged() || joints[i]->isSelected()){ selectedJointIndex = i; bJointSelected = true; break; } } // for // Constrain quad texture selection if(joints.size() == 4){ if(bJointSelected){ constrainJointsToQuad(selectedJointIndex); if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){ GridWarpSurface * s = (GridWarpSurface *)surface; std::vector<Vec2> texCoords = surface->getTexCoords(); Vec2 textureSize = Vec2( surface->getSource()->getTexture()->getWidth(), surface->getSource()->getTexture()->getHeight()); int rows = s->getGridRows(); int cols = s->getGridCols(); int vertsPerRow = cols + 1; // Distance between horizontal tex coords float sx = joints[0]->position.x / textureSize.x; float ex = joints[1]->position.x / textureSize.x; float dx = (ex - sx) / (float)cols; // Distance between vertical tex coords float sy = joints[0]->position.y / textureSize.y; float ey = joints[2]->position.y / textureSize.y; float dy = (ey - sy) / (float)rows; int i = 0; for(int iy = 0; iy <= rows; ++iy){ for(int ix = 0; ix <= cols; ++ix){ Vec2 t; t.x = sx + dx * ix; t.y = sy + dy * iy; surface->setTexCoord(i, t); ++i; } } }else{ for(int i = 0; i < joints.size(); i++){ surface->setTexCoord(i, joints[i]->position / textureSize); } } } // if }else{ if(bJointSelected){ surface->setTexCoord(selectedJointIndex, joints[selectedJointIndex]->position / textureSize); } } // else }