diff options
Diffstat (limited to 'modules/csg/csg_gizmos.cpp')
| -rw-r--r-- | modules/csg/csg_gizmos.cpp | 146 | 
1 files changed, 73 insertions, 73 deletions
diff --git a/modules/csg/csg_gizmos.cpp b/modules/csg/csg_gizmos.cpp index 1b63bccb06..fa176cb94e 100644 --- a/modules/csg/csg_gizmos.cpp +++ b/modules/csg/csg_gizmos.cpp @@ -32,7 +32,7 @@  /////////// -CSGShapeSpatialGizmoPlugin::CSGShapeSpatialGizmoPlugin() { +CSGShape3DGizmoPlugin::CSGShape3DGizmoPlugin() {  	Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.0, 0.4, 1, 0.15));  	create_material("shape_union_material", gizmo_color); @@ -49,46 +49,46 @@ CSGShapeSpatialGizmoPlugin::CSGShapeSpatialGizmoPlugin() {  	create_handle_material("handles");  } -String CSGShapeSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const { +String CSGShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { -	CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); +	CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); -	if (Object::cast_to<CSGSphere>(cs)) { +	if (Object::cast_to<CSGSphere3D>(cs)) {  		return "Radius";  	} -	if (Object::cast_to<CSGBox>(cs)) { +	if (Object::cast_to<CSGBox3D>(cs)) {  		static const char *hname[3] = { "Width", "Height", "Depth" };  		return hname[p_idx];  	} -	if (Object::cast_to<CSGCylinder>(cs)) { +	if (Object::cast_to<CSGCylinder3D>(cs)) {  		return p_idx == 0 ? "Radius" : "Height";  	} -	if (Object::cast_to<CSGTorus>(cs)) { +	if (Object::cast_to<CSGTorus3D>(cs)) {  		return p_idx == 0 ? "InnerRadius" : "OuterRadius";  	}  	return "";  } -Variant CSGShapeSpatialGizmoPlugin::get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const { +Variant CSGShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { -	CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); +	CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); -	if (Object::cast_to<CSGSphere>(cs)) { +	if (Object::cast_to<CSGSphere3D>(cs)) { -		CSGSphere *s = Object::cast_to<CSGSphere>(cs); +		CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs);  		return s->get_radius();  	} -	if (Object::cast_to<CSGBox>(cs)) { +	if (Object::cast_to<CSGBox3D>(cs)) { -		CSGBox *s = Object::cast_to<CSGBox>(cs); +		CSGBox3D *s = Object::cast_to<CSGBox3D>(cs);  		switch (p_idx) {  			case 0: return s->get_width();  			case 1: return s->get_height(); @@ -96,23 +96,23 @@ Variant CSGShapeSpatialGizmoPlugin::get_handle_value(EditorSpatialGizmo *p_gizmo  		}  	} -	if (Object::cast_to<CSGCylinder>(cs)) { +	if (Object::cast_to<CSGCylinder3D>(cs)) { -		CSGCylinder *s = Object::cast_to<CSGCylinder>(cs); +		CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs);  		return p_idx == 0 ? s->get_radius() : s->get_height();  	} -	if (Object::cast_to<CSGTorus>(cs)) { +	if (Object::cast_to<CSGTorus3D>(cs)) { -		CSGTorus *s = Object::cast_to<CSGTorus>(cs); +		CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs);  		return p_idx == 0 ? s->get_inner_radius() : s->get_outer_radius();  	}  	return Variant();  } -void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point) { +void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { -	CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); +	CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node());  	Transform gt = cs->get_global_transform();  	//gt.orthonormalize(); @@ -123,15 +123,15 @@ void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i  	Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; -	if (Object::cast_to<CSGSphere>(cs)) { +	if (Object::cast_to<CSGSphere3D>(cs)) { -		CSGSphere *s = Object::cast_to<CSGSphere>(cs); +		CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs);  		Vector3 ra, rb;  		Geometry::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);  		float d = ra.x; -		if (SpatialEditor::get_singleton()->is_snap_enabled()) { -			d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap()); +		if (Node3DEditor::get_singleton()->is_snap_enabled()) { +			d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());  		}  		if (d < 0.001) @@ -140,17 +140,17 @@ void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i  		s->set_radius(d);  	} -	if (Object::cast_to<CSGBox>(cs)) { +	if (Object::cast_to<CSGBox3D>(cs)) { -		CSGBox *s = Object::cast_to<CSGBox>(cs); +		CSGBox3D *s = Object::cast_to<CSGBox3D>(cs);  		Vector3 axis;  		axis[p_idx] = 1.0;  		Vector3 ra, rb;  		Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);  		float d = ra[p_idx]; -		if (SpatialEditor::get_singleton()->is_snap_enabled()) { -			d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap()); +		if (Node3DEditor::get_singleton()->is_snap_enabled()) { +			d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());  		}  		if (d < 0.001) @@ -163,17 +163,17 @@ void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i  		}  	} -	if (Object::cast_to<CSGCylinder>(cs)) { +	if (Object::cast_to<CSGCylinder3D>(cs)) { -		CSGCylinder *s = Object::cast_to<CSGCylinder>(cs); +		CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs);  		Vector3 axis;  		axis[p_idx == 0 ? 0 : 1] = 1.0;  		Vector3 ra, rb;  		Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);  		float d = axis.dot(ra); -		if (SpatialEditor::get_singleton()->is_snap_enabled()) { -			d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap()); +		if (Node3DEditor::get_singleton()->is_snap_enabled()) { +			d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());  		}  		if (d < 0.001) @@ -185,17 +185,17 @@ void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i  			s->set_height(d * 2.0);  	} -	if (Object::cast_to<CSGTorus>(cs)) { +	if (Object::cast_to<CSGTorus3D>(cs)) { -		CSGTorus *s = Object::cast_to<CSGTorus>(cs); +		CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs);  		Vector3 axis;  		axis[0] = 1.0;  		Vector3 ra, rb;  		Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);  		float d = axis.dot(ra); -		if (SpatialEditor::get_singleton()->is_snap_enabled()) { -			d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap()); +		if (Node3DEditor::get_singleton()->is_snap_enabled()) { +			d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());  		}  		if (d < 0.001) @@ -207,26 +207,26 @@ void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i  			s->set_outer_radius(d);  	}  } -void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { -	CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); +	CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); -	if (Object::cast_to<CSGSphere>(cs)) { -		CSGSphere *s = Object::cast_to<CSGSphere>(cs); +	if (Object::cast_to<CSGSphere3D>(cs)) { +		CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs);  		if (p_cancel) {  			s->set_radius(p_restore);  			return;  		} -		UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); +		UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();  		ur->create_action(TTR("Change Sphere Shape Radius"));  		ur->add_do_method(s, "set_radius", s->get_radius());  		ur->add_undo_method(s, "set_radius", p_restore);  		ur->commit_action();  	} -	if (Object::cast_to<CSGBox>(cs)) { -		CSGBox *s = Object::cast_to<CSGBox>(cs); +	if (Object::cast_to<CSGBox3D>(cs)) { +		CSGBox3D *s = Object::cast_to<CSGBox3D>(cs);  		if (p_cancel) {  			switch (p_idx) {  				case 0: s->set_width(p_restore); break; @@ -236,7 +236,7 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  			return;  		} -		UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); +		UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();  		ur->create_action(TTR("Change Box Shape Extents"));  		static const char *method[3] = { "set_width", "set_height", "set_depth" };  		float current = 0; @@ -251,8 +251,8 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  		ur->commit_action();  	} -	if (Object::cast_to<CSGCylinder>(cs)) { -		CSGCylinder *s = Object::cast_to<CSGCylinder>(cs); +	if (Object::cast_to<CSGCylinder3D>(cs)) { +		CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs);  		if (p_cancel) {  			if (p_idx == 0)  				s->set_radius(p_restore); @@ -261,7 +261,7 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  			return;  		} -		UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); +		UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();  		if (p_idx == 0) {  			ur->create_action(TTR("Change Cylinder Radius"));  			ur->add_do_method(s, "set_radius", s->get_radius()); @@ -275,8 +275,8 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  		ur->commit_action();  	} -	if (Object::cast_to<CSGTorus>(cs)) { -		CSGTorus *s = Object::cast_to<CSGTorus>(cs); +	if (Object::cast_to<CSGTorus3D>(cs)) { +		CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs);  		if (p_cancel) {  			if (p_idx == 0)  				s->set_inner_radius(p_restore); @@ -285,7 +285,7 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  			return;  		} -		UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); +		UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();  		if (p_idx == 0) {  			ur->create_action(TTR("Change Torus Inner Radius"));  			ur->add_do_method(s, "set_inner_radius", s->get_inner_radius()); @@ -299,37 +299,37 @@ void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int  		ur->commit_action();  	}  } -bool CSGShapeSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) { -	return Object::cast_to<CSGSphere>(p_spatial) || Object::cast_to<CSGBox>(p_spatial) || Object::cast_to<CSGCylinder>(p_spatial) || Object::cast_to<CSGTorus>(p_spatial) || Object::cast_to<CSGMesh>(p_spatial) || Object::cast_to<CSGPolygon>(p_spatial); +bool CSGShape3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { +	return Object::cast_to<CSGSphere3D>(p_spatial) || Object::cast_to<CSGBox3D>(p_spatial) || Object::cast_to<CSGCylinder3D>(p_spatial) || Object::cast_to<CSGTorus3D>(p_spatial) || Object::cast_to<CSGMesh3D>(p_spatial) || Object::cast_to<CSGPolygon3D>(p_spatial);  } -String CSGShapeSpatialGizmoPlugin::get_name() const { -	return "CSGShapes"; +String CSGShape3DGizmoPlugin::get_name() const { +	return "CSGShape3D";  } -int CSGShapeSpatialGizmoPlugin::get_priority() const { +int CSGShape3DGizmoPlugin::get_priority() const {  	return -1;  } -bool CSGShapeSpatialGizmoPlugin::is_selectable_when_hidden() const { +bool CSGShape3DGizmoPlugin::is_selectable_when_hidden() const {  	return true;  } -void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { +void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { -	CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); +	CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node());  	p_gizmo->clear();  	Ref<Material> material;  	switch (cs->get_operation()) { -		case CSGShape::OPERATION_UNION: +		case CSGShape3D::OPERATION_UNION:  			material = get_material("shape_union_material", p_gizmo);  			break; -		case CSGShape::OPERATION_INTERSECTION: +		case CSGShape3D::OPERATION_INTERSECTION:  			material = get_material("shape_intersection_material", p_gizmo);  			break; -		case CSGShape::OPERATION_SUBTRACTION: +		case CSGShape3D::OPERATION_SUBTRACTION:  			material = get_material("shape_subtraction_material", p_gizmo);  			break;  	} @@ -366,13 +366,13 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  		Ref<Material> solid_material;  		switch (cs->get_operation()) { -			case CSGShape::OPERATION_UNION: +			case CSGShape3D::OPERATION_UNION:  				solid_material = get_material("shape_union_solid_material", p_gizmo);  				break; -			case CSGShape::OPERATION_INTERSECTION: +			case CSGShape3D::OPERATION_INTERSECTION:  				solid_material = get_material("shape_intersection_solid_material", p_gizmo);  				break; -			case CSGShape::OPERATION_SUBTRACTION: +			case CSGShape3D::OPERATION_SUBTRACTION:  				solid_material = get_material("shape_subtraction_solid_material", p_gizmo);  				break;  		} @@ -380,8 +380,8 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  		p_gizmo->add_mesh(mesh, false, Ref<SkinReference>(), solid_material);  	} -	if (Object::cast_to<CSGSphere>(cs)) { -		CSGSphere *s = Object::cast_to<CSGSphere>(cs); +	if (Object::cast_to<CSGSphere3D>(cs)) { +		CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs);  		float r = s->get_radius();  		Vector<Vector3> handles; @@ -389,8 +389,8 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  		p_gizmo->add_handles(handles, handles_material);  	} -	if (Object::cast_to<CSGBox>(cs)) { -		CSGBox *s = Object::cast_to<CSGBox>(cs); +	if (Object::cast_to<CSGBox3D>(cs)) { +		CSGBox3D *s = Object::cast_to<CSGBox3D>(cs);  		Vector<Vector3> handles;  		handles.push_back(Vector3(s->get_width() * 0.5, 0, 0)); @@ -399,8 +399,8 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  		p_gizmo->add_handles(handles, handles_material);  	} -	if (Object::cast_to<CSGCylinder>(cs)) { -		CSGCylinder *s = Object::cast_to<CSGCylinder>(cs); +	if (Object::cast_to<CSGCylinder3D>(cs)) { +		CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs);  		Vector<Vector3> handles;  		handles.push_back(Vector3(s->get_radius(), 0, 0)); @@ -408,8 +408,8 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  		p_gizmo->add_handles(handles, handles_material);  	} -	if (Object::cast_to<CSGTorus>(cs)) { -		CSGTorus *s = Object::cast_to<CSGTorus>(cs); +	if (Object::cast_to<CSGTorus3D>(cs)) { +		CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs);  		Vector<Vector3> handles;  		handles.push_back(Vector3(s->get_inner_radius(), 0, 0)); @@ -419,6 +419,6 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {  }  EditorPluginCSG::EditorPluginCSG(EditorNode *p_editor) { -	Ref<CSGShapeSpatialGizmoPlugin> gizmo_plugin = Ref<CSGShapeSpatialGizmoPlugin>(memnew(CSGShapeSpatialGizmoPlugin)); -	SpatialEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin); +	Ref<CSGShape3DGizmoPlugin> gizmo_plugin = Ref<CSGShape3DGizmoPlugin>(memnew(CSGShape3DGizmoPlugin)); +	Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);  }  |