File: collectViewpoints.awk

package info (click to toggle)
whitedune 0.30.10-2.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 42,004 kB
  • sloc: cpp: 116,017; ansic: 79,688; java: 20,101; sh: 3,248; yacc: 2,902; makefile: 1,717; lex: 848; awk: 363; perl: 270; objc: 143; lisp: 112; python: 22
file content (157 lines) | stat: -rw-r--r-- 5,693 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# collectViewpoints.awk

# A simple script to collect the parameters of all Viewpoints
# to a VRML file with a Transform animation of all Viewpoints.

# This script do not support the collections of Viewpoints which
# are moved/rotated/scaled etc. by Transform nodes.

# Important: You need to load and store to a different file with the program 
#            white_dune before use, this script depends on white_dune layout 

# example usage:

# awk -f collectViewpoints.awk inputfile.wrl > outputfile.wrl

# Copyright (C) 2003 J. "MUFTI" Scheurich
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file "COPYING" for details); if 
# not, write to the Free Software Foundation, Inc., 675 Mass Ave, 
# Cambridge, MA 02139, USA.

BEGIN {
      posIndex = 0;
      orientIndex = 0;
      viewPointIndex = 0;
      routeIndex = 0;
      lineIndex = 0;
      }

/Viewpoint/ { 
            viewPointFlag = 1;
            viewPointIndex++;
            }

/}/              { 
                 if (viewPointFlag == 1) 
                    {
                    viewPointFlag = 0;
                    if (orientIndex < viewPointIndex)
                       {
                       orientList[orientIndex,0]=0;
                       orientList[orientIndex,1]=0;
                       orientList[orientIndex,2]=1;
                       orientList[orientIndex,3]=0;
                       orientIndex++;
                       }                    
                    if (posIndex < viewPointIndex)
                       {
                       posList[posIndex,0]=0;
                       posList[posIndex,1]=0;
                       posList[posIndex,2]=-10;
                       posIndex++;
                       }
                    }                                              

                 }

/orientation/    {
                 if (viewPointFlag) 
                    {
                    orientList[orientIndex,0]=$2;
                    orientList[orientIndex,1]=$3;
                    orientList[orientIndex,2]=$4;
                    orientList[orientIndex,3]=-$5;
                    orientIndex++;
                    }                    
                 }

/position/       {
                 if (viewPointFlag) 
                    {
                    posList[posIndex,0]=-$2;
                    posList[posIndex,1]=-$3;
                    posList[posIndex,2]=-$4;
                    posIndex++;
                    }                    
                 }

/^/              { 
                 if ($1 == "ROUTE")
                    route[routeIndex++] = $0; 
                 else
                    line[lineIndex++] = $0; 
                 }

END              {
                 print("#VRML V2.0 utf8");

                 print("Viewpoint");
                 print("  {");
                 print("  position 0 0 0");
                 print("  }");

                 print("DEF POS PositionInterpolator");
                 print("  {");
                 print("  key");
                 print("    [");
                 for (i=0;i<posIndex;i++)
                     print("    " i/(posIndex-1));
                 print("    ]");
                 print("  keyValue");
                 print("    [");
                 for (i=0;i<posIndex;i++)
                     printf("    %f %f %f\n",
                            posList[i,0],posList[i,1],posList[i,2]);
                 print("    ]");
                 print("  }");

                 print("DEF ORIENT OrientationInterpolator");
                 print("  {");
                 print("  key");
                 print("    [");
                 for (i=0;i<orientIndex;i++)
                     print("    " i/(orientIndex-1));
                 print("    ]");
                 print("  keyValue");
                 print("    [");
                 for (i=0;i<orientIndex;i++)
                     printf("    %f %f %f %f\n",
                            orientList[i,0],orientList[i,1],orientList[i,2],
                            orientList[i,3]);
                 print("    ]");
                 print("  }");
                 print("DEF TIME TimeSensor");
                 print("  {");
                 print("  loop TRUE");
                 print("  cycleInterval 10");
                 print("  }");
                 print("DEF TRANSFORM1 Transform");
                 print("  {");
                 print("  children DEF TRANSFORM2 Transform");
                 print("    {");
                 print("    children");
                 print("      [");
                 for (i=0;i<lineIndex;i++)
                    print("      " line[i]);
                 print("      ]");
                 print("    }");
                 print("  }");
                 for (i=0;i<routeIndex;i++)
                    print(route[i]);
                 print("ROUTE TIME.fraction_changed TO ORIENT.set_fraction");
                 print("ROUTE ORIENT.value_changed TO TRANSFORM1.rotation");
                 print("ROUTE TIME.fraction_changed TO POS.set_fraction");
                 print("ROUTE POS.value_changed TO TRANSFORM2.translation");
                 }