Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
geom_threejs.cxx File Reference

Detailed Description

The tutorial demonstrates how three.js model for geometry can be created and displayed.

In geom_threejs.cxx one uses RGeomDescription class from geometry viewer, which produces JSON data with all necessary information. Then RWebWindow is started and this information provided. In client.html one uses build function to create Object3D with geometry Then such object placed in three.js scene and rendered. Also simple animation is implemented

std::shared_ptr<ROOT::RWebWindow> window;
TString base64;
void ProcessData(unsigned connid, const std::string &arg)
{
if (arg == "get") {
// send arbitrary text message
window->Send(connid, base64.Data());
} else if (arg == "halt") {
// terminate ROOT
window->TerminateROOT();
}
}
void geom_threejs()
{
TGeoManager::Import("https://root.cern/files/cms.root");
data.Build(gGeoManager, "CMSE");
std::string json = data.ProduceJson();
base64 = TBase64::Encode(json.c_str());
// create window
// configure default html page
// either HTML code can be specified or just name of file after 'file:' prefix
std::string fdir = __FILE__;
auto pos = fdir.find("geom_threejs.cxx");
if (pos > 0)
fdir.resize(pos);
else
fdir = gROOT->GetTutorialsDir() + std::string("/webgui/geom/");
window->SetDefaultPage("file:" + fdir + "geom_threejs.html");
// this is call-back, invoked when message received from client
window->SetDataCallBack(ProcessData);
window->SetGeometry(800, 600); // configure predefined geometry
window->Show();
}
nlohmann::json json
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
R__EXTERN TGeoManager * gGeoManager
#define gROOT
Definition TROOT.h:406
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4626
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
TGeoVolume * GetVolume(const char *name) const
Search for a named volume. All trailing blanks stripped.
void DefaultColors()
Set default volume colors according to A of material.
void SetTransparency(Char_t transparency=0)
Definition TGeoVolume.h:376
void InvisibleAll(Bool_t flag=kTRUE)
Make volume and each of it daughters (in)visible.
void SetLineColor(Color_t lcolor) override
Set the line color.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
Author
Sergey Linev

Definition in file geom_threejs.cxx.