Hello everyone!
So ive been really interested in scripting and the sorts and i thought i should give it a try.
Basically what i am trying to do:-
Im making a Blueprint manager. What it would do is let you select images (Front,Top,Left,RIght,Back) and create planes with the same measurements as the image and place it in the viewports. So basically,you could easily just plug in your images and hit create to get them.
I also added in a Freeze Images and Darken images options. The former is pretty easy to do i guess.For the darkening, ive decided to have a function to reduce the gamma of the images.People who usually use blueprints will understand why i have the darken option there.
macroscript BlueprintManager
Category: "Butt tools" buttontext: "Butt tools"
----------------------------------------------
--Errors and mistakes expected
--Thanks to Polycount and CGEmpire
----------------------------------------------
(
local ROL_Bmanager
local PIC_Front
local TEX_Front
--ROLL-OUT
----------------------------------------------
rollout ROL_Bmanager "Blueprint Manager" width:193 height:250
(
-- Set up the controls on our interface
button BTN_Create "Create!" pos:[110,211] width:70 height:24
button BTN_Front "Front" pos:[13,25] width:70 height:26 enabled:true
button BTN_Top "Top" pos:[110,25] width:70 height:24
button BTN_Left "Left" pos:[13,55] width:70 height:24
button BTN_Right "Right" pos:[110,55] width:70 height:24
button BTN_Back "Back" pos:[13,85] width:70 height:24
GroupBox LBL_select "Select Images" pos:[6,3] width:180 height:120
GroupBox grp3 "Options" pos:[7,127] width:180 height:73
checkbox CHK_Darken "Darken Image(s)" pos:[20,146] width:133 height:26
checkbox CHK_Freeze "Freeze Image(s)" pos:[20,172] width:133 height:26
label LBL_author "Author: Saad Butt " pos:[3,215] width:97 height:15
label lbl3 "buttsahib.wordpress" pos:[3,230] width:97 height:15
-- Set what each control does when it's used
--For Front
---------------------------------------------
on BTN_Front pressed do
(
PIC_Front = selectBitmap caption: "Select Front Image"
If PIC_Front != undefined then
PIC_Front = TEX_Front
TEX_Front.bitmap=bitmaptexture
X = TEX_Front.length
Y = TEX_Front.Height
Front= plane length:X width:Y isSelected:false lengthsegs:1 widthsegs:1 showFrozenInGray:false max backface
Filepath=TEX_Front.filename
Front.material = standard diffuseMap: (Bitmaptexture fileName:Filepath) showInViewport:true
showTextureMap P.material on
Filename=TEX_Front Filepath
Front.name=Front
deselect Front
)
) createdialog ROL_Bmanager
)
The code is just for the front as you can see,after i get it working ill add all the sides in.
I have really no idea whats wrong. But after i select the image for the front, i get a -- error which says that the "bitmap" is undefined. All the knowledge i have is from that cgempire tutorial psyko posted and cgtalk and the book i have 3dsmax bible.
Heres what the interface looks like btw:-
Any and ALL help is appreciated!
Replies
Will update soon. Have got some things working
So i had to write it again. It was working perfectly before (after my first post) but now im getting this error "cannot covert bitmaptexture to type:TextureMap"
I have no idea why im getting this as it was working before.
But here is the related code:
man i was so happy please help
So it should bomb on ".name" or ".n"
For example if you where trying to change the wire color of the selected object you would use "$.wirecolor 0 0 0" $ is used for selection.
There are other problems after that, but that will solve your immediate problem and since you're learning I won't hold your hand and write it for ya. You're getting it, just keep plugging away. I suggest getting the Autodesk approved, MaxScript Essentials book.
I have no idea why,but this is teh actual code. It somehow changes when i put code tags
PIC_Front = selectBitmap caption: "Select Front Image"
TEX_Front = PIC_Front
X = TEX_Front.height
Y = TEX_Front.width
F= plane length:X width:Y isSelected:false lengthsegs:1 widthsegs:1 showFrozenInGray:false max backface
Filepath = TEX_Front.filename
Filename = getFilenameFile Filepath
$Plane01.name = "Front"
$Front.wirecolor = color 0 0 0
frontRotationObject = eulerangles 90 0 0
rotate $front frontRotationObject
$Front.material = meditMaterials[1]
meditMaterials[1].diffuseMap = PIC_Front showInViewport:true
deselect F
)
Everything works right till the second last line of code. When i run it, i get a plane,renamed,rotated,black wired,etc
hehe thanks for making me try my hand at this but PLEASE,for godssake....WTF should i do about the "unabel to convert" problem.just a teenchy weency push would be appreciated! :P looking at all this code is makes me want to jump out my window
1) It might be a bad idea to name things the same as a viewport like "front" so change that to something like FrontPlane.
2) You'll need to define the texture type in material[1] then you can pass it the name/path of your bitmap.
So instead of using:
meditMaterials[1].diffuseMap = PIC_Front showInViewport:true
Use:
meditMaterials[1].diffusemap = bitmapTexture() -- Creates the proper texture type. Just like clicking the diffuse slot, picking bitmap and then canceling it without selecting a file (the map slot will be blank, but the material type will be set to bitmap which is what the next line needs)
meditMaterials[1].diffusemap.bitmap = PIC_Front -- Applies the bitmap to the now correctly defined mat diffuse slot.
showTextureMap $FrontPlane.material $FrontPlane.material.diffuseMap on -- Turns on the diffuse map in the viewport
What you had was assuming there was already a bitmap "texture type" inside the diffuse slot. It found "none" instead of "bitmap" and then would error out, because "none" does not have a map slot to define.
You also might want to to make sure that material1 is available, or make sure its set to standard before you start to monkey with it.
meditMaterials[1] = Standardmaterial () --Will reset the material to standard
So your button should look like this:
on BTN_Front pressed do
(
PIC_Front = selectBitmap caption: "Select Front Image"
TEX_Front = PIC_Front
X = TEX_Front.height
Y = TEX_Front.width
F= plane length:X width:Y isSelected:false lengthsegs:1 widthsegs:1 showFrozenInGray:false max backface
Filepath = TEX_Front.filename
Filename = getFilenameFile Filepath
$Plane01.name = "FrontPlane"
$FrontPlane.wirecolor = color 0 0 0
frontRotationObject = eulerangles 90 0 0
rotate $FrontPlane frontRotationObject
meditMaterials[1] = Standardmaterial ()
$FrontPlane.material = meditMaterials[1]
meditMaterials[1].diffusemap = bitmapTexture()
meditMaterials[1].diffusemap.bitmap = PIC_Front
showTextureMap $FrontPlane.material $FrontPlane.material.diffuseMap on
clearSelection()
max zoomext sel all
)
UI Suggestions:
- Instead of regular buttons use MapButton, MaterialButton or maybe just PickButton?
- Don't actually create the planes until you click create, heh.
- Might be easier to use check buttons instead of boxes for the options, might save space also since your title function take up the same visual space.
- Simplify how many planes you need. I bet you could get by with, Front, Side, Top.
You have no idea how much help you have been.seriously. thank you very much
Oh and you edited the post later?
Sweeet. Ill be sure to read it once i up this post and my throbbing err.headache subsides:)
UPDATES THANKS TO VIG
Btw,some of the things addressed would/should definitely be similar to what you posted. I will make more changes after going through your extremely generous help.
New look:-
I have it so that when you load an image from any of the "browse" buttons, the respective checkbutton is ticked marked.
Also,everything is created once you hit create and that also destroys the dialog aswell
And here is the code for those who are interested:
Issue for me right now:- (strict game artists-ala me, a day ago- look away! :P)
ok so you can see the image right? you can see that the ends of the planes arent meeting.What i want to do is something like this (in my logically ill-logical terms):
We are going to take the front for this issue. What i want to do is:
if BTN_Left or BTN_Right != undefined then
(
$Front_View.pos.y = (TEX_Left.Length/2) or (TEX_Right.length/2)
)
else
(
move $Front_View [0,-300-0]
)
BTN being the browse button for the left and right respectiveley where the images are stored, Frontview being the plane, TEX_ being their textures respectively. Now the problem is im taking in two variables (BTN_LEft and BTN_Right) and maybe two operations aswell (If>then>else and or).
I used TEX_Left.length/2 because as the left and right imges are created at the origin,i would want to move the front_view plane just half their lengths in the y-axis so their ends would meet.
I will up it at scriptspot after i work in the above mentioned issue and the other two options aswell
Man scripting is weird.Its rewarding.Techincal. Often becomes hair-pullingly crazy...and often....arouses.....:poly141:
Again,Vig,Cant thank you enough
looks like a useful script as well! maybe you could include something like this:
-move all the planes so that x position of the left view is on front_width/2 and so on. (don't know if that was what you where talking about earlier).
-when all the planes are created, convert them to editable poly
-attach everything together
-weld corner verts
-turn on backface culling
i have NO idea if that is all possible, but it'd be nice .
I don't have time to explain right now, there is a way to move the planes to where you need them to be. Basically you find an extreme point and tell it to move the plane there.
There is also room for a lot of optimization in your code, there's quite a bit of redundant stuff that could be handled with simple functions. But dude you got it working and that's awesome! Nice work! Way to stick it out!
Edit: Actually I used a tiny bit of it in this script, it might be of some use. The script takes the pivot point moves it to the lowest local Z axis point, then moves the whole model to the world 0 0 0. If I have time later I'll expand on it, as well as some ways to put in some functions.
Now I really gotta get home its snowing like crazy here...