2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* sprite_3d.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2019-01-01 11:53:14 +00:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 12:46:12 +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-05-29 13:56:39 +00:00
|
|
|
#ifndef SPRITE_3D_H
|
|
|
|
#define SPRITE_3D_H
|
|
|
|
|
|
|
|
#include "scene/2d/animated_sprite.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/3d/visual_instance.h"
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2014-06-11 13:41:03 +00:00
|
|
|
class SpriteBase3D : public GeometryInstance {
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(SpriteBase3D, GeometryInstance);
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2018-05-06 18:49:22 +00:00
|
|
|
mutable Ref<TriangleMesh> triangle_mesh; //cached
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-05-29 13:56:39 +00:00
|
|
|
enum DrawFlags {
|
|
|
|
FLAG_TRANSPARENT,
|
|
|
|
FLAG_SHADED,
|
2017-04-17 01:32:51 +00:00
|
|
|
FLAG_DOUBLE_SIDED,
|
2014-05-29 13:56:39 +00:00
|
|
|
FLAG_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AlphaCutMode {
|
|
|
|
ALPHA_CUT_DISABLED,
|
|
|
|
ALPHA_CUT_DISCARD,
|
|
|
|
ALPHA_CUT_OPAQUE_PREPASS
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool color_dirty;
|
|
|
|
Color color_accum;
|
|
|
|
|
|
|
|
SpriteBase3D *parent_sprite;
|
2017-03-05 15:44:50 +00:00
|
|
|
List<SpriteBase3D *> children;
|
|
|
|
List<SpriteBase3D *>::Element *pI;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
|
|
|
bool centered;
|
|
|
|
Point2 offset;
|
|
|
|
|
|
|
|
bool hflip;
|
|
|
|
bool vflip;
|
|
|
|
|
|
|
|
Color modulate;
|
|
|
|
float opacity;
|
|
|
|
|
|
|
|
Vector3::Axis axis;
|
|
|
|
float pixel_size;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB aabb;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
|
|
|
RID immediate;
|
|
|
|
|
|
|
|
bool flags[FLAG_MAX];
|
|
|
|
AlphaCutMode alpha_cut;
|
2019-07-16 23:04:36 +00:00
|
|
|
SpatialMaterial::BillboardMode billboard_mode;
|
2014-05-29 13:56:39 +00:00
|
|
|
bool pending_update;
|
|
|
|
void _im_update();
|
|
|
|
|
|
|
|
void _propagate_color_changed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Color _get_color_accum();
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void _draw() = 0;
|
2017-11-17 02:09:00 +00:00
|
|
|
_FORCE_INLINE_ void set_aabb(const AABB &p_aabb) { aabb = p_aabb; }
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ RID &get_immediate() { return immediate; }
|
2014-05-29 13:56:39 +00:00
|
|
|
void _queue_update();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-05-29 13:56:39 +00:00
|
|
|
void set_centered(bool p_center);
|
|
|
|
bool is_centered() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_offset(const Point2 &p_offset);
|
2014-05-29 13:56:39 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
void set_region(bool p_region);
|
|
|
|
bool is_region() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_region_rect(const Rect2 &p_region_rect);
|
2014-05-29 13:56:39 +00:00
|
|
|
Rect2 get_region_rect() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_modulate(const Color &p_color);
|
2014-05-29 13:56:39 +00:00
|
|
|
Color get_modulate() const;
|
|
|
|
|
|
|
|
void set_opacity(float p_amount);
|
|
|
|
float get_opacity() const;
|
|
|
|
|
|
|
|
void set_pixel_size(float p_amount);
|
|
|
|
float get_pixel_size() const;
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_axis(Vector3::Axis p_axis);
|
2014-05-29 13:56:39 +00:00
|
|
|
Vector3::Axis get_axis() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_draw_flag(DrawFlags p_flag, bool p_enable);
|
2014-05-29 13:56:39 +00:00
|
|
|
bool get_draw_flag(DrawFlags p_flag) const;
|
|
|
|
|
|
|
|
void set_alpha_cut_mode(AlphaCutMode p_mode);
|
|
|
|
AlphaCutMode get_alpha_cut_mode() const;
|
2019-07-16 23:04:36 +00:00
|
|
|
void set_billboard_mode(SpatialMaterial::BillboardMode p_mode);
|
|
|
|
SpatialMaterial::BillboardMode get_billboard_mode() const;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual Rect2 get_item_rect() const = 0;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
virtual AABB get_aabb() const;
|
2017-01-07 21:25:37 +00:00
|
|
|
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
2018-05-06 18:49:22 +00:00
|
|
|
Ref<TriangleMesh> generate_triangle_mesh() const;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
|
|
|
SpriteBase3D();
|
|
|
|
~SpriteBase3D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sprite3D : public SpriteBase3D {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Sprite3D, SpriteBase3D);
|
2014-05-29 13:56:39 +00:00
|
|
|
Ref<Texture> texture;
|
|
|
|
|
|
|
|
bool region;
|
|
|
|
Rect2 region_rect;
|
|
|
|
|
|
|
|
int frame;
|
|
|
|
|
|
|
|
int vframes;
|
|
|
|
int hframes;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2014-05-29 13:56:39 +00:00
|
|
|
protected:
|
|
|
|
virtual void _draw();
|
|
|
|
static void _bind_methods();
|
2016-07-07 02:46:04 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void _validate_property(PropertyInfo &property) const;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
void set_texture(const Ref<Texture> &p_texture);
|
2014-05-29 13:56:39 +00:00
|
|
|
Ref<Texture> get_texture() const;
|
|
|
|
|
|
|
|
void set_region(bool p_region);
|
|
|
|
bool is_region() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_region_rect(const Rect2 &p_region_rect);
|
2014-05-29 13:56:39 +00:00
|
|
|
Rect2 get_region_rect() const;
|
|
|
|
|
|
|
|
void set_frame(int p_frame);
|
|
|
|
int get_frame() const;
|
|
|
|
|
2019-08-07 10:54:30 +00:00
|
|
|
void set_frame_coords(const Vector2 &p_coord);
|
2019-01-25 18:21:23 +00:00
|
|
|
Vector2 get_frame_coords() const;
|
|
|
|
|
2014-05-29 13:56:39 +00:00
|
|
|
void set_vframes(int p_amount);
|
|
|
|
int get_vframes() const;
|
|
|
|
|
|
|
|
void set_hframes(int p_amount);
|
|
|
|
int get_hframes() const;
|
|
|
|
|
|
|
|
virtual Rect2 get_item_rect() const;
|
|
|
|
|
|
|
|
Sprite3D();
|
2017-01-14 11:26:56 +00:00
|
|
|
//~Sprite3D();
|
2014-05-29 13:56:39 +00:00
|
|
|
};
|
|
|
|
|
2016-06-08 21:03:06 +00:00
|
|
|
class AnimatedSprite3D : public SpriteBase3D {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(AnimatedSprite3D, SpriteBase3D);
|
2016-06-08 21:03:06 +00:00
|
|
|
|
|
|
|
Ref<SpriteFrames> frames;
|
|
|
|
bool playing;
|
|
|
|
StringName animation;
|
|
|
|
int frame;
|
|
|
|
|
|
|
|
bool centered;
|
|
|
|
|
|
|
|
float timeout;
|
|
|
|
|
|
|
|
bool hflip;
|
|
|
|
bool vflip;
|
|
|
|
|
|
|
|
Color modulate;
|
|
|
|
|
|
|
|
void _res_changed();
|
|
|
|
|
|
|
|
void _reset_timeout();
|
|
|
|
void _set_playing(bool p_playing);
|
|
|
|
bool _is_playing() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void _draw();
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void _validate_property(PropertyInfo &property) const;
|
2016-06-08 21:03:06 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
|
|
|
|
Ref<SpriteFrames> get_sprite_frames() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void play(const StringName &p_animation = StringName());
|
2016-06-08 21:03:06 +00:00
|
|
|
void stop();
|
|
|
|
bool is_playing() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_animation(const StringName &p_animation);
|
2016-06-08 21:03:06 +00:00
|
|
|
StringName get_animation() const;
|
|
|
|
|
|
|
|
void set_frame(int p_frame);
|
|
|
|
int get_frame() const;
|
|
|
|
|
|
|
|
virtual Rect2 get_item_rect() const;
|
|
|
|
|
|
|
|
virtual String get_configuration_warning() const;
|
|
|
|
AnimatedSprite3D();
|
|
|
|
};
|
2014-05-29 13:56:39 +00:00
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(SpriteBase3D::DrawFlags);
|
|
|
|
VARIANT_ENUM_CAST(SpriteBase3D::AlphaCutMode);
|
|
|
|
#endif // SPRITE_3D_H
|