You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the following code i create an offscreen renderer to create a few folders with renders at different angles. I want these images to be 180x180 so i use offscreen_renderer.SetSize(180, 180)
my code:
importos.pathimportrandomimportsysfromOCC.Core.STEPControlimportSTEPControl_ReaderfromOCC.Display.OCCViewerimportViewer3dfromOCC.Core.IFSelectimportIFSelect_RetDone, IFSelect_ItemsByEntityfromOCC.Extend.ShapeFactoryimportrotate_shp_3_axisinput_dir="./input/"output_dir="./output/"# create the rendereroffscreen_renderer=Viewer3d()
# by default, the offscreenrenderer size is 640*480offscreen_renderer.Create()
offscreen_renderer.SetModeWireFrame()
offscreen_renderer.EnableAntiAliasing()
offscreen_renderer.SetSize(180, 180)
defread_step_file(filename):
# read the STEP file and returns a compoundstep_reader=STEPControl_Reader()
status=step_reader.ReadFile(os.path.join(input_dir+filename))
ifstatus==IFSelect_RetDone: # check statusfailsonly=Falsestep_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
step_reader.TransferRoot(1)
a_shape=step_reader.Shape(1)
else:
print("Error: can't read file.")
sys.exit(0)
returna_shapedefrandom_rotate_shape(shape):
angle_x=random.random() *360angle_y=random.random() *360angle_z=random.random() *360returnrotate_shp_3_axis(shape, angle_x, angle_y, angle_z, "deg")
defrender_file(filename, amount):
# create shape from .stpshape=read_step_file(filename)
output_dir_path=os.path.join(output_dir+filename.split(".")[0])
ifnotos.path.exists(output_dir_path):
os.makedirs(output_dir_path)
foriinrange(amount):
# give the shape a random rotationshape=random_rotate_shape(shape)
# send the shape to the rendereroffscreen_renderer.DisplayColoredShape(shape, color='WHITE', update=True)
output_name=os.path.join(output_dir_path+"/"+filename.split(".")[0] +"("+str(i) +").png")
# export the current shape to an imageoffscreen_renderer.ExportToImage(output_name)
offscreen_renderer.EraseAll()
if__name__=="__main__":
forfilenameinos.listdir(input_dir):
render_file(filename, 5)
all images generated with this code are 196x219 not 180x180
using offscreen_renderer.SetSize(1920, 1080)
results in images that are 1936x1119
The text was updated successfully, but these errors were encountered:
I retested the same code on my machine again and it still doesn't work. Could it be a windows issue? Did you try my code or could it be that I missed something?
pythonocc-core: 7.7.2
Using the following code i create an offscreen renderer to create a few folders with renders at different angles. I want these images to be 180x180 so i use
offscreen_renderer.SetSize(180, 180)
my code:
all images generated with this code are 196x219 not 180x180
using
offscreen_renderer.SetSize(1920, 1080)
results in images that are 1936x1119
The text was updated successfully, but these errors were encountered: