diff options
Diffstat (limited to 'scene/3d/sprite_3d.cpp')
-rw-r--r-- | scene/3d/sprite_3d.cpp | 282 |
1 files changed, 4 insertions, 278 deletions
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index e45cb6d5b9..49a3205f21 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -70,13 +70,9 @@ void SpriteBase3D::_notification(int p_what) { if (!pending_update) _im_update(); - Node *parent = get_parent(); - if (parent) { - - parent_sprite = parent->cast_to<SpriteBase3D>(); - if (parent_sprite) { - pI = parent_sprite->children.push_back(this); - } + parent_sprite = Object::cast_to<SpriteBase3D>(get_parent()); + if (parent_sprite) { + pI = parent_sprite->children.push_back(this); } } @@ -602,219 +598,6 @@ Sprite3D::Sprite3D() { //////////////////////////////////////// -#if 0 - -void AnimatedSprite3D::_draw() { - - RID immediate = get_immediate(); - VS::get_singleton()->immediate_clear(immediate); - - if (!frames.is_valid() || !frames->get_frame_count(animation) || frame<0 || frame>=frames->get_frame_count(animation)) { - return; - } - - Ref<Texture> texture = frames->get_frame(animation,frame); - if (!texture.is_valid()) - return; //no texuture no life - Vector2 tsize = texture->get_size(); - if (tsize.x==0 || tsize.y==0) - return; - - Size2i s=tsize; - Rect2i src_rect; - - src_rect.size=s; - - Point2i ofs=get_offset(); - if (is_centered()) - ofs-=s/2; - - Rect2i dst_rect(ofs,s); - - - Rect2 final_rect; - Rect2 final_src_rect; - if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect)) - return; - - - if (final_rect.size.x==0 || final_rect.size.y==0) - return; - - Color color=_get_color_accum(); - color.a*=get_opacity(); - - float pixel_size=get_pixel_size(); - - Vector2 vertices[4]={ - - (final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size, - (final_rect.pos+final_rect.size) * pixel_size, - (final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size, - final_rect.pos * pixel_size, - - - }; - Vector2 uvs[4]={ - final_src_rect.pos / tsize, - (final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize, - (final_src_rect.pos+final_src_rect.size) / tsize, - (final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize, - }; - - if (is_flipped_h()) { - SWAP(uvs[0],uvs[1]); - SWAP(uvs[2],uvs[3]); - } - if (is_flipped_v()) { - - SWAP(uvs[0],uvs[3]); - SWAP(uvs[1],uvs[2]); - } - - - Vector3 normal; - int axis = get_axis(); - normal[axis]=1.0; - - RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS); - VS::get_singleton()->immediate_set_material(immediate,mat); - - VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid()); - - int x_axis = ((axis + 1) % 3); - int y_axis = ((axis + 2) % 3); - - if (axis!=Vector3::AXIS_Z) { - SWAP(x_axis,y_axis); - - for(int i=0;i<4;i++) { - //uvs[i] = Vector2(1.0,1.0)-uvs[i]; - //SWAP(vertices[i].x,vertices[i].y); - if (axis==Vector3::AXIS_Y) { - vertices[i].y = - vertices[i].y; - } else if (axis==Vector3::AXIS_X) { - vertices[i].x = - vertices[i].x; - } - } - } - - AABB aabb; - - for(int i=0;i<4;i++) { - VS::get_singleton()->immediate_normal(immediate,normal); - VS::get_singleton()->immediate_color(immediate,color); - VS::get_singleton()->immediate_uv(immediate,uvs[i]); - - Vector3 vtx; - vtx[x_axis]=vertices[i][0]; - vtx[y_axis]=vertices[i][1]; - VS::get_singleton()->immediate_vertex(immediate,vtx); - if (i==0) { - aabb.pos=vtx; - aabb.size=Vector3(); - } else { - aabb.expand_to(vtx); - } - } - set_aabb(aabb); - VS::get_singleton()->immediate_end(immediate); - -} - -void AnimatedSprite3D::_bind_methods(){ - - ClassDB::bind_method(D_METHOD("set_sprite_frames","sprite_frames"),&AnimatedSprite3D::set_sprite_frames); - ClassDB::bind_method(D_METHOD("get_sprite_frames"),&AnimatedSprite3D::get_sprite_frames); - ClassDB::bind_method(D_METHOD("set_frame","frame"),&AnimatedSprite3D::set_frame); - ClassDB::bind_method(D_METHOD("get_frame"),&AnimatedSprite3D::get_frame); - - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), "set_sprite_frames","get_sprite_frames"); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame"); - - ADD_SIGNAL(MethodInfo("frame_changed")); - -} - - - - -void AnimatedSprite3D::set_sprite_frames(const Ref<SpriteFrames>& p_sprite_frames) { - - - if (frames==p_sprite_frames) - return; - - if (frames.is_valid()) - frames->disconnect("changed",this,"_queue_update"); - frames=p_sprite_frames; - if (frames.is_valid()) - frames->connect("changed",this,"_queue_update"); - - if (!frames.is_valid() || frame >=frames->get_frame_count(animation)) { - frame=0; - - } - _queue_update(); - -} - -Ref<SpriteFrames> AnimatedSprite3D::get_sprite_frames() const{ - - return frames; -} - -void AnimatedSprite3D::set_frame(int p_frame){ - - if (frames.is_null()) - return; - - ERR_FAIL_INDEX(p_frame,frames->get_frame_count(animation)); - - if (frame==p_frame) - return; - - frame=p_frame; - _queue_update(); - emit_signal(SceneStringNames::get_singleton()->frame_changed); - -} -int AnimatedSprite3D::get_frame() const{ - - return frame; -} - -Rect2 AnimatedSprite3D::get_item_rect() const { - - if (!frames.is_valid() || !frames->get_frame_count(animation) || frame<0 || frame>=frames->get_frame_count(animation)) { - return Rect2(0,0,1,1); - } - - Ref<Texture> t = frames->get_frame(animation,frame); - if (t.is_null()) - return Rect2(0,0,1,1); - Size2i s = t->get_size(); - - Point2i ofs=get_offset(); - if (is_centered()) - ofs-=s/2; - - if (s==Size2(0,0)) - s=Size2(1,1); - - return Rect2(ofs,s); -} - - - -AnimatedSprite3D::AnimatedSprite3D() { - - animation="current"; - frame=0; -} - -#endif - void AnimatedSprite3D::_draw() { RID immediate = get_immediate(); @@ -1026,63 +809,6 @@ void AnimatedSprite3D::_notification(int p_what) { timeout -= to_process; } } break; -#if 0 - case NOTIFICATION_DRAW: { - - if (frames.is_null()) { - print_line("no draw no faemos"); - return; - } - - if (frame<0) { - print_line("no draw frame <0"); - return; - } - - if (!frames->has_animation(animation)) { - print_line("no draw no anim: "+String(animation)); - return; - } - - - - Ref<Texture> texture = frames->get_frame(animation,frame); - if (texture.is_null()) { - print_line("no draw texture is null"); - return; - } - - //print_line("DECIDED TO DRAW"); - - RID ci = get_canvas_item(); - - /* - texture->draw(ci,Point2()); - break; - */ - - Size2i s; - s = texture->get_size(); - Point2 ofs=offset; - if (centered) - ofs-=s/2; - - if (OS::get_singleton()->get_use_pixel_snap()) { - ofs=ofs.floor(); - } - Rect2 dst_rect(ofs,s); - - if (hflip) - dst_rect.size.x=-dst_rect.size.x; - if (vflip) - dst_rect.size.y=-dst_rect.size.y; - - //texture->draw_rect(ci,dst_rect,false,modulate); - texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()),modulate); - //VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate); - - } break; -#endif } } |