[Closed] Geting vert pos problem
I’m having a problem with this code:
(
st = timestamp()
theMaxX = 10^10
theMaxY = 10^10
theMaxZ = 10^10
theMinX = 10^10
theMinY = 10^10
theMinZ = 10^10
theMesh = snapshotasmesh $
for v = 1 to theMesh.numverts do
(
thePos = getVert theMesh v
if thePos.x > theMaxX then theMaxX = thePos.x
if thePos.y > theMaxY then theMaxY = thePos.y
if thePos.z > theMaxZ then theMaxZ = thePos.z
--
if thePos.x < theMinX then theMinX = thePos.x
if thePos.y < theMinY then theMinY = thePos.y
if thePos.z < theMinZ then theMinZ = thePos.z
)
end = timestamp()
format "timeEM: %
" ((end-st)/1000.0)
format "maxX:% maxY:% maxZ:% minX:% minY:% minZ:%
" theMaxX theMaxY theMaxZ theMinX theMinY theMinZ
)
The author of the code is Borislav Petrov. I get it from this thread.
The code return correct result only for maxX, maxY and maxZ. The results for minX, minY and minZ is not collect corectly, and I don’t know why? The Bobo code work fine, but mine…
Can someone show me where is myu mistake?
use negative values for initial min x,y,z.
in your code vert position can’t be less than 10^10.
are you getting mesh BBox? i posted the fastest way that i know in this forum. try to find.
Thanks!
I solved the problem 10 minutes ago.
Is this is your method of getting bbox: – http://forums.cgsociety.org/showpost.php?p=6971983&postcount=8
I tested both methods with teapots with 5 TS modifiers, converted to editable_poly – 517 12 verts
#1
(
st = timestamp()
local bmin = [1e9,1e9,0], bmax = [-1e9,-1e9,0]
theMesh = snapshotasmesh $
for v=1 to theMesh.numverts do
(
vp = (GetVert theMesh v)
if vp.x < bmin.x do bmin.x = vp.x
if vp.x > bmax.x do bmax.x = vp.x
if vp.y < bmin.y do bmin.y = vp.y
if vp.y > bmax.y do bmax.y = vp.y
if vp.z < bmin.z do bmin.z = vp.z
if vp.z > bmax.z do bmax.z = vp.z
)
free theMesh
w = (bmax.x - bmin.x)
l = (bmax.y - bmin.y)
h = (bmax.z - bmin.z)
end = timestamp()
format "timeEM: %
" ((end-st)/1000.0)
format "Length:% Width:% Height:%
" l w h
)
time: 5.516 sec
#2
(
st = timestamp()
theMaxX = -2147483648
theMaxY = -2147483648
theMaxZ = -2147483648
theMinX = 2147483648
theMinY = 2147483648
theMinZ = 2147483648
theMesh = snapshotasmesh $
for v = 1 to theMesh.numverts do
(
thePos = getVert theMesh v
if thePos.x > theMaxX then theMaxX = thePos.x
if thePos.y > theMaxY then theMaxY = thePos.y
if thePos.z > theMaxZ then theMaxZ = thePos.z
--
if thePos.x < theMinX then theMinX = thePos.x
if thePos.y < theMinY then theMinY = thePos.y
if thePos.z < theMinZ then theMinZ = thePos.z
)
objLength = (theMaxY) - (theMinY)
objWidth = (theMaxX) - (theMinX)
objHeight = (theMaxZ) - (theMinZ)
end = timestamp()
format "timeEM: %
" ((end-st)/1000.0)
format "Length:% Width:% Height:%
" objLength objWidth objHeight
)
time: 4.922 sec.
Almost identical.
the difference is access to float variable and to component of point3
it’s 10%… not a little to ignore it. so use floats