View Full Version : 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.
|
|
sergo.pogosyan
01-12-2011, 07: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)
MatanH
01-12-2011, 09: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
)
uniqueMats
)
Insanto
01-12-2011, 11:47 AM
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
johnwhile
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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.