autoenablesDefaultLighting is too bright in iOS 12 and SCNView.pointOfView is not effective - objective-c

I am using SceneKit’s autoenablesDefaultLighting and allowsCameraControl functions of my sceneView to provide light to an obj 3D model in the app and rotate around this object in Objective-C. Since upgrading to iOS12, the default light intensity of autoenablesDefaultLighting gets higher and the 3D model looks so bright!
Did anyone faced the same issue? If yes, is there a way to control the light intensity of autoenablesDefaultLighting when its value is ‘YES’? If it is not editable, I tried to attach/constraint an omni light or directional light to a camera by creating a node, assign a light to this node and add as child of SCNView.pointOfView but no light illuminates the scene.
Exemple:
3D object displayed before iOS 12
3D object displayed in iOS 12
It will be good if anyone can help me on it.
Many thanks!
Edit to solve this issue
I create a new SCNCamera and add this in a node and set the PointOfView of my scnView.
Activate the HDR of this camera with scnView.pointOfView.wantHDR = YES;
but a had a grey background.
To delete the grey background I delete the background color with scnView.backgroundColor = [UIColor ClearColor]
and set the explosure of the camera to -1 with :
self.scnView.pointOfView.camera.minimumExposure = -1;
self.scnView.pointOfView.camera.maximumExposure = -1;
Thanks

You can try enabling HDR. It should result in a balanced exposure
scnView?.pointOfView?.camera?.wantsHDR = true
With HDR enabled, you can even control exposure compensation with
scnView?.pointOfView?.camera?.exposureOffset

.camera?.wantsHDR = true
.camera?.wantsExposureAdaptation = false
Should solve the problem!

Related

How do I resize an array of squished PyQt5 widgets? [duplicate]

I have a QScrollArea Widget, which starts empty;
It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area;
Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works;
I have turned the vertical scrollbar on all the time, so that when it appears it does not sit on top of the other stuff in there. Note that the scroll bar is larger than the scroll box already though, despite not needing to be.
This is the problem. The scroll area seems to be preset, and i cannot change it. If i add more rows to the QGridLayout, the scroll area doesn't increase in size.
Instead, it stays the same size, and squeezes the QGridLayout, making it look ugly (at first);
And then after adding even more it becomes unusable;
Note that again, the scroll bar is still the same size as in previous images. The first two images are from Qt Designer, the subsequent 3 are from the program running.
If I resize the window so that the QScrollArea grows, then I see this:
Indicating that there's some layout inside the scroll area that is not resizing properly.
My question is; what do I need to do to make the scrollable area of the widget resize dynamically as I add and remove from the QGridLayout?
If you're coming here from Google and not having luck with the accepted answer, that's because you're missing the other secret invocation: QScrollArea::setWidget. You must create and explicitly identify a single widget which is to be scrolled. It's not enough to just add the item as a child! Adding multiple items directly to the ScrollArea will also not work.
This script demonstrates a simple working example of QScrollArea:
from PySide.QtGui import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
inner.layout().addWidget(b)
scroll.show()
app.exec_()
The documentation provide an answer :
widgetResizable : bool
This property holds whether the scroll area should resize the view widget.
If this property is set to false (the default), the scroll area honors the size of its widget.
Set it to true.
Why don't you use a QListView for your rows, it will manage all the issues for you? Just make sure that after you add it you click on the Class (top right window of designer) and assign a layout or it wont expand properly.
I use a QLIstWidget inside a QScrollArea to make a scrollable image list
Try this for adding other objects to the list, this is how I add an image to the list.
QImage& qim = myclass.getQTImage();
QImage iconImage = copyImageToSquareRegion(qim, ui->display_image->palette().color(QWidget::backgroundRole()));
QListWidgetItem* pItem = new QListWidgetItem(QIcon(QPixmap::fromImage(iconImage)), NULL);
pItem->setData(Qt::UserRole, "thumb" + QString::number(ui->ImageThumbList->count())); // probably not necessary for you
QString strTooltip = "a tooltip"
pItem->setToolTip(strTooltip);
ui->ImageThumbList->addItem(pItem);
Update on Artfunkel's answer:
Here's a PySide6 demo that uses a "Populate" button to run the for loop adding items to the scroll area. Each button will also delete itself when clicked.
from PySide6.QtWidgets import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
def on_remove_widget(button):
button.deleteLater()
def populate():
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
b.clicked.connect(b.deleteLater)
inner.layout().addWidget(b)
b = QPushButton(inner)
b.setText("Populate")
b.clicked.connect(populate)
inner.layout().addWidget(b)
scroll.show()
app.exec()

Qt3D Billboards: how to make plane always face to camera

I try to use camera's viewVector to make plane face to camera, but it will turn Clockwise or Counterclockwise when Camera rotate to left or right.
Can I make the plane always face to camera without turning Clockwise or Counterclockwise?
I think camera->upVector() can help me maybe, but I don't how to use.
My code :
class planeTransformClass : public Qt3DCore::QTransform {
public:
planeTransformClass( Qt3DCore::QNode *entity = nullptr ) :Qt3DCore::QTransform(entity) {}
signals:
void faceTo( QVector3D v ) {
setRotation(QQuaternion::rotationTo(QVector3D(0,1,0), -v));
} ;
};
// Background
Qt3DCore::QEntity *planeEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh(planeEntity);
planeMesh->setHeight(2);
planeMesh->setWidth(2);
Qt3DExtras::QTextureMaterial planeMaterial = new Qt3DExtras::QTextureMaterial(planeEntity);
Qt3DRender::QTexture2D *planeTexture = new Qt3DRender::QTexture2D(planeMaterial);
FlippedTextureImage *planeTextureImage = new FlippedTextureImage(planeTexture);
planeTextureImage->setSize(QSize(3000, 3000));
planeTexture->addTextureImage(planeTextureImage);
planeMaterial->setTexture(planeTexture);
planeMaterial->setAlphaBlendingEnabled(true);
// Transform
planeTransformClass planeTransform = new planeTransformClass(planeEntity);
planeTransform->setRotationX(90);
planeTransform->setTranslation(QVector3D(2, 0, 0));
planeEntity->addComponent(planeMesh);
planeEntity->addComponent(planeMaterial);
planeEntity->addComponent(planeTransform);
// connect camera's viewVectorChanged
camera->connect( camera, &Qt3DRender::QCamera::viewVectorChanged,
planeTransform, &planeTransformClass::faceTo);
Solution using geometry shader
There is already a C++ translation this QML code that I tried to translate (using geometry shader):
https://github.com/ismailsunni/qt3d-custom-shader
My own translation can be found here. It works now after solving the issues mentioned in this question.
Solution without geometry shader
I got a different version running based on this bug report. You can find my implementation on GitHub. The billboards don't change their size when the camera moves, i.e. become smaller and larger on screen like every other object, but I hope you can work with that.
On the master branch the images also move for some reason as can be seen in this image:
The no_instanced_rendering branch doesn't use instanced rendering and displays everything correctly.
Edit
I'm sorry I'm not using your example but I don't have time anymore to adjust it. Check out the patch related to the bug report I mentioned. The person implemented a material with this effect, you should be able to extract it and make it run.

BABYLONJS : How to move the camera in front of a mesh

It's my first post in StackOverFlow.
I'm asking for how can I put the camera in front of a mesh.
Context :
my projects is a museum, and when i click in to picture " mesh" , i need the camera get in front of the mesh , so that i can watch the picture.
I tried :
camera.postion = Mesh.position;
Problem :
the camera take the position of the mesh so i cannot see the picture , but i'm in the picture !
Thank you for your help !
You can try to move the camera a bit away from the mesh position.
Something like that:
camera.position = mesh.position.add(new BABYLON.Vector3(0, 0, 5));
camera.target = mesh.position
I found the right solution !
Thank you for your answer ! i did tried before, but it doesn't worked properly !
Solution !
Picture.metadata={};
Picture.metadata.visitorPosition = new BABYLON.Vector3(x,y,z);
if (pickResult.hit){
if(!pickResult.pickedMesh.metadata){return;}
camera.position = pickResult.pickedMesh.metadata.visitorPosition;
camera.setTarget(pickResult.pickedMesh.position);}

Python platypus changing from Portrait to Landscape

I'm looking for some inspiration. I have some code that is changing the orientation of a page from the default portrait to landscape however the frames I create within the pagetemplates always get created as if they are on a portrait page still.
doc = BaseDocTemplate('test2.pdf', pagesize=landscape(A4))
myFrameThresholdLeft = Frame(
doc.leftMargin,
doc.bottomMargin,
doc.width / 2,
doc.height,
showBoundary=1 # set to 1 for debugging
)
emptyTemplate = PageTemplate(id='emptyTemplate',
pagesize=landscape(A4),
frames=[myFrameThresholdLeft,
myFrameThresholdRight],
onPage=emptyLayout)
elements.append(NextPageTemplate('emptyTemplate'))
elements.append(PageBreak())
I think this is because the values returned by the e.g. doc.width methods are not changing as I change the pagesize in the pagetemplate. Can someone put me on the right tracks here?

Can't show more than one map annotation in WatchOS 2.0

I've updated recently an apple watch app to watchOS 2 and I'm facing a strange behaviour involving map annotations. In the previous version I drew two annotations with two images without any problem but now I can see the images only when just one annotation is shown. When I try to add two annotations, the most recent added is not showing the image and show the default pin annotation. Is that a bug? I'm shocked nobody seems to comment this issue.
This is my code:
var distance = currentLocation.distanceFromLocation(aLocation!)
let middleLat = (currentLocation.coordinate.latitude + aLocation!.coordinate.latitude)/2
let middleLon = (currentLocation.coordinate.longitude + aLocation!.coordinate.longitude)/2
let middleCoords = CLLocationCoordinate2DMake(middleLat, middleLon)
self.theMap.removeAllAnnotations()
let region = MKCoordinateRegionMakeWithDistance(middleCoords, distance * 1.6 , distance * 1.3)
self.theMap.addAnnotation(aLocation!.coordinate, withImageNamed: "aAnnotation", centerOffset: CGPoint(x: 0, y: 0))
self.theMap.addAnnotation(currentLocation.coordinate, withImageNamed: "UserAnnotationW", centerOffset: CGPoint(x: 0, y: 0))
self.theMap.setRegion(region)
In this case only image for "aAnnotation" is shown and "UserAnnotation" get the default pin. If I swap lines 7 and 8, the user image is shown instead.
Anyone?
Thx
Well, I've been told in the apple devs forum that in fact this is a bug. So, nothing to worry about if you are in the same case.
Update: Everything back to normal using the new 2.0 GM released today.