1 #ifndef __LDRAWMODELVIEWER_H__ 2 #define __LDRAWMODELVIEWER_H__ 3 4 #include <TCFoundation/TCAlertSender.h> 5 #include <TCFoundation/TCStringArray.h> 6 #include <TCFoundation/mystring.h> 7 #include <TCFoundation/TCStlIncludes.h> 8 #include <TCFoundation/TCTypedObjectArray.h> 9 #include <LDLoader/LDLCamera.h> 10 #include <TRE/TREGL.h> 11 #include <LDExporter/LDExporter.h> 12 #ifdef USE_CPP11 13 #define USE_STD_CHRONO 14 #include <chrono> 15 #endif // USE_CPP11 16 #ifndef USE_STD_CHRONO 17 #ifdef _QT 18 #include <QtCore/qdatetime.h> 19 #endif 20 #endif // !USE_STD_CHRONO 21 22 typedef enum 23 { 24 LDVStereoNone, 25 LDVStereoHardware, 26 LDVStereoCrossEyed, 27 LDVStereoParallel 28 } LDVStereoMode; 29 30 typedef enum 31 { 32 LDVCutawayNormal, 33 LDVCutawayWireframe, 34 LDVCutawayStencil 35 } LDVCutawayMode; 36 37 typedef enum 38 { 39 LDVAngleDefault, 40 LDVAngleFront, 41 LDVAngleBack, 42 LDVAngleLeft, 43 LDVAngleRight, 44 LDVAngleTop, 45 LDVAngleBottom, 46 LDVAngleIso, 47 } LDVAngle; 48 49 typedef enum 50 { 51 LDVMouseNone, 52 LDVMouseNormal, 53 LDVMouseZoom, 54 LDVMousePan, 55 LDVMouseLight 56 } LDVMouseMode; 57 58 typedef enum 59 { 60 LDVLookAtNone, 61 LDVLookAtModel, 62 LDVLookAtOrigin, 63 } LDVLookAt; 64 65 class TCImage; 66 class LDLError; 67 class TCProgressAlert; 68 class TREMainModel; 69 class LDLMainModel; 70 class LDLModel; 71 class LDLFileLine; 72 class LDLFindFileAlert; 73 class TCWebClient; 74 class LDPreferences; 75 class LDPartsList; 76 class LDViewPoint; 77 class LDInputHandler; 78 class LDLFileLine; 79 typedef TCTypedObjectArray<LDLFileLine> LDLFileLineArray; 80 81 class LDrawModelViewer: public TCAlertSender 82 { 83 public: 84 enum ViewMode 85 { 86 VMExamine, 87 VMFlyThrough, 88 VMWalk, 89 }; 90 enum ExamineMode 91 { 92 EMFree, 93 EMLatLong, 94 }; 95 enum ExportType 96 { 97 ETFirst = 1, 98 ETPov = ETFirst, 99 #ifdef EXPORT_LDR 100 ETLdr, 101 #endif // EXPORT_LDR 102 ETStl, 103 #ifdef EXPORT_3DS 104 ET3ds, 105 ETLast = ET3ds 106 #else // EXPORT_3DS 107 ETLast = ETStl 108 #endif // EXPORT_3DS 109 }; 110 struct StandardSize 111 { 112 int width; 113 int height; 114 ucstring name; 115 }; 116 typedef std::list<StandardSize> StandardSizeList; 117 typedef std::vector<StandardSize> StandardSizeVector; 118 119 LDrawModelViewer(TCFloat, TCFloat); 120 LDInputHandler *getInputHandler(void); 121 virtual void update(void); 122 virtual void perspectiveView(void); 123 virtual void perspectiveView(bool resetViewport); setLDConfig(const std::string & value)124 void setLDConfig(const std::string& value) { m_ldConfig = value; } getLDConfig(void)125 const std::string& getLDConfig(void) const { return m_ldConfig; } setAppVersion(const std::string & value)126 static void setAppVersion(const std::string& value) 127 { 128 sm_appVersion = value; 129 } getAppVersion(void)130 static const std::string& getAppVersion(void) 131 { 132 return sm_appVersion; 133 } setAppCopyright(const std::string & value)134 static void setAppCopyright(const std::string& value) 135 { 136 sm_appCopyright = value; 137 } getAppCopyright(void)138 static const std::string& getAppCopyright(void) 139 { 140 return sm_appCopyright; 141 } setQualityLighting(bool value)142 void setQualityLighting(bool value) { flags.qualityLighting = value; } getQualityLighting(void)143 bool getQualityLighting(void) const 144 { 145 return flags.qualityLighting != false; 146 } 147 virtual void setSubduedLighting(bool value); getSubduedLighting(void)148 bool getSubduedLighting(void) const 149 { 150 return flags.subduedLighting != false; 151 } 152 virtual void setShowsHighlightLines(bool value); getShowsHighlightLines(void)153 bool getShowsHighlightLines(void) const 154 { 155 return flags.showsHighlightLines != false; 156 } 157 virtual void setDrawConditionalHighlights(bool value); getDrawConditionalHighlights(void)158 bool getDrawConditionalHighlights(void) const 159 { 160 return flags.drawConditionalHighlights != false; 161 } 162 virtual void setPerformSmoothing(bool value); getPerformSmoothing(void)163 bool getPerformSmoothing(void) const 164 { 165 return flags.performSmoothing != false; 166 } setConstrainZoom(bool value)167 void setConstrainZoom(bool value) { flags.constrainZoom = value; } getConstrainZoom(void)168 bool getConstrainZoom(void) const 169 { 170 return flags.constrainZoom != false; 171 } 172 virtual void setLineSmoothing(bool value); getLineSmoothing(void)173 bool getLineSmoothing(void) const 174 { 175 return flags.lineSmoothing != false; 176 } 177 virtual void setMemoryUsage(int value); getMemoryUsage(void)178 int getMemoryUsage(void) const { return memoryUsage; } 179 virtual void setQualityStuds(bool value); getQualityStuds(void)180 bool getQualityStuds(void) const 181 { 182 return flags.qualityStuds != false; 183 } 184 virtual void setAllowPrimitiveSubstitution(bool value); getAllowPrimitiveSubstitution(void)185 bool getAllowPrimitiveSubstitution(void) const 186 { 187 return flags.allowPrimitiveSubstitution != false; 188 } setUsesFlatShading(bool value)189 void setUsesFlatShading(bool value) { flags.usesFlatShading = value; } getUsesFlatShading(void)190 bool getUsesFlatShading(void) const 191 { 192 return flags.usesFlatShading != false; 193 } 194 TCVector getCameraLocation(void); 195 void setCameraLocation(const TCVector& newLocation, LDVLookAt lookAt, 196 bool shouldRequestRedraw = true); 197 void setObi(bool value); getObi(void)198 bool getObi(void) const { return flags.obi != false; } 199 void setGl2ps(bool value); getGl2ps(void)200 bool getGl2ps(void) const { return flags.gl2ps; } 201 virtual void setUsesSpecular(bool value); getUsesSpecular(void)202 bool getUsesSpecular(void) const { return flags.usesSpecular != false; } 203 virtual void setOneLight(bool value); getOneLight(void)204 bool getOneLight(void) const { return flags.oneLight != false; } 205 virtual bool forceOneLight(void) const; 206 virtual void setWidth(TCFloat value); 207 virtual void setHeight(TCFloat value); getWidth(void)208 int getWidth(void) const { return (int)width; } getHeight(void)209 int getHeight(void) const { return (int)height; } getRotationCenter(void)210 const TCVector& getRotationCenter(void) const { return center; } 211 void setRotationCenter(const TCVector& value); 212 void resetRotationCenter(void); getFloatWidth(void)213 TCFloat getFloatWidth(void) const { return width; } getFloatHeight(void)214 TCFloat getFloatHeight(void) const { return height; } 215 virtual void setScaleFactor(TCFloat value); getScaleFactor(void)216 TCFloat getScaleFactor(void) const { return scaleFactor; } scale(int value)217 int scale(int value) const { return (int)(scaleFactor * value); } scale(TCFloat value)218 TCFloat scale(TCFloat value) const { return (TCFloat)(scaleFactor * value); } 219 void setViewMode(ViewMode value); getViewMode(void)220 ViewMode getViewMode(void) const { return viewMode; } 221 void setExamineMode(ExamineMode value); getExamineMode(void)222 ExamineMode getExamineMode(void) const { return examineMode; } setXRotate(TCFloat value)223 void setXRotate(TCFloat value) { xRotate = value; } setYRotate(TCFloat value)224 void setYRotate(TCFloat value) { yRotate = value; } setZRotate(TCFloat value)225 void setZRotate(TCFloat value) { zRotate = value; } getXRotate(void)226 TCFloat getXRotate(void) { return xRotate; } getYRotate(void)227 TCFloat getYRotate(void) { return yRotate; } getZRotate(void)228 TCFloat getZRotate(void) { return zRotate; } 229 void panXY(int xValue, int yValue); getXPan(void)230 TCFloat getXPan(void) { return xPan; } getYPan(void)231 TCFloat getYPan(void) { return yPan; } 232 void setXYPan(TCFloat xValue, TCFloat yValue); 233 void setRotationSpeed(TCFloat value); getRotationSpeed(void)234 TCFloat getRotationSpeed(void) const { return rotationSpeed; } 235 void setCameraXRotate(TCFloat value); 236 void setCameraYRotate(TCFloat value); 237 void setCameraZRotate(TCFloat value); getCameraXRotate(void)238 TCFloat getCameraXRotate(void) { return cameraXRotate; } getCameraYRotate(void)239 TCFloat getCameraYRotate(void) { return cameraYRotate; } getCameraZRotate(void)240 TCFloat getCameraZRotate(void) { return cameraZRotate; } 241 void setCameraMotion(const TCVector &value); getCameraMotion(void)242 TCVector getCameraMotion(void) { return cameraMotion; } 243 virtual void setZoomSpeed(TCFloat value); getZoomSpeed(void)244 TCFloat getZoomSpeed(void) { return zoomSpeed; } 245 virtual void zoom(TCFloat amount, bool apply = true); 246 virtual void updateCameraPosition(void); 247 virtual void applyZoom(void); setClipZoom(bool value)248 void setClipZoom(bool value) { clipZoom = value; } getClipZoom(void)249 bool getClipZoom(void) const { return clipZoom != false; } 250 virtual void setFilename(const char*); 251 virtual void setProgramPath(const char *value); 252 void setFileIsPart(bool); getFileIsPart(void)253 bool getFileIsPart(void) const { return flags.fileIsPart != false; } getFilename(void)254 char* getFilename(void) { return filename; } getFilename(void)255 const char *getFilename(void) const { return filename; } 256 std::string getCurFilename(void) const; getHighlightPaths(void)257 const StringList &getHighlightPaths(void) const 258 { 259 return highlightPaths; 260 } 261 void setHighlightPaths(std::string value); 262 void setHighlightPaths(const StringList &value); 263 void setHighlightColor(int r, int g, int b, bool redraw = true); 264 virtual int loadModel(bool = true); 265 virtual void drawFPS(TCFloat); 266 virtual void drawBoundingBox(void); 267 virtual void setup(void); 268 virtual void setBackgroundRGB(int r, int g, int b); 269 virtual void setBackgroundRGBA(int r, int g, int b, int a); getBackgroundR(void)270 int getBackgroundR(void) { return (int)(backgroundR * 255); } getBackgroundG(void)271 int getBackgroundG(void) { return (int)(backgroundG * 255); } getBackgroundB(void)272 int getBackgroundB(void) { return (int)(backgroundB * 255); } getBackgroundA(void)273 int getBackgroundA(void) { return (int)(backgroundA * 255); } 274 virtual void setDefaultRGB(TCByte r, TCByte g, TCByte b, 275 bool transparent); 276 virtual void getDefaultRGB(TCByte &r, TCByte &g, TCByte &b, 277 bool &transparent) const; 278 virtual void setDefaultColorNumber(int value); getDefaultColorNumber(void)279 int getDefaultColorNumber(void) const { return defaultColorNumber; } 280 virtual void setSeamWidth(TCFloat); getSeamWidth(void)281 TCFloat getSeamWidth(void) const { return seamWidth; } 282 virtual void setDrawWireframe(bool); getDrawWireframe(void)283 bool getDrawWireframe(void) const 284 { 285 return flags.drawWireframe != false; 286 } 287 virtual void setBfc(bool value); getBfc(void)288 bool getBfc(void) const { return flags.bfc != false; } 289 virtual void setRedBackFaces(bool value); getRedBackFaces(void)290 bool getRedBackFaces(void) const { return flags.redBackFaces != false; } 291 virtual void setGreenFrontFaces(bool value); getGreenFrontFaces(void)292 bool getGreenFrontFaces(void) const 293 { 294 return flags.greenFrontFaces != false; 295 } 296 virtual void setBlueNeutralFaces(bool value); getBlueNeutralFaces(void)297 bool getBlueNeutralFaces(void) const 298 { 299 return flags.blueNeutralFaces != false; 300 } setCheckPartTracker(bool value)301 void setCheckPartTracker(bool value) { flags.checkPartTracker = value; } getCheckPartTracker(void)302 bool getCheckPartTracker(void) const 303 { 304 return flags.checkPartTracker != false; 305 } 306 void setDrawLightDats(bool value); getDrawLightDats(void)307 bool getDrawLightDats(void) const 308 { 309 return flags.drawLightDats != false; 310 } 311 void setOptionalStandardLight(bool value); getOptionalStandardLight(void)312 bool getOptionalStandardLight(void) const 313 { 314 return flags.optionalStandardLight != false; 315 } getNoLightGeom(void)316 bool getNoLightGeom(void) const { return flags.noLightGeom != false; } 317 void setNoLightGeom(bool value); getUpdating(void)318 bool getUpdating(void) const { return flags.updating != false; } setMissingPartWait(int value)319 void setMissingPartWait(int value) { missingPartWait = value; } getMissingPartWait(void)320 int getMissingPartWait(void) { return missingPartWait; } setUpdatedPartWait(int value)321 void setUpdatedPartWait(int value) { updatedPartWait = value; } getUpdatedPartWait(void)322 int getUpdatedPartWait(void) { return updatedPartWait; } 323 virtual void setUseWireframeFog(bool); getUseWireframeFog(void)324 bool getUseWireframeFog(void) const 325 { 326 return flags.useWireframeFog != false; 327 } 328 virtual void setRemoveHiddenLines(bool value); getRemoveHiddenLines(void)329 bool getRemoveHiddenLines(void) const 330 { 331 return flags.removeHiddenLines != false; 332 } 333 virtual void setEdgesOnly(bool value); getEdgesOnly(void)334 bool getEdgesOnly(void) const { return flags.edgesOnly != false; } 335 virtual void setHiResPrimitives(bool value); getHiResPrimitives(void)336 bool getHiResPrimitives(void) const 337 { 338 return flags.hiResPrimitives != false; 339 } 340 virtual void setUsePolygonOffset(bool); getUsePolygonOffset(void)341 bool getUsePolygonOffset(void) const 342 { 343 return flags.usePolygonOffset != false; 344 } 345 virtual void setUseLighting(bool); getUseLighting(void)346 bool getUseLighting(void) const { return flags.useLighting != false; } setCommandLineStep(int value)347 void setCommandLineStep(int value) { commandLineStep = value; } getShowLightDir(void)348 bool getShowLightDir(void) const { return flags.showLight != false; } 349 void setShowLightDir(bool value); 350 virtual void setUseStipple(bool); getUseStipple(void)351 bool getUseStipple(void) const { return flags.useStipple != false; } 352 virtual void setSortTransparent(bool); getSortTransparent(void)353 bool getSortTransparent(void) const 354 { 355 return flags.sortTransparent != false; 356 } 357 virtual void setHighlightLineWidth(TCFloat32 value); getHighlightLineWidth(void)358 TCFloat32 getHighlightLineWidth(void) const 359 { 360 return highlightLineWidth; 361 } 362 TCFloat32 getScaledHighlightLineWidth(void) const; 363 virtual void setWireframeLineWidth(TCFloat32 value); getWireframeLineWidth(void)364 TCFloat32 getWireframeLineWidth(void) const 365 { 366 return wireframeLineWidth; 367 } 368 TCFloat32 getScaledWireframeLineWidth(void) const; 369 virtual void setAnisoLevel(TCFloat32 value); getAnisoLevel(void)370 TCFloat32 getAnisoLevel(void) const { return anisoLevel; } 371 virtual void setProcessLDConfig(bool value); getProcessLDConfig(void)372 bool getProcessLDConfig(void) const 373 { 374 return flags.processLDConfig != false; 375 } 376 virtual void setSkipValidation(bool value); getSkipValidation(void)377 bool getSkipValidation(void) const 378 { 379 return flags.skipValidation != false; 380 } setAutoCenter(bool value)381 void setAutoCenter(bool value) { flags.autoCenter = value; } getAutoCenter(void)382 bool getAutoCenter(void) const { return flags.autoCenter != false; } 383 virtual void setForceZoomToFit(bool value); getForceZoomToFit(void)384 bool getForceZoomToFit(void) const 385 { 386 return flags.forceZoomToFit != false; 387 } 388 virtual void setSaveAlpha(bool value); getSaveAlpha(void)389 bool getSaveAlpha(void) const { return flags.saveAlpha != false; } 390 virtual void setMultiThreaded(bool value); getMultiThreaded(void)391 bool getMultiThreaded(void) const 392 { 393 return flags.multiThreaded != false; 394 } setShowAxes(bool value)395 virtual void setShowAxes(bool value) { flags.showAxes = value; } getShowAxes(void)396 bool getShowAxes(void) const { return flags.showAxes != false; } setAxesAtOrigin(bool value)397 virtual void setAxesAtOrigin(bool value) { flags.axesAtOrigin = value; } getAxesAtOrigin(void)398 bool getAxesAtOrigin(void) const { return flags.axesAtOrigin != false; } 399 virtual void setShowBoundingBox(bool value); getShowBoundingBox(void)400 bool getShowBoundingBox(void) const 401 { 402 return flags.showBoundingBox != false; 403 } 404 virtual void setBoundingBoxesOnly(bool value); getBoundingBoxesOnly(void)405 bool getBoundingBoxesOnly(void) const 406 { 407 return flags.boundingBoxesOnly != false; 408 } getBoundingMin(void)409 const TCVector &getBoundingMin(void) const { return boundingMin; } getBoundingMax(void)410 const TCVector &getBoundingMax(void) const { return boundingMax; } 411 virtual bool recompile(void); 412 virtual void uncompile(void); 413 virtual void reload(void); 414 virtual void reparse(void); 415 // virtual void setProgressCallback(LDMProgressCallback callback, 416 // void* userData); 417 // virtual void setErrorCallback(LDMErrorCallback callback, 418 // void* userData); 419 virtual void clear(void); 420 virtual void resetView(LDVAngle viewAngle = LDVAngleDefault); 421 virtual void setLatLon(float lat, float lon, float distance = -1.0); 422 virtual void pause(void); 423 virtual void unpause(void); getPaused(void)424 bool getPaused(void) const { return flags.paused != false; } 425 virtual void setXTile(int value); getXTile(void)426 int getXTile(void) { return xTile; } 427 virtual void setYTile(int value); getYTile(void)428 int getYTile(void) { return yTile; } 429 virtual void setNumXTiles(int value); getNumXTiles(void)430 int getNumXTiles(void) { return numXTiles; } 431 virtual void setNumYTiles(int value); getNumYTiles(void)432 int getNumYTiles(void) { return numYTiles; } 433 virtual void setStereoMode(LDVStereoMode mode); getStereoMode(void)434 LDVStereoMode getStereoMode(void) { return stereoMode; } setStereoEyeSpacing(TCFloat spacing)435 void setStereoEyeSpacing(TCFloat spacing) 436 { 437 stereoEyeSpacing = spacing; 438 } getStereoEyeSpacing(void)439 TCFloat getStereoEyeSpacing(void) { return stereoEyeSpacing; } 440 virtual void setCutawayMode(LDVCutawayMode mode); getCutawayMode(void)441 LDVCutawayMode getCutawayMode(void) { return cutawayMode; } 442 virtual void setCutawayAlpha(TCFloat32 value); getCutawayAlpha(void)443 TCFloat32 getCutawayAlpha(void) { return cutawayAlpha; } 444 virtual void setCutawayLineWidth(TCFloat32 value); getCutawayLineWidth(void)445 TCFloat32 getCutawayLineWidth(void) { return cutawayLineWidth; } 446 TCFloat32 getScaledCutawayLineWidth(void) const; setSlowClear(bool value)447 void setSlowClear(bool value) { flags.slowClear = value; } getSlowClear(void)448 bool getSlowClear(void) const { return flags.slowClear != false; } 449 virtual void setBlackHighlights(bool value); getBlackHighlights(void)450 bool getBlackHighlights(void) const 451 { 452 return flags.blackHighlights != false; 453 } setZoomMax(TCFloat value)454 void setZoomMax(TCFloat value) { zoomMax = value; } getZoomMax(void)455 TCFloat getZoomMax(void) { return zoomMax; } 456 virtual void setShowAllConditionalLines(bool value); getShowAllConditionalLines(void)457 bool getShowAllConditionalLines(void) const 458 { 459 return flags.showAllConditionalLines != false; 460 } 461 virtual void setShowConditionalControlPoints(bool value); getShowConditionalControlPoints(void)462 bool getShowConditionalControlPoints(void) const 463 { 464 return flags.showConditionalControlPoints != false; 465 } getNeedsReload(void)466 bool getNeedsReload(void) const { return flags.needsReload != false; } setNeedsReload(void)467 void setNeedsReload(void) { flags.needsReload = true; } getNeedsReparse(void)468 bool getNeedsReparse(void) const { return flags.needsReparse != false; } setNeedsReparse(void)469 void setNeedsReparse(void) { flags.needsReparse = true; } getNeedsRecompile(void)470 bool getNeedsRecompile(void) const 471 { 472 return flags.needsRecompile != false; 473 } setNeedsRecompile(void)474 void setNeedsRecompile(void) { flags.needsRecompile = true; } getNeedsCalcSize(void)475 bool getNeedsCalcSize(void) const 476 { 477 return flags.needsCalcSize != false; 478 } 479 void setCurveQuality(int value); getCurveQuality(void)480 int getCurveQuality(void) const { return curveQuality; } 481 void setTextureStuds(bool value); getTextureStuds(void)482 bool getTextureStuds(void) const { return flags.textureStuds != false; } 483 void setTextureFilterType(int value); getTextureFilterType(void)484 int getTextureFilterType(void) const { return textureFilterType; } getMainTREModel(void)485 TREMainModel *getMainTREModel(void) { return mainTREModel; } 486 void setMpdChildIndex(int index); getMpdChildIndex(void)487 int getMpdChildIndex(void) const { return mpdChildIndex; } 488 LDLModel *getMpdChild(void); 489 const LDLModel *getMpdChild(void) const; 490 LDLModel *getCurModel(void); 491 const LDLModel *getCurModel(void) const; getMainModel(void)492 LDLMainModel *getMainModel(void) { return mainModel; } getMainModel(void)493 const LDLMainModel *getMainModel(void) const { return mainModel; } 494 bool getCompiled(void) const; setPixelAspectRatio(TCFloat value)495 void setPixelAspectRatio(TCFloat value) { pixelAspectRatio = value; } getPixelAspectRatio(void)496 TCFloat getPixelAspectRatio(void) { return pixelAspectRatio; } 497 bool getLDrawCommandLineMatrix(char *matrixString, int bufferLength); 498 bool getLDrawCommandLine(char *shortFilename, char *commandString, 499 int bufferLength); 500 bool getLDGLiteCommandLine(char *commandString, int bufferLength); setDistanceMultiplier(TCFloat value)501 void setDistanceMultiplier(TCFloat value) 502 { 503 distanceMultiplier = value; 504 } getDistanceMultiplier(void)505 TCFloat getDistanceMultiplier(void) { return distanceMultiplier; } 506 virtual void clearBackground(void); 507 virtual void setFontData(TCByte *fontData, long length); 508 virtual void setModelCenter(const TCVector &value); 509 virtual void setModelSize(const TCFloat value); getNoUI(void)510 bool getNoUI(void) const { return flags.noUI ? true : false; } setNoUI(bool value)511 void setNoUI(bool value) { flags.noUI = value; } getKeepRightSideUp(void)512 bool getKeepRightSideUp(void) const 513 { 514 return flags.keepRightSideUp ? true : false; 515 } setKeepRightSideUp(bool value)516 void setKeepRightSideUp(bool value) { flags.keepRightSideUp = value; } getTexmaps(void)517 bool getTexmaps(void) const { return flags.texmaps ? true : false; } 518 void setTexmaps(bool value); getTexturesAfterTransparent(void)519 bool getTexturesAfterTransparent(void) const 520 { 521 return flags.texturesAfterTransparent ? true : false; 522 } 523 void setTexturesAfterTransparent(bool value); getTextureOffsetFactor(void)524 TCFloat getTextureOffsetFactor(void) const 525 { 526 return textureOffsetFactor; 527 } 528 void setTextureOffsetFactor(TCFloat value); getUseStrips(void)529 bool getUseStrips(void) const { return flags.useStrips ? true : false; } 530 void setUseStrips(bool value); getRandomColors(void)531 bool getRandomColors(void) const 532 { 533 return flags.randomColors ? true : false; 534 } 535 virtual void setRandomColors(bool value); getPovCameraAspect(void)536 bool getPovCameraAspect(void) const 537 { 538 return flags.povCameraAspect ? true : false; 539 } 540 virtual void setPovCameraAspect(bool value, bool saveSetting); 541 virtual void setDefaultRotationMatrix(const TCFloat *value); 542 virtual void setDefaultLatLong(TCFloat latitude, TCFloat longitude); getDefaultRotationMatrix(void)543 const TCFloat *getDefaultRotationMatrix(void) 544 { 545 return defaultRotationMatrix; 546 } getRotationMatrix(void)547 const TCFloat *getRotationMatrix(void) { return rotationMatrix; } getExamineLatitude(void)548 TCFloat getExamineLatitude(void) { return examineLatitude; } getExamineLongitude(void)549 TCFloat getExamineLongitude(void) { return examineLongitude; } 550 virtual void setFov(TCFloat value); getFov(void)551 TCFloat getFov(void) { return fov; } 552 TCFloat getHFov(void); 553 TCFloat getDistance(void) const; getDefaultDistance(void)554 TCFloat getDefaultDistance(void) const { return defaultDistance; } 555 void setDefaultDistance(TCFloat value); 556 void setExtraSearchDirs(TCStringArray *value); getExtraSearchDirs(void)557 TCStringArray *getExtraSearchDirs(void) { return extraSearchDirs; } 558 bool skipCameraPositioning(void); getCamera(void)559 virtual LDLCamera &getCamera(void) { return camera; } 560 virtual void zoomToFit(void); 561 virtual void openGlWillEnd(void); 562 virtual void setLightVector(const TCVector &value); getLightVector(void)563 TCVector getLightVector(void) { return lightVector; } 564 virtual void getPovCameraInfo(UCCHAR *&userMessage, char *&povCamera); setPreferences(LDPreferences * value)565 virtual void setPreferences(LDPreferences *value) 566 { 567 // Don't retain; it retains us. 568 preferences = value; 569 } 570 virtual LDPartsList *getPartsList(void); 571 LDViewPoint *saveViewPoint(void) const; 572 void restoreViewPoint(const LDViewPoint *viewPoint); 573 void rightSideUp(bool shouldRequestRedraw = true); 574 virtual void setupFont(const char *fontFilename); 575 virtual void setupFont2x(const char *fontFilename); 576 virtual void setRawFont2xData(const TCByte *data, long length); 577 virtual void setFont2x(TCImage *image); 578 virtual int exportCurModel(const char *filename, 579 const char *version = NULL, const char *copyright = NULL, 580 ExportType type = (ExportType)0); 581 virtual void setExportType(ExportType type, bool forceNew = false); 582 virtual LDExporter *getExporter(ExportType type = (ExportType)0, 583 bool forceNew = false); getExportType(void)584 virtual ExportType getExportType(void) const { return exportType; } 585 586 virtual bool mouseDown(LDVMouseMode mode, int x, int y); 587 virtual bool mouseUp(int x, int y); 588 virtual bool mouseMove(int x, int y); 589 virtual void showLight(void); 590 virtual void orthoView(void); 591 592 virtual void requestRedraw(void); 593 virtual void mouseMoveLight(int deltaX, int deltaY); 594 595 bool getViewInfo(ucstring &message, ucstring &commandLine); 596 TREMainModel *getContrastingLightDirModel(); getAlertSender(void)597 virtual TCObject *getAlertSender(void) { return this; } 598 599 void setStep(int value); getStep(void)600 int getStep(void) const { return step + 1; } 601 int getNumSteps(void) const; 602 603 void enable(GLenum cap); 604 void disable(GLenum cap); 605 void blendFunc(GLenum sfactor, GLenum dfactor); 606 void lineWidth(GLfloat width); 607 608 static UCSTR getOpenGLDriverInfo(int &numExtensions); 609 static void cleanupFloats(TCFloat *array, int count = 16); 610 static bool fileExists(const char *filename); alertClass(void)611 static const char *alertClass(void) { return "LDrawModelViewerAlert"; } redrawAlertClass(void)612 static const char *redrawAlertClass(void) { return "LDRedrawNeeded"; } frameDoneAlertClass(void)613 static const char *frameDoneAlertClass(void) { return "LDFrameDone"; } loadAlertClass(void)614 static const char *loadAlertClass(void) 615 { 616 return "LDrawModelViewerLoad"; 617 } 618 static void getStandardSizes(int maxWidth, int maxHeight, 619 StandardSizeVector &sizes); 620 static void resetUnofficialDownloadTimes(void); 621 // static bool doCommandLineExport(void); 622 protected: 623 ~LDrawModelViewer(void); 624 void dealloc(void); 625 // bool commandLineExport(void); 626 // ExportType exportTypeForFilename(const char* filename); 627 virtual void drawSetup(TCFloat eyeXOffset = 0.0f); 628 virtual void drawModel(TCFloat eyeXOffset = 0.0f); 629 virtual void innerDrawModel(void); 630 virtual void drawAxes(bool atOrigin); 631 virtual void removeHiddenLines(TCFloat eyeXOffset = 0.0f); 632 virtual void setFieldOfView(double, TCFloat, TCFloat); 633 virtual void setupRotationMatrix(void); 634 virtual void setupMaterial(void); 635 virtual void setupLight(GLenum light, 636 const TCVector &color = TCVector(1.0, 1.0, 1.0)); 637 void drawLight(GLenum, TCFloat, TCFloat, TCFloat); 638 virtual void setupLighting(void); 639 virtual void setupTextures(void); 640 void drawLights(void); 641 void drawLightDats(void); 642 virtual void drawToClipPlane(TCFloat eyeXOffset); 643 virtual void drawToClipPlaneUsingStencil(TCFloat eyeXOffset); 644 // virtual void drawToClipPlaneUsingAccum(TCFloat eyeXOffset); 645 virtual void drawToClipPlaneUsingDestinationAlpha(TCFloat eyeXOffset); 646 virtual void drawToClipPlaneUsingNoEffect(TCFloat eyeXOffset); 647 virtual void perspectiveViewToClipPlane(void); 648 virtual void applyTile(void); 649 virtual void drawString(TCFloat xPos, TCFloat yPos, char* string); 650 virtual void loadVGAFont(const char *fontFilename); 651 virtual void setupDefaultViewAngle(void); 652 virtual void setupFrontViewAngle(void); 653 virtual void setupBackViewAngle(void); 654 virtual void setupLeftViewAngle(void); 655 virtual void setupRightViewAngle(void); 656 virtual void setupTopViewAngle(void); 657 virtual void setupBottomViewAngle(void); 658 // void ldlErrorCallback(LDLError *error); 659 // void progressAlertCallback(TCProgressAlert *error); 660 virtual void setupIsoViewAngle(void); 661 virtual TCFloat calcDefaultDistance(void); 662 virtual void updateCurrentFov(void); 663 virtual TCFloat getStereoWidthModifier(void); 664 virtual TCFloat getWideLineMargin(void); 665 virtual TCFloat getClipRadius(void); 666 virtual TCFloat getZDistance(void); 667 virtual bool haveLightDats(void) const; 668 virtual bool haveStandardLight(void); 669 void findFileAlertCallback(LDLFindFileAlert *alert); 670 virtual bool canCheckForUnofficialPart(const char *filename, 671 bool exists); 672 virtual void unofficialPartNotFound(const char *filename); 673 virtual bool connectionFailure(TCWebClient *webClient); 674 virtual void applyModelRotation(void); 675 virtual bool loadLDLModel(void); 676 virtual bool calcSize(void); 677 virtual bool parseModel(void); 678 virtual void releaseTREModels(void); 679 virtual LDExporter *initExporter(void); 680 681 void updateFrameTime(bool force = false); 682 void highlightPathsChanged(void); 683 void parseHighlightPath(const std::string &path, 684 const LDLModel *srcModel, LDLModel *dstModel, 685 const std::string &prePath, int pathNum); 686 void resetColors(LDLFileLine *actionLine); 687 void resetColors(LDLModel *model); 688 void attachFileLine(LDLFileLine *dstFileLine, 689 LDLFileLineArray *dstFileLines, LDLModel *dstModel); 690 void attachLineLine(LDLFileLineArray *dstFileLines, LDLModel *dstModel, 691 const TCVector &pt0, const TCVector &pt1); 692 std::string adjustHighlightPath(std::string path, LDLModel *mpdChild); 693 std::string getModelKey(const std::string& keyName); 694 bool getRotationCenter(TCVector& rotationCenter); 695 void rotationCenterChanged(void); 696 697 static void fixLongitude(TCFloat &lon); 698 static void setUnofficialPartPrimitive(const char *filename, 699 bool primitive); 700 static void initStandardSizes(void); 701 static void addStandardSize(int width, int height, CUCSTR name = NULL); 702 static bool checkAspect(TCFloat width, TCFloat height, int aspectW, 703 int aspectH); 704 static ucstring getAspectString(TCFloat aWidth, TCFloat aHeight, 705 CUCSTR separator, bool standardOnly = false); 706 707 //int L3Solve6(TCFloat x[L3ORDERN], const TCFloat A[L3ORDERM][L3ORDERN], 708 // const TCFloat b[L3ORDERM]); 709 //void scanCameraPoint(const TCVector &point); 710 //virtual void preCalcCamera(void); 711 712 void initLightDirModel(TREMainModel *&lightDirModel, TCULong color); 713 void initLightDirModels(void); 714 void projectCamera(const TCVector &distance); 715 716 TREMainModel *mainTREModel; 717 LDLMainModel *mainModel; 718 TREMainModel *whiteLightDirModel; 719 TREMainModel *blueLightDirModel; 720 TREMainModel *highlightModel; 721 char* filename; 722 std::string mpdName; 723 char* programPath; 724 TCFloat width; 725 TCFloat height; 726 TCFloat scaleFactor; 727 TCFloat pixelAspectRatio; 728 TCFloat size; 729 TCFloat clipSize; 730 TCVector center; 731 TCVector boundingMin; 732 TCVector boundingMax; 733 int lastFrameTimeLength; 734 int cullBackFaces; 735 ViewMode viewMode; 736 ExamineMode examineMode; 737 TCFloat xRotate; 738 TCFloat yRotate; 739 TCFloat zRotate; 740 TCFloat rotationSpeed; 741 TCFloat cameraXRotate; 742 TCFloat cameraYRotate; 743 TCFloat cameraZRotate; 744 TCVector cameraMotion; 745 TCFloat zoomSpeed; 746 TCFloat xPan; 747 TCFloat yPan; 748 TCFloat* rotationMatrix; 749 TCFloat* defaultRotationMatrix; 750 TCFloat defaultLatitude; 751 TCFloat defaultLongitude; 752 TCFloat examineLatitude; 753 TCFloat examineLongitude; 754 TCFloat clipAmount; 755 TCFloat nextClipAmount; 756 TCFloat nextDistance; 757 TCFloat32 highlightLineWidth; 758 TCFloat32 wireframeLineWidth; 759 TCFloat32 anisoLevel; 760 bool clipZoom; 761 GLuint fontListBase; 762 GLclampf backgroundR; 763 GLclampf backgroundG; 764 GLclampf backgroundB; 765 GLclampf backgroundA; 766 TCByte defaultR; 767 TCByte defaultG; 768 TCByte defaultB; 769 int defaultColorNumber; 770 // LDMProgressCallback progressCallback; 771 // void* progressUserData; 772 // LDMErrorCallback errorCallback; 773 // void* errorUserData; 774 int xTile; 775 int yTile; 776 int numXTiles; 777 int numYTiles; 778 LDVStereoMode stereoMode; 779 TCFloat stereoEyeSpacing; 780 LDVCutawayMode cutawayMode; 781 TCFloat32 cutawayAlpha; 782 TCFloat32 cutawayLineWidth; 783 TCFloat zoomMax; 784 int curveQuality; 785 int textureFilterType; 786 TCFloat distanceMultiplier; 787 TCImage *fontImage1x; 788 TCImage *fontImage2x; 789 GLuint fontTextureID; 790 LDLCamera camera; 791 TCFloat aspectRatio; 792 TCFloat currentFov; 793 TCFloat fov; 794 TCFloat defaultDistance; 795 TCStringArray *extraSearchDirs; 796 TCFloat seamWidth; 797 TCFloat zoomToFitWidth; 798 TCFloat zoomToFitHeight; 799 TCFloat textureOffsetFactor; 800 int memoryUsage; 801 TCVector lightVector; 802 LDPreferences *preferences; 803 int missingPartWait; 804 int updatedPartWait; 805 LDVMouseMode mouseMode; 806 int lastMouseX; 807 int lastMouseY; 808 LDInputHandler *inputHandler; 809 int step; 810 int commandLineStep; 811 int mpdChildIndex; 812 LDExporter *exporter; 813 ExportType exportType; 814 StringList highlightPaths; 815 int highlightR; 816 int highlightG; 817 int highlightB; 818 #ifdef USE_STD_CHRONO 819 std::chrono::time_point<std::chrono::steady_clock> frameTime; 820 #else 821 #ifdef WIN32 822 DWORD frameTicks; 823 LARGE_INTEGER hrpcFrequency; 824 LARGE_INTEGER hrpcFrameCount; 825 #endif // WIN32 826 #ifdef COCOA 827 void *frameTime; 828 #endif // COCOA 829 #ifdef _QT 830 QTime qtime; 831 #endif 832 #endif // !USE_STD_CHRONO 833 std::string m_ldConfig; 834 struct 835 { 836 bool qualityLighting:1; 837 bool showsHighlightLines:1; 838 bool qualityStuds:1; 839 bool usesFlatShading:1; 840 bool usesSpecular:1; 841 bool drawWireframe:1; 842 bool useWireframeFog:1; 843 bool removeHiddenLines:1; 844 bool usePolygonOffset:1; 845 bool useLighting:1; 846 bool subduedLighting:1; 847 bool allowPrimitiveSubstitution:1; 848 bool useStipple:1; 849 bool fileIsPart:1; 850 bool sortTransparent:1; 851 bool needsSetup:1; 852 bool needsTextureSetup:1; 853 bool needsMaterialSetup:1; 854 bool needsLightingSetup:1; 855 bool needsReload:1; 856 bool needsReparse:1; 857 bool needsRecompile:1; 858 bool needsResize:1; 859 bool needsCalcSize:1; 860 bool needsRotationMatrixSetup:1; 861 bool needsViewReset:1; 862 bool needsResetStep:1; 863 bool needsResetMpd:1; 864 bool paused:1; 865 bool slowClear:1; 866 bool blackHighlights:1; 867 bool textureStuds:1; 868 bool oneLight:1; 869 bool drawConditionalHighlights:1; 870 bool showAllConditionalLines:1; 871 bool showConditionalControlPoints:1; 872 bool performSmoothing:1; 873 bool lineSmoothing:1; 874 bool constrainZoom:1; 875 bool edgesOnly:1; 876 bool hiResPrimitives:1; 877 bool processLDConfig:1; 878 bool skipValidation:1; 879 bool autoCenter:1; 880 bool forceZoomToFit:1; 881 bool defaultTrans:1; 882 bool bfc:1; 883 bool redBackFaces:1; 884 bool greenFrontFaces:1; 885 bool blueNeutralFaces:1; 886 bool defaultLightVector:1; 887 bool overrideModelCenter:1; 888 bool overrideModelSize:1; 889 bool overrideDefaultDistance:1; 890 bool checkPartTracker:1; 891 bool showLight:1; 892 bool drawLightDats:1; 893 bool optionalStandardLight:1; 894 bool noLightGeom:1; 895 bool updating:1; 896 bool saveAlpha:1; 897 bool multiThreaded:1; 898 bool showAxes:1; 899 bool axesAtOrigin:1; 900 bool showBoundingBox:1; 901 bool boundingBoxesOnly:1; 902 bool obi:1; 903 bool gl2ps:1; 904 bool povCameraAspect:1; 905 bool animating:1; 906 bool randomColors:1; 907 bool noUI:1; 908 bool keepRightSideUp:1; 909 bool texmaps:1; 910 bool texturesAfterTransparent:1; 911 bool useStrips:1; 912 } flags; 913 struct CameraData 914 { CameraDataCameraData915 CameraData(void) 916 :direction(0.0f, 0.0f, -1.0f), 917 horizontal(1.0f, 0.0f, 0.0f), 918 vertical(0.0f, -1.0f, 0.0f), 919 horMin(1e6), 920 horMax(-1e6), 921 verMin(1e6), 922 verMax(-1e6) 923 { 924 int i; 925 // TCVector up = vertical; 926 927 // horizontal = direction * up; 928 // vertical = horizontal * direction; 929 for (i = 0; i < 4; i++) 930 { 931 dMin[i] = 1e6; 932 } 933 } 934 TCVector direction; 935 TCVector horizontal; 936 TCVector vertical; 937 TCVector normal[4]; 938 TCFloat dMin[4]; 939 TCFloat horMin; 940 TCFloat horMax; 941 TCFloat verMin; 942 TCFloat verMax; 943 TCFloat fov; 944 } *cameraData; 945 static StandardSizeList standardSizes; 946 static std::string sm_appVersion; 947 static std::string sm_appCopyright; 948 }; 949 950 #endif // __LDRAWMODELVIEWER_H__ 951