Preventing add_curve curves exploding...
-
or repairing...
I posted this on the 'official' site but know quite a few only visit here...
@unknownuser said:
Using entities.add_curve(points_array) will return a continuous selectable curve...
If you add this curve to a surface it remains a continuous selectable curve...
if you add a 'surface' to the curve it becomes a series of disconnected edges, but each edge still reports as being a curve...
this occurs for surfaces formed from the curve to a centre point or between two curves...
the gif shows a demo from the script attached...
I have tried many ways of grouping, moving, exploding in different sequences, but they all result exactly the same as this one...
I looked at many welding scripts, but they either fail to work, are buggy or spend a lot of effort 'looking' for an edge array...
As already have original point arrays, is there a way to remedy this splitting of the curses highlighted in the gif...
# script to aid in disscussion of welding surface edges... model = Sketchup.active_model sel = model.selection ents = model.active_entities view = model.active_view mats = model.materials # cylindrical sine wave pair on a unit radius with 24 sides... wave = [[1.0, 0.0, 0.0], [0.9659258262890683, 0.25881904510252074, 0.050799999999999984], [0.8660254037844387, 0.49999999999999994, 0.08798818102449896], [0.7071067811865476, 0.7071067811865475, 0.1016], [0.5000000000000001, 0.8660254037844386, 0.08798818102449898], [0.25881904510252096, 0.9659258262890682, 0.05080000000000003], [6.123233995736766e-17, 1.0, 1.2442411479337108e-17], [-0.25881904510252063, 0.9659258262890683, -0.05079999999999998], [-0.4999999999999998, 0.8660254037844388, -0.08798818102449893], [-0.7071067811865475, 0.7071067811865476, -0.1016], [-0.8660254037844385, 0.5000000000000003, -0.087988181024499], [-0.9659258262890682, 0.258819045102521, -0.050800000000000047], [-1.0, 1.2246467991473532e-16, -2.4884822958674216e-17], [-0.9659258262890684, -0.25881904510252035, 0.05079999999999989], [-0.8660254037844388, -0.4999999999999998, 0.08798818102449892], [-0.7071067811865479, -0.7071067811865471, 0.1016], [-0.5000000000000004, -0.8660254037844384, 0.08798818102449903], [-0.25881904510252146, -0.9659258262890681, 0.05080000000000014], [-1.8369701987210297e-16, -1.0, 3.267705224142925e-17], [0.2588190451025203, -0.9659258262890684, -0.050799999999999915], [0.4999999999999993, -0.866025403784439, -0.08798818102449889], [0.7071067811865475, -0.7071067811865477, -0.1016], [0.8660254037844384, -0.5000000000000004, -0.08798818102449901], [0.9659258262890681, -0.2588190451025215, -0.05080000000000014], [1.0, 0.0, -0.0]] rev_wave = wave.reverse # outer_wave = [] rev_wave.each{|pt| outer_wave << [pt[0], pt[1], pt[2] + 0.1]} # inner_wave = [] outer_wave.each{|pt| inner_wave << [pt[0] * 0.5, pt[1] * 0.5, pt[2]]} # single undo model.start_operation('Wave', false, false, false) # add colors to watch the order of construction... mat_names = [] mats.each{|n| mat_names << n.name} mats.add('inner').color = 'skyblue' unless mat_names.include?('inner') mats.add('outer').color = 'seashell' unless mat_names.include?('outer') # Make the empty 'wave' group. wave_grp = ents.add_group() # Make array to hold entities... wave_ents = wave_grp.entities # Add outer points to inner points for the radial pairs... radial = outer_wave.zip(inner_wave) radial_edges = radial.each {|pr| e = wave_ents.add_edges(pr) e[0].soft="true" e[0].smooth="true" # for watching only sel.add(e) view.refresh } sel.clear # Add outer points to offset inner points for the diagonal pairs... diagonal = outer_wave.zip(inner_wave[0..-2].unshift(inner_wave[-1])) diagonal_edges = diagonal.each {|pr| e = wave_ents.add_edges(pr) e[0].soft="true" e[0].smooth="true" e[0].casts_shadows = false # for watching only sel.add(e) view.refresh } sel.clear # Add the inner 'curve' and face created between curve, radial and diagonal edges... inner_edges = wave_ents.add_curve(inner_wave) i = 0 inner_edges.each {|e| e.find_faces f = e.faces[0] i += 1 # for watching only f.material = 'inner' sel.add(f) view.refresh } sel.clear # outer_edges = wave_ents.add_curve(outer_wave) i = 0 outer_edges.each {|e| e.find_faces f = e.faces[0] i += 1 # for watching only f.material = 'outer' sel.add(f) view.refresh } sel.clear sel.add(inner_edges, outer_edges) model.commit_operation
another gif...
If I run Curvisard or Reweld on the selected 'curves' after making them, they are repaired almost instantly...
However, they spend time looking for the 'edges' and I already have those...
I tried one version where I called
Reweld::recurve_curve
but it's quite buggy and adds geometry in a very odd fashion that can bugsplat...I couldn't fathom how to link into Curvisard which is much more common and very reliable...
I would prefer to do it directly in the code, but can't find a way to achieve this...
john
-
Here's the working example...
We have had separate PMs about this before...The order of operations is critical.
Make the softened edges, make the facets, make a curve in a group and explode it over the facets.
If desired turn the smoothed edges back solid...Try this code pasted into the Ruby Console, in an empty model, to make two 1" facets with a shared 'curve' edge-set which straddles an otherwise splitting cross-edge that is smoothed to stop the splitting...
out the smoothing code-line and/or the final un-smoothing code-line to see the differences.
### the vertices of two rectangles sharing edge b,e a=[0,0,0] b=[0,0,1] c=[1,0,1] d=[1,1,1] e=[0,1,1] f=[0,1,0] ### model=Sketchup.active_model aents=model.active_entities ### group=aents.add_group() gents=group.entities ### add softened edge - otherwise splitting at b.e edge=gents.add_line(b,e); edge.smooth=true; edge.soft=true ### gents.add_face(a,b,e,f) gents.add_face(b,c,d,e) ### subgp=aents.add_group() sents=subgp.entities sents.add_curve(a,b,c,d,e,f) ### group.explode subgp.explode ### reset edge b,e back solid, if desired edge.smooth=false; edge.soft=false ###
-
I'll post the code here, because it's where I searched for a solution first and couldn't find one...
I striped out the colouring but left the selection add, as a progress bar substitute...
# with Tig's advice from PM ... model = Sketchup.active_model sel = model.selection ents = model.active_entities view = model.active_view mats = model.materials # cylindrical sine wave pair on a unit radius with 24 sides... wave = [[1.0, 0.0, 0.0], [0.9659258262890683, 0.25881904510252074, 0.050799999999999984], [0.8660254037844387, 0.49999999999999994, 0.08798818102449896], [0.7071067811865476, 0.7071067811865475, 0.1016], [0.5000000000000001, 0.8660254037844386, 0.08798818102449898], [0.25881904510252096, 0.9659258262890682, 0.05080000000000003], [6.123233995736766e-17, 1.0, 1.2442411479337108e-17], [-0.25881904510252063, 0.9659258262890683, -0.05079999999999998], [-0.4999999999999998, 0.8660254037844388, -0.08798818102449893], [-0.7071067811865475, 0.7071067811865476, -0.1016], [-0.8660254037844385, 0.5000000000000003, -0.087988181024499], [-0.9659258262890682, 0.258819045102521, -0.050800000000000047], [-1.0, 1.2246467991473532e-16, -2.4884822958674216e-17], [-0.9659258262890684, -0.25881904510252035, 0.05079999999999989], [-0.8660254037844388, -0.4999999999999998, 0.08798818102449892], [-0.7071067811865479, -0.7071067811865471, 0.1016], [-0.5000000000000004, -0.8660254037844384, 0.08798818102449903], [-0.25881904510252146, -0.9659258262890681, 0.05080000000000014], [-1.8369701987210297e-16, -1.0, 3.267705224142925e-17], [0.2588190451025203, -0.9659258262890684, -0.050799999999999915], [0.4999999999999993, -0.866025403784439, -0.08798818102449889], [0.7071067811865475, -0.7071067811865477, -0.1016], [0.8660254037844384, -0.5000000000000004, -0.08798818102449901], [0.9659258262890681, -0.2588190451025215, -0.05080000000000014], [1.0, 0.0, -0.0]] # waves have an additional point to complete the circle... segments = wave.length - 1 # single undo model.start_operation('wave') # Make the empty 'container' group. container = ents.add_group() cont_ents = container.entities # add the empty surf_grp() to cont_ents surf_grp = cont_ents.add_group() surf_ents = surf_grp.entities # Add Surface soft edges and faces using offset points... i = 0 segments.times do f = surf_ents.add_face(ORIGIN, wave[i], wave[i + 1]) view.refresh f.edges.each{|e| e.soft="true" e.smooth="true" sel.add(e) } i += 1 view.refresh end # add the wave to cont_ents... cont_ents.add_curve(wave) # and explode the surface faces... surf_grp.explode sel.clear model.commit_operation
EDIT: after getting the other working using
add_face
I made a few adjustment to this code...john
Advertisement