void PathSpatialGizmo::redraw(){ clear(); Ref<Curve3D> c = path->get_curve(); if (c.is_null()) return; Vector3Array v3a=c->tesselate(); //Vector3Array v3a=c->get_baked_points(); int v3s = v3a.size(); if (v3s==0) return; Vector<Vector3> v3p; Vector3Array::Read r = v3a.read(); for(int i=0;i<v3s-1;i++) { v3p.push_back(r[i]); v3p.push_back(r[i+1]); //v3p.push_back(r[i]); //v3p.push_back(r[i]+Vector3(0,0.2,0)); } add_lines(v3p,PathEditorPlugin::singleton->path_material); add_collision_segments(v3p); if (PathEditorPlugin::singleton->get_edited_path()==path) { v3p.clear(); Vector<Vector3> handles; Vector<Vector3> sec_handles; for(int i=0;i<c->get_point_count();i++) { Vector3 p = c->get_point_pos(i); handles.push_back(p); if (i>0) { v3p.push_back(p); v3p.push_back(p+c->get_point_in(i)); sec_handles.push_back(p+c->get_point_in(i)); } if (i<c->get_point_count()-1) { v3p.push_back(p); v3p.push_back(p+c->get_point_out(i)); sec_handles.push_back(p+c->get_point_out(i)); } } add_lines(v3p,PathEditorPlugin::singleton->path_thin_material); add_handles(handles); add_handles(sec_handles,false,true); } }
/* Add a point by splitting segment into two, putting the new point at 'point' or, if NULL, in the middle */ ObjectChange * beziershape_add_segment(BezierShape *bezier, int segment, Point *point) { BezPoint realpoint; BezCornerType corner_type = BEZ_CORNER_SYMMETRIC; Handle *new_handle1, *new_handle2, *new_handle3; ConnectionPoint *new_cp1, *new_cp2; Point startpoint; Point other; if (segment != 1) startpoint = bezier->points[segment-1].p3; else startpoint = bezier->points[0].p1; other = bezier->points[segment].p3; if (point == NULL) { realpoint.p1.x = (startpoint.x + other.x)/6; realpoint.p1.y = (startpoint.y + other.y)/6; realpoint.p2.x = (startpoint.x + other.x)/3; realpoint.p2.y = (startpoint.y + other.y)/3; realpoint.p3.x = (startpoint.x + other.x)/2; realpoint.p3.y = (startpoint.y + other.y)/2; } else { realpoint.p2.x = point->x+(startpoint.x-other.x)/6; realpoint.p2.y = point->y+(startpoint.y-other.y)/6; realpoint.p3 = *point; /* this really goes into the next segment ... */ realpoint.p1.x = point->x-(startpoint.x-other.x)/6; realpoint.p1.y = point->y-(startpoint.y-other.y)/6; } realpoint.type = BEZ_CURVE_TO; new_handle1 = g_new0(Handle,1); new_handle2 = g_new0(Handle,1); new_handle3 = g_new0(Handle,1); setup_handle(new_handle1, HANDLE_RIGHTCTRL); setup_handle(new_handle2, HANDLE_LEFTCTRL); setup_handle(new_handle3, HANDLE_BEZMAJOR); new_cp1 = g_new0(ConnectionPoint, 1); new_cp2 = g_new0(ConnectionPoint, 1); new_cp1->object = &bezier->object; new_cp2->object = &bezier->object; add_handles(bezier, segment, &realpoint, corner_type, new_handle1, new_handle2, new_handle3, new_cp1, new_cp2); return beziershape_create_point_change(bezier, TYPE_ADD_POINT, &realpoint, corner_type, segment, new_handle1, new_handle2, new_handle3, new_cp1, new_cp2); }
void PathSpatialGizmo::redraw() { clear(); Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material"); Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material"); Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles"); Ref<Curve3D> c = path->get_curve(); if (c.is_null()) return; PoolVector<Vector3> v3a = c->tessellate(); //PoolVector<Vector3> v3a=c->get_baked_points(); int v3s = v3a.size(); if (v3s == 0) return; Vector<Vector3> v3p; PoolVector<Vector3>::Read r = v3a.read(); // BUG: the following won't work when v3s, avoid drawing as a temporary workaround. for (int i = 0; i < v3s - 1; i++) { v3p.push_back(r[i]); v3p.push_back(r[i + 1]); //v3p.push_back(r[i]); //v3p.push_back(r[i]+Vector3(0,0.2,0)); } if (v3p.size() > 1) { add_lines(v3p, path_material); add_collision_segments(v3p); } if (PathEditorPlugin::singleton->get_edited_path() == path) { v3p.clear(); Vector<Vector3> handles; Vector<Vector3> sec_handles; for (int i = 0; i < c->get_point_count(); i++) { Vector3 p = c->get_point_position(i); handles.push_back(p); if (i > 0) { v3p.push_back(p); v3p.push_back(p + c->get_point_in(i)); sec_handles.push_back(p + c->get_point_in(i)); } if (i < c->get_point_count() - 1) { v3p.push_back(p); v3p.push_back(p + c->get_point_out(i)); sec_handles.push_back(p + c->get_point_out(i)); } } if (v3p.size() > 1) { add_lines(v3p, path_thin_material); } if (handles.size()) { add_handles(handles, handles_material); } if (sec_handles.size()) { add_handles(sec_handles, handles_material, false, true); } } }