Notifications
Clear all

[Closed] video file pre-load using maxscript?

Hi guys,
you might have checked out my script already, if not:
http://www.scriptspot.com/3ds-max/scripts/animated-grass-generator-script

so my script generates animated grass, and currently uses a whole algorithm of random values and bend modifiers to do so.
BUT ofcourse I want to put as much control as I can in the hands of the user, so I decided to implement an option to load a video file that defines the height of the grass determined by the brightness value of the pixel in the video file corresponding to the position of each grass strand. (use the video output as an animated heightmap in other words)
now, i’ve implemented a sampling function that works fine, but I ran into a very big problem.

obviously grass strands are numerous, which means that for my script to be useable in the least bit, I need speed. lots of it. so far everything worked out fine: I have a laptop that gets slower every single day, and I still don’t have any trouble running my script creating thousands of animated strands in a matter of seconds.
however, when I load in the video file and begin sampling, the problems start.

I am currently using the “getpixels videofile [position,position (point2 values)] nrofpixels” maxscript function, in combination with the “gotoframe” function.
basically, for each frame of the video file, I sample the brightness value I need (one per frame for each grass strand), and then move to the next frame, doing the same thing, and that for every frame of the video file for every grass strand.

now apparently max doesn’t load the file / frames until it needs them, and once it’s loaded them and used them it discards them again. I’m assuming this is a built-in memory saving mesure. that would be fine, but now it takes over a full minute PER STRAND to sample a grayscale hypercompressed 20 mb video file of a mere 630 frames, which is insanely slow. agreed, my laptop isn’t what it used to be, but it’s still stronger than most of our home computers, that simply freeze upon running the script with a video file loaded.

now what I need to do, or what I would like to do at least, is to somehow create a kind of buffer before sampling, to which I go back for each sample, so that i only need to load the entire video file only once, and than the animation sampling can go smoothly.

is there a way to achieve this?
if not, do you have any other suggestions to achieve the result i’m going for?

to give you a good example of the end effect i’m hoping to achieve:
http://cg.tutsplus.com/tutorials/autodesk-3d-studio-max/how-to-create-a-…

only with grass or custom geometry that’s user-defined. (yes, i put that in, too)

8 Replies

Do I understand you correctly, that you analyse the same frame in the video multiple times?
If yes, you should cache the data you extract from the frame in some kind of array…

you could maybe skip the problem by generating uv’s for the strands that matches the uv coords on the distribution surface and then use a volum select and the texture method to soft select the objects by the intensity of your video file and scale them accordingly with an xform modifier or something like that…

if you still want to cache the data, I would create an array for every strand, then when I need to access the data of a strand x at time y I would check the data in the array of strand x at place y, if it’s undefined I would use the getPixel method and store the data for future use. But personally I think this is not the correct way to go here.

 lo1

I’m guessing strand count and position can change dynamically, so you’ll probably need a 3-dimensional array (Frame,X,Y) to store the values. After which, you can discard the bitmap.

Keep in mind though, that even for a 500 frame 500X500 video, this array will gobble up 500MB of your precious heap, since Maxscript integers are 32-bit.

I think a more optimized solution would find a way to have this array be a dotnet array of 8-bit bytes, but have not tested this.

these are all great comments but judging by the heaviness of the use of a video file I think i’m better off using an audio file, and then generate radial equaliser waves from that. thanks for all the replies

 lo1

could please explain? How are you reading audio information inside max?

I looked into that, and I was thinking about an audio float controller, or do you have any other suggestions?

 lo1

right, there’s that. I was never a fan because it’s very limited, but it might work for your goal. I don’t understand how a radial EQ can represent grass growth but I trust you do.

ah well, the radial EQ isn’t meant to represent grass growth, it’s just to offer the user control over it’s animation. the possibility of this would be a radial 3D visualisation of an audio file, and in combination with the use of the user’s custom geometry, creating a music video using only an audio file and then letting the script do the rest for you would fall into the possibilities.

now that I think of it, I just might offer the option to do both; either a video or an audio file. for now though, i’ll start by looking into audio, see if that might do. thanks for the replies