I need a little script to delete last MatID(Mesh)

Hello, i spent a lot of time on making this stuff and first time i release it, but second i couldn't make it again,
to delete last MatID(mesh) by 1 click, can someone help me with this ?
IT's a simple script when you select a mesh and press button - it deletes last MaTID(mesh).

P.S.

And if it possible http://dfiles.ru/files/owsepv1vr to modifie this script(its .psk file importer) and add to it a possibility to insert special mesh(On the importing model), while importing the file, with position controlling rulers.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
DolVai's picture

it works

Thx! it works,

Second question, http://dfiles.ru/files/owsepv1vr is it possible to modifie this script, it is importing psk files(that have mesh, bones and skin data)
I need a little modification, to attach a mesh(from folder - in 3ds format or obj) on import and to be able to change it's position using script ?

I'm in need of this for a long time, 3-6 months.

Thx guys anyway! for your time and work its helps me a lot.

barigazy's picture

Hey Artemie

Why don't you ask the author to add new features that you suggested

barigazy

DolVai's picture

i did

I did asked him, he doesn't have 3ds max anymore and he won't install it, if this future will be available it would save a lot of time,

or is to hard ?

DolVai's picture

Skin problem

--Update guys,

this script works perfectly even for meshes with skin modifier applied on!

fn delMeshFaces obj =
(
	local getFID = getFaceMatID, idArr = #(), lastID = 0, aFaces = #()
	for i = 1 to obj.numfaces where ((id = getFID obj i) > lastID) do lastID = id
	for f = 1 to obj.numFaces where getFID obj f == lastID do append aFaces f ;
	meshop.deleteFaces obj aFaces
)

Hey thx guys for helping me out, but seems script won't work with skin modifier applied on mesh http://i.imgur.com/ZOMKUIL.png
Is it possible to add little support - with skin applied ?

I tested anubis script on max 9 and its didn't work =(.

barigazy's picture

try now

fn delMeshFaces obj =
(
	local getFID = getFaceMatID, idArr = #(), lastID = 0, aFaces = #()
	for i = 1 to obj.numfaces where ((id = getFID obj i) > lastID) do lastID = id
	for f = 1 to obj.numFaces where getFID obj f == lastID do append aFaces f ;
	meshop.deleteFaces obj.baseobject aFaces ; update obj
)

barigazy

Anubis's picture

the script from the PNG is not mine ;-)

it was made by Branko and he already update and fixed it, so it works too now in Max 9, but the script you post above is mine, with some additional optimization mades by Branko, and if it works fine, then where is the problem?

my recent MAXScripts RSS (archive here)

barigazy's picture

This is my test. Based on

This is my test. Based on your solution I fixed memory lecking
First test scene (10 collapsed boxes)

delete objects
testmesh = Editable_Mesh()
for m = 1 to 10 do attach testmesh (box lengthsegs:10 widthsegs:10 heightsegs:10 pos:[(m-1)*30,0,0])
select testmesh

Now your original code #1 solution

fn delfaces obj = 
(
	local lastID = 0, currID, aFaces, getFID = getFaceMatID
	for f = 1 to obj.numFaces do
	if (currID = getFaceMatID obj f) > lastID do
		lastID = currID
	aFaces = for f = 1 to obj.numFaces where \
	(currID = getFaceMatID obj f) == lastID \
		collect f
	meshop.deleteFaces obj aFaces
)

This is recreation of your code #2 solution

fn delMeshFaces obj =
(
	local getFID = getFaceMatID, idArr = #(), lastID = 0, aFaces = #()
	for i = 1 to obj.numfaces where ((id = getFID obj i) > lastID) do lastID = id
	for f = 1 to obj.numFaces where getFID obj f == lastID do append aFaces f ;
	meshop.deleteFaces obj aFaces
)

And now the result
#1 solution

gc()
t1 = timestamp()
m1 = heapfree
delfaces testmesh
format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
update testmesh

time:0.064 memory:1485368L

#2 solution

gc()
t1 = timestamp()
m1 = heapfree
delMeshFaces testmesh testmesh
format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
update testmesh

time:time:0.048 memory:129824L

#2 solution is 10 time memory efficient and 1/3 time faster

barigazy

Anubis's picture

thanks for testing

Interesting, I always thought that Collect is more faster than Append. Maybe I s'd test them again.

my recent MAXScripts RSS (archive here)

barigazy's picture

This is the replacement for

This is the replacement for "appendIfUnique"

obj = $
arr = #()
objFaceIDs = for f in 1 to obj.numfaces where (finditem arr (hVal = gethashvalue (fID = (getFaceMatID obj f)) 0)) == 0
collect ( append arr hVal ; fID)

and the final code will be

try(destroydialog ::testRoll) catch() 
rollout testRoll "Delete LastMTLID Faces"
(
	fn deleteLastMtlIDfaces obj =
	( 
		local arr = #()
		objFaceIDs = for f in 1 to obj.numfaces where (finditem arr (hVal = gethashvalue (fID = (getFaceMatID obj f)) 0)) == 0 collect (append arr hVal ; fID)
		for f in 1 to obj.numfaces do appendIfUnique arr (getFaceMatID obj f)
		lastIDFaces = sort (for f = 1 to obj.numfaces where (getFaceMatID obj f) == (amax objFaceIDs) collect f)
		for f = lastIDFaces.count to 1 by -1 do deleteFace obj lastIDFaces[f]
		free arr ; free objFaceIDs ; update obj
	)
	button theButton "Do the JOB!" pos:[5,5] width:140 height:40
 
	on theButton pressed do 
	(
		if selection.count != 0 do 
		(
			for o in selection where iskindof o Editable_Mesh do deleteLastMtlIDfaces o
		)
	)
)
createDialog testRoll 150 50 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)	

barigazy

Anubis's picture

...

Did you tested my example function I post below?

I'm just curious is it worth :)

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.