PDA

View Full Version : help me


FILIPPOCREA
10-10-2005, 04:37 PM
one friend of mine has created me these 2 lines....the first one a chart creates me..and it is ok..
the second, creates me a lines TXT with name volume and sides of the objects in the scene..is the problem this, that the dimensions are not real, but they is those of a playpen created around, would I like the exact measures even if has the object rotated, since is the volume correct even if has the object rotated, is it possible to find the measures estte of the sides?

and in end, is it possible to insert the everything in the chart of the first lines?

you excuse for my English...does someone speak Italian?
hi filippo



un mio amico mi ha creato questi 2 file....il primo mi crea una tabella ..ed č ok..
il secondo , mi crea un file TXT con nome volume e lati degli oggetti nella scena..il problema č questo, che le dimensioni non sono reali, ma sono quelle di un box creato attorno, io vorrei le misure esatte anche se l'oggetto č ruotato, siccome il volume č giusto anche se l'oggetto č ruotato, č possibile trovare le misure estte dei lati?

ed in fine, č possibile inserire il tutto nella tabella del primo file?

scusate per il mio inglese...qualcuno parla italiano?
ciao filippo

antonv
10-10-2005, 08:24 PM
I suppose you need to apply an resetxform modifier before trying to get the dimensions of the objects.

Hope it helps!

FILIPPOCREA
10-11-2005, 08:43 AM
fn lla obj = (

larg = (obj.max.x-obj.min.x)

lung = (obj.max.y-obj.min.y)

alt = (obj.max.z-obj.min.z)

ou = "Larghezza:" + larg as string + " Lunghezza:" + lung as string + " Altezza:" + alt as string

)

fn CVM obj = (

Volume= 0.0

Center= [0.0, 0.0, 0.0]

numFaces = obj.mesh.numfaces

theMesh = obj.mesh

for i = 1 to numFaces do (

Face= getFace theMesh i

vert2 = getVert theMesh Face.z

vert1 = getVert theMesh Face.y

vert0 = getVert theMesh Face.x

dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0

Volume+= dV

Center+= (vert0 + vert1 + vert2) * dV

)

Volume /= 6

Center /= 24

Center /= Volume

Volume

)

--select geometry

a = selection as array

f = createfile "c:\lista_geometrie.txt"

for i = 1 to a.count do print (

a[i].name as string + " | " + lla a[i] + " | Volume:" + cvm a[i] as string + " | Posizione " + " X:" + a[i].pos.x as string + " Y:" + a[i].pos.y as string + " Z:" + a[i].pos.z as string

) to:f

close f

FILIPPOCREA
10-11-2005, 08:50 AM
fn lla obj = (

larg = (obj.max.x-obj.min.x)

lung = (obj.max.y-obj.min.y)

alt = (obj.max.z-obj.min.z)

ou = "Larghezza:" + larg as string + " Lunghezza:" + lung as string + " Altezza:" + alt as string

)

fn CVM obj = (

Volume= 0.0

Center= [0.0, 0.0, 0.0]

numFaces = obj.mesh.numfaces

theMesh = obj.mesh

for i = 1 to numFaces do (

Face= getFace theMesh i

vert2 = getVert theMesh Face.z

vert1 = getVert theMesh Face.y

vert0 = getVert theMesh Face.x

dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0

Volume+= dV

Center+= (vert0 + vert1 + vert2) * dV

)

Volume /= 6

Center /= 24

Center /= Volume

Volume

)

--select geometry

a = selection as array

f = createfile "c:\lista_geometrie.txt"

for i = 1 to a.count do print (

a[i].name as string + " | " + lla a[i] + " | Volume:" + cvm a[i] as string + " | Posizione " + " X:" + a[i].pos.x as string + " Y:" + a[i].pos.y as string + " Z:" + a[i].pos.z as string

) to:f

close f

prettyPixel
10-11-2005, 11:40 PM
Hi filippo

I modified a little the maxscript of your friend.
The secret is to use " coordsys local ".
The CVM function is really interesting. I don't understand how that does work but that does work !


No puedo hablar italiano pero creo que comprenderías espanol.
He modificado un poco el maxscript de tu amigo.
El secreto es de utilizar "coordsys local".

La función CVM es verdaderamente interesante. No comprendo cómo esto funciona pero esto funciona ! :thumbsup:

fn getSize o = (
obj=o.mesh
objNumVerts=obj.numVerts
if objNumVerts>0 do
(
coord=coordsys local meshOp.getVert obj 1
minX=coord.x; minY=coord.y; minZ=coord.z; maxX=coord.x; maxY=coord.y; maxZ=coord.z
for v=2 to objNumVerts do
(
coord=coordsys local meshOp.getVert obj v
if coord.x<minX then minX=coord.x
if coord.y<minY then minY=coord.y
if coord.z<minZ then minZ=coord.z
if coord.x>maxX then maxX=coord.x
if coord.y>maxY then maxY=coord.y
if coord.z>maxZ then maxZ=coord.z
)--for
return ("Larghezza:" + (maxX-minX) as string + " Lunghezza:" + (maxY-minY) as string + " Altezza:" + (maxZ-minZ) as string)
)
)

fn CVM obj = (
Volume= 0.0
Center= [0.0, 0.0, 0.0]
numFaces = obj.mesh.numfaces
theMesh = obj.mesh
for i = 1 to numFaces do (
Face= getFace theMesh i
vert2 = coordsys local getVert theMesh Face.z
vert1 = coordsys local getVert theMesh Face.y
vert0 = coordsys local getVert theMesh Face.x
dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0
Volume+= dV
Center+= (vert0 + vert1 + vert2) * dV
)
Volume /= 6
Center /= 24
Center /= Volume
Volume
)

a = selection as array
f = createfile "c:\lista_geometrie.txt"
for i = 1 to a.count do
print ( a[i].name as string + " | " + getSize a[i] + " | Volume:" + CVM a[i] as string + " | Posizione " + " X:" + a[i].pos.x as string + " Y:" + a[i].pos.y as string + " Z:" + a[i].pos.z as string ) to:f
close f

Bobo
10-12-2005, 01:13 AM
Hi filippo

I modified a little the maxscript of your friend.
The secret is to use " coordsys local ".
The CVM function is really interesting. I don't understand how that does work but that does work !
[/CODE]

This is the current version from the Reference, it is faster and does not leak memory ;)




fn CalculateVolumeAndCenterOfMass obj = (
Volume= 0.0
Center= [0.0, 0.0, 0.0]
theMesh = snapshotasmesh obj
numFaces = theMesh.numfaces
for i = 1 to numFaces do
(
Face= getFace theMesh i
vert2 = getVert theMesh Face.z
vert1 = getVert theMesh Face.y
vert0 = getVert theMesh Face.x
dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0
Volume+= dV
Center+= (vert0 + vert1 + vert2) * dV
)
delete theMesh
Volume /= 6
Center /= 24
Center /= Volume
#(Volume,Center)
)



The code is largely based on nice little functions found on Mathworld:
http://mathworld.wolfram.com/Tetrahedron.html

http://mathworld.wolfram.com/images/equations/Tetrahedron/equation12.gif

Basically, it finds the volumes of all tetrahedra defined by each face and the origin, where flipped faces result in negative volumes, thus correctly calculating complex volumes with internal and external surfaces, tubes, tori etc.

The results should be identical to those of the Measure Utility.

prettyPixel
10-12-2005, 01:55 AM
bobo :) I find a pretty code and you are his author...
The method is artful !
Calculate the volume of the tetraedras... All seems easy with you.

I would have to read the maxscript reference also...
The reference seems to be full with interesting things.

mathworld is also a formidable resource (like you lol)

Have a nice day

Bobo
10-12-2005, 02:23 AM
bobo :) I find a pretty code and you are his author...
The method is artful !
Calculate the volume of the tetraedras... All seems easy with you.

I would have to read the maxscript reference also...
The reference seems to be full with interesting things.

mathworld is also a formidable resource (like you lol)

Have a nice day

I wish I could take credit for this code, but I cannot. I just put it into the Reference.
The original code was written in HiC, our inhouse scripting language at my former game development company (source-code-level compatible with Wolfram Research's Mathematica, but realtime graphics oriented) by my good friend Felix "Bumblebee" Hummel. He is a math genius and Mathematica addict. I simply implemented the MAXScript version of the code, and Larry Minton fixed the memory leak ;)

CGTalk Moderation
10-12-2005, 02:23 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.