0
$\begingroup$

My data assigns a specific time (say a calendar day or shorter) to the appearance of each of its several hundred objects. To show this I'd like to run through say a year of time in about 10 seconds and have the objects appear on the 3D display sequentially. Should I set out to write a python script that simulates time passage and then changes the layer or transparency of each object depending on whether its time has arrived? This sounds like a lot of processing, rechecking the status of all objects every unit of time. Is there some standard efficient strategy for minimizing the processing time so the computing time doesn't slow everything down?

$\endgroup$
1
$\begingroup$

Keyframes or Drivers on hide and hide_render

I would suggest either creating ether a keyframed action, or setting up drivers on the hide and hide_render properties of your object.

How you convert from your time to frames is up to you. In bpy.utils there is a convenience method that converts a datetime object to a frame.

Drivers

Each object from data will be hidden (both in viewer and to render) until the scene frame is greater than the data frame. Test script below.

import bpy

context = bpy.context
scene = context.scene

data = [[0, 0, 1, 12],
        [0, 10, 3, 30],
        [3, 3, 4, 40],]


for line in data:
    x, y, scale, frame = line
    bpy.ops.mesh.primitive_uv_sphere_add(
            location=(x, y, 0))
    ob = context.active_object
    # set scale
    ob.scale *= scale
    # add drivers
    for dp in ["hide", "hide_render"]: # xxx
        driver = ob.driver_add(dp)
        driver.driver.expression = "frame < %f" % frame

Keyframes

Keyframe as hidden at frame 1, show at data frame.

    # add keyframes
    for dp in ["hide", "hide_render"]: # xxx
        setattr(ob, dp, 1)
        ob.keyframe_insert(dp, frame=0)
        setattr(ob, dp, 0)
        ob.keyframe_insert(dp, frame=frame)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.