2020-12-21 16:39:32 +01:00
|
|
|
/*************************************************************************/
|
2021-09-21 03:24:31 +02:00
|
|
|
/* importer_mesh.h */
|
2020-12-21 16:39:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-12-21 16:39:32 +01: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2021-09-21 03:24:31 +02:00
|
|
|
#ifndef SCENE_IMPORTER_MESH_H
|
|
|
|
#define SCENE_IMPORTER_MESH_H
|
2020-12-21 16:39:32 +01:00
|
|
|
|
|
|
|
#include "core/io/resource.h"
|
2021-09-07 17:44:50 +02:00
|
|
|
#include "core/templates/local_vector.h"
|
2021-03-19 13:57:52 +01:00
|
|
|
#include "scene/resources/concave_polygon_shape_3d.h"
|
|
|
|
#include "scene/resources/convex_polygon_shape_3d.h"
|
2020-12-21 16:39:32 +01:00
|
|
|
#include "scene/resources/mesh.h"
|
2021-03-19 13:57:52 +01:00
|
|
|
#include "scene/resources/navigation_mesh.h"
|
2021-09-09 06:29:14 +02:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2020-12-21 16:39:32 +01:00
|
|
|
// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
|
|
|
|
// so the data is not registered (hence, quality loss), importing happens faster and
|
|
|
|
// its easier to modify before saving
|
|
|
|
|
2021-09-21 03:24:31 +02:00
|
|
|
class ImporterMesh : public Resource {
|
|
|
|
GDCLASS(ImporterMesh, Resource)
|
2020-12-21 16:39:32 +01:00
|
|
|
|
|
|
|
struct Surface {
|
|
|
|
Mesh::PrimitiveType primitive;
|
|
|
|
Array arrays;
|
|
|
|
struct BlendShape {
|
|
|
|
Array arrays;
|
|
|
|
};
|
|
|
|
Vector<BlendShape> blend_shape_data;
|
|
|
|
struct LOD {
|
|
|
|
Vector<int> indices;
|
2021-09-07 17:44:50 +02:00
|
|
|
float distance = 0.0f;
|
2020-12-21 16:39:32 +01:00
|
|
|
};
|
|
|
|
Vector<LOD> lods;
|
|
|
|
Ref<Material> material;
|
|
|
|
String name;
|
2021-09-09 06:29:14 +02:00
|
|
|
uint32_t flags = 0;
|
2021-09-07 17:44:50 +02:00
|
|
|
|
|
|
|
struct LODComparator {
|
|
|
|
_FORCE_INLINE_ bool operator()(const LOD &l, const LOD &r) const {
|
|
|
|
return l.distance < r.distance;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void split_normals(const LocalVector<int> &p_indices, const LocalVector<Vector3> &p_normals);
|
2021-10-06 11:53:53 +02:00
|
|
|
static void _split_normals(Array &r_arrays, const LocalVector<int> &p_indices, const LocalVector<Vector3> &p_normals);
|
2020-12-21 16:39:32 +01:00
|
|
|
};
|
|
|
|
Vector<Surface> surfaces;
|
|
|
|
Vector<String> blend_shapes;
|
|
|
|
Mesh::BlendShapeMode blend_shape_mode = Mesh::BLEND_SHAPE_MODE_NORMALIZED;
|
|
|
|
|
|
|
|
Ref<ArrayMesh> mesh;
|
|
|
|
|
2021-09-21 03:24:31 +02:00
|
|
|
Ref<ImporterMesh> shadow_mesh;
|
2021-01-25 16:20:11 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
Size2i lightmap_size_hint;
|
|
|
|
|
2020-12-21 16:39:32 +01:00
|
|
|
protected:
|
|
|
|
void _set_data(const Dictionary &p_data);
|
|
|
|
Dictionary _get_data() const;
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void add_blend_shape(const String &p_name);
|
|
|
|
int get_blend_shape_count() const;
|
|
|
|
String get_blend_shape_name(int p_blend_shape) const;
|
|
|
|
|
2021-09-09 06:29:14 +02:00
|
|
|
void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String(), const uint32_t p_flags = 0);
|
2020-12-21 16:39:32 +01:00
|
|
|
int get_surface_count() const;
|
|
|
|
|
|
|
|
void set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode);
|
|
|
|
Mesh::BlendShapeMode get_blend_shape_mode() const;
|
|
|
|
|
|
|
|
Mesh::PrimitiveType get_surface_primitive_type(int p_surface);
|
|
|
|
String get_surface_name(int p_surface) const;
|
2021-08-23 03:11:57 +02:00
|
|
|
void set_surface_name(int p_surface, const String &p_name);
|
2020-12-21 16:39:32 +01:00
|
|
|
Array get_surface_arrays(int p_surface) const;
|
|
|
|
Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const;
|
|
|
|
int get_surface_lod_count(int p_surface) const;
|
|
|
|
Vector<int> get_surface_lod_indices(int p_surface, int p_lod) const;
|
|
|
|
float get_surface_lod_size(int p_surface, int p_lod) const;
|
|
|
|
Ref<Material> get_surface_material(int p_surface) const;
|
2021-09-09 06:29:14 +02:00
|
|
|
uint32_t get_surface_format(int p_surface) const;
|
2020-12-21 16:39:32 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
void set_surface_material(int p_surface, const Ref<Material> &p_material);
|
|
|
|
|
2021-09-07 17:44:50 +02:00
|
|
|
void generate_lods(float p_normal_merge_angle, float p_normal_split_angle);
|
2020-12-21 16:39:32 +01:00
|
|
|
|
2021-01-25 16:20:11 +01:00
|
|
|
void create_shadow_mesh();
|
2021-09-21 03:24:31 +02:00
|
|
|
Ref<ImporterMesh> get_shadow_mesh() const;
|
2021-01-25 16:20:11 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
Vector<Face3> get_faces() const;
|
Improve collision generation usability in the new 3D scene import workflow.
With this PR it's possible to add a collision during the Mesh import, directly in editor.
To generate the shape is possible to chose between the following options:
- Decompose Convex: The Mesh is decomposed in one or many Convex Shapes (Using the VHACD library).
- Simple Convex: Is generated a convex shape that enclose the entire mesh.
- Trimesh: Generate a trimesh shape using the Mesh faces.
- Box: Add a primitive box shape, where you can tweak the `size`, `position`, `rotation`.
- Sphere: Add a primitive sphere shape, where you can tweak the `radius`, `position`, `rotation`.
- Cylinder: Add a primitive cylinder shape, where you can tweak the `height`, `radius`, `position`, `rotation`.
- Capsule: Add a primitive capsule shape, where you can tweak the `height`, `radius`, `position`, `rotation`.
It's also possible to chose the generated body, so you can create:
- Rigid Body
- Static Body
- Area
2021-08-22 18:19:13 +02:00
|
|
|
Vector<Ref<Shape3D>> convex_decompose(const Mesh::ConvexDecompositionSettings &p_settings) const;
|
2021-03-19 13:57:52 +01:00
|
|
|
Ref<Shape3D> create_trimesh_shape() const;
|
|
|
|
Ref<NavigationMesh> create_navigation_mesh();
|
2020-10-17 07:08:21 +02:00
|
|
|
Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
|
2021-03-19 13:57:52 +01:00
|
|
|
|
|
|
|
void set_lightmap_size_hint(const Size2i &p_size);
|
|
|
|
Size2i get_lightmap_size_hint() const;
|
|
|
|
|
2020-12-21 16:39:32 +01:00
|
|
|
bool has_mesh() const;
|
2021-08-23 03:11:57 +02:00
|
|
|
Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>());
|
2020-12-21 16:39:32 +01:00
|
|
|
void clear();
|
|
|
|
};
|
2021-09-21 03:24:31 +02:00
|
|
|
#endif // SCENE_IMPORTER_MESH_H
|