[SOLVED] Screenshot with a camera and not the canvas

Ya that was, my last option, but we are hoping for something better.

Render target, like you said looked like a nice solution, but turning a texture to an image is challenging. If you figure it out let me know! :slight_smile:

Finally done it after some posted in an old thread of someone else trying to do the same thing

https://playcanvas.com/project/605131/overview/capturing-screenshot-from-camera

WOW, i’ve been strungling with this. I was able to render the camera to texture, but not an image.
Thank you so make @yaustar !

Hey @yaustar,

I see you use layer with the renderTarget, but with that I am finding hard to have multiple cameras. I am trying to have multiple hidden camera screenshot.

What problems are you running into?

well I am trying to get like 6 screenshots from different cameras with one click of a button.

I tried by having the 6 camera in the same layer, but enabling them one at a time to get one screenshot for each. that did not work, the screenshot were just blank.

I tried by having 6 camera enabled at the start each in different layer but this happened.

looks like Playcanvas doesn’t like the fact that I have more then one enabled camera, but in your project you had another one to, so I am confused

nevermind for the second part the error, it was because the light was not reliated to all the layers

For this, chances are that you will need to at least wait for one render frame before taking the screen shot.

I see if I can get this working in the demo.

Done. https://playcanvas.com/project/605131/overview/capturing-screenshot-from-camera

Basically used the same camera and moved it each render frame to a new position.

1 Like

Building on top of this solution: Instead of setting the renterTaget of a layer to the texture, you can directly set the renderTarget of the screenshot camera to the texture. Then you don’t have to create another layer and tag every object you want to see in the screenshot.

(I would have commented directly on the demo project, but the devlog is empty, so I can’t.)

2 Likes

Ah yes, I think the render pipeline recently changed to allow for this now

Interesting, but I am not sure what will change in @yaustar’s demo:

In camera-to-texture.js, I’m not even sure how these lines are working and how they need to change. The variable layer is not used elsewhere, but still, changing the renderTarget of that object change the behavior.

var layer = this.app.scene.layers.getLayerByName(this.layerName);
layer.renderTarget = this.renderTarget;

You can replace those two lines with

this.cameraEntity.camera.renderTarget = this.renderTarget;

The renderTarget is basically the place where the calculated pixels should be drawn. The original approach used a layer to mark all included objects, which is a bit more cumbersome. With the camera renderTarget everything seen by this camera is drawn to the renderTarget (screenshot texture).

2 Likes

Great! Thank you, exactly what I was looking for. :slight_smile:

Hello!

Trying this and I always have 3 reversed image that are the same? did this example fall behind the engine upgrades maybe?

Is it supposed to get a camera view screenshot?

thanks for the support.

ha! this seem to fix the problem!

Thank you!

Oh, my personal project (before I joined PlayCanvas again) is way outdated.

The official one should work: Capturing a screenshot | Learn PlayCanvas

1 Like

Amazing project, I was in need to be able to take screenshot from a camera view. Not all the canvas.

Thank you for sharing. It work just fine!

A post was split to a new topic: How to add screenshot to a material