Home Technical Talk

MaxScript (Beginners) Questions

polycounter lvl 12
Offline / Send Message
PeteHawk polycounter lvl 12
Hey folks.
Currently working on a project for uni, trying to create a more user friendly fire generator in 3DsMax.
Using Partical systems as the basis of the tool and just simplifying it.

FireGen_img.png

Replies

  • PeteHawk
    Options
    Offline / Send Message
    PeteHawk polycounter lvl 12
    So I may need a little help here and there. Would appreciate it if anyone could point me in the right direction.
    Here's what I'm stuck with:


    1st:
    I need it so that my spinners are disabled when the Partical System is not selected in the scene
    if myPartical != undefined then
    (
    particalSpeed.enabled = false
    )
    else
    (
    particalSpeed.enabled = true
    )

    2nd
    I want to add a play timeline button to my rollout. But I cannot find the maxScript of the action.
    timeline.play
    ??
  • Mark Dygert
    Options
    Offline / Send Message
    RE 1st:
    I'm not exactly sure how to acomplish this without doing some trial and error scripting which I don't have time for right now but I think I can help with you're 2nd question.

    RE 2nd:
    "max time play" to start the animation playback.
    "stopAnimation()" to stop the playback.

    You might also want to add an option to your fire generator to create a looping system since particles in max don't actually loop on their own. You do this by creating 4 identical sprayers set to go off at regular intervals and fade out as others are fading in. Here is a thread that talks about it as well as links to another script that automates the process a bit:
    http://www.polycount.com/forum/showthread.php?p=1197140#post1197140
  • havardsc
    Options
    Offline / Send Message
    To update the ui you can add a selection callback:
    (	
    	tp = teapot name:"Special teapot"
    	
    	fn selectionCallback e handles =
    	(
    		if handles.count == 1  and selection[1] == tp then 
    			print tp.name
    	)
    	
    	::callbackItem = nodeEventCallback selectionChanged:selectionCallback
    )
    
    This one checks if there is only one object selected and if the selected object is the teapot created before. The reason I use selection[1] instead of GetHandleByAnim is to prevent the if-statement to pass when you deselect the object. Be sure to clean it up if you use it.
    More details here: http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/files/GUID-7C91D285-5683-4606-9F7C-B8D3A7CA508-2062.htm

    Instead of max time play you can use playanimation() which gives you some more optional arguments.
  • PeteHawk
    Options
    Offline / Send Message
    PeteHawk polycounter lvl 12
    Cheers guys, still having a little trouble with the callback but everything else is working just fine. Much appreciated.
    I'm working on adding a texture to my particle. It's a pre-set that I've made which should be applied by a simple button press.


    Untitled-1.png

    Error:
    -- Error occurred in texture(); filename: F: \MaxScript\; position: 888; line: 32
    -- Frame:
    -- called in addTexture.pressed(); filename: F: \MaxScript\; position: 2716; line: 63
    -- Frame:
    >> MAXScript Rollout Handler Exception:
    -- Unknown property: "color1" in undefined <<

    I also need to find a way of applying textures to the viewport (2 on diagram)
  • monster
    Options
    Offline / Send Message
    monster polycounter
    1. You should probably use a more descriptive function name. Generic names like "texture" are easy to type, but when you look at your code some time from now, or share it with others, a more descriptive name will be appriciated. So instead of Texture() we'll use ApplyNoiseTexture().

    2. The problem is that you are referencing the Noise map by name, but the name of the map has changed. When you apply a Noise texture through the interface, the name is #Diffuse_Color__Map__1____Noise. However, when you apply it through maxscript the name is #Diffuse_Color__Noise____Noise. Working with names is unreliable. Instead you should store the Noise texture in a variable on creation, then reference the variable's properties.

    fn ApplyNoiseTexture =
    (
    	newNoiseMap = Noise()
    	newNoiseMap.color1 = color 255 146 30
    	newNoiseMap.color2 = color 255 42 0
    	newNoiseMap.type = 1
    	meditMaterials[1].diffuseMap = newNoiseMap
    )
    
  • PeteHawk
    Options
    Offline / Send Message
    PeteHawk polycounter lvl 12
    Great stuff monster, makes perfect sense and thanks for the tip. I still need to comment my script at some point.
    Any ideas for showing material in viewport? maybe
    showTextureMap newNoiseMap true
    
  • PeteHawk
    Options
    Offline / Send Message
    PeteHawk polycounter lvl 12
    Ok, finally got the callback working, so that you can only change the values if its selected, thanks havardsc and cheers mark for the timeline playback.
    One final question would be, how to link my two colour pickers to the noise texture.

    myColorPicker cp2 "" width:72 height:40 title:"Colour 2"
    myColorPicker cp1 "" width:72 height:40 title:"Colour 1"
    
    newNoiseMap.color1 = color 255 144 0
    newNoiseMap.color2 = color 255 30 0
    
  • monster
    Options
    Offline / Send Message
    monster polycounter
    One way control is pretty easy. (Color Picker controls the Noise Map)
    on cp1 changed val do
    (
    	meditMaterials[1].diffuseMap.color1 = val
    )
    
    on cp2 changed val do
    (
    	meditMaterials[1].diffuseMap.color2 = val
    )
    

    Two way control would be a little trickier since the ColorPicker control doesn't support animation controllers. Basically, you would create hidden spinners, have those modifier the color picker and vice versa. But also assign the controllers of the RGB channels of the Noise map color to the spinners.

    For this script to work reset the scene, and apply a noise map to medit[1]'s diffuse channel.
    rollout ColorLinkTest "Color Link"
    (
    	colorPicker cp1 "" width:72 height:40
    	spinner spnR "" range:[0,1,0] visible:false
    	spinner spnG "" range:[0,1,0] visible:false
    	spinner spnB "" range:[0,1,0] visible:false
    	
    	fn updateColor = 
    	(
    		cp1.color = (color (spnR.value*255.0) (spnG.value*255.0) (spnB.value*255.0))
    	)
    	
    	on ColorLinkTest open do
    	(
    		AnimController = Point3_XYZ()
    		
    		meditMaterials[1].diffuseMap.color2.controller = AnimController
    		spnR.controller = meditMaterials[1].diffuseMap.color2.controller.x.controller
    		spnG.controller = meditMaterials[1].diffuseMap.color2.controller.y.controller
    		spnB.controller = meditMaterials[1].diffuseMap.color2.controller.z.controller
    		
    		updateColor()
    	)
    	
    	on cp1 changed val do
    	(
    		spnR.value = val.r/255.0
    		spnG.value = val.g/255.0
    		spnB.value = val.b/255.0
    	)
    	
    	on spnR changed val do
    	(
    		updateColor()
    	)
    	
    	on spnG changed val do
    	(
    		updateColor()
    	)
    	
    	on spnB changed val do
    	(
    		updateColor()
    	)
    )
    createDialog ColorLinkTest
    
Sign In or Register to comment.