-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRibGlue.c
1113 lines (884 loc) · 25.2 KB
/
RibGlue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* RibGlue.c
* MacRib
*
* Created by flip phillips on 9/30/04.
* Copyright 2004 skidmore ebv labs. All rights reserved.
*
* $Id: RibGlue.c 22 2007-06-03 04:24:18Z flip $
*/
#include "mathlink.h"
#include "ri.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include <RibGlue.h>
////
// utility
////
typedef struct {
void *array;
int len;
unsigned char aType;
} apar;
// globals. i know. i'm tired. it doesn't matter, chompers aren't re-entrant
static int *gIparams;
static float *gFparams;
static char **gSparams;
static apar *gAparams;
static int gNfp=0, gNsp=0, gNip=0,gNap=0;
//
// chomp parses off name-value pairs from a list
// its up to you to make sure that the values have the right types
// there's no way to know from the RiSpec what optional arguments' types
// should be
//
int
chompPairs(long *nparams, RtToken **tokens, RtPointer **pparams)
{
int n,np;
int i,j;
float* fp;
int* ip;
apar* ap;
// do we even have a list of things to parse?
MLTestHead(stdlink,"List",&n);
if(n<=0) {
*nparams = 0;
*tokens = NULL;
*pparams = NULL;
return 0;
}
// do we have an even number of things to parse?
else if (n%2 != 0) {
*nparams = 0;
*tokens = NULL;
*pparams = NULL;
return RIE_MISSINGDATA;
}
// we're going to make this harder
// than we probably should
np = n/2; *nparams = np;
// allocate stuff to be passed to V functions
*tokens = (RtToken*)malloc(np*sizeof(RtToken));
*pparams = (RtPointer*)malloc(np*sizeof(RtPointer));
// allocate storage for worst case
gIparams = (int*)malloc(np*sizeof(int));
gFparams = (float*)malloc(np*sizeof(float));
gSparams = (char**)malloc(np*sizeof(char*));
gAparams = (apar*)malloc(np*sizeof(apar));
// peel off pairs
for(i=0;i<np;i++) {
// token
MLGetString(stdlink,(kcharpp_ct)&(*tokens)[i]);
// value
switch (MLGetNext(stdlink)) {
case MLTKINT:
MLGetInteger32(stdlink,&gIparams[gNip]);
(*pparams)[i] = &gIparams[gNip++];
break;
case MLTKREAL:
MLGetReal32(stdlink,&gFparams[gNfp]);
(*pparams)[i] = &gFparams[gNfp++];
break;
case MLTKSTR:
MLGetString(stdlink,(kcharpp_ct)&gSparams[gNsp]);
(*pparams)[i]=&gSparams[gNsp++];
break;
// better be a list...
case MLTKFUNC:
MLTestHead(stdlink,"List",&n);
if(n<=0) {
MLFlush(stdlink);
return RIE_MISSINGDATA;
}
ap=&gAparams[gNap++];
ap->aType=MLGetNext(stdlink);
ap->len=n;
ap->array=(void*)malloc(sizeof(int)*n);
fp=(float*)ap->array;
ip=(int*)ap->array;
for(j=0;j<n;j++,fp++,ip++) {
switch(ap->aType) {
case MLTKINT:
MLGetInteger32(stdlink,ip);
break;
case MLTKREAL:
MLGetReal32(stdlink,fp);
break;
default: //error
MLFlush(stdlink);
return RIE_MISSINGDATA;
}
}
(*pparams)[i]=ap->array;
break;
default: // error
MLFlush(stdlink);
return RIE_MISSINGDATA;
}
}
return 0;
}
void
cleanTeeth(long nparams, RtToken *tokens, RtPointer *params)
{
long i;
if(nparams <= 0)
return;
// clean up mathlink
for(i=0;i<nparams;i++)
MLReleaseString(stdlink,tokens[i]);
for(i=0;i<gNsp;i++)
MLReleaseString(stdlink,gSparams[i]);
for(i=0;i<gNap;i++) {
apar* ap=&gAparams[i];
free(ap->array);
}
// clean up our universe
free(tokens);
free(params);
free(gIparams);
free(gFparams);
free(gSparams);
free(gAparams);
gNfp=0, gNsp=0, gNip=0; gNap=0;
}
// globals
int gRiLastError() {return RiLastError;}
// filtration
/* no glue needed
float RiGaussianFilter(float x, float y, float xwidth, float ywidth);
float RiBoxFilter(float x, float y, float xwidth, float ywidth);
float RiTriangleFilter(float x, float y, float xwidth, float ywidth);
float RiCatmullRomFilter(float x, float y, float xwidth, float ywidth);
float RiSeparableCatmullRomFilter(float x, float y, float xwidth, float ywidth);
float RiBlackmanHarrisFilter(float x, float y, float xwidth, float ywidth);
float RiLanczosFilter(float x, float y, float xwidth, float ywidth);
float RiMitchellFilter(float x, float y, float xwidth, float ywidth);
float RiSincFilter(float x, float y, float xwidth, float ywidth);
float RiBesselFilter(float x, float y, float xwidth, float ywidth);
float RiDiskFilter(float x, float y, float xwidth, float ywidth);
*/
// error stuff
int gRiErrorIgnore(int code, int severity, char *msg) { RiErrorIgnore(code, severity, msg); return RiLastError; }
int gRiErrorPrint(int code, int severity, char *msg) { RiErrorPrint(code, severity, msg); return RiLastError; }
int gRiErrorPrintOnce(int code, int severity, char *msg) { RiErrorPrintOnce(code, severity, msg); return RiLastError; }
int gRiErrorCondAbort(int code, int severity, char *msg) { RiErrorCondAbort(code, severity, msg); return RiLastError; }
int gRiErrorAbort(int code, int severity, char *msg) { RiErrorAbort(code, severity, msg); return RiLastError; }
int gRiErrorCleanup(void) { RiErrorCleanup(); return RiLastError; }
////
// procs
////
// NEEDS IMPLEMENTATION
// RtVoid RiProcDelayedReadArchive(RtPointer data, float detail);
// RtVoid RiProcRunProgram(RtPointer data, float detail);
// RtVoid RiProcDynamicLoad(RtPointer data, float detail);
////
// context
////
void gRiGetContext(void)
{
RtContextHandle ctx = RiGetContext();
MLPutFunction(stdlink,"RtContextHandle",1);
MLPutInteger(stdlink,(int)ctx);
return;
}
int gRiContext(void* ip)
{
RtContextHandle ctx;
ctx = (RtContextHandle)ip;
RiContext(ctx);
return RiLastError;
}
////
// declare token
////
void gRiDeclare(char *name, char *declaration) { MLPutString(stdlink,RiDeclare(name,declaration));}
////
// general state
////
int gRiBegin(char* name) { RiBegin(name); return RiLastError; }
int gRiEnd() { RiEnd(); return RiLastError; }
int gRiFrameBegin(int num) { RiFrameBegin(num); return RiLastError; }
int gRiFrameEnd() { RiFrameEnd(); return RiLastError; }
int gRiWorldBegin() { RiWorldBegin(); return RiLastError; }
int gRiWorldEnd() { RiWorldEnd(); return RiLastError; }
////
// image formation
////
int gRiFormat(int xres, int yres, double aspect) {RiFormat(xres,yres,aspect); return RiLastError;}
int gRiFrameAspectRatio(double aspect) {RiFrameAspectRatio(aspect); return RiLastError;}
int gRiScreenWindow(double left, double right, double bot, double top) {RiScreenWindow(left,right,bot,top); return RiLastError;}
int gRiCropWindow(double xmin, double xmax, double ymin, double ymax) {RiCropWindow(xmin,xmax,ymin,ymax); return RiLastError;}
int gRiProjection(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiProjectionV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiClipping(double hither, double yon) {RiClipping(hither,yon); return RiLastError;}
int gRiClippingPlane(double Nx, double Ny, double Nz, double Px, double Py, double Pz) {RiClippingPlane(Nx,Ny,Nz,Px,Py,Pz); return RiLastError;}
int gRiDepthOfField(double fstop, double focallength, double focaldistance) {RiDepthOfField(fstop,focallength,focaldistance); return RiLastError;}
int gRiShutter(double min, double max) {RiShutter(min,max); return RiLastError;}
int gRiPixelVariance(double variation){ RiPixelVariance(variation); return RiLastError; }
int gRiPixelFidelity(double variation){ /* RiPixelFidelity(variation); */ return RiLastError; }
int gRiPixelSamples(double xsamples, double ysamples){ RiPixelSamples(xsamples, ysamples); return RiLastError; }
//int gRiPixelFilter(RtFilterFunc filterfunc, float xwidth, float ywidth){ RiPixelFilter(filterfunc, xwidth, ywidth); return RiLastError; }
int gRiExposure(double gain, double gamma){ RiExposure(gain, gamma); return RiLastError; }
int gRiImager(char* name)
{
RtToken *tokens;
RtPointer *parms;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, &parms)))
goto error;
RiImagerV(name, nparams, tokens, parms);
cleanTeeth(nparams,tokens,parms);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiQuantize(char* type, int one, int min, int max, double ampl){ RiQuantize( type, one, min, max, ampl); return RiLastError; }
int gRiDisplay(char *name, char* type, char* mode)
{
RtToken *tokens;
RtPointer *parms;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, &parms)))
goto error;
RiDisplayV(name, type, mode, nparams, tokens, parms);
cleanTeeth(nparams,tokens,parms);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiHider(char* type)
{
RtToken *tokens;
RtPointer *parms;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, &parms)))
goto error;
RiHiderV(type, nparams, tokens, parms);
cleanTeeth(nparams,tokens,parms);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiColorSamples(int n, double nRGB[], long len1, double RGBn[], long len2)
{
float nnRGB[512]; // if you have a color space this large you're in trouble
float RGBnn[512];
long i;
if((len1!=len2!=n*3)||len1>512)
return RIE_MISSINGDATA;
for(i=0;i<len1;i++) {
nnRGB[i]=nRGB[i];
RGBnn[i]=RGBn[i];
}
RiColorSamples(n, nnRGB, RGBnn);
return RiLastError;
}
int gRiRelativeDetail(double relativedetail){ RiRelativeDetail(relativedetail); return RiLastError; }
int gRiOption(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiOptionV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
////
// attributes
////
int gRiAttributeBegin(void){ RiAttributeBegin(); return RiLastError; }
int gRiAttributeEnd(void){ RiAttributeEnd(); return RiLastError; }
int gRiColor(double r, double g, double b)
{
RtColor cc={r,g,b};
RiColor(cc);
return RiLastError;
}
int gRiOpacity(double r, double g, double b)
{
RtColor cc={r,g,b};
RiOpacity(cc);
return RiLastError;
}
int gRiTextureCoordinates(double s1, double t1, double s2, double t2, double s3, double t3, double s4, double t4){ RiTextureCoordinates( s1, t1, s2, t2, s3, t3, s4, t4); return RiLastError; }
////
// light sources
////
void gRiLightSource(char* type)
{
RtLightHandle hndl;
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
hndl = RiLightSourceV(type, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
MLPutFunction(stdlink,"RtLightHandle",1);
MLPutInteger(stdlink,(int)hndl);
return;
error:
MLClearError(stdlink);
MLFlush(stdlink);
MLPutSymbol(stdlink,"$Failed");
return;
}
void gRiAreaLightSource(char* type)
{
RtLightHandle hndl;
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
hndl = RiAreaLightSource(type, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
MLPutFunction(stdlink,"RtLightHandle",1);
MLPutInteger(stdlink,(int)hndl);
return;
error:
MLClearError(stdlink);
MLFlush(stdlink);
MLPutSymbol(stdlink,"$Failed");
return;
}
int gRiIlluminate(void* ip, char* state)
{
RtLightHandle light = (RtLightHandle)ip;
RiIlluminate(light,strcmp(state,"True")?1:0);
return RiLastError;
}
int gRiSurface(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiSurfaceV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiAtmosphere(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiAtmosphereV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiInterior(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiInteriorV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiExterior(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiExteriorV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiShadingRate(double size){ RiShadingRate(size); return RiLastError; }
int gRiShadingInterpolation(char* type){ RiShadingInterpolation(type); return RiLastError; }
int gRiMatte(char* state){ RiMatte(strcmp(state,"True")?1:0); return RiLastError; }
int gRiBound(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
{
RtBound bb = {xmin, xmax, ymin, ymax, zmin, zmax};
RiBound(bb);
return RiLastError;
}
int gRiDetail(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
{
RtBound bb = {xmin, xmax, ymin, ymax, zmin, zmax};
RiDetail(bb);
return RiLastError;
}
int gRiDetailRange(double minvis, double lowtran, double uptran, double maxvis){ RiDetailRange(minvis,lowtran,uptran,maxvis); return RiLastError; }
int gRiGeometricApproximation(char* type, double value){ RiGeometricApproximation(type,value); return RiLastError; }
int gRiOrientation(char* orientation){ RiOrientation(orientation); return RiLastError; }
int gRiReverseOrientation(void){ RiReverseOrientation(); return RiLastError; }
int gRiSides(int sides){ RiSides(sides); return RiLastError; }
////
// transformations
////
int gRiIdentity(void){ RiIdentity(); return RiLastError; }
int gRiTransform(void)
{
RtMatrix m;
float *mp = (float*)m;
double *a; int *dims;
char **heads;
long i; int d, err = 0;
MLGetReal64Array(stdlink,&a,&dims,&heads,&d);
if(d!=2 || dims[0]!=4 || dims[1]!=4){
err = RIE_MISSINGDATA;
goto error;
}
for(i=0;i<16;i++)
mp[i]=a[i];
RiTransform(m);
error:
MLReleaseReal64Array(stdlink,a,dims,heads,d);
return err;
}
int gRiConcatTransform(RtMatrix transform)
{
RtMatrix m;
float *mp = (float*)m;
double *a; int *dims;
char **heads;
long i; int d, err = 0;
MLGetReal64Array(stdlink,&a,&dims,&heads,&d);
if(d!=2 || dims[0]!=4 || dims[1]!=4){
err = RIE_MISSINGDATA;
goto error;
}
for(i=0;i<16;i++)
mp[i]=a[i];
RiConcatTransform(m);
error:
MLReleaseReal64Array(stdlink,a,dims,heads,d);
return err;
}
int gRiPerspective(double fov){ RiPerspective(fov); return RiLastError; }
int gRiTranslate(double dx, double dy, double dz){ RiTranslate(dx,dy,dz); return RiLastError; }
int gRiRotate(double angle, double dx, double dy, double dz){ RiRotate(angle,dx,dy,dz); return RiLastError; }
int gRiScale(double sx, double sy, double sz){ RiScale(sx,sy,sz); return RiLastError; }
int gRiSkew(double angle, double dx1, double dy1, double dz1, double dx2, double dy2, double dz2){ RiSkew(angle,dx1,dy1,dz1,dx2,dy2,dz2); return RiLastError; }
int gRiDeformation(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiDeformationV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiDisplacement(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiDisplacementV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
int gRiCoordinateSystem(char* space){ RiCoordinateSystem(space); return RiLastError; }
int gRiScopedCoordinateSystem(char* space){ RiScopedCoordinateSystem(space); return RiLastError; }
int gRiCoordSysTransform(char* space){ RiCoordSysTransform(space); return RiLastError; }
// this is here but is unclaimed... RiTransformPoints isn't available under macos
void gRiTransformPoints(char* fromspace, char* tospace)
{
RtPoint *m;
float *mp;
double *a,*ap; int *dims, d;
char **heads; long i;
MLGetReal64Array(stdlink,&a,&dims,&heads,&d);
if(d!=2 || dims[1]!=3){
MLReleaseReal64Array(stdlink,a,dims,heads,d);
a=NULL;
return;
}
m=(RtPoint*)malloc(dims[0]*sizeof(RtPoint));
for(mp=(float*)m,ap=a,i=0;i<dims[0]*dims[1];i++,mp++,ap++)
*mp=*ap;
RiTransformPoints(fromspace, tospace, dims[0], m);
for(mp=(float*)m,ap=a,i=0;i<dims[0]*dims[1];i++,mp++,ap++)
*ap=*mp;
MLPutReal64Array(stdlink,a, dims,NULL,d);
free(m);
// not going to disown since we are returning it?
return;
}
int gRiTransformBegin(void){ RiTransformBegin(); return RiLastError; }
int gRiTransformEnd(void){ RiTransformEnd(); return RiLastError; }
////
// attributes
////
int gRiAttribute(char* name)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiAttributeV(name, nparams, tokens, params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
/////
// geometry
////
int gRiPolygon(void)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
// hack alert... presumes that P is first...
// RiPolygonV(gAparams[0].dims[0],nparams,tokens,params);
// need diff parser here
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
// RiGeneralPolygon(RtInt nloops, RtInt nverts[], ...),
int
gRiPointsPolygons(int npolys, int* nverts, long nnnverts, int* verts, long nnverts)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiPointsPolygonsV(npolys,nverts,verts,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
// RiPointsGeneralPolygons(RtInt npolys, RtInt nloops[], RtInt nverts[], RtInt verts[], ...),
// RiBasis(RtBasis ubasis, RtInt ustep, RtBasis vbasis, RtInt vstep),
// RiPatch(RtToken type, ...),
//RiPatchV(RtToken type, RtInt n, RtToken tokens[], RtPointer parms[]),
int gRiPatch(char* type)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiPatchV(type,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink);
MLFlush(stdlink);
return err;
}
// RiPatchMesh(RtToken type, RtInt nu, RtToken uwrap, RtInt nv, RtToken vwrap, ...),
// RiNuPatch(RtInt nu, RtInt uorder, RtFloat uknot[], RtFloat umin, RtFloat umax,
// RtInt nv, RtInt vorder, RtFloat vknot[], RtFloat vmin,
// RtFloat vmax, ...),
int gRiSphere(double radius, double zmin, double zmax, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiSphereV(radius, zmin, zmax, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiCone(double height, double radius, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiConeV(height, radius, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiCylinder(double radius, double zmin, double zmax, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiCylinderV(radius, zmin, zmax, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiHyperboloid(RtPoint point1, RtPoint point2, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiHyperboloidV(point1, point2, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiParaboloid(double rmax, double zmin, double zmax, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiParaboloidV(rmax, zmin, zmax, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiDisk(double height, double radius, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiDiskV(height, radius, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiTorus(double majrad, double minrad, double phimin, double phimax, double tmax)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiTorusV(majrad, minrad, phimin, phimax, tmax,nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
// Needs Implementation
//RiBlobby(RtInt nleaf, RtInt ncode, RtInt code[],
// RtInt nflt, RtFloat flt[],
// RtInt nstr, RtToken str[], ...);
int gRiCurves(char* type, int ncurves, int nvertices[], char* wrap)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiCurvesV(type, ncurves, nvertices, wrap, nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);
return err;
}
int gRiPoints(int nverts)
{
RtToken *tokens;
RtPointer *params;
long nparams;
int err;
if((err=chompPairs(&nparams, &tokens, ¶ms)))
goto error;
RiPointsV(nverts, nparams,tokens,params);
cleanTeeth(nparams,tokens,params);
return RiLastError;
error:
MLClearError(stdlink); MLFlush(stdlink);