[Closed] Mesh exporter
I trying to write a Mesh exporter using the code from the help files in max . I got the main code working fine but the code will not export the pivot point of the mesh. so if I bring my mesh back in using the import script the pivot point is always set at 0.0.0 , so what I would like to know is can anyone help me with this part of the code ? how do I export pivot point data and import it again ? , below is the code I have so far .
thanks for reading
tmesh = snapshotAsMesh selection[1]
out_file = createfile ((GetDir #export)+"/testmesh.dat")
format "%,%
" tmesh.numverts tmesh.numfaces to:out_file
for v = 1 to tmesh.numverts do
format "%," (getVert tmesh v) to:out_file
format "
" to:out_file
for f = 1 to tmesh.numfaces do
format "%," (getFace tmesh f) to:out_file
close out_file
I think this should do it
tmesh = snapshotAsMesh selection[1]
out_file = createfile ((GetDir #export)+"/testmesh.dat")
format "%,%
" tmesh.numverts tmesh.numfaces to:out_file
for v = 1 to tmesh.numverts do
format "%," (getVert tmesh v) to:out_file
format "
" to:out_file
for f = 1 to tmesh.numfaces do
format "%," (getFace tmesh f) to:out_file
format "%," (tmesh.pivot) to:out_file
close out_file
you import it something like this:
$.pivot = point3 xvalue y value zvalue
ok Ive added that line of code but I get an error “unknown property; “pivot” in TriMesh. can anyone help or point me to some info on this mater as I cant find anything in the max script help files Im goin to try work it out but if anyone has any ideas then please do let me know.
Thanks for reading
Ok this is the script so far its working fine but I still cant get it to record the pivot point of the mesh
rollout keysRollout "Keys"
(
group "controls" (
button IM "Import" pos:[32,18] width:96 height:24
button EX "Export" pos:[32,48] width:96 height:24
)
group "test" (
label ax " "
)
on IM pressed do (
vert_array = #()
face_array = #()
in_file = openFile ((GetDir #export)+"/testmesh.dat")
if in_file != undefined then
(
num_verts = readValue in_file
num_faces = readValue in_file
vert_array.count = num_verts
face_array.count = num_faces
for v = 1 to num_verts do vert_array[v] = (readValue in_file)
for f = 1 to num_faces do face_array[f] = (readValue in_file)
close in_file
new_mesh = mesh vertices:vert_array faces:face_array
-- $.pivot = point3 x value y value z value
ax.text = "Imported"
)
)
on EX pressed do (
tmesh = snapshotAsMesh selection[1]
out_file = createfile ((GetDir #export)+"/testmesh.dat")
format "%,%
" tmesh.numverts tmesh.numfaces to:out_file
for v = 1 to tmesh.numverts do
format "%," (getVert tmesh v) to:out_file
format "
" to:out_file
for f = 1 to tmesh.numfaces do
format "%," (getFace tmesh f) to:out_file
-- format "%," (tmesh.pivot) to:out_file
close out_file
ax.text = "Exported"
)
)
createDialog keysRollout width:150 height:150
I cant find any info on this , so Im stuck on this right now .
thanks for reading
Ok, here is what happens:
snapshotasmesh returns the vertex position in WORLD space, after all transforms and space warps. So the pivot cannot be anywhere else than at the origin, otherwise the result would be wrong.
To get the pivot and the mesh, you would have to transform all vertices back into object space and of course store the position, rotation and scale of the node.
My second DVD would be a perfect companion in this case, but also the BFF script I wrote does this so you could peek into it.
Here is a simplified solution. It does not store the pivot offset, but at least it exports and imports the node transform and the vertices in object space, so when you import a moved, rotated and scaled object, its pivot point will be just where it was when exported:
rollout keysRollout "Keys"
(
group "controls"
(
button IM "Import" pos:[32,18] width:96 height:24
button EX "Export" pos:[32,48] width:96 height:24
)
group "test"
(
label ax " "
)
on IM pressed do (
vert_array = #()
face_array = #()
in_file = openFile ((GetDir #export)+"/testmesh.dat")
if in_file != undefined then
(
theTM = readValue in_file [b]--import the transformation matrix[/b]
num_verts = readValue in_file
num_faces = readValue in_file
vert_array.count = num_verts
face_array.count = num_faces
for v = 1 to num_verts do vert_array[v] = (readValue in_file)
for f = 1 to num_faces do face_array[f] = (readValue in_file)
close in_file
new_mesh = mesh vertices:vert_array faces:face_array
new_mesh.transform = theTM [b]--set the matrix[/b]
ax.text = "Imported"
)
)
on EX pressed do
(
tmesh = snapshotAsMesh selection[1]
theTM = selection[1].transform [b]--grab the transformation matrix
[/b]theInvTM = inverse theTM [b]--invert the matrix once
[/b] out_file = createfile ((GetDir #export)+"/testmesh.dat")
format "%
" theTM to:out_file [b]--output the transformation matrix[/b]
format "%,%
" tmesh.numverts tmesh.numfaces to:out_file
for v = 1 to tmesh.numverts do
format "%," ((getVert tmesh v) * theInvTM) to:out_file [b]--convert to object space[/b]
format "
" to:out_file
for f = 1 to tmesh.numfaces do
format "%," (getFace tmesh f) to:out_file
close out_file
ax.text = "Exported"
)
)
createDialog keysRollout width:150 height:150
Thanks for the reply Bobo I will give that a go I was goin out me head tryin to work this out
thanks again