How to set viewing a canvas with `X3D` from program

I want to see my canvas in X3D after execution of my program. I could do this by hand:
View->View With->X3D.
But how to do this from program by code?
I read a docs (not very deep) and I saw that gPad->x3d() deprecated so I used

myCanvas->GetViewer3D()

but nothing has been changed.

myCanvas->Update();
myCanvas->GetViewer3D("x3d");

After `c->GetViewer3D(“x3d”) I get Segmentation violation with the following error:

Error in TViewerX3D::InitX3DWindow: view is not set

Note: x3d view works perfectly if I set it by hand.

can you try this macro:. It works for me.

{
   c1 = new TCanvas("c1","Geometry Shapes",200,10,700,500);

   //delete previous geometry objects in case this script is reexecuted
   if (gGeometry) {
      gGeometry->GetListOfNodes()->Delete();
      gGeometry->GetListOfShapes()->Delete();
   }

   //  Define some volumes
   brik = new TBRIK("BRIK","BRIK","void",200,150,150);
   sphe1 = new TSPHE("SPHE1","SPHE1","void",0,140, 0,180, 0,360);
   sphe2 = new TSPHE("SPHE2","SPHE2","void",0,140, 0,180, 0,360);

   //  Set shapes attributes
   brik->SetLineColor(kBlue);
   sphe1->SetLineColor(kRed);
   sphe2->SetLineColor(kYellow);

   //  Build the geometry hierarchy
   node1 = new TNode("NODE1","NODE1","BRIK");
   node1->cd();

   node2  = new TNode("NODE2","NODE2","SPHE1",-200,-150,-140);
   node3  = new TNode("NODE3","NODE3","SPHE2",-400,-400,-400);

   // Draw this geometry in the current canvas
   node1->cd();
   node1->Draw();
   c1->Update();

   c1->GetViewer3D("x3d");
}

I did not try. But after adding

c->Update();

next to GetViewer3D("x3d") it worked. Thank you. Why is this so?

The scene need to be fully rendered before being displayed with x3d.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.