Skip to content

Commit

Permalink
Merge pull request #1 from alja/overlay
Browse files Browse the repository at this point in the history
Introduce overlay scene in GlViewerRCore and integrate it in RenderQu…
  • Loading branch information
Waad4254 authored Oct 26, 2023
2 parents 2ac9f0f + fe12f37 commit 250d0f7
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 8 deletions.
4 changes: 4 additions & 0 deletions graf3d/eve7/inc/ROOT/REveScene.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected:
std::vector<SceneCommand> fCommands; ///<!

bool fMandatory{true};
bool fIsOverlay{false};
// void RetransHierarchicallyRecurse(REveElement* el, const REveTrans& tp);

public:
Expand Down Expand Up @@ -122,6 +123,9 @@ public:
bool GetMandatory() { return fMandatory; }
void SetMandatory(bool x) { fMandatory = x; }

bool GetIsOverlay() { return fIsOverlay; }
void SetIsOverlay(bool x) { fIsOverlay = x; }

void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action);
};

Expand Down
1 change: 1 addition & 0 deletions graf3d/eve7/src/REveScene.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ REveScene::~REveScene()
int REveScene::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
{
j["Mandatory"] = fMandatory;
j["IsOverlay"] = fIsOverlay;

return REveElement::WriteCoreJson(j, rnr_offset);
}
Expand Down
113 changes: 113 additions & 0 deletions tutorials/eve7/overlay_test.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/// \file
/// \ingroup tutorial_eve
/// Demonstrates usage of TEveBox class.
///
/// \image html eve_box.png
/// \macro_code
///
/// \author Matevz Tadel
#include <ROOT/REveBox.hxx>
#include <ROOT/REveScene.hxx>
#include <ROOT/REveManager.hxx>

using namespace ROOT::Experimental;
const Double_t kR_min = 240;
const Double_t kR_max = 250;
const Double_t kZ_d = 300;

void makeTracks(int N_Tracks,REveElement* trackHolder)
{
TRandom &r = *gRandom;
auto prop = new REveTrackPropagator();
prop->SetMagFieldObj(new REveMagFieldDuo(350, 3.5, -2.0));
prop->SetMaxR(300);
prop->SetMaxZ(600);
prop->SetMaxOrbs(6);
// Default is kHelix propagator.
// prop->SetStepper(REX::REveTrackPropagator::kRungeKutta);

double v = 0.5;
double m = 5;

for (int i = 0; i < N_Tracks; i++)
{
auto p = new TParticle();

int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
p->SetPdgCode(pdg);

p->SetProductionVertex(r.Uniform(-v,v), r.Uniform(-v,v), r.Uniform(-v,v), 1);
p->SetMomentum(r.Uniform(-m,m), r.Uniform(-m,m), r.Uniform(-m,m)*r.Uniform(1, 3), 1);
auto track = new REveTrack(p, 1, prop);
track->MakeTrack();
track->SetMainColor(kBlue);
track->SetName(Form("RandomTrack_%d", i));
track->SetLineWidth(3);
trackHolder->AddElement(track);
}
}

REveElement* makeBox(Float_t a=10, Float_t d=5, Float_t x=0, Float_t y=0, Float_t z=0)
{

TRandom& r = * gRandom;
auto b = new REveBox;
b->SetMainColor(kCyan);
b->SetMainTransparency(0);

#define RND_BOX(x) r.Uniform(-(x), (x))
b->SetVertex(0, x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d));
b->SetVertex(1, x - a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d));
b->SetVertex(2, x + a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d));
b->SetVertex(3, x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d));
b->SetVertex(4, x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d));
b->SetVertex(5, x - a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d));
b->SetVertex(6, x + a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d));
b->SetVertex(7, x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d));
#undef RND_BOX

return b;
}


void makeJets(int N_Jets, REveElement *jetHolder)
{
TRandom &r = *gRandom;

for (int i = 0; i < N_Jets; i++)
{
auto jet = new REveJetCone(Form("Jet_%d",i ));
jet->SetCylinder(2*kR_max, 2*kZ_d);
jet->AddEllipticCone(r.Uniform(-0.5, 0.5), r.Uniform(0, TMath::TwoPi()),
0.1, 0.2);
jet->SetFillColor(kRed);
jet->SetLineColor(kRed);

jetHolder->AddElement(jet);
}
}


void overlay_test()
{
auto gEve = REveManager::Create();

TRandom& r = * gRandom;

// add box to overlay
REveScene* os = gEve->SpawnNewScene("OverlyScene", "OverlayTitle");
os->SetIsOverlay(true);



auto jetHolder = new REveElement("jets");
makeJets(2,jetHolder);
gEve->GetEventScene()->AddElement(jetHolder);


auto trackHolder = new REveElement("Tracks");
gEve->GetEventScene()->AddElement(trackHolder);
makeTracks(100, trackHolder);

gEve->Show();
}
5 changes: 3 additions & 2 deletions ui5/eve7/controller/GL.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ sap.ui.define([
//==============================================================================

/** returns container for 3d objects */
getSceneContainer: function(scene_name)
getSceneContainer: function(scene)
{
let parent = this.viewer.get_top_scene();
let parent = scene.IsOverlay ? this.viewer.get_overlay_scene() : this.viewer.get_top_scene();
let scene_name = "scene" + scene.id;

for (let k = 0; k < parent.children.length; ++k)
{
Expand Down
12 changes: 7 additions & 5 deletions ui5/eve7/lib/EveScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
/** method insert all objects into three.js container */
redrawScene()
{
let eveScene = this.mgr.GetElement(this.id);
console.log("redraw scene OVERLAY ?? ", eveScene);
if (!this.glctrl) return;

let res3d = this.create3DObjects(true);
if ( ! res3d.length && this.first_time) return;

let cont = this.glctrl.getSceneContainer("scene" + this.id);
let cont = this.glctrl.getSceneContainer(this);
while (cont.children.length > 0)
cont.remove(cont.children[0]);

Expand All @@ -149,7 +151,7 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
{
if (!this.glctrl) return;

let cont = this.glctrl.getSceneContainer("scene" + this.id);
let cont = this.glctrl.getSceneContainer(this);
while (cont.children.length > 0)
cont.remove(cont.children[0]);

Expand Down Expand Up @@ -212,7 +214,7 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
if ( ! obj3d) return;

// let scene = this.mgr.GetElement(this.id);
let container = this.glctrl.getSceneContainer("scene" + this.id);
let container = this.glctrl.getSceneContainer(this);

container.add(obj3d);

Expand All @@ -224,7 +226,7 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
replaceElement(el) {
if (!this.glctrl) return;

let container = this.glctrl.getSceneContainer("scene" + this.id);
let container = this.glctrl.getSceneContainer(this);

try {
let obj3d = this.getObj3D(el.fElementId);
Expand Down Expand Up @@ -257,7 +259,7 @@ sap.ui.define(['rootui5/eve7/lib/EveManager'], function(EveManager) {
continue;
}

let container = this.glctrl.getSceneContainer("scene" + this.id);
let container = this.glctrl.getSceneContainer(this);
container.remove(obj3d);

this.id2obj_map.delete(elId);
Expand Down
16 changes: 15 additions & 1 deletion ui5/eve7/lib/GlViewerRCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ sap.ui.define([
{
return this.scene;
}
get_overlay_scene()
{
return this.overlay_scene;
}

//==============================================================================

Expand Down Expand Up @@ -144,6 +148,7 @@ sap.ui.define([

this.renderer.clearColor = '#' + this.bgCol.getHexString() + '00';
this.scene = new RC.Scene();
this.overlay_scene = new RC.Scene();

this.lights = new RC.Group;
this.lights.name = "Light container";
Expand Down Expand Up @@ -218,7 +223,7 @@ sap.ui.define([

this.rot_center = new RC.Vector3(0,0,0);

this.rqt = new RC.RendeQuTor(this.renderer, this.scene, this.camera);
this.rqt = new RC.RendeQuTor(this.renderer, this.scene, this.camera, this.overlay_scene);
if (this.RQ_Mode == "Direct")
{
this.rqt.initDirectToScreen();
Expand Down Expand Up @@ -637,6 +642,15 @@ sap.ui.define([

this.rqt.render_main_and_blend_outline();

// XXXX here add rendering of overlay, e.g.:
if (this.rqt.queue.used_fail_count == 0 && this.overlay_scene.children.length > 0) {
this.rqt.render_overlay_and_blend_it();
}
// YYYY Or, it might be better to render overlay after the tone-mapping.
// Eventually, if only overlay changes, we don't need to render the base-scene but
// only overlay and re-merge them. Need to keep base textures alive in RendeQuTor.
// Note that rgt.render_end() releases all std textures.

if (this.rqt.queue.used_fail_count == 0) {
this.rqt.render_tone_map_to_screen();
// this.rqt.render_final_to_screen();
Expand Down

0 comments on commit 250d0f7

Please sign in to comment.