//////////////////////////////////////////////////////////////////////////////// // // Paella // Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX // Authors : // Thomas FORGIONE // Emilie JALRAS // Marion LENFANT // Thierry MALON // Amandine PAILLOUX // // This file is part of the project Paella // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it freely, // subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; // you must not claim that you wrote the original software. // If you use this software in a product, an acknowledgment // in the product documentation would be appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, // and must not be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. //////////////////////////////////////////////////////////////////////////////// #ifndef ANIMATEDMESH_HPP #define ANIMATEDMESH_HPP #include #include #include #include #include #include #include #include #include #include namespace pae { /////////////////////////////////////////////////////////// /// \ingroup animation /// \brief Class representing an animated mesh /////////////////////////////////////////////////////////// class AnimatedMesh { public: /////////////////////////////////////////////////////////// /// \brief Usual constructor /// \param skeleton Skeleton to animate /// /// Create an animated mesh from the skeletton. It opens /// a GUI to create patellas with the left clic, and choose a root for /// the trees. The right click must be on an extremity of the mesh. /////////////////////////////////////////////////////////// AnimatedMesh(Skeleton3D const& skeleton); /////////////////////////////////////////////////////////// /// \brief OpenGL render function /// /// Draw the animated mesh with OpenGL /////////////////////////////////////////////////////////// void draw() const; geo::Tree rotations; ///< Tree of rotations std::vector paths; ///< Vector of paths to access elements in the order private: ///////////////////////////////////////////////////////////////////// /// /// \brief find the nearest segment of each point /// /// \param segments takes a vector for the different splines, containing vectors corresponding to the different segments /// \param mesh the mesh /// /// \return the associated segment for each point /// ///////////////////////////////////////////////////////////////////// void associateBranches(std::vector> const& segments, geo::Mesh& mesh); ////////////////////////////////////////////////////////////////////// /// /// \brief find a point nearest segment /// /// \param segments list of skeleton's segments /// \param p point to project /// /// \return nearest segment index /// ////////////////////////////////////////////////////////////////////// unsigned int findNearestSegment(std::vector> const& segments, geo::Point const& p); ////////////////////////////////////////////////////////////////////// /// /// \brief find the faces associated to each segment /// /// \param associatedSegments the associated segment for each point /// \param mesh the mesh /// \param nbSegments number of segments /// /// \return faces associated to each segment /// ////////////////////////////////////////////////////////////////////// void findFaces(std::vector const& associatedSegments, geo::Mesh& mesh, unsigned int nbSegments); std::vector> segments; ///< segments of the skeleton std::vector> vertices; ///< Vertices of the mesh std::vector associatedSegment; ///< Each element of this vector is the indexes of the associated segment std::vector>> facesPerSegment; ///< Each vector contains the faces of one segment geo::Tree structure; ///< Tree containing the indices of the vertices. The root is -1 geo::Tree> roots; ///< Tree containing the vertices corresponding to the centers of the rotations geo::Tree>> structuredFaces; ///< Faces structured as a tree std::unordered_map otherVertices; ///< map providing path to access to vertices in the trees (usefull to find the rotations) geo::Tree> colors; ///< Tree containg the colors of vertices }; geo::Tree& genStructure(std::vector> const& segments, geo::Tree> const& tree, geo::Tree& ret); geo::Tree>& genStructure(std::vector> const& segments, geo::Tree> const& tree, geo::Tree>& ret); geo::Tree>>& genStructuredFaces( std::vector>> const& facesPerSegment, geo::Tree const& structure, geo::Tree>>& faces ); std::unordered_map& genOtherVertices( std::vector> const& vertices, std::vector> const& otherFaces, std::vector associatedSegment, geo::Tree const& structure, std::unordered_map& ret, geo::Path path = {} ); geo::Tree>& genColors( geo::Tree const& structure, geo::Tree>& colors); geo::Tree& genRotations( geo::Tree> const& extremities, geo::Tree& ret ); std::vector& genPaths( geo::Tree const& structure, std::vector& paths, geo::Path currentPath = {}); void drawTree(std::vector> const& vertices, geo::Tree>> const& faces, geo::Tree> const& colors, geo::Tree> const& extremities, geo::Tree const& rotations); void drawOthers(std::vector> const& vertices, std::unordered_map const& other_vertices, std::vector> const& faces, geo::Tree> const& colors, geo::Tree const& rotations); } // namespace pae #endif // ANIMATEDMESH_HPP