HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_IORib.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Geometry Conversion Utility Library (C++)
7  *
8  * COMMENTS:
9  * Save a gdp to RIB. This is not able to load or convert any files.
10  *
11  */
12 
13 #ifndef __GEO_IORib_h__
14 #define __GEO_IORib_h__
15 
16 #include "GEO_API.h"
17 #include "GEO_IOTranslator.h"
18 #include "GEO_IORibExt.h"
19 
20 #include <UT/UT_BitArray.h>
21 #include <UT/UT_IntArray.h>
22 #include <UT/UT_Array.h>
23 #include <GA/GA_AttributeRef.h>
24 #include <UT/UT_VectorTypes.h>
25 #include <TS/TS_Expression.h>
26 #include <iosfwd>
27 
28 class GEO_Detail;
29 class GEO_Primitive;
30 class GEO_PrimPoly;
31 class GEO_Vertex;
32 class GEO_IORibXlate;
33 class GEO_IORibPrinter;
34 class GEO_PrimParticle;
35 class GA_PrimitiveGroup;
36 
37 #define GEO_RIB_MAX_SEGMENTS 5
38 
40 {
41 public:
42  GEO_IORib();
43  ~GEO_IORib() override;
44 
45  /// This method is used to create a copy of the sub-class
46  GEO_IOTranslator *duplicate() const override;
47 
48  const char *formatName() const override;
49 
50  int checkExtension(const char *name) override;
51  int checkMagicNumber(unsigned magic) override;
52 
54  std::ostream &) override;
56 
57  // This method does not duplicate the geometry, make sure it's stays
58  // around while fileSave is called!
59  void setMBGeo(const GEO_Detail *gdp) { myGdps[1] = gdp; }
60  // Add gdp's in sequence
61  void addMBGeo(const GEO_Detail *gdp);
62  void setMBParticle(int onoff) { myBlurParticle = onoff; }
64  {
65  myOutPrimGroup = grp;
66  }
67 
68  //
69  // Setting the version of the renderer turns on extensions to the RIB
70  // stream. These extensions are defined in GEO_IORibExt.h. The different
71  // renderers we expect to see are:
72  // "rdc" - RenderDotC (Support Version 3.1)
73  // "bmrt" - BMRT (No extensions supported)
74  // "prman" - Pixar's RenderMan (Support Version 3.6 to 10.0)
75  //
76  void setVersion(const char *renderer,
77  int major=3, int minor=6)
78  {
79  myExtensions.setRenderer(renderer, major, minor);
80  }
81  // GEO_IO is being used for IFDs. If it's not flagged as being used for
82  // IFD's, shading interpolation will be set on and the normal attribute
83  // will be declared.
84  void setForIFD(int onoff=1) { myIFDFlag = onoff; }
85 
86  void setCurveBasis(const char *basis);
87  void setPolySubdivide(int on);
88  void setPoints(int on, float size=1);
89 
90  // The shutter speed is used for particle blur.
91  void setShutterSpeed(float shutter=1)
92  {
93  myShutterTime = shutter;
94  }
95 
96  // The following are public, but shouldn't really be called unless
97  // you really know what you're doing...
98  static void outputQuadricAttributes(GEO_IORibPrinter &,
99  const GEO_Primitive *, GA_Size vtx,
100  int dup = 4, float pscale = 1);
101  // This returns 1 if the "width" parameter was found, 0 if not.
102  static int outputParticleAttributes(GEO_IORibPrinter &out,
103  const GEO_PrimParticle *part,
104  float pscale=1, int dup=1,
105  int allow_N=0);
106 
107 private:
108  int isBlurred() const { return myGdps[1] != 0; }
109  int hasExtension(int ext)
110  {
111  return myExtensions.hasExtension(ext);
112  }
113 
114  const GEO_Detail *myGdps[GEO_RIB_MAX_SEGMENTS];
115  int mySegments;
116  GA_ROHandleV3 ptVel; // Point velocity
117  int myBlurParticle; // Motion blur particles
118 
119  unsigned myGeoFlag; // For geometry interpretation
120  float myPointSize; // Size for RiPoints()
121  float myShutterTime;
122 
123  const GA_PrimitiveGroup *myOutPrimGroup; // Motion blur gdp
124 
125 #if 0
126  int myParticleIndex;
127  UT_Array<GEO_Detail*> *myParticleDetails;
128  UT_Array<GEO_Detail*> *myParticleMBDetails;
129 #endif
130 
131  void outputPolysAttrib(GEO_IORibPrinter &, const GEO_Detail *,
132  const UT_BitArray &, const GEO_IORibXlate *,
133  const UT_IntArray *group);
134  void outputBlobbyAttrib(GEO_IORibPrinter &, const GEO_Detail *,
135  const GEO_IORibXlate *,
137  void outputCurvesAttrib(GEO_IORibPrinter &, const GEO_Detail *,
138  const GEO_IORibXlate *,
139  const char *curve_interp,
140  int curve_step);
141 
142  void outputParticleLinePosition(GEO_IORibPrinter &out,
143  const GEO_PrimParticle *part,
144  const GA_ROHandleV3 &vel,
145  float vscale);
146  void outputMatrix (GEO_IORibPrinter &out, const UT_Matrix4 &xform);
147  void outputBlobbies(GEO_IORibPrinter &out, int nblobs,
148  const GEO_Detail *gdp);
149  int outputPolys(GEO_IORibPrinter &out, const GEO_Detail *gdp);
150  void outputSubDivs(GEO_IORibPrinter &out);
151  void outputSubDivGroup(GEO_IORibPrinter &out,
152  const GEO_Detail *gdp,
153  UT_IntArray &group, // may be modified !
154  bool first_time);
155  int outputPolyCurves(GEO_IORibPrinter &out, const GEO_Detail *gdp,
156  const char *curve_interp, int curve_step);
157  void outputNURBSCurves(GEO_IORibPrinter &out, const GEO_Detail *gdp);
158  void outputMesh (GEO_IORibPrinter &out, const GEO_Primitive *prim);
159  void outputNURBS (GEO_IORibPrinter &out, const GEO_Primitive *prim);
160  void outputBezier (GEO_IORibPrinter &out, const GEO_Primitive *prim);
161  void outputSphere (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
162  void outputTube (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
163  void outputCircle (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
164  void outputPoints (GEO_IORibPrinter &out, const GEO_Detail *gdp);
165  void outputParticles(GEO_IORibPrinter &out,
166  const GEO_Primitive *prim);
167  void outputParticlePoints(GEO_IORibPrinter &out,
168  const GEO_PrimParticle *part,
169  const GA_ROHandleV3 &vel,
170  float vscale, float pscale);
171  void outputParticleLines(GEO_IORibPrinter &out,
172  const GEO_PrimParticle *part,
173  float pscale);
174 
175  int isOutputPrim( const GEO_Primitive *prim );
176 
177 
178  static void outputExpressionBlobbies(GEO_IORibPrinter &out,
179  const TS_MetaExpressionPtr &expr,
180  int &floatAddr, int &exprNum);
181 
182  GEO_IORibExt myExtensions;
183  UT_Array<GEO_IORibXlate *> myTranslators;
184 
185  int myIFDFlag;
186 };
187 
188 // A wrapper class that implements buffered C-style output.
190 {
191 public:
192  GEO_IORibPrinter(std::ostream &os);
193  ~GEO_IORibPrinter();
194 
195  void print(const char *fmt, ...);
196  void print(const UT_Matrix4 &mat);
197 
198  std::ostream &getStream();
199  void flush();
200 private:
201  static const int theBufferSize;
202  static const int theBlockSize;
203 
204  std::ostream &myStream;
205  unsigned mySize;
206  unsigned myLineLen;
207  char *myFreeStart;
208  char *myFileBuffer;
209 };
210 
211 
212 #endif
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
virtual GEO_IOTranslator * duplicate() const =0
This method is used to create a copy of the sub-class.
virtual GA_Detail::IOStatus fileLoad(GEO_Detail *gdp, UT_IStream &is, bool ate_magic)=0
void setVersion(const char *renderer, int major=3, int minor=6)
Definition: GEO_IORib.h:76
#define GEO_API
Definition: GEO_API.h:14
#define GEO_RIB_MAX_SEGMENTS
Definition: GEO_IORib.h:37
GLuint const GLchar * name
Definition: glcorearb.h:786
void setShutterSpeed(float shutter=1)
Definition: GEO_IORib.h:91
GLsizeiptr size
Definition: glcorearb.h:664
virtual const char * formatName() const =0
void setForIFD(int onoff=1)
Definition: GEO_IORib.h:84
virtual int checkExtension(const char *name)=0
GA_API const UT_StringHolder pscale
void setMBParticle(int onoff)
Definition: GEO_IORib.h:62
virtual int checkMagicNumber(unsigned magic)=0
void setMBGeo(const GEO_Detail *gdp)
Definition: GEO_IORib.h:59
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
virtual GA_Detail::IOStatus fileSave(const GEO_Detail *gdp, std::ostream &os)=0
void setOutputPrimGroup(const GA_PrimitiveGroup *grp)
Definition: GEO_IORib.h:63