FreeWRL / FreeX3D 4.3.0
capabilitiesHandler.c
1/*
2
3 FreeWRL support library.
4 X3D capabilities.
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28
29#include <config.h>
30#include <system.h>
31#include <display.h>
32#include <internal.h>
33
34#include <libFreeWRL.h>
35#include <io_files.h>
36
37#include "../vrml_parser/Structs.h"
38#include "../main/headers.h"
39
40
41/* table showing which levels are supported by which component */
42static const int capabilities[] = {
43 COM_Geometry2D, 2, /* May 12, 2009 */
44 COM_Rendering, 5, /* Sep 22, 2016 */
45 COM_Picking, 0, /* May 12, 2009 */
46 COM_DIS, 0, /* May 12, 2009 */
47 COM_EnvironmentalSensor, 3, /* May 12, 2009 */
48 COM_Text, 1, /* May 12, 2009 */
49 COM_NURBS, 4, /* Dec 2016 */
50 COM_CubeMapTexturing, 3, /* Sep 13, 2016 */
51 COM_EventUtilities, 1, /* May 12, 2009 */
52 COM_Interpolation, 5, /* Dec 2016 */
53 COM_Shaders, 1, /* May 12, 2009 */
54 COM_Navigation, 3, /* July 29 2010 */
55 COM_Grouping, 3, /* October 29, 2008 */
56 COM_Texturing, 3, /* May 12, 2009 */
57 COM_Geospatial, 2, /* May 12, 2009 */
58 COM_CADGeometry, 2, /* July 10 2013 */
59 COM_EnvironmentalEffects, 3, /* May 12, 2009 */
60 COM_Shape, 4, /* May 12, 2009 */
61 COM_Texturing3D, 2, /* Sept 4, 2016 */
62 COM_PointDeviceSensor, 1, /* May 12, 2009 */
63 COM_HAnim, 1, /* Nov 2016 */
64 COM_RigidBodyPhysics, 2, /* Nov 2016 */
65 COM_Core, 2, /* October 29, 2008 */
66 COM_Layout, 2, /* Jan 2016 */
67 COM_Time, 2, /* October 29, 2008 */
68 COM_Geometry3D, 4, /* May 12, 2009 */
69 COM_Followers, 1, /* 2016 */
70 COM_Scripting, 1, /* May 12, 2009 */
71 COM_Lighting, 3, /* May 12, 2009 */
72 COM_KeyDeviceSensor, 2, /* May 12, 2009 */
73 COM_Layering, 1, /* Jan 2016 */
74 COM_Networking, 3, /* May 12, 2009 */
75 COM_ParticleSystems, 3, /* Nov 2016 */
76 COM_Sound, 1, /* May 12, 2009 */
77 COM_VolumeRendering, 4, /* Oct 1, 2016 */
78 COM_ProjectiveTextureMapping, 2, /* Feb 9, 2020 */
79 INT_ID_UNDEFINED, INT_ID_UNDEFINED,
80};
81
82/* profiles... */
83
84/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 H3 Component support */
85static const int CADInterchangeProfile[] = {
86 COM_Core, 1,
87 COM_Networking, 1,
88 COM_Grouping, 1,
89 COM_Rendering, 4,
90 COM_Shape, 2,
91 COM_Lighting, 1,
92 COM_Texturing, 2,
93 COM_Navigation, 2,
94 COM_Shaders, 1,
95 COM_CADGeometry, 2,
96 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
97
98
99/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 A3 Component support */
100static const int CoreProfile[] = {
101 COM_Core, 1,
102 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
103
104
105/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 F3 Component support */
106static const int FullProfile[] = {
107 COM_Core, 2,
108 COM_Time, 2,
109 COM_Networking, 3,
110 COM_Grouping, 3,
111 COM_Rendering, 5,
112 COM_Shape, 4,
113 COM_Geometry3D, 4,
114 COM_Geometry2D, 2,
115 COM_Text, 1,
116 COM_Sound, 1,
117 COM_Lighting, 3,
118 COM_Texturing, 3,
119 COM_Interpolation, 5,
120 COM_Navigation, 3,
121 COM_PointDeviceSensor, 1,
122 COM_KeyDeviceSensor, 2,
123 COM_EnvironmentalSensor, 3,
124 COM_EnvironmentalEffects, 4,
125 COM_Geospatial, 2,
126 COM_HAnim, 1,
127 COM_NURBS, 4,
128 COM_DIS, 2,
129 COM_Scripting, 1,
130 COM_EventUtilities, 1,
131 COM_Shaders, 1,
132 COM_CADGeometry, 2,
133 COM_Texturing3D, 2,
134 COM_CubeMapTexturing, 3,
135 COM_Layering, 1,
136 COM_Layout, 2,
137 COM_RigidBodyPhysics, 2,
138 COM_Picking, 3,
139 COM_Followers, 1,
140 COM_ParticleSystems, 3,
141 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
142
143
144/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 E3 Component support */
145static const int ImmersiveProfile[] = {
146 COM_Core, 2,
147 COM_Time, 1,
148 COM_Networking, 3,
149 COM_Grouping, 2,
150 COM_Rendering, 3,
151 COM_Shape, 2,
152 COM_Geometry3D, 4,
153 COM_Geometry2D, 1,
154 COM_Text, 1,
155 COM_Sound, 1,
156 COM_Lighting, 2,
157 COM_Texturing, 3,
158 COM_Interpolation, 2,
159 COM_PointDeviceSensor, 1,
160 COM_KeyDeviceSensor, 2,
161 COM_EnvironmentalSensor, 2,
162 COM_EnvironmentalEffects, 2,
163 COM_Scripting, 1,
164 COM_EventUtilities, 1,
165 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
166
167
168/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 C3 Component support */
169static const int InteractiveProfile[] = {
170 COM_Core, 1,
171 COM_Time, 1,
172 COM_Networking, 2,
173 COM_Grouping, 2,
174 COM_Rendering, 3,
175 COM_Shape, 1,
176 COM_Geometry3D, 3,
177 COM_Lighting, 2,
178 COM_Texturing, 2,
179 COM_Interpolation, 2,
180 COM_Navigation, 1,
181 COM_PointDeviceSensor, 1,
182 COM_KeyDeviceSensor, 1,
183 COM_EnvironmentalSensor, 1,
184 COM_EnvironmentalEffects, 1,
185 COM_EventUtilities, 1,
186 COM_Layering, 1,
187 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
188
189
190/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 B3 Component support */
191static const int InterchangeProfile[] = {
192 COM_Core, 1,
193 COM_Time, 1,
194 COM_Networking, 1,
195 COM_Grouping, 1,
196 COM_Rendering, 3,
197 COM_Shape, 1,
198 COM_Geometry3D, 2,
199 COM_Lighting, 1,
200 COM_Texturing, 2,
201 COM_Interpolation, 2,
202 COM_Navigation, 1,
203 COM_EnvironmentalEffects, 1,
204 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
205
206
207/* ISO-IEC-FDISINT_ID_UNDEFINED9775:1.2 D3 Component support */
208static const int MPEG4Profile[] = {
209 COM_Core, 1,
210 COM_Time, 1,
211 COM_Networking, 2,
212 COM_Grouping, 2,
213 COM_Rendering, 1,
214 COM_Shape, 1,
215 COM_Geometry3D, 2,
216 COM_Lighting, 2,
217 COM_Texturing, 1,
218 COM_Interpolation, 2,
219 COM_Navigation, 1,
220 COM_PointDeviceSensor, 1,
221 COM_EnvironmentalSensor, 1,
222 COM_Navigation, 1,
223 COM_EnvironmentalEffects, 1,
224 INT_ID_UNDEFINED, INT_ID_UNDEFINED};
225
226
227//dug9 Aug,2013 ecmascript interface V3 says a ProfileInfo has a name, level??, Title, providerUrl, componentInfoArray
228//
229//Q. how do you assign a Level to a Profile?
230//H0: 1 if you have it, else 0
231//H1: minimum of component levels in profile
232//H2: maximum of component levels in profile
233//H3: maximum nesting level - see diagram ie if you have Geospatial,Hanim,Nurbs you are at Full or Level=4
234//http://www.web3d.org/realtime-3d/x3d/profiles
235//I'll just make up and hardcode some values now
236
238 int profileName;
239 const int *profileTable;
240 int level; //dug9
241};
242
243static struct proftablestruct profTable[] = {
244 {PRO_Interchange, InterchangeProfile, 1},
245 {PRO_CADInterchange, CADInterchangeProfile, 1},
246 {PRO_MPEG4, MPEG4Profile, 1},
247 {PRO_Interactive, InteractiveProfile, 1},
248 {PRO_Full, FullProfile, 1},
249 {PRO_Immersive, ImmersiveProfile, 1},
250 {PRO_Core, CoreProfile, 1},
251 {INT_ID_UNDEFINED, (const int*) INT_ID_UNDEFINED, INT_ID_UNDEFINED}
252};
253
254
255void handleVersion(const char *versionString) {
256 int xa=0;
257 int xb=0;
258 int xc=0;
259 int rt;
260
261 UNUSED(rt); // compiler warning mitigation
262
263 /* printf ("handleVersion - x3d version :%s:\n", versionString); */
264 rt = sscanf (versionString,"%d.%d.%d",&xa, &xb,&xc);
265 /* printf ("rt %d xa %d xb %d xc %d\n",rt,xa,xb,xc); */
266
267 /* we could (should?) do some more checking here, but for now... */
268 inputFileVersion[0] = xa, inputFileVersion[1] = xb; inputFileVersion[2] = xc;
269}
270
271
272
273void handleMetaDataStringString(struct Uni_String *val1, struct Uni_String *val2) {
274 #ifdef CAPABILITIESVERBOSE
275 printf ("handleMetaDataStringString, :%s:, :%s:\n",val1->strptr, val2->strptr);
276 #endif
277}
278
279// UNIT category unitname conversionfactor
280// UNIT length micro 0.000001
281// http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/core.html#UNITStatement
282// http://www.web3d.org/documents/specifications/19776-2/V3.3/Part02/grammar.html#General
283// http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/concepts.html#t-Standardunits
284void addUnits(void *ec, char *category, char *unit, double factor);
285void handleUnitDataStringString(void *ec, char *categoryname, char *unitname, double conversionfactor) {
286 addUnits(ec, categoryname,unitname,conversionfactor);
287 //printf ("handleUnitDataStringString, :%s:, :%s: :%lf:\n",categoryname,unitname,conversionfactor);
288}
289
290void handleProfile (int myProfile) {
291 int *myTable = NULL;
292 int i;
293 /* myProfile is a valid profile number - bounds checked before entry */
294 #ifdef CAPABILITIESVERBOSE
295 printf ("handleProfile, my profile is %s (%d)\n",stringProfileType(myProfile), myProfile);
296 #endif
297
298 i=0;
299 while ((profTable[i].profileName != INT_ID_UNDEFINED) && (profTable[i].profileName != myProfile)) i++;
300
301 /* we really should have found this, unless we have a new profile that is not coded properly here */
302 if (profTable[i].profileName == INT_ID_UNDEFINED) {
303 ConsoleMessage ("Something wrong in handleProfile for profile %s\n",
304 stringProfileType(myProfile));
305 } else {
306 int comp;
307 int lev;
308 gglobal()->Mainloop.scene_profile = i;
309 myTable = (int *)profTable[i].profileTable;
310 /* go through the selected table, and see if each component is within range */
311 comp = *myTable; myTable++; lev = *myTable; myTable++;
312 while (comp != INT_ID_UNDEFINED) {
313 handleComponent(comp,lev);
314 comp = *myTable; myTable++; lev = *myTable; myTable++;
315 }
316 }
317}
318//>> exported to jsVRMLBrowser.c
319int capabilitiesHandler_getComponentLevel(int *table, int comp)
320{
321 return table[(comp*2) +1];
322}
323int capabilitiesHandler_getProfileLevel(int prof)
324{
325 return profTable[prof].level;
326}
327const int *capabilitiesHandler_getProfileComponent(int prof)
328{
329 return profTable[prof].profileTable;
330}
331const int *capabilitiesHandler_getCapabilitiesTable()
332{
333 return capabilities;
334}
335int capabilitiesHandler_getTableLength(int* table){
336 int len = 0;
337 if(table == NULL) return 0;
338 while(table[2*len] != INT_ID_UNDEFINED)
339 len++;
340 return len;
341}
342//>>exported to jsVRMLBrowser_duk.c
343struct proftablestruct *getProfTable(){
344 return profTable;
345}
346const int * getCapabilitiesTable(){
347 return capabilities;
348}
349
350void scene_addComponent(int myComponent, int mylevel){
351 //besides the static tables for freewrl, we need a table for scene (desired) components
352 //generated during parsing
353 //we need an init to clear this
354 //and we need a Scene or ProtoInstance (ie broto) struct to store this in
355 int *scene_comps = gglobal()->Mainloop.scene_components;
356 int len = capabilitiesHandler_getTableLength(scene_comps);
357 scene_comps = realloc(scene_comps,sizeof(int)*2*(len+2));
358 scene_comps[len*2] = myComponent;
359 scene_comps[len*2 +1] = mylevel;
360 len++;
361 scene_comps[len*2] = INT_ID_UNDEFINED;
362 scene_comps[len*2 +1] = INT_ID_UNDEFINED;
363 gglobal()->Mainloop.scene_components = scene_comps;
364}
365void scene_clearComponents(){
366 FREE_IF_NZ(gglobal()->Mainloop.scene_components);
367}
368
369//<<
370
371void handleComponent (int myComponent, int myLevel) {
372 int i;
373
374 /* myComponent is a valid component number - bounds checked before entry */
375 #ifdef CAPABILITIESVERBOSE
376 printf ("handleComponent: my Component is %s, level %d\n",COMPONENTS[myComponent], myLevel);
377 #endif
378
379 i=0;
380 while ((capabilities[i] != myComponent) && (capabilities[i] != INT_ID_UNDEFINED)) {
381 i+=2;
382 }
383
384 /* did we find the component? */
385 if (capabilities[i] == myComponent) {
386 scene_addComponent(myComponent,myLevel);
387
388 #ifdef CAPABILITIESVERBOSE
389 printf ("handleComponent, comparing requested level %d with supported level %d\n",myLevel, capabilities[i+1]);
390 #endif
391
392 if (myLevel > capabilities[i+1]) {
393 ConsoleMessage ("Component %s support level %d, requested %d",
394 COMPONENTS[myComponent], capabilities[i+1], myLevel);
395 }
396 } else {
397 ConsoleMessage ("did not find component %s in capabilities table!",COMPONENTS[myComponent]);
398 }
399}