Make a 3D from a contour

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Romeo4755
Posts: 13
Joined: Sat Jun 03, 2023 9:38 pm

Re: Make a 3D from a contour

Post by Romeo4755 »

GeneFC wrote: Sun Jun 04, 2023 4:53 pm Very rough
Just do not expect it to become smooth in the manner that Jeno showed.
Yes, exactly. Rough is good.
I am sorry to be such a bother but... is there a way to import a ready outline into freeCad and make it part of the sketch?
jeno
Veteran
Posts: 1820
Joined: Sun Jun 29, 2014 10:41 am

Re: Make a 3D from a contour

Post by jeno »

Romeo4755 wrote: Sun Jun 04, 2023 4:59 pm ...
Yes, exactly. Rough is good.
I am sorry to be such a bother but... is there a way to import a ready outline into freeCad and make it part of the sketch?
Your'e after something like that?
dagger-axe-rough.png
dagger-axe-rough.png (13.18 KiB) Viewed 949 times
Attached the svg-path by hand roughly made from the picture.
Fire up Freecad. New file - Import -> dagger-axe.svg as geometry (and yes 96dpi). Extrude the path. Go further as you like.

cheers
Attachments
dagger-axe.svg
(1.72 KiB) Downloaded 11 times
mconsidine
Posts: 125
Joined: Wed Jan 18, 2023 10:41 pm
Location: Randolph, VT USA

Re: Make a 3D from a contour

Post by mconsidine »

There may be room for a bit of automation. Inkscape uses potrace and autotrace (I think) and the former has been ported to Python. So ... slooooow.
But, as a proof of concept:

Code: Select all

import numpy as np
#after pip install potracer
import potrace
from PIL import Image

#via https://github.com/FreeCAD/FreeCAD-documentation/blob/main/wiki/Topological_data_scripting.md
def makeBCurveEdge(Points):
   geomCurve = Part.BezierCurve()
   geomCurve.setPoles(Points)
   edge = Part.Edge(geomCurve)
   return(edge)

#inspired by https://github.com/tatarize/potrace-cli/blob/main/cli/backend_svg.py
# and https://github.com/tatarize/potrace/issues/5
#SVG attributes: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d

img=Image.open("/home/matt/Downloads/DXFtests/fm7es4338mye.jpeg")
img = img.convert("1", dither=Image.NONE)

data=np.asarray(img)
bitmap=potrace.Bitmap(data)
path=bitmap.trace()

segments = []
for p in path:
  current_pt = p.start_point
  for aseg in p.segments:
    if aseg.is_corner:
      a = aseg.c
      #segments.append(App.Vector(a.x, a.y, 0.0))
      b = aseg.end_point
      #segments.append(App.Vector(b.x, b.y, 0.0))
      if current_pt != a:
        segments.append(Part.makeLine(App.Vector(current_pt.x, current_pt.y, 0.0),App.Vector(a.x, a.y, 0.0)))        
      segments.append(Part.makeLine(App.Vector(a.x, a.y, 0.0),App.Vector(b.x, b.y, 0.0)))
      current_pt = b
    else:
      a = aseg.c1
      b = aseg.c2
      c = aseg.end_point
      pt1 = App.Vector(a.x, a.y, 0.0)
      pt2 = App.Vector(b.x, b.y, 0.0)
      pt3 = App.Vector(c.x, c.y, 0.0)
      if current_pt != a:
        segments.append(Part.makeLine(App.Vector(current_pt.x, current_pt.y, 0.0),App.Vector(a.x, a.y, 0.0)))      
      potrace_edge = makeBCurveEdge((pt1,pt2,pt3))
      segments.append(potrace_edge)
      current_pt = c
  if current_pt != p.start_point :
    segments.append(Part.makeLine(App.Vector(current_pt.x, current_pt.y, 0.0),App.Vector(p.start_point.x, p.start_point.y, 0.0)))

for s in segments:
  Part.show(s)
In an early effort with a more simple input file I wasn't able to automatically tease out the closed pieces as faces, for reasons I haven't had time to figure out.

HTH,
mconsidine

EDIT: @jeno idea is a whole lot easier ...
Attachments
Screenshot from 2023-06-04 15-32-05.png
Screenshot from 2023-06-04 15-32-05.png (65.02 KiB) Viewed 905 times
Romeo4755
Posts: 13
Joined: Sat Jun 03, 2023 9:38 pm

Re: Make a 3D from a contour

Post by Romeo4755 »

jeno wrote: Sun Jun 04, 2023 5:35 pm Your'e after something like that?dagger-axe-rough.png
Attached the svg-path by hand roughly made from the picture.
Fire up Freecad. New file - Import -> dagger-axe.svg as geometry (and yes 96dpi). Extrude the path. Go further as you like.
!!!New file - Import -> dagger-axe.svg as geometry (and yes 96dpi). !!! Wow! That's a godsend!
However, had I known earlier you would spend this effort, I would have:
1) not traced the sketch already (today) in freeCAD. :D
2) warned you that the image in the original post is just an example. What I want to make is a bit other in shape artifact from Beijing National Museum.
All the same I will learn the trick with svg and hope to be able create other models from images. I will also use your ge in another project (or maybe I will fail with my own model, it is quite crooked. )) )
Thank you so much.
User avatar
papyblaise
Veteran
Posts: 7864
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Make a 3D from a contour

Post by papyblaise »

make a guard and sharpen it, and this weapon "Can kill"
Attachments
épée en bois.JPG
épée en bois.JPG (17.81 KiB) Viewed 781 times
épée en bois.FCStd
(112.17 KiB) Downloaded 7 times
Romeo4755
Posts: 13
Joined: Sat Jun 03, 2023 9:38 pm

Re: Make a 3D from a contour

Post by Romeo4755 »

I am sorry for going out of the topic, but I don't want to start a new thread, not to mention that the people here motivated me to sit and use FreeCAD for two days in a row. :D
Is there a way to export my obj out of CAD so that it consisted of 2 parts. I tried fusions and compounds, the blade and the handle each consist of many parts fused together but I can only get an OBJ that is recognized by other programs as one solid piece.
Image
Last edited by Romeo4755 on Mon Jun 05, 2023 8:56 pm, edited 1 time in total.
Romeo4755
Posts: 13
Joined: Sat Jun 03, 2023 9:38 pm

Re: Make a 3D from a contour

Post by Romeo4755 »

papyblaise wrote: Mon Jun 05, 2023 11:53 am make a guard and sharpen it, and this weapon "Can kill"
I should just have asked people for a ready model!
Thank you!
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Make a 3D from a contour

Post by GeneFC »

Romeo4755 wrote: Mon Jun 05, 2023 8:41 pm Is there a way to export my obj out of CAD so that it consisted of 2 parts.
The crude but straightforward method is to make a copy of the FCStd file (outside of FreeCAD!)

This assumes that the two parts are actually separate. If they are intermingled this will not work.

Load one file and delete everything related to the handle. Save, export, etc.

Load the other file and delete everything related to the blade. Save, export, etc.

Make sure you keep a copy of the entire model file if you want a complete file. The steps above will no longer give complete models.

Gene
Romeo4755
Posts: 13
Joined: Sat Jun 03, 2023 9:38 pm

Re: Make a 3D from a contour

Post by Romeo4755 »

GeneFC wrote: Mon Jun 05, 2023 9:04 pm Load one file and delete everything related to the handle. Save, export, etc.
Thank you.
So I guess there no other way besides exporting parts and assembling the thing in another program (previously having created UV points and texture map form in one more application). And then exporting the whole thing with parts and textures.
OK, after main work is done this seems like no big deal.
Thank you guys for teaching me freeCAD. It is a great application.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Make a 3D from a contour

Post by GeneFC »

Romeo4755 wrote: Mon Jun 05, 2023 9:16 pm So I guess there no other way
Since you did not include a file it is impossible to say much about other methods. :mrgreen:

Gene
Post Reply