home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-09-12 | 55.2 KB | 1,701 lines |
- /* gMaterialED.ms - gmax scripted material editor */
-
- -- lam 8/28/01 - moved vUIParamChange = false into fUpdatePropertyDisplay. Callback is delayed until scene redraw, so this flag
- -- was always being set to false before the callback was performed.
- -- mjy 8/06/01 - incorporated UI for 2-sided mtls. additional layout tweaks.
- -- lam 7/27/01 - turning off all callbacks if createDialog fails
-
- -- orb 07-26-01 implemented show map in vieport functionality.
- -- added the following functions
- -- fGetMapSMIVState, fGetMaterialSMIVState
- -- finished the implementations of the following
- -- fShowMap, fShowMaterial, fUpdateTools, fUpdatePanel
- -- Mod on 7/25/01 by L. Minton:
- -- Added vUIParamChange flag which is set to true before the UI changes a material parameter. This flag is tested
- -- in the callback function before updated the UI.
-
- -- *** orb 07-24-01
- -- NOTE: not checking in the full implementation of fSetCurrentMaterial.
- -- This means that 302114, 302099, 302040 WILL NOT BE FIXED as described immediately
- -- following this note. The fSetCurrentMaterial implementation slows down the editor
- -- too much, so I'm leaving this out
- -- Fixes on 7/23/2001 by Mark Young:
- -- Defects 302114, 302099, 302040 - Added function fSetCurrentMaterial
- -- which is now called when vMaterialCurrent is reassigned. Besides
- -- setting vMaterialCurrent, the function sets a change handler for
- -- the current material to update the GUI when property edits are undone.
- -- Defect 302552 - Modified function fUpdateMaterials and added change handler
- -- for sceneMaterials. This also supports undo for "new", "copy" and "delete".
- -- Defect 301646 - Modified function fDeleteMaterial to handle multimaterials.
- -- Defect 302121 - Changed tooltip and title for SelectByName dialog to
- -- "Select from Objects with Material ..." to better reflect functionality.
- -- Defect 302870 - Modified function fGetMaterial to copy multimaterials.
- -- Defect 302860 - Modified function fApplyMaterial to apply multimaterials.
- -- Unlogged bug - Fixed a new bug in function fGetSelectedMaterial
- -- that blocked "get" for subobject selections.
-
- -- orb 07-24-01 removed fChangeMaterials because it isn't needed,
- -- changed "when subAnimStructure sceneMaterials" callback to call fResetGUI
-
-
- -- Modifications on 7/16/01 by L. Minton for removal of as many 'return's as possible, and some speed tweaks.
- -- Fixed known issue 2 - messagebox is run from listener thread, and the 2nd 'on enter' event was executing while the
- -- messagebox from the first 'on enter' was up and blocking execution of the remainder of the handler. Moved the line
- -- field.text = material.name from after the messagebox call to before.
- -- Known issue 3 should not exist any more. Fixed earlier via defect 298613
- -- Known issue 4c (enabled property) fixed via defect 302171
- -- Defect 301368 (tab out of Name edittext and then change focus throws error) fixed. The tab was setting focus to the next
- -- ui item, which is the vEditMultiMaterial edittext. Changing focus then caused the 'on entered' handler to be called on that. But
- -- this wasn't being handled properly in the conditional at the top of fEditMaterial.
- -- Known issues 4a and 4b not reproducible here. Tried moving the 2 edittext fields to the bottom if the ui item definitions, no problems.
- -- Could have been related to problem fixed in defect 298613.
- -- Handler exception on Escape in edittext field fixed via defect 298264
- -- Handler exception on Escape when creating object fixed via defect 298264
- -- Random crashes after appending or deleting from sceneMaterials fix via defect 298231
- -- Fixed set of <array>.count via defect 302167. This can be used for "pre-allocating" arrays. See fUpdateMaterials, fUpdateSubMaterials.
-
- /* Known Issues: */
- /* 1. FIXED: "Show Material/Map" toggle buttons currently have no effect. */
- /* Functionality will require MAXScript exposure of the ability */
- /* to read the state controlled by "showTextureMap ..." */
- /* 2. FIXED: Displays error messages (modal dialog) twice when invalid */
- /* (i.e., blank or duplicate) material names are entered */
- /* - apparently due to a MAXScript bug with "enter" events */
- /* for EditText UI controls. */
- /* 3. FIXED: All application windows occassionally blink when materials are */
- /* unloaded/loaded - apparently due to a MAXScript bug/unsupported-feature */
- /* where some UI controls make the whole app redraw when their position */
- /* properties are changed (DropDownList is the culprit in this script). */
- /* 4. FIXED: There are a couple of problems that workarounds currently avoid: */
- /* - EditText control must be defined first for proper interaction */
- /* - EditText control must be defined without specifying */
- /* a height property for proper interaction */
- /* - Controls that may be disabled need to be moved offscreen (by */
- /* setting position property) and then moved back onscreen in order */
- /* for the disabled state's color/font to be properly rendered */
-
- try callbacks.removeScripts id:#gMaterialED
- catch ()
- if vMaterialED != undefined do
- ( try unRegisterTimeCallback vMaterialED.fUpdatePropertyDisplay
- catch ()
- try DestroyDialog vMaterialED
- catch ()
- )
- try deleteAllChangeHandlers id:#gMaterialEdTransient
- catch ()
- try deleteAllChangeHandlers id:#gMaterialEdPersistent
- catch ()
-
- /* vMaterialED.fSetMaterial uses the following global variable to support */
- /* external calls when vMaterialED is not open (i.e., defined, but not instanced). */
- /* This specifies the material, parent multimaterial and tab */
- /* to be loaded when vMaterialED subsequently opens. */
- vMaterialED_SetMaterial = #(undefined,undefined,undefined)
-
- -- orb 07-23-01 defect 298557
- -- This global is indicates whether or not Flash 5 activeXcontrols loaded
- -- successfully. See the fOpen() implementation
- vMaterialED_Flash5Installed = 1
-
-
- -- orb 08-20-2001 fixing defect 306451
- vMaterialED_Position = [300, 200]
-
-
- rollout vMaterialEd "gmax Material Editor" width:351 height:410
- (
- -- orb -8-20-2001 Fixing Tab order
- -- Please maintain the order for everything between the --******* symbols...
- --******* please maintain order so tab order is preserved - BEGIN ******
- label vLabelMaterials " Scene Materials" pos:[8,4] width:42 height:26
- dropDownList vListMaterials "" pos:[54,10] width:258 height:21
- button vButtonGet "get" pos:[8,39] width:32 height:24 toolTip:"Get material from selected object"
- button vButtonNew "new" pos:[47,39] width:32 height:24 toolTip:"Create new material"
- button vButtonCopy "copy" pos:[86,39] width:32 height:24 toolTip:"Create new material with current properties"
- button vButtonApply "apply" pos:[125,39] width:32 height:24 toolTip:"Apply material to selected object(s)"
- button vButtonDelete "delete" pos:[195,39] width:32 height:24 toolTip:"Delete material from scene"
-
- editText vEditMultiMaterial "Multi-Material " pos:[10,73] width:301
- dropDownList vListSubMaterials "" pos:[79,91] width:233 height:21
- editText vEditName "Name " pos:[44,119] width:267
- label vLabelOptions "Option" pos:[41,145] width:50 height:13
- checkBox vCheckboxTwoSided "2-sided" pos:[83,145] width:60 height:16
- --******* please maintain order so tab order is preserved - END ******
-
-
- -- orb 07-23-01 defect 298557
- -- load the Flash 5 control, so we can give an appropriate error message
- --
- activeXControl vFlashTabs "ShockwaveFlash.ShockwaveFlash.5" pos:[7,187] width:120 height:211
- activeXControl vFlashTop "ShockwaveFlash.ShockwaveFlash.5" pos:[126,167] width:218 height:20
- activeXControl vFlashBottom "ShockwaveFlash.ShockwaveFlash.5" pos:[126,398] width:218 height:18
- activeXControl vFlashRight "ShockwaveFlash.ShockwaveFlash.5" pos:[331,187] width:18 height:211
-
-
- colorPicker vColor "Color" pos:[146,216] width:65 height:20 color:(color 197 197 197) modal:false
- checkbox vCheckboxMap "on" pos:[143,304] width:39 height:16
- bitmap vImageMap "" pos:[226,257] width:100 height:100
- spinner vSpinnerMap "Amount" pos:[170,339] width:52 height:16 range:[0,100,100] type:#integer scale:1
- button vButtonMapOpen "open" pos:[142,257] width:24 height:24 toolTip:"Assign texture - pick map file"
- button vButtonMapClear "clear" pos:[170,257] width:24 height:24 toolTip:"Clear map"
- groupBox vGroupMap "Map" pos:[138,241] width:193 height:120
- checkbox vCheckboxMatchDiffuse "match Diffuse Color/Map" pos:[152,193] width:136 height:18
- activeXControl vFlashArrow "ShockwaveFlash.ShockwaveFlash.1" pos:[127,192] width:25 height:18
- label vLabelComponents "Components" pos:[13,170] width:60 height:13
-
- checkButton vButtonMaterialShow "show" pos:[320,140] width:24 height:24 toolTip:"Show material's maps in viewport"
- checkButton vButtonMapShow "show" pos:[198,257] width:24 height:24 toolTip:"Show map in viewport"
- button vButtonNavigator "nav" pos:[320,8] width:24 height:24 toolTip:"gmax Material Navigator"
- label vLabelSubMaterials "Sub-Material" pos:[13,94] width:60 height:13
- button vButtonSelect "select" pos:[320,39] width:24 height:24 toolTip:"Select from object(s) with material"
-
-
- activeXControl vFlashHighlight "ShockwaveFlash.ShockwaveFlash.1" pos:[236,224] width:95 height:85
- spinner vSpinnerSpecularLevel "Level " pos:[179,232] width:50 height:16 range:[0,999,0] type:#integer scale:1
- spinner vSpinnerGlossiness "Glossiness " pos:[172,258] width:57 height:16 range:[0,100,10] type:#integer scale:1
- spinner vSpinnerSoften "Soften " pos:[177,284] width:52 height:16 range:[0,1,0.1] type:#float scale:0.1
-
- colorPicker vColorSelfIllum "" pos:[202,220] width:48 height:18 color:(color 0 0 155) modal:false
- spinner vSpinnerSelfIllum "" pos:[205,200] width:45 height:16 range:[0,100,0] type:#integer scale:1
- checkbox vCheckboxSelfIllumAmount "Amount" pos:[147,200] width:56 height:16
- checkbox vCheckboxSelfIllumColor "Color" pos:[147,221] width:47 height:16
-
- spinner vSpinnerOpacity "Amount " pos:[179,218] width:52 height:16 range:[0,100,100] type:#integer scale:1
-
- -- russom - 08/27/01 - 308413
- -- Can't assume getdir #ui returns <root>/ui
- -- removed getDir #ui references
- local vFlashPath = (getDir #maxroot) + "\\UI\\Flash\\gMaterialED-"
- local vIconPath = (getDir #maxroot) + "\\UI\\Icons\\gMaterialED"
- local vMovieTabs = "tabs"
- local vMovieTop = "top"
- local vMovieBottom = "bottom"
- local vMovieRight = "right"
- local vMovieArrow = "arrow"
- local vMovieHighlight = "highlight"
- local vIconCount = 9
- local vIconsNavigator = #(1,1)
- local vIconsOpen = #(2,2)
- local vIconsShow = #(2,4)
- local vIconsDelete = #(2,6)
- local vIconsSelect = #(2,8)
-
- local vOffsetInvisible = 500
-
- local vDimTabs = 0.80
- local vDimDisabled = 0.20
-
- local vTabDiffuse = "Diffuse"
- local vTabAmbient = "Ambient"
- local vTabHighlight = "Highlight"
- local vTabSpecularColor = "Color"
- local vTabSpecularLevel = "Level"
- local vTabGlossiness = "Glossiness"
- local vTabSelfIllum = "Self-Illumination"
- local vTabOpacity = "Opacity"
- local vTabBump = "Bump"
-
- local vSymbolDiffuse = vTabDiffuse
- local vSymbolAmbient = vTabAmbient
- local vSymbolHighlight = vTabHighlight
- local vSymbolSpecularColor = "Specular"
- local vSymbolSpecularLevel = "SpecularLevel"
- local vSymbolGlossiness = vTabGlossiness
- local vSymbolSelfIllum = "SelfIllum"
- local vSymbolOpacity = vTabOpacity
- local vSymbolBump = vTabBump
-
- local vOffsetMaterialID = 0
-
- local vFlagVisible = false
- local vTabCurrent = undefined
- local vMaterialCurrent = undefined
- local vMultiMaterial = undefined
- local vMaterialUndefined = standardMaterial name:"undefined"
- local vImageBuffer = bitmap 100 100 /* note: must be same size as vImageMap */
- local vMapUndefined, vColorText, vColorBackground, vColorViewport
- local vTabPrevious = undefined
- local vCountMaterials = 0
- local vUIParamChange = false -- flag for signaling material param change was due to UI action
-
- /* "fTabSymbol" converts a string from Flash tab's label or Mtl/Map Nav */
- /* channel spec to string used by this script as an ID for a tab when */
- /* it sends messages to Flash. The labels (which are also used as IDs) */
- /* contain spaces and the tab IDs returned by "fTabSymbol" are used to */
- /* form the prefix of names variables in Flash that this script will */
- /* assign values to in order to control the tabs' Flash display. */
- function fTabSymbol label =
- (
- local suffix = " Color"
- case label of (
- vTabDiffuse: vSymbolDiffuse
- (vTabDiffuse+suffix): vSymbolDiffuse
- vTabAmbient: vSymbolAmbient
- (vTabAmbient+suffix): vSymbolAmbient
- vTabHighlight: vSymbolHighlight
- vTabSpecularColor: vSymbolSpecularColor
- vTabSpecularLevel: vSymbolSpecularLevel
- vTabGlossiness: vSymbolGlossiness
- vTabSelfIllum: vSymbolSelfIllum
- vTabOpacity: vSymbolOpacity
- vTabBump: vSymbolBump
- default: undefined
- )
- )
-
- /* convert color to Flash's color values */
- function fFlashColor rgb =
- (
- local x = rgb as color
- local i = ((x.red as integer) * 256 + (x.green as integer)) * 256 + (x.blue as integer)
- (i as string)
- )
-
- function fEnableFlash item enabled =
- (
- if (item == vFlashHighlight) then (
- item.SetVariable "vEnabled" (enabled as string)
- ) else if (item == vFlashTabs and not enabled) then (
- local c = vColorBackground * (1.0 + vDimTabs) / 2
- item.SetVariable "colorText" (fFlashColor c)
- ) else (
- local c = vColorText
- if (not enabled) do
- c = vColorBackground + (c - vColorBackground) * vDimDisabled
- item.SetVariable "colorText" (fFlashColor c)
- )
- item.TCallLabel "/" "fUpdate"
- )
-
- function fEnable item enabled =
- (
- if ((classof item) == activeXControl) then
- fEnableFlash item enabled
- else
- item.enabled = enabled
- )
-
- function fSetPosition item visible enabled =
- (
- if (visible and item.pos.y > vOffsetInvisible) then
- item.pos.y = item.pos.y - vOffsetInvisible
- else if (not visible and item.pos.y < vOffsetInvisible) do
- item.pos.y = item.pos.y + vOffsetInvisible
- if (visible) do fEnable item enabled
- )
-
- function fSetPositionMap visible enabled mapDefined mapEnabled =
- (
- fSetPosition vGroupMap visible enabled
- fSetPosition vCheckboxMap visible mapDefined
- fSetPosition vSpinnerMap visible (mapDefined and mapEnabled)
- fSetPosition vButtonMapOpen visible enabled
- fSetPosition vButtonMapShow visible mapDefined
- fSetPosition vButtonMapClear visible mapDefined
- fSetPosition vImageMap visible false
- )
-
- function fSetPositionMatchDiffuse visible enabled =
- (
- fSetPosition vFlashArrow visible enabled
- fSetPosition vCheckboxMatchDiffuse visible enabled
- )
-
- function fSetPositionHighlight visible enabled =
- (
- fSetPosition vFlashHighlight visible enabled
- fSetPosition vSpinnerSpecularLevel visible enabled
- fSetPosition vSpinnerGlossiness visible enabled
- fSetPosition vSpinnerSoften visible enabled
- )
-
- function fSetPositionSelfIllum visible enabled color =
- (
- fSetPosition vCheckboxSelfIllumAmount visible enabled
- fSetPosition vSpinnerSelfIllum visible (enabled and not color)
- fSetPosition vCheckboxSelfIllumColor visible enabled
- fSetPosition vColorSelfIllum visible (enabled and color)
- )
-
- function fGetResizedImage map =
- (
- renderMap map into:vImageBuffer
- vImageBuffer
- )
-
- function fUpdateMaterials =
- (
- if (vMaterialED.vFlagVisible) do
- (
- local i, j=0, k=0, v = #()
- vCountMaterials = sceneMaterials.count
- v.count = vCountMaterials
- for i=1 to vCountMaterials do
- (
- local m = sceneMaterials[i]
- -- orb 08-22-2001 Fixing Defect 306419
- v[i] = if m != undefined then m.name else ""
-
- if (m == vMaterialCurrent) then j = i
- else if (m == vMultiMaterial) do k = i
- )
- vListMaterials.items = v
-
- local enabled = (vCountMaterials > 0)
- fEnable vLabelMaterials enabled
- fEnable vListMaterials enabled
-
- -- orb 07-30-01 fixing defect 298254
- if (k > 0) then i = k
- else if (j > 0) then i = j
- else i = 0
- vListMaterials.selection = i
- )
- )
-
- function fUpdateSubMaterials state =
- (
- if (state) then (
- local m = vMultiMaterial
- local i, j=0, v=#()
-
- -- orb 08-08-2001 Fixing defect 301873
- -- Apparently, some of the submaterials for a given multi-material
- -- are allowed to be undefined. This seems like it shouldn't be the case.
- -- Oh well, we have to look to see if any of the submtls are "fake".
- --
- local fakeSubs = 0
- for i=1 to m.numSubs do
- (
- if (m.materialList[i] == undefined) then
- (
- fakeSubs = fakeSubs + 1
- )
- )
-
- -- our array will only contain "real" submaterials
- v.count = m.numSubs - fakeSubs
-
-
- local vIdx = 0 -- index into our "real" array
- for i=1 to m.numSubs do
- (
- if (m.materialList[i] != undefined) then
- (
- if (m.materialList[i] == vMaterialCurrent) do j = i
- local k = m.materialIDList[i] - vOffsetMaterialID
-
- vIdx = vIdx + 1
- v[vIdx] = ((k as string) + ": " + m.materialList[i].name)
-
- )
- )
- vListSubMaterials.items = v
- if (j > 0) then vListSubMaterials.selection = j
- else vListSubMaterials.selection = 1
- ) else vListSubMaterials.items = #()
-
- fSetPosition vEditMultiMaterial state state
- fSetPosition vListSubMaterials state state
- fSetPosition vLabelSubMaterials state state
- )
-
-
- function fGetSelectedMaterial =
- (
- if (selection.count != 1) then
- undefined
- else
- ( local m, surf = selection[1]
- try m = surf.material
- catch m = undefined
- if (m == undefined) then undefined
- else
- ( local type = classof m
-
- if (type == StandardMaterial) then m
-
- else if (type != MultiMaterial) then undefined
- else if (subObjectLevel == undefined or subObjectLevel == 0) then m
- else
- ( type = classof surf
- if (type != Editable_Mesh and type != Editable_Poly) then undefined
- else
- ( local i=undefined, face, k, f = surf.selectedFaces
- if (f.count == 0) then undefined
- else
- ( for face in f do
- ( if (type == Editable_Mesh) then k = getFaceMatID surf face.index
- else k = polyOp.getFaceMatID surf face.index
- if (i == undefined) then i = k
- else if (k != i) do return undefined
- )
- #(m, (findItem m.materialIDList (i + vOffsetMaterialID)))
- )
- )
- )
- )
- )
- )
-
- -- orb 08-06-01 fixing defect 304170
- function fCountSelGeom =
- (
- local nCount = 0
- for obj in selection do
- (
- if (isKindOf obj shape) then
- (
- nCount = nCount + 1
- )
- else if (SuperClassOf obj == GeometryClass) then
- (
- if (obj.isTarget != true) then
- (
- nCount = nCount + 1
- )
-
- )
- )
- nCount
- )
-
- -- orb 08-22-2001 Fixing Defect 304726
- function fValidateShader m =
- (
- local bIsValid = true
- if (m != undefined) then
- (
- try
- (
- local test
- test = m.diffuseMap
- test = m.diffuseMapEnable
- test = m.diffuseMapAmount
- test = m.diffuse
- test = m.ambientMap
- test = m.ambientMapEnable
- test = m.ambientMapAmount
- test = m.adLock
- test = m.adTextureLock
- test = m.specularLevel
- test = m.glossiness
- test = m.soften
- test = m.specularMap
- test = m.specularMapEnable
- test = m.specularMapAmount
- test = m.dsLock
- test = m.specular
- test = m.specularLevelMap
- test = m.specularLevelMapEnable
- test = m.specularLevelMapAmount
- test = m.glossinessMap
- test = m.glossinessMapEnable
- test = m.glossinessMapAmount
- test = m.selfIllumMap
- test = m.selfIllumMapEnable
- test = m.selfIllumMapAmount
- test = m.useSelfIllumColor
- test = m.selfIllumAmount
- test = m.selfIllumColor
- test = m.opacityMap
- test = m.opacityMapEnable
- test = m.opacityMapAmount
- test = m.opacity
- test = m.bumpMapEnable
- test = m.bumpMapAmount
- )
- catch
- (
- bIsValid = false
- )
- )
- bIsValid
- )
-
- function fUpdateTools =
- (
- if (vMaterialED.vFlagVisible) do
- (
- -- orb 08-22-2001 Fixing Defect 304726
- local f = ((vMaterialCurrent != undefined) and (vMaterialED.fValidateShader vMaterialCurrent))
-
- fEnable vButtonGet (fGetSelectedMaterial()!=undefined)
- fEnable vButtonNew true
- fEnable vButtonApply (f and vMaterialED.fCountSelGeom()>0)
- fEnable vButtonCopy f
- fEnable vButtonDelete f
- fEnable vButtonMaterialShow f
- fEnable vButtonSelect f
-
- local mtlOn = vMaterialED.fGetMaterialSMIVState(vMaterialCurrent)
- vButtonMaterialShow.state = (f and mtlOn)
-
- fUpdateSubMaterials (vMultiMaterial != undefined)
-
- if (f) then (
- vEditName.text = vMaterialCurrent.name
- if (vMultiMaterial != undefined) do vEditMultiMaterial.text = vMultiMaterial.name
- vCheckboxTwoSided.state = vMaterialCurrent.twoSided
- ) else (
- vEditName.text = ""
- vCheckboxTwoSided.state = false
- )
- fEnable vEditName f
- fEnable vLabelOptions f
- fEnable vCheckboxTwoSided f
- )
- )
-
- function fUpdatePanel tab:undefined =
- (
- if (tab != undefined) then (
- vTabCurrent = tab
- local label = tab
- if (tab == vTabSpecularColor or tab == vTabSpecularLevel) do
- label = "Specular " + label
- if (tab == vTabSpecularLevel or tab == vTabGlossiness) then
- label = label + " Map"
- else label = label + " Factors"
- vFlashTop.SetVariable "label.text" label
- vGroupMap.text = tab + " Map"
- ) else if (vTabCurrent == undefined) do return 0
-
- local m, f = (vMaterialCurrent != undefined)
- if (f) then m = vMaterialCurrent
- else m = vMaterialUndefined
- fEnable vLabelComponents f
- fEnable vFlashTabs f
- fEnable vFlashTop f
-
- local map, mapEnable, mapAmount
- local flagMatchDiffuse=false, flagColor=false
-
- -- orb 08-22-2001 Fixing Defect 304726
- if (vMaterialED.fValidateShader m) then
- (
- case vTabCurrent of (
- vTabDiffuse: (
- map = m.diffuseMap
- mapEnable = m.diffuseMapEnable
- mapAmount = m.diffuseMapAmount
- vColor.color = m.diffuse
- flagColor = true
- )
- vTabAmbient: (
- map = m.ambientMap
- mapEnable = m.ambientMapEnable
- mapAmount = m.ambientMapAmount
- if (f) then vCheckboxMatchDiffuse.state = (m.adLock or m.adTextureLock)
- else vCheckboxMatchDiffuse.state = false
- vColor.color = m.ambient
- flagMatchDiffuse = true
- flagColor = true
- )
- vTabHighlight: (
- vSpinnerSpecularLevel.value = m.specularLevel
- vSpinnerGlossiness.value = m.glossiness
- vSpinnerSoften.value = m.soften
- )
- vTabSpecularColor: (
- map = m.specularMap
- mapEnable = m.specularMapEnable
- mapAmount = m.specularMapAmount
- if (f) then vCheckboxMatchDiffuse.state = m.dsLock
- else vCheckboxMatchDiffuse.state = false
- vColor.color = m.specular
- flagMatchDiffuse = true
- flagColor = true
- )
- vTabSpecularLevel: (
- map = m.specularLevelMap
- mapEnable = m.specularLevelMapEnable
- mapAmount = m.specularLevelMapAmount
- )
- vTabGlossiness: (
- map = m.glossinessMap
- mapEnable = m.glossinessMapEnable
- mapAmount = m.glossinessMapAmount
- )
- vTabSelfIllum: (
- map = m.selfIllumMap
- mapEnable = m.selfIllumMapEnable
- mapAmount = m.selfIllumMapAmount
- vCheckboxSelfIllumAmount.state = (not m.useSelfIllumColor)
- vCheckboxSelfIllumColor.state = m.useSelfIllumColor
- vSpinnerSelfIllum.value = m.selfIllumAmount
- vColorSelfIllum.color = m.selfIllumColor
- )
- vTabOpacity: (
- map = m.opacityMap
- mapEnable = m.opacityMapEnable
- mapAmount = m.opacityMapAmount
- vSpinnerOpacity.value = m.opacity
- )
- vTabBump: (
- map = m.bumpMap
- mapEnable = m.bumpMapEnable
- mapAmount = m.bumpMapAmount
- )
- default: return 0
- )
- )
-
- fSetPositionHighlight (vTabCurrent == vTabHighlight) f
- if (flagMatchDiffuse) then (
- fSetPositionMatchDiffuse true f
- f = (f and (not vCheckboxMatchDiffuse.state))
- ) else fSetPositionMatchDiffuse false false
- if (flagColor) then fSetPosition vColor true f
- else fSetPosition vColor false false
- if (vTabCurrent == vTabSelfIllum) then fSetPositionSelfIllum true f m.useSelfIllumColor
- else fSetPositionSelfIllum false false false
- if (vTabCurrent == vTabOpacity) then fSetPosition vSpinnerOpacity true f
- else fSetPosition vSpinnerOpacity false false
-
- if (vTabCurrent == vTabHighlight) then fSetPositionMap false false false false
- else (
- fSetPositionMap true f (map != undefined) mapEnable
- if (map == undefined) then (
- vCheckboxMap.state = false
- vSpinnerMap.value = 0
- vImageMap.bitmap = vMapUndefined
- vButtonMapShow.state = false
- ) else (
- vCheckboxMap.state = mapEnable
- vSpinnerMap.value = mapAmount
- vImageMap.bitmap = fGetResizedImage map
- vButtonMapShow.state = vMaterialED.fGetMapSMIVState(map)
- )
- )
-
- vTabPrevious = vTabCurrent
- )
-
- function fSetTab type =
- (
- -- orb 07-19-2001 Fixing defect 301851
- if (type == undefined) do type = vSymbolDiffuse
-
- vFlashTabs.SetVariable "tabSelect" type
- vFlashTabs.TCallLabel "/" "fUpdate"
- )
-
- function fSetTabColor type color =
- (
- vFlashTabs.SetVariable ("color" + type) (fFlashColor color)
- vFlashTabs.TCallLabel "/" "fUpdate"
- )
-
- function fSetTabAmount type value =
- (
- vFlashTabs.SetVariable ("amount" + type) (value as string)
- vFlashTabs.TCallLabel "/" "fUpdate"
- )
-
- function fSetTabValue type =
- (
- local m = vMaterialCurrent
- case type of (
- vSymbolSpecularLevel: (
- if (m.specularLevel > 0) then fSetTabAmount type m.specularLevel
- else fSetTabAmount type false
- )
- vSymbolGlossiness: (
- if (m.specularLevel > 0) then fSetTabAmount type m.glossiness
- else fSetTabAmount type false
- )
- vSymbolSelfIllum: (
- if (m.useSelfIllumColor) then (
- local c = m.selfIllumColor
- if (c.red > 0 or c.green > 0 or c.blue > 0) then
- fSetTabColor type c
- else fSetTabAmount type false
- ) else if (m.selfIllumAmount > 0) then
- fSetTabAmount type m.selfIllumAmount
- else fSetTabAmount type false
- )
- vSymbolOpacity: (
- if (m.opacity < 100) then fSetTabAmount type m.opacity
- else fSetTabAmount type false
- )
- default: ()
- )
- )
-
- function fSetTabMap type state =
- (
- vFlashTabs.SetVariable ("map" + type) (state as string)
- vFlashTabs.TCallLabel "/" "fUpdate"
- )
-
- function fSetTabDiffuseRelative type =
- (
- local lock, color, map, mtl = vMaterialCurrent
- if (type == vSymbolAmbient) then (
- lock = (mtl.adLock or mtl.adTextureLock)
- color = mtl.ambient
- map = mtl.ambientMapEnable
- ) else (
- lock = mtl.dsLock
- color = mtl.specular
- map = mtl.specularMapEnable
- )
- vFlashTabs.SetVariable ("lock" + type) (lock as string)
- vFlashTabs.TCallLabel "/" "fUpdate"
- if (not lock) do (
- fSetTabColor type color
- fSetTabMap type map
- )
- )
-
- function fDrawHighlight =
- (
- local level=0, gloss=0
- if (vMaterialCurrent != undefined) do (
- level = vMaterialCurrent.specularLevel
- gloss = vMaterialCurrent.glossiness
- )
- vFlashHighlight.SetVariable "vSpecularLevel" (level as string)
- vFlashHighlight.SetVariable "vGlossiness" (gloss as string)
- vFlashHighlight.TCallLabel "/" "fUpdate"
- )
-
- function fUpdateFlashValues =
- (
- local m = vMaterialCurrent
-
- -- orb 08-22-2001 Fixing Defect 304726
- if (vMaterialED.fValidateShader m) then
- (
- fSetTabColor vSymbolDiffuse m.diffuse
- fSetTabMap vSymbolDiffuse m.diffuseMapEnable
- fSetTabDiffuseRelative vSymbolAmbient
- fSetTabDiffuseRelative vSymbolSpecularColor
- fSetTabValue vSymbolSpecularLevel
- fSetTabMap vSymbolSpecularLevel m.specularLevelMapEnable
- fSetTabValue vSymbolGlossiness
- fSetTabMap vSymbolGlossiness m.glossinessMapEnable
- fSetTabValue vSymbolSelfIllum
- fSetTabMap vSymbolSelfIllum m.selfIllumMapEnable
- fSetTabValue vSymbolOpacity
- fSetTabMap vSymbolOpacity m.opacityMapEnable
- fSetTabMap vSymbolBump m.bumpMapEnable
- fDrawHighlight()
- )
- else
- (
- vMaterialED.fSetCurrentMaterial undefined
- vMaterialED.fResetGUI()
-
- )
- )
-
- function fMessageUnsupported mat =
- (
- messageBox ("Warning: unsupported shader on material " + mat.name + ".")
- )
-
- function fUpdatePropertyDisplay =
- (
- if (not vUIParamChange and vMaterialED.vFlagVisible and vMaterialED.vMaterialCurrent != undefined) then (
- vUIParamChange = false -- LAM - 8/28/01
- vMaterialED.fUpdatePanel()
- vMaterialED.fUpdateFlashValues()
- )
- else
- vUIParamChange = false -- LAM - 8/28/01
- )
-
- function fSetCurrentMaterial material =
- (
- try deleteAllChangeHandlers id:#gMaterialEdTransient
- catch ()
- vMaterialCurrent = material
- if (material != undefined) then
- (
- when parameters material change id:#gMaterialEdTransient handleAt:#redrawViews do vMaterialED.fUpdatePropertyDisplay()
- )
-
-
- )
-
- function fResetGUI tab:undefined =
- (
- -- orb 07-20-2001: don't do anything unles the window is visible
- if (vMaterialED.vFlagVisible) do
- (
- if (tab == undefined) do tab = vSymbolDiffuse
-
-
- -- orb 08-22-2001 Fixing Defect 304726
- if (vMaterialED_SetMaterial[1] != undefined) then
- (
- if (vMaterialED.fValidateShader vMaterialED_SetMaterial[1]) then
- (
- fSetCurrentMaterial vMaterialED_SetMaterial[1]
- vMultiMaterial = vMaterialED_SetMaterial[2]
- tab = vMaterialED_SetMaterial[3]
- vMaterialED_SetMaterial[1] = undefined
- vMaterialED_SetMaterial[2] = undefined
- vMaterialED_SetMaterial[3] = undefined
- )
- else
- (
- vMaterialED.fMessageUnsupported vMaterialED_SetMaterial[1]
- )
- )
-
- fUpdateMaterials()
- fUpdateTools()
- vFlashTabs.TCallLabel "/" "fInitialize"
- if (vMaterialCurrent != undefined) do fUpdateFlashValues()
- fSetTab tab
- )
- )
-
- -- orb 07-19-2001 Fixing defect 301872
- -- Also call this in callbacks at the bottom of file
- function fResetDefaultGUI =
- (
- vMaterialED_SetMaterial[1] = undefined
- vMaterialED_SetMaterial[2] = undefined
- vMaterialED_SetMaterial[3] = undefined
- fSetCurrentMaterial undefined
- vMultiMaterial = undefined
- vTabCurrent = undefined
- fResetGUI()
- )
-
- function fCheckMaterials =
- (
- if (vMaterialED.vFlagVisible \
- and vMaterialED.vCountMaterials != sceneMaterials.count) do
- vMaterialED.fResetDefaultGUI()
- )
-
- function fOpen =
- (
-
- if (vMaterialED_Flash5Installed != 1) then
- (
- -- This will be true if the first time we tried to open it it failed
- -- This way the message box will pop up every time the user hits
- -- the mtl editor button
- MessageBox "Error: Macromedia Flash 5 Player is required to run the gmax Material Editor" title:"gmax Material Editor"
- )
- else
- (
- try (
- createDialog vMaterialED \
- pos: vMaterialED_Position \
- style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
- -- orb 08-06-01 Fixing defect 304842
- setFocus vMaterialED
- )
- catch
- (
- vMaterialED_Flash5Installed = 0
- vFlagVisible = false
- callbacks.removeScripts id:#gMaterialED
- callbacks.removeScripts id:#gMaterialEdPersistent
- unregisterTimeCallback fUpdatePropertyDisplay
- deleteAllChangeHandlers id:#gMaterialEdTransient
- MessageBox "Error: Macromedia Flash 5 Player is required to run the gmax Material Editor" title:"gmax Material Editor"
- )
- )
- )
-
- function fGetMaterialByName name =
- (
- local mtl
- for mtl in sceneMaterials do
- if (mtl.name == name) do return mtl
- undefined
- )
-
- function fGetCopyName name =
- (
- local i=0, s1="Copy", s2=" of "+name
- name = s1 + s2
- while ((fGetMaterialByName name) != undefined) do (
- i = i + 1
- name = s1 + (i as string) + s2
- )
- name
- )
-
- function fGetMaterial new:false fromCopy:false index:undefined =
- (
- local m = vMaterialCurrent
- if (new) then (
- m = standardMaterial()
- assignNewName m
- append sceneMaterials m
- -- orb 08-01-01 have to update SMIV for vMaterialCurrent!!!
- vMaterialCurrent = m
- vMaterialED.fShowMaterial true
-
- ) else if (fromCopy) then (
- if (vMultiMaterial != undefined) do m = vMultiMaterial
- local n = copy m
- n.name = fGetCopyName m.name
- if (vMultiMaterial != undefined) do (
- local i=0, s, t
- for s in m.materialList do (
- t = copy s
- t.name = fGetCopyName s.name
- i = i + 1
- n.materialList[i] = t
- )
- )
- append sceneMaterials n
- m = n
- ) else if (index != undefined) do
- m = sceneMaterials[index]
- m
- )
-
- function fGetMaterialFromSlot index =
- (
- /* get material from core Material Editor slot */
- local m = getMeditMaterial index
-
- /* determine if material is already in scene */
- local mtl
- for mtl in sceneMaterials do
- if (mtl == m) do return m
-
- /* not in scene -> add to scene with unique name */
- if ((fGetMaterialByName m.name) != undefined) do m.name = fGetCopyName m.name
- append sceneMaterials m
- m
- )
-
- function fSetMaterial material subIndex:undefined tab:undefined =
- (
- local type = classof material
- if (type == MultiMaterial) then (
- vMultiMaterial = material
- if (subIndex == undefined) do subIndex = 1
- if (subIndex > 0 and subIndex <= material.numSubs) then
- material = material.materialList[subIndex]
- else material = undefined
- ) else (
- vMultiMaterial = undefined
-
- if (type != StandardMaterial) then
- (
- -- orb 08-22-2001 Fixing Defect 304726
- local msg = "Warning: Material " + material.name + " is an unsupported material type."
- messageBox (msg)
- material = undefined
- )
- else if (not (vMaterialED.fValidateShader material)) then
- (
- -- orb 08-22-2001 Fixing Defect 304726
- vMaterialED.fMessageUnsupported material
- )
- )
- fSetCurrentMaterial material
- if (vFlagVisible) then fResetGUI tab:tab
- else (
- vMaterialED_SetMaterial = #(vMaterialCurrent,vMultiMaterial,tab)
- fOpen()
- )
- )
-
- function fSetSubMaterial index =
- (
- fSetCurrentMaterial vMultiMaterial.materialList[index]
- fResetGUI tab:(fTabSymbol vTabCurrent)
- )
-
- function fSelectMaterial =
- (
- local m = fGetSelectedMaterial()
- if (m != undefined) do (
- if ((classof m) == Array) then fSetMaterial m[1] subIndex:m[2]
- else fSetMaterial m
- )
- )
-
- function fSetMap map =
- (
- try
- ( vUIParamChange = true
- local m = vMaterialCurrent
- if (map == undefined) do (
- local map0
- case vTabCurrent of (
- vTabDiffuse: map0 = m.diffuseMap
- vTabAmbient: map0 = m.ambientMap
- vTabSpecularColor: map0 = m.specularMap
- vTabSpecularLevel: map0 = m.specularLevelMap
- vTabGlossiness: map0 = m.glossinessMap
- vTabSelfIllum: map0 = m.selfIllumMap
- vTabOpacity: map0 = m.opacityMap
- vTabBump: map0 = m.bumpMap
- default: (vUIParamChange = false;return 0) -- LAM - 8/28/01
- )
- if (map0 != undefined) do (
- vMaterialED.fShowMap false
- vCheckboxMap.state = false
- fEnable vCheckboxMap false
- vSpinnerMap.value = 0
- fEnable vSpinnerMap false
- fEnable vButtonMapClear false
- vImageMap.bitmap = vMapUndefined
- )
- )
- local f = (map != undefined)
- case vTabCurrent of (
- vTabDiffuse: (
- m.diffuseMap = map
- fSetTabMap vSymbolDiffuse f
- )
- vTabAmbient: (
- m.ambientMap = map
- fSetTabMap vSymbolAmbient f
- )
- vTabSpecularColor: (
- m.specularMap = map
- fSetTabMap vSymbolSpecularColor f
- )
- vTabSpecularLevel: (
- m.specularLevelMap = map
- fSetTabMap vSymbolSpecularLevel f
- )
- vTabGlossiness: (
- m.glossinessMap = map
- fSetTabMap vSymbolGlossiness f
- )
- vTabSelfIllum: (
- m.selfIllumMap = map
- fSetTabMap vSymbolSelfIllum f
- )
- vTabOpacity: (
- m.opacityMap = map
- fSetTabMap vSymbolOpacity f
- )
- vTabBump: (
- m.bumpMap = map
- fSetTabMap vSymbolBump f
- )
- default: (
- vUIParamChange = false
- return 0
- )
- )
- if (map != undefined) then (
- -- orb 08-01-01 removed this to fix defect
- -- showTextureMap m map true
-
- vCheckboxMap.state = true
- fEnable vCheckboxMap true
- vSpinnerMap.value = 100
- fEnable vSpinnerMap true
- fEnable vButtonMapClear true
- fEnable vButtonMapShow true
- vImageMap.bitmap = fGetResizedImage map
- )
- )
- catch ()
- -- vUIParamChange = false -- LAM - 8/28/01
- )
-
- function fChangeMap mode =
- (
- if (mode == #clear) then fSetMap undefined
- else if (mode == #open) do (
- local s = "Locate bitmap file for " + vTabCurrent + " component ..."
- local i = selectBitMap caption:s
- if (i != undefined) then
- (
- bmTex = bitmapTexture bitmap:i
-
- -- orb 08-07-01 Fixing defect 305535
- bmTex.Reload()
- fSetMap (bmTex)
- )
- )
- )
-
- function fGetMapSMIVState map =
- (
- local mapIsOn = false
- if (map != undefined) then
- (
- bits = getMTLMEditFlags map
- if bits[6] then (mapIsOn = true)
- else (mapIsOn = false)
- )
- mapIsOn
- )
-
- function fGetMaterialSMIVState mtl =
- (
- local mtlIsOn = false
-
- if (mtl!=undefined) then
- (
- local bits
- bits = getMTLMEditFlags mtl
- if bits[6] then
- (
- mtlIsOn = true
- )
- else
- (
- mtlIsOn = false
- )
- )
- mtlIsOn
- )
-
- -- orb 07-25-01
- -- fShowMap turns on the "map level" show map in viewport (SMIV) for the current map
- -- if state is true, then it also turns off the "material level" SMIV for the current material
- function fShowMap state =
- (
- local m = vMaterialCurrent
- if (m != undefined) do (
- local map0
- case vTabCurrent of (
- vTabDiffuse: map0 = m.diffuseMap
- vTabAmbient: map0 = m.ambientMap
- vTabSpecularColor: map0 = m.specularMap
- vTabSpecularLevel: map0 = m.specularLevelMap
- vTabGlossiness: map0 = m.glossinessMap
- vTabSelfIllum: map0 = m.selfIllumMap
- vTabOpacity: map0 = m.opacityMap
- vTabBump: map0 = m.bumpMap
- default: return 0
- )
- if (map0 != undefined) then
- (
- local mapOn = false
- mapOn = fGetMapSMIVState(map0)
- if (mapOn != state) then
- (
- showTextureMap m map0 state
- if (state == true) then
- (
- -- We've turned on the "map SMIV", so turn off the "material" SMIV
- showTextureMap m false
- )
- )
- vMaterialED.fResetGUI tab:(fTabSymbol vTabCurrent) -- update the SMIV buttons for "material" and "map"
-
- )
- )
-
- )
-
- -- orb 07-25-01
- -- fShowMaterial turns on the "material level" show map in viewport (SMIV) for the current material
- -- if state is true, then it also turns off all submaps "map level" SMIV
- function fShowMaterial state =
- (
- local m = vMaterialCurrent
- if (m != undefined) then
- (
- local mtlOn = false
- mtlOn = fGetMaterialSMIVState(m)
- if (mtlOn != state) then
- (
- showTextureMap m state
- if (state == true) then
- (
- -- We've turned on the "material SMIV", so turn off all the submaps SMIV
- if (m.diffuseMap != undefined) do showTextureMap m m.diffuseMap false
- if (m.ambientMap != undefined) do showTextureMap m m.ambientMap false
- if (m.specularMap != undefined) do showTextureMap m m.specularMap false
- if (m.specularLevelMap != undefined) do showTextureMap m m.specularLevelMap false
- if (m.glossinessMap != undefined) do showTextureMap m m.glossinessMap false
- if (m.selfIllumMap != undefined) do showTextureMap m m.selfIllumMap false
- if (m.opacityMap != undefined) do showTextureMap m m.opacityMap false
- if (m.bumpMap != undefined) do showTextureMap m m.bumpMap false
- )
- vMaterialED.fResetGUI tab:(fTabSymbol vTabCurrent) -- update the SMIV buttons for "material" and "map"
- )
- )
- )
-
- function fProcessNameChange material field =
- (
- local mtl, name = field.text
- if (name == material.name) then
- false
- else
- (
- if (name == "") then (
- field.text = material.name
- messageBox "Materials cannot have blank names." title:"gmax Material Editor: Error"
- false
- )
- else
- ( for mtl in sceneMaterials do
- if (name == mtl.name and mtl != vMaterialCurrent) do (
- field.text = material.name
- messageBox ("Name \"" + name + "\" is used by another material." \
- + " Material names must be unique.") \
- title:"MaterialED: Error"
- return false
- )
-
- vUIParamChange = true
- material.name = name
- -- vUIParamChange = false -- LAM - 8/28/01
- fUpdateMaterials()
- true
- )
- )
- )
-
- function fEditMaterial field value =
- (
- try
- ( vUIParamChange = true
- if ((vMaterialCurrent != undefined and field != #nameMulti)\
- or (vMultiMaterial != undefined and field == #nameMulti)) do
-
- ( local m=vMaterialCurrent, x=value
- case field of (
- #name: if ((fProcessNameChange vMaterialCurrent vEditName) \
- and vMultiMaterial != undefined) do fUpdateSubMaterials true
- #nameMulti: fProcessNameChange vMultiMaterial vEditMultiMaterial
- #twoSided: m.twoSided = vCheckboxTwoSided.state
- #matchDiffuse: (
- if (vTabCurrent == vTabAmbient) then (
- if (x == undefined) do x = not (m.adLock or m.adTextureLock)
- m.adLock = x
- m.adTextureLock = x
- fSetTabDiffuseRelative vSymbolAmbient
- ) else (
- if (x == undefined) do x = not m.dsLock
- m.dsLock = x
- fSetTabDiffuseRelative vSymbolSpecularColor
- )
- fUpdatePanel() -- LAM - 8/28/01 - shouldn't need this. change handler will call
- )
- #color: (
- if (vTabCurrent == vTabDiffuse) then (
- m.diffuse = x
- fSetTabColor vSymbolDiffuse x
- ) else if (vTabCurrent == vTabAmbient) then (
- m.ambient = x
- fSetTabColor vSymbolAmbient x
- ) else ( /* vTabCurrent == vTabSpecularColor */
- m.specular = x
- fSetTabColor vSymbolSpecularColor x
- )
- )
- #specularLevel: (
- m.specularLevel = x
- fSetTabValue vSymbolSpecularLevel
- fSetTabValue vSymbolGlossiness
- fDrawHighlight()
- )
- #glossiness: (
- m.glossiness = x
- fSetTabValue vSymbolSpecularLevel
- fSetTabValue vSymbolGlossiness
- fDrawHighlight()
- )
- #soften: m.soften = x
- #selfIllumType: (
- m.useSelfIllumColor = not x
- vCheckboxSelfIllumAmount.state = x
- vCheckboxSelfIllumColor.state = not x
- fEnable vSpinnerSelfIllum x
- fEnable vColorSelfIllum (not x)
- fSetTabValue vSymbolSelfIllum
- )
- #selfIllumAmount: (
- m.selfIllumAmount = x
- fSetTabValue vSymbolSelfIllum
- )
- #selfIllumColor: (
- m.selfIllumColor = x
- fSetTabValue vSymbolSelfIllum
- )
- #opacity: (
- m.opacity = x
- fSetTabValue vSymbolOpacity
- )
- #map: (
- case vTabCurrent of (
- vTabDiffuse: (
- m.diffuseMapEnable = x
- fSetTabMap vSymbolDiffuse x
- )
- vTabAmbient: (
- m.ambientMapEnable = x
- fSetTabMap vSymbolAmbient x
- )
- vTabSpecularColor: (
- m.specularMapEnable = x
- fSetTabMap vSymbolSpecularColor x
- )
- vTabSpecularLevel: (
- m.specularLevelMapEnable = x
- fSetTabMap vSymbolSpecularLevel x
- )
- vTabGlossiness: (
- m.glossinessMapEnable = x
- fSetTabMap vSymbolGlossiness x
- )
- vTabSelfIllum: (
- m.selfIllumMapEnable = x
- fSetTabMap vSymbolSelfIllum x
- )
- vTabOpacity: (
- m.opacityMapEnable = x
- fSetTabMap vSymbolOpacity x
- )
- vTabBump: (
- m.bumpMapEnable = x
- fSetTabMap vSymbolBump x
- )
- default: (
- vUIParamChange = false
- return 0
- )
- )
- fEnable vSpinnerMap x
- )
- #mapAmount: (
- case vTabCurrent of (
- vTabDiffuse: m.diffuseMapAmount = x
- vTabAmbient: m.ambientMapAmount = x
- vTabSpecularColor: m.specularMapAmount = x
- vTabSpecularLevel: m.specularLevelMapAmount = x
- vTabGlossiness: m.glossinessMapAmount = x
- vTabSelfIllum: m.selfIllumMapAmount = x
- vTabOpacity: m.opacityMapAmount = x
- vTabBump: m.bumpMapAmount = x
- default: (vUIParamChange = false) -- LAM - 8/28/01
- )
- )
- default: (vUIParamChange = false) -- LAM - 8/28/01
- )
- )
- )
- catch ()
- -- vUIParamChange = false -- LAM - 8/28/01
-
- )
-
- function fApplyMaterial =
- (
- local mtl=vMaterialCurrent, mtlNew=undefined, idxNew=undefined, obj
- if (vMultiMaterial != undefined \
- and (subObjectLevel == undefined or subObjectLevel == 0)) do mtl = vMultiMaterial
- for obj in selection do
- try (
- obj.material = mtl
- if (obj.material != mtl) do (
- mtlNew = obj.material
- if ((classof mtlNew) == MultiMaterial) do (
- local j = findItem mtlNew.materialList vMaterialCurrent
- if (j > 0) do idxNew = j
- )
- )
- )
- catch ()
- if (mtlNew != undefined) do fSetMaterial mtlNew subIndex:idxNew
-
- -- orb 08-06-01 Fixing defect 303795
- vMaterialED.fResetGUI()
- )
-
- function fDeleteMaterial =
- (
- local i, m = vMaterialCurrent
- if (vMultiMaterial != undefined) do m = vMultiMaterial
- for i in rootNode.children do
- try if (i.material == m) do i.material = undefined
- catch ()
- i = findItem sceneMaterials m
- if (i > 0) do deleteItem sceneMaterials i
- fSetCurrentMaterial undefined
- vMaterialED.fResetGUI()
-
- )
-
- function fUpdateColors =
- (
- if (vMaterialED.vFlagVisible) do
-
- ( vColorText = (colorMan.getColor #text) * 255
- vColorBackground = (colorMan.getColor #background) * 255
- vColorViewport = (getUIColor 41) * 255
-
- local c1 = fFlashColor vColorText
- local c2 = fFlashColor vColorBackground
- local c3 = fFlashColor (vColorBackground * vDimTabs)
- local f, v = #( vFlashTabs, vFlashRight, vFlashTop, vFlashBottom, vFlashArrow )
- for f in v do (
- f.SetVariable "colorText" c1
- f.SetVariable "colorBackground" c2
- f.SetVariable "colorSelected" c2
- f.SetVariable "colorUnselected" c3
- f.TCallLabel "/" "fUpdate"
- )
- vFlashHighlight.SetVariable "rgbBackground" (fFlashColor vColorViewport)
- vFlashHighlight.SetVariable "rgbDisabled" c2
- vFlashHighlight.TCallLabel "/" "fApplyColors"
-
- vMapUndefined = bitmap 1 1 color:vColorBackground
- )
- )
-
- function fLoadGraphics control graphics =
- (
- if ((classof control) == activeXControl) then (
- control.movie = vFlashPath + graphics + ".swf"
- control.menu = false
- ) else (
- local file1 = vIconPath + "_i.bmp"
- local file2 = vIconPath + "_a.bmp"
- local count = graphics[1]
- local i1 = graphics[2]
- local i2 = graphics[2]
- if (count > 1) do i2 = i2 + 1
- control.images = #(file1, file2, vIconCount, i1, i1, i2, i2)
- )
- )
-
- function fInitializeWindow =
- (
- vFlagVisible = true
- if ((maxversion())[1] < 4200) do vOffsetMaterialID = -1
- fLoadGraphics vFlashTabs vMovieTabs
- fLoadGraphics vFlashTop vMovieTop
- fLoadGraphics vFlashBottom vMovieBottom
- fLoadGraphics vFlashRight vMovieRight
- fLoadGraphics vFlashArrow vMovieArrow
- fLoadGraphics vFlashHighlight vMovieHighlight
- fLoadGraphics vButtonNavigator vIconsNavigator
- fLoadGraphics vButtonSelect vIconsSelect
- fLoadGraphics vButtonMapOpen vIconsOpen
- fLoadGraphics vButtonMapClear vIconsDelete
- fLoadGraphics vButtonMaterialShow vIconsShow
- fLoadGraphics vButtonMapShow vIconsShow
- fUpdateColors()
- fSetPositionMatchDiffuse false false
- fSetPositionHighlight false false
- fSetPositionSelfIllum false false false
- fSetPosition vSpinnerOpacity false false
- fResetGUI()
- )
-
- function fTabsCallback command args =
- (
- local arg = filterString args ","
- if (command == "tab") then fUpdatePanel tab:args
- else if (command == "map" or command == "color") then (
- local type = #((fTabSymbol arg[1]), (fTabSymbol arg[2]))
- local base = "vMaterialED.vMaterialCurrent.", assign="="
- local source = base + type[1]
- local target = base + type[2]
- if command == "map" then (
- local map="Map", amount="Amount", enable="Enable"
- try (
- execute(target+map + assign + "copy " + source+map)
- execute(target+map+amount + assign + source+map+amount)
- execute(target+map+enable + assign + source+map+enable)
- )
- catch ()
- fSetTabMap type[2] (execute (target+map + "!= undefined"))
- ) else (
- local suffix = "Color"
- if (type[1] == vSymbolSelfIllum) do source = source + suffix
- if (type[2] == vSymbolSelfIllum) do (
- target = target + suffix
- vMaterialED.vMaterialCurrent.useSelfIllumColor = true
- )
- try execute(target + assign + source)
- catch ()
- fSetTabColor type[2] (execute target)
- )
- fSetTab type[2]
- ) /* else messageBox (command + args) *//* debug aid */
- )
-
- function fSelectByMaterialFilter object =
- (
- local m
- try m = object.material
- catch ()
- if m != undefined then
- ( local c = classof m
- if (c == StandardMaterial) then
- (m == vMaterialCurrent)
- else if (c == MultiMaterial) do (
- local v = m.materialList
- local sMtl
- for sMtl in v do
- if (sMtl == vMaterialCurrent) do return true
- false
- )
- )
- else
- false
- )
-
- function fSelectByMaterial =
- (
-
- local obj, v = selectByName filter:fSelectByMaterialFilter showHidden:true \
- title:("Select from Objects with Material \"" + vMaterialCurrent.name + "\"")
- if (v != undefined) do
- select v
- )
-
- /* fSet-BySlot functions are interface for external code to tell */
- /* scripted editor to load a particular material and/or to pick */
- /* a particular tabbed panel. Arguments include a core Material */
- /* Editor slot number which indicates the location of the material */
- /* object to be loaded. Other arguments may specify a submaterial */
- /* (by index) or tab (by channel name). The Material/Map Navigator */
- /* calls these functions when it executes "open" operations. */
- /**/
- /* fSetMaterialBySlot slot: Directs the scripted editor */
- /* to the material in slot number "slot" (int>=1) */
- /* with the Diffuse panel showing.
- /* Opens a top-level StandardMaterial or MultiMaterial. */
- /**/
- /* fSetMaterialTabBySlot slot tab: Directs the scripted editor */
- /* to the material in slot number "slot" (int>=1) at the "tab" */
- /* panel (string = "Diffuse Color", "Ambient Color", ...). */
- /* Opens a map channel within a top-level StandardMaterial. */
- /**/
- /* fSetMultiMaterialBySlot slot index: Directs the scripted editor to */
- /* submaterial number "index" (int>=1) of the MultiMaterial in slot */
- /* number "slot" (int>=1) with the Diffuse panel showing. Opens a */
- /* submaterial (i.e., StandardMaterial nested within a MultiMaterial). */
- /**/
- /* fSetMultiMaterialTabBySlot slot index tab: Directs the scripted editor */
- /* to the submaterial number "index" (int>=1) of the MultiMaterial in */
- /* slot number "slot" (int) with the panel specified by "tab" (string) */
- /* showing. Opens a map channel within a submaterial. */
-
- function fSetMaterialBySlot slot =
- (
- fSetMaterial (fGetMaterialFromSlot slot)
- )
-
- function fSetMaterialTabBySlot slot tab =
- (
- fSetMaterial (fGetMaterialFromSlot slot) tab:(fTabSymbol tab)
- )
-
- function fSetMultiMaterialBySlot slot index =
- (
- fSetMaterial (fGetMaterialFromSlot slot) subIndex:index
- )
-
- function fSetMultiMaterialTabBySlot slot index tab =
- (
- fSetMaterial (fGetMaterialFromSlot slot) subIndex:index tab:(fTabSymbol tab)
- )
-
- function fTerminateWindow =
- (
-
-
- vMaterialED_Position = GetDialogPos(vMaterialEd)
-
- try deleteAllChangeHandlers id:#gMaterialEdTransient
- catch ()
- vFlagVisible = false
- )
-
- -- orb 08-07-01 added this function & calls below to fix 304061
- function fUpdateListText text multi =
- (
- if (multi) then
- (
- -- user is typing in vEditMultiMaterial
- -- update the multi-material name in the materials list
- if vListMaterials.selection != 0 do vListMaterials.selected = text
- )
- else
- (
- -- user is typing in vEditName
- if (vMultiMaterial != undefined) then
- (
- -- update the subMaterial name in the submaterials list
- if vListSubMaterials.selection != 0 do vListSubMaterials.selected = text
- )
- else
- (
- -- update the material name in the materials list
- if vListMaterials.selection != 0 do vListMaterials.selected = text
- )
- )
- )
-
- on vMaterialED open do fInitializeWindow()
- on vMaterialED close do fTerminateWindow()
-
- on vListMaterials selected arg do fSetMaterial (fGetMaterial index:arg)
- on vButtonGet pressed do fSelectMaterial()
- on vButtonNew pressed do undo "New Material" on fSetMaterial (fGetMaterial new:true)
-
- on vButtonApply pressed do undo "Apply Material" on fApplyMaterial()
- on vButtonCopy pressed do undo "Copy Material" on fSetMaterial (fGetMaterial fromCopy:true)
- on vButtonDelete pressed do undo "Delete Material" on fDeleteMaterial()
- on vButtonMaterialShow changed arg do fShowMaterial arg
-
- on vEditMultiMaterial entered arg do fEditMaterial #nameMulti arg
- on vEditMultiMaterial changed arg do (vMaterialED.fUpdateListText arg true)
-
- on vListSubMaterials selected arg do fSetSubMaterial arg
-
- on vEditName entered arg do undo "Material Name" on fEditMaterial #name arg
- on vEditName changed arg do (vMaterialED.fUpdateListText arg false)
-
- on vCheckboxTwoSided changed arg do undo "Material 2-sided" on fEditMaterial #twoSided arg
- on vFlashTabs FSCommand arg1 arg2 do vMaterialED.fTabsCallback arg1 arg2
-
- on vFlashArrow FSCommand arg1 arg2 do undo on fEditMaterial #matchDiffuse undefined
- on vCheckboxMatchDiffuse changed arg do undo "Mtl Match Diffuse" on fEditMaterial #matchDiffuse arg
- on vColor changed arg do undo "Mtl Param Change" on fEditMaterial #color arg
-
- on vCheckboxSelfIllumAmount changed arg do undo "Mtl Param Change" on fEditMaterial #selfIllumType arg
- on vCheckboxSelfIllumColor changed arg do undo "Mtl Param Change" on fEditMaterial #selfIllumType (not arg)
- on vSpinnerSelfIllum changed arg do undo "Mtl Param Change" on fEditMaterial #selfIllumAmount arg
- on vColorSelfIllum changed arg do undo "Mtl Param Change" on fEditMaterial #selfIllumColor arg
-
- on vSpinnerOpacity changed arg do undo "Mtl Param Change" on fEditMaterial #opacity arg
-
- on vSpinnerSpecularLevel changed arg do undo "Mtl Param Change" on fEditMaterial #specularLevel arg
- on vSpinnerGlossiness changed arg do undo "Mtl Param Change" on fEditMaterial #glossiness arg
- on vSpinnerSoften changed arg do undo "Mtl Param Change" on fEditMaterial #soften arg
-
- on vCheckboxMap changed arg do undo "Mtl Param Change" on fEditMaterial #map arg
- on vSpinnerMap changed arg do undo "Mtl Param Change" on fEditMaterial #mapAmount arg
- on vButtonMapOpen pressed do undo "Mtl Assign Map" on fChangeMap #open
- on vButtonMapClear pressed do undo "Mtl Clear Map" on fChangeMap #clear
- on vButtonMapShow changed arg do fShowMap arg
-
- on vButtonSelect pressed do undo "Select by Mtl" on fSelectByMaterial()
- on vButtonNavigator pressed do max material browser
- )
-
- /* note: all of these functions should do nothing if window is not open */
- callbacks.addScript #selectionSetChanged "vMaterialED.fUpdateTools()" id:#gMaterialED
- callbacks.addScript #filePostOpen "vMaterialED.fResetDefaultGUI()" id:#gMaterialED
- callbacks.addScript #filePostMerge "vMaterialED.fUpdateMaterials()" id:#gMaterialED
- callbacks.addScript #systemPostReset "vMaterialED.fResetDefaultGUI()" id:#gMaterialED
- callbacks.addScript #systemPostNew "vMaterialED.fResetDefaultGUI()" id:#gMaterialED
- callbacks.addScript #colorChanged "vMaterialED.fUpdateColors()" id:#gMaterialED
- registerTimeCallback vMaterialED.fUpdatePropertyDisplay
- when subAnimStructure sceneMaterials change handleAt:#redrawViews id:#gMaterialEdPersistent do vMaterialED.fCheckMaterials()
-
- /* eof */
-