I need help guys,im stuck on exporting bf2 vehicle.when i try to export i get this error. PLEASE HELP:(
And sorry for my bad english.
Code:
-- Unknown property: "saveMaterial" in undefined
Code:
-- this struct holds the main scene dumping functions
struct rSceneDump
(
fn getFilenameExt =
(
return "Objects(Objects.con)|Objects.con|All|*.*|"
),
-- rSceneDump.writeMesh f meshObj matInfo coordSpace:(matrix3 1) s:s isNonVis:isNonVis
fn writeMesh f obj matInfo coordSpace:#world s:0.1 isNonVis:false bnObjs:#() dontWarnSkinWeights:false minUvSetCnt:0=
(
RMesh.export obj fHandle:f isLocal:true matInfo:matInfo coordSpace:coordSpace s:s isNonVis:isNonVis bnObjs:bnObjs dontWarnSkinWeights:dontWarnSkinWeights minUvSetCnt:minUvSetCnt
),
fn writeTransform f t s:0.1=
(
writeFloat f t.row1.x
writeFloat f t.row1.z
writeFloat f t.row1.y
writeFloat f t.row3.x
writeFloat f t.row3.z
writeFloat f t.row3.y
writeFloat f t.row2.x
writeFloat f t.row2.z
writeFloat f t.row2.y
-- Position
writeFloat f (t.row4.x*s)
writeFloat f (t.row4.z*s)
writeFloat f (t.row4.y*s)
),
fn saveAnimation f obj objParent range:#(0,0) s:0.1=
(
writeLong f (range[2] - range[1] + 1)
if objParent != undefined then
(
for i=range[1] to range[2] do
(
local t
at time i
(
local t1 = copy obj.transform
local t2 = copy objParent.transform
t = t1 * inverse t2
)
local bonePos = [t.row4.x, t.row4.z, t.row4.y] * s
t.row4 = [0,0,0]
local r = (bf2TransformConvert t).rotation
writeFloat f r.x
writeFloat f r.y
writeFloat f r.z
writeFloat f r.w
writeFloat f bonePos[1]
writeFloat f bonePos[2]
writeFloat f bonePos[3]
)
)
else
(
for i=range[1] to range[2] do
(
local t
at time i
(
t = copy obj.transform
)
local bonePos = [t.row4.x, t.row4.z, t.row4.y] * s
t.row4 = [0,0,0]
local r = (bf2TransformConvert t).rotation
writeFloat f r.x
writeFloat f r.y
writeFloat f r.z
writeFloat f r.w
writeFloat f bonePos[1]
writeFloat f bonePos[2]
writeFloat f bonePos[3]
)
)
),
fn getRootNode objs =
(
for i=1 to objs.count do
(
if objs[i].parent == undefined then
(
if objs[i].name.count > 5 then
(
local testName = lowercase objs[i].name
if "root_" == (substring testName 1 5) then
(
return objs[i]
)
)
)
)
return undefined
),
fn getRootNodeType rootObjNode =
(
local objectTypeName = undefined
if isValidNode rootObjNode then
(
local testName = lowercase rootObjNode.name
objectTypeName = substring testName 6 -1
-- "root_staticmesh_MyName"
local foundID = findstring objectTypeName "_"
if foundID != undefined then
(
objectTypeName = substring objectTypeName 1 (foundID-1)
)
)
return objectTypeName
),
fn save fname:undefined objs:undefined dbg:true anmRange:undefined anmObjs:undefined s:0.1 prefix:undefined=
(
format "save()\n"
if objs == undefined then objs = objects as array
if objs.count == 0 then
(
format "ERROR! No objects to export!\n"
return false
)
local scalesAreUniform = BF2checkScales objs
format " scalesAreUniform: %\n" scalesAreUniform
format " anmRange: %\n" anmRange
format " anmObjs: %\n" anmObjs
-- Filename handling
if fname == undefined then
(
fname = getSaveFileName types:(rSceneDump.getFilenameExt())
)
if fname == undefined then
( return false
)
-- make sure it has the .dat file extension
local fnameType = getFilenameType fname
if lowercase fnameType != ".dat" then
(
if fnameType.count > 0 then fname = (substring fname 1 (fname.count - fnameType.count)) + ".dat"
else fname = fname + ".dat"
)
format " fname: %\n" fname
format " objs: %\n" objs
-- find the root node type
local rootObjNode = rSceneDump.getRootNode objs
local objectTypeName = rSceneDump.getRootNodeType rootObjNode
if objectTypeName == undefined then
(
MessageBox "Undefined root type! should be one of these: bundledMesh, staticMesh, ..."
return false
)
local isStaticObject = false
local isAnimation = false
local isSkeleton = false
local jointNodeTypes = #()
append JointNodeTypes BoneGeometry
append jointNodeTypes Pyramid
local validType = false
if objectTypeName == "staticmesh" then
(
isStaticObject = true
anmRange = #(currentTime, currentTime)
anmObjs = #()
jointNodeTypes = #()
validType = true
)
if objectTypeName == "bundledmesh" or objectTypeName == "meshparticlemesh" then
(
anmRange = #(currentTime, currentTime)
anmObjs = #()
validType = true
)
if objectTypeName == "skeleton" or objectTypeName == "skinnedmesh" then
(
isSkeleton = true
anmRange = #(currentTime, currentTime)
anmObjs = #()
validType = true
)
if objectTypeName == "animation" then
(
isAnimation = true
--append jointNodeTypes Dummy
validType = true
)
if not validType then
(
local errMesg = "ERROR! Root object name is unknown: \"" + (objectTypeName as string) + "\"\nCheck your spelling."
format "%\n" errMesg
MessageBox errMesg
return false
)
local isAnimOrSke = isAnimation or isSkeleton
format " jointNodeTypes: %\n" jointNodeTypes
-- For use in animations, kit parts and weapon parts
-----------------
local rHand
local root_bone
local is1p = false
local is3p = false
if isAnimOrSke then
(
for o in objs do
(
local bnName = lowercase o.name
if bnName == "right_ullna" then
(
rHand = o
is3p = true
)
if bnName == "torus" then
(
rHand = o
is1p = true
)
if bnName == "root" then
(
root_bone = o
)
)
)
-- (1p skeleton) weapon parts are mesh1 ... mesh16
-- (3p skeleton) kits take over mesh9 ... mesh16
local numWeapParts = 0
if is3p then
(
numWeapParts = 8
)
else
(
if is1p then numWeapParts = 16
)
-----------------
-- create the file
local f = fopen fname "wb"
-- file didn't open, so create the path and try again
if (f == undefined) then
(
local fnamePath = getFilenamePath fname
fnamePath = replaceChar fnamePath "/" "\\"
local b = makeDir fnamePath
f = fopen fname "wb"
)
if (f != undefined) then
(
local rootNodeTransform = rootObjNode.transform
-- Prefixes object names to make them unique for the global game scope
local objsPrefix = #()
if not isAnimOrSke and classof prefix == String then
(
if isValidNode rootObjNode then
(
bf2getNodesforPrefix rootObjNode objsPrefix
bf2AddNamePrefix objsPrefix prefix
)
)
-------------
-- SORTING object order
--
local objsNew = BF2SortSkeParts objs objectTypeName is1p is3p
--fclose f
--return
--objs = objsNew
if not isAnimOrSke then
objs = objsNew
if isAnimation then
(
format " isAnimation : %\n" isAnimation
-- objs = objsNew
)
local oldRootName = rootObjNode.name
rootObjNode.name = "root_" + objectTypeName
-- CALCULATE MESH INFO
local meshCount = 0
local validMeshIDs = #()
local objUsesMesh = #()
objUsesMesh[objs.count] = undefined
for i=1 to objs.count do
(
local curObj = objs[i]
if SuperClassof curObj == GeometryClass then
(
if not (isOneOfThese curObj JointNodeTypes) then
(
local meshObjId = i
objUsesMesh[i] = meshObjId
if 0 == (findItem validMeshIDs meshObjId) then
append validMeshIDs meshObjId
)
)
)
format " validMeshIDs: %\n" validMeshIDs
-- EXPORT MESH DATA
writeLong f validMeshIDs.count
local matFname = (getFilenamePath fname) + (getFilenameFile fname) + ".material"
deleteFile matFname
local fMat = fopen matFname "w"
if fmat != undefined then
(
fclose fMat
)
else
(
format "WARNING! Unable to create file: %\n" matFname
)
for i=1 to validMeshIDs.count do
(
local meshObj = objs[validMeshIDs[i]]
local matInfo = BF2MatInfo.getMulti meshObj.material type:objectTypeName
local meshObj_OriginalTransform = meshObj.transform
local isNonVis = false
if isValidNode meshObj.parent then
(
if (lowercase meshObj.parent.name == "nonvis_") then
isNonVis = true;
)
local crdSpace = matrix3 1
if isStaticObject then
(
crdSpace = meshObj.transform * (inverse rootObjNode.transform)
)
else
(
local p = meshObj.parent
if isValidNode p then
(
if lowercase p.name == "nonvis_" then
(
if isValidNode p.parent then
(
-- A collision mesh's pivot is the visible mesh that it is parented to
crdSpace = meshObj.transform * (inverse p.parent.transform)
)
)
-- scale the mesh
crdSpace = crdSpace * scaleMatrix meshObj.scale
)
)
local dontWarnSkinWeights = false
local bnObjs = #()
-- TODO: Get the skeleton bones in the correct order as they will be in the export
if objectTypeName == "skinnedmesh" then
(
format "SkinnedMesh ... Getting skeleton bones for mesh: %\n" meshObj.name
bnObjs = bf2GetSkinMeshBones meshObj objs jointNodeTypes
)
if objectTypeName == "bundledmesh" then
(
dontWarnSkinWeights = true
for o in objs do
(
if findItem jointNodeTypes (classof o) > 0 then
append bnObjs o
)
)
local minUvSetCnt = 0
if isStaticObject and not isNonVis then
(
minUvSetCnt = 4
)
rSceneDump.writeMesh f meshObj matInfo coordSpace:crdSpace s:s isNonVis:isNonVis bnObjs:bnObjs dontWarnSkinWeights:dontWarnSkinWeights minUvSetCnt:minUvSetCnt
meshObj.transform = meshObj_OriginalTransform
local a = ""
for i=1 to matInfo.count do
(
local fxMat = matInfo[i]
if fxMat.fxFilename == undefined then
(
format "WARNING: % has undefined .fxFilename\n" meshObj.name
--format " % \n" fxMat
--format " % \n" meshObj.material
)
local b = fxMat.materialID as string
b = b + ";" + (fxMat.materialName as string)
b = b + ";" + (fxMat.fxFilename as string)
b = b + ";" + (fxMat.technique as string) + ";"
for j=1 to fxMat.textures.count do
(
local tmpTexture = fxMat.textures[j]
if tmpTexture.count == 0 then tmpTexture = "default.dds"
b = b + "|" + tmpTexture
)
a = a + "?" + b
)
local saveMatSuccess = bf2mdtOps.saveMaterial matFname ("mesh" + ((i-1) as string)) a
if saveMatSuccess != 0 then
(
format "WARNING! Unable to save file: %\n" matFname
)
)
-------------------------------
-- EXPORT NODE GRAPH DATA
-- each node has transform and can have a mesh instance
writeLong f objs.count
local animatedNodeNames = #()
for i=1 to objs.count do
(
local curObj = objs[i]
-- path Names "Fred|mike|pete" for graphing the scene
local pathName = BF2getObjectPath curObj
writeLong f (pathName.count + 1)
writestring f pathName
-- debug info
if dbg == true then
(
if i < 10 then format " 0%_:%\n" i pathName
else format " %_:%\n" i pathName
)
-- Node TypeId
local typeId = -1
local meshId = objUsesMesh[i]
if meshId != undefined then
(
meshId = findItem validMeshIDs objUsesMesh[i]
if (meshId == 0) then
throw "ASSERT! meshID == 0!\n"
meshId = meshId - 1
typeId = 0 -- Is mesh
)
else
(
meshId = -1
if (isOneOfThese curObj JointNodeTypes) then
(
typeId = 3; -- joint
)
else
(
case (classof curObj) of
(
Point: typeId = 1 -- locator
default: typeID = 2 -- transform
)
)
)
local m_flags = 0
local hasAnim = false
if classof anmObjs == array then
(
local findID = findItem anmObjs curObj
if findID != 0 then
(
append animatedNodeNames curObj.name
m_flags = bit.set m_flags 1 true -- anim_export true
hasAnim = true
)
)
--format "typeId: % %\n" typeId hasAnim
writeLong f typeId
writeLong f meshId
writelong f m_flags
if hasAnim then
(
local objParent = curObj.parent
-- weapons are relative to right hand
local meshID = BF2GetMeshIDFromName curObj.name
if classof meshID == integer then
( if meshID <= numWeapParts then
(
objParent = objs[1]
format " weapon part: % (meshID : %)\n" curObj.name meshID
)
)
rSceneDump.saveAnimation f curObj objParent range:anmRange s:s
)
else
(
if typeId == 3 then -- joint
(
rSceneDump.saveAnimation f curObj curObj.parent range:#(currentTime,currentTime) s:s
)
else
(
local t = undefined
if isStaticObject then
(
t = matrix3 1 -- the staticobject will snap to this transform if not already this transform
)
else
(
local p = curObj.parent
if isValidNode p then
(
if lowercase curObj.name == "nonvis_" then
(
t = matrix3 1
)
else
(
if lowercase p.name == "nonvis_" then
(
if isValidNode p.parent then
(
t = matrix3 1
)
)
)
)
)
if t == undefined then
(
t = curObj.transform
if isValidNode curObj.parent then
(
t = curObj.transform * (inverse curObj.parent.transform)
t.row4 = t.row4 * curObj.parent.scale
)
else
(
)
)
-- format " t: %\n" t
-- write out relative transform coordinates
writelong f 0
rSceneDump.writeTransform f t s:s
)
)
)
format " animatedNodeNames: %\n" animatedNodeNames
fclose f
if objs.count > 0 then
objs[1].name = oldRootName
-- Removes Prefixes object names to make them unique for the global game scope
if not isAnimOrSke and classof prefix == String then
(
bf2RemoveNamePrefix objsPrefix prefix
)
return fname
)
else
(
format "Error! Could not create file!\n\t%\n" fname
MessageBox ("Error! Could not create file:\n" + (fname as string))
)
return false
)
)