/*
 * Copyright (c) 1999-2019 Hartmut Seichter
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
#ifndef PW_CORE_MESH_HPP
#define PW_CORE_MESH_HPP

#include <pw/core/globals.hpp>
#include <pw/core/vector.hpp>
#include <pw/core/aabb.hpp>
#include <pw/core/resource.hpp>

namespace pw {

class geometry {
public:

    enum class topology_type {
        triangles,
        triangle_strip,
        triangle_fan,
        quads,
        lines,
        line_strip,
        points
    };

    using index_t = size_t;

	using valuearray_t = std::vector<real_t> ;
	using indexarray_t = std::vector<index_t> ;

	using vertex2array_t = std::vector<vector2> ;
	using vertex3array_t = std::vector<vector3> ;

    geometry() = default;

	void set_indices(const indexarray_t& v) { _indices = v; }
	const indexarray_t& indices() const { return _indices; }

	void set_vertices(const vertex3array_t& v);
	const vertex3array_t& vertices() const { return _vertices; }

    void set_normals(const geometry::vertex3array_t &v);
    const geometry::vertex3array_t& normals() const;

    void set_topology(topology_type t) { _topology = t; }
    topology_type topology() { return _topology; }

	void apply(const matrix4x4& m);

	void reset();

    aabb get_aabb() const { return _aabb; }

	void compute_normals();

    void compute_bounds();

protected:

    topology_type _topology = topology_type::triangles;
	indexarray_t _indices; //!< indices according to topology type

    vertex3array_t _vertices; //!< geometry data
	vertex3array_t _normals; //!< normal data
	vertex3array_t _colors; //!< color data

	std::vector<vertex2array_t> _uvs;			//!< storing multiple UV sets

    struct aabb _aabb;

	// TODO add weights, tangents etc. pp.

};

}

#endif

