Skip to content
Snippets Groups Projects
Commit aa2848a6 authored by Philip Trettner's avatar Philip Trettner
Browse files

attributes and vector math

parent 6364a377
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,17 @@ For example, ``m.vertices().avg(pos)`` computes the average vertex position.
Integrating Mesh and Attributes
-------------------------------
TODO: by deriving
Sometimes, it is useful to have a class that represents a mesh with a set of default attributes.
An easy way to achieve this is to derive from :class:`polymesh::Mesh` and declare the attributes as members: ::
class MyMesh : public pm::Mesh
{
pm::vertex_attribute<tg::pos3> pos{*this};
pm::vertex_attribute<tg::dir3> normal{*this};
pm::halfedge_attribute<tg::pos2> texCoords{*this};
};
Note that attributes should be initialized with ``{*this}`` to attach them to the mesh.
Advanced Attributes
......
......@@ -17,3 +17,4 @@ Long Term
* add more formats
* add more objects
* re-add binary polymesh format with arbitrary attributes
* sparse attributes
Vector Math
===========
TODO
A :class:`polymesh::Mesh` only represents topology (see :doc:`mesh-topology`) and has no knowledge of any embedding into 2D or 3D space.
Any data needed for such embeddings are stored in :doc:`attributes`.
However, :doc:`serialization` and many :doc:`algorithms` work on or with the geometric interpretation of a mesh.
Polymesh is designed to be largely agnostic of which math library is used.
We currently officially support:
* `Typed Geometry <https://graphics.rwth-aachen.de:9000/ptrettner/typed-geometry>`_ (recommended)
* `GLM <https://github.com/g-truc/glm>`_
* `Eigen <http://eigen.tuxfamily.org/>`_
Using Custom Math Types
-----------------------
:doc:`algorithms` are typically templated and written in a way that abstract over the actual math library.
Polymesh assumes that the type used for positions and vectors can be different (e.g. ``tg::pos3`` vs. ``tg::vec3`` in Typed Geometry) or the same (e.g. ``glm::vec3`` in GLM).
Your own math types should work as long as the following operations are provided:
* ``pos - pos -> vec``
* ``pos + vec -> pos``
* ``pos - vec -> pos``
* ``vec + vec -> vec``
* ``vec - vec -> vec``
* ``vec * scalar -> vec``
* ``vec / scalar -> vec``
* ``pos * scalar -> pos``
* ``pos / scalar -> pos``
* ``pos[int-literal] -> scalar``
* ``vec[int-literal] -> scalar``
* ``pos`` and ``vec`` default constructor
* ``pos``, ``vec``, and ``scalar`` behave like value types
(Algorithms should only use right multiplication with scalars. Violations should be reported as defects.)
Contributing Algorithms
-----------------------
Algorithms should be written such that they can be used with custom math types.
They must only rely on the previously mentioned operations.
The utility header ``fields.hh`` contains the type ``pm::field3<Pos3>`` which contains a few helper functions like ``dot``, ``cross``, and ``length``.
NOTE: this only concerns authors of new ``polymesh::`` algorithms.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment