2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* sprite_3d.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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-05 00:50:27 +01:00
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
#ifndef SPRITE_3D_H
|
|
|
|
#define SPRITE_3D_H
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2021-08-13 01:05:59 +02:00
|
|
|
#include "scene/resources/sprite_frames.h"
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class SpriteBase3D : public GeometryInstance3D {
|
|
|
|
GDCLASS(SpriteBase3D, GeometryInstance3D);
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
mutable Ref<TriangleMesh> triangle_mesh; //cached
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-05-29 15:56:39 +02:00
|
|
|
enum DrawFlags {
|
|
|
|
FLAG_TRANSPARENT,
|
|
|
|
FLAG_SHADED,
|
2017-04-17 03:32:51 +02:00
|
|
|
FLAG_DOUBLE_SIDED,
|
2022-04-19 12:27:18 +02:00
|
|
|
FLAG_DISABLE_DEPTH_TEST,
|
|
|
|
FLAG_FIXED_SIZE,
|
2014-05-29 15:56:39 +02:00
|
|
|
FLAG_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AlphaCutMode {
|
|
|
|
ALPHA_CUT_DISABLED,
|
|
|
|
ALPHA_CUT_DISCARD,
|
2023-01-24 11:24:53 +01:00
|
|
|
ALPHA_CUT_OPAQUE_PREPASS,
|
|
|
|
ALPHA_CUT_HASH,
|
|
|
|
ALPHA_CUT_MAX
|
2014-05-29 15:56:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2021-02-07 22:29:31 +01:00
|
|
|
bool color_dirty = true;
|
2014-05-29 15:56:39 +02:00
|
|
|
Color color_accum;
|
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
SpriteBase3D *parent_sprite = nullptr;
|
2014-05-29 15:56:39 +02:00
|
|
|
List<SpriteBase3D *> children;
|
2021-02-07 22:29:31 +01:00
|
|
|
List<SpriteBase3D *>::Element *pI = nullptr;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
bool centered = true;
|
2014-05-29 15:56:39 +02:00
|
|
|
Point2 offset;
|
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
bool hflip = false;
|
|
|
|
bool vflip = false;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
Color modulate = Color(1, 1, 1, 1);
|
2022-04-30 10:41:50 +02:00
|
|
|
int render_priority = 0;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
Vector3::Axis axis = Vector3::AXIS_Z;
|
2021-01-30 01:55:54 +01:00
|
|
|
real_t pixel_size = 0.01;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
RID mesh;
|
|
|
|
RID material;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2022-09-18 20:03:03 +02:00
|
|
|
RID last_shader;
|
|
|
|
RID last_texture;
|
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
bool flags[FLAG_MAX] = {};
|
2021-02-07 22:29:31 +01:00
|
|
|
AlphaCutMode alpha_cut = ALPHA_CUT_DISABLED;
|
2023-01-24 11:24:53 +01:00
|
|
|
float alpha_scissor_threshold = 0.5;
|
|
|
|
float alpha_hash_scale = 1.0;
|
2023-01-31 09:40:08 +01:00
|
|
|
StandardMaterial3D::AlphaAntiAliasing alpha_antialiasing_mode = StandardMaterial3D::ALPHA_ANTIALIASING_OFF;
|
|
|
|
float alpha_antialiasing_edge = 0.0f;
|
2021-02-07 22:29:31 +01:00
|
|
|
StandardMaterial3D::BillboardMode billboard_mode = StandardMaterial3D::BILLBOARD_DISABLED;
|
2022-04-19 12:27:18 +02:00
|
|
|
StandardMaterial3D::TextureFilter texture_filter = StandardMaterial3D::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
|
2021-02-07 22:29:31 +01:00
|
|
|
bool pending_update = false;
|
2014-05-29 15:56:39 +02:00
|
|
|
void _im_update();
|
|
|
|
|
|
|
|
void _propagate_color_changed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Color _get_color_accum();
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
virtual void _draw() = 0;
|
2022-09-18 20:03:03 +02:00
|
|
|
void draw_texture_rect(Ref<Texture2D> p_texture, Rect2 p_dst_rect, Rect2 p_src_rect);
|
2017-11-17 03:09:00 +01:00
|
|
|
_FORCE_INLINE_ void set_aabb(const AABB &p_aabb) { aabb = p_aabb; }
|
2021-06-30 03:55:11 +02:00
|
|
|
_FORCE_INLINE_ RID &get_mesh() { return mesh; }
|
|
|
|
_FORCE_INLINE_ RID &get_material() { return material; }
|
|
|
|
|
|
|
|
uint32_t mesh_surface_offsets[RS::ARRAY_MAX];
|
|
|
|
PackedByteArray vertex_buffer;
|
|
|
|
PackedByteArray attribute_buffer;
|
2022-05-02 16:28:25 +02:00
|
|
|
uint32_t vertex_stride = 0;
|
2023-08-29 21:04:32 +02:00
|
|
|
uint32_t normal_tangent_stride = 0;
|
2022-05-02 16:28:25 +02:00
|
|
|
uint32_t attrib_stride = 0;
|
|
|
|
uint32_t skin_stride = 0;
|
|
|
|
uint32_t mesh_surface_format = 0;
|
2021-06-30 03:55:11 +02:00
|
|
|
|
2022-08-09 12:57:18 +02:00
|
|
|
void _queue_redraw();
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-05-29 15:56:39 +02:00
|
|
|
void set_centered(bool p_center);
|
|
|
|
bool is_centered() const;
|
|
|
|
|
|
|
|
void set_offset(const Point2 &p_offset);
|
|
|
|
Point2 get_offset() const;
|
|
|
|
|
|
|
|
void set_flip_h(bool p_flip);
|
|
|
|
bool is_flipped_h() const;
|
|
|
|
|
|
|
|
void set_flip_v(bool p_flip);
|
|
|
|
bool is_flipped_v() const;
|
|
|
|
|
2022-04-30 10:41:50 +02:00
|
|
|
void set_render_priority(int p_priority);
|
|
|
|
int get_render_priority() const;
|
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
void set_modulate(const Color &p_color);
|
|
|
|
Color get_modulate() const;
|
|
|
|
|
2021-01-30 01:55:54 +01:00
|
|
|
void set_pixel_size(real_t p_amount);
|
|
|
|
real_t get_pixel_size() const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2017-08-11 21:10:05 +02:00
|
|
|
void set_axis(Vector3::Axis p_axis);
|
2014-05-29 15:56:39 +02:00
|
|
|
Vector3::Axis get_axis() const;
|
|
|
|
|
|
|
|
void set_draw_flag(DrawFlags p_flag, bool p_enable);
|
|
|
|
bool get_draw_flag(DrawFlags p_flag) const;
|
|
|
|
|
|
|
|
void set_alpha_cut_mode(AlphaCutMode p_mode);
|
|
|
|
AlphaCutMode get_alpha_cut_mode() const;
|
2022-04-19 12:27:18 +02:00
|
|
|
|
2023-01-24 11:24:53 +01:00
|
|
|
void set_alpha_scissor_threshold(float p_threshold);
|
|
|
|
float get_alpha_scissor_threshold() const;
|
|
|
|
|
|
|
|
void set_alpha_hash_scale(float p_hash_scale);
|
|
|
|
float get_alpha_hash_scale() const;
|
|
|
|
|
2023-01-31 09:40:08 +01:00
|
|
|
void set_alpha_antialiasing(BaseMaterial3D::AlphaAntiAliasing p_alpha_aa);
|
|
|
|
BaseMaterial3D::AlphaAntiAliasing get_alpha_antialiasing() const;
|
|
|
|
|
|
|
|
void set_alpha_antialiasing_edge(float p_edge);
|
|
|
|
float get_alpha_antialiasing_edge() const;
|
|
|
|
|
2019-09-15 06:01:52 +02:00
|
|
|
void set_billboard_mode(StandardMaterial3D::BillboardMode p_mode);
|
|
|
|
StandardMaterial3D::BillboardMode get_billboard_mode() const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2022-04-19 12:27:18 +02:00
|
|
|
void set_texture_filter(StandardMaterial3D::TextureFilter p_filter);
|
|
|
|
StandardMaterial3D::TextureFilter get_texture_filter() const;
|
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
virtual Rect2 get_item_rect() const = 0;
|
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual AABB get_aabb() const override;
|
2022-03-10 08:17:38 +01:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
Ref<TriangleMesh> generate_triangle_mesh() const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
|
|
|
SpriteBase3D();
|
|
|
|
~SpriteBase3D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sprite3D : public SpriteBase3D {
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(Sprite3D, SpriteBase3D);
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> texture;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
bool region = false;
|
2014-05-29 15:56:39 +02:00
|
|
|
Rect2 region_rect;
|
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
int frame = 0;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
int vframes = 1;
|
|
|
|
int hframes = 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
protected:
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _draw() override;
|
2014-05-29 15:56:39 +02:00
|
|
|
static void _bind_methods();
|
2016-07-07 04:46:04 +02:00
|
|
|
|
2022-08-12 22:57:11 +02:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
|
|
|
public:
|
2019-06-11 20:43:37 +02:00
|
|
|
void set_texture(const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_texture() const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
2021-06-30 03:55:11 +02:00
|
|
|
void set_region_enabled(bool p_region);
|
2021-03-14 14:43:43 +01:00
|
|
|
bool is_region_enabled() const;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
|
|
|
void set_region_rect(const Rect2 &p_region_rect);
|
|
|
|
Rect2 get_region_rect() const;
|
|
|
|
|
|
|
|
void set_frame(int p_frame);
|
|
|
|
int get_frame() const;
|
|
|
|
|
2021-05-23 18:46:39 +02:00
|
|
|
void set_frame_coords(const Vector2i &p_coord);
|
|
|
|
Vector2i get_frame_coords() const;
|
2019-01-25 19:21:23 +01:00
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
void set_vframes(int p_amount);
|
|
|
|
int get_vframes() const;
|
|
|
|
|
|
|
|
void set_hframes(int p_amount);
|
|
|
|
int get_hframes() const;
|
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Rect2 get_item_rect() const override;
|
2014-05-29 15:56:39 +02:00
|
|
|
|
|
|
|
Sprite3D();
|
2017-01-14 12:26:56 +01:00
|
|
|
//~Sprite3D();
|
2014-05-29 15:56:39 +02:00
|
|
|
};
|
|
|
|
|
2016-06-08 23:03:06 +02:00
|
|
|
class AnimatedSprite3D : public SpriteBase3D {
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(AnimatedSprite3D, SpriteBase3D);
|
2016-06-08 23:03:06 +02:00
|
|
|
|
|
|
|
Ref<SpriteFrames> frames;
|
2023-01-21 06:51:03 +01:00
|
|
|
String autoplay;
|
|
|
|
|
2021-02-07 22:29:31 +01:00
|
|
|
bool playing = false;
|
|
|
|
StringName animation = "default";
|
|
|
|
int frame = 0;
|
2022-11-26 15:00:38 +01:00
|
|
|
float speed_scale = 1.0;
|
2023-01-21 06:51:03 +01:00
|
|
|
float custom_speed_scale = 1.0;
|
2016-06-08 23:03:06 +02:00
|
|
|
|
2023-01-21 06:51:03 +01:00
|
|
|
real_t frame_speed_scale = 1.0;
|
|
|
|
real_t frame_progress = 0.0;
|
2016-06-08 23:03:06 +02:00
|
|
|
|
|
|
|
void _res_changed();
|
|
|
|
|
2022-08-09 12:57:18 +02:00
|
|
|
double _get_frame_duration();
|
2023-01-21 06:51:03 +01:00
|
|
|
void _calc_frame_speed_scale();
|
|
|
|
void _stop_internal(bool p_reset);
|
2016-06-08 23:03:06 +02:00
|
|
|
|
|
|
|
protected:
|
2023-01-21 06:51:03 +01:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
#endif
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _draw() override;
|
2016-06-08 23:03:06 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
2022-08-12 22:57:11 +02:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2016-06-08 23:03:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
|
|
|
|
Ref<SpriteFrames> get_sprite_frames() const;
|
|
|
|
|
2023-01-21 06:51:03 +01:00
|
|
|
void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false);
|
|
|
|
void play_backwards(const StringName &p_name = StringName());
|
|
|
|
void pause();
|
2016-06-08 23:03:06 +02:00
|
|
|
void stop();
|
2022-08-09 13:20:07 +02:00
|
|
|
|
2016-06-08 23:03:06 +02:00
|
|
|
bool is_playing() const;
|
|
|
|
|
2023-01-21 06:51:03 +01:00
|
|
|
void set_animation(const StringName &p_name);
|
2016-06-08 23:03:06 +02:00
|
|
|
StringName get_animation() const;
|
|
|
|
|
2023-01-21 06:51:03 +01:00
|
|
|
void set_autoplay(const String &p_name);
|
|
|
|
String get_autoplay() const;
|
|
|
|
|
2016-06-08 23:03:06 +02:00
|
|
|
void set_frame(int p_frame);
|
|
|
|
int get_frame() const;
|
|
|
|
|
2023-01-21 06:51:03 +01:00
|
|
|
void set_frame_progress(real_t p_progress);
|
|
|
|
real_t get_frame_progress() const;
|
|
|
|
|
|
|
|
void set_frame_and_progress(int p_frame, real_t p_progress);
|
|
|
|
|
2022-11-26 15:00:38 +01:00
|
|
|
void set_speed_scale(float p_speed_scale);
|
|
|
|
float get_speed_scale() const;
|
2023-01-21 06:51:03 +01:00
|
|
|
float get_playing_speed() const;
|
2022-08-09 12:57:18 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Rect2 get_item_rect() const override;
|
2016-06-08 23:03:06 +02:00
|
|
|
|
2022-09-19 17:43:15 +02:00
|
|
|
virtual PackedStringArray get_configuration_warnings() const override;
|
2022-05-04 14:56:20 +02:00
|
|
|
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
|
|
|
|
|
2016-06-08 23:03:06 +02:00
|
|
|
AnimatedSprite3D();
|
|
|
|
};
|
2014-05-29 15:56:39 +02:00
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(SpriteBase3D::DrawFlags);
|
|
|
|
VARIANT_ENUM_CAST(SpriteBase3D::AlphaCutMode);
|
2021-06-30 03:55:11 +02:00
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
#endif // SPRITE_3D_H
|