Skip to content

Commit 9ff6d55

Browse files
committed
Polygon2D
-=-=-=-=- Another gift for those who make 2D games: -Edit polygons, concave or convex, color them, texture them and uv-map them -Corresponding editor -Can have a custom pivot, so they are compatible with bones and IK
1 parent 3d68949 commit 9ff6d55

16 files changed

+1631
-12
lines changed

core/variant_op.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,59 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
33543354
case INT_ARRAY:{ r_dst=a; } return;
33553355
case REAL_ARRAY:{ r_dst=a; } return;
33563356
case STRING_ARRAY:{ r_dst=a; } return;
3357-
case VECTOR3_ARRAY:{ r_dst=a; } return;
3357+
case VECTOR2_ARRAY:{
3358+
const DVector<Vector2> *arr_a=reinterpret_cast<const DVector<Vector2>* >(a._data._mem);
3359+
const DVector<Vector2> *arr_b=reinterpret_cast<const DVector<Vector2>* >(b._data._mem);
3360+
int sz = arr_a->size();
3361+
if (sz==0 || arr_b->size()!=sz) {
3362+
3363+
r_dst=a;
3364+
} else {
3365+
3366+
DVector<Vector2> v;
3367+
v.resize(sz);
3368+
{
3369+
DVector<Vector2>::Write vw=v.write();
3370+
DVector<Vector2>::Read ar=arr_a->read();
3371+
DVector<Vector2>::Read br=arr_b->read();
3372+
3373+
for(int i=0;i<sz;i++) {
3374+
vw[i]=ar[i].linear_interpolate(br[i],c);
3375+
}
3376+
}
3377+
r_dst=v;
3378+
3379+
}
3380+
3381+
3382+
} return;
3383+
case VECTOR3_ARRAY:{
3384+
3385+
3386+
const DVector<Vector3> *arr_a=reinterpret_cast<const DVector<Vector3>* >(a._data._mem);
3387+
const DVector<Vector3> *arr_b=reinterpret_cast<const DVector<Vector3>* >(b._data._mem);
3388+
int sz = arr_a->size();
3389+
if (sz==0 || arr_b->size()!=sz) {
3390+
3391+
r_dst=a;
3392+
} else {
3393+
3394+
DVector<Vector3> v;
3395+
v.resize(sz);
3396+
{
3397+
DVector<Vector3>::Write vw=v.write();
3398+
DVector<Vector3>::Read ar=arr_a->read();
3399+
DVector<Vector3>::Read br=arr_b->read();
3400+
3401+
for(int i=0;i<sz;i++) {
3402+
vw[i]=ar[i].linear_interpolate(br[i],c);
3403+
}
3404+
}
3405+
r_dst=v;
3406+
3407+
}
3408+
3409+
} return;
33583410
case COLOR_ARRAY:{ r_dst=a; } return;
33593411
default: {
33603412

scene/2d/path_texture.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "path_texture.h"
2+
3+
4+
void PathTexture::set_begin_texture(const Ref<Texture>& p_texture) {
5+
6+
begin=p_texture;
7+
update();
8+
}
9+
10+
Ref<Texture> PathTexture::get_begin_texture() const{
11+
12+
return begin;
13+
}
14+
15+
void PathTexture::set_repeat_texture(const Ref<Texture>& p_texture){
16+
17+
repeat=p_texture;
18+
update();
19+
20+
}
21+
Ref<Texture> PathTexture::get_repeat_texture() const{
22+
23+
return repeat;
24+
}
25+
26+
void PathTexture::set_end_texture(const Ref<Texture>& p_texture){
27+
28+
end=p_texture;
29+
update();
30+
}
31+
Ref<Texture> PathTexture::get_end_texture() const{
32+
33+
return end;
34+
}
35+
36+
void PathTexture::set_subdivisions(int p_amount){
37+
38+
ERR_FAIL_INDEX(p_amount,32);
39+
subdivs=p_amount;
40+
update();
41+
42+
}
43+
44+
int PathTexture::get_subdivisions() const{
45+
46+
return subdivs;
47+
}
48+
49+
void PathTexture::set_overlap(int p_amount){
50+
51+
overlap=p_amount;
52+
update();
53+
}
54+
int PathTexture::get_overlap() const{
55+
56+
return overlap;
57+
}
58+
59+
60+
PathTexture::PathTexture() {
61+
62+
overlap=0;
63+
subdivs=1;
64+
}

scene/2d/path_texture.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef PATH_TEXTURE_H
2+
#define PATH_TEXTURE_H
3+
4+
#include "scene/2d/node_2d.h"
5+
6+
class PathTexture : public Node2D {
7+
OBJ_TYPE( PathTexture, Node2D );
8+
9+
Ref<Texture> begin;
10+
Ref<Texture> repeat;
11+
Ref<Texture> end;
12+
int subdivs;
13+
bool overlap;
14+
public:
15+
16+
void set_begin_texture(const Ref<Texture>& p_texture);
17+
Ref<Texture> get_begin_texture() const;
18+
19+
void set_repeat_texture(const Ref<Texture>& p_texture);
20+
Ref<Texture> get_repeat_texture() const;
21+
22+
void set_end_texture(const Ref<Texture>& p_texture);
23+
Ref<Texture> get_end_texture() const;
24+
25+
void set_subdivisions(int p_amount);
26+
int get_subdivisions() const;
27+
28+
void set_overlap(int p_amount);
29+
int get_overlap() const;
30+
31+
PathTexture();
32+
};
33+
34+
#endif // PATH_TEXTURE_H

0 commit comments

Comments
 (0)