LIB3MFMETHODIMP CCOMModelTexture2D::ReadFromFileUTF8(_In_z_ LPCSTR pszFilename) { try { if (pszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); std::string sUTF8FileName(pszFilename); PImportStream pImportStream = fnCreateImportStreamInstance(sUTF8FileName.c_str()); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); pModel->removeAttachment(pTextureResource->getPath()); pModel->addAttachment(pTextureResource->getPath(), PACKAGE_TEXTURE_RELATIONSHIP_TYPE, pImportStream); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
void CModelReaderNode100_Vertex::OnAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) { m_fX = wcstof(pAttributeValue, nullptr); if (isnan (m_fX)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); m_bHasX = true; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) { m_fY = wcstof(pAttributeValue, nullptr); if (isnan (m_fY)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); m_bHasY = true; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) { m_fZ = wcstof(pAttributeValue, nullptr); if (isnan (m_fZ)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); m_bHasZ = true; } }
LIB3MFMETHODIMP CCOMModelTexture2D::ReadFromBuffer(_In_ BYTE * pBuffer, _In_ ULONG64 cbBufferSize) { try { if (pBuffer == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pImportStream = std::make_shared<CImportStream_Memory>(pBuffer, cbBufferSize); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); pModel->removeAttachment(pTextureResource->getPath()); pModel->addAttachment(pTextureResource->getPath(), PACKAGE_TEXTURE_RELATIONSHIP_TYPE, pImportStream); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
void CModelReaderNode093_Components::OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader) { __NMRASSERT(pChildName); __NMRASSERT(pXMLReader); __NMRASSERT(pNameSpace); if ((strcmp(pNameSpace, XML_3MF_NAMESPACE_CORESPEC093) == 0) || (strcmp(pNameSpace, "") == 0)) { if (strcmp(pChildName, XML_3MF_ELEMENT_COMPONENT) == 0) { // Read Component PModelReaderNode093_Component pXMLNode = std::make_shared<CModelReaderNode093_Component>(m_pComponentsObject->getModel(), m_pWarnings); pXMLNode->parseXML(pXMLReader); // Retrieve object and transform CModelObject * pObject = pXMLNode->getObject(); NMATRIX3 mTransform = pXMLNode->getTransform(); // Check, if we have an associated object if (!pObject) throw CNMRException(NMR_ERROR_COULDNOTFINDCOMPONENTOBJECT); // Create component PModelComponent pComponent = std::make_shared<CModelComponent>(pObject, mTransform); m_pComponentsObject->addComponent(pComponent); } } }
CModelWriterNode::CModelWriterNode(_In_ CModel * pModel, _In_ CXmlWriter * pXMLWriter) { __NMRASSERT(pModel); __NMRASSERT(pXMLWriter); m_pModel = pModel; m_pXMLWriter = pXMLWriter; }
void CModelWriter_3MF_Native::addTextureParts(_In_ CModel * pModel, _In_ POpcPackageWriter pPackageWriter, _In_ POpcPackagePart pModelPart) { __NMRASSERT(pModel != nullptr); __NMRASSERT(pModelPart.get() != nullptr); __NMRASSERT(pPackageWriter.get() != nullptr); nfUint32 nCount = pModel->getTextureStreamCount(); nfUint32 nIndex; if (nCount > 0) { for (nIndex = 0; nIndex < nCount; nIndex++) { PImportStream pStream = pModel->getTextureStream(nIndex); std::wstring sPath = fnIncludeLeadingPathDelimiter (pModel->getTextureStreamPath(nIndex)); if (pStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); // create Texture Part POpcPackagePart pTexturePart = pPackageWriter->addPart(sPath); PExportStream pExportStream = pTexturePart->getExportStream(); // Copy data pStream->seekPosition(0, true); pExportStream->copyFrom(pStream.get(), pStream->retrieveSize(), MODELWRITER_NATIVE_BUFFERSIZE); // add relationships pModelPart->addRelationship(generateRelationShipID(), PACKAGE_TEXTURE_RELATIONSHIP_TYPE, pTexturePart.get()); } } }
void CModelReaderNode100_Tex2DGroup::OnAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TEX2DGROUP_ID) == 0) { if (m_nID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! m_nID = fnWStringToUint32(pAttributeValue); } else if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TEX2DGROUP_TEXTUREID) == 0) { if (m_nTextureID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! ModelResourceID nID = fnWStringToUint32(pAttributeValue); if (nID == 0) m_pWarnings->addException(CNMRException(NMR_ERROR_INVALIDMODELRESOURCE), mrwInvalidMandatoryValue); m_nTextureID = nID; } else m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ATTRIBUTE), mrwInvalidOptionalValue); }
void CModelWriter_3MF_Native::addAttachments(_In_ CModel * pModel, _In_ POpcPackageWriter pPackageWriter, _In_ POpcPackagePart pModelPart) { __NMRASSERT(pModel != nullptr); __NMRASSERT(pModelPart.get() != nullptr); __NMRASSERT(pPackageWriter.get() != nullptr); nfUint32 nCount = pModel->getAttachmentCount(); nfUint32 nIndex; if (nCount > 0) { for (nIndex = 0; nIndex < nCount; nIndex++) { PModelAttachment pAttachment = pModel->getModelAttachment(nIndex); PImportStream pStream = pAttachment->getStream(); std::wstring sPath = fnIncludeLeadingPathDelimiter(pAttachment->getPathURI()); std::wstring sRelationShipType = pAttachment->getRelationShipType(); if (pStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); // create Texture Part POpcPackagePart pAttachmentPart = pPackageWriter->addPart(sPath); PExportStream pExportStream = pAttachmentPart->getExportStream(); // Copy data pStream->seekPosition(0, true); pExportStream->copyFrom(pStream.get(), pStream->retrieveSize(), MODELWRITER_NATIVE_BUFFERSIZE); // add relationships pModelPart->addRelationship(generateRelationShipID(), sRelationShipType.c_str(), pAttachmentPart->getURI()); } } }
LIB3MFMETHODIMP CCOMModelTexture2D::ReadFromFile(_In_z_ LPCWSTR pwszFilename) { try { if (pwszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pImportStream = std::make_shared<CImportStream_COM>(pwszFilename); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); pModel->removeTextureStream(pTextureResource->getPath()); pModel->addTextureStream(pTextureResource->getPath(), pImportStream); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::GetAttachment(_Out_ ILib3MFModelAttachment ** ppTextureAttachment) { try { if (ppTextureAttachment == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); // Retrieve Path std::string sPath = pTextureResource->getPath(); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); PModelAttachment pAttachment = pModel->findModelAttachment(sPath); CCOMObject<CCOMModelAttachment> * pCOMObject = new CCOMObject<CCOMModelAttachment>(); pCOMObject->AddRef(); pCOMObject->setAttachment(pAttachment); *ppTextureAttachment = pCOMObject; return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
CModelReaderNode100_Triangles::CModelReaderNode100_Triangles(_In_ CModel * pModel, _In_ CMesh * pMesh, _In_ PModelReaderWarnings pWarnings) : CModelReaderNode(pWarnings) { __NMRASSERT(pMesh); __NMRASSERT(pModel); m_pModel = pModel; m_pMesh = pMesh; }
void CModelWriterNode::writeConstStringAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); __NMRASSERT(m_pXMLWriter); m_pXMLWriter->WriteAttributeString(nullptr, pAttributeName, nullptr, pAttributeValue); }
CComPtr<IOpcPart> CModelReader_3MF_OPC::getPartFromPackage(_In_ IOpcPartSet* pPartSet, _In_ IOpcRelationshipSet* pRelationshipSet, _In_ LPCWSTR pszRelationshipType, _In_opt_ LPCWSTR pszExpectedContentType) { __NMRASSERT(pPartSet != nullptr); __NMRASSERT(pRelationshipSet != nullptr); __NMRASSERT(pszRelationshipType != nullptr); CComPtr<IOpcRelationship> pRelationship = getSingleRelationShipByType(pRelationshipSet, pszRelationshipType); return getRelationshipTargetPart(pPartSet, pRelationship, pszExpectedContentType); }
void CModelReaderNode100_Color::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_COLORS_COLOR) == 0) { // Convert to color and make a input and range check! m_bHasColor = fnStringToSRGBColor(pAttributeValue, m_cColor); } }
PImportStream CModelReader_3MF_OPC::extract3MFOPCPackage(_In_ PImportStream pPackageStream) { HRESULT hResult; __NMRASSERT(pPackageStream != nullptr); // Cast to COM Streams CImportStream_COM * pCOMImportStream = dynamic_cast<CImportStream_COM *> (pPackageStream.get()); if (pCOMImportStream == nullptr) throw CNMRException(NMR_ERROR_INVALIDSTREAMTYPE); CComPtr<IStream> pCOMPackageStream = pCOMImportStream->getCOMStream (); // Define result model stream; CComPtr<IStream> pModelStream = nullptr; // Reset all values m_pPackagePartSet = nullptr; m_pPackageRelationshipSet = nullptr; m_pModelPart = nullptr; // Create OPC Factory CComPtr<IOpcFactory> pFactory; hResult = CoCreateInstance(__uuidof(OpcFactory), NULL, CLSCTX_INPROC_SERVER, __uuidof(IOpcFactory), (LPVOID*)&pFactory); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCFACTORYCREATEFAILED, hResult); // Read OPC Package CComPtr<IOpcPackage> pPackage; hResult = pFactory->ReadPackageFromStream(pCOMPackageStream, OPC_READ_DEFAULT, &pPackage); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCREADFAILED, hResult); // Read OPC Package Part Set hResult = pPackage->GetPartSet(&m_pPackagePartSet); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCPARTSETREADFAILED, hResult); // Read OPC Relationship Set hResult = pPackage->GetRelationshipSet(&m_pPackageRelationshipSet); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPSETREADFAILED, hResult); // Extract Model from OPC Package __NMRASSERT(m_pPackagePartSet != nullptr); __NMRASSERT(m_pPackageRelationshipSet != nullptr); m_pModelPart = getPartFromPackage(m_pPackagePartSet, m_pPackageRelationshipSet, PACKAGE_START_PART_RELATIONSHIP_TYPE, PACKAGE_3D_MODEL_CONTENT_TYPE); // Extract Model Stream __NMRASSERT(m_pModelPart != nullptr); hResult = m_pModelPart->GetContentStream(&pModelStream); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCCOULDNOTGETMODELSTREAM, hResult); return std::make_shared<CImportStream_COM>(pModelStream); }
void CModelReaderNode093_Resources::OnNSChildElement(_In_z_ const nfWChar * pChildName, _In_z_ const nfWChar * pNameSpace, _In_ CXmlReader * pXMLReader) { __NMRASSERT(pChildName); __NMRASSERT(pXMLReader); __NMRASSERT(pNameSpace); if ((wcscmp(pNameSpace, XML_3MF_NAMESPACE_CORESPEC093) == 0) || (wcscmp(pNameSpace, L"") == 0)) { if (wcscmp(pChildName, XML_3MF_ELEMENT_OBJECT) == 0) { PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode093_Object>(m_pModel, m_pColorMapping, m_pMaterialResource, m_pWarnings); pXMLNode->parseXML(pXMLReader); } if (wcscmp(pChildName, XML_3MF_ELEMENT_COLOR) == 0) { PModelReaderNode093_Color pXMLNode = std::make_shared<CModelReaderNode093_Color>(m_pWarnings); pXMLNode->parseXML(pXMLReader); ModelResourceID nResourceID = pXMLNode->retrieveID(); ModelResourceID nTextureRefID = pXMLNode->retrieveTextureID(); if (nTextureRefID > 0) { m_pColorMapping->registerTextureReference(nResourceID, nTextureRefID); } else { m_pColorMapping->registerColor(pXMLNode->retrieveID(), 0, pXMLNode->retrieveColor()); } } if (wcscmp(pChildName, XML_3MF_ELEMENT_TEXTURE) == 0) { PModelReaderNode093_Texture pXMLNode = std::make_shared<CModelReaderNode093_Texture>(m_pModel, m_pWarnings); pXMLNode->parseXML(pXMLReader); } if (wcscmp(pChildName, XML_3MF_ELEMENT_MATERIAL) == 0) { PModelReaderNode093_Material pXMLNode = std::make_shared<CModelReaderNode093_Material>(m_pWarnings); pXMLNode->parseXML(pXMLReader); if (m_pMaterialResource.get() == nullptr) { m_pMaterialResource = std::make_shared<CModelBaseMaterialResource> (m_pModel->generateResourceID(), m_pModel); m_pModel->addResource(m_pMaterialResource); } nfColor cColor; if (!m_pColorMapping->findColor(pXMLNode->retrieveColorID(), 0, cColor)) { cColor = 0xffffffff; } ModelResourceIndex nMaterialIndex; nMaterialIndex = m_pMaterialResource->addBaseMaterial(pXMLNode->retrieveName(), cColor); m_pColorMapping->registerMaterialReference(pXMLNode->retrieveID(), nMaterialIndex); } } }
LIB3MFMETHODIMP CCOMModelTexture2D::ReadFromBuffer(_In_ BYTE * pBuffer, _In_ ULONG64 cbBufferSize) try { if (pBuffer == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); HRESULT hResult; CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); CComPtr<IStream> pMemoryStream = nullptr; hResult = CreateStreamOnHGlobal(nullptr, true, &pMemoryStream); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_COULDNOTCREATESTREAM, hResult); BYTE * pByte = pBuffer; nfUint64 cbBytesLeft = cbBufferSize; while (cbBytesLeft > 0) { nfUint64 cbLength = cbBytesLeft; if (cbLength > NMR_IMPORTSTREAM_COPYBUFFERSIZE) cbLength = NMR_IMPORTSTREAM_COPYBUFFERSIZE; ULONG cbWrittenBytes = 0; hResult = pMemoryStream->Write(pByte, (nfUint32)cbLength, &cbWrittenBytes); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_COULDNOTWRITESTREAM, hResult); if (cbWrittenBytes != cbLength) throw CNMRException(NMR_ERROR_COULDNOTWRITEFULLDATA); cbBytesLeft -= cbLength; pByte += cbLength; } PImportStream pImportStream = std::make_shared<CImportStream_COM>(pMemoryStream); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); pModel->removeTextureStream(pTextureResource->getPath()); pModel->addTextureStream(pTextureResource->getPath(), pImportStream); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); }
void CModelReaderNode093_Object::OnNSChildElement(_In_z_ const nfWChar * pChildName, _In_z_ const nfWChar * pNameSpace, _In_ CXmlReader * pXMLReader) { __NMRASSERT(pChildName); __NMRASSERT(pXMLReader); __NMRASSERT(pNameSpace); if ((wcscmp(pNameSpace, XML_3MF_NAMESPACE_CORESPEC093) == 0) || (wcscmp(pNameSpace, L"") == 0)) { // Read a mesh object if (wcscmp(pChildName, XML_3MF_ELEMENT_MESH) == 0) { // If we already have parsed an object, the node is duplicate if (m_pObject.get()) throw CNMRException(NMR_ERROR_AMBIGUOUSOBJECTDEFINITON); // Create Empty Mesh PMesh pMesh = std::make_shared<CMesh>(); // Create Mesh Object m_pObject = std::make_shared<CModelMeshObject>(m_nID, m_pModel, pMesh); // Read Mesh PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode093_Mesh>(m_pModel, pMesh.get(), m_pColorMapping, m_pMaterialResource, m_pWarnings); pXMLNode->parseXML(pXMLReader); // Add Object to Parent m_pModel->addResource(m_pObject); } // Read a component object if (wcscmp(pChildName, XML_3MF_ELEMENT_COMPONENTS) == 0) { // If we already have parsed an object, the node is duplicate if (m_pObject.get()) throw CNMRException(NMR_ERROR_AMBIGUOUSOBJECTDEFINITON); // Create Component List Object PModelComponentsObject pComponentsObject = std::make_shared<CModelComponentsObject>(m_nID, m_pModel); m_pObject = pComponentsObject; // Read Components PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode093_Components>(pComponentsObject.get(), m_pWarnings); pXMLNode->parseXML(pXMLReader); // Add Object to Parent m_pModel->addResource(m_pObject); } } }
void CModelReaderNode100_Colors::OnAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_COLORS_ID) == 0) { if (m_nID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! m_nID = fnWStringToUint32(pAttributeValue); } }
void CModelReaderNode100_BaseMaterials::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_BASEMATERIALS_ID) == 0) { if (m_nID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! m_nID = fnStringToUint32(pAttributeValue); } }
CModelReaderNode093_Triangles::CModelReaderNode093_Triangles(_In_ CModel * pModel, _In_ CMesh * pMesh, _In_ PModelReader_ColorMapping pColorMapping, _In_ PModelReader_TexCoordMapping pTexCoordMapping, _In_ PModelBaseMaterialResource pMaterialResource, _In_ PModelReaderWarnings pWarnings) : CModelReaderNode(pWarnings) { __NMRASSERT(pMesh); __NMRASSERT(pModel); __NMRASSERT(pColorMapping.get() != nullptr); __NMRASSERT(pTexCoordMapping.get() != nullptr); m_pModel = pModel; m_pMesh = pMesh; m_pColorMapping = pColorMapping; m_pTexCoordMapping = pTexCoordMapping; m_pMaterialResource = pMaterialResource; }
void CModelReaderNode093_Build::OnNSChildElement(_In_z_ const nfWChar * pChildName, _In_z_ const nfWChar * pNameSpace, _In_ CXmlReader * pXMLReader) { __NMRASSERT(pChildName); __NMRASSERT(pXMLReader); __NMRASSERT(pNameSpace); if ((wcscmp(pNameSpace, XML_3MF_NAMESPACE_CORESPEC093) == 0 ) || (wcscmp(pNameSpace, L"") == 0)) { if (wcscmp(pChildName, XML_3MF_ELEMENT_ITEM) == 0) { PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode093_BuildItem>(m_pModel, m_pWarnings); pXMLNode->parseXML(pXMLReader); } } }
void CModelReaderNode100_Triangle::OnAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); nfInt32 nValue; if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_V1) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nIndex1 = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_V2) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nIndex2 = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_V3) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nIndex3 = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_PID) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEID)) m_nPropertyID = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_P1) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nPropertyIndex1 = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_P2) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nPropertyIndex2 = nValue; } if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLE_P3) == 0) { nValue = fnWStringToInt32(pAttributeValue); if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) m_nPropertyIndex3 = nValue; } }
CComPtr<IOpcRelationship> CModelReader_3MF_OPC::getSingleRelationShipByType(_In_ IOpcRelationshipSet * pRelationshipSet, _In_ LPCWSTR pszRelationshipType) { __NMRASSERT(pRelationshipSet != nullptr); __NMRASSERT(pszRelationshipType != nullptr); HRESULT hResult; // Retrieve Enumerator CComPtr<IOpcRelationshipEnumerator> pEnumerator; hResult = pRelationshipSet->GetEnumeratorForType(pszRelationshipType, &pEnumerator); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPENUMERATIONFAILED, hResult); // Enumerate the first two relationships CComPtr<IOpcRelationship> pFirstRelationShip = nullptr; CComPtr<IOpcRelationship> pSecondRelationShip = nullptr; // Get the first relationship BOOL bHasFirst; hResult = pEnumerator->MoveNext(&bHasFirst); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPENUMERATIONFAILED, hResult); if (bHasFirst) { hResult = pEnumerator->GetCurrent(&pFirstRelationShip); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPENUMERATIONFAILED, hResult); // Get the first relationship BOOL bHasSecond; hResult = pEnumerator->MoveNext(&bHasSecond); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPENUMERATIONFAILED, hResult); if (bHasSecond) { hResult = pEnumerator->GetCurrent(&pSecondRelationShip); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_OPCRELATIONSHIPENUMERATIONFAILED, hResult); } } // We may only have exactly one relationship, otherwise it is ambigouus if (!pFirstRelationShip) throw CNMRException(NMR_ERROR_OPCRELATIONSHIPNOTFOUND); if (pSecondRelationShip) throw CNMRException(NMR_ERROR_OPCRELATIONSHIPNOTUNIQUE); return pFirstRelationShip; }
PImportStream CModelTexture2DResource::getTextureStream() { CModel * pModel = getModel(); __NMRASSERT(pModel != nullptr); return pModel->findTextureStream(m_sPath); }
LIB3MFMETHODIMP CCOMModelTexture2D::GetPath(_Out_opt_ LPWSTR pwszBuffer, _In_ ULONG cbBufferSize, _Out_ ULONG * pcbNeededChars) { try { if (cbBufferSize > MODEL_MAXSTRINGBUFFERLENGTH) throw CNMRException(NMR_ERROR_INVALIDBUFFERSIZE); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); // Retrieve Path std::wstring sPath = pTextureResource->getPath(); // Safely call StringToBuffer nfUint32 nNeededChars = 0; fnWStringToBufferSafe(sPath, pwszBuffer, cbBufferSize, &nNeededChars); // Return length if needed if (pcbNeededChars) *pcbNeededChars = nNeededChars; return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::GetBox2D(_Out_ FLOAT * pfU, _Out_ FLOAT * pfV, _Out_ FLOAT * pfWidth, _Out_ FLOAT * pfHeight) { try { if ((pfU == nullptr) || (pfV == nullptr) || (pfWidth == nullptr) || (pfHeight == nullptr)) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); nfFloat fU, fV, fWidth, fHeight; if (pTextureResource->getBox2D(fU, fV, fWidth, fHeight)) { *pfU = fU; *pfV = fV; *pfWidth = fWidth; *pfHeight = fHeight; } else { *pfU = 0.0f; *pfV = 0.0f; *pfWidth = 1.0f; *pfHeight = 1.0f; } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::GetStreamSize(_Out_ ULONG64 * pcbStreamSize) { try { CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureStream = pTextureResource->getTextureStream(); if (pTextureStream.get() != nullptr) { *pcbStreamSize = pTextureStream->retrieveSize(); } else { *pcbStreamSize = 0; } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToFile(_In_z_ LPCWSTR pwszFilename) { try { if (pwszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureStream = pTextureResource->getTextureStream(); if (pTextureStream.get() != nullptr) { pTextureStream->writeToFile(pwszFilename); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToBuffer(_Out_ BYTE * pBuffer, _In_ ULONG64 cbBufferSize) { try { if (pBuffer == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureStream = pTextureResource->getTextureStream(); if (pTextureStream.get() != nullptr) { nfUint64 cbStreamSize = pTextureStream->retrieveSize(); if (cbStreamSize > cbBufferSize) throw CNMRException(NMR_ERROR_INSUFFICIENTBUFFERSIZE); pTextureStream->seekPosition(0, true); pTextureStream->readBuffer(pBuffer, cbStreamSize, true); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }