Hi,
the “mesh to cpp” script from examples/widget does not export uv coords,
Do you have similar exporter that will export also uv coords?
Thanks
Hi,
the “mesh to cpp” script from examples/widget does not export uv coords,
Do you have similar exporter that will export also uv coords?
Thanks
and vertex colours
macroScript Mesh2CPP
category:"Claudes Utils"
tooltip:"Mesh to CPP"
(
Global Mesh2CPP_Toolbar;
local isOpen = false;
local titlestr = "Mesh to C++";
local win_width = 150, win_height = 30;
local set_face_smoothing_group = false;
local vi_offset = 0;
local fi_offset = 0;
--**********************************************************************************************************
fn ExportCPP var_name msh tm stream =
(
format "\t%.setNumVerts(%);\n" var_name msh.numverts to:stream
format "\t%.setNumFaces(%);\n\n" var_name msh.numfaces to:stream
for i = 1 to msh.numverts do
(
pnt = roundvert ((getvert msh i) * tm) 0.0001;
format "\t%.setVert(%,size*Point3(%f,%f,%f));\n" var_name (vi_offset + i - 1) pnt.x pnt.y pnt.z to:stream
)
for i = 1 to msh.numfaces do
(
pnt = getface msh i
format "\t%.faces[%].setVerts(%, %, %);\n" var_name \
(fi_offset + i-1) \
(vi_offset + pnt.x as integer - 1) \
(vi_offset + pnt.y as integer - 1) \
(vi_offset + pnt.z as integer - 1) \
to:stream
format "\t%.faces[%].setEdgeVisFlags(%,%,%);\n" var_name\
(fi_offset + i-1) \
(if (getedgevis msh i 1) then 1 else 0) \
(if (getedgevis msh i 2) then 1 else 0) \
(if (getedgevis msh i 3) then 1 else 0) \
to:stream
if set_face_smoothing_group then
format "\t%.faces[%].setSmGroup(%);\n" var_name (fi_offset + i-1) (getfacesmoothgroup msh i) to:stream
)
if msh.numtverts != 0 then
(
format "\n\t%.setNumTVerts(%);\n" var_name msh.numtverts to:stream
format "\t%.setNumTVFaces(%);\n\n" var_name msh.numfaces to:stream
for i = 1 to msh.numtverts do
(
pnt = roundvert (getTVert msh i) 0.0001;
format "\t%.setTVert(%,Point3(%f,%f,%f));\n" var_name (i-1) pnt.x pnt.y pnt.z to:stream
)
for i = 1 to msh.numfaces do
(
pnt = getTVface msh i
format "\t%.tvFace[%].setTVerts(%, %, %);\n" var_name \
(i-1) (pnt.x as integer - 1) (pnt.y as integer - 1) (pnt.z as integer - 1) to:stream
)
)
if msh.numcpvverts != 0 then
(
format "\n\t%.setNumVertCol(%);\n" var_name msh.numcpvverts to:stream
format "\t%.setNumVCFaces(%);\n\n" var_name msh.numfaces to:stream
for i = 1 to msh.numcpvverts do
(
pnt = (getVertColor msh i as point3)/255.0
format "\t%.setMapVert(0, %,Point3(%f,%f,%f));\n" var_name (i-1) pnt.x pnt.y pnt.z to:stream;
)
for i = 1 to msh.numfaces do
(
pnt = getVCFace msh i;
format "\t%.mapFaces(0)[%].setTVerts(%, %, %);\n" var_name \
(i-1) (pnt.x as integer - 1) (pnt.y as integer - 1) (pnt.z as integer - 1) to:stream;
)
)
if(meshop.getmapsupport msh 2 == true) then
(
nmapverts = meshop.getNumMapVerts msh 2;
nmapfaces = meshop.getNumMapFaces msh 2;
format "\n\t%.setMapSupport(%);\n" var_name 2 to:stream;
format "\t%.setNumMapVerts(%,%);\n" var_name 2 nmapverts to:stream;
format "\t%.setNumMapFaces(%,%);\n\n" var_name 2 nmapfaces to:stream;
for i = 1 to nmapverts do
(
pnt = roundvert (meshop.getMapVert msh 2 i) 0.0001;
format "\t%.setMapVert(2, %,Point3(%f,%f,%f));\n" var_name (i-1) pnt.x pnt.y pnt.z to:stream;
)
for i = 1 to nmapfaces do
(
pnt = meshop.getMapFace msh 2 i
format "\t%.mapFaces(2)[%].setTVerts(%, %, %);\n" var_name \
(i-1) (pnt.x as integer - 1) (pnt.y as integer - 1) (pnt.z as integer - 1) to:stream;
)
)
format "\n\t%.InvalidateGeomCache();\n" var_name to:stream;
format "\t%.EnableEdgeList(1);\n" var_name to:stream;
)
--**********************************************************************************************************
fn TheExport =
(
if (obj = selection[1]) != undefined and canConvertTo obj Editable_mesh then
(
-- get the user props
local var_name = getUserProp obj "var_name";
if var_name == undefined then var_name = "mesh"
if (temp = getUserProp obj "vert_index_offset") != undefined then
vi_offset = (temp as integer);
if (temp = getUserProp obj "face_index_offset") != undefined then
fi_offset = (temp as integer);
tm = inverse obj.transform;
objmesh = snapshotAsMesh obj;
local fname = getsavefilename types:"Header Files (*.h)|*.h|"
if fname != undefined then
(
local stream = createfile fname
if stream != undefined then
(
ExportCPP var_name objmesh tm stream
close stream
)
else
messagebox ("Error opening file \"" + fname + "\"")
)
delete objmesh;
)
else
messagebox "You must select an object with a mesh."
)
--**********************************************************************************************************
rollout Mesh2CPP_Toolbar titlestr
(
checkbox set_smg_exp_chbx "Export Face Smg" checked:set_face_smoothing_group align:#left across:2 offset:[-4,0];
on set_smg_exp_chbx changed val do set_face_smoothing_group = val;
button do_the_export_btn "Export" align:#right offset:[-3,-3] \
images:#("meshtocpp_16i.bmp", "meshtocpp_16a.bmp", 1, 1, 1, 1, 1, true) border:false;
on do_the_export_btn pressed do TheExport();
on Mesh2CPP_Toolbar close do
(
isOpen = false;
updateToolbarButtons();
)
)
--**********************************************************************************************************
on isChecked do isOpen;
--**********************************************************************************************************
on execute do
(
-- we do it this was becaude closedialogs event doesn't seem to work for RegisterDialogBar dialogs
if Mesh2CPP_Toolbar.open then
(
try(cui.UnRegisterDialogBar Mesh2CPP_Toolbar)catch()
try
(
destroyDialog Mesh2CPP_Toolbar;
isOpen = false;
)catch();
)
else
(
createDialog Mesh2CPP_Toolbar pos:[0,-100] width:win_width height:win_height lockWidth:true lockHeight:true style:#();
cui.RegisterDialogBar Mesh2CPP_Toolbar minSize:200 maxSize:200 style:#(#cui_dock_top,#cui_handles,#cui_floatable)
cui.DockDialogBar Mesh2CPP_Toolbar #cui_dock_top;
isOpen = true;
)
)
--**********************************************************************************************************
)
you’ll need to remove the roundvert calls or create your own mxs version of it.