Printer script

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 09 September 2012   #1
Printer script

Inspired by the out-of-date maxscript challenge thread I've made this script. It allows you to make object print on another object, it doesn't use any displacement maps, it works on geometry (object must be an Editable_Poly). Feel free to comment


-- Kamil M. (C) 2012

try(destroyDialog printer_rollout) catch()
rollout printer_rollout "Printer!"
	global softobj = undefined
	global hardobj = undefined
	fn epfilter obj = classof obj == Editable_Poly
	function zaokr liczba =
		local ulamek = (liczba-(floor liczba))*1000.0
		ulamek = floor ulamek
		local dodac=false
		if (mod ulamek 10.0)>=5.0 then dodac=true
		ulamek =floor (ulamek/10.0)
		if dodac then ulamek+=1
		return ((floor liczba)+(ulamek/100.0))
	group "Objects"
		pickbutton pbut1 "Pick soft object" width:140 height:26 filter:epfilter
		pickbutton pbut2 "Pick hard object" width:140 height:26 filter:epfilter
	group "Properties"
		spinner startframe "Start frame: " align:#center type:#integer range:[animationRange.start,animationRange.end,animationR  ange.start] width:122 fieldWidth:45
		spinner endframe "End frame: " align:#center type:#integer range:[animationRange.start,100000,animationRange.end] width:122 fieldWidth:45
		spinner spinsub "Substeps: " range:[1,30,1] type:#integer align:#center fieldWidth:45 width:122
		checkbox bump "Bump around" checked:false align:#center
		spinner b_height "Height limit: " range:[0,1000,0.1] type:#worldunits align:#center fieldWidth:60 enabled:false
		spinner g_width "Width (grow): " range:[0,10000,3] type:#integer align:#center fieldWidth:60 width:132 enabled:false
	group "Animation"
		button startbut "BAKE ANIMATION" width:140 height:40 enabled:false
		label labprog "Progress: 0.00%" align:#left
		progressbar pbar value:0 color:green
	on pbut1 picked obj do
		pbut1.caption =
		softobj = obj
		if (softobj != undefined and hardobj != undefined) then startbut.enabled = true
	on pbut2 picked obj do
		pbut2.caption =
		hardobj = obj
		if (softobj != undefined and hardobj != undefined) then startbut.enabled = true
	on bump changed state do

	on startbut pressed do
		meshsel = meshselect useSoftSelection:false
		addmodifier softobj meshsel
		volsel = volumeselect level:1 volume:3 node:hardobj
		addmodifier softobj volsel
		norm = normalmodifier flip:true
		addmodifier hardobj norm
		local step = (1.0/(spinsub.value)as float) as float
		local licznik_t =0
		local tabwszystkich = #{}
		local polozenia = #()
		local wagi = #()
		for i = 1 to softobj.getnumvertices() do
			append polozenia (meshop.getvert softobj i)
			append wagi 0.0
		animate on for t in startframe.value to endframe.value by step do
		at time t
			local w_sredni = [0.0,0.0,0.0]
			local tabvert = getvertselection softobj
			local liczba_wierzch = tabvert.numberSet
			obecnypos = hardobj.pos
			local zm=0
			--petla po vertexach z volume select
			for i in tabvert do
				licznik_t += 1
				zm += 1
				vert = meshop.getvert softobj i
				promien = ray vert -z_axis
				i_ray = intersectray hardobj promien

				if ((i_ray != undefined) and (i_ray.pos.z < vert.z)) then 
					--dodaj klatke kluczowa przed obecna
					at time (t-step)
						(polyop.setvert softobj i ((meshop.getvert softobj i)+[1,1,1]))
						(polyop.setvert softobj i ((meshop.getvert softobj i)-[1,1,1]))
					--ustaw nowe polozenie vertexa
					polyop.setvert softobj i i_ray.pos
				--jesli potrzeba - licz wektor ruchu
				if (bump.state==true) then w_sredni+=[0.0,0.0,i_ray.pos.z - vert.z]
				local prog = (((t as float-startframe.value as float)/((endframe.value+1.0) as float-startframe.value as float))*100.0)as float +(((zm as float*step) as float/liczba_wierzch as float) as float)
				if (licznik_t == 4) then
					labprog.caption = "Progress: "+(zaokr prog)as string+"%"
					licznik_t = 0
				pbar.value = prog
			--wyciagniecie sredniej wektora ruchu vertexow
			if (bump.state==true) and (liczba_wierzch > 0) then
				w_sredni = (w_sredni/liczba_wierzch)*-1
				if ((w_sredni.z/2.0)>b_height.value) then w_sredni.z = b_height.value * 2.0
			--bumpowanie dookola
			if (bump.state==true) and (liczba_wierzch > 0) then
				if (findstring labprog.caption "b" == undefined) then labprog.caption = labprog.caption + " (bumping...)"
				softobj.setselection #vertex tabvert
				for i =1 to g_width.value do
					local wczesniejsze = softobj.getselection #vertex
					softobj.growselection selLevel:#vertex
					local nowe = (softobj.getselection #vertex) - wczesniejsze
					if (i == 1) then
						for w in nowe do wagi[w] = -0.5
						local kat
						if (i == 2) then kat = 90 else kat = 90.0 + ((180.0 / (g_width.value as float - 1.0))*(i-2.0))
						for w in nowe do wagi[w] = ((sin kat)+1.0)/2.0
				tabwszystkich = tabwszystkich + tabvert
				local ostateczne = (softobj.getselection #vertex)-tabwszystkich
				for i in ostateczne do
					local nowy_pos = (meshop.getvert softobj i)+((w_sredni/2.0)*wagi[i])
					if (nowy_pos.z > (meshop.getvert softobj i).z) then
						at time (t-step)
							(polyop.setvert softobj i ((meshop.getvert softobj i)+[1,1,1]))
							(polyop.setvert softobj i ((meshop.getvert softobj i)-[1,1,1]))
						--nowe polozenie vertexa bumpowanego w gore
						if ((nowy_pos - polozenia[i]).z > ((b_height.value)*wagi[i])) then
							if (polozenia[i].z+(b_height.value*wagi[i])) > ((meshop.getvert softobj i).z) then
								polyop.setvert softobj i [polozenia[i].x,polozenia[i].y,(polozenia[i].z+(b_height.value*(random 0.9 1.1)*wagi[i]))]
						else polyop.setvert softobj i nowy_pos
		labprog.caption = "Progress: 100.00%"
		pbar.value = 100
		deletemodifier hardobj 1
		deletemodifier softobj 1
		deletemodifier softobj 1
		pbar.value = 0
		labprog.caption = "Progress: 0.00%"
		update softobj

createdialog printer_rollout width:210
Old 09 September 2012   #2
Although I have not tired it yet, the video makes that look very useful and for that reason alone thanks for creating and posting it!
Portfolio -
Animation -
Old 09 September 2012   #3
Wow... thanks.. that might be useful some day! )
Mad,Sad and Bad to the Bone!!!
Old 09 September 2012   #4
Hehe! I just finished making a tutorial on using vraydistancetex to achieve this same effect but this looks even better.

Nice one.
Old 09 September 2012   #5
Thread automatically closed

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.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:46 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.