PDA

View Full Version : Performant way to get all used Material IDs?


CanisLupus
11-24-2010, 09:28 AM
Hi,

I'm writing a scene exporter and I wondered if there is a way to get all used material IDs in the current scene without going through every single triangle? Because I tried the following and it takes ages with complex scenes:


global ALL_TRIANGLES = #()
struct triStruct (
triNode,
triMatID,
triIndex)

fn getAllTriangles =
(
start = timeStamp()
ALL_TRIANGLES = #()
for obj in $* where (superclassof obj == GeometryClass) do
(
s = (snapShotAsMesh obj)
numFaces = meshop.getNumFaces s

for i = 1 to numFaces do
(
newFace = triStruct triNode:obj triMatID:(getFaceMatID s i) triIndex:i
append ALL_TRIANGLES newFace
)
)
end = timeStamp()
format "%ms\n" (end-start)
)

I've been searching the Maxscript help for hours without any luck.
Any ideas how to improve the speed here?

kthxbye

broomy
11-24-2010, 09:01 PM
hi,
Look at it the other way, if you have the material/submaterial on the objects in the scene try to select the faces on each Id and if you get a result that is greater than 0 faces its in use, that way you loop will run once per id not once per poly :)

Hope that helps

:)

denisT
11-24-2010, 09:26 PM
Hi,

I'm writing a scene exporter and I wondered if there is a way to get all used material IDs in the current scene without going through every single triangle? Because I tried the following and it takes ages with complex scenes...


i don't know the other way then go through all geo nodes and their faces to collect face ids.
how complex your scene is?

(
ids = #{}
for node in geometry as array do
(
m = snapshotasmesh node
for f=1 to m.numfaces do ids[getFaceMatID m f] = on
delete m
)
ids
)


for 1,500,000 faces it takes ~3sec. not too bad.

CanisLupus
11-25-2010, 08:45 AM
i don't know the other way then go through all geo nodes and their faces to collect face ids.
how complex your scene is?

(
ids = #{}
for node in geometry as array do
(
m = snapshotasmesh node
for f=1 to m.numfaces do ids[getFaceMatID m f] = on
delete m
)
ids
)


for 1,500,000 faces it takes ~3sec. not too bad.

Thank you, this is indeed faster than my approach. Could you explain what exactly "ids[getFaceMatID m f] = on", especially the "= on", does? Is there a difference to:


ids = for f=1 to m.numfaces collect (getFaceMatID m f)


?

Light
11-25-2010, 05:23 PM
Thank you, this is indeed faster than my approach. Could you explain what exactly "ids[getFaceMatID m f] = on", especially the "= on", does? Is there a difference to:


ids = for f=1 to m.numfaces collect (getFaceMatID m f)


?

It just sets the indexed BitArray element to true. The difference is his uses a BitArray, yours creates an Array. BitArrays are more compact than Arrays, so more efficient in certain problems.




Light

CGTalk Moderation
11-25-2010, 05:23 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.