PDA

View Full Version : Bitmap rotated objects


cyrille32
05-29-2008, 05:45 PM
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

Kramsurfer
05-29-2008, 11:09 PM
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...

cyrille32
05-30-2008, 08:56 AM
Oh, thanks a lot,
Im gonna try this as soon as Im at the office.
Thank you again.

cyrille32
05-30-2008, 10:34 AM
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

Neuro69
05-30-2008, 11:18 AM
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.

Neuro69
05-30-2008, 11:21 AM
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...

cyrille32
05-30-2008, 11:25 AM
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.

Neuro69
05-30-2008, 12:00 PM
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.

cyrille32
05-30-2008, 01:41 PM
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, 10*5 panels and a 10*5 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.

Neuro69
05-30-2008, 05:06 PM
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.x*info[3]) as integer
ypix=(rpos.y*info[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 110x80 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.

cyrille32
05-30-2008, 06:47 PM
Thanks for your research!
Ive added a script controleur and it works,
awesome.
Thanks a lot for the effort,
Ill send you the result when it will be out of NDA (its a contest).
Best,
Cyrille

jonahhawk
05-31-2008, 05:26 PM
We were tasked with animating a wall of small panels at one point. We tried several solutions and finally turned to Bobo for advice. You might find this thread helpful.

http://forums.cgsociety.org/showthread.php?f=98&t=489438&highlight=bitmap+rotation

Neuro69 - I'm missing something witht the script controller. I assigned the rectangle to a node that surrounds my tiles, Assign Node. I assigned thisobj to one of the first tile before arraying it, Assign Node. I have a material assigned to the tiles, bitmap in diffuse slot, planar uvw covering the whole area of tiles.

--Type error: Call needs function or class, got: undefined.

I'm pretty sure this relates to how i assigned the mat variable. I used Assign Controller and assigned it to the bitmap map.

-- Error occurred in anonymous codeblock
-- Frame:
-- f: 29.0
-- Rectangle: $Rectangle
-- rpos: [0.0141584,0.037031,-2322.68]
-- t: 4640.0
-- s: 0.966667
-- pix: undefined
-- this: Controller:Float_Script
-- maxi: [208.051,153.866,-1.34514e-005]
-- info: undefined
-- xpix: undefined
-- thisobj: $Box01
-- mat: MyMap:Bitmap
-- thispos: [-202.16,-142.47,0.0625]
-- size: [416.102,307.732,-2.69028e-005]
-- getBitmapInfo: undefined
-- NT: 0.29
-- mini: [-208.051,-153.866,1.34514e-005]
-- ypix: undefined
>> MAXScript Script Controller Exception: -- Type error: Call needs function or class, got: undefined <<




Sorry for the novice problems...

Neuro69
06-02-2008, 09:57 AM
Yes, it would appear to be about the mat-variable, as the variable "info" is undefined. I used Assign Controller, then found \Objects\$object\mat-name\Maps\Diffuse Color:map and selected this. The UVW is not necessary, that was just an earlier idea; the rectangle defines the "UVW-mapping". The Diffuse Map must be a normal bitmap. If you've done this correctly, then I'm not sure... haven't exactly done any debugging.

CGTalk Moderation
06-02-2008, 09:57 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.