diff options
Diffstat (limited to 'scene')
43 files changed, 700 insertions, 1140 deletions
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index ded86702ef..819b06e095 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -507,7 +507,13 @@ void Particles2D::_notification(int p_what) { } - for(int i=0;i<particle_count;i++) { + int start_particle = (int)(time * (float)particle_count / lifetime); + + for (int id=0;id<particle_count;++id) { + int i = start_particle + id; + if (i >= particle_count) { + i -= particle_count; + } Particle &p=pdata[i]; if (!p.active) diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 7678cb980c..308aa8402f 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -925,6 +925,8 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { normal=rest_info.normal; collider=rest_info.collider_id; collider_vel=rest_info.linear_velocity; + collider_shape=rest_info.shape; + collider_metadata=rest_info.metadata; } } @@ -1013,6 +1015,20 @@ ObjectID KinematicBody2D::get_collider() const { return collider; } + +int KinematicBody2D::get_collider_shape() const { + + ERR_FAIL_COND_V(!colliding,0); + return collider_shape; +} + +Variant KinematicBody2D::get_collider_metadata() const { + + ERR_FAIL_COND_V(!colliding,0); + return collider_metadata; + +} + void KinematicBody2D::set_collide_with_static_bodies(bool p_enable) { collide_static=p_enable; @@ -1076,6 +1092,8 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_collision_normal"),&KinematicBody2D::get_collision_normal); ObjectTypeDB::bind_method(_MD("get_collider_velocity"),&KinematicBody2D::get_collider_velocity); ObjectTypeDB::bind_method(_MD("get_collider:Object"),&KinematicBody2D::_get_collider); + ObjectTypeDB::bind_method(_MD("get_collider_shape"),&KinematicBody2D::get_collider_shape); + ObjectTypeDB::bind_method(_MD("get_collider_metadata"),&KinematicBody2D::get_collider_metadata); ObjectTypeDB::bind_method(_MD("set_collide_with_static_bodies","enable"),&KinematicBody2D::set_collide_with_static_bodies); @@ -1112,6 +1130,8 @@ KinematicBody2D::KinematicBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_KI colliding=false; collider=0; + collider_shape=0; + margin=0.08; } KinematicBody2D::~KinematicBody2D() { diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index b2625c3d97..e429ca1432 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -254,7 +254,8 @@ class KinematicBody2D : public PhysicsBody2D { Vector2 normal; Vector2 collider_vel; ObjectID collider; - + int collider_shape; + Variant collider_metadata; Variant _get_collider() const; @@ -273,6 +274,8 @@ public: Vector2 get_collision_normal() const; Vector2 get_collider_velocity() const; ObjectID get_collider() const; + int get_collider_shape() const; + Variant get_collider_metadata() const; void set_collide_with_static_bodies(bool p_enable); bool can_collide_with_static_bodies() const; diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 7d033ed87f..8c3bbfdfc9 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -64,20 +64,20 @@ void Sprite::_notification(int p_what) { break; */ - Size2i s; - Rect2i src_rect; + Size2 s; + Rect2 src_rect; if (region) { s=region_rect.size; src_rect=region_rect; } else { - s = texture->get_size(); - s=s/Size2i(hframes,vframes); + s = Size2(texture->get_size()); + s=s/Size2(hframes,vframes); src_rect.size=s; - src_rect.pos.x+=(frame%hframes)*s.x; - src_rect.pos.y+=(frame/hframes)*s.y; + src_rect.pos.x+=float(frame%hframes)*s.x; + src_rect.pos.y+=float(frame/hframes)*s.y; } @@ -85,7 +85,7 @@ void Sprite::_notification(int p_what) { if (centered) ofs-=s/2; - Rect2i dst_rect(ofs,s); + Rect2 dst_rect(ofs,s); if (hflip) dst_rect.size.x=-dst_rect.size.x; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 72ef653d14..eb04ca924f 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -179,6 +179,7 @@ void TileMap::_update_dirty_quadrants() { vs->canvas_item_clear(q.canvas_item); ps->body_clear_shapes(q.static_body); + int shape_idx=0; for(int i=0;i<q.cells.size();i++) { @@ -259,6 +260,8 @@ void TileMap::_update_dirty_quadrants() { ps->body_add_shape(q.static_body,shape->get_rid(),xform); + ps->body_set_shape_metadata(q.static_body,shape_idx++,Vector2(E->key().x,E->key().y)); + } } } diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp index c1cc1f6b68..b55093a779 100644 --- a/scene/3d/baked_light_instance.cpp +++ b/scene/3d/baked_light_instance.cpp @@ -63,3 +63,81 @@ BakedLightInstance::BakedLightInstance() { } +///////////////////////// + + +void BakedLightSampler::set_param(Param p_param,float p_value) { + ERR_FAIL_INDEX(p_param,PARAM_MAX); + params[p_param]=p_value; + VS::get_singleton()->baked_light_sampler_set_param(base,VS::BakedLightSamplerParam(p_param),p_value); +} + +float BakedLightSampler::get_param(Param p_param) const{ + + ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0); + return params[p_param]; + +} + +void BakedLightSampler::set_resolution(int p_resolution){ + + ERR_FAIL_COND(p_resolution<4 && p_resolution>32); + resolution=p_resolution; + VS::get_singleton()->baked_light_sampler_set_resolution(base,resolution); +} +int BakedLightSampler::get_resolution() const { + + return resolution; +} + +AABB BakedLightSampler::get_aabb() const { + + float r = get_param(PARAM_RADIUS); + return AABB( Vector3(-r,-r,-r),Vector3(r*2,r*2,r*2)); +} +DVector<Face3> BakedLightSampler::get_faces(uint32_t p_usage_flags) const { + return DVector<Face3>(); +} + +void BakedLightSampler::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_param","param","value"),&BakedLightSampler::set_param); + ObjectTypeDB::bind_method(_MD("get_param","param"),&BakedLightSampler::get_param); + + ObjectTypeDB::bind_method(_MD("set_resolution","resolution"),&BakedLightSampler::set_resolution); + ObjectTypeDB::bind_method(_MD("get_resolution"),&BakedLightSampler::get_resolution); + + + BIND_CONSTANT( PARAM_RADIUS ); + BIND_CONSTANT( PARAM_STRENGTH ); + BIND_CONSTANT( PARAM_ATTENUATION ); + BIND_CONSTANT( PARAM_DETAIL_RATIO ); + BIND_CONSTANT( PARAM_MAX ); + + ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/radius",PROPERTY_HINT_RANGE,"0.01,1024,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_RADIUS); + ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/strength",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_STRENGTH); + ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/attenuation",PROPERTY_HINT_EXP_EASING),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION); + ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/detail_ratio",PROPERTY_HINT_RANGE,"0.01,1.0,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_DETAIL_RATIO); +// ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/detail_ratio",PROPERTY_HINT_RANGE,"0,20,1"),_SCS("set_param"),_SCS("get_param"),PARAM_DETAIL_RATIO); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"params/resolution",PROPERTY_HINT_RANGE,"4,32,1"),_SCS("set_resolution"),_SCS("get_resolution")); + +} + +BakedLightSampler::BakedLightSampler() { + + base = VS::get_singleton()->baked_light_sampler_create(); + set_base(base); + + params[PARAM_RADIUS]=1.0; + params[PARAM_STRENGTH]=1.0; + params[PARAM_ATTENUATION]=1.0; + params[PARAM_DETAIL_RATIO]=0.1; + resolution=16; + + +} + +BakedLightSampler::~BakedLightSampler(){ + + VS::get_singleton()->free(base); +} diff --git a/scene/3d/baked_light_instance.h b/scene/3d/baked_light_instance.h index b904ced9a7..0694c813ce 100644 --- a/scene/3d/baked_light_instance.h +++ b/scene/3d/baked_light_instance.h @@ -30,4 +30,46 @@ public: BakedLightInstance(); }; + + +class BakedLightSampler : public VisualInstance { + OBJ_TYPE(BakedLightSampler,VisualInstance); + + +public: + + enum Param { + PARAM_RADIUS=VS::BAKED_LIGHT_SAMPLER_RADIUS, + PARAM_STRENGTH=VS::BAKED_LIGHT_SAMPLER_STRENGTH, + PARAM_ATTENUATION=VS::BAKED_LIGHT_SAMPLER_ATTENUATION, + PARAM_DETAIL_RATIO=VS::BAKED_LIGHT_SAMPLER_DETAIL_RATIO, + PARAM_MAX=VS::BAKED_LIGHT_SAMPLER_MAX + }; + + + +protected: + + RID base; + float params[PARAM_MAX]; + int resolution; + static void _bind_methods(); +public: + + virtual AABB get_aabb() const; + virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; + + void set_param(Param p_param,float p_value); + float get_param(Param p_param) const; + + void set_resolution(int p_resolution); + int get_resolution() const; + + BakedLightSampler(); + ~BakedLightSampler(); +}; + +VARIANT_ENUM_CAST( BakedLightSampler::Param ); + + #endif // BAKED_LIGHT_H diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index c85ad70c63..ab28c0c8d4 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -219,11 +219,14 @@ void Camera::_notification(int p_what) { } + camera_group = "_vp_cameras"+itos(get_viewport()->get_instance_ID()); + add_to_group(camera_group); if (viewport_ptr) viewport_ptr->cameras.insert(this); if (current) make_current(); + } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -241,6 +244,8 @@ void Camera::_notification(int p_what) { if (viewport_ptr) viewport_ptr->cameras.erase(this); viewport_ptr=NULL; + remove_from_group(camera_group); + } break; case NOTIFICATION_BECAME_CURRENT: { @@ -314,6 +319,20 @@ void Camera::make_current() { //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this); } + +void Camera::_camera_make_next_current(Node *p_exclude) { + + if (this==p_exclude) + return; + if (!is_inside_scene()) + return; + if (get_viewport()->get_camera()!=NULL) + return; + + make_current(); +} + + void Camera::clear_current() { current=false; @@ -321,8 +340,12 @@ void Camera::clear_current() { return; if (viewport_ptr) { - if (viewport_ptr->get_camera()==this) + if (viewport_ptr->get_camera()==this) { viewport_ptr->_set_camera(NULL); + //a group is used beause this needs to be in order to be deterministic + get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_next_current",this); + + } } } @@ -444,7 +467,15 @@ Vector3 Camera::project_local_ray_normal(const Point2& p_pos) const { ERR_FAIL_COND_V(!is_inside_scene(),Vector3()); } + +#if 0 Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Vector2 cpos = p_pos; +#else + + Size2 viewport_size = viewport_ptr->get_camera_rect_size(); + Vector2 cpos = viewport_ptr->get_camera_coords(p_pos); +#endif Vector3 ray; @@ -456,10 +487,9 @@ Vector3 Camera::project_local_ray_normal(const Point2& p_pos) const { cm.set_perspective(fov,viewport_size.get_aspect(),near,far,keep_aspect==KEEP_WIDTH); float screen_w,screen_h; cm.get_viewport_size(screen_w,screen_h); - ray=Vector3( ((p_pos.x/viewport_size.width)*2.0-1.0)*screen_w, ((1.0-(p_pos.y/viewport_size.height))*2.0-1.0)*screen_h,-near).normalized(); + ray=Vector3( ((cpos.x/viewport_size.width)*2.0-1.0)*screen_w, ((1.0-(cpos.y/viewport_size.height))*2.0-1.0)*screen_h,-near).normalized(); } - return ray; }; @@ -471,8 +501,14 @@ Vector3 Camera::project_ray_origin(const Point2& p_pos) const { ERR_FAIL_COND_V(!is_inside_scene(),Vector3()); } +#if 0 Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Vector2 cpos = p_pos; +#else + Size2 viewport_size = viewport_ptr->get_camera_rect_size(); + Vector2 cpos = viewport_ptr->get_camera_coords(p_pos); +#endif ERR_FAIL_COND_V( viewport_size.y == 0, Vector3() ); // float aspect = viewport_size.x / viewport_size.y; @@ -482,7 +518,7 @@ Vector3 Camera::project_ray_origin(const Point2& p_pos) const { return get_camera_transform().origin; } else { - Vector2 pos = p_pos / viewport_size; + Vector2 pos = cpos / viewport_size; float vsize,hsize; if (keep_aspect==KEEP_WIDTH) { vsize = size/viewport_size.get_aspect(); @@ -636,6 +672,7 @@ void Camera::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment); ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode); ObjectTypeDB::bind_method(_MD("get_keep_aspect_mode"),&Camera::get_keep_aspect_mode); + ObjectTypeDB::bind_method(_MD("_camera_make_next_current"),&Camera::_camera_make_next_current); //ObjectTypeDB::bind_method( _MD("_camera_make_current"),&Camera::_camera_make_current ); BIND_CONSTANT( PROJECTION_PERSPECTIVE ); @@ -732,7 +769,8 @@ Camera::Camera() { mode=PROJECTION_PERSPECTIVE; set_perspective(60.0,0.1,100.0); keep_aspect=KEEP_HEIGHT; - layers=0xFFFFFFFF; + layers=0xfffff; + VisualServer::get_singleton()->camera_set_visible_layers(camera,layers); //active=false; } diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 014c7cb520..bac8173bb7 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -66,6 +66,8 @@ private: RID camera; RID scenario_id; + String camera_group; + uint32_t layers; Viewport *viewport_ptr; @@ -74,6 +76,7 @@ private: virtual bool _can_gizmo_scale() const; virtual RES _get_gizmo_geometry() const; + void _camera_make_next_current(Node *p_exclude); //void _camera_make_current(Node *p_camera); diff --git a/scene/3d/follow_camera.cpp b/scene/3d/follow_camera.cpp deleted file mode 100644 index e7ced6c2ba..0000000000 --- a/scene/3d/follow_camera.cpp +++ /dev/null @@ -1,778 +0,0 @@ -/*************************************************************************/ -/* follow_camera.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* 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. */ -/*************************************************************************/ -#include "follow_camera.h" - - -#include "physics_body.h" -#include "scene/resources/surface_tool.h" - -void FollowCamera::_set_initial_orbit(const Vector2& p_orbit) { - - initial_orbit=p_orbit; - set_orbit(p_orbit); -} - - - -void FollowCamera::_clear_queries() { - - if (!queries_active) - return; -#if 0 - for(int i=0;i<3;i++) - PhysicsServer::get_singleton()->query_clear(clip_ray[i].query); -#endif - queries_active=false; - -} - -void FollowCamera::_compute_camera() { - - // update the transform with the next proposed transform (camera is 1 logic frame delayed) - - /* - float time = get_root_node()->get_frame_time(); - Vector3 oldp = accepted.get_origin(); - Vector3 newp = proposed.get_origin(); - - float frame_dist = time * - if (oldp.distance_to(newp) > - */ - - float time = get_process_delta_time(); - bool noblend=false; - - if (clip) { - - if ((clip_ray[0].clipped==clip_ray[2].clipped || fullclip) && clip_ray[1].clipped) { - //all have been clipped - proposed_pos=clip_ray[1].clip_pos-extraclip*(proposed_pos-target_pos).normalized(); - if (clip_ray[0].clipped) - fullclip=true; - noblend=true; - - - } else { - - - //Vector3 rel=follow_pos-target_pos; - - if (clip_ray[0].clipped && !clip_ray[2].clipped) { - - float distance = target_pos.distance_to(clip_ray[0].clip_pos); - real_t amount = 1.0-(distance/clip_len); - amount = CLAMP(amount,0,1)*autoturn_speed*time; - if (clip_ray[1].clipped) - amount*=2.0; - //rotate_rel=Matrix3(Vector3(0,1,0),amount).xform(rel); - rotate_orbit(Vector2(0,amount)); - - } else if (clip_ray[2].clipped && !clip_ray[0].clipped) { - - float distance = target_pos.distance_to(clip_ray[2].clip_pos); - real_t amount = 1.0-(distance/clip_len); - amount = CLAMP(amount,0,1)*autoturn_speed*time; - if (clip_ray[1].clipped) - amount*=2.0; - rotate_orbit(Vector2(0,-amount)); - } - - fullclip=false; - - } - } - - - Vector3 base_pos = get_global_transform().origin; - Vector3 pull_from = base_pos; - pull_from.y+=height; // height compensate - - - - Vector3 camera_target; - if (use_lookat_target) { - - camera_target = lookat_target; - } else { - camera_target = base_pos; - }; - - Transform proposed; - proposed.set_look_at(proposed_pos,camera_target,up_vector); - proposed = proposed * Transform(Matrix3(Vector3(1,0,0),Math::deg2rad(inclination)),Vector3()); //inclination - - - accepted=proposed; - if (smooth && !noblend) { - - - Vector3 vec1 = accepted.origin; - Vector3 vec2 = final.origin; - final.origin = vec2.linear_interpolate(vec1, MIN(1,smooth_pos_ratio * time));; - - Quat q1 = accepted.basis; - Quat q2 = final.basis; - final.basis = q2.slerp(q1, MIN(1,smooth_rot_ratio * time)); - - } else { - final=accepted; - } - - _update_camera(); - - // calculate the next proposed transform - - - Vector3 new_pos; - - { /*follow code*/ - - - - /* calculate some variables */ - - Vector3 rel = follow_pos - pull_from; - - float l = rel.length(); - Vector3 rel_n = (l > 0) ? (rel/l) : Vector3(); - float ang = Math::acos(rel_n.dot( Vector3(0,1,0) )); - - Vector3 tangent = rel_n; - tangent.y=0; // get rid of y - if (tangent.length_squared() < CMP_EPSILON2) - tangent=Vector3(0,0,1); // use Z as tangent if rel is parallel to y - else - tangent.normalize(); - - /* now start applying the rules */ - - //clip distance - if (l > max_distance) - l=max_distance; - if (l < min_distance) - l=min_distance; - - //fix angle - - float ang_min = Math_PI * 0.5 + Math::deg2rad(min_orbit_x); - float ang_max = Math_PI * 0.5 + Math::deg2rad(max_orbit_x); - - if (ang<ang_min) - ang=ang_min; - if (ang>ang_max) - ang=ang_max; - - /* finally, rebuild the validated camera position */ - - new_pos=Vector3(0,Math::cos(ang),0); - new_pos+=tangent*Math::sin(ang); - new_pos*=l; - new_pos+=pull_from; - follow_pos=new_pos; - - } - - proposed_pos=new_pos; - - Vector3 rel = new_pos-camera_target; - - - if (clip) { - - Vector<RID> exclude; - exclude.push_back(target_body); - - for(int i=0;i<3;i++) { - - clip_ray[i].clipped=false; - clip_ray[i].clip_pos=Vector3(); - clip_ray[i].cast_pos=camera_target; - - Vector3 cast_to = camera_target+Matrix3(Vector3(0,1,0),Math::deg2rad(autoturn_tolerance*(i-1.0))).xform(rel); - - - if (i!=1) { - - Vector3 side = rel.cross(Vector3(0,1,0)).normalized()*(i-1.0); - clip_ray[i].cast_pos+side*target_width+rel.normalized()*target_width; - - Vector3 d = -rel; - d.rotate(Vector3(0,1,0),Math::deg2rad(get_fov())*(i-1.0)); - Plane p(new_pos,new_pos+d,new_pos+Vector3(0,1,0)); //fov clipping plane, build a face and use it as plane, facing doesn't matter - Vector3 intersect; - if (p.intersects_segment(clip_ray[i].cast_pos,cast_to,&intersect)) - cast_to=intersect; - - } else { - - cast_to+=rel.normalized()*extraclip; - } - - // PhysicsServer::get_singleton()->query_intersection(clip_ray[i].query,get_world()->get_space(),exclude); - // PhysicsServer::get_singleton()->query_intersection_segment(clip_ray[i].query,clip_ray[i].cast_pos,cast_to); - - - - - } - - queries_active=true; - } else { - - _clear_queries(); - } - target_pos=camera_target; - clip_len=rel.length(); - -} - -void FollowCamera::set_use_lookat_target(bool p_use, const Vector3 &p_lookat) { - - use_lookat_target = p_use; - lookat_target = p_lookat; -}; - - -void FollowCamera::_notification(int p_what) { - - switch(p_what) { - - case NOTIFICATION_PROCESS: { - - - _compute_camera(); - } break; - - case NOTIFICATION_ENTER_WORLD: { - - set_orbit(orbit); - set_distance(distance); - - accepted=final=get_global_transform(); - proposed_pos=accepted.origin; - - target_body = RID(); -/* - Node* parent = get_parent(); - while (parent) { - PhysicsBody* p = parent->cast_to<PhysicsBody>(); - if (p) { - target_body = p->get_body(); - break; - }; - parent = parent->get_parent(); - }; -*/ - set_process(true); - - } break; - case NOTIFICATION_TRANSFORM_CHANGED: { - - } break; - case NOTIFICATION_EXIT_WORLD: { - - distance=get_distance(); - orbit=get_orbit(); - _clear_queries(); - - } break; - case NOTIFICATION_BECAME_CURRENT: { - - set_process(true); - } break; - case NOTIFICATION_LOST_CURRENT: { - - set_process(false); - _clear_queries(); - - } break; - } - -} - - - -void FollowCamera::set_orbit(const Vector2& p_orbit) { - - orbit=p_orbit; - - if(is_inside_scene()) { - - Vector3 char_pos = get_global_transform().origin; - char_pos.y+=height; - float d = char_pos.distance_to(follow_pos); - - Matrix3 m; - m.rotate(Vector3(0,1,0),orbit.y); - m.rotate(Vector3(1,0,0),orbit.x); - - follow_pos=char_pos + m.get_axis(2) * d; - - } - - update_gizmo(); - -} -void FollowCamera::set_orbit_x(float p_x) { - - orbit.x=p_x; - if(is_inside_scene()) - set_orbit(Vector2( p_x, get_orbit().y )); -} -void FollowCamera::set_orbit_y(float p_y) { - - - orbit.y=p_y; - if(is_inside_scene()) - set_orbit(Vector2( get_orbit().x, p_y )); - -} -Vector2 FollowCamera::get_orbit() const { - - - if (is_inside_scene()) { - - Vector3 char_pos = get_global_transform().origin; - char_pos.y+=height; - Vector3 rel = (follow_pos - char_pos).normalized(); - Vector2 ret_orbit; - ret_orbit.x = Math::acos( Vector3(0,1,0).dot( rel ) ) - Math_PI * 0.5; - ret_orbit.y = Math::atan2(rel.x,rel.z); - return ret_orbit; - } - return orbit; -} - -void FollowCamera::rotate_orbit(const Vector2& p_relative) { - - if (is_inside_scene()) { - - Matrix3 m; - m.rotate(Vector3(0,1,0),Math::deg2rad(p_relative.y)); - m.rotate(Vector3(1,0,0),Math::deg2rad(p_relative.x)); - - Vector3 char_pos = get_global_transform().origin; - char_pos.y+=height; - Vector3 rel = (follow_pos - char_pos); - rel = m.xform(rel); - follow_pos=char_pos+rel; - - } - - orbit+=p_relative; - update_gizmo(); -} - -void FollowCamera::set_height(float p_height) { - - - height=p_height; - update_gizmo(); -} - -float FollowCamera::get_height() const { - - return height; - -} - -void FollowCamera::set_max_orbit_x(float p_max) { - - max_orbit_x=p_max; - update_gizmo(); -} - -float FollowCamera::get_max_orbit_x() const { - - return max_orbit_x; -} - -void FollowCamera::set_min_orbit_x(float p_min) { - - min_orbit_x=p_min; - update_gizmo(); -} - -float FollowCamera::get_min_orbit_x() const { - - return min_orbit_x; -} - -float FollowCamera::get_min_distance() const { - - return min_distance; -} -float FollowCamera::get_max_distance() const { - - return max_distance; -} - -void FollowCamera::set_min_distance(float p_min) { - - min_distance=p_min; - update_gizmo(); -} - -void FollowCamera::set_max_distance(float p_max) { - - max_distance = p_max; - update_gizmo(); -} - - -void FollowCamera::set_distance(float p_distance) { - - if (is_inside_scene()) { - - Vector3 char_pos = get_global_transform().origin; - char_pos.y+=height; - Vector3 rel = (follow_pos - char_pos).normalized(); - rel*=p_distance; - follow_pos=char_pos+rel; - - } - - distance=p_distance; -} - -float FollowCamera::get_distance() const { - - if (is_inside_scene()) { - - Vector3 char_pos = get_global_transform().origin; - char_pos.y+=height; - return (follow_pos - char_pos).length(); - - } - - return distance; -} - -void FollowCamera::set_clip(bool p_enabled) { - - - clip=p_enabled; - - if (!p_enabled) - _clear_queries(); -} - -bool FollowCamera::has_clip() const { - - return clip; - -} - - -void FollowCamera::set_autoturn(bool p_enabled) { - - - autoturn=p_enabled; -} - -bool FollowCamera::has_autoturn() const { - - return autoturn; - -} - -void FollowCamera::set_autoturn_tolerance(float p_degrees) { - - - autoturn_tolerance=p_degrees; -} -float FollowCamera::get_autoturn_tolerance() const { - - - return autoturn_tolerance; -} - -void FollowCamera::set_inclination(float p_degrees) { - - - inclination=p_degrees; -} -float FollowCamera::get_inclination() const { - - - return inclination; -} - - -void FollowCamera::set_autoturn_speed(float p_speed) { - - - autoturn_speed=p_speed; -} - -float FollowCamera::get_autoturn_speed() const { - - return autoturn_speed; - -} - - -RES FollowCamera::_get_gizmo_geometry() const { - - Ref<SurfaceTool> surface_tool( memnew( SurfaceTool )); - - Ref<FixedMaterial> mat( memnew( FixedMaterial )); - - mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(1.0,0.5,1.0,0.3) ); - mat->set_line_width(4); - mat->set_flag(Material::FLAG_DOUBLE_SIDED,true); - mat->set_flag(Material::FLAG_UNSHADED,true); -// mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true); - - surface_tool->begin(Mesh::PRIMITIVE_LINES); - surface_tool->set_material(mat); - - - int steps=16; - - Vector3 base_up = Matrix3(Vector3(1,0,0),Math::deg2rad(max_orbit_x)).get_axis(2); - Vector3 base_down = Matrix3(Vector3(1,0,0),Math::deg2rad(min_orbit_x)).get_axis(2); - - Vector3 ofs(0,height,0); - - for(int i=0;i<steps;i++) { - - - Matrix3 rot(Vector3(0,1,0),Math_PI*2*float(i)/steps); - Matrix3 rot2(Vector3(0,1,0),Math_PI*2*float(i+1)/steps); - - Vector3 up = rot.xform(base_up); - Vector3 up2 = rot2.xform(base_up); - - Vector3 down = rot.xform(base_down); - Vector3 down2 = rot2.xform(base_down); - - surface_tool->add_vertex(ofs+up*min_distance); - surface_tool->add_vertex(ofs+up*max_distance); - surface_tool->add_vertex(ofs+up*min_distance); - surface_tool->add_vertex(ofs+up2*min_distance); - surface_tool->add_vertex(ofs+up*max_distance); - surface_tool->add_vertex(ofs+up2*max_distance); - - surface_tool->add_vertex(ofs+down*min_distance); - surface_tool->add_vertex(ofs+down*max_distance); - surface_tool->add_vertex(ofs+down*min_distance); - surface_tool->add_vertex(ofs+down2*min_distance); - surface_tool->add_vertex(ofs+down*max_distance); - surface_tool->add_vertex(ofs+down2*max_distance); - - int substeps = 8; - - for(int j=0;j<substeps;j++) { - - Vector3 a = up.linear_interpolate(down,float(j)/substeps).normalized()*max_distance; - Vector3 b = up.linear_interpolate(down,float(j+1)/substeps).normalized()*max_distance; - Vector3 am = up.linear_interpolate(down,float(j)/substeps).normalized()*min_distance; - Vector3 bm = up.linear_interpolate(down,float(j+1)/substeps).normalized()*min_distance; - - surface_tool->add_vertex(ofs+a); - surface_tool->add_vertex(ofs+b); - surface_tool->add_vertex(ofs+am); - surface_tool->add_vertex(ofs+bm); - - } - } - - - return surface_tool->commit(); - - -} - - -void FollowCamera::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("_set_initial_orbit","orbit"),&FollowCamera::_set_initial_orbit); - ObjectTypeDB::bind_method(_MD("set_orbit","orbit"),&FollowCamera::set_orbit); - ObjectTypeDB::bind_method(_MD("get_orbit"),&FollowCamera::get_orbit); - ObjectTypeDB::bind_method(_MD("set_orbit_x","x"),&FollowCamera::set_orbit_x); - ObjectTypeDB::bind_method(_MD("set_orbit_y","y"),&FollowCamera::set_orbit_y); - ObjectTypeDB::bind_method(_MD("set_min_orbit_x","x"),&FollowCamera::set_min_orbit_x); - ObjectTypeDB::bind_method(_MD("get_min_orbit_x"),&FollowCamera::get_min_orbit_x); - ObjectTypeDB::bind_method(_MD("set_max_orbit_x","x"),&FollowCamera::set_max_orbit_x); - ObjectTypeDB::bind_method(_MD("get_max_orbit_x"),&FollowCamera::get_max_orbit_x); - ObjectTypeDB::bind_method(_MD("set_height","height"),&FollowCamera::set_height); - ObjectTypeDB::bind_method(_MD("get_height"),&FollowCamera::get_height); - ObjectTypeDB::bind_method(_MD("set_inclination","inclination"),&FollowCamera::set_inclination); - ObjectTypeDB::bind_method(_MD("get_inclination"),&FollowCamera::get_inclination); - - ObjectTypeDB::bind_method(_MD("rotate_orbit"),&FollowCamera::rotate_orbit); - ObjectTypeDB::bind_method(_MD("set_distance","distance"),&FollowCamera::set_distance); - ObjectTypeDB::bind_method(_MD("get_distance"),&FollowCamera::get_distance); - ObjectTypeDB::bind_method(_MD("set_max_distance","max_distance"),&FollowCamera::set_max_distance); - ObjectTypeDB::bind_method(_MD("get_max_distance"),&FollowCamera::get_max_distance); - ObjectTypeDB::bind_method(_MD("set_min_distance","min_distance"),&FollowCamera::set_min_distance); - ObjectTypeDB::bind_method(_MD("get_min_distance"),&FollowCamera::get_min_distance); - ObjectTypeDB::bind_method(_MD("set_clip","enable"),&FollowCamera::set_clip); - ObjectTypeDB::bind_method(_MD("has_clip"),&FollowCamera::has_clip); - ObjectTypeDB::bind_method(_MD("set_autoturn","enable"),&FollowCamera::set_autoturn); - ObjectTypeDB::bind_method(_MD("has_autoturn"),&FollowCamera::has_autoturn); - ObjectTypeDB::bind_method(_MD("set_autoturn_tolerance","degrees"),&FollowCamera::set_autoturn_tolerance); - ObjectTypeDB::bind_method(_MD("get_autoturn_tolerance"),&FollowCamera::get_autoturn_tolerance); - ObjectTypeDB::bind_method(_MD("set_autoturn_speed","speed"),&FollowCamera::set_autoturn_speed); - ObjectTypeDB::bind_method(_MD("get_autoturn_speed"),&FollowCamera::get_autoturn_speed); - ObjectTypeDB::bind_method(_MD("set_smoothing","enable"),&FollowCamera::set_smoothing); - ObjectTypeDB::bind_method(_MD("has_smoothing"),&FollowCamera::has_smoothing); - ObjectTypeDB::bind_method(_MD("set_rotation_smoothing","amount"),&FollowCamera::set_rotation_smoothing); - ObjectTypeDB::bind_method(_MD("get_rotation_smoothing"),&FollowCamera::get_rotation_smoothing); - ObjectTypeDB::bind_method(_MD("set_translation_smoothing","amount"),&FollowCamera::set_translation_smoothing); - ObjectTypeDB::bind_method(_MD("get_translation_smoothing"),&FollowCamera::get_translation_smoothing); - ObjectTypeDB::bind_method(_MD("set_use_lookat_target","use","lookat"),&FollowCamera::set_use_lookat_target, DEFVAL(Vector3())); - ObjectTypeDB::bind_method(_MD("set_up_vector","vector"),&FollowCamera::set_up_vector); - ObjectTypeDB::bind_method(_MD("get_up_vector"),&FollowCamera::get_up_vector); - - ObjectTypeDB::bind_method(_MD("_ray_collision"),&FollowCamera::_ray_collision); - - ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "orbit" ), _SCS("_set_initial_orbit"),_SCS("get_orbit") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,0.01" ), _SCS("set_height"), _SCS("get_height") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "inclination", PROPERTY_HINT_RANGE,"-90,90,0.01" ), _SCS("set_inclination"), _SCS("get_inclination") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "max_orbit_x", PROPERTY_HINT_RANGE,"-90,90,0.01" ), _SCS("set_max_orbit_x"), _SCS("get_max_orbit_x") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "min_orbit_x", PROPERTY_HINT_RANGE,"-90,90,0.01" ), _SCS("set_min_orbit_x"), _SCS("get_min_orbit_x") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "min_distance", PROPERTY_HINT_RANGE,"0,100,0.01" ), _SCS("set_min_distance"), _SCS("get_min_distance") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "max_distance", PROPERTY_HINT_RANGE,"0,100,0.01" ), _SCS("set_max_distance"), _SCS("get_max_distance") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "distance", PROPERTY_HINT_RANGE,"0.01,1024,0,01"), _SCS("set_distance"), _SCS("get_distance") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "clip"), _SCS("set_clip"), _SCS("has_clip") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "autoturn"), _SCS("set_autoturn"), _SCS("has_autoturn") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "autoturn_tolerance", PROPERTY_HINT_RANGE,"1,90,0.01") , _SCS("set_autoturn_tolerance"), _SCS("get_autoturn_tolerance") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "autoturn_speed", PROPERTY_HINT_RANGE,"1,90,0.01"), _SCS("set_autoturn_speed"), _SCS("get_autoturn_speed") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "smoothing"), _SCS("set_smoothing"), _SCS("has_smoothing") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "translation_smooth", PROPERTY_HINT_RANGE,"0.01,128,0.01"), _SCS("set_translation_smoothing"), _SCS("get_translation_smoothing") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "rotation_smooth", PROPERTY_HINT_RANGE,"0.01,128,0.01"), _SCS("set_rotation_smoothing"), _SCS("get_rotation_smoothing") ); - - -} - -void FollowCamera::_ray_collision(Vector3 p_point, Vector3 p_normal, int p_subindex, ObjectID p_against,int p_idx) { - - clip_ray[p_idx].clip_pos=p_point; - clip_ray[p_idx].clipped=true; - -}; - -Transform FollowCamera::get_camera_transform() const { - - return final; -} - -void FollowCamera::set_smoothing(bool p_enable) { - - smooth=p_enable; -} - -bool FollowCamera::has_smoothing() const { - - return smooth; -} - -void FollowCamera::set_translation_smoothing(float p_amount) { - - smooth_pos_ratio=p_amount; -} -float FollowCamera::get_translation_smoothing() const { - - return smooth_pos_ratio; -} - -void FollowCamera::set_rotation_smoothing(float p_amount) { - - smooth_rot_ratio=p_amount; - -} - -void FollowCamera::set_up_vector(const Vector3& p_up) { - - up_vector=p_up; -} - -Vector3 FollowCamera::get_up_vector() const{ - - return up_vector; -} - -float FollowCamera::get_rotation_smoothing() const { - - return smooth_pos_ratio; - -} - - -FollowCamera::FollowCamera() { - - - height=1; - - orbit=Vector2(0,0); - up_vector=Vector3(0,1,0); - - distance=3; - min_distance=2; - max_distance=5; - - autoturn=true; - autoturn_tolerance=10; - autoturn_speed=80; - - min_orbit_x=-50; - max_orbit_x=70; - inclination=0; - target_width=0.3; - - clip=true; - use_lookat_target = false; - extraclip=0.3; - fullclip=false; - - smooth=true; - smooth_rot_ratio=10; - smooth_pos_ratio=10; - - - for(int i=0;i<3;i++) { -// clip_ray[i].query=PhysicsServer::get_singleton()->query_create(this, "_ray_collision", i, true); - clip_ray[i].clipped=false; - } - - queries_active=false; - - -} - -FollowCamera::~FollowCamera() { - - for(int i=0;i<3;i++) { - PhysicsServer::get_singleton()->free(clip_ray[i].query); - } - - -} diff --git a/scene/3d/follow_camera.h b/scene/3d/follow_camera.h deleted file mode 100644 index 10912eb606..0000000000 --- a/scene/3d/follow_camera.h +++ /dev/null @@ -1,180 +0,0 @@ -/*************************************************************************/ -/* follow_camera.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* 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. */ -/*************************************************************************/ -#ifndef FOLLOW_CAMERA_H -#define FOLLOW_CAMERA_H - -#include "scene/3d/camera.h" - -class FollowCamera : public Camera { - - OBJ_TYPE( FollowCamera, Camera ); - -private: - - - //used for follow - Vector3 follow_pos; - //used for fixed - Vector2 initial_orbit; - Vector2 orbit; - float distance; - - float height; - float target_width; - - float min_distance; - float max_distance; - - float max_orbit_x; - float min_orbit_x; - - float inclination; - float extraclip; - bool fullclip; - - bool clip; - bool autoturn; - float autoturn_tolerance; - float autoturn_speed; - - bool smooth; - float smooth_rot_ratio; - float smooth_pos_ratio; - - - - struct ClipRay { - RID query; - bool clipped; - Vector3 cast_pos; - Vector3 clip_pos; - }; - - ClipRay clip_ray[3]; - Vector3 target_pos; - float clip_len; - - Vector3 up_vector; - - - virtual RES _get_gizmo_geometry() const; - - Transform ted; - Vector3 proposed_pos; - Transform accepted; - Transform final; - RID target_body; - - bool use_lookat_target; - Vector3 lookat_target; - - void _compute_camera(); - - bool queries_active; - void _clear_queries(); - - void _set_initial_orbit(const Vector2& p_orbit); - -protected: - - virtual void _request_camera_update() {} //ignore - - void _notification(int p_what); - - static void _bind_methods(); - - void _ray_collision(Vector3 p_point, Vector3 p_normal, int p_subindex, ObjectID p_against,int p_idx); - -public: - - - void set_orbit(const Vector2& p_orbit); - void set_orbit_x(float p_x); - void set_orbit_y(float p_y); - Vector2 get_orbit() const; - - void set_height(float p_height); - float get_height() const; - - void set_inclination(float p_degrees); - float get_inclination() const; - - void set_max_orbit_x(float p_max); - float get_max_orbit_x() const; - - void set_min_orbit_x(float p_min); - float get_min_orbit_x() const; - - void rotate_orbit(const Vector2& p_relative); - - void set_distance(float p_distance); - float get_distance() const; - - float get_min_distance() const; - float get_max_distance() const; - void set_min_distance(float p_min); - void set_max_distance(float p_max); - - /** FINISH THIS AND CLEAN IT UP */ - - void set_clip(bool p_enabled); - bool has_clip() const; - - void set_autoturn(bool p_enabled); - bool has_autoturn() const; - - void set_autoturn_tolerance(float p_degrees); - float get_autoturn_tolerance() const; - - void set_autoturn_speed(float p_speed); - float get_autoturn_speed() const; - - void set_smoothing(bool p_enable); - bool has_smoothing() const; - - void set_translation_smoothing(float p_amount); - float get_translation_smoothing() const; - - void set_rotation_smoothing(float p_amount); - float get_rotation_smoothing() const; - - void set_use_lookat_target(bool p_use, const Vector3 &p_lookat = Vector3()); - - void set_up_vector(const Vector3& p_up); - Vector3 get_up_vector() const; - - virtual Transform get_camera_transform() const; - - FollowCamera(); - ~FollowCamera(); -}; - - - -#endif // FOLLOW_CAMERA_H diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry.cpp index 1459f2c362..a4206894ff 100644 --- a/scene/3d/immediate_geometry.cpp +++ b/scene/3d/immediate_geometry.cpp @@ -72,6 +72,53 @@ DVector<Face3> ImmediateGeometry::get_faces(uint32_t p_usage_flags) const { return DVector<Face3>(); } + + +void ImmediateGeometry::add_sphere(int p_lats,int p_lons,float p_radius) { + + for(int i = 1; i <= p_lats; i++) { + double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); + + double lat1 = Math_PI * (-0.5 + (double) i / p_lats); + double z1 = Math::sin(lat1); + double zr1 = Math::cos(lat1); + + for(int j = p_lons; j >= 1; j--) { + + double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons; + double x0 = Math::cos(lng0); + double y0 = Math::sin(lng0); + + double lng1 = 2 * Math_PI * (double) (j) / p_lons; + double x1 = Math::cos(lng1); + double y1 = Math::sin(lng1); + + + Vector3 v[4]={ + Vector3(x1 * zr0, z0, y1 *zr0), + Vector3(x1 * zr1, z1, y1 *zr1), + Vector3(x0 * zr1, z1, y0 *zr1), + Vector3(x0 * zr0, z0, y0 *zr0) + }; + +#define ADD_POINT(m_idx)\ + set_normal(v[m_idx]);\ + add_vertex(v[m_idx]*p_radius); + + ADD_POINT(0); + ADD_POINT(1); + ADD_POINT(2); + + ADD_POINT(2); + ADD_POINT(3); + ADD_POINT(0); + } + } + +} + void ImmediateGeometry::_bind_methods() { ObjectTypeDB::bind_method(_MD("begin","primitive","texture:Texture"),&ImmediateGeometry::begin); @@ -81,11 +128,14 @@ void ImmediateGeometry::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_uv","uv"),&ImmediateGeometry::set_uv); ObjectTypeDB::bind_method(_MD("set_uv2","uv"),&ImmediateGeometry::set_uv2); ObjectTypeDB::bind_method(_MD("add_vertex","color"),&ImmediateGeometry::add_vertex); + ObjectTypeDB::bind_method(_MD("add_sphere","lats","lons","radius"),&ImmediateGeometry::add_sphere); ObjectTypeDB::bind_method(_MD("end"),&ImmediateGeometry::end); ObjectTypeDB::bind_method(_MD("clear"),&ImmediateGeometry::clear); } + + ImmediateGeometry::ImmediateGeometry() { im = VisualServer::get_singleton()->immediate_create(); diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry.h index 2db81134c6..beb8ea8214 100644 --- a/scene/3d/immediate_geometry.h +++ b/scene/3d/immediate_geometry.h @@ -31,6 +31,11 @@ public: void end(); void clear(); + + void add_sphere(int p_lats,int p_lons,float p_radius); + + + virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 0d571b77cd..e51a9764f6 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -429,10 +429,42 @@ void Light::approximate_opengl_attenuation(float p_constant, float p_linear, flo } + +void Light::_update_visibility() { + + if (!is_inside_scene()) + return; + + +bool editor_ok=true; + +#ifdef TOOLS_ENABLED + if (editor_only) { + if (!get_scene()->is_editor_hint()) { + editor_ok=false; + } else { + editor_ok = (get_scene()->get_edited_scene_root() && (this==get_scene()->get_edited_scene_root() || get_owner()==get_scene()->get_edited_scene_root())); + } + } +#endif + + VS::get_singleton()->instance_light_set_enabled(get_instance(),is_visible() && enabled && editor_ok); + _change_notify("geometry/visible"); + +} + + +void Light::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_SCENE || p_what==NOTIFICATION_VISIBILITY_CHANGED) { + _update_visibility(); + } +} + void Light::set_enabled(bool p_enabled) { enabled=p_enabled; - VS::get_singleton()->instance_light_set_enabled(get_instance(),enabled); + _update_visibility(); } bool Light::is_enabled() const{ @@ -440,6 +472,17 @@ bool Light::is_enabled() const{ return enabled; } +void Light::set_editor_only(bool p_editor_only) { + + editor_only=p_editor_only; + _update_visibility(); +} + +bool Light::is_editor_only() const{ + + return editor_only; +} + void Light::_bind_methods() { @@ -457,9 +500,12 @@ void Light::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_bake_mode"), &Light::get_bake_mode ); ObjectTypeDB::bind_method(_MD("set_enabled","enabled"), &Light::set_enabled ); ObjectTypeDB::bind_method(_MD("is_enabled"), &Light::is_enabled ); + ObjectTypeDB::bind_method(_MD("set_editor_only","editor_only"), &Light::set_editor_only ); + ObjectTypeDB::bind_method(_MD("is_editor_only"), &Light::is_editor_only ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "params/enabled"), _SCS("set_enabled"), _SCS("is_enabled")); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "params/editor_only"), _SCS("set_editor_only"), _SCS("is_editor_only")); ADD_PROPERTY( PropertyInfo( Variant::INT, "params/bake_mode",PROPERTY_HINT_ENUM,"Disabled,Indirect,Indirect+Shadows,Full"), _SCS("set_bake_mode"), _SCS("get_bake_mode")); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/energy", PROPERTY_HINT_EXP_RANGE, "0,64,0.01"), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_ENERGY ); /* @@ -531,6 +577,7 @@ Light::Light(VisualServer::LightType p_type) { set_project_shadows( false ); set_base(light); enabled=true; + editor_only=false; bake_mode=BAKE_MODE_DISABLED; } diff --git a/scene/3d/light.h b/scene/3d/light.h index 8e7395fd84..6fb57a269b 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -92,8 +92,10 @@ private: VisualServer::LightType type; bool shadows; bool enabled; + bool editor_only; Operator op; - + + void _update_visibility(); // bind helpers protected: @@ -104,6 +106,7 @@ protected: virtual RES _get_gizmo_geometry() const; static void _bind_methods(); + void _notification(int p_what); Light(VisualServer::LightType p_type); @@ -132,6 +135,9 @@ public: void set_enabled(bool p_enabled); bool is_enabled() const; + void set_editor_only(bool p_editor_only); + bool is_editor_only() const; + virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 40981d468e..72d63fa006 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -30,7 +30,7 @@ #include "skeleton.h" #include "physics_body.h" - +#include "body_shape.h" bool MeshInstance::_set(const StringName& p_name, const Variant& p_value) { @@ -181,6 +181,11 @@ void MeshInstance::create_trimesh_collision() { add_child(static_body); if (get_owner()) static_body->set_owner( get_owner() ); + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(static_body->get_shape(0)); + static_body->add_child(cshape); + if (get_owner()) + cshape->set_owner( get_owner() ); } @@ -210,6 +215,12 @@ void MeshInstance::create_convex_collision() { add_child(static_body); if (get_owner()) static_body->set_owner( get_owner() ); + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(static_body->get_shape(0)); + static_body->add_child(cshape); + if (get_owner()) + cshape->set_owner( get_owner() ); + } @@ -229,9 +240,9 @@ void MeshInstance::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_skeleton_path:NodePath"),&MeshInstance::get_skeleton_path); ObjectTypeDB::bind_method(_MD("get_aabb"),&MeshInstance::get_aabb); ObjectTypeDB::bind_method(_MD("create_trimesh_collision"),&MeshInstance::create_trimesh_collision); - ObjectTypeDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT); ObjectTypeDB::bind_method(_MD("create_convex_collision"),&MeshInstance::create_convex_collision); - ObjectTypeDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT); ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "mesh/mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh" ), _SCS("set_mesh"), _SCS("get_mesh")); ADD_PROPERTY( PropertyInfo (Variant::NODE_PATH, "mesh/skeleton"), _SCS("set_skeleton_path"), _SCS("get_skeleton_path")); } diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 831e1c95c2..15ec60514a 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -967,6 +967,7 @@ Vector3 KinematicBody::move(const Vector3& p_motion) { normal=rest.normal; collider=rest.collider_id; collider_vel=rest.linear_velocity; + collider_shape=rest.shape; } } @@ -1055,7 +1056,12 @@ ObjectID KinematicBody::get_collider() const { ERR_FAIL_COND_V(!colliding,0); return collider; } +int KinematicBody::get_collider_shape() const { + ERR_FAIL_COND_V(!colliding,-1); + return collider_shape; + +} void KinematicBody::set_collide_with_static_bodies(bool p_enable) { collide_static=p_enable; @@ -1119,6 +1125,7 @@ void KinematicBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_collision_normal"),&KinematicBody::get_collision_normal); ObjectTypeDB::bind_method(_MD("get_collider_velocity"),&KinematicBody::get_collider_velocity); ObjectTypeDB::bind_method(_MD("get_collider:Object"),&KinematicBody::_get_collider); + ObjectTypeDB::bind_method(_MD("get_collider_shape"),&KinematicBody::get_collider_shape); ObjectTypeDB::bind_method(_MD("set_collide_with_static_bodies","enable"),&KinematicBody::set_collide_with_static_bodies); @@ -1155,6 +1162,7 @@ KinematicBody::KinematicBody() : PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) colliding=false; collider=0; margin=0.001; + collider_shape=0; } KinematicBody::~KinematicBody() { diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 951aaf4da3..a19ad48c87 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -266,6 +266,8 @@ class KinematicBody : public PhysicsBody { Vector3 normal; Vector3 collider_vel; ObjectID collider; + int collider_shape; + Variant _get_collider() const; @@ -291,6 +293,7 @@ public: Vector3 get_collision_normal() const; Vector3 get_collider_velocity() const; ObjectID get_collider() const; + int get_collider_shape() const; void set_collide_with_static_bodies(bool p_enable); bool can_collide_with_static_bodies() const; diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 858ee4e4ad..737f7d2dce 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -237,6 +237,21 @@ Transform Skeleton::get_bone_transform(int p_bone) const { return bones[p_bone].pose_global * bones[p_bone].rest_global_inverse; } + +void Skeleton::set_bone_global_pose(int p_bone,const Transform& p_pose) { + + ERR_FAIL_INDEX(p_bone,bones.size()); + if (bones[p_bone].parent==-1) { + + set_bone_pose(p_bone,bones[p_bone].rest.inverse() * p_pose); + } else { + + set_bone_pose(p_bone, bones[p_bone].rest.inverse() * (get_bone_global_pose(bones[p_bone].parent).affine_inverse() * p_pose)); + + } + +} + Transform Skeleton::get_bone_global_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone,bones.size(),Transform()); @@ -519,6 +534,7 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_bone_pose","bone_idx"),&Skeleton::get_bone_pose); ObjectTypeDB::bind_method(_MD("set_bone_pose","bone_idx","pose"),&Skeleton::set_bone_pose); + ObjectTypeDB::bind_method(_MD("set_bone_global_pose","bone_idx","pose"),&Skeleton::set_bone_global_pose); ObjectTypeDB::bind_method(_MD("get_bone_global_pose","bone_idx"),&Skeleton::get_bone_global_pose); ObjectTypeDB::bind_method(_MD("get_bone_custom_pose","bone_idx"),&Skeleton::get_bone_custom_pose); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index 3e0ab0afd7..c61946a4c7 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -118,6 +118,8 @@ public: Transform get_bone_transform(int p_bone) const; Transform get_bone_global_pose(int p_bone) const; + void set_bone_global_pose(int p_bone,const Transform& p_pose); + void set_bone_enabled(int p_bone, bool p_enabled); bool is_bone_enabled(int p_bone) const; diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp index af535e139f..398fbdea82 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance.cpp @@ -50,17 +50,24 @@ void VisualInstance::_notification(int p_what) { // CHECK ROOM Spatial * parent = get_parent_spatial(); Room *room=NULL; + bool is_geom = cast_to<GeometryInstance>(); while(parent) { room = parent->cast_to<Room>(); if (room) break; - else - parent=parent->get_parent_spatial(); + + if (is_geom && parent->cast_to<BakedLightSampler>()) { + VS::get_singleton()->instance_geometry_set_baked_light_sampler(get_instance(),parent->cast_to<BakedLightSampler>()->get_instance()); + break; + } + + parent=parent->get_parent_spatial(); } + if (room) { VisualServer::get_singleton()->instance_set_room(instance,room->get_instance()); @@ -85,6 +92,7 @@ void VisualInstance::_notification(int p_what) { VisualServer::get_singleton()->instance_set_scenario( instance, RID() ); VisualServer::get_singleton()->instance_set_room(instance,RID()); VisualServer::get_singleton()->instance_attach_skeleton( instance, RID() ); + VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() ); } break; diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h index bbb49a2e78..e9fefe1ba0 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance.h @@ -47,6 +47,7 @@ class VisualInstance : public Spatial { RID _get_visual_instance_rid() const; + protected: diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 88fabb3489..9a3c7e71ec 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -927,7 +927,7 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float StringName next=animation_get_next(p_name); - if (next!=StringName()) { + if (next!=StringName() && animation_set.has(next)) { queue(next); } } diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index ac2417d539..7745ce11fc 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -55,6 +55,9 @@ void BaseButton::_input_event(InputEvent p_event) { if (b.pressed) { if (!toggle_mode) { //mouse press attempt + + status.press_attempt=true; + status.pressing_inside=true; pressed(); emit_signal("pressed"); @@ -71,8 +74,15 @@ void BaseButton::_input_event(InputEvent p_event) { } + } else { + + if (status.press_attempt &&status.pressing_inside) { + pressed(); + emit_signal("pressed"); + } + status.press_attempt=false; } - + update(); break; } diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index ac0ded03ab..90393a1296 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -297,7 +297,7 @@ void AcceptDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_label"),&AcceptDialog::get_label); ObjectTypeDB::bind_method(_MD("set_hide_on_ok","enabled"),&AcceptDialog::set_hide_on_ok); ObjectTypeDB::bind_method(_MD("get_hide_on_ok"),&AcceptDialog::get_hide_on_ok); - ObjectTypeDB::bind_method(_MD("add_button:Button","text","right","action"),&AcceptDialog::add_cancel,DEFVAL(false),DEFVAL("")); + ObjectTypeDB::bind_method(_MD("add_button:Button","text","right","action"),&AcceptDialog::add_button,DEFVAL(false),DEFVAL("")); ObjectTypeDB::bind_method(_MD("add_cancel:Button","name"),&AcceptDialog::add_cancel); ObjectTypeDB::bind_method(_MD("_builtin_text_entered"),&AcceptDialog::_builtin_text_entered); ObjectTypeDB::bind_method(_MD("register_text_enter:LineEdit","line_edit"),&AcceptDialog::register_text_enter); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index c2dc1318c9..0ba3bdb7c6 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -855,7 +855,7 @@ void PopupMenu::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_item","label","id","accel"),&PopupMenu::add_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_icon_check_item","texture","label","id","accel"),&PopupMenu::add_icon_check_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_check_item","label","id","accel"),&PopupMenu::add_check_item,DEFVAL(-1),DEFVAL(0)); - ObjectTypeDB::bind_method(_MD("add_submenu_item","label","submenu","id"),&PopupMenu::add_check_item,DEFVAL(-1)); + ObjectTypeDB::bind_method(_MD("add_submenu_item","label","submenu","id"),&PopupMenu::add_submenu_item,DEFVAL(-1)); ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&PopupMenu::set_item_text); ObjectTypeDB::bind_method(_MD("set_item_icon","idx","icon"),&PopupMenu::set_item_icon); ObjectTypeDB::bind_method(_MD("set_item_accelerator","idx","accel"),&PopupMenu::set_item_accelerator); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 9084983a4c..a39c61ecac 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1438,8 +1438,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ if (p_button==BUTTON_LEFT) { /* process selection */ - if (p_doubleclick && (!c.editable || c.mode==TreeItem::CELL_MODE_CUSTOM || c.mode==TreeItem::CELL_MODE_ICON)) { - + if (p_doubleclick && (!c.editable || c.mode==TreeItem::CELL_MODE_CUSTOM || c.mode==TreeItem::CELL_MODE_ICON || c.mode==TreeItem::CELL_MODE_CHECK)) { emit_signal("item_activated"); return -1; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index bcdc50c880..c51974167d 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -968,6 +968,18 @@ void SceneMainLoop::set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect } +#ifdef TOOLS_ENABLED +void SceneMainLoop::set_edited_scene_root(Node *p_node) { + edited_scene_root=p_node; +} + +Node *SceneMainLoop::get_edited_scene_root() const { + + return edited_scene_root; +} +#endif + + void SceneMainLoop::_bind_methods() { @@ -983,6 +995,10 @@ void SceneMainLoop::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_editor_hint","enable"),&SceneMainLoop::set_editor_hint); ObjectTypeDB::bind_method(_MD("is_editor_hint"),&SceneMainLoop::is_editor_hint); +#ifdef TOOLS_ENABLED + ObjectTypeDB::bind_method(_MD("set_edited_scene_root","scene"),&SceneMainLoop::set_edited_scene_root); + ObjectTypeDB::bind_method(_MD("get_edited_scene_root"),&SceneMainLoop::get_edited_scene_root); +#endif ObjectTypeDB::bind_method(_MD("set_pause","enable"),&SceneMainLoop::set_pause); ObjectTypeDB::bind_method(_MD("is_paused"),&SceneMainLoop::is_paused); @@ -1069,6 +1085,10 @@ SceneMainLoop::SceneMainLoop() { root->set_physics_object_picking(GLOBAL_DEF("physics/enable_object_picking",true)); +#ifdef TOOLS_ENABLED + edited_scene_root=NULL; +#endif + ADD_SIGNAL( MethodInfo("idle_frame")); ADD_SIGNAL( MethodInfo("fixed_frame")); diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index 493644d2bc..bfa755ff7c 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -102,6 +102,9 @@ private: int64_t current_frame; int node_count; +#ifdef TOOLS_ENABLED + Node *edited_scene_root; +#endif struct UGCall { StringName group; @@ -223,6 +226,13 @@ public: void set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect,const Size2 p_minsize); + //void change_scene(const String& p_path); + //Node *get_loaded_scene(); + +#ifdef TOOLS_ENABLED + void set_edited_scene_root(Node *p_node); + Node *get_edited_scene_root() const; +#endif SceneMainLoop(); ~SceneMainLoop(); diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 25d1c8530e..8e80f868c6 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -36,8 +36,12 @@ void Timer::_notification(int p_what) { case NOTIFICATION_READY: { - if (autostart) - start(); + if (autostart) { +#ifdef TOOLS_ENABLED + if (get_scene()->is_editor_hint() && get_scene()->get_edited_scene_root() && (get_scene()->get_edited_scene_root()==this || get_scene()->get_edited_scene_root()->is_a_parent_of(this))) + break; +#endif start(); + } } break; case NOTIFICATION_PROCESS: { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index bd39fafc8b..6b7ed66463 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -95,8 +95,8 @@ void Viewport::_update_stretch_transform() { if (size_override_stretch && size_override) { - print_line("sive override size "+size_override_size); - print_line("rect size "+rect.size); + //print_line("sive override size "+size_override_size); + //print_line("rect size "+rect.size); stretch_transform=Matrix32(); Size2 scale = rect.size/(size_override_size+size_override_margin*2); stretch_transform.scale(scale); @@ -135,7 +135,9 @@ void Viewport::_update_rect() { } vr.width=rect.size.width; vr.height=rect.size.height; + VisualServer::get_singleton()->viewport_set_rect(viewport,vr); + last_vp_rect=rect; if (canvas_item.is_valid()) { VisualServer::get_singleton()->canvas_item_set_custom_rect(canvas_item,true,rect); @@ -513,6 +515,7 @@ void Viewport::set_rect(const Rect2& p_rect) { if (rect==p_rect) return; rect=p_rect; + _update_rect(); _update_stretch_transform(); @@ -558,7 +561,7 @@ void Viewport::_update_listener() { void Viewport::_update_listener_2d() { - if (is_inside_scene() && audio_listener && camera && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) + if (is_inside_scene() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,find_world_2d()->get_sound_space()); else SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,RID()); @@ -1029,13 +1032,16 @@ void Viewport::_make_input_local(InputEvent& ev) { Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); - Vector2 r = ai.xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); + Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); + Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); ev.mouse_motion.x=l.x; ev.mouse_motion.y=l.y; ev.mouse_motion.global_x=g.x; ev.mouse_motion.global_y=g.y; ev.mouse_motion.relative_x=r.x; ev.mouse_motion.relative_y=r.y; + ev.mouse_motion.speed_x=s.x; + ev.mouse_motion.speed_y=s.y; } break; case InputEvent::SCREEN_TOUCH: { @@ -1050,8 +1056,8 @@ void Viewport::_make_input_local(InputEvent& ev) { Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); - Vector2 r = ai.xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); - Vector2 s = ai.xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); + Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); + Vector2 s = ai.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); ev.screen_drag.x=t.x; ev.screen_drag.y=t.y; ev.screen_drag.relative_x=r.x; @@ -1185,6 +1191,21 @@ void Viewport::set_physics_object_picking(bool p_enable) { } + +Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const { + + Matrix32 xf = get_final_transform(); + return xf.xform(p_viewport_coords); + + +} + +Vector2 Viewport::get_camera_rect_size() const { + + return last_vp_rect.size; +} + + bool Viewport::get_physics_object_picking() { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 5d68438f0d..37f1b357c6 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -110,6 +110,7 @@ friend class RenderTargetTexture; Size2 size_override_size; Size2 size_override_margin; + Rect2 last_vp_rect; bool transparent_bg; bool render_target_vflip; @@ -229,6 +230,10 @@ public: RenderTargetUpdateMode get_render_target_update_mode() const; Ref<RenderTargetTexture> get_render_target_texture() const; + + Vector2 get_camera_coords(const Vector2& p_viewport_coords) const; + Vector2 get_camera_rect_size() const; + void queue_screen_capture(); Image get_screen_capture() const; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index a5ad38e79c..f3b13f30bf 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -176,7 +176,6 @@ #include "scene/3d/camera.h" #include "scene/3d/interpolated_camera.h" -#include "scene/3d/follow_camera.h" #include "scene/3d/position_3d.h" #include "scene/3d/test_cube.h" #include "scene/3d/mesh_instance.h" @@ -353,7 +352,6 @@ void register_scene_types() { ObjectTypeDB::register_type<BoneAttachment>(); ObjectTypeDB::register_virtual_type<VisualInstance>(); ObjectTypeDB::register_type<Camera>(); - ObjectTypeDB::register_type<FollowCamera>(); ObjectTypeDB::register_type<InterpolatedCamera>(); ObjectTypeDB::register_type<TestCube>(); ObjectTypeDB::register_type<MeshInstance>(); @@ -396,6 +394,7 @@ void register_scene_types() { ObjectTypeDB::register_type<VisibilityNotifier>(); ObjectTypeDB::register_type<VisibilityEnabler>(); ObjectTypeDB::register_type<BakedLightInstance>(); + ObjectTypeDB::register_type<BakedLightSampler>(); ObjectTypeDB::register_type<WorldEnvironment>(); //scenariofx diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp index 647c8df5d4..226edec9ae 100644 --- a/scene/resources/baked_light.cpp +++ b/scene/resources/baked_light.cpp @@ -23,6 +23,27 @@ DVector<uint8_t> BakedLight::get_octree() const { return VS::get_singleton()->baked_light_get_octree(baked_light); } +void BakedLight::set_light(const DVector<uint8_t>& p_light) { + + VS::get_singleton()->baked_light_set_light(baked_light,p_light); +} + +DVector<uint8_t> BakedLight::get_light() const { + + return VS::get_singleton()->baked_light_get_light(baked_light); +} + + +void BakedLight::set_sampler_octree(const DVector<int>& p_sampler_octree) { + + VS::get_singleton()->baked_light_set_sampler_octree(baked_light,p_sampler_octree); +} + +DVector<int> BakedLight::get_sampler_octree() const { + + return VS::get_singleton()->baked_light_get_sampler_octree(baked_light); +} + @@ -199,6 +220,43 @@ float BakedLight::get_normal_damp() const { return normal_damp; } +void BakedLight::set_tint(float p_margin) { + tint=p_margin; +} + +float BakedLight::get_tint() const { + + return tint; +} + +void BakedLight::set_saturation(float p_margin) { + saturation=p_margin; +} + +float BakedLight::get_saturation() const { + + return saturation; +} + +void BakedLight::set_ao_radius(float p_ao_radius) { + ao_radius=p_ao_radius; +} + +float BakedLight::get_ao_radius() const { + return ao_radius; +} + +void BakedLight::set_ao_strength(float p_ao_strength) { + + ao_strength=p_ao_strength; +} + +float BakedLight::get_ao_strength() const { + + return ao_strength; +} + + void BakedLight::set_energy_multiplier(float p_multiplier){ energy_multiply=p_multiplier; @@ -329,6 +387,13 @@ void BakedLight::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_octree","octree"),&BakedLight::set_octree); ObjectTypeDB::bind_method(_MD("get_octree"),&BakedLight::get_octree); + ObjectTypeDB::bind_method(_MD("set_light","light"),&BakedLight::set_light); + ObjectTypeDB::bind_method(_MD("get_light"),&BakedLight::get_light); + + ObjectTypeDB::bind_method(_MD("set_sampler_octree","sampler_octree"),&BakedLight::set_sampler_octree); + ObjectTypeDB::bind_method(_MD("get_sampler_octree"),&BakedLight::get_sampler_octree); + + ObjectTypeDB::bind_method(_MD("add_lightmap","texture:Texture","gen_size"),&BakedLight::add_lightmap); ObjectTypeDB::bind_method(_MD("erase_lightmap","id"),&BakedLight::erase_lightmap); ObjectTypeDB::bind_method(_MD("clear_lightmaps"),&BakedLight::clear_lightmaps); @@ -357,6 +422,18 @@ void BakedLight::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_normal_damp","normal_damp"),&BakedLight::set_normal_damp); ObjectTypeDB::bind_method(_MD("get_normal_damp"),&BakedLight::get_normal_damp); + ObjectTypeDB::bind_method(_MD("set_tint","tint"),&BakedLight::set_tint); + ObjectTypeDB::bind_method(_MD("get_tint"),&BakedLight::get_tint); + + ObjectTypeDB::bind_method(_MD("set_saturation","saturation"),&BakedLight::set_saturation); + ObjectTypeDB::bind_method(_MD("get_saturation"),&BakedLight::get_saturation); + + ObjectTypeDB::bind_method(_MD("set_ao_radius","ao_radius"),&BakedLight::set_ao_radius); + ObjectTypeDB::bind_method(_MD("get_ao_radius"),&BakedLight::get_ao_radius); + + ObjectTypeDB::bind_method(_MD("set_ao_strength","ao_strength"),&BakedLight::set_ao_strength); + ObjectTypeDB::bind_method(_MD("get_ao_strength"),&BakedLight::get_ao_strength); + ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format); ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format); @@ -384,17 +461,24 @@ void BakedLight::_bind_methods(){ ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/plot_size",PROPERTY_HINT_RANGE,"1.0,16.0,0.01"),_SCS("set_plot_size"),_SCS("get_plot_size")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/energy_mult",PROPERTY_HINT_RANGE,"0.01,4096.0,0.01"),_SCS("set_energy_multiplier"),_SCS("get_energy_multiplier")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/gamma_adjust",PROPERTY_HINT_EXP_EASING),_SCS("set_gamma_adjust"),_SCS("get_gamma_adjust")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"baking/saturation",PROPERTY_HINT_RANGE,"0,8,0.01"),_SCS("set_saturation"),_SCS("get_saturation")); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/diffuse"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_DIFFUSE); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/specular"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_SPECULAR); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/translucent"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_TRANSLUCENT); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/conserve_energy"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_CONSERVE_ENERGY); + ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/linear_color"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_LINEAR_COLOR); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"lightmap/use_only_uv2"),_SCS("set_transfer_lightmaps_only_to_uv2"),_SCS("get_transfer_lightmaps_only_to_uv2")); ADD_PROPERTY( PropertyInfo(Variant::RAW_ARRAY,"octree",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_octree"),_SCS("get_octree")); + ADD_PROPERTY( PropertyInfo(Variant::RAW_ARRAY,"light",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_light"),_SCS("get_light")); + ADD_PROPERTY( PropertyInfo(Variant::INT_ARRAY,"sampler_octree",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_sampler_octree"),_SCS("get_sampler_octree")); ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"lightmaps",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_lightmap_data"),_SCS("_get_lightmap_data")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/cell_margin",PROPERTY_HINT_RANGE,"0.01,0.8,0.01"),_SCS("set_cell_extra_margin"),_SCS("get_cell_extra_margin")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/edge_damp",PROPERTY_HINT_RANGE,"0.0,8.0,0.1"),_SCS("set_edge_damp"),_SCS("get_edge_damp")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/normal_damp",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),_SCS("set_normal_damp"),_SCS("get_normal_damp")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/light_tint",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),_SCS("set_tint"),_SCS("get_tint")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/ao_radius",PROPERTY_HINT_RANGE,"0.0,16.0,0.01"),_SCS("set_ao_radius"),_SCS("get_ao_radius")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/ao_strength",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),_SCS("set_ao_strength"),_SCS("get_ao_strength")); BIND_CONSTANT( MODE_OCTREE ); BIND_CONSTANT( MODE_LIGHTMAPS ); @@ -415,18 +499,24 @@ BakedLight::BakedLight() { lattice_subdiv=4; plot_size=2.5; bounces=1; - energy_multiply=1.0; - gamma_adjust=1.0; + energy_multiply=2.0; + gamma_adjust=0.7; cell_extra_margin=0.05; edge_damp=0.0; normal_damp=0.0; + saturation=1; + tint=0.0; + ao_radius=2.5; + ao_strength=0.7; format=FORMAT_RGB; transfer_only_uv2=false; + flags[BAKE_DIFFUSE]=true; flags[BAKE_SPECULAR]=false; flags[BAKE_TRANSLUCENT]=true; flags[BAKE_CONSERVE_ENERGY]=false; + flags[BAKE_LINEAR_COLOR]=false; mode=MODE_OCTREE; baked_light=VS::get_singleton()->baked_light_create(); diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h index 57ed7d7aee..41e1e5f9e0 100644 --- a/scene/resources/baked_light.h +++ b/scene/resources/baked_light.h @@ -26,6 +26,7 @@ public: BAKE_SPECULAR, BAKE_TRANSLUCENT, BAKE_CONSERVE_ENERGY, + BAKE_LINEAR_COLOR, BAKE_MAX }; @@ -50,6 +51,10 @@ private: float cell_extra_margin; float edge_damp; float normal_damp; + float tint; + float ao_radius; + float ao_strength; + float saturation; int bounces; bool transfer_only_uv2; Format format; @@ -99,6 +104,18 @@ public: void set_normal_damp(float p_margin); float get_normal_damp() const; + void set_tint(float p_margin); + float get_tint() const; + + void set_saturation(float p_saturation); + float get_saturation() const; + + void set_ao_radius(float p_ao_radius); + float get_ao_radius() const; + + void set_ao_strength(float p_ao_strength); + float get_ao_strength() const; + void set_bake_flag(BakeFlags p_flags,bool p_enable); bool get_bake_flag(BakeFlags p_flags) const; @@ -114,6 +131,14 @@ public: void set_octree(const DVector<uint8_t>& p_octree); DVector<uint8_t> get_octree() const; + void set_light(const DVector<uint8_t>& p_light); + DVector<uint8_t> get_light() const; + + void set_sampler_octree(const DVector<int>& p_sampler_octree); + DVector<int> get_sampler_octree() const; + + + void add_lightmap(const Ref<Texture> &p_texture,Size2 p_gen_size=Size2(256,256)); void set_lightmap_gen_size(int p_idx,const Size2& p_size); Size2 get_lightmap_gen_size(int p_idx) const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 4320d4c081..2c278f4fed 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -36,7 +36,8 @@ static const char*_flag_names[Material::FLAG_MAX]={ "invert_faces", "unshaded", "on_top", - "lightmap_on_uv2" + "lightmap_on_uv2", + "colarray_is_srgb" }; @@ -46,7 +47,8 @@ static const Material::Flag _flag_indices[Material::FLAG_MAX]={ Material::FLAG_INVERT_FACES, Material::FLAG_UNSHADED, Material::FLAG_ONTOP, - Material::FLAG_LIGHTMAP_ON_UV2 + Material::FLAG_LIGHTMAP_ON_UV2, + Material::FLAG_COLOR_ARRAY_SRGB, }; @@ -132,6 +134,8 @@ void Material::_bind_methods() { BIND_CONSTANT( FLAG_INVERT_FACES ); BIND_CONSTANT( FLAG_UNSHADED ); BIND_CONSTANT( FLAG_ONTOP ); + BIND_CONSTANT( FLAG_LIGHTMAP_ON_UV2 ); + BIND_CONSTANT( FLAG_COLOR_ARRAY_SRGB ); BIND_CONSTANT( FLAG_MAX ); BIND_CONSTANT( DEPTH_DRAW_ALWAYS ); @@ -156,6 +160,8 @@ Material::Material(const RID& p_material) { flags[FLAG_INVERT_FACES]=false; flags[FLAG_UNSHADED]=false; flags[FLAG_ONTOP]=false; + flags[FLAG_LIGHTMAP_ON_UV2]=true; + flags[FLAG_COLOR_ARRAY_SRGB]=false; depth_draw_mode=DEPTH_DRAW_OPAQUE_ONLY; @@ -427,7 +433,7 @@ FixedMaterial::FixedMaterial() : Material(VS::get_singleton()->fixed_material_cr param[PARAM_SHADE_PARAM]=0.5; param[PARAM_DETAIL]=1.0; - + set_flag(FLAG_COLOR_ARRAY_SRGB,true); fixed_flags[FLAG_USE_ALPHA]=false; fixed_flags[FLAG_USE_COLOR_ARRAY]=false; @@ -544,6 +550,10 @@ void ShaderMaterial::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"), &ShaderMaterial::set_shader ); ObjectTypeDB::bind_method(_MD("get_shader:Shader"), &ShaderMaterial::get_shader ); + + ObjectTypeDB::bind_method(_MD("set_shader_param","param","value:var"), &ShaderMaterial::set_shader_param); + ObjectTypeDB::bind_method(_MD("get_shader_param:var","param"), &ShaderMaterial::get_shader_param); + ObjectTypeDB::bind_method(_MD("_shader_changed"), &ShaderMaterial::_shader_changed ); } @@ -589,6 +599,8 @@ ParticleSystemMaterial::ParticleSystemMaterial() :Material(VisualServer::get_sin set_depth_draw_mode(DEPTH_DRAW_NEVER); VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,true); VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); + set_flag(FLAG_COLOR_ARRAY_SRGB,true); + } ParticleSystemMaterial::~ParticleSystemMaterial() { @@ -659,6 +671,8 @@ UnshadedMaterial::UnshadedMaterial() :Material(VisualServer::get_singleton()->fi set_flag(FLAG_UNSHADED,true); set_use_alpha(true); + set_flag(FLAG_COLOR_ARRAY_SRGB,true); + } UnshadedMaterial::~UnshadedMaterial() { diff --git a/scene/resources/material.h b/scene/resources/material.h index ad503c43c6..9c3feede08 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -54,6 +54,7 @@ public: FLAG_UNSHADED = VS::MATERIAL_FLAG_UNSHADED, FLAG_ONTOP = VS::MATERIAL_FLAG_ONTOP, FLAG_LIGHTMAP_ON_UV2 = VS::MATERIAL_FLAG_LIGHTMAP_ON_UV2, + FLAG_COLOR_ARRAY_SRGB = VS::MATERIAL_FLAG_COLOR_ARRAY_SRGB, FLAG_MAX = VS::MATERIAL_FLAG_MAX }; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index c6e492fcb3..3aeccdc551 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -29,6 +29,7 @@ #include "mesh.h" #include "scene/resources/concave_polygon_shape.h" #include "scene/resources/convex_polygon_shape.h" +#include "surface_tool.h" static const char*_array_name[]={ "vertex_array", @@ -648,6 +649,30 @@ void Mesh::center_geometry() { } +void Mesh::regen_normalmaps() { + + + Vector< Ref<SurfaceTool> > surfs; + for(int i=0;i<get_surface_count();i++) { + + Ref<SurfaceTool> st = memnew( SurfaceTool ); + st->create_from(Ref<Mesh>(this),i); + surfs.push_back(st); + } + + while (get_surface_count()) { + surface_remove(0); + } + + for(int i=0;i<surfs.size();i++) { + + surfs[i]->generate_tangents(); + surfs[i]->commit(Ref<Mesh>(this)); + } +} + + + Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { if (triangle_mesh.is_valid()) @@ -740,6 +765,8 @@ void Mesh::_bind_methods() { ObjectTypeDB::bind_method(_MD("surface_get_name","surf_idx"),&Mesh::surface_get_name); ObjectTypeDB::bind_method(_MD("center_geometry"),&Mesh::center_geometry); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("center_geometry"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::bind_method(_MD("regen_normalmaps"),&Mesh::regen_normalmaps); + ObjectTypeDB::set_method_flags(get_type_static(),_SCS("regen_normalmaps"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::bind_method(_MD("set_custom_aabb","aabb"),&Mesh::set_custom_aabb); ObjectTypeDB::bind_method(_MD("get_custom_aabb"),&Mesh::get_custom_aabb); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 5243163a4d..d6ab6a1198 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -167,6 +167,7 @@ public: Ref<Shape> create_convex_shape() const; void center_geometry(); + void regen_normalmaps(); DVector<Face3> get_faces() const; Ref<TriangleMesh> generate_triangle_mesh() const; diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index df5fee81a8..3ed6cebf07 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -148,8 +148,8 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("node_set_pos"),&ShaderGraph::node_set_pos ); ObjectTypeDB::bind_method(_MD("node_get_pos"),&ShaderGraph::node_get_pos ); - ObjectTypeDB::bind_method(_MD("node_get_param"),&ShaderGraph::node_get_type); - ObjectTypeDB::bind_method(_MD("node_get_type"),&ShaderGraph::node_get_param); + ObjectTypeDB::bind_method(_MD("node_get_param"),&ShaderGraph::node_get_param); + ObjectTypeDB::bind_method(_MD("node_get_type"),&ShaderGraph::node_get_type); ObjectTypeDB::bind_method(_MD("connect"),&ShaderGraph::connect ); ObjectTypeDB::bind_method(_MD("disconnect"),&ShaderGraph::disconnect ); diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index ca891920da..738b642d43 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -109,7 +109,7 @@ void Shape2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("collide","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide); ObjectTypeDB::bind_method(_MD("collide_with_motion","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion); ObjectTypeDB::bind_method(_MD("collide_and_get_contacts:var","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide_and_get_contacts); - ObjectTypeDB::bind_method(_MD("collide_with_motion_and_get_contacts:var","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_and_get_contacts); + ObjectTypeDB::bind_method(_MD("collide_with_motion_and_get_contacts:var","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion_and_get_contacts); ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_solver_bias",PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_custom_solver_bias"),_SCS("get_custom_solver_bias")); } diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 2856101674..dd39205932 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -105,7 +105,7 @@ void SurfaceTool::add_vertex( const Vector3& p_vertex) { vtx.weights=last_weights; vtx.bones=last_bones; vtx.tangent=last_tangent.normal; - vtx.binormal=last_tangent.normal.cross(last_normal).normalized() * last_tangent.d; + vtx.binormal=last_normal.cross(last_tangent.normal).normalized() * last_tangent.d; vertex_array.push_back(vtx); first=false; format|=Mesh::ARRAY_FORMAT_VERTEX; @@ -299,7 +299,9 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) { w[idx+0]=v.tangent.x; w[idx+1]=v.tangent.y; w[idx+2]=v.tangent.z; - float d = v.binormal.dot(v.normal.cross(v.tangent)); + + //float d = v.tangent.dot(v.binormal,v.normal); + float d = v.binormal.dot( v.normal.cross(v.tangent)); w[idx+3]=d<0 ? -1 : 1; } @@ -565,6 +567,7 @@ void SurfaceTool::create_from(const Ref<Mesh>& p_existing, int p_surface) { clear(); primitive=p_existing->surface_get_primitive_type(p_surface); _create_list(p_existing,p_surface,&vertex_array,&index_array,format); + material=p_existing->surface_get_material(p_surface); } @@ -611,165 +614,96 @@ void SurfaceTool::append_from(const Ref<Mesh>& p_existing, int p_surface,const T } +//mikktspace callbacks +int SurfaceTool::mikktGetNumFaces(const SMikkTSpaceContext * pContext) { -void SurfaceTool::generate_tangents() { - - ERR_FAIL_COND(!(format&Mesh::ARRAY_FORMAT_TEX_UV)); - ERR_FAIL_COND(!(format&Mesh::ARRAY_FORMAT_NORMAL)); - - - if (index_array.size()) { - - Vector<List<Vertex>::Element*> vtx; - vtx.resize(vertex_array.size()); - int idx=0; - for (List<Vertex>::Element *E=vertex_array.front();E;E=E->next()) { - vtx[idx++]=E; - E->get().binormal=Vector3(); - E->get().tangent=Vector3(); - } - - for (List<int>::Element *E=index_array.front();E;) { - - int i[3]; - i[0]=E->get(); - E=E->next(); - ERR_FAIL_COND(!E); - i[1]=E->get(); - E=E->next(); - ERR_FAIL_COND(!E); - i[2]=E->get(); - E=E->next(); - ERR_FAIL_COND(!E); - - - Vector3 v1 = vtx[ i[0] ]->get().vertex; - Vector3 v2 = vtx[ i[1] ]->get().vertex; - Vector3 v3 = vtx[ i[2] ]->get().vertex; - - Vector2 w1 = vtx[ i[0] ]->get().uv; - Vector2 w2 = vtx[ i[1] ]->get().uv; - Vector2 w3 = vtx[ i[2] ]->get().uv; - - - float x1 = v2.x - v1.x; - float x2 = v3.x - v1.x; - float y1 = v2.y - v1.y; - float y2 = v3.y - v1.y; - float z1 = v2.z - v1.z; - float z2 = v3.z - v1.z; - - float s1 = w2.x - w1.x; - float s2 = w3.x - w1.x; - float t1 = w2.y - w1.y; - float t2 = w3.y - w1.y; - - float r = (s1 * t2 - s2 * t1); - - Vector3 binormal,tangent; - - if (r==0) { - binormal=Vector3(0,0,0); - tangent=Vector3(0,0,0); - } else { - tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, - (t2 * z1 - t1 * z2) * r); - binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, - (s1 * z2 - s2 * z1) * r); - } - - tangent.normalize(); - binormal.normalize(); - Vector3 normal=Plane( v1, v2, v3 ).normal; - - Vector3 tangentp = tangent - normal * normal.dot( tangent ); - Vector3 binormalp = binormal - normal * (normal.dot(binormal)) - tangent * (tangent.dot(binormal)); - - tangentp.normalize(); - binormalp.normalize(); + Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData); + return varr.size()/3; +} +int SurfaceTool::mikktGetNumVerticesOfFace(const SMikkTSpaceContext * pContext, const int iFace){ + return 3; //always 3 +} +void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext * pContext, float fvPosOut[], const int iFace, const int iVert){ - for (int j=0;j<3;j++) { - vtx[ i[j] ]->get().binormal+=binormalp; - vtx[ i[j] ]->get().tangent+=tangentp; + Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData); + Vector3 v = varr[iFace*3+iVert]->get().vertex; + fvPosOut[0]=v.x; + fvPosOut[1]=v.y; + fvPosOut[2]=v.z; - } - } - for (List<Vertex>::Element *E=vertex_array.front();E;E=E->next()) { - E->get().binormal.normalize(); - E->get().tangent.normalize(); - } +} +void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext * pContext, float fvNormOut[], const int iFace, const int iVert){ - } else { + Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData); + Vector3 v = varr[iFace*3+iVert]->get().normal; + fvNormOut[0]=v.x; + fvNormOut[1]=v.y; + fvNormOut[2]=v.z; - for (List<Vertex>::Element *E=vertex_array.front();E;) { +} +void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext * pContext, float fvTexcOut[], const int iFace, const int iVert){ - List< Vertex >::Element *v[3]; - v[0]=E; - v[1]=v[0]->next(); - ERR_FAIL_COND(!v[1]); - v[2]=v[1]->next(); - ERR_FAIL_COND(!v[2]); - E=v[2]->next(); + Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData); + Vector2 v = varr[iFace*3+iVert]->get().uv; + fvTexcOut[0]=v.x; + //fvTexcOut[1]=v.y; + fvTexcOut[1]=1.0-v.y; - Vector3 v1 = v[0]->get().vertex; - Vector3 v2 = v[1]->get().vertex; - Vector3 v3 = v[2]->get().vertex; +} +void SurfaceTool::mikktSetTSpaceBasic(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert){ - Vector2 w1 = v[0]->get().uv; - Vector2 w2 = v[1]->get().uv; - Vector2 w3 = v[2]->get().uv; + Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData); + Vertex &vtx = varr[iFace*3+iVert]->get(); + vtx.tangent = Vector3(fvTangent[0],fvTangent[1],fvTangent[2]); + vtx.binormal = vtx.normal.cross(vtx.tangent) * fSign; +} - float x1 = v2.x - v1.x; - float x2 = v3.x - v1.x; - float y1 = v2.y - v1.y; - float y2 = v3.y - v1.y; - float z1 = v2.z - v1.z; - float z2 = v3.z - v1.z; - float s1 = w2.x - w1.x; - float s2 = w3.x - w1.x; - float t1 = w2.y - w1.y; - float t2 = w3.y - w1.y; +void SurfaceTool::generate_tangents() { - float r = (s1 * t2 - s2 * t1); + ERR_FAIL_COND(!(format&Mesh::ARRAY_FORMAT_TEX_UV)); + ERR_FAIL_COND(!(format&Mesh::ARRAY_FORMAT_NORMAL)); - Vector3 binormal,tangent; + bool indexed = index_array.size()>0; + if (indexed) + deindex(); - if (r==0) { - binormal=Vector3(0,0,0); - tangent=Vector3(0,0,0); - } else { - tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, - (t2 * z1 - t1 * z2) * r); - binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, - (s1 * z2 - s2 * z1) * r); - } - tangent.normalize(); - binormal.normalize(); - Vector3 normal=Plane( v1, v2, v3 ).normal; + SMikkTSpaceInterface mkif; + mkif.m_getNormal=mikktGetNormal; + mkif.m_getNumFaces=mikktGetNumFaces; + mkif.m_getNumVerticesOfFace=mikktGetNumVerticesOfFace; + mkif.m_getPosition=mikktGetPosition; + mkif.m_getTexCoord=mikktGetTexCoord; + mkif.m_setTSpaceBasic=mikktSetTSpaceBasic; + mkif.m_setTSpace=NULL; - Vector3 tangentp = tangent - normal * normal.dot( tangent ); - Vector3 binormalp = binormal - normal * (normal.dot(binormal)) - tangent * (tangent.dot(binormal)); + SMikkTSpaceContext msc; + msc.m_pInterface=&mkif; - tangentp.normalize(); - binormalp.normalize(); + Vector<List<Vertex>::Element*> vtx; + vtx.resize(vertex_array.size()); + int idx=0; + for (List<Vertex>::Element *E=vertex_array.front();E;E=E->next()) { + vtx[idx++]=E; + E->get().binormal=Vector3(); + E->get().tangent=Vector3(); + } + msc.m_pUserData=&vtx; + bool res = genTangSpaceDefault(&msc); - for (int j=0;j<3;j++) { - v[j]->get().binormal=binormalp; - v[j]->get().tangent=tangentp; + ERR_FAIL_COND(!res); + format|=Mesh::ARRAY_FORMAT_TANGENT; - } - } - } + if (indexed) + index(); - format|=Mesh::ARRAY_FORMAT_TANGENT; } diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index fe82d3a4ce..fc5940145b 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -30,7 +30,7 @@ #define SURFACE_TOOL_H #include "scene/resources/mesh.h" - +#include "mikktspace.h" class SurfaceTool : public Reference { @@ -82,6 +82,14 @@ private: void _create_list(const Ref<Mesh>& p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index,int &lformat); + + //mikktspace callbacks + static int mikktGetNumFaces(const SMikkTSpaceContext * pContext); + static int mikktGetNumVerticesOfFace(const SMikkTSpaceContext * pContext, const int iFace); + static void mikktGetPosition(const SMikkTSpaceContext * pContext, float fvPosOut[], const int iFace, const int iVert); + static void mikktGetNormal(const SMikkTSpaceContext * pContext, float fvNormOut[], const int iFace, const int iVert); + static void mikktGetTexCoord(const SMikkTSpaceContext * pContext, float fvTexcOut[], const int iFace, const int iVert); + static void mikktSetTSpaceBasic(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert); protected: static void _bind_methods(); |