I am aware that aframe commonly uses one single scene only (except when using iframe) - However, I was wondering if it would be possible to have it show two different scenes and a slider that could show one scene on the left of the slider and the other scene in the right.
This is an example using ThreeJS:
https://codepen.io/looeee/pen/jpebjN
This code uses multiple scenes like this:
function render() {
renderer.setScissor( 0, 0, sliderPos, window.innerHeight );
renderer.render( sceneL, camera );
renderer.setScissor( sliderPos, 0, window.innerWidth, window.innerHeight );
renderer.render( sceneR, camera );
}
I have been trying to figure out solutions that could use aframe to make this happen, but I hit roadblocks every time... Before I go a full threejs route I thought I'd ask here and see if anyone has other ideas.
Thanks!
It can be done in THREEjs and Aframe is built on top, so the answer is that it can be done.
Here is the example for how it is done in THREEjs.
https://threejs.org/examples/webgl_multiple_views.html
Related
I am looking for a way to load an AFrame Scene through the click on a thumb.
I am trying to use a picture slider, and every picture should have a 3d scene behind it. So if i click a picture in the slider, the aframe scene should pop up in the foreground, with a different sky texture for example.
I tried multiple ways, but nothing really works. I can load a new scene through a new window, but that's not a good way.
I would appreciate any help that could lead me on the right path. :) :D
Cheers, Max
Have an A-Frame scene in the background (or somewhere on the page) <a-scene embedded style="z-index: -1"></a-scene>. On the click of the picture, set the scene's z-index to the foreground and change whatever else you need in the scene to match the picture.
var aframeScene = AFRAME.scenes[0];
yourPic.addEventListener('click', function () {
aframeScene.style.zIndex = 9999;
aframeScene.querySelector('a-sky').setAttribute('src', 'newImage.jpg');
});
Hi guys I'm totally new to Unity3D. I'm trying to create a scrollable button list where users can scroll through a list of buttons inside a panel. So I have a OnGUI function and inside of it I created some buttons that are of the same width and height. Their Y-axis position is separated by about 55 units each. This is all done in Unity's C# script. I attached the script to a panel and that panel is also attached with a vertical scrollbar. I added the Mask component in the panel where I unchecked the Show Mask Graphic. But when I click play, the buttons do not show up at all. Is it possible to create a scrollbar inside the script and attach to the button list? Thanks
Ok I would highly advise you use the new Unity UI system instead of using Immediate Mode GUI (OnGui functions). You can still control things programatically with ease but it is much easier with a canvas to work with.
You mention using panels and masks but they don't mix with the OnGui setup, that is the legacy UI system and should only be used for Unity editor plug ins.
That said there are great learning resources which cover exactly what you need in these three tutorials on the Unity site:
Scroll Rect Tutorial
Scroll Bar Tutorial
UI Mask Tutorial
And if you have not got any experience using the newer system the main tutorial page is here.
I hope that helps.
Try this code:
(taken from the Unity Script Reference for GUI.BeginScrollView)
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Vector2 scrollPosition = Vector2.zero;
void OnGUI() {
scrollPosition = GUI.BeginScrollView(new Rect(10, 300, 100, 100), scrollPosition, new Rect(0, 0, 220, 200));
GUI.Button(new Rect(0, 0, 100, 20), "Top-left");
GUI.Button(new Rect(120, 0, 100, 20), "Top-right");
GUI.Button(new Rect(0, 180, 100, 20), "Bottom-left");
GUI.Button(new Rect(120, 180, 100, 20), "Bottom-right");
GUI.EndScrollView();
}
}
If its in game, I don't recommend OnGUI, rather use the Unity UI components. There is good video on how to create scrolalble lists here:
https://www.youtube.com/watch?v=lUun2xW6FJ4
You can add buttons to the vertical or horizontal group easily from editor or from code. You just instantiate button prefabs and place them inside the horizontal group parent.
GameObject horLayoutGroup;
GameObject buttonPrefab;
var myButton = Instantiate(buttonPrefab, new Vector3(default), Quaternion.identity);
myButton.transform.SetParent(horLayoutGroup.transform)
this will automatically scale the entire layout group and place everything neatly next to each other, without having to play with pixel offset.
If you want to add a function to a button, you use the following code:
myButton = GetComponent<Button>();
myButton.onClick.RemoveAllListeners();
myButton.onClick.AddListener(() => SomeClassInstance.PublicFunction);
myButton.onClick.AddListener(() => SomeOtherClassInstance.AnotherPublicFunction);
I get a small triangle in left bottom corner or right top corner of the QPushButton I am using. I am not sure how it is showing up. I am just using simple PushButton. I needed same kind of thing for my custom widget derived from QWidget.
I wanted to know is there any flag to set this or do I need to implement explicitly ? Looks like a page turn symbol we see in some online pdf's.
I am kind of new to Qt. Please answer.
The small triangle indicates that the QPushButton has a popup menu associated: QPushButton::setMenu().
If you want to add a triangle, you can use stylesheet or reimplement QWidget::paintEvent() to paint the triangle in a corner. A basic example:
void Widget::paintEvent( QPaintEvent* event ) {
QWiudget::paintEvent( event );
QPainter painter( this );
QPolygon p();
p.append( QPoint(10, 10) );
p.append( QPoint(14, 10) );
p.append( QPoint(12, 14) );
painter.drawPolygon( p );
}
But, I think, a better solution would be adding a QPushButton to your widget. It would be easier to detect a click on your triangle...
I am using qt 5.0.1 in windows. I am creating 200k+ custom QGraphicsItem. I have added basic functionalists in these custom items, like mouse hover, mouse click etc.. This items are static. But on top of these items I add some items (200 max) which animates (different property animation, scale, opacity etc).
When I add those items in the scene it become extremely slow, in a relatively powerful workstation.
QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0, 0, width, height);
scene->setBackgroundBrush(Qt::darkGray);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
QGraphicsView *view = new QGraphicsView( scene );
view->setRenderHint(QPainter::Antialiasing, false);
view->setResizeAnchor(QGraphicsView::AnchorViewCenter);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->resize( width, height );
view->setOptimizationFlags(QGraphicsView::DontSavePainterState);
view->setViewportUpdateMode( QGraphicsView::SmartViewportUpdate);
view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate);
view->show();
I have tried the following, but it makes the rendered view extremely bad, as it seems to enable antialiasing, but I need some pixel label precision.
view->setViewport(new QGLWidget( QGLFormat(QGL::SampleBuffers)));
Am I missing some important Qt programming tricks? Please suggest. I can post the code, or explain more if in case please let me know. Thanks in advance.
When you have a lot of items, the bottleneck is when you have them many on the screen at the same time, which would mean they are fairly small. In such cases, it is advisable to resort to using different LOD - that's level of details. When the item is small, draw a simplified version of it. Combine that with LOD baking and caching and an OpenGL widget to draw onto and you could easily get tens or even hundreds of thousands items at a time.
In my QGraphicsView, I display a map. I need to display a horizontal ruler and a vertical ruler on the top edge and left edge respectfully.
The map needs to scrolled but the above rulers should be displayed at their fixed positions, but change their scale values.
I tried to implement this using drawForeground method. Due to the maps large size I only paint the visible area. So I need to update() every time scrolling is done. But this result sometimes flickers.
I feel it would be best to have separate layer like approach.
What is the best way to approach the problem?
The correct way to implement a ruler on the top and left is to derive from QGraphicsView, and then call in the constructor:
// add two rulers on top and left.
setViewportMargins(20, 20, 0, 0);
// add grid layout
QGridLayout* gridLayout = new QGridLayout();
gridLayout->setSpacing(0);
gridLayout->setMargin(0);
// create rulers
hRuler = new Ruler(Qt::Horizontal);
vRuler = new Ruler(Qt::Vertical);
// add items to grid layout
QWidget* corner = new QWidget();
corner->setBackgroundRole(QPalette::Window);
corner->setFixedSize(20, 20);
gridLayout->addWidget(corner, 0, 0);
gridLayout->addWidget(hRuler, 0, 1);
gridLayout->addWidget(vRuler, 1, 0);
gridLayout->addWidget(viewport(), 1, 1);
// finally set layout
setLayout(gridLayout);
This solution was initially presented here, and it works very well. The result looks like this.
I just changed ViewportUpdateMode of the graphics view to FullViewportUpdate to get away from flicker.
You can use SmartViewportUpdate for somewhat good results also.
The downside is, during animations, this takes more process power.