Render issues

I’m getting strange results when I try rending my animation out. I am now trying to render
the viewport using Python, because I can’t seem to get the particles to work right otherwise.
When I render the viewport, I am getting the result I want, but when I render normally or with
python code, I get something different.

This is the viewport:


Rendering using Python code yields this:


If I render it out in the normal way, I get really crappy results, the comet has
no tail, it is just a short blotch of white.

Here is the code I use to render the viewport:

import bpy
scene = bpy.context.scene
bpy.data.scenes[“Scene”].render.image_settings.file_format = ‘PNG’
scene.render.resolution_x = 1920
scene.render.resolution_y = 1080
n = 52 # Frame
bpy.context.scene.frame_set(0)
bpy.context.scene.frame_set(n)
scene.frame_start = n
scene.frame_end = n
bpy.ops.render.render(animation=True)

I’m only rendering one frame because it is just a test, to try to get the render to come out right.
If I try this without setting frames from 0 to n, the particles do not render, that is a side issue though.
The resolution does not change as the code specifies, but the main issue is, why is the viewport
rendering particles correctly, and the render that I do using code or just rendering normally . . . .
different?

**** I have attached the .blend file here, but you have to run the script in the text
editor to make the animation run and work properly. **** Just in case it is not contained
with the .blend file, I am listing it below:

import bpy, os
create = False
def addParticles(objName):
bpy.ops.object.select_pattern(pattern=objName)
bpy.context.scene.objects.active = bpy.data.objects[objName]
bpy.ops.object.particle_system_add()
bpy.data.particles[“ParticleSettings”].effector_weights.gravity = 0
bpy.data.particles[“ParticleSettings”].count = 5000
bpy.data.particles[“ParticleSettings”].frame_end = 600
bpy.data.particles[“ParticleSettings”].lifetime_random = 0.22
bpy.data.particles[“ParticleSettings”].lifetime = 14
bpy.data.particles[“ParticleSettings”].particle_size = 0.01
bpy.data.particles[“ParticleSettings”].size_random = 0.008
bpy.data.particles[“ParticleSettings”].render_type = ‘OBJECT’
bpy.data.particles[“ParticleSettings”].dupli_object = bpy.data.objects[“duplisphere”]

if(create): # One
for n in range(3):
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, -5, 0))
bpy.ops.transform.resize(value=(0.01, 0.01, 0.01))
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.subdivide(smoothness=0)
bpy.ops.object.editmode_toggle()
bpy.context.object.name = “comet” + str(n+1)
addParticles(“comet”+ str(n+1))
bpy.ops.object.empty_add(type=‘SPHERE’, radius=.4, view_align=False, location=(0, 0, 0))
bpy.context.object.name = “Rotator” + str(n+1)
bpy.ops.object.lamp_add(type=‘POINT’, radius=1, view_align=False, location=(0, -5, -.01))
bpy.context.object.name = “pointLight”+ str(n+1)
bpy.ops.object.select_pattern(pattern=“comet” + str(n+1))
# Parenting
bpy.context.scene.objects.active = bpy.data.objects[“Rotator” + str(n+1)]
bpy.ops.object.select_pattern(pattern=“comet”+ str(n+1))
bpy.ops.object.parent_set(type=‘OBJECT’, keep_transform=False)
bpy.ops.object.select_all(action=‘TOGGLE’)
bpy.context.scene.objects.active = bpy.data.objects[“comet” + str(n+1)]
bpy.ops.object.select_pattern(pattern=“pointLight”+ str(n+1))
bpy.ops.object.parent_set(type=‘OBJECT’, keep_transform=False)

Set Rotations

def set_object_location(f):
ob = bpy.data.objects.get(“Rotator1”)
ob.rotation_euler.x = bpy.context.scene.frame_current * .06
ob.rotation_euler.y = 1.047
ob.rotation_euler.z = 0
ob = bpy.data.objects.get(“Rotator2”)
ob.rotation_euler.x = bpy.context.scene.frame_current * .06 + 90
ob.rotation_euler.y = 2.094
ob.rotation_euler.z = 0
ob = bpy.data.objects.get(“Rotator3”)
ob.rotation_euler.x = bpy.context.scene.frame_current * .06 + 180
ob.rotation_euler.y = 3.14
ob.rotation_euler.z = 0

every frame change, this function is called.

def my_handler(scene):
frame = scene.frame_current
f = frame % 158
set_object_location(f)

bpy.app.handlers.frame_change_pre.append(my_handler)

Attachments

Comet22.blend (7.99 MB)

Hi skywola,

When I move to another frame and render it, the tail is gone, also when I baked it complete before, but when I move to another frame and do an “Update All To Frame” (Particle System -> Cache -> Update All To Frame) before rendering then the result is better.

You can try this in the render script: move to the next frame, do “bpy.ops.ptcache.bake_all(bake=False)” this is the python code for Update All To Frame and render that frame, then move to the next frame do bpy.ops.ptcache.bake_all(bake=False) and render that frame and so on.

Thanks! I will give that a try . . . .

Update . . . I have taken this to the rendering forum, as it appears that it is a render issue as opposed to a coding issue.

I found my problem . . . . it appears that you cannot manually enter in the resolution that you want to render to; I had entered 1920x1080 manually instead of setting it via the drop-down . . . . . arrrrrrggggg! I am posting this so anyone who experiences a similar issue can solve it faster than I did. It now renders normally, just as it appears in render view.