From d9cb00151bd662a25016ecab69433b2d4c146f6e Mon Sep 17 00:00:00 2001 From: Will Nations Date: Thu, 7 Dec 2017 00:31:03 -0600 Subject: [PATCH] [DOCS] Camera property changes --- doc/classes/Camera.xml | 182 +++++++++---------------------------- scene/3d/camera.cpp | 198 ++++++++++++++++------------------------- scene/3d/camera.h | 13 ++- 3 files changed, 132 insertions(+), 261 deletions(-) diff --git a/doc/classes/Camera.xml b/doc/classes/Camera.xml index 5d6c13498cf..91c9ecc7746 100644 --- a/doc/classes/Camera.xml +++ b/doc/classes/Camera.xml @@ -25,88 +25,6 @@ Get the camera transform. Subclassed cameras (such as CharacterCamera) may provide different transforms than the [Node] transform. - - - - - Returns the culling mask, describing which 3D render layers are rendered by this Camera. - - - - - - - - - - - - - Returns the [Environment] used by this Camera. - - - - - - - Returns the [i]FOV[/i] Y angle in degrees (FOV means Field of View). - - - - - - - Returns the horizontal (X) offset of the Camera viewport. - - - - - - - Returns the current mode for keeping the aspect ratio. See [code]KEEP_*[/code] constants. - - - - - - - Returns the Camera's projection. See PROJECTION_* constants. - - - - - - - - - - - - - Returns the vertical (Y) offset of the Camera viewport. - - - - - - - Returns the far clip plane in world space units. - - - - - - - Returns the near clip plane in world space units. - - - - - - - Returns [code]true[/code] if the Camera is the current one in the [Viewport], or plans to become current (if outside the scene tree). - - @@ -129,6 +47,7 @@ + Returns a normal vector from the screen point location directed along the camera. Orthogonal cameras are normalized. Perspective cameras account for perspective, screen width/height, etc. @@ -158,51 +77,6 @@ Returns a 3D position in worldspace, that is the result of projecting a point on the [Viewport] rectangle by the camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking. - - - - - - - Sets the cull mask, describing which 3D render layers are rendered by this Camera. - - - - - - - - - Changes Doppler effect tracking. See [code]DOPPLER_*[/code] constants. - - - - - - - - - Sets the [Environment] to use for this Camera. - - - - - - - - - Sets the horizontal (X) offset of the Camera viewport. - - - - - - - - - Sets the mode for keeping the aspect ratio. See [code]KEEP_*[/code] constants. - - @@ -229,15 +103,6 @@ Set the camera projection to perspective mode, by specifying a [i]FOV[/i] Y angle in degrees (FOV means Field of View), and the [i]near[/i] and [i]far[/i] clip planes in worldspace units. - - - - - - - Sets the vertical (Y) offset of the Camera viewport. - - @@ -248,6 +113,47 @@ + + + The culling mask that describes which 3D render layers are rendered by this camera. + + + If [code]true[/code] the ancestor [Viewport] is currently using this Camera. Default value: [code]false[/code]. + + + If not [code]DOPPLER_TRACKING_DISABLED[/code] this Camera will simulate the Doppler effect for objects changed in particular [code]_process[/code] methods. Default value: [code]DOPPLER_TRACKING_DISABLED[/code]. + + + Set the [Environment] to use for this Camera. + + + The distance to the far culling boundary for this Camera relative to its local z-axis. + + + The camera's field of view angle (in degrees). Only applicable in perspective mode. Since [member keep_aspect] locks one axis, [code]fov[/code] sets the other axis' field of view angle. + + + The horizontal (X) offset of the Camear viewport. + + + The axis to lock during [member fov]/[member size] adjustments. + + + The distance to the near culling boundary for this Camera relative to its local z-axis. + + + The camera's projection mode. In [code]PROJECTION_PERSPECTIVE[/code] mode, objects' z-distance from the camera's local space scales their perceived size. + + + The camera's size measured as 1/2 the width or height. Only applicable in orthogonal mode. Since [member keep_aspect] locks on axis, [code]size[/code] sets the other axis' size length. + + + The horizontal (Y) offset of the Camear viewport. + + + A boolean representation of [member keep_aspect] in which [code]true[/code] is equivalent to [code]KEEP_WIDTH[/code]. + + Perspective Projection (object's size on the screen becomes smaller when far away). @@ -256,10 +162,10 @@ Orthogonal Projection (objects remain the same size on the screen no matter how far away they are). - Try to keep the aspect ratio when scaling the Camera's viewport to the screen. If not possible, preserve the viewport's width by changing the height. Height is [code]sizey[/code] for orthographic projection, [code]fovy[/code] for perspective projection. + Preserves the horizontal aspect ratio. - Try to keep the aspect ratio when scaling the Camera's viewport to the screen. If not possible, preserve the viewport's height by changing the width. Width is [code]sizex[/code] for orthographic projection, [code]fovx[/code] for perspective projection. + Preserves the vertical aspect ratio. Disable Doppler effect simulation (default). diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index af210fff1c9..72c0b979afe 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -56,126 +56,16 @@ void Camera::_update_camera_mode() { } } -bool Camera::_set(const StringName &p_name, const Variant &p_value) { - - bool changed_all = false; - if (p_name == "projection") { - - int proj = p_value; - if (proj == PROJECTION_PERSPECTIVE) - mode = PROJECTION_PERSPECTIVE; - if (proj == PROJECTION_ORTHOGONAL) - mode = PROJECTION_ORTHOGONAL; - - changed_all = true; - } else if (p_name == "fov" || p_name == "fovy" || p_name == "fovx") - fov = p_value; - else if (p_name == "size" || p_name == "sizex" || p_name == "sizey") - size = p_value; - else if (p_name == "near") - near = p_value; - else if (p_name == "far") - far = p_value; - else if (p_name == "keep_aspect") - set_keep_aspect_mode(KeepAspect(int(p_value))); - else if (p_name == "vaspect") - set_keep_aspect_mode(p_value ? KEEP_WIDTH : KEEP_HEIGHT); - else if (p_name == "h_offset") - h_offset = p_value; - else if (p_name == "v_offset") - v_offset = p_value; - else if (p_name == "current") { - if (p_value.operator bool()) { - make_current(); - } else { - clear_current(); +void Camera::_validate_property(PropertyInfo &p_property) const { + if (p_property.name == "fov") { + if (mode == PROJECTION_ORTHOGONAL) { + p_property.usage = PROPERTY_USAGE_NOEDITOR; } - } else if (p_name == "cull_mask") { - set_cull_mask(p_value); - } else if (p_name == "environment") { - set_environment(p_value); - } else if (p_name == "doppler/tracking") { - set_doppler_tracking(DopplerTracking(int(p_value))); - } else - return false; - - _update_camera_mode(); - if (changed_all) - _change_notify(); - return true; -} -bool Camera::_get(const StringName &p_name, Variant &r_ret) const { - - if (p_name == "projection") { - r_ret = mode; - } else if (p_name == "fov" || p_name == "fovy" || p_name == "fovx") - r_ret = fov; - else if (p_name == "size" || p_name == "sizex" || p_name == "sizey") - r_ret = size; - else if (p_name == "near") - r_ret = near; - else if (p_name == "far") - r_ret = far; - else if (p_name == "keep_aspect") - r_ret = int(keep_aspect); - else if (p_name == "current") { - - if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { - r_ret = current; - } else { - r_ret = is_current(); + } else if (p_property.name == "size") { + if (mode == PROJECTION_PERSPECTIVE) { + p_property.usage = PROPERTY_USAGE_NOEDITOR; } - } else if (p_name == "cull_mask") { - r_ret = get_cull_mask(); - } else if (p_name == "h_offset") { - r_ret = get_h_offset(); - } else if (p_name == "v_offset") { - r_ret = get_v_offset(); - } else if (p_name == "environment") { - r_ret = get_environment(); - } else if (p_name == "doppler/tracking") { - r_ret = get_doppler_tracking(); - } else - return false; - - return true; -} - -void Camera::_get_property_list(List *p_list) const { - - p_list->push_back(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal")); - - switch (mode) { - - case PROJECTION_PERSPECTIVE: { - - p_list->push_back(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_NOEDITOR)); - if (keep_aspect == KEEP_WIDTH) - p_list->push_back(PropertyInfo(Variant::REAL, "fovx", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_EDITOR)); - else - p_list->push_back(PropertyInfo(Variant::REAL, "fovy", PROPERTY_HINT_RANGE, "1,179,0.1", PROPERTY_USAGE_EDITOR)); - - } break; - case PROJECTION_ORTHOGONAL: { - - p_list->push_back(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "1,16384,0.01", PROPERTY_USAGE_NOEDITOR)); - if (keep_aspect == KEEP_WIDTH) - p_list->push_back(PropertyInfo(Variant::REAL, "sizex", PROPERTY_HINT_RANGE, "0.1,16384,0.01", PROPERTY_USAGE_EDITOR)); - else - p_list->push_back(PropertyInfo(Variant::REAL, "sizey", PROPERTY_HINT_RANGE, "0.1,16384,0.01", PROPERTY_USAGE_EDITOR)); - - } break; } - - p_list->push_back(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01")); - p_list->push_back(PropertyInfo(Variant::REAL, "far", PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01")); - p_list->push_back(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height")); - p_list->push_back(PropertyInfo(Variant::BOOL, "current")); - p_list->push_back(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER)); - p_list->push_back(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment")); - p_list->push_back(PropertyInfo(Variant::REAL, "h_offset")); - p_list->push_back(PropertyInfo(Variant::REAL, "v_offset")); - p_list->push_back(PropertyInfo(Variant::INT, "doppler/tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics")); } void Camera::_update_camera() { @@ -282,6 +172,14 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { update_gizmo(); } +void Camera::set_projection(Camera::Projection p_mode) { + if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL) { + mode = p_mode; + _update_camera_mode(); + _change_notify(); + } +} + RID Camera::get_camera() const { return camera; @@ -311,6 +209,14 @@ void Camera::clear_current() { } } +void Camera::set_current(bool p_current) { + if (p_current) { + make_current(); + } else { + clear_current(); + } +} + bool Camera::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { @@ -481,6 +387,7 @@ void Camera::set_environment(const Ref &p_environment) { VS::get_singleton()->camera_set_environment(camera, environment->get_rid()); else VS::get_singleton()->camera_set_environment(camera, RID()); + _update_camera_mode(); } Ref Camera::get_environment() const { @@ -489,10 +396,9 @@ Ref Camera::get_environment() const { } void Camera::set_keep_aspect_mode(KeepAspect p_aspect) { - keep_aspect = p_aspect; VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); - + _update_camera_mode(); _change_notify(); } @@ -501,6 +407,15 @@ Camera::KeepAspect Camera::get_keep_aspect_mode() const { return keep_aspect; } +void Camera::set_vaspect(bool p_vaspect) { + set_keep_aspect_mode(p_vaspect ? KEEP_WIDTH : KEEP_HEIGHT); + _update_camera_mode(); +} + +bool Camera::get_vaspect() const { + return keep_aspect == KEEP_HEIGHT; +} + void Camera::set_doppler_tracking(DopplerTracking p_tracking) { if (doppler_tracking == p_tracking) @@ -511,6 +426,7 @@ void Camera::set_doppler_tracking(DopplerTracking p_tracking) { velocity_tracker->set_track_physics_step(doppler_tracking == DOPPLER_TRACKING_PHYSICS_STEP); velocity_tracker->reset(get_global_transform().origin); } + _update_camera_mode(); } Camera::DopplerTracking Camera::get_doppler_tracking() const { @@ -529,13 +445,19 @@ void Camera::_bind_methods() { ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal); ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current); ClassDB::bind_method(D_METHOD("clear_current"), &Camera::clear_current); + ClassDB::bind_method(D_METHOD("set_current"), &Camera::set_current); ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current); ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform); ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov); ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size); ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar); ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear); + ClassDB::bind_method(D_METHOD("set_fov"), &Camera::set_fov); + ClassDB::bind_method(D_METHOD("set_size"), &Camera::set_size); + ClassDB::bind_method(D_METHOD("set_zfar"), &Camera::set_zfar); + ClassDB::bind_method(D_METHOD("set_znear"), &Camera::set_znear); ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection); + ClassDB::bind_method(D_METHOD("set_projection"), &Camera::set_projection); ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset); ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset); ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset); @@ -546,10 +468,26 @@ void Camera::_bind_methods() { ClassDB::bind_method(D_METHOD("get_environment"), &Camera::get_environment); ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode); ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode); + ClassDB::bind_method(D_METHOD("set_vaspect"), &Camera::set_vaspect); + ClassDB::bind_method(D_METHOD("get_vaspect"), &Camera::get_vaspect); ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera::set_doppler_tracking); ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera::get_doppler_tracking); //ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current ); + ADD_PROPERTY(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height"), "set_keep_aspect_mode", "get_keep_aspect_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vaspect"), "set_vaspect", "get_vaspect"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "h_offset"), "set_h_offset", "get_h_offset"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_offset"), "set_v_offset", "get_v_offset"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal"), "set_projection", "get_projection"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "0.1,16384,0.01"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "near"), "set_znear", "get_znear"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "far"), "set_zfar", "get_zfar"); + BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE); BIND_ENUM_CONSTANT(PROJECTION_ORTHOGONAL); @@ -586,10 +524,30 @@ Camera::Projection Camera::get_projection() const { return mode; } -void Camera::set_cull_mask(uint32_t p_layers) { +void Camera::set_fov(float p_fov) { + fov = p_fov; + _update_camera_mode(); +} +void Camera::set_size(float p_size) { + size = p_size; + _update_camera_mode(); +} + +void Camera::set_znear(float p_znear) { + near = p_znear; + _update_camera_mode(); +} + +void Camera::set_zfar(float p_zfar) { + far = p_zfar; + _update_camera_mode(); +} + +void Camera::set_cull_mask(uint32_t p_layers) { layers = p_layers; VisualServer::get_singleton()->camera_set_cull_mask(camera, layers); + _update_camera_mode(); } uint32_t Camera::get_cull_mask() const { diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 73c6844c1a6..520afb962bb 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -95,10 +95,8 @@ protected: virtual void _request_camera_update(); void _update_camera_mode(); - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; void _notification(int p_what); + virtual void _validate_property(PropertyInfo &property) const; static void _bind_methods(); @@ -111,9 +109,11 @@ public: void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_orthogonal(float p_size, float p_z_near, float p_z_far); + void set_projection(Camera::Projection p_mode); void make_current(); void clear_current(); + void set_current(bool p_current); bool is_current() const; RID get_camera() const; @@ -124,6 +124,11 @@ public: float get_znear() const; Projection get_projection() const; + void set_fov(float p_fov); + void set_size(float p_size); + void set_zfar(float p_zfar); + void set_znear(float p_znear); + virtual Transform get_camera_transform() const; Vector3 project_ray_normal(const Point2 &p_pos) const; @@ -143,6 +148,8 @@ public: void set_keep_aspect_mode(KeepAspect p_aspect); KeepAspect get_keep_aspect_mode() const; + void set_vaspect(bool p_vaspect); + bool get_vaspect() const; void set_v_offset(float p_offset); float get_v_offset() const;