diff --git a/Pdf4QtLib/sources/pdf3d_u3d.cpp b/Pdf4QtLib/sources/pdf3d_u3d.cpp index d4e3908..53323e9 100644 --- a/Pdf4QtLib/sources/pdf3d_u3d.cpp +++ b/Pdf4QtLib/sources/pdf3d_u3d.cpp @@ -2470,8 +2470,8 @@ void PDF3D_U3D_Parser::processCLODMesh(const PDF3D_U3D_Decoder& decoder) case PDF3D_U3D_Block_Info::BT_GeneratorCLODProgMesh: { - // TODO: process block data - auto currentBlock = PDF3D_U3D_CLODProgressiveMeshContinuationBlock::parse(blockData.blockData, blockData.metaData, this/*, declarationBlock*/); + auto currentBlock = PDF3D_U3D_CLODProgressiveMeshContinuationBlock::parse(blockData.blockData, blockData.metaData, this); + Q_UNUSED(currentBlock); break; } @@ -3410,7 +3410,6 @@ void PDF3D_U3D_Parser::addBlockToU3D(PDF3D_U3D_AbstractBlockPtr block) default: { - // TODO: add block to U3D m_errors << PDFTranslationContext::tr("Block type (%1) not supported in scene decoder.").arg(block->getBlockType(), 8, 16); break; } @@ -3561,6 +3560,12 @@ void PDF3D_U3D_Parser::processGenericBlock(const PDF3D_U3D_Block_Data& blockData PDF3D_U3D_Block_Info::EPalette effectivePalette = PDF3D_U3D_Block_Info::isChain(blockData.blockType) ? palette : PDF3D_U3D_Block_Info::getPalette(blockData.blockType); + if (effectivePalette == PDF3D_U3D_Block_Info::PL_LastPalette) + { + m_errors << PDFTranslationContext::tr("Failed to add block '%1' - decoder chain does not exist!").arg(blockName); + return; + } + PDF3D_U3D_DecoderPalette* decoderPalette = m_decoderPalettes.getDecoderPalette(effectivePalette); if (PDF3D_U3D_Block_Info::isContinuation(blockData.blockType)) @@ -4698,6 +4703,8 @@ PDF3D_U3D_AbstractBlockPtr PDF3D_U3D_CLODProgressiveMeshContinuationBlock::parse block->m_resolutionUpdateCount = block->m_endResolution - block->m_startResolution; + // We do not implement this block +#if 0 for (uint32_t i = block->m_startResolution; i < block->m_endResolution; ++i) { ResolutionUpdate updateItem; @@ -4768,11 +4775,11 @@ PDF3D_U3D_AbstractBlockPtr PDF3D_U3D_CLODProgressiveMeshContinuationBlock::parse updateItem.newFaces.emplace_back(std::move(facePositionInfo)); } - // TODO: Fixme - block->m_resolutionUpdates.emplace_back(std::move(updateItem)); } +#endif + block->parseMetadata(metaData, object); return pointer; } diff --git a/Pdf4QtLib/sources/pdf3d_u3d.h b/Pdf4QtLib/sources/pdf3d_u3d.h index c933e4f..afe3870 100644 --- a/Pdf4QtLib/sources/pdf3d_u3d.h +++ b/Pdf4QtLib/sources/pdf3d_u3d.h @@ -546,8 +546,6 @@ private: float m_reflectivity = 0.0; }; -// TODO: apply material to default color - class PDF4QTLIBSHARED_EXPORT PDF3D_U3D { public: diff --git a/Pdf4QtViewer/pdf3dsceneprocessor.cpp b/Pdf4QtViewer/pdf3dsceneprocessor.cpp index 1e39620..c9bd336 100644 --- a/Pdf4QtViewer/pdf3dsceneprocessor.cpp +++ b/Pdf4QtViewer/pdf3dsceneprocessor.cpp @@ -514,10 +514,111 @@ Qt3DCore::QNode* PDF3DSceneProcessor::createMeshGeometry(const pdf::u3d::PDF3D_U return node; } - case ShadedWireframe: case HiddenWireframe: + { + return createWireframeWithoutObscuredEdgesMeshGeometry(meshGeometry); + } + case SolidOutline: + { + Qt3DCore::QNode* node = new Qt3DCore::QNode(); + + Qt3DCore::QNode* solidGeometry = createSolidMeshGeometry(meshGeometry, 1.0); + Qt3DCore::QNode* wireframeGeometry = createWireframeWithoutObscuredEdgesMeshGeometry(meshGeometry); + + solidGeometry->setParent(node); + wireframeGeometry->setParent(node); + + return node; + } + case ShadedVertices: + { + // We will display vertices with triangle color + + // Vertex buffer + Qt3DRender::QAttribute* positionAttribute = createPositionAttribute(meshGeometry->getPositions()); + + // Color buffer + Qt3DRender::QBuffer* colorBuffer = new Qt3DRender::QBuffer(); + colorBuffer->setType(Qt3DRender::QBuffer::VertexBuffer); + const uint positionCount = positionAttribute->count(); + + QByteArray colorBufferData; + colorBufferData.resize(positionCount * 3 * sizeof(float)); + float* colorBufferDataPtr = reinterpret_cast(colorBufferData.data()); + + for (size_t i = 0; i < positionCount; ++i) + { + QVector3D color(0.0, 0.0, 0.0); + std::vector triangles = meshGeometry->queryTrianglesByVertexIndex(i); + + if (!triangles.empty()) + { + pdf::u3d::PDF3D_U3D_MeshGeometry::Triangle triangle = triangles.front(); + + for (const auto& vertex : triangle.vertices) + { + if (vertex.positionIndex == i) + { + color = meshGeometry->getDiffuseColor(vertex.diffuseColorIndex).toVector3D(); + } + } + } + + *colorBufferDataPtr++ = color.x(); + *colorBufferDataPtr++ = color.y(); + *colorBufferDataPtr++ = color.z(); + } + colorBuffer->setData(colorBufferData); + + Qt3DRender::QAttribute* colorAttribute = new Qt3DRender::QAttribute(); + colorAttribute->setName(Qt3DRender::QAttribute::defaultColorAttributeName()); + colorAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + colorAttribute->setVertexSize(3); + colorAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + colorAttribute->setBuffer(colorBuffer); + colorAttribute->setByteOffset(0); + colorAttribute->setByteStride(3 * sizeof(float)); + colorAttribute->setCount(positionCount); + + // Geometry + Qt3DRender::QGeometry* geometry = new Qt3DRender::QGeometry(); + geometry->addAttribute(positionAttribute); + geometry->addAttribute(colorAttribute); + + Qt3DRender::QGeometryRenderer* geometryRenderer = new Qt3DRender::QGeometryRenderer(); + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveRestartEnabled(false); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Points); + + Qt3DExtras::QPerVertexColorMaterial* material = new Qt3DExtras::QPerVertexColorMaterial(); + + Qt3DRender::QEffect* effect = material->effect(); + for (Qt3DRender::QTechnique* technique : effect->techniques()) + { + for (Qt3DRender::QRenderPass* renderPass : technique->renderPasses()) + { + Qt3DRender::QPointSize* pointSize = new Qt3DRender::QPointSize(); + pointSize->setSizeMode(Qt3DRender::QPointSize::Fixed); + pointSize->setValue(m_pointSize); + renderPass->addRenderState(pointSize); + } + } + + addDepthTestToMaterial(material); + + Qt3DCore::QEntity* entity = new Qt3DCore::QEntity(); + entity->addComponent(geometryRenderer); + entity->addComponent(material); + return entity; + } + + case ShadedWireframe: + { + // Just display wireframe geometry + return createWireframeMeshGeometry(meshGeometry); + } default: Q_ASSERT(false); diff --git a/Pdf4QtViewer/pdfmediaviewerdialog.cpp b/Pdf4QtViewer/pdfmediaviewerdialog.cpp index b539f3a..c563654 100644 --- a/Pdf4QtViewer/pdfmediaviewerdialog.cpp +++ b/Pdf4QtViewer/pdfmediaviewerdialog.cpp @@ -197,8 +197,8 @@ void PDFMediaViewerDialog::regenerateScene() if (m_sceneU3d.has_value()) { PDF3DSceneProcessor processor; - processor.setMode(PDF3DSceneProcessor::ShadedIllustration); - processor.setSceneRoot("PDF3D Scene"); + processor.setMode(PDF3DSceneProcessor::Solid); + processor.setSceneRoot("Scene3D_MalOcc_sceneName"/*"PDF3D Scene"*/); processor.setPointSize(6.0f); auto scene = processor.createScene(&m_sceneU3d.value()); if (scene.sceneRoot) diff --git a/prc/prc_format.xml b/prc/prc_format.xml new file mode 100644 index 0000000..ff8ed66 --- /dev/null +++ b/prc/prc_format.xml @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +