Notifications
Clear all

[Closed] How to fast search material ID from objects

(
	format "GET MESH TEST\n"
	
	delete objects
	
	obj = geosphere segs:100
-- 	obj = converttomesh (geosphere segs:100)
-- 	obj = converttopoly (geosphere segs:100)
	
	nodes = for j = 1 to 100 collect obj
	
	gc(); st = timestamp(); sh = heapfree
	for j in nodes do tmesh = snapshotasmesh j
	format "snapshotAsMesh:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	gc(); st = timestamp(); sh = heapfree
	for j in nodes do tmesh = copy j.mesh
	format ".Mesh:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	if gettrimesh != undefined then
	(
		gc(); st = timestamp(); sh = heapfree
		for j in nodes do tmesh = copy (gettrimesh j)
		format "getTrimesh:% heap:%\n" (timestamp()-st) (sh-heapfree)	
	)
	else print "getTrimesh() method not available"
	
	---------------------------------------------------------------------------
	
	format "\nGET MESH FACES MATERIALS IDs TEST\n"
	
	nodes = for j = 1 to 50 collect obj
	
	gc(); st = timestamp(); sh = heapfree
	for j in nodes do
	(
		tmesh = snapshotasmesh j
		for k = 1 to tmesh.numfaces do id = getfacematid tmesh k
	)
	format "snapshotAsMesh:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	gc(); st = timestamp(); sh = heapfree
	for j in nodes do
	(
		tmesh = copy j.mesh
		for k = 1 to tmesh.numfaces do id = getfacematid tmesh k
	)
	format ".Mesh:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	if gettrimesh != undefined then
	(
		gc(); st = timestamp(); sh = heapfree
		for j in nodes do
		(
			tmesh = copy (gettrimesh j)
			for k = 1 to tmesh.numfaces do id = getfacematid tmesh k
		)
		format "getTrimesh:% heap:%\n" (timestamp()-st) (sh-heapfree)
	)
	else print "getTrimesh() method not available"
)

MAX 2016


PRIMITIVE

GET MESH TEST

  • snapshotAsMesh:318 heap:15328L
  • .Mesh:627 heap:15480L
  • getTrimesh:571 heap:30528L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:3056 heap:7664L
  • .Mesh:3208 heap:7880L
  • getTrimesh:3184 heap:15328L

EDITABLE_MESH

GET MESH TEST

  • snapshotAsMesh:332 heap:15328L
  • .Mesh:287 heap:15480L
  • getTrimesh:287 heap:30528L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:3060 heap:7664L
  • .Mesh:3036 heap:7880L
  • getTrimesh:3051 heap:15328L

EDITABLE_POLY

GET MESH TEST

  • snapshotAsMesh:2047 heap:15328L
  • .Mesh:2029 heap:15480L
  • getTrimesh:1962 heap:30528L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:3928 heap:7664L
  • .Mesh:3910 heap:7880L
  • getTrimesh:3881 heap:15328L

MAX 2021


PRIMITIVE

GET MESH TEST

  • snapshotAsMesh:337 heap:17728L
  • .Mesh:598 heap:17912L
  • getTrimesh:553 heap:35336L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:1793 heap:8868L
  • .Mesh:1926 heap:9112L
  • getTrimesh:1882 heap:17736L

EDITABLE_MESH

GET MESH TEST

  • snapshotAsMesh:343 heap:17736L
  • .Mesh:270 heap:17912L
  • getTrimesh:271 heap:35336L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:1777 heap:8936L
  • .Mesh:1759 heap:9112L
  • getTrimesh:1744 heap:17736L

EDITABLE_POLY

GET MESH TEST

  • snapshotAsMesh:1897 heap:17736L
  • .Mesh:1837 heap:17912L
  • getTrimesh:1781 heap:35336L

GET MESH FACES MATERIALS IDs TEST

  • snapshotAsMesh:2567 heap:8936L
  • .Mesh:2529 heap:9112L
  • getTrimesh:2507 heap:17736L

Oh!!! I figured out what was going wrong … We call the mesh value for each face operation (in our case getfacematid). This is a built-in max function and like any other mesh methods, setup_mesh is used for each call. This is almost the same as making a copy every time you call a single subobject.
My mesh methods (from my extension) don’t do this, when only READ access is needed. So for built-in MXS, using snapshotmesh node is generally better than copy node.mesh. But you should know and understand that the snapshot by default takes renderMesh, which in some cases may not yet be generated at the moment. This can cause some problems.

Page 2 / 2