| 1 | /**************************************************************************/ |
| 2 | /* gltf_physics_shape.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef GLTF_PHYSICS_SHAPE_H |
| 32 | #define GLTF_PHYSICS_SHAPE_H |
| 33 | |
| 34 | #include "../../gltf_defines.h" |
| 35 | |
| 36 | #include "scene/3d/collision_shape_3d.h" |
| 37 | |
| 38 | class ImporterMesh; |
| 39 | |
| 40 | // GLTFPhysicsShape is an intermediary between OMI_collider and Godot's collision shape nodes. |
| 41 | // https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_collider |
| 42 | |
| 43 | class GLTFPhysicsShape : public Resource { |
| 44 | GDCLASS(GLTFPhysicsShape, Resource) |
| 45 | |
| 46 | protected: |
| 47 | static void _bind_methods(); |
| 48 | |
| 49 | private: |
| 50 | String shape_type; |
| 51 | Vector3 size = Vector3(1.0, 1.0, 1.0); |
| 52 | real_t radius = 0.5; |
| 53 | real_t height = 2.0; |
| 54 | bool is_trigger = false; |
| 55 | GLTFMeshIndex mesh_index = -1; |
| 56 | Ref<ImporterMesh> importer_mesh = nullptr; |
| 57 | // Internal only, for caching Godot shape resources. Used in `to_node`. |
| 58 | Ref<Shape3D> _shape_cache = nullptr; |
| 59 | |
| 60 | public: |
| 61 | String get_shape_type() const; |
| 62 | void set_shape_type(String p_shape_type); |
| 63 | |
| 64 | Vector3 get_size() const; |
| 65 | void set_size(Vector3 p_size); |
| 66 | |
| 67 | real_t get_radius() const; |
| 68 | void set_radius(real_t p_radius); |
| 69 | |
| 70 | real_t get_height() const; |
| 71 | void set_height(real_t p_height); |
| 72 | |
| 73 | bool get_is_trigger() const; |
| 74 | void set_is_trigger(bool p_is_trigger); |
| 75 | |
| 76 | GLTFMeshIndex get_mesh_index() const; |
| 77 | void set_mesh_index(GLTFMeshIndex p_mesh_index); |
| 78 | |
| 79 | Ref<ImporterMesh> get_importer_mesh() const; |
| 80 | void set_importer_mesh(Ref<ImporterMesh> p_importer_mesh); |
| 81 | |
| 82 | static Ref<GLTFPhysicsShape> from_node(const CollisionShape3D *p_shape_node); |
| 83 | CollisionShape3D *to_node(bool p_cache_shapes = false); |
| 84 | |
| 85 | static Ref<GLTFPhysicsShape> from_dictionary(const Dictionary p_dictionary); |
| 86 | Dictionary to_dictionary() const; |
| 87 | }; |
| 88 | |
| 89 | #endif // GLTF_PHYSICS_SHAPE_H |
| 90 | |