[Closed] Creating a Mesh is faster than Instancing One?
I’ve been doing some speed tests, and I found that if I create a Teapot() instead of Instancing one, its 1.5-2x faster to create vs. instance??
Is there a faster way to do this? Or is that just how its gonna be?
(
start = timestamp()
local objs = #()
local geo = selection[1]
local mesh = selection[1].verts as bitarray
local pGetVert = polyop.getVert
if (classof geo != Editable_Poly) do convertToPoly geo
DisableSceneRedraw()
with undo off
(
for vert in mesh do
(
a = pGetVert geo vert node:geo
--maxOps.CloneNodes $Teapot01 cloneType:#instance newNodes:&Temp1
t = teapot()
--t= Instance $Teapot01
t.radius = 1.0
t.pos = a
freeze t
append objs t
)
select objs
)
EnableSceneRedraw()
end = timeStamp()
gc()
format "Processing took % seconds
" ((end - start) / 1000.0)
)
It seems like if I create a copy of the actual mesh and assign it to an empty Editable_Mesh, its faster than Instancing??
(
start = timestamp()
local objs = #()
local geo = selection[1]
if (classof geo != Editable_Poly) do convertToPoly geo
local mesh = selection[1].verts as bitarray
local pGetVert = polyop.getVert
local theMesh = snapshotAsMesh $Teapot01
local rndClr = (random [0,0,0] [255,255,255])
local wireColor = color rndClr.X rndClr.Y rndClr.Z 255
DisableSceneRedraw()
with undo off
(
for vert in mesh do
(
a = pGetVert geo vert node:geo
local t = Editable_mesh()
t.mesh = theMesh --assign TriMesh value to the EMesh
--t = teapot()
--t= Instance $Teapot01
--t.radius = 1.0
t.pivot = [t.center.X,t.center.Y,t.min.Z]
t.pos = a
t.wirecolor = wireColor
freeze t
append objs t
)
select objs
)
delete theMesh --free up memory
EnableSceneRedraw()
end = timeStamp()
gc()
format "Processing took % seconds
" ((end - start) / 1000.0)
)
Yeah, creating 961 Teapots in Max 2010 64bit, using Vert Positions, it took
1.873 seconds using Instance $Teapot01
vs.
0.903 seconds using the Empty Mesh and copying over the data.
Maybe this is because of all the other properties that come with instancing like Materials and such? Although, I prob. have to stick with the slower method, because I need to have Instance/Reference working in my other script that this is for…:twisted:
I forgot, assigning a specific name in Max 2010/2011 makes it quite a bit faster.
(
start = timestamp()
DisableSceneRedraw()
local objs = #()
local geo = selection[1]
if (classof geo != Editable_Poly) do convertToPoly geo
local mesh = selection[1].verts as bitarray
local pGetVert = polyop.getVert
local theTeapot = $Teapot01
local isnt = Instance
with undo off
(
for vert in mesh do
(
a = pGetVert geo vert node:geo
t = isnt theTeapot
t.pos = a
t.name = "wee"
t.isFrozen = true
append objs t
)
select objs
)
EnableSceneRedraw()
end = timeStamp()
gc()
format "Processing took % seconds
" ((end - start) / 1000.0)
)
This is very odd…
So I used the standard Shift + Drag/Instance Method, and created 600 Teapots, and it was basically instant.
Then right after that I did the same but using my code again on the same mesh as before, but now is is executing the code roughly 3x faster… I’m creating almost 1000 objects in 0.355 seconds vs. around 1 or 1.2 before.
Edit: I found out why. I didn’t realize I did it. But if you’re instancing a non-convering Standard Mesh, its at least 2x faster to instance, if not more.
I noticed that it’s faster to instance primitive objects, like teapot, than editable meshes. Or was it the other way round?
It was alot faster to instance primitives than converted meshes.
Maybe I need to do some sort of Proxy Mode for what I’m doing using Primitives.
Tested again, and it still holds true, Primitives are 3-4x faster than instancing a converted Mesh.
I think there is no absolute truth in this matter. I can write a scripted primitive that will be very slow in its creation. Much slower than a simple mesh copy.
But in general case primitives are using simple algorithms that make their creation fast.
Well yes, exactly. But in regards to the built in ones, if you use a standard teapot, and don’t convert it, its much faster to Instanced that if you do convert it.
it might be faster to create a new primitive than make a copy of an existent one because it doesn’t copy material, controllers, etc. But how can it help you?
I have a Preview Mode in my Object Placer tool, which makes the objects grey/frozen anyways in preview. So if the user wanted faster previewing, and just wanted to get rough placement/randomization, they could use the primitive mesh I suppose.