scripting.docu 5.03 KB
Newer Older
1
/*!
Jan Möbius's avatar
Jan Möbius committed
2
\page scripting OpenFlipper Scripting and Batch Mode
3

Jan Möbius's avatar
Jan Möbius committed
4
5
6
7
8
9
10
11
  \section scripting_batch_mode OpenFlipper Batch mode
    OpenFlipper can be started in batch mode without a graphical user interface by providing "-b" 
    as a command line option. Furthermore you have to provide an OpenFlipper script (extension is .ofs),
    which will get executed. To get output to the command line, you also have to provide the command 
    line switch "-c". Only plugins which support batch mode ( They implement an nogui() function ), will
    be loaded. For example, no renderers, postprocessors or other plugins providing only user interface
    or graphical functionality will be loaded. You can see on the command line (when "-c" is given),
    which plugins are activated and which are skipped in batch mode.
12

13
  \section scripting_iterating Iterating over objects
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    In the scripting system you can also iterate over objects in the scene.

    \code
      // Get a list of all target triangle meshes in the scene
      var list = datacontrol.getTargetObjects(DataType("TriangleMesh"));

      // Print the names of all target objects
      for( object in list )
      {
        print(datacontrol.getObjectName(list[object]))
      }
    \endcode


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  \section scripting_datattypes DataTypes
    In the scripting system the type DataType is already known. You can do for example
    \code
      DataType("TriangleMesh");
    \endcode
    You can get a string list with all available data types via
    \code
      // Get the string list of data types via DataControl Plugin
      var types = datacontrol.availableDataTypeNames();
    \endcode

    \subsection scripting_datattypes_getting_type Getting the DataType of an Object
      \code
      // Set the object id
      var object = 5;

Matthias Möller's avatar
Matthias Möller committed
44
      // Get the DataTypes and print its name. the DataType is returned by the function
45
46
47
      print(datacontrol.dataType(object))
      \endcode

Matthias Möller's avatar
Matthias Möller committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    \subsection scripting_datattypes_getting_id Getting the Id of an Object
      Openflipper provides functions gathering the id of an object.
      Also, some functions create an object and return its id.
      Some examples:
      \code
      //gathering id of an object
      core.loadObject(QString) //generate an object and returns its Id
      core.getObjectId(QString) // returns Id by object name
      datacontrol.getObjectName(int) // returns object name by Id
      datacontrol.getTargetObjects(DataType) // returns IdList of all target objects
      primitivesgenerator.addPyramid() //generate an object and returns its Id
      ...
      \endcode
      

63
  \section scripting_vectortype Vector data type
64
65
66
     The Vec3d used in the C++ code is mapped to the scripting language. Details
     can be found here:
       \subpage scripting_vector_type
67

Jan Möbius's avatar
Jan Möbius committed
68
  \section scripting_vector4dtype Vector4 data type
Jan Möbius's avatar
Jan Möbius committed
69
70
71
72
     The Vector4d data type is corresponding to the Vec4d type in C++. It is mostly used for colors. Details
     can be found here:
       \subpage scripting_vector_type_4d

73
74
75
76
  \section scripting_matrixtype Matrix data type
     The Matrix4x4T type used in the C++ code is mapped to the scripting language. Details
     can be found here:
       \subpage scripting_matrix_type
Matthias Möller's avatar
Matthias Möller committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

  \section idlisttype IdList type
    Some functions can perform the same operation on several objects or give multiple objects back.
    The Id's of these objects are saved in a IdList. This is a simple list of integer containing the id's.
    Example code:
    \code
      //Assume, "Object 1" and "Object 2" are already created or loaded
      var id1 = core.getObjectId("Object 1")
      var id2 = core.getObjectId("Object 2")
      var list = [id1,id2]
      datacontrol.groupObjects(list)
    \endcode

  \section qVariantMaptype QVariantMap type
    The QVariantMap type is used by some function as input.
    A QVariantMap is similar to a map with key and value, where the types of the key and value is not defined.
    Mostly, the keys are \a strings describing the property where the value type is of type \a int.
    Example code:
    \code
      // creating a scripting object
      var constraints = new Object()
      // filling the QVariantMap
      constraints["decimater_type"] = 0 
      constraints["decimation_order"] = 0
      constraints["vertices"] = 50
      // load e.g. mesh object
      var id = core.loadObject("MyTriangleMesh.obj")
      // perform decimation
      decimater.decimate(id,constraints)
    \endcode
Jan Möbius's avatar
Jan Möbius committed
107
108
109
110
111
112
113
114
 
  \section scripting_misc Miscellaneuos
     \subsection scripting_misc_path How to get the path of the current script?
       \code
         // The path of the currently executed script is stored in the ScriptPath variable.
         print(ScriptPath)
       \endcode
  
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  \section scripting_examples Scripting Examples
    \subsection scripting_examples_qstringlist Iterating over a QStringList

      \code
      // Get the string list of data types via DataControl Plugin
      var types = datacontrol.availableDataTypeNames();

      // Iterate over the list and print to the console
      for ( i = 0 ; i < types.length ; ++i ) {
        print(types[i]);
      }
      \endcode



 */