Help with dynamic texture

Can some one help me out, maybe it’s a camera setting ?
I’m trying to render a dynamic texture imprinted on an object with render to texture.
The render to texture function works and projects the image from a camera that takes feed from some objects in the scene, but with the other camera in the scene pointed at the plane/wall I’m trying to render to file the image captured on the wall.

When I start the game engine the texture shows up fine in my cam view and I get a view on the wall from the other camera that takes feed from some objects in the scene. It’s sort of like a security cam, one cam takes image and imprints in on a wall that is sort of the monitor, and the other camera is pointed at the monitor wall to view it, like looking on a tv, problem is when I save to file the wall is blank in the image I saved and the dynamic texture is not there. But while I’m in the game viewing the texture is projected as a feed from the other camera.

I save with bpy render.render function to file. Can it be some camera setting ? or something else.
It works with screenshot function, but I have no way of controling screenshot function, I have to log in manually in the camera , where as with render.render the camera takes pictures and saves to file without me touching anything, setting viewport and so on, moving the scene.

Why is the dynamic texture not shown in the images I save ?
I want to take picture with camera that is pointed at the wall/monitor where the texture is imprinted.

Here is what I’m using.
scene = bpy.context.scene
bpy.context.scene.camera = bpy.context.scene.objects[“Camera”]

scene.render.resolution_x = 320
scene.render.resolution_y = 240
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = ‘JPEG’
scene.render.filepath = “/temp/”
bpy.ops.render.render(write_still = 1)

Saves image without the texture on the wall in the game engine .
It takes picture of wall from camera view regardless if I’m in or out of this camera view.
I can have set up multiple cameras each doing their thing like capturing scense from the game.

makescreenshot you have to log in manually in the camera view, but if I do log inside the camera view and I press start game it saves to file the image with the dynamic texture on it, like I saw it live in the game, I have no way of controlling screenshot function. I have to point manually where I want to take screenshot and then press start game engine.

what version of the game engine are you using? the reason i ask is that the only version of the game engine that supports using bpy is UPBGE 0.3, all older ones do not.

The latest edderkop, alpha 3.
I could upload the blend file if you think you can help.
I can give you the whole code if you want.

import bge
import bpy


controller = bge.logic.getCurrentController()
own = controller.owner

## get current scene
scene = bge.logic.getCurrentScene()  

# check to see variable RenderToTexture has been created
if "RenderToTexture" in own:
    
 # update the texture
 own["RenderToTexture"].refresh(True)

# if variable RenderToTexture hasn't been created
else:
  
 # import VideoTexture module
 import VideoTexture
    
 # get a list of objects in the scene
 ownList = scene.objects
    
 cameraName = own['cam']

 cam = scene.cameras[cameraName]
 print(cameraName)

 # get the texture material ID
 matID = bge.texture.materialID(own, "MA" + own['material'])

 # set the texture 
 renderToTexture = VideoTexture.Texture(own, matID)

 # Source to refresh to change the texture with the view cam.
 renderToTexture.source = VideoTexture.ImageRender(scene,cam)

 # save RenderToTexture as an object variable for loop to carry it each loop around.
 own["RenderToTexture"] = renderToTexture
 

 #######################
# The other code part with the other camera that saves what the other camera recorded on the wall.

#Defining contextual objects from the scene I want.
scene = bpy.context.scene
bpy.context.scene.camera = bpy.context.scene.objects["Camera"]

scene.render.resolution_x = 320
scene.render.resolution_y = 240
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = 'JPEG'
scene.render.filepath = "/Users/me/Downloads/temp/a.JPEG"
bpy.ops.render.render(write_still = 1)

There is more but this is the important part. Rest is to store data to array for use later on data image work.

So this code works, changes texture live, every frame over and over, works with the other camera that records and feeds the Monitor, second camera just takes a snap shot of the monitor but does not record the texture modified on the monitor/wall, but in live view inside the game it’s all there, if you move inside the camera the texture is there on the monitor shown.

The camera records anyway, so this option is ideal, it records even if you are not in the port view, it works in the background and saves image, while makescrenshot does save a file with the texture on the wall you have no way to manipulate it, you have to be in viewport other wise it just takes snap shot of the scene. You can not control it, it just prints the screen of where you are in the scene positioned.

I forgot to mention does the same even if you switch to viewport and you have in front of you the texture, does the same thing it records the wall without anything on it, you end up with a file that has just a gray wall like it’s colored before you apply the texture.

If I put a static texture on the wall, regular texture okay, it saves it with the texture.
So it does not like the dynamic texture.

No errors in the console. Maybe there are some camera settings ? I don’t know about.

Imagine what you can do, mix images with lots of cameras recording in different places and mix it on the wall and grab an mage from there to work with. Make stereo camera view matrix.

have you tried render from the active camera (view from player)

I have 3 cameras, they have to be unactive camera, passive cameras or it does not work at all.
But yes I switched the one that looks at the wall and made it active just to see what happens. For video texture the camera that takes the live feed and sends it to the wall that changes textures is absolutly necessary for it to be unactive or it does not work at all.

The camera that looks at the wall, I tried yep to make it active, set it as active cam.
The last of the 3 stays active cam, it does not do anything, so the other two remain unactive that work with the script

the thing i was trying to figure out is if the video texture is culled when not seen by player. (performane in game)

When I want to look at the texture in front I make that one active, and it works.
But if I zoom out of the camera , out of it and run the script like this it no longer takes shots if it remains active, it has to stay unactive while out of it or otherwise it does not take shots in the background. To see the texture active on the wall you have to be in the camera, make it active, that is when you are in the game, and when out when it captures undisturbed it has to be set as unactive.

In other older blenders you could see the texture when you were not in camera also, now only when you are inside the camera you can see it active on the wall, but when it takes snap shots in the backgorund when you are not inside of it, it captures the view port so it should work.

culled as in set as a standard texture ? I don’t know, I was asking the colaborators on discord, no answer yet. It’s a dynamic texture so I don’t know. I put effort into getting it to work, the video texture, with an old script from 2.5, lots of things that were not found that I had to guess in the logical editor. Took me a week to make it work.

the surface you project the video texture to, does that have a texture applied (and actual picture not blank/black)

It has it’s texture yes, video texture works on the basis of texture replacement, sets the new one dumps the old one and it repeats, with a variable that you make as a python object, it’s constantly replaced. You have to have a texture image there, anything, a blank transparent picture for example that is replaced, it’s actually the same image you set but the texture projects on it frame by frame. This is for ImageRender only. other bge.texture formats you can change pictures.

i know how it work, what i want to know if it renders the original and not the video texture, that’s why ask if the texture had something to show.

You have to load an image as texture there on the wall with a material, you add material then anything as a texture, I tried many, blank white picture, transparent picture, textured picture, it remains there and the video format imprints on it repeating frame by frame. If it’s a white picture set as texture for the wall/plane for example you can see the projection on the whiteish background. If it’s textured, it will have the texture and the projection on the texture, the texture becomes dimmer.

It changes so fast that the replacement is equal, you see bolth of them, a ghost of the old texture + the videotexture imprinted on the material. If you set a brown color texture for example to be replaced then your background will have this light brownish color with the new one imprinted. It’s sort of a blend of the two with the other dimed out.

I can send you the blend if you want but I have to find somewhere to upload.

is that the result from this ?

yes that is it. 1 is write to file That is not the render of videotexture but the write to file to be saved to disk.

Render of texture is first line inside the IF parameter, the refresh function, it renders the source.

if it is less that 5mb just drag it here in you post.

okay let me see

let me clean the code it’s all sort of stuff added there, to reduce it

how do I drag ?