Blender (jusqu'à 2.49)
Python : 
Importing Paths in Bezier's curves
from several  basic formats 
Version Française
    Main   Index
previous: Script in the menus 
 The "import_paths" script  Next:

In vectorial drawing softwares like : Adobe Illustrator,  Inkscape, Sodipody, Coreldraw, Sketch, we can save our work in a standardized formats. The most popular and known are those used by illustrators  : AI et EPS.
But there is also a more elaborated and concerted standardization project for the WEB,  the SVG format.
At last, there are more unknown and unusual vectorial formats, like the paths export format used by GIMP.

Those formats are not yet read and interpreted by Blender wich is mainly used for 3D modelling. However, Blender is offering tools to deal with beziers curves and a python module to modify them, alas, the python module is not yet enough developped to create them directly and adding points or vertices (the command does exists, but only for NURBS curves). 
Those options could be available in a few month. One can imagine that there is no solution to the problem, and that's true : we are not afford to create such curves within Blender but we can do it outside to circumvent the problem. To do so, we are using a very recent command of the API (this command is not yet implemented in the official version but will be available in the 2.34 version):
 

Blender.Load(file_name)  ...

This command is the key wich will allow to open and read a few type of file formats, the .BLEND  files themselves of course. But also the .DXF,.VRML...VIDEOSCAPE files.  

The VIDEOSCAPE format is the NEOGEO one,  the firm where the first versions of the software was developped . It is established that ( this is mentioned in the Blender official documentation, at least the one from 1999 the period the software was a shareware) this format can contain information on curves POLYLINE, NURBS,  and BEZIER. Still better, when you load it, these type of curves are automatically created, and even in the very last versions of Blender. Thus, to import AI, EPS, GIMPpath ou SVG files, you have  to translate them into VIDEOSCAPE format first.

Example of a VIDEOSCAPE file :
 

3DG3 


0 0 
1.0 0.0 0.0 0.0 
0.0 1.0 0.0 0.0 
0.0 0.0 1.0 0.0 
0.0 0.0 0.0 1.0 

4 0 
32 0 
0 0 
1 0 
1.501234 0.0 1.595448 
1.228398 0.0 1.595448 
0.955562 0.0 1.595448 
2 2 
0.734104 0.0 1.394819 
0.734104 0.0 1.147645 
0.734104 0.0 0.900472 
2 2 
0.955562 0.0 0.699843 
1.228398 0.0 0.699843 
1.501234 0.0 0.699843 
2 2 
1.722692 0.0 0.900472 
1.722692 0.0 1.147645 
1.722692 0.0 1.394819 
2 2

As we see, this is a very bald format, and if we can easily guess that the 4x4 series of figures are square matrix and that the other 3X3 series represent vertices locations with their control handles, other lines are rather abstruse.

Here is the key :
 

line 1  : 3DG3             -Magic figure
line 2  : type                -Object type (5 for surfaces, any other values for bezier curves)
line 3  :items_number -The number of curves or surfaces
line 4  : ext1 ext2           -The value to extrude numbers, given for surfaces too.
                                                Carefull, these figures are not decimal but integers divided by
                                                500.
line 5  : Matrix [4][4]          - Right hand Matrix. Used to determine location, rotation and
                                                size
For each item :
line 6    :type           - type (0 - poly, 1 - bezier, 4 - nurbs. Add 8 to this if it's a 2D curve)
line 7    :pntsu pntsv      - number of vertices in u and v directions. 
line 8    :resolu resolv    - fineness /resolution in u and v directions.
line 9:   :orderu orderv   - order in u et v directions.
line 10  :lagu flagv          - The 'cyclic' flag in u and v directions. Cyclic if equal to 1.

For bezier we need to repeat the following bloc "pntsu" time:
line 11  :x y z
line 12  :x y z
line 13  :x y z            - 3 control handles.
line 14  :h1 h2          - Handles type  (0 - free, 1 - automatic, 2 - vector, 3 - aligned)
....

To use these data into scripts,  I established 3 classes :

  • Bez
  • ITEM
  • COURBE
In the following way :
#=============================== 
# Blender Curve Data 
#=============================== 
objBEZIER=0 
objSURFACE=5 
typBEZIER3D=1  #3D 
typBEZIER2D=9  #2D 

class Bez: 
      def __init__(self): 
           self.co=[] 
           self.ha=[0,0] 

class ITEM: 
      def __init__(self): 
               self.type        =  typBEZIER3D, 
               self.pntsUV      =  [0,0] 
               self.resolUV     =  [32,0] 
               self.orderUV     =  [0,0] 
               self.flagUV      =  [0,0] 
               self.Origine     =  [0.0,0.0] 
               self.beziers_knot = [] 

class COURBE: 
      def __init__(self): 
              self.magic_number='3DG3' 
              self.type            =  objBEZIER 
              self.number_of_items =  0 
              self.ext1_ext2       =  [0,0] 
              self.matrix          =  """0.0 0.0 1.0 0.0 
0.0 1.0 0.0 0.0 
0.0 0.0 1.0 0.0 
0.0 0.0 0.0 1.0 """ 
              self.ITEM            = {}

Point out

1/ The matrix must be modified to give a correct display otherwise the shape is seriously leaning as if we had  applied a warping matrix (tilting matrix ). Thus :
 

0.0 0.0 1.0 0.0 
0.0 1.0 0.0 0.0 
0.0 0.0 1.0 0.0 
0.0 0.0 0.0 1.0

instead of :
 

1.0 0.0 0.0 0.0 
0.0 1.0 0.0 0.0 
0.0 0.0 1.0 0.0 
0.0 0.0 0.0 1.0

2/ The order of coordinates submission must be oriented on the XZ plane otherwise the shape is completely flattened out.

3/ To have the Blender.Load() function available you need the 2.34 Blender version at least or upper (the 2.33 versions compiled from the CVS of  the 20th july 2004 work too). But it is still possible to recover the intermediary file in wich the curves data before importation are stored. This file is in the same directory as the original file, and has the same name without extension with addition of  "OOO.obj". There is not any risk to mash the original file up.
- the disappearing of this ability is possible in the next versions of the importation curves module  to be replaced by a sole temporary file wich will be located in the "bpydata" directory.

4/ When the object file is loaded, the name of the current blender file is modified. If you are not carefull, you may save your work with a bit complicated extension name. The coders of the python's API have solved the problem and this bugg should disappear in Blender 2.34,  official version.

5/ The menus : as the number of scripts is increasing, the entries Paths of the Import menu

have been gathered in a sub-menu :


previous Scripts in the menus 
 The "import_paths" script  Next:
To the   Top of the page

Questions concerning this page can be asked on  : :
 news://news.zoo-logique.org/3D.Blender


 

 

a

Les questions concernant cette page  peuvent être posées sur  :
news://news.zoo-logique.org/3D.Blender

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube