2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* mesh.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef MESH_H
|
|
|
|
#define MESH_H
|
|
|
|
|
2019-04-10 20:46:04 +00:00
|
|
|
#include "core/math/face3.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/math/triangle_mesh.h"
|
|
|
|
#include "core/resource.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/material.h"
|
|
|
|
#include "scene/resources/shape.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "servers/visual_server.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
class Mesh : public Resource {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Mesh, Resource);
|
2017-06-07 21:18:55 +00:00
|
|
|
|
|
|
|
mutable Ref<TriangleMesh> triangle_mesh; //cached
|
2018-09-09 17:39:34 +00:00
|
|
|
mutable Vector<Vector3> debug_lines;
|
2017-12-09 17:11:26 +00:00
|
|
|
Size2 lightmap_size_hint;
|
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
protected:
|
2017-07-13 22:15:55 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
|
|
|
enum {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NO_INDEX_ARRAY = VisualServer::NO_INDEX_ARRAY,
|
|
|
|
ARRAY_WEIGHTS_SIZE = VisualServer::ARRAY_WEIGHTS_SIZE
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ArrayType {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ARRAY_VERTEX = VisualServer::ARRAY_VERTEX,
|
|
|
|
ARRAY_NORMAL = VisualServer::ARRAY_NORMAL,
|
|
|
|
ARRAY_TANGENT = VisualServer::ARRAY_TANGENT,
|
|
|
|
ARRAY_COLOR = VisualServer::ARRAY_COLOR,
|
|
|
|
ARRAY_TEX_UV = VisualServer::ARRAY_TEX_UV,
|
|
|
|
ARRAY_TEX_UV2 = VisualServer::ARRAY_TEX_UV2,
|
|
|
|
ARRAY_BONES = VisualServer::ARRAY_BONES,
|
|
|
|
ARRAY_WEIGHTS = VisualServer::ARRAY_WEIGHTS,
|
|
|
|
ARRAY_INDEX = VisualServer::ARRAY_INDEX,
|
|
|
|
ARRAY_MAX = VisualServer::ARRAY_MAX
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum ArrayFormat {
|
|
|
|
/* ARRAY FORMAT FLAGS */
|
2017-03-05 15:44:50 +00:00
|
|
|
ARRAY_FORMAT_VERTEX = 1 << ARRAY_VERTEX, // mandatory
|
|
|
|
ARRAY_FORMAT_NORMAL = 1 << ARRAY_NORMAL,
|
|
|
|
ARRAY_FORMAT_TANGENT = 1 << ARRAY_TANGENT,
|
|
|
|
ARRAY_FORMAT_COLOR = 1 << ARRAY_COLOR,
|
|
|
|
ARRAY_FORMAT_TEX_UV = 1 << ARRAY_TEX_UV,
|
|
|
|
ARRAY_FORMAT_TEX_UV2 = 1 << ARRAY_TEX_UV2,
|
|
|
|
ARRAY_FORMAT_BONES = 1 << ARRAY_BONES,
|
|
|
|
ARRAY_FORMAT_WEIGHTS = 1 << ARRAY_WEIGHTS,
|
|
|
|
ARRAY_FORMAT_INDEX = 1 << ARRAY_INDEX,
|
|
|
|
|
|
|
|
ARRAY_COMPRESS_BASE = (ARRAY_INDEX + 1),
|
|
|
|
ARRAY_COMPRESS_VERTEX = 1 << (ARRAY_VERTEX + ARRAY_COMPRESS_BASE), // mandatory
|
|
|
|
ARRAY_COMPRESS_NORMAL = 1 << (ARRAY_NORMAL + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_TANGENT = 1 << (ARRAY_TANGENT + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_COLOR = 1 << (ARRAY_COLOR + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_TEX_UV = 1 << (ARRAY_TEX_UV + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_TEX_UV2 = 1 << (ARRAY_TEX_UV2 + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_BONES = 1 << (ARRAY_BONES + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_WEIGHTS = 1 << (ARRAY_WEIGHTS + ARRAY_COMPRESS_BASE),
|
|
|
|
ARRAY_COMPRESS_INDEX = 1 << (ARRAY_INDEX + ARRAY_COMPRESS_BASE),
|
|
|
|
|
|
|
|
ARRAY_FLAG_USE_2D_VERTICES = ARRAY_COMPRESS_INDEX << 1,
|
|
|
|
ARRAY_FLAG_USE_16_BIT_BONES = ARRAY_COMPRESS_INDEX << 2,
|
2017-11-14 20:25:42 +00:00
|
|
|
ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 3,
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2018-07-03 13:55:50 +00:00
|
|
|
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 | ARRAY_COMPRESS_WEIGHTS
|
2016-11-24 23:46:55 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum PrimitiveType {
|
2017-03-05 15:44:50 +00:00
|
|
|
PRIMITIVE_POINTS = VisualServer::PRIMITIVE_POINTS,
|
|
|
|
PRIMITIVE_LINES = VisualServer::PRIMITIVE_LINES,
|
|
|
|
PRIMITIVE_LINE_STRIP = VisualServer::PRIMITIVE_LINE_STRIP,
|
|
|
|
PRIMITIVE_LINE_LOOP = VisualServer::PRIMITIVE_LINE_LOOP,
|
|
|
|
PRIMITIVE_TRIANGLES = VisualServer::PRIMITIVE_TRIANGLES,
|
|
|
|
PRIMITIVE_TRIANGLE_STRIP = VisualServer::PRIMITIVE_TRIANGLE_STRIP,
|
|
|
|
PRIMITIVE_TRIANGLE_FAN = VisualServer::PRIMITIVE_TRIANGLE_FAN,
|
2016-03-08 23:00:52 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-12 11:34:00 +00:00
|
|
|
enum BlendShapeMode {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
BLEND_SHAPE_MODE_NORMALIZED = VS::BLEND_SHAPE_MODE_NORMALIZED,
|
|
|
|
BLEND_SHAPE_MODE_RELATIVE = VS::BLEND_SHAPE_MODE_RELATIVE,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
virtual int get_surface_count() const = 0;
|
|
|
|
virtual int surface_get_array_len(int p_idx) const = 0;
|
|
|
|
virtual int surface_get_array_index_len(int p_idx) const = 0;
|
2017-11-21 00:36:32 +00:00
|
|
|
virtual bool surface_is_softbody_friendly(int p_idx) const;
|
2017-06-07 21:18:55 +00:00
|
|
|
virtual Array surface_get_arrays(int p_surface) const = 0;
|
2017-09-10 10:10:28 +00:00
|
|
|
virtual Array surface_get_blend_shape_arrays(int p_surface) const = 0;
|
2017-06-07 21:18:55 +00:00
|
|
|
virtual uint32_t surface_get_format(int p_idx) const = 0;
|
|
|
|
virtual PrimitiveType surface_get_primitive_type(int p_idx) const = 0;
|
2019-01-31 17:04:36 +00:00
|
|
|
virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) = 0;
|
2017-06-07 21:18:55 +00:00
|
|
|
virtual Ref<Material> surface_get_material(int p_idx) const = 0;
|
|
|
|
virtual int get_blend_shape_count() const = 0;
|
|
|
|
virtual StringName get_blend_shape_name(int p_index) const = 0;
|
2020-10-15 14:53:18 +00:00
|
|
|
virtual void set_blend_shape_name(int p_index, const StringName &p_name) = 0;
|
2017-06-07 21:18:55 +00:00
|
|
|
|
|
|
|
PoolVector<Face3> get_faces() const;
|
|
|
|
Ref<TriangleMesh> generate_triangle_mesh() const;
|
2017-11-21 00:36:32 +00:00
|
|
|
void generate_debug_mesh_lines(Vector<Vector3> &r_lines);
|
|
|
|
void generate_debug_mesh_indices(Vector<Vector3> &r_points);
|
2017-06-07 21:18:55 +00:00
|
|
|
|
|
|
|
Ref<Shape> create_trimesh_shape() const;
|
2021-07-09 22:31:05 +00:00
|
|
|
Ref<Shape> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
|
2017-06-07 21:18:55 +00:00
|
|
|
|
|
|
|
Ref<Mesh> create_outline(float p_margin) const;
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
virtual AABB get_aabb() const = 0;
|
2017-06-07 21:18:55 +00:00
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
void set_lightmap_size_hint(const Vector2 &p_size);
|
|
|
|
Size2 get_lightmap_size_hint() const;
|
2018-09-09 17:39:34 +00:00
|
|
|
void clear_cache() const;
|
2017-12-09 17:11:26 +00:00
|
|
|
|
2021-07-09 22:31:05 +00:00
|
|
|
typedef Vector<Vector<Face3>> (*ConvexDecompositionFunc)(const Vector<Face3> &p_faces, int p_max_convex_hulls);
|
2019-04-10 20:46:04 +00:00
|
|
|
|
|
|
|
static ConvexDecompositionFunc convex_composition_function;
|
|
|
|
|
2021-07-09 22:31:05 +00:00
|
|
|
Vector<Ref<Shape>> convex_decompose(int p_max_convex_hulls = -1) const;
|
2019-04-10 20:46:04 +00:00
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
Mesh();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArrayMesh : public Mesh {
|
|
|
|
GDCLASS(ArrayMesh, Mesh);
|
2017-06-15 22:44:11 +00:00
|
|
|
RES_BASE_EXTENSION("mesh");
|
2017-06-07 21:18:55 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
private:
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Surface {
|
|
|
|
String name;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB aabb;
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Material> material;
|
2017-06-22 12:17:06 +00:00
|
|
|
bool is_2d;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
Vector<Surface> surfaces;
|
|
|
|
RID mesh;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB aabb;
|
2017-01-12 11:34:00 +00:00
|
|
|
BlendShapeMode blend_shape_mode;
|
|
|
|
Vector<StringName> blend_shapes;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB custom_aabb;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _recompute_aabb();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
protected:
|
2017-04-07 02:36:37 +00:00
|
|
|
virtual bool _is_generated() const { return false; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
static void _bind_methods();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), uint32_t p_flags = ARRAY_COMPRESS_DEFAULT);
|
2021-05-04 12:20:36 +00:00
|
|
|
void add_surface(uint32_t p_format, PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<PoolVector<uint8_t>> &p_blend_shapes = Vector<PoolVector<uint8_t>>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>());
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Array surface_get_arrays(int p_surface) const;
|
2017-09-10 10:10:28 +00:00
|
|
|
Array surface_get_blend_shape_arrays(int p_surface) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_blend_shape(const StringName &p_name);
|
2017-01-12 11:34:00 +00:00
|
|
|
int get_blend_shape_count() const;
|
|
|
|
StringName get_blend_shape_name(int p_index) const;
|
2020-10-15 14:53:18 +00:00
|
|
|
void set_blend_shape_name(int p_index, const StringName &p_name);
|
2017-01-12 11:34:00 +00:00
|
|
|
void clear_blend_shapes();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-12 11:34:00 +00:00
|
|
|
void set_blend_shape_mode(BlendShapeMode p_mode);
|
|
|
|
BlendShapeMode get_blend_shape_mode() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-14 20:25:42 +00:00
|
|
|
void surface_update_region(int p_surface, int p_offset, const PoolVector<uint8_t> &p_data);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int get_surface_count() const;
|
|
|
|
void surface_remove(int p_idx);
|
2021-06-19 04:01:25 +00:00
|
|
|
void clear_surfaces();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
void surface_set_custom_aabb(int p_idx, const AABB &p_aabb); //only recognized by driver
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int surface_get_array_len(int p_idx) const;
|
|
|
|
int surface_get_array_index_len(int p_idx) const;
|
|
|
|
uint32_t surface_get_format(int p_idx) const;
|
|
|
|
PrimitiveType surface_get_primitive_type(int p_idx) const;
|
|
|
|
bool surface_is_alpha_sorting_enabled(int p_idx) const;
|
|
|
|
|
2019-01-31 17:04:36 +00:00
|
|
|
virtual void surface_set_material(int p_idx, const Ref<Material> &p_material);
|
|
|
|
virtual Ref<Material> surface_get_material(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-28 00:34:31 +00:00
|
|
|
int surface_find_by_name(const String &p_name) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void surface_set_name(int p_idx, const String &p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
String surface_get_name(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
void set_custom_aabb(const AABB &p_custom);
|
|
|
|
AABB get_custom_aabb() const;
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB get_aabb() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
2014-10-14 04:01:25 +00:00
|
|
|
void regen_normalmaps();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
Error lightmap_unwrap(const Transform &p_base_transform = Transform(), float p_texel_size = 0.05);
|
2020-12-19 17:17:22 +00:00
|
|
|
Error lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache, const Transform &p_base_transform = Transform(), float p_texel_size = 0.05);
|
2017-12-09 17:11:26 +00:00
|
|
|
|
2017-11-12 03:48:00 +00:00
|
|
|
virtual void reload_from_file();
|
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
ArrayMesh();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
~ArrayMesh();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VARIANT_ENUM_CAST(Mesh::ArrayType);
|
2017-08-20 15:45:01 +00:00
|
|
|
VARIANT_ENUM_CAST(Mesh::ArrayFormat);
|
2017-03-05 15:44:50 +00:00
|
|
|
VARIANT_ENUM_CAST(Mesh::PrimitiveType);
|
|
|
|
VARIANT_ENUM_CAST(Mesh::BlendShapeMode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#endif
|