PDA

View Full Version : How to add 3D object



npatil15
4th October 2019, 12:56
Hi,

I have a 3D object but didn't find a proper way to add it.
I'm not using any qml file for development.

I got some examples like Qt3DRender::QMesh, but they have explained it will XML file, and I'm not using any XML file.

Please suggest me an example or your suggestions for this.

Thanks

npatil15
5th October 2019, 08:35
Hi,

I'm using the viewer as pcl::visualization::PCLVisualizer, and I want to add this 3D object over that viewer.
I've done this below, but not sure does it right or wrong, and now want to add this Vehicle.obj 3D object over the viewer


vtkWidget = new QVTKWidget(this);

viewer = pcl::visualization::PCLVisualizer("viewer", false);

vtkWidget->SetRenderWindow(viewer->getRenderWindow());

QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(vtkWidget);

// Root entity
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;

// Material
Qt3DRender::QMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity);

// Chest Entity
Qt3DCore::QEntity *Entity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QMesh *Mesh = new Qt3DRender::QMesh(rootEntity);
Mesh->setSource(QUrl("qrc:/Vehicle.obj"));

Entity->addComponent(Mesh);
Entity->addComponent(material);

Qt3DCore::QEntity *scene = rootEntity;

Qt3DExtras::Qt3DWindow view;
view.setRootEntity(scene);]

Please help me out here, I didn't find a piece of proper information over google.

Thanks in advance!

npatil15
15th October 2019, 11:18
Hi,

Still, I'm on the same page, please help me with some findings.

Thanks

d_stranz
15th October 2019, 16:27
I think you are trying to mix apples, oranges, and maybe some other kind of fruit together and the blend isn't working. VTK and Qt3D might all be using OpenGL for display purposes, but each is using a different object model, transformations, and other things which probably are not compatible.


Qt3DExtras::Qt3DWindow view;

What do you think happens to this view instance once the code where this variable lives goes out of scope?

npatil15
16th October 2019, 05:50
Thanks for the reply,

I agreed with your point, I just want to ensure this thing, because I was not sure about it.
Using this approach is because I want to insert a 3D model on the PCL view. I have tried with the below code and its working in windows only, in Linux it's crashing. So just looking for another approach.

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer
pcl::PolygonMesh polymesh;
pcl::io::loadPolygonFile("Vehicle.obj", polymesh);
viewer->addPolygonMesh(polymesh, "meshes", 0);

I have using PCL-1.8, boost-1_64, VTK-8.1

Does update the PCL library to 1.9 will work?

Please suggest me.

Thanks in advanced.

npatil15
16th October 2019, 12:57
I have updated my Ubuntu to 18.2 LTS.

As soon as I used this (pcl::io::loadPolygonFile("Vehicle.obj", polymesh);) code get crashed and give error as,

double free or corruption (out)

Over google, I found some issues related to this, and they seem to be fixed somewhere.
https://github.com/PointCloudLibrary/pcl/issues/2013 or https://github.com/PointCloudLibrary/pcl/issues/1889).

The errors say that memory, which was allocated, it is tried to free it twice.

Suggest me, if any code hack will solve this, or only tried with update PCL-1.9 library will solve this issue?

Thanks

d_stranz
16th October 2019, 17:07
You are asking these questions on the wrong forum. PCL is out of scope here; you need to find a PCL forum to post your questions. You might be the only person here who is using PCL, and even if you aren't you are probably the only one who is trying to use it in this way.