Get number of elements in a mesh object

Get number of elements in a mesh object

Anonymous
Not applicable
4,636 Views
18 Replies
Message 1 of 19

Get number of elements in a mesh object

Anonymous
Not applicable

Is there a way to look at a mesh object and find out how many elements are contained within? I know I can access elements by using face bit arrays but was hoping there would be an easier way that does not involve having to do it this protracted way. I was hoping there may be a <mesh>.getNumElements that I can access, but I have not found such an attribute. I probably missed it.

Thanks

Accepted solutions (1)
4,637 Views
18 Replies
Replies (18)
Message 2 of 19

Swordslayer
Advisor
Advisor
Accepted solution
Message 3 of 19

Anonymous
Not applicable

Ah buggar. Oh well, thanks for the link, I am sure it will prove very useful.

Seems like it would be a worthwhile addition to the MeshOps or PolyOps interface though.

Message 4 of 19

bigonethegod
Enthusiast
Enthusiast

Made this tiny modifier just for this!

https://gumroad.com/l/elements_count 

 
0 Likes
Message 5 of 19

bigonethegod
Enthusiast
Enthusiast

Made this tiny modifier just for this!

Mesh Elements Count 

0 Likes
Message 6 of 19

obaida_ds
Contributor
Contributor

sorry , the function was not working so I deleted it .

0 Likes
Message 7 of 19

denisT.MaxDoctor
Advisor
Advisor

Please test your solutions before posting them...

 

try:

delete objects
gc()

s = geosphere name:#test_mesh segs:4 wirecolor:orange isselected:on
converttomesh s
meshop.explodefaces s #all 0

GetMeshElements s

 

Message 8 of 19

obaida_ds
Contributor
Contributor

Thanks for Feedback , ofc it should not be the best way but it works !! (not yet , need more tests)

0 Likes
Message 9 of 19

denisT.MaxDoctor
Advisor
Advisor

better now. at least it somehow works 🙂 ... but it gives wrong number 

Message 10 of 19

obaida_ds
Contributor
Contributor

🙂 , actually I tested it on copied faces (not detached) so it works , detached faces keep its index !! .

0 Likes
Message 11 of 19

obaida_ds
Contributor
Contributor

 

fn GetMeshElements obj = (
	local tf = obj.faces as bitarray, 
	el = meshOp.getElementsUsingFace obj 1, n = 1
	if el.numberset != obj.numfaces do (
		local lf = tf - el
		while lf.numberset != 0 do (
		       lf -= meshOp.getElementsUsingFace obj (lf as array)[1]
			n += 1
		)
	)
	n
)

 

I Hope this one will work 🙂 

0 Likes
Message 12 of 19

denisT.MaxDoctor
Advisor
Advisor

@obaida_ds wrote:

 

I Hope this one will work 🙂 


Great! Now let's test the performance... 😉
change the number of geosphere segment to 20 first.... 

 

 

 

delete objects
gc()

s = geosphere name:#test_mesh segs:20 wirecolor:orange isselected:on
(
	converttomesh s
	meshop.explodefaces s #all 0
)

(
	t0 = timestamp()
	h0 = heapfree
	n = GetMeshElements s

	format "num:% time:% heap:%\n" n (timestamp() - t0) (h0 - heapfree)
)

 

 

 

0 Likes
Message 13 of 19

obaida_ds
Contributor
Contributor

ok , not that much 🙂  ,

if you can help here we all will appreciate that 🙂

0 Likes
Message 14 of 19

denisT.MaxDoctor
Advisor
Advisor

for reference:
* the method shown by Swordslayer above takes ~30 ms
* another method (that you can find on CGTalk) takes ~10 ms

0 Likes
Message 15 of 19

obaida_ds
Contributor
Contributor

thank .

0 Likes
Message 16 of 19

denisT.MaxDoctor
Advisor
Advisor

@obaida_ds wrote:

thank .


Anyway you are on the right track. The best practical solution is to first try to do it yourself, then find the highest rated and find out how yours differs from the best.
There was a big discussion on CGTalk about optimizing the search for mesh elements ... as a result of testing and discussion, the decision took the final form. Unfortunately, CGTalk is now broken by "fatal improvements". And even I can not find this topic, although I was a direct participant in it. Maybe someone will be lucky to find it somehow.

Message 17 of 19

Serejah
Advocate
Advocate

@denisT.MaxDoctor  написал (-а):

@obaida_ds wrote:

thank .


And even I can not find this topic, although I was a direct participant in it. Maybe someone will be lucky to find it somehow.


All I remember is this topic about poly elements count.

A faster method for retrieving element count 

Message 18 of 19

obaida_ds
Contributor
Contributor
0 Likes
Message 19 of 19

denisT.MaxDoctor
Advisor
Advisor

A faster method for retrieving element count 

How to quickly eliminate elements with lowest face count? 

 

yes... those are the discussions I was talking about. Thanks guys for finding it!