33 #if defined(JAVASCRIPT_DUK)
37 #include <libFreeWRL.h>
40 #include "../vrml_parser/Structs.h"
41 #include "../vrml_parser/CRoutes.h"
42 #include "../opengl/OpenGL_Utils.h"
43 #include "../main/headers.h"
44 #include "../scenegraph/RenderFuncs.h"
45 #include "../vrml_parser/CParseGeneral.h"
46 #include "../scenegraph/Vector.h"
47 #include "../vrml_parser/CFieldDecls.h"
48 #include "../vrml_parser/CParseParser.h"
49 #include "../vrml_parser/CParseLexer.h"
50 #include "../vrml_parser/CParse.h"
51 #include "../main/Snapshot.h"
52 #include "../scenegraph/Collision.h"
53 #include "../scenegraph/quaternion.h"
54 #include "../scenegraph/Viewer.h"
55 #include "../x3d_parser/Bindable.h"
56 #include "../input/EAIHeaders.h"
65 #define malloc(A) MALLOCV(A)
66 #define free(A) FREE_IF_NZ(A)
67 #define realloc(A,B) REALLOC(A,B)
227 struct string_int lookup_X3DConstants[] = {
228 {
"INITIALIZED_EVENT",1},
229 {
"SHUTDOWN_EVENT",1},
230 {
"CONNECTION_ERROR",1},
231 {
"INITIALIZED_ERROR",1},
232 {
"NOT_STARTED_STATE",1},
233 {
"IN_PROGRESS_STATE",1},
234 {
"COMPLETE_STATE",1},
236 {
"SFBool",FIELDTYPE_SFBool},
237 {
"MFBool",FIELDTYPE_MFBool},
238 {
"MFInt32",FIELDTYPE_MFInt32},
239 {
"SFInt32",FIELDTYPE_SFInt32},
240 {
"SFFloat",FIELDTYPE_SFFloat},
241 {
"MFFloat",FIELDTYPE_MFFloat},
242 {
"SFDouble",FIELDTYPE_SFDouble},
243 {
"MFDouble",FIELDTYPE_MFDouble},
244 {
"SFTime",FIELDTYPE_SFTime},
245 {
"MFTime",FIELDTYPE_MFTime},
246 {
"SFNode",FIELDTYPE_SFNode},
247 {
"MFNode",FIELDTYPE_MFNode},
248 {
"SFVec2f",FIELDTYPE_SFVec2f},
249 {
"MFVec2f",FIELDTYPE_MFVec2f},
250 {
"SFVec3f",FIELDTYPE_SFVec3f},
251 {
"MFVec3f",FIELDTYPE_MFVec3f},
252 {
"SFVec3d",FIELDTYPE_SFVec3d},
253 {
"MFVec3d",FIELDTYPE_MFVec3d},
254 {
"SFRotation",FIELDTYPE_SFRotation},
255 {
"MFRotation",FIELDTYPE_MFRotation},
256 {
"SFColor",FIELDTYPE_SFColor},
257 {
"MFColor",FIELDTYPE_MFColor},
258 {
"SFImage",FIELDTYPE_SFImage},
260 {
"SFColorRGBA",FIELDTYPE_SFColorRGBA},
261 {
"MFColorRGBA",FIELDTYPE_MFColorRGBA},
262 {
"SFString",FIELDTYPE_SFString},
263 {
"MFString",FIELDTYPE_MFString},
307 {
"inputOnly",PKW_inputOnly},
308 {
"outputOnly",PKW_outputOnly},
309 {
"inputOutput",PKW_inputOutput},
310 {
"initializeOnly",PKW_initializeOnly},
314 struct string_int *lookup_string_int(
struct string_int *table,
char *searchkey,
int *index){
318 if(!table)
return NULL;
321 if(!strcmp(table[i].c,searchkey)){
331 int X3DConstantsGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
333 fwretval->_integer = lookup_X3DConstants[index].i;
334 fwretval->itype =
'I';
339 int len = (
sizeof(lookup_X3DConstants) /
sizeof(
struct string_int)) -1;
342 int X3DConstantsIterator(
int index,
FWTYPE *fwt,
FWPointer *pointer,
char **name,
int *lastProp,
int *jndex,
char *type,
char *readOnly){
345 if(index < len_constants()){
346 (*name) = lookup_X3DConstants[index].c;
355 FWTYPE X3DConstantsType = {
356 AUXTYPE_X3DConstants,
363 X3DConstantsIterator,
373 int VrmlBrowserGetName(
FWType fwtype,
void *ec,
void * fwn,
int argc,
FWval fwpars,
FWval fwretval)
375 fwretval->_string = BrowserName;
376 fwretval->itype =
'S';
379 int VrmlBrowserGetVersion(
FWType fwtype,
void *ec,
void * fwn,
int argc,
FWval fwpars,
FWval fwretval)
381 fwretval->_string = libFreeWRL_get_version();
382 fwretval->itype =
'S';
385 int VrmlBrowserGetCurrentSpeed(
FWType fwtype,
void *ec,
void * fwn,
int argc,
FWval fwpars,
FWval fwretval)
388 sprintf (
string,
"%f",gglobal()->Mainloop.BrowserSpeed);
389 fwretval->_string = strdup(
string);
390 fwretval->itype =
'S';
394 int VrmlBrowserGetCurrentFrameRate(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
397 sprintf (
string,
"%6.2f",gglobal()->Mainloop.BrowserFPS);
398 fwretval->_string = strdup(
string);
399 fwretval->itype =
'S';
402 int VrmlBrowserGetWorldURL(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
404 fwretval->_string = BrowserFullPath;
405 fwretval->itype =
'S';
408 const char *flexiString(
FWval fwpars,
char *buffer)
421 if(fwpars[0].itype ==
'W'){
422 switch(fwpars[0]._web3dval.fieldType){
423 case FIELDTYPE_SFString:
427 _costr = sfs->strptr;
430 case FIELDTYPE_MFString:
434 int i, l1, l2, l3, lt;
441 for(i=0;i<mfs->n;i++){
442 l3 = strlen(mfs->p[i]->strptr);
443 if(lt + l1 + l2 + l3 > lenbuf)
break;
444 strcat(buffer,
"[\"");
445 strcat(buffer,mfs->p[i]->strptr);
446 strcat(buffer,
"\"] ");
451 _costr = mfs->p[0]->strptr;
460 int VrmlBrowserReplaceWorld(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
465 _costr = strdup(flexiString(&fwpars[0],NULL));
472 void conCat (
char *out,
char *in) {
474 while (strlen (in) > 0) {
475 strcat (out,
" :loadURLStringBreak:");
476 while (*out !=
'\0') out++;
478 if (*in ==
'[') in++;
479 while ((*in !=
'\0') && (*in ==
' ')) in++;
483 while (*in !=
'"') { *out = *in; out++; in++; }
489 if (*in ==
'"') in++;
490 if (*in ==
',') in++;
491 if (*in ==
']') in++;
495 void createLoadUrlString(
char *out,
int outLen,
char *url,
char *param) {
515 commacount1 = 0; commacount2 = 0;
516 tptr = url;
while (*tptr !=
'\0') {
if (*tptr ==
'"') commacount1 ++; tptr++; }
517 tptr = param;
while (*tptr !=
'\0') {
if (*tptr ==
'"') commacount2 ++; tptr++; }
518 commacount1 = commacount1 / 2;
519 commacount2 = commacount2 / 2;
523 (commacount1 * strlen (
" :loadURLStringBreak:")) +
524 (commacount2 * strlen (
" :loadURLStringBreak:"))) > (outLen - 20)) {
525 printf (
"createLoadUrlString, string too long\n");
529 sprintf (out,
"%d %d",commacount1,commacount2);
532 while (*out !=
'\0') out++;
536 while (*out !=
'\0') out++;
539 struct X3D_Anchor* get_EAIEventsIn_AnchorNode();
540 int VrmlBrowserLoadURL(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
542 char *url, *parameter;
543 char bufferUrl[1000];
544 char bufferParam[1000];
547 url = strdup(flexiString(&fwpars[0],bufferUrl));
548 parameter = strdup(flexiString(&fwpars[1],bufferParam));
552 createLoadUrlString(myBuf,1000,url, parameter);
553 createLoadURL(myBuf);
556 setAnchorsAnchor( get_EAIEventsIn_AnchorNode());
558 gglobal()->RenderFuncs.BrowserAction = TRUE;
561 int VrmlBrowserSetDescription(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
564 if(fwpars[0].itype ==
'S')
565 gglobal()->Mainloop.BrowserDescription = fwpars[0]._string;
568 int VrmlBrowserCreateX3DFromString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
582 const char *_c = fwpars[0]._string;
585 retGroup = createNewX3DNode0(NODE_Group);
586 gglobal()->ProdCon.savedParser = (
void *)globalParser; globalParser = NULL;
587 ra = EAI_CreateX3d(
"String",_c,ec,retGroup);
588 globalParser = (
struct VRMLParser*)gglobal()->ProdCon.savedParser;
589 if(retGroup->children.n > 0) {
591 memcpy(mfn,&retGroup->children,
sizeof(
struct Multi_Node));
592 FREE_IF_NZ(retGroup);
593 for(i=0;i<mfn->n;i++){
594 mfn->p[i]->_parentVector->n = 0;
596 fwretval->_web3dval.native = mfn;
597 fwretval->_web3dval.fieldType = FIELDTYPE_MFNode;
598 fwretval->_web3dval.gc = 1;
599 fwretval->itype =
'W';
602 FREE_IF_NZ(retGroup);
608 int VrmlBrowserCreateVrmlFromString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
621 const char *_c = fwpars[0]._string;
624 retGroup = createNewX3DNode0(NODE_Group);
625 gglobal()->ProdCon.savedParser = (
void *)globalParser; globalParser = NULL;
626 ra = EAI_CreateVrml(
"String",_c,ec,retGroup);
627 globalParser = (
struct VRMLParser*)gglobal()->ProdCon.savedParser;
628 if(retGroup->children.n > 0) {
630 memcpy(mfn,&retGroup->children,
sizeof(
struct Multi_Node));
631 for(i=0;i<mfn->n;i++){
632 mfn->p[i]->_parentVector->n = 0;
634 fwretval->_web3dval.native = mfn;
635 fwretval->_web3dval.fieldType = FIELDTYPE_MFNode;
636 fwretval->_web3dval.gc = 1;
637 fwretval->itype =
'W';
640 deleteVector(
struct X3D_Node*,retGroup->_parentVector);
641 FREE_IF_NZ(retGroup);
646 void *createNewX3DNode(
int nt);
647 void add_node_to_broto_context(
struct X3D_Proto *currentContext,
struct X3D_Node *node);
648 int VrmlBrowserCreateNodeFromString(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
650 int i, iret, isVRML,isX3D;
652 const char *_c = fwpars[0]._string;
658 for(i=0;i<strlen(_c);i++){
659 if(_c[i] ==
'<') isX3D = TRUE;
660 if(_c[i] ==
'{') isVRML = TRUE;
662 if(!isX3D && !isVRML){
666 ctype = findFieldInNODES(_c);
668 node = (
struct X3D_Node*)createNewX3DNode(ctype);
669 add_node_to_broto_context(ec,node);
676 iret = VrmlBrowserCreateVrmlFromString(fwtype,ec,fwn,argc,fwpars,fwretval);
678 iret = VrmlBrowserCreateX3DFromString(fwtype,ec,fwn,argc,fwpars,fwretval);
680 node = fwretval->_web3dval.anyvrml->mfnode.p[0];
681 node->_executionContext = ec;
685 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
686 fwretval->_web3dval.anyvrml->sfnode = node;
687 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
688 fwretval->_web3dval.gc = 0;
689 fwretval->itype =
'W';
695 int VrmlBrowserCreateVrmlFromURL(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
699 int i, iret, type,kind,ifield,ifound;
709 if(fwpars[0].itype ==
'W')
710 url = &fwpars[0]._web3dval.anyvrml->mfstring;
712 if(fwpars[1].itype ==
'W')
713 if(fwpars[1]._web3dval.fieldType == FIELDTYPE_SFNode)
714 target_node = fwpars[1]._web3dval.anyvrml->sfnode;
715 if(fwpars[2].itype ==
'S')
716 cfield = fwpars[2]._string;
718 if(!url || !target_node || !cfield){
719 ConsoleMessage(
"createX3DFromURL parameters: (MFString url, SFNode target_node, string target_field\n");
724 ifound = getFieldFromNodeAndName(target_node,cfield,&type,&kind,&ifield,&value);
726 ConsoleMessage(
"createX3DFromURL no field named %s on nodetype %s\n",cfield,stringNodeType(target_node->_nodeType));
733 res = resource_create_multi(url);
735 res->whereToPlaceData = target_node;
736 res->offsetFromWhereToPlaceData = (int) ((
size_t)value - (size_t) target_node);
739 send_resource_to_parser_async(res);
745 void jsRegisterRoute(
748 int len,
const char *adrem) {
751 if (strcmp(
"addRoute",adrem) == 0)
755 CRoutes_Register(ad, from, fromOfs, to, toOfs , len,
756 returnInterpolatorPointer(to->_nodeType), 0, 0);
759 void *addDeleteRoute0(
void *fwn,
char*callingFunc,
struct X3D_Node* fromNode,
char *sfromField,
struct X3D_Node* toNode,
char *stoField){
761 int fromType,toType,fromKind,toKind,fromField,toField;
762 int i, len, fromOfs, toOfs;
763 union anyVrml *fromValue, *toValue;
765 getFieldFromNodeAndName(fromNode,sfromField,&fromType,&fromKind,&fromField,&fromValue);
766 getFieldFromNodeAndName(toNode,stoField,&toType,&toKind,&toField,&toValue);
769 if (fromType != toType) {
770 printf (
"Javascript routing problem - can not route from %s to %s\n",
771 stringNodeType(fromNode->_nodeType),
772 stringNodeType(toNode->_nodeType));
776 len = returnRoutingElementLength(toType);
780 if(!ec) ec = (
struct X3D_Proto*)fromNode->_executionContext;
781 if(!strcmp(callingFunc,
"addRoute")){
782 broute = createNewBrotoRoute();
783 broute->from.node = fromNode;
784 broute->from.ifield = fromField;
786 broute->from.ftype = fromType;
787 broute->to.node = toNode;
788 broute->to.ifield = toField;
790 broute->to.ftype = toType;
791 broute->lastCommand = 1;
792 CRoutes_RegisterSimpleB(broute->from.node,broute->from.ifield,broute->to.node,broute->to.ifield,broute->ft);
793 broute->ft = fromType == toType ? fromType : -1;
796 stack_push(
struct brotoRoute *, ec->__ROUTES, broute);
797 retval = (
void*)broute;
801 for(i=0;i<vectorSize(ec->__ROUTES);i++){
802 broute = vector_get(
struct brotoRoute*,ec->__ROUTES,i);
803 if(broute->from.node == fromNode && broute->from.ifield == fromField
804 && broute->to.node == toNode && broute->to.ifield == toField){
805 if(broute->lastCommand == 1)
806 CRoutes_RemoveSimpleB(broute->from.node,broute->from.ifield,broute->to.node,broute->to.ifield,broute->ft);
807 broute->lastCommand = 0;
808 vector_remove_elem(
struct brotoRoute*,ec->__ROUTES,i);
820 void * addDeleteRoute(
void *fwn,
char* callingFunc,
int argc,
FWval fwpars,
FWval fwretval){
823 const char *fromField, *toField;
830 fromNode = fwpars[0]._web3dval.anyvrml->sfnode;
831 toNode = fwpars[2]._web3dval.anyvrml->sfnode;
833 fromField = fwpars[1]._string;
834 toField = fwpars[3]._string;
836 retval = addDeleteRoute0(fwn,callingFunc,fromNode, fromField, toNode, toField);
839 int X3DExecutionContext_deleteRoute(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
844 char *fromField, *toField;
845 int fromIfield, toIfield;
849 if(fwpars[0].itype !=
'P')
return nr;
853 fromNode = broute->from.node;
854 fromIfield = broute->from.ifield;
855 toNode = broute->to.node;
856 toIfield = broute->to.ifield;
858 getFieldFromNodeAndIndex(fromNode,fromIfield,&fromField,&ftype,&kind,&value);
859 getFieldFromNodeAndIndex(toNode,toIfield,&toField,&ftype,&kind,&value);
860 xroute = addDeleteRoute0(fwn,
"deleteRoute",fromNode, fromField, toNode, toField);
864 int VrmlBrowserAddRoute(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
867 xroute = addDeleteRoute(fwn,
"addRoute",argc,fwpars,fwretval);
869 fwretval->_web3dval.fieldType = AUXTYPE_X3DRoute;
870 fwretval->_web3dval.native = xroute;
871 fwretval->_web3dval.gc = 0;
872 fwretval->itype =
'P';
877 int VrmlBrowserDeleteRoute(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
880 xroute = addDeleteRoute(fwn,
"deleteRoute",argc,fwpars,fwretval);
883 int VrmlBrowserPrint(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
885 const char *_costr = NULL;
886 if(fwpars[0].itype ==
'S'){
887 _costr = fwpars[0]._string;
889 ConsoleMessage(
"%s",_costr);
893 int VrmlBrowserPrintln(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval)
895 const char *_costr = NULL;
896 if(fwpars[0].itype ==
'S'){
897 _costr = fwpars[0]._string;
899 ConsoleMessage(
"%s\n",_costr);
905 {
"getName", VrmlBrowserGetName,
'S',{0,0,0,NULL}},
906 {
"getVersion", VrmlBrowserGetVersion,
'S',{0,0,0,NULL}},
907 {
"getCurrentSpeed", VrmlBrowserGetCurrentSpeed,
'S',{0,0,0,NULL}},
908 {
"getCurrentFrameRate", VrmlBrowserGetCurrentFrameRate,
'S',{0,0,0,NULL}},
909 {
"getWorldURL", VrmlBrowserGetWorldURL,
'S',{0,0,0,NULL}},
910 {
"replaceWorld", VrmlBrowserReplaceWorld,
'0',{1,-1,0,
"Z"}},
911 {
"loadURL", VrmlBrowserLoadURL,
'0',{2,1,
'T',
"FF"}},
912 {
"setDescription", VrmlBrowserSetDescription,
'0',{1,-1,0,
"S"}},
913 {
"createVrmlFromString", VrmlBrowserCreateVrmlFromString,
'W',{1,-1,0,
"S"}},
914 {
"createVrmlFromURL", VrmlBrowserCreateVrmlFromURL,
'0',{3,3,0,
"WWS"}},
915 {
"createX3DFromString", VrmlBrowserCreateX3DFromString,
'W',{1,-1,0,
"S"}},
916 {
"createX3DFromURL", VrmlBrowserCreateVrmlFromURL,
'0',{3,3,0,
"WWS"}},
917 {
"addRoute", VrmlBrowserAddRoute,
'P',{4,-1,0,
"WSWS"}},
918 {
"deleteRoute", VrmlBrowserDeleteRoute,
'0',{4,-1,0,
"WSWS"}},
919 {
"print", VrmlBrowserPrint,
'0',{1,-1,0,
"S"}},
920 {
"println", VrmlBrowserPrintln,
'0',{1,-1,0,
"S"}},
940 {
"name", 0,
'S',
'T'},
941 {
"version", 1,
'S',
'T'},
942 {
"currentSpeed", 2,
'D',
'T'},
943 {
"currentFrameRate", 3,
'D',
'T'},
944 {
"description", 4,
'S', 0},
945 {
"supportedComponents", 5,
'P',
'T'},
946 {
"supportedProfiles", 6,
'P',
'T'},
947 {
"currentScene", 7,
'P',
'T'},
952 const int *profileTable;
956 const int * getCapabilitiesTable();
957 int BrowserGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
962 fwretval->_string = BrowserName;
963 fwretval->itype =
'S';
966 fwretval->_string = libFreeWRL_get_version();
967 fwretval->itype =
'S';
970 fwretval->_numeric = gglobal()->Mainloop.BrowserSpeed;
971 fwretval->itype =
'D';
974 fwretval->_numeric = gglobal()->Mainloop.BrowserFPS;
975 fwretval->itype =
'D';
978 fwretval->_string = gglobal()->Mainloop.BrowserDescription;
979 fwretval->itype =
'S';
982 fwretval->_pointer.fieldType = AUXTYPE_ComponentInfoArray;
983 fwretval->_pointer.native = (
void*)getCapabilitiesTable();
984 fwretval->_pointer.gc = 0;
985 fwretval->itype =
'P';
988 fwretval->_pointer.fieldType = AUXTYPE_ProfileInfoArray;
989 fwretval->_pointer.native = (
void*)getProfTable();
990 fwretval->_pointer.gc = 0;
991 fwretval->itype =
'P';
994 fwretval->_web3dval.fieldType = AUXTYPE_X3DExecutionContext;
995 fwretval->_web3dval.native = (
void *)(
struct X3D_Node*)ec;
996 fwretval->_web3dval.gc = 0;
998 fwretval->itype =
'P';
1005 int BrowserSetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwval){
1008 gglobal()->Mainloop.BrowserDescription = fwval->_string;
1048 int capabilitiesHandler_getTableLength(
int* table);
1049 int capabilitiesHandler_getComponentLevel(
int *table,
int comp);
1050 int capabilitiesHandler_getProfileLevel(
int prof);
1051 const int *capabilitiesHandler_getProfileComponent(
int prof);
1052 const int *capabilitiesHandler_getCapabilitiesTable();
1066 int *intdup(
int value){
1067 int* p = malloc(
sizeof(
int));
1068 memcpy(p,&value,
sizeof(
int));
1071 int ComponentInfoArrayGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1074 _table = (
int *)fwn;
1079 int _length = capabilitiesHandler_getTableLength(_table);
1081 fwretval->itype =
'I';
1082 fwretval->_integer = _length;
1084 }
else if(index > -1 && index < COMPONENTS_COUNT ){
1085 fwretval->_pointer.native = &_table[2*index];
1086 fwretval->_pointer.fieldType = AUXTYPE_ComponentInfo;
1087 fwretval->_pointer.gc = 0;
1088 fwretval->itype =
'P';
1095 {
"length", -1,
'I',
'T'},
1099 FWTYPE ComponentInfoArrayType = {
1100 AUXTYPE_ComponentInfoArray,
1102 "ComponentInfoArray",
1106 ComponentInfoArrayProperties,
1108 ComponentInfoArrayGetter,
1115 {
"name", 0,
'S',
'T'},
1116 {
"Title", 1,
'S',
'T'},
1117 {
"level", 2,
'I',
'T'},
1118 {
"providerUrl", 3,
'S',
'T'},
1123 int ComponentInfoGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1124 int nr, *tableEntry, nameIndex;
1125 tableEntry = (
int *)fwn;
1131 nameIndex = tableEntry[0];
1132 fwretval->_string = COMPONENTS[nameIndex];
1133 fwretval->itype =
'S';
1136 fwretval->_integer = tableEntry[1];
1137 fwretval->itype =
'I';
1140 fwretval->_string =
"freewrl.sourceforge.net";
1141 fwretval->itype =
'S';
1150 FWTYPE ComponentInfoType = {
1151 AUXTYPE_ComponentInfo,
1157 ComponentInfoProperties,
1159 ComponentInfoGetter,
1173 int ProfileInfoArrayGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1181 fwretval->_integer = PROFILES_COUNT;
1182 fwretval->itype =
'I';
1183 }
else if(index > -1 && index < PROFILES_COUNT ){
1184 fwretval->_pointer.native = &_table[index];
1185 fwretval->_pointer.fieldType = AUXTYPE_ProfileInfo;
1186 fwretval->_pointer.gc = 0;
1187 fwretval->itype =
'P';
1194 {
"length", -1,
'I',
'T'},
1198 FWTYPE ProfileInfoArrayType = {
1199 AUXTYPE_ProfileInfoArray,
1205 ProfileInfoArrayProperties,
1207 ProfileInfoArrayGetter,
1223 {
"name", 0,
'S',
'T'},
1224 {
"Title", 1,
'I',
'T'},
1225 {
"level", 2,
'S',
'T'},
1226 {
"providerUrl", 3,
'S',
'T'},
1227 {
"components", 4,
'P',
'T'},
1232 int ProfileInfoGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1241 nameIndex = tableEntry->profileName;
1242 fwretval->_string = stringProfileType(nameIndex);
1243 fwretval->itype =
'S';
1246 fwretval->_integer = tableEntry->level;
1247 fwretval->itype =
'I';
1250 fwretval->_string =
"freewrl.sourceforge.net";
1251 fwretval->itype =
'S';
1254 fwretval->_pointer.native = (
void *)tableEntry->profileTable;
1255 fwretval->_pointer.fieldType = AUXTYPE_ComponentInfoArray;
1256 fwretval->_pointer.gc = 0;
1257 fwretval->itype =
'P';
1266 FWTYPE ProfileInfoType = {
1267 AUXTYPE_ProfileInfo,
1273 ProfileInfoProperties,
1284 struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name);
1285 struct X3D_Node * broto_search_ALLnames(
struct X3D_Proto *context,
char *name,
int *source);
1286 int X3DExecutionContext_getNamedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1291 node = broto_search_DEFname(ec, fwpars[0]._string);
1295 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1296 fwretval->_web3dval.anyvrml->sfnode = node;
1297 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1298 fwretval->_web3dval.gc = 1;
1299 fwretval->itype =
'W';
1305 int X3DExecutionContext_updateNamedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1313 defname = fwpars[0]._string;
1314 node = X3D_NODE(fwpars[1]._web3dval.native);
1315 if(_ec->__DEFnames){
1316 for(i=0;i<vectorSize(_ec->__DEFnames);i++){
1317 bd = vector_get(
struct brotoDefpair *,_ec->__DEFnames,i);
1320 if(!strcmp(bd->name,defname)){
1325 if(bd->node == node){
1326 bd->name = strdup(defname);
1334 if(!_ec->__DEFnames)
1338 bd->name = strdup(defname);
1344 int X3DExecutionContext_removeNamedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1351 defname = fwpars[0]._string;
1352 if(_ec->__DEFnames){
1354 for(i=0;i<vectorSize(_ec->__DEFnames);i++){
1355 bd = vector_get(
struct brotoDefpair *,_ec->__DEFnames,i);
1356 if(!strcmp(bd->name,defname)){
1361 vector_remove_elem(
struct brotoDefpair *,_ec->__DEFnames,i);
1363 remove_broto_node(_ec,node);
1371 void add_node_to_broto_context(
struct X3D_Proto *context,
struct X3D_Node *node);
1372 int X3DExecutionContext_createProto(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1380 if( isAvailableBroto(fwpars[0]._string, ec, &proto))
1383 node=X3D_NODE(brotoInstance(proto,1));
1384 node->_executionContext = X3D_NODE(ec);
1385 add_node_to_broto_context(ec,node);
1389 source = X3D_PROTO(X3D_PROTO(node)->__prototype);
1390 dest = X3D_PROTO(node);
1391 deep_copy_broto_body2(&source,&dest);
1395 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1396 fwretval->_web3dval.anyvrml->sfnode = node;
1397 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1398 fwretval->_web3dval.gc = 1;
1399 fwretval->itype =
'W';
1405 int X3DExecutionContext_getImportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1416 node = broto_search_ALLnames(ec, fwpars[0]._string,&source);
1417 if(source == 0) node = NULL;
1420 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1421 fwretval->_web3dval.anyvrml->sfnode = node;
1422 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1423 fwretval->_web3dval.gc = 1;
1424 fwretval->itype =
'W';
1430 void update_weakRoutes(
struct X3D_Proto *context);
1431 int X3DExecutionContext_updateImportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1439 char *mxname, *as, *nline;
1443 nline = fwpars[0]._string;
1444 mxname = fwpars[1]._string;
1447 as = fwpars[2]._string;
1448 node = X3D_NODE(fwpars[1]._web3dval.native);
1450 for(i=0;i<vectorSize(_ec->__IMPORTS);i++){
1451 mxp = vector_get(
struct IMEXPORT *,_ec->__IMPORTS,i);
1454 if(!strcmp(nline,mxp->inlinename) && !strcmp(mxp->mxname,mxname)){
1455 mxp->as = strdup(as);
1464 _ec->__IMPORTS = newVector(
struct IMEXPORT *,4);
1466 mxp->mxname = strdup(mxname);
1467 mxp->as = strdup(as);
1468 mxp->inlinename = strdup(nline);
1469 stack_push(
struct IMEXPORT *,_ec->__IMPORTS,mxp);
1471 update_weakRoutes(_ec);
1476 int X3DExecutionContext_removeImportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1483 defname = fwpars[0]._string;
1486 for(i=0;i<vectorSize(_ec->__IMPORTS);i++){
1487 mxp = vector_get(
struct IMEXPORT *,_ec->__IMPORTS,i);
1488 if(!strcmp(mxp->as,defname)){
1490 vector_remove_elem(
struct IMEXPORT *,_ec->__IMPORTS,i);
1491 update_weakRoutes(_ec);
1500 int X3DScene_getExportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1506 mxp = broto_search_EXPORTname(ec, fwpars[0]._string);
1508 node = mxp->nodeptr;
1512 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1513 fwretval->_web3dval.anyvrml->sfnode = node;
1514 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1515 fwretval->_web3dval.gc = 1;
1516 fwretval->itype =
'W';
1522 int X3DScene_updateExportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1532 defname = fwpars[0]._string;
1533 node = X3D_NODE(fwpars[1]._web3dval.anyvrml->sfnode);
1535 for(i=0;i<vectorSize(_ec->__EXPORTS);i++){
1536 mxp = vector_get(
struct IMEXPORT *,_ec->__EXPORTS,i);
1539 if(!strcmp(mxp->as,defname)){
1540 mxp->nodeptr = node;
1544 if(mxp->nodeptr == node){
1545 mxp->as = strdup(defname);
1554 _ec->__EXPORTS = newVector(
struct IMEXPORT *,4);
1556 mxp->nodeptr = node;
1557 mxp->mxname = strdup(defname);
1558 mxp->as = mxp->mxname;
1559 stack_push(
struct IMEXPORT *,_ec->__EXPORTS,mxp);
1561 if(_ec->_executionContext){
1564 update_weakRoutes(X3D_PROTO(_ec->_executionContext));
1569 int X3DScene_removeExportedNode(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1576 defname = fwpars[0]._string;
1579 for(i=0;i<vectorSize(_ec->__EXPORTS);i++){
1580 mxp = vector_get(
struct IMEXPORT *,_ec->__EXPORTS,i);
1581 if(!strcmp(mxp->as,defname)){
1583 vector_remove_elem(
struct IMEXPORT *,_ec->__EXPORTS,i);
1588 if(_ec->_executionContext){
1591 update_weakRoutes(X3D_PROTO(_ec->_executionContext));
1595 int X3DScene_setMetaData(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1598 name = fwpars[0]._string;
1599 value = fwpars[1]._string;
1603 int X3DScene_getMetaData(
FWType fwtype,
void *ec,
void *fwn,
int argc,
FWval fwpars,
FWval fwretval){
1607 name = fwpars[0]._string;
1610 fwretval->_string = value;
1611 fwretval->itype =
'S';
1619 {
"addRoute", VrmlBrowserAddRoute,
'P',{4,-1,0,
"WSWS"}},
1620 {
"deleteRoute", X3DExecutionContext_deleteRoute,
'0',{1,-1,0,
"P"}},
1621 {
"createNode", VrmlBrowserCreateNodeFromString,
'W',{1,-1,0,
"S"}},
1622 {
"createProto", X3DExecutionContext_createProto,
'W',{1,-1,0,
"S"}},
1623 {
"getImportedNode", X3DExecutionContext_getImportedNode,
'W',{1,-1,0,
"S"}},
1624 {
"updateImportedNode", X3DExecutionContext_updateImportedNode,
'0',{3,-1,0,
"SSS"}},
1625 {
"removeImportedNode", X3DExecutionContext_removeImportedNode,
'0',{1,-1,0,
"S"}},
1626 {
"getNamedNode", X3DExecutionContext_getNamedNode,
'W',{1,-1,0,
"S"}},
1627 {
"updateNamedNode", X3DExecutionContext_updateNamedNode,
'0',{2,-1,0,
"SW"}},
1628 {
"removeNamedNode", X3DExecutionContext_removeNamedNode,
'0',{1,-1,0,
"S"}},
1630 {
"setMetaData", X3DScene_setMetaData,
'0',{2,-1,0,
"SS"}},
1631 {
"getMetaData", X3DScene_getMetaData,
'S',{1,-1,0,
"S"}},
1632 {
"getExportedNode", X3DScene_getExportedNode,
'W',{1,-1,0,
"S"}},
1633 {
"updateExportedNode", X3DScene_updateExportedNode,
'0',{2,-1,0,
"SW"}},
1634 {
"removeExportedNode", X3DScene_removeExportedNode,
'0',{1,-1,0,
"S"}},
1642 {
"specificationVersion", 0,
'S',
'T'},
1643 {
"encoding", 1,
'S',
'T'},
1644 {
"profile", 2,
'P',
'T'},
1645 {
"components", 3,
'P',
'T'},
1646 {
"worldURL", 4,
'S',
'T'},
1647 {
"rootNodes", 5,
'W',
'T'},
1648 {
"protos", 6,
'P',
'T'},
1649 {
"externprotos", 7,
'P',
'T'},
1650 {
"routes", 8,
'P',
'T'},
1652 {
"isScene", 9,
'B',
'T'},
1655 static int _TRUE = TRUE;
1656 static int _FALSE = FALSE;
1657 int X3DExecutionContextGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1666 sprintf(str,
"{%d,%d,%d}",inputFileVersion[0],inputFileVersion[1],inputFileVersion[2]);
1667 fwretval->_string = strdup(str);
1668 fwretval->itype =
'S';
1674 fwretval->_string =
"not filled in yet sb. VRML or XML or ..";
1675 fwretval->itype =
'S';
1681 int index = gglobal()->Mainloop.scene_profile;
1682 profile = getProfTable();
1683 fwretval->_pointer.native = &profile[index];
1684 fwretval->_pointer.fieldType = AUXTYPE_ProfileInfo;
1685 fwretval->_pointer.gc = 0;
1686 fwretval->itype =
'P';
1690 fwretval->_pointer.native = (
void *)gglobal()->Mainloop.scene_components;
1691 fwretval->_pointer.fieldType = AUXTYPE_ComponentInfoArray;
1692 fwretval->_pointer.gc = 0;
1693 fwretval->itype =
'P';
1696 fwretval->_string = gglobal()->Mainloop.url;
1697 fwretval->itype =
'S';
1700 fwretval->_web3dval.native = (
void *)&ecc->__children;
1701 fwretval->_web3dval.fieldType = FIELDTYPE_MFNode;
1702 fwretval->_web3dval.gc = 0;
1703 fwretval->itype =
'W';
1706 fwretval->_pointer.fieldType = AUXTYPE_X3DProtoArray;
1707 fwretval->_pointer.native = (
void*)ecc->__protoDeclares;
1708 fwretval->_pointer.gc = 0;
1709 fwretval->itype =
'P';
1712 fwretval->_pointer.fieldType = AUXTYPE_X3DExternProtoArray;
1713 fwretval->_pointer.native = (
void*)ecc->__externProtoDeclares;
1714 fwretval->_pointer.gc = 0;
1715 fwretval->itype =
'P';
1718 fwretval->_pointer.fieldType = AUXTYPE_X3DRouteArray;
1719 fwretval->_pointer.native = (
void*)ecc->__ROUTES;
1720 fwretval->_pointer.gc = 0;
1721 fwretval->itype =
'P';
1725 fwretval->itype =
'B';
1727 unsigned char flag = ciflag_get(ecc->__protoFlags,2);
1729 fwretval->_boolean = TRUE;
1731 fwretval->_boolean = FALSE;
1740 FWTYPE X3DExecutionContextType = {
1741 AUXTYPE_X3DExecutionContext,
1743 "X3DExecutionContext",
1747 X3DExecutionContextProperties,
1749 X3DExecutionContextGetter,
1752 X3DExecutionContextFunctions,
1756 int getCRouteCount();
1757 int *getCRouteCounter();
1758 int X3DRouteArrayGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1764 _length = vectorSize(fwn);
1765 fwretval->_integer = _length;
1766 fwretval->itype =
'I';
1768 }
else if(index > -1 ){
1769 if(index < vectorSize(fwn)){
1770 fwretval->_pointer.native = vector_get(
void *, fwn, index);
1771 fwretval->_pointer.gc = 0;
1772 fwretval->_pointer.fieldType = AUXTYPE_X3DRoute;
1773 fwretval->itype =
'P';
1782 {
"length", -1,
'I',
'T'},
1786 FWTYPE X3DRouteArrayType = {
1787 AUXTYPE_X3DRouteArray,
1793 X3DRouteArrayProperties,
1795 X3DRouteArrayGetter,
1809 {
"sourceNode", 0,
'W',
'T'},
1810 {
"sourceField", 1,
'S',
'T'},
1811 {
"destinationNode", 2,
'W',
'T'},
1812 {
"destinationField", 3,
'S',
'T'},
1815 int X3DRouteGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1819 struct X3D_Node *fromNode, *toNode;
1820 int fromIndex, toIndex;
1824 fromNode = broute->from.node;
1825 fromIndex = broute->from.ifield;
1826 toNode = broute->to.node;
1827 toIndex = broute->to.ifield;
1829 if(!fromNode || !toNode)
return 0;
1836 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1837 fwretval->_web3dval.anyvrml->sfnode = fromNode;
1838 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1839 fwretval->_web3dval.gc = 1;
1840 fwretval->itype =
'W';
1844 getFieldFromNodeAndIndex(fromNode,fromIndex,&fieldname,&type,&kind,&value);
1845 fwretval->_string = fieldname;
1846 fwretval->itype =
'S';
1850 fwretval->_web3dval.anyvrml = malloc(
sizeof(
union anyVrml));
1851 fwretval->_web3dval.anyvrml->sfnode = toNode;
1852 fwretval->_web3dval.fieldType = FIELDTYPE_SFNode;
1853 fwretval->itype =
'W';
1854 fwretval->_web3dval.gc = 1;
1858 getFieldFromNodeAndIndex(toNode,toIndex,&fieldname,&type,&kind,&value);
1859 fwretval->_string = fieldname;
1860 fwretval->itype =
'S';
1886 int X3DProtoArrayGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1892 _length = vectorSize(fwn);
1893 fwretval->_integer = _length;
1894 fwretval->itype =
'I';
1896 }
else if(index > -1 ){
1897 if(index < vectorSize(fwn)){
1898 fwretval->_pointer.native = vector_get(
void *, fwn, index);
1899 fwretval->_pointer.gc = 1;
1900 fwretval->_pointer.fieldType = AUXTYPE_X3DProto;
1901 fwretval->itype =
'P';
1910 {
"length", -1,
'I',
'T'},
1914 FWTYPE X3DProtoArrayType = {
1915 AUXTYPE_X3DProtoArray,
1921 X3DProtoArrayProperties,
1923 X3DProtoArrayGetter,
1929 FWTYPE X3DExternProtoArrayType = {
1930 AUXTYPE_X3DExternProtoArray,
1932 "X3DExternProtoArray",
1936 X3DProtoArrayProperties,
1938 X3DProtoArrayGetter,
1945 struct tuplePointerInt {
1951 {
"name", 0,
'S',
'T'},
1952 {
"fields", 1,
'W',
'T'},
1953 {
"isExternProto", 2,
'B',
'T'},
1956 int X3DProtoGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
1961 fwretval->_string = X3D_PROTO(fwn)->__typename;
1962 fwretval->itype =
'S';
1965 fwretval->_web3dval.native = fwn;
1966 fwretval->_web3dval.fieldType = AUXTYPE_X3DFieldDefinitionArray;
1967 fwretval->itype =
'W';
1968 fwretval->_web3dval.gc = 0;
1971 fwretval->itype =
'B';
1973 unsigned char flag = ciflag_get(X3D_PROTO(fwn)->__protoFlags,3);
1975 fwretval->_boolean = TRUE;
1977 fwretval->_boolean = FALSE;
1989 "X3DProtoDeclaration",
2000 FWTYPE X3DExternProtoType = {
2001 AUXTYPE_X3DExternProto,
2003 "X3DExternProtoDeclaration",
2015 int count_fields(
struct X3D_Node* node);
2016 int X3DFieldDefinitionArrayGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2025 _length = count_fields(node);
2026 fwretval->_integer = _length;
2027 fwretval->itype =
'I';
2029 }
else if(index > -1 ){
2030 if(index < vectorSize(fwn)){
2031 struct tuplePointerInt *tpi = malloc(
sizeof(
struct tuplePointerInt));
2032 tpi->pointer = (
void*)node;
2033 tpi->integer = index;
2034 fwretval->_pointer.native = tpi;
2035 fwretval->_pointer.gc = 1;
2036 fwretval->_pointer.fieldType = AUXTYPE_X3DFieldDefinition;
2037 fwretval->itype =
'P';
2046 {
"length", -1,
'I',
'T'},
2050 FWTYPE X3DFieldDefinitionArrayType = {
2051 AUXTYPE_X3DFieldDefinitionArray,
2053 "X3DFieldDefinitionArray",
2057 X3DFieldDefinitionArrayProperties,
2059 X3DFieldDefinitionArrayGetter,
2066 {
"name", 0,
'S',
'T'},
2067 {
"accessType", 1,
'I',
'T'},
2068 {
"dataType", 2,
'I',
'T'},
2071 int X3DFieldDefinitionGetter(
FWType fwt,
int index,
void *ec,
void *fwn,
FWval fwretval){
2072 int ifield, type,kind, konstindex, nr = 0;
2073 struct string_int * si;
2077 struct tuplePointerInt *tpi = (
struct tuplePointerInt*)fwn;
2078 node = tpi->pointer;
2079 ifield = tpi->integer;
2082 if(getFieldFromNodeAndIndex(node,ifield,&fname,&type,&kind,&value)){
2086 fwretval->_string = fname;
2087 fwretval->itype =
'S';
2090 si = lookup_string_int(lookup_X3DConstants,PROTOKEYWORDS[kind],&konstindex);
2091 fwretval->_integer = konstindex;
2092 fwretval->itype =
'I';
2095 si = lookup_string_int(lookup_X3DConstants,FIELDTYPES[type],&konstindex);
2096 fwretval->_integer = konstindex;
2097 fwretval->itype =
'I';
2107 FWTYPE X3DFieldDefinitionType = {
2108 AUXTYPE_X3DFieldDefinition,
2110 "X3DFieldDefinition",
2114 X3DFieldDefinitionProperties,
2116 X3DFieldDefinitionGetter,
2127 void initVRMLBrowser(
FWTYPE** typeArray,
int *n){
2128 typeArray[*n] = &X3DRouteType; (*n)++;
2129 typeArray[*n] = &X3DRouteArrayType; (*n)++;
2130 typeArray[*n] = &X3DExecutionContextType; (*n)++;
2131 typeArray[*n] = &ProfileInfoType; (*n)++;
2132 typeArray[*n] = &ProfileInfoArrayType; (*n)++;
2133 typeArray[*n] = &ComponentInfoType; (*n)++;
2134 typeArray[*n] = &ComponentInfoArrayType; (*n)++;
2135 typeArray[*n] = &BrowserType; (*n)++;
2136 typeArray[*n] = &X3DConstantsType; (*n)++;
2138 typeArray[*n] = &X3DProtoType; (*n)++;
2139 typeArray[*n] = &X3DProtoArrayType; (*n)++;
2140 typeArray[*n] = &X3DExternProtoType; (*n)++;
2141 typeArray[*n] = &X3DExternProtoArrayType; (*n)++;
2142 typeArray[*n] = &X3DFieldDefinitionType; (*n)++;
2143 typeArray[*n] = &X3DFieldDefinitionArrayType; (*n)++;