FreeWRL / FreeX3D 4.3.0
jsVRML_SFClasses_sm.cpp
1/*
2
3 A substantial amount of code has been adapted from js/src/js.c,
4 which is the sample application included with the javascript engine.
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#include <config.h>
29#ifdef JAVASCRIPT_SM
30#if defined(JS_SMCPP)
31#undef DEBUG
32//#define DEBUG 1 //challenge it with lots of ASSERTS, just for cleaning up code correctness, not production
33# include <jsapi.h> /* JS compiler */
34# include <jsdbgapi.h> /* JS debugger */
35#define JS_VERSION 187
36//#define JS_THREADSAFE 1 //by default in 186+
37int JS_SetPrivateFw(JSContext *cx, JSObject* obj, void *data);
38JSObject* JS_NewGlobalObjectFw(JSContext *cx, JSClass *clasp); //, JSPrincipals *princ);
39void * JS_GetPrivateFw(JSContext *cx,JSObject*_obj);
40JSObject* JS_GetParentFw(JSContext *cx, JSObject *me);
41JSObject * JS_ConstructObjectWithArgumentsFw(JSContext *cx, JSClass *clasp, JSObject *parent, unsigned argc, jsval *argv);
42JSObject * JS_ConstructObjectFw(JSContext *cx, JSClass *clasp, void *whatever, JSObject *parent);
43JSObject * JS_GetPrototypeFw(JSContext *cx, JSObject * obj);
44JSClass * JS_GetClassFw(JSContext *cx, JSObject * obj);
45#define STRING_SIZE 256
46#define uintN unsigned
47#define intN int
48#define jsint int32_t
49#define jsuint uint32_t
50#define int32 int32_t
51#define jsdouble double
52
53#define JS_FinalizeStub NULL
54#define JS_GET_CLASS JS_GetClassFw
55JSBool JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
56//#define JSVAL_IS_OBJECT(retval) JSVAL_IS_OBJECT_OR_NULL_IMPL(retval)
57
58#ifndef IBOOL
59typedef int IBOOL;
60#endif
61typedef IBOOL _Bool;
62//typedef _Bool bool;
63
64
65
66extern "C" {
67#include <system.h>
68//#include <system_threads.h>
69//#include <display.h>
70#include <internal.h>
71
72//#include <libFreeWRL.h>
73//#include <list.h>
74#include "scenegraph/LinearAlgebra.h"
75#include "scenegraph/quaternion.h"
76//#include <io_files.h>
77
78//#include "../vrml_parser/Structs.h"
79//#include "../main/headers.h"
80#include "../main/ProdCon.h"
81//#include "../vrml_parser/CParseGeneral.h"
82//#include "../main/Snapshot.h"
83//#include "../scenegraph/LinearAlgebra.h"
84//#include "../scenegraph/Collision.h"
85//#include "../scenegraph/quaternion.h"
86//#include "../scenegraph/Viewer.h"
87//#include "../input/SensInterps.h"
88//#include "../x3d_parser/Bindable.h"
89//#include "../input/InputFunctions.h"
90
91//#include <system_js.h>
92#include "JScript.h"
93#include "CScripts.h"
94#include "jsNative.h"
95
96void Parser_scanStringValueToMem_B(union anyVrml* any, indexT ctype, const char *value, int isXML);
97} //extern "C"
98
99#include "jsUtils_sm.h"
100#include "jsVRMLClasses_sm.h"
101
102//#include "JScript.h"
103
104
105/********************************************************/
106/* */
107/* Second part - SF classes */
108/* */
109/********************************************************/
110
111/* from http://www.cs.rit.edu/~ncs/color/t_convert.html */
112double dMIN3(double a, double b, double c) {
113 double min;
114 if((a<b)&&(a<c))min=a; else if((b<a)&&(b<c))min=b; else min=c; return min;
115}
116
117double dMAX3(double a, double b, double c) {
118 double max;
119 if((a>b)&&(a>c))max=a; else if((b>a)&&(b>c))max=b; else max=c; return max;
120}
121
122void convertRGBtoHSV(double r, double g, double b, double *h, double *s, double *v) {
123 double my_min, my_max, delta;
124
125 my_min = dMIN3( r, g, b );
126 my_max = dMAX3( r, g, b );
127 *v = my_max; /* v */
128 delta = my_max - my_min;
129 if( my_max != 0 )
130 *s = delta / my_max; /* s */
131 else {
132 /* r = g = b = 0 */ /* s = 0, v is undefined */
133 *s = 0;
134 *h = -1;
135 return;
136 }
137 if( r == my_max )
138 *h = ( g - b ) / delta; /* between yellow & magenta */
139 else if( g == my_max )
140 *h = 2 + ( b - r ) / delta; /* between cyan & yellow */
141 else
142 *h = 4 + ( r - g ) / delta; /* between magenta & cyan */
143 *h *= 60; /* degrees */
144 if( *h < 0 )
145 *h += 360;
146}
147void convertHSVtoRGB( double h, double s, double v ,double *r, double *g, double *b)
148{
149 int i;
150 double f, p, q, t;
151 if( s == 0 ) {
152 /* achromatic (grey) */
153 *r = *g = *b = v;
154 return;
155 }
156 h /= 60; /* sector 0 to 5 */
157 i = (int) floor( h );
158 f = h - i; /* factorial part of h */
159 p = v * ( 1 - s );
160 q = v * ( 1 - s * f );
161 t = v * ( 1 - s * ( 1 - f ) );
162 switch( i ) {
163 case 0: *r = v; *g = t; *b = p; break;
164 case 1: *r = q; *g = v; *b = p; break;
165 case 2: *r = p; *g = v; *b = t; break;
166 case 3: *r = p; *g = q; *b = v; break;
167 case 4: *r = t; *g = p; *b = v; break;
168 default: *r = v; *g = p; *b = q; break;
169 }
170}
171
172JSBool
173#if JS_VERSION < 185
174SFColorGetHSV(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
175#else
176SFColorGetHSV(JSContext *cx, uintN argc, jsval *vp) {
177 JSObject *obj = JS_THIS_OBJECT(cx,vp);
178 jsval *argv = JS_ARGV(cx,vp);
179#endif
180 JSObject *result;
181 double xp[3];
182 jsval _v;
183 int i;
184 float *cc;
185
186 UNUSED(argv);
187 if (argc != 0) {
188 printf ("SFColorGetHSV; arguments found but not expected\n");
189 return JS_FALSE;
190 }
191
192 /* get the RGB values */
193 if(SM_method()==2){
194 AnyNative *ptr;
195 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
196 printf( "JS_GetPrivate failed in SFColorGetHSV.\n");
197 return JS_FALSE;
198 }
199 cc = ptr->v->sfcolor.c;
200
201 }else{
202 SFColorNative *ptr;
203 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
204 printf( "JS_GetPrivate failed in SFColorGetHSV.\n");
205 return JS_FALSE;
206 }
207 cc = ptr->v.c;
208 }
209 /* convert rgb to hsv */
210 convertRGBtoHSV(cc[0], cc[1], cc[2],&xp[0],&xp[1],&xp[2]);
211
212 #ifdef JSVRMLCLASSESVERBOSE
213 printf("hsv code, orig rgb is %.9g %.9g %.9g\n", (ptr->v).c[0], (ptr->v).c[1], (ptr->v).c[2]);
214 printf ("hsv conversion is %lf %lf %lf\n",xp[0],xp[1],xp[2]);
215 #endif
216 // http://www.web3d.org/documents/specifications/19777-1/V3.3/Part1/functions.html#SFColor
217 // - specs want a numeric[3] return val
218 result = JS_NewArrayObject(cx, 3, NULL);
219 ADD_ROOT(cx, result);
220 for(i=0; i<3; i++) {
221 if (JS_NewNumberValue(cx, xp[i],&_v) == JS_FALSE) {
222 printf( "JS_NewDouble failed for %f in SFColorGetHSV.\n", xp[i]);
223 return JS_FALSE;
224 }
225 JS_SetElement(cx, result, (jsint)i, &_v);
226 }
227
228 /* JAS - should we remove this here, or on finalize? JS_RemoveRoot(cx, &result); */
229#if JS_VERSION < 185
230 *rval = OBJECT_TO_JSVAL(result);
231#else
232 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(result));
233#endif
234 return JS_TRUE;
235}
236
237JSBool
238#if JS_VERSION < 185
239SFColorSetHSV(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
240#else
241SFColorSetHSV(JSContext *cx, uintN argc, jsval *vp) {
242 JSObject *obj = JS_THIS_OBJECT(cx,vp);
243 jsval *argv = JS_ARGV(cx,vp);
244#endif
245 double hue, saturation, value;
246 double red,green,blue;
247 float *cc;
248
249 if(SM_method() == 2){
250 AnyNative *ptr;
251 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
252 printf( "JS_GetPrivate failed in SSFColorSetHSV.\n");
253 return JS_FALSE;
254 }
255 if(ptr->valueChanged)
256 (*ptr->valueChanged) ++;
257 cc = ptr->v->sfcolor.c;
258 }else{
259 SFColorNative *ptr;
260 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
261 printf( "JS_GetPrivate failed in SFColorSetHSV.\n");
262 return JS_FALSE;
263 }
264 ptr->valueChanged ++;
265 cc = ptr->v.c;
266 }
267
268 if (!JS_ConvertArguments(cx, argc, argv, "d d d", &hue, &saturation, &value)) {
269 printf( "JS_ConvertArguments failed in SFColorSetHSV.\n");
270 return JS_FALSE;
271 }
272
273 /* do conversion here!!! */
274 #ifdef JSCLASSESVERBOSE
275 printf("hsv code, orig rgb is %.9g %.9g %.9g\n", (ptr->v).c[0], (ptr->v).c[1], (ptr->v).c[2]);
276 printf ("SFColorSetHSV, have %lf %lf %lf\n",hue,saturation,value);
277 #endif
278
279 convertHSVtoRGB(hue,saturation,value, &red, &green, &blue);
280 cc[0] = (float) red;
281 cc[1] = (float) green;
282 cc[2] = (float) blue;
283 #ifdef JSCLASSESVERBOSE
284 printf("hsv code, now rgb is %.9g %.9g %.9g\n", (ptr->v).c[0], (ptr->v).c[1], (ptr->v).c[2]);
285 #endif
286
287#if JS_VERSION < 185
288 *rval = OBJECT_TO_JSVAL(obj);
289#else
290 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
291#endif
292
293 return JS_TRUE;
294}
295
296JSBool
297#if JS_VERSION < 185
298SFColorToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
299#else
300SFColorToString(JSContext *cx, uintN argc, jsval *vp) {
301 JSObject *obj = JS_THIS_OBJECT(cx,vp);
302 jsval *argv = JS_ARGV(cx,vp);
303#endif
304 JSString *_str;
305 char _buff[STRING];
306 float *cc;
307
308 UNUSED(argc);
309 UNUSED(argv);
310 if(SM_method()==2){
311 AnyNative *ptr;
312 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
313 printf( "JS_GetPrivate failed in SFColorToString.\n");
314 return JS_FALSE;
315 }
316 cc = ptr->v->sfcolor.c;
317 }else{
318 SFColorNative *ptr;
319 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
320 printf( "JS_GetPrivate failed in SFColorToString.\n");
321 return JS_FALSE;
322 }
323 cc = ptr->v.c;
324 }
325 memset(_buff, 0, STRING);
326 sprintf(_buff, "%.9g %.9g %.9g",
327 cc[0], cc[1], cc[2]);
328 _str = JS_NewStringCopyZ(cx, _buff);
329#if JS_VERSION < 185
330 *rval = STRING_TO_JSVAL(_str);
331#else
332 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
333#endif
334 return JS_TRUE;
335}
336
337JSBool
338#if JS_VERSION < 185
339SFColorAssign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
340#else
341SFColorAssign(JSContext *cx, uintN argc, jsval *vp) {
342 JSObject *obj = JS_THIS_OBJECT(cx,vp);
343 jsval *argv = JS_ARGV(cx,vp);
344 JSString *_id_jsstr;
345#endif
346 JSObject *_from_obj;
347 char *_id_str;
348
349 UNUSED(_id_str); // compiler warning mitigation
350
351 if(SM_method() == 2){
352 AnyNative *lhs, *rhs;
353 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
354 printf( "JS_GetPrivate failed for obj in SFColorAssign.\n");
355 return JS_FALSE;
356 }
357 //if (!JSVAL_IS_OBJECT(*vp))
358 if (!(*vp).isObject())
359 return JS_FALSE;
360 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
361 printf("JS_ConvertArguments failed in SFColorAssign. \n");
362 return JS_FALSE;
363 }
364 AnyNativeAssign(lhs,rhs);
365 }else{
366 SFColorNative *ptr, *fptr;
367 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
368 printf( "JS_GetPrivate failed for obj in SFColorAssign.\n");
369 return JS_FALSE;
370 }
371
372
373 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFColorClass)
374
375#if JS_VERSION < 185
376 if (!JS_ConvertArguments(cx, argc, argv, "o s", &_from_obj, &_id_str)) {
377#else
378 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
379 _id_str = JS_EncodeString(cx,_id_jsstr);
380 } else {
381#endif
382 printf( "JS_ConvertArguments failed in SFColorAssign.\n");
383 return JS_FALSE;
384 }
385
386 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFColorClass)
387
388 if ((fptr = (SFColorNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
389 printf( "JS_GetPrivate failed for _from_obj in SFColorAssign.\n");
390 return JS_FALSE;
391 }
392 #ifdef JSVRMLCLASSESVERBOSE
393 printf("SFColorAssign: obj = %p, id = \"%s\", from = %p\n", obj, _id_str, _from_obj);
394 #endif
395
396 SFColorNativeAssign(ptr, fptr);
397 }
398#if JS_VERSION < 185
399 *rval = OBJECT_TO_JSVAL(obj);
400#else
401 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
402#endif
403
404 return JS_TRUE;
405}
406
407JSBool
408#if JS_VERSION < 185
409SFColorConstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
410#else
411SFColorConstr(JSContext *cx, uintN argc, jsval *vp) {
412 JSObject *obj = JS_NewObject(cx,&SFColorClass,NULL,NULL);
413 jsval *argv = JS_ARGV(cx,vp);
414#endif
415 jsdouble pars[3];
416 float *cc;
417
418 ADD_ROOT(cx,obj)
419 if(SM_method() == 2){
420 AnyNative *any;
421 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFColor,NULL,NULL)) == NULL){
422 printf( "AnyfNativeNew failed in SFColorConstr.\n");
423 return JS_FALSE;
424 }
425 if (!JS_SetPrivateFw(cx, obj, any)) {
426 printf( "JS_SetPrivate failed in SFColorConstr.\n");
427 return JS_FALSE;
428 }
429 cc = any->v->sfvec3f.c;
430 }else{
431 SFColorNative *ptr;
432
433 if ((ptr = (SFColorNative *) SFColorNativeNew()) == NULL) {
434 printf( "SFColorNativeNew failed in SFColorConstr.\n");
435 return JS_FALSE;
436 }
437
438 //if (!JS_DefineProperties(cx, obj, SFColorProperties)) {
439 // printf( "JS_DefineProperties failed in SFColorConstr.\n");
440 // return JS_FALSE;
441 //}
442
443 if (!JS_SetPrivateFw(cx, obj, ptr)) {
444 printf( "JS_SetPrivate failed in SFColorConstr.\n");
445 return JS_FALSE;
446 }
447 cc = ptr->v.c;
448 ptr->valueChanged = 1;
449 }
450 if (argc == 0) {
451 cc[0] = (float) 0.0;
452 cc[1] = (float) 0.0;
453 cc[2] = (float) 0.0;
454 } else if (JS_ConvertArguments(cx, argc, argv, "d d d", &(pars[0]), &(pars[1]), &(pars[2]))) {
455 cc[0] = (float) pars[0];
456 cc[1] = (float) pars[1];
457 cc[2] = (float) pars[2];
458 } else {
459 printf( "Invalid arguments for SFColorConstr.\n");
460 return JS_FALSE;
461 }
462 #ifdef JSVRMLCLASSESVERBOSE
463 printf("SFColorConstr: obj = %p args = %d, %f %f %f\n",
464 obj, argc,
465 cc[0], cc[1], cc[2]);
466 #endif
467
468
469#if JS_VERSION < 185
470 *rval = OBJECT_TO_JSVAL(obj);
471#else
472 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
473#endif
474
475 return JS_TRUE;
476}
477
478
479JSBool
480#if JS_VERSION < 185
481SFColorGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
482#elif JS_VERSION == 185
483SFColorGetProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp){
484#else
485SFColorGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
486 JSObject *obj = *hobj.address();
487 jsid iid = *hiid.address();
488 jsval *vp = hvp.address();
489
490#endif
491
492 jsdouble d;
493 float *cc;
494
495#if JS_VERSION >= 185
496 jsval id;
497 if (!JS_IdToValue(cx,iid,&id)) {
498 printf("JS_IdToValue failed in SFColorGetProperty.\n");
499 return JS_FALSE;
500 }
501#endif
502 if(SM_method()==2){
503 AnyNative *any;
504 if ((any = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
505 printf( "JS_GetPrivate failed in SFColorGetProperty.\n");
506 return JS_FALSE;
507 }
508 cc = any->v->sfcolor.c;
509 }else{
510 SFColorNative *ptr;
511
512 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
513 printf( "JS_GetPrivate failed in SFColorGetProperty.\n");
514 return JS_FALSE;
515 }
516 cc = ptr->v.c;
517 }
518 if (JSVAL_IS_INT(id)) {
519 switch (JSVAL_TO_INT(id)) {
520 case 0:
521 d = cc[0];
522 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
523 printf(
524 "JS_NewDouble failed for %f in SFColorGetProperty.\n",
525 d);
526 return JS_FALSE;
527 }
528 break;
529 case 1:
530 d = cc[1];
531 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
532 printf(
533 "JS_NewDouble failed for %f in SFColorGetProperty.\n",
534 d);
535 return JS_FALSE;
536 }
537 break;
538 case 2:
539 d = cc[2];
540 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
541 printf(
542 "JS_NewDouble failed for %f in SFColorGetProperty.\n",
543 d);
544 return JS_FALSE;
545 }
546 break;
547 }
548 }
549 return JS_TRUE;
550}
551
552JSBool
553#if JS_VERSION < 185
554SFColorSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
555#elif JS_VERSION == 185
556SFColorSetProperty(JSContext *cx, JSObject *obj, jsid iid, JSBool strict, jsval *vp){
557#else
558SFColorSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
559 JSObject *obj = *hobj.address();
560 jsid iid = *hiid.address();
561 jsval *vp = hvp.address();
562#endif
563
564 jsval _val;
565 float *cc;
566
567#if JS_VERSION >= 185
568 jsval id;
569 if (!JS_IdToValue(cx,iid,&id)) {
570 printf("JS_IdToValue failed in SFColorSetProperty.\n");
571 return JS_FALSE;
572 }
573#endif
574 if(SM_method() == 2){
575 AnyNative *any;
576 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
577 printf( "JS_GetPrivate failed in SFColorSetProperty.\n");
578 return JS_FALSE;
579 }
580 if(any->valueChanged)
581 (*any->valueChanged)++;
582 cc = any->v->sfcolor.c;
583 }else{
584 SFColorNative *ptr;
585
586 if ((ptr = (SFColorNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
587 printf( "JS_GetPrivate failed in SFColorSetProperty.\n");
588 return JS_FALSE;
589 }
590 ptr->valueChanged++;
591 #ifdef JSVRMLCLASSESVERBOSE
592 printf("SFColorSetProperty: obj = %p, id = %d, valueChanged = %d\n",
593 obj, JSVAL_TO_INT(id), ptr->valueChanged);
594 #endif
595 cc = ptr->v.c;
596 }
597 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &_val)) {
598 printf( "JS_ConvertValue failed in SFColorSetProperty.\n");
599 return JS_FALSE;
600 }
601
602 if (JSVAL_IS_INT(id)) {
603 switch (JSVAL_TO_INT(id)) {
604 case 0:
605#if JS_VERSION < 185
606 cc[0] = (float) *JSVAL_TO_DOUBLE(_val);
607#else
608 cc[0] = (float) JSVAL_TO_DOUBLE(_val);
609#endif
610 break;
611 case 1:
612#if JS_VERSION < 185
613 cc[1] = (float) *JSVAL_TO_DOUBLE(_val);
614#else
615 cc[1] = (float) JSVAL_TO_DOUBLE(_val);
616#endif
617 break;
618 case 2:
619#if JS_VERSION < 185
620 cc[2] = (float) *JSVAL_TO_DOUBLE(_val);
621#else
622 cc[2] = (float) JSVAL_TO_DOUBLE(_val);
623#endif
624 break;
625
626 }
627 }
628 return JS_TRUE;
629}
630
631/* copy code from SFColorGetHSV if the spec ever decides to implement this. */
632JSBool
633#if JS_VERSION < 185
634SFColorRGBAGetHSV(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
635#else
636SFColorRGBAGetHSV(JSContext *cx, uintN argc, jsval *vp) {
637 JSObject *obj = JS_THIS_OBJECT(cx,vp);
638 jsval *argv = JS_ARGV(cx,vp);
639#endif
640
641
642 JSObject *_arrayObj;
643 jsdouble hue = 0, saturation = 0, value = 0;
644 jsval _v;
645
646 UNUSED(obj);
647 UNUSED(argc);
648 UNUSED(argv);
649 /* do conversion here!!! */
650
651 if ((_arrayObj = JS_NewArrayObject(cx, 0, NULL)) == NULL) {
652 printf( "JS_NewArrayObject failed in SFColorRGBAGetHSV.\n");
653 return JS_FALSE;
654 }
655
656 /* construct new double before conversion? */
657 JS_NewNumberValue(cx,hue,&_v); /* was: _v = DOUBLE_TO_JSVAL(&hue); */
658 if (!JS_SetElement(cx, _arrayObj, 0, &_v)) {
659 printf( "JS_SetElement failed for hue in SFColorRGBAGetHSV.\n");
660 return JS_FALSE;
661 }
662 JS_NewNumberValue(cx,saturation,&_v); /* was: _v = DOUBLE_TO_JSVAL(&saturation); */
663 if (!JS_SetElement(cx, _arrayObj, 1, &_v)) {
664 printf( "JS_SetElement failed for saturation in SFColorRGBAGetHSV.\n");
665 return JS_FALSE;
666 }
667 JS_NewNumberValue(cx,value,&_v); /* was: _v = DOUBLE_TO_JSVAL(&value); */
668 if (!JS_SetElement(cx, _arrayObj, 2, &_v)) {
669 printf( "JS_SetElement failed for value in SFColorRGBAGetHSV.\n");
670 return JS_FALSE;
671 }
672#if JS_VERSION < 185
673 *rval = OBJECT_TO_JSVAL(_arrayObj);
674#else
675 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_arrayObj));
676#endif
677
678 return JS_TRUE;
679}
680
681/* implement later?? Copy most of code from SFColorSetHSV if we require this */
682JSBool
683#if JS_VERSION < 185
684SFColorRGBASetHSV(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
685#else
686SFColorRGBASetHSV(JSContext *cx, uintN argc, jsval *vp) {
687 JSObject *obj = JS_THIS_OBJECT(cx,vp);
688 jsval *argv = JS_ARGV(cx,vp);
689#endif
690
691 jsdouble hue, saturation, value;
692 float *cc;
693
694 if(SM_method()==2){
695 AnyNative *ptr;
696 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
697 printf( "JS_GetPrivate failed in SFColorRGBAToString.\n");
698 return JS_FALSE;
699 }
700 cc = ptr->v->sfcolorrgba.c;
701 }else{
702 SFColorRGBANative *ptr;
703 if ((ptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, obj)) == NULL) {
704 printf( "JS_GetPrivate failed in SFColorRGBAToString.\n");
705 return JS_FALSE;
706 }
707 cc = ptr->v.c;
708 }
709 if (!JS_ConvertArguments(cx, argc, argv, "d d d",
710 &hue, &saturation, &value)) {
711 printf( "JS_ConvertArguments failed in SFColorRGBASetHSV.\n");
712 return JS_FALSE;
713 }
714
715 /* do conversion here!!! NOT DOING ANYTHING - BUG */
716
717#if JS_VERSION < 185
718 *rval = OBJECT_TO_JSVAL(obj);
719#else
720 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
721#endif
722
723 return JS_TRUE;
724}
725
726JSBool
727#if JS_VERSION < 185
728SFColorRGBAToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
729#else
730SFColorRGBAToString(JSContext *cx, uintN argc, jsval *vp) {
731 JSObject *obj = JS_THIS_OBJECT(cx,vp);
732 jsval *argv = JS_ARGV(cx,vp);
733#endif
734
735 JSString *_str;
736 char _buff[STRING];
737 float *cc;
738
739 UNUSED(argc);
740 UNUSED(argv);
741 if(SM_method()==2){
742 AnyNative *ptr;
743 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
744 printf( "JS_GetPrivate failed in SFColorRGBAToString.\n");
745 return JS_FALSE;
746 }
747 cc = ptr->v->sfcolorrgba.c;
748
749 }else{
750 SFColorRGBANative *ptr;
751 if ((ptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, obj)) == NULL) {
752 printf( "JS_GetPrivate failed in SFColorRGBAToString.\n");
753 return JS_FALSE;
754 }
755 cc = ptr->v.c;
756 }
757 memset(_buff, 0, STRING);
758 sprintf(_buff, "%.9g %.9g %.9g %.9g",
759 cc[0], cc[1], cc[2],cc[3]);
760 _str = JS_NewStringCopyZ(cx, _buff);
761
762#if JS_VERSION < 185
763 *rval = STRING_TO_JSVAL(_str);
764#else
765 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
766#endif
767
768 return JS_TRUE;
769}
770
771JSBool
772#if JS_VERSION < 185
773SFColorRGBAAssign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
774#else
775SFColorRGBAAssign(JSContext *cx, uintN argc, jsval *vp) {
776 JSObject *obj = JS_THIS_OBJECT(cx,vp);
777 jsval *argv = JS_ARGV(cx,vp);
778 JSString *_id_jsstr;
779#endif
780
781 JSObject *_from_obj;
782 char *_id_str;
783
784 UNUSED(_id_str); // compiler warning mitigation
785 if(SM_method() == 2){
786 AnyNative *lhs, *rhs;
787 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
788 printf( "JS_GetPrivate failed for obj in SFColorRGBAAssign.\n");
789 return JS_FALSE;
790 }
791 //if (!JSVAL_IS_OBJECT(*vp))
792 if (!(*vp).isObject())
793 return JS_FALSE;
794 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
795 printf("JS_ConvertArguments failed in SFColorRGBAAssign. \n");
796 return JS_FALSE;
797 }
798 AnyNativeAssign(lhs,rhs);
799 }else{
800 SFColorRGBANative *ptr, *fptr;
801
802
803 if ((ptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, obj)) == NULL) {
804 printf( "JS_GetPrivate failed for obj in SFColorRGBAAssign.\n");
805 return JS_FALSE;
806 }
807
808 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFColorRGBAClass)
809
810#if JS_VERSION < 185
811 if (!JS_ConvertArguments(cx, argc, argv, "o s", &_from_obj, &_id_str)) {
812#else
813 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
814 _id_str = JS_EncodeString(cx,_id_jsstr);
815 } else {
816#endif
817 printf( "JS_ConvertArguments failed in SFColorRGBAAssign.\n");
818 return JS_FALSE;
819 }
820
821 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFColorRGBAClass)
822
823 if ((fptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
824 printf( "JS_GetPrivate failed for _from_obj in SFColorRGBAAssign.\n");
825 return JS_FALSE;
826 }
827 #ifdef JSVRMLCLASSESVERBOSE
828 printf("SFColorRGBAAssign: obj = %p, id = \"%s\", from = %p\n",
829 obj, _id_str, _from_obj);
830 #endif
831
832 SFColorRGBANativeAssign(ptr, fptr);
833 }
834#if JS_VERSION < 185
835 *rval = OBJECT_TO_JSVAL(obj);
836#else
837 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
838#endif
839
840 return JS_TRUE;
841}
842
843JSBool
844#if JS_VERSION < 185
845SFColorRGBAConstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
846#else
847SFColorRGBAConstr(JSContext *cx, uintN argc, jsval *vp) {
848 JSObject *obj = JS_NewObject(cx,&SFColorRGBAClass,NULL,NULL);
849 jsval *argv = JS_ARGV(cx,vp);
850#endif
851 float *cc;
852 jsdouble pars[4];
853
854 ADD_ROOT(cx,obj)
855 if(SM_method() == 2){
856 AnyNative *any;
857 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFColorRGBA,NULL,NULL)) == NULL){
858 printf( "AnyfNativeNew failed in SFColorRGBAConstr.\n");
859 return JS_FALSE;
860 }
861 if (!JS_SetPrivateFw(cx, obj, any)) {
862 printf( "JS_SetPrivate failed in SFColorRGBAConstr.\n");
863 return JS_FALSE;
864 }
865 cc = any->v->sfvec4f.c;
866 }else{
867 SFColorRGBANative *ptr;
868
869 if ((ptr = (SFColorRGBANative *) SFColorNativeNew()) == NULL) {
870 printf( "SFColorRGBANativeNew failed in SFColorConstr.\n");
871 return JS_FALSE;
872 }
873
874 //if (!JS_DefineProperties(cx, obj, SFColorRGBAProperties)) {
875 // printf( "JS_DefineProperties failed in SFColorRGBAConstr.\n");
876 // return JS_FALSE;
877 //}
878
879 if (!JS_SetPrivateFw(cx, obj, ptr)) {
880 printf( "JS_SetPrivate failed in SFColorRGBAConstr.\n");
881 return JS_FALSE;
882 }
883 cc = ptr->v.c;
884 ptr->valueChanged = 1;
885
886 }
887 if (argc == 0) {
888 cc[0] = (float) 0.0;
889 cc[1] = (float) 0.0;
890 cc[2] = (float) 0.0;
891 cc[3] = (float) 0.0;
892 } else if (JS_ConvertArguments(cx, argc, argv, "d d d d",
893 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]))) {
894 cc[0] = (float) pars[0];
895 cc[1] = (float) pars[1];
896 cc[2] = (float) pars[2];
897 cc[3] = (float) pars[3];
898 } else {
899 printf( "Invalid arguments for SFColorRGBAConstr.\n");
900 return JS_FALSE;
901 }
902
903
904
905 #ifdef JSVRMLCLASSESVERBOSE
906 printf("SFColorRGBAConstr: obj = %p %u args, %f %f %f %f\n",
907 obj, argc,
908 cc[0], cc[1], cc[2],cc[3]);
909 #endif
910#if JS_VERSION < 185
911 *rval = OBJECT_TO_JSVAL(obj);
912#else
913 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
914#endif
915
916 return JS_TRUE;
917}
918
919JSBool
920#if JS_VERSION < 185
921SFColorRGBAGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
922#elif JS_VERSION == 185
923SFColorRGBAGetProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp){
924 //jsval id;
925#else
926SFColorRGBAGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
927 JSObject *obj = *hobj.address();
928 jsid iid = *hiid.address();
929 jsval *vp = hvp.address();
930 //jsval id = JS_NumberValue(0.0); = INT_TO_JSVAL(0)
931#endif
932
933 jsdouble d;
934 float *cc;
935
936#if JS_VERSION >= 185
937 jsval id;
938 if (!JS_IdToValue(cx,iid,&id)) {
939 printf("JS_IdToValue failed in SFColorRGBAGetProperty.\n");
940 return JS_FALSE;
941 }
942#endif
943
944 if(SM_method()==2){
945 AnyNative *any;
946 if ((any = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
947 printf( "JS_GetPrivate failed in SFColorRGBAGetProperty.\n");
948 return JS_FALSE;
949 }
950 cc = any->v->sfcolorrgba.c;
951 }else{
952 SFColorRGBANative *ptr;
953 if ((ptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, obj)) == NULL) {
954 printf( "JS_GetPrivate failed in SFColorRGBAGetProperty.\n");
955 return JS_FALSE;
956 }
957 cc = ptr->v.c;
958 }
959 if (JSVAL_IS_INT(id)) {
960 int kk = 1;
961 switch (JSVAL_TO_INT(id)) {
962 case 0:
963 d = cc[0];
964 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
965 printf(
966 "JS_NewDouble failed for %f in SFColorRGBAGetProperty.\n",
967 d);
968 return JS_FALSE;
969 }
970 break;
971 case 1:
972 d = cc[1];
973 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
974 printf(
975 "JS_NewDouble failed for %f in SFColorRGBAGetProperty.\n",
976 d);
977 return JS_FALSE;
978 }
979 break;
980 case 2:
981 d = cc[2];
982 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
983 printf(
984 "JS_NewDouble failed for %f in SFColorRGBAGetProperty.\n",
985 d);
986 return JS_FALSE;
987 }
988 break;
989 case 3:
990 d = cc[3];
991 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
992 printf(
993 "JS_NewDouble failed for %f in SFColorRGBAGetProperty.\n",
994 d);
995 return JS_FALSE;
996 }
997 break;
998 }
999 }
1000 return JS_TRUE;
1001}
1002
1003JSBool
1004#if JS_VERSION < 185
1005SFColorRGBASetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
1006#elif JS_VERSION == 185
1007SFColorRGBASetProperty(JSContext *cx, JSObject *obj, jsid iid, JSBool strict, jsval *vp){
1008#else
1009SFColorRGBASetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
1010 JSObject *obj = *hobj.address();
1011 jsid iid = *hiid.address();
1012 jsval *vp = hvp.address();
1013#endif
1014
1015 jsval _val;
1016 float *cc;
1017
1018#if JS_VERSION >= 185
1019 jsval id;
1020 if (!JS_IdToValue(cx,iid,&id)) {
1021 printf("JS_IdToValue failed in SFColorRGBASetProperty.\n");
1022 return JS_FALSE;
1023 }
1024#endif
1025 if(SM_method() == 2){
1026 AnyNative *any;
1027 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1028 printf( "JS_GetPrivate failed in SFColorRGBASetProperty.\n");
1029 return JS_FALSE;
1030 }
1031 if(any->valueChanged)
1032 (*any->valueChanged)++;
1033 cc = any->v->sfcolorrgba.c;
1034 }else{
1035 SFColorRGBANative *ptr;
1036
1037 if ((ptr = (SFColorRGBANative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1038 printf( "JS_GetPrivate failed in SFColorRGBASetProperty.\n");
1039 return JS_FALSE;
1040 }
1041 ptr->valueChanged++;
1042 #ifdef JSVRMLCLASSESVERBOSE
1043 printf("SFColorRGBASetProperty: obj = %p, id = %d, valueChanged = %d\n",
1044 obj, JSVAL_TO_INT(id), ptr->valueChanged);
1045 #endif
1046 cc = ptr->v.c;
1047 }
1048 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &_val)) {
1049 printf( "JS_ConvertValue failed in SFColorRGBASetProperty.\n");
1050 return JS_FALSE;
1051 }
1052
1053 if (JSVAL_IS_INT(id)) {
1054 switch (JSVAL_TO_INT(id)) {
1055 case 0:
1056#if JS_VERSION < 185
1057 cc[0] = (float) *JSVAL_TO_DOUBLE(_val);
1058#else
1059 cc[0] = (float) JSVAL_TO_DOUBLE(_val);
1060#endif
1061 break;
1062 case 1:
1063#if JS_VERSION < 185
1064 cc[1] = (float) *JSVAL_TO_DOUBLE(_val);
1065#else
1066 cc[1] = (float) JSVAL_TO_DOUBLE(_val);
1067#endif
1068 break;
1069 case 2:
1070#if JS_VERSION < 185
1071 cc[2] = (float) *JSVAL_TO_DOUBLE(_val);
1072#else
1073 cc[2] = (float) JSVAL_TO_DOUBLE(_val);
1074#endif
1075 break;
1076 case 3:
1077#if JS_VERSION < 185
1078 cc[3] = (float) *JSVAL_TO_DOUBLE(_val);
1079#else
1080 cc[3] = (float) JSVAL_TO_DOUBLE(_val);
1081#endif
1082 break;
1083
1084 }
1085 }
1086 return JS_TRUE;
1087}
1088
1089JSBool
1090#if JS_VERSION < 185
1091SFImageToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1092#else
1093SFImageToString(JSContext *cx, uintN argc, jsval *vp) {
1094 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1095 jsval *argv = JS_ARGV(cx,vp);
1096 jsval rval;
1097 JSBool retval;
1098#endif
1099 char buff[STRING];
1100 JSString* _str;
1101
1102 #ifdef JSVRMLCLASSESVERBOSE
1103 printf("SFImageToString: obj = %p, %u args\n", obj, argc);
1104 #endif
1105
1106 UNUSED(argc);
1107 UNUSED(argv);
1108
1109#if JS_VERSION < 185
1110 return doMFToString(cx, obj, "SFImage", rval);
1111#else
1112 if (SM_method() == 2) {
1113 AnyNative* ptr;
1114 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
1115 printf("JS_GetPrivate failed in SFVec3fToString.\n");
1116 return JS_FALSE;
1117 }
1118 int *cc = ptr->v->sfimage.arr.p;
1119 int nn = ptr->v->sfimage.arr.n;
1120 int* whc = ptr->v->sfimage.whc;
1121 memset(buff, 0, STRING);
1122 sprintf(buff, "%d %d %d ",
1123 whc[0], whc[1], whc[2]);
1124 char sbuf[10];
1125 for (int i = 0; i < nn; i++) {
1126 sprintf(sbuf, "%#x ", cc[i]);
1127 strcat(buff, sbuf);
1128 }
1129 _str = JS_NewStringCopyZ(cx, buff);
1130
1131 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
1132 retval = JS_TRUE;
1133 }
1134 else {
1135 retval = doMFToString(cx, obj, "SFImage", &rval);
1136 JS_SET_RVAL(cx, vp, rval);
1137 }
1138 return retval;
1139#endif
1140}
1141
1142JSBool
1143#if JS_VERSION < 185
1144SFImageAssign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1145#else
1146SFImageAssign(JSContext *cx, uintN argc, jsval *vp) {
1147 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1148 jsval *argv = JS_ARGV(cx,vp);
1149 jsval rval;
1150 JSBool retval;
1151#endif
1152
1153 #ifdef JSVRMLCLASSESVERBOSE
1154 printf("SFImageAssign: obj = %p, %u args\n", obj, argc);
1155 #endif
1156
1157#if JS_VERSION < 185
1158 return _standardMFAssign (cx, obj, argc, argv, rval, &SFImageClass,FIELDTYPE_SFImage);
1159#else
1160 retval = _standardMFAssign (cx, obj, argc, argv, &rval, &SFImageClass,FIELDTYPE_SFImage);
1161 JS_SET_RVAL(cx,vp,rval);
1162 return retval;
1163#endif
1164}
1165
1166JSBool
1167#if JS_VERSION < 185
1168SFImageConstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1169#else
1170SFImageConstr(JSContext *cx, uintN argc, jsval *vp) {
1171 JSObject *obj = JS_NewObject(cx,&SFImageClass,NULL,NULL);
1172 jsval *argv = JS_ARGV(cx,vp);
1173#endif
1174 unsigned int i;
1175 jsval mv;
1176 int param[3];
1177 int expectedSize;
1178 union anyVrml* anyv;
1179
1180
1181
1182 ADD_ROOT(cx,obj)
1183
1184 #ifdef JSVRMLCLASSESVERBOSE
1185 printf("SFImageConstr: obj = %p, %u args\n", obj, argc);
1186 #endif
1187
1188 /* SFImage really only has the valueChanged flag. */
1189 if(SM_method()==2){
1190 AnyNative *ptr;
1191 if ((ptr = (AnyNative *) AnyNativeNew(FIELDTYPE_SFImage,NULL,NULL)) == NULL) {
1192 printf( "SFImageNativeNew failed in SFImageConstr.\n");
1193 return JS_FALSE;
1194 }
1195
1196 if (!JS_SetPrivateFw(cx, obj, ptr)) {
1197 printf( "JS_SetPrivate failed in SFImageConstr.\n");
1198 return JS_FALSE;
1199 }
1200 //if(ptr->valueChanged)
1201 // (*ptr->valueChanged) = 1;
1202 anyv = ptr->v;
1203
1204
1205 }else{
1206 SFImageNative *ptr;
1207 if ((ptr = (SFImageNative *) SFImageNativeNew()) == NULL) {
1208 printf( "SFImageNativeNew failed in SFImageConstr.\n");
1209 return JS_FALSE;
1210 }
1211
1212 if (!JS_SetPrivateFw(cx, obj, ptr)) {
1213 printf( "JS_SetPrivate failed in SFImageConstr.\n");
1214 return JS_FALSE;
1215 }
1216
1217 ptr->valueChanged = 1;
1218 }
1219 /* make this so that one can get the ".x", ".y", ".comp" and ".array" */
1220 //if (!JS_DefineProperties(cx, obj, SFImageProperties)) {
1221 // printf( "JS_DefineProperties failed in SFImageConstr.\n");
1222 // return JS_FALSE;
1223 //}
1224
1225 /* null image. Make this [0, 0, 0] NOTE - there are only 3 elements now! */
1226 if (!argc) {
1227 /* expect arguments to be number, number, number, mfint32 */
1228 if (SM_method() == 2) {
1229 anyv->sfimage.arr.n = 0;
1230 anyv->sfimage.arr.p = NULL;
1231 anyv->sfimage.whc[0] = anyv->sfimage.whc[1] = anyv->sfimage.whc[2] = 0;
1232 }else {
1233 mv = INT_TO_JSVAL(0);
1234 for (i = 0; i < 4; i++) {
1235 if (i == 3) {
1236#if JS_VERSION < 185
1237 MFInt32Constr(cx, obj, 0, NULL, &mv);
1238#else
1239 /* note - old default constructor call allocates a new obj and assigns to mv,
1240 * but calling fn directly may not actually do that. It seems illegal to call
1241 * the constructor of another object directly on this object, and then feed it
1242 * as a proprety of itself, but since that's what the old code did (and it seems
1243 * to work), am keeping it as-is.
1244 *
1245 * I would -expect- that 'JS_NewObject(cx,&MFInt32Class,NULL,NULL)' should be
1246 * used instead of 'obj' below.... */
1247 MFInt32ConstrInternals(cx, obj, 0, NULL, &mv);
1248#endif
1249 }
1250 if (!JS_DefineElement(cx, obj, (jsuint)i, mv, JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB6, JSPROP_ENUMERATE)) {
1251 printf("JS_DefineElement failed for arg %d in SFImageConstr.\n", i);
1252 return JS_FALSE;
1253 }
1254 }
1255 DEFINE_LENGTH(cx, obj, 4)
1256 }
1257#if JS_VERSION >= 185
1258 /* returning with success here, so must set rval to return the object we just finished creating */
1259 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
1260#endif
1261 return JS_TRUE;
1262 }
1263
1264 /* ok, ok. There are some parameters here. There had better be 4, or else... */
1265 if ((argc != 4) && (argc != 3)) {
1266 printf ("SFImageConstr, expect 4 parameters, got %d\n",argc);
1267 return JS_FALSE;
1268 }
1269
1270
1271 //DEFINE_LENGTH(cx,obj,argc)
1272
1273 /* expect arguments to be number, number, number, mfint32 */
1274 for (i=0; i<3; i++) {
1275 /* printf ("looking at parameter %d\n",i); */
1276 if (JSVAL_IS_INT(argv[i])) {
1277 /* printf ("parameter is a number\n"); */
1278 //param[i] = JSVAL_TO_INT(argv[i]);
1279 JS_ValueToInt32(cx, argv[i], &param[i]);
1280 /* printf ("param is %d\n",param[i]); */
1281 } else {
1282 printf ("SFImageConstr: parameter %d is not a number\n",i);
1283 return JS_FALSE;
1284 }
1285 }
1286 /* now look at the MFInt32 array, and tack it on here */
1287 expectedSize = param[0] * param[1];
1288
1289
1290 /* the third number should be in the range of 0-4 inclusive (number of components in image) */
1291 if ((param[2]<0) || (param[2]>4)) {
1292
1293 printf ("SFImageConstr: with size > 0, comp must be between 1 and 4 inclusive, got %d\n",param[2]);
1294 return JS_FALSE;
1295 }
1296
1297 /* case 1 of null initializer */
1298 if ((expectedSize == 0) && (param[2] != 0)) {
1299 printf ("SFImageConstr: with x and y equal to zero, comp must be zero\n");
1300 return JS_FALSE;
1301 }
1302 /* case 2 of null initializer */
1303 if ((expectedSize != 0) && (param[2] == 0)) {
1304 printf ("SFImageConstr: with x and y not zero, comp must be non-zero\n");
1305 return JS_FALSE;
1306 }
1307 /* worry about the MFInt32 array. Note that we copy the object pointer here. Should
1308 we copy ALL of the elements, or just the object itself?? */
1309
1310 if (argc == 4 && SM_method() != 2) {
1311 #ifdef JSVRMLCLASSESVERBOSE
1312 printJSNodeType(cx,JSVAL_TO_OBJECT(argv[3]));
1313 #endif
1314 CHECK_CLASS(cx, JSVAL_TO_OBJECT(argv[3]), NULL, __FUNCTION__, MFInt32Class)
1315 if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(argv[3]), MF_LENGTH_FIELD, &mv)) {
1316 printf("JS_GetProperty failed for MFInt32 length in SFImageConstr\n");
1317 return JS_FALSE;
1318 }
1319 if (expectedSize != JSVAL_TO_INT(mv)) {
1320 printf("SFImageConstr: warning expected %d elements in image data, got %d\n", expectedSize, JSVAL_TO_INT(mv));
1321 //return JS_FALSE;
1322 }
1323 }
1324
1325 /* parameters are ok - just save them now in the new object. */
1326 if (SM_method() == 2) {
1327 int* cc = NULL;
1328 int nn = 0;
1329 if (argc == 4) {
1330 //JS_GetPrivate
1331 AnyNative* ptr;
1332 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[3]))) == NULL) {
1333 printf("JS_GetPrivate failed in SFImageConstr get MFInt32.\n");
1334 return JS_FALSE;
1335 }
1336 cc = ptr->v->mfint32.p;
1337 nn = ptr->v->mfint32.n;
1338 }
1339 int newsize;
1340 newsize = sizeof(int) * upper_power_of_two(expectedSize); //newsize in bytes
1341 anyv->sfimage.arr.p = MALLOC(int*, newsize);
1342 memset(anyv->sfimage.arr.p, 0, newsize);
1343 anyv->sfimage.arr.n = expectedSize;
1344 anyv->sfimage.whc[0] = param[0];
1345 anyv->sfimage.whc[1] = param[1];
1346 anyv->sfimage.whc[2] = param[2];
1347 int ncopy = expectedSize > nn ? nn : expectedSize; //assume balance are memset 0
1348 for (i = 0; i < ncopy; i++) {
1349 anyv->sfimage.arr.p[i] = cc[i];
1350 }
1351
1352 } else {
1353 for (i = 0; i < argc; i++) {
1354 if (!JS_DefineElement(cx, obj, (jsint)i, argv[i], JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB6, JSPROP_ENUMERATE)) {
1355 printf("JS_DefineElement failed for arg %d in SFImageConstr.\n", i);
1356 return JS_FALSE;
1357 }
1358 }
1359 }
1360
1361 /* if we are here, we must have had some success... */
1362#if JS_VERSION < 185
1363 *rval = OBJECT_TO_JSVAL(obj);
1364#else
1365 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
1366#endif
1367 return JS_TRUE;
1368}
1369
1370JSBool
1371SFImageAddProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp) {
1372 return doMFAddProperty(cx, obj, id, vp, "SFImage"); //FIXME: is this ok ??? "SFImageAddProperty");
1373}
1374
1375#if JS_VERSION < 186
1376JSBool SFImageGetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp) {
1377#else
1378JSBool SFImageGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
1379 JSObject *obj = *hobj.address();
1380 jsid iid = *hiid.address();
1381 jsval *vp = hvp.address();
1382#endif
1383 int nn, * cc, *whc;
1384 jsval id;
1385 if (!JS_IdToValue(cx, iid, &id)) {
1386 printf("JS_IdToValue failed in SFVec3fGetProperty.\n");
1387 return JS_FALSE;
1388 }
1389
1390 if (SM_method() == 2) {
1391 AnyNative* any;
1392 if ((any = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
1393 printf("JS_GetPrivate failed in SFImageGetProperty.\n");
1394 return JS_FALSE;
1395 }
1396 cc = any->v->sfimage.arr.p;
1397 nn = any->v->sfimage.arr.n;
1398 whc = any->v->sfimage.whc;
1399 }
1400 //else {
1401 // SFVec3fNative* ptr;
1402 // if ((ptr = (SFVec3fNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
1403 // printf("JS_GetPrivate failed in SFVec3fGetProperty.\n");
1404 // return JS_FALSE;
1405 // }
1406 // cc = ptr->v.c;
1407 //}
1408 if (JSVAL_IS_INT(id)) {
1409 int d;
1410 switch (JSVAL_TO_INT(id)) {
1411 case 0: //width
1412 d = whc[0];
1413 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
1414 printf("JS_NewNumberValue failed for %d in SFImageGetProperty.\n", d);
1415 return JS_FALSE;
1416 }
1417 break;
1418 case 1: //height
1419 d = whc[1];
1420 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
1421 printf("JS_NewNumberValue failed for %d in SFImageGetProperty.\n", d);
1422 return JS_FALSE;
1423 }
1424 break;
1425 case 2: //comp
1426 d = whc[2];
1427 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
1428 printf("JS_NewNumberValue failed for %d in SFImageGetProperty.\n",d);
1429 return JS_FALSE;
1430 }
1431 break;
1432 case 3: //arr
1433 JSObject * obj2 = JS_NewObject(cx, &MFInt32Class, NULL, NULL);
1434 ADD_ROOT(cx, obj2)
1435 AnyNative* ptr;
1436 if ((ptr = (AnyNative*)AnyNativeNew(FIELDTYPE_MFInt32, NULL, NULL)) == NULL) {
1437 printf("MFInt32NativeNew failed in SFImageGetter.\n");
1438 return JS_FALSE;
1439 }
1440 if (!JS_SetPrivateFw(cx, obj2, ptr)) {
1441 printf("JS_SetPrivate failed in SFImageGetter.\n");
1442 return JS_FALSE;
1443 }
1444 ptr->v->mfint32.n = nn;
1445 ptr->v->mfint32.p = cc;
1446 ptr->gc = 0;
1447 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj2));
1448 break;
1449
1450 }
1451 return JS_TRUE;
1452 }
1453 else {
1454#ifdef JSVRMLCLASSESVERBOSE
1455 printf("SFVec3fGetProperty, id is NOT an int...\n");
1456#endif
1457 }
1458 return JS_TRUE;
1459 //return _standardMFGetProperty(cx, obj, id, vp, "_FreeWRL_Internal = 0", FIELDTYPE_SFImage); //FIXME: is this ok ??? "SFImage");
1460}
1461
1462
1463JSBool
1464#if JS_VERSION < 185
1465SFImageSetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp) {
1466#elif JS_VERSION == 185
1467SFImageSetProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp){
1468#else
1469SFImageSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
1470 JSObject *obj = *hobj.address();
1471 jsid id = *hiid.address();
1472 jsval *vp = hvp.address();
1473#endif
1474 return doMFSetProperty(cx, obj, id, vp, FIELDTYPE_SFImage);
1475}
1476
1477/**********************************************************************************/
1478
1479
1480/* returns a string rep of the pointer to the node in memory */
1481JSBool
1482#if JS_VERSION < 185
1483SFNodeValueOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1484#else
1485SFNodeValueOf(JSContext *cx, uintN argc, jsval *vp) {
1486 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1487 jsval *argv = JS_ARGV(cx,vp);
1488 jsval rvalinst;
1489 jsval *rval = &rvalinst;
1490#endif
1491 SFNodeNative *ptr;
1492 void* handle;
1493
1494 UNUSED(argc);
1495 UNUSED(argv);
1496 if(SM_method() == 2){
1497 AnyNative *nany;
1498 if ((nany = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1499 printf( "JS_GetPrivate failed in SFNodeToString.\n");
1500 return JS_FALSE;
1501 }
1502 handle = nany->v->sfnode;
1503 }else{
1504 #ifdef JSVRMLCLASSESVERBOSE
1505 printf ("SFNODETOSTRING\n");
1506 #endif
1507 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1508 printf( "JS_GetPrivate failed in SFNodeToString.\n");
1509 return JS_FALSE;
1510 }
1511 handle = ptr->handle;
1512 }
1513 /* get the string from creation, and return it. */
1514
1515 /* used to do:
1516 *rval = INT_TO_JSVAL(ptr->handle);
1517
1518 but we have 64 bit pointers in OSX now, and ints are 32 bits. so...
1519 we convert to a double, and hope that it is still correct (seems to be ok
1520 32 and 64 bits - tests/46.wrl will use this path, btw */
1521
1522 {
1523 jsdouble nv;
1524 char tmpline[100];
1525 sprintf (tmpline,"%p",handle);
1526 /* sprintf (tmpline,"%ld",ptr->handle); */
1527
1528 /* printf ("pointer to long int :%s:\n",tmpline); */
1529
1530 nv = strtod(tmpline,NULL);
1531 /* printf ("double is %lf\n",nv); */
1532
1533 /* printf ("nv %lf, handle %lu and %p\n",nv,ptr->handle,ptr->handle); */
1534 if (!JS_NewNumberValue(cx, nv, rval)) {
1535 ConsoleMessage ("Conversion issue in SFNodeToString");
1536 }
1537 }
1538
1539
1540 #ifdef JSVRMLCLASSESVERBOSE
1541 printf ("SFNodeToString, handle %p ",ptr->handle);
1542 printf ("SFNodeToString, handle as unsignned %u ",(unsigned int)ptr->handle);
1543 if (ptr->handle != NULL) {
1544 printf (" (%s) ", stringNodeType (((struct X3D_Node *)ptr->handle)->_nodeType));
1545 }
1546 printf ("string \"%s\"\n",ptr->X3DString);
1547 #endif
1548
1549#if JS_VERSION >= 185
1550 JS_SET_RVAL(cx,vp,*rval);
1551#endif
1552 return JS_TRUE;
1553}
1554
1555JSBool
1556#if JS_VERSION < 185
1557SFNodeToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1558#else
1559SFNodeToString(JSContext *cx, uintN argc, jsval *vp) {
1560 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1561 jsval *argv = JS_ARGV(cx,vp);
1562 jsval rvalinst;
1563 jsval *rval = &rvalinst;
1564#endif
1565 JSString *_str;
1566 SFNodeNative *ptr;
1567 void *handle;
1568
1569 UNUSED(argc);
1570 UNUSED(argv);
1571 #ifdef JSVRMLCLASSESVERBOSE
1572 printf ("SFNODETOSTRING\n");
1573 #endif
1574 if(SM_method() == 2){
1575 AnyNative *nany;
1576 if ((nany = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1577 printf( "JS_GetPrivate failed in SFNodeToString.\n");
1578 return JS_FALSE;
1579 }
1580 handle = nany->v->sfnode;
1581 }else{
1582
1583 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1584 printf( "JS_GetPrivate failed in SFNodeToString.\n");
1585 return JS_FALSE;
1586 }
1587 handle = ptr->handle;
1588 }
1589
1590 /* get the string from creation, and return it. */
1591
1592 /* used to do:
1593 *rval = INT_TO_JSVAL(ptr->handle);
1594
1595 but we have 64 bit pointers in OSX now, and ints are 32 bits. so...
1596 we convert to a double, and hope that it is still correct (seems to be ok
1597 32 and 64 bits - tests/46.wrl will use this path, btw */
1598
1599 {
1600 jsdouble nv;
1601 char buff[STRING];
1602 memset(buff, 0, STRING);
1603 sprintf (buff,"_%p_",handle);
1604 /* sprintf (tmpline,"%ld",ptr->handle); */
1605
1606 /* printf ("pointer to long int :%s:\n",tmpline); */
1607 ADD_ROOT(cx,_str)
1608 _str = JS_NewStringCopyZ(cx, buff);
1609
1610#if JS_VERSION < 185
1611 *rval = STRING_TO_JSVAL(_str);
1612#else
1613 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
1614#endif
1615
1616 REMOVE_ROOT (cx,_str)
1617
1618 }
1619
1620 return JS_TRUE;
1621}
1622
1623
1624
1625JSBool
1626#if JS_VERSION < 185
1627SFNodeAssign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1628#else
1629SFNodeAssign(JSContext *cx, uintN argc, jsval *vp) {
1630 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1631 jsval *argv = JS_ARGV(cx,vp);
1632 JSString *_id_jsstr;
1633#endif
1634
1635 JSObject *_from_obj;
1636 SFNodeNative *fptr, *ptr;
1637 char *_id_str;
1638
1639 UNUSED(_id_str); // compiler warning mitigation
1640 if(SM_method() == 2){
1641 AnyNative *lhs, *rhs;
1642 //if (JSVAL_IS_OBJECT(*vp)) {
1643 if ((*vp).isObject()){
1644 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) != NULL) {
1645 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) != NULL) {
1646 AnyNativeAssign(lhs,rhs);
1647 }
1648 }
1649 }
1650 }else{
1651
1652
1653 /* unsigned int toptr; */
1654 #ifdef JSVRMLCLASSESVERBOSE
1655 printf ("start of SFNodeAssign argc %d\n",argc);
1656 #endif
1657
1658 /* are we saving to a SFNode? */
1659 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFNodeClass)
1660
1661 /* get the pointer to the internal stuff */
1662 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1663 printf( "JS_GetPrivate failed for obj in SFNodeAssign.\n");
1664 return JS_FALSE;
1665 }
1666
1667 /* get the from, and the string */
1668 #ifdef JSVRMLCLASSESVERBOSE
1669 printf ("SFNodeAssign, we have %d and %d\n",(int)argv[0], (int)argv[1]);
1670 #endif
1671
1672#if JS_VERSION < 185
1673 if (!JS_ConvertArguments(cx, argc, argv, "o s", &_from_obj, &_id_str)) {
1674#else
1675 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
1676 _id_str = JS_EncodeString(cx,_id_jsstr);
1677 } else {
1678#endif
1679 printf( "JS_ConvertArguments failed in SFNodeAssign.\n");
1680 return JS_FALSE;
1681 }
1682 if (_from_obj != NULL) {
1683 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFNodeClass)
1684
1685 if ((fptr = (SFNodeNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
1686 printf( "JS_GetPrivate failed for _from_obj in SFNodeAssign.\n");
1687 return JS_FALSE;
1688 }
1689 #ifdef JSVRMLCLASSESVERBOSE
1690 printf("SFNodeAssign: obj = %p, id = \"%s\", from = %p\n",
1691 obj, _id_str, _from_obj);
1692 #endif
1693 } else { fptr = NULL; }
1694
1695 /* assign this internally */
1696 if (!SFNodeNativeAssign(ptr, fptr)) {
1697 printf( "SFNodeNativeAssign failed in SFNodeAssign.\n");
1698 return JS_FALSE;
1699 }
1700 } //SMmethod == 2
1701#if JS_VERSION < 185
1702 *rval = OBJECT_TO_JSVAL(obj);
1703#else
1704 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
1705#endif
1706
1707 #ifdef JSVRMLCLASSESVERBOSE
1708 printf ("end of SFNodeAssign\n");
1709 #endif
1710 return JS_TRUE;
1711}
1712
1713
1714// https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/1.8.5
1715// when adding a node.function() don't forget to add a check in SFNodeGetProperty for "function"
1716JSBool
1717#if JS_VERSION < 185
1718SFNodeEquals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1719 jsval rvalinst;
1720 jsval *rval = &rvalinst;
1721#else
1722SFNodeEquals(JSContext *cx, uintN argc, jsval *vp) {
1723 JSObject *obj = JS_THIS_OBJECT(cx,vp);
1724 jsval *argv = JS_ARGV(cx,vp);
1725#endif
1726 int iret;
1727 JSObject *_from_obj;
1728 SFNodeNative *ptr, *fptr;
1729
1730 if(SM_method() == 2){
1731 AnyNative *lhs, *rhs;
1732 iret = 0;
1733 //if (JSVAL_IS_OBJECT(*vp)) {
1734 if ((*vp).isObject()) {
1735 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) != NULL) {
1736 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) != NULL) {
1737 iret = lhs->v->sfnode == rhs->v->sfnode ? 1 : 0;
1738 }
1739 }
1740 }
1741 }else{
1742
1743 //JS_SET_RVAL(cx,vp,BOOLEAN_TO_JSVAL(1)); //JS_TRUE);
1744 //return JS_TRUE;
1745 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1746 printf( "JS_GetPrivate failed in SFNodeNative.\n");
1747 return JS_FALSE;
1748 }
1749 if (!JS_ConvertArguments(cx, argc, argv, "o",
1750 &_from_obj)) {
1751 printf( "JS_ConvertArguments failed in SFNodeNative.\n");
1752 return JS_FALSE;
1753 }
1754
1755
1756 if (_from_obj != NULL) {
1757 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFNodeClass)
1758
1759 if ((fptr = (SFNodeNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
1760 printf( "JS_GetPrivate failed for _from_obj in SFNodeAssign.\n");
1761 return JS_FALSE;
1762 }
1763 #ifdef JSVRMLCLASSESVERBOSE
1764 printf("SFNodeAssign: obj = %p, id = \"%s\", from = %p\n",
1765 obj, _id_str, _from_obj);
1766 #endif
1767 } else { fptr = NULL; }
1768
1769
1770 /* assign this internally */
1771 iret = SFNodeNativeEquals(ptr, fptr);
1772 } //SM_method == 2
1773#if JS_VERSION < 185
1774 *rval = BOOLEAN_TO_JSVAL(iret);
1775#else
1776 JS_SET_RVAL(cx,vp,BOOLEAN_TO_JSVAL(iret));
1777#endif
1778
1779 #ifdef JSVRMLCLASSESVERBOSE
1780 printf ("end of SFNodeEqual\n");
1781 #endif
1782
1783 return JS_TRUE;
1784}
1785
1786
1787
1788/* define JSVRMLCLASSESVERBOSE */
1789
1790JSBool
1791#if JS_VERSION < 185
1792SFNodeConstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1793#else
1794SFNodeConstr(JSContext *cx, uintN argc, jsval *vp) {
1795 JSObject *obj = JS_NewObject(cx,&SFNodeClass,NULL,NULL);
1796 jsval *argv = JS_ARGV(cx,vp);
1797#endif
1798 /*
1799 X3D ecmascript specs:
1800 http://www.web3d.org/files/specifications/19777-1/V3.0/Part1/functions.html#SFNodeInstanceCreationFunction
1801 "7.6.5.2 Instance creation function
1802 This object cannot be directly instantiated"
1803 That means there should never be myNode = new SFNode(); or SFNode('string') or SFNode('0x12345');
1804 X3DScene Browser.createX3DFromString(String x3dSyntax)
1805
1806 VRML vrmlscript specs:
1807 http://www.web3d.org/x3d/specifications/vrml/ISO-IEC-14772-VRML97/part1/javascript.html#SFNode
1808 sfNodeObjectName = new SFNode(String vrmlstring);
1809 MFNode Browser.createVrmlFromString( String vrmlSyntax )
1810
1811 The support below is for VRML specs SFNode(vrmlstring),
1812 plus 2 freewrl-specific techniques:
1813 sfn = new SFNode(oldSFNode)
1814 sfn = new SFNode('0x12345'); //ptr to another node
1815
1816 - a char* ptr->X3Dstring holding vrmlstring from a previous new SFNode(string)
1817 is dragged around with an SFNode, and when new SFNode(old) it resends the
1818 string to the parser to create the new node.
1819 - this should fail when oldnode wasn't created with new SFNode(vrmlstring).
1820 (a future broto version would/could possibly deep copy the binary oldnode,
1821 elliminating the need for saving/holding the X3DString, and allowing it to
1822 work even when the oldNode wasn't created with a new SFNode(vrmlstring) constructor call)
1823
1824 */
1825 SFNodeNative *newPtr;
1826 SFNodeNative *oldPtr;
1827
1828 struct X3D_Node *newHandle;
1829 JSString *myStr;
1830 char *cString;
1831
1832 /* unused struct X3D_Group *myGroup; */
1833
1834 ADD_ROOT(cx,obj)
1835 newHandle = NULL;
1836 cString = NULL;
1837
1838 #ifdef JSVRMLCLASSESVERBOSE
1839 printf ("Start of SFNodeConstr argc %d object %p\n",argc,obj);
1840 #endif
1841
1842 /* verify the argc */
1843 if (argc == 0) {
1844 newHandle = NULL;
1845 cString = STRDUP("SFNodeConstr from argc eq 0");
1846 } else if (argc == 1) {
1847 /* is this a string, or a number indicating a node? */
1848 myStr = JS_ValueToString(cx, argv[0]);
1849#if JS_VERSION < 185
1850 cString = JS_GetStringBytes(myStr);
1851#else
1852 cString = JS_EncodeString(cx,myStr);
1853#endif
1854 #ifdef JSVRMLCLASSESVERBOSE
1855 printf ("SFNodeConstr, argc =1l string %s\n",cString);
1856 #endif
1857
1858 /* this is either a memory pointer, or it is actual X3D text, or it is junk */
1859 //if (JSVAL_IS_OBJECT(argv[0])) {
1860 if (argv[0].isObject()) {
1861 /* myNode2 = new SFNode(myNode1); not in specs*/
1862 #ifdef JSVRMLCLASSESVERBOSE
1863 printf ("SFNodeConstr, cstring was an object\n");
1864 #endif
1865 if(SM_method() == 2){
1866 AnyNative *rhs;
1867 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
1868 #ifdef JSVRMLCLASSESVERBOSE
1869 printf( "JS_GetPrivate failed in SFNodeConstr.\n");
1870 #endif
1871 return JS_FALSE;
1872 }
1873
1874 newHandle = rhs->v->sfnode;
1875
1876 }else{
1877 if ((oldPtr = (SFNodeNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
1878 #ifdef JSVRMLCLASSESVERBOSE
1879 printf( "JS_GetPrivate failed in SFNodeConstr.\n");
1880 #endif
1881 return JS_FALSE;
1882 }
1883
1884 newHandle = oldPtr->handle;
1885 }
1886 if(SM_method() == 0)
1887 cString = STRDUP(oldPtr->X3DString);
1888
1889 } else {
1890 #ifdef JSVRMLCLASSESVERBOSE
1891 printf ("SFNodeConstr, cstring was NOT an object\n");
1892 #endif
1893
1894 /* check if the first character is numeric, if it is then assume a pointer */
1895 if (!((cString[0] >= 'A' && cString [0] <= 'Z')||(cString[0] >= 'a' && cString [0] <= 'z'))) {
1896 /* lets hope this is an initializer, like "new SFNode("0x100675790") */
1897 if (sscanf (cString,"%p",&newHandle) != 1) {
1898 ConsoleMessage ("expected pointer for Javascript SFNode constr, got :%s:",cString);
1899 newHandle = NULL;
1900 #ifdef JSVRMLCLASSESVERBOSE
1901 printf ("SFNodeConstr, expected pointer for Javascript SFNode constr, got :%s:\n",cString);
1902 } else {
1903 printf ("SFNodeConstr, got pointer for Javascript SFNode constr, :%p:\n",newHandle);
1904 #endif
1905 }
1906 } else {
1907 /* cannot be an initializer, must parse the string */
1908 /* myNode = new SFNode('Group{...}'); */
1909 /* try compiling this X3D code... */
1910 resource_item_t* res = resource_create_from_string(cString);
1911 //where put any script defined DEF names?
1912 // 1= throw-away Proto context 2) Script node parent x3d context (inline, scene, protobody)
1913 // they both tested working May 13, 2022 but with unknown side effects
1914 int defname_context_method = 2;
1915 if (defname_context_method == 1) {
1916 struct X3D_Proto* myProto = (struct X3D_Proto*)createNewX3DNode(NODE_Proto);
1917 res->whereToPlaceData = myProto;
1918 res->ectx = myProto;
1919 res->offsetFromWhereToPlaceData = (int)offsetof(struct X3D_Proto, __children);
1920 res->media_type = resm_vrml;
1921 res->parsed_request = strdup("From the EAI bootcamp of life ");
1922 parser_process_res_VRML_X3D(res);
1923 newHandle = X3D_NODE(myProto->__children.p[0]);
1924
1925 }
1926 else if(defname_context_method == 2) {
1927 struct X3D_Group* myGroup = (struct X3D_Group*)createNewX3DNode(NODE_Group);
1928 res->whereToPlaceData = myGroup;
1929 res->ectx = JS_GetContextPrivate(cx); //executionContext the script is in, stored using JS_SetContextPrivate
1930 res->offsetFromWhereToPlaceData = (int)offsetof(struct X3D_Group, children);
1931 res->media_type = resm_vrml;
1932 res->parsed_request = strdup("From the EAI bootcamp of life ");
1933 parser_process_res_VRML_X3D(res);
1934 newHandle = X3D_NODE(myGroup->children.p[0]);
1935
1936 }
1937 //res->media_type = resm_vrml;
1938 //res->parsed_request = strdup("From the EAI bootcamp of life ");
1939 //#ifdef JSVRMLCLASSESVERBOSE
1940 //printf ("SFNodeConstr, sending resource to parser\n");
1941 //#endif
1943 //#ifdef JSVRMLCLASSESVERBOSE
1944 //printf ("SFNodeConstr, waiting on resource\n");
1945 //#endif
1947
1948 //#ifdef JSVRMLCLASSESVERBOSE
1949 //printf ("SFNodeConstr we have created %d nodes\n",myGroup->children.n);
1950 //#endif
1951
1957 //parser_process_res_VRML_X3D(res);
1958 //if(defname_context_method == 1)
1959 // newHandle = X3D_NODE(myProto->__children.p[0]);
1960 //else if(defname_context_method == 2)
1961 // newHandle = X3D_NODE(myGroup->children.p[0]);
1962 }
1963
1964 cString = STRDUP("node created in SFNodeConstr");
1965 }
1966
1967 } else if (argc == 2) {
1968 /* eg, createVrmlFromString will send a bunch of SFNodes to a MFNode with text */
1969
1970 #ifdef JSVRMLCLASSESVERBOSE
1971 printf ("SFNodeConstr - have 2 arguments\n");
1972 #endif
1973
1974 if ((JSVAL_IS_STRING(argv[0])) && (JSVAL_IS_STRING(argv[1]))) {
1975 JSString *_idStr;
1976 char *_id_c;
1977
1978 _idStr = JS_ValueToString(cx, argv[0]);
1979#if JS_VERSION < 185
1980 _id_c = JS_GetStringBytes(_idStr);
1981#else
1982 _id_c = JS_EncodeString(cx,_idStr);
1983#endif
1984 /* printf ("first string :%s:\n",_id_c); */
1985
1986 cString = STRDUP(_id_c);
1987
1988 _idStr = JS_ValueToString(cx, argv[1]);
1989#if JS_VERSION < 185
1990 _id_c = JS_GetStringBytes(_idStr);
1991#else
1992 _id_c = JS_EncodeString(cx,_idStr);
1993#endif
1994 /* printf ("second string :%s:\n",_id_c); */
1995
1996 if (sscanf (_id_c,"%p",&newHandle) != 1) {
1997 printf ("SFNodeConstr - can not get handle from %s\n",_id_c);
1998 return JS_FALSE;
1999 }
2000/* nope, need to do this as a pointer string.. newHandle = (struct X3D_Node *) JSVAL_TO_GCTHING(argv[1]); */
2001
2002 #ifdef JSVRMLCLASSESVERBOSE
2003 printf ("string is :%s: new handle is %p\n",cString,newHandle);
2004 #endif
2005
2006 } else {
2007 printf ("SFNodeConstr - 2 args, expected 2 strings\n");
2008 return JS_FALSE;
2009 }
2010
2011
2012 } else {
2013 printf( "SFNodeConstr requires at least 1 string arg.\n");
2014 return JS_FALSE;
2015 }
2016
2017 if(SM_method() == 2){
2018 AnyNative *lhs;
2019 if ((lhs = (AnyNative *) AnyNativeNew(FIELDTYPE_SFNode,NULL,NULL)) == NULL) {
2020 printf( "AnyNativeNew failed in SFNodeConstr.\n");
2021 return JS_FALSE;
2022 }
2023 if (!JS_SetPrivateFw(cx, obj, lhs)) {
2024 printf( "JS_SetPrivate failed in SFNodeConstr.\n");
2025 return JS_FALSE;
2026 }
2027 //lhs->valueChanged = NULL;
2028 lhs->v->sfnode = newHandle;
2029 }else{
2030 /* ok, so far so good... */
2031 if ((newPtr = (SFNodeNative *) SFNodeNativeNew()) == NULL) {
2032 printf( "SFNodeNativeNew failed in SFNodeConstr.\n");
2033 return JS_FALSE;
2034 }
2035
2036 //if (!JS_DefineProperties(cx, obj, SFNodeProperties)) {
2037 // printf( "JS_DefineProperties failed in SFNodeConstr.\n");
2038 // return JS_FALSE;
2039 //}
2040
2041 if (!JS_SetPrivateFw(cx, obj, newPtr)) {
2042 printf( "JS_SetPrivate failed in SFNodeConstr.\n");
2043 return JS_FALSE;
2044 }
2045
2046 newPtr->handle = newHandle;
2047 if(SM_method() == 0){
2048 newPtr->X3DString = (char *)STRDUP(cString);
2049
2050 if (!JS_DefineSFNodeSpecificProperties (cx, obj, newHandle)) {
2051 printf( "JS_DefineSFNodeSpecificProperties failed in SFNodeConstr.\n");
2052 return JS_FALSE;
2053
2054 }
2055 }
2056
2057 newPtr->valueChanged = 1;
2058 } //SM_method == 2
2059
2060 #ifdef JSVRMLCLASSESVERBOSE
2061 {
2062 if (newHandle == NULL)
2063 printf("end of SFNodeConstr: created obj = %p, argc: %u mem ptr: %p (null pointer) text string: %s\n",
2064 obj, argc, newHandle, cString);
2065 else
2066 printf("end of SFNodeConstr: created obj = %p, argc: %u mem ptr: %p (%s) text string: %s\n",
2067 obj, argc, newHandle, stringNodeType(newHandle->_nodeType),cString);
2068 }
2069 #endif
2070
2071#if JS_VERSION < 185
2072 *rval = OBJECT_TO_JSVAL(obj);
2073#else
2074 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
2075#endif
2076
2077 return JS_TRUE;
2078}
2079
2080/* undef JSVRMLCLASSESVERBOSE */
2081
2082void
2083#if JS_VERSION < 186
2084SFNodeFinalize(JSContext *cx, JSObject *obj){
2085#else
2086SFNodeFinalize(JSFreeOp *fop, JSObject *obj){
2087JSContext *cx = NULL;
2088#endif
2089 SFNodeNative *ptr;
2090 AnyNative *any;
2091
2092 #ifdef JSVRMLCLASSESVERBOSE
2093 printf("SFNodeFinalize: obj = %p\n", obj);
2094 #endif
2095
2096 REMOVE_ROOT(cx,obj)
2097
2098 /*so, it appears that recent (2010) versions ofJavascript will give the following error when
2099 the interpreter is shutdown. It appears that sending in the url will cause a SFNode to
2100 be created, even though the normal constructor is not called, eg:
2101
2102 DEF t Script {
2103 url "vrmlscript:
2104 function eventsProcessed () {}
2105 "
2106 }
2107
2108 will cause the following JS_GetPrivate to fail. */
2109 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2110 /* see above printf( "JS_GetPrivate failed in SFNodeFinalize.\n"); */
2111 return;
2112 } else {
2113 if(SM_method() == 0)
2114 FREE_IF_NZ (ptr->X3DString);
2115 if(SM_method() == 2){
2116 any = (AnyNative*)ptr;
2117 if(any->gc) FREE_IF_NZ(any->v);
2118 }
2119
2120 FREE_IF_NZ (ptr);
2121 JS_SetPrivateFw(cx,obj,NULL);
2122 }
2123}
2124
2125
2126void X3D_ECMA_TO_JS(JSContext *cx, void *Data, int datalen, int dataType, jsval *newval);
2127void X3D_MF_TO_JS(JSContext *cx, JSObject *obj, void *Data, int dataType, jsval *newval, char *fieldName);
2128void X3D_SF_TO_JS(JSContext *cx, JSObject *obj, void *Data, unsigned datalen, int dataType, jsval *newval);
2129void X3D_MF_TO_JS_B(JSContext *cx, void *Data, int dataType, int *valueChanged, jsval *newval);
2130void X3D_SF_TO_JS_B(JSContext *cx, void *Data, unsigned datalen, int dataType, int *valueChanged, jsval *newval);
2131int getFieldFromNodeAndName(struct X3D_Node* node,const char *fieldname, int *type, int *kind, int *iifield, union anyVrml **value);
2132JSBool
2133#if JS_VERSION < 185
2134SFNodeGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
2135#elif JS_VERSION == 185
2136SFNodeGetProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp){
2137#else
2138SFNodeGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
2139 JSObject *obj = *hobj.address();
2140 jsid iid = *hiid.address();
2141 jsval *vp = hvp.address();
2142#endif
2143
2144
2145 /* We can't really get a property of a SFNode. There are no sub-indexes, etc...
2146 so we don't do anything. Check out SFVec3fGetProperty to see how it handles
2147 properties, should we need to have properties in the future. */
2148
2149 SFNodeNative *ptr;
2150 JSString *_idStr;
2151 char *_id_c;
2152 jsval rval;
2153#if JS_VERSION >= 185
2154 jsval id;
2155 if (!JS_IdToValue(cx,iid,&id)) {
2156 printf("JS_IdToValue failed in SFNodeGetProperty.\n");
2157 return JS_FALSE;
2158 }
2159#endif
2160 if (JSVAL_IS_INT(id)) {
2161 printf("SFNode has no [index] property.\n");
2162 /* would be nice to say node type or node name */
2163 /* note the setter does seem to take [0 or 1] */
2164 return JS_FALSE;
2165 }
2166
2167 _idStr = JS_ValueToString(cx, id);
2168#if JS_VERSION < 185
2169 _id_c = JS_GetStringBytes(_idStr);
2170#else
2171 _id_c = JS_EncodeString(cx,_idStr);
2172#endif
2173 #ifdef JSVRMLCLASSESVERBOSE
2174 printf ("start of SFNodeGetProperty... id is %s\n",_id_c);
2175 #endif
2176
2177 /* is this the string "undefined" ? */
2178 if (strcmp ("undefined",_id_c) == 0) return JS_TRUE;
2179
2180 /* is this one of the SFNode standard functions? see JSFunctionSpec (SFNodeFunctions)[] */
2181 if (strcmp ("toString",_id_c) == 0) return JS_TRUE;
2182 if (strcmp ("valueOf",_id_c) == 0) return JS_TRUE;
2183 if (strcmp ("equals",_id_c) == 0) return JS_TRUE;
2184 if (strcmp ("assign",_id_c) == 0) return JS_TRUE;
2185
2186 /* get the private pointer for this node */
2187 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) != NULL) {
2188 int ifound, type, kind, iifield, *valueChanged, sfsize, sftype;
2189 union anyVrml *value;
2190 char *fieldname = _id_c;
2191 struct X3D_Node *node;
2192 if(SM_method() == 2){
2193 AnyNative *any = (AnyNative *)ptr;
2194 node = any->v->sfnode;
2195 }else{
2196 node = ptr->handle;
2197 }
2198 #ifdef JSVRMLCLASSESVERBOSE
2199 printf ("SFNodeGetProperty, working on node %p, field %s\n",ptr->handle,_id_c);
2200 #endif
2201 if(SM_method() == 2){
2202 ifound = getFieldFromNodeAndName(node,fieldname,&type,&kind,&iifield,&value);
2203 if(ifound && value){
2204 // script and proto inputOnly won't be readable
2205 valueChanged = &node->_change; //if a regular node field changes, we (re-) compile_Node
2206 // ... (but have no way to detect which field, so routes can't be done later in freewrl system :{
2207 if(node->_nodeType == NODE_Script){
2208 //need one more thing - valueChanged
2209 struct X3D_Script *scriptnode = X3D_SCRIPT(node);
2210 getFieldFromScript((struct Shader_Script*)scriptnode->__scriptObj,fieldname,&type,&kind,&iifield,&value,&valueChanged);
2211 }
2212 sftype = type2SF(type);
2213 sfsize = sizeofSForMF(sftype);
2214
2215 //set up a return value
2216 switch (type) {
2217 case FIELDTYPE_SFBool:
2218 case FIELDTYPE_SFFloat:
2219 case FIELDTYPE_SFTime:
2220 case FIELDTYPE_SFDouble:
2221 case FIELDTYPE_SFInt32:
2222 case FIELDTYPE_SFString:
2223 X3D_ECMA_TO_JS(cx, value,sfsize,type,vp);
2224 break;
2225 case FIELDTYPE_SFColor:
2226 case FIELDTYPE_SFColorRGBA:
2227 case FIELDTYPE_SFNode:
2228 case FIELDTYPE_SFVec2f:
2229 case FIELDTYPE_SFVec3f:
2230 case FIELDTYPE_SFVec4f:
2231 case FIELDTYPE_SFVec2d:
2232 case FIELDTYPE_SFVec3d:
2233 case FIELDTYPE_SFVec4d:
2234 case FIELDTYPE_SFRotation:
2235 X3D_SF_TO_JS_B(cx, value,sfsize, type, valueChanged, vp);
2236 break;
2237 case FIELDTYPE_MFInt32:
2238 case FIELDTYPE_MFBool:
2239 case FIELDTYPE_MFFloat:
2240 case FIELDTYPE_MFDouble:
2241 case FIELDTYPE_MFTime:
2242 case FIELDTYPE_MFString:
2243 case FIELDTYPE_MFNode:
2244 case FIELDTYPE_MFColor:
2245 case FIELDTYPE_MFColorRGBA:
2246 case FIELDTYPE_MFVec2f:
2247 case FIELDTYPE_MFVec3f:
2248 case FIELDTYPE_MFVec4f:
2249 case FIELDTYPE_MFVec2d:
2250 case FIELDTYPE_MFVec3d:
2251 case FIELDTYPE_MFVec4d:
2252 case FIELDTYPE_MFRotation:
2253 case FIELDTYPE_SFImage:
2254 //static void X3D_MF_TO_JS(JSContext *cx, JSObject *obj, void *Data, int dataType, jsval *newval, char *fieldName) {
2255 X3D_MF_TO_JS_B(cx, value, type, valueChanged, vp);
2256 break;
2257 default:
2258 printf ("unhandled type FIELDTYPE_ %d in getSFNodeProperty!\n", type) ;
2259 return JS_FALSE;
2260 }
2261
2262
2263 //#if JS_VERSION < 185
2264 // *rval = OBJECT_TO_JSVAL(obj);
2265 //#else
2266 // JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
2267 //#endif
2268
2269 }
2270 } //SM_method > 0
2271 if(SM_method() == 0){
2272 // dug9 attempt to find read the field of another script
2273 //if(!strcmp(stringNodeType(ptr->handle->_nodeType),"Script"))
2274 if( ptr->handle && ptr->handle->_nodeType== NODE_Script )
2275 {
2276 struct Shader_Script *myObj;
2277 JSContext *cx2;
2278 JSObject *obj2;
2279 struct CRscriptStruct *ScriptControl; // = getScriptControl();
2280 myObj = (struct Shader_Script*)X3D_SCRIPT(ptr->handle)->__scriptObj;
2281 // get context and global object for this script
2282 ScriptControl = getScriptControlIndex(myObj->num);
2283 cx2 = (JSContext*)ScriptControl->cx;
2284 obj2 = (JSObject*)ScriptControl->glob;
2285 if (JS_GetProperty (cx2, obj2, _id_c, &rval)) {
2286 if (JSVAL_IS_NULL(rval)) {
2287 ConsoleMessage ("Script - field :%s: does not exist",_id_c);
2288 return JS_FALSE;
2289 }else{
2290 *vp = rval;
2291 return JS_TRUE;
2292 }
2293 }
2294 }
2295
2296 JS_DefineSFNodeSpecificProperties (cx, obj, ptr->handle);
2297
2298 // does the property exist?
2299 if (JS_LookupProperty (cx, obj, _id_c, &rval)) {
2300 if (JSVAL_IS_NULL(rval)) {
2301 // if you mis-spell a builtin node field
2302 // like Cylinder.hight (sb height) you'll end up in here
2303 ConsoleMessage ("SFNode - field :%s: does not exist",_id_c);
2304 return JS_FALSE;
2305 }
2306 }
2307 // if your SFNode is type Script you'll end up here
2308 #ifdef JSVRMLCLASSESVERBOSE
2309 printf ("wondering about rval.. %d. it is a\n",(int)rval);
2310 if (JSVAL_IS_INT(rval)) printf ("IS AN INT\n");
2311 if (JSVAL_IS_OBJECT(rval)) printf ("IS AN OBJECT\n");
2312 if (JSVAL_IS_STRING(rval)) printf ("IS AN STRING\n");
2313 if (rval == JSVAL_FALSE) printf ("FALSE\n");
2314 if (rval == JSVAL_NULL) printf ("NULL\n");
2315 if (rval == JSVAL_ONE) printf ("ONE\n");
2316 if (rval == JSVAL_ZERO) printf ("ZERO\n");
2317 if (rval == JSVAL_VOID) printf ("VOID\n");
2318 if (rval == JSVAL_TRUE) printf ("TRUE\n");
2319 #endif
2320
2321
2322 //dug9 - I find the next line JS_GetProperty recursive
2323 //when the sfnode we're trying to read is a Script node
2324 //if (JS_GetProperty (cx, obj, _id_c, &rval)) {
2325 if(false){
2326 #ifdef JSVRMLCLASSESVERBOSE
2327 printf ("SFNodeGetProperty, found field \"%s\" in node, returning property\n",_id_c);
2328 #endif
2329
2330 *vp = rval;
2331 } else {
2332 #ifdef JSVRMLCLASSESVERBOSE
2333 printf ("SFNodeGetProperty, did not find field \"%s\" in node.\n",_id_c);
2334 #endif
2335 return JS_FALSE;
2336 }
2337 } //SM_method() == 0
2338 } else {
2339 printf ("could not get private for SFNodeGetProperty, field :%s:\n",_id_c);
2340 return JS_FALSE;
2341 }
2342
2343 return JS_TRUE;
2344}
2345
2346void Parser_scanStringValueToMem_B(union anyVrml* any, indexT ctype, const char *value, int isXML);
2347void JS_MF_TO_X3D(JSContext *cx, JSObject * obj, void *Data, int dataType, jsval *newval);
2348JSBool
2349#if JS_VERSION < 185
2350SFNodeSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){
2351#elif JS_VERSION == 185
2352SFNodeSetProperty(JSContext *cx, JSObject *obj, jsid iid, JSBool strict, jsval *vp){
2353#else
2354SFNodeSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
2355 JSObject *obj = *hobj.address();
2356 jsid iid = *hiid.address();
2357 jsval *vp = hvp.address();
2358#endif
2359 JSString *_idStr, *_valStr;
2360 char *_id_c, *_val_c;
2361 SFNodeNative *ptr;
2362 size_t val_len;
2363 size_t tmp;
2364#if JS_VERSION >= 185
2365 jsval id;
2366 if (!JS_IdToValue(cx,iid,&id)) {
2367 printf("JS_IdToValue failed in SFNodeSetProperty.\n");
2368 return JS_FALSE;
2369 }
2370#endif
2371 if(SM_method() == 2){
2372 AnyNative *lhs;
2373 int ifound, type, kind, iifield, *valueChanged, sfsize, sftype;
2374 union anyVrml *value;
2375 char *fieldname;
2376 struct X3D_Node *node;
2377
2378 if((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2379 return JS_FALSE;
2380 }
2381 _idStr = JS_ValueToString(cx, id);
2382#if JS_VERSION < 185
2383 _id_c = JS_GetStringBytes(_idStr);
2384#else
2385 _id_c = JS_EncodeString(cx,_idStr); /* _id_c field name as a string ie "currX" */
2386#endif
2387 fieldname = _id_c;
2388 node = lhs->v->sfnode;
2389 ifound = getFieldFromNodeAndName(node,fieldname,&type,&kind,&iifield,&value);
2390 if(ifound) {
2391 valueChanged = &node->_change;
2392 if(node->_nodeType == NODE_Script){
2393 //need one more thing - valueChanged
2394 struct X3D_Script *scriptnode = X3D_SCRIPT(node);
2395 getFieldFromScript((struct Shader_Script*)scriptnode->__scriptObj,fieldname,&type,&kind,&iifield,&value,&valueChanged);
2396 }
2397 sftype = type2SF(type);
2398 sfsize = sizeofSForMF(sftype);
2399 //set up a return value
2400 //in js, null is an object
2401 if( JSVAL_IS_NULL(*vp)){
2402 if(type == FIELDTYPE_SFNode)
2403 value->sfnode = NULL;
2404 if(valueChanged)
2405 (*valueChanged) ++;
2406 //} else if (JSVAL_IS_OBJECT(*vp)) {
2407 } else if ((*vp).isObject()) {
2408 AnyNative *rhs;
2409 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
2410 //printf("in setECMANative, RHS was NOT native type \n");
2411 }else{
2412 //printf("in setECMANative, RHS was native type \n");
2413 //can do an assign here
2414 if(type == rhs->type){
2415 if(valueChanged)
2416 (*valueChanged) ++;
2417 //shallow assumes the top has already been malloced (just base part of MF needed)
2418 //use this if you need to malloc anyvrml: int sizeofSForMF(int itype)
2419 shallow_copy_field(rhs->type,rhs->v,value);
2420 }
2421 }
2422
2423 } else {
2424
2425 switch (type) {
2426 case FIELDTYPE_SFBool:
2427 case FIELDTYPE_SFFloat:
2428 case FIELDTYPE_SFTime:
2429 case FIELDTYPE_SFDouble:
2430 case FIELDTYPE_SFInt32:
2431 case FIELDTYPE_SFString:
2432 JS_ECMA_TO_X3D(cx, value,sfsize,type,vp);
2433
2434 if(valueChanged)
2435 (*valueChanged)++;
2436
2437 break;
2438 //case FIELDTYPE_SFColor:
2439 //case FIELDTYPE_SFNode:
2440 //case FIELDTYPE_SFVec2f:
2441 //case FIELDTYPE_SFVec3f:
2442 //case FIELDTYPE_SFVec3d:
2443 //case FIELDTYPE_SFRotation:
2444 // JS_SF_TO_X3D(cx, obj, value,sfsize, type, vp);
2445 // break;
2446 //case FIELDTYPE_MFColor:
2447 //case FIELDTYPE_MFVec3f:
2448 //case FIELDTYPE_MFVec2f:
2449 //case FIELDTYPE_MFFloat:
2450 //case FIELDTYPE_MFTime:
2451 //case FIELDTYPE_MFInt32:
2452 //case FIELDTYPE_MFString:
2453 //case FIELDTYPE_MFNode:
2454 //case FIELDTYPE_MFRotation:
2455 //case FIELDTYPE_SFImage:
2456 // JS_MF_TO_X3D(cx, obj, value, type, vp);
2457 // break;
2458 default:
2459 printf ("unhandled type FIELDTYPE_ %d in setSFNodeProperty?\n", type) ;
2460 return JS_FALSE;
2461 }
2462 }
2463
2464 //#if JS_VERSION < 185
2465 // *rval = OBJECT_TO_JSVAL(obj);
2466 //#else
2467 // JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
2468 //#endif
2469 return JS_TRUE;
2470
2471 }
2472 return JS_FALSE;
2473
2474 }else{ //SM_method == 2
2475 //if (JSVAL_IS_INT(id)) {
2476 // printf("SFNode has no [index] property.\n");
2477 // /* would be nice to say node type or node name */
2478 // return JS_FALSE;
2479 //}
2480
2481 _idStr = JS_ValueToString(cx, id);
2482 _valStr = JS_ValueToString(cx, *vp);
2483#if JS_VERSION < 185
2484 _id_c = JS_GetStringBytes(_idStr);
2485 _val_c = JS_GetStringBytes(_valStr);
2486#else
2487 _id_c = JS_EncodeString(cx,_idStr); /* _id_c field name as a string ie "currX" */
2488 _val_c = JS_EncodeString(cx,_valStr); /* _val_c field value as a string ie "33" */
2489#endif
2490
2491
2492 #ifdef JSVRMLCLASSESVERBOSE
2493 printf("SFNodeSetProperty: obj = %p, id = %s, vp = %s\n",
2494 obj, _id_c, _val_c);
2495 #endif
2496
2497
2498 if ((ptr = (SFNodeNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2499 printf( "JS_GetPrivate failed in SFNodeSetProperty.\n");
2500 return JS_FALSE;
2501 }
2502
2503 if (JSVAL_IS_INT(id)) {
2504 /* dug9 Aug 2013: no Properties are defined on SFNode, so there shouldn't be
2505 any public SFNode[id] = ?. What are we doing here?
2506 Was it an experiment or test method? Or does some other internal
2507 function call this setter[id]? May we drop support for it?*/
2508 if(SM_method() == 0){
2509 ptr->valueChanged++;
2510 val_len = (int) strlen(_val_c) + 1;
2511
2512 #ifdef JSVRMLCLASSESVERBOSE
2513 printf ("switching on %d\n",JSVAL_TO_INT(id));
2514 #endif
2515
2516 switch (JSVAL_TO_INT(id)) {
2517 case 0:
2518 if ((strlen(ptr->X3DString) + 1) > val_len) {
2519 ptr->X3DString =
2520 (char *) REALLOC (ptr->X3DString, val_len * sizeof(char));
2521 }
2522 memset(ptr->X3DString, 0, val_len);
2523 memmove(ptr->X3DString, _val_c, val_len);
2524 break;
2525 case 1:
2526 scanUnsignedIntoValue(_val_c,&tmp);
2527 ptr->handle = X3D_NODE(tmp);
2528 break;
2529 }
2530 } //SM_method == 0
2531 } else {
2532 #ifdef JSVRMLCLASSESVERBOSE
2533 printf ("JS_IS_INT false\n");
2534
2535 printf ("SFNodeSetProperty, setting node %p field %s to value %s\n", ptr->handle,_id_c,_val_c);
2536
2537 {
2538 struct X3D_Node* ptx;
2539 ptx = X3D_NODE(ptr->handle);
2540 printf ("node is of type %s\n",stringNodeType(ptx->_nodeType));
2541 }
2542 #endif
2543
2544 /* dug9 2012 attempt to find and write the field of another script */
2545 if( ptr->handle->_nodeType== NODE_Script )
2546 {
2547 /* code borrowed from fieldGet.c L.138 in set_one_ECMAtype() and reworked
2548 for cx2, obj2 - writes to a script eventIn with timestamp,
2549 and runs the script function, completing the event
2550 cascade (I think)
2551 */
2552 char scriptline[100];
2553 JSScript *eventInFunction;
2554 struct ScriptFieldDecl* myfield;
2555 struct CRjsnameStruct *JSparamnames; // = getJSparamnames();
2556 struct Shader_Script *myObj;
2557 JSContext *cx2;
2558 JSObject *obj2;
2559 jsval newval;
2560 //indexT myfieldType;
2561 //union anyVrml vrmlField;
2562 //bool deepcopy;
2563 struct CRscriptStruct *ScriptControl; // = getScriptControl();
2564 myObj = (struct Shader_Script*)X3D_SCRIPT(ptr->handle)->__scriptObj;
2565 /* is the script ok and initialized? */
2566 ScriptControl = getScriptControlIndex(myObj->num);
2567 if ((!ScriptControl->_initialized) || (!ScriptControl->scriptOK)) {
2568 /* printf ("waiting for initializing script %d at %s:%d\n",(uintptr_t)to_ptr->routeToNode, __FILE__,__LINE__); */
2569 return JS_FALSE;;
2570 }
2571
2572 /* get context and global object for this script */
2573 cx2 = (JSContext*)ScriptControl->cx;
2574 obj2 = (JSObject*)ScriptControl->glob;
2575 //it doesn't seem to matter which cx/obj we use.
2576 cx2 = cx;
2577 obj2 = obj;
2578
2579 { // Scope A for our various stack objects (JSAutoRequest, RootedObject), so they all go
2580 // out of scope before we JS_DestroyContext.
2581 JSAutoRequest ar(cx); // In practice, you would want to exit this any
2582 // time you're spinning the event loop
2583 { // Scope B for JSAutoCompartment
2584 JSAutoCompartment ac(cx, obj2);
2585 /* set the time for this script */
2586 //SET_JS_TICKTIME()
2587 {
2588 jsval zimbo;
2589 JS_NewNumberValue(cx2, TickTime(), &zimbo);
2590 if (!JS_DefineProperty(cx2,obj2, "__eventInTickTime", zimbo, JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB2, JSPROP_PERMANENT)) {
2591 printf( "JS_DefineProperty failed for __eventInTickTime at %s:%d.\n",__FILE__,__LINE__);
2592 return JS_FALSE;
2593 }
2594 }
2595 //X3D_ECMA_TO_JS(cx, Data, datalen, dataType, &newval);
2596 //if( getSFNodeField(cx,obj, id, &newval) == JS_FALSE) //this is for getting fields from builtin node types, not Script nodes
2597 // return JS_FALSE;
2598 myfield = script_getField_viaCharName(myObj, _id_c);
2599
2600 //Q. do I need to deepcopy the vp?
2601 // newval = deepcopy(vp);
2602 //a slight difference: pointer copy: bool=true, deep copy: bool=1
2603 //I'll stick with pointer copy
2604 /*
2605 deepcopy = false;
2606 if(deepcopy)
2607 {
2608 //step 1. get the target/output field's datatype
2609 myfieldType = myfield->fieldDecl->fieldType;
2610
2611 //step 2. try and read the input *vp using that datatype
2612 // borrowed from jsUtils.c L.1247
2613 switch (myfieldType) {
2614 case FIELDTYPE_SFBool:
2615 case FIELDTYPE_SFFloat:
2616 case FIELDTYPE_SFTime:
2617 case FIELDTYPE_SFDouble:
2618 case FIELDTYPE_SFInt32:
2619 case FIELDTYPE_SFString:
2620 JS_ECMA_TO_X3D(cx2, &vrmlField, returnElementLength(myfieldType), myfieldType, vp);
2621 break;
2622 case FIELDTYPE_SFColor:
2623 case FIELDTYPE_SFNode:
2624 case FIELDTYPE_SFVec2f:
2625 case FIELDTYPE_SFVec3f:
2626 case FIELDTYPE_SFVec3d:
2627 case FIELDTYPE_SFRotation:
2628 JS_SF_TO_X3D(cx2,&vrmlField,returnElementLength(myfieldType) * returnElementRowSize(myfieldType) , myfieldType, vp);
2629 break;
2630 case FIELDTYPE_MFColor:
2631 case FIELDTYPE_MFVec3f:
2632 case FIELDTYPE_MFVec2f:
2633 case FIELDTYPE_MFFloat:
2634 case FIELDTYPE_MFTime:
2635 case FIELDTYPE_MFInt32:
2636 case FIELDTYPE_MFString:
2637 case FIELDTYPE_MFNode:
2638 case FIELDTYPE_MFRotation:
2639 case FIELDTYPE_SFImage:
2640 JS_MF_TO_X3D(cx2, obj2, &vrmlField, myfieldType, vp);
2641 break;
2642 default: printf ("unhandled type in setSFNodeField\n");
2643 return JS_FALSE;
2644 }
2645 //step 3. if successful, convert back to a second copy newval
2646 //int setField_FromEAI_ToScript(int tonode, int toname, int datatype, void *data, unsigned rowcount) {
2647 switch (myfieldType) {
2648 case FIELDTYPE_SFBool:
2649 case FIELDTYPE_SFFloat:
2650 case FIELDTYPE_SFTime:
2651 case FIELDTYPE_SFDouble:
2652 case FIELDTYPE_SFInt32:
2653 case FIELDTYPE_SFString:
2654 X3D_ECMA_TO_JS(cx2, &vrmlField, returnElementLength(myfieldType), myfieldType, &newval);
2655 break;
2656 case FIELDTYPE_SFColor:
2657 case FIELDTYPE_SFNode:
2658 case FIELDTYPE_SFVec2f:
2659 case FIELDTYPE_SFVec3f:
2660 case FIELDTYPE_SFVec3d:
2661 case FIELDTYPE_SFRotation:
2662 X3D_SF_TO_JS(cx2, obj2, &vrmlField, returnElementLength(myfieldType) * returnElementRowSize(myfieldType) , myfieldType, &newval);
2663 break;
2664 case FIELDTYPE_MFColor:
2665 case FIELDTYPE_MFVec3f:
2666 case FIELDTYPE_MFVec2f:
2667 case FIELDTYPE_MFFloat:
2668 case FIELDTYPE_MFTime:
2669 case FIELDTYPE_MFInt32:
2670 case FIELDTYPE_MFString:
2671 case FIELDTYPE_MFNode:
2672 case FIELDTYPE_MFRotation:
2673 case FIELDTYPE_SFImage:
2674 X3D_MF_TO_JS(cx2, obj2, &vrmlField, myfieldType, &newval, _id_c);
2675 break;
2676 default: printf ("unhandled type FIELDTYPE_ %d in getSFNodeField\n", myfieldType) ;
2677 return JS_FALSE;
2678 }
2679 }else{ //deepcopy
2680 */
2681 newval = *vp;
2682 //}
2683 /* get the variable name to hold the incoming value */
2684 //sprintf (scriptline,"__eventIn_Value_%s", _id_c);
2685 strcpy(scriptline,_id_c);
2686 #ifdef JSVRMLCLASSESVERBOSE
2687 printf ("set_one_ECMAtype, calling JS_DefineProperty on name %s obj %u, setting setECMANative, 0 \n",scriptline,obj2);
2688 #endif
2689
2690 if (!JS_DefineProperty(cx2,obj2, scriptline, newval, JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_PERMANENT)) {
2691 printf( "JS_DefineProperty failed for SFNodeSetProperty at %s:%d.\n",__FILE__,__LINE__);
2692 #if defined(JS_THREADSAFE)
2693 JS_EndRequest(cx);
2694 #endif
2695 return JS_FALSE;
2696 }
2697 /* is the function compiled yet? */
2698 //COMPILE_FUNCTION_IF_NEEDED(toname)
2699 JSparamnames = getJSparamnames();
2700 eventInFunction = (JSScript*) JSparamnames[myfield->fieldDecl->JSparamNameIndex].eventInFunction;
2701 if ( eventInFunction == NULL) {
2702 //sprintf (scriptline,"%s(__eventIn_Value_%s,__eventInTickTime)", _id_c, _id_c);
2703 sprintf (scriptline,"set_%s(%s,__eventInTickTime)", _id_c, _id_c);
2704 /* printf ("compiling function %s\n",scriptline); */
2705 eventInFunction = JS_CompileScript(cx2, obj2, scriptline, strlen(scriptline), "compile eventIn",1);
2706 if(true){
2707 //if (!JS_AddObjectRoot(cx2,&eventInFunction)) {
2708 JSparamnames[myfield->fieldDecl->JSparamNameIndex].eventInFunction = eventInFunction;
2709 #if JS_VERSION >= 185
2710 if (!JS_AddObjectRoot(cx,(JSObject**)(&JSparamnames[myfield->fieldDecl->JSparamNameIndex].eventInFunction))) {
2711 printf( "JS_AddObjectRoot failed for compilation of script \"%s\" at %s:%d.\n",scriptline,__FILE__,__LINE__);
2712 return JS_FALSE;
2713 }
2714 #endif
2715 }
2716 }
2717 /* and run the function */
2718 //RUN_FUNCTION (toname)
2719 {
2720 jsval zimbo;
2721 if (!JS_ExecuteScript(cx2, obj2, eventInFunction, &zimbo))
2722 {
2723 printf ("failed to set parameter for eventIn %s in FreeWRL code %s:%d\n",_id_c,__FILE__,__LINE__); \
2724 /* printf ("myThread is %u\n",pthread_self());*/ \
2725 return JS_FALSE;
2726 }
2727 return JS_TRUE;
2728 }
2729 } //Scope B
2730 } //Scope A
2731 }
2732 //dug9 July 9, 2014 - failed attempt to fix, see runQueuedDirectOutputs()
2733 // problem: 1) it's a lot of work to drill into the JS object for the other script to set the field value and valueChanged flag
2734 // 2) taking a shortcut in the routing loop would require refactoring: JSGlobal_object between get_valueChanged and js_setField_javascriptEventOut
2735 // would need to be generalized to do anyVrml or anyVrml passed directly up and down.
2736 if(0) if( ptr->handle->_nodeType== NODE_Script )
2737 {
2738 int itype, kind;
2739 //step 1. unconditionally write the script->field->value regardless of its kind/PKW
2740 struct ScriptFieldDecl* myfield;
2741 struct Shader_Script *script;
2742 struct CRscriptStruct *ScriptControl; // = getScriptControl();
2743 script = (struct Shader_Script*)X3D_SCRIPT(ptr->handle)->__scriptObj;
2744 /* is the script ok and initialized? */
2745 ScriptControl = getScriptControlIndex(script->num);
2746 if ((!ScriptControl->_initialized) || (!ScriptControl->scriptOK)) {
2747 /* printf ("waiting for initializing script %d at %s:%d\n",(uintptr_t)to_ptr->routeToNode, __FILE__,__LINE__); */
2748 return JS_FALSE;;
2749 }
2750 myfield = script_getField_viaCharName(script, _id_c);
2751 if(!myfield) return JS_FALSE;
2752 itype = ScriptFieldDecl_getType(myfield);
2753 kind = ScriptFieldDecl_getMode(myfield);
2754 Parser_scanStringValueToMem_B(&myfield->value, itype, _val_c, FALSE);
2755 if(kind == PKW_inputOnly || kind == PKW_inputOutput)
2756 myfield->eventInSet = TRUE; //flag for runQueuedDirectOutputs() to run eventIn function on other script, feeding it the value we just set
2757 if(kind == PKW_inputOutput || kind == PKW_outputOnly)
2758 myfield->valueChanged = TRUE; //flag for eventOuts on other script to send what we are writing
2759 return JS_TRUE;
2760 }
2761
2762 setField_fromJavascript (X3D_NODE(ptr->handle), _id_c, _val_c, FALSE);
2763 }
2764 } //SM_method == 2
2765 return JS_TRUE;
2766}
2767
2768
2769/********************************************************************/
2770
2771JSBool
2772SFRotationGetAxis(JSContext *cx, uintN argc, jsval *vp) {
2773 JSObject *obj = JS_THIS_OBJECT(cx,vp);
2774 jsval *argv = JS_ARGV(cx,vp);
2775
2776 JSObject *_retObj;
2777 float *cc, *cclhs;
2778
2779 UNUSED(argc);
2780 UNUSED(argv);
2781 #ifdef JSVRMLCLASSESVERBOSE
2782 printf ("start of SFRotationGetAxis\n");
2783 #endif
2784
2785 if ((_retObj = JS_ConstructObjectFw(cx, &SFVec3fClass, NULL, NULL)) == NULL) {
2786 printf( "JS_ConstructObject failed in SFRotationGetAxis.\n");
2787 return JS_FALSE;
2788 }
2789
2790 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_retObj));
2791
2792 if(SM_method()==2){
2793 AnyNative *_rot;
2794 AnyNative *_retNative;
2795 if ((_rot = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2796 printf( "JS_GetPrivate failed for obj in SFRotationGetAxis.\n");
2797 return JS_FALSE;
2798 }
2799
2800 if ((_retNative = (AnyNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2801 printf( "JS_GetPrivate failed for _retObj in SFRotationGetAxis.\n");
2802 return JS_FALSE;
2803 }
2804 cc = _rot->v->sfrotation.c;
2805 cclhs = _retNative->v->sfvec3f.c;
2806 }else{
2807 SFRotationNative *_rot;
2808 SFVec3fNative *_retNative;
2809 if ((_rot = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2810 printf( "JS_GetPrivate failed for obj in SFRotationGetAxis.\n");
2811 return JS_FALSE;
2812 }
2813
2814 if ((_retNative = (SFVec3fNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2815 printf( "JS_GetPrivate failed for _retObj in SFRotationGetAxis.\n");
2816 return JS_FALSE;
2817 }
2818 cc = _rot->v.c;
2819 cclhs = _retNative->v.c;
2820
2821 }
2822 veccopy3f(cclhs,cc);
2823
2824 #ifdef JSVRMLCLASSESVERBOSE
2825 printf("SFRotationGetAxis: obj = %p, result = [%.9g, %.9g, %.9g]\n",
2826 obj,
2827 (_retNative->v).c[0],
2828 (_retNative->v).c[1],
2829 (_retNative->v).c[2]);
2830 #endif
2831
2832 return JS_TRUE;
2833}
2834
2835JSBool
2836SFRotationInverse(JSContext *cx, uintN argc, jsval *vp) {
2837 JSObject *obj = JS_THIS_OBJECT(cx,vp);
2838 jsval *argv = JS_ARGV(cx,vp);
2839
2840 JSObject *_retObj, *_proto;
2841 Quaternion q1,qret;
2842 double a,b,c,d;
2843 float *cc, *cclhs;
2844 UNUSED(argc);
2845 UNUSED(argv);
2846 #ifdef JSVRMLCLASSESVERBOSE
2847 printf ("start of SFRotationInverse\n");
2848 #endif
2849
2850 if ((_proto = JS_GetPrototypeFw(cx, obj)) == NULL) {
2851 printf( "JS_GetPrototype failed in SFRotationInverse.\n");
2852 return JS_FALSE;
2853 }
2854 if ((_retObj = JS_ConstructObjectFw(cx, &SFRotationClass, _proto, NULL)) == NULL) {
2855 printf( "JS_ConstructObject failed in SFRotationInverse.\n");
2856 return JS_FALSE;
2857 }
2858 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_retObj));
2859
2860
2861 if(SM_method()==2){
2862 AnyNative *_rot, *_retNative;
2863
2864 if ((_rot = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2865 printf( "JS_GetPrivate failed for obj in SFRotationInverse.\n");
2866 return JS_FALSE;
2867 }
2868
2869 if ((_retNative = (AnyNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2870 printf( "JS_GetPrivate failed for _retObj in SFRotationInverse.\n");
2871 return JS_FALSE;
2872 }
2873 cc = _rot->v->sfrotation.c;
2874 cclhs = _retNative->v->sfrotation.c;
2875
2876 }else{
2877 SFRotationNative *_rot, *_retNative;
2878
2879 if ((_rot = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2880 printf( "JS_GetPrivate failed for obj in SFRotationInverse.\n");
2881 return JS_FALSE;
2882 }
2883
2884 if ((_retNative = (SFRotationNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2885 printf( "JS_GetPrivate failed for _retObj in SFRotationInverse.\n");
2886 return JS_FALSE;
2887 }
2888 _retNative->valueChanged = 1;
2889 cc = _rot->v.c;
2890 cclhs = _retNative->v.c;
2891 }
2892 /* convert both rotation to quaternion */
2893 vrmlrot_to_quaternion(&q1, (double) cc[0],
2894 (double) cc[1], (double)cc[2], (double) cc[3]);
2895
2896 /* invert it */
2897 quaternion_inverse(&qret,&q1);
2898
2899
2900 /* and return the resultant, as a vrml rotation */
2901 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
2902 /* double to floats, can not use pointers... */
2903 cclhs[0] = (float) a;
2904 cclhs[1] = (float) b;
2905 cclhs[2] = (float) c;
2906 cclhs[3] = (float) d;
2907
2908 /* and, we now have a new value */
2909
2910 return JS_TRUE;
2911}
2912
2913JSBool
2914SFRotationMultiply(JSContext *cx, uintN argc, jsval *vp) {
2915 JSObject *obj = JS_THIS_OBJECT(cx,vp);
2916 jsval *argv = JS_ARGV(cx,vp);
2917
2918 Quaternion q1,q2,qret;
2919 double a,b,c,d;
2920
2921 JSObject *_multObj, *_proto, *_retObj;
2922 float *cc, *cc1, *cclhs;
2923 #ifdef JSVRMLCLASSESVERBOSE
2924 printf ("start of SFRotationMultiply\n");
2925 #endif
2926
2927 if (!JS_ConvertArguments(cx, argc, argv, "o", &_multObj)) {
2928 printf( "JS_ConvertArguments failed in SFRotationMultiply.\n");
2929 return JS_FALSE;
2930 }
2931 CHECK_CLASS(cx,_multObj,argv,__FUNCTION__,SFRotationClass)
2932
2933 if ((_proto = JS_GetPrototypeFw(cx, _multObj)) == NULL) {
2934 printf( "JS_GetPrototype failed in SFRotationMultiply.\n");
2935 return JS_FALSE;
2936 }
2937
2938 if ((_retObj = JS_ConstructObjectFw(cx, &SFRotationClass, _proto, NULL)) == NULL) {
2939 printf( "JS_ConstructObject failed in SFRotationMultiply.\n");
2940 return JS_FALSE;
2941 }
2942
2943
2944 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_retObj));
2945
2946 if(SM_method()==2){
2947 AnyNative *_rot1, *_rot2, *_retNative;
2948
2949 if ((_rot1 = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2950 printf( "JS_GetPrivate failed for obj in SFRotationMultiply.\n");
2951 return JS_FALSE;
2952 }
2953
2954 if ((_rot2 = (AnyNative *)JS_GetPrivateFw(cx, _multObj)) == NULL) {
2955 printf( "JS_GetPrivate failed for _multObj in SFRotationMultiply.\n");
2956 return JS_FALSE;
2957 }
2958
2959 if ((_retNative = (AnyNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2960 printf( "JS_GetPrivate failed for _retObj in SFRotationMultiply.\n");
2961 return JS_FALSE;
2962 }
2963 cc = _rot1->v->sfrotation.c;
2964 cc1 = _rot2->v->sfrotation.c;
2965 cclhs = _retNative->v->sfrotation.c;
2966 }else{
2967 SFRotationNative *_rot1, *_rot2, *_retNative;
2968
2969 if ((_rot1 = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
2970 printf( "JS_GetPrivate failed for obj in SFRotationMultiply.\n");
2971 return JS_FALSE;
2972 }
2973
2974 if ((_rot2 = (SFRotationNative *)JS_GetPrivateFw(cx, _multObj)) == NULL) {
2975 printf( "JS_GetPrivate failed for _multObj in SFRotationMultiply.\n");
2976 return JS_FALSE;
2977 }
2978
2979 if ((_retNative = (SFRotationNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
2980 printf( "JS_GetPrivate failed for _retObj in SFRotationMultiply.\n");
2981 return JS_FALSE;
2982 }
2983 cc = _rot1->v.c;
2984 cc1 = _rot2->v.c;
2985 cclhs = _retNative->v.c;
2986 _retNative->valueChanged = 1;
2987
2988 }
2989 /* convert both rotations into quaternions */
2990 vrmlrot_to_quaternion(&q1, (double) cc[0],
2991 (double) cc[1], (double) cc[2], (double) cc[3]);
2992 vrmlrot_to_quaternion(&q2, (double) cc1[0],
2993 (double) cc1[1], (double) cc1[2], (double) cc1[3]);
2994
2995 /* multiply them */
2996 quaternion_multiply(&qret,&q1,&q2);
2997
2998
2999 /* and return the resultant, as a vrml rotation */
3000 quaternion_to_vrmlrot(&qret, &a, &b, &c, &d);
3001 /* double to floats, can not use pointers... */
3002 cclhs[0] = (float) a;
3003 cclhs[1] = (float) b;
3004 cclhs[2] = (float) c;
3005 cclhs[3] = (float) d;
3006
3007 /* and, we now have a new value */
3008
3009 return JS_TRUE;
3010}
3011
3012JSBool
3013SFRotationMultVec(JSContext *cx, uintN argc, jsval *vp) {
3014 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3015 jsval *argv = JS_ARGV(cx,vp);
3016
3017 JSObject *_multObj, *_retObj, *_proto;
3018 float rl;
3019 //float vl;
3020 //float rlpt;
3021 float s, c, angle;
3022 //struct point_XYZ r, v, c1, c2;
3023 int i;
3024 float *rot, *vec, *cclhs;
3025 float c1[3], c2[3], r[3]; //temps
3026
3027
3028 #ifdef JSVRMLCLASSESVERBOSE
3029 printf ("start of SFRotationMultiVec\n");
3030 #endif
3031
3032 if (!JS_ConvertArguments(cx, argc, argv, "o", &_multObj)) {
3033 printf( "JS_ConvertArguments failed in SFRotationMultVec.\n");
3034 return JS_FALSE;
3035 }
3036
3037 CHECK_CLASS(cx,_multObj,argv,__FUNCTION__,SFVec3fClass)
3038
3039 if ((_proto = JS_GetPrototypeFw(cx, _multObj)) == NULL) {
3040 printf( "JS_GetPrototype failed in SFRotationMultVec.\n");
3041 return JS_FALSE;
3042 }
3043
3044 if ((_retObj = JS_ConstructObjectFw(cx, &SFVec3fClass, _proto, NULL)) == NULL) {
3045 printf( "JS_ConstructObject failed in SFRotationMultVec.\n");
3046 return JS_FALSE;
3047 }
3048
3049 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_retObj));
3050
3051 if(SM_method()==2){
3052 AnyNative *_rot;
3053 AnyNative *_vec, *_retNative;
3054
3055 if ((_rot = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3056 printf( "JS_GetPrivate failed for obj in SFRotationMultVec.\n");
3057 return JS_FALSE;
3058 }
3059
3060 if ((_vec = (AnyNative *)JS_GetPrivateFw(cx, _multObj)) == NULL) {
3061 printf( "JS_GetPrivate failed for_multObjin SFRotationMultVec.\n");
3062 return JS_FALSE;
3063 }
3064 if ((_retNative = (AnyNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3065 printf( "JS_GetPrivate failed for _retObj in SFRotationMultVec.\n");
3066 return JS_FALSE;
3067 }
3068 rot = _rot->v->sfrotation.c;
3069 vec = _vec->v->sfvec3f.c;
3070 cclhs = _retNative->v->sfvec3f.c;
3071
3072 }else{
3073 SFRotationNative *_rot;
3074 SFVec3fNative *_vec, *_retNative;
3075
3076 if ((_rot = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3077 printf( "JS_GetPrivate failed for obj in SFRotationMultVec.\n");
3078 return JS_FALSE;
3079 }
3080 //COPY_SFVEC3F_TO_POINT_XYZ(r,_rot->v.c);
3081 //angle = _rot->v.c[3];
3082
3083 if ((_vec = (SFVec3fNative *)JS_GetPrivateFw(cx, _multObj)) == NULL) {
3084 printf( "JS_GetPrivate failed for_multObjin SFRotationMultVec.\n");
3085 return JS_FALSE;
3086 }
3087 //COPY_SFVEC3F_TO_POINT_XYZ(v,_vec->v.c);
3088 if ((_retNative = (SFVec3fNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3089 printf( "JS_GetPrivate failed for _retObj in SFRotationMultVec.\n");
3090 return JS_FALSE;
3091 }
3092 rot = _rot->v.c;
3093 vec = _vec->v.c;
3094 cclhs = _retNative->v.c;
3095 }
3096 rl = veclength3f(rot);
3097 angle = rot[3];
3098 s = (float) sin(angle);
3099 c = (float) cos(angle);
3100 veccross3f(c1,rot,vec);
3101 rl = veclength3f(c1);
3102 vecscale3f(c1,c1,1.0f/rl);
3103 veccross3f(c2,rot,c1);
3104 rl = veclength3f(c2);
3105 vecscale3f(c2,c2,1.0f/rl);
3106 for(i=0;i<3;i++)
3107 cclhs[i] = (float) (vec[i] + s * c1[i] + (1.0-c) * c2[i]);
3108
3109
3110 return JS_TRUE;
3111}
3112
3113JSBool
3114SFRotationSetAxis(JSContext *cx, uintN argc, jsval *vp) {
3115 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3116 jsval *argv = JS_ARGV(cx,vp);
3117
3118 JSObject *_setAxisObj;
3119 float *rot, *vec;
3120
3121 #ifdef JSVRMLCLASSESVERBOSE
3122 printf ("start of SFRotationSetAxis\n");
3123 #endif
3124
3125 if (!JS_ConvertArguments(cx, argc, argv, "o", &_setAxisObj)) {
3126 printf( "JS_ConvertArguments failed in SFRotationSetAxis.\n");
3127 return JS_FALSE;
3128 }
3129
3130 CHECK_CLASS(cx,_setAxisObj,argv,__FUNCTION__,SFVec3fClass)
3131
3132 if(SM_method() == 2){
3133 AnyNative *_rot;
3134 AnyNative *_vec;
3135 if ((_rot = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3136 printf( "JS_GetPrivate failed for obj in SFRotationSetAxis.\n");
3137 return JS_FALSE;
3138 }
3139
3140 if ((_vec = (AnyNative *)JS_GetPrivateFw(cx, _setAxisObj)) == NULL) {
3141 printf( "JS_GetPrivate failed for _retObj in SFRotationSetAxis.\n");
3142 return JS_FALSE;
3143 }
3144 rot = _rot->v->sfrotation.c;
3145 vec = _vec->v->sfvec3f.c;
3146 }else{
3147 SFRotationNative *_rot;
3148 SFVec3fNative *_vec;
3149 if ((_rot = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3150 printf( "JS_GetPrivate failed for obj in SFRotationSetAxis.\n");
3151 return JS_FALSE;
3152 }
3153
3154 if ((_vec = (SFVec3fNative *)JS_GetPrivateFw(cx, _setAxisObj)) == NULL) {
3155 printf( "JS_GetPrivate failed for _retObj in SFRotationSetAxis.\n");
3156 return JS_FALSE;
3157 }
3158 rot = _rot->v.c;
3159 vec = _vec->v.c;
3160 }
3161 veccopy3f(rot,vec);
3162
3163 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
3164
3165
3166 #ifdef JSVRMLCLASSESVERBOSE
3167 printf("SFRotationSetAxis: obj = %p, result = [%.9g, %.9g, %.9g, %.9g]\n",
3168 obj,
3169 rot[0],
3170 rot[1],
3171 rot[2],
3172 rot[3]);
3173 #endif
3174
3175 return JS_TRUE;
3176}
3177
3178JSBool
3179SFRotationSlerp(JSContext *cx, uintN argc, jsval *vp) {
3180 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3181 jsval *argv = JS_ARGV(cx,vp);
3182 jsval rvalinst;
3183 jsval *rval = &rvalinst;
3184
3185 JSObject *_destObj, *_retObj, *_proto;
3186 Quaternion _quat, _quat_dest, _quat_ret;
3187 jsdouble t;
3188 float *rot, *dest, *ret;
3189
3190 #ifdef JSVRMLCLASSESVERBOSE
3191 printf ("start of SFRotationSlerp\n");
3192 #endif
3193 if (!JS_ConvertArguments(cx, argc, argv, "o d", &_destObj, &t)) {
3194 printf( "JS_ConvertArguments failed in SFRotationSlerp.\n");
3195 return JS_FALSE;
3196 }
3197
3198 CHECK_CLASS(cx,_destObj,argv,__FUNCTION__,SFRotationClass)
3199
3200
3201 /*
3202 * From Annex C, C.6.7.4:
3203 *
3204 * For t = 0, return object's rotation.
3205 * For t = 1, return 1st argument.
3206 * For 0 < t < 1, compute slerp.
3207 */
3208 if (APPROX(t, 0)) {
3209 *rval = OBJECT_TO_JSVAL(obj);
3210 } else if (APPROX(t, 1)) {
3211 *rval = OBJECT_TO_JSVAL(_destObj);
3212 } else {
3213 if ((_proto = JS_GetPrototypeFw(cx, _destObj)) == NULL) {
3214 printf( "JS_GetPrototype failed in SFRotationSlerp.\n");
3215 return JS_FALSE;
3216 }
3217
3218 if ((_retObj = JS_ConstructObjectFw(cx, &SFRotationClass, _proto, NULL)) == NULL) {
3219 printf( "JS_ConstructObject failed in SFRotationSlerp.\n");
3220 return JS_FALSE;
3221 }
3222 /* root the object */
3223 *rval = OBJECT_TO_JSVAL(_retObj);
3224
3225 if(SM_method() == 2){
3226 AnyNative *_rot, *_dest, *_ret;
3227 if ((_rot = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3228 printf( "JS_GetPrivate failed for obj in SFRotationSlerp.\n");
3229 return JS_FALSE;
3230 }
3231
3232 if ((_dest = (AnyNative *)JS_GetPrivateFw(cx, _destObj)) == NULL) {
3233 printf( "JS_GetPrivate failed for _destObj in SFRotationSlerp.\n");
3234 return JS_FALSE;
3235 }
3236
3237 if ((_ret = (AnyNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3238 printf( "JS_GetPrivate failed for _retObj in SFRotationSlerp.\n");
3239 return JS_FALSE;
3240 }
3241 rot = _rot->v->sfrotation.c;
3242 dest = _dest->v->sfrotation.c;
3243 ret = _ret->v->sfrotation.c;
3244 }else{
3245 SFRotationNative *_rot, *_dest, *_ret;
3246 if ((_rot = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3247 printf( "JS_GetPrivate failed for obj in SFRotationSlerp.\n");
3248 return JS_FALSE;
3249 }
3250
3251 if ((_dest = (SFRotationNative *)JS_GetPrivateFw(cx, _destObj)) == NULL) {
3252 printf( "JS_GetPrivate failed for _destObj in SFRotationSlerp.\n");
3253 return JS_FALSE;
3254 }
3255
3256 if ((_ret = (SFRotationNative *)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3257 printf( "JS_GetPrivate failed for _retObj in SFRotationSlerp.\n");
3258 return JS_FALSE;
3259 }
3260 rot = _rot->v.c;
3261 dest = _dest->v.c;
3262 ret = _ret->v.c;
3263 }
3264 vrmlrot_to_quaternion(&_quat,
3265 rot[0],
3266 rot[1],
3267 rot[2],
3268 rot[3]);
3269
3270 vrmlrot_to_quaternion(&_quat_dest,
3271 dest[0],
3272 dest[1],
3273 dest[2],
3274 dest[3]);
3275
3276 quaternion_slerp(&_quat_ret, &_quat, &_quat_dest, t);
3277 quaternion_to_vrmlrot4f(&_quat_ret,ret);
3278 }
3279
3280
3281 JS_SET_RVAL(cx,vp,*rval);
3282
3283 return JS_TRUE;
3284}
3285
3286
3287JSBool
3288SFRotationToString(JSContext *cx, uintN argc, jsval *vp) {
3289 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3290 jsval *argv = JS_ARGV(cx,vp);
3291
3292 JSString *_str;
3293 char buff[STRING];
3294 float *cc;
3295
3296 UNUSED(argc);
3297 #ifdef JSVRMLCLASSESVERBOSE
3298 printf ("start of SFRotationToString\n");
3299 #endif
3300
3301 ADD_ROOT (cx,ptr)
3302 ADD_ROOT(cx,_str)
3303 if(SM_method() == 2){
3304 AnyNative *ptr;
3305 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3306 printf( "JS_GetPrivate failed in SFRotationToString.\n");
3307 return JS_FALSE;
3308 }
3309 cc = ptr->v->sfrotation.c;
3310 }else{
3311 SFRotationNative *ptr;
3312 if ((ptr = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3313 printf( "JS_GetPrivate failed in SFRotationToString.\n");
3314 return JS_FALSE;
3315 }
3316 cc = ptr->v.c;
3317 }
3318 memset(buff, 0, STRING);
3319 sprintf(buff, "%.9g %.9g %.9g %.9g",
3320 cc[0], cc[1], cc[2], cc[3]);
3321 _str = JS_NewStringCopyZ(cx, buff);
3322
3323 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
3324
3325
3326 REMOVE_ROOT (cx,ptr)
3327 REMOVE_ROOT (cx,_str)
3328 return JS_TRUE;
3329}
3330
3331JSBool
3332SFRotationAssign(JSContext *cx, uintN argc, jsval *vp) {
3333 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3334 jsval *argv = JS_ARGV(cx,vp);
3335 JSString *_id_jsstr;
3336
3337 JSObject *_from_obj;
3338 char *_id_str;
3339
3340 UNUSED(_id_str); // compiler warning mitigation
3341
3342
3343 #ifdef JSVRMLCLASSESVERBOSE
3344 printf ("start of SFRotationAssign\n");
3345 #endif
3346 if(SM_method() == 2){
3347 AnyNative *lhs, *rhs;
3348 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3349 printf( "JS_GetPrivate failed for obj in SFRotationfAssign.\n");
3350 return JS_FALSE;
3351 }
3352 if (!(*vp).isObject())
3353 return JS_FALSE;
3354 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
3355 printf("JS_ConvertArguments failed in SFRotationAssign. \n");
3356 return JS_FALSE;
3357 }
3358 if(lhs->type != rhs->type) return JS_FALSE;
3359 AnyNativeAssign(lhs,rhs);
3360 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
3361
3362
3363 }else{
3364 SFRotationNative *fptr, *ptr;
3365
3366 if ((ptr = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3367 printf( "JS_GetPrivate failed for obj in SFRotationAssign.\n");
3368 return JS_FALSE;
3369 }
3370
3371 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFRotationClass)
3372
3373 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
3374 _id_str = JS_EncodeString(cx,_id_jsstr);
3375 } else {
3376
3377 printf( "JS_ConvertArguments failed in SFRotationAssign.\n");
3378 return JS_FALSE;
3379 }
3380
3381 /* is this an assignment of NULL? */
3382 if (_from_obj == NULL) {
3383 printf ("we have an assignment to null in SFRotationAssign\n");
3384 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(NULL)); //JSVAL_VOID);
3385
3386 } else {
3387
3388
3389 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFRotationClass)
3390
3391 if ((fptr = (SFRotationNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
3392 printf( "JS_GetPrivate failed for _from_obj in SFRotationAssign.\n");
3393 return JS_FALSE;
3394 }
3395 #ifdef JSVRMLCLASSESVERBOSE
3396 printf("SFRotationAssign: obj = %p, id = \"%s\", from = %p\n",
3397 obj, _id_str, _from_obj);
3398 #endif
3399
3400 SFRotationNativeAssign(ptr, fptr);
3401 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
3402
3403 }
3404 }
3405 #ifdef JSVRMLCLASSESVERBOSE
3406 printf("SFRotationAssign: returning object as jsval\n");
3407 #endif
3408 return JS_TRUE;
3409}
3410
3411JSBool
3412SFRotationConstr(JSContext *cx, uintN argc, jsval *vp) {
3413 JSObject *obj = JS_NewObject(cx,&SFRotationClass,NULL,NULL);
3414 jsval *argv = JS_ARGV(cx,vp);
3415
3416
3417 JSObject *_ob1, *_ob2;
3418 jsdouble pars[4];
3419 jsdouble doub;
3420 float v1len, v2len;
3421 double v12dp;
3422 struct point_XYZ v1, v2;
3423 int v3fv3f;
3424 float *cc, *vec, *vec2;
3425
3426 #ifdef JSVRMLCLASSESVERBOSE
3427 printf ("start of SFRotationConstr\n");
3428 #endif
3429
3430 ADD_ROOT(cx,obj)
3431 if(SM_method() == 2){
3432 AnyNative *any;
3433 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFRotation,NULL,NULL)) == NULL){
3434 printf( "AnyfNativeNew failed in SFRotationConstr.\n");
3435 return JS_FALSE;
3436 }
3437 if (!JS_SetPrivateFw(cx, obj, any)) {
3438 printf( "JS_SetPrivate failed in SFRotationConstr.\n");
3439 return JS_FALSE;
3440 }
3441 cc = any->v->sfrotation.c;
3442 }else{
3443 SFRotationNative *ptr;
3444
3445 if ((ptr = (SFRotationNative *)SFRotationNativeNew()) == NULL) {
3446 printf( "SFRotationNativeNew failed in SFRotationConstr.\n");
3447 return JS_FALSE;
3448 }
3449
3450 //if (!JS_DefineProperties(cx, obj, SFRotationProperties)) {
3451 // printf( "JS_DefineProperties failed in SFRotationConstr.\n");
3452 // return JS_FALSE;
3453 //}
3454
3455 if (!JS_SetPrivateFw(cx, obj, ptr)) {
3456 printf( "JS_SetPrivate failed in SFRotationConstr.\n");
3457 return JS_FALSE;
3458 }
3459 ptr->valueChanged = 1;
3460 cc = ptr->v.c;
3461
3462 }
3463 if (argc == 0) {
3464 cc[0] = 0.0f; cc[1] = 0.0f; cc[2] = 1.0f; cc[3] = 0.0f;
3465
3466 } else if (argc == 2) {
3467 /* two possibilities - SFVec3f/numeric, or SFVec3f/SFVec3f */
3468 if (argv[0].isObject()) {
3469/* _ob1 = (JSObject *)argv[0]; */
3470 _ob1 = JSVAL_TO_OBJECT(argv[0]);
3471
3472
3473 CHECK_CLASS(cx,_ob1,argv,__FUNCTION__,SFVec3fClass)
3474 if(SM_method()==2){
3475 AnyNative *_vec = NULL;
3476 if ((_vec = (AnyNative *)JS_GetPrivateFw(cx, _ob1)) == NULL) {
3477 printf( "JS_GetPrivate failed for arg format \"o d\" in SFRotationConstr.\n");
3478 return JS_FALSE;
3479 }
3480 vec = _vec->v->sfvec3f.c;
3481 }else{
3482 SFVec3fNative *_vec = NULL;
3483 if ((_vec = (SFVec3fNative *)JS_GetPrivateFw(cx, _ob1)) == NULL) {
3484 printf( "JS_GetPrivate failed for arg format \"o d\" in SFRotationConstr.\n");
3485 return JS_FALSE;
3486 }
3487 vec = _vec->v.c;
3488 }
3489 }
3490 //if (JSVAL_IS_OBJECT(argv[1])) {
3491 if (argv[1].isObject()) {
3492/* _ob2 = (JSObject *)argv[1]; */
3493 _ob2 = JSVAL_TO_OBJECT(argv[1]);
3494
3495 v3fv3f = TRUE;
3496
3497 CHECK_CLASS(cx,_ob2,argv,__FUNCTION__,SFVec3fClass)
3498 if(SM_method()==2){
3499 AnyNative *_vec2 = NULL;
3500 if ((_vec2 = (AnyNative *)JS_GetPrivateFw(cx, _ob2)) == NULL) {
3501 printf( "JS_GetPrivate failed for _ob1 in SFRotationConstr.\n");
3502 return JS_FALSE;
3503 }
3504 vec2 = _vec2->v->sfvec3f.c;
3505 }else{
3506 SFVec3fNative *_vec2 = NULL;
3507 if ((_vec2 = (SFVec3fNative *)JS_GetPrivateFw(cx, _ob2)) == NULL) {
3508 printf( "JS_GetPrivate failed for _ob1 in SFRotationConstr.\n");
3509 return JS_FALSE;
3510 }
3511 vec2 = _vec2->v.c;
3512 }
3513 } else {
3514 v3fv3f = FALSE;
3515 if (!JSVAL_IS_NUMBER(argv[1])) {
3516 printf ("SFRotationConstr param error - number expected\n");
3517 return JS_FALSE;
3518 }
3519 if (!JS_ValueToNumber(cx, argv[1], &doub)) {
3520 printf("JS_ValueToNumber failed in SFRotationConstr.\n");
3521 return JS_FALSE;
3522 }
3523 }
3524
3525
3526 if (!v3fv3f) {
3527 cc[0] = vec[0];
3528 cc[1] = vec[1];
3529 cc[2] = vec[2];
3530 cc[3] = (float) doub;
3531 } else {
3532 v1len = veclength3f(vec);
3533 v2len = veclength3f(vec2);
3534 v12dp = vecdot3f(vec,vec2);
3535 veccross3f(cc,vec,vec2); //I think the following is cross product
3536 //(ptr->v).c[0] = (float) (v1.y * v2.z - v2.y * v1.z);
3537 //(ptr->v).c[1] = (float) (v1.z * v2.x - v2.z * v1.x);
3538 //(ptr->v).c[2] = (float) (v1.x * v2.y - v2.x * v1.y);
3539 v12dp /= v1len * v2len;
3540 cc[3] = (float) atan2(sqrt(1 - v12dp * v12dp), v12dp);
3541 }
3542 } else if (argc == 4 && JS_ConvertArguments(cx, argc, argv, "d d d d",
3543 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]))) {
3544 cc[0] = (float) pars[0];
3545 cc[1] = (float) pars[1];
3546 cc[2] = (float) pars[2];
3547 cc[3] = (float) pars[3];
3548 } else {
3549 printf( "Invalid arguments for SFRotationConstr.\n");
3550 return JS_FALSE;
3551 }
3552
3553 #ifdef JSVRMLCLASSESVERBOSE
3554 printf("SFRotationConstr: obj = %p, %u args, %f %f %f %f\n",
3555 obj, argc,
3556 cc[0], cc[1], cc[2], cc[3]);
3557 #endif
3558
3559
3560 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
3561
3562
3563 return JS_TRUE;
3564}
3565
3566JSBool
3567SFRotationGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
3568 JSObject *obj = *hobj.address();
3569 jsid iid = *hiid.address();
3570 jsval *vp = hvp.address();
3571
3572 jsdouble d;
3573 float *cc;
3574
3575 jsval id;
3576 if (!JS_IdToValue(cx,iid,&id)) {
3577 printf("JS_IdToValue failed in SFRotationGetProperty.\n");
3578 return JS_FALSE;
3579 }
3580
3581
3582 #ifdef JSVRMLCLASSESVERBOSE
3583 printf ("start of SFRotationGetProperty\n");
3584 #endif
3585 if(SM_method()== 2){
3586 AnyNative *ptr;
3587 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3588 printf( "JS_GetPrivate failed in SFRotationGetProperty.\n");
3589 return JS_FALSE;
3590 }
3591 cc = ptr->v->sfrotation.c;
3592 }else{
3593 SFRotationNative *ptr;
3594 if ((ptr = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3595 printf( "JS_GetPrivate failed in SFRotationGetProperty.\n");
3596 return JS_FALSE;
3597 }
3598 cc = ptr->v.c;
3599 }
3600 if (JSVAL_IS_INT(id)) {
3601 switch (JSVAL_TO_INT(id)) {
3602 case 0:
3603 d = cc[0];
3604 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
3605 printf(
3606 "JS_NewDouble failed for %f in SFRotationGetProperty.\n",
3607 d);
3608 return JS_FALSE;
3609 }
3610 break;
3611 case 1:
3612 d = cc[1];
3613 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
3614 printf(
3615 "JS_NewDouble failed for %f in SFRotationGetProperty.\n",
3616 d);
3617 return JS_FALSE;
3618 }
3619 break;
3620 case 2:
3621 d = cc[2];
3622 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
3623 printf(
3624 "JS_NewDouble failed for %f in SFRotationGetProperty.\n",
3625 d);
3626 return JS_FALSE;
3627 }
3628 break;
3629 case 3:
3630 d = cc[3];
3631 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
3632 printf(
3633 "JS_NewDouble failed for %f in SFRotationGetProperty.\n",
3634 d);
3635 return JS_FALSE;
3636 }
3637 break;
3638 }
3639 }
3640 return JS_TRUE;
3641}
3642
3643JSBool
3644SFRotationSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
3645 JSObject *obj = *hobj.address();
3646 jsid iid = *hiid.address();
3647 jsval *vp = hvp.address();
3648
3649 jsval myv;
3650 float *cc;
3651
3652
3653 jsval id;
3654 if (!JS_IdToValue(cx,iid,&id)) {
3655 printf("JS_IdToValue failed in SFRotationSetProperty.\n");
3656 return JS_FALSE;
3657 }
3658
3659
3660 #ifdef JSVRMLCLASSESVERBOSE
3661 printf ("start of SFRotationSetProperty\n");
3662 #endif
3663 if(SM_method() == 2){
3664 AnyNative *any;
3665 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3666 printf( "JS_GetPrivate failed in SFRotationProperty.\n");
3667 return JS_FALSE;
3668 }
3669 if(any->valueChanged)
3670 (*any->valueChanged)++;
3671 cc = any->v->sfrotation.c;
3672 }else{
3673 SFRotationNative *ptr;
3674
3675 if ((ptr = (SFRotationNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
3676 printf( "JS_GetPrivate failed in SFRotationSetProperty.\n");
3677 return JS_FALSE;
3678 }
3679 ptr->valueChanged++;
3680 #ifdef JSVRMLCLASSESVERBOSE
3681 printf("SFRotationSetProperty: obj = %p, id = %d, valueChanged = %d\n",
3682 obj, JSVAL_TO_INT(id), ptr->valueChanged);
3683 #endif
3684 cc = ptr->v.c;
3685 }
3686 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
3687 printf( "JS_ConvertValue failed in SFRotationSetProperty.\n");
3688 return JS_FALSE;
3689 }
3690
3691 if (JSVAL_IS_INT(id)) {
3692 switch (JSVAL_TO_INT(id)) {
3693 case 0:
3694 cc[0] = (float) JSVAL_TO_DOUBLE(myv);
3695 break;
3696 case 1:
3697 cc[1] = (float) JSVAL_TO_DOUBLE(myv);
3698 break;
3699 case 2:
3700 cc[2] = (float) JSVAL_TO_DOUBLE(myv);
3701 break;
3702 case 3:
3703 cc[3] = (float) JSVAL_TO_DOUBLE(myv);
3704 break;
3705 }
3706 }
3707 return JS_TRUE;
3708}
3709
3710/********************************************************************/
3711
3712/* Generic SFVec2f routines that return a SFVec2f */
3713#define __2FADD 1
3714#define __2FDIVIDE 2
3715#define __2FMULT 3
3716#define __2FSUBT 4
3717#define __2FDOT 5
3718#define __2FLENGTH 6
3719#define __2FNORMALIZE 8
3720JSBool SFVec2fGeneric( JSContext *cx, JSObject *obj,
3721 uintN argc, jsval *argv, jsval *rval, int op) {
3722
3723 JSObject *_paramObj, *_proto, *_retObj;
3724 jsdouble d=0.0;
3725 jsdouble d0=0.0;
3726 jsdouble d1=0.0;
3727 struct point_XYZ v1, v2;
3728 float *cc, *cc2, cc3[2], cclhs[2];
3729
3730
3731 /* parameters */
3732 int SFParam = FALSE;
3733 int numParam = FALSE;
3734
3735 /* return values */
3736 int retSFVec2f = FALSE;
3737 int retNumeric = FALSE;
3738
3739 /* is the "argv" parameter a string? */
3740 int param_isString;
3741 char *charString;
3742 jsdouble pars[3];
3743 JSString *_str;
3744
3745 /* determine what kind of parameter to get */
3746 if ((op==__2FADD)||(op==__2FDOT)||(op==__2FSUBT))SFParam=TRUE;
3747 if ((op==__2FDIVIDE)||(op==__2FMULT))numParam=TRUE;
3748
3749 /* determine the return value, if it is NOT a SFVec2f */
3750 if ((op==__2FDOT)||(op==__2FLENGTH)) retNumeric = TRUE;
3751 retSFVec2f = (!retNumeric);
3752
3753 /* is the parameter a string, possibly gotten from the VRML/X3d
3754 * side of things? */
3755 param_isString = JSVAL_IS_STRING (*argv);
3756
3757 /* get the parameter */
3758 if ((SFParam) || (numParam)) {
3759 if (numParam) {
3760 if (!JSVAL_IS_NUMBER(argv[0])) {
3761 printf ("SFVec2f param error - number expected\n");
3762 return JS_FALSE;
3763 }
3764 if (!JS_ValueToNumber(cx, argv[0], &d)) {
3765 printf("JS_ValueToNumber failed in SFVec2f.\n");
3766 return JS_FALSE;
3767 }
3768 } else {
3769 /* did this come in from VRML as a string, or did
3770 * it get created in javascript? */
3771 if (param_isString) {
3772 _str = JS_ValueToString(cx, *argv);
3773 charString = JS_EncodeString(cx,_str);
3774
3775 if (sscanf(charString, "%lf %lf",
3776 &(pars[0]), &(pars[1])) != 2) {
3777 printf ("conversion problem in SFVec2fGeneric\n");
3778 return JS_FALSE;
3779 }
3780 /* printf ("past scan, %f %f %f\n",pars[0], pars[1]);*/
3781 cc3[0] = pars[0];
3782 cc3[1] = pars[1];
3783 cc2 = cc3;
3784 } else {
3785 if(SM_method()==2){
3786 if (argv[0].isObject()) {
3787 AnyNative *_vec2;
3788 if ((_vec2 = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
3789 printf("in SFVec2f, RHS was NOT native type \n");
3790 return JS_FALSE;
3791 }
3792 //if(_vec2->type == FIELDTYPE_SFVec2f) or color. if 3d convert....
3793 cc2 = _vec2->v->sfvec2f.c;
3794 }else{
3795 return JS_FALSE;
3796 }
3797
3798 }else{
3799 SFVec2fNative *_vec2 = NULL;
3800
3801 if (!JS_ConvertArguments(cx, argc, argv, "o", &_paramObj)) {
3802 printf( "JS_ConvertArguments failed in SFVec2f.\n");
3803 return JS_FALSE;
3804 }
3805
3806 CHECK_CLASS(cx,_paramObj,argv,__FUNCTION__,SFVec2fClass)
3807
3808 if ((_vec2 = (SFVec2fNative*)JS_GetPrivateFw(cx, _paramObj)) == NULL) {
3809 printf( "JS_GetPrivate failed for _paramObj in SFVec2f.\n");
3810 return JS_FALSE;
3811 }
3812 cc2 = _vec2->v.c;
3813 }
3814 }
3815 }
3816 }
3817
3818 /* get our values */
3819 if(SM_method() == 2){
3820 AnyNative *_vec1;
3821 if ((_vec1 = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
3822 printf( "JS_GetPrivate failed for obj in SFVec3fAdd.\n");
3823 return JS_FALSE;
3824 }
3825 cc = _vec1->v->sfvec2f.c;
3826 }else{
3827 SFVec2fNative *_vec1 = NULL;
3828 if ((_vec1 = (SFVec2fNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
3829 printf( "JS_GetPrivate failed for obj in SFVec2fAdd.\n");
3830 return JS_FALSE;
3831 }
3832 cc = _vec1->v.c;
3833 }
3834 /* do the operation */
3835 switch (op) {
3836 /* returning a SFVec2f */
3837 case __2FADD:
3838 vecadd2f(cclhs,cc,cc2);
3839 break;
3840 case __2FDIVIDE:
3841 vecscale2f(cclhs,cc,1.0/d);
3842 break;
3843 case __2FMULT:
3844 vecscale2f(cclhs,cc,d);
3845 break;
3846 case __2FSUBT:
3847 vecdif2f(cclhs,cc,cc2);
3848 break;
3849 case __2FDOT:
3850 d = vecdot2f(cc,cc2);
3851 break;
3852 case __2FLENGTH:
3853 d = veclength2f(cc);
3854 break;
3855 case __2FNORMALIZE:
3856 vecnormal2f(cclhs,cc);
3857 break;
3858 default:
3859 return JS_FALSE;
3860 }
3861
3862 /* set the return object */
3863 if (retSFVec2f) {
3864 if ((_proto = JS_GetPrototypeFw(cx, obj)) == NULL) {
3865 printf( "JS_GetPrototype failed in SFVec2f.\n");
3866 return JS_FALSE;
3867 }
3868 if ((_retObj =
3869 JS_ConstructObjectFw(cx, &SFVec2fClass, _proto, NULL)) == NULL) {
3870 printf( "JS_ConstructObject failed in SFVec2f.\n");
3871 return JS_FALSE;
3872 }
3873 *rval = OBJECT_TO_JSVAL(_retObj);
3874 if(SM_method() == 2){
3875 AnyNative *any;
3876 if ((any = (AnyNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3877 printf( "JS_GetPrivate failed for _retObj in SFVec3f.\n");
3878 return JS_FALSE;
3879 }
3880 memcpy(any->v->sfvec2f.c,cclhs,2*sizeof(float));
3881 }else{
3882 SFVec3fNative *_retNative;
3883 if ((_retNative = (SFVec3fNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
3884 printf( "JS_GetPrivate failed for _retObj in SFVec3f.\n");
3885 return JS_FALSE;
3886 }
3887 memcpy(_retNative->v.c,cclhs,2*sizeof(float));
3888 }
3889
3890 } else if (retNumeric) {
3891 if (JS_NewNumberValue(cx,d,rval) == JS_FALSE) {
3892 printf( "JS_NewDouble failed for %f in SFVec2f.\n",d);
3893 return JS_FALSE;
3894 }
3895 }
3896
3897 #ifdef JSVRMLCLASSESVERBOSE
3898 if (retSFVec2f){
3899 printf("SFVec2fgeneric: obj = %p, result = [%.9g, %.9g]\n",
3900 obj,
3901 (_retNative->v).c[0], (_retNative->v).c[1]);
3902 }
3903 if (retNumeric){
3904 printf("SFVec2fgeneric: obj = %p, result = %.9g\n",
3905 obj, d);
3906 }
3907 #endif
3908
3909 return JS_TRUE;
3910}
3911
3912JSBool
3913SFVec2fAdd(JSContext *cx, uintN argc, jsval *vp) {
3914 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3915 jsval *argv = JS_ARGV(cx,vp);
3916 jsval rval;
3917 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FADD);
3918 JS_SET_RVAL(cx,vp,rval);
3919 return retval;
3920
3921}
3922
3923JSBool
3924SFVec2fDivide(JSContext *cx, uintN argc, jsval *vp) {
3925 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3926 jsval *argv = JS_ARGV(cx,vp);
3927 jsval rval;
3928 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FDIVIDE);
3929 JS_SET_RVAL(cx,vp,rval);
3930 return retval;
3931}
3932
3933JSBool
3934SFVec2fMultiply(JSContext *cx, uintN argc, jsval *vp) {
3935 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3936 jsval *argv = JS_ARGV(cx,vp);
3937 jsval rval;
3938 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FMULT);
3939 JS_SET_RVAL(cx,vp,rval);
3940 return retval;
3941
3942}
3943
3944JSBool
3945SFVec2fSubtract(JSContext *cx, uintN argc, jsval *vp) {
3946 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3947 jsval *argv = JS_ARGV(cx,vp);
3948 jsval rval;
3949 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FSUBT);
3950 JS_SET_RVAL(cx,vp,rval);
3951 return retval;
3952
3953}
3954
3955JSBool
3956SFVec2fDot(JSContext *cx, uintN argc, jsval *vp) {
3957 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3958 jsval *argv = JS_ARGV(cx,vp);
3959 jsval rval;
3960 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FDOT);
3961 JS_SET_RVAL(cx,vp,rval);
3962 return retval;
3963}
3964
3965JSBool
3966SFVec2fLength(JSContext *cx, uintN argc, jsval *vp) {
3967 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3968 jsval *argv = JS_ARGV(cx,vp);
3969 jsval rval;
3970 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FLENGTH);
3971 JS_SET_RVAL(cx,vp,rval);
3972 return retval;
3973
3974}
3975
3976JSBool
3977SFVec2fNormalize(JSContext *cx, uintN argc, jsval *vp) {
3978 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3979 jsval *argv = JS_ARGV(cx,vp);
3980 jsval rval;
3981 JSBool retval = SFVec2fGeneric(cx, obj, argc, argv, &rval, __2FNORMALIZE);
3982 JS_SET_RVAL(cx,vp,rval);
3983 return retval;
3984}
3985
3986JSBool
3987SFVec2fToString(JSContext *cx, uintN argc, jsval *vp) {
3988 JSObject *obj = JS_THIS_OBJECT(cx,vp);
3989 jsval *argv = JS_ARGV(cx,vp);
3990 JSString *_str;
3991 char buff[STRING];
3992 float *cc;
3993
3994 UNUSED(argc);
3995 UNUSED(argv);
3996 if(SM_method()==2){
3997 AnyNative *ptr;
3998 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
3999 printf( "JS_GetPrivate failed in SFVec2fToString.\n");
4000 return JS_FALSE;
4001 }
4002 cc = ptr->v->sfvec2f.c;
4003 }else{
4004 SFVec2fNative *ptr;
4005 if ((ptr = (SFVec2fNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
4006 printf( "JS_GetPrivate failed in SFVec2fToString.\n");
4007 return JS_FALSE;
4008 }
4009 cc = ptr->v.c;
4010 }
4011 memset(buff, 0, STRING);
4012 sprintf(buff, "%.9g %.9g",
4013 cc[0], cc[1]);
4014 _str = JS_NewStringCopyZ(cx, buff);
4015 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
4016
4017 return JS_TRUE;
4018}
4019
4020JSBool
4021SFVec2fAssign(JSContext *cx, uintN argc, jsval *vp) {
4022 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4023 jsval *argv = JS_ARGV(cx,vp);
4024 JSString *_id_jsstr;
4025
4026 JSObject *_from_obj;
4027 char *_id_str;
4028
4029 UNUSED(_id_str); // compiler warning mitigation
4030
4031 if(SM_method() == 2){
4032 AnyNative *lhs, *rhs;
4033 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4034 printf( "JS_GetPrivate failed for obj in SFVec3dAssign.\n");
4035 return JS_FALSE;
4036 }
4037 if (!(*vp).isObject())
4038 return JS_FALSE;
4039 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
4040 printf("JS_ConvertArguments failed in SFVec2fAssign. \n");
4041 return JS_FALSE;
4042 }
4043 AnyNativeAssign(lhs,rhs);
4044 }else{
4045 SFVec2fNative *fptr, *ptr;
4046
4047 if ((ptr = (SFVec2fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4048 printf( "JS_GetPrivate failed for obj in SFVec2fAssign.\n");
4049 return JS_FALSE;
4050 }
4051
4052 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFVec2fClass)
4053
4054 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
4055 _id_str = JS_EncodeString(cx,_id_jsstr);
4056 } else {
4057
4058 printf( "JS_ConvertArguments failed in SFVec2fAssign.\n");
4059 return JS_FALSE;
4060 }
4061
4062 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFVec2fClass)
4063
4064 if ((fptr = (SFVec2fNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
4065 printf( "JS_GetPrivate failed for _from_obj in SFVec2fAssign.\n");
4066 return JS_FALSE;
4067 }
4068 #ifdef JSVRMLCLASSESVERBOSE
4069 printf("SFVec2fAssign: obj = %p, id = \"%s\", from = %p\n",
4070 obj, _id_str, _from_obj);
4071 #endif
4072
4073 SFVec2fNativeAssign(ptr, fptr);
4074 }
4075 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
4076
4077
4078 return JS_TRUE;
4079}
4080
4081JSBool
4082SFVec2fConstr(JSContext *cx, uintN argc, jsval *vp) {
4083 JSObject *obj = JS_NewObject(cx,&SFVec2fClass,NULL,NULL);
4084 jsval *argv = JS_ARGV(cx,vp);
4085
4086 jsdouble pars[2];
4087 float *cc;
4088
4089 ADD_ROOT(cx,obj)
4090
4091 if(SM_method() == 2){
4092 AnyNative *any;
4093 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFVec2f,NULL,NULL)) == NULL){
4094 printf( "AnyfNativeNew failed in SFVec3fConstr.\n");
4095 return JS_FALSE;
4096 }
4097 if (!JS_SetPrivateFw(cx, obj, any)) {
4098 printf( "JS_SetPrivate failed in SFVec2fConstr.\n");
4099 return JS_FALSE;
4100 }
4101
4102 cc = any->v->sfvec2f.c;
4103 }else{
4104 SFVec2fNative *ptr;
4105
4106 if ((ptr = (SFVec2fNative *) SFVec2fNativeNew()) == NULL) {
4107 printf( "SFVec2fNativeNew failed in SFVec2fConstr.\n");
4108 return JS_FALSE;
4109 }
4110
4111 //if (!JS_DefineProperties(cx, obj, SFVec2fProperties)) {
4112 // printf( "JS_DefineProperties failed in SFVec2fConstr.\n");
4113 // return JS_FALSE;
4114 //}
4115 if (!JS_SetPrivateFw(cx, obj, ptr)) {
4116 printf( "JS_SetPrivate failed in SFVec2fConstr.\n");
4117 return JS_FALSE;
4118 }
4119 cc = ptr->v.c;
4120 ptr->valueChanged = 1;
4121
4122 }
4123 if (argc == 0) {
4124 cc[0] = (float) 0.0;
4125 cc[1] = (float) 0.0;
4126 } else {
4127 if (!JS_ConvertArguments(cx, argc, argv, "d d", &(pars[0]), &(pars[1]))) {
4128 printf( "JS_ConvertArguments failed in SFVec2fConstr.\n");
4129 return JS_FALSE;
4130 }
4131 cc[0] = (float) pars[0];
4132 cc[1] = (float) pars[1];
4133 }
4134 #ifdef JSVRMLCLASSESVERBOSE
4135 printf("SFVec2fConstr: obj = %p, %u args, %f %f\n",
4136 obj, argc,
4137 (ptr->v).c[0], (ptr->v).c[1]);
4138 #endif
4139
4140
4141 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
4142
4143 return JS_TRUE;
4144}
4145
4146
4147JSBool
4148SFVec2fGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
4149 JSObject *obj = *hobj.address();
4150 jsid iid = *hiid.address();
4151 jsval *vp = hvp.address();
4152
4153 jsdouble d;
4154 float *cc;
4155
4156 jsval id;
4157 if (!JS_IdToValue(cx,iid,&id)) {
4158 printf("JS_IdToValue failed in SFVec2fGetProperty.\n");
4159 return JS_FALSE;
4160 }
4161
4162
4163 if(SM_method()==2){
4164 AnyNative *any;
4165 if ((any = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
4166 printf( "JS_GetPrivate failed in SFVec2fGetProperty.\n");
4167 return JS_FALSE;
4168 }
4169 cc = any->v->sfvec2f.c;
4170 }else{
4171 SFVec2fNative *ptr;
4172
4173 if ((ptr = (SFVec2fNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
4174 printf( "JS_GetPrivate failed in SFVec2fGetProperty.\n");
4175 return JS_FALSE;
4176 }
4177 cc = ptr->v.c;
4178 }
4179 if (JSVAL_IS_INT(id)) {
4180 switch (JSVAL_TO_INT(id)) {
4181 case 0:
4182 d = cc[0];
4183 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
4184 printf(
4185 "JS_NewDouble failed for %f in SFVec2fGetProperty.\n",
4186 d);
4187 return JS_FALSE;
4188 }
4189 break;
4190 case 1:
4191 d = cc[1];
4192 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
4193 printf(
4194 "JS_NewDouble failed for %f in SFVec2fGetProperty.\n",
4195 d);
4196 return JS_FALSE;
4197 }
4198 break;
4199 }
4200 }
4201 return JS_TRUE;
4202}
4203
4204JSBool
4205SFVec2fSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
4206 JSObject *obj = *hobj.address();
4207 jsid iid = *hiid.address();
4208 jsval *vp = hvp.address();
4209
4210 jsval myv;
4211 float *cc;
4212
4213
4214 jsval id;
4215 if (!JS_IdToValue(cx,iid,&id)) {
4216 printf("JS_IdToValue failed in SFVec2fSetProperty.\n");
4217 return JS_FALSE;
4218 }
4219
4220
4221 if(SM_method() == 2){
4222 AnyNative *any;
4223 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4224 printf( "JS_GetPrivate failed in SFVec2fSetProperty.\n");
4225 return JS_FALSE;
4226 }
4227 if(any->valueChanged)
4228 (*any->valueChanged)++;
4229 cc = any->v->sfvec2f.c;
4230 }else{
4231 SFVec2fNative *ptr;
4232
4233 if ((ptr = (SFVec2fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4234 printf( "JS_GetPrivate failed in SFVec2fSetProperty.\n");
4235 return JS_FALSE;
4236 }
4237 ptr->valueChanged++;
4238 #ifdef JSVRMLCLASSESVERBOSE
4239 printf("SFVec2fSetProperty: obj = %p, id = %d, valueChanged = %d\n",
4240 obj, JSVAL_TO_INT(id), ptr->valueChanged);
4241 #endif
4242 cc = ptr->v.c;
4243 }
4244 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
4245 printf( "JS_ConvertValue failed in SFVec2fSetProperty.\n");
4246 return JS_FALSE;
4247 }
4248
4249 if (JSVAL_IS_INT(id)) {
4250 switch (JSVAL_TO_INT(id)) {
4251 case 0:
4252 cc[0] = (float) JSVAL_TO_DOUBLE(myv);
4253 break;
4254 case 1:
4255 cc[1] = (float) JSVAL_TO_DOUBLE(myv);
4256 break;
4257 default: break;
4258 }
4259 }
4260 return JS_TRUE;
4261}
4262
4263
4264/********************************************************************/
4265
4266/* Generic SFVec3f routines that return a SFVec3f */
4267#define __3FADD 1
4268#define __3FDIVIDE 2
4269#define __3FMULT 3
4270#define __3FSUBT 4
4271#define __3FDOT 5
4272#define __3FLENGTH 6
4273#define __3FNORMALIZE 8
4274#define __3FNEGATE 7
4275#define __3FCROSS 9
4276
4277JSBool SFVec3fGeneric( JSContext *cx, JSObject *obj,
4278 uintN argc, jsval *argv, jsval *rval, int op) {
4279 JSObject *_paramObj, *_proto, *_retObj;
4280 //SFVec3fNative *_vec1, *_vec2, *_retNative;
4281 jsdouble d=0.0;
4282 jsdouble d0=0.0;
4283 jsdouble d1=0.0;
4284 jsdouble d2=0.0;
4285 struct point_XYZ v1, v2, ret;
4286 float *cc, *cc2, cc3[3], cclhs[3];
4287
4288
4289 /* parameters */
4290 int SFParam = FALSE;
4291 int numParam = FALSE;
4292
4293 /* return values */
4294 int retSFVec3f = FALSE;
4295 int retNumeric = FALSE;
4296
4297 /* is the "argv" parameter a string? */
4298 int param_isString;
4299 char *charString;
4300 jsdouble pars[3];
4301 JSString *_str;
4302
4303 #ifdef JSVRMLCLASSESVERBOSE
4304 printf ("SFVec3fGeneric\n");
4305 #endif
4306
4307 /* determine what kind of parameter to get */
4308 if ((op==__3FADD)||(op==__3FDOT)||(op==__3FCROSS)||(op==__3FSUBT))SFParam=TRUE;
4309 if ((op==__3FDIVIDE)||(op==__3FMULT))numParam=TRUE;
4310
4311 /* determine the return value, if it is NOT a SFVec3f */
4312 if ((op==__3FDOT)||(op==__3FLENGTH)) retNumeric = TRUE;
4313 retSFVec3f = (!retNumeric);
4314
4315 /* is the parameter a string, possibly gotten from the VRML/X3d
4316 * side of things? */
4317 param_isString = JSVAL_IS_STRING (*argv);
4318
4319 /* get the parameter */
4320 if ((SFParam) || (numParam)) {
4321 if (numParam) {
4322 if (!JSVAL_IS_NUMBER(argv[0])) {
4323 printf ("SFVec3f param error - number expected\n");
4324 return JS_FALSE;
4325 }
4326 if (!JS_ValueToNumber(cx, argv[0], &d)) {
4327 printf("JS_ValueToNumber failed in SFVec3f.\n");
4328 return JS_FALSE;
4329 }
4330 } else {
4331 /* did this come in from VRML as a string, or did
4332 * it get created in javascript? */
4333 if (param_isString) {
4334 _str = JS_ValueToString(cx, *argv);
4335 charString = JS_EncodeString(cx,_str);
4336 if (sscanf(charString, "%lf %lf %lf",
4337 &(pars[0]), &(pars[1]), &(pars[2])) != 3) {
4338 printf ("conversion problem in SFVec3fGeneric\n");
4339 return JS_FALSE;
4340 }
4341 /* printf ("past scan, %f %f %f\n",pars[0], pars[1],pars[2]);*/
4342 cc3[0] = pars[0];
4343 cc3[1] = pars[1];
4344 cc3[2] = pars[2];
4345 cc2 = cc3;
4346 } else {
4347 if(SM_method() == 2){
4348 if (argv[0].isObject()) {
4349 AnyNative *_vec2;
4350 if ((_vec2 = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
4351 printf("in SFVec3d, RHS was NOT native type \n");
4352 return JS_FALSE;
4353 }
4354 //if(_vec2->type == FIELDTYPE_SFVec3f) or color. if 3d convert....
4355 cc2 = _vec2->v->sfvec3f.c;
4356 }else{
4357 return JS_FALSE;
4358 }
4359
4360 }else{
4361 SFVec3fNative *_vec2;
4362 if (!JS_ConvertArguments(cx, argc, argv, "o", &_paramObj)) {
4363 printf( "JS_ConvertArguments failed in SFVec3f.\n");
4364 return JS_FALSE;
4365 }
4366
4367 CHECK_CLASS(cx,_paramObj,argv,__FUNCTION__,SFVec3fClass)
4368
4369 /* get the second object's data */
4370 if ((_vec2 = (SFVec3fNative*)JS_GetPrivateFw(cx, _paramObj)) == NULL) {
4371 printf( "JS_GetPrivate failed for _paramObj in SFVec3f.\n");
4372 return JS_FALSE;
4373 }
4374 cc2 = _vec2->v.c;
4375 }
4376 }
4377 }
4378 }
4379
4380 /* get our values */
4381 if(SM_method() == 2){
4382 AnyNative *_vec1;
4383 if ((_vec1 = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
4384 printf( "JS_GetPrivate failed for obj in SFVec3fAdd.\n");
4385 return JS_FALSE;
4386 }
4387 cc = _vec1->v->sfvec3f.c;
4388 }else{
4389 SFVec3fNative *_vec1;
4390 if ((_vec1 = (SFVec3fNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
4391 printf( "JS_GetPrivate failed for obj in SFVec3fAdd.\n");
4392 return JS_FALSE;
4393 }
4394 cc = _vec1->v.c;
4395 }
4396 /* do the operation */
4397 #ifdef JSVRMLCLASSESVERBOSE
4398 printf ("SFVec3f generic, vec2 %f %f %f\n",pars[0],pars[1],pars[2]);
4399 #endif
4400
4401 switch (op) {
4402 /* returning a SFVec3f */
4403 case __3FADD:
4404 vecadd3f(cclhs,cc,cc2);
4405 break;
4406 case __3FDIVIDE:
4407 vecscale3f(cclhs,cc,1.0/d);
4408 break;
4409 case __3FMULT:
4410 vecscale3f(cclhs,cc,d);
4411 break;
4412 case __3FSUBT:
4413 vecdif3f(cclhs,cc,cc2);
4414 break;
4415 case __3FDOT:
4416 d = vecdot3f(cc,cc2);
4417 break;
4418 case __3FCROSS:
4419 veccross3f(cclhs,cc,cc2);
4420 break;
4421 case __3FLENGTH:
4422 d = veclength3f(cc);
4423 break;
4424 case __3FNORMALIZE:
4425 vecnormalize3f(cclhs,cc);
4426 break;
4427 case __3FNEGATE:
4428 vecnegate3f(cclhs,cc);
4429 break;
4430 default:
4431 printf ("woops... %d\n",op);
4432 return JS_FALSE;
4433 }
4434
4435 #ifdef JSVRMLCLASSESVERBOSE
4436 printf ("past calcs\n");
4437 #endif
4438
4439 /* set the return object */
4440 if (retSFVec3f) {
4441 #ifdef JSVRMLCLASSESVERBOSE
4442 printf ("returning SFVec3f\n");
4443 #endif
4444 if ((_proto = JS_GetPrototypeFw(cx, obj)) == NULL) {
4445 printf( "JS_GetPrototype failed in SFVec3f.\n");
4446 return JS_FALSE;
4447 }
4448 if ((_retObj =
4449 JS_ConstructObjectFw(cx, &SFVec3fClass, _proto, NULL)) == NULL) {
4450 printf( "JS_ConstructObject failed in SFVec3f.\n");
4451 return JS_FALSE;
4452 }
4453 *rval = OBJECT_TO_JSVAL(_retObj);
4454 if(SM_method() == 2){
4455 AnyNative *any;
4456 if ((any = (AnyNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
4457 printf( "JS_GetPrivate failed for _retObj in SFVec3f.\n");
4458 return JS_FALSE;
4459 }
4460 memcpy(any->v->sfvec3f.c,cclhs,3*sizeof(float));
4461 }else{
4462 SFVec3fNative *_retNative;
4463 if ((_retNative = (SFVec3fNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
4464 printf( "JS_GetPrivate failed for _retObj in SFVec3f.\n");
4465 return JS_FALSE;
4466 }
4467 memcpy(_retNative->v.c,cclhs,3*sizeof(float));
4468 }
4469 } else if (retNumeric) {
4470 if (JS_NewNumberValue(cx,d,rval) == JS_FALSE) {
4471 printf( "JS_NewDouble failed for %f in SFVec3f.\n",d);
4472 return JS_FALSE;
4473 }
4474 }
4475 #ifdef JSVRMLCLASSESVERBOSE
4476 if (retSFVec3f){
4477 printf("SFVec3fgeneric: obj = %p, result = [%.9g, %.9g, %.9g]\n",
4478 obj,
4479 (_retNative->v).c[0], (_retNative->v).c[1],
4480 (_retNative->v).c[2]);
4481 }
4482 if (retNumeric){
4483 printf("SFVec2fgeneric: obj = %p, result = %.9g\n",
4484 obj, d);
4485 }
4486 #endif
4487return JS_TRUE;
4488}
4489
4490JSBool
4491SFVec3fAdd(JSContext *cx, uintN argc, jsval *vp) {
4492 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4493 jsval *argv = JS_ARGV(cx,vp);
4494 jsval rval;
4495 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FADD);
4496 JS_SET_RVAL(cx,vp,rval);
4497 return retval;
4498}
4499
4500JSBool
4501SFVec3fCross(JSContext *cx, uintN argc, jsval *vp) {
4502 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4503 jsval *argv = JS_ARGV(cx,vp);
4504 jsval rval;
4505 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FCROSS);
4506 JS_SET_RVAL(cx,vp,rval);
4507 return retval;
4508}
4509
4510JSBool
4511SFVec3fDivide(JSContext *cx, uintN argc, jsval *vp) {
4512 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4513 jsval *argv = JS_ARGV(cx,vp);
4514 jsval rval;
4515 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FDIVIDE);
4516 JS_SET_RVAL(cx,vp,rval);
4517 return retval;
4518}
4519
4520JSBool
4521SFVec3fDot(JSContext *cx, uintN argc, jsval *vp) {
4522 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4523 jsval *argv = JS_ARGV(cx,vp);
4524 jsval rval;
4525 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FDOT);
4526 JS_SET_RVAL(cx,vp,rval);
4527 return retval;
4528}
4529
4530JSBool
4531SFVec3fLength(JSContext *cx, uintN argc, jsval *vp) {
4532 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4533 jsval *argv = JS_ARGV(cx,vp);
4534 jsval rval;
4535 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FLENGTH);
4536 JS_SET_RVAL(cx,vp,rval);
4537 return retval;
4538}
4539
4540
4541JSBool
4542SFVec3fMultiply(JSContext *cx, uintN argc, jsval *vp) {
4543 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4544 jsval *argv = JS_ARGV(cx,vp);
4545 jsval rval;
4546 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FMULT);
4547 JS_SET_RVAL(cx,vp,rval);
4548 return retval;
4549}
4550
4551
4552JSBool
4553SFVec3fNegate(JSContext *cx, uintN argc, jsval *vp) {
4554 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4555 jsval *argv = JS_ARGV(cx,vp);
4556 jsval rval;
4557 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FNEGATE);
4558 JS_SET_RVAL(cx,vp,rval);
4559 return retval;
4560}
4561
4562JSBool
4563SFVec3fNormalize(JSContext *cx, uintN argc, jsval *vp) {
4564 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4565 jsval *argv = JS_ARGV(cx,vp);
4566 jsval rval;
4567 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FNORMALIZE);
4568 JS_SET_RVAL(cx,vp,rval);
4569 return retval;
4570}
4571
4572JSBool
4573SFVec3fSubtract(JSContext *cx, uintN argc, jsval *vp) {
4574 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4575 jsval *argv = JS_ARGV(cx,vp);
4576 jsval rval;
4577 JSBool retval = SFVec3fGeneric(cx, obj, argc, argv, &rval, __3FSUBT);
4578 JS_SET_RVAL(cx,vp,rval);
4579 return retval;
4580}
4581
4582JSBool
4583SFVec3fToString(JSContext *cx, uintN argc, jsval *vp) {
4584 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4585 jsval *argv = JS_ARGV(cx,vp);
4586
4587 JSString *_str;
4588 char buff[STRING];
4589 float *cc;
4590
4591 UNUSED(argc);
4592 UNUSED(argv);
4593 if(SM_method()==2){
4594 AnyNative *ptr;
4595 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4596 printf( "JS_GetPrivate failed in SFVec3fToString.\n");
4597 return JS_FALSE;
4598 }
4599 cc = ptr->v->sfvec3f.c;
4600 }else{
4601 SFVec3fNative *ptr;
4602 if ((ptr = (SFVec3fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4603 printf( "JS_GetPrivate failed in SFVec3fToString.\n");
4604 return JS_FALSE;
4605 }
4606 cc = ptr->v.c;
4607 }
4608 memset(buff, 0, STRING);
4609 sprintf(buff, "%.9g %.9g %.9g",
4610 cc[0], cc[1], cc[2]);
4611 _str = JS_NewStringCopyZ(cx, buff);
4612
4613 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
4614
4615 #ifdef JSVRMLCLASSESVERBOSE
4616 printf ("SFVec3fToString, string is :%s:\n",buff);
4617 #endif
4618
4619 return JS_TRUE;
4620}
4621
4622
4623JSBool
4624SFVec3fAssign(JSContext *cx, uintN argc, jsval *vp) {
4625 JSObject *obj = JS_THIS_OBJECT(cx,vp);
4626 jsval *argv = JS_ARGV(cx,vp);
4627 JSString *_id_jsstr;
4628 JSObject *_from_obj;
4629 char *_id_str;
4630
4631
4632 UNUSED(_id_str); // compiler warning mitigation
4633
4634 #ifdef JSVRMLCLASSESVERBOSE
4635 printf ("start of SFVec3fAssign\n");
4636 #endif
4637
4638 if(SM_method() == 2){
4639 AnyNative *lhs, *rhs;
4640 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4641 printf( "JS_GetPrivate failed for obj in SFVec3dAssign.\n");
4642 return JS_FALSE;
4643 }
4644 if (!(*vp).isObject())
4645 return JS_FALSE;
4646 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
4647 printf("JS_ConvertArguments failed in SFVec3fAssign. \n");
4648 return JS_FALSE;
4649 }
4650 AnyNativeAssign(lhs,rhs);
4651 }else{
4652 SFVec3fNative *fptr, *ptr;
4653 if ((ptr = (SFVec3fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4654 printf( "JS_GetPrivate failed for obj in SFVec3fAssign.\n");
4655 return JS_FALSE;
4656 }
4657
4658 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFVec3fClass)
4659
4660 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr)) {
4661 _id_str = JS_EncodeString(cx,_id_jsstr);
4662 } else {
4663 printf( "JS_ConvertArguments failed in SFVec3fAssign.\n");
4664 return JS_FALSE;
4665 }
4666
4667 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFVec3fClass)
4668
4669 if ((fptr = (SFVec3fNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
4670 printf( "JS_GetPrivate failed for _from_obj in SFVec3fAssign.\n");
4671 return JS_FALSE;
4672 }
4673 #ifdef JSVRMLCLASSESVERBOSE
4674 printf("SFVec3fAssign: obj = %p, id = \"%s\", from = %p\n",
4675 obj, _id_str, _from_obj);
4676 #endif
4677
4678 SFVec3fNativeAssign(ptr, fptr);
4679 }
4680 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
4681
4682 #ifdef JSVRMLCLASSESVERBOSE
4683 printf ("end of SFVec3fAssign\n");
4684 #endif
4685
4686 return JS_TRUE;
4687}
4688
4689JSBool
4690SFVec3fConstr(JSContext *cx, uintN argc, jsval *vp) {
4691 JSObject *obj = JS_NewObject(cx,&SFVec3fClass,NULL,NULL);
4692 jsval *argv = JS_ARGV(cx,vp);
4693 jsdouble pars[3];
4694 float *cc;
4695
4696 #ifdef JSVRMLCLASSESVERBOSE
4697 printf ("start of SFVec3fConstr\n");
4698 #endif
4699
4700 ADD_ROOT(cx,obj)
4701 if(SM_method() == 2){
4702 AnyNative *any;
4703 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFVec3f,NULL,NULL)) == NULL){
4704 printf( "AnyfNativeNew failed in SFVec3fConstr.\n");
4705 return JS_FALSE;
4706 }
4707 if (!JS_SetPrivateFw(cx, obj, any)) {
4708 printf( "JS_SetPrivate failed in SFVec3fConstr.\n");
4709 return JS_FALSE;
4710 }
4711 cc = any->v->sfvec3f.c;
4712 }else{
4713 SFVec3fNative *ptr;
4714 if ((ptr = (SFVec3fNative *) SFVec3fNativeNew()) == NULL) {
4715 printf( "SFVec3fNativeNew failed in SFVec3fConstr.\n");
4716 return JS_FALSE;
4717 }
4718
4719 //if (!JS_DefineProperties(cx, obj, SFVec3fProperties)) {
4720 // printf( "JS_DefineProperties failed in SFVec3fConstr.\n");
4721 // return JS_FALSE;
4722 //}
4723 if (!JS_SetPrivateFw(cx, obj, ptr)) {
4724 printf( "JS_SetPrivate failed in SFVec3fConstr.\n");
4725 return JS_FALSE;
4726 }
4727 ptr->valueChanged = 1;
4728 cc = ptr->v.c;
4729 }
4730 if (argc == 0) {
4731 cc[0] = 0.0f;
4732 cc[1] = 0.0f;
4733 cc[2] = 0.0f;
4734 } else if(argc == 1){
4735 if(SM_method() == 2){
4736 int found = 0;
4737 if (argv[0].isObject()) {
4738 AnyNative *rhs;
4739 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) != NULL) {
4740 union anyVrml *anyv = rhs->v;
4741 int rhstype = rhs->type;
4742 found = 1;
4743 switch(rhstype){
4744 case FIELDTYPE_SFVec3f:
4745 veccopy3f(cc,anyv->sfvec3f.c); break;
4746 case FIELDTYPE_SFVec3d:
4747 double2float(cc,anyv->sfvec3d.c,3); break;
4748 case FIELDTYPE_SFRotation:
4749 veccopy3f(cc,anyv->sfrotation.c); break;
4750 default:
4751 vecset3f(cc,0.0f,0.0f,0.0f);
4752 ConsoleMessage("new SFVec3f( obj ) doesn't handle obj type %d\n",rhstype);
4753 found = 0;
4754 }
4755 }
4756 }
4757 if(!found)
4758 return JS_FALSE;
4759 }
4760 } else {
4761 if (!JS_ConvertArguments(cx, argc, argv, "d d d",
4762 &(pars[0]), &(pars[1]), &(pars[2]))) {
4763 printf( "JS_ConvertArguments failed in SFVec3fConstr.\n");
4764 return JS_FALSE;
4765 }
4766 cc[0] = (float) pars[0];
4767 cc[1] = (float) pars[1];
4768 cc[2] = (float) pars[2];
4769 }
4770 #ifdef JSVRMLCLASSESVERBOSE
4771 printf("SFVec3fConstr: obj = %p, %u args, %f %f %f\n",
4772 obj, argc,
4773 cc[0], cc[1], cc[2]);
4774 #endif
4775
4776
4777 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
4778 return JS_TRUE;
4779}
4780
4781JSBool
4782SFVec3fGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
4783 JSObject *obj = *hobj.address();
4784 jsid iid = *hiid.address();
4785 jsval *vp = hvp.address();
4786
4787 jsdouble d;
4788 float *cc;
4789 #ifdef JSVRMLCLASSESVERBOSE
4790 JSString *_idStr;
4791 char *_id_c;
4792 #endif
4793
4794 jsval id;
4795 if (!JS_IdToValue(cx,iid,&id)) {
4796 printf("JS_IdToValue failed in SFVec3fGetProperty.\n");
4797 return JS_FALSE;
4798 }
4799
4800 #ifdef JSVRMLCLASSESVERBOSE
4801
4802 //JSString *_idStr;
4803 //char *_id_c;
4804
4805/* note, since same variables are used, this first bit gets overwritten -- commenting out
4806 _idStr = JS_ValueToString(cx, id);
4807 _id_c = JS_GetStringBytes(_idStr);*/
4808 _idStr = JS_ValueToString(cx, *vp);
4809#if JS_VERSION < 185
4810 _id_c = JS_GetStringBytes(_idStr);
4811#else
4812 _id_c = JS_EncodeString(cx,_idStr);
4813#endif
4814 #endif
4815 if(SM_method()==2){
4816 AnyNative *any;
4817 if ((any = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
4818 printf( "JS_GetPrivate failed in SFVec3fGetProperty.\n");
4819 return JS_FALSE;
4820 }
4821 cc = any->v->sfvec3f.c;
4822 }else{
4823 SFVec3fNative *ptr;
4824 if ((ptr = (SFVec3fNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
4825 printf( "JS_GetPrivate failed in SFVec3fGetProperty.\n");
4826 return JS_FALSE;
4827 }
4828 cc = ptr->v.c;
4829 }
4830 if (JSVAL_IS_INT(id)) {
4831 switch (JSVAL_TO_INT(id)) {
4832 case 0:
4833 d = cc[0];
4834 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
4835 printf(
4836 "JS_NewDouble failed for %f in SFVec3fGetProperty.\n",
4837 d);
4838 return JS_FALSE;
4839 }
4840 break;
4841 case 1:
4842 d = cc[1];
4843 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
4844 printf(
4845 "JS_NewDouble failed for %f in SFVec3fGetProperty.\n",
4846 d);
4847 return JS_FALSE;
4848 }
4849 break;
4850 case 2:
4851 d = cc[2];
4852 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
4853 printf(
4854 "JS_NewDouble failed for %f in SFVec3fGetProperty.\n",
4855 d);
4856 return JS_FALSE;
4857 }
4858 break;
4859 }
4860 } else {
4861 #ifdef JSVRMLCLASSESVERBOSE
4862 printf ("SFVec3fGetProperty, id is NOT an int...\n");
4863 #endif
4864 }
4865
4866 return JS_TRUE;
4867}
4868
4869JSBool
4870SFVec3fSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
4871 JSObject *obj = *hobj.address();
4872 jsid iid = *hiid.address();
4873 jsval *vp = hvp.address();
4874
4875 jsval myv;
4876 float *cc;
4877
4878 jsval id;
4879 if (!JS_IdToValue(cx,iid,&id)) {
4880 printf("JS_IdToValue failed in SFVec3fSetProperty.\n");
4881 return JS_FALSE;
4882 }
4883
4884
4885 if(SM_method() == 2){
4886 AnyNative *any;
4887 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4888 printf( "JS_GetPrivate failed in SFVec3fSetProperty.\n");
4889 return JS_FALSE;
4890 }
4891 if(any->valueChanged)
4892 (*any->valueChanged)++;
4893 cc = any->v->sfvec3f.c;
4894 }else{
4895 SFVec3fNative *ptr;
4896 if ((ptr = (SFVec3fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
4897 printf( "JS_GetPrivate failed in SFVec3fSetProperty.\n");
4898 return JS_FALSE;
4899 }
4900 ptr->valueChanged++;
4901 #ifdef JSVRMLCLASSESVERBOSE
4902 printf("SFVec3fSetProperty: obj = %p, id = %d, valueChanged = %d\n",
4903 obj, JSVAL_TO_INT(id), ptr->valueChanged);
4904 #endif
4905 cc = ptr->v.c;
4906 }
4907 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
4908 printf( "JS_ConvertValue failed in SFVec3fSetProperty.\n");
4909 return JS_FALSE;
4910 }
4911
4912 if (JSVAL_IS_INT(id)) {
4913 switch (JSVAL_TO_INT(id)) {
4914 case 0:
4915 cc[0] = (float) JSVAL_TO_DOUBLE(myv);
4916 break;
4917 case 1:
4918 cc[1] = (float) JSVAL_TO_DOUBLE(myv);
4919 break;
4920 case 2:
4921 cc[2] = (float) JSVAL_TO_DOUBLE(myv);
4922 break;
4923 }
4924 }
4925 return JS_TRUE;
4926}
4927
4928
4929/********************************************************************/
4930//SFVec2d
4931JSBool SFVec2dGeneric(JSContext* cx, JSObject* obj,
4932 uintN argc, jsval* argv, jsval* rval, int op) {
4933
4934 JSObject* _paramObj, * _proto, * _retObj;
4935 jsdouble d = 0.0;
4936 jsdouble d0 = 0.0;
4937 jsdouble d1 = 0.0;
4938 struct point_XYZ v1, v2;
4939 double* cc, * cc2, cc3[2], cclhs[2];
4940
4941
4942 /* parameters */
4943 int SFParam = FALSE;
4944 int numParam = FALSE;
4945
4946 /* return values */
4947 int retSFVec2d = FALSE;
4948 int retNumeric = FALSE;
4949
4950 /* is the "argv" parameter a string? */
4951 int param_isString;
4952 char* charString;
4953 jsdouble pars[3];
4954 JSString* _str;
4955
4956 /* determine what kind of parameter to get */
4957 if ((op == __2FADD) || (op == __2FDOT) || (op == __2FSUBT))SFParam = TRUE;
4958 if ((op == __2FDIVIDE) || (op == __2FMULT))numParam = TRUE;
4959
4960 /* determine the return value, if it is NOT a SFVec2d */
4961 if ((op == __2FDOT) || (op == __2FLENGTH)) retNumeric = TRUE;
4962 retSFVec2d = (!retNumeric);
4963
4964 /* is the parameter a string, possibly gotten from the VRML/X3d
4965 * side of things? */
4966 param_isString = JSVAL_IS_STRING(*argv);
4967
4968 /* get the parameter */
4969 if ((SFParam) || (numParam)) {
4970 if (numParam) {
4971 if (!JSVAL_IS_NUMBER(argv[0])) {
4972 printf("SFVec2d param error - number expected\n");
4973 return JS_FALSE;
4974 }
4975 if (!JS_ValueToNumber(cx, argv[0], &d)) {
4976 printf("JS_ValueToNumber failed in SFVec2d.\n");
4977 return JS_FALSE;
4978 }
4979 }
4980 else {
4981 /* did this come in from VRML as a string, or did
4982 * it get created in javascript? */
4983 if (param_isString) {
4984 _str = JS_ValueToString(cx, *argv);
4985 charString = JS_EncodeString(cx, _str);
4986
4987 if (sscanf(charString, "%lf %lf",
4988 &(pars[0]), &(pars[1])) != 2) {
4989 printf("conversion problem in SFVec2dGeneric\n");
4990 return JS_FALSE;
4991 }
4992 /* printf ("past scan, %f %f %f\n",pars[0], pars[1]);*/
4993 cc3[0] = pars[0];
4994 cc3[1] = pars[1];
4995 cc2 = cc3;
4996 }
4997 else {
4998 if (SM_method() == 2) {
4999 if (argv[0].isObject()) {
5000 AnyNative* _vec2;
5001 if ((_vec2 = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
5002 printf("in SFVec2d, RHS was NOT native type \n");
5003 return JS_FALSE;
5004 }
5005 //if(_vec2->type == FIELDTYPE_SFVec2d) or color. if 3d convert....
5006 cc2 = _vec2->v->sfvec2d.c;
5007 }
5008 else {
5009 return JS_FALSE;
5010 }
5011
5012 }
5013 else {
5014 SFVec2dNative* _vec2 = NULL;
5015
5016 if (!JS_ConvertArguments(cx, argc, argv, "o", &_paramObj)) {
5017 printf("JS_ConvertArguments failed in SFVec2d.\n");
5018 return JS_FALSE;
5019 }
5020
5021 CHECK_CLASS(cx, _paramObj, argv, __FUNCTION__, SFVec2dClass)
5022
5023 if ((_vec2 = (SFVec2dNative*)JS_GetPrivateFw(cx, _paramObj)) == NULL) {
5024 printf("JS_GetPrivate failed for _paramObj in SFVec2d.\n");
5025 return JS_FALSE;
5026 }
5027 cc2 = _vec2->v.c;
5028 }
5029 }
5030 }
5031 }
5032
5033 /* get our values */
5034 if (SM_method() == 2) {
5035 AnyNative* _vec1;
5036 if ((_vec1 = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5037 printf("JS_GetPrivate failed for obj in SFVec3fAdd.\n");
5038 return JS_FALSE;
5039 }
5040 cc = _vec1->v->sfvec2d.c;
5041 }
5042 else {
5043 SFVec2dNative* _vec1 = NULL;
5044 if ((_vec1 = (SFVec2dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5045 printf("JS_GetPrivate failed for obj in SFVec2dAdd.\n");
5046 return JS_FALSE;
5047 }
5048 cc = _vec1->v.c;
5049 }
5050 /* do the operation */
5051 switch (op) {
5052 /* returning a SFVec2d */
5053 case __2FADD:
5054 vecadd2d(cclhs, cc, cc2);
5055 break;
5056 case __2FDIVIDE:
5057 vecscale2d(cclhs, cc, 1.0 / d);
5058 break;
5059 case __2FMULT:
5060 vecscale2d(cclhs, cc, d);
5061 break;
5062 case __2FSUBT:
5063 vecdif2d(cclhs, cc, cc2);
5064 break;
5065 case __2FDOT:
5066 d = vecdot2d(cc, cc2);
5067 break;
5068 case __2FLENGTH:
5069 d = veclength2d(cc);
5070 break;
5071 case __2FNORMALIZE:
5072 vecnormal2d(cclhs, cc);
5073 break;
5074 default:
5075 return JS_FALSE;
5076 }
5077
5078 /* set the return object */
5079 if (retSFVec2d) {
5080 if ((_proto = JS_GetPrototypeFw(cx, obj)) == NULL) {
5081 printf("JS_GetPrototype failed in SFVec2d.\n");
5082 return JS_FALSE;
5083 }
5084 if ((_retObj =
5085 JS_ConstructObjectFw(cx, &SFVec2dClass, _proto, NULL)) == NULL) {
5086 printf("JS_ConstructObject failed in SFVec2d.\n");
5087 return JS_FALSE;
5088 }
5089 *rval = OBJECT_TO_JSVAL(_retObj);
5090 if (SM_method() == 2) {
5091 AnyNative* any;
5092 if ((any = (AnyNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
5093 printf("JS_GetPrivate failed for _retObj in SFVec3f.\n");
5094 return JS_FALSE;
5095 }
5096 memcpy(any->v->sfvec2d.c, cclhs, 2 * sizeof(float));
5097 }
5098 else {
5099 SFVec3fNative* _retNative;
5100 if ((_retNative = (SFVec3fNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
5101 printf("JS_GetPrivate failed for _retObj in SFVec3f.\n");
5102 return JS_FALSE;
5103 }
5104 memcpy(_retNative->v.c, cclhs, 2 * sizeof(float));
5105 }
5106
5107 }
5108 else if (retNumeric) {
5109 if (JS_NewNumberValue(cx, d, rval) == JS_FALSE) {
5110 printf("JS_NewDouble failed for %f in SFVec2d.\n", d);
5111 return JS_FALSE;
5112 }
5113 }
5114
5115#ifdef JSVRMLCLASSESVERBOSE
5116 if (retSFVec2d) {
5117 printf("SFVec2dgeneric: obj = %p, result = [%.9g, %.9g]\n",
5118 obj,
5119 (_retNative->v).c[0], (_retNative->v).c[1]);
5120 }
5121 if (retNumeric) {
5122 printf("SFVec2dgeneric: obj = %p, result = %.9g\n",
5123 obj, d);
5124 }
5125#endif
5126
5127 return JS_TRUE;
5128}
5129
5130JSBool
5131SFVec2dAdd(JSContext* cx, uintN argc, jsval* vp) {
5132 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5133 jsval* argv = JS_ARGV(cx, vp);
5134 jsval rval;
5135 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FADD);
5136 JS_SET_RVAL(cx, vp, rval);
5137 return retval;
5138
5139}
5140
5141JSBool
5142SFVec2dDivide(JSContext* cx, uintN argc, jsval* vp) {
5143 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5144 jsval* argv = JS_ARGV(cx, vp);
5145 jsval rval;
5146 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FDIVIDE);
5147 JS_SET_RVAL(cx, vp, rval);
5148 return retval;
5149}
5150
5151JSBool
5152SFVec2dMultiply(JSContext* cx, uintN argc, jsval* vp) {
5153 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5154 jsval* argv = JS_ARGV(cx, vp);
5155 jsval rval;
5156 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FMULT);
5157 JS_SET_RVAL(cx, vp, rval);
5158 return retval;
5159
5160}
5161
5162JSBool
5163SFVec2dSubtract(JSContext* cx, uintN argc, jsval* vp) {
5164 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5165 jsval* argv = JS_ARGV(cx, vp);
5166 jsval rval;
5167 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FSUBT);
5168 JS_SET_RVAL(cx, vp, rval);
5169 return retval;
5170
5171}
5172
5173JSBool
5174SFVec2dDot(JSContext* cx, uintN argc, jsval* vp) {
5175 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5176 jsval* argv = JS_ARGV(cx, vp);
5177 jsval rval;
5178 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FDOT);
5179 JS_SET_RVAL(cx, vp, rval);
5180 return retval;
5181}
5182
5183JSBool
5184SFVec2dLength(JSContext* cx, uintN argc, jsval* vp) {
5185 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5186 jsval* argv = JS_ARGV(cx, vp);
5187 jsval rval;
5188 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FLENGTH);
5189 JS_SET_RVAL(cx, vp, rval);
5190 return retval;
5191
5192}
5193
5194JSBool
5195SFVec2dNormalize(JSContext* cx, uintN argc, jsval* vp) {
5196 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5197 jsval* argv = JS_ARGV(cx, vp);
5198 jsval rval;
5199 JSBool retval = SFVec2dGeneric(cx, obj, argc, argv, &rval, __2FNORMALIZE);
5200 JS_SET_RVAL(cx, vp, rval);
5201 return retval;
5202}
5203
5204JSBool
5205SFVec2dToString(JSContext* cx, uintN argc, jsval* vp) {
5206 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5207 jsval* argv = JS_ARGV(cx, vp);
5208 JSString* _str;
5209 char buff[STRING];
5210 double* cc;
5211
5212 UNUSED(argc);
5213 UNUSED(argv);
5214 if (SM_method() == 2) {
5215 AnyNative* ptr;
5216 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5217 printf("JS_GetPrivate failed in SFVec2dToString.\n");
5218 return JS_FALSE;
5219 }
5220 cc = ptr->v->sfvec2d.c;
5221 }
5222 else {
5223 SFVec2dNative* ptr;
5224 if ((ptr = (SFVec2dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5225 printf("JS_GetPrivate failed in SFVec2dToString.\n");
5226 return JS_FALSE;
5227 }
5228 cc = ptr->v.c;
5229 }
5230 memset(buff, 0, STRING);
5231 sprintf(buff, "%.9g %.9g",
5232 cc[0], cc[1]);
5233 _str = JS_NewStringCopyZ(cx, buff);
5234 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
5235
5236 return JS_TRUE;
5237}
5238
5239JSBool
5240SFVec2dAssign(JSContext* cx, uintN argc, jsval* vp) {
5241 JSObject* obj = JS_THIS_OBJECT(cx, vp);
5242 jsval* argv = JS_ARGV(cx, vp);
5243 JSString* _id_jsstr;
5244
5245 JSObject* _from_obj;
5246 char* _id_str;
5247
5248 UNUSED(_id_str); // compiler warning mitigation
5249
5250 if (SM_method() == 2) {
5251 AnyNative* lhs, * rhs;
5252 if ((lhs = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5253 printf("JS_GetPrivate failed for obj in SFVec3dAssign.\n");
5254 return JS_FALSE;
5255 }
5256 if (!(*vp).isObject())
5257 return JS_FALSE;
5258 if ((rhs = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
5259 printf("JS_ConvertArguments failed in SFVec2dAssign. \n");
5260 return JS_FALSE;
5261 }
5262 AnyNativeAssign(lhs, rhs);
5263 }
5264 else {
5265 SFVec2dNative* fptr, * ptr;
5266
5267 if ((ptr = (SFVec2dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5268 printf("JS_GetPrivate failed for obj in SFVec2dAssign.\n");
5269 return JS_FALSE;
5270 }
5271
5272 CHECK_CLASS(cx, obj, argv, __FUNCTION__, SFVec2dClass)
5273
5274 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
5275 _id_str = JS_EncodeString(cx, _id_jsstr);
5276 }
5277 else {
5278
5279 printf("JS_ConvertArguments failed in SFVec2dAssign.\n");
5280 return JS_FALSE;
5281 }
5282
5283 CHECK_CLASS(cx, _from_obj, argv, __FUNCTION__, SFVec2dClass)
5284
5285 if ((fptr = (SFVec2dNative*)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
5286 printf("JS_GetPrivate failed for _from_obj in SFVec2dAssign.\n");
5287 return JS_FALSE;
5288 }
5289#ifdef JSVRMLCLASSESVERBOSE
5290 printf("SFVec2dAssign: obj = %p, id = \"%s\", from = %p\n",
5291 obj, _id_str, _from_obj);
5292#endif
5293
5294 SFVec2fNativeAssign(ptr, fptr);
5295 }
5296 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
5297
5298
5299 return JS_TRUE;
5300}
5301
5302JSBool
5303SFVec2dConstr(JSContext* cx, uintN argc, jsval* vp) {
5304 JSObject* obj = JS_NewObject(cx, &SFVec2dClass, NULL, NULL);
5305 jsval* argv = JS_ARGV(cx, vp);
5306
5307 jsdouble pars[2];
5308 double* cc;
5309
5310 ADD_ROOT(cx, obj)
5311
5312 if (SM_method() == 2) {
5313 AnyNative* any;
5314 if ((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFVec2d, NULL, NULL)) == NULL) {
5315 printf("AnyfNativeNew failed in SFVec3fConstr.\n");
5316 return JS_FALSE;
5317 }
5318 if (!JS_SetPrivateFw(cx, obj, any)) {
5319 printf("JS_SetPrivate failed in SFVec2dConstr.\n");
5320 return JS_FALSE;
5321 }
5322
5323 cc = any->v->sfvec2d.c;
5324 }
5325 else {
5326 SFVec2dNative* ptr;
5327
5328 if ((ptr = (SFVec2dNative*)SFVec2dNativeNew()) == NULL) {
5329 printf("SFVec2dNativeNew failed in SFVec2dConstr.\n");
5330 return JS_FALSE;
5331 }
5332
5333 //if (!JS_DefineProperties(cx, obj, SFVec2dProperties)) {
5334 // printf( "JS_DefineProperties failed in SFVec2dConstr.\n");
5335 // return JS_FALSE;
5336 //}
5337 if (!JS_SetPrivateFw(cx, obj, ptr)) {
5338 printf("JS_SetPrivate failed in SFVec2dConstr.\n");
5339 return JS_FALSE;
5340 }
5341 cc = ptr->v.c;
5342 ptr->valueChanged = 1;
5343
5344 }
5345 if (argc == 0) {
5346 cc[0] = 0.0;
5347 cc[1] = 0.0;
5348 }
5349 else {
5350 if (!JS_ConvertArguments(cx, argc, argv, "d d", &(pars[0]), &(pars[1]))) {
5351 printf("JS_ConvertArguments failed in SFVec2dConstr.\n");
5352 return JS_FALSE;
5353 }
5354 cc[0] = pars[0];
5355 cc[1] = pars[1];
5356 }
5357#ifdef JSVRMLCLASSESVERBOSE
5358 printf("SFVec2dConstr: obj = %p, %u args, %f %f\n",
5359 obj, argc,
5360 (ptr->v).c[0], (ptr->v).c[1]);
5361#endif
5362
5363
5364 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
5365
5366 return JS_TRUE;
5367}
5368
5369
5370JSBool
5371SFVec2dGetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp) {
5372 JSObject* obj = *hobj.address();
5373 jsid iid = *hiid.address();
5374 jsval* vp = hvp.address();
5375
5376 jsdouble d;
5377 double* cc;
5378
5379 jsval id;
5380 if (!JS_IdToValue(cx, iid, &id)) {
5381 printf("JS_IdToValue failed in SFVec2dGetProperty.\n");
5382 return JS_FALSE;
5383 }
5384
5385
5386 if (SM_method() == 2) {
5387 AnyNative* any;
5388 if ((any = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5389 printf("JS_GetPrivate failed in SFVec2dGetProperty.\n");
5390 return JS_FALSE;
5391 }
5392 cc = any->v->sfvec2d.c;
5393 }
5394 else {
5395 SFVec2dNative* ptr;
5396
5397 if ((ptr = (SFVec2dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5398 printf("JS_GetPrivate failed in SFVec2dGetProperty.\n");
5399 return JS_FALSE;
5400 }
5401 cc = ptr->v.c;
5402 }
5403 if (JSVAL_IS_INT(id)) {
5404 switch (JSVAL_TO_INT(id)) {
5405 case 0:
5406 d = cc[0];
5407 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
5408 printf(
5409 "JS_NewDouble failed for %f in SFVec2dGetProperty.\n",
5410 d);
5411 return JS_FALSE;
5412 }
5413 break;
5414 case 1:
5415 d = cc[1];
5416 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
5417 printf(
5418 "JS_NewDouble failed for %f in SFVec2dGetProperty.\n",
5419 d);
5420 return JS_FALSE;
5421 }
5422 break;
5423 }
5424 }
5425 return JS_TRUE;
5426}
5427
5428JSBool
5429SFVec2dSetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp) {
5430 JSObject* obj = *hobj.address();
5431 jsid iid = *hiid.address();
5432 jsval* vp = hvp.address();
5433
5434 jsval myv;
5435 double* cc;
5436
5437
5438 jsval id;
5439 if (!JS_IdToValue(cx, iid, &id)) {
5440 printf("JS_IdToValue failed in SFVec2dSetProperty.\n");
5441 return JS_FALSE;
5442 }
5443
5444
5445 if (SM_method() == 2) {
5446 AnyNative* any;
5447 if ((any = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5448 printf("JS_GetPrivate failed in SFVec2dSetProperty.\n");
5449 return JS_FALSE;
5450 }
5451 if (any->valueChanged)
5452 (*any->valueChanged)++;
5453 cc = any->v->sfvec2d.c;
5454 }
5455 else {
5456 SFVec2dNative* ptr;
5457
5458 if ((ptr = (SFVec2dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5459 printf("JS_GetPrivate failed in SFVec2dSetProperty.\n");
5460 return JS_FALSE;
5461 }
5462 ptr->valueChanged++;
5463#ifdef JSVRMLCLASSESVERBOSE
5464 printf("SFVec2dSetProperty: obj = %p, id = %d, valueChanged = %d\n",
5465 obj, JSVAL_TO_INT(id), ptr->valueChanged);
5466#endif
5467 cc = ptr->v.c;
5468 }
5469 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
5470 printf("JS_ConvertValue failed in SFVec2dSetProperty.\n");
5471 return JS_FALSE;
5472 }
5473
5474 if (JSVAL_IS_INT(id)) {
5475 switch (JSVAL_TO_INT(id)) {
5476 case 0:
5477 cc[0] = (float)JSVAL_TO_DOUBLE(myv);
5478 break;
5479 case 1:
5480 cc[1] = (float)JSVAL_TO_DOUBLE(myv);
5481 break;
5482 default: break;
5483 }
5484 }
5485 return JS_TRUE;
5486}
5487
5488
5489/********************************************************************/
5490
5491/* Generic SFVec3d routines that return a SFVec3d -- note, already defined above
5492#define __3FADD 1
5493#define __3FDIVIDE 2
5494#define __3FMULT 3
5495#define __3FSUBT 4
5496#define __3FDOT 5
5497#define __3FLENGTH 6
5498#define __3FNORMALIZE 8
5499#define __3FNEGATE 7
5500#define __3FCROSS 9
5501*/
5502
5503JSBool SFVec3dGeneric( JSContext *cx, JSObject *obj,
5504 uintN argc, jsval *argv, jsval *rval, int op) {
5505 JSObject *_paramObj, *_proto, *_retObj;
5506 //SFVec3dNative *_vec1, *_vec2, *_retNative;
5507 jsdouble d=0.0;
5508 jsdouble d0=0.0;
5509 jsdouble d1=0.0;
5510 jsdouble d2=0.0;
5511 double *cc, *cc2, cc3[3], cclhs[3];
5512 struct point_XYZ v1, v2, ret;
5513
5514
5515 /* parameters */
5516 int SFParam = FALSE;
5517 int numParam = FALSE;
5518
5519 /* return values */
5520 int retSFVec3d = FALSE;
5521 int retNumeric = FALSE;
5522
5523 /* is the "argv" parameter a string? */
5524 int param_isString;
5525 char *charString;
5526 jsdouble pars[3];
5527 JSString *_str;
5528
5529 /* determine what kind of parameter to get */
5530 if ((op==__3FADD)||(op==__3FDOT)||(op==__3FCROSS)||(op==__3FSUBT))SFParam=TRUE;
5531 if ((op==__3FDIVIDE)||(op==__3FMULT))numParam=TRUE;
5532
5533 /* determine the return value, if it is NOT a SFVec3d */
5534 if ((op==__3FDOT)||(op==__3FLENGTH)) retNumeric = TRUE;
5535 retSFVec3d = (!retNumeric);
5536
5537 /* is the parameter a string, possibly gotten from the VRML/X3d
5538 * side of things? */
5539 param_isString = JSVAL_IS_STRING (*argv);
5540
5541 /* get the parameter */
5542 if ((SFParam) || (numParam)) {
5543 if (numParam) {
5544 if (!JSVAL_IS_NUMBER(argv[0])) {
5545 printf ("SFVec3d param error - number expected\n");
5546 return JS_FALSE;
5547 }
5548 if (!JS_ValueToNumber(cx, argv[0], &d)) {
5549 printf("JS_ValueToNumber failed in SFVec3d.\n");
5550 return JS_FALSE;
5551 }
5552 } else {
5553 /* did this come in from VRML as a string, or did
5554 * it get created in javascript? */
5555 if (param_isString) {
5556 _str = JS_ValueToString(cx, *argv);
5557 charString = JS_EncodeString(cx,_str);
5558 if (sscanf(charString, "%lf %lf %lf",
5559 &(pars[0]), &(pars[1]), &(pars[2])) != 3) {
5560 printf ("conversion problem in SFVec3dGeneric\n");
5561 return JS_FALSE;
5562 }
5563 /* printf ("past scan, %f %f %f\n",pars[0], pars[1],pars[2]);*/
5564 cc3[0] = pars[0];
5565 cc3[1] = pars[1];
5566 cc3[2] = pars[2];
5567 cc2 = cc3;
5568 } else {
5569 if(SM_method() == 2){
5570 if (argv[0].isObject()) {
5571 AnyNative *_vec2;
5572 if ((_vec2 = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(argv[0]))) == NULL) {
5573 printf("in SFVec3d, RHS was NOT native type \n");
5574 return JS_FALSE;
5575 }
5576 cc2 = _vec2->v->sfvec3d.c;
5577 }else{
5578 return JS_FALSE;
5579 }
5580 }else{
5581 SFVec3dNative *_vec2;
5582 if (!JS_ConvertArguments(cx, argc, argv, "o", &_paramObj)) {
5583 printf( "JS_ConvertArguments failed in SFVec3d.\n");
5584 return JS_FALSE;
5585 }
5586
5587 CHECK_CLASS(cx,_paramObj,argv,__FUNCTION__,SFVec3dClass)
5588
5589 /* get the second object's data */
5590 if ((_vec2 = (SFVec3dNative*)JS_GetPrivateFw(cx, _paramObj)) == NULL) {
5591 printf( "JS_GetPrivate failed for _paramObj in SFVec3d.\n");
5592 return JS_FALSE;
5593 }
5594 cc2 = (_vec2->v).c;
5595 }
5596 }
5597 }
5598 }
5599
5600
5601 /* get our values */
5602 if(SM_method() == 2){
5603 AnyNative *_vec1;
5604 if ((_vec1 = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5605 printf( "JS_GetPrivate failed for obj in SFVec3dAdd.\n");
5606 return JS_FALSE;
5607 }
5608 cc = _vec1->v->sfvec3d.c;
5609 }else{
5610 SFVec3dNative *_vec1;
5611 if ((_vec1 = (SFVec3dNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
5612 printf( "JS_GetPrivate failed for obj in SFVec3dAdd.\n");
5613 return JS_FALSE;
5614 }
5615 cc = _vec1->v.c;
5616 }
5617 /* do the operation */
5618 #ifdef JSVRMLCLASSESVERBOSE
5619 printf ("SFVec3d generic, vec2 %f %f %f\n",pars[0],pars[1],pars[2]);
5620 #endif
5621
5622 switch (op) {
5623 /* returning a SFVec3d */
5624 case __3FADD:
5625 vecaddd(cclhs,cc,cc2);
5626 break;
5627 case __3FDIVIDE:
5628 vecscaled(cclhs,cc,1.0/d);
5629 break;
5630 case __3FMULT:
5631 vecscaled(cclhs,cc,d);
5632 break;
5633 case __3FSUBT:
5634 vecdifd(cclhs,cc,cc2);
5635 break;
5636 case __3FDOT:
5637 d = vecdotd(cc,cc2);
5638 break;
5639 case __3FCROSS:
5640 veccrossd(cclhs,cc,cc2);
5641 break;
5642 case __3FLENGTH:
5643 d = veclengthd(cc);
5644 break;
5645 case __3FNORMALIZE:
5646 vecnormald(cclhs,cc);
5647 break;
5648 case __3FNEGATE:
5649 vecnegated(cclhs,cc);
5650 break;
5651 default:
5652 printf ("woops... %d\n",op);
5653 return JS_FALSE;
5654 }
5655
5656 #ifdef JSVRMLCLASSESVERBOSE
5657 printf ("past calcs\n");
5658 #endif
5659
5660 /* set the return object */
5661 if (retSFVec3d) {
5662 #ifdef JSVRMLCLASSESVERBOSE
5663 printf ("returning SFVec3d\n");
5664 #endif
5665 if ((_proto = JS_GetPrototypeFw(cx, obj)) == NULL) {
5666 printf( "JS_GetPrototype failed in SFVec3d.\n");
5667 return JS_FALSE;
5668 }
5669 if ((_retObj =
5670 JS_ConstructObjectFw(cx, &SFVec3dClass, _proto, NULL)) == NULL) {
5671 printf( "JS_ConstructObject failed in SFVec3d.\n");
5672 return JS_FALSE;
5673 }
5674 *rval = OBJECT_TO_JSVAL(_retObj);
5675 if(SM_method() == 2){
5676 AnyNative *any;
5677 if ((any = (AnyNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
5678 printf( "JS_GetPrivate failed for _retObj in SFVec3d.\n");
5679 return JS_FALSE;
5680 }
5681 memcpy(any->v->sfvec3d.c,cclhs,sizeof(double)*3);
5682 }else{
5683 SFVec3dNative *_retNative;
5684 if ((_retNative = (SFVec3dNative*)JS_GetPrivateFw(cx, _retObj)) == NULL) {
5685 printf( "JS_GetPrivate failed for _retObj in SFVec3d.\n");
5686 return JS_FALSE;
5687 }
5688 memcpy(_retNative->v.c,cclhs,3*sizeof(double));
5689 }
5690 } else if (retNumeric) {
5691 if (JS_NewNumberValue(cx,d,rval) == JS_FALSE) {
5692 printf( "JS_NewDouble failed for %f in SFVec3d.\n",d);
5693 return JS_FALSE;
5694 }
5695 }
5696 #ifdef JSVRMLCLASSESVERBOSE
5697 if (retSFVec3d){
5698 printf("SFVec3dgeneric: obj = %p, result = [%.9g, %.9g, %.9g]\n",
5699 obj,
5700 (_retNative->v).c[0], (_retNative->v).c[1],
5701 (_retNative->v).c[2]);
5702 }
5703 if (retNumeric){
5704 printf("SFVec2dgeneric: obj = %p, result = %.9g\n",
5705 obj, d);
5706 }
5707 #endif
5708
5709return JS_TRUE;
5710}
5711
5712JSBool
5713SFVec3dAdd(JSContext *cx, uintN argc, jsval *vp) {
5714 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5715 jsval *argv = JS_ARGV(cx,vp);
5716 jsval rval;
5717 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FADD);
5718 JS_SET_RVAL(cx,vp,rval);
5719 return retval;
5720}
5721
5722JSBool
5723SFVec3dCross(JSContext *cx, uintN argc, jsval *vp) {
5724 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5725 jsval *argv = JS_ARGV(cx,vp);
5726 jsval rval;
5727 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FCROSS);
5728 JS_SET_RVAL(cx,vp,rval);
5729 return retval;
5730}
5731
5732JSBool
5733SFVec3dDivide(JSContext *cx, uintN argc, jsval *vp) {
5734 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5735 jsval *argv = JS_ARGV(cx,vp);
5736 jsval rval;
5737 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FDIVIDE);
5738 JS_SET_RVAL(cx,vp,rval);
5739 return retval;
5740}
5741
5742JSBool
5743SFVec3dDot(JSContext *cx, uintN argc, jsval *vp) {
5744 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5745 jsval *argv = JS_ARGV(cx,vp);
5746 jsval rval;
5747 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FDOT);
5748 JS_SET_RVAL(cx,vp,rval);
5749 return retval;
5750}
5751
5752JSBool
5753SFVec3dLength(JSContext *cx, uintN argc, jsval *vp) {
5754 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5755 jsval *argv = JS_ARGV(cx,vp);
5756 jsval rval;
5757 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FLENGTH);
5758 JS_SET_RVAL(cx,vp,rval);
5759 return retval;
5760}
5761
5762
5763JSBool
5764SFVec3dMultiply(JSContext *cx, uintN argc, jsval *vp) {
5765 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5766 jsval *argv = JS_ARGV(cx,vp);
5767 jsval rval;
5768 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FMULT);
5769 JS_SET_RVAL(cx,vp,rval);
5770 return retval;
5771}
5772
5773
5774JSBool
5775SFVec3dNegate(JSContext *cx, uintN argc, jsval *vp) {
5776 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5777 jsval *argv = JS_ARGV(cx,vp);
5778 jsval rval;
5779 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FNEGATE);
5780 JS_SET_RVAL(cx,vp,rval);
5781 return retval;
5782}
5783
5784JSBool
5785SFVec3dNormalize(JSContext *cx, uintN argc, jsval *vp) {
5786 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5787 jsval *argv = JS_ARGV(cx,vp);
5788 jsval rval;
5789 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FNORMALIZE);
5790 JS_SET_RVAL(cx,vp,rval);
5791 return retval;
5792}
5793
5794JSBool
5795SFVec3dSubtract(JSContext *cx, uintN argc, jsval *vp) {
5796 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5797 jsval *argv = JS_ARGV(cx,vp);
5798 jsval rval;
5799 JSBool retval = SFVec3dGeneric(cx, obj, argc, argv, &rval, __3FSUBT);
5800 JS_SET_RVAL(cx,vp,rval);
5801 return retval;
5802}
5803
5804JSBool
5805SFVec3dToString(JSContext *cx, uintN argc, jsval *vp) {
5806 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5807 jsval *argv = JS_ARGV(cx,vp);
5808 JSString *_str;
5809 char buff[STRING];
5810 double *cc;
5811
5812 UNUSED(argc);
5813 UNUSED(argv);
5814 if(SM_method()==2){
5815 AnyNative *ptr;
5816 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
5817 printf( "JS_GetPrivate failed in SFVec3dToString.\n");
5818 return JS_FALSE;
5819 }
5820 cc = ptr->v->sfvec3d.c;
5821 }else{
5822 SFVec3dNative *ptr;
5823 if ((ptr = (SFVec3dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
5824 printf( "JS_GetPrivate failed in SFVec3dToString.\n");
5825 return JS_FALSE;
5826 }
5827 cc = ptr->v.c;
5828 }
5829 memset(buff, 0, STRING);
5830 sprintf(buff, "%.9g %.9g %.9g",
5831 cc[0], cc[1], cc[2]);
5832 _str = JS_NewStringCopyZ(cx, buff);
5833 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
5834
5835 #ifdef JSVRMLCLASSESVERBOSE
5836 printf ("SFVec3dToString, string is :%s:\n",buff);
5837 #endif
5838
5839 return JS_TRUE;
5840}
5841
5842JSBool
5843SFVec3dAssign(JSContext *cx, uintN argc, jsval *vp) {
5844 JSObject *obj = JS_THIS_OBJECT(cx,vp);
5845 jsval *argv = JS_ARGV(cx,vp);
5846 JSString *_id_jsstr;
5847 JSObject *_from_obj;
5848
5849 char *_id_str;
5850
5851 UNUSED(_id_str); // compiler warning mitigation
5852
5853
5854 #ifdef JSVRMLCLASSESVERBOSE
5855 printf ("start of SFVec3dAssign\n");
5856 #endif
5857 if(SM_method() == 2){
5858 AnyNative *lhs, *rhs;
5859 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
5860 printf( "JS_GetPrivate failed for obj in SFVec3dAssign.\n");
5861 return JS_FALSE;
5862 }
5863 if (!(*vp).isObject())
5864 return JS_FALSE;
5865 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
5866 printf("in setECMANative, RHS was NOT native type \n");
5867 return JS_FALSE;
5868 }
5869 AnyNativeAssign(lhs,rhs);
5870
5871 }else{
5872 SFVec3dNative *fptr, *ptr;
5873
5874 if ((ptr = (SFVec3dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
5875 printf( "JS_GetPrivate failed for obj in SFVec3dAssign.\n");
5876 return JS_FALSE;
5877 }
5878
5879 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFVec3dClass)
5880
5881 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
5882 _id_str = JS_EncodeString(cx,_id_jsstr);
5883 } else {
5884 printf( "JS_ConvertArguments failed in SFVec3dAssign.\n");
5885 return JS_FALSE;
5886 }
5887
5888 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFVec3dClass)
5889
5890 if ((fptr = (SFVec3dNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
5891 printf( "JS_GetPrivate failed for _from_obj in SFVec3dAssign.\n");
5892 return JS_FALSE;
5893 }
5894 #ifdef JSVRMLCLASSESVERBOSE
5895 printf("SFVec3dAssign: obj = %p, id = \"%s\", from = %p\n",
5896 obj, _id_str, _from_obj);
5897 #endif
5898
5899 SFVec3dNativeAssign(ptr, fptr);
5900 }
5901
5902 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
5903
5904 #ifdef JSVRMLCLASSESVERBOSE
5905 printf ("end of SFVec3dAssign\n");
5906 #endif
5907
5908 return JS_TRUE;
5909}
5910
5911JSBool
5912SFVec3dConstr(JSContext *cx, uintN argc, jsval *vp) {
5913 JSObject *obj = JS_NewObject(cx,&SFVec3dClass,NULL,NULL);
5914 jsval *argv = JS_ARGV(cx,vp);
5915 jsdouble pars[3];
5916 double *cc;
5917
5918 #ifdef JSVRMLCLASSESVERBOSE
5919 printf ("start of SFVec3dConstr\n");
5920 #endif
5921
5922 ADD_ROOT(cx,obj)
5923
5924 if(SM_method() == 2){
5925 AnyNative *any;
5926 if ((any = (AnyNative *) AnyNativeNew(FIELDTYPE_SFVec3d,NULL,NULL)) == NULL) {
5927 printf( "SFVec3dNativeNew failed in SFVec3dConstr.\n");
5928 return JS_FALSE;
5929 }
5930
5931 if (!JS_SetPrivateFw(cx, obj, any)) {
5932 printf( "JS_SetPrivate failed in SFVec3dConstr.\n");
5933 return JS_FALSE;
5934 }
5935 cc = any->v->sfvec3d.c;
5936 }else{
5937 SFVec3dNative *ptr;
5938 if ((ptr = (SFVec3dNative *) SFVec3dNativeNew()) == NULL) {
5939 printf( "SFVec3dNativeNew failed in SFVec3dConstr.\n");
5940 return JS_FALSE;
5941 }
5942
5943 //if (!JS_DefineProperties(cx, obj, SFVec3dProperties)) {
5944 // printf( "JS_DefineProperties failed in SFVec3dConstr.\n");
5945 // return JS_FALSE;
5946 //}
5947 if (!JS_SetPrivateFw(cx, obj, ptr)) {
5948 printf( "JS_SetPrivate failed in SFVec3dConstr.\n");
5949 return JS_FALSE;
5950 }
5951 cc = ptr->v.c;
5952 ptr->valueChanged = 1;
5953 }
5954 if (argc == 0) {
5955 cc[0] = (float) 0.0;
5956 cc[1] = (float) 0.0;
5957 cc[2] = (float) 0.0;
5958 } else {
5959 if (!JS_ConvertArguments(cx, argc, argv, "d d d",
5960 &(pars[0]), &(pars[1]), &(pars[2]))) {
5961 printf( "JS_ConvertArguments failed in SFVec3dConstr.\n");
5962 return JS_FALSE;
5963 }
5964 cc[0] = (float) pars[0];
5965 cc[1] = (float) pars[1];
5966 cc[2] = (float) pars[2];
5967 }
5968 #ifdef JSVRMLCLASSESVERBOSE
5969 printf("SFVec3dConstr: obj = %p, %u args, %f %f %f\n",
5970 obj, argc,
5971 (ptr->v).c[0], (ptr->v).c[1], (ptr->v).c[2]);
5972 #endif
5973
5974
5975 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
5976 return JS_TRUE;
5977}
5978
5979JSBool
5980SFVec3dGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
5981 JSObject *obj = *hobj.address();
5982 jsid iid = *hiid.address();
5983 jsval *vp = hvp.address();
5984 double *cc;
5985 jsdouble d;
5986 #ifdef JSVRMLCLASSESVERBOSE
5987 JSString *_idStr;
5988 char *_id_c;
5989 #endif
5990
5991 jsval id;
5992 if (!JS_IdToValue(cx,iid,&id)) {
5993 printf("JS_IdToValue failed in SFVec3dGetProperty.\n");
5994 return JS_FALSE;
5995 }
5996
5997
5998 #ifdef JSVRMLCLASSESVERBOSE
5999
6000
6001/* same as earlier, these are never used
6002 _idStr = JS_ValueToString(cx, id);
6003 _id_c = JS_GetStringBytes(_idStr); */
6004 _idStr = JS_ValueToString(cx, *vp);
6005#if JS_VERSION < 185
6006 _id_c = JS_GetStringBytes(_idStr);
6007#else
6008 _id_c = JS_EncodeString(cx,_idStr);
6009#endif
6010 #endif
6011
6012 if(SM_method()==2){
6013 AnyNative *ptr;
6014 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6015 printf( "JS_GetPrivate failed in SFVec3dGetProperty.\n");
6016 return JS_FALSE;
6017 }
6018 cc = ptr->v->sfvec3d.c;
6019 }else{
6020 SFVec3dNative *ptr;
6021 if ((ptr = (SFVec3dNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6022 printf( "JS_GetPrivate failed in SFVec3dGetProperty.\n");
6023 return JS_FALSE;
6024 }
6025 cc = ptr->v.c;
6026 }
6027 if (JSVAL_IS_INT(id)) {
6028 switch (JSVAL_TO_INT(id)) {
6029 case 0:
6030 d = cc[0];
6031 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6032 printf(
6033 "JS_NewDouble failed for %f in SFVec3dGetProperty.\n",
6034 d);
6035 return JS_FALSE;
6036 }
6037 break;
6038 case 1:
6039 d = cc[1];
6040 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6041 printf(
6042 "JS_NewDouble failed for %f in SFVec3dGetProperty.\n",
6043 d);
6044 return JS_FALSE;
6045 }
6046 break;
6047 case 2:
6048 d = cc[2];
6049 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6050 printf(
6051 "JS_NewDouble failed for %f in SFVec3dGetProperty.\n",
6052 d);
6053 return JS_FALSE;
6054 }
6055 break;
6056 }
6057 } else {
6058 #ifdef JSVRMLCLASSESVERBOSE
6059 printf ("SFVec3dGetProperty, id is NOT an int...\n");
6060 #endif
6061 }
6062
6063 return JS_TRUE;
6064}
6065
6066JSBool
6067SFVec3dSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
6068 JSObject *obj = *hobj.address();
6069 jsid iid = *hiid.address();
6070 jsval *vp = hvp.address();
6071
6072 double *cc;
6073 jsval myv;
6074
6075 jsval id;
6076 if (!JS_IdToValue(cx,iid,&id)) {
6077 printf("JS_IdToValue failed in SFVec3dSetProperty.\n");
6078 return JS_FALSE;
6079 }
6080
6081
6082 if(SM_method()==2){
6083 AnyNative *ptr;
6084 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6085 printf( "JS_GetPrivate failed in SFVec3dSetProperty.\n");
6086 return JS_FALSE;
6087 }
6088 if(ptr->valueChanged)
6089 (*ptr->valueChanged)++;
6090 #ifdef JSVRMLCLASSESVERBOSE
6091 printf("SFVec3dSetProperty: obj = %p, id = %d, valueChanged = %d\n",
6092 obj, JSVAL_TO_INT(id), ptr->valueChanged);
6093 #endif
6094 cc = ptr->v->sfvec3d.c;
6095 }else{
6096 SFVec3dNative *ptr;
6097 if ((ptr = (SFVec3dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6098 printf( "JS_GetPrivate failed in SFVec3dSetProperty.\n");
6099 return JS_FALSE;
6100 }
6101 ptr->valueChanged++;
6102 #ifdef JSVRMLCLASSESVERBOSE
6103 printf("SFVec3dSetProperty: obj = %p, id = %d, valueChanged = %d\n",
6104 obj, JSVAL_TO_INT(id), ptr->valueChanged);
6105 #endif
6106 cc = ptr->v.c;
6107 }
6108 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
6109 printf( "JS_ConvertValue failed in SFVec3dSetProperty.\n");
6110 return JS_FALSE;
6111 }
6112
6113 if (JSVAL_IS_INT(id)) {
6114 switch (JSVAL_TO_INT(id)) {
6115 case 0:
6116 cc[0] = JSVAL_TO_DOUBLE(myv);
6117 break;
6118 case 1:
6119 cc[1] = JSVAL_TO_DOUBLE(myv);
6120 break;
6121 case 2:
6122 cc[2] = JSVAL_TO_DOUBLE(myv);
6123 break;
6124 }
6125 }
6126 return JS_TRUE;
6127}
6128
6129
6130JSBool
6131SFVec4fToString(JSContext *cx, uintN argc, jsval *vp) {
6132 JSObject *obj = JS_THIS_OBJECT(cx,vp);
6133 jsval *argv = JS_ARGV(cx,vp);
6134 JSString *_str;
6135 char buff[STRING];
6136 float *cc;
6137
6138 UNUSED(argc);
6139 UNUSED(argv);
6140 if(SM_method()==2){
6141 AnyNative *ptr;
6142 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6143 printf( "JS_GetPrivate failed in SFVec4fToString.\n");
6144 return JS_FALSE;
6145 }
6146 cc = ptr->v->sfvec4f.c;
6147
6148 }else{
6149 SFVec4fNative *ptr;
6150 if ((ptr = (SFVec4fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6151 printf( "JS_GetPrivate failed in SFVec4fToString.\n");
6152 return JS_FALSE;
6153 }
6154 cc = ptr->v.c;
6155 }
6156 memset(buff, 0, STRING);
6157 sprintf(buff, "%.9g %.9g %.9g %.9g",
6158 cc[0], cc[1], cc[2],cc[3]);
6159 _str = JS_NewStringCopyZ(cx, buff);
6160 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
6161
6162 #ifdef JSVRMLCLASSESVERBOSE
6163 printf ("SFVec4fToString, string is :%s:\n",buff);
6164 #endif
6165
6166 return JS_TRUE;
6167}
6168
6169JSBool
6170SFVec4fAssign(JSContext *cx, uintN argc, jsval *vp) {
6171 JSObject *obj = JS_THIS_OBJECT(cx,vp);
6172 jsval *argv = JS_ARGV(cx,vp);
6173 JSString *_id_jsstr;
6174 JSObject *_from_obj;
6175 char *_id_str;
6176
6177 UNUSED(_id_str); // compiler warning mitigation
6178
6179
6180 #ifdef JSVRMLCLASSESVERBOSE
6181 printf ("start of SFVec4fAssign\n");
6182 #endif
6183 if(SM_method() == 2){
6184 AnyNative *lhs, *rhs;
6185 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6186 printf( "JS_GetPrivate failed for obj in SFVec4fAssign.\n");
6187 return JS_FALSE;
6188 }
6189 if (!(*vp).isObject())
6190 return JS_FALSE;
6191 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
6192 printf("JS_ConvertArguments failed in SFVec4fAssign. \n");
6193 return JS_FALSE;
6194 }
6195 AnyNativeAssign(lhs,rhs);
6196 }else{
6197 SFVec4fNative *fptr, *ptr;
6198
6199 if ((ptr = (SFVec4fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6200 printf( "JS_GetPrivate failed for obj in SFVec4fAssign.\n");
6201 return JS_FALSE;
6202 }
6203
6204 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFVec4fClass)
6205
6206 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
6207 _id_str = JS_EncodeString(cx,_id_jsstr);
6208 } else {
6209 printf( "JS_ConvertArguments failed in SFVec4fAssign.\n");
6210 return JS_FALSE;
6211 }
6212
6213 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFVec4fClass)
6214
6215 if ((fptr = (SFVec4fNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
6216 printf( "JS_GetPrivate failed for _from_obj in SFVec4fAssign.\n");
6217 return JS_FALSE;
6218 }
6219 #ifdef JSVRMLCLASSESVERBOSE
6220 printf("SFVec4fAssign: obj = %p, id = \"%s\", from = %p\n",
6221 obj, _id_str, _from_obj);
6222 #endif
6223
6224 SFVec4fNativeAssign(ptr, fptr);
6225 }
6226 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
6227
6228 #ifdef JSVRMLCLASSESVERBOSE
6229 printf ("end of SFVec4fAssign\n");
6230 #endif
6231
6232 return JS_TRUE;
6233}
6234
6235JSBool
6236SFVec4fConstr(JSContext *cx, uintN argc, jsval *vp) {
6237 JSObject *obj = JS_NewObject(cx,&SFVec4fClass,NULL,NULL);
6238 jsval *argv = JS_ARGV(cx,vp);
6239 jsdouble pars[4];
6240 float *cc;
6241
6242 #ifdef JSVRMLCLASSESVERBOSE
6243 printf ("start of SFVec4fConstr\n");
6244 #endif
6245
6246 ADD_ROOT(cx,obj)
6247 if(SM_method() == 2){
6248 AnyNative *any;
6249 if((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFVec4f,NULL,NULL)) == NULL){
6250 printf( "AnyfNativeNew failed in SFVec4fConstr.\n");
6251 return JS_FALSE;
6252 }
6253 if (!JS_SetPrivateFw(cx, obj, any)) {
6254 printf( "JS_SetPrivate failed in SFVec4fConstr.\n");
6255 return JS_FALSE;
6256 }
6257 cc = any->v->sfvec4f.c;
6258 }else{
6259 SFVec4fNative *ptr;
6260 if ((ptr = (SFVec4fNative *) SFVec4fNativeNew()) == NULL) {
6261 printf( "SFVec4fNativeNew failed in SFVec4fConstr.\n");
6262 return JS_FALSE;
6263 }
6264 ptr->valueChanged = 1;
6265 cc = ptr->v.c;
6266 //if (!JS_DefineProperties(cx, obj, SFVec4fProperties)) {
6267 // printf( "JS_DefineProperties failed in SFVec4fConstr.\n");
6268 // return JS_FALSE;
6269 //}
6270 if (!JS_SetPrivateFw(cx, obj, ptr)) {
6271 printf( "JS_SetPrivate failed in SFVec4fConstr.\n");
6272 return JS_FALSE;
6273 }
6274 }
6275
6276 if (argc == 0) {
6277 cc[0] = (float) 0.0;
6278 cc[1] = (float) 0.0;
6279 cc[2] = (float) 0.0;
6280 cc[3] = (float) 0.0;
6281 } else {
6282 if (!JS_ConvertArguments(cx, argc, argv, "d d d d",
6283 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]))) {
6284 printf( "JS_ConvertArguments failed in SFVec4fConstr.\n");
6285 return JS_FALSE;
6286 }
6287 cc[0] = (float) pars[0];
6288 cc[1] = (float) pars[1];
6289 cc[2] = (float) pars[2];
6290 cc[3] = (float) pars[3];
6291 }
6292 #ifdef JSVRMLCLASSESVERBOSE
6293 printf("SFVec4fConstr: obj = %p, %u args, %f %f %f %f\n",
6294 obj, argc,
6295 cc[0], cc[1], cc[2], cc[3]);
6296 #endif
6297
6298 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
6299 return JS_TRUE;
6300}
6301
6302JSBool
6303SFVec4fGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
6304 JSObject *obj = *hobj.address();
6305 jsid iid = *hiid.address();
6306 jsval *vp = hvp.address();
6307
6308 jsdouble d;
6309 float *cc;
6310 #ifdef JSVRMLCLASSESVERBOSE
6311 JSString *_idStr;
6312 char *_id_c;
6313 #endif
6314
6315 jsval id;
6316 if (!JS_IdToValue(cx,iid,&id)) {
6317 printf("JS_IdToValue failed in SFVec4fGetProperty.\n");
6318 return JS_FALSE;
6319 }
6320
6321
6322 #ifdef JSVRMLCLASSESVERBOSE
6323
6324 //JSString *_idStr;
6325 //char *_id_c;
6326
6327/* same as above
6328 _idStr = JS_ValueToString(cx, id);
6329 _id_c = JS_GetStringBytes(_idStr); */
6330 _idStr = JS_ValueToString(cx, *vp);
6331#if JS_VERSION < 185
6332 _id_c = JS_GetStringBytes(_idStr);
6333#else
6334 _id_c = JS_EncodeString(cx,_idStr);
6335#endif
6336 #endif
6337
6338 if(SM_method()==2){
6339 AnyNative *any;
6340 if ((any = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6341 printf( "JS_GetPrivate failed in SFVec4fGetProperty.\n");
6342 return JS_FALSE;
6343 }
6344 cc = any->v->sfvec4f.c;
6345 }else{
6346 SFVec4fNative *ptr;
6347 if ((ptr = (SFVec4fNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6348 printf( "JS_GetPrivate failed in SFVec4fGetProperty.\n");
6349 return JS_FALSE;
6350 }
6351 cc = ptr->v.c;
6352 }
6353 if (JSVAL_IS_INT(id)) {
6354 switch (JSVAL_TO_INT(id)) {
6355 case 0:
6356 d = cc[0];
6357 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6358 printf(
6359 "JS_NewDouble failed for %f in SFVec4fGetProperty.\n",
6360 d);
6361 return JS_FALSE;
6362 }
6363 break;
6364 case 1:
6365 d = cc[1];
6366 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6367 printf(
6368 "JS_NewDouble failed for %f in SFVec4fGetProperty.\n",
6369 d);
6370 return JS_FALSE;
6371 }
6372 break;
6373 case 2:
6374 d = cc[2];
6375 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6376 printf(
6377 "JS_NewDouble failed for %f in SFVec4fGetProperty.\n",
6378 d);
6379 return JS_FALSE;
6380 }
6381 break;
6382 case 3:
6383 d = cc[3];
6384 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6385 printf(
6386 "JS_NewDouble failed for %f in SFVec4fGetProperty.\n",
6387 d);
6388 return JS_FALSE;
6389 }
6390 break;
6391 }
6392 } else {
6393 #ifdef JSVRMLCLASSESVERBOSE
6394 printf ("SFVec4fGetProperty, id is NOT an int...\n");
6395 #endif
6396 }
6397
6398 return JS_TRUE;
6399}
6400
6401JSBool
6402SFVec4fSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
6403 JSObject *obj = *hobj.address();
6404 jsid iid = *hiid.address();
6405 jsval *vp = hvp.address();
6406
6407 jsval myv;
6408 float *cc;
6409
6410
6411 jsval id;
6412 if (!JS_IdToValue(cx,iid,&id)) {
6413 printf("JS_IdToValue failed in SFVec4fSetProperty.\n");
6414 return JS_FALSE;
6415 }
6416
6417 if(SM_method() == 2){
6418 AnyNative *any;
6419 if ((any = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6420 printf( "JS_GetPrivate failed in SFVec4fSetProperty.\n");
6421 return JS_FALSE;
6422 }
6423 if(any->valueChanged)
6424 (*any->valueChanged)++;
6425 cc = any->v->sfvec4f.c;
6426 }else{
6427 SFVec4fNative *ptr;
6428
6429 if ((ptr = (SFVec4fNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6430 printf( "JS_GetPrivate failed in SFVec4fSetProperty.\n");
6431 return JS_FALSE;
6432 }
6433 ptr->valueChanged++;
6434 #ifdef JSVRMLCLASSESVERBOSE
6435 printf("SFVec4fSetProperty: obj = %p, id = %d, valueChanged = %d\n",
6436 obj, JSVAL_TO_INT(id), ptr->valueChanged);
6437 #endif
6438 cc = ptr->v.c;
6439 }
6440 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
6441 printf( "JS_ConvertValue failed in SFVec4fSetProperty.\n");
6442 return JS_FALSE;
6443 }
6444
6445 if (JSVAL_IS_INT(id)) {
6446 switch (JSVAL_TO_INT(id)) {
6447 case 0:
6448 cc[0] = (float) JSVAL_TO_DOUBLE(myv);
6449 break;
6450 case 1:
6451 cc[1] = (float) JSVAL_TO_DOUBLE(myv);
6452 break;
6453 case 2:
6454 cc[2] = (float) JSVAL_TO_DOUBLE(myv);
6455 break;
6456 case 3:
6457 cc[3] = (float) JSVAL_TO_DOUBLE(myv);
6458 break;
6459 }
6460 }
6461 return JS_TRUE;
6462}
6463
6464
6465// SFVec4d
6466JSBool
6467SFVec4dToString(JSContext *cx, uintN argc, jsval *vp) {
6468 JSObject *obj = JS_THIS_OBJECT(cx,vp);
6469 jsval *argv = JS_ARGV(cx,vp);
6470
6471 JSString *_str;
6472 double *cc;
6473 char buff[STRING];
6474
6475 UNUSED(argc);
6476 UNUSED(argv);
6477 if(SM_method()==2){
6478 AnyNative *ptr;
6479 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6480 printf( "JS_GetPrivate failed in SFVec4dToString.\n");
6481 return JS_FALSE;
6482 }
6483 cc = ptr->v->sfvec4d.c;
6484 }else{
6485 SFVec4dNative *ptr;
6486 if ((ptr = (SFVec4dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6487 printf( "JS_GetPrivate failed in SFVec4dToString.\n");
6488 return JS_FALSE;
6489 }
6490 cc = ptr->v.c;
6491 }
6492 memset(buff, 0, STRING);
6493 sprintf(buff, "%.9g %.9g %.9g %.9g",
6494 cc[0], cc[1], cc[2],cc[3]);
6495 _str = JS_NewStringCopyZ(cx, buff);
6496
6497 JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(_str));
6498
6499 #ifdef JSVRMLCLASSESVERBOSE
6500 printf ("SFVec4dToString, string is :%s:\n",buff);
6501 #endif
6502
6503 return JS_TRUE;
6504}
6505
6506JSBool
6507SFVec4dAssign(JSContext *cx, uintN argc, jsval *vp) {
6508 JSObject *obj = JS_THIS_OBJECT(cx,vp);
6509 jsval *argv = JS_ARGV(cx,vp);
6510 JSString *_id_jsstr;
6511 JSObject *_from_obj;
6512 char *_id_str;
6513
6514 UNUSED(_id_str); // compiler warning mitigation
6515
6516 #ifdef JSVRMLCLASSESVERBOSE
6517 printf ("start of SFVec4dAssign\n");
6518 #endif
6519
6520 if(SM_method() == 2){
6521 AnyNative *lhs, *rhs;
6522 if ((lhs = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6523 printf( "JS_GetPrivate failed for obj in SFVec4dAssign.\n");
6524 return JS_FALSE;
6525 }
6526 if (!(*vp).isObject())
6527 return JS_FALSE;
6528 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
6529 printf("in SFVec4dAssign, RHS was NOT native type \n");
6530 return JS_FALSE;
6531 }
6532 AnyNativeAssign(lhs,rhs);
6533
6534 }else{
6535 SFVec4dNative *fptr, *ptr;
6536
6537 if ((ptr = (SFVec4dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6538 printf( "JS_GetPrivate failed for obj in SFVec4dAssign.\n");
6539 return JS_FALSE;
6540 }
6541
6542 CHECK_CLASS(cx,obj,argv,__FUNCTION__,SFVec4dClass)
6543
6544 if (JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr) == JS_TRUE) {
6545 _id_str = JS_EncodeString(cx,_id_jsstr);
6546 } else {
6547 printf( "JS_ConvertArguments failed in SFVec4dAssign.\n");
6548 return JS_FALSE;
6549 }
6550
6551 CHECK_CLASS(cx,_from_obj,argv,__FUNCTION__,SFVec4dClass)
6552
6553 if ((fptr = (SFVec4dNative *)JS_GetPrivateFw(cx, _from_obj)) == NULL) {
6554 printf( "JS_GetPrivate failed for _from_obj in SFVec4dAssign.\n");
6555 return JS_FALSE;
6556 }
6557 #ifdef JSVRMLCLASSESVERBOSE
6558 printf("SFVec4dAssign: obj = %p, id = \"%s\", from = %p\n",
6559 obj, _id_str, _from_obj);
6560 #endif
6561
6562 SFVec4dNativeAssign(ptr, fptr);
6563 }
6564 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
6565
6566 #ifdef JSVRMLCLASSESVERBOSE
6567 printf ("end of SFVec4dAssign\n");
6568 #endif
6569
6570 return JS_TRUE;
6571}
6572
6573JSBool
6574SFVec4dConstr(JSContext *cx, uintN argc, jsval *vp) {
6575 JSObject *obj = JS_NewObject(cx,&SFVec4dClass,NULL,NULL);
6576 jsval *argv = JS_ARGV(cx,vp);
6577 jsdouble pars[4];
6578 double *cc;
6579
6580 #ifdef JSVRMLCLASSESVERBOSE
6581 printf ("start of SFVec4dConstr\n");
6582 #endif
6583
6584 ADD_ROOT(cx,obj)
6585 if(SM_method() == 2){
6586 AnyNative *any;
6587 if ((any = (AnyNative *) AnyNativeNew(FIELDTYPE_SFVec4d,NULL,NULL)) == NULL) {
6588 printf( "SFVec3dNativeNew failed in SFVec3dConstr.\n");
6589 return JS_FALSE;
6590 }
6591
6592 if (!JS_SetPrivateFw(cx, obj, any)) {
6593 printf( "JS_SetPrivate failed in SFVec3dConstr.\n");
6594 return JS_FALSE;
6595 }
6596 cc = any->v->sfvec4d.c;
6597 }else{
6598 SFVec4dNative *ptr;
6599
6600 if ((ptr = (SFVec4dNative *) SFVec4dNativeNew()) == NULL) {
6601 printf( "SFVec4dNativeNew failed in SFVec4dConstr.\n");
6602 return JS_FALSE;
6603 }
6604
6605 //if (!JS_DefineProperties(cx, obj, SFVec4dProperties)) {
6606 // printf( "JS_DefineProperties failed in SFVec4dConstr.\n");
6607 // return JS_FALSE;
6608 //}
6609 if (!JS_SetPrivateFw(cx, obj, ptr)) {
6610 printf( "JS_SetPrivate failed in SFVec4dConstr.\n");
6611 return JS_FALSE;
6612 }
6613 ptr->valueChanged = 1;
6614 cc = ptr->v.c;
6615 }
6616 if (argc == 0) {
6617 cc[0] = (float) 0.0;
6618 cc[1] = (float) 0.0;
6619 cc[2] = (float) 0.0;
6620 cc[3] = (float) 0.0;
6621 } else {
6622 if (!JS_ConvertArguments(cx, argc, argv, "d d d d",
6623 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]))) {
6624 printf( "JS_ConvertArguments failed in SFVec4dConstr.\n");
6625 return JS_FALSE;
6626 }
6627 cc[0] = (float) pars[0];
6628 cc[1] = (float) pars[1];
6629 cc[2] = (float) pars[2];
6630 cc[3] = (float) pars[3];
6631 }
6632 #ifdef JSVRMLCLASSESVERBOSE
6633 printf("SFVec4dConstr: obj = %p, %u args, %f %f %f %f\n",
6634 obj, argc,
6635 cc[0], cc[1], cc[2], cc[3]);
6636 #endif
6637
6638
6639 JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(obj));
6640 return JS_TRUE;
6641}
6642
6643JSBool
6644SFVec4dGetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
6645 JSObject *obj = *hobj.address();
6646 jsid iid = *hiid.address();
6647 jsval *vp = hvp.address();
6648
6649 jsdouble d;
6650 double *cc;
6651 #ifdef JSVRMLCLASSESVERBOSE
6652 JSString *_idStr;
6653 char *_id_c;
6654 #endif
6655
6656 jsval id;
6657 if (!JS_IdToValue(cx,iid,&id)) {
6658 printf("JS_IdToValue failed in SFVec4dGetProperty.\n");
6659 return JS_FALSE;
6660 }
6661
6662
6663 #ifdef JSVRMLCLASSESVERBOSE
6664
6665/* _idStr = JS_ValueToString(cx, id);
6666 _id_c = JS_GetStringBytes(_idStr);*/
6667 _idStr = JS_ValueToString(cx, *vp);
6668#if JS_VERSION < 185
6669 _id_c = JS_GetStringBytes(_idStr);
6670#else
6671 _id_c = JS_EncodeString(cx,_idStr);
6672#endif
6673 #endif
6674
6675 if(SM_method()==2){
6676 AnyNative *ptr;
6677 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6678 printf( "JS_GetPrivate failed in SFVec4dGetProperty.\n");
6679 return JS_FALSE;
6680 }
6681 cc = ptr->v->sfvec4d.c;
6682 }else{
6683 SFVec4dNative *ptr;
6684 if ((ptr = (SFVec4dNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
6685 printf( "JS_GetPrivate failed in SFVec4dGetProperty.\n");
6686 return JS_FALSE;
6687 }
6688 cc = ptr->v.c;
6689 }
6690 if (JSVAL_IS_INT(id)) {
6691 switch (JSVAL_TO_INT(id)) {
6692 case 0:
6693 d = cc[0];
6694 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6695 printf(
6696 "JS_NewDouble failed for %f in SFVec4dGetProperty.\n",
6697 d);
6698 return JS_FALSE;
6699 }
6700 break;
6701 case 1:
6702 d = cc[1];
6703 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6704 printf(
6705 "JS_NewDouble failed for %f in SFVec4dGetProperty.\n",
6706 d);
6707 return JS_FALSE;
6708 }
6709 break;
6710 case 2:
6711 d = cc[2];
6712 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6713 printf(
6714 "JS_NewDouble failed for %f in SFVec4dGetProperty.\n",
6715 d);
6716 return JS_FALSE;
6717 }
6718 break;
6719 case 3:
6720 d = cc[3];
6721 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6722 printf(
6723 "JS_NewDouble failed for %f in SFVec4dGetProperty.\n",
6724 d);
6725 return JS_FALSE;
6726 }
6727 break;
6728 }
6729 } else {
6730 #ifdef JSVRMLCLASSESVERBOSE
6731 printf ("SFVec4dGetProperty, id is NOT an int...\n");
6732 #endif
6733 }
6734
6735 return JS_TRUE;
6736}
6737
6738JSBool
6739SFVec4dSetProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
6740 JSObject *obj = *hobj.address();
6741 jsid iid = *hiid.address();
6742 jsval *vp = hvp.address();
6743
6744 jsval myv;
6745 double *cc;
6746
6747
6748 jsval id;
6749 if (!JS_IdToValue(cx,iid,&id)) {
6750 printf("JS_IdToValue failed in SFVec4dSetProperty.\n");
6751 return JS_FALSE;
6752 }
6753
6754 if(SM_method()==2){
6755 AnyNative *ptr;
6756 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6757 printf( "JS_GetPrivate failed in SFVec4dSetProperty.\n");
6758 return JS_FALSE;
6759 }
6760 if(ptr->valueChanged)
6761 (*ptr->valueChanged)++;
6762 #ifdef JSVRMLCLASSESVERBOSE
6763 printf("SFVec4dSetProperty: obj = %p, id = %d, valueChanged = %d\n",
6764 obj, JSVAL_TO_INT(id), ptr->valueChanged);
6765 #endif
6766 cc = ptr->v->sfvec4d.c;
6767 }else{
6768 SFVec4dNative *ptr;
6769
6770 if ((ptr = (SFVec4dNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
6771 printf( "JS_GetPrivate failed in SFVec4dSetProperty.\n");
6772 return JS_FALSE;
6773 }
6774 ptr->valueChanged++;
6775 #ifdef JSVRMLCLASSESVERBOSE
6776 printf("SFVec4dSetProperty: obj = %p, id = %d, valueChanged = %d\n",
6777 obj, JSVAL_TO_INT(id), ptr->valueChanged);
6778 #endif
6779 cc = ptr->v.c;
6780 }
6781 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
6782 printf( "JS_ConvertValue failed in SFVec4dSetProperty.\n");
6783 return JS_FALSE;
6784 }
6785
6786 if (JSVAL_IS_INT(id)) {
6787 switch (JSVAL_TO_INT(id)) {
6788 case 0:
6789 cc[0] = (float) JSVAL_TO_DOUBLE(myv);
6790 break;
6791 case 1:
6792 cc[1] = (float) JSVAL_TO_DOUBLE(myv);
6793 break;
6794 case 2:
6795 cc[2] = (float) JSVAL_TO_DOUBLE(myv);
6796 break;
6797 case 3:
6798 cc[3] = (float) JSVAL_TO_DOUBLE(myv);
6799 break;
6800 }
6801 }
6802 return JS_TRUE;
6803}
6804
6805//SFMatrix3f
6806
6807JSBool
6808SFMatrix3fToString(JSContext* cx, uintN argc, jsval* vp) {
6809 JSObject* obj = JS_THIS_OBJECT(cx, vp);
6810 jsval* argv = JS_ARGV(cx, vp);
6811
6812 JSString* _str;
6813 float* cc;
6814 char buff[STRING];
6815
6816 UNUSED(argc);
6817 UNUSED(argv);
6818 if (SM_method() == 2) {
6819 AnyNative* ptr;
6820 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
6821 printf("JS_GetPrivate failed in SFMatrix3fToString.\n");
6822 return JS_FALSE;
6823 }
6824 cc = ptr->v->sfmatrix3f.c;
6825 }
6826 memset(buff, 0, STRING);
6827 sprintf(buff, "%.9g %.9g %.9g, %.9g %.9g %.9g, %.9g %.9g %.9g ",
6828 cc[0], cc[1], cc[2],
6829 cc[3], cc[4], cc[5],
6830 cc[6], cc[7], cc[8]);
6831 _str = JS_NewStringCopyZ(cx, buff);
6832
6833 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
6834 return JS_TRUE;
6835}
6836
6837JSBool
6838SFMatrix3fAssign(JSContext* cx, uintN argc, jsval* vp) {
6839 JSObject* obj = JS_THIS_OBJECT(cx, vp);
6840 jsval* argv = JS_ARGV(cx, vp);
6841 JSString* _id_jsstr;
6842 JSObject* _from_obj;
6843 char* _id_str;
6844
6845 UNUSED(_id_str); // compiler warning mitigation
6846
6847#ifdef JSVRMLCLASSESVERBOSE
6848 printf("start of SFMatrix3fAssign\n");
6849#endif
6850
6851 if (SM_method() == 2) {
6852 AnyNative* lhs, * rhs;
6853 if ((lhs = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
6854 printf("JS_GetPrivate failed for obj in SFMatrix3fAssign.\n");
6855 return JS_FALSE;
6856 }
6857 if (!(*vp).isObject())
6858 return JS_FALSE;
6859 if ((rhs = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
6860 printf("in SFMatrix3fAssign, RHS was NOT native type \n");
6861 return JS_FALSE;
6862 }
6863 AnyNativeAssign(lhs, rhs);
6864
6865 }
6866 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
6867
6868#ifdef JSVRMLCLASSESVERBOSE
6869 printf("end of SFMatrix3fAssign\n");
6870#endif
6871
6872 return JS_TRUE;
6873}
6874
6875JSBool
6876SFMatrix3fConstr(JSContext* cx, uintN argc, jsval* vp) {
6877 JSObject* obj = JS_NewObject(cx, &SFMatrix3fClass, NULL, NULL);
6878 jsval* argv = JS_ARGV(cx, vp);
6879 jsdouble pars[9];
6880 float * cc;
6881
6882 ADD_ROOT(cx, obj)
6883 if (SM_method() == 2) {
6884 AnyNative* any;
6885 if ((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFMatrix3f, NULL, NULL)) == NULL) {
6886 printf("SFMatrix3fNativeNew failed in SFMatrix3fConstr.\n");
6887 return JS_FALSE;
6888 }
6889
6890 if (!JS_SetPrivateFw(cx, obj, any)) {
6891 printf("JS_SetPrivate failed in SFMatrix3fConstr.\n");
6892 return JS_FALSE;
6893 }
6894 cc = any->v->sfmatrix3f.c;
6895 }
6896 memset(cc, 0, sizeof(struct SFMatrix3f));
6897 int ncopy = 0;
6898 if (argc == 1) {
6899 JSObject* _arrayObj;
6900 int isArray;
6901
6902 if (!JS_ValueToObject(cx, argv[0], &_arrayObj)) {
6903 printf("JS_ValueToObject failed in SFMatrix3fConstr.\n");
6904 return JS_FALSE;
6905 }
6906
6907 if (JS_IsArrayObject(cx, _arrayObj)) {
6908 jsuint lengthp;
6909 jsval vp;
6910 double _d;
6911 //printf("its an array\n");
6912 isArray = TRUE;
6913 JS_GetArrayLength(cx, _arrayObj, &lengthp);
6914 ncopy = lengthp > 9 ? 9 : lengthp;
6915 for (int i = 0; i < ncopy; i++) {
6916 JS_GetElement(cx, _arrayObj, i, &vp);
6917 if (JS_ValueToNumber(cx, vp, &_d))
6918 cc[i] = _d;
6919 }
6920 }
6921 else {
6922
6923 AnyNative* ptr;
6924 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
6925 printf("JS_GetPrivate failed in SFMatrix3fConstr.\n");
6926 return JS_FALSE;
6927 }
6928 shallow_copy_field_precision(ptr->type, FIELDTYPE_SFMatrix3f, ptr->v, (union anyVrml*)cc);
6929 }
6930 }else if(argc == 9){
6931 if (!JS_ConvertArguments(cx, argc, argv, "d d d d d d d d d",
6932 &(pars[0]), &(pars[1]), &(pars[2]),
6933 &(pars[3]), &(pars[4]), &(pars[5]),
6934 &(pars[6]), &(pars[7]), &(pars[8]) )) {
6935 printf("JS_ConvertArguments failed in SFMatrix3fConstr.\n");
6936 return JS_FALSE;
6937 }
6938 for(int i=0;i<9;i++)
6939 cc[i] = (float)pars[i];
6940 }
6941 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
6942 return JS_TRUE;
6943}
6944
6945JSBool
6946SFMatrix3fGetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp) {
6947 JSObject* obj = *hobj.address();
6948 jsid iid = *hiid.address();
6949 jsval* vp = hvp.address();
6950
6951 jsdouble d;
6952 float* cc;
6953
6954 jsval id;
6955 if (!JS_IdToValue(cx, iid, &id)) {
6956 printf("JS_IdToValue failed in SFMatrix3fGetProperty.\n");
6957 return JS_FALSE;
6958 }
6959
6960 if (SM_method() == 2) {
6961 AnyNative* ptr;
6962 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
6963 printf("JS_GetPrivate failed in SFMatrix3fGetProperty.\n");
6964 return JS_FALSE;
6965 }
6966 cc = ptr->v->sfmatrix3f.c;
6967 }
6968 if (JSVAL_IS_INT(id)) {
6969 int ii = JSVAL_TO_INT(id);
6970 if (ii > -1 && ii < 9) {
6971 d = cc[ii];
6972 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
6973 printf(
6974 "JS_NewDouble failed for %f in SFMatrix3fGetProperty.\n",
6975 d);
6976 return JS_FALSE;
6977 }
6978 }
6979 else {
6980 //index out of range
6981 return JS_FALSE;
6982 }
6983
6984 }
6985 return JS_TRUE;
6986}
6987
6988JSBool
6989SFMatrix3fSetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp) {
6990 JSObject* obj = *hobj.address();
6991 jsid iid = *hiid.address();
6992 jsval* vp = hvp.address();
6993
6994 jsval myv;
6995 float* cc;
6996
6997
6998 jsval id;
6999 if (!JS_IdToValue(cx, iid, &id)) {
7000 printf("JS_IdToValue failed in SFMatrix3fSetProperty.\n");
7001 return JS_FALSE;
7002 }
7003
7004 if (SM_method() == 2) {
7005 AnyNative* ptr;
7006 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7007 printf("JS_GetPrivate failed in SFMatrix3fSetProperty.\n");
7008 return JS_FALSE;
7009 }
7010 if (ptr->valueChanged)
7011 (*ptr->valueChanged)++;
7012 cc = ptr->v->sfmatrix3f.c;
7013 }
7014 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
7015 printf("JS_ConvertValue failed in SFMatrix3fSetProperty.\n");
7016 return JS_FALSE;
7017 }
7018
7019 if (JSVAL_IS_INT(id)) {
7020 int ii = JSVAL_TO_INT(id);
7021 if(ii > -1 && ii < 9)
7022 cc[ii] = (float)JSVAL_TO_DOUBLE(myv);
7023 }
7024 return JS_TRUE;
7025}
7026
7027
7028//SFMatrix4f
7029
7030JSBool
7031SFMatrix4fToString(JSContext* cx, uintN argc, jsval* vp) {
7032 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7033 jsval* argv = JS_ARGV(cx, vp);
7034
7035 JSString* _str;
7036 float* cc;
7037 char buff[STRING];
7038
7039 UNUSED(argc);
7040 UNUSED(argv);
7041 if (SM_method() == 2) {
7042 AnyNative* ptr;
7043 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7044 printf("JS_GetPrivate failed in SFMatrix4fToString.\n");
7045 return JS_FALSE;
7046 }
7047 cc = ptr->v->sfmatrix4f.c;
7048 }
7049 memset(buff, 0, STRING);
7050 sprintf(buff, "%.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g",
7051 cc[0], cc[1], cc[2], cc[3],
7052 cc[4], cc[5], cc[6], cc[7],
7053 cc[8], cc[9], cc[10], cc[11],
7054 cc[12], cc[13], cc[14], cc[15]
7055 );
7056 _str = JS_NewStringCopyZ(cx, buff);
7057
7058 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
7059 return JS_TRUE;
7060}
7061
7062JSBool
7063SFMatrix4fAssign(JSContext* cx, uintN argc, jsval* vp) {
7064 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7065 jsval* argv = JS_ARGV(cx, vp);
7066 JSString* _id_jsstr;
7067 JSObject* _from_obj;
7068 char* _id_str;
7069
7070 UNUSED(_id_str); // compiler warning mitigation
7071
7072#ifdef JSVRMLCLASSESVERBOSE
7073 printf("start of SFMatrix4fAssign\n");
7074#endif
7075
7076 if (SM_method() == 2) {
7077 AnyNative* lhs, * rhs;
7078 if ((lhs = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7079 printf("JS_GetPrivate failed for obj in SFMatrix4fAssign.\n");
7080 return JS_FALSE;
7081 }
7082 if (!(*vp).isObject())
7083 return JS_FALSE;
7084 if ((rhs = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
7085 printf("in SFMatrix4fAssign, RHS was NOT native type \n");
7086 return JS_FALSE;
7087 }
7088 AnyNativeAssign(lhs, rhs);
7089
7090 }
7091 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7092
7093#ifdef JSVRMLCLASSESVERBOSE
7094 printf("end of SFMatrix4fAssign\n");
7095#endif
7096
7097 return JS_TRUE;
7098}
7099
7100JSBool
7101SFMatrix4fConstr(JSContext* cx, uintN argc, jsval* vp) {
7102 JSObject* obj = JS_NewObject(cx, &SFMatrix4fClass, NULL, NULL);
7103 jsval* argv = JS_ARGV(cx, vp);
7104 jsdouble pars[16];
7105 float* cc;
7106
7107 ADD_ROOT(cx, obj)
7108 if (SM_method() == 2) {
7109 AnyNative* any;
7110 if ((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFMatrix4f, NULL, NULL)) == NULL) {
7111 printf("SFMatrix4fNativeNew failed in SFMatrix4fConstr.\n");
7112 return JS_FALSE;
7113 }
7114
7115 if (!JS_SetPrivateFw(cx, obj, any)) {
7116 printf("JS_SetPrivate failed in SFMatrix4fConstr.\n");
7117 return JS_FALSE;
7118 }
7119 cc = any->v->sfmatrix4f.c;
7120 }
7121 memset(cc, 0, sizeof(struct SFMatrix4f));
7122 int ncopy = 0;
7123 if (argc == 1) {
7124 JSObject* _arrayObj;
7125 int isArray;
7126
7127 if (!JS_ValueToObject(cx, argv[0], &_arrayObj)) {
7128 printf("JS_ValueToObject failed in SFMatrix4fConstr.\n");
7129 return JS_FALSE;
7130 }
7131
7132 if (JS_IsArrayObject(cx, _arrayObj)) {
7133 jsuint lengthp;
7134 jsval vp;
7135 double _d;
7136 //printf("its an array\n");
7137 isArray = TRUE;
7138 JS_GetArrayLength(cx, _arrayObj, &lengthp);
7139 ncopy = lengthp > 16 ? 16 : lengthp;
7140 for (int i = 0; i < ncopy; i++) {
7141 JS_GetElement(cx, _arrayObj, i, &vp);
7142 if (JS_ValueToNumber(cx, vp, &_d))
7143 cc[i] = _d;
7144 }
7145 }
7146 else {
7147
7148 AnyNative* ptr;
7149 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7150 printf("JS_GetPrivate failed in SFMatrix4fConstr.\n");
7151 return JS_FALSE;
7152 }
7153 shallow_copy_field_precision(ptr->type, FIELDTYPE_SFMatrix4f, ptr->v, (union anyVrml*)cc);
7154 }
7155 }
7156 else if (argc == 16) {
7157 if (!JS_ConvertArguments(cx, argc, argv, "d d d d d d d d d d d d d d d d",
7158 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]),
7159 &(pars[4]), &(pars[5]), &(pars[6]), &(pars[7]),
7160 &(pars[8]), &(pars[9]), &(pars[10]), &(pars[11]),
7161 &(pars[12]), &(pars[13]), &(pars[14]), &(pars[15])
7162 ) )
7163 {
7164 printf("JS_ConvertArguments failed in SFMatrix4fConstr.\n");
7165 return JS_FALSE;
7166 }
7167 for (int i = 0; i < 16; i++)
7168 cc[i] = (float)pars[i];
7169 }
7170 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7171 return JS_TRUE;
7172}
7173
7174JSBool
7175SFMatrix4fGetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp) {
7176 JSObject* obj = *hobj.address();
7177 jsid iid = *hiid.address();
7178 jsval* vp = hvp.address();
7179
7180 jsdouble d;
7181 float* cc;
7182
7183 jsval id;
7184 if (!JS_IdToValue(cx, iid, &id)) {
7185 printf("JS_IdToValue failed in SFMatrix4fGetProperty.\n");
7186 return JS_FALSE;
7187 }
7188
7189 if (SM_method() == 2) {
7190 AnyNative* ptr;
7191 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7192 printf("JS_GetPrivate failed in SFMatrix4fGetProperty.\n");
7193 return JS_FALSE;
7194 }
7195 cc = ptr->v->sfmatrix4f.c;
7196 }
7197 if (JSVAL_IS_INT(id)) {
7198 int ii = JSVAL_TO_INT(id);
7199 if (ii > -1 && ii < 16) {
7200 d = cc[ii];
7201 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
7202 printf(
7203 "JS_NewDouble failed for %f in SFMatrix4fGetProperty.\n",
7204 d);
7205 return JS_FALSE;
7206 }
7207 }
7208 else {
7209 //index out of range
7210 return JS_FALSE;
7211 }
7212 }
7213 return JS_TRUE;
7214}
7215
7216JSBool
7217SFMatrix4fSetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp) {
7218 JSObject* obj = *hobj.address();
7219 jsid iid = *hiid.address();
7220 jsval* vp = hvp.address();
7221
7222 jsval myv;
7223 float* cc;
7224
7225
7226 jsval id;
7227 if (!JS_IdToValue(cx, iid, &id)) {
7228 printf("JS_IdToValue failed in SFMatrix4fSetProperty.\n");
7229 return JS_FALSE;
7230 }
7231
7232 if (SM_method() == 2) {
7233 AnyNative* ptr;
7234 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7235 printf("JS_GetPrivate failed in SFMatrix4fSetProperty.\n");
7236 return JS_FALSE;
7237 }
7238 if (ptr->valueChanged)
7239 (*ptr->valueChanged)++;
7240 cc = ptr->v->sfmatrix4f.c;
7241 }
7242 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
7243 printf("JS_ConvertValue failed in SFMatrix3fSetProperty.\n");
7244 return JS_FALSE;
7245 }
7246
7247 if (JSVAL_IS_INT(id)) {
7248 int ii = JSVAL_TO_INT(id);
7249 if(ii > -1 && ii < 16)
7250 cc[ii] = (float)JSVAL_TO_DOUBLE(myv);
7251 }
7252 return JS_TRUE;
7253}
7254
7255// SFMatrix3d
7256
7257JSBool
7258SFMatrix3dToString(JSContext* cx, uintN argc, jsval* vp) {
7259 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7260 jsval* argv = JS_ARGV(cx, vp);
7261
7262 JSString* _str;
7263 double* cc;
7264 char buff[STRING];
7265
7266 UNUSED(argc);
7267 UNUSED(argv);
7268 if (SM_method() == 2) {
7269 AnyNative* ptr;
7270 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7271 printf("JS_GetPrivate failed in SFMatrix3dToString.\n");
7272 return JS_FALSE;
7273 }
7274 cc = ptr->v->sfmatrix3d.c;
7275 }
7276 memset(buff, 0, STRING);
7277 sprintf(buff, "%.9g %.9g %.9g, %.9g %.9g %.9g, %.9g %.9g %.9g ",
7278 cc[0], cc[1], cc[2],
7279 cc[3], cc[4], cc[5],
7280 cc[6], cc[7], cc[8]);
7281 _str = JS_NewStringCopyZ(cx, buff);
7282
7283 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
7284 return JS_TRUE;
7285}
7286
7287JSBool
7288SFMatrix3dAssign(JSContext* cx, uintN argc, jsval* vp) {
7289 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7290 jsval* argv = JS_ARGV(cx, vp);
7291 JSString* _id_jsstr;
7292 JSObject* _from_obj;
7293 char* _id_str;
7294
7295 UNUSED(_id_str); // compiler warning mitigation
7296
7297#ifdef JSVRMLCLASSESVERBOSE
7298 printf("start of SFMatrix3dAssign\n");
7299#endif
7300
7301 if (SM_method() == 2) {
7302 AnyNative* lhs, * rhs;
7303 if ((lhs = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7304 printf("JS_GetPrivate failed for obj in SFMatrix3dAssign.\n");
7305 return JS_FALSE;
7306 }
7307 if (!(*vp).isObject())
7308 return JS_FALSE;
7309 if ((rhs = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
7310 printf("in SFMatrix3dAssign, RHS was NOT native type \n");
7311 return JS_FALSE;
7312 }
7313 AnyNativeAssign(lhs, rhs);
7314
7315 }
7316 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7317
7318#ifdef JSVRMLCLASSESVERBOSE
7319 printf("end of SFMatrix3dAssign\n");
7320#endif
7321
7322 return JS_TRUE;
7323}
7324
7325JSBool
7326SFMatrix3dConstr(JSContext* cx, uintN argc, jsval* vp) {
7327 JSObject* obj = JS_NewObject(cx, &SFMatrix3dClass, NULL, NULL);
7328 jsval* argv = JS_ARGV(cx, vp);
7329 jsdouble pars[9];
7330 double* cc;
7331
7332 ADD_ROOT(cx, obj)
7333 if (SM_method() == 2) {
7334 AnyNative* any;
7335 if ((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFMatrix3d, NULL, NULL)) == NULL) {
7336 printf("SFMatrix3dNativeNew failed in SFMatrix3dConstr.\n");
7337 return JS_FALSE;
7338 }
7339
7340 if (!JS_SetPrivateFw(cx, obj, any)) {
7341 printf("JS_SetPrivate failed in SFMatrix3dConstr.\n");
7342 return JS_FALSE;
7343 }
7344 cc = any->v->sfmatrix3d.c;
7345 }
7346 memset(cc, 0, sizeof(struct SFMatrix3d));
7347 int ncopy = 0;
7348 if (argc == 1) {
7349 JSObject* _arrayObj;
7350 int isArray;
7351
7352 if (!JS_ValueToObject(cx, argv[0], &_arrayObj)) {
7353 printf("JS_ValueToObject failed in SFMatrix3dConstr.\n");
7354 return JS_FALSE;
7355 }
7356
7357 if (JS_IsArrayObject(cx, _arrayObj)) {
7358 jsuint lengthp;
7359 jsval vp;
7360 double _d;
7361 //printf("its an array\n");
7362 isArray = TRUE;
7363 JS_GetArrayLength(cx, _arrayObj, &lengthp);
7364 ncopy = lengthp > 9 ? 9 : lengthp;
7365 for (int i = 0; i < ncopy; i++) {
7366 JS_GetElement(cx, _arrayObj, i, &vp);
7367 if (JS_ValueToNumber(cx, vp, &_d))
7368 cc[i] = _d;
7369 }
7370 }
7371 else {
7372
7373 AnyNative* ptr;
7374 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7375 printf("JS_GetPrivate failed in SFMatrix3dConstr.\n");
7376 return JS_FALSE;
7377 }
7378 shallow_copy_field_precision(ptr->type, FIELDTYPE_SFMatrix3d, ptr->v, (union anyVrml*)cc);
7379 }
7380 }
7381 else if (argc == 9) {
7382 if (!JS_ConvertArguments(cx, argc, argv, "d d d d d d d d d",
7383 &(pars[0]), &(pars[1]), &(pars[2]),
7384 &(pars[3]), &(pars[4]), &(pars[5]),
7385 &(pars[6]), &(pars[7]), &(pars[8]))) {
7386 printf("JS_ConvertArguments failed in SFMatrix3dConstr.\n");
7387 return JS_FALSE;
7388 }
7389 for (int i = 0; i < 9; i++)
7390 cc[i] = (double)pars[i];
7391 }
7392 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7393 return JS_TRUE;
7394}
7395
7396JSBool
7397SFMatrix3dGetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp) {
7398 JSObject* obj = *hobj.address();
7399 jsid iid = *hiid.address();
7400 jsval* vp = hvp.address();
7401
7402 jsdouble d;
7403 double* cc;
7404
7405 jsval id;
7406 if (!JS_IdToValue(cx, iid, &id)) {
7407 printf("JS_IdToValue failed in SFMatrix3dGetProperty.\n");
7408 return JS_FALSE;
7409 }
7410
7411 if (SM_method() == 2) {
7412 AnyNative* ptr;
7413 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7414 printf("JS_GetPrivate failed in SFMatrix3dGetProperty.\n");
7415 return JS_FALSE;
7416 }
7417 cc = ptr->v->sfmatrix3d.c;
7418 }
7419 if (JSVAL_IS_INT(id)) {
7420 int ii = JSVAL_TO_INT(id);
7421 if (ii > -1 && ii < 9) {
7422 d = cc[ii];
7423 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
7424 printf(
7425 "JS_NewDouble failed for %f in SFMatrix3dGetProperty.\n",
7426 d);
7427 return JS_FALSE;
7428 }
7429 }
7430 else {
7431 //index out of range
7432 return JS_FALSE;
7433 }
7434
7435 }
7436 return JS_TRUE;
7437}
7438
7439JSBool
7440SFMatrix3dSetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp) {
7441 JSObject* obj = *hobj.address();
7442 jsid iid = *hiid.address();
7443 jsval* vp = hvp.address();
7444
7445 jsval myv;
7446 double* cc;
7447
7448
7449 jsval id;
7450 if (!JS_IdToValue(cx, iid, &id)) {
7451 printf("JS_IdToValue failed in SFMatrix3dSetProperty.\n");
7452 return JS_FALSE;
7453 }
7454
7455 if (SM_method() == 2) {
7456 AnyNative* ptr;
7457 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7458 printf("JS_GetPrivate failed in SFMatrix3dSetProperty.\n");
7459 return JS_FALSE;
7460 }
7461 if (ptr->valueChanged)
7462 (*ptr->valueChanged)++;
7463 cc = ptr->v->sfmatrix3d.c;
7464 }
7465 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
7466 printf("JS_ConvertValue failed in SFMatrix3dSetProperty.\n");
7467 return JS_FALSE;
7468 }
7469
7470 if (JSVAL_IS_INT(id)) {
7471 int ii = JSVAL_TO_INT(id);
7472 if (ii > -1 && ii < 9)
7473 cc[ii] = (double)JSVAL_TO_DOUBLE(myv);
7474 }
7475 return JS_TRUE;
7476}
7477
7478// SFMatrix4d
7479
7480JSBool
7481SFMatrix4dToString(JSContext* cx, uintN argc, jsval* vp) {
7482 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7483 jsval* argv = JS_ARGV(cx, vp);
7484
7485 JSString* _str;
7486 double* cc;
7487 char buff[STRING];
7488
7489 UNUSED(argc);
7490 UNUSED(argv);
7491 if (SM_method() == 2) {
7492 AnyNative* ptr;
7493 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7494 printf("JS_GetPrivate failed in SFMatrix4dToString.\n");
7495 return JS_FALSE;
7496 }
7497 cc = ptr->v->sfmatrix4d.c;
7498 }
7499 memset(buff, 0, STRING);
7500 sprintf(buff, "%.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g, %.9g %.9g %.9g %.9g",
7501 cc[0], cc[1], cc[2], cc[3],
7502 cc[4], cc[5], cc[6], cc[7],
7503 cc[8], cc[9], cc[10], cc[11],
7504 cc[12], cc[13], cc[14], cc[15]
7505 );
7506 _str = JS_NewStringCopyZ(cx, buff);
7507
7508 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(_str));
7509 return JS_TRUE;
7510}
7511
7512JSBool
7513SFMatrix4dAssign(JSContext* cx, uintN argc, jsval* vp) {
7514 JSObject* obj = JS_THIS_OBJECT(cx, vp);
7515 jsval* argv = JS_ARGV(cx, vp);
7516 JSString* _id_jsstr;
7517 JSObject* _from_obj;
7518 char* _id_str;
7519
7520 UNUSED(_id_str); // compiler warning mitigation
7521
7522#ifdef JSVRMLCLASSESVERBOSE
7523 printf("start of SFMatrix4dAssign\n");
7524#endif
7525
7526 if (SM_method() == 2) {
7527 AnyNative* lhs, * rhs;
7528 if ((lhs = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7529 printf("JS_GetPrivate failed for obj in SFMatrix4dAssign.\n");
7530 return JS_FALSE;
7531 }
7532 if (!(*vp).isObject())
7533 return JS_FALSE;
7534 if ((rhs = (AnyNative*)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
7535 printf("in SFMatrix4dAssign, RHS was NOT native type \n");
7536 return JS_FALSE;
7537 }
7538 AnyNativeAssign(lhs, rhs);
7539
7540 }
7541 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7542
7543#ifdef JSVRMLCLASSESVERBOSE
7544 printf("end of SFMatrix4dAssign\n");
7545#endif
7546
7547 return JS_TRUE;
7548}
7549
7550JSBool
7551SFMatrix4dConstr(JSContext* cx, uintN argc, jsval* vp) {
7552 JSObject* obj = JS_NewObject(cx, &SFMatrix4dClass, NULL, NULL);
7553 jsval* argv = JS_ARGV(cx, vp);
7554 jsdouble pars[16];
7555 double* cc;
7556
7557 ADD_ROOT(cx, obj)
7558 if (SM_method() == 2) {
7559 AnyNative* any;
7560 if ((any = (AnyNative*)AnyNativeNew(FIELDTYPE_SFMatrix4d, NULL, NULL)) == NULL) {
7561 printf("SFMatrix4dNativeNew failed in SFMatrix4dConstr.\n");
7562 return JS_FALSE;
7563 }
7564
7565 if (!JS_SetPrivateFw(cx, obj, any)) {
7566 printf("JS_SetPrivate failed in SFMatrix4dConstr.\n");
7567 return JS_FALSE;
7568 }
7569 cc = any->v->sfmatrix4d.c;
7570 }
7571 memset(cc, 0, sizeof(struct SFMatrix4d));
7572 int ncopy = 0;
7573 if (argc == 1) {
7574 JSObject* _arrayObj;
7575 int isArray;
7576
7577 if (!JS_ValueToObject(cx, argv[0], &_arrayObj)) {
7578 printf("JS_ValueToObject failed in SFMatrix4dConstr.\n");
7579 return JS_FALSE;
7580 }
7581
7582 if (JS_IsArrayObject(cx, _arrayObj)) {
7583 jsuint lengthp;
7584 jsval vp;
7585 double _d;
7586 //printf("its an array\n");
7587 isArray = TRUE;
7588 JS_GetArrayLength(cx, _arrayObj, &lengthp);
7589 ncopy = lengthp > 16 ? 16 : lengthp;
7590 for (int i = 0; i < ncopy; i++) {
7591 JS_GetElement(cx, _arrayObj, i, &vp);
7592 if (JS_ValueToNumber(cx, vp, &_d))
7593 cc[i] = _d;
7594 }
7595 }
7596 else {
7597
7598 AnyNative* ptr;
7599 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7600 printf("JS_GetPrivate failed in SFMatrix4dConstr.\n");
7601 return JS_FALSE;
7602 }
7603 shallow_copy_field_precision(ptr->type, FIELDTYPE_SFMatrix4d, ptr->v, (union anyVrml*)cc);
7604 }
7605 }
7606 else if (argc == 16) {
7607 if (!JS_ConvertArguments(cx, argc, argv, "d d d d d d d d d d d d d d d d",
7608 &(pars[0]), &(pars[1]), &(pars[2]), &(pars[3]),
7609 &(pars[4]), &(pars[5]), &(pars[6]), &(pars[7]),
7610 &(pars[8]), &(pars[9]), &(pars[10]), &(pars[11]),
7611 &(pars[12]), &(pars[13]), &(pars[14]), &(pars[15])
7612 ))
7613 {
7614 printf("JS_ConvertArguments failed in SFMatrix4dConstr.\n");
7615 return JS_FALSE;
7616 }
7617 for (int i = 0; i < 16; i++)
7618 cc[i] = (double)pars[i];
7619 }
7620 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
7621 return JS_TRUE;
7622}
7623
7624JSBool
7625SFMatrix4dGetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp) {
7626 JSObject* obj = *hobj.address();
7627 jsid iid = *hiid.address();
7628 jsval* vp = hvp.address();
7629
7630 jsdouble d;
7631 double* cc;
7632
7633 jsval id;
7634 if (!JS_IdToValue(cx, iid, &id)) {
7635 printf("JS_IdToValue failed in SFMatrix4dGetProperty.\n");
7636 return JS_FALSE;
7637 }
7638
7639 if (SM_method() == 2) {
7640 AnyNative* ptr;
7641 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7642 printf("JS_GetPrivate failed in SFMatrix4dGetProperty.\n");
7643 return JS_FALSE;
7644 }
7645 cc = ptr->v->sfmatrix4d.c;
7646 }
7647 if (JSVAL_IS_INT(id)) {
7648 int ii = JSVAL_TO_INT(id);
7649 if (ii > -1 && ii < 16) {
7650 d = cc[ii];
7651 if (JS_NewNumberValue(cx, d, vp) == JS_FALSE) {
7652 printf(
7653 "JS_NewDouble failed for %f in SFMatrix4dGetProperty.\n",
7654 d);
7655 return JS_FALSE;
7656 }
7657 }
7658 else {
7659 //index out of range
7660 return JS_FALSE;
7661 }
7662 }
7663 return JS_TRUE;
7664}
7665
7666JSBool
7667SFMatrix4dSetProperty(JSContext* cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp) {
7668 JSObject* obj = *hobj.address();
7669 jsid iid = *hiid.address();
7670 jsval* vp = hvp.address();
7671
7672 jsval myv;
7673 double* cc;
7674
7675
7676 jsval id;
7677 if (!JS_IdToValue(cx, iid, &id)) {
7678 printf("JS_IdToValue failed in SFMatrix4dSetProperty.\n");
7679 return JS_FALSE;
7680 }
7681
7682 if (SM_method() == 2) {
7683 AnyNative* ptr;
7684 if ((ptr = (AnyNative*)JS_GetPrivateFw(cx, obj)) == NULL) {
7685 printf("JS_GetPrivate failed in SFMatrix4dSetProperty.\n");
7686 return JS_FALSE;
7687 }
7688 if (ptr->valueChanged)
7689 (*ptr->valueChanged)++;
7690 cc = ptr->v->sfmatrix4d.c;
7691 }
7692 if (!JS_ConvertValue(cx, *vp, JSTYPE_NUMBER, &myv)) {
7693 printf("JS_ConvertValue failed in SFMatrix3fSetProperty.\n");
7694 return JS_FALSE;
7695 }
7696
7697 if (JSVAL_IS_INT(id)) {
7698 int ii = JSVAL_TO_INT(id);
7699 if (ii > -1 && ii < 16)
7700 cc[ii] = (double)JSVAL_TO_DOUBLE(myv);
7701 }
7702 return JS_TRUE;
7703}
7704
7705
7706
7707#endif //defined(JS_SMCPP)
7708#endif //JAVASCRIPT_SM