--Bitmap delete 1.0 alpha
--date:9/18/2005
--Written By Zhang Yang

--function:
--Did you ever be troubled by change your local map path to network map path one by one before you want to network rendering?
--Ok your nightmare ended! use this one-click tool and have a rest.
--network name also called UNC(Universal Naming Convention).
--Requirement:3ds max4
--contact:yang.zhang@autodesk.com



--Init Var
--sysinfo
machineName=sysInfo.computername
userName=sysInfo.username
--shareMapLib=#()
sharedMapCount=0

debug=createFile "c:/temp/debug.log"

--get inter string function
--function usage: interString <string> <string(begin)> <string(end)> <string(end2)>
fn interString wholeString startString endString endStringSnd=
(	
	startPos=findstring wholeString startString
	if startPos==undefined do undefined
	wholeString=substring wholeString startPos -1
	endPos=findstring wholeString endString
	endPosSnd=findstring wholeString endStringSnd
	if endPos==undefined then endPos=-1
		else endPos=endPos-1
	if endPosSnd==undefined then endPosSnd=0
		else
			if (endPosSnd-1)<endPos or endPos==-1 do endPos=endPosSnd-1
	finalString=substring wholeString 1 endPos
	return (finalString)
)


--following code idea part from "map_path_editor" which written by Jaroslaw Marcin's recursive function but enforced.
--main function
fn changeMaps item = (
		
		--exclude all other type of value except materials and texturemap
		if superclassof(item)!=material and superclassof(item)!=textureMap and classof(item)!=ArrayParameter do return false

		--detect whether the current map is bitmap
		if (classof item)==Bitmaptexture then
			(	local fileStr=item.filename
				print  fileStr to:debug
				if (getfiles fileStr).count==0 do return true
				return false
			)
		
		print "Processing properties table" to:debug
		--get all the properties in the material or texturemap
		props=#()
		propsTable=stringStream ""
		showProperties item to:propsTable
		seek propsTable 1
		print "property table start:========" to:debug
		--collect props
		while (not eof propsTable) do
			(	
				appendString=interString (readline propsTable) "." " " "("
				print appendString to:debug
				if appendString==undefined do print "no bitmap property finded" to:debug
				append props appendString
			)
				
		print "property table end:========" to:debug
		 
		print props.count to:debug
		--searching under the material or texturemap for bitmap
		for aProp in props do
		(   	
				newItem=item
				format "item:%" item to:debug
                newProp="newItem"+aProp
				newProp=execute newProp
				format "item:% org:% Class:%, Name:%\n\n" item aProp (classof newProp) newProp to:debug
				flush debug
				if changeMaps newProp do (
					local changStr="newItem"+aProp+"=noTexture()"
					format "change this:%\n" changStr to:debug
					sharedMapCount+=1
					execute changStr
					)
		)
		return false
)
--end of recursive function

fn mapShare =
(	
	for proMat in sceneMaterials do
	(
		print proMat.name to:debug
		changeMaps proMat
		
	)
	stringCollect="Finish!Total "+ sharedMapCount as string +" Maps have been Shared."
	messageBox stringCollect

)

--Create Interface
Utility mapShareUti "Network Map Sharer" rolledUp:true
( 
 
    rollout aboutMapShare "About NetMapSharer"
    (
         label lab1 "NetMapSharer 1.4 Alpha" 
         label lab2 "Written By Snow"
         --bitmap the_bmp bitmap:icon_Snow3D
         label lab3 "Home http://zsnow.yeah.net"
         label lab4 "Email: yang.zhang@autodesk.com"
         label lab5 "discreet China AE. Nov,2000"
     )
    rollout MainParament "SysInfo"
    (


		 label lab6 "machineName:" align:#left
		 label lab8 "UserName:" align:#left
		 button shareb "ShareMap"
		 on shareb pressed do
		 (
		 	lab6.caption=machineName
			lab8.caption=userName
			--init var
			sharedMapCount=0
			mapShare()
		 )
	)
	
	 on mapShareUti open do
	 (	
		addRollout aboutMapShare
		addRollout MainParament
	 ) 

  	 --close Rollout
 	 on mapShareUti close do
  	 (  
   	   	removeRollout aboutMapShare
        removeRollout MainParament
      )   

)