# Getting the size from a model - Macromedia Director 3D

Hello How I can get the size of a model (from a *.w3d-file). The model does not contain the properties width, height or length, so I guess that I have to measure the distance between the models vertices. But I can't seem to think of a good way to do it in. I guess a loop of some kind? But it would seem rather unomptimized to actually loop through each and every vertex point in the model I wan't measured. Any suggestions?...

1. ## Getting the size from a model

Hello
How I can get the size of a model (from a *.w3d-file). The model does not
contain the properties width, height or length, so I guess that I have to
measure the distance between the models vertices.
But I can't seem to think of a good way to do it in. I guess a loop of some
kind? But it would seem rather unomptimized to actually loop through each and
every vertex point in the model I wan't measured.

Any suggestions?

SuperTank Guest 2. ## Re: Getting the size from a model

You can quickly get the bounding sphere radius of a model using this:

Otherwise, if you want the axis-aligned width, length and height, you will
have to add the meshdeform modifier, and loop through every vertex.

- Ben

duckets Guest 3. ## Re: Getting the size from a model

The closest thing to model's dimensional properties is the model's
boundingSphere property. It gives a radius of an imaginary sphere that contains
all the vertices of the model; the sphere's diameter is the distance between
the two hest-apart vertices. However it includes the model's children in
the sphere. Set yourModel.debug = TRUE to see it.

You could loop through each model, add a mesh deform modifier, go through each
mesh[ ].vertexlist, keep track of each max and min x, y, and z value, the
calculate w, l, h from that. It would take a little time... you probably
wouldn't want to do it every frame. But you could do it on a keypress or
something.

tedalde2 Guest 4. ## Re: Getting the size from a model

I thought I had something like this lying around somewhere. Sure enough, here
it is (attached below).

Enjoy!

on getModelSize cModel

maxVertices = void

repeat with meshNum=1 to cmodel.meshdeform.mesh.count

repeat with vertexNum = 1 to
cmodel.meshdeform.mesh[meshNum].vertexList.count

cvertex = cmodel.meshdeform.mesh[meshNum].vertexList[vertexNum]

if voidp(maxVertices) then

maxVertices = cVertex.duplicate()
minVertices = cVertex.duplicate()

else

if cVertex.x > maxVertices.x then
maxVertices.x = cVertex.x
end if
if cVertex.y > maxVertices.y then
maxVertices.y = cVertex.y
end if
if cVertex.z > maxVertices.z then
maxVertices.z = cVertex.z
end if

if cVertex.x < minVertices.x then
minVertices.x = cVertex.x
end if
if cVertex.y < minVertices.y then
minVertices.y = cVertex.y
end if
if cVertex.z < minVertices.z then
minVertices.z = cVertex.z
end if
end if

end repeat
end repeat

xSize = maxVertices.x-minVertices.x
ySize = maxVertices.y-minVertices.y
zSize = maxVertices.z-minVertices.z

return [#x:xSize,#y:ySize,#z:zSize]

end

duckets Guest #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•