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 00010 #pragma once 00011 00012 #include "ImageRepository.h" 00013 #include "TextureWriter.h" 00014 #include "TextureRepository.h" 00015 00016 #include <slapi/model/drawing_element.h> 00017 00018 #include <hc.h> 00019 00020 #include <string> 00021 #include <cstdint> 00022 00023 class StyleRepository 00024 { 00025 public: 00026 struct FaceMaterialAndTextureId { 00027 FaceMaterialAndTextureId() 00028 : frontMaterialId(0), frontTextureId(0), backMaterialId(0), backTextureId(0) { } 00029 FaceMaterialAndTextureId(int32_t frMatId, int32_t frTextId, int32_t bkMatId, int32_t bkTextId) 00030 : frontMaterialId(frMatId), frontTextureId(frTextId), 00031 backMaterialId(bkMatId), backTextureId(bkTextId) { } 00032 00033 int32_t frontMaterialId; 00034 int32_t frontTextureId; 00035 int32_t backMaterialId; 00036 int32_t backTextureId; 00037 }; 00038 00039 static const FaceMaterialAndTextureId InvalidId; 00040 00041 public: 00042 StyleRepository(HC_KEY modelSegmentKey, HC_KEY includeSegmentKey, 00043 TextureWriter& textureWriter, ImageRepository& imageRepository); 00044 00045 HC_KEY GetStyleKey(SUFaceRef& face); 00046 HC_KEY GetStyleKey(SUDrawingElementRef& drawingElement); 00047 bool GetId(SUFaceRef& face, FaceMaterialAndTextureId& id); 00048 bool GetId(SUDrawingElementRef& drawingElement, int32_t& id); 00049 00050 TextureRepository & GetTextureRepository() { return m_textureRepository; } 00051 00052 private: 00053 StyleRepository(const StyleRepository&); 00054 StyleRepository& operator=(const StyleRepository&); 00055 00056 bool ImportLineColor(SUDrawingElementRef& drawingElement); 00057 bool ImportFaceColorAndTexture(SUFaceRef& face); 00058 bool ImportFaceColors(SUFaceRef& face, std::string& frontColor, std::string& backColor); 00059 bool ImportFaceTextures(SUFaceRef& face, std::string& frontTexture, std::string& backTexture); 00060 bool ImportTexture(int32_t textureId, std::size_t parameterOffset, std::string& textureDefinition); 00061 bool ImportColorDefinition(SUMaterialRef& material, std::string& colorDefinition); 00062 void ApplyFaceStyle(const std::string& frontColor, const std::string& frontTexture, 00063 const std::string& backColor, const std::string& backTexture); 00064 00065 private: 00066 static const std::size_t s_parameterOffset = 3; 00067 00068 HC_KEY m_stylesSegmentKey; 00069 00070 std::map<FaceMaterialAndTextureId, HC_KEY> m_faceStylesMap; 00071 std::map<int32_t, HC_KEY> m_lineStylesMap; 00072 00073 TextureRepository m_textureRepository; 00074 TextureWriter& m_textureWriter; 00075 ImageRepository& m_imageRepository; 00076 }; 00077 00078 bool operator==(const StyleRepository::FaceMaterialAndTextureId& op1, 00079 const StyleRepository::FaceMaterialAndTextureId& op2); 00080 bool operator<(const StyleRepository::FaceMaterialAndTextureId& op1, 00081 const StyleRepository::FaceMaterialAndTextureId& op2);