XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : makeUniqueArray for complex types?

01-12-2011, 07:45 AM
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.

01-12-2011, 08:58 AM
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)

01-12-2011, 10:10 AM
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


01-12-2011, 12:47 PM
fn getUniqueMatsByName mats =
local uniqueMatNames = #()

for m in mats collect (
if findItem uniqueMatNames (toLower m.name) == 0 then
append uniqueMatNames (toLower m.name)
should be faster

10-07-2011, 03:01 PM
-- delete --

CGTalk Moderation
10-07-2011, 03:01 PM
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.