[Closed] Bitmap rotated objects
Hello to all scripting masters,
I have to write a little piece of script that would rotate an aray of selected objects (a serie of glass panels) depending on the value of a bitmap.
Imagine instead of a bump applied to all the objects, the value of the image make them rotate less or more.
Unfortunately my scripting ability is pretty limited, anyone here nice enough to point me in the right direction?
Thank you
What do you mean by “the Value of a bitmap?” A RGB bitmap has three values for every pixel, you need to consolidate it down to one rotation?
You could wire it. Right Click and select Wire Parameters. Shown in the image I have the diffuse color channel wired to a rotation.
Note I’m using the red color channel, as the color (RGB) is converted to a point3 number (xyz) and I’ve multiplied by 10 to make it rotate more…
Oh, thanks a lot,
Im gonna try this as soon as Im at the office.
Thank you again.
Im having troubles doing this as you’ve indicated,
here’s a screenshot of what Im trying to do,
so far I havent succeded in wiring the x rotation value to the average value of the mapped bitmap ( (r+g+b)/3 ) applied, for all the selected objects at once.
thanks again
The wire example is not wiring a bitmap, only the .x component of a diffuse color. The only reference I could find to a “pixel averaging” function is the averageColor method in the Architectural Material. I guess you could creat your own function by reading all the pixels in an image and calculating an average, but I’m also guessing that it would be very slow.
If you can use an Architectural Material, that would probably do the trick. I presume the idea is to use a movie as input. If you could use audio instead, or somehow convert the video-levels to an audio-track, there are some audio-controllers available that works quite nicely.
Oops, excuse me, just noticed your last image. What you want in not an average (at least not of the whole image). Looks like a nice idea, I’ll have to think about it! It should be possible with maxscript, although the viewport update might be somewhat slow…
Thank you for your answer.
It doesnt have to be fast,
The idea is to use a picture provided by the architect to make orientation varations of an array of glass panels covering a wall.
As there’s gonna be a lot of panels and the image is subject to change depending on the visual result of this whole variation, Im trying to find a way to automate this whole process.
What I would try: use a planar UVW-map modifier on the group of objects. Give the objects an XYZ-rotation controller and put a script controller on the appropriate axis. Calculate the position of the object in the UVW space and convert this to a pixel coordinate in the bitmap. Get the value of this pixel (or an average of local pixels) and use this to control the rotation. The hardest part is perhaps finding the object position in UVW space (My understanding of matrix transformations is limited).
Edit: or perhaps just use a box or a rectangle to “frame” the image. That would probably be easier than sorting out the transforms between different objects and UVW modifiers.
I think the best way would be to have a bitmap that has the same number of pixels than the number of boxes (see the attached image above, 105 panels and a 105 bitmap mapped onto them) and by script to get the value of each pixel and apply a corresponding rotation (white:no rotation, black:90°rotation).
I’ve started studying one of Bobo’s tutorial where a bitmap is creating a serie of boxes which heights depends on the intensity of the bitmap’s pixel.
http://www.scriptspot.com/bobo/mxs2/mxs_tut/lesson01.html
But I get stuck where somewhere while listing the objects and trying to apply the desired rotation value.
I made a working prototype, using this script in a (rotation, one axis) float script controller:
in coordsys rectangle
(
thispos=thisobj.pos
mini=rectangle.min
maxi=rectangle.max
)
size=maxi-mini
rpos=(thispos+(size/2))/size
info=getBitmapInfo mat.bitmap
xpix=(rpos.xinfo[3]) as integer
ypix=(rpos.yinfo[4]) as integer
pix=getPixels mat.bitmap [xpix,ypix] 1
pix[1].v/255.*pi/2
where:
-rectangle is a variable connected to a rectangle object that frames the tiles
-thisobj is a variable connected to the current tile (the parent of this controller)
-mat is a variable connected to the bitmap (Assign Controller and find the bitmap in trackview list)
black gives no rotation, white gives 90 degrees. I tried using up to 110×80 tiles inside this area (Tools/Array and instances), and while it is extreeeeemly slow, it works… As usual, there are probably ways to make it faster, but for a first effort I’m usually happy if it just works The bitmap can be any size, and each object samples a single pixel for it’s value.