# convert .xfig drawings over plan into .obj
bash ribs2gpdata.sh ; bash gpdata2obj.sh

# scale of boat is 7 m long, ie, huge

# then load into meshlab
#Filters -> Cleaning, Repearing -> Remove Zero Area faces
#  "               "            -> Remove Duplicated Vertex
# and that enough to have nothing show as bad under Show Boundary, Show non-manifold, Show non-faux edges

# though orignially did this..:
#Filters -> Cleaning Reparing -> Remove unreferenced vertices
#  "               "          -> Merge close vertices (0.01mm abs)

# highly recommended. 
#Filters -> Remeshing, ... -> Quadratic edge colapse ... (~60000 faces, +preserve boandary, -preserve normals, +presevre topology)

# save out, then Quadratic edge colapse again to 16000 faces.

# and save out as boat.stl

# which makes the face count more managable.
# while also removing some of the flaws/junk from the original obj.



# then scale it down, 170mm/1800mm , ie, beam of 1.8 meters down to 17cm.
printf "n=170/1800; scale([n,n,n])import(\"boat.stl\",convexivity=10);\n" > scaleboat.scad
openscad -o boat_scaled.stl scaleboat.scad
printf "n=170/1800; scale([n,n,n])import(\"block.stl\",convexivity=10);\n" > scaleboat.scad
openscad -o block_scaled.stl scaleboat.scad

#Filters -> Remeshing, ... -> Uniform mesh resampling. (1mm abs precission, -5mm offset, +clean vertices, +multisample)
# To turn it into a shell
# except that it likes to crash out.

# Then turn it into a shell, of 10mm thickness, 2mm res. Dies. however, -1mm thick, 4mm res works.
# -5mm depth and 10mm res dies, as does -1mm thick and 3mm res.
# -0.2457mm depth, 1.0036mm res is running
# -3mm depth, 6mm res worked. Defo doesnt like low res. Saving out while the other runs.


#save it out as 


# crashing, trying 39mm , -31mm, with 6000 faces.  worked.
# 25, -10, with 6000 faces worked.
# 2.5, -10, with 6000 faces. Thinks much harder. worked.
# 2.5, -50, with 6000 faces. Worked. Needs 50mm because the final scale will be about 1 in 10, and a 5mm shell sounds reasonable.
# then it went through a phase of crashing out, had
# to use 50mm (maybe higher), -50mm to get past it.

# And the result had a boundary error on the bow, that I didnt see.
# Really need to make more use of the Show Boundaries option in meshlab.

# With the boandary error, openscad fails. So was forced to use Blender,
# which combined the outside with the insdie, and how a powerful Boolean 
# operator (spanner, on rhs options, select major object first, the from
# pull down pick what is being subtracted).

# However, with boundary error fixed, openscad is fine, albeit slow to do a full F6 rendering. F5 is fine most of the time

boat_combinedall.scad

# and so did the various boolean operations on the shell and the hull in openscad
# was able to subtract a prop shaft, add a prop shaft support, add motor supports, add rudder support and hole,
# and cut out a big access hole, with lip.

# there is a lot of hard coded numerics, so a change in scale would be a tricky task - would be easier
# to scale the prop shaft and rudder shaft, and then scale the whole model.

# The general rendering is done with the outermost union() enabled, and the intersection() commented out.
# When I was happy with it, union() was swapped for intersection(), and the *0, ... , *0 on one line just below
# was changed to *1, ... , *1 , which creates a large cube around the section, leaving only that section for saving out.

# It would be handy to have another script that rotates each part into the correct oriantation, as that is a tad tedious.

# Printing each with Cura, the estimated grams of plastic and print times are:
# echo "144+188+176+133+110+82" | bc -l ; echo "(24+32+26+21+17+12)/24" | bc -l
# 833 grams of plastic
# 5.5 days of print time, end to end.

# This was printing with pairs facing the bed, ie,
# part 1 (bow) faces bed
# part 2, the side facing the bed is what attaches to the bow
# part 3, face that attaches to part 4 faces the bed. Also means its the narrowest on the bed.
# part 4, face that attaches to part 3 faces the bed.
# etc
# Also, the keel is always facing away, with the hollow of the hull facing forwards.
# Supports are always necessary, but part 2 and 6 pretty much require supports.

# its a tight squeeze on a 200x200mm bed, fort mine turned out to be more like 212mm^2, which fits in the widest sections 
# without having to rotate slightly.
# Also found the Cura 2.5 said it was printing at 30mm/s and 40mm/s, but generating gcode stats, it was 20mm/s for most
# most of the print, so the above timing is definately worst case.


# Printed out, there was some distortion. After much considerion, the sections were hot glued.

# Stern (section 6) to section 5. Section 3 to section 4, then section 3+4 to 5+6, with the drive shaft
# tube in place. This did mean temp hot gluing the drive shaft while sections 3+4 were glued together, 
# to ensure the drive shaft was straight and well supported.
# Section 1 was hot glued to section 2, the 1+2 glued to 3-6, which was easily the best fit of all 5 joints.
# A small amount of hot glue was put on the keen, then pressed together. Then hot glue was applied inside a line
# at a time, which give enough to time to hold it in the best overall positoin.
# Also tried hotgluing an entire section to another, but the set time (even though warmed on the bed) was
# too short.

# More hot glue was applied, so the entire meeting surfaces had hot glue, and stringers of hot glue were squirted
# into the corners and keel line. Hot glue was also forced in from the outside, because most sections really
# needed some filling.
# Then painted over outside hull and decking with varnish. Many coats over days, then sanded it down,
# and applied more coats.

# Looking around, the original White Cap used a 6cylinder 150 HP engine. Scaling that down by 
# size (150*750*(170/1800)^3)=95 Watts. Scaling that down by weight, 


