📄 ogreskeletonlib_meshfns.ms
字号:
-- same thing with physique modifier if defined
if (phy != undefined) then (
-- TODO: here the selection ($) is used because tmesh can't be used...
-- it should be changed ti use pmesh (in the main function) for example.
vwcount = physiqueOps.getVertexBoneCount $ a ; -- a is the vertex number: "a = (int) (f[j]) ;"
for k=1 to vwcount do
(
bone = physiqueOps.getVertexBone $ a k
w = physiqueOps.getVertexWeight $ a k
-- search the bone number
bid = getUserProp bone "number" ;
--format "%,%\n%(%)\n" v weight bid.Name k ;
append boneAssignments[matId] #(ogreVertNum,bid,w) ;
)
-- assignment to the root bone.
if (vwcount==0) then (
-- gets the root Id:
--rootId=getRootsId sk
--append boneAssignments[matId] #(ogreVertNum,rootId[1],1) ;
print "No assignment" ;
)
)
)
ogreFace[j] = ogreVertNum ;
)
-- flip normal capability
if (flipNormal) then
(
faceTmp = copy ogreFace ;
ogreFace[2] = faceTmp[3] ;
ogreFace[3] = faceTmp[2] ;
)
if (facesArrays[matId] == undefined) then
facesArrays[matId] = #() ;
append facesArrays[matId] #(ogreFace[1],ogreFace[2],ogreFace[3]) ; -- Face is added to datas
)
)
-------------------------------------------------
-- writes in the mesh.xml file
-- outName : filename
-- exportUV = true if you want to export texture
-- exportColor = true if you want to export vertices colors
--
-- Uses the arrays verticesArrays and facesArrays
-------------------------------------------------
function writeM exportUV exportColours material outName =
(
local a,v,f,matname,hasSkeleton,outFile,numTexCoord,hasColours,matId ;
hasSkeleton = false ;
texCoordString = "" ;
if (exportUV) then
texCoordString = "texture_coords=\"1\" texture_coord_dimensions_0=\"2\" "
hasColours = false ;
if (exportColours) then
hasColours = true ;
-- the final file is created
outFile = createfile (outName + ".mesh.xml") ;
-- writes the header
format("<mesh>\n") to:outFile ;
-- submeshes start
format("\t<submeshes>\n") to:outFile ;
-- for each submesh
for matId in submeshesId do (
-- Do we need 32-bit indexes?
use32bitindexes = "false";
if arrayLength verticesArrays[matId] > 65535 then
use32bitindexes = "true";
-- get the name of the sub material if needed.
submatname = replacespaces material.name ;
if (classof material == MultiMaterial) then
submatname += "/" + replacespaces material.materiallist[matId].name ;
-- HELLO ! --
---------------------------------------------------------------------------------
-- IF YOU COME HERE BECAUSE YOUR OBJECT FAILED EXPORTING, MAYBE THAT'S BECAUSE --
-- YOU USE MATERIAL ID IN YOUR MESH THAT DOESN'T EXIST IN YOUR MULTIMATERIAL --
---------------------------------------------------------------------------------
format("\t\t<submesh material = \"%\" usesharedvertices=\"false\" use32bitindexes=\"%\">\n") submatname use32bitindexes to:outFile ;
format "- writing faces...\n"
format("\t\t\t<faces count=\"%\">\n") (arraylength facesArrays[matId]) to:outFile;
-- for each face
for f in facesArrays[matId] do (
format("\t\t\t\t<face ") to:outFile ;
format("v1=\"%\" v2=\"%\" v3=\"%\" />\n") ((int)f[1]) ((int)f[2]) ((int)f[3]) to:outFile ;
)
format("\t\t\t</faces>\n") to:outFile ;
format "- writing vertices...\n"
format("\t\t\t<geometry vertexcount=\"%\">\n") (arrayLength verticesArrays[matId] ) to:outFile;
format("\t\t\t\t<vertexbuffer positions=\"true\" normals=\"true\" colours_diffuse=\"%\" %>\n") hasColours TexCoordString to:outFile ;
-- for each vertex
for v in verticesArrays[matId] do
(
format("\t\t\t\t\t<vertex>\n") to:outFile ;
format("\t\t\t\t\t\t<position x=\"%\" y=\"%\" z=\"%\" />\n") v[1] v[2] v[3] to:outFile ;
format("\t\t\t\t\t\t<normal x=\"%\" y=\"%\" z=\"%\" />\n") v[4] v[5] v[6] to:outFile ;
if (exportUV) then
format("\t\t\t\t\t\t<texcoord u=\"%\" v=\"%\" />\n") v[7] (1 - v[8]) to:outFile ;
if (exportColours) then (
cv = (float) 255*(int)v[12] ; -- a
cv = 255*(cv + (int)v[11]) ; -- b
cv = 255*(cv + (int)v[10]) ; -- g
cv = cv+ (int)v[12] ; -- r
cv_part2 = (int) (mod cv 1000000) ;
cv_part1 = (int) (cv/1000000);
format("\t\t\t\t\t\t<colour_diffuse value=\"%\" />\n") cv_part1 cv_part2 to:outFile ;
)
format("\t\t\t\t\t</vertex>\n") to:outFile ;
)
format("\t\t\t\t</vertexbuffer>\n") to:outFile ;
format("\t\t\t</geometry>\n") to:outFile ;
-- and now bone assignments (and skeleton), if there is at least one element in boneAssignments array.
if ((arrayLength boneAssignments[matId]) != 0) then
(
hasSkeleton = true ;
format "- writing bone assignments...\n"
format("\t\t\t<boneassignments>\n") to:outFile ;
for a in boneAssignments[matId] do (
format("\t\t\t\t<vertexboneassignment vertexindex=\"%\" boneindex=\"%\" weight=\"%\" />\n") a[1] a[2] a[3] to:outFile ;
)
format("\t\t\t</boneassignments>\n") to:outFile ;
)
-- submesh end
format("\t\t</submesh>\n") to:outFile ;
)
-- submeshes end
format("\t</submeshes>\n") to:outFile ;
-- Skeleton link if there is at least one bone assignement.
if (hasSkeleton) then
(
t = filterstring outName "\\" ;
format ("\t<skeletonlink name=\"%\"/>\n") (t[arrayLength t] + ".skeleton") to:outFile ;
)
format("</mesh>\n") to: outFile ;
close outFile ;
)
---------------------------------
-- writes the mesh: main function
---------------------------------
function writeMesh pmesh exportOptions out_name =
(
local m,sk,outFile,message,phy ;
m = snapshotAsMesh pmesh ;
-- tries to find errors
message = exploreMesh pmesh exportOptions.exportUV exportOptions.exportColours;
if (message != "OK") then
(
MessageBox ("\n There is a problem with your mesh:\n" + message + "\n\nOperation aborted") ;
delete m ;
return false ;
)
else
(
format "\n\n"
format "------------------------------------------\n"
format "------- OGRE Mesh Exporter Log -------\n"
format "----- -----\n"
-- get the skin modifier ( may be undefined )
-- and physique modifier
phy = getPhysique pmesh ;
sk = getSkin pmesh;
if (sk != undefined) then
format "Skin modifier detected.\n"
if (phy != undefined) then
format "Physique modifier detected.\n"
-- if not undefined, skin modifier is selected in modifier tab. Or there will be an error.
if (sk != undefined) then
(
-- in order to perform, skin should be opened
max modify mode ;
modPanel.setCurrentObject pmesh.modifiers[#Skin] ;
)
-- physique
if (phy != undefined) then
(
-- in order to perform, skin should be opened
max modify mode ;
modPanel.setCurrentObject pmesh.modifiers[#Physique] ;
setBonesNumber phy ;
--physiqueOps.setInitialPose pmesh true ;
)
-- retieving material
if (pmesh.material != undefined) then (
materialName = pmesh.material.name ;
replaceSpaces materialName ;
)
else materialName = pmesh.name + "Material" ;
format "Material name exported : \n- %/*** \n" materialName ;
-- retrieving all datas
format "Retrieving vertices and faces data : \n" ;
getDatas m exportOptions.flipyz exportOptions.scale exportOptions.flipNormal exportOptions.exportUV exportOptions.exportColours sk phy;
-- writing in the file
format "Writing in file %.mesh.xml : \n" out_name ;
WriteM exportOptions.exportUV exportOptions.exportColours pmesh.material out_name ;
format "Export successful.\n"
delete m ;
format "----- -----\n"
format "---------- END ---------\n"
format "------------------------------------------\n"
MessageBox ("Exporting mesh successful !") ;
)
return true ;
)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -