0
$\begingroup$

I'm having an application where I want to draw a 3-dimensional track that extends with every frame. Something like this here:

enter image description here

This is based on Blender 3.1.2, btw.

From the screenshot it might appear that I did achieve what I wanted. However, there are some issues....

Essentially, this (yellow) track is based on a path with a bezier-circle as bevel. So far I did this in a script where I create a new path with each new frame within a frame-change handler. One issue here is that the complete path needs to be re-created with every frame, and considering that we are talking about several 10000 track points, this is taking longer and longer the further the animation goes. But anyway, it is working essentially. However, what I did is working only during editing. When I render the animation, Blender is crashing with a segmentation fault after a couple of frames.

So how did I do this?

My frame-change handler is looking like this:

def draw_track(): current_frame = bpy.context.scene.frame_current

# Delete the old track path
old_object = bpy.context.scene.objects.get('TrackPath')
if old_object:
    bpy.data.objects.remove(old_object)

# make a new curve
crv = bpy.data.curves.new('crv', 'CURVE')
crv.dimensions = '3D'

# make a new spline in that curve
spline = crv.splines.new(type='NURBS')

# a spline point for each point
spline.points.add(current_frame) 

for i in range(current_frame+1):   
    <determine x, y, z> 
    spline.points[i].co = [x,y,z] + [1.0]

# make a new object with the curve
obj = bpy.data.objects.new('TrackPath', crv)
bpy.context.scene.collection.objects.link(obj) 
bpy.data.objects['TrackPath'].data.bevel_object  = bpy.data.objects["TrackCircle"]
bpy.data.objects['TrackPath'].data.bevel_mode  = 'OBJECT'
bpy.data.objects['TrackPath'].data.use_fill_caps = True
material = bpy.data.materials["TrackMaterial"]
bpy.data.objects['TrackPath'].data.materials.append(material)

So essentially, the object "TrackPath" is being removed and recreated for each frame. There is also an object "TrackCircle" which is persistent and associated with the "TrackPath" object. Same for "TrackMaterial".

As pointed out earlier, this method is working fine during editing. I can click around in the time line and I see what I expect to see. However, Blender crashes during rendering the animation.

One thing that might be an issue here is that the created curve appears not to be deleted with the deletion of the old TrackPath. I'm seeing this in the scene object browser of Blender. The script is creating a new curve with the name "crv". However, what I see in the browser is something like "crv.10" and counting up. Blender does this when one is using a name that is already present.

I'm not sure whether this is the reason for the crash of Blender during rendering the animation. Unfortunately, I was not yet able to delete the created curve object. So first question is: How can I delete it?

Another point is my general procedure. It appears to be not a very good practice to delete the objects and recreate them over and over again. It seems to be better to have a persistent TrackPath object with a more or less persistent curve where points are added and removed on demand depending on the current frame number. In some sort of pseudo-code something like: <if there are too less points in the curve, add the according points> <if there are too much points in the curve, delete the according points>

Unfortunately, I was not able yet to figure out how I can do this.

Thanks for any hints!

Mario

An update on that matter: I found another potentially better way to deal with that. It would assume that the path resp. curve is statically present. In fact, it could be created by a script at the beginning. This appears to work as planned. Now, in the Object Data Properties of a path there is a "Start & End Mapping". The allows to cut or better said ignore parts of the path at the beginning or the end. In fact, only the end-cut is needed here. In theory, it would be sufficient to interpolate the end-mapping linearly from a value of 0.0 at the very first frame to a value of 1.0 at the very last frame. It is important to switch the interpolation to linear here, because Blender uses a non-linear interpolation by default when setting keyframes.

So, this would be some really nice way to handle this task. However, obviously it is too nice to be true.... There is some issue that the path is falling short here. For instance, when I set the current frame to half of the total frame count and set the end-mapping to 0.5, one would suppose that the track ends exactly after half of its points. However, it does not. It is falling short visibly. Things change slightly when I change these other mapping settings between "Resolution", "Segments", and "Spline", but there is not really a constant behavior. Depending on the track situation and position, things are sometimes getting more worse and sometimes less worse. However, according to the Blender documentation the setting "Resolution" appears to be the only correct one anyway for that use.

So what can be wrong here now? I'm having some suspicion here that Blender does collapse curve points with more or less the same coordinates. Might this be the case? If yes, can it be avoided?

$\endgroup$
4
  • $\begingroup$ Hi Mario, it would be great if you could explain us in easy words what you want to achieve - without getting too technical.e.g. i wanna paint a track "live" when a bicycle drives through the woods (or something similar). I think/believe that this is possible with GN as well...and much easier than python ;) $\endgroup$
    – Chris
    Commented May 23, 2022 at 10:40
  • 1
    $\begingroup$ Don't use a frame change handler. Simply use the frame number as a parameter to 'grow' your path to a particular point. $\endgroup$ Commented May 23, 2022 at 13:47
  • $\begingroup$ @Chris: What I'm trying to do is, in fact, the visualization of a path on the planet from some sort of tracking data repository that is outside the scope of this particular visualization problem. In fact, I'm having new positioning information for each frame, I want to visualize the current position with some object (the red sphere in the screenshot), and I also want to visualize the track until the current frame (the yellow thing). Something similar to what is described here: blender.stackexchange.com/questions/218394/… $\endgroup$
    – Mario
    Commented May 23, 2022 at 17:00
  • $\begingroup$ @MartyFouts: If this is possible as well, I might do that. But how do I grow the path in detail? Anyway, I'll search on how to do that. $\endgroup$
    – Mario
    Commented May 23, 2022 at 17:04

2 Answers 2

0
$\begingroup$

hopefully i understood you right, and this is what you are trying to achieve?

enter image description here

you can achieve that with this node setup:

enter image description here

So I did create a Path in Poly-mode with a couple of well-defined points - 9 totally. Refer to the screenshot here: enter image description here

I set keyframes for the "Value" with 0 at frame 0 and 100 at frame 9. The interpolation mode for the animation of "Value" has been set to "Linear", so that there's been added 100/9 resp. 11.111111 with each frame. I did also play a bit with the "Map Range" node and its "Linear" and "Stepped Linear" settings. The problem is clearly visible in the screenshot. We are at frame 4. The yellow track is supposed to end at the fifth point resp. point number 4. However, it does clearly not and is "overshooting" somewhat. The reason for that is apparently that the position on the path is related to the total length of the path and not to the point count within the path. When I move the points after the corner so that all segments are equal in length, then this would be working perfectly. However, this is not realistic for a GPS-track, for instance.

So question is whether it is possible to use the number of points as reference for the end-mapping rather than the length of the path? If this is not possible, I think this method cannot be used here at all and I end up with my initial method with dynamically created paths (that needs some improvement, however....). Although this method might be nice to do some sort of artificial movement, it is not suitable for "technically correct" animations.

$\endgroup$
4
  • $\begingroup$ This is looking great and matches my initial outcome in essence. I don't fully understand it's concept yet. But might it be that it is also based on the very same "End Mapping" as I tried to explain in my last attempt? If yes, I hope that this mechanism is not faced with the same issue (perhaps caused by collapsing curve points) as I did observe there.... Anyway, could you please provide the Blender file of your example so that I can better understand and adopt it? $\endgroup$
    – Mario
    Commented May 24, 2022 at 6:52
  • $\begingroup$ i added the blend file $\endgroup$
    – Chris
    Commented May 24, 2022 at 6:55
  • $\begingroup$ Ok, thanks! I see.... You are using a BezierCurve as base and the end of the track is interpolated along the curve. I need to use a Path instead and the end of the track needs to be at a point in that path. I.e. at frame 1000 the track has to end at point 1000 - not 999 and not 1001.... I'll try to adopt your example accordingly and will report later on. However, I'm afraid that there will be also that issue with the end-mapping. Perhaps this is even a bug in Blender. We'll see.... $\endgroup$
    – Mario
    Commented May 24, 2022 at 7:41
  • $\begingroup$ Here we go.... I tried this and was partly successful. I'm going to try to edit your post because I want to add a screenshot for illustration what I can't do here.... $\endgroup$
    – Mario
    Commented May 24, 2022 at 18:16
0
$\begingroup$

I was able to solve that problem. Essentially I did this by using a statically present path that is being dynamically extended or shortened from within a frame-change handler depending on the current frame. For details refer to the solution of my question I did post here: How to dynamically remove and add points to a curve resp. path via frame-change handler?

This dynamic extension/shortening should reduce the processing overhead significantly as the track data has not to be read in completely with every new frame.

Though I did still observe crashes of Blender without special precautions. However, I was able to deal with that situation in an acceptable manner (refer to How to dynamically remove and add points to a curve resp. path via frame-change handler?).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .