示例#1
0
void Palette::updateColour() {
	QColor newColour = QColor( sliderRed->value(), sliderGreen->value(), sliderBlue->value(), sliderAlpha->value() );
	editor->updateColour(currentColour(), newColour);
}
//----------------------------------------------------------------------------------------------------------------------
ImportMesh::ImportMesh(std::string _loc){

    OpenMesh::IO::Options ropt;
    if ( ! OpenMesh::IO::read_mesh(m_mesh, _loc,ropt))
    {
      std::cerr << "Error loading mesh from file " << _loc << std::endl;
    }
    //check to see if Open mesh has behaved and imported useful things
    bool hasNormals = ropt.check(OpenMesh::IO::Options::VertexNormal);
    bool hasTexCoords = ropt.check(OpenMesh::IO::Options::VertexTexCoord);
    bool hasColors = ropt.check(OpenMesh::IO::Options::VertexColor);
    //if not let dynamically add it, not much we can do about texture coords sadly :(
    //need colors though as we are going to use them to store our weights!
    if(!hasNormals) m_mesh.request_vertex_normals();
    if(!hasColors) m_mesh.request_vertex_colors();
    std::cout << "imported VertexNormal" << ( hasNormals ? ": yes\n":": no\n");
    std::cout << "provides VertexTexCoord" << ( hasTexCoords ? ": yes\n":": no\n");

    // mesh structure
    (m_mesh.is_trimesh()) ? std::cout<<"It's triangulated wooo!"<<std::endl :std::cout<<"Triangluate this fool!"<<std::endl;
    // mesh stats
    std::cout << "# Vertices: " << m_mesh.n_vertices() << std::endl;
    std::cout << "# Edges   : " << m_mesh.n_edges() << std::endl;
    std::cout << "# Faces   : " << m_mesh.n_faces() << std::endl;
    // mesh capabilities
    std::cout << "Mesh supports\n";
    std::cout<<"vertex normals: ";(m_mesh.has_vertex_normals()) ? std::cout<<"true"<<std::endl : std::cout<<"false"<<std::endl;
    std::cout<<"vertex colors: ";(m_mesh.has_vertex_colors()) ? std::cout<<"true"<<std::endl : std::cout<<"false"<<std::endl;
    std::cout<<"vertex texcoords: ";(m_mesh.has_vertex_texcoords2D()) ? std::cout<<"true"<<std::endl : std::cout<<"false"<<std::endl;
    std::cout<<"face normals: ";(m_mesh.has_face_normals()) ? std::cout<<"true"<<std::endl : std::cout<<"false"<<std::endl;
    std::cout<<"face colors: ";(m_mesh.has_face_colors()) ? std::cout<<"true"<<std::endl : std::cout<<"false"<<std::endl;

    // put our verticies into our VBO
    MyMesh::Point currentPoint;
    MyMesh::Normal currentNormal;
    MyMesh::Color currentColour(1.0,1.0,0.0);
    std::vector<ngl::Vec3> normals;
    std::vector<ngl::Vec3> colors;
    std::vector<ngl::Vec3> positions;
    ngl::Vec3 e1,e2,fn;
    //iterate over all faces
    for(MyMesh::FaceIter f_it=m_mesh.faces_begin(); f_it!=m_mesh.faces_end(); ++f_it){
        // iterate over every vertex in the face
        for(MyMesh::FaceVertexIter fv_it=m_mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it){
            currentPoint = m_mesh.point(*fv_it);
            positions.push_back(ngl::Vec3(currentPoint[0],currentPoint[1],currentPoint[2]));
            //initialize all our colors aswell
            m_mesh.set_color(*fv_it,currentColour);
            colors.push_back(ngl::Vec3(currentColour[0],currentColour[1],currentColour[2]));
            //if open mesh is being nice and it has normals lets push them back
            if(hasNormals){
                currentNormal = m_mesh.normal(*fv_it);
                normals.push_back(ngl::Vec3(currentNormal[0],currentNormal[1],currentNormal[2]));
            }

        }
        // If open mesh is not being nice and importing normals lets give it some face normals
        if(!hasNormals){
            e1 = positions[positions.size()-2] - positions[positions.size()-1];
            e2 = positions[positions.size()-3] - positions[positions.size()-1];
            fn.cross(e2,e1);
            normals.push_back(fn);
            normals.push_back(fn);
            normals.push_back(fn);
            currentNormal[0] = (float)fn.m_x;
            currentNormal[1] = (float)fn.m_y;
            currentNormal[2] = (float)fn.m_z;
            // stick this information into our half edge structure aswell
            for(MyMesh::FaceVertexIter fv_it=m_mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it){
                m_mesh.set_normal(*fv_it,currentNormal);
            }
        }
    }
    //push the data into our vbo
    std::vector<ngl::Vec3> meshVBO;
    for(unsigned int i=0; i<positions.size();i++){
        meshVBO.push_back(positions[i]);
        meshVBO.push_back(normals[i]);
        meshVBO.push_back(colors[i]);
    }
    //add our data to our VAO
    m_VAO = ngl::VertexArrayObject::createVOA(GL_TRIANGLES);
    m_VAO->bind();
    m_VAO->setData(meshVBO.size()*sizeof(ngl::Vec3), meshVBO[0].m_x);

    //set up our attribute pointer
    m_VAO->setVertexAttributePointer(0,3,GL_FLOAT,sizeof(ngl::Vec3)*3,0);
    m_VAO->setVertexAttributePointer(1,3,GL_FLOAT,sizeof(ngl::Vec3)*3,3);
    m_VAO->setVertexAttributePointer(2,3,GL_FLOAT,sizeof(ngl::Vec3)*3,6);

    //set our indices
    m_VAO->setNumIndices(positions.size());
    //set our VAO free into the wild
    m_VAO->unbind();

    // now lets fill up our array of actual verticies for use with our selectables
    for(MyMesh::VertexIter v_it=m_mesh.vertices_begin(); v_it!=m_mesh.vertices_end();++v_it){
        currentPoint = m_mesh.point(*v_it);
        m_vertPositions.push_back(ngl::Vec3(currentPoint[0],currentPoint[1],currentPoint[2]));
    }
}
示例#3
0
void Palette::colourSwatchClicked() {
	editor->changeColour(currentColour());
}