render not work
whu-lee opened this issue · 3 comments
whu-lee commented
I'm using bpy to render a 3D model into a PNG image. I have the same problem as #51, so I add the following code
bpy.context.scene.render.engine = 'CYCLES'
But the resulting image has a box in the middle. How should I change the code?
Thank you very much
I am also on Windows 10 x64 ,python 3.7
`
import bpy
import os
import math
import numpy as np
import glob
from os import listdir
from os.path import isfile, join
context = bpy.context
models_path = "E:\\data\\ModelNet40"
models = sorted(glob.glob(models_path + "/*/*/*.off"))
nviews = 12
scene = bpy.context.scene
missed_models_list = []
for model_path in models:
print(model_path)
command = 'e:/antiprism/off2obj ' + model_path[:-4] + '.off -o ' + model_path[:-4] + '.obj'
model_path = model_path[:-4] + '.obj'
os.system(command)
try:
bpy.ops.import_scene.obj(filepath=model_path, filter_glob="*.obj")
except:
missed_models_list.append(model_path)
continue
imported = bpy.context.selected_objects[0]
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
maxDimension = 5.0
scaleFactor = maxDimension / max(imported.dimensions)
imported.scale = (scaleFactor, scaleFactor, scaleFactor)
imported.location = (0, 0, 0)
imported.rotation_mode = 'XYZ'
views = np.linspace(0, 2 * np.pi, nviews, endpoint=False)
print(views)
for i in range(nviews):
imported.rotation_euler[2] = views[i]
imported.rotation_euler[0] = np.pi
filename = model_path.split("/")[-1]
print(filename)
bpy.ops.view3d.camera_to_view_selected()
context.scene.render.filepath = model_path + "_whiteshaded_v" + str(i) + ".png"
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.render.render(write_still=True)
meshes_to_remove = []
for ob in bpy.context.selected_objects:
meshes_to_remove.append(ob.data)
bpy.ops.object.delete()
# Remove the meshes from memory too
for mesh in meshes_to_remove:
bpy.data.meshes.remove(mesh)
imported = None
del imported
`
TylerGubala commented
Just like Blender, when bpy is imported there will probably be the default
cube as part of the new scene.
You'll need to delete that to see the cube go away.
…On Tue, May 11, 2021, 10:52 AM whu-lee ***@***.***> wrote:
I'm using bpy to render a 3D model into a PNG image. I have the same
problem as #51 <#51>, so I
add the following code
bpy.context.scene.render.engine = 'CYCLES'
But the resulting image has a box in the middle. How should I change the
code?
Thank you very much
I am also on Windows 10 x64 ,python 3.7
[image: airplane_0627 obj_whiteshaded_v0]
<https://user-images.githubusercontent.com/69310975/117836141-04866380-b2ab-11eb-81ce-1c1b9d5900f1.png>
`
import bpy
import os
import math
import numpy as np
import glob
from os import listdir
from os.path import isfile, join
context = bpy.context
models_path = "E:\\data\\ModelNet40"
models = sorted(glob.glob(models_path + "/*/*/*.off"))
nviews = 12
scene = bpy.context.scene
missed_models_list = []
for model_path in models:
print(model_path)
command = 'e:/antiprism/off2obj ' + model_path[:-4] + '.off -o ' + model_path[:-4] + '.obj'
model_path = model_path[:-4] + '.obj'
os.system(command)
try:
bpy.ops.import_scene.obj(filepath=model_path, filter_glob="*.obj")
except:
missed_models_list.append(model_path)
continue
imported = bpy.context.selected_objects[0]
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
maxDimension = 5.0
scaleFactor = maxDimension / max(imported.dimensions)
imported.scale = (scaleFactor, scaleFactor, scaleFactor)
imported.location = (0, 0, 0)
imported.rotation_mode = 'XYZ'
views = np.linspace(0, 2 * np.pi, nviews, endpoint=False)
print(views)
for i in range(nviews):
imported.rotation_euler[2] = views[i]
imported.rotation_euler[0] = np.pi
filename = model_path.split("/")[-1]
print(filename)
bpy.ops.view3d.camera_to_view_selected()
context.scene.render.filepath = model_path + "_whiteshaded_v" + str(i) + ".png"
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.render.render(write_still=True)
meshes_to_remove = []
for ob in bpy.context.selected_objects:
meshes_to_remove.append(ob.data)
bpy.ops.object.delete()
# Remove the meshes from memory too
for mesh in meshes_to_remove:
bpy.data.meshes.remove(mesh)
imported = None
del imported
`
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#94>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFLEYR5FUMPP54FM7VXL4ILTNFAB7ANCNFSM44VXNGOQ>
.
whu-lee commented
Sorry I'm not very familiar with Blender.
Thank you very much. It really helps.
TylerGubala commented
No need to apologize and happy coding
…On Wed, May 12, 2021, 11:06 PM whu-lee ***@***.***> wrote:
Sorry I'm not very familiar with Blender.
Thank you very much. It really helps.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#94 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFLEYR35RRYTPPKLOZM6FFDTNM62VANCNFSM44VXNGOQ>
.