Notifications
Clear all

[Closed] makeUniqueArray for complex types?

I have an array/collection of materials, where I want to return a unique array by comparing only the material name, and nothing else. How do I do that? It’s current behavior is to see two materials called “Red” but different in specular value as unique, for example.

4 Replies

If the source array is not too big I would iterate through the array, putting materials from this array to another checking target array if it already contains the material.

fn alreadyHas matArray matIn=
  (
  	found = false
  	for mat in matArray while (not found) do
  		if mat.name == matIn.name then found = true
  	
  	return found
  )
  
  matArrayOut = #()
  for mat in matArrayIn do
 	if (not alreadyHas matArrayOut mat) then (append matArrayOut mat)
fn getUniqueMatsByName mats =
(
	local uniqueMatNames = #()
	local uniqueMats = #()
	
	for m in mats where findItem uniqueMatNames (m.name as name) == 0 do (
		append uniqueMatNames (m.name as name)
		append uniqueMats m
	)
		
	uniqueMats
)

fn getUniqueMatsByName mats =
(
	local uniqueMatNames = #()
	
	for m in mats collect (
		if findItem uniqueMatNames (toLower m.name) == 0 then
		(
		append uniqueMatNames (toLower m.name)
		m
		)
		else(dontcollect)
	)
)

?
should be faster

– delete –