0120. Tips for importing 2D curves and texts

Getting started, ptsxpy, Python language, trueSpace, programming, syntax highlighting for text editor, etc.
Note: it's provisional and topics will be added and revised at random till some sort of documentations are prepared.
Post Reply
User avatar
Site Admin
Posts: 45
Joined: 2018-Jul-13 9:35

0120. Tips for importing 2D curves and texts

Post by 3DfromNULL »

Note: This is an example to import a 2D closed curve from Inkscape by hand. There might be other smarter or easier ways.

You might think that the 2D editor in trueSpace (tS) is poor and would like to import curves and/or text drawn using other free vector drawing tools like Inkscape in order to sweep them to polyhedrons and use from ptsxpy + your Python script. Though there are several file formats that Inkscape can export and tS7.6 Model side (or other paid tS versions with Conversion Pack) can import, it seems that they cannot help to import Inkscape's curves directly due to perhaps difference of version compatibilities as far as I check them (.ps, .eps, .dxf). Using blender is one of the ways to solve that.


The steps below explains how to import a 2D curve drawn by Inkspace to tS via Blender and to use as a swept 3D object. We need to extrude (i.e. sweep) once in Blender to avoid an error in tS (mentioned later *1):
  • Open an empty Inkscape document and draw a closed curve without filling inside near the bottom left of the page frame (it's the origin of the xy-axes). You would be able to get better result in case the black (#000000ff) stroke (i.e. line). It's not recommended to fill a color to the curve (mentioned later *2). The width of the line should be ignored as far as I know.
  • Save the whole document as a .svg file (not exporting to .png).
  • Open Blender. Import the .svg file as; "File" - "Import" - "Scalable Vector Graphics (.svg)"
  • Click "Curve" in the scene tree near the top right of Blender. (red, green, and blue arrows appear near the origin)
  • Zoom to the curve using mouse roller so that you can see it. Please note that the curve and three arrows will disappear if you zoom too close. (If needed, Shift roll to up/down the view, Ctrl roll to move the view horizontally, move mouse while pushing its wheel to rotate the view.)
  • Convert the curve into a mesh as; From menu near the bottom left of Blender, "Object" - "Convert to" - "Mesh from Curve/Meta/Surf/Text"
  • Enter to the edit mode as; Click and hold "Object Mode" near the bottom left of Blender, select "Edit Mode".
  • Select all points as; From the horizontal menu near the bottom left of Blender, "Select" - "Select All by Trait" - "Non Manifold".
  • Start extrude-mode (the extrusion corresponds to tS's sweeping) for the mesh as; From the left side menu, click "Extrude Region" twice without moving mouse. (Don't double click but click twice.) If you move mouse mistakenly between 1st click and 2nd, the extruding by mouse starts. In that case, correct both X and Y to 0 in the following step.
  • Set value for extrusion as; Click "Z" in the XYZ input box near the bottom left of Blender, enter 0.01 there, and hit enter key. (correct X and Y to zero if non-zero)
  • Export it to an .obj file as; From the menu near the top left, "File" - "Export" - "Wavefront (.obj)"
  • Import the .obj file to tS; "File" - "Load" - "Object"
The imported object does not have top and bottom face. It would be excusable and we could have corrected easily, but it has another problem; Each normal vector of (inexistent) top and bottom face has been reversed for tS. In other words, the top hole's normal vector has not upward but downward direction, and bottom hole's one has upwards. We need to correct that and add top/bottom faces as below.
  • In tS, click the loaded object to select.
  • Right click it to enter the point edit mode. (Its color will change and hovering mouse will highlight each edge.)
  • In a perspective view, manipulate the View Control (or use "Eye Rotate" and "Eye Move" icons) so that you see bottom hole through top hole.
  • Make sure there is no top face; Mouse hovering over the top highlights vertical edges.
  • Click "Add Face" icon in the tool bar appeared at starting point editing.
  • Hover your mouse near the top again and make sure the bottom hole is highlighted.
  • Click the bottom hole when it was highlighted. (A face is added and its normal vector should (illegally) point upward now)
  • Click "Point Edit: Faces".
  • Hover mouse on the bottom face (through the top hole), and click the highlighted bottom to select.
  • Make sure "Point Move" icon is active, and right drag the ground to move the selected bottom face upward till it become higher position than top hole.
The object's all normal vectors have right direction at this time, and the new bottom (former top) rightly has its normal vector to downward. The only thing we should do is to add a face to the new bottom;
  • Manipulate the View Control (or use "Eye Rotate" and "Eye Move" icons) so that you look up the new bottom hole (former top hole) from the lower position.
  • Click "Add Face" icon and click the bottom hole to add a face to it.
Other tips:
  • You need to repeat the section from selecting "Curve" to extrusion about each curve in case that you would like to import multiple curves (e.g. text) to Blender.
  • In case you import a text from Inkscape, you should convert it to path using "Path" - "Object to Path" before save your Inkscape document to a .svg file. In this way, you can make 3D letters in tS using fonts unsupported by tS's 3D text feature (like Chinese, Japanese, or Korean multibyte characters). Examples of applications using ptsxpy + your script; a 3D text animation, engraving a ring or a hollow sphere with several letters, etc.
  • You can decompose a set of multiple objects using "Decompose into objects" icon in tS if needed.
  • Boolean operations ("subtraction" or "intersection" in this case) with a cube helps to prune unnecessary faces or to decompose, too.
  • There is at least one other way to import Inkscape's 2D curve to tS via free tools though you need to write a short code for the tool; .svg -> OpenSCAD -> .stl -> tS.
*1 Omitting to extrude once in Blender will cause an error "Bad input data" at loading to tS.

*2 In case you filled the shape in Inkscape at the first, the object loaded in tS has a triangulated top and/or bottom face, and you will be forced to take unnecessary efforts to remove many edges (and faces if extruded in Blender) from the object before sweep in your tS. The image below is of no-extrusion in Blender. You cannot sweep adjacent multiple faces in tS and must remove edges inside before sweeping. You will get also unnecessary faces inside of the object if you extrude it in Blender.
Post Reply