Skip to main content
bugfix, does not change my question/problem
Source Link
ntg
  • 227
  • 1
  • 11

I made this toy example to demonstrate the problem i have. I am trying to use BGE to make screenshots of a rotating object for a report. I use a script on the cube to rotate and capture that uses logic to run on the object (e.g. deleted the cube and added a rotated cone - to which I applied the rotation, so in the screenshot it has rotation 0):

enter image description here

import bpy
import bge
from mathutils import *
import numpy as np
import math


cont = bge.logic.getCurrentController()
own = cont.owner
new_q = np.random.randint(4)
if new_q == 0:
    q = Euler((0.0, 0.0, 0.0)).to_quaternion()    
elif new_q == 1:
    q = Euler((0.0, 0.0, math.radians(90.0))).to_quaternion()    
elif new_q == 2:
    q = Euler((0.0, 0.0, math.radians(180.0))).to_quaternion()    
elif new_q == 3:
    q = Euler((0.0, 0.0, math.radians(270.0))).to_quaternion()    
own.worldOrientation = q
fname = 'e:/temp/q_{}-{}.png'.format(new_q,int(np.random.random() * 100000))
ivp = bge.texture.ImageViewport()
ivp.refresh()
print ('saving {}'.format(fname))
bge.render.makeScreenshot(fname)

the script rotates the object and then captures a screenshot: However, when I compare the screenshots, they are not acurate. E.g., files starting with q_0 randomly point to all axes...

Is there any way to enforce a new render so that the saved images have the exact rotation they are supposed to have?

I also tried saving on the next frame (e.g. saving to the global dictionary a flag, and then on the next time the script was called, save then) No joy there either... :S

I made this toy example to demonstrate the problem i have. I am trying to use BGE to make screenshots of a rotating object for a report. I use a script on the cube to rotate and capture that uses logic to run on the object (e.g. deleted the cube and added a rotated cone - to which I applied the rotation, so in the screenshot it has rotation 0):

enter image description here

import bpy
import bge
from mathutils import *
import numpy as np


cont = bge.logic.getCurrentController()
own = cont.owner
new_q = np.random.randint(4)
if new_q == 0:
    q = Euler((0.0, 0.0, 0.0)).to_quaternion()    
elif new_q == 1:
    q = Euler((0.0, 0.0, 90.0)).to_quaternion()    
elif new_q == 2:
    q = Euler((0.0, 0.0, 180.0)).to_quaternion()    
elif new_q == 3:
    q = Euler((0.0, 0.0, 270.0)).to_quaternion()    
own.worldOrientation = q
fname = 'e:/temp/q_{}-{}.png'.format(new_q,int(np.random.random() * 100000))
ivp = bge.texture.ImageViewport()
ivp.refresh()
print ('saving {}'.format(fname))
bge.render.makeScreenshot(fname)

the script rotates the object and then captures a screenshot: However, when I compare the screenshots, they are not acurate.

Is there any way to enforce a new render so that the saved images have the exact rotation they are supposed to have?

I also tried saving on the next frame (e.g. saving to the global dictionary a flag, and then on the next time the script was called, save then) No joy there either... :S

I made this toy example to demonstrate the problem i have. I am trying to use BGE to make screenshots of a rotating object for a report. I use a script on the cube to rotate and capture that uses logic to run on the object (e.g. deleted the cube and added a rotated cone - to which I applied the rotation, so in the screenshot it has rotation 0):

enter image description here

import bpy
import bge
from mathutils import *
import numpy as np
import math


cont = bge.logic.getCurrentController()
own = cont.owner
new_q = np.random.randint(4)
if new_q == 0:
    q = Euler((0.0, 0.0, 0.0)).to_quaternion()    
elif new_q == 1:
    q = Euler((0.0, 0.0, math.radians(90.0))).to_quaternion()    
elif new_q == 2:
    q = Euler((0.0, 0.0, math.radians(180.0))).to_quaternion()    
elif new_q == 3:
    q = Euler((0.0, 0.0, math.radians(270.0))).to_quaternion()    
own.worldOrientation = q
fname = 'e:/temp/q_{}-{}.png'.format(new_q,int(np.random.random() * 100000))
ivp = bge.texture.ImageViewport()
ivp.refresh()
print ('saving {}'.format(fname))
bge.render.makeScreenshot(fname)

the script rotates the object and then captures a screenshot: However, when I compare the screenshots, they are not acurate. E.g., files starting with q_0 randomly point to all axes...

Is there any way to enforce a new render so that the saved images have the exact rotation they are supposed to have?

I also tried saving on the next frame (e.g. saving to the global dictionary a flag, and then on the next time the script was called, save then) No joy there either... :S

Source Link
ntg
  • 227
  • 1
  • 11

ImageViewport.refresh() seems to do nothing / how to re-render in BGE before taking a screenshot

I made this toy example to demonstrate the problem i have. I am trying to use BGE to make screenshots of a rotating object for a report. I use a script on the cube to rotate and capture that uses logic to run on the object (e.g. deleted the cube and added a rotated cone - to which I applied the rotation, so in the screenshot it has rotation 0):

enter image description here

import bpy
import bge
from mathutils import *
import numpy as np


cont = bge.logic.getCurrentController()
own = cont.owner
new_q = np.random.randint(4)
if new_q == 0:
    q = Euler((0.0, 0.0, 0.0)).to_quaternion()    
elif new_q == 1:
    q = Euler((0.0, 0.0, 90.0)).to_quaternion()    
elif new_q == 2:
    q = Euler((0.0, 0.0, 180.0)).to_quaternion()    
elif new_q == 3:
    q = Euler((0.0, 0.0, 270.0)).to_quaternion()    
own.worldOrientation = q
fname = 'e:/temp/q_{}-{}.png'.format(new_q,int(np.random.random() * 100000))
ivp = bge.texture.ImageViewport()
ivp.refresh()
print ('saving {}'.format(fname))
bge.render.makeScreenshot(fname)

the script rotates the object and then captures a screenshot: However, when I compare the screenshots, they are not acurate.

Is there any way to enforce a new render so that the saved images have the exact rotation they are supposed to have?

I also tried saving on the next frame (e.g. saving to the global dictionary a flag, and then on the next time the script was called, save then) No joy there either... :S