00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00011 00016 #ifndef BBINFILETKHEADER 00017 #define BBINFILETKHEADER 00018 00019 #ifndef _MSC_VER 00020 #define __wchar_t wchar_t 00021 #endif 00022 00023 #ifdef __ia64 00024 #ifndef __HP_aCC 00025 #error C++ compiler required 00026 #endif 00027 #else 00028 #ifndef __cplusplus 00029 #error C++ compiler required 00030 #endif 00031 #endif 00032 00037 #if defined(_MSC_VER) && !defined(BSTREAM_STATIC_LIB) 00038 #ifdef BBINFILETK_EXPORTS 00039 #define BBINFILETK_API2 __declspec (dllexport) 00040 #else 00041 #define BBINFILETK_API2 __declspec (dllimport) 00042 #endif 00043 #endif 00044 00045 #if defined(LINUX_SYSTEM) && !defined(BSTREAM_STATIC_LIB) 00046 #ifdef BBINFILETK_EXPORTS 00047 #define BBINFILETK_API2 __attribute__ ((visibility ("default"))) 00048 #else 00049 #define BBINFILETK_API2 00050 #endif 00051 #endif 00052 00053 #ifndef BBINFILETK_API2 00054 #define BBINFILETK_API2 00055 #endif 00056 00060 #ifdef TEST_RIG_1 00061 #define BBINFILETK_API 00062 #else 00063 #define BBINFILETK_API BBINFILETK_API2 00064 #endif 00065 00066 00070 #define TK_File_Format_Version 2010 // 20.10 00071 00073 // but are mentioned in the spec as test points for format changes) 00074 #ifdef CREATE_FILE_FORMAT_HISTORY_TABLE 00075 BBINFILETK_API int TK_File_Format_History[] = { 00076 // Format Release Notes 00077 //------------------------------------------------------------------------------------------ 00078 // 2010 // complex clip region 00079 2005, // selection culling, handling for max distance and view volume culling 00080 2000, // depth peeling algorithm 00081 1980, // 1980 initial 20 release 00082 // 1975 // double precision 00083 // 1950 // text font layout 00084 1910, // mask transform "offset" 00085 1905, // object space clip region 00086 1900, // 1900 00087 // 1840 // text region fitting 00088 // 1835 // png and texture source dimensions 00089 // 1830 // texture camera 00090 // 1825 // conditional actions 00091 // 1820 // separate edge join cutoff 00092 // 1815 // named styles 00093 // 1810 // material shaders 00094 // 1805 // compressed images directly supported in graphics system (jpeg, targa, dxt, luminance8) 00095 1800, // 1800 00096 // 1790 // hlr transparency cutoff 00097 // 1785 // contour and isoline options, diffuse texture tint, diffuse color tint 00098 // 1780 // new indexed user data 00099 // 1775 // new text alignment format, explicit patterns 00100 // 1770 // text character color & horizontal offset, vertex displacement, hlr render text, max extent level 00101 // 1765 // force defer, vertex decimation, model type 00102 // 1760 // transparency depth writing 00103 // 1755 // rgba vertex colors 00104 // 1750 // hard extent culling 00105 1715, // 17.1 vertex displacement backport 00106 1710, // ignore subsegment locks 00107 1700, // 1700 00108 // 1660 // camera relative lights 00109 // 1655 // reflection visibility 00110 // 1650 // ambient up vector, separate ambient colors, gooch options, marker index interpolation 00111 1615, // anti-alias 00112 1610, // 1610 00113 // 1605 // infinite ray, zsort options, geometry options 00114 1600, // 1600 00115 // 1555 // fix to some color types 00116 // 1550 // colors can now have Geo_Extended2, shadow map/simple reflection rendering options 00117 // 1520 // geometry reference 00118 // 1515 // shadow map options, selection level, display list levels, simple reflection, infinite line opcode 00119 // 1510 // maximum extent mode 00120 // 1505 // screen range, depth images 00121 1500, // 1500 00122 // 1415 // obscuration use octree 00123 // 1410 // simple shadow opacity, anisotropic texture filter 00124 // 1405 // join cutoff angle, ordered drawing heuristics 00125 1401, // 1410 internal polyline selection limit 00126 1400, // 1400 00127 // 1345 // string format color maps 00128 // 1340 // rgba image compression 00129 // 1335 // general displacement 00130 // 1330 // priority 00131 // 1325 // text greeking mode, extended text renderer & text preference 00132 // 1320 // Heuristic_Detail_Selection, nonculled edge visibility 00133 // 1315 // distance threshold LOD option, new fallback type "bounding none" 00134 // 1310 // depth peeling 00135 // 1305 // cutting section, adjacent edge visibility, force grayscale 00136 1300, // 1300 00137 // 1220 // font bold/italic/renderer, cut geometry color locks 00138 // 1215 // circular center 00139 // 1210 // geometry-level attributes, text character attributes, unicode32, image tint 00140 // 1205 // obscuration pixel threshold, subpixel culling, hard edge angle 00141 1200, // 1200 00142 // 1175 // explicit parameter width, uncompressed parameters 00143 // 1170 // camera relative lights, simple shadow mode 00144 // 1165 // extended texture definitions 00145 // 1160 // glyph definitions & line styles 00146 // 1155 // spheres, texture downsamping, compressed dictionary, image reference 00147 // 1150 // conditions, new hlr options (color, weight) 00148 1105, // additional polyhedron attributes 00149 1100, // 1100 00150 // 1002 // simple shadow options, text region 00151 // 1001 // camera near_limit, mask transform, image size/scale, new texture options 00152 1000, // 1000 00153 // 908 // threshold type in LOD options 00154 // 907 // polar normals 00155 // 906 // edgebreaker changes 00156 // 905 // hlr silhouette cleanup, unicode_options 00157 900, // 900 00158 // 806 // bounding box inheritance, cut geometry options, fast hidden line, 00159 // hidden line render faces, depth range, gradient window patterns, 00160 // additional NURBS surface controls 00161 // 805 // polycylinder attributes, ExRef, URL 00162 800, // 800 00163 710, // 760 new transparency controls, dictionary format 2 00164 // 705, // PolyCylinder, Extended Heuristics, XML, LoD collections, Shell Regions 00165 // 702, // PolyPolypoint 00166 700, // 700 00167 // 652, // null shell 00168 651, // 661 00169 // 650, // NURBS Surface, Cylinder, Extended Rendering_Options, Defined Fonts, Selectability 00170 // extensive polyhedron data & compression changes 00171 // 610, // View 00172 // 600, // Stream version generally synched to Hoops version 00173 // 601, // support longer text string 00174 105, // 600 Generate_Dictionary changed to Suppress_Dictionary 00175 100, // 500 Initial release 00176 0 // [list termination] 00177 }; 00178 #else 00179 extern BBINFILETK_API int TK_File_Format_History[]; 00180 #endif 00181 00182 00183 #define TK_DEFAULT_BUFFER_SIZE 32768 //!< default amount of the internal memory buffer used for file processing 00184 00185 00186 00187 #ifdef HSTREAM_READONLY 00188 #ifndef BSTREAM_READONLY 00189 #define BSTREAM_READONLY 00190 #endif 00191 #endif 00192 #ifdef BSTREAM_READONLY 00193 extern char const stream_readonly[]; 00194 #endif 00195 #ifdef BSTREAM_DISABLE_QUANTIZATION 00196 extern char const stream_disable_quantization[]; 00197 #endif 00198 #ifdef BSTREAM_DISABLE_EDGEBREAKER 00199 extern char const stream_disable_edgebreaker[]; 00200 #endif 00201 #ifdef BSTREAM_DISABLE_REPULSE_COMPRESSION 00202 extern char const stream_disable_repulse_compression[]; 00203 #endif 00204 #ifdef BSTREAM_DISABLE_ASCII 00205 extern char const stream_disable_ascii[]; 00206 #endif 00207 00208 00209 #include <math.h> 00210 #include <string.h> 00211 #include <stdio.h> 00212 00213 #ifdef NEED_BOOL_TYPE 00214 #undef NEED_BOOL_TYPE 00215 typedef int bool; 00216 00217 const bool true = !0; 00218 const bool false = 0; 00219 #endif 00220 00221 00226 #if defined(WIN64) || defined(_WIN64) 00227 # define ID_Key __int64 00228 #else 00229 # define ID_Key long 00230 #endif 00231 00232 00233 00234 #ifndef alter 00235 # define alter //!< complementary to const, indicates we thought about it instead of a forgotten "const" 00236 #endif 00237 00238 00239 #ifndef HPS_CORE_BUILD 00240 template <typename T> void Swap (T & a, T & b) { T tmp = a; a = b; b = tmp; } 00241 #endif 00242 00243 00248 00249 00253 enum TK_Status { 00254 TK_Normal = 0, 00255 TK_Error = 1, 00256 TK_Pause = 2, 00257 TK_Single = 3, 00258 TK_Pending = 4, 00259 TK_Revisit = 5, 00260 TK_Complete = 6, 00261 TK_Version = 7, 00262 TK_NotFound = 8, 00263 TK_Abort = 9, 00264 TK_LibraryNotFound = 10 00265 }; 00269 00270 00276 enum TK_File_Write_Options { 00277 TK_Suppress_LOD = 0x00000002, 00278 TK_Full_Resolution_Vertices = 0x00000004, 00279 TK_Full_Resolution_Normals = 0x00000008, 00280 TK_First_LOD_Is_Bounding_Box = 0x00000010, 00281 TK_Force_Tags = 0x00000020, 00282 TK_Disable_Priority_Heuristic = 0x00000040, 00283 TK_Disable_Global_Compression = 0x00000100, 00284 TK_Disable_Instancing = 0x00000200, 00285 TK_Generate_Dictionary = 0x00000400, 00286 TK_Connectivity_Compression = 0x00000800, 00287 TK_Disable_Tristrips = 0x00001000, 00288 TK_Disable_Compound_Primitives = 0x00002000, 00289 TK_Global_Quantization = 0x00004000, 00290 TK_Full_Resolution_Parameters = 0x00008000, 00291 TK_Full_Resolution_Colors = 0x00010000, 00292 TK_Full_Resolution_Index_Colors= 0x00020000, 00293 TK_Communicator_Mode = 0x00040000, 00294 TK_Full_Resolution = (TK_Full_Resolution_Vertices|TK_Full_Resolution_Normals|TK_Full_Resolution_Parameters|TK_Full_Resolution_Colors|TK_Full_Resolution_Index_Colors) 00295 }; 00296 00297 00301 enum TK_Dictionary_Options { 00302 TK_Dictionary_Bounding_Volumes = 0x00000001 00303 }; 00304 00305 00309 enum TK_File_Read_Options { 00310 TK_Flag_Unhandled_Opcodes = 0x00000001, 00311 TK_Ignore_Version = 0x00000002, 00312 TK_Skip_External_References = 0x00000004, 00313 TK_Ignore_Bounding_LODs = 0x00000008, 00314 TK_Disable_Deferal = 0x00000010 00315 }; 00316 00320 enum TK_Debug_Logging_Options { 00321 TK_Logging_Sequence = 0x00000001, 00322 TK_Logging_Tagging = 0x00000002, 00323 TK_Logging_Segment_Names = 0x00000004 00324 }; 00325 00326 00330 enum TK_General_Flags { 00331 // for Geometryoes and some attributes 00332 TK_Double_Precision = 0x01, 00333 00334 // for includes and styles 00335 TK_Has_Condition = 0x01, 00336 TK_Has_Filter = 0x02 00337 }; 00338 00339 00340 #include "BOpcodeHandler.h" 00341 #include "BStreamFileToolkit.h" 00342 00348 00349 00359 #ifndef SWIG 00360 TK_Status BBINFILETK_API TK_Read_Stream_File (char const * filename, BStreamFileToolkit * tk); 00361 #endif 00362 00364 00373 #ifndef SWIG 00374 TK_Status BBINFILETK_API TK_Read_Stream_File (char const * filename, int flags = 0); 00375 #endif 00376 00377 00378 00379 00381 TK_Status BBINFILETK_API TK_Read_Stream_File (__wchar_t const * filename, BStreamFileToolkit * tk); 00382 #ifdef _MSC_VER 00383 TK_Status BBINFILETK_API TK_Read_Stream_File (unsigned short const * filename, BStreamFileToolkit * tk); 00384 #endif 00385 00387 TK_Status BBINFILETK_API TK_Read_Stream_File (__wchar_t const * filename, int flags = 0); 00388 #ifdef _MSC_VER 00389 TK_Status BBINFILETK_API TK_Read_Stream_File (unsigned short const * filename, int flags = 0); 00390 #endif 00391 00392 00394 00401 #ifndef SWIG 00402 TK_Status BBINFILETK_API TK_Read_Stream_File (char const * filename, int flags, BStreamFileToolkit * tk); 00403 #endif 00404 00406 #endif 00407