[Interest] [Qt3D] QGeometryRenderer can't be shared
Sean Harmer
sh at theharmers.co.uk
Fri Sep 30 16:47:24 CEST 2016
Hi,
please do open a JIRA. However, it is more natural to share the Geometry
rather than the GeometryRenderer component itself.
Cheers,
Sean
On 30/09/2016 15:18, Xavier Bigand wrote:
> I found a workaround :
>
> QGeometryRenderer*clonedGeometryRenderer=newQGeometryRenderer();
>
> QGeometry*clonedMeshGeometry=newQGeometry(clonedGeometryRenderer);
>
>
> foreach(QAttribute*attribute,geometryRenderer->geometry()->attributes())
>
> {
>
> attribute->buffer()->setParent(clonedMeshGeometry);
>
> attribute->setParent(clonedMeshGeometry);
>
> clonedMeshGeometry->addAttribute(attribute);
>
> }
>
> clonedGeometryRenderer->setGeometry(clonedMeshGeometry);
>
> subEntity->addComponent(clonedGeometryRenderer);
>
>
>
> I have to call setParent on buffers and attributes, that will have more than one parent, but it works, they can be shared in this way.
>
> Need I open a bug, because it doesn't seems natural and reusing directly a component will be much better.
>
>
>
>
> 2016-09-30 15:34 GMT+02:00 Xavier Bigand <flamaros.xavier at gmail.com
> <mailto:flamaros.xavier at gmail.com>>:
>
> I took a look to the addComponent implementation and it seems normal
> that my code doesn't work because a component is intended to be
> attached once.
> So I don't understand the meaning of the shareable flag.
>
> I'll try to share the geometry instead.
>
> 2016-09-30 15:20 GMT+02:00 Xavier Bigand <flamaros.xavier at gmail.com
> <mailto:flamaros.xavier at gmail.com>>:
>
> I am trying to share my QGeometryRenderer between many Entities,
> but the addComponent doesn't have any effect.
>
> When I load our models from files, I save the root entity node
> in a map, and after I clone the node tree when a previously
> model is in the map.
> I have no issue with the material component that is in the
> cloned tree, but the geometryRenderer isn't printed by my trace
> method (material and geometryRenderer components are at the same
> level on sub-entities).
>
> I set the shareable flag to true on the geometryRenderer.
>
> PS : for the material component I don't assign the same ptr to
> the cloned model, because I don't want to share the material all
> attributs. My material class have is own clone method to copy
> only the shareable attributs (maps, specular,...).
>
>
> Here is my cloning method :
>
> voidModel::cloneModel(Qt3DCore::QEntity*source,Qt3DCore::QEntity&destination)
>
> {
>
> QNodeVectorsourceEntities=source->childNodes();
>
>
> foreach(QNode*node,sourceEntities)
>
> {
>
> QEntity*sourceSubEntity=dynamic_cast<QEntity*>(node);
>
> QEntity*subEntity=newQEntity(&destination);
>
>
> H3D_ASSERT(sourceSubEntity!=nullptr);
>
>
> subEntity->setObjectName(sourceSubEntity->objectName());
>
>
> QComponentVectorsourceComponents=sourceSubEntity->components();
>
>
> foreach(QComponent*component,sourceComponents)
>
> {
>
> QGeometryRenderer*geometryRenderer=dynamic_cast<QGeometryRenderer*>(component);
>
> LightingMaterial*material=dynamic_cast<LightingMaterial*>(component);
>
>
> if(geometryRenderer)
>
> {
>
> subEntity->addComponent(geometryRenderer);
>
> LOG_INFO("geometryRenderer%s%s",qPrintable(component->metaObject()->className()),qPrintable(component->objectName()));
>
> }
>
> elseif(material)
>
> {
>
> LightingMaterial*clonedMaterial=newLightingMaterial();
>
>
> clonedMaterial->clone(*material);
>
> subEntity->addComponent(clonedMaterial);
>
> }
>
> elseif(dynamic_cast<QPhongMaterial*>(component))//TODOtoremove
>
> {
>
> }
>
> elseif(dynamic_cast<QPhongAlphaMaterial*>(component))//TODOtoremove
>
> {
>
> }
>
> else
>
> {
>
> H3D_ASSERT_MSG(false,"Unsupportedcomponenttype%s",qPrintable(component->metaObject()->className()));
>
> }
>
> }
>
> }
>
> }
>
>
> I have this issue with Qt 5.7 and 5.8 build from the git branch.
>
> --
> Xavier
>
>
>
>
> --
> Xavier
>
>
>
>
> --
> Xavier
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
More information about the Interest
mailing list